示例#1
0
 /**
  * Method to store the field
  *
  * @access	public
  * @return	boolean	True on success
  * @since	1.0
  */
 function store($data)
 {
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     // NOTE: 'data' is post['jform'] for J2.5 (this is done by the controller or other caller)
     $field = $this->getTable('flexicontent_fields', '');
     $types = isset($data['tid']) ? $data['tid'] : array();
     // types to which the field is being assigned
     // Support for 'dirty' field properties
     if ($data['id']) {
         $field->load($data['id']);
         if ($field->issearch == -1 || $field->issearch == 2) {
             unset($data['issearch']);
         } else {
             if (@$data['issearch'] == 0 && $field->issearch == 1) {
                 $data['issearch'] = -1;
             } else {
                 if (@$data['issearch'] == 1 && $field->issearch == 0) {
                     $data['issearch'] = 2;
                 }
             }
         }
         // Becomes dirty ON
         if ($field->isadvsearch == -1 || $field->isadvsearch == 2) {
             unset($data['isadvsearch']);
         } else {
             if (@$data['isadvsearch'] == 0 && $field->isadvsearch == 1) {
                 $data['isadvsearch'] = -1;
             } else {
                 if (@$data['isadvsearch'] == 1 && $field->isadvsearch == 0) {
                     $data['isadvsearch'] = 2;
                 }
             }
         }
         // Becomes dirty ON
         if ($field->isadvfilter == -1 || $field->isadvfilter == 2) {
             unset($data['isadvfilter']);
         } else {
             if (@$data['isadvfilter'] == 0 && $field->isadvfilter == 1) {
                 $data['isadvfilter'] = -1;
             } else {
                 if (@$data['isadvfilter'] == 1 && $field->isadvfilter == 0) {
                     $data['isadvfilter'] = 2;
                 }
             }
         }
         // Becomes dirty ON
         // FORCE dirty OFF, if field is being unpublished -and- is not already normal OFF
         if (isset($data['published']) && $data['published'] == 0 && $field->published == 1) {
             if ($field->issearch != 0) {
                 $data['issearch'] = -1;
             }
             if ($field->isadvsearch != 0) {
                 $data['isadvsearch'] = -1;
             }
             if ($field->isadvfilter != 0) {
                 $data['isadvfilter'] = -1;
             }
         }
     }
     // bind it to the table
     if (!$field->bind($data)) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // Get field attibutes, for J1.5 is params for J2.5 is attribs
     $attibutes = !FLEXI_J16GE ? $data['params'] : $data['attribs'];
     // Build attibutes INI string
     if (FLEXI_J16GE) {
         // JSON encoding allows to use new lines etc
         // handled by 'flexicontent_types' (extends JTable for flexicontent_types)
         //$field->attribs = json_encode($attibutes);
     } else {
         if (is_array($attibutes)) {
             $txt = array();
             foreach ($attibutes as $k => $v) {
                 if (is_array($v)) {
                     $v = implode('|', $v);
                 }
                 $txt[] = "{$k}={$v}";
             }
             $field->attribs = implode("\n", $txt);
         }
     }
     // Put the new fields in last position
     if (!$field->id) {
         $field->ordering = $field->getNextOrder();
     }
     // Make sure the data is valid
     if (!$field->check()) {
         $this->setError($field->getError());
         return false;
     }
     // Store it in the db
     if (!$field->store()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     if (FLEXI_ACCESS) {
         FAccess::saveaccess($field, 'field');
     } else {
         if (FLEXI_J16GE) {
             // saving asset in J2.5 is handled by the fields table class
         }
     }
     $this->_field =& $field;
     $this->_id = $field->id;
     // Assign (a) chosen types to custom field or (b) all types if field is core
     $this->_assignTypesToField($types);
     return true;
 }
 /**
  * Method to apply a NEW CURRENT version when saving an APPROVED item version
  *
  * @access	public
  * @return	boolean	True on success
  * @since	1.0
  */
 function applyCurrentVersion(&$item, &$data, $createonly = false)
 {
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $cparams = $this->_cparams;
     $editjf_translations = $cparams->get('editjf_translations', 0);
     // ******************************
     // Check and store item in the db
     // ******************************
     // Make sure the data is valid
     if (!$item->check()) {
         $this->setError($item->getError());
         return false;
     }
     if (!$item->store()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     $this->_id = $item->id;
     $this->_item =& $item;
     // ***********************
     // Save access information
     // ***********************
     if (FLEXI_ACCESS) {
         $rights = FAccess::checkAllItemAccess('com_content', 'users', $user->gmid, $item->id, $item->catid);
         $canRight = in_array('right', $rights) || $user->gid > 24;
         if ($canRight) {
             FAccess::saveaccess($item, 'item');
         }
     } else {
         if (FLEXI_J16GE) {
             // Rules for J1.6+ are handled in the JTABLE class of the item with overriden JTable functions: bind() and store()
         }
     }
     // ***************************
     // If creating only return ...
     // ***************************
     if ($createonly) {
         return true;
     }
     // ****************************
     // Save joomfish data in the db
     // ****************************
     if (FLEXI_FISH && $editjf_translations == 2) {
         // 0:disable with warning about found translations,  1:disable without warning about found translations,  2:edit-save translations,
         $this->_saveJFdata($data['jfdata'], $item);
     }
     // ***********************************************
     // Delete old tag relations and Store the new ones
     // ***********************************************
     $tags = $data['tags'];
     $query = 'DELETE FROM #__flexicontent_tags_item_relations WHERE itemid = ' . $item->id;
     $this->_db->setQuery($query);
     $this->_db->query();
     foreach ($tags as $tag) {
         $query = 'INSERT INTO #__flexicontent_tags_item_relations (`tid`, `itemid`) VALUES(' . $tag . ',' . $item->id . ')';
         $this->_db->setQuery($query);
         $this->_db->query();
     }
     // ***********************************************************************************************************
     // Delete only category relations which are not part of the categories array anymore to avoid loosing ordering
     // ***********************************************************************************************************
     $cats = $data['categories'];
     $query = 'DELETE FROM #__flexicontent_cats_item_relations' . ' WHERE itemid = ' . $item->id . ($cats ? ' AND catid NOT IN (' . implode(', ', $cats) . ')' : '');
     $this->_db->setQuery($query);
     $this->_db->query();
     // Get an array of the item's used categories (already assigned in DB)
     $query = 'SELECT catid' . ' FROM #__flexicontent_cats_item_relations' . ' WHERE itemid = ' . $item->id;
     $this->_db->setQuery($query);
     $used = FLEXI_J16GE ? $this->_db->loadColumn() : $this->_db->loadResultArray();
     foreach ($cats as $cat) {
         // insert only the new records
         if (!in_array($cat, $used)) {
             $query = 'INSERT INTO #__flexicontent_cats_item_relations (`catid`, `itemid`)' . ' VALUES(' . $cat . ',' . $item->id . ')';
             $this->_db->setQuery($query);
             $this->_db->query();
         }
     }
     return true;
 }
示例#3
0
 /**
  * Method to store the type
  *
  * @access	public
  * @return	boolean	True on success
  * @since	1.0
  */
 function store($data)
 {
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     // NOTE: 'data' is post['jform'] for J2.5 (this is done by the controller or other caller)
     $type = $this->getTable('flexicontent_types', '');
     // Load existing data and set new record flag
     $isnew = !(bool) $data['id'];
     if ($data['id']) {
         $type->load($data['id']);
     }
     // Build attibutes INI string
     if (FLEXI_J16GE) {
         // Retrieve form data these are subject to basic filtering
         $jform = JRequest::getVar('jform', array(), 'post', 'array');
         $ilayout = $data['attribs']['ilayout'];
         if (!empty($jform['layouts'][$ilayout])) {
             $data['attribs'] = array_merge($data['attribs'], $jform['layouts'][$ilayout]);
         }
         // JSON encoding allows to use new lines etc, handled by 'flexicontent_types' (extends JTable for flexicontent_types)
         //$data['attribs'] = json_encode($data['attribs']);
         // bind it to the table
         if (!$type->bind($data)) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
     } else {
         // bind it to the table
         if (!$type->bind($data)) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
         if (is_array($data['params'])) {
             // Get layout parameters
             $ilayout = $data['params']['ilayout'];
             $tmpl_params = $data['layouts'][$ilayout];
             // Clear parameters of all layouts
             unset($data['layouts']);
             // Merge the parameters of currently selected layout
             $data['params'] = array_merge($data['params'], $tmpl_params);
             $txt = array();
             foreach ($data['params'] as $k => $v) {
                 if (is_array($v)) {
                     $v = implode('|', $v);
                 }
                 $txt[] = "{$k}={$v}";
             }
             $type->attribs = implode("\n", $txt);
         }
     }
     // Put the new types in last position, currently this column is missing
     /*if (!$type->id) {
     			$type->ordering = $type->getNextOrder();
     		}*/
     // Make sure the data is valid
     if (!$type->check()) {
         $this->setError($type->getError());
         return false;
     }
     // Store it in the db
     if (!$type->store()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     if (FLEXI_ACCESS) {
         FAccess::saveaccess($type, 'type');
     } else {
         if (FLEXI_J16GE) {
             // saving asset in J2.5 is handled by the types table class
         }
     }
     $this->_type =& $type;
     $this->_id = $type->id;
     // Only insert default relations if the type is new
     if ($isnew) {
         $this->_addCoreFieldRelations();
     }
     return true;
 }
示例#4
0
 /**
  * Method to store the category
  *
  * @access	public
  * @return	boolean	True on success
  * @since	1.0
  */
 function store($data)
 {
     $copyparams = JRequest::getVar('copycid', null, 'post', 'int');
     if ($copyparams) {
         unset($data['params']);
     }
     $category = JTable::getInstance('flexicontent_categories', '');
     // Bind the data.
     if (!$category->bind($data)) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     if (!$category->id) {
         $category->ordering = $category->getNextOrder();
     }
     // Either set parameters via copying from a given category
     if ($copyparams) {
         $category->params = $this->getParams($copyparams);
     } else {
         // Build parameter INI string
         if (is_array($data['params'])) {
             // Get layout parameters
             $clayout = $data['params']['clayout'];
             $tmpl_params = $data['layouts'][$clayout];
             // Clear parameters of all layouts
             unset($data['layouts']);
             // Merge the parameters of currently selected layout
             $params = array_merge($data['params'], $tmpl_params);
             $txt = array();
             foreach ($params as $k => $v) {
                 if (is_array($v)) {
                     $v = implode('|', $v);
                 }
                 $txt[] = "{$k}={$v}";
             }
             $category->params = implode("\n", $txt);
         }
     }
     // Make sure the data is valid
     if (!$category->check()) {
         $this->setError($category->getError());
         return false;
     }
     // Store it in the db
     if (!$category->store()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     if (FLEXI_ACCESS) {
         FAccess::saveaccess($category, 'category');
     }
     $this->_category = $category;
     return true;
 }