PageRenderTime 38ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_jce/editor/extensions/browser/link.php

https://github.com/viollarr/alab
PHP | 203 lines | 134 code | 35 blank | 34 comment | 20 complexity | c1221a1b8a4d0497239102925d436e0e MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, AGPL-3.0, Apache-2.0, BSD-3-Clause, GPL-3.0
  1. <?php
  2. /**
  3. * @package JCE
  4. * @copyright Copyright Š 2009-2011 Ryan Demmer. All rights reserved.
  5. * @license GNU/GPL 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  6. * JCE is free software. This version may have been modified pursuant
  7. * to the GNU General Public License, and as distributed it includes or
  8. * is derivative of works licensed under the GNU General Public License or
  9. * other free or open source software licenses.
  10. */
  11. defined('_JEXEC') or die('RESTRICTED');
  12. wfimport('editor.libraries.classes.extensions.browser');
  13. class WFLinkBrowser extends WFBrowserExtension {
  14. /*
  15. * @var varchar
  16. */
  17. private $extensions = array();
  18. /**
  19. * Constructor activating the default information of the class
  20. *
  21. * @access protected
  22. */
  23. public function __construct() {
  24. parent::__construct();
  25. $extensions = self::loadExtensions(array(
  26. 'types' => array('links')
  27. ));
  28. // Load all link extensions
  29. foreach ($extensions['links'] as $link) {
  30. $this->extensions[] = $this->getLinkExtension($link);
  31. }
  32. $request = WFRequest::getInstance();
  33. $request->setRequest(array($this, 'getLinks'));
  34. }
  35. public function display() {
  36. parent::display();
  37. $document = WFDocument::getInstance();
  38. $document->addScript(array('tree'), 'libraries');
  39. $document->addScript(array('link'), 'extensions.browser.js');
  40. $document->addStyleSheet(array('tree'), 'libraries');
  41. foreach ($this->extensions as $extension) {
  42. $extension->display();
  43. }
  44. }
  45. private function &getLinkExtension($name) {
  46. static $links;
  47. if (!isset($links)) {
  48. $links = array();
  49. }
  50. if (empty($links[$name])) {
  51. $classname = 'WFLinkBrowser_' . ucfirst($name);
  52. if (class_exists($classname)) {
  53. $links[$name] = new $classname();
  54. }
  55. }
  56. return $links[$name];
  57. }
  58. public function render() {
  59. $list = array();
  60. foreach ($this->extensions as $extension) {
  61. if ($extension->isEnabled()) {
  62. $list[] = $extension->getList();
  63. }
  64. }
  65. if (count($list)) {
  66. $view = $this->getView('links');
  67. $view->assign('list', implode("\n", $list));
  68. $view->display();
  69. }
  70. }
  71. public function getLinks($args) {
  72. foreach ($this->extensions as $extension) {
  73. if (in_array($args->option, $extension->getOption())) {
  74. $items = $extension->getLinks($args);
  75. }
  76. }
  77. $array = array();
  78. $result = array();
  79. if (isset($items)) {
  80. foreach ($items as $item) {
  81. $array[] = array(
  82. 'id' => isset($item['id']) ? WFEditor::xmlEncode($item['id']) : '',
  83. 'url' => isset($item['url']) ? WFEditor::xmlEncode($item['url']) : '',
  84. 'name' => WFEditor::xmlEncode($item['name']), 'class' => $item['class']
  85. );
  86. }
  87. $result = array('folders' => $array);
  88. }
  89. return $result;
  90. }
  91. /**
  92. * Category function used by many extensions
  93. *
  94. * @access public
  95. * @return Category list object.
  96. * @since 1.5
  97. */
  98. public function getCategory($section, $parent = 1) {
  99. $db = JFactory::getDBO();
  100. $user = JFactory::getUser();
  101. $wf = WFEditorPlugin::getInstance();
  102. $query = 'SELECT id AS slug, id AS id, title, alias, access';
  103. if ($wf->getParam('category_alias', 1) == 1) {
  104. $dbquery = $db->getQuery(true);
  105. if (is_object($dbquery)) {
  106. //sqlsrv changes
  107. $case_when = ' CASE WHEN ';
  108. $case_when .= $dbquery->charLength('alias');
  109. $case_when .= ' THEN ';
  110. $a_id = $dbquery->castAsChar('id');
  111. $case_when .= $dbquery->concatenate(array($a_id, 'alias'), ':');
  112. $case_when .= ' ELSE ';
  113. $case_when .= $a_id . ' END as slug';
  114. } else {
  115. $case_when = ' CASE WHEN CHAR_LENGTH(alias) THEN CONCAT_WS(":", id, alias) ELSE id END as slug';
  116. }
  117. $query .= ',' . $case_when;
  118. }
  119. if (method_exists('JUser', 'getAuthorisedViewLevels')) {
  120. $where = ' WHERE parent_id = ' . (int) $parent;
  121. $where .= ' AND extension = ' . $db->Quote($section);
  122. $where .= ' AND access IN (' . implode(',', $user->authorisedLevels()) . ')';
  123. if (!$wf->checkAccess('static', 1)) {
  124. $where .= ' AND path != ' . $db->Quote('uncategorised');
  125. }
  126. } else {
  127. $where = ' WHERE section = ' . $db->Quote($section);
  128. $where .= ' AND access <= ' . (int) $user->get('aid');
  129. }
  130. $query .= ' FROM #__categories'
  131. . $where
  132. . ' AND published = 1'
  133. . ' ORDER BY title'
  134. ;
  135. $db->setQuery($query);
  136. return $db->loadObjectList();
  137. }
  138. /**
  139. * (Attempt to) Get an Itemid
  140. *
  141. * @access public
  142. * @param string $component
  143. * @param array $needles
  144. * @return Category list object.
  145. */
  146. public function getItemId($component, $needles = array()) {
  147. $match = null;
  148. require_once(JPATH_SITE . DS . 'includes' . DS . 'application.php');
  149. $tag = WF_JOOMLA15 ? 'componentid' : 'component_id';
  150. $component = JComponentHelper::getComponent($component);
  151. $menu = JSite::getMenu();
  152. $items = $menu->getItems($tag, $component->id);
  153. if ($items) {
  154. foreach ($needles as $needle => $id) {
  155. foreach ($items as $item) {
  156. if ((@$item->query['view'] == $needle) && (@$item->query['id'] == $id)) {
  157. $match = $item->id;
  158. break;
  159. }
  160. }
  161. if (isset($match)) {
  162. break;
  163. }
  164. }
  165. }
  166. return $match ? '&Itemid=' . $match : '';
  167. }
  168. }