You've already forked joomla_test
first commit
This commit is contained in:
35
plugins/josetta_ext/k2category/definitions.xml
Normal file
35
plugins/josetta_ext/k2category/definitions.xml
Normal file
@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<josetta>
|
||||
<context>com_k2_category</context>
|
||||
<name>K2 Category</name>
|
||||
<table>#__k2_categories</table>
|
||||
<reference>
|
||||
<id>
|
||||
<column>id</column>
|
||||
<type>int</type>
|
||||
<size>11</size>
|
||||
</id>
|
||||
<title>
|
||||
<column>name</column>
|
||||
<type>josettatext</type>
|
||||
<size>255</size>
|
||||
</title>
|
||||
<published>
|
||||
<column>published</column>
|
||||
<type>int</type>
|
||||
<size>6</size>
|
||||
</published>
|
||||
<parent>
|
||||
<column>parent</column>
|
||||
<type>int</type>
|
||||
<size>11</size>
|
||||
</parent>
|
||||
</reference>
|
||||
<reference_filters>
|
||||
<reference_filter>
|
||||
<table>#__k2_categories</table>
|
||||
<column>trash</column>
|
||||
<value>0</value>
|
||||
</reference_filter>
|
||||
</reference_filters>
|
||||
</josetta>
|
131
plugins/josetta_ext/k2category/fields_common.xml
Normal file
131
plugins/josetta_ext/k2category/fields_common.xml
Normal file
@ -0,0 +1,131 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<josetta>
|
||||
<fields>
|
||||
<field>
|
||||
<id>name</id>
|
||||
<name>K2_TITLE</name>
|
||||
<description></description>
|
||||
<column>name</column>
|
||||
<type>josettatext</type>
|
||||
<size>60</size>
|
||||
<length>255</length>
|
||||
<translate>yes</translate>
|
||||
<display>yes</display>
|
||||
<require>yes</require>
|
||||
</field>
|
||||
<field>
|
||||
<id>alias</id>
|
||||
<name>K2_TITLE_ALIAS</name>
|
||||
<description></description>
|
||||
<column>alias</column>
|
||||
<type>josettatext</type>
|
||||
<size>60</size>
|
||||
<length>255</length>
|
||||
<translate>yes</translate>
|
||||
<display>yes</display>
|
||||
<require>no</require>
|
||||
</field>
|
||||
<field>
|
||||
<id>parent</id>
|
||||
<name>K2_PARENT_CATEGORY</name>
|
||||
<column>parent</column>
|
||||
<type>k2languagecategory</type>
|
||||
<addfieldpath>/plugins/josetta_ext/k2item/fields</addfieldpath>
|
||||
<translate>yes</translate>
|
||||
<display>yes</display>
|
||||
<require>yes</require>
|
||||
<show_root>yes</show_root>
|
||||
</field>
|
||||
<field>
|
||||
<id>description</id>
|
||||
<name>K2_DESCRIPTION</name>
|
||||
<description></description>
|
||||
<column>description</column>
|
||||
<type>editor</type>
|
||||
<filter>JComponentHelper::filterText</filter>
|
||||
<size>0</size>
|
||||
<length>0</length>
|
||||
<translate>yes</translate>
|
||||
<display>yes</display>
|
||||
<require>no</require>
|
||||
</field>
|
||||
<field>
|
||||
<id>image</id>
|
||||
<name>image</name>
|
||||
<description></description>
|
||||
<column>image</column>
|
||||
<translate>no</translate>
|
||||
<display>no</display>
|
||||
<require>no</require>
|
||||
</field>
|
||||
<field>
|
||||
<id>metadesc</id>
|
||||
<name>K2_DESCRIPTION</name>
|
||||
<description></description>
|
||||
<column>metadesc</column>
|
||||
<type>textarea</type>
|
||||
<size>0</size>
|
||||
<length>0</length>
|
||||
<translate>yes</translate>
|
||||
<display>yes</display>
|
||||
<require>no</require>
|
||||
</field>
|
||||
<field>
|
||||
<id>metakey</id>
|
||||
<name>K2_KEYWORDS</name>
|
||||
<description></description>
|
||||
<column>metakey</column>
|
||||
<type>textarea</type>
|
||||
<size>0</size>
|
||||
<length>0</length>
|
||||
<translate>yes</translate>
|
||||
<display>yes</display>
|
||||
<require>no</require>
|
||||
</field>
|
||||
<field>
|
||||
<id>language</id>
|
||||
<name>K2_LANGUAGE</name>
|
||||
<column>language</column>
|
||||
<type>language</type>
|
||||
<size>0</size>
|
||||
<length>0</length>
|
||||
<translate>no</translate>
|
||||
<display>no</display>
|
||||
<require>no</require>
|
||||
<grid>yes</grid>
|
||||
</field>
|
||||
<field>
|
||||
<id>access</id>
|
||||
<name>access</name>
|
||||
<column>access</column>
|
||||
<translate>no</translate>
|
||||
<display>no</display>
|
||||
<require>no</require>
|
||||
</field>
|
||||
<field>
|
||||
<id>extraFieldsGroup</id>
|
||||
<name>extraFieldsGroup</name>
|
||||
<column>extraFieldsGroup</column>
|
||||
<translate>no</translate>
|
||||
<display>no</display>
|
||||
<require>no</require>
|
||||
</field>
|
||||
<field>
|
||||
<id>attribs</id>
|
||||
<name>attribs</name>
|
||||
<column>params</column>
|
||||
<translate>no</translate>
|
||||
<display>no</display>
|
||||
<require>no</require>
|
||||
</field>
|
||||
<field>
|
||||
<id>xreference</id>
|
||||
<name>xreference</name>
|
||||
<column>xreference</column>
|
||||
<translate>no</translate>
|
||||
<display>no</display>
|
||||
<require>no</require>
|
||||
<grid>no</grid>
|
||||
</field>
|
||||
</fields>
|
||||
</josetta>
|
308
plugins/josetta_ext/k2category/k2category.php
Normal file
308
plugins/josetta_ext/k2category/k2category.php
Normal file
@ -0,0 +1,308 @@
|
||||
<?php
|
||||
/**
|
||||
* @version $Id: k2category.php 1812 2013-01-14 18:45:06Z lefteris.kavadas $
|
||||
* @package K2
|
||||
* @author JoomlaWorks http://www.joomlaworks.net
|
||||
* @copyright Copyright (c) 2006 - 2013 JoomlaWorks Ltd. All rights reserved.
|
||||
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
// include K2Base Josetta plugin, which shares many methods and thus is used as a base class
|
||||
require_once JPATH_PLUGINS . '/josetta_ext/k2item/classes/basek2plugin.php';
|
||||
|
||||
class plgJosetta_extK2Category extends plgJosetta_extBaseK2Plugin
|
||||
{
|
||||
|
||||
protected $_context = 'com_k2_category';
|
||||
protected $_defaultTable = 'K2Category';
|
||||
|
||||
/**
|
||||
* Method to build the dropdown of josetta translator screen
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public function onJosettaGetTypes()
|
||||
{
|
||||
$this->loadLanguages();
|
||||
$item = array(self::$this->_context => 'K2 ' . JText::_('K2_CATEGORIES'));
|
||||
$items[] = $item;
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overriden method, to add indentation to the list of categories
|
||||
*
|
||||
*/
|
||||
public function onJosettaLoadItems($context, $state)
|
||||
{
|
||||
|
||||
if ((!empty($context) && ($context != $this->_context)))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// read data. Can't use parent, as this would slice the results
|
||||
// using limitstart and limit. K2 needs to slice later on,
|
||||
// after indenting has been done
|
||||
$items = array();
|
||||
$db = JFactory::getDbo();
|
||||
$this->_buildItemsListQuery($state);
|
||||
$db->setQuery($this->_query);
|
||||
$rawItems = $db->loadObjectList();
|
||||
|
||||
// Check for a database error.
|
||||
if ($db->getErrorNum())
|
||||
{
|
||||
ShlSystem_Log::logError(__METHOD__ . ': ' . $db->getErrorMsg());
|
||||
$rawItems = array();
|
||||
}
|
||||
|
||||
// now indent
|
||||
if (!empty($rawItems))
|
||||
{
|
||||
|
||||
// Joomla! framework menu utility used to indent
|
||||
// requires fields as parent_id instead of parent
|
||||
foreach ($rawItems as &$item)
|
||||
{
|
||||
$item->title = $item->name;
|
||||
$item->parent_id = $item->parent;
|
||||
}
|
||||
|
||||
// indent cat list, for easier reading
|
||||
$items = self::indentCategories($rawItems);
|
||||
foreach ($items as &$item)
|
||||
{
|
||||
$item->name = JString::str_ireplace('<sup>|_</sup>', '', $item->treename);
|
||||
}
|
||||
|
||||
// finally slice up to get the set we need
|
||||
$items = array_slice($items, $state->get('list.start'), $state->get('list.limit'));
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see JosettaClassesExtensionplugin::onJosettaLoadItem()
|
||||
*/
|
||||
public function onJosettaLoadItem($context, $id = '')
|
||||
{
|
||||
|
||||
if ((!empty($context) && ($context != $this->_context)) || (empty($id)))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
//call the parent base class method to load the context information
|
||||
$category = parent::onJosettaLoadItem($context, $id);
|
||||
|
||||
// Display the parent category name instead of the ID
|
||||
$db = JFactory::getDBO();
|
||||
$db->setQuery('SELECT name FROM #__k2_categories WHERE id = ' . (int) $category->parent);
|
||||
$category->parent = $db->loadResult();
|
||||
|
||||
// Convert the meta description and meta keywords params to fields so user can translate them
|
||||
$categoryParams = new JRegistry($category->params);
|
||||
$category->metadesc = $categoryParams->get('catMetaDesc');
|
||||
$category->metakey = $categoryParams->get('catMetaKey');
|
||||
return $category;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save an item after it has been translated
|
||||
* This will be called by Josetta when a user clicks
|
||||
* the Save button. The context is passed so
|
||||
* that each plugin knows if it must process the data or not
|
||||
*
|
||||
* if $item->reference_id is empty, this is
|
||||
* a new item, otherwise we are updating the item
|
||||
*
|
||||
* $item->data contains the fields entered by the user
|
||||
* that needs to be saved
|
||||
*
|
||||
*@param context type
|
||||
*@param data in form of array
|
||||
*
|
||||
*return table id if data is inserted
|
||||
*
|
||||
*return false if error occurs
|
||||
*
|
||||
*/
|
||||
|
||||
public function onJosettaSaveItem($context, $item, &$errors)
|
||||
{
|
||||
|
||||
if (($context != $this->_context))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// load languages for form and error messages
|
||||
$this->loadLanguages();
|
||||
|
||||
// Save
|
||||
jimport('joomla.filesystem.file');
|
||||
JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/tables');
|
||||
require_once(JPATH_ADMINISTRATOR . '/components/com_k2/lib/class.upload.php');
|
||||
$row = JTable::getInstance('K2Category', 'Table');
|
||||
$params = JComponentHelper::getParams('com_k2');
|
||||
|
||||
if (!$row->bind($item))
|
||||
{
|
||||
JosettaHelper::enqueueMessages($row->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
$row->parent = (int) $row->parent;
|
||||
|
||||
//$input = JRequest::get('post');
|
||||
$filter = JFilterInput::getInstance();
|
||||
$categoryParams = new JRegistry($row->params);
|
||||
$categoryParams->set('catMetaDesc', $filter->clean($item['metadesc']));
|
||||
$categoryParams->set('catMetaKey', $filter->clean($item['metakey']));
|
||||
$row->params = $categoryParams->toString();
|
||||
|
||||
$isNew = ($row->id) ? false : true;
|
||||
|
||||
//Trigger the finder before save event
|
||||
$dispatcher = JDispatcher::getInstance();
|
||||
JPluginHelper::importPlugin('finder');
|
||||
$results = $dispatcher->trigger('onFinderBeforeSave', array('com_k2.category', $row, $isNew));
|
||||
|
||||
if ($params->get('xssFiltering'))
|
||||
{
|
||||
$filter = new JFilterInput(array(), array(), 1, 1, 0);
|
||||
$row->description = $filter->clean($row->description);
|
||||
}
|
||||
|
||||
if (!$row->id)
|
||||
{
|
||||
$row->ordering = $row->getNextOrder('parent = ' . $row->parent . ' AND trash=0');
|
||||
}
|
||||
|
||||
$savepath = JPATH_ROOT . '/media/k2/categories/';
|
||||
if ($row->image && JFile::exists($savepath . $image))
|
||||
{
|
||||
$uniqueName = uniqid() . '.jpg';
|
||||
JFile::copy($savepath . $row->image, $savepath . $uniqueName);
|
||||
$row->image = $uniqueName;
|
||||
}
|
||||
|
||||
if (!$row->check())
|
||||
{
|
||||
JosettaHelper::enqueueMessages($row->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$row->store())
|
||||
{
|
||||
JosettaHelper::enqueueMessages($row->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$params->get('disableCompactOrdering'))
|
||||
$row->reorder('parent = ' . $row->parent . ' AND trash=0');
|
||||
|
||||
if ((int) $params->get('imageMemoryLimit'))
|
||||
{
|
||||
ini_set('memory_limit', (int) $params->get('imageMemoryLimit') . 'M');
|
||||
}
|
||||
|
||||
//$files = JRequest::get('files');
|
||||
|
||||
$savepath = JPATH_ROOT . '/media/k2/categories/';
|
||||
|
||||
// TODO: this will be renamed when used through Josetta
|
||||
//$existingImage = JRequest::getVar('existingImage');
|
||||
if (!empty($item['files']) && !empty($item['files']['image']))
|
||||
{
|
||||
if (($item['files']['image']['error'] === 0 || !empty($item['existingImage'])) && empty($item['del_image']))
|
||||
{
|
||||
if ($item['files']['image']['error'] === 0)
|
||||
{
|
||||
$image = $item['files']['image'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$image = JPATH_SITE . '/' . JPath::clean($item['existingImage']);
|
||||
}
|
||||
|
||||
$handle = new Upload($image);
|
||||
if ($handle->uploaded)
|
||||
{
|
||||
$handle->file_auto_rename = false;
|
||||
$handle->jpeg_quality = $params->get('imagesQuality', '85');
|
||||
$handle->file_overwrite = true;
|
||||
$handle->file_new_name_body = $row->id;
|
||||
$handle->image_resize = true;
|
||||
$handle->image_ratio_y = true;
|
||||
$handle->image_x = $params->get('catImageWidth', '100');
|
||||
$handle->Process($savepath);
|
||||
if ($files['image']['error'] === 0)
|
||||
$handle->Clean();
|
||||
}
|
||||
else
|
||||
{
|
||||
JosettaHelper::enqueueMessages($handle->error);
|
||||
return false;
|
||||
}
|
||||
$row->image = $handle->file_dst_name;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: this will be renamed when used through Josetta
|
||||
if (!empty($item['del_image']))
|
||||
{
|
||||
$currentRow = JTable::getInstance('K2Category', 'Table');
|
||||
$currentRow->load($row->id);
|
||||
if (JFile::exists(JPATH_ROOT . '/media/k2/categories/' . $currentRow->image))
|
||||
{
|
||||
JFile::delete(JPATH_ROOT . '/media/k2/categories/' . $currentRow->image);
|
||||
}
|
||||
$row->image = '';
|
||||
}
|
||||
|
||||
if (!$row->store())
|
||||
{
|
||||
JosettaHelper::enqueueMessages($row->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
//Trigger the finder after save event
|
||||
$dispatcher = JDispatcher::getInstance();
|
||||
JPluginHelper::importPlugin('finder');
|
||||
$results = $dispatcher->trigger('onFinderAfterSave', array('com_k2.category', $row, $isNew));
|
||||
|
||||
$cache = JFactory::getCache('com_k2');
|
||||
$cache->clean();
|
||||
|
||||
return $row->id;
|
||||
|
||||
}
|
||||
|
||||
public static function indentCategories(&$rows, $root = 0)
|
||||
{
|
||||
|
||||
$children = array();
|
||||
if (count($rows))
|
||||
{
|
||||
foreach ($rows as $v)
|
||||
{
|
||||
$pt = $v->parent;
|
||||
$list = @$children[$pt] ? $children[$pt] : array();
|
||||
array_push($list, $v);
|
||||
$children[$pt] = $list;
|
||||
}
|
||||
}
|
||||
|
||||
$categories = JHTML::_('menu.treerecurse', $root, '', array(), $children);
|
||||
|
||||
return $categories;
|
||||
}
|
||||
|
||||
}
|
17
plugins/josetta_ext/k2category/k2category.xml
Normal file
17
plugins/josetta_ext/k2category/k2category.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<extension version="2.5" type="plugin" group="josetta_ext" method="upgrade">
|
||||
<name>Josetta - K2 Categories</name>
|
||||
<author>JoomlaWorks</author>
|
||||
<creationDate>July 8th, 2013</creationDate>
|
||||
<copyright>Copyright (c) 2006 - 2013 JoomlaWorks Ltd. All rights reserved.</copyright>
|
||||
<authorEmail>please-use-the-contact-form@joomlaworks.net</authorEmail>
|
||||
<authorUrl>www.joomlaworks.net</authorUrl>
|
||||
<version>2.6.7</version>
|
||||
<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
|
||||
<description></description>
|
||||
<files>
|
||||
<filename plugin="k2category">k2category.php</filename>
|
||||
<filename>definitions.xml</filename>
|
||||
<filename>fields_common.xml</filename>
|
||||
</files>
|
||||
</extension>
|
219
plugins/josetta_ext/k2item/classes/basek2plugin.php
Normal file
219
plugins/josetta_ext/k2item/classes/basek2plugin.php
Normal file
@ -0,0 +1,219 @@
|
||||
<?php
|
||||
/**
|
||||
* @version $Id: basek2plugin.php 1812 2013-01-14 18:45:06Z lefteris.kavadas $
|
||||
* @package K2
|
||||
* @author JoomlaWorks http://www.joomlaworks.net
|
||||
* @copyright Copyright (c) 2006 - 2013 JoomlaWorks Ltd. All rights reserved.
|
||||
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die ;
|
||||
|
||||
// include base class of josetta plugins
|
||||
require_once JPATH_ADMINISTRATOR.DS.'components/com_josetta/classes/extensionplugin.php';
|
||||
|
||||
class plgJosetta_extBaseK2Plugin extends JosettaadminClass_Extensionplugin
|
||||
{
|
||||
|
||||
protected $_context = 'com_k2';
|
||||
|
||||
public function loadLanguages()
|
||||
{
|
||||
// load Joomla global language files
|
||||
parent::loadLanguages();
|
||||
$language = JFactory::getLanguage();
|
||||
// load the administrator english language of the component
|
||||
$language->load('com_k2', JPATH_ADMINISTRATOR, 'en-GB', true);
|
||||
// load the administrator default language of the component
|
||||
$language->load('com_k2', JPATH_ADMINISTRATOR, null, true);
|
||||
}
|
||||
|
||||
protected function _setPath()
|
||||
{
|
||||
$this->_path = JPATH_PLUGINS.'/josetta_ext/'.$this->_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook for 3rd party extensions to add a path to search for
|
||||
* additional subtypes fields definitions
|
||||
* To be used by extensions, for instance to handle specific menu items
|
||||
* subtypes, or module subtypes
|
||||
*
|
||||
* @param string context
|
||||
*/
|
||||
public function onJosettaAddSubTypePath($context, $subType)
|
||||
{
|
||||
|
||||
if (!empty($context) && ($context != $this->_context))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// a 3rd party extension will use this hook to store a full path to
|
||||
// a directory where fields_*.xml files can be found
|
||||
// to be appended to the translation form,
|
||||
// for instance:
|
||||
$this->_subTypePath[] = JPATH_PLUGINS.'/josetta_ext/'.$this->_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to build a list filter for the main translator view
|
||||
* Used when such filter is not one of the Josetta built in filters type
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public function onJosettaGet3rdPartyFilter($context, $filterType, $filterName, $current)
|
||||
{
|
||||
|
||||
if (!empty($context) && ($context != $this->_context))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$filterHtml = '';
|
||||
|
||||
switch( $filterType)
|
||||
{
|
||||
|
||||
case 'k2languagecategory' :
|
||||
|
||||
// this is a category, so use Joomla html helper to build the drop down
|
||||
$filterHtml = '';
|
||||
$filterHtml .= JText::_('COM_JOSETTA_CONTENT_CATEGORY');
|
||||
$filterHtml .= '<select name="'.$filterName.'" id="'.$filterName.'" class="inputbox" onchange="this.form.submit()">'."\n";
|
||||
$filterHtml .= '<option value="0">'.JText::_('JOPTION_SELECT_CATEGORY').'</option>'."\n";
|
||||
|
||||
$categoriesSelectConfig = array('filter.published' => array(0, 1), 'filter.languages' => array('*', JosettaHelper::getSiteDefaultLanguage()));
|
||||
require_once JPATH_PLUGINS.'/josetta_ext/k2item/helpers/helper.php';
|
||||
$categoriesOptionsHtml = JosettaK2ItemHelper::getCategoryOptionsPerLanguage($categoriesSelectConfig);
|
||||
|
||||
$filterHtml .= JHtml::_('select.options', $categoriesOptionsHtml, 'value', 'text', (int)($current))."\n";
|
||||
$filterHtml .= "</select>\n";
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
}
|
||||
|
||||
return empty($filterHtml) ? null : $filterHtml;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Compute the subtitle of a provided item
|
||||
* Subtitle is used for display to the user of an item
|
||||
* to provide more context
|
||||
* By default, we use an item category
|
||||
*
|
||||
* @param string $context
|
||||
* @param mixed $item
|
||||
*/
|
||||
public function onJosettaGetSubtitle($context, $item)
|
||||
{
|
||||
|
||||
if (!empty($context) && ($context != $this->_context))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$subTitle = '';
|
||||
if (empty($item))
|
||||
{
|
||||
return $subTitle;
|
||||
}
|
||||
|
||||
return $subTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook for module to add their own fields processing
|
||||
* to the form xml
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _output3rdPartyFieldsXml($xmlData, $field, $itemType, $item, $originalItem, $targetLanguage)
|
||||
{
|
||||
switch( $xmlData->fieldType)
|
||||
{
|
||||
|
||||
case 'k2languagecategory' :
|
||||
//add extension tag if type category is present
|
||||
//add option tag in list if present in jform
|
||||
foreach ($field->option as $option)
|
||||
{
|
||||
$xmlData->subfield .= '<option value="'.$option->value->data().'">'.$option->title->data().'</option>';
|
||||
}
|
||||
//Important for developer if using category type extension must be defined in xml
|
||||
$xmlData->other .= ' languages="'.$targetLanguage.'"';
|
||||
$multiple = !empty($field->multiple) && $field->multiple->data() == 'yes';
|
||||
$xmlData->other .= $multiple ? ' multiple="true"' : '';
|
||||
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
|
||||
return $xmlData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a the original field value for display on the translate view
|
||||
*
|
||||
* @param object $originalItem the actual data of the original item
|
||||
* @param string $originalFieldTitle the field title
|
||||
* @param object $field the Joomla! field object
|
||||
* @param string the formatted, ready to display, string
|
||||
*/
|
||||
public function onJosettaGet3rdPartyFormatOriginalField($originalItem, $originalFieldTitle, $field)
|
||||
{
|
||||
|
||||
$html = null;
|
||||
|
||||
switch( strtolower( $field->type))
|
||||
{
|
||||
case 'k2languagecategory' :
|
||||
// element id can be stored in 2 different locations, depending on plugin
|
||||
$elementId = empty($originalItem->request) || !isset($originalItem->request['id']) ? null : $originalItem->request['id'];
|
||||
$elementId = is_null($elementId) ? $originalItem->$originalFieldTitle : $elementId;
|
||||
|
||||
if (is_array($elementId))
|
||||
{
|
||||
// mmultiple categories selected
|
||||
|
||||
$size = $field->element->getAttribute('size');
|
||||
$size = empty($size) ? 10 : $size;
|
||||
$html = '<select name="josetta_dummy" id="josetta_dummy" class="inputbox" size="'.$size.'" multiple="multiple" disabled="disabled">'."\n";
|
||||
$categoriesSelectConfig = array('filter.published' => array(0, 1), 'filter.languages' => array('*', JosettaHelper::getSiteDefaultLanguage()));
|
||||
require_once JPATH_PLUGINS.'/josetta_ext/k2item/helpers/helper.php';
|
||||
$categoriesOptionsHtml = JosettaK2ItemHelper::getCategoryOptionsPerLanguage($categoriesSelectConfig);
|
||||
$html .= JHtml::_('select.options', $categoriesOptionsHtml, 'value', 'text', $elementId)."\n";
|
||||
$html .= "</select>\n";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// just one category
|
||||
if (empty($elementId))
|
||||
{
|
||||
$html = JText::_('ROOT');
|
||||
}
|
||||
else
|
||||
{
|
||||
require_once JPATH_PLUGINS.'/josetta_ext/k2item/helpers/helper.php';
|
||||
$categories = JosettaK2ItemHelper::getCategoriesPerLanguage(null, 'id');
|
||||
$categoryDetails = empty($categories[$elementId]) ? null : $categories[$elementId];
|
||||
$html = empty($categoryDetails) ? $elementId : $categoryDetails->title;
|
||||
if ($html == 'ROOT')
|
||||
{
|
||||
$html = JText::_('ROOT');
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
}
|
1
plugins/josetta_ext/k2item/classes/index.html
Normal file
1
plugins/josetta_ext/k2item/classes/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
46
plugins/josetta_ext/k2item/definitions.xml
Normal file
46
plugins/josetta_ext/k2item/definitions.xml
Normal file
@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<josetta>
|
||||
<context>com_k2_item</context>
|
||||
<name>K2 Item</name>
|
||||
<table>#__k2_items</table>
|
||||
<reference>
|
||||
<id>
|
||||
<column>id</column>
|
||||
<type>int</type>
|
||||
<size>11</size>
|
||||
</id>
|
||||
<title>
|
||||
<column>title</column>
|
||||
<type>josettatext</type>
|
||||
<size>255</size>
|
||||
</title>
|
||||
<last_modified_by>
|
||||
<column>modified_by</column>
|
||||
</last_modified_by>
|
||||
<last_modified>
|
||||
<column>modified</column>
|
||||
</last_modified>
|
||||
<published>
|
||||
<column>published</column>
|
||||
<type>int</type>
|
||||
<size>6</size>
|
||||
</published>
|
||||
</reference>
|
||||
<filters>
|
||||
<filter>
|
||||
<type>k2languagecategory</type>
|
||||
<id>filter_category</id>
|
||||
<table>#__k2_categories</table>
|
||||
<column>catid</column>
|
||||
<default>0</default>
|
||||
<addfieldpath>/plugins/josetta_ext/k2item/fields</addfieldpath>
|
||||
</filter>
|
||||
</filters>
|
||||
<reference_filters>
|
||||
<reference_filter>
|
||||
<table>#__k2_items</table>
|
||||
<column>trash</column>
|
||||
<value>0</value>
|
||||
</reference_filter>
|
||||
</reference_filters>
|
||||
</josetta>
|
1
plugins/josetta_ext/k2item/fields/index.html
Normal file
1
plugins/josetta_ext/k2item/fields/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
80
plugins/josetta_ext/k2item/fields/k2extrafields.js
Normal file
80
plugins/josetta_ext/k2item/fields/k2extrafields.js
Normal file
@ -0,0 +1,80 @@
|
||||
/**
|
||||
* @version $Id: k2extrafields.js 1812 2013-01-14 18:45:06Z lefteris.kavadas $
|
||||
* @package K2
|
||||
* @author JoomlaWorks http://www.joomlaworks.net
|
||||
* @copyright Copyright (c) 2006 - 2013 JoomlaWorks Ltd. All rights reserved.
|
||||
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
|
||||
*/
|
||||
|
||||
$K2(document).ready(function() {
|
||||
extraFields();
|
||||
setTimeout(function() {
|
||||
initExtraFieldsEditor();
|
||||
}, 1000);
|
||||
|
||||
$K2('[id$=josetta_form_catid]').change(function() {
|
||||
if ($K2(this).find('option:selected').attr('disabled')) {
|
||||
alert(K2Language[4]);
|
||||
$K2(this).val('0');
|
||||
return;
|
||||
}
|
||||
extraFields();
|
||||
});
|
||||
});
|
||||
|
||||
function extraFields() {
|
||||
var selectedValue = $K2('[id$=josetta_form_catid]').val();
|
||||
var url = K2BasePath + '/index.php?option=com_k2&view=item&task=extraFields&cid=' + selectedValue + '&id=' + Josetta.josettaItemid;
|
||||
$K2('#extraFieldsContainer').fadeOut('slow', function() {
|
||||
$K2.ajax({
|
||||
url : url,
|
||||
type : 'get',
|
||||
success : function(response) {
|
||||
$K2('#extraFieldsContainer').html(response);
|
||||
initExtraFieldsEditor();
|
||||
$K2('img.calendar').each(function() {
|
||||
inputFieldID = $K2(this).prev().attr('id');
|
||||
imgFieldID = $K2(this).attr('id');
|
||||
Calendar.setup({
|
||||
inputField : inputFieldID,
|
||||
ifFormat : "%Y-%m-%d",
|
||||
button : imgFieldID,
|
||||
align : "Tl",
|
||||
singleClick : true
|
||||
});
|
||||
});
|
||||
$K2('#extraFieldsContainer').fadeIn('slow');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function initExtraFieldsEditor() {
|
||||
$K2('.k2ExtraFieldEditor').each(function() {
|
||||
var id = $K2(this).attr('id');
|
||||
if ( typeof tinymce != 'undefined') {
|
||||
if (tinyMCE.get(id)) {
|
||||
tinymce.EditorManager.remove(tinyMCE.get(id));
|
||||
}
|
||||
tinyMCE.execCommand('mceAddControl', false, id);
|
||||
} else {
|
||||
new nicEditor({
|
||||
fullPanel : true,
|
||||
maxHeight : 180,
|
||||
iconsPath : K2BasePath + '/media/k2/assets/images/system/nicEditorIcons.gif'
|
||||
}).panelInstance($K2(this).attr('id'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function syncExtraFieldsEditor() {
|
||||
$K2('.k2ExtraFieldEditor').each(function() {
|
||||
editor = nicEditors.findEditor($K2(this).attr('id'));
|
||||
if ( typeof editor != 'undefined') {
|
||||
if (editor.content == '<br>' || editor.content == '<br />') {
|
||||
editor.setContent('');
|
||||
}
|
||||
editor.saveContent();
|
||||
}
|
||||
});
|
||||
}
|
49
plugins/josetta_ext/k2item/fields/k2extrafields.php
Normal file
49
plugins/josetta_ext/k2item/fields/k2extrafields.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* @version $Id: k2extrafields.php 1812 2013-01-14 18:45:06Z lefteris.kavadas $
|
||||
* @package K2
|
||||
* @author JoomlaWorks http://www.joomlaworks.net
|
||||
* @copyright Copyright (c) 2006 - 2013 JoomlaWorks Ltd. All rights reserved.
|
||||
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die ;
|
||||
|
||||
class JFormFieldK2ExtraFields extends JFormField
|
||||
{
|
||||
|
||||
protected $type = 'K2ExtraFields';
|
||||
|
||||
protected function getInput()
|
||||
{
|
||||
$document = JFactory::getDocument();
|
||||
$document->addScriptDeclaration('var K2BasePath = "'.JURI::root(true).'";');
|
||||
$document->addScript(JURI::root(true).'/plugins/josetta_ext/k2item/fields/k2extrafields.js');
|
||||
|
||||
K2Model::addIncludePath(JPATH_SITE.'/components/com_k2/models');
|
||||
JLoader::register('K2HelperUtilities', JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'helpers'.DS.'utilities.php');
|
||||
$model = K2Model::getInstance('Item', 'K2Model');
|
||||
$extraFields = $model->getItemExtraFields($this->value);
|
||||
$html = '<div id="extraFieldsContainer">';
|
||||
if (count($extraFields))
|
||||
{
|
||||
$html .= '<table class="admintable" id="extraFields">';
|
||||
foreach ($extraFields as $extraField)
|
||||
{
|
||||
$html .= '<tr>
|
||||
<td align="right" class="key">'.$extraField->name.'</td>
|
||||
<td>'.$extraField->element.'</td>
|
||||
</tr>';
|
||||
}
|
||||
$html .= '</table>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$html .= '<span class="k2Note"> '.JText::_('K2_PLEASE_SELECT_A_CATEGORY_FIRST_TO_RETRIEVE_ITS_RELATED_EXTRA_FIELDS').' </span>';
|
||||
}
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
}
|
75
plugins/josetta_ext/k2item/fields/k2languagecategory.php
Normal file
75
plugins/josetta_ext/k2item/fields/k2languagecategory.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* @version $Id: k2languagecategory.php 1812 2013-01-14 18:45:06Z lefteris.kavadas $
|
||||
* @package K2
|
||||
* @author JoomlaWorks http://www.joomlaworks.net
|
||||
* @copyright Copyright (c) 2006 - 2013 JoomlaWorks Ltd. All rights reserved.
|
||||
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die ;
|
||||
|
||||
JFormHelper::loadFieldClass('list');
|
||||
JFormHelper::loadFieldClass('category');
|
||||
|
||||
class JFormFieldK2LanguageCategory extends JFormFieldCategory
|
||||
{
|
||||
|
||||
public $type = 'K2LanguageCategory';
|
||||
|
||||
public function __get($name)
|
||||
{
|
||||
|
||||
switch ($name)
|
||||
{
|
||||
case 'element' :
|
||||
return $this->$name;
|
||||
break;
|
||||
}
|
||||
|
||||
$value = parent::__get($name);
|
||||
return $value;
|
||||
}
|
||||
|
||||
protected function getOptions()
|
||||
{
|
||||
|
||||
// Initialise variables.
|
||||
$options = array();
|
||||
$published = (string)$this->element['published'];
|
||||
$languages = (string)$this->element['languages'];
|
||||
$name = (string)$this->element['name'];
|
||||
|
||||
// insert custom options passed in xml file
|
||||
$options = array();
|
||||
if (!is_null($this->element->option))
|
||||
{
|
||||
foreach ($this->element->option as $option)
|
||||
{
|
||||
$options[] = JHtml::_('select.option', $option->getAttribute('value'), JText::_($option->data()));
|
||||
}
|
||||
}
|
||||
|
||||
// Filter over published state or not depending upon if it is present.
|
||||
// include k2item helper, which has the method we want
|
||||
require_once JPATH_PLUGINS.'/josetta_ext/k2item/helpers/helper.php';
|
||||
if ($published)
|
||||
{
|
||||
$categoriesoptions = JosettaK2ItemHelper::getCategoryOptionsPerLanguage(array('filter.published' => explode(',', $published), 'filter.languages' => explode(',', $languages)));
|
||||
}
|
||||
else
|
||||
{
|
||||
$categoriesoptions = JosettaK2ItemHelper::getCategoryOptionsPerLanguage(array('filter.languages' => explode(',', $languages)));
|
||||
}
|
||||
|
||||
$options = array_merge($options, $categoriesoptions);
|
||||
|
||||
if (!empty($this->element['show_root']) && strtolower($this->element['show_root']) == 'yes')
|
||||
{
|
||||
array_unshift($options, JHtml::_('select.option', '0', JText::_('JGLOBAL_ROOT')));
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
}
|
124
plugins/josetta_ext/k2item/fields/k2tags.css
Normal file
124
plugins/josetta_ext/k2item/fields/k2tags.css
Normal file
@ -0,0 +1,124 @@
|
||||
/**
|
||||
* @version $Id: k2tags.css 1812 2013-01-14 18:45:06Z lefteris.kavadas $
|
||||
* @package K2
|
||||
* @author JoomlaWorks http://www.joomlaworks.net
|
||||
* @copyright Copyright (c) 2006 - 2013 JoomlaWorks Ltd. All rights reserved.
|
||||
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
|
||||
*/
|
||||
|
||||
.ui-autocomplete {
|
||||
position: absolute;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
border: 1px solid #eee;
|
||||
background-color: white;
|
||||
border-right-color: #ddd;
|
||||
border-bottom-color: #ddd;
|
||||
text-align: left;sans-serif;
|
||||
z-index: 50;
|
||||
}
|
||||
* html .ui-autocomplete {
|
||||
width: 1px;
|
||||
}/* without this, the menu expands to 100% in IE6 */
|
||||
.ui-menu {
|
||||
list-style: none;
|
||||
padding: 2px;
|
||||
margin: 0;
|
||||
margin-top: -3px;
|
||||
display: block;
|
||||
float: left;
|
||||
}
|
||||
.ui-menu .ui-menu-item {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
zoom: 0;
|
||||
float: left;
|
||||
clear: left;
|
||||
width: 99%;
|
||||
}
|
||||
.ui-menu .ui-menu-item a {
|
||||
text-decoration: none;
|
||||
display: block;
|
||||
padding: .2em .4em;
|
||||
line-height: 1.5;
|
||||
zoom: 1;
|
||||
font-weight: bold;
|
||||
}
|
||||
.ui-menu .ui-menu-item a.ui-state-hover, .ui-menu .ui-menu-item a.ui-state-active {
|
||||
margin: -1px;
|
||||
background-color: #444;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
ul.tags {
|
||||
background: #fff;
|
||||
border: 1px solid #c0c0c0;
|
||||
padding: 0;
|
||||
cursor: default;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: 99%;
|
||||
}
|
||||
ul.tags li {
|
||||
-moz-border-radius: 4px;
|
||||
-webkit-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
background: #cfe4fa;
|
||||
color: #222;
|
||||
border: 1px solid #b0d2f9;
|
||||
padding: 2px 4px 4px;
|
||||
list-style: none;
|
||||
float: left;
|
||||
clear: none;
|
||||
height: 18px;
|
||||
margin: 2px 1px 1px;
|
||||
}
|
||||
ul.tags li span.tagRemove {
|
||||
color: #5279a1;
|
||||
padding-left: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
ul.tags li span.tagRemove:hover {
|
||||
color: #505050;
|
||||
cursor: pointer;
|
||||
}
|
||||
ul.tags li input {
|
||||
border: none;
|
||||
padding-top: 2px;
|
||||
background: none;
|
||||
float: left;
|
||||
clear: none;
|
||||
margin:0;
|
||||
padding:0;
|
||||
height:18px;
|
||||
}
|
||||
ul.tags li input:focus {
|
||||
background: none;
|
||||
}
|
||||
ul.tags li input.tagsLoading {
|
||||
background: url(../../../../media/k2/assets/images/system/loader.gif) no-repeat 50% 50%;
|
||||
}
|
||||
ul.tags li.clr {
|
||||
clear: both;
|
||||
height: 0;
|
||||
line-height: 0;
|
||||
border: none;
|
||||
float: none;
|
||||
background: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
ul.tags li.tagAdd {
|
||||
border-color: #fff;
|
||||
background: none;
|
||||
}
|
||||
ul.tags li.tagAdd input {
|
||||
border: none;
|
||||
}
|
||||
span.k2Note {
|
||||
display: block;
|
||||
padding: 4px 0 0 0;
|
||||
font-style: italic;
|
||||
color: #777;
|
||||
}
|
80
plugins/josetta_ext/k2item/fields/k2tags.js
Normal file
80
plugins/josetta_ext/k2item/fields/k2tags.js
Normal file
@ -0,0 +1,80 @@
|
||||
/**
|
||||
* @version $Id: k2tags.js 1919 2013-02-11 19:02:02Z joomlaworks $
|
||||
* @package K2
|
||||
* @author JoomlaWorks http://www.joomlaworks.net
|
||||
* @copyright Copyright (c) 2006 - 2013 JoomlaWorks Ltd. All rights reserved.
|
||||
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
|
||||
*/
|
||||
|
||||
$K2(document).ready(function() {
|
||||
|
||||
// Generic function to get URL params passed in .js script include
|
||||
function getUrlParams(targetScript, varName) {
|
||||
var scripts = document.getElementsByTagName('script');
|
||||
var scriptCount = scripts.length;
|
||||
for (var a = 0; a < scriptCount; a++) {
|
||||
var scriptSrc = scripts[a].src;
|
||||
if (scriptSrc.indexOf(targetScript) >= 0) {
|
||||
varName = varName.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
|
||||
var re = new RegExp("[\\?&]" + varName + "=([^&#]*)");
|
||||
var parsedVariables = re.exec(scriptSrc);
|
||||
if (parsedVariables !== null) {
|
||||
return parsedVariables[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set the site root path
|
||||
var K2SitePath = getUrlParams('k2.js', 'sitepath');
|
||||
|
||||
$K2('.tagRemove').click(function(event) {
|
||||
event.preventDefault();
|
||||
$K2(this).parent().remove();
|
||||
});
|
||||
|
||||
/*
|
||||
$K2('ul.tags').click(function() {
|
||||
//$K2('#search-field').focus();
|
||||
});
|
||||
*/
|
||||
|
||||
$K2('.k2-search-field').keypress(function(event) {
|
||||
if (event.which == '13') {
|
||||
if ($K2(this).val() != '') {
|
||||
$K2('<li id="' + this.attributes['rel'].value + '_tagAdd" class="addedTag">' + $K2(this).val() + '<span class="tagRemove" onclick="Josetta.itemChanged('+this.id+');$K2(this).parent().remove();">x</span><input type="hidden" value="' + $K2(this).val() + '" name="'+this.attributes['rel'].value + '[tags][]"></li>').insertBefore('.tags #' + this.attributes['rel'].value + '_tagAdd.tagAdd');
|
||||
Josetta.itemChanged(this);
|
||||
$K2(this).val('');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$K2('.k2-search-field').autocomplete({
|
||||
source : function(request, response) {
|
||||
var target = this.element[0];
|
||||
$K2.ajax({
|
||||
type : 'post',
|
||||
url : K2SitePath + 'index.php?option=com_k2&view=item&task=tags',
|
||||
data : 'q=' + request.term,
|
||||
dataType : 'json',
|
||||
success : function(data) {
|
||||
target.removeClass('tagsLoading');
|
||||
response($K2.map(data, function(item) {
|
||||
return item;
|
||||
}));
|
||||
}
|
||||
});
|
||||
},
|
||||
minLength : 3,
|
||||
select : function(event, ui) {
|
||||
$K2('<li id="' + this.attributes['rel'].value + '_tagAdd" class="addedTag">' + ui.item.label + '<span class="tagRemove" onclick="Josetta.itemChanged('+this.id+');$K2(this).parent().remove();">x</span><input type="hidden" value="' + ui.item.value + '" name="'+this.attributes['rel'].value + '[tags][]"></li>').insertBefore('.tags #' + this.attributes['rel'].value + '_tagAdd.tagAdd');
|
||||
Josetta.itemChanged(this);
|
||||
this.value = '';
|
||||
return false;
|
||||
},
|
||||
search : function(event, ui) {
|
||||
event.target.addClass('tagsLoading');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
42
plugins/josetta_ext/k2item/fields/k2tags.php
Normal file
42
plugins/josetta_ext/k2item/fields/k2tags.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @version $Id: k2tags.php 1978 2013-05-15 19:34:16Z joomlaworks $
|
||||
* @package K2
|
||||
* @author JoomlaWorks http://www.joomlaworks.net
|
||||
* @copyright Copyright (c) 2006 - 2013 JoomlaWorks Ltd. All rights reserved.
|
||||
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die ;
|
||||
|
||||
class JFormFieldK2Tags extends JFormField
|
||||
{
|
||||
|
||||
protected $type = 'K2Tags';
|
||||
|
||||
protected function getInput()
|
||||
{
|
||||
$document = JFactory::getDocument();
|
||||
$document->addStyleSheet(JURI::root(true).'/plugins/josetta_ext/k2item/fields/k2tags.css?v=2.6.7');
|
||||
$document->addScript('//ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js');
|
||||
$document->addScript(JURI::root(true).'/plugins/josetta_ext/k2item/fields/k2tags.js?v=2.6.7&sitepath='.JURI::root(true).'/');
|
||||
|
||||
$html = '<ul class="tags">';
|
||||
$tags = explode(',', $this->value);
|
||||
if (count($tags))
|
||||
{
|
||||
foreach ($tags as $tag)
|
||||
{
|
||||
$tag = JString::trim($tag);
|
||||
$html .= '<li id="'.$this->formControl.'_tagAdd" class="tagAdded">'.$tag.'<span title="'.JText::_('K2_CLICK_TO_REMOVE_TAG').'" onclick="Josetta.itemChanged(\'' . $this->id . '\');" class="tagRemove">x</span><input type="hidden" name="'.$this->name.'[]" value="'.$tag.'" /></li>';
|
||||
}
|
||||
|
||||
}
|
||||
$html .= '<li id="'.$this->formControl.'_tagAdd" class="tagAdd"><input type="text" id="' . $this->id . '" rel="' . $this->formControl . '" class="k2-search-field" /></li>
|
||||
<li class="clr"></li>
|
||||
</ul>
|
||||
<span class="k2Note"> '.JText::_('K2_WRITE_A_TAG_AND_PRESS_RETURN_OR_COMMA_TO_ADD_IT').' </span>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
}
|
170
plugins/josetta_ext/k2item/fields_common.xml
Normal file
170
plugins/josetta_ext/k2item/fields_common.xml
Normal file
@ -0,0 +1,170 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<josetta>
|
||||
<fields>
|
||||
<field>
|
||||
<id>title</id>
|
||||
<name>K2_TITLE</name>
|
||||
<description></description>
|
||||
<column>title</column>
|
||||
<type>josettatext</type>
|
||||
<size>60</size>
|
||||
<length>255</length>
|
||||
<translate>yes</translate>
|
||||
<display>yes</display>
|
||||
<require>yes</require>
|
||||
</field>
|
||||
<field>
|
||||
<id>alias</id>
|
||||
<name>K2_TITLE_ALIAS</name>
|
||||
<description></description>
|
||||
<column>alias</column>
|
||||
<type>josettatext</type>
|
||||
<size>60</size>
|
||||
<length>255</length>
|
||||
<translate>yes</translate>
|
||||
<display>yes</display>
|
||||
</field>
|
||||
<field>
|
||||
<id>catid</id>
|
||||
<name>K2_CATEGORY</name>
|
||||
<description></description>
|
||||
<column>catid</column>
|
||||
<type>k2languagecategory</type>
|
||||
<addfieldpath>/plugins/josetta_ext/k2item/fields</addfieldpath>
|
||||
<size>0</size>
|
||||
<length>0</length>
|
||||
<translate>yes</translate>
|
||||
<display>yes</display>
|
||||
<require>yes</require>
|
||||
<show_root>no</show_root>
|
||||
</field>
|
||||
<field>
|
||||
<id>articletext</id>
|
||||
<name>K2_TEXT</name>
|
||||
<description></description>
|
||||
<column>articletext</column>
|
||||
<type>editor</type>
|
||||
<filter>JComponentHelper::filterText</filter>
|
||||
<size>0</size>
|
||||
<length>0</length>
|
||||
<translate>yes</translate>
|
||||
<display>yes</display>
|
||||
<require>no</require>
|
||||
</field>
|
||||
<field>
|
||||
<id>tags</id>
|
||||
<name>K2_TAGS</name>
|
||||
<description></description>
|
||||
<column>tags</column>
|
||||
<type>k2tags</type>
|
||||
<addfieldpath>/plugins/josetta_ext/k2item/fields</addfieldpath>
|
||||
<size>0</size>
|
||||
<length>0</length>
|
||||
<translate>yes</translate>
|
||||
<display>yes</display>
|
||||
<require>no</require>
|
||||
</field>
|
||||
<field>
|
||||
<id>extra_fields</id>
|
||||
<name>K2_EXTRA_FIELDS</name>
|
||||
<description></description>
|
||||
<column>extra_fields</column>
|
||||
<type>k2extrafields</type>
|
||||
<addfieldpath>/plugins/josetta_ext/k2item/fields</addfieldpath>
|
||||
<size>0</size>
|
||||
<length>0</length>
|
||||
<translate>yes</translate>
|
||||
<display>yes</display>
|
||||
<require>no</require>
|
||||
</field>
|
||||
<field>
|
||||
<id>created_by_alias</id>
|
||||
<name>K2_AUTHOR_ALIAS</name>
|
||||
<description></description>
|
||||
<column>created_by_alias</column>
|
||||
<type>josettatext</type>
|
||||
<size>60</size>
|
||||
<length>255</length>
|
||||
<translate>yes</translate>
|
||||
<display>yes</display>
|
||||
</field>
|
||||
<field>
|
||||
<id>metadesc</id>
|
||||
<name>K2_DESCRIPTION</name>
|
||||
<description></description>
|
||||
<column>metadesc</column>
|
||||
<type>textarea</type>
|
||||
<size>0</size>
|
||||
<length>0</length>
|
||||
<translate>yes</translate>
|
||||
<display>yes</display>
|
||||
</field>
|
||||
<field>
|
||||
<id>metakey</id>
|
||||
<name>K2_KEYWORDS</name>
|
||||
<description></description>
|
||||
<column>metakey</column>
|
||||
<type>textarea</type>
|
||||
<size>0</size>
|
||||
<length>0</length>
|
||||
<translate>yes</translate>
|
||||
<display>yes</display>
|
||||
</field>
|
||||
<field>
|
||||
<id>language</id>
|
||||
<name>COM_JOSETTA_COM_CONTENT_LANGUAGE</name>
|
||||
<column>language</column>
|
||||
<type>language</type>
|
||||
<size>0</size>
|
||||
<length>0</length>
|
||||
<translate>no</translate>
|
||||
<display>no</display>
|
||||
<require>no</require>
|
||||
<grid>yes</grid>
|
||||
</field>
|
||||
<field>
|
||||
<id>access</id>
|
||||
<name>access</name>
|
||||
<column>access</column>
|
||||
<translate>no</translate>
|
||||
<display>no</display>
|
||||
<require>no</require>
|
||||
<grid>no</grid>
|
||||
</field>
|
||||
<field>
|
||||
<id>metadata</id>
|
||||
<name>metadata</name>
|
||||
<column>metadata</column>
|
||||
<translate>no</translate>
|
||||
<display>no</display>
|
||||
<require>no</require>
|
||||
<grid>no</grid>
|
||||
</field>
|
||||
<field>
|
||||
<id>featured</id>
|
||||
<name>featured</name>
|
||||
<column>featured</column>
|
||||
<translate>no</translate>
|
||||
<display>no</display>
|
||||
<require>no</require>
|
||||
<grid>no</grid>
|
||||
</field>
|
||||
<field>
|
||||
<id>attribs</id>
|
||||
<name>attribs</name>
|
||||
<column>params</column>
|
||||
<translate>no</translate>
|
||||
<display>no</display>
|
||||
<require>no</require>
|
||||
</field>
|
||||
<field>
|
||||
<id>xreference</id>
|
||||
<name>xreference</name>
|
||||
<column>xreference</column>
|
||||
<translate>no</translate>
|
||||
<display>no</display>
|
||||
<require>no</require>
|
||||
<grid>no</grid>
|
||||
</field>
|
||||
</fields>
|
||||
</josetta>
|
108
plugins/josetta_ext/k2item/helpers/helper.php
Normal file
108
plugins/josetta_ext/k2item/helpers/helper.php
Normal file
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
* @version $Id: helper.php 1812 2013-01-14 18:45:06Z lefteris.kavadas $
|
||||
* @package K2
|
||||
* @author JoomlaWorks http://www.joomlaworks.net
|
||||
* @copyright Copyright (c) 2006 - 2013 JoomlaWorks Ltd. All rights reserved.
|
||||
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die ;
|
||||
|
||||
abstract class JosettaK2ItemHelper
|
||||
{
|
||||
|
||||
protected static $_categoriesOptionsPerLanguage = array();
|
||||
protected static $_categoriesDataPerLanguage = array();
|
||||
|
||||
public static function getCategoryOptionsPerLanguage($config = array('filter.published' => array(0, 1), 'filter.languages' => array()))
|
||||
{
|
||||
|
||||
$hash = md5(serialize($config));
|
||||
|
||||
if (!isset(self::$_categoriesOptionsPerLanguage[$hash]))
|
||||
{
|
||||
|
||||
$config = (array)$config;
|
||||
|
||||
// read categories from db
|
||||
$items = self::getCategoriesPerLanguage($config);
|
||||
|
||||
// B/C compat.
|
||||
foreach ($items as &$item)
|
||||
{
|
||||
$item->title = $item->name;
|
||||
$item->parent_id = $item->parent;
|
||||
}
|
||||
|
||||
// indent cat list, for easier reading
|
||||
$items = self::indentCategories($items);
|
||||
|
||||
self::$_categoriesOptionsPerLanguage[$hash] = array();
|
||||
foreach ($items as &$item)
|
||||
{
|
||||
self::$_categoriesOptionsPerLanguage[$hash][] = JHtml::_('select.option', $item->id, JString::str_ireplace('<sup>|_</sup>', '', $item->treename));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return self::$_categoriesOptionsPerLanguage[$hash];
|
||||
}
|
||||
|
||||
public static function getCategoriesPerLanguage($config = array('filter.published' => array(0, 1), 'filter.languages' => array()), $index = null)
|
||||
{
|
||||
|
||||
$hash = md5(serialize($config));
|
||||
|
||||
if (!isset(self::$_categoriesDataPerLanguage[$hash]))
|
||||
{
|
||||
$config = (array)$config;
|
||||
$db = JFactory::getDbo();
|
||||
|
||||
$query = "SELECT c.*, g.title AS groupname, exfg.name as extra_fields_group FROM #__k2_categories as c LEFT JOIN #__viewlevels AS g ON g.id = c.access"." LEFT JOIN #__k2_extra_fields_groups AS exfg ON exfg.id = c.extraFieldsGroup WHERE c.id>0";
|
||||
|
||||
if (!empty($config['filter.published']))
|
||||
{
|
||||
$query .= ' and c.published in ('.ShlDbHelper::arrayToIntvalList($config['filter.published']).')';
|
||||
}
|
||||
if (!empty($config['filter.languages']))
|
||||
{
|
||||
$query .= ' and c.language in ('.ShlDbHelper::arrayToQuotedList($config['filter.languages']).')';
|
||||
}
|
||||
|
||||
$db->setQuery($query);
|
||||
$items = $db->loadObjectList($index);
|
||||
|
||||
foreach ($items as &$item)
|
||||
{
|
||||
$item->title = $item->name;
|
||||
$item->parent_id = $item->parent;
|
||||
}
|
||||
|
||||
self::$_categoriesDataPerLanguage[$hash] = $items;
|
||||
}
|
||||
|
||||
return self::$_categoriesDataPerLanguage[$hash];
|
||||
}
|
||||
|
||||
public static function indentCategories(&$rows, $root = 0)
|
||||
{
|
||||
|
||||
$children = array();
|
||||
if (count($rows))
|
||||
{
|
||||
foreach ($rows as $v)
|
||||
{
|
||||
$pt = $v->parent;
|
||||
$list = @$children[$pt] ? $children[$pt] : array();
|
||||
array_push($list, $v);
|
||||
$children[$pt] = $list;
|
||||
}
|
||||
}
|
||||
|
||||
$categories = JHTML::_('menu.treerecurse', $root, '', array(), $children);
|
||||
|
||||
return $categories;
|
||||
}
|
||||
|
||||
}
|
1
plugins/josetta_ext/k2item/helpers/index.html
Normal file
1
plugins/josetta_ext/k2item/helpers/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
123
plugins/josetta_ext/k2item/k2item.php
Normal file
123
plugins/josetta_ext/k2item/k2item.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* @version $Id: k2item.php 1812 2013-01-14 18:45:06Z lefteris.kavadas $
|
||||
* @package K2
|
||||
* @author JoomlaWorks http://www.joomlaworks.net
|
||||
* @copyright Copyright (c) 2006 - 2013 JoomlaWorks Ltd. All rights reserved.
|
||||
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
// include K2Base Josetta plugin, which shares many methods and thus is used as a base class
|
||||
require_once JPATH_PLUGINS . '/josetta_ext/k2item/classes/basek2plugin.php';
|
||||
|
||||
class plgJosetta_extK2item extends plgJosetta_extBaseK2Plugin
|
||||
{
|
||||
|
||||
protected $_context = 'com_k2_item';
|
||||
protected $_defaultTable = 'K2Item';
|
||||
|
||||
public function onJosettaGetTypes()
|
||||
{
|
||||
$this->loadLanguages();
|
||||
$item = array(self::$this->_context => 'K2 ' . JText::_('K2_ITEMS'));
|
||||
$items[] = $item;
|
||||
return $items;
|
||||
}
|
||||
|
||||
public function onJosettaLoadItem($context, $id = '')
|
||||
{
|
||||
|
||||
if ((!empty($context) && ($context != $this->_context)) || (empty($id)))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
$item = parent::onJosettaLoadItem($context, $id);
|
||||
|
||||
// Merge introtext and fulltext
|
||||
$item->articletext = trim($item->fulltext) != '' ? $item->introtext . "<hr id=\"system-readmore\" />" . $item->fulltext : $item->introtext;
|
||||
|
||||
// Get tags
|
||||
K2Model::addIncludePath(JPATH_SITE . '/components/com_k2/models');
|
||||
JLoader::register('K2HelperUtilities', JPATH_SITE . '/components/com_k2/helpers/utilities.php');
|
||||
$model = K2Model::getInstance('Item', 'K2Model');
|
||||
$tags = $model->getItemTags($item->id);
|
||||
$tmp = array();
|
||||
foreach ($tags as $tag)
|
||||
{
|
||||
$tmp[] = $tag->name;
|
||||
}
|
||||
$item->tags = implode(', ', $tmp);
|
||||
|
||||
// Get extra fields
|
||||
$extraFields = $model->getItemExtraFields($item->extra_fields);
|
||||
$html = '';
|
||||
if (count($extraFields))
|
||||
{
|
||||
$html .= '<ul>';
|
||||
foreach ($extraFields as $key => $extraField)
|
||||
{
|
||||
$html .= '<li class="type' . ucfirst($extraField->type) . ' group' . $extraField->group
|
||||
. '">
|
||||
<span class="itemExtraFieldsLabel">' . $extraField->name . ':</span>
|
||||
<span class="itemExtraFieldsValue">' . $extraField->value . '</span>
|
||||
</li>';
|
||||
}
|
||||
$html .= '</ul>';
|
||||
}
|
||||
$item->extra_fields = $html;
|
||||
|
||||
// Return the item
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save an item after it has been translated
|
||||
* This will be called by Josetta when a user clicks
|
||||
* the Save button. The context is passed so
|
||||
* that each plugin knows if it must process the data or not
|
||||
*
|
||||
* if $item->reference_id is empty, this is
|
||||
* a new item, otherwise we are updating the item
|
||||
*
|
||||
* $item->data contains the fields entered by the user
|
||||
* that needs to be saved
|
||||
*
|
||||
*@param context type
|
||||
*@param data in form of array
|
||||
*
|
||||
*return table id if data is inserted
|
||||
*
|
||||
*return false if error occurs
|
||||
*
|
||||
*/
|
||||
|
||||
public function onJosettaSaveItem($context, $item, &$errors)
|
||||
{
|
||||
|
||||
if (($context != $this->_context))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// load languages for form and error messages
|
||||
$this->loadLanguages();
|
||||
|
||||
require_once JPATH_PLUGINS . '/josetta_ext/k2item/models/item.php';
|
||||
$k2ItemModel = new JosettaK2ModelItem();
|
||||
|
||||
$savedItemId = $k2ItemModel->save($item);
|
||||
|
||||
if (empty($savedItemId))
|
||||
{
|
||||
// make sure errors are displayed
|
||||
JosettaHelper::enqueueMessages($k2ItemModel->getErrors());
|
||||
return false;
|
||||
}
|
||||
|
||||
return $savedItemId;
|
||||
|
||||
}
|
||||
|
||||
}
|
21
plugins/josetta_ext/k2item/k2item.xml
Normal file
21
plugins/josetta_ext/k2item/k2item.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<extension version="2.5" type="plugin" group="josetta_ext" method="upgrade">
|
||||
<name>Josetta - K2 Items</name>
|
||||
<author>JoomlaWorks</author>
|
||||
<creationDate>June 7th, 2012</creationDate>
|
||||
<copyright>Copyright (c) 2006 - 2013 JoomlaWorks Ltd. All rights reserved.</copyright>
|
||||
<authorEmail>please-use-the-contact-form@joomlaworks.net</authorEmail>
|
||||
<authorUrl>www.joomlaworks.net</authorUrl>
|
||||
<version>2.6.7</version>
|
||||
<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
|
||||
<description></description>
|
||||
<files>
|
||||
<filename plugin="k2item">k2item.php</filename>
|
||||
<filename>definitions.xml</filename>
|
||||
<filename>fields_common.xml</filename>
|
||||
<folder>classes</folder>
|
||||
<folder>fields</folder>
|
||||
<folder>helpers</folder>
|
||||
<folder>models</folder>
|
||||
</files>
|
||||
</extension>
|
1
plugins/josetta_ext/k2item/models/index.html
Normal file
1
plugins/josetta_ext/k2item/models/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
360
plugins/josetta_ext/k2item/models/item.php
Normal file
360
plugins/josetta_ext/k2item/models/item.php
Normal file
@ -0,0 +1,360 @@
|
||||
<?php
|
||||
/**
|
||||
* @version $Id: item.php 1812 2013-01-14 18:45:06Z lefteris.kavadas $
|
||||
* @package K2
|
||||
* @author JoomlaWorks http://www.joomlaworks.net
|
||||
* @copyright Copyright (c) 2006 - 2013 JoomlaWorks Ltd. All rights reserved.
|
||||
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die ;
|
||||
|
||||
jimport('joomla.application.component.model');
|
||||
|
||||
JTable::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_k2/tables');
|
||||
|
||||
class JosettaK2ModelItem extends JModel
|
||||
{
|
||||
|
||||
public function save($item, $front = false)
|
||||
{
|
||||
|
||||
jimport('joomla.filesystem.file');
|
||||
jimport('joomla.filesystem.folder');
|
||||
jimport('joomla.filesystem.archive');
|
||||
require_once (JPATH_ADMINISTRATOR.'/components/com_k2/lib/class.upload.php');
|
||||
$db = JFactory::getDBO();
|
||||
$user = JFactory::getUser();
|
||||
$row = JTable::getInstance('K2Item', 'Table');
|
||||
$params = JComponentHelper::getParams('com_k2');
|
||||
$nullDate = $db->getNullDate();
|
||||
|
||||
if (!$row->bind($item))
|
||||
{
|
||||
$this->setError($row->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
$row->catid = (int)$row->catid;
|
||||
|
||||
if ($front && $row->id == NULL)
|
||||
{
|
||||
JLoader::register('K2HelperPermissions', JPATH_SITE.'/components/com_k2/helpers/permissions.php');
|
||||
if (!K2HelperPermissions::canAddItem($row->catid))
|
||||
{
|
||||
$this->setError(JText::_('K2_YOU_ARE_NOT_ALLOWED_TO_POST_TO_THIS_CATEGORY_SAVE_FAILED'));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
($row->id) ? $isNew = false : $isNew = true;
|
||||
|
||||
if ($params->get('xssFiltering'))
|
||||
{
|
||||
$filter = new JFilterInput( array(), array(), 1, 1, 0);
|
||||
$item['articletext'] = $filter->clean($item['articletext']);
|
||||
}
|
||||
$pattern = '#<hr\s+id=("|\')system-readmore("|\')\s*\/*>#i';
|
||||
$tagPos = preg_match($pattern, $item['articletext']);
|
||||
if ($tagPos == 0)
|
||||
{
|
||||
$row->introtext = $item['articletext'];
|
||||
$row->fulltext = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
list($row->introtext, $row->fulltext) = preg_split($pattern, $item['articletext'], 2);
|
||||
}
|
||||
|
||||
if ($row->id)
|
||||
{
|
||||
$datenow = JFactory::getDate();
|
||||
$row->modified = $datenow->toSql();
|
||||
$row->modified_by = $user->get('id');
|
||||
}
|
||||
else
|
||||
{
|
||||
$row->ordering = $row->getNextOrder("catid = {$row->catid} AND trash = 0");
|
||||
if ($row->featured)
|
||||
$row->featured_ordering = $row->getNextOrder("featured = 1 AND trash = 0", 'featured_ordering');
|
||||
}
|
||||
|
||||
$row->created_by = $row->created_by ? $row->created_by : $user->get('id');
|
||||
|
||||
if ($front)
|
||||
{
|
||||
$K2Permissions = K2Permissions::getInstance();
|
||||
if (!$K2Permissions->permissions->get('editAll'))
|
||||
{
|
||||
$row->created_by = $user->get('id');
|
||||
}
|
||||
}
|
||||
|
||||
if ($row->created && strlen(trim($row->created)) <= 10)
|
||||
{
|
||||
$row->created .= ' 00:00:00';
|
||||
}
|
||||
|
||||
$config = JFactory::getConfig();
|
||||
$tzoffset = $config->get('config.offset');
|
||||
$date = JFactory::getDate($row->created, $tzoffset);
|
||||
$row->created = $date->toSql();
|
||||
|
||||
if (strlen(trim($row->publish_up)) <= 10)
|
||||
{
|
||||
$row->publish_up .= ' 00:00:00';
|
||||
}
|
||||
|
||||
$date = JFactory::getDate($row->publish_up, $tzoffset);
|
||||
$row->publish_up = $date->toSql();
|
||||
|
||||
if (trim($row->publish_down) == JText::_('K2_NEVER') || trim($row->publish_down) == '')
|
||||
{
|
||||
$row->publish_down = $nullDate;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strlen(trim($row->publish_down)) <= 10)
|
||||
{
|
||||
$row->publish_down .= ' 00:00:00';
|
||||
}
|
||||
$date = JFactory::getDate($row->publish_down, $tzoffset);
|
||||
$row->publish_down = $date->toSql();
|
||||
}
|
||||
|
||||
if (!$row->check())
|
||||
{
|
||||
$this->setError($row->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
$dispatcher = JDispatcher::getInstance();
|
||||
JPluginHelper::importPlugin('k2');
|
||||
$result = $dispatcher->trigger('onBeforeK2Save', array(&$row, $isNew));
|
||||
if (in_array(false, $result, true))
|
||||
{
|
||||
$this->setError($row->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
//Trigger the finder before save event
|
||||
$dispatcher = JDispatcher::getInstance();
|
||||
JPluginHelper::importPlugin('finder');
|
||||
$results = $dispatcher->trigger('onFinderBeforeSave', array('com_k2.item', $row, $isNew));
|
||||
|
||||
if (!$row->store())
|
||||
{
|
||||
$this->setError($row->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$params->get('disableCompactOrdering'))
|
||||
{
|
||||
$row->reorder("catid = {$row->catid} AND trash = 0");
|
||||
}
|
||||
if ($row->featured && !$params->get('disableCompactOrdering'))
|
||||
{
|
||||
$row->reorder("featured = 1 AND trash = 0", 'featured_ordering');
|
||||
}
|
||||
|
||||
// Image copy
|
||||
$src = md5("Image".$item['ref_id']);
|
||||
$target = md5("Image".$row->id);
|
||||
$sizes = array('XL', 'L', 'M', 'S', 'XS');
|
||||
$savepath = JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache';
|
||||
foreach($sizes as $size)
|
||||
{
|
||||
if(JFile::exists($savepath.DS.$src.'_'.$size.'.jpg') && !JFile::exists($savepath.DS.$target.'_'.$size.'.jpg'))
|
||||
{
|
||||
JFile::copy($savepath.DS.$src.'_'.$size.'.jpg', $savepath.DS.$target.'_'.$size.'.jpg');
|
||||
}
|
||||
}
|
||||
|
||||
//Extra fields
|
||||
$objects = array();
|
||||
$variables = JRequest::get('post', 4);
|
||||
foreach ($variables as $key => $value)
|
||||
{
|
||||
if (( bool )JString::stristr($key, 'K2ExtraField_'))
|
||||
{
|
||||
$object = new JObject;
|
||||
$object->set('id', JString::substr($key, 13));
|
||||
$object->set('value', $value);
|
||||
unset($object->_errors);
|
||||
$objects[] = $object;
|
||||
}
|
||||
}
|
||||
|
||||
$csvFiles = empty($item['files']) ? array() : $item['files'];
|
||||
foreach ($csvFiles as $key => $file)
|
||||
{
|
||||
if (( bool )JString::stristr($key, 'K2ExtraField_'))
|
||||
{
|
||||
$object = new JObject;
|
||||
$object->set('id', JString::substr($key, 13));
|
||||
$csvFile = $file['tmp_name'][0];
|
||||
if (!empty($csvFile) && JFile::getExt($file['name'][0]) == 'csv')
|
||||
{
|
||||
$handle = @fopen($csvFile, 'r');
|
||||
$csvData = array();
|
||||
while (($data = fgetcsv($handle, 1000)) !== FALSE)
|
||||
{
|
||||
$csvData[] = $data;
|
||||
}
|
||||
fclose($handle);
|
||||
$object->set('value', $csvData);
|
||||
}
|
||||
else
|
||||
{
|
||||
require_once (JPATH_ADMINISTRATOR.'/components/com_k2/lib/JSON.php');
|
||||
$json = new Services_JSON;
|
||||
$object->set('value', $json->decode($item['K2CSV_'.$object->id]));
|
||||
if (!empty($item['K2ResetCSV_'.$object->id])) {
|
||||
$object->set('value', null);
|
||||
}
|
||||
}
|
||||
unset($object->_errors);
|
||||
$objects[] = $object;
|
||||
}
|
||||
}
|
||||
|
||||
require_once (JPATH_ADMINISTRATOR.'/components/com_k2/lib/JSON.php');
|
||||
$json = new Services_JSON;
|
||||
$row->extra_fields = $json->encode($objects);
|
||||
|
||||
$row->extra_fields_search = '';
|
||||
|
||||
foreach ($objects as $object)
|
||||
{
|
||||
$row->extra_fields_search .= $this->getSearchValue($object->id, $object->value);
|
||||
$row->extra_fields_search .= ' ';
|
||||
}
|
||||
|
||||
$query = "DELETE FROM #__k2_tags_xref WHERE itemID={intval($row->id)}";
|
||||
$db->setQuery($query);
|
||||
$db->query();
|
||||
|
||||
if (!empty($item['tags']))
|
||||
{
|
||||
$tags = array_unique($item['tags']);
|
||||
foreach ($tags as $tag)
|
||||
{
|
||||
$tag = JString::str_ireplace('-', '', $tag);
|
||||
$query = "SELECT id FROM #__k2_tags WHERE name=".$db->Quote($tag);
|
||||
$db->setQuery($query);
|
||||
$tagID = $db->loadResult();
|
||||
if ($tagID)
|
||||
{
|
||||
$query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {intval($tagID)}, {intval($row->id)})";
|
||||
$db->setQuery($query);
|
||||
$db->query();
|
||||
}
|
||||
else
|
||||
{
|
||||
$K2Tag = JTable::getInstance('K2Tag', 'Table');
|
||||
$K2Tag->name = $tag;
|
||||
$K2Tag->published = 1;
|
||||
$K2Tag->check();
|
||||
$K2Tag->store();
|
||||
$query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {intval($K2Tag->id)}, {intval($row->id)})";
|
||||
$db->setQuery($query);
|
||||
$db->query();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Image
|
||||
if ((int)$params->get('imageMemoryLimit'))
|
||||
{
|
||||
ini_set('memory_limit', (int)$params->get('imageMemoryLimit').'M');
|
||||
}
|
||||
|
||||
if ($front)
|
||||
{
|
||||
if (!K2HelperPermissions::canPublishItem($row->catid) && $row->published)
|
||||
{
|
||||
$row->published = 0;
|
||||
$this->setError(JText::_('K2_YOU_DONT_HAVE_THE_PERMISSION_TO_PUBLISH_ITEMS'));
|
||||
}
|
||||
}
|
||||
|
||||
$query = "UPDATE #__k2_items SET video_caption = ".$db->Quote($row->video_caption).", video_credits = ".$db->Quote($row->video_credits).", ";
|
||||
|
||||
if (!is_null($row->video))
|
||||
{
|
||||
$query .= " video = ".$db->Quote($row->video).", ";
|
||||
}
|
||||
if (!is_null($row->gallery))
|
||||
{
|
||||
$query .= " gallery = ".$db->Quote($row->gallery).", ";
|
||||
}
|
||||
$query .= " extra_fields = ".$db->Quote($row->extra_fields).", extra_fields_search = ".$db->Quote($row->extra_fields_search)." , published = ".$db->Quote($row->published)." WHERE id = ".$row->id;
|
||||
$db->setQuery($query);
|
||||
|
||||
if (!$db->query())
|
||||
{
|
||||
$this->setError($db->getErrorMsg());
|
||||
return false;
|
||||
}
|
||||
|
||||
$row->checkin();
|
||||
|
||||
$cache = JFactory::getCache('com_k2');
|
||||
$cache->clean();
|
||||
|
||||
//$dispatcher->trigger('onAfterK2Save', array(&$row, $isNew));
|
||||
$dispatcher->trigger('onContentAfterSave', array(&$row, $isNew));
|
||||
|
||||
//Trigger the finder after save event
|
||||
$dispatcher = JDispatcher::getInstance();
|
||||
JPluginHelper::importPlugin('finder');
|
||||
$results = $dispatcher->trigger('onFinderAfterSave', array('com_k2.item', $row, $isNew));
|
||||
|
||||
return $row->id;
|
||||
}
|
||||
|
||||
protected function getSearchValue($id, $currentValue)
|
||||
{
|
||||
|
||||
$row = JTable::getInstance('K2ExtraField', 'Table');
|
||||
$row->load($id);
|
||||
|
||||
require_once (JPATH_ADMINISTRATOR.DS.'components'.DS.'com_k2'.DS.'lib'.DS.'JSON.php');
|
||||
$json = new Services_JSON;
|
||||
$jsonObject = $json->decode($row->value);
|
||||
|
||||
$value = '';
|
||||
if ($row->type == 'textfield' || $row->type == 'textarea')
|
||||
{
|
||||
$value = $currentValue;
|
||||
}
|
||||
else if ($row->type == 'multipleSelect')
|
||||
{
|
||||
foreach ($jsonObject as $option)
|
||||
{
|
||||
if (in_array($option->value, $currentValue))
|
||||
$value .= $option->name.' ';
|
||||
}
|
||||
}
|
||||
else if ($row->type == 'link')
|
||||
{
|
||||
$value .= $currentValue[0].' ';
|
||||
$value .= $currentValue[1].' ';
|
||||
}
|
||||
else if ($row->type == 'labels')
|
||||
{
|
||||
$parts = explode(',', $currentValue);
|
||||
$value .= implode(' ', $parts);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($jsonObject as $option)
|
||||
{
|
||||
if ($option->value == $currentValue)
|
||||
$value .= $option->name;
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user