From 52c983764a2f1e6dd596d439b21292848425b2e9 Mon Sep 17 00:00:00 2001 From: Fotis Evangelou Date: Wed, 14 Mar 2018 12:20:43 +0200 Subject: [PATCH] Assign v2.6.1 and format to PSR-1/2. --- README.md | 20 +- .../language/en-GB/en-GB.plg_jce_links-k2.ini | 10 +- .../en-GB/en-GB.plg_jce_links-k2.sys.ini | 10 +- links-k2.xml | 55 ++- plugins/jce/links-k2/k2links/k2.php | 399 +++++++++--------- plugins/jce/links-k2/k2links/tags.php | 335 +++++++-------- plugins/jce/links-k2/k2links/users.php | 346 +++++++-------- plugins/jce/links-k2/links-k2.php | 198 ++++----- 8 files changed, 663 insertions(+), 710 deletions(-) diff --git a/README.md b/README.md index 867cd06..e5af483 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -K2 Links for JCE -========= +K2 Links for JCE (v2.6.1) +========================= This JCE 2.6.x compatible extension allows you to quickly link any part of your content to K2 items, categories, tags and users, directly from within the WYSIWYG editor window. Once installed, whenever you create a new link using JCE's link options, you'll see available link actions specifically for K2 content. @@ -13,17 +13,17 @@ This is a backend extension so a public demo or showcase is currently not availa This is a JCE extension and the only basic requirements to use it are: - JCE v2.6.x -- K2 v2.6.x or newer (preferrably v2.7.x+) +- K2 v2.7.x or newer - Joomla v3.x -The latest version should work on all Joomla releases from version 2.5 to 3.x. Support for Joomla 1.5 is no longer available. +Support for Joomla 1.5 & 2.5 is no longer available. ### FAQ Q. The search field in the JCE link manager does not return any K2 content A. The search field uses the Joomla K2 Search plugin, the same one used to search the site in the front-end. This must be enabled in JCE Editor Profiles -> Plugin Parameters -> Link, in the Search section (scroll to the bottom of the page). ### LICENSE -This is a Joomla! extension co-developed by JoomlaWorks Ltd. (makers of K2) & Widget Factory Ltd. (makers of JCE) and released under the GNU/GPL v2 license. +This is a Joomla extension co-developed by JoomlaWorks Ltd. (makers of K2) & Widget Factory Ltd. (makers of JCE) and released under the GNU/GPL v2 license. ### ADDITIONAL INFO Some helpful links: @@ -38,14 +38,12 @@ If you want to provide feedback for this JCE extension, you may use the GitHub i - Add a language translation file ## DOWNLOAD -You can grab the latest release here: https://github.com/getk2/k2-links-for-jce/archive/master.zip (v2.6.0) +You can grab the latest release here: https://github.com/getk2/k2-links-for-jce/archive/master.zip (v2.6.1) -## INSTALLATION - -Install using the Joomla Installer! +## INSTALLATION (& UPGRADING) +Install or upgrade using the Joomla Installer. ### OLDER VERSIONS - Version 2.0.1 for JCE 2.5.x is available here - https://github.com/getk2/k2-links-for-jce/archive/2.0.x.zip -**Install using the JCE Installer!** +**(Install using the JCE Installer!)** diff --git a/administrator/language/en-GB/en-GB.plg_jce_links-k2.ini b/administrator/language/en-GB/en-GB.plg_jce_links-k2.ini index 4d198d2..f3fd40b 100644 --- a/administrator/language/en-GB/en-GB.plg_jce_links-k2.ini +++ b/administrator/language/en-GB/en-GB.plg_jce_links-k2.ini @@ -1,2 +1,10 @@ +;/** +; * @version 2.6.1 +; * @package K2 Links for JCE +; * @author JoomlaWorks http://www.joomlaworks.net +; * @copyright Copyright (c) 2006 - 2018 JoomlaWorks Ltd. All rights reserved. +; * @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html +; */ + PLG_JCE_LINKS_K2="K2 Links for JCE" -PLG_JCE_LINKS_K2_XML_DESC="K2 Links plugin for JCE Link" +PLG_JCE_LINKS_K2_XML_DESC="K2 Links plugin for JCE" diff --git a/administrator/language/en-GB/en-GB.plg_jce_links-k2.sys.ini b/administrator/language/en-GB/en-GB.plg_jce_links-k2.sys.ini index 4d198d2..f3fd40b 100644 --- a/administrator/language/en-GB/en-GB.plg_jce_links-k2.sys.ini +++ b/administrator/language/en-GB/en-GB.plg_jce_links-k2.sys.ini @@ -1,2 +1,10 @@ +;/** +; * @version 2.6.1 +; * @package K2 Links for JCE +; * @author JoomlaWorks http://www.joomlaworks.net +; * @copyright Copyright (c) 2006 - 2018 JoomlaWorks Ltd. All rights reserved. +; * @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html +; */ + PLG_JCE_LINKS_K2="K2 Links for JCE" -PLG_JCE_LINKS_K2_XML_DESC="K2 Links plugin for JCE Link" +PLG_JCE_LINKS_K2_XML_DESC="K2 Links plugin for JCE" diff --git a/links-k2.xml b/links-k2.xml index 31eff35..fc1f596 100644 --- a/links-k2.xml +++ b/links-k2.xml @@ -1,31 +1,30 @@ - plg_jce_links_k2 - 2.6.0 - October 2016 - JoomlaWorks - please-use-the-contact-form@joomlaworks.net - www.joomlaworks.net - Copyright (c) 2006 - 2014 JoomlaWorks Ltd. All rights reserved. - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL - K2 Links for JCE 2.6 - - links-k2.php - k2links - - - - - - - - - - - - - - en-GB.plg_jce_links-k2.ini - en-GB.plg_jce_links-k2.sys.ini - + plg_jce_links_k2 + 2.6.1 + March 14th, 2018 + JoomlaWorks + please-use-the-contact-form@joomlaworks.net + www.joomlaworks.net + Copyright (c) 2006 - 2018 JoomlaWorks Ltd. All rights reserved. + http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL + K2 Links for JCE 2.6 + + links-k2.php + k2links + + + + + + + + + + + + + en-GB.plg_jce_links-k2.ini + en-GB.plg_jce_links-k2.sys.ini + diff --git a/plugins/jce/links-k2/k2links/k2.php b/plugins/jce/links-k2/k2links/k2.php index 31e254c..f248ada 100644 --- a/plugins/jce/links-k2/k2links/k2.php +++ b/plugins/jce/links-k2/k2links/k2.php @@ -1,200 +1,199 @@ - $browser =JContentEditor::getInstance(); - * - * @access public - * @return JCE The editor object. - * @since 1.5 - */ - public function getInstance() - { - static $instance; - - if (!is_object($instance)) { - $instance = new K2linksK2(); - } - return $instance; - } - - public function getOption() - { - return $this->_option; - } - - public function getTask() - { - return $this->_task; - } - - public function getList() - { - $advlink = WFEditorPlugin::getInstance(); - $list = ''; - if ($advlink->checkAccess('k2links.k2', '1')) { - $list = '
  • '; - } - return $list; - } - - public static function _getK2Categories($parent_id = 0) - { - // K2 2.x - if (defined('K2_JVERSION')) { - $db = JFactory::getDBO(); - $query = 'SELECT id, name, alias FROM #__k2_categories WHERE published = 1'; - $user = JFactory::getUser(); - if (version_compare(JVERSION, '1.6.0', 'ge')) { - $query .= ' AND `access` IN (' . implode(',', $user->getAuthorisedViewLevels()) . ')'; - } else { - $query .= "\nAND `access` <=" . (int) $user->get('aid'); - } - $query .= ' AND parent = ' . $db->Quote($parent_id) . ' ORDER BY ordering ASC'; - $db->setQuery($query); - $rows = $db->loadObjectList(); - } - // K2 3.x - else { - if ($parent_id == 0) { - $parent_id = 1; - } - $model = K2Model::getInstance('Categories'); - $model->setState('site', true); - $model->setState('parent', $parent_id); - $model->setState('sorting', 'ordering'); - $rows = $model->getRows(); - } - - return $rows; - } - - public static function _getK2Items($category_id = 0) - { - // K2 2.x - if (defined('K2_JVERSION')) { - $db = JFactory::getDBO(); - - $query = 'SELECT id, title, alias, CONCAT(' . $db->quoteName('introtext') . ',' . $db->quoteName('fulltext') . ') AS content FROM #__k2_items WHERE published = 1'; - - $user = JFactory::getUser(); - if (version_compare(JVERSION, '1.6.0', 'ge')) { - $query .= ' AND `access` IN (' . implode(',', $user->getAuthorisedViewLevels()) . ')'; - } else { - $query .= "\nAND `access` <=" . (int) $user->get('aid'); - } - - $query .= ' AND catid = ' . $db->Quote($category_id) . ' ORDER BY ordering ASC'; - - $db->setQuery($query); - $rows = $db->loadObjectList(); - } - // K2 3.x - else { - $model = K2Model::getInstance('Items'); - $model->setState('site', true); - $model->setState('category', (int) $category_id); - $model->setState('recursive', false); - $model->setState('sorting', 'ordering'); - $rows = $model->getRows(); - } - return $rows; - } - - public function getLinks($args) - { - $mainframe = JFactory::getApplication(); - - $advlink = WFEditorPlugin::getInstance(); - if (defined('K2_JVERSION')) { - require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'route.php'; - } - - $items = array(); - $view = isset($args->view) ? $args->view : ''; - - switch ($view) { - - default: - $categories = self::_getK2Categories(); - foreach ($categories as $category) { - $category->href = K2HelperRoute::getCategoryRoute($category->id); - $items[] = array('id' => $category->href, 'name' => $category->name, 'class' => 'folder content'); - } - break; - - case 'itemlist': - $categories = self::_getK2Categories($args->id); - $itemlist = self::_getK2Items($args->id); - foreach ($categories as $category) { - $category->href = K2HelperRoute::getCategoryRoute($category->id); - $items[] = array('id' => $category->href, 'name' => $category->name, 'class' => 'folder content'); - } - foreach ($itemlist as $item) { - $item->href = K2HelperRoute::getItemRoute($item->id . ':' . $item->alias, $item->catid); - $items[] = array('id' => $item->href, 'name' => $item->title, 'class' => 'file'); - - $anchors = self::getAnchors($item->content); - - foreach ($anchors as $anchor) { - $items[] = array( - 'id' => $item->href . '#' . $anchor, - 'name' => '#' . $anchor, - 'class' => 'file anchor', - ); - } - } - break; - - case 'item': - break; - } - return $items; - } - - private static function getAnchors($content) - { - preg_match_all('#]+)(name|id)="([a-z]+[\w\-\:\.]*)"([^>]*)>#i', $content, $matches, PREG_SET_ORDER); - - $anchors = array(); - - if (!empty($matches)) { - foreach ($matches as $match) { - if (strpos($match[0], 'href') === false) { - $anchors[] = $match[3]; - } - } - } - - return $anchors; - } -} + $browser =JContentEditor::getInstance(); + * + * @access public + * @return JCE The editor object. + * @since 1.5 + */ + public function getInstance() + { + static $instance; + + if (!is_object($instance)) { + $instance = new K2linksK2(); + } + return $instance; + } + + public function getOption() + { + return $this->_option; + } + + public function getTask() + { + return $this->_task; + } + + public function getList() + { + $advlink = WFEditorPlugin::getInstance(); + $list = ''; + if ($advlink->checkAccess('k2links.k2', '1')) { + $list = '
  • '; + } + return $list; + } + + public static function _getK2Categories($parent_id = 0) + { + // K2 2.x + if (defined('K2_JVERSION')) { + $db = JFactory::getDBO(); + $query = 'SELECT id, name, alias FROM #__k2_categories WHERE published = 1'; + $user = JFactory::getUser(); + if (version_compare(JVERSION, '1.6.0', 'ge')) { + $query .= ' AND `access` IN (' . implode(',', $user->getAuthorisedViewLevels()) . ')'; + } else { + $query .= "\nAND `access` <=" . (int) $user->get('aid'); + } + $query .= ' AND parent = ' . $db->Quote($parent_id) . ' ORDER BY ordering ASC'; + $db->setQuery($query); + $rows = $db->loadObjectList(); + } + // K2 3.x + else { + if ($parent_id == 0) { + $parent_id = 1; + } + $model = K2Model::getInstance('Categories'); + $model->setState('site', true); + $model->setState('parent', $parent_id); + $model->setState('sorting', 'ordering'); + $rows = $model->getRows(); + } + + return $rows; + } + + public static function _getK2Items($category_id = 0) + { + // K2 2.x + if (defined('K2_JVERSION')) { + $db = JFactory::getDBO(); + + $query = 'SELECT id, title, alias, CONCAT(' . $db->quoteName('introtext') . ',' . $db->quoteName('fulltext') . ') AS content FROM #__k2_items WHERE published = 1'; + + $user = JFactory::getUser(); + if (version_compare(JVERSION, '1.6.0', 'ge')) { + $query .= ' AND `access` IN (' . implode(',', $user->getAuthorisedViewLevels()) . ')'; + } else { + $query .= "\nAND `access` <=" . (int) $user->get('aid'); + } + + $query .= ' AND catid = ' . $db->Quote($category_id) . ' ORDER BY ordering ASC'; + + $db->setQuery($query); + $rows = $db->loadObjectList(); + } + // K2 3.x + else { + $model = K2Model::getInstance('Items'); + $model->setState('site', true); + $model->setState('category', (int) $category_id); + $model->setState('recursive', false); + $model->setState('sorting', 'ordering'); + $rows = $model->getRows(); + } + return $rows; + } + + public function getLinks($args) + { + $mainframe = JFactory::getApplication(); + + $advlink = WFEditorPlugin::getInstance(); + if (defined('K2_JVERSION')) { + require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'route.php'; + } + + $items = array(); + $view = isset($args->view) ? $args->view : ''; + + switch ($view) { + + default: + $categories = self::_getK2Categories(); + foreach ($categories as $category) { + $category->href = K2HelperRoute::getCategoryRoute($category->id); + $items[] = array('id' => $category->href, 'name' => $category->name, 'class' => 'folder content'); + } + break; + + case 'itemlist': + $categories = self::_getK2Categories($args->id); + $itemlist = self::_getK2Items($args->id); + foreach ($categories as $category) { + $category->href = K2HelperRoute::getCategoryRoute($category->id); + $items[] = array('id' => $category->href, 'name' => $category->name, 'class' => 'folder content'); + } + foreach ($itemlist as $item) { + $item->href = K2HelperRoute::getItemRoute($item->id . ':' . $item->alias, $item->catid); + $items[] = array('id' => $item->href, 'name' => $item->title, 'class' => 'file'); + + $anchors = self::getAnchors($item->content); + + foreach ($anchors as $anchor) { + $items[] = array( + 'id' => $item->href . '#' . $anchor, + 'name' => '#' . $anchor, + 'class' => 'file anchor', + ); + } + } + break; + + case 'item': + break; + } + return $items; + } + + private static function getAnchors($content) + { + preg_match_all('#]+)(name|id)="([a-z]+[\w\-\:\.]*)"([^>]*)>#i', $content, $matches, PREG_SET_ORDER); + + $anchors = array(); + + if (!empty($matches)) { + foreach ($matches as $match) { + if (strpos($match[0], 'href') === false) { + $anchors[] = $match[3]; + } + } + } + + return $anchors; + } +} diff --git a/plugins/jce/links-k2/k2links/tags.php b/plugins/jce/links-k2/k2links/tags.php index 98c9e58..18c327d 100644 --- a/plugins/jce/links-k2/k2links/tags.php +++ b/plugins/jce/links-k2/k2links/tags.php @@ -1,178 +1,157 @@ - $browser =JContentEditor::getInstance(); - * - * @access public - * @return JCE The editor object. - * @since 1.5 - */ - function getInstance() - { - static $instance; - - if (!is_object($instance)) - { - $instance = new K2linksTags(); - } - return $instance; - } - - public function getOption() - { - return $this->_option; - } - - public function getTask() - { - return $this->_task; - } - - public function getList() - { - $advlink = WFEditorPlugin::getInstance(); - $list = ''; - if ($advlink->checkAccess('k2links.tags', '1')) - { - $list = '
  • '; - } - return $list; - } - - public static function _getK2Tags() - { - if (defined('K2_JVERSION')) - { - $db = JFactory::getDBO(); - $user = JFactory::getUser(); - $query = 'SELECT id, name FROM #__k2_tags WHERE published = 1 ORDER BY name ASC'; - $db->setQuery($query); - $rows = $db->loadObjectList(); - } - else - { - $model = K2Model::getInstance('Tags'); - $model->setState('state', 1); - $model->setState('sorting', 'name'); - $rows = $model->getRows(); - } - return $rows; - } - - public static function _getK2Items($tag = '') - { - if (defined('K2_JVERSION')) - { - - $db = JFactory::getDBO(); - $user = JFactory::getUser(); - $query = "SELECT `i`.`id`, `i`.`title`, `i`.`alias`, `i`.`catid`, `c`.`alias` AS categoryAlias - FROM `#__k2_tags_xref` as `x` - INNER JOIN `#__k2_items` as `i` ON(`i`.`id` = `x`.`itemID`) - INNER JOIN `#__k2_tags` as `t` ON (`t`.`id` = `x`.`tagID`) - INNER JOIN `#__k2_categories` as `c` ON(`i`.`catid` = `c`.`id`) - WHERE `t`.`name` = ".$db->quote($tag); - $query .= ' AND `i`.`published` = 1 AND `c`.`published` = 1 '; - if (version_compare(JVERSION, '1.6.0', 'ge')) - { - $query .= ' AND `i`.`access` IN ('.implode(',', $user->getAuthorisedViewLevels()).')'; - $query .= ' AND `c`.`access` IN ('.implode(',', $user->getAuthorisedViewLevels()).')'; - } - else - { - $query .= "\nAND `i`.`access` <=".(int)$user->get('aid'); - $query .= "\nAND `c`.`access` <=".(int)$user->get('aid'); - } - $query .= "\nORDER BY `i`.`title`, `i`.`created` ASC"; - $db->setQuery($query); - $rows = $db->loadObjectList(); - } - else - { - $model = K2Model::getInstance('Items'); - $model->setState('site', true); - $model->setState('tag', (int)$tag); - $model->setState('sorting', 'title'); - $rows = $model->getRows(); - } - return $rows; - } - - function getLinks($args) - { - $mainframe = JFactory::getApplication(); - - $advlink = WFEditorPlugin::getInstance(); - - if (defined('K2_JVERSION')) - { - require_once (JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'helpers'.DS.'route.php'); - } - $items = array(); - $view = isset($args->view) ? $args->view : ''; - - switch ($view) - { - - default : - $tags = self::_getK2Tags(); - foreach ($tags as $tag) - { - if (defined('K2_JVERSION')) - { - $tag->href = K2HelperRoute::getTagRoute($tag->name); - } - else - { - $tag->href = K2HelperRoute::getTagRoute($tag->id.':'.$tag->alias); - } - $items[] = array('id' => $tag->href, 'name' => $tag->name, 'class' => 'folder content'); - } - break; - - case 'itemlist' : - $itemlist = self::_getK2Items($args->tag); - foreach ($itemlist as $item) - { - $item->href = K2HelperRoute::getItemRoute($item->id.':'.$item->alias, $item->catid); - $items[] = array('id' => $item->href, 'name' => $item->title, 'class' => 'file'); - } - break; - - case 'item' : - break; - } - return $items; - } - -} + $browser =JContentEditor::getInstance(); + * + * @access public + * @return JCE The editor object. + * @since 1.5 + */ + public function getInstance() + { + static $instance; + + if (!is_object($instance)) { + $instance = new K2linksTags(); + } + return $instance; + } + + public function getOption() + { + return $this->_option; + } + + public function getTask() + { + return $this->_task; + } + + public function getList() + { + $advlink = WFEditorPlugin::getInstance(); + $list = ''; + if ($advlink->checkAccess('k2links.tags', '1')) { + $list = '
  • '; + } + return $list; + } + + public static function _getK2Tags() + { + if (defined('K2_JVERSION')) { + $db = JFactory::getDBO(); + $user = JFactory::getUser(); + $query = 'SELECT id, name FROM #__k2_tags WHERE published = 1 ORDER BY name ASC'; + $db->setQuery($query); + $rows = $db->loadObjectList(); + } else { + $model = K2Model::getInstance('Tags'); + $model->setState('state', 1); + $model->setState('sorting', 'name'); + $rows = $model->getRows(); + } + return $rows; + } + + public static function _getK2Items($tag = '') + { + if (defined('K2_JVERSION')) { + $db = JFactory::getDBO(); + $user = JFactory::getUser(); + $query = "SELECT `i`.`id`, `i`.`title`, `i`.`alias`, `i`.`catid`, `c`.`alias` AS categoryAlias + FROM `#__k2_tags_xref` as `x` + INNER JOIN `#__k2_items` as `i` ON(`i`.`id` = `x`.`itemID`) + INNER JOIN `#__k2_tags` as `t` ON (`t`.`id` = `x`.`tagID`) + INNER JOIN `#__k2_categories` as `c` ON(`i`.`catid` = `c`.`id`) + WHERE `t`.`name` = ".$db->quote($tag); + $query .= ' AND `i`.`published` = 1 AND `c`.`published` = 1 '; + if (version_compare(JVERSION, '1.6.0', 'ge')) { + $query .= ' AND `i`.`access` IN ('.implode(',', $user->getAuthorisedViewLevels()).')'; + $query .= ' AND `c`.`access` IN ('.implode(',', $user->getAuthorisedViewLevels()).')'; + } else { + $query .= "\nAND `i`.`access` <=".(int)$user->get('aid'); + $query .= "\nAND `c`.`access` <=".(int)$user->get('aid'); + } + $query .= "\nORDER BY `i`.`title`, `i`.`created` ASC"; + $db->setQuery($query); + $rows = $db->loadObjectList(); + } else { + $model = K2Model::getInstance('Items'); + $model->setState('site', true); + $model->setState('tag', (int)$tag); + $model->setState('sorting', 'title'); + $rows = $model->getRows(); + } + return $rows; + } + + public function getLinks($args) + { + $mainframe = JFactory::getApplication(); + + $advlink = WFEditorPlugin::getInstance(); + + if (defined('K2_JVERSION')) { + require_once(JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'helpers'.DS.'route.php'); + } + $items = array(); + $view = isset($args->view) ? $args->view : ''; + + switch ($view) { + + default: + $tags = self::_getK2Tags(); + foreach ($tags as $tag) { + if (defined('K2_JVERSION')) { + $tag->href = K2HelperRoute::getTagRoute($tag->name); + } else { + $tag->href = K2HelperRoute::getTagRoute($tag->id.':'.$tag->alias); + } + $items[] = array('id' => $tag->href, 'name' => $tag->name, 'class' => 'folder content'); + } + break; + + case 'itemlist': + $itemlist = self::_getK2Items($args->tag); + foreach ($itemlist as $item) { + $item->href = K2HelperRoute::getItemRoute($item->id.':'.$item->alias, $item->catid); + $items[] = array('id' => $item->href, 'name' => $item->title, 'class' => 'file'); + } + break; + + case 'item': + break; + } + return $items; + } +} diff --git a/plugins/jce/links-k2/k2links/users.php b/plugins/jce/links-k2/k2links/users.php index a26bee2..44546e6 100644 --- a/plugins/jce/links-k2/k2links/users.php +++ b/plugins/jce/links-k2/k2links/users.php @@ -1,185 +1,161 @@ - $browser =JContentEditor::getInstance(); - * - * @access public - * @return JCE The editor object. - * @since 1.5 - */ - function getInstance() - { - static $instance; - - if (!is_object($instance)) - { - $instance = new K2linksTags(); - } - return $instance; - } - - public function getOption() - { - return $this->_option; - } - - public function getTask() - { - return $this->_task; - } - - public function getList() - { - $advlink = WFEditorPlugin::getInstance(); - $list = ''; - if ($advlink->checkAccess('k2links.users', '1')) - { - $list = '
  • '; - } - return $list; - } - - public static function _getK2Users() - { - if (defined('K2_JVERSION')) - { - $db = JFactory::getDBO(); - $query = "SELECT juser.id, juser.name FROM #__users as juser - RIGHT JOIN #__k2_users as k2user ON juser.id = k2user.userID"; - $db->setQuery($query); - $rows = $db->loadObjectList(); - } - else - { - $model = K2Model::getInstance('Users'); - $rows = $model->getRows(); - } - return $rows; - } - - public static function _getK2Items($userID = '') - { - if (defined('K2_JVERSION')) - { - $db = JFactory::getDBO(); - $query = "SELECT item.id, item.title, item.alias, item.catid, category.alias AS categoryAlias FROM #__k2_items AS item - LEFT JOIN #__k2_categories AS category ON item.catid = category.id - WHERE item.created_by = ".(int)$userID." AND item.created_by_alias = ''"; - $query .= ' AND item.published = 1 AND category.published = 1 '; - $user = JFactory::getUser(); - if (version_compare(JVERSION, '1.6.0', 'ge')) - { - $query .= ' AND item.access IN ('.implode(',', $user->getAuthorisedViewLevels()).')'; - $query .= ' AND category.access IN ('.implode(',', $user->getAuthorisedViewLevels()).')'; - } - else - { - $query .= " AND item.access <=".(int)$user->get('aid'); - $query .= " AND category.access <=".(int)$user->get('aid'); - } - $query .= " ORDER BY title, created ASC"; - $db->setQuery($query); - $rows = $db->loadObjectList(); - } - else - { - $model = K2Model::getInstance('Items'); - $model->setState('site', true); - $model->setState('author', (int)$userID); - $model->setState('sorting', 'title'); - $rows = $model->getRows(); - } - return $rows; - } - - function getLinks($args) - { - $mainframe = JFactory::getApplication(); - - $advlink = WFEditorPlugin::getInstance(); - - if (defined('K2_JVERSION')) - { - require_once (JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'helpers'.DS.'utilities.php'); - require_once (JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'helpers'.DS.'route.php'); - } - - $items = array(); - $view = isset($args->view) ? $args->view : ''; - - switch ($view) - { - - default : - $users = self::_getK2Users(); - foreach ($users as $user) - { - if ($user->id) - { - if (defined('K2_JVERSION')) - { - $user->href = K2HelperRoute::getUserRoute($user->id); - } - else - { - if (JFactory::getConfig()->get('unicodeslugs') == 1) - { - $alias = JFilterOutput::stringURLUnicodeSlug($user->name); - } - else - { - $alias = JFilterOutput::stringURLSafe($user->name); - } - $user->href = K2HelperRoute::getUserRoute($user->id.':'.$alias); - } - $items[] = array('id' => $user->href, 'name' => $user->name, 'class' => 'folder content'); - } - } - break; - - case 'itemlist' : - $itemlist = self::_getK2Items($args->id); - foreach ($itemlist as $item) - { - $item->href = K2HelperRoute::getItemRoute($item->id.':'.$item->alias, $item->catid); - $items[] = array('id' => $item->href, 'name' => $item->title, 'class' => 'file'); - } - break; - - case 'item' : - break; - } - return $items; - } - -} + $browser =JContentEditor::getInstance(); + * + * @access public + * @return JCE The editor object. + * @since 1.5 + */ + public function getInstance() + { + static $instance; + + if (!is_object($instance)) { + $instance = new K2linksTags(); + } + return $instance; + } + + public function getOption() + { + return $this->_option; + } + + public function getTask() + { + return $this->_task; + } + + public function getList() + { + $advlink = WFEditorPlugin::getInstance(); + $list = ''; + if ($advlink->checkAccess('k2links.users', '1')) { + $list = '
  • '; + } + return $list; + } + + public static function _getK2Users() + { + if (defined('K2_JVERSION')) { + $db = JFactory::getDBO(); + $query = "SELECT juser.id, juser.name FROM #__users as juser + RIGHT JOIN #__k2_users as k2user ON juser.id = k2user.userID"; + $db->setQuery($query); + $rows = $db->loadObjectList(); + } else { + $model = K2Model::getInstance('Users'); + $rows = $model->getRows(); + } + return $rows; + } + + public static function _getK2Items($userID = '') + { + if (defined('K2_JVERSION')) { + $db = JFactory::getDBO(); + $query = "SELECT item.id, item.title, item.alias, item.catid, category.alias AS categoryAlias FROM #__k2_items AS item + LEFT JOIN #__k2_categories AS category ON item.catid = category.id + WHERE item.created_by = ".(int)$userID." AND item.created_by_alias = ''"; + $query .= ' AND item.published = 1 AND category.published = 1 '; + $user = JFactory::getUser(); + if (version_compare(JVERSION, '1.6.0', 'ge')) { + $query .= ' AND item.access IN ('.implode(',', $user->getAuthorisedViewLevels()).')'; + $query .= ' AND category.access IN ('.implode(',', $user->getAuthorisedViewLevels()).')'; + } else { + $query .= " AND item.access <=".(int)$user->get('aid'); + $query .= " AND category.access <=".(int)$user->get('aid'); + } + $query .= " ORDER BY title, created ASC"; + $db->setQuery($query); + $rows = $db->loadObjectList(); + } else { + $model = K2Model::getInstance('Items'); + $model->setState('site', true); + $model->setState('author', (int)$userID); + $model->setState('sorting', 'title'); + $rows = $model->getRows(); + } + return $rows; + } + + public function getLinks($args) + { + $mainframe = JFactory::getApplication(); + + $advlink = WFEditorPlugin::getInstance(); + + if (defined('K2_JVERSION')) { + require_once(JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'helpers'.DS.'utilities.php'); + require_once(JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'helpers'.DS.'route.php'); + } + + $items = array(); + $view = isset($args->view) ? $args->view : ''; + + switch ($view) { + + default: + $users = self::_getK2Users(); + foreach ($users as $user) { + if ($user->id) { + if (defined('K2_JVERSION')) { + $user->href = K2HelperRoute::getUserRoute($user->id); + } else { + if (JFactory::getConfig()->get('unicodeslugs') == 1) { + $alias = JFilterOutput::stringURLUnicodeSlug($user->name); + } else { + $alias = JFilterOutput::stringURLSafe($user->name); + } + $user->href = K2HelperRoute::getUserRoute($user->id.':'.$alias); + } + $items[] = array('id' => $user->href, 'name' => $user->name, 'class' => 'folder content'); + } + } + break; + + case 'itemlist': + $itemlist = self::_getK2Items($args->id); + foreach ($itemlist as $item) { + $item->href = K2HelperRoute::getItemRoute($item->id.':'.$item->alias, $item->catid); + $items[] = array('id' => $item->href, 'name' => $item->title, 'class' => 'file'); + } + break; + + case 'item': + break; + } + return $items; + } +} diff --git a/plugins/jce/links-k2/links-k2.php b/plugins/jce/links-k2/links-k2.php index b304979..2735c58 100644 --- a/plugins/jce/links-k2/links-k2.php +++ b/plugins/jce/links-k2/links-k2.php @@ -1,9 +1,9 @@ _adapters[] = new $classname; - } - } - } - - /** - * Returns a reference to a editor object - * - * This method must be invoked as: - *
      $browser =JContentEditor::getInstance();
    - * - * @access public - * @return JCE The editor object. - * @since 1.5 - */ - public function getInstance() - { - static $instance; - - if (!is_object($instance)) - { - $instance = new WFLinkBrowser_K2(); - } - return $instance; - } - - public function display() - { - - } - - public function isEnabled() - { - $wf = WFEditorPlugin::getInstance(); - return $wf->checkAccess($wf->getName().'.links.k2links', 1); - } - - public function getOption() - { - foreach ($this->_adapters as $adapter) - { - $this->_option[] = $adapter->getOption(); - } - return $this->_option; - } - - public function getList() - { - $list = ''; - - foreach ($this->_adapters as $adapter) - { - $list .= $adapter->getList(); - } - return $list; - } - - public function getLinks($args) - { - foreach ($this->_adapters as $adapter) - { - if ($adapter->getOption() == $args->option) - { - if (property_exists($args, 'task')) - { - $task = $args->task; - } - else - { - $task = 'category'; - } - if ($adapter->getTask() == $task) - { - return $adapter->getLinks($args); - } - } - } - } - + public $_option = array(); + public $_adapters = array(); + + /** + * Constructor activating the default information of the class + * + * @access protected + */ + public function __construct($options = array()) + { + jimport('joomla.filesystem.folder'); + jimport('joomla.filesystem.file'); + + $path = dirname(__FILE__).DS.'k2links'; + + // Get all files + $files = JFolder::files($path, '\.(php)$'); + + if (!empty($files)) { + foreach ($files as $file) { + require_once($path.DS.$file); + $classname = 'K2links'.ucfirst(basename($file, '.php')); + $this->_adapters[] = new $classname; + } + } + } + + /** + * Returns a reference to a editor object + * + * This method must be invoked as: + *
      $browser =JContentEditor::getInstance();
    + * + * @access public + * @return JCE The editor object. + * @since 1.5 + */ + public function getInstance() + { + static $instance; + + if (!is_object($instance)) { + $instance = new WFLinkBrowser_K2(); + } + return $instance; + } + + public function display() + { + } + + public function isEnabled() + { + $wf = WFEditorPlugin::getInstance(); + return $wf->checkAccess($wf->getName().'.links.k2links', 1); + } + + public function getOption() + { + foreach ($this->_adapters as $adapter) { + $this->_option[] = $adapter->getOption(); + } + return $this->_option; + } + + public function getList() + { + $list = ''; + + foreach ($this->_adapters as $adapter) { + $list .= $adapter->getList(); + } + return $list; + } + + public function getLinks($args) + { + foreach ($this->_adapters as $adapter) { + if ($adapter->getOption() == $args->option) { + if (property_exists($args, 'task')) { + $task = $args->task; + } else { + $task = 'category'; + } + if ($adapter->getTask() == $task) { + return $adapter->getLinks($args); + } + } + } + } }