Example #1
0
 /**
  * Method to save the configuration data.
  *
  * @param   array  $data  An array containing all global config data.
  *
  * @return  bool   True on success, false on failure.
  */
 public function save($data)
 {
     $dispatcher = RFactory::getDispatcher();
     $table = JTable::getInstance('Extension');
     $isNew = true;
     // Save the rules.
     if (isset($data['params']) && isset($data['params']['rules'])) {
         $rules = new JAccessRules($data['params']['rules']);
         $asset = JTable::getInstance('asset');
         if (!$asset->loadByName($data['option'])) {
             $root = JTable::getInstance('asset');
             $root->loadByName('root.1');
             $asset->name = $data['option'];
             $asset->title = $data['option'];
             $asset->setLocation($root->id, 'last-child');
         }
         $asset->rules = (string) $rules;
         if (!$asset->check() || !$asset->store()) {
             $this->setError($asset->getError());
             return false;
         }
         // We don't need this anymore
         unset($data['option']);
         unset($data['params']['rules']);
     }
     // Load the previous Data
     if (!$table->load($data['id'])) {
         $this->setError($table->getError());
         return false;
     }
     unset($data['id']);
     // Bind the data.
     if (!$table->bind($data)) {
         $this->setError($table->getError());
         return false;
     }
     // Check the data.
     if (!$table->check()) {
         $this->setError($table->getError());
         return false;
     }
     // Trigger the onConfigurationBeforeSave event.
     $result = $dispatcher->trigger($this->event_before_save, array($this->option . '.' . $this->name, $table, $isNew));
     if (in_array(false, $result, true)) {
         $this->setError($table->getError());
         return false;
     }
     // Store the data.
     if (!$table->store()) {
         $this->setError($table->getError());
         return false;
     }
     // Clean the component cache.
     $this->cleanCache('_system');
     // Trigger the onConfigurationAfterSave event.
     $dispatcher->trigger($this->event_after_save, array($this->option . '.' . $this->name, $table, $isNew));
     return true;
 }
Example #2
0
 /**
  * Method to save the form data.
  *
  * @param   array  $data  The form data.
  *
  * @return  boolean       True on success.
  */
 public function save($data)
 {
     $dispatcher = RFactory::getDispatcher();
     $table = $this->getTable();
     $pk = !empty($data['id']) ? $data['id'] : (int) $this->getState($this->getName() . '.id');
     $isNew = true;
     // Include the content plugins for the on save events.
     JPluginHelper::importPlugin('content');
     // Load the row if saving an existing category.
     if ($pk > 0) {
         $table->load($pk);
         $isNew = false;
     }
     // Set the new parent id if parent id not matched OR while New/Save as Copy .
     if ($table->parent_id != $data['parent_id'] || $data['id'] == 0) {
         $table->setLocation($data['parent_id'], 'last-child');
     }
     // Bind the data.
     if (!$table->bind($data)) {
         $this->setError($table->getError());
         return false;
     }
     // Prepare the row for saving
     $this->prepareTable($table);
     // Check the data.
     if (!$table->check()) {
         $this->setError($table->getError());
         return false;
     }
     // Trigger the event_before_save event.
     $result = $dispatcher->trigger($this->event_before_save, array($this->option . '.' . $this->name, &$table, $isNew));
     if (in_array(false, $result, true)) {
         $this->setError($table->getError());
         return false;
     }
     // Store the data.
     if (!$table->store()) {
         $this->setError($table->getError());
         return false;
     }
     // Trigger the event_after_save event.
     $dispatcher->trigger($this->event_after_save, array($this->option . '.' . $this->name, &$table, $isNew));
     // Rebuild the path for the category:
     if (!$table->rebuildPath($table->id)) {
         $this->setError($table->getError());
         return false;
     }
     // Rebuild the paths of the category's children:
     if (!$table->rebuild($table->id, $table->lft, $table->level, $table->path)) {
         $this->setError($table->getError());
         return false;
     }
     $this->setState($this->getName() . '.id', $table->id);
     // Clear the cache
     $this->cleanCache();
     return true;
 }
Example #3
0
 /**
  * Method to get a list of field types available
  *
  * @return  array  The field option objects.
  *
  * @since   1.0
  */
 protected function getOptions()
 {
     $options = array();
     $types = array();
     JPluginHelper::importPlugin('rsfield');
     $dispatcher = RFactory::getDispatcher();
     $dispatcher->trigger('onGetFieldTypesList', array($types));
     if (!empty($types)) {
         foreach ($types as $type) {
             $text = JText::_('PLG_RSFIELD_TYPE_' . strtoupper($type));
             $options[$text] = JHtml::_('select.option', $type, $text);
         }
     }
     ksort($options);
     return array_merge(parent::getOptions(), $options);
 }
Example #4
0
 /**
  * Uploads file to the given media folder.
  *
  * @param   array   $files              The array of Files (file descriptor returned by PHP)
  * @param   string  $destinationFolder  Name of a folder in media/com_redcore/.
  * @param   array   $options            Array of options for check
  *                         maxFileSize              => Maximum allowed file size. Set 0 to disable check
  *                         allowedFileExtensions    => Comma separated string list of allowed file extensions.
  *                         allowedMIMETypes         => Comma separated string list of allowed MIME types.
  *                         setUniqueFileName        => If set this will mangle destination file name
  *                         overrideExistingFile     => If set this will override File with the same name if it exists
  *
  * @return array|bool
  */
 public static function uploadFiles($files, $destinationFolder, $options = array())
 {
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.path');
     $app = JFactory::getApplication();
     $resultFile = array();
     foreach ($files as &$file) {
         // Get unique name
         if (!empty($options['setUniqueFileName'])) {
             $fileExtension = self::getExt($file['name']);
             $file['destinationFileName'] = self::getUniqueName($file['name']) . '.' . $fileExtension;
         } else {
             $file['destinationFileName'] = self::makeSafe($file['name']);
         }
         // Get full path
         $file['filePath'] = JPath::clean($destinationFolder . '/' . $file['destinationFileName']);
         // Can we upload this file type?
         if (!self::canUpload($file, $options)) {
             return false;
         }
     }
     JPluginHelper::importPlugin('content');
     $dispatcher = RFactory::getDispatcher();
     foreach ($files as &$file) {
         // Trigger the onContentBeforeSave event.
         $objectFile = new JObject($file);
         $result = $dispatcher->trigger('onContentBeforeSave', array('com_redcore.file', &$objectFile, true));
         if (in_array(false, $result, true)) {
             // There are some errors in the plugins
             $errors = $objectFile->getErrors();
             $app->enqueueMessage(JText::sprintf('LIB_REDCORE_ERROR_BEFORE_SAVE', implode('<br />', $errors)), 'error');
             return false;
         }
         if (!self::upload($objectFile->tmp_name, $objectFile->filePath)) {
             // Error in upload
             $app->enqueueMessage(JText::_('LIB_REDCORE_ERROR_UNABLE_TO_UPLOAD_FILE'), 'error');
             return false;
         } else {
             // Trigger the onContentAfterSave event.
             $dispatcher->trigger('onContentAfterSave', array('com_redcore.file', &$objectFile, true));
         }
         $resultFile[] = array('original_filename' => $objectFile->name, 'uploaded_filename' => $objectFile->destinationFileName, 'mime_type' => !empty($objectFile->mimeTypeName) ? $objectFile->mimeTypeName : self::getMimeType($file), 'filepath' => $objectFile->filePath);
     }
     // Return the file info
     return $resultFile;
 }
Example #5
0
 /**
  * Method to store a node in the database table.
  *
  * @param   boolean  $updateNulls  True to update null values as well.
  *
  * @return  boolean  True on success.
  */
 public function store($updateNulls = false)
 {
     $dispatcher = RFactory::getDispatcher();
     // Import plugin types
     if ($this->_eventBeforeStore || $this->_eventAfterStore) {
         foreach ($this->_pluginTypesToImport as $type) {
             JPluginHelper::importPlugin($type);
         }
     }
     // Trigger before store
     if ($this->_eventBeforeStore) {
         $results = $dispatcher->trigger($this->_eventBeforeStore, array($this, $updateNulls));
         if (count($results) && in_array(false, $results, true)) {
             return false;
         }
     }
     // Store
     if (!parent::store($updateNulls)) {
         return false;
     }
     // Trigger after store
     if ($this->_eventAfterStore) {
         $results = $dispatcher->trigger($this->_eventAfterStore, array($this, $updateNulls));
         if (count($results) && in_array(false, $results, true)) {
             return false;
         }
     }
     return true;
 }
Example #6
0
 /**
  * Method to allow derived classes to preprocess the form.
  *
  * @param   JForm   $form   A JForm object.
  * @param   mixed   $data   The data expected for the form.
  * @param   string  $group  The name of the plugin group to import (defaults to "content").
  *
  * @return  void
  *
  * @throws  Exception if there is an error in the form event.
  */
 protected function preprocessForm(JForm $form, $data, $group = 'content')
 {
     // Import the appropriate plugin group.
     JPluginHelper::importPlugin($group);
     // Get the dispatcher.
     $dispatcher = RFactory::getDispatcher();
     // Trigger the form preparation event.
     $results = $dispatcher->trigger('onContentPrepareForm', array($form, $data));
     // Check for errors encountered while preparing the form.
     if (count($results) && in_array(false, $results, true)) {
         // Get the last error.
         $error = $dispatcher->getError();
         if (!$error instanceof Exception) {
             throw new Exception($error);
         }
     }
 }
Example #7
0
 /**
  * Called after store().
  *
  * @param   boolean  $updateNulls  True to update null values as well.
  *
  * @return  boolean  True on success.
  */
 protected function afterStore($updateNulls = false)
 {
     if ($this->_eventAfterStore) {
         // Import the plugin types
         $this->importPluginTypes();
         // Trigger the event
         $results = RFactory::getDispatcher()->trigger($this->_eventAfterStore, array($this, $updateNulls));
         if (count($results) && in_array(false, $results, true)) {
             return false;
         }
     }
     return true;
 }
Example #8
0
 /**
  * Method to save the form data.
  *
  * @param   array  $data  The form data.
  *
  * @return  boolean  True on success.
  */
 public function save($data)
 {
     $translationTable = RedcoreHelpersTranslation::getTranslationTable();
     $contentElement = RTranslationHelper::getContentElement($translationTable->option, $translationTable->xml);
     $translation = JFactory::getApplication()->input->get('translation', array(), 'array');
     $original = JFactory::getApplication()->input->get('original', array(), 'array');
     $id = !empty($data['rctranslations_id']) ? (int) $data['rctranslations_id'] : 0;
     $data = array_merge($data, $translation);
     $fieldsXml = $contentElement->getTranslateFields();
     foreach ($fieldsXml as $field) {
         if ((string) $field['type'] == 'params' && (string) $field['translate'] == '1') {
             $fieldName = (string) $field['name'];
             $original[$fieldName] = $original['params_' . $fieldName];
             $paramsChanged = false;
             if (!empty($data[$fieldName])) {
                 $registry = new JRegistry();
                 $registry->loadString($original[$fieldName]);
                 $originalParams = $registry->toArray();
                 foreach ($data[$fieldName] as $paramKey => $paramValue) {
                     if (!isset($originalParams[$paramKey]) && $paramValue != '' || $originalParams[$paramKey] != $paramValue) {
                         $paramsChanged = true;
                         break;
                     }
                 }
                 if ($paramsChanged) {
                     $data[$fieldName] = json_encode($data[$fieldName]);
                 } else {
                     $data[$fieldName] = '';
                 }
             }
         }
     }
     $dispatcher = RFactory::getDispatcher();
     /** @var RedcoreTableTranslation $table */
     $table = $this->getTable();
     if (empty($id)) {
         $db = $this->getDbo();
         $query = $db->getQuery(true)->select('rctranslations_id')->from($db->qn(RTranslationTable::getTranslationsTableName($translationTable->table, '')))->where('rctranslations_language = ' . $db->q($data['rctranslations_language']));
         foreach ($translationTable->primaryKeys as $primaryKey) {
             if (!empty($data[$primaryKey])) {
                 $query->where($db->qn($primaryKey) . ' = ' . $db->q($data[$primaryKey]));
             }
         }
         $db->setQuery($query);
         $id = $db->loadResult();
     }
     foreach ($translationTable->primaryKeys as $primaryKey) {
         $original[$primaryKey] = $data[$primaryKey];
     }
     $isNew = true;
     // Load the row if saving an existing item.
     $table->load((int) $id);
     if ($table->rctranslations_modified) {
         $isNew = false;
     }
     $data['rctranslations_originals'] = RTranslationTable::createOriginalValueFromColumns($original, $translationTable->columns);
     // We run posthandler methods
     foreach ($fieldsXml as $field) {
         $postHandler = (string) $field['posthandler'];
         $fieldName = (string) $field['name'];
         if (!empty($postHandler) && (string) $field['translate'] == '1') {
             $postHandlerFunctions = explode(',', $postHandler);
             foreach ($postHandlerFunctions as $postHandlerFunction) {
                 $postHandlerFunctionArray = explode('::', $postHandlerFunction);
                 if (empty($postHandlerFunctionArray[1])) {
                     $postHandlerFunctionArray[1] = $postHandlerFunctionArray[0];
                     $postHandlerFunctionArray[0] = 'RTranslationContentHelper';
                     $postHandlerFunction = 'RTranslationContentHelper::' . $postHandlerFunction;
                 }
                 if (method_exists($postHandlerFunctionArray[0], $postHandlerFunctionArray[1])) {
                     call_user_func_array(array($postHandlerFunctionArray[0], $postHandlerFunctionArray[1]), array($field, &$data[$fieldName], &$data, $translationTable));
                 }
             }
         }
     }
     // Bind the data.
     if (!$table->bind($data)) {
         $this->setError($table->getError());
         return false;
     }
     // Prepare the row for saving
     $this->prepareTable($table);
     // Check the data.
     if (!$table->check()) {
         $this->setError($table->getError());
         return false;
     }
     // Trigger the onContentBeforeSave event.
     $result = $dispatcher->trigger($this->event_before_save, array($this->option . '.' . $this->name, &$table, $isNew));
     if (in_array(false, $result, true)) {
         $this->setError($table->getError());
         return false;
     }
     // Store the data.
     if (!$table->store()) {
         $this->setError($table->getError());
         return false;
     }
     // Trigger the onContentAfterSave event.
     $dispatcher->trigger($this->event_after_save, array($this->option . '.' . $this->name, &$table, $isNew));
     $this->setState($this->getName() . '.id', $table->rctranslations_id);
     // Clear the cache
     $this->cleanCache();
     return true;
 }
Example #9
0
 /**
  * Method to allow derived classes to preprocess the form.
  *
  * @param   JForm                       $form            A JForm object.
  * @param   mixed                       $data            The data expected for the form.
  * @param   string                      $group           The name of the plugin group to import (defaults to "content").
  * @param   array                       $column          Content element column
  * @param   RTranslationContentElement  $contentElement  Content element
  *
  * @return  void
  *
  * @see     JFormField
  * @since   12.2
  * @throws  Exception if there is an error in the form event.
  */
 public static function preprocessForm(JForm $form, $data, $group = 'content', $column = array(), $contentElement = null)
 {
     if (strtolower($contentElement->name) == 'modules') {
         $form = self::preprocessFormModules($form, $data);
     } elseif (strtolower($contentElement->name) == 'menus') {
         $form = self::preprocessFormMenu($form, $data);
     } elseif (strtolower($contentElement->name) == 'plugins') {
         $form = self::preprocessFormPlugins($form, $data);
     }
     // Import the appropriate plugin group.
     JPluginHelper::importPlugin($group);
     // Get the dispatcher.
     $dispatcher = RFactory::getDispatcher();
     // Trigger the form preparation event.
     $results = $dispatcher->trigger('onContentPrepareForm', array($form, $data));
     // Check for errors encountered while preparing the form.
     if (count($results) && in_array(false, $results, true)) {
         // Get the last error.
         $error = $dispatcher->getError();
         if (!$error instanceof Exception) {
             throw new Exception($error);
         }
     }
 }
Example #10
0
 /**
  * Method to save the configuration data.
  *
  * @return  bool   True on success, false on failure.
  */
 public static function saveRedcoreTranslationConfig()
 {
     $data = array();
     $component = JComponentHelper::getComponent('com_redcore');
     $component->params->set('translations', RTranslationHelper::getInstalledTranslationTables());
     $data['params'] = $component->params->toString('JSON');
     $dispatcher = RFactory::getDispatcher();
     $table = JTable::getInstance('Extension');
     $isNew = true;
     // Load the previous Data
     if (!$table->load($component->id)) {
         return false;
     }
     // Bind the data.
     if (!$table->bind($data)) {
         return false;
     }
     // Check the data.
     if (!$table->check()) {
         return false;
     }
     // Trigger the onConfigurationBeforeSave event.
     $result = $dispatcher->trigger('onExtensionBeforeSave', array('com_redcore.config', &$table, $isNew));
     if (in_array(false, $result, true)) {
         return false;
     }
     // Store the data.
     if (!$table->store()) {
         return false;
     }
     // Trigger the onConfigurationAfterSave event.
     $dispatcher->trigger('onExtensionAfterSave', array('com_redcore.config', &$table, $isNew));
     return true;
 }