/** * Method to display a view. * * @param boolean If true, the view output will be cached * @param array An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}. * * @return JController This object to support chaining. * @since 1.5 */ public function display($cachable = false, $urlparams = false) { // Get the document object. $document = JFactory::getDocument(); // Set the default view name and format from the Request. $vName = JRequest::getCmd('view', 'categories'); $vFormat = $document->getType(); $lName = JRequest::getCmd('layout', 'default'); $id = JRequest::getInt('id'); // Check for edit form. if ($vName == 'category' && $lName == 'edit' && !$this->checkEditId('com_categories.edit.category', $id)) { // Somehow the person just went to the form - we don't allow that. $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id)); $this->setMessage($this->getError(), 'error'); $this->setRedirect(JRoute::_('index.php?option=com_categories&view=categories&extension=' . $this->extension, false)); return false; } // Get and render the view. if ($view = $this->getView($vName, $vFormat)) { // Get the model for the view. $model = $this->getModel($vName, 'CategoriesModel', array('name' => $vName . '.' . substr($this->extension, 4))); // Push the model into the view (as default). $view->setModel($model, true); $view->setLayout($lName); // Push document object into the view. $view->assignRef('document', $document); // Load the submenu. require_once JPATH_COMPONENT . '/helpers/categories.php'; CategoriesHelper::addSubmenu($model->getState('filter.extension')); $view->display(); } return $this; }
/** * Render the list of associated items * * @param integer $catid Category identifier to search its associations * @param string $extension Category Extension * * @return string The language HTML * * @since 3.2 * @throws Exception */ public static function association($catid, $extension = 'com_content') { // Defaults $html = ''; // Get the associations if ($associations = CategoriesHelper::getAssociations($catid, $extension)) { $associations = ArrayHelper::toInteger($associations); // Get the associated categories $db = JFactory::getDbo(); $query = $db->getQuery(true)->select('c.id, c.title')->select('l.sef as lang_sef')->select('l.lang_code')->from('#__categories as c')->where('c.id IN (' . implode(',', array_values($associations)) . ')')->join('LEFT', '#__languages as l ON c.language=l.lang_code')->select('l.image')->select('l.title as language_title'); $db->setQuery($query); try { $items = $db->loadObjectList('id'); } catch (RuntimeException $e) { throw new Exception($e->getMessage(), 500, $e); } if ($items) { foreach ($items as &$item) { $text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX'; $url = JRoute::_('index.php?option=com_categories&task=category.edit&id=' . (int) $item->id . '&extension=' . $extension); $classes = 'hasPopover label label-association label-' . $item->lang_sef; $item->link = '<a href="' . $url . '" title="' . $item->language_title . '" class="' . $classes . '" data-content="' . $item->title . '" data-placement="top">' . $text . '</a>'; } } JHtml::_('bootstrap.popover'); $html = JLayoutHelper::render('joomla.content.associations', $items); } return $html; }
/** * @param int $articleid The article item id */ public static function association($catid) { // Get the associations $associations = CategoriesHelper::getAssociations($catid); JArrayHelper::toInteger($associations); // Get the associated menu items $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('c.*'); $query->from('#__categories as c'); $query->where('c.id IN (' . implode(',', array_values($associations)) . ')'); $query->leftJoin('#__languages as l ON c.language=l.lang_code'); $query->select('l.image'); $query->select('l.title as language_title'); $db->setQuery($query); $items = $db->loadObjectList('id'); // Check for a database error. if ($error = $db->getErrorMsg()) { JError::raiseWarning(500, $error); return false; } // Construct html $text = array(); foreach ($associations as $tag => $associated) { if ($associated != $catid) { $text[] = JText::sprintf('COM_CATEGORIES_TIP_ASSOCIATED_LANGUAGE', JHtml::_('image', 'mod_languages/' . $items[$associated]->image . '.gif', $items[$associated]->language_title, array('title' => $items[$associated]->language_title), true), $items[$associated]->title); } } return JHtml::_('tooltip', implode('<br />', $text), JText::_('COM_CATEGORIES_TIP_ASSOCIATION'), 'admin/icon-16-links.png'); }
/** * Render the list of associated items * * @param integer $catid Category identifier to search its associations * @param string $extension Category Extension * * @return string The language HTML */ public static function association($catid, $extension = 'com_content') { // Defaults $html = ''; // Get the associations if ($associations = CategoriesHelper::getAssociations($catid, $extension)) { JArrayHelper::toInteger($associations); // Get the associated categories $db = JFactory::getDbo(); $query = $db->getQuery(true)->select('c.id, c.title')->select('l.sef as lang_sef')->from('#__categories as c')->where('c.id IN (' . implode(',', array_values($associations)) . ')')->join('LEFT', '#__languages as l ON c.language=l.lang_code')->select('l.image')->select('l.title as language_title'); $db->setQuery($query); try { $items = $db->loadObjectList('id'); } catch (RuntimeException $e) { throw new Exception($e->getMessage(), 500); } if ($items) { foreach ($items as &$item) { $text = strtoupper($item->lang_sef); $url = JRoute::_('index.php?option=com_categories&task=category.edit&id=' . (int) $item->id . '&extension=' . $extension); $tooltipParts = array(JHtml::_('image', 'mod_languages/' . $item->image . '.gif', $item->language_title, array('title' => $item->language_title), true), $item->title); $item->link = JHtml::_('tooltip', implode(' ', $tooltipParts), null, null, $text, $url, null, ' label label-association label-' . $item->lang_sef); } } $html = JLayoutHelper::render('joomla.content.associations', $items); } return $html; }
/** * Method to get the associations for a given category * * @param integer $id Id of the item * @param string $extension Name of the component * * @return array Array of associations for the component categories * * @since 3.0 */ public static function getCategoryAssociations($id = 0, $extension = 'com_content') { $return = array(); if ($id) { $associations = CategoriesHelper::getAssociations($id, $extension); foreach ($associations as $tag => $item) { $return[$tag] = ContentHelperRoute::getCategoryRoute($item, $tag); } } return $return; }
public static function getAssociationsForm($id, $name, $config = array()) { if (!self::hasAssociations()) { return ''; } $app = JFactory::getApplication(); $addform = new SimpleXMLElement('<form />'); $extension = $app->input->getString('extension', 'com_content'); $fields = $addform->addChild('fields'); $fields->addAttribute('name', $name); $fieldset = $fields->addChild('fieldset'); $fieldset->addAttribute('name', 'item_associations'); $fieldset->addAttribute('description', 'COM_CATEGORIES_ITEM_ASSOCIATIONS_FIELDSET_DESC'); $fieldset->addAttribute('addfieldpath', '/administrator/components/com_categories/models/fields'); $hasForm = false; $languages = JLanguageHelper::getLanguages('lang_code'); foreach ($languages as $tag => $language) { if (empty($config['language']) || $tag != $config['language']) { $hasForm = true; $f = $fieldset->addChild('field'); $f->addAttribute('name', $tag); $f->addAttribute('type', 'modal_category'); $f->addAttribute('language', $tag); $f->addAttribute('label', $language->title); $f->addAttribute('translate_label', 'false'); $f->addAttribute('extension', $extension); } } $form = JForm::getInstance($id, $addform->asXML()); if ($hasForm) { $form->load($addform, false); $associations = CategoriesHelper::getAssociations($config['pk'], $extension); if (count($associations)) { foreach ($associations as $tag => $association_id) { $form->setValue($tag, $name, $association_id); } } if ($config['translate_id'] && isset($config['translate'])) { $form->setValue($config['translate'], $name, $config['translate_id']); } } // Render Form $fields = $form->getFieldset('item_associations'); $form = ''; foreach ($fields as $f) { $form .= '<div class="control-group"><div class="control-label">' . $f->label . '</div><div class="controls">' . $f->input . '</div></div>'; } return $form; }
/** * Display the view */ public function display($tpl = null) { $JSNMedia = JSNFactory::getMedia(); $JSNMedia->addStyleSheet(JSN_POWERADMIN_STYLE_URI . 'content.css'); JSNHtmlAsset::addScript(JSN_POWERADMIN_LIB_JSNJS_URI . 'jsn.content.js'); //Load language JFactory::getLanguage()->load('com_categories'); $this->form = $this->get('Form'); $this->item = $this->get('Item'); $this->state = $this->get('State'); $this->canDo = CategoriesHelper::getActions($this->state->get('category.component')); // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } parent::display($tpl); }
/** * Method to get the associations for a given category * * @param integer $id Id of the item * @param string $extension Name of the component * * @return array Array of associations for the component categories * * @since 3.0 */ public static function getCategoryAssociations($id = 0, $extension = 'com_content') { $return = array(); if ($id) { // Load route helper jimport('helper.route', JPATH_COMPONENT_SITE); $helperClassname = ucfirst(substr($extension, 4)) . 'HelperRoute'; $associations = CategoriesHelper::getAssociations($id, $extension); foreach ($associations as $tag => $item) { if (class_exists($helperClassname) && is_callable(array($helperClassname, 'getCategoryRoute'))) { $return[$tag] = $helperClassname::getCategoryRoute($item, $tag); } else { $return[$tag] = 'index.php?option=' . $extension . '&view=category&id=' . $item; } } } return $return; }
/** * Method to display a view. * * @return void */ function display() { // Get the document object. $document =& JFactory::getDocument(); // Set the default view name and format from the Request. $vName = JRequest::getWord('view', 'categories'); $vFormat = $document->getType(); $lName = JRequest::getWord('layout', 'default'); // Get and render the view. if ($view =& $this->getView($vName, $vFormat)) { // Get the model for the view. $model =& $this->getModel($vName); // Push the model into the view (as default). $view->setModel($model, true); $view->setLayout($lName); // Push document object into the view. $view->assignRef('document', $document); $view->display(); // Load the submenu. require_once JPATH_COMPONENT . DS . 'helpers' . DS . 'categories.php'; CategoriesHelper::addSubmenu($model->getState('filter.extension')); } }
/** * Method to get the associations for a given category * * @param integer $id Id of the item * @param string $extension Name of the component * * @return array Array of associations for the component categories * * @since 3.0 */ public static function getCategoryAssociations($id = 0, $extension = 'com_content', $view = '') { $return = array(); if ($id) { // if(!is_array($id)){ // Load route helper jimport('helper.route', JPATH_COMPONENT_SITE); $helperClassname = 'TZ_PortfolioHelperRoute'; $associations = CategoriesHelper::getAssociations($id, $extension); foreach ($associations as $tag => $item) { if (class_exists($helperClassname) && is_callable(array($helperClassname, 'getCategoryRoute'))) { $return[$tag] = $helperClassname::getCategoryRoute($item, $tag); } else { $return[$tag] = 'index.php?option=com_tz_portfolio&view=category&id=' . $item; } } // }else{ // $associations = CategoriesHelper::getAssociations($id, $extension); // var_dump($associations); // } } return $return; }
/** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success. * * @since 3.0 */ public function save($data) { $input = JFactory::getApplication()->input; JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php'); // Cast catid to integer for comparison $catid = (int) $data['catid']; // Check if New Category exists if ($catid > 0) { $catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_contact'); } // Save New Category if ($catid == 0 && $this->canCreateCategory()) { $table = array(); $table['title'] = $data['catid']; $table['parent_id'] = 1; $table['extension'] = 'com_contact'; $table['language'] = $data['language']; $table['published'] = 1; // Create new category and get catid back $data['catid'] = CategoriesHelper::createCategory($table); } // Alter the name for save as copy if ($input->get('task') == 'save2copy') { $origTable = clone $this->getTable(); $origTable->load($input->getInt('id')); if ($data['name'] == $origTable->name) { list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['name']); $data['name'] = $name; $data['alias'] = $alias; } else { if ($data['alias'] == $origTable->alias) { $data['alias'] = ''; } } $data['published'] = 0; } $links = array('linka', 'linkb', 'linkc', 'linkd', 'linke'); foreach ($links as $link) { if ($data['params'][$link]) { $data['params'][$link] = JStringPunycode::urlToPunycode($data['params'][$link]); } } return parent::save($data); }
/** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success. * * @since 3.1 */ public function save($data) { $app = JFactory::getApplication(); JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php'); // Cast catid to integer for comparison $catid = (int) $data['catid']; // Check if New Category exists if ($catid > 0) { $catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_weblinks'); } // Save New Category if ($catid == 0 && $this->canCreateCategory()) { $table = array(); $table['title'] = $data['catid']; $table['parent_id'] = 1; $table['extension'] = 'com_weblinks'; $table['language'] = $data['language']; $table['published'] = 1; // Create new category and get catid back $data['catid'] = CategoriesHelper::createCategory($table); } // Alter the title for save as copy if ($app->input->get('task') == 'save2copy') { list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']); $data['title'] = $name; $data['alias'] = $alias; $data['state'] = 0; } return parent::save($data); }
<?php defined('_JEXEC') or die; require_once __DIR__ . '/helper.php'; $categories = CategoriesHelper::getCategories(); if (!empty($categories)) { require JModuleHelper::getLayoutPath('mod_categories', $params->get('layout', 'default')); }
/** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success. * * @since 1.6 */ public function save($data) { $input = JFactory::getApplication()->input; JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php'); // Cast catid to integer for comparison $catid = (int) $data['catid']; // Check if New Category exists if ($catid > 0) { $catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_banners'); } // Save New Category if ($catid == 0) { $table = array(); $table['title'] = $data['catid']; $table['parent_id'] = 1; $table['extension'] = 'com_banners'; $table['language'] = $data['language']; $table['published'] = 1; // Create new category and get catid back $data['catid'] = CategoriesHelper::createCategory($table); } // Alter the name for save as copy if ($input->get('task') == 'save2copy') { /** @var BannersTableBanner $origTable */ $origTable = clone $this->getTable(); $origTable->load($input->getInt('id')); if ($data['name'] == $origTable->name) { list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['name']); $data['name'] = $name; $data['alias'] = $alias; } else { if ($data['alias'] == $origTable->alias) { $data['alias'] = ''; } } $data['state'] = 0; } return parent::save($data); }
<p> <b> <?php echo $form->labelEx($model, 'categoryIds'); ?> </b> </p> <input type="text" name="categoryFilter" class="filter span8" placeholder="<?php echo Yii::t('main', 'text.filter.placeholder'); ?> "/> <div> <?php echo $form->inlineCheckBoxList($model, 'categoryIds', CategoriesHelper::all(), ['template' => '{beginLabel}{input} {labelTitle}{endLabel}', 'separator' => '']); ?> </div> </div> <hr /> <div class="control-group"> <p> <b> <?php echo $form->labelEx($model, 'positionIds'); ?> </b> </p <p> <?php echo Yii::t('main', 'vacancy.label.positionIds.ext');
/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { $categoryId = $this->state->get('filter.category_id'); $component = $this->state->get('filter.component'); $section = $this->state->get('filter.section'); $canDo = null; $user = JFactory::getUser(); $extension = JFactory::getApplication()->input->get('extension', '', 'word'); // Get the toolbar object instance $bar = JToolBar::getInstance('toolbar'); // Avoid nonsense situation. if ($component == 'com_categories') { return; } // Need to load the menu language file as mod_menu hasn't been loaded yet. $lang = JFactory::getLanguage(); $lang->load($component, JPATH_BASE, null, false, false) || $lang->load($component, JPATH_ADMINISTRATOR . '/components/' . $component, null, false, false) || $lang->load($component, JPATH_BASE, $lang->getDefault(), false, false) || $lang->load($component, JPATH_ADMINISTRATOR . '/components/' . $component, $lang->getDefault(), false, false); // Load the category helper. require_once JPATH_COMPONENT . '/helpers/categories.php'; // Get the results for each action. $canDo = CategoriesHelper::getActions($component, $categoryId); // If a component categories title string is present, let's use it. if ($lang->hasKey($component_title_key = strtoupper($component . ($section ? "_{$section}" : '')) . '_CATEGORIES_TITLE')) { $title = JText::_($component_title_key); } elseif ($lang->hasKey($component_section_key = strtoupper($component . ($section ? "_{$section}" : '')))) { $title = JText::sprintf('COM_CATEGORIES_CATEGORIES_TITLE', $this->escape(JText::_($component_section_key))); } else { $title = JText::_('COM_CATEGORIES_CATEGORIES_BASE_TITLE'); } // Load specific css component JHtml::_('stylesheet', $component . '/administrator/categories.css', array(), true); // Prepare the toolbar. JToolbarHelper::title($title, 'categories ' . substr($component, 4) . ($section ? "-{$section}" : '') . '-categories'); if ($canDo->get('core.create') || count($user->getAuthorisedCategories($component, 'core.create')) > 0) { JToolbarHelper::addNew('category.add'); } if ($canDo->get('core.edit') || $canDo->get('core.edit.own')) { JToolbarHelper::editList('category.edit'); } if ($canDo->get('core.edit.state')) { JToolbarHelper::publish('categories.publish', 'JTOOLBAR_PUBLISH', true); JToolbarHelper::unpublish('categories.unpublish', 'JTOOLBAR_UNPUBLISH', true); JToolbarHelper::archiveList('categories.archive'); } if (JFactory::getUser()->authorise('core.admin')) { JToolbarHelper::checkin('categories.checkin'); } if ($this->state->get('filter.published') == -2 && $canDo->get('core.delete', $component)) { JToolbarHelper::deleteList('', 'categories.delete', 'JTOOLBAR_EMPTY_TRASH'); } elseif ($canDo->get('core.edit.state')) { JToolbarHelper::trash('categories.trash'); } // Add a batch button if ($user->authorise('core.create', $extension) & $user->authorise('core.edit', $extension) && $user->authorise('core.edit.state', $extension)) { 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::custom('categories.rebuild', 'refresh.png', 'refresh_f2.png', 'JTOOLBAR_REBUILD', false); JToolbarHelper::preferences($component); } // Compute the ref_key if it does exist in the component if (!$lang->hasKey($ref_key = strtoupper($component . ($section ? "_{$section}" : '')) . '_CATEGORIES_HELP_KEY')) { $ref_key = 'JHELP_COMPONENTS_' . strtoupper(substr($component, 4) . ($section ? "_{$section}" : '')) . '_CATEGORIES'; } // Get help for the categories view for the component by // -remotely searching in a language defined dedicated URL: *component*_HELP_URL // -locally searching in a component help file if helpURL param exists in the component and is set to '' // -remotely searching in a component URL if helpURL param exists in the component and is NOT set to '' if ($lang->hasKey($lang_help_url = strtoupper($component) . '_HELP_URL')) { $debug = $lang->setDebug(false); $url = JText::_($lang_help_url); $lang->setDebug($debug); } else { $url = null; } JToolbarHelper::help($ref_key, JComponentHelper::getParams($component)->exists('helpURL'), $url); JHtmlSidebar::setAction('index.php?option=com_categories&view=categories'); JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_MAX_LEVELS'), 'filter_level', JHtml::_('select.options', $this->f_levels, 'value', 'text', $this->state->get('filter.level'))); 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'))); if (JHelperTags::getTypes('objectList', array($extension . '.category'), true)) { JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_TAG'), 'filter_tag', JHtml::_('select.options', JHtml::_('tag.options', true, true), 'value', 'text', $this->state->get('filter.tag'))); } }
/** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success. * * @since 1.6 */ public function save($data) { $input = JFactory::getApplication()->input; $filter = JFilterInput::getInstance(); if (isset($data['metadata']) && isset($data['metadata']['author'])) { $data['metadata']['author'] = $filter->clean($data['metadata']['author'], 'TRIM'); } if (isset($data['created_by_alias'])) { $data['created_by_alias'] = $filter->clean($data['created_by_alias'], 'TRIM'); } if (isset($data['images']) && is_array($data['images'])) { $registry = new Registry(); $registry->loadArray($data['images']); $data['images'] = (string) $registry; } JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php'); // Cast catid to integer for comparison $catid = (int) $data['catid']; // Check if New Category exists if ($catid > 0) { $catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_content'); } // Save New Categoryg if ($catid == 0 && $this->canCreateCategory()) { $table = array(); $table['title'] = $data['catid']; $table['parent_id'] = 1; $table['extension'] = 'com_content'; $table['language'] = $data['language']; $table['published'] = 1; // Create new category and get catid back $data['catid'] = CategoriesHelper::createCategory($table); } if (isset($data['urls']) && is_array($data['urls'])) { $check = $input->post->get('jform', array(), 'array'); foreach ($data['urls'] as $i => $url) { if ($url != false && ($i == 'urla' || $i == 'urlb' || $i == 'urlc')) { if (preg_match('~^#[a-zA-Z]{1}[a-zA-Z0-9-_:.]*$~', $check['urls'][$i]) == 1) { $data['urls'][$i] = $check['urls'][$i]; } else { $data['urls'][$i] = JStringPunycode::urlToPunycode($url); } } } unset($check); $registry = new Registry(); $registry->loadArray($data['urls']); $data['urls'] = (string) $registry; } // Alter the title for save as copy if ($input->get('task') == 'save2copy') { $origTable = clone $this->getTable(); $origTable->load($input->getInt('id')); if ($data['title'] == $origTable->title) { list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']); $data['title'] = $title; $data['alias'] = $alias; } else { if ($data['alias'] == $origTable->alias) { $data['alias'] = ''; } } $data['state'] = 0; } // Automatic handling of alias for empty fields if (in_array($input->get('task'), array('apply', 'save', 'save2new')) && (!isset($data['id']) || (int) $data['id'] == 0)) { if ($data['alias'] == null) { if (JFactory::getConfig()->get('unicodeslugs') == 1) { $data['alias'] = JFilterOutput::stringURLUnicodeSlug($data['title']); } else { $data['alias'] = JFilterOutput::stringURLSafe($data['title']); } $table = JTable::getInstance('Content', 'JTable'); if ($table->load(array('alias' => $data['alias'], 'catid' => $data['catid']))) { $msg = JText::_('COM_CONTENT_SAVE_WARNING'); } list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']); $data['alias'] = $alias; if (isset($msg)) { JFactory::getApplication()->enqueueMessage($msg, 'warning'); } } } if (parent::save($data)) { if (isset($data['featured'])) { $this->featured($this->getState($this->getName() . '.id'), $data['featured']); } return true; } return false; }
/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { // Initialise variables. $categoryId = $this->state->get('filter.category_id'); $component = $this->state->get('filter.component'); $section = $this->state->get('filter.section'); $canDo = null; // Avoid nonsense situation. if ($component == 'com_categories') { return; } // Need to load the menu language file as mod_menu hasn't been loaded yet. $lang = JFactory::getLanguage(); $lang->load($component, JPATH_BASE, null, false, false) || $lang->load($component, JPATH_ADMINISTRATOR . '/components/' . $component, null, false, false) || $lang->load($component, JPATH_BASE, $lang->getDefault(), false, false) || $lang->load($component, JPATH_ADMINISTRATOR . '/components/' . $component, $lang->getDefault(), false, false); // Load the category helper. require_once JPATH_COMPONENT . '/helpers/categories.php'; // Get the results for each action. $canDo = CategoriesHelper::getActions($component, $categoryId); // If a component categories title string is present, let's use it. if ($lang->hasKey($component_title_key = strtoupper($component . ($section ? "_{$section}" : '')) . '_CATEGORIES_TITLE')) { $title = JText::_($component_title_key); } elseif ($lang->hasKey($component_section_key = strtoupper($component . ($section ? "_{$section}" : '')))) { $title = JText::sprintf('COM_CATEGORIES_CATEGORIES_TITLE', $this->escape(JText::_($component_section_key))); } else { $title = JText::_('COM_CATEGORIES_CATEGORIES_BASE_TITLE'); } // Load specific css component JHtml::_('stylesheet', $component . '/administrator/categories.css', array(), true); // Prepare the toolbar. JToolBarHelper::title($title, 'categories ' . substr($component, 4) . ($section ? "-{$section}" : '') . '-categories'); if ($canDo->get('core.create')) { JToolBarHelper::custom('category.add', 'new.png', 'new_f2.png', 'JTOOLBAR_NEW', false); } if ($canDo->get('core.edit') || $canDo->get('core.edit.own')) { JToolBarHelper::custom('category.edit', 'edit.png', 'edit_f2.png', 'JTOOLBAR_EDIT', true); JToolBarHelper::divider(); } if ($canDo->get('core.edit.state')) { JToolBarHelper::custom('categories.publish', 'publish.png', 'publish_f2.png', 'JTOOLBAR_PUBLISH', true); JToolBarHelper::custom('categories.unpublish', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH', true); JToolBarHelper::divider(); JToolBarHelper::archiveList('categories.archive', 'JTOOLBAR_ARCHIVE'); } if (JFactory::getUser()->authorise('core.admin')) { JToolBarHelper::custom('categories.checkin', 'checkin.png', 'checkin_f2.png', 'JTOOLBAR_CHECKIN', true); } if ($this->state->get('filter.published') == -2 && $canDo->get('core.delete', $component)) { JToolBarHelper::deleteList('', 'categories.delete', 'JTOOLBAR_EMPTY_TRASH'); } else { if ($canDo->get('core.edit.state')) { JToolBarHelper::trash('categories.trash', 'JTOOLBAR_TRASH'); JToolBarHelper::divider(); } } if ($canDo->get('core.admin')) { JToolBarHelper::custom('categories.rebuild', 'refresh.png', 'refresh_f2.png', 'JTOOLBAR_REBUILD', false); JToolBarHelper::preferences($component); JToolBarHelper::divider(); } // Compute the ref_key if it does exist in the component if (!$lang->hasKey($ref_key = strtoupper($component . ($section ? "_{$section}" : '')) . '_CATEGORIES_HELP_KEY')) { $ref_key = 'JHELP_COMPONENTS_' . strtoupper(substr($component, 4) . ($section ? "_{$section}" : '')) . '_CATEGORIES'; } // Get help for the categories view for the component by // -remotely searching in a language defined dedicated URL: *component*_HELP_URL // -locally searching in a component help file if helpURL param exists in the component and is set to '' // -remotely searching in a component URL if helpURL param exists in the component and is NOT set to '' if ($lang->hasKey($lang_help_url = strtoupper($component) . '_HELP_URL')) { $debug = $lang->setDebug(false); $url = JText::_($lang_help_url); $lang->setDebug($debug); } else { $url = null; } JToolBarHelper::help($ref_key, JComponentHelper::getParams($component)->exists('helpURL'), $url); }
/** * Method to get a category. * * @param integer $pk An optional id of the object to get, otherwise the id from the model state is used. * * @return mixed Category data object on success, false on failure. * * @since 1.6 */ public function getItem($pk = null) { if ($result = parent::getItem($pk)) { // Prime required properties. if (empty($result->id)) { $result->parent_id = $this->getState('category.parent_id'); $result->extension = $this->getState('category.extension'); } // Convert the metadata field to an array. $registry = new Registry(); $registry->loadString($result->metadata); $result->metadata = $registry->toArray(); // Convert the created and modified dates to local user time for display in the form. $tz = new DateTimeZone(JFactory::getApplication()->get('offset')); if ((int) $result->created_time) { $date = new JDate($result->created_time); $date->setTimezone($tz); $result->created_time = $date->toSql(true); } else { $result->created_time = null; } if ((int) $result->modified_time) { $date = new JDate($result->modified_time); $date->setTimezone($tz); $result->modified_time = $date->toSql(true); } else { $result->modified_time = null; } if (!empty($result->id)) { $result->tags = new JHelperTags(); $result->tags->getTagIds($result->id, $result->extension . '.category'); } } $assoc = $this->getAssoc(); if ($assoc) { if ($result->id != null) { $result->associations = CategoriesHelper::getAssociations($result->id, $result->extension); JArrayHelper::toInteger($result->associations); } else { $result->associations = array(); } } return $result; }
/** * Method to get a category. * * @param integer An optional id of the object to get, otherwise the id from the model state is used. * @return mixed Category data object on success, false on failure. * @since 1.6 */ public function getItem($pk = null) { $pk = $pk ? $pk : $this->_id; if ($result = parent::getItem($pk)) { // Prime required properties. if (empty($result->id)) { $result->parent_id = $this->getState('com_flexicontent.category.parent_id'); $result->extension = $this->getState('com_flexicontent.category.extension'); } // Convert the metadata field to an array. $registry = new JRegistry($result->metadata); $result->metadata = $registry->toArray(); // Convert the created and modified dates to local user time for display in the form. jimport('joomla.utilities.date'); $site_zone = JFactory::getApplication()->getCfg('offset'); $user_zone = JFactory::getUser()->getParam('timezone', $site_zone); $tz_string = $user_zone; $tz = new DateTimeZone($tz_string); if (intval($result->created_time)) { $date = new JDate($result->created_time); $date->setTimezone($tz); $result->created_time = $date->toSql(true); } else { $result->created_time = null; } if (intval($result->modified_time)) { $date = new JDate($result->modified_time); $date->setTimezone($tz); $result->modified_time = $date->toSql(true); } else { $result->modified_time = null; } $this->_category = $result; } $useAssocs = $this->useAssociations(); if ($useAssocs) { if ($result->id != null) { $result->associations = CategoriesHelper::getAssociations($result->id, $result->extension); JArrayHelper::toInteger($result->associations); } else { $result->associations = array(); } } return $result; }
/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { // Initialise variables. $extension = JRequest::getCmd('extension'); $user = JFactory::getUser(); $userId = $user->get('id'); $isNew = $this->item->id == 0; $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $userId); // Avoid nonsense situation. if ($extension == 'com_categories') { return; } // The extension can be in the form com_foo.section $parts = explode('.', $extension); $component = $parts[0]; $section = count($parts) > 1 ? $parts[1] : null; // Need to load the menu language file as mod_menu hasn't been loaded yet. $lang = JFactory::getLanguage(); $lang->load($component, JPATH_BASE, null, false, true) || $lang->load($component, JPATH_ADMINISTRATOR . '/components/' . $component, null, false, true); // Load the category helper. require_once JPATH_COMPONENT . '/helpers/categories.php'; // Get the results for each action. $canDo = CategoriesHelper::getActions($component, $this->item->id); // If a component categories title string is present, let's use it. if ($lang->hasKey($component_title_key = $component . ($section ? "_{$section}" : '') . '_CATEGORY_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE')) { $title = JText::_($component_title_key); } elseif ($lang->hasKey($component_section_key = $component . ($section ? "_{$section}" : ''))) { $title = JText::sprintf('COM_CATEGORIES_CATEGORY_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE', $this->escape(JText::_($component_section_key))); } else { $title = JText::_('COM_CATEGORIES_CATEGORY_BASE_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE'); } // Load specific css component JHtml::_('stylesheet', $component . '/administrator/categories.css', array(), true); // Prepare the toolbar. JToolBarHelper::title($title, 'category-' . ($isNew ? 'add' : 'edit') . ' ' . substr($component, 4) . ($section ? "-{$section}" : '') . '-category-' . ($isNew ? 'add' : 'edit')); // For new records, check the create permission. if ($isNew && count($user->getAuthorisedCategories($component, 'core.create')) > 0) { JToolBarHelper::apply('category.apply'); JToolBarHelper::save('category.save'); JToolBarHelper::save2new('category.save2new'); } elseif (!$checkedOut && ($canDo->get('core.edit') || $canDo->get('core.edit.own') && $this->item->created_user_id == $userId)) { JToolBarHelper::apply('category.apply'); JToolBarHelper::save('category.save'); if ($canDo->get('core.create')) { JToolBarHelper::save2new('category.save2new'); } } // If an existing item, can save to a copy. if (!$isNew && $canDo->get('core.create')) { JToolBarHelper::save2copy('category.save2copy'); } if (empty($this->item->id)) { JToolBarHelper::cancel('category.cancel'); } else { JToolBarHelper::cancel('category.cancel', 'JTOOLBAR_CLOSE'); } JToolBarHelper::divider(); // Compute the ref_key if it does exist in the component if (!$lang->hasKey($ref_key = strtoupper($component . ($section ? "_{$section}" : '')) . '_CATEGORY_' . ($isNew ? 'ADD' : 'EDIT') . '_HELP_KEY')) { $ref_key = 'JHELP_COMPONENTS_' . strtoupper(substr($component, 4) . ($section ? "_{$section}" : '')) . '_CATEGORY_' . ($isNew ? 'ADD' : 'EDIT'); } // Get help for the category/section view for the component by // -remotely searching in a language defined dedicated URL: *component*_HELP_URL // -locally searching in a component help file if helpURL param exists in the component and is set to '' // -remotely searching in a component URL if helpURL param exists in the component and is NOT set to '' if ($lang->hasKey($lang_help_url = strtoupper($component) . '_HELP_URL')) { $debug = $lang->setDebug(false); $url = JText::_($lang_help_url); $lang->setDebug($debug); } else { $url = null; } JToolBarHelper::help($ref_key, JComponentHelper::getParams($component)->exists('helpURL'), $url, $component); }
/** * Method to get a category. * * @param integer $pk An optional id of the object to get, otherwise the id from the model state is used. * * @return mixed Category data object on success, false on failure. * * @since 1.6 */ public function getItem($pk = null) { if ($result = parent::getItem($pk)) { // Prime required properties. if (empty($result->id)) { $result->parent_id = $this->getState('category.parent_id'); $result->extension = $this->getState('category.extension'); } // Convert the metadata field to an array. $registry = new JRegistry(); $registry->loadString($result->metadata); $result->metadata = $registry->toArray(); // Convert the created and modified dates to local user time for display in the form. jimport('joomla.utilities.date'); $tz = new DateTimeZone(JFactory::getApplication()->getCfg('offset')); if (intval($result->created_time)) { $date = new JDate($result->created_time); $date->setTimezone($tz); $result->created_time = $date->toSql(true); } else { $result->created_time = null; } if (intval($result->modified_time)) { $date = new JDate($result->modified_time); $date->setTimezone($tz); $result->modified_time = $date->toSql(true); } else { $result->modified_time = null; } } if (COM_TZ_PORTFOLIO_JVERSION_COMPARE) { $assoc = $this->getAssoc(); if ($assoc) { if ($result->id != null) { $result->associations = CategoriesHelper::getAssociations($result->id, $result->extension); JArrayHelper::toInteger($result->associations); } else { $result->associations = array(); } } } return $result; }