/** * Display the view */ public function display($tpl = null) { $this->state = $this->get('State'); $this->items = $this->get('Items'); $this->pagination = $this->get('Pagination'); TagsHelper::addSubmenu('tags'); // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } // Preprocess the list of items to find ordering divisions. foreach ($this->items as &$item) { $this->ordering[$item->parent_id][] = $item->id; } // Levels filter. $options = array(); $options[] = JHtml::_('select.option', '1', JText::_('J1')); $options[] = JHtml::_('select.option', '2', JText::_('J2')); $options[] = JHtml::_('select.option', '3', JText::_('J3')); $options[] = JHtml::_('select.option', '4', JText::_('J4')); $options[] = JHtml::_('select.option', '5', JText::_('J5')); $options[] = JHtml::_('select.option', '6', JText::_('J6')); $options[] = JHtml::_('select.option', '7', JText::_('J7')); $options[] = JHtml::_('select.option', '8', JText::_('J8')); $options[] = JHtml::_('select.option', '9', JText::_('J9')); $options[] = JHtml::_('select.option', '10', JText::_('J10')); $this->f_levels = $options; $this->addToolbar(); $this->sidebar = JHtmlSidebar::render(); parent::display($tpl); }
/** * Add the page title and toolbar. * * @since 3.1 */ protected function addToolbar() { $state = $this->get('State'); $canDo = TagsHelper::getActions($state->get('filter.parent_id')); $user = JFactory::getUser(); // Get the toolbar object instance $bar = JToolBar::getInstance('toolbar'); JToolbarHelper::title(JText::_('COM_TAGS_MANAGER_TAGS'), 'tags'); if ($canDo->get('core.create')) { JToolbarHelper::addNew('tag.add'); } if ($canDo->get('core.edit')) { JToolbarHelper::editList('tag.edit'); } if ($canDo->get('core.edit.state')) { JToolbarHelper::publish('tags.publish', 'JTOOLBAR_PUBLISH', true); JToolbarHelper::unpublish('tags.unpublish', 'JTOOLBAR_UNPUBLISH', true); JToolbarHelper::archiveList('tags.archive'); } if ($canDo->get('core.admin')) { JToolbarHelper::checkin('tags.checkin'); } if ($state->get('filter.published') == -2 && $canDo->get('core.delete')) { JToolbarHelper::deleteList('', 'tags.delete', 'JTOOLBAR_EMPTY_TRASH'); } elseif ($canDo->get('core.edit.state')) { JToolbarHelper::trash('tags.trash'); } // Add a batch button if ($user->authorise('core.create', 'com_tags') && $user->authorise('core.edit', 'com_tags') && $user->authorise('core.edit.state', 'com_tags')) { JHtml::_('bootstrap.modal', 'collapseModal'); $title = JText::_('JTOOLBAR_BATCH'); // Instantiate a new JLayoutFile instance and render the batch button $layout = new JLayoutFile('joomla.toolbar.batch'); $dhtml = $layout->render(array('title' => $title)); $bar->appendButton('Custom', $dhtml, 'batch'); } if ($canDo->get('core.admin')) { JToolbarHelper::preferences('com_tags'); } JToolbarHelper::help('JHELP_COMPONENTS_TAGS_MANAGER'); JHtmlSidebar::setAction('index.php?option=com_tags&view=tags'); JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_PUBLISHED'), 'filter_published', JHtml::_('select.options', JHtml::_('jgrid.publishedOptions'), 'value', 'text', $this->state->get('filter.published'), true)); JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_ACCESS'), 'filter_access', JHtml::_('select.options', JHtml::_('access.assetgroups'), 'value', 'text', $this->state->get('filter.access'))); JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_LANGUAGE'), 'filter_language', JHtml::_('select.options', JHtml::_('contentlanguage.existing', true, true), 'value', 'text', $this->state->get('filter.language'))); }
/** * Add the page title and toolbar. * * @since 3.1 */ protected function addToolbar() { $state = $this->get('State'); $canDo = TagsHelper::getActions($state->get('filter.parent_id')); $user = JFactory::getUser(); // Get the toolbar object instance $bar = JToolBar::getInstance('toolbar'); JToolbarHelper::title(JText::_('COM_TAGS_MANAGER_TAGS'), 'modules.png'); if ($canDo->get('core.create')) { JToolbarHelper::addNew('tag.add'); } if ($canDo->get('core.edit')) { JToolbarHelper::editList('tag.edit'); } if ($canDo->get('core.edit.state')) { JToolbarHelper::publish('tags.publish', 'JTOOLBAR_PUBLISH', true); JToolbarHelper::unpublish('tags.unpublish', 'JTOOLBAR_UNPUBLISH', true); JToolbarHelper::archiveList('tags.archive'); } if ($canDo->get('core.admin')) { JToolbarHelper::checkin('tags.checkin'); } if ($state->get('filter.published') == -2 && $canDo->get('core.delete')) { JToolbarHelper::deleteList('', 'tags.delete', 'JTOOLBAR_EMPTY_TRASH'); } elseif ($canDo->get('core.edit.state')) { JToolbarHelper::trash('tags.trash'); } // Add a batch button if ($user->authorise('core.edit')) { JHtml::_('bootstrap.modal', 'collapseModal'); $title = JText::_('JTOOLBAR_BATCH'); $dhtml = "<button data-toggle=\"modal\" data-target=\"#collapseModal\" class=\"btn btn-small\">\n\t\t\t\t\t\t<i class=\"icon-checkbox-partial\" title=\"{$title}\"></i>\n\t\t\t\t\t\t{$title}</button>"; $bar->appendButton('Custom', $dhtml, 'batch'); } if ($canDo->get('core.admin')) { JToolbarHelper::preferences('com_tags'); } JToolbarHelper::help('JHELP_COMPONENTS_TAGS_MANAGER'); JHtmlSidebar::setAction('index.php?option=com_tags&view=tags'); JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_PUBLISHED'), 'filter_published', JHtml::_('select.options', JHtml::_('jgrid.publishedOptions'), 'value', 'text', $this->state->get('filter.published'), true)); JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_ACCESS'), 'filter_access', JHtml::_('select.options', JHtml::_('access.assetgroups'), 'value', 'text', $this->state->get('filter.access'))); JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_LANGUAGE'), 'filter_language', JHtml::_('select.options', JHtml::_('contentlanguage.existing', true, true), 'value', 'text', $this->state->get('filter.language'))); }
/** * Add the page title and toolbar. * * @since 3.1 */ protected function addToolbar() { $input = JFactory::getApplication()->input; $user = JFactory::getUser(); $userId = $user->get('id'); $isNew = $this->item->id == 0; $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $userId); // Need to load the menu language file as mod_menu hasn't been loaded yet. $lang = JFactory::getLanguage(); $lang->load('com_tags', JPATH_BASE, null, false, false) || $lang->load('com_tags', JPATH_ADMINISTRATOR . '/components/com_tags', null, false, false) || $lang->load('com_tags', JPATH_BASE, $lang->getDefault(), false, false) || $lang->load('com_tags', JPATH_ADMINISTRATOR . '/components/com_tags', $lang->getDefault(), false, false); // Load the tags helper. require_once JPATH_COMPONENT . '/helpers/tags.php'; // Get the results for each action. $canDo = TagsHelper::getActions('com_tags', $this->item->id); $title = JText::_('COM_TAGS_BASE_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE'); // Prepare the toolbar. JToolbarHelper::title($title, 'tag-' . ($isNew ? 'add' : 'edit') . ($isNew ? 'add' : 'edit')); // For new records, check the create permission. if ($isNew) { JToolbarHelper::apply('tag.apply'); JToolbarHelper::save('tag.save'); JToolbarHelper::save2new('tag.save2new'); } elseif (!$checkedOut && ($canDo->get('core.edit') || $canDo->get('core.edit.own') && $this->item->created_user_id == $userId)) { JToolbarHelper::apply('tag.apply'); JToolbarHelper::save('tag.save'); if ($canDo->get('core.create')) { JToolbarHelper::save2new('tag.save2new'); } } // If an existing item, can save to a copy. if (!$isNew && $canDo->get('core.create')) { JToolbarHelper::save2copy('tag.save2copy'); } if (empty($this->item->id)) { JToolbarHelper::cancel('tag.cancel'); } else { JToolbarHelper::cancel('tag.cancel', 'JTOOLBAR_CLOSE'); } JToolbarHelper::help('JHELP_COMPONENTS_TAGS_MANAGER_EDIT'); JToolbarHelper::divider(); }
/** * Import all the tags for a single item */ static function import_tags_for_item(&$queue) { if (!module::is_active("tag")) { return t("Gallery 3 tag module is inactive, no tags will be imported"); } GalleryCoreApi::requireOnce("modules/tags/classes/TagsHelper.class"); $g2_item_id = array_shift($queue); $g3_item = ORM::factory("item", self::map($g2_item_id)); try { $tag_names = array_values(g2(TagsHelper::getTagsByItemId($g2_item_id))); } catch (Exception $e) { return t("Failed to import Gallery 2 tags for item with id: %id\n%exception", array("id" => $g2_item_id, "exception" => $e->__toString())); } $tags = ""; // Multiword tags have the space changed to dots.s foreach ($tag_names as $tag_name) { $tags .= (strlen($tags) ? ", " : "") . tag::add($g3_item, preg_replace('/\\s+/', '.', $tag_name)); } // Tag operations are idempotent so we don't need to map them. Which is good because we don't // have an id for each individual tag mapping anyway so it'd be hard to set up the mapping. }
/** * Import all the tags for a single item */ static function import_tags_for_item(&$queue) { if (!module::is_active("tag")) { return t("Gallery 3 tag module is inactive, no tags will be imported"); } GalleryCoreApi::requireOnce("modules/tags/classes/TagsHelper.class"); $g2_item_id = array_shift($queue); $g3_item = ORM::factory("item", self::map($g2_item_id)); if (!$g3_item->loaded()) { return; } try { $tag_names = array_values(g2(TagsHelper::getTagsByItemId($g2_item_id))); } catch (Exception $e) { return t("Failed to import Gallery 2 tags for item with id: %id\n%exception", array("id" => $g2_item_id, "exception" => (string) $e)); } foreach ($tag_names as $tag_name) { tag::add($g3_item, $tag_name); } // Tag operations are idempotent so we don't need to map them. Which is good because we don't // have an id for each individual tag mapping anyway so it'd be hard to set up the mapping. }
/** * Import all the tags for a single item */ static function import_tags_for_item(&$queue) { GalleryCoreApi::requireOnce("modules/tags/classes/TagsHelper.class"); $g2_item_id = array_shift($queue); $g3_item = ORM::factory("item", self::map($g2_item_id)); try { $tag_names = array_values(g2(TagsHelper::getTagsByItemId($g2_item_id))); } catch (Exception $e) { g2_import::log("Failed to import tags for Gallery 2 item with id: %id", array("id" => $g2_item_id)); return; } foreach ($tag_names as $tag_name) { $tag = tag::add($g3_item, $tag_name); } // Tag operations are idempotent so we don't need to map them. Which is good because we don't // have an id for each individual tag mapping anyway so it'd be hard to set up the mapping. }
/** * Overloaded bind function to pre-process the params. * * @param array $array Named array * @param mixed $ignore Optional array or list of parameters to ignore * * @return null|string null is operation was satisfactory, otherwise returns an error * * @see JTable:bind * @since 1.5 */ public function bind($array, $ignore = '') { if (isset($array['tags']) && !empty($array['tags'])) { // Load the tags helper. require_once JPATH_ADMINISTRATOR . '/components/com_tags/helpers/tags.php'; // Get the allowed actions for the user $canDo = TagsHelper::getActions('com_tags'); // The helper get the user and the component name itself // Load the tags model. require_once JPATH_ADMINISTRATOR . '/components/com_tags/models/tag.php'; JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tags/tables'); // Get an instance of the table for insertion the new tags $tagsModel = TagsModelTag::getInstance('Tag', 'TagsModel'); $tags = array(); // Initialization of the tag container must be processed // If tags is an array, store-mode if (is_array($array['tags'])) { // "Allow user creation" mode must be activated (default) in the component creation field // Save the tags does not exist into the table tags and get its id for save the entire Item with the proper data foreach ($array['tags'] as $singleTag) { // If there is any new tag... create it to get the id and save into the table #__COMPONENT_NAME_TABLE_NAME if (strpos($singleTag, "#new#") !== FALSE) { $user = JFactory::getUser(); $userId = $user->id; // For writting permissions $tagName = str_replace("#new#", "", $singleTag); $tagAlias = $tagPath = preg_replace('/[\\s\\W\\.]+/', '-', $tagName); // Tags alias filter $tagMetadata = array("author" => "", "robots" => "", "tags" => null); // The data tag field row $data = array("parent_id" => 0, "path" => $tagPath, "title" => $tagName, "alias" => $tagAlias, "created_by_alias" => $user, "created_user_id" => $userId, "published" => 1, "checked_out" => 0, "metadata" => json_encode($tagMetadata)); // Finally, store the tag if the user is granted for that if ($canDo->get('core.create')) { $table = $tagsModel->getTable(); $table->bind($data) ? $table->store($data) : exit; $tags[] = $table->id; // And store the insert_id } } else { $tags[] = intval($singleTag); } } // Overrride the tags array, because we should need to change the id before field saving // The field in database will look like "299,345,567,567" $array['tags'] = implode(',', $tags); } } else { $array['tags'] = ''; } // Support for multiple or not foreign key field: cuisines_id if (!empty($array['cuisines_id'])) { if (is_array($array['cuisines_id'])) { $array['cuisines_id'] = implode(',', $array['cuisines_id']); } else { if (strrpos($array['cuisines_id'], ',') != false) { $array['cuisines_id'] = explode(',', $array['cuisines_id']); } } } else { $array['cuisines_id'] = ''; } // Support for multiple or not foreign key field: meal_course_id if (!empty($array['meal_course_id'])) { if (is_array($array['meal_course_id'])) { $array['meal_course_id'] = implode(',', $array['meal_course_id']); } else { if (strrpos($array['meal_course_id'], ',') != false) { $array['meal_course_id'] = explode(',', $array['meal_course_id']); } } } else { $array['meal_course_id'] = ''; } $input = JFactory::getApplication()->input; $task = $input->getString('task', ''); if (($task == 'save' || $task == 'apply') && (!JFactory::getUser()->authorise('core.edit.state', 'com_akrecipes') && $array['state'] == 1)) { $array['state'] = 0; } if ($array['id'] == 0) { $array['created_by'] = JFactory::getUser()->id; } if ($array['id'] == 0) { $array['modified_by'] = JFactory::getUser()->id; } // Support for checkbox field: sponsored if (!isset($array['sponsored'])) { $array['sponsored'] = 0; } // Support for checkbox field: featured if (!isset($array['featured'])) { $array['featured'] = 0; } if (isset($array['params']) && is_array($array['params'])) { $registry = new JRegistry(); $registry->loadArray($array['params']); $array['params'] = (string) $registry; } if (isset($array['metadata']) && is_array($array['metadata'])) { $registry = new JRegistry(); $registry->loadArray($array['metadata']); $array['metadata'] = (string) $registry; } if (!JFactory::getUser()->authorise('core.admin', 'com_akrecipes.recipe.' . $array['id'])) { $actions = JAccess::getActionsFromFile(JPATH_ADMINISTRATOR . '/components/com_akrecipes/access.xml', "/access/section[@name='recipe']/"); $default_actions = JAccess::getAssetRules('com_akrecipes.recipe.' . $array['id'])->getData(); $array_jaccess = array(); foreach ($actions as $action) { $array_jaccess[$action->name] = $default_actions[$action->name]; } $array['rules'] = $this->JAccessRulestoArray($array_jaccess); } // Bind the rules for ACL where supported. if (isset($array['rules']) && is_array($array['rules'])) { $this->setRules($array['rules']); } return parent::bind($array, $ignore); }