PageRenderTime 69ms CodeModel.GetById 42ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/cladjidane/D-mo-HTML5-CSS3
PHP | 407 lines | 226 code | 51 blank | 130 comment | 48 complexity | 9113baf1383068c5986a137ceb59bb7f MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: editor.php 221 2011-06-11 17:30:33Z happy_noodle_boy $
  4. * @package JCE
  5. * @copyright Copyright (C) 2005 - 2009 Ryan Demmer. All rights reserved.
  6. * @author Ryan Demmer
  7. * @license GNU/GPL
  8. * JCE is free software. This version may have been modified pursuant
  9. * to the GNU General Public License, and as distributed it includes or
  10. * is derivative of works licensed under the GNU General Public License or
  11. * other free or open source software licenses.
  12. */
  13. defined('_JEXEC') or die('RESTRICTED');
  14. wfimport('editor.libraries.classes.utility');
  15. wfimport('editor.libraries.classes.token');
  16. wfimport('editor.libraries.classes.document');
  17. wfimport('editor.libraries.classes.view');
  18. wfimport('editor.libraries.classes.tabs');
  19. wfimport('editor.libraries.classes.request');
  20. /**
  21. * JCE class
  22. *
  23. * @static
  24. * @package JCE
  25. * @since 1.5
  26. */
  27. class WFEditor extends JObject
  28. {
  29. /**
  30. * @var varchar
  31. */
  32. var $_version = '2.0.1';
  33. /**
  34. * @var boolean
  35. */
  36. var $_debug = false;
  37. /**
  38. * Constructor activating the default information of the class
  39. *
  40. * @access protected
  41. */
  42. function __construct($config = array())
  43. {
  44. $this->setProperties($config);
  45. }
  46. /**
  47. * Returns a reference to a editor object
  48. *
  49. * This method must be invoked as:
  50. * <pre> $browser =JContentEditor::getInstance();</pre>
  51. *
  52. * @access public
  53. * @return JCE The editor object.
  54. * @since 1.5
  55. */
  56. function &getInstance()
  57. {
  58. static $instance;
  59. if (!is_object($instance)) {
  60. $instance = new WFEditor();
  61. }
  62. return $instance;
  63. }
  64. /**
  65. * Get the current version
  66. * @return Version
  67. */
  68. function getVersion()
  69. {
  70. return $this->get('_version');
  71. }
  72. /**
  73. * Get the Super Administrator status
  74. *
  75. * Determine whether the user is a Super Administrator
  76. *
  77. * @return boolean
  78. */
  79. function isSuperAdmin()
  80. {
  81. $user = JFactory::getUser();
  82. if (WF_JOOMLA15) {
  83. return (strtolower($user->usertype) == 'superadministrator' || strtolower($user->usertype) == 'super administrator' || $user->gid == 25) ? true : false;
  84. }
  85. return false;
  86. }
  87. /**
  88. * Get an appropriate editor profile
  89. * @return $profile Object
  90. */
  91. public function getProfile()
  92. {
  93. static $profile;
  94. if (!is_object($profile)) {
  95. $mainframe =JFactory::getApplication();
  96. $db = JFactory::getDBO();
  97. $user = JFactory::getUser();
  98. $option = $this->getComponentOption();
  99. $query = 'SELECT *'
  100. . ' FROM #__wf_profiles'
  101. . ' WHERE published = 1'
  102. . ' ORDER BY ordering ASC'
  103. ;
  104. $db->setQuery($query);
  105. $profiles = $db->loadObjectList();
  106. if ($option == 'com_jce') {
  107. $component_id = JRequest::getInt('component_id');
  108. if ($component_id) {
  109. $component = WFExtensionHelper::getComponent($component_id);
  110. $option = isset($component->element) ? $component->element : $component->option;
  111. }
  112. }
  113. $area = $mainframe->isAdmin() ? 2 : 1;
  114. foreach ($profiles as $item) {
  115. // check if option is in list - always true if option is com_jce
  116. $isComponent = ($option == 'com_jce') ? true : in_array($option, explode(',', $item->components));
  117. // Set area default as Front-end / Back-end
  118. if (!isset($item->area) || $item->area == '') {
  119. $item->area = 0;
  120. }
  121. if ($item->area == $area || $item->area == 0) {
  122. // Check user
  123. if (in_array($user->id, explode(',', $item->users))) {
  124. if ($item->components) {
  125. if ($isComponent) {
  126. $profile = $item;
  127. return $profile;
  128. }
  129. } else {
  130. $profile = $item;
  131. return $profile;
  132. }
  133. }
  134. // Joomla! 1.6+
  135. if (method_exists('JUser', 'getAuthorisedGroups')) {
  136. $keys = $user->getAuthorisedGroups();
  137. } else {
  138. $keys = array($user->gid);
  139. }
  140. if ($item->types) {
  141. $groups = array_intersect($keys, explode(',', $item->types));
  142. if (!empty($groups)) {
  143. // Check components
  144. if ($item->components) {
  145. if ($isComponent) {
  146. $profile = $item;
  147. return $profile;
  148. }
  149. } else {
  150. $profile = $item;
  151. return $profile;
  152. }
  153. }
  154. }
  155. // Check components only
  156. if ($item->components && $isComponent) {
  157. $profile = $item;
  158. return $profile;
  159. }
  160. }
  161. }
  162. return null;
  163. }
  164. return $profile;
  165. }
  166. function getComponentOption()
  167. {
  168. $option = JRequest::getCmd('option', '');
  169. switch ($option) {
  170. case 'com_section':
  171. $option = 'com_content';
  172. break;
  173. case 'com_categories':
  174. $section = JRequest::getVar('section');
  175. if ($section) {
  176. $option = $section;
  177. }
  178. break;
  179. }
  180. return $option;
  181. }
  182. public function getParams($options = array())
  183. {
  184. static $params;
  185. if (!isset( $params )) {
  186. $params = array();
  187. }
  188. // set blank key if not set
  189. if (!isset($options['key'])) {
  190. $options['key'] = '';
  191. }
  192. // set blank path if not set
  193. if (!isset($options['path'])) {
  194. $options['path'] = '';
  195. }
  196. $signature = serialize($options);
  197. if (empty($params[$signature])) {
  198. wfimport('admin.helpers.extension');
  199. // get component
  200. $component = WFExtensionHelper::getComponent();
  201. // get params data for this profile
  202. $profile = $this->getProfile();
  203. if (!$component->params) {
  204. $component->params = '{}';
  205. }
  206. if (!$profile || !$profile->params) {
  207. $profile_params = '{}';
  208. } else {
  209. $profile_params = $profile->params;
  210. }
  211. // merge data and convert to json string
  212. $data = WFParameter::array_to_object(array_merge_recursive(json_decode($component->params, true), json_decode($profile_params, true)));
  213. $params[$signature] = new WFParameter($data, $options['path'], $options['key']);
  214. }
  215. return $params[$signature];
  216. }
  217. /**
  218. * Remove linebreaks and carriage returns from a parameter value
  219. *
  220. * @return The modified value
  221. * @param string The parameter value
  222. */
  223. function cleanParam($param)
  224. {
  225. if (is_array($param)) {
  226. $param = implode('|', $param);
  227. }
  228. return trim(preg_replace('/\n|\r|\t(\r\n)[\s]+/', '', $param));
  229. }
  230. /**
  231. * Get a parameter by key
  232. * @param $key Parameter key eg: editor.width
  233. * @param $fallback Fallback value
  234. * @param $default Default value
  235. */
  236. public function getParam($key, $fallback = '', $default = '')
  237. {
  238. // get all keys
  239. $keys = explode('.', $key);
  240. // remove base key eg: 'editor'
  241. $base = array_shift($keys);
  242. // get params for base key
  243. $params = self::getParams(array('key' => $base));
  244. // get a parameter
  245. $param = $params->get($keys, $fallback);
  246. if (is_string($param)) {
  247. $param = self::cleanParam($param);
  248. }
  249. if (is_numeric($default)) {
  250. $default = intval($default);
  251. }
  252. if (is_numeric($param)) {
  253. $param = intval($param);
  254. }
  255. return ($param === $default) ? '' : $param;
  256. }
  257. /**
  258. * Load a language file
  259. *
  260. * @param string $prefix Language prefix
  261. * @param object $path[optional] Base path
  262. */
  263. function loadLanguage($prefix, $path = JPATH_SITE)
  264. {
  265. $language = JFactory::getLanguage();
  266. $language->load($prefix, $path);
  267. }
  268. /**
  269. * Load the language files for the current plugin
  270. */
  271. function loadLanguages()
  272. {
  273. $this->loadLanguage('com_jce');
  274. $this->loadPluginLanguage();
  275. }
  276. /**
  277. * Return the curernt language code
  278. *
  279. * @access public
  280. * @return language code
  281. */
  282. function getLanguageDir()
  283. {
  284. $language = JFactory::getLanguage();
  285. return $language->isRTL() ? 'rtl' : 'ltr';
  286. }
  287. /**
  288. * Return the curernt language code
  289. *
  290. * @access public
  291. * @return language code
  292. */
  293. function getLanguageTag()
  294. {
  295. $language = JFactory::getLanguage();
  296. if ($language->isRTL()) {
  297. return 'en-GB';
  298. }
  299. return $language->getTag();
  300. }
  301. /**
  302. * Return the curernt language code
  303. *
  304. * @access public
  305. * @return language code
  306. */
  307. function getLanguage()
  308. {
  309. $tag = $this->getLanguageTag();
  310. if (file_exists(JPATH_SITE .DS. 'language' .DS. $tag .DS. $tag .'.com_jce.xml')) {
  311. return substr($tag, 0, strpos($tag, '-'));
  312. }
  313. return 'en';
  314. }
  315. /**
  316. * Named wrapper to check access to a feature
  317. *
  318. * @access public
  319. * @param string The feature to check, eg: upload
  320. * @param string The defalt value
  321. * @return string
  322. */
  323. function checkUser()
  324. {
  325. return $this->getProfile();
  326. }
  327. /**
  328. * XML encode a string.
  329. *
  330. * @access public
  331. * @param string String to encode
  332. * @return string Encoded string
  333. */
  334. function xmlEncode($string)
  335. {
  336. return preg_replace(array('/&/', '/</', '/>/', '/\'/', '/"/'), array('&amp;', '&lt;', '&gt;', '&apos;', '&quot;'), $string);
  337. }
  338. /**
  339. * XML decode a string.
  340. *
  341. * @access public
  342. * @param string String to decode
  343. * @return string Decoded string
  344. */
  345. function xmlDecode($string)
  346. {
  347. return preg_replace(array('&amp;', '&lt;', '&gt;', '&apos;', '&quot;'), array('/&/', '/</', '/>/', '/\'/', '/"/'), $string);
  348. }
  349. function log($file, $msg)
  350. {
  351. jimport('joomla.error.log');
  352. $log =JLog::getInstance($file);
  353. $log->addEntry(array('comment' => 'LOG: '.$msg));
  354. }
  355. }
  356. ?>