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>
|
Reference in New Issue
Block a user