Пример #1
0
 /**
  * Get editor parameters
  * @access  public
  * @param 	array $options
  * @return 	object
  */
 public function getParams($options = array())
 {
     if (!isset(self::$params)) {
         self::$params = array();
     }
     // set blank key if not set
     if (!isset($options['key'])) {
         $options['key'] = '';
     }
     // set blank path if not set
     if (!isset($options['path'])) {
         $options['path'] = '';
     }
     $plugin = JRequest::getCmd('plugin');
     if ($plugin) {
         $options['plugin'] = $plugin;
     }
     $signature = serialize($options);
     if (empty(self::$params[$signature])) {
         wfimport('admin.helpers.extension');
         // get component
         $component = WFExtensionHelper::getComponent();
         // get params data for this profile
         $profile = $this->getProfile($plugin);
         $profile_params = array();
         $component_params = array();
         if (!empty($component->params)) {
             $component_params = json_decode($component->params, true);
             // set null as array
             if (!$component_params) {
                 $component_params = array();
             }
         }
         if ($profile) {
             $profile_params = json_decode($profile->params, true);
             // set null as array
             if (!$profile_params) {
                 $profile_params = array();
             }
         }
         // merge data and convert to json string
         $data = WFParameter::mergeParams($component_params, $profile_params);
         self::$params[$signature] = new WFParameter($data, $options['path'], $options['key']);
     }
     return self::$params[$signature];
 }
Пример #2
0
 /**
  * Get editor parameters
  * @access  public
  * @param 	array $options
  * @return 	object
  */
 public function getParams($options = array())
 {
     if (!isset(self::$params)) {
         self::$params = array();
     }
     // set blank key if not set
     if (!isset($options['key'])) {
         $options['key'] = '';
     }
     // set blank path if not set
     if (!isset($options['path'])) {
         $options['path'] = '';
     }
     $plugin = JRequest::getCmd('plugin');
     if ($plugin) {
         $options['plugin'] = $plugin;
     }
     $signature = serialize($options);
     if (empty(self::$params[$signature])) {
         wfimport('admin.helpers.extension');
         // get plugin
         $editor_plugin = WFExtensionHelper::getPlugin();
         // get params data for this profile
         $profile = $this->getProfile($plugin);
         $profile_params = array();
         $editor_params = array();
         // get params from editor plugin
         if ($editor_plugin->params && $editor_plugin->params !== "{}") {
             $editor_params['editor'] = json_decode($editor_plugin->params, true);
         } else {
             // get component
             $component = WFExtensionHelper::getComponent();
             // get params from component "params" field (legacy)
             if ($component->params && $component->params !== "{}") {
                 $data = json_decode($component->params, true);
                 if (isset($data['editor'])) {
                     $editor_params['editor'] = $data['editor'];
                 }
             }
         }
         if ($profile) {
             $profile_params = json_decode($profile->params, true);
         }
         // make sure we have an empty array if null or false
         if (empty($editor_params)) {
             $editor_params = array();
         }
         // make sure we have an empty array if null or false
         if (empty($profile_params)) {
             $profile_params = array();
         }
         // merge data and convert to json string
         $data = WFParameter::mergeParams($editor_params, $profile_params, true, false);
         self::$params[$signature] = new WFParameter($data, $options['path'], $options['key']);
     }
     return self::$params[$signature];
 }
Пример #3
0
 public function save()
 {
     // Check for request forgeries
     JRequest::checkToken() or die('RESTRICTED');
     $db = JFactory::getDBO();
     $filter = JFilterInput::getInstance();
     $row = JTable::getInstance('profiles', 'WFTable');
     $task = $this->getTask();
     $post = JRequest::get('post', array());
     $id = JRequest::getInt('id');
     $result = array('error' => false);
     // load existing profile
     $row->load($id);
     // bind data but ignore params and usergroups
     $row->bind($post, array('params', 'usergroups'));
     // process values
     foreach ($post as $key => $value) {
         // don't process null values
         if (is_null($value)) {
             continue;
         }
         switch ($key) {
             case 'name':
             case 'description':
                 $value = $filter->clean($value);
                 break;
             case 'components':
             case 'device':
                 $value = array_filter($value);
                 $value = implode(',', $this->cleanInput($value));
                 break;
             case 'usergroups':
                 $key = 'types';
                 $value = implode(',', $this->cleanInput(array_filter($value), 'int'));
                 break;
             case 'users':
                 $value = implode(',', $this->cleanInput(array_filter($value), 'int'));
                 break;
             case 'area':
                 if (empty($value) || count($value) == 2) {
                     $value = 0;
                 } else {
                     $value = $value[0];
                 }
                 break;
             case 'plugins':
                 $value = preg_replace('#[^\\w,]+#', '', $value);
                 break;
             case 'rows':
                 $value = preg_replace('#[^\\w,;]+#', '', $value);
                 break;
             case 'params':
                 $json = array();
                 // get params
                 $params = isset($row->params) ? $row->params : '';
                 // convert params to json data array
                 $data = (array) json_decode($params, true);
                 // assign editor data
                 if (array_key_exists('editor', $value)) {
                     $json['editor'] = $value['editor'];
                 }
                 // get plugins
                 $plugins = explode(',', $row->plugins);
                 // assign plugin data
                 foreach ($plugins as $plugin) {
                     // add plugin params to array
                     if (array_key_exists($plugin, $value)) {
                         $json[$plugin] = $value[$plugin];
                     }
                 }
                 // combine and encode as json string
                 $value = json_encode(WFParameter::mergeParams($data, $json, false));
                 break;
         }
         $row->bind(array($key => $value));
     }
     if (!$row->check()) {
         JError::raiseError(500, $db->getErrorMsg());
     }
     if (!$row->store()) {
         JError::raiseError(500, $db->getErrorMsg());
     }
     $row->checkin();
     switch ($task) {
         case 'apply':
             $msg = JText::sprintf('WF_PROFILES_SAVED_CHANGES', $row->name);
             $this->setRedirect('index.php?option=com_jce&view=profiles&task=edit&cid[]=' . $row->id, $msg);
             break;
         case 'save':
         default:
             $msg = JText::sprintf('WF_PROFILES_SAVED', $row->name);
             $this->setRedirect('index.php?option=com_jce&view=profiles', $msg);
             break;
     }
 }