/** * @param null $tpl * * @return bool */ function display($tpl = null) { $this->state = $this->get('State'); $this->params = $this->state->get('params'); $this->item = $this->get('Item'); $this->items = $this->get('Items'); $this->extensions = $this->get('Extensions'); $this->canEdit = JFactory::getUser()->authorise('core.edit', 'com_xmap.sitemap.' . $this->item->id); // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseWarning(500, implode("\n", $errors)); return false; } $this->displayer = new XmapDisplayerHtml($this->item, $this->items, $this->extensions); $this->displayer->setCanEdit($this->canEdit); $this->pageclass_sfx = htmlspecialchars($this->params->get('pageclass_sfx')); $this->prepareDocument(); parent::display($tpl); $this->getModel()->hit($this->displayer->getCount()); }
/** * @param $uid * @param $itemid * * @return int */ public function toggleItem($uid, $itemid) { $sitemap = $this->getItem(); $items = $this->getItems(); $extensions = $this->getExtensions(); $displayer = new XmapDisplayerHtml($sitemap, $items, $extensions); $excludedItems = $displayer->getExcludedItems(); if (isset($excludedItems[$itemid])) { $excludedItems[$itemid] = (array) $excludedItems[$itemid]; } if (!$displayer->isExcluded($itemid, $uid)) { $excludedItems[$itemid][] = $uid; $state = 0; } else { if (is_array($excludedItems[$itemid]) && count($excludedItems[$itemid])) { // TODO refactor, create_function is bad $excludedItems[$itemid] = array_filter($excludedItems[$itemid], create_function('$var', 'return ($var != \'' . $uid . '\');')); } else { unset($excludedItems[$itemid]); } $state = 1; } $registry = new Registry(); $registry->loadArray($excludedItems); $str = $registry->toString(); $db = JFactory::getDbo(); $query = $db->getQuery(true)->update('#__xmap_sitemap AS s')->set('s.excluded_items = ' . $db->quote($str))->where('s.id = ' . $db->quote($sitemap->id)); $db->setQuery($query); $db->execute(); return $state; }