Esempio n. 1
0
 /**
  * Method to display a view.
  *
  * @param   boolean  $cachable   If true, the view output will be cached
  * @param   boolean  $urlparams  An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
  *
  * @return  TemplatesController  This object to support chaining.
  *
  * @since   1.5
  */
 public function display($cachable = false, $urlparams = false)
 {
     $view = $this->input->get('view', 'styles');
     $layout = $this->input->get('layout', 'default');
     $id = $this->input->getInt('id');
     $document = JFactory::getDocument();
     // For JSON requests
     if ($document->getType() == 'json') {
         $view = new TemplatesViewStyle();
         // Get/Create the model
         if ($model = new TemplatesModelStyle()) {
             $model->addTablePath(JPATH_ADMINISTRATOR . '/components/com_templates/tables');
             // Push the model into the view (as default)
             $view->setModel($model, true);
         }
         $view->document = $document;
         return $view->display();
     }
     // Check for edit form.
     if ($view == 'style' && $layout == 'edit' && !$this->checkEditId('com_templates.edit.style', $id)) {
         // Somehow the person just went to the form - we don't allow that.
         $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id));
         $this->setMessage($this->getError(), 'error');
         $this->setRedirect(JRoute::_('index.php?option=com_templates&view=styles', false));
         return false;
     }
     return parent::display();
 }
Esempio n. 2
0
 function save()
 {
     // This should be put in an extension plugin when available
     JRequest::checkToken() or jexit('Invalid Token');
     jimport('joomla.filesystem.folder');
     jimport('joomla.filesystem.file');
     $lang = JFactory::getLanguage();
     $lang->load('com_templates');
     $post = JRequest::get('post');
     $template = JFilterInput::clean($post['jform']['template'], 'alnum');
     $db = JFactory::getDbo();
     $user = JFactory::getUser();
     if (empty($template)) {
         jexit('Invalid call');
     }
     // Parse standard jform and Joomla data using the original Joomla component for maximum compatibility
     JTable::addIncludePath(JPATH_ROOT . '/administrator/components/com_templates/tables');
     require_once JPATH_ROOT . '/administrator/components/com_templates/models/style.php';
     $model = new TemplatesModelStyle();
     $data = $post['jform'];
     if (JRequest::getVar('task') == 'save2copy') {
         // Force new ID
         $data['id'] = 0;
         $nul = $model->getState('style.id');
         $model->setState('style.id', 0);
     }
     if ($model->save($data)) {
         // If Joomla save succeeds, do XTC
         $id = $model->getState('style.id');
         // Get style ID from model
         // Parse joomla parameters into params.ini
         foreach (array_keys($post['jform']['params']) as $param) {
             $value = is_array($post['jform']['params'][$param]) ? implode('|', $post['jform']['params'][$param]) : $post['jform']['params'][$param];
             $parameters[] = $param . '=' . $value;
         }
         // Parse xtc parameters into params.ini
         foreach (array_keys($post['xtcparam']) as $prefix) {
             foreach (array_keys($post['xtcparam'][$prefix]) as $group) {
                 foreach (array_keys($post['xtcparam'][$prefix][$group]) as $param) {
                     $value = is_array($post['xtcparam'][$prefix][$group][$param]) ? implode('|', $post['xtcparam'][$prefix][$group][$param]) : $post['xtcparam'][$prefix][$group][$param];
                     $parameters[] = '{' . $prefix . '+' . $group . '}' . $param . '=' . $value;
                 }
             }
         }
         // Save params.ini
         $parameterFile = JPATH_ROOT . '/templates/' . $template . '/params_' . $id . '.ini';
         if (!JFile::write($parameterFile, implode("\n", $parameters))) {
             jexit('Error writing parameters file.');
         }
         // Return to template component
         $msg = JText::_('COM_TEMPLATES_STYLE_SAVE_SUCCESS');
         switch ($this->getTask()) {
             case 'save':
                 // go back to main page
                 $this->setRedirect('index.php?option=com_templates', $msg);
                 break;
             case 'save2copy':
                 // we need to add ID to editable ID list first
                 $app = JFactory::getApplication();
                 $ids = $app->getUserState('com_templates.edit.style.id');
                 $ids[] = $id;
                 $app->setUserState('com_templates.edit.style.id', $ids);
             case 'apply':
                 // go to edit page
                 $this->setRedirect('index.php?option=com_templates&view=style&layout=edit&id=' . $id, $msg);
                 break;
         }
     }
 }