PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_jce/controller.php

https://github.com/cavila/Astica
PHP | 219 lines | 137 code | 46 blank | 36 comment | 12 complexity | f2ff2e8f81a8784f93385cafe8e4d02f MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, Apache-2.0, BSD-3-Clause
  1. <?php
  2. /**
  3. * @version $Id: controller.php 231 2011-06-14 15:47:00Z happy_noodle_boy $
  4. * @package JCE
  5. * @copyright Copyright Š 2009-2011 Ryan Demmer. All rights reserved.
  6. * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
  7. * @license GNU/GPL 2 or later
  8. * 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 access');
  14. jimport('joomla.application.component.controller');
  15. /**
  16. * JCE Component Controller
  17. *
  18. * @package JCE
  19. * @since 1.5.8
  20. */
  21. class WFController extends JController
  22. {
  23. /**
  24. * Custom Constructor
  25. */
  26. function __construct($default = array())
  27. {
  28. parent::__construct($default);
  29. $view = JRequest::getWord('view', 'cpanel');
  30. $this->registerTask('apply', 'save');
  31. $this->registerTask('unpublish', 'publish');
  32. // load classes
  33. wfimport('admin.classes.installer');
  34. // load helpers
  35. wfimport('admin.helpers.parameter');
  36. wfimport('admin.helpers.extension');
  37. wfimport('admin.helpers.xml');
  38. $document = JFactory::getDocument();
  39. $document->setTitle(WFText::_('WF_ADMINISTRATION') . ' :: ' . WFText::_('WF_' . strtoupper($view)));
  40. $language = JFactory::getLanguage();
  41. $language->load('com_jce', JPATH_ADMINISTRATOR);
  42. $model = $this->getModel($view);
  43. // jquery versions
  44. $document->addScript(JURI::root(true) . '/components/com_jce/editor/libraries/js/jquery/jquery-' . WF_JQUERY . '.min.js?version=' . $model->getVersion());
  45. $document->addScript(JURI::root(true) . '/components/com_jce/editor/libraries/js/jquery/jquery-ui-' . WF_JQUERYUI . '.custom.min.js?version=' . $model->getVersion());
  46. // jQuery noConflict
  47. $document->addScriptDeclaration('jQuery.noConflict();');
  48. $scripts = array();
  49. switch ($view) {
  50. case 'help':
  51. $scripts[] = 'help.js';
  52. break;
  53. default:
  54. // load Joomla! core javascript
  55. if (method_exists('JHtml', 'core')) {
  56. JHtml::core();
  57. }
  58. require_once(JPATH_ADMINISTRATOR . DS . 'includes' . DS . 'toolbar.php');
  59. JToolBarHelper::title(WFText::_('WF_ADMINISTRATION') . ' &rsaquo;&rsaquo; ' . WFText::_('WF_' . strtoupper($view)), 'logo.png');
  60. $params = WFParameterHelper::getComponentParams();
  61. $theme = $params->get('preferences.theme', 'jce');
  62. $scripts = array_merge(array(
  63. 'tips.js',
  64. 'html5.js'
  65. ));
  66. // Load admin scripts
  67. $document->addScript(JURI::root(true) . '/administrator/components/com_jce/media/js/jce.js?version=' . $model->getVersion());
  68. $options = array(
  69. 'labels' => array(
  70. 'ok' => WFText::_('WF_LABEL_OK'),
  71. 'cancel' => WFText::_('WF_LABEL_CANCEL'),
  72. 'select' => WFText::_('WF_LABEL_SELECT'),
  73. 'save' => WFText::_('WF_LABEL_SAVE'),
  74. 'saveclose' => WFText::_('WF_LABEL_SAVECLOSE'),
  75. 'alert' => WFText::_('WF_LABEL_ALERT'),
  76. 'required' => WFText::_('WF_MESSAGE_REQUIRED')
  77. )
  78. );
  79. $document->addScriptDeclaration('jQuery(document).ready(function($){$.jce.init(' . json_encode($options) . ');});');
  80. $installer = WFInstaller::getInstance();
  81. $installer->check();
  82. break;
  83. }
  84. // Load site scripts
  85. foreach ($scripts as $script) {
  86. $document->addScript(JURI::root(true) . '/components/com_jce/editor/libraries/js/' . $script . '?version=' . $model->getVersion());
  87. }
  88. require_once(dirname(__FILE__) . DS . 'helpers' . DS . 'system.php');
  89. $app = JFactory::getApplication();
  90. $app->registerEvent('onAfterRender', 'WFSystemHelper');
  91. }
  92. function loadMenu()
  93. {
  94. $view = JRequest::getWord('view', 'cpanel');
  95. $model = $this->getModel($view);
  96. JSubMenuHelper::addEntry(WFText::_('WF_CPANEL'), 'index.php?option=com_jce&view=cpanel', $view == 'cpanel');
  97. $subMenus = array(
  98. 'WF_CONFIGURATION' => 'config',
  99. 'WF_PROFILES' => 'profiles',
  100. 'WF_INSTALL' => 'installer'
  101. );
  102. if (JPluginHelper::isEnabled('system', 'jcemediabox')) {
  103. $subMenus['WF_MEDIABOX'] = 'mediabox';
  104. }
  105. foreach ($subMenus as $menu => $item) {
  106. if ($model->authorize($item)) {
  107. JSubMenuHelper::addEntry(WFText::_($menu), 'index.php?option=com_jce&view=' . $item, $view == $item);
  108. }
  109. }
  110. }
  111. /**
  112. * Display View
  113. * @return
  114. */
  115. function display()
  116. {
  117. $document = JFactory::getDocument();
  118. $name = JRequest::getWord('view', 'cpanel');
  119. $view = $this->getView($name, $document->getType(), '', array(
  120. 'base_path' => dirname(__FILE__)
  121. ));
  122. switch ($name) {
  123. case 'help':
  124. if ($model = $this->getModel($name)) {
  125. $view->setModel($model, true);
  126. }
  127. break;
  128. default:
  129. $view->addHelperPath(dirname(__FILE__) . DS . 'helpers');
  130. $this->addModelPath(dirname(__FILE__) . DS . 'models');
  131. $view->loadHelper('toolbar');
  132. $view->loadHelper('tools');
  133. $view->loadHelper('xml');
  134. $view->loadHelper($name);
  135. if ($model = $this->getModel($name)) {
  136. $view->setModel($model, true);
  137. }
  138. $this->loadMenu();
  139. break;
  140. }
  141. $view->assignRef('document', $document);
  142. $view->display();
  143. }
  144. /**
  145. * Generic cancel method
  146. * @return
  147. */
  148. function cancel()
  149. {
  150. // Check for request forgeries
  151. JRequest::checkToken() or die('Invalid Token');
  152. $this->setRedirect(JRoute::_('index.php?option=com_jce&view=cpanel', false));
  153. }
  154. function repair()
  155. {
  156. $installer = WFInstaller::getInstance();
  157. $installer->repair();
  158. }
  159. function authorize($task)
  160. {
  161. $view = JRequest::getWord('view', 'cpanel');
  162. if ($view == 'popup') {
  163. return true;
  164. }
  165. $model = $this->getModel($view);
  166. if (!$model->authorize($task)) {
  167. $this->setRedirect('index.php', WFText::_('ALERTNOTAUTH'));
  168. return false;
  169. }
  170. return true;
  171. }
  172. }
  173. ?>