public function save($object) { if ($object->name == '') { throw new CategoryTableException('Invalid name'); } if ($object->alias == '' || $object->alias != YString::sluggify($object->alias)) { throw new CategoryTableException('Invalid slug'); } if (CategoryHelper::checkAliasExists($object->alias, $object->id)) { throw new CategoryTableException('Slug already exists, please choose a unique slug'); } if (!is_numeric($object->parent)) { throw new CategoryTableException('Invalid parent id'); } return parent::save($object); }
public function save($object) { if (!is_string($object->type) || empty($object->type)) { throw new ItemTableException('Invalid type id'); } if ($object->name == '') { throw new ItemTableException('Invalid name'); } if ($object->alias == '' || $object->alias != YString::sluggify($object->alias)) { throw new ItemTableException('Invalid slug'); } if (ItemHelper::checkAliasExists($object->alias, $object->id)) { throw new ItemTableException('Alias already exists, please choose a unique alias'); } // first save to get id if (empty($object->id)) { parent::save($object); } // init vars $db = $this->getDBO(); $search_data = array(); $element_data = array(); foreach ($object->getElements() as $id => $element) { // get element data $element_data[] = $element->toXML(); // get search data if ($data = $element->getSearchData()) { $search_data[] = "(" . $object->id . ", " . $db->quote($id) . ", " . $db->quote($data) . ")"; } } // set element data $object->elements = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<elements>\n" . implode("\n", $element_data) . "\n</elements>"; // delete old search data $query = "DELETE FROM " . ZOO_TABLE_SEARCH . " WHERE item_id = " . (int) $object->id; $db->query($query); // insert new search data if (count($search_data)) { $query = "INSERT INTO " . ZOO_TABLE_SEARCH . " VALUES " . implode(", ", $search_data); $db->query($query); } // save tags YTable::getInstance('tag')->save($object->id, $object->getTags()); return parent::save($object); }
public function saveType() { // check for request forgeries YRequest::checkToken() or jexit('Invalid Token'); // init vars $post = YRequest::get('post'); $cid = YRequest::getArray('cid.0', '', 'string'); // get type $type = $this->application->getType($cid); // type is new ? if (!$type) { $type = new Type(null, $this->application->getPath() . '/types'); $type->setApplication($this->application); } // filter identifier $post['identifier'] = YString::sluggify($post['identifier'] == '' ? $post['name'] : $post['identifier']); try { // set post data and save type $type->bind($post); TypeHelper::setUniqueIndentifier($type); // clean and save layout positions if ($type->id != $type->identifier) { // update templates $path = $this->application->getPath() . '/templates'; foreach (JFolder::folders($path, '.', false, true) as $template) { $this->_sanatizePositionsConfig($template, $type); } // update submissions if (!empty($type->id)) { $table = YTable::getInstance('submission'); $applications = array_keys(ApplicationHelper::getApplications($this->application->getGroup())); if (!empty($applications)) { $submissions = $table->all(array('conditions' => 'application_id IN (' . implode(',', $applications) . ')')); foreach ($submissions as $submission) { $params = $submission->getParams(); if ($tmp = $params->get('form.' . $type->id)) { $params->set('form.' . $type->identifier, $tmp); $params->remove('form.' . $type->id); $submission->params = $params->toString(); $table->save($submission); } } } } // update modules $module_path = JPATH_ROOT . '/modules/'; foreach (JFolder::folders($module_path) as $module) { if (JFolder::exists($module_path . $module . '/renderer')) { $this->_sanatizePositionsConfig($module_path . $module, $type); } } // update plugins $plugin_path = JPATH_ROOT . '/plugins/'; foreach (JFolder::folders($plugin_path) as $plugin_type) { foreach (JFolder::folders($plugin_path . $plugin_type) as $plugin) { if (JFolder::exists($plugin_path . $plugin_type . '/' . $plugin . '/renderer')) { $this->_sanatizePositionsConfig($plugin_path . $plugin_type . '/' . $plugin, $type); } } } } $type->save(); // set redirect message $msg = JText::_('Type Saved'); } catch (YException $e) { // raise notice on exception JError::raiseNotice(0, JText::_('Error Saving Type') . ' (' . $e . ')'); $this->_task = 'apply'; $msg = null; } switch ($this->getTask()) { case 'applytype': $link = $this->baseurl . '&task=edittype&cid[]=' . $type->id; break; case 'savetype': default: $link = $this->baseurl . '&task=types'; break; } $this->setRedirect($link, $msg); }
public function save() { // check for request forgeries YRequest::checkToken() or jexit('Invalid Token'); // init vars $post = YRequest::get('post'); $cid = YRequest::getArray('cid.0', '', 'int'); try { // get item table $table = YTable::getInstance('submission'); // get item if ($cid) { $submission = $table->get($cid); } else { $submission = new Submission(); $submission->application_id = $this->application->id; } // bind submission data $submission->bind($post, array('params')); // generate unique slug $submission->alias = SubmissionHelper::getUniqueAlias($submission->id, YString::sluggify($submission->alias)); // set params $submission->params = $submission->getParams()->clear()->set('form.', @$post['params']['form'])->set('trusted_mode', @$post['params']['trusted_mode'])->set('show_tooltip', @$post['params']['show_tooltip'])->toString(); // save submission $table->save($submission); // set redirect message $msg = JText::_('Submission Saved'); } catch (YException $e) { // raise notice on exception JError::raiseNotice(0, JText::_('Error Saving Submission') . ' (' . $e . ')'); $this->_task = 'apply'; $msg = null; } $link = $this->baseurl; switch ($this->getTask()) { case 'apply': $link .= '&task=edit&cid[]=' . $submission->id; break; case 'saveandnew': $link .= '&task=add'; break; } $this->setRedirect($link, $msg); }
<p class="meta"> <?php echo JHTML::_('date', $comment->created, JText::_('ZOO_COMMENT_MODULE_DATE_FORMAT')); ?> | <a class="permalink" href="<?php echo JRoute::_(RouteHelper::getItemRoute($item) . '#comment-' . $comment->id); ?> ">#</a> </p> <?php } ?> <p class="content"> <?php echo CommentHelper::filterContentOutput(YString::truncate($comment->content, modZooCommentHelper::MAX_CHARACTERS)); ?> </p> </li> <?php $i++; } ?> </ul> <?php } else { ?> <?php
public function export() { $db = YDatabase::getInstance(); $user = JFactory::getUser(); // get mtree categories $query = "SELECT *" . ", cat_parent as parent" . ", cat_created as created" . ", cat_published as published" . ", cat_name as name" . ", cat_desc as description" . ", cat_image as image" . " FROM #__mt_cats" . " WHERE cat_id != 0" . " ORDER BY cat_parent, ordering"; $categories = $db->queryObjectList($query, 'cat_id'); // get category table $category_table = YTable::getInstance('category'); // get item table $item_table = YTable::getInstance('item'); // sanatize category aliases $aliases = array(); foreach ($categories as $category) { $i = 2; $alias = YString::sluggify($category->alias); if (empty($alias)) { $alias = YString::sluggify($category->name); } $category->alias = $alias; while (in_array($alias, $aliases)) { $alias = $category->alias . '-' . $i++; } $category->alias = $alias; // remember used aliases to ensure unique aliases $aliases[] = $category->alias; } // get image and file path $this->image_path = JComponentHelper::getParams('com_media')->get('image_path'); $this->image_path = trim($this->image_path, '\\/') . '/'; $this->file_path = JComponentHelper::getParams('com_media')->get('file_path'); $this->file_path = trim($this->file_path, '\\/') . '/'; require_once JPATH_ADMINISTRATOR . '/components/com_mtree/config.mtree.class.php'; $mtconf = new mtConfig($db); $this->category_image_path = $mtconf->get('relative_path_to_cat_original_image'); $this->category_image_path = trim($this->category_image_path, '\\/') . '/'; $this->listing_image_path = $mtconf->get('relative_path_to_listing_original_image'); $this->listing_image_path = trim($this->listing_image_path, '\\/') . '/'; $this->attachement_path = $mtconf->get('relative_path_to_attachments'); $this->attachement_path = trim($this->attachement_path, '\\/') . '/'; $this->import_path_category_images = JPATH_ROOT . '/' . $this->image_path . 'zoo/mtree_import/cats/'; $this->import_path_item_images = JPATH_ROOT . '/' . $this->image_path . 'zoo/mtree_import/items/'; $this->import_path_attachments = JPATH_ROOT . '/' . $this->image_path . 'zoo/mtree_import/attachments/'; $this->import_path_gallery = JPATH_ROOT . '/' . $this->image_path . 'zoo/mtree_import/gallery/'; // create import folders if (!JFolder::exists($this->import_path_category_images)) { JFolder::create($this->import_path_category_images); } if (!JFolder::exists($this->import_path_item_images)) { JFolder::create($this->import_path_item_images); } if (!JFolder::exists($this->import_path_attachments)) { JFolder::create($this->import_path_attachments); } if (!JFolder::exists($this->import_path_gallery)) { JFolder::create($this->import_path_gallery); } // export categories foreach ($categories as $category) { // assign attributes $attributes = array(); foreach (self::$category_attributes as $attribute) { if (isset($category->{$attribute})) { $attributes[$attribute] = $category->{$attribute}; } } // sanatize parent if ($category->parent && isset($categories[$category->parent])) { $attributes['parent'] = $categories[$category->parent]->alias; } // add category $category_xml = $this->_buildCategory($category->alias, $category->name, $attributes); if ($category->image) { $old_file_name = JPATH_ROOT . '/' . $this->category_image_path . $category->image; $file_info = pathinfo($category->image); $file_name = $this->import_path_category_images . $category->image; $i = 2; while (JFile::exists($file_name)) { $file_name = $this->import_path_category_images . $file_info['filename'] . '-' . $i++ . '.' . $file_info['extension']; } if (JFile::copy($old_file_name, $file_name)) { $image = trim(str_replace('\\', '/', preg_replace('/^' . preg_quote(JPATH_ROOT, '/') . '/i', '', $file_name)), '/'); $this->_attachCategoryImage($category_xml, $image, 'Image'); } } $this->_addCategory($category_xml); } // get mtree items $query = "SELECT *, link_id as id" . ", link_name as name" . ", link_desc as description" . ", user_id as created_by" . ", link_hits as hits" . ", link_published as published" . ", link_created as created" . ", link_modified as modified" . " FROM #__mt_links"; $items = $db->queryObjectList($query, 'link_id'); // sanatize item aliases $aliases = array(); foreach ($items as $item) { $i = 2; $alias = YString::sluggify($item->alias); while (in_array($alias, $aliases)) { $alias = YString::sluggify($item->alias) . '-' . $i++; } $item->alias = $alias; // remember used aliases to ensure unique aliases $aliases[] = $item->alias; } // export items foreach ($items as $item) { $this->_addItem('mtree', $this->_itemToXML($item, $categories)); } return parent::export(); }
public static function importCSV($file, $type = '', $contains_headers = false, $field_separator = ',', $field_enclosure = '"', $element_assignment = array()) { // get application if ($application = Zoo::getApplication()) { if ($type_obj = $application->getType($type)) { $c = 0; $assignments = array(); foreach ($element_assignment as $column => $value) { if (!empty($value[$type])) { $name = $value[$type]; $assignments[$name][] = $column; } } if (!isset($assignments['_name'])) { throw new ImportHelperException('No item name was assigned.'); } if (($handle = fopen($file, "r")) !== FALSE) { $item_table = YTable::getInstance('item'); $category_table = YTable::getInstance('category'); $user_id = JFactory::getUser()->get('id'); $now = JFactory::getDate(); $row = 0; $app_categories = $application->getCategories(); $app_categories = array_map(create_function('$cat', 'return $cat->name;'), $app_categories); $elements = $type_obj->getElements(); while (($data = fgetcsv($handle, 0, $field_separator, $field_enclosure)) !== FALSE) { if (!($contains_headers && $row == 0)) { $item = new Item(); $item->application_id = $application->id; $item->type = $type; // store created by $item->created_by = $user_id; // set created $item->created = $now->toMySQL(); // store modified_by $item->modified_by = $user_id; // set modified $item->modified = $now->toMySQL(); // store element_data and item name $item_categories = array(); foreach ($assignments as $assignment => $columns) { $column = current($columns); switch ($assignment) { case '_name': $item->name = $data[$column]; break; case '_created_by_alias': $item->created_by_alias = $data[$column]; break; case '_created': if (!empty($data[$column])) { $item->created = $data[$column]; } break; default: if (substr($assignment, 0, 9) == '_category') { foreach ($columns as $column) { $item_categories[] = $data[$column]; } } else { if (isset($elements[$assignment])) { $elements[$assignment]->unsetData(); switch ($elements[$assignment]->getElementType()) { case 'text': case 'textarea': case 'link': case 'email': case 'date': $element_data = array(); foreach ($columns as $column) { if (!empty($data[$column])) { $element_data[$column] = array('value' => $data[$column]); } } $elements[$assignment]->bindData($element_data); break; case 'gallery': $data[$column] = trim($data[$column], '/\\'); $elements[$assignment]->bindData(array('value' => $data[$column])); break; case 'image': case 'download': $elements[$assignment]->bindData(array('file' => $data[$column])); break; case 'googlemaps': $elements[$assignment]->bindData(array('location' => $data[$column])); break; } } } break; } } $elements_string = '<?xml version="1.0" encoding="UTF-8"?><elements>'; foreach ($elements as $element) { $elements_string .= $element->toXML(); } $elements_string .= '</elements>'; $item->elements = $elements_string; $item->alias = YString::sluggify($item->name); if (empty($item->alias)) { $item->alias = '42'; } // set a valid category alias while (ItemHelper::checkAliasExists($item->alias)) { $item->alias .= '-2'; } if (!empty($item->name)) { try { $item_table->save($item); $item_id = $item->id; $item->unsetElementData(); // store categories foreach ($item_categories as $category_name) { if (!in_array($category_name, $app_categories)) { $category = new Category(); $category->application_id = $application->id; $category->name = $category_name; $category->parent = 0; $category->alias = YString::sluggify($category_name); // set a valid category alias while (CategoryHelper::checkAliasExists($category->alias)) { $category->alias .= '-2'; } try { $category_table->save($category); $related_categories[$category->id] = $category->name; $app_categories[$category->id] = $category->name; } catch (CategoryTableException $e) { } } else { $related_categories = array_filter($app_categories, create_function('$cat', 'return $cat=="' . $category_name . '";')); } // add category to item relations if (!empty($related_categories)) { CategoryHelper::saveCategoryItemRelations($item_id, array_keys($related_categories)); } } } catch (ItemTableException $e) { } } } $row++; } fclose($handle); return true; } else { throw new ImportHelperException('Could not open csv file.'); } } else { throw new ImportHelperException('Could not find type.'); } } throw new ImportHelperException('No application to import too.'); }
public function save() { // check for request forgeries YRequest::checkToken() or jexit('Invalid Token'); // init vars $db = JFactory::getDBO(); $config = JFactory::getConfig(); $now = JFactory::getDate(); $post = YRequest::get('post'); $frontpage = YRequest::getBool('frontpage', false); $categories = YRequest::getArray('categories', null); $details = YRequest::getArray('details', null); $metadata = YRequest::getArray('meta', null); $cid = YRequest::getArray('cid.0', '', 'int'); $tzoffset = $config->getValue('config.offset'); $post = array_merge($post, $details); try { // get item table $table = YTable::getInstance('item'); // get item if ($cid) { $item = $table->get($cid); } else { $item = new Item(); $item->application_id = $this->application->id; $item->type = YRequest::getVar('type'); } // bind item data $item->bind($post, array('elements', 'params', 'created_by')); $created_by = isset($post['created_by']) ? $post['created_by'] : ''; $item->created_by = empty($created_by) ? JFactory::getUser()->id : $created_by == 'NO_CHANGE' ? $item->created_by : $created_by; $tags = isset($post['tags']) ? $post['tags'] : array(); $item->setTags($tags); // bind element data foreach ($item->getElements() as $id => $element) { if (isset($post['elements'][$id])) { $element->bindData($post['elements'][$id]); } else { $element->bindData(); } } // set alias $item->alias = ItemHelper::getUniqueAlias($item->id, YString::sluggify($item->alias)); // set modified $item->modified = $now->toMySQL(); $item->modified_by = $this->user->get('id'); // set created date if ($item->created && strlen(trim($item->created)) <= 10) { $item->created .= ' 00:00:00'; } $date = JFactory::getDate($item->created, $tzoffset); $item->created = $date->toMySQL(); // set publish up date if (strlen(trim($item->publish_up)) <= 10) { $item->publish_up .= ' 00:00:00'; } $date = JFactory::getDate($item->publish_up, $tzoffset); $item->publish_up = $date->toMySQL(); // set publish down date if (trim($item->publish_down) == JText::_('Never') || trim($item->publish_down) == '') { $item->publish_down = $db->getNullDate(); } else { if (strlen(trim($item->publish_down)) <= 10) { $item->publish_down .= ' 00:00:00'; } $date = JFactory::getDate($item->publish_down, $tzoffset); $item->publish_down = $date->toMySQL(); } // get primary category $primary_category = @$post['params']['primary_category']; if (empty($primary_category) && count($categories)) { $primary_category = $categories[0]; } // set params $item->params = $item->getParams()->remove('metadata.')->remove('template.')->set('metadata.', @$post['params']['metadata'])->set('template.', @$post['params']['template'])->set('config.enable_comments', @$post['params']['enable_comments'])->set('config.primary_category', $primary_category)->toString(); // save item $table->save($item); // make sure categories contain primary category if (!empty($primary_category) && !in_array($primary_category, $categories)) { $categories[] = $primary_category; } // save category relations if ($frontpage) { $categories[] = 0; } CategoryHelper::saveCategoryItemRelations($item->id, $categories); // set redirect message $msg = JText::_('Item Saved'); } catch (YException $e) { // raise notice on exception JError::raiseNotice(0, JText::_('Error Saving Item') . ' (' . $e . ')'); $this->_task = 'apply'; $msg = null; } $link = $this->baseurl; switch ($this->getTask()) { case 'apply': $link .= '&task=edit&type=' . $item->type . '&cid[]=' . $item->id; break; case 'saveandnew': $link .= '&task=add'; break; } $this->setRedirect($link, $msg); }
public function export() { $db = YDatabase::getInstance(); // get docman categories $query = "SELECT c.*, c.parent_id as parent" . " FROM #__categories AS c" . " WHERE c.section = 'com_docman'" . " AND c.published != -2" . " ORDER BY c.parent_id, c.ordering"; $categories = $db->queryObjectList($query, 'id'); // get category table $category_table = YTable::getInstance('category'); // get item table $item_table = YTable::getInstance('item'); // sanatize category aliases $aliases = array(); foreach ($categories as $category) { $i = 2; $alias = YString::sluggify($category->alias); if (empty($alias)) { $alias = YString::sluggify($category->title); } while (in_array($alias, $aliases)) { $alias = $category->alias . '-' . $i++; } $category->alias = $alias; // remember used aliases to ensure unique aliases $aliases[] = $category->alias; } // get image path $this->image_path = JComponentHelper::getParams('com_media')->get('image_path'); $this->image_path = trim($this->image_path, '\\/') . '/'; // export categories foreach ($categories as $category) { // assign attributes $attributes = array(); foreach (self::$category_attributes as $attribute) { if (isset($category->{$attribute})) { $attributes[$attribute] = $category->{$attribute}; } } // sanatize parent if ($category->parent && isset($categories[$category->parent])) { $attributes['parent'] = $categories[$category->parent]->alias; } // add category $category_xml = $this->_buildCategory($category->alias, $category->name, $attributes); if ($category->image) { $this->_attachCategoryImage($category_xml, $this->image_path . $category->image, 'Image'); } $this->_addCategory($category_xml); } // get docman items $query = "SELECT * FROM #__docman"; $items = $db->queryObjectList($query, 'id'); // sanatize item aliases $aliases = array(); foreach ($items as $item) { $i = 2; $alias = YString::sluggify($item->dmname); while (in_array($alias, $aliases)) { $alias = YString::sluggify($item->dmname) . '-' . $i++; } $item->alias = $alias; // remember used aliases to ensure unique aliases $aliases[] = $item->alias; } require_once JPATH_ADMINISTRATOR . '/components/com_docman/docman.config.php'; $config = new dmConfig(); $document_path = trim(str_replace('\\', '/', preg_replace('/^' . preg_quote(JPATH_ROOT, '/') . '/i', '', $config->dmpath)), '/') . '/'; // export items foreach ($items as $item) { if (preg_match('/^Link:/', $item->dmfilename)) { $type = 'Linked File'; $item->dmfilename = preg_replace('/^Link:/', '', $item->dmfilename); } else { $type = 'File'; $item->dmfilename = $document_path . $item->dmfilename; } $this->_addItem($type, $this->_itemToXML($item, $categories, $type)); } return parent::export(); }
public function export() { $db = YDatabase::getInstance(); // get k2 categories $query = "SELECT a.*, b.name AS extra_field_group_name " . " FROM #__k2_categories AS a" . " LEFT JOIN #__k2_extra_fields_groups AS b ON b.id = a.extraFieldsGroup"; $categories = $db->queryObjectList($query, 'id'); // get category table $category_table = YTable::getInstance('category'); // get item table $item_table = YTable::getInstance('item'); // sanatize category aliases $aliases = array(); foreach ($categories as $category) { $i = 2; $alias = YString::sluggify($category->alias); while (in_array($alias, $aliases)) { $alias = $category->alias . '-' . $i++; } $category->alias = $alias; // remember used aliases to ensure unique aliases $aliases[] = $category->alias; } // export categories foreach ($categories as $category) { // assign attributes $attributes = array(); foreach (self::$category_attributes as $attribute) { if (isset($category->{$attribute})) { $attributes[$attribute] = $category->{$attribute}; } } // sanatize parent if ($category->parent && isset($categories[$category->parent])) { $attributes['parent'] = $categories[$category->parent]->alias; } // add category $category_xml = $this->_buildCategory($category->alias, $category->name, $attributes); if ($category->image) { $this->_attachCategoryImage($category_xml, '/media/k2/categories/' . $category->image, 'Image'); } $this->_addCategory($category_xml); } // get k2 items $query = "SELECT * FROM #__k2_items"; $items = $db->queryObjectList($query, 'id'); // get k2 extra fields $query = "SELECT * FROM #__k2_extra_fields"; $extra_fields = $db->queryObjectList($query, 'id'); // get k2 tags $query = "SELECT a.itemID, b.name" . " FROM #__k2_tags_xref as a" . " JOIN #__k2_tags AS b ON a.tagID = b.id"; $tag_result = $db->queryObjectList($query); $tags = array(); foreach ($tag_result as $tag) { $tags[$tag->itemID][] = $tag->name; } // sanatize item aliases $aliases = array(); foreach ($items as $item) { $i = 2; $alias = YString::sluggify($item->alias); while (in_array($alias, $aliases)) { $alias = $item->alias . '-' . $i++; } $item->alias = $alias; // remember used aliases to ensure unique aliases $aliases[] = $item->alias; } // export items foreach ($items as $item) { if (!$item->trash) { if (!($type = $categories[$item->catid]->extra_field_group_name)) { $type = JText::_('K2-Unassigned'); } $this->_addItem($type, $this->_itemToXML($item, $categories, $tags, $extra_fields)); } } return parent::export(); }
public function bind($data) { if (isset($data['identifier'])) { // check identifier if ($data['identifier'] == '' || $data['identifier'] != YString::sluggify($data['identifier'])) { throw new TypeException('Invalid identifier'); } $this->identifier = $data['identifier']; } if (isset($data['name'])) { // check name if ($data['name'] == '') { throw new TypeException('Invalid name'); } $this->name = $data['name']; } return $this; }
public function save() { // check for request forgeries YRequest::checkToken() or jexit('Invalid Token'); // init vars $post = JRequest::get('post'); $db = YDatabase::getInstance(); $tzoffset = JFactory::getConfig()->getValue('config.offset'); $now = JFactory::getDate(); $now->setOffset($tzoffset); $msg = ''; try { $this->_init(); // is this an item edit? $edit = (int) $this->item->id; // is current user the item owner and does the user have sufficient user rights if ($edit && (!$this->item->canAccess($this->user) || $this->item->created_by != $this->user->id)) { throw new YControllerException('You are not allowed to make changes to this item.'); } // get default category - only in none trusted mode $categories = array(); if (!$this->submission->isInTrustedMode() && ($category = $this->submission->getForm($this->type->id)->get('category'))) { $categories[] = $category; } // get element data from post if (isset($post['elements'])) { // filter element data if (!$this->submission->isInTrustedMode() && !UserHelper::isJoomlaAdmin($this->user)) { JRequest::setVar('elements', SubmissionHelper::filterData($post['elements'])); $post = JRequest::get('post'); } // merge elements into post $post = array_merge($post, $post['elements']); } // fix publishing dates in trusted mode if ($this->submission->isInTrustedMode()) { // set publish up date if (isset($post['publish_up'])) { if (empty($post['publish_up'])) { $post['publish_up'] = $now->toMySQL(true); } } // set publish down date if (isset($post['publish_down'])) { if (trim($post['publish_down']) == JText::_('Never') || trim($post['publish_down']) == '') { $post['publish_down'] = $db->getNullDate(); } } } // sanatize tags if (!isset($post['tags'])) { $post['tags'] = array(); } // build new item form and bind it with post data $form = new ItemForm(array('submission' => $this->submission, 'item' => $this->item, 'elements_config' => $this->elements_config)); $form->bind($post); // save item if form is valid if ($form->isValid()) { // set name $this->item->name = $form->getValue('name'); // bind elements foreach ($this->elements_config as $data) { if (($element = $this->item->getElement($data->element)) && ($field = $form->getFormField($data->element))) { if ($field_data = $field->hasError() ? $field->getTaintedValue() : $field->getValue()) { $element->bindData($field_data); } else { $element->bindData(); } // perform submission uploads if ($element instanceof iSubmissionUpload) { $element->doUpload(); } } } // set alias $this->item->alias = ItemHelper::getUniqueAlias($this->item->id, YString::sluggify($this->item->name)); // set modified $this->item->modified = $now->toMySQL(); $this->item->modified_by = $this->user->get('id'); // creating new item if (!$edit) { // set state $this->item->state = 0; // set created date $this->item->created = $now->toMySQL(); $this->item->created_by = $this->user->get('id'); $this->item->created_by_alias = ''; // set publish up - publish down $this->item->publish_up = $now->toMySQL(); $this->item->publish_down = $db->getNullDate(); // set access $this->item->access = 0; // set searchable $this->item->searchable = 1; } if ($this->submission->isInTrustedMode()) { // set state $this->item->state = $form->getValue('state'); // set publish up if (($publish_up = $form->getValue('publish_up')) && !empty($publish_up)) { $date = JFactory::getDate($publish_up, $tzoffset); $publish_up = $date->toMySQL(); } $this->item->publish_up = $publish_up; // set publish down if (($publish_down = $form->getValue('publish_down')) && !empty($publish_down) && !($publish_down == $db->getNullDate())) { $date = JFactory::getDate($publish_down, $tzoffset); $publish_down = $date->toMySQL(); } $this->item->publish_down = $publish_down; // set searchable $this->item->searchable = $form->getValue('searchable'); // set comments enabled $this->item->params = $this->item->getParams()->set('config.enable_comments', $form->getValue('enable_comments'))->toString(); // set frontpage if ($form->getValue('frontpage')) { $categories[] = 0; } // set categories $tmp_categories = $form->getValue('categories'); if (!empty($tmp_categories)) { foreach ($form->getValue('categories') as $category) { $categories[] = $category; } } // set tags $tags = $form->hasError('tags') ? $form->getTaintedValue('tags') : $form->getValue('tags'); $this->item->setTags($tags); } else { // spam protection - user may only submit items every SubmissionController::TIME_BETWEEN_PUBLIC_SUBMISSIONS seconds if (!$edit) { $timestamp = $this->session->get('ZOO_LAST_SUBMISSION_TIMESTAMP'); $now = time(); if ($now < $timestamp + SubmissionController::TIME_BETWEEN_PUBLIC_SUBMISSIONS) { throw new SubmissionControllerException('You are submitting to fast, please try again in a few moments.'); } $this->session->set('ZOO_LAST_SUBMISSION_TIMESTAMP', $now); } } // save item YTable::getInstance('item')->save($this->item); // save category relations - only if editing in trusted mode if (!$edit || $this->submission->isInTrustedMode()) { CategoryHelper::saveCategoryItemRelations($this->item->id, $categories); } // set redirect message $msg = $this->submission->isInTrustedMode() ? JText::_('Thanks for your submission.') : JText::_('Thanks for your submission. It will be reviewed before being posted on the site.'); // add form to session if form is not valid } else { $this->addFormToSession($form); } } catch (SubmissionControllerException $e) { // raise warning on exception JError::raiseWarning(0, (string) $e); } catch (YException $e) { // raise warning on exception JError::raiseWarning(0, JText::_('There was an error saving your submission, please try again later.')); // add exception details, for super administrators only if ($this->user->superadmin) { JError::raiseWarning(0, (string) $e); } } // redirect to mysubmissions if ($this->redirect == 'mysubmissions' && $form && $form->isValid()) { $link = RouteHelper::getMySubmissionsRoute($this->submission); // redirect to edit form } else { $link = RouteHelper::getSubmissionRoute($this->submission, $this->type->id, $this->hash, $this->item_id, $this->redirect); } $link = JRoute::_($link, false); $this->setRedirect($link, $msg); }
$app->alias = ApplicationHelper::getUniqueAlias($app->id, YString::sluggify($app->name)); try { $table->save($app); } catch (ApplicationTableException $e) { } } } // set primary category for each item $table = YTable::getInstance('item'); $items = $table->all(); foreach ($items as $item) { if ($item->getPrimaryCategoryId() != null) { continue; } $relatedCategoriesIds = $item->getRelatedCategoryIds(); $relatedCategoriesIds = array_filter($relatedCategoriesIds, create_function('$id', 'return !empty($id);')); if (!empty($relatedCategoriesIds)) { // set params $item->params = $item->getParams()->set('config.primary_category', array_shift($relatedCategoriesIds))->toString(); $item->alias = YString::sluggify($item->alias); if (empty($item->alias)) { ItemHelper::getUniqueAlias($item->id, YString::sluggify($item->name)); } // save item try { $table->save($item); } catch (ItemTableException $e) { } } } }
public function save() { // check for request forgeries YRequest::checkToken() or jexit('Invalid Token'); // init vars $post = YRequest::get('post'); $cid = YRequest::getArray('cid.0', '', 'int'); // set application $post['application_id'] = $this->application->id; // get raw description from post data $post['description'] = YRequest::getVar('description', '', 'post', 'string', JREQUEST_ALLOWRAW); try { // get category table $table = YTable::getInstance('category'); // get category and bind post data $category = $cid ? $table->get($cid) : new Category(); $category->bind($post, array('params')); $category->alias = CategoryHelper::getUniqueAlias($category->id, YString::sluggify($category->alias)); $category->params = $category->getParams()->remove('content.')->remove('config.')->remove('template.')->set('content.', @$post['params']['content'])->set('config.', @$post['params']['config'])->set('template.', @$post['params']['template'])->toString(); // save category and update category ordering $table->save($category); $table->updateorder($this->application->id, $category->parent); // set redirect message $msg = JText::_('Category Saved'); } catch (YException $e) { // raise notice on exception JError::raiseNotice(0, JText::_('Error Saving Category') . ' (' . $e . ')'); $this->_task = 'apply'; $msg = null; } $link = $this->baseurl; switch ($this->getTask()) { case 'apply': $link .= '&task=edit&cid[]=' . $category->id; break; case 'saveandnew': $link .= '&task=edit&cid[]='; break; } $this->setRedirect($link, $msg); }