PageRenderTime 33ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_roksprocket/controller.php

https://bitbucket.org/pastor399/newcastleunifc
PHP | 129 lines | 73 code | 14 blank | 42 comment | 8 complexity | 2f8fa6e75e1e04a63389df66ee06577e MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @author RocketTheme http://www.rockettheme.com
  5. * @copyright Copyright (C) 2007 - 2013 RocketTheme, LLC
  6. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
  7. */
  8. // no direct access
  9. defined('_JEXEC') or die('Restricted access');
  10. jimport('joomla.application.component.controller');
  11. include_once(JPATH_COMPONENT_ADMINISTRATOR.'/helpers/legacy_class.php');
  12. /**
  13. * rokgallery Controller
  14. *
  15. * @package Joomla
  16. * @subpackage rokgallery
  17. */
  18. class RokSprocketController extends RokSprocketLegacyJController
  19. {
  20. /**
  21. * Constructor
  22. * @access private
  23. * @subpackage rokgallery
  24. */
  25. function __construct()
  26. {
  27. $app = JFactory::getApplication();
  28. $input = $app->input;
  29. //Get View
  30. if ($input->get('view') == '') {
  31. $input->set('view', 'default');
  32. }
  33. $this->item_type = 'Default';
  34. parent::__construct();
  35. }
  36. /**
  37. * Method to display a view.
  38. *
  39. * @param bool $cachable
  40. * @param bool $urlparams
  41. *
  42. * @internal param \If $boolean true, the view output will be cached
  43. * @internal param \An $array array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
  44. *
  45. * @return JController This object to support chaining.
  46. * @since 1.5
  47. */
  48. public function display($cachable = false, $urlparams = false)
  49. {
  50. require_once JPATH_ADMINISTRATOR.'/components/com_modules/helpers/modules.php';
  51. // Load the submenu.
  52. ModulesHelper::addSubmenu(JFactory::getApplication()->input->getCmd('view', 'modules'));
  53. $view = JFactory::getApplication()->input->getCmd('view', 'modules');
  54. $layout = JFactory::getApplication()->input->getCmd('layout', 'default');
  55. $id = JFactory::getApplication()->input->getInt('id', null);
  56. // Check for edit form.
  57. if ($view == 'module' && $layout == 'edit' && !$this->checkEditId('com_roksprocket.edit.module', $id)) {
  58. // Somehow the person just went to the form - we don't allow that.
  59. $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
  60. $this->setMessage($this->getError(), 'error');
  61. $this->setRedirect(JRoute::_(sprintf('index.php?option=%s&view=modules',RokSprocket_Helper::getRedirectionOption()), false));
  62. return false;
  63. }
  64. parent::display();
  65. }
  66. /**
  67. *
  68. */
  69. public function ajax()
  70. {
  71. try {
  72. $app = JFactory::getApplication();
  73. $input = $app->input;
  74. RokCommon_Ajax::addModelPath(JPATH_SITE . '/components/com_roksprocket/lib/RokSprocket/Admin/Ajax/Model',
  75. 'RokSprocketAdminAjaxModel');
  76. $model = $input->getWord('model', null);
  77. $action = $input->getWord('model_action', null);
  78. if (isset($_REQUEST['params'])) {
  79. $params = $this->smartstripslashes($_REQUEST['params']);
  80. }
  81. echo RokCommon_Ajax::run($model, $action, $params);
  82. } catch (Exception $e) {
  83. $result = new RokCommon_Ajax_Result();
  84. $result->setAsError();
  85. $result->setMessage($e->getMessage());
  86. echo json_encode($result);
  87. }
  88. }
  89. /**
  90. * @param $str
  91. *
  92. * @return string
  93. */
  94. protected function smartstripslashes($str)
  95. {
  96. $cd1 = substr_count($str, "\"");
  97. $cd2 = substr_count($str, "\\\"");
  98. $cs1 = substr_count($str, "'");
  99. $cs2 = substr_count($str, "\\'");
  100. $tmp = strtr($str, array(
  101. "\\\"" => "",
  102. "\\'" => ""
  103. ));
  104. $cb1 = substr_count($tmp, "\\");
  105. $cb2 = substr_count($tmp, "\\\\");
  106. if ($cd1 == $cd2 && $cs1 == $cs2 && $cb1 == 2 * $cb2) {
  107. return strtr($str, array(
  108. "\\\"" => "\"",
  109. "\\'" => "'",
  110. "\\\\" => "\\"
  111. ));
  112. }
  113. return $str;
  114. }
  115. }