예제 #1
0
파일: element.php 프로젝트: LGBGit/tierno
 /**
  * Method to save the form data.
  *
  * @param   array $data The form data.
  *
  * @return  boolean  True on success, False on error.
  */
 public function save($data)
 {
     $config = JComponentHelper::getParams('com_fabrik');
     if ($config->get('fbConf_wysiwyg_label', 0) == 0) {
         // Ensure the data is in the same format as when saved by the wysiwyg element e.g. < becomes &lt;
         $data['label'] = htmlspecialchars($data['label']);
     }
     jimport('joomla.utilities.date');
     $input = $this->app->input;
     $new = $data['id'] == 0 ? true : false;
     $params = $data['params'];
     $data['name'] = FabrikString::iclean($data['name']);
     $name = $data['name'];
     $params['validations'] = FArrayHelper::getValue($data, 'validationrule', array());
     $elementModel = $this->getElementPluginModel($data);
     $elementModel->getElement()->bind($data);
     $origId = $input->getInt('id');
     $row = $elementModel->getElement();
     if ($new) {
         // Have to forcefully set group id otherwise listmodel id is blank
         $elementModel->getElement()->group_id = $data['group_id'];
     }
     $listModel = $elementModel->getListModel();
     $item = $listModel->getTable();
     // Are we updating the name of the primary key element?
     if ($row->name === FabrikString::shortColName($item->db_primary_key)) {
         if ($name !== $row->name) {
             // Yes we are so update the table
             $item->db_primary_key = str_replace($row->name, $name, $item->db_primary_key);
             $item->store();
         }
     }
     $jsons = array('sub_values', 'sub_labels', 'sub_initial_selection');
     foreach ($jsons as $json) {
         if (array_key_exists($json, $data)) {
             $data[$json] = json_encode($data[$json]);
         }
     }
     // Only update the element name if we can alter existing columns, otherwise the name and field name become out of sync
     $data['name'] = $listModel->canAlterFields() || $new || $listModel->noTable() ? $name : $input->get('name_orig', '');
     $ar = array('published', 'use_in_page_title', 'show_in_list_summary', 'link_to_detail', 'can_order', 'filter_exact_match');
     foreach ($ar as $a) {
         if (!array_key_exists($a, $data)) {
             $data[$a] = 0;
         }
     }
     /**
      * $$$ rob - test for change in element type
      * (eg if changing from db join to field we need to remove the join
      * entry from the #__{package}_joins table
      */
     $elementModel->beforeSave($row);
     // Unlink linked elements
     if ($input->get('unlink') == 'on') {
         $data['parent_id'] = 0;
     }
     $dateNow = new JDate();
     if ($row->id != 0) {
         $data['modified'] = $dateNow->toSql();
         $data['modified_by'] = $this->user->get('id');
     } else {
         $data['created'] = $dateNow->toSql();
         $data['created_by'] = $this->user->get('id');
         $data['created_by_alias'] = $this->user->get('username');
     }
     /**
      * $$$ hugh
      * This insane chunk of code is needed because the validation rule params are not in sequential,
      * completely indexed arrays.  What we have is single item arrays, with specific numeric
      * keys, like foo-something[0], bar-otherthing[2], etc.  And if you json_encode an array with incomplete
      * or out of sequence numeric indexes, it encodes it as an object instead of an array.  Which means the first
      * validation plugin will encode as an array, as it's params are single [0] index, and the rest as objects.
      * This foobars things, as we then don't know if validation params are arrays or objects!
      *
      * One option would be to modify every validation, and test every param we use, and if necessary convert it,
      * but that would be a major pain in the ass.
      *
      * So ... we need to fill in the blanks in the arrays, and ksort them.  But, we need to know the param names
      * for each validation.  But as they are just stuck in with the rest of the element params, there is no easy
      * way of knowing which are validation params and which are element params.
      *
      * So ... we need to load the validation objects, then load the XML file for each one, and iterate through
      * the fieldsets!  Well, that's the only way I could come up with doing it.  Hopefully Rob can come up with
      * a quicker and simpler way of doing this!
      */
     $validations = FArrayHelper::getValue($params['validations'], 'plugin', array());
     $num_validations = count($validations);
     $validation_plugins = $this->getValidations($elementModel, $validations);
     foreach ($validation_plugins as $plugin) {
         $plugin_form = $plugin->getJForm();
         JForm::addFormPath(JPATH_SITE . '/plugins/fabrik_validationrule/' . $plugin->get('pluginName'));
         $xmlFile = JPATH_SITE . '/plugins/fabrik_validationrule/' . $plugin->get('pluginName') . '/forms/fields.xml';
         $xml = $plugin->jform->loadFile($xmlFile, false);
         foreach ($plugin_form->getFieldsets() as $fieldset) {
             foreach ($plugin_form->getFieldset($fieldset->name) as $field) {
                 if (isset($params[$field->fieldname])) {
                     if (is_array($params[$field->fieldname])) {
                         for ($x = 0; $x < $num_validations; $x++) {
                             if (!array_key_exists($x, $params[$field->fieldname])) {
                                 $params[$field->fieldname][$x] = '';
                             }
                         }
                         ksort($params[$field->fieldname]);
                     }
                 }
             }
         }
     }
     $data['params'] = json_encode($params);
     $row->params = $data['params'];
     $cond = 'group_id = ' . (int) $row->group_id;
     if ($new) {
         $data['ordering'] = $row->getNextOrder($cond);
     }
     $row->reorder($cond);
     /**
      * $$$ hugh - shouldn't updateChildIds() happen AFTER we save the main row?
      * Same place we do updateJavascript()?
      */
     $this->updateChildIds($row);
     $elementModel->getElement()->bind($data);
     $origName = $input->get('name_orig', '');
     list($update, $q, $oldName, $newdesc, $origDesc) = $listModel->shouldUpdateElement($elementModel, $origName);
     if ($update && $input->get('task') !== 'save2copy') {
         $origPlugin = $input->get('plugin_orig');
         $prefix = $this->config->get('dbprefix');
         $tableName = $listModel->getTable()->db_table_name;
         $hasPrefix = strstr($tableName, $prefix) === false ? false : true;
         $tableName = str_replace($prefix, '#__', $tableName);
         if (in_array($tableName, $this->core)) {
             $this->app->enqueueMessage(FText::_('COM_FABRIK_WARNING_UPDATE_CORE_TABLE'), 'notice');
         } else {
             if ($hasPrefix) {
                 $this->app->enqueueMessage(FText::_('COM_FABRIK_WARNING_UPDATE_TABLE_WITH_PREFIX'), 'notice');
             }
         }
         $this->app->setUserState('com_fabrik.confirmUpdate', 1);
         $this->app->setUserState('com_fabrik.plugin_orig', $origPlugin);
         $this->app->setUserState('com_fabrik.q', $q);
         $this->app->setUserState('com_fabrik.newdesc', $newdesc);
         $this->app->setUserState('com_fabrik.origDesc', $origDesc);
         $this->app->setUserState('com_fabrik.origplugin', $origPlugin);
         $this->app->setUserState('com_fabrik.oldname', $oldName);
         $this->app->setUserState('com_fabrik.newname', $data['name']);
         $this->app->setUserState('com_fabrik.origtask', $input->get('task'));
         $this->app->setUserState('com_fabrik.plugin', $data['plugin']);
         $task = $input->get('task');
         $url = 'index.php?option=com_fabrik&view=element&layout=confirmupdate&id=' . (int) $origId . '&origplugin=' . $origPlugin . '&origtask=' . $task . '&plugin=' . $row->plugin;
         $this->app->setUserState('com_fabrik.redirect', $url);
     } else {
         $this->app->setUserState('com_fabrik.confirmUpdate', 0);
     }
     if ((int) $listModel->getTable()->id !== 0) {
         $this->updateIndexes($elementModel, $listModel, $row);
     }
     $return = parent::save($data);
     if ($return) {
         $this->updateJavascript($data);
         $elementModel->setId($this->getState($this->getName() . '.id'));
         $row->id = $elementModel->getId();
         $data['id'] = $row->id;
         $this->createRepeatElement($elementModel, $row);
         // If new, check if the element's db table is used by other tables and if so add the element  to each of those tables' groups
         if ($new) {
             $this->addElementToOtherDbTables($elementModel, $row);
         }
         if (!$elementModel->onSave($data)) {
             $this->setError(FText::_('COM_FABRIK_ERROR_SAVING_ELEMENT_PLUGIN_OPTIONS'));
             return false;
         }
     }
     parent::cleanCache('com_fabrik');
     return $return;
     /**
      * used for prefab
      * return $elementModel;
      */
 }
예제 #2
0
파일: element.php 프로젝트: rhotog/fabrik
 function save($data)
 {
     jimport('joomla.utilities.date');
     $user = JFactory::getUser();
     $app = JFactory::getApplication();
     $new = $data['id'] == 0 ? true : false;
     $params = $data['params'];
     $data['name'] = FabrikString::iclean($data['name']);
     $name = $data['name'];
     $params['validations'] = JArrayHelper::getValue($data, 'validationrule', array());
     $elementModel = $this->getElementPluginModel($data);
     $row = $elementModel->getElement();
     if ($new) {
         //have to forcefully set group id otherwise listmodel id is blank
         $elementModel->getElement()->group_id = $data['group_id'];
     }
     $listModel = $elementModel->getListModel();
     $item = $listModel->getTable();
     //are we updating the name of the primary key element?
     if ($row->name === FabrikString::shortColName($item->db_primary_key)) {
         if ($name !== $row->name) {
             //yes we are so update the table
             $item->db_primary_key = str_replace($row->name, $name, $item->db_primary_key);
             $item->store();
         }
     }
     $jsons = array('sub_values', 'sub_labels', 'sub_initial_selection');
     foreach ($jsons as $json) {
         if (array_key_exists($json, $data)) {
             $data[$json] = json_encode($data[$json]);
         }
     }
     //only update the element name if we can alter existing columns, otherwise the name and
     //field name become out of sync
     $data['name'] = $listModel->canAlterFields() || $new ? $name : JRequest::getVar('name_orig', '', 'post', 'cmd');
     $ar = array('published', 'use_in_page_title', 'show_in_list_summary', 'link_to_detail', 'can_order', 'filter_exact_match');
     foreach ($ar as $a) {
         if (!array_key_exists($a, $data)) {
             $data[$a] = 0;
         }
     }
     // $$$ rob - test for change in element type
     //(eg if changing from db join to field we need to remove the join
     //entry from the #__{package}_joins table
     // @TODO test this for j1.6
     $elementModel->beforeSave($row);
     //unlink linked elements
     if (JRequest::getVar('unlink') == 'on') {
         $data['parent_id'] = 0;
     }
     $datenow = new JDate();
     if ($row->id != 0) {
         $data['modified'] = $datenow->toSql();
         $data['modified_by'] = $user->get('id');
     } else {
         $data['created'] = $datenow->toSql();
         $data['created_by'] = $user->get('id');
         $data['created_by_alias'] = $user->get('username');
     }
     $data['params'] = json_encode($params);
     $cond = 'group_id = ' . (int) $row->group_id;
     if ($new) {
         $data['ordering'] = $row->getNextOrder($cond);
     }
     $row->reorder($cond);
     $this->updateChildIds($row);
     $elementModel->getElement()->bind($data);
     $origName = JRequest::getVar('name_orig', '', 'post', 'cmd');
     list($update, $q, $oldName, $newdesc, $origDesc) = $listModel->shouldUpdateElement($elementModel, $origName);
     if ($update) {
         $origplugin = JRequest::getVar('plugin_orig');
         $config = JFactory::getConfig();
         $prefix = $config->getValue('dbprefix');
         $tablename = $listModel->getTable()->db_table_name;
         $hasprefix = strstr($tablename, $prefix) === false ? false : true;
         $tablename = str_replace($prefix, '#__', $tablename);
         if (in_array($tablename, $this->core)) {
             $app->enqueueMessage(JText::_('COM_FABRIK_WARNING_UPDATE_CORE_TABLE'), 'notice');
         } else {
             if ($hasprefix) {
                 $app->enqueueMessage(JText::_('COM_FABRIK_WARNING_UPDATE_TABLE_WITH_PREFIX'), 'notice');
             }
         }
         $app->setUserState('com_fabrik.confirmUpdate', 1);
         $app->setUserState('com_fabrik.plugin_orig', $origplugin);
         $app->setUserState('com_fabrik.q', $q);
         $app->setUserState('com_fabrik.newdesc', $newdesc);
         $app->setUserState('com_fabrik.origDesc', $origDesc);
         $app->setUserState('com_fabrik.origplugin', $origplugin);
         $app->setUserState('com_fabrik.oldname', $oldName);
         $app->setUserState('com_fabrik.origtask', JRequest::getCmd('task'));
         $app->setUserState('com_fabrik.plugin', $data['plugin']);
         $task = JRequest::getCmd('task');
         $app->setUserState('com_fabrik.redirect', 'index.php?option=com_fabrik&view=element&layout=confirmupdate&id=' . (int) $row->id . "&origplugin={$origplugin}&&origtaks={$task}&plugin={$row->plugin}");
     } else {
         $app->setUserState('com_fabrik.confirmUpdate', 0);
     }
     if ((int) $listModel->getTable()->id !== 0) {
         $this->updateIndexes($elementModel, $listModel, $row);
     }
     $return = parent::save($data);
     if ($return) {
         $this->updateJavascript($data);
         $elementModel->_id = $this->getState($this->getName() . '.id');
         $row->id = $elementModel->_id;
         $this->createRepeatElement($elementModel, $row);
         // If new, check if the element's db table is used by other tables and if so add the element
         // to each of those tables' groups
         if ($new) {
             $this->addElementToOtherDbTables($elementModel, $row);
         }
         if (!$elementModel->onSave($data)) {
             $this->setError(JText::_('COM_FABRIK_ERROR_SAVING_ELEMENT_PLUGIN_OPTIONS'));
             return false;
         }
     }
     return $return;
     //used for prefab
     //return $elementModel;
 }
예제 #3
0
파일: string.php 프로젝트: rogeriocc/fabrik
 /**
  * Wrapper for iclean(), that does strtolower on output of clean()
  *
  * @param   $str      string  to clean
  * @param   $fromEnc  string  from encoding
  * @param   $toEnc    string  to encoding
  *
  * @return  string  cleaned
  */
 public static function clean($str, $fromEnc = "UTF-8", $toEnc = "ASCII//IGNORE//TRANSLIT")
 {
     return JString::strtolower(FabrikString::iclean($str, $fromEnc, $toEnc));
 }