PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_jce/controller.php

https://gitlab.com/che234/adn
PHP | 327 lines | 208 code | 79 blank | 40 comment | 33 complexity | fd4d6970809ce53d03f8eecbbd3c84fe MD5 | raw file
  1. <?php
  2. /**
  3. * @package JCE
  4. * @copyright Copyright (c) 2009-2016 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('admin.classes.controller');
  13. class WFController extends WFControllerBase {
  14. /**
  15. * Custom Constructor
  16. */
  17. public function __construct($default = array()) {
  18. parent::__construct($default);
  19. // load helpers
  20. wfimport('admin.helpers.parameter');
  21. wfimport('admin.helpers.extension');
  22. wfimport('admin.helpers.xml');
  23. }
  24. private function loadMenu() {
  25. $view = JRequest::getWord('view', 'cpanel');
  26. wfimport('admin.models.model');
  27. JSubMenuHelper::addEntry(WFText::_('WF_CPANEL'), 'index.php?option=com_jce&view=cpanel', $view == 'cpanel');
  28. $subMenus = array(
  29. 'WF_CONFIGURATION' => 'config',
  30. 'WF_PROFILES' => 'profiles',
  31. 'WF_INSTALL' => 'installer'
  32. );
  33. if (JPluginHelper::isEnabled('system', 'jcemediabox')) {
  34. $subMenus['WF_MEDIABOX'] = 'mediabox';
  35. }
  36. foreach ($subMenus as $menu => $item) {
  37. if (WFModel::authorize($item)) {
  38. JSubMenuHelper::addEntry(WFText::_($menu), 'index.php?option=com_jce&view=' . $item, $view == $item);
  39. }
  40. }
  41. }
  42. /**
  43. * Create the View.
  44. * This is an overloaded function of JController::getView
  45. * and includes addition of the JDocument Object with required scripts and styles
  46. * @return object
  47. */
  48. public function getView($name = '', $type = '', $prefix = '', $config = array()) {
  49. $language = JFactory::getLanguage();
  50. $language->load('com_jce', JPATH_ADMINISTRATOR);
  51. $document = JFactory::getDocument();
  52. if (!$name) {
  53. $name = JRequest::getWord('view', 'cpanel');
  54. }
  55. if (!$type) {
  56. $type = $document->getType();
  57. }
  58. if (empty($config)) {
  59. $config = array(
  60. 'base_path' => dirname(__FILE__)
  61. );
  62. }
  63. $model = $this->getModel($name);
  64. $view = parent::getView($name, $type, $prefix, $config);
  65. $document = JFactory::getDocument();
  66. // set device-width meta
  67. $document->setMetaData('meta', 'width=device-width, initial-scale=1.0');
  68. $version = new JVersion;
  69. if ($version->isCompatible('3.0')) {
  70. // Include jQuery
  71. JHtml::_('jquery.framework');
  72. } else {
  73. // JQuery
  74. $view->addScript(JURI::root(true) . '/components/com_jce/editor/libraries/jquery/js/jquery.min.js');
  75. // jQuery noConflict
  76. $view->addScriptDeclaration('jQuery.noConflict();');
  77. }
  78. // JQuery UI
  79. $view->addScript(JURI::root(true) . '/components/com_jce/editor/libraries/jquery/js/jquery-ui.min.js');
  80. $scripts = array();
  81. switch ($name) {
  82. case 'help':
  83. $view->addScript(JURI::root(true) . '/components/com_jce/editor/libraries/js/help.js');
  84. break;
  85. default:
  86. $view->addStyleSheet(JURI::root(true) . '/administrator/components/com_jce/media/css/global.css');
  87. // load Joomla! core javascript
  88. if (method_exists('JHtml', 'core')) {
  89. JHtml::core();
  90. }
  91. require_once(JPATH_ADMINISTRATOR . '/includes/toolbar.php');
  92. JToolBarHelper::title(WFText::_('WF_ADMINISTRATION') . ' :: ' . WFText::_('WF_' . strtoupper($name)), 'logo.png');
  93. $params = WFParameterHelper::getComponentParams();
  94. $theme = $params->get('preferences.theme', 'jce');
  95. $view->addScript(JURI::root(true) . '/administrator/components/com_jce/media/js/core.js');
  96. $options = array(
  97. 'labels' => array(
  98. 'ok' => WFText::_('WF_LABEL_OK'),
  99. 'cancel' => WFText::_('WF_LABEL_CANCEL'),
  100. 'select' => WFText::_('WF_LABEL_SELECT'),
  101. 'save' => WFText::_('WF_LABEL_SAVE'),
  102. 'saveclose' => WFText::_('WF_LABEL_SAVECLOSE'),
  103. 'alert' => WFText::_('WF_LABEL_ALERT'),
  104. 'required' => WFText::_('WF_MESSAGE_REQUIRED')
  105. )
  106. );
  107. $view->addScriptDeclaration('jQuery.jce.options = ' . json_encode($options) . ';');
  108. $view->addHelperPath(dirname(__FILE__) . '/helpers');
  109. $this->addModelPath(dirname(__FILE__) . '/models');
  110. $view->loadHelper('toolbar');
  111. $view->loadHelper('xml');
  112. $view->loadHelper($name);
  113. $this->loadMenu();
  114. break;
  115. }
  116. if ($model = $this->getModel($name)) {
  117. $view->setModel($model, true);
  118. }
  119. $view->assignRef('document', $document);
  120. return $view;
  121. }
  122. protected function getStyles() {
  123. jimport('joomla.filesystem.folder');
  124. jimport('joomla.filesystem.file');
  125. wfimport('admin.helpers.extension');
  126. $view = JRequest::getCmd('view', 'cpanel');
  127. $component = WFExtensionHelper::getComponent();
  128. $params = new WFParameter($component->params);
  129. $theme = $params->get('preferences.theme', 'jce');
  130. $site_path = JPATH_SITE . '/component/com_jce/editor/libraries/css';
  131. // Load styles
  132. $styles = array();
  133. if (!JFolder::exists($site_path . '/jquery/' . $theme)) {
  134. $theme = 'jce';
  135. }
  136. // admin global css
  137. $styles = array_merge($styles, array(
  138. 'administrator/components/com_jce/media/css/global.css'
  139. ));
  140. return $styles;
  141. }
  142. public function pack() {
  143. }
  144. /**
  145. * Display View
  146. * @return
  147. */
  148. public function display($cachable = false, $params = false) {
  149. $view = $this->getView();
  150. $view->display();
  151. }
  152. /**
  153. * Generic cancel method
  154. * @return
  155. */
  156. public function cancel() {
  157. // Check for request forgeries
  158. JRequest::checkToken() or die('Invalid Token');
  159. $this->setRedirect(JRoute::_('index.php?option=com_jce&view=cpanel', false));
  160. }
  161. public function check() {
  162. // we already no its broken..
  163. if (JRequest::getCmd('task') == 'repair') {
  164. return;
  165. }
  166. wfimport('admin.models.profiles');
  167. $profiles = new WFModelProfiles();
  168. $state = $profiles->checkTable();
  169. // Check Profiles DB
  170. if (!$state) {
  171. $link = JHTML::link('index.php?option=com_jce&amp;task=repair&amp;type=tables', WFText::_('WF_DB_CREATE_RESTORE'));
  172. self::_redirect(WFText::_('WF_DB_PROFILES_ERROR') . ' - ' . $link, 'error');
  173. }
  174. if ($state) {
  175. if (!$profiles->checkTableContents()) {
  176. $link = JHTML::link('index.php?option=com_jce&amp;task=repair&amp;type=tables', WFText::_('WF_DB_CREATE_RESTORE'));
  177. self::_redirect(WFText::_('WF_DB_PROFILES_ERROR') . ' - ' . $link, 'error');
  178. }
  179. }
  180. jimport('joomla.plugin.helper');
  181. // Check Editor is installed
  182. if (JPluginHelper::getPlugin('editors', 'jce') === false) {
  183. $link = JHTML::link('index.php?option=com_jce&amp;task=repair&amp;type=editor', WFText::_('WF_EDITOR_INSTALL'));
  184. self::_redirect(WFText::_('WF_EDITOR_INSTALLED_MANUAL_ERROR') . ' - ' . $link, 'error');
  185. }
  186. }
  187. public function repair() {
  188. $app = JFactory::getApplication();
  189. $type = JRequest::getWord('type', 'tables');
  190. switch ($type) {
  191. case 'tables' :
  192. wfimport('admin.models.profiles');
  193. $profiles = new WFModelProfiles();
  194. $profiles->installProfiles();
  195. $this->setRedirect(JRoute::_('index.php?option=com_jce&view=cpanel', false));
  196. break;
  197. case 'editor' :
  198. $source = dirname(__FILE__) . '/packages/editors';
  199. if (is_dir($source)) {
  200. jimport('joomla.installer.installer');
  201. $installer = new JInstaller();
  202. if ($installer->install($source)) {
  203. $app->enqueueMessage(WFText::_('WF_EDITOR_INSTALL_SUCCESS'));
  204. } else {
  205. $app->enqueueMessage(WFText::_('WF_EDITOR_INSTALL_FAILED'));
  206. }
  207. $this->setRedirect(JRoute::_('index.php?option=com_jce&view=cpanel', false));
  208. }
  209. break;
  210. }
  211. }
  212. public function authorize($task) {
  213. wfimport('admin.models.model');
  214. // map updates/blank/cpanel task to manage
  215. if (empty($task) || $task == 'cpanel' || $task == 'updates') {
  216. $task = 'manage';
  217. }
  218. if (WFModel::authorize($task) === false) {
  219. $this->setRedirect('index.php', WFText::_('ALERTNOTAUTH'), 'error');
  220. return false;
  221. }
  222. return true;
  223. }
  224. private static function _redirect($msg = '', $state = '') {
  225. $app = JFactory::getApplication();
  226. if ($msg) {
  227. $app->enqueueMessage($msg, $state);
  228. }
  229. JRequest::setVar('view', 'cpanel');
  230. JRequest::setVar('task', '');
  231. return false;
  232. }
  233. public function cleanInput($input, $method = 'string') {
  234. $filter = JFilterInput::getInstance();
  235. $input = (array) $input;
  236. foreach ($input as $k => $v) {
  237. if (!empty($v)) {
  238. if (is_array($v)) {
  239. $input[$k] = $this->cleanInput($v, $method);
  240. } else {
  241. $input[$k] = $filter->clean($v, $method);
  242. }
  243. }
  244. }
  245. return $input;
  246. }
  247. }
  248. ?>