PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/components/com_jce/editor/libraries/classes/extensions.php

https://bitbucket.org/pastor399/newcastleunifc
PHP | 240 lines | 98 code | 41 blank | 101 comment | 18 complexity | 55fa06589f2caff2b22494186d73d938 MD5 | raw file
  1. <?php
  2. /**
  3. * @package JCE
  4. * @copyright Copyright (c) 2009-2013 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. class WFExtension extends JObject {
  13. /**
  14. * Constructor activating the default information of the class
  15. *
  16. * @access public
  17. */
  18. public function __construct($config = array()) {
  19. parent::__construct();
  20. // set extension properties
  21. $this->setProperties($config);
  22. }
  23. /**
  24. * Returns a reference to a WFExtension object
  25. *
  26. * This method must be invoked as:
  27. * <pre> $extension = WFExtension::getInstance();</pre>
  28. *
  29. * @access public
  30. * @return object WFExtension
  31. */
  32. /* public static function getInstance()
  33. {
  34. static $instance;
  35. if (!is_object($instance)) {
  36. $instance = new WFExtension();
  37. }
  38. return $instance;
  39. } */
  40. /**
  41. * Display the extension
  42. * @access $public
  43. */
  44. public function display() {
  45. $document = WFDocument::getInstance();
  46. // Load Extensions Object
  47. $document->addScript(array(
  48. 'extensions'
  49. ));
  50. }
  51. /**
  52. * Load a plugin extension
  53. *
  54. * @access public
  55. * @return array
  56. */
  57. private static function _load($types = array(), $extension = null, $config = array()) {
  58. jimport('joomla.filesystem.folder');
  59. jimport('joomla.filesystem.file');
  60. $extensions = array();
  61. if (!isset($config['base_path'])) {
  62. $config['base_path'] = WF_EDITOR;
  63. }
  64. // core extensions path
  65. $path = $config['base_path'] . '/extensions';
  66. // cast as array
  67. $types = (array) $types;
  68. // get all types from core
  69. if (empty($types)) {
  70. $types = JFolder::folders(WF_EDITOR . '/extensions');
  71. }
  72. if (JFolder::exists($path)) {
  73. foreach ($types as $type) {
  74. if ($extension) {
  75. if (JFile::exists($path . '/' . $type . '/' . $extension . '.xml') && JFile::exists($path . '/' . $type . '/' . $extension . '.php')) {
  76. $object = new stdClass();
  77. $object->folder = $type;
  78. $object->path = $path . '/' . $type;
  79. $object->extension = $extension;
  80. $extensions[] = $object;
  81. }
  82. } else {
  83. $files = JFolder::files($path . '/' . $type, '\.xml$', false, true);
  84. foreach ($files as $file) {
  85. $object = new stdClass();
  86. $object->folder = $type;
  87. $object->path = $path . '/' . $type;
  88. $name = JFile::stripExt(basename($file));
  89. if (JFile::exists(dirname($file) . '/' . $name . '.php')) {
  90. $object->extension = $name;
  91. }
  92. $extensions[] = $object;
  93. }
  94. }
  95. }
  96. }
  97. // set default prefix
  98. /* if (!array_key_exists('prefix', $config)) {
  99. $config['prefix'] = 'jce-';
  100. }
  101. // get external extensions
  102. jimport('joomla.plugin.helper');
  103. foreach ($types as $type) {
  104. $installed = JPluginHelper::getPlugin($config['prefix'] . $type, $extension);
  105. foreach ($installed as $item) {
  106. $object = new stdClass();
  107. $object->folder = $item->type;
  108. $object->path = JPATH_PLUGINS . '/' . $item->type;
  109. $name = $item->element;
  110. if (JFile::exists(JPATH_PLUGINS . '/' . $item->type . '/' . $item->element . '.php')) {
  111. $object->extension = $name;
  112. }
  113. $extensions[] = $object;
  114. }
  115. } */
  116. return $extensions;
  117. }
  118. /**
  119. * Load & Call an extension
  120. *
  121. * @access public
  122. * @param array $config
  123. * @return mixed
  124. */
  125. public static function loadExtensions($type, $extension = null, $config = array()) {
  126. jimport('joomla.filesystem.folder');
  127. jimport('joomla.filesystem.file');
  128. $language = JFactory::getLanguage();
  129. if (!isset($config['base_path'])) {
  130. $config['base_path'] = WF_EDITOR;
  131. }
  132. // set default prefix
  133. /* if (!array_key_exists('prefix', $config)) {
  134. $config['prefix'] = 'jce-';
  135. } */
  136. // sanitize $type
  137. $type = preg_replace('#[^A-Z0-9\._-]#i', '', $type);
  138. // sanitize $extension
  139. if ($extension) {
  140. $extension = preg_replace('#[^A-Z0-9\._-]#i', '', $extension);
  141. }
  142. // Create extensions path
  143. $base = $config['base_path'] . '/extensions';
  144. // Get all extensions
  145. $extensions = self::_load((array) $type, $extension, $config);
  146. $result = array();
  147. if (!empty($extensions)) {
  148. foreach ($extensions as $item) {
  149. $name = isset($item->extension) ? $item->extension : '';
  150. $folder = $item->folder;
  151. $path = $item->path;
  152. if ($name) {
  153. $root = $path . '/' . $name . '.php';
  154. if (file_exists($root)) {
  155. // Load root extension file
  156. require_once($root);
  157. // Load Extension language file
  158. $language->load('com_jce_' . $type . '_' . $name, JPATH_SITE);
  159. // remove prefix
  160. //$folder = str_replace($config['prefix'], '', $folder);
  161. // Return array of extension names
  162. $result[$type][] = $name;
  163. // if we only want a named extension
  164. if ($extension && $extension == $name) {
  165. return $name;
  166. }
  167. }
  168. }
  169. }
  170. }
  171. // only return extension types requested
  172. if ($type && array_key_exists($type, $result)) {
  173. return $result[$type];
  174. }
  175. // Return array or extension name
  176. return $result;
  177. }
  178. /**
  179. * Return a parameter for the current plugin / group
  180. * @param object $param Parameter name
  181. * @param object $default Default value
  182. * @return string Parameter value
  183. */
  184. public function getParam($param, $default = '') {
  185. $wf = WFEditor::getInstance();
  186. return $wf->getParam($param, $default);
  187. }
  188. public function getView($options = array()) {
  189. return new WFView($options);
  190. }
  191. }
  192. ?>