static function edit($weblink, $params, $attribs = array()) { $user = JFactory::getUser(); $uri = JFactory::getURI(); if ($params && $params->get('popup')) { return; } if ($weblink->state < 0) { return; } JHtml::_('behavior.tooltip'); $url = WeblinksHelperRoute::getFormRoute($weblink->id, base64_encode($uri)); $icon = $weblink->state ? 'edit.png' : 'edit_unpublished.png'; $text = JHtml::_('image', 'system/' . $icon, JText::_('JGLOBAL_EDIT'), NULL, true); if ($weblink->state == 0) { $overlib = JText::_('JUNPUBLISHED'); } else { $overlib = JText::_('JPUBLISHED'); } $date = JHtml::_('date', $weblink->created); $author = $weblink->created_by_alias ? $weblink->created_by_alias : $weblink->author; $overlib .= '<br />'; $overlib .= $date; $overlib .= '<br />'; $overlib .= htmlspecialchars($author, ENT_COMPAT, 'UTF-8'); $button = JHtml::_('link', JRoute::_($url), $text); $output = '<span class="hasTip" title="' . JText::_('COM_WEBLINKS_EDIT') . ' :: ' . $overlib . '">' . $button . '</span>'; return $output; }
/** * Prepares the document * * @return void */ protected function prepareDocument() { $app = JFactory::getApplication(); $menus = $app->getMenu(); $pathway = $app->getPathway(); $title = null; // Because the application sets a default page title, // we need to get it from the menu item itself $menu = $menus->getActive(); if ($menu) { $this->params->def('page_heading', $this->params->get('page_title', $menu->title)); } else { $this->params->def('page_heading', JText::_('COM_WEBLINKS_DEFAULT_PAGE_TITLE')); } $id = (int) @$menu->query['id']; if ($menu && ($menu->query['option'] != 'com_weblinks' || $id != $this->category->id)) { $this->params->set('page_subheading', $this->category->title); $path = array(array('title' => $this->category->title, 'link' => '')); $category = $this->category->getParent(); while (($menu->query['option'] != 'com_weblinks' || $id != $category->id) && $category->id > 1) { $path[] = array('title' => $category->title, 'link' => WeblinksHelperRoute::getCategoryRoute($category->id)); $category = $category->getParent(); } $path = array_reverse($path); foreach ($path as $item) { $pathway->addItem($item['title'], $item['link']); } } parent::addFeed(); }
function getItems($args) { $items = array(); switch ($args->view) { // Get all WebLink categories default: case 'categories': $categories = AdvLink::getCategory('com_weblinks'); foreach ($categories as $category) { $itemid = AdvLink::getItemId('com_weblinks', array('categories' => null, 'category' => $category->id)); $items[] = array('id' => 'index.php?option=com_weblinks&view=category&id=' . $category->id . $itemid, 'name' => $category->title . ' / ' . $category->alias, 'class' => 'folder weblink'); } break; // Get all links in the category // Get all links in the category case 'category': require_once JPATH_SITE . DS . 'includes' . DS . 'application.php'; require_once JPATH_SITE . DS . 'components' . DS . 'com_weblinks' . DS . 'helpers' . DS . 'route.php'; $weblinks = AdvlinkWeblinks::_weblinks($args->id); foreach ($weblinks as $weblink) { $items[] = array('id' => WeblinksHelperRoute::getWeblinkRoute($weblink->id, $args->id), 'name' => $weblink->title . ' / ' . $weblink->alias, 'class' => 'file'); } break; } return $items; }
function display($tpl = null) { $app = JFactory::getApplication(); $document = JFactory::getDocument(); $document->link = JRoute::_(WeblinksHelperRoute::getCategoryRoute(JRequest::getVar('id', null, '', 'int'))); JRequest::setVar('limit', $app->getCfg('feed_limit')); $siteEmail = $app->getCfg('mailfrom'); $fromName = $app->getCfg('fromname'); $document->editor = $fromName; $document->editorEmail = $siteEmail; // Get some data from the model $items = $this->get('Items'); $category = $this->get('Category'); foreach ($items as $item) { // strip html from feed item title $title = $this->escape($item->title); $title = html_entity_decode($title, ENT_COMPAT, 'UTF-8'); // url link to article $link = JRoute::_(WeblinksHelperRoute::getWeblinkRoute($item->slug, $item->catid)); // strip html from feed item description text $description = $item->description; $date = $item->date ? date('r', strtotime($item->date)) : ''; // load individual item creator class $feeditem = new JFeedItem(); $feeditem->title = $title; $feeditem->link = $link; $feeditem->description = $description; $feeditem->date = $date; $feeditem->category = 'Weblinks'; // loads item info into rss array $document->addItem($feeditem); } }
function getWeblinkRoute($id, $catid) { $needles = array('category' => (int) $catid, 'categories' => null); $itemid = WeblinksHelperRoute::_findItem($needles); $itemid = $itemid ? '&Itemid=' . $itemid : ''; $link = 'index.php?option=com_weblinks&view=weblink&id=' . $id . '&catid=' . $catid . $itemid; return $link; }
function display($tpl = null) { $app = JFactory::getApplication(); $document = JFactory::getDocument(); $document->link = JRoute::_(WeblinksHelperRoute::getCategoryRoute(JRequest::getVar('id', null, '', 'int'))); JRequest::setVar('limit', $app->getCfg('feed_limit')); $params = $app->getParams(); $siteEmail = $app->getCfg('mailfrom'); $fromName = $app->getCfg('fromname'); $feedEmail = $app->getCfg('feed_email', 'author'); $document->editor = $fromName; if ($feedEmail != "none") { $document->editorEmail = $siteEmail; } // Get some data from the model $items = $this->get('Items'); $category = $this->get('Category'); foreach ($items as $item) { // strip html from feed item title $title = $this->escape($item->title); $title = html_entity_decode($title, ENT_COMPAT, 'UTF-8'); // url link to article $link = JRoute::_(WeblinksHelperRoute::getWeblinkRoute($item->id, $item->catid)); // strip html from feed item description text $description = $item->description; $author = $item->created_by_alias ? $item->created_by_alias : $item->author; $date = $item->date ? date('r', strtotime($item->date)) : ''; // load individual item creator class $feeditem = new JFeedItem(); $feeditem->title = $title; $feeditem->link = $link; $feeditem->description = $description; $feeditem->date = $date; $feeditem->category = $category->title; $feeditem->author = $author; // We don't have the author email so we have to use site in both cases. if ($feedEmail == 'site') { $feeditem->authorEmail = $siteEmail; } elseif ($feedEmail === 'author') { $feeditem->authorEmail = $item->author_email; } // loads item info into rss array $document->addItem($feeditem); } }
public static function getCategoryRoute($catid) { jimport('joomla.application.categories'); $categoryTree = JCategories::getInstance('com_weblinks'); $category = $categoryTree->get($catid); $catids = array(); $catids[] = $category->id; while ($category->getParent() instanceof JCategoryNode) { $category = $category->getParent(); $catids[] = $category->id; } $catids = array_reverse($catids); $needles = array('category' => $catids); $category = $categoryTree->get($catid); //Create the link $link = 'index.php?option=com_weblinks&view=category&id=' . $category->slug; if ($item = WeblinksHelperRoute::_findItem($needles)) { if (isset($item->query['layout'])) { $link .= '&layout=' . $item->query['layout']; } $link .= '&Itemid=' . $item->id; } return $link; }
defined('_JEXEC') or die; ?> <?php if (count($this->children[$this->category->id]) > 0 && $this->maxLevel != 0) { ?> <ul> <?php foreach ($this->children[$this->category->id] as $id => $child) { ?> <?php if ($this->params->get('show_empty_categories') || $child->numitems || count($child->getChildren())) { ?> <li> <a href="<?php echo JRoute::_(WeblinksHelperRoute::getCategoryRoute($child->id)); ?> "><?php echo $this->escape($child->title); ?> </a> <?php if ($this->params->get('show_cat_items') == 1) { ?> <small>(<?php echo $child->numitems; ?> )</small> <?php }
<?php if ($this->params->get('show_empty_categories_cat') || $item->numitems || count($item->getChildren())) { if (!isset($this->items[$this->parent->id][$id + 1])) { $class = ' class="last"'; } ?> <div <?php echo $class; ?> > <?php $class = ''; ?> <h3 class="page-header item-title"> <a href="<?php echo JRoute::_(WeblinksHelperRoute::getCategoryRoute($item->id)); ?> "> <?php echo $this->escape($item->title); ?> </a> <?php if ($this->params->get('show_cat_num_articles_cat') == 1) { ?> <span class="badge badge-info tip hasTooltip" title="<?php echo JHtml::tooltipText('COM_WEBLINKS_NUM_ITEMS'); ?> "> <?php echo $item->numitems;
protected static function _findItem($needles = null) { $app = JFactory::getApplication(); $menus = $app->getMenu('site'); // Prepare the reverse lookup array. if (self::$lookup === null) { self::$lookup = array(); $component = JComponentHelper::getComponent('com_weblinks'); $items = $menus->getItems('component_id', $component->id); foreach ($items as $item) { if (isset($item->query) && isset($item->query['view'])) { $view = $item->query['view']; if (!isset(self::$lookup[$view])) { self::$lookup[$view] = array(); } if (isset($item->query['id'])) { self::$lookup[$view][$item->query['id']] = $item->id; } } } } if ($needles) { foreach ($needles as $view => $ids) { if (isset(self::$lookup[$view])) { foreach ($ids as $id) { if (isset(self::$lookup[$view][(int) $id])) { return self::$lookup[$view][(int) $id]; } } } } } else { $active = $menus->getActive(); if ($active) { return $active->id; } } return null; }
/** * @param XmapDisplayerInterface $xmap * @param stdClass $parent * @param array $params * @param int $catid */ private static function getlinks($xmap, stdClass $parent, array &$params, $catid) { self::getCategoryTree($xmap, $parent, $params, $catid); if (!$params['include_links']) { return; } $db = JFactory::getDbo(); $now = JFactory::getDate('now', 'UTC')->toSql(); $query = $db->getQuery(true)->select(array('w.id', 'w.alias', 'w.title'))->from('#__weblinks AS w')->where('w.catid = ' . $db->Quote($catid))->where('w.state = 1')->where('(w.publish_up = ' . $db->quote($db->getNullDate()) . ' OR w.publish_up <= ' . $db->quote($now) . ')')->where('(w.publish_down = ' . $db->quote($db->getNullDate()) . ' OR w.publish_down >= ' . $db->quote($now) . ')')->order('w.ordering'); if (!$params['show_unauth']) { $query->where('w.access IN(' . $params['groups'] . ')'); } if ($params['language_filter']) { $query->where('w.language IN(' . $db->quote(JFactory::getLanguage()->getTag()) . ', ' . $db->quote('*') . ')'); } $db->setQuery($query); $rows = $db->loadObjectList(); if (empty($rows)) { return; } $xmap->changeLevel(1); foreach ($rows as $row) { $node = new stdclass(); $node->id = $parent->id; $node->name = $row->title; $node->uid = $parent->uid . '_' . $row->id; $node->browserNav = $parent->browserNav; $node->priority = $params['link_priority']; $node->changefreq = $params['link_changefreq']; $node->link = WeblinksHelperRoute::getWeblinkRoute($row->id . ':' . $row->alias, $catid); $xmap->printNode($node); } $xmap->changeLevel(-1); }
JHtml::_('bootstrap.tooltip'); if (count($this->items[$this->parent->id]) > 0 && $this->maxLevelcat != 0) : ?> <?php foreach($this->items[$this->parent->id] as $id => $item) : ?> <?php if ($this->params->get('show_empty_categories_cat') || $item->numitems || count($item->getChildren())) : if (!isset($this->items[$this->parent->id][$id + 1])) { $class = ' class="last"'; } ?> <div <?php echo $class; ?> > <?php $class = ''; ?> <h3 class="page-header item-title"> <a href="<?php echo JRoute::_(WeblinksHelperRoute::getCategoryRoute($item->id));?>"> <?php echo $this->escape($item->title); ?></a> <?php if ($this->params->get('show_cat_num_articles_cat') == 1) :?> <span class="badge badge-info tip hasTooltip" title="<?php echo JText::_('COM_WEBLINKS_NUM_ITEMS'); ?>"> <?php echo $item->numitems; ?> </span> <?php endif; ?> <?php if (count($item->getChildren()) > 0) : ?> <a href="#category-<?php echo $item->id;?>" data-toggle="collapse" data-toggle="button" class="btn btn-mini pull-right"><span class="icon-plus"></span></a> <?php endif;?> </h3> <?php if ($this->params->get('show_subcat_desc_cat') == 1) :?> <?php if ($item->description) : ?> <div class="category-desc"> <?php echo JHtml::_('content.prepare', $item->description, '', 'com_weblinks.categories'); ?> </div>
public function getLinks($args) { $wf = WFEditorPlugin::getInstance(); $items = array(); switch ($args->view) { // Get all WebLink categories default: case 'categories': $categories = WFLinkBrowser::getCategory('com_weblinks'); foreach ($categories as $category) { if (method_exists('WeblinksHelperRoute', 'getCategoryRoute')) { $id = WeblinksHelperRoute::getCategoryRoute($category->id); } else { $itemid = WFLinkBrowser::getItemId('com_weblinks', array('categories' => null, 'category' => $category->id)); $id = 'index.php?option=com_weblinks&view=category&id=' . $category->id . $itemid; } $items[] = array('id' => $id, 'name' => $category->title . ' / ' . $category->alias, 'class' => 'folder weblink'); } break; // Get all links in the category // Get all links in the category case 'category': require_once JPATH_SITE . DS . 'includes' . DS . 'application.php'; require_once JPATH_SITE . DS . 'components' . DS . 'com_weblinks' . DS . 'helpers' . DS . 'route.php'; if (!WF_JOOMLA15) { $categories = WFLinkBrowser::getCategory('com_weblinks', $args->id); if (count($categories)) { foreach ($categories as $category) { $children = WFLinkBrowser::getCategory('com_weblinks', $category->id); if ($children) { $id = 'index.php?option=com_weblinks&view=category&id=' . $category->id; } else { if (method_exists('WeblinksHelperRoute', 'getCategoryRoute')) { $id = WeblinksHelperRoute::getCategoryRoute($category->id); } else { $itemid = WFLinkBrowser::getItemId('com_weblinks', array('categories' => null, 'category' => $category->id)); $id = 'index.php?option=com_weblinks&view=category&id=' . $category->id . $itemid; } } $items[] = array('id' => $id, 'name' => $category->title . ' / ' . $category->alias, 'class' => 'folder weblink'); } } } $weblinks = self::_weblinks($args->id); foreach ($weblinks as $weblink) { $items[] = array('id' => WeblinksHelperRoute::getWeblinkRoute($weblink->slug, $weblink->catslug), 'name' => $weblink->title . ' / ' . $weblink->alias, 'class' => 'file'); } break; } return $items; }
static function getCategoryTree($xmap, $parent, &$params, $category) { $db = JFactory::getDBO(); $children = $category->getChildren(); $xmap->changeLevel(1); foreach ($children as $cat) { $node = new stdclass(); $node->id = $parent->id; $node->uid = $parent->uid . 'c' . $cat->id; $node->name = $cat->title; $node->link = WeblinksHelperRoute::getCategoryRoute($cat); $node->priority = $params['cat_priority']; $node->changefreq = $params['cat_changefreq']; $node->expandible = true; if ($xmap->printNode($node) !== FALSE) { xmap_com_weblinks::getCategoryTree($xmap, $parent, $params, $cat); } } $xmap->changeLevel(-1); if ($params['include_links']) { //view=category&catid=... $linksModel = new WeblinksModelCategory(); $linksModel->getState(); // To force the populate state $linksModel->setState('list.limit', JArrayHelper::getValue($params, 'max_links', NULL)); $linksModel->setState('list.start', 0); $linksModel->setState('list.ordering', 'ordering'); $linksModel->setState('list.direction', 'ASC'); $linksModel->setState('category.id', $category->id); $links = $linksModel->getItems(); $xmap->changeLevel(1); foreach ($links as $link) { $item_params = new JRegistry(); $item_params->loadString($link->params); $node = new stdclass(); $node->id = $parent->id; $node->uid = $parent->uid . 'i' . $link->id; $node->name = $link->title; // Find the Itemid $Itemid = intval(preg_replace('/.*Itemid=([0-9]+).*/', '$1', WeblinksHelperRoute::getWeblinkRoute($link->id, $category->id))); if ($item_params->get('count_clicks', $params['count_clicks']) == 1) { $node->link = 'index.php?option=com_weblinks&task=weblink.go&id=' . $link->id . '&Itemid=' . ($Itemid ? $Itemid : $parent->id); } else { $node->link = $link->url; } $node->priority = $params['link_priority']; $node->changefreq = $params['link_changefreq']; $node->expandible = false; $xmap->printNode($node); } $xmap->changeLevel(-1); } }
<?php defined('_JEXEC') or die; ?> <?php if (count($this->items[$this->parent->id]) > 0 && $this->maxLevelcat != 0) : ?> <ul> <?php foreach($this->items[$this->parent->id] as $id => $item) : ?> <?php if ($this->params->get('show_empty_categories_cat') || $item->numitems || count($item->getChildren())) : ?> <li> <a href="<?php echo JRoute::_(WeblinksHelperRoute::getCategoryRoute($item->id));?>"><?php echo $this->escape($item->title); ?></a> <?php if ($this->params->get('show_cat_items_cat') == 1) : ?> <small>(<?php echo $item->numitems; ?>)</small> <?php endif; ?> <?php if (($this->params->get('show_subcat_desc_cat') == 1) && $item->description) : ?> <div><?php echo JHtml::_('content.prepare', $item->description, '', 'com_weblinks.categories'); ?></div> <?php endif; ?> <?php if (count($item->getChildren()) > 0) { $this->items[$item->id] = $item->getChildren(); $this->parent = $item; $this->maxLevelcat--; echo $this->loadTemplate('items'); $this->parent = $item->getParent(); $this->maxLevelcat++; } ?> </li>
/** * Weblink Search method * * The sql must return the following fields that are used in a common display * routine: href, title, section, created, text, browsernav * @param string Target search string * @param string mathcing option, exact|any|all * @param string ordering option, newest|oldest|popular|alpha|category * @param mixed An array if the search it to be restricted to areas, null if search all */ function plgSearchJFWeblinks($text, $phrase = '', $ordering = '', $areas = null) { $db =& JFactory::getDBO(); $user =& JFactory::getUser(); $registry =& JFactory::getConfig(); $lang = $registry->getValue("config.jflang"); require_once JPATH_SITE . DS . 'components' . DS . 'com_weblinks' . DS . 'helpers' . DS . 'route.php'; if (is_array($areas)) { if (!array_intersect($areas, array_keys(plgSearchWeblinksAreas()))) { return array(); } } // load plugin params info $plugin =& JPluginHelper::getPlugin('search', 'jfweblinks'); $pluginParams = new JParameter($plugin->params); $limit = $pluginParams->def('search_limit', 50); $activeLang = $pluginParams->def('active_language_only', 0); $text = trim($text); if ($text == '') { return array(); } $section = JText::_('Web Links'); $wheres = array(); switch ($phrase) { case 'exact': $text = $db->Quote('%' . $db->getEscaped($text, true) . '%', false); $where = "LOWER(jfc.value) LIKE " . $text; break; case 'all': case 'any': default: $words = explode(' ', $text); $wheres = array(); foreach ($words as $word) { $word = $db->Quote('%' . $db->getEscaped($word, true) . '%', false); $wheres[] = "LOWER(jfc.value) LIKE " . $word; } $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')'; break; } switch ($ordering) { case 'oldest': $order = 'a.date ASC'; break; case 'popular': $order = 'a.hits DESC'; break; case 'alpha': $order = 'a.title ASC'; break; case 'category': $order = 'b.title ASC, a.title ASC'; break; case 'newest': default: $order = 'a.date DESC'; } $query = 'SELECT a.id as wltid, b.id as catid, a.title AS title, a.description AS text, a.date AS created,' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug, ' . ' CASE WHEN CHAR_LENGTH(b.alias) THEN CONCAT_WS(\':\', b.id, b.alias) ELSE b.id END as catslug, ' . ' b.title as btitle, ' . ' "1" AS browsernav,' . ' jfl.code as jflang, jfl.name as jflname' . ' FROM #__weblinks AS a' . ' INNER JOIN #__categories AS b ON b.id = a.catid' . "\n LEFT JOIN #__jf_content as jfc ON reference_id = a.id" . "\n LEFT JOIN #__languages as jfl ON jfc.language_id = jfl.id" . ' WHERE (' . $where . ')' . ' AND a.published = 1' . ' AND b.published = 1' . ' AND b.access <= ' . (int) $user->get('aid') . "\n AND jfc.reference_table = 'weblinks'" . ($activeLang ? "\n AND jfl.code = '{$lang}'" : '') . ' GROUP BY a.id' . ' ORDER BY ' . $order; $db->setQuery($query, 0, $limit); $rows = $db->loadObjectList(); foreach ($rows as $key => $row) { $rows[$key]->section = $db->Quote($section) . "/" . $row->btitle . " - " . $row->jflname; $rows[$key]->href = WeblinksHelperRoute::getWeblinkRoute($row->slug, $row->catslug); } return $rows; }
/** * Method to index an item. The item must be a FinderIndexerResult object. * * @param FinderIndexerResult $item The item to index as an FinderIndexerResult object. * @param string $format The item format * * @return void * * @since 2.5 * @throws Exception on database error. */ protected function index(FinderIndexerResult $item, $format = 'html') { // Check if the extension is enabled if (JComponentHelper::isEnabled($this->extension) == false) { return; } // Initialize the item parameters. $registry = new JRegistry(); $registry->loadString($item->params); $item->params = $registry; $registry = new JRegistry(); $registry->loadString($item->metadata); $item->metadata = $registry; // Build the necessary route and path information. $item->url = $this->getURL($item->id, $this->extension, $this->layout); $item->route = WeblinksHelperRoute::getWeblinkRoute($item->slug, $item->catslug); $item->path = FinderIndexerHelper::getContentPath($item->route); /* * Add the meta-data processing instructions based on the newsfeeds * configuration parameters. */ // Add the meta-author. $item->metaauthor = $item->metadata->get('author'); // Handle the link to the meta-data. $item->addInstruction(FinderIndexer::META_CONTEXT, 'link'); $item->addInstruction(FinderIndexer::META_CONTEXT, 'metakey'); $item->addInstruction(FinderIndexer::META_CONTEXT, 'metadesc'); $item->addInstruction(FinderIndexer::META_CONTEXT, 'metaauthor'); $item->addInstruction(FinderIndexer::META_CONTEXT, 'author'); $item->addInstruction(FinderIndexer::META_CONTEXT, 'created_by_alias'); // Add the type taxonomy data. $item->addTaxonomy('Type', 'Web Link'); // Add the category taxonomy data. $item->addTaxonomy('Category', $item->category, $item->cat_state, $item->cat_access); // Add the language taxonomy data. $item->addTaxonomy('Language', $item->language); // Get content extras. FinderIndexerHelper::getContentExtras($item); // Index the item. FinderIndexer::index($item); }
static function getCategoryTree($xmap, $parent, &$params, $category) { $db = JFactory::getDBO(); $children = $category->getChildren(); $xmap->changeLevel(1); foreach ($children as $cat) { $node = new stdclass(); $node->id = $parent->id; $node->uid = $parent->uid . 'c' . $cat->id; $node->name = $cat->title; $node->link = WeblinksHelperRoute::getCategoryRoute($cat); $node->priority = $params['cat_priority']; $node->changefreq = $params['cat_changefreq']; $node->expandible = true; if ($xmap->printNode($node) !== FALSE) { xmap_com_weblinks::getCategoryTree($xmap, $parent, $params, $cat); } } $xmap->changeLevel(-1); if ($params['include_links']) { //view=category&catid=... $linksModel = new WeblinksModelCategory(); $linksModel->getState(); // To force the populate state $linksModel->setState('list.limit', JArrayHelper::getValue($params, 'max_links', NULL)); $linksModel->setState('list.start', 0); $linksModel->setState('list.ordering', 'ordering'); $linksModel->setState('list.direction', 'ASC'); $linksModel->setState('category.id', $category->id); $links = $linksModel->getItems(); $xmap->changeLevel(1); foreach ($links as $link) { $node = new stdclass(); $node->id = $parent->id; $node->uid = $parent->uid . 'i' . $link->id; $node->name = $link->title; $node->link = WeblinksHelperRoute::getWeblinkRoute($link->id, $category->id); $node->priority = $params['link_priority']; $node->changefreq = $params['link_changefreq']; $node->expandible = false; $xmap->printNode($node); } $xmap->changeLevel(-1); } }
/** * Search content (weblinks). * * The SQL must return the following fields that are used in a common display * routine: href, title, section, created, text, browsernav * * @param string $text Target search string. * @param string $phrase Matching option (possible values: exact|any|all). Default is "any". * @param string $ordering Ordering option (possible values: newest|oldest|popular|alpha|category). Default is "newest". * @param mixed $areas An array if the search it to be restricted to areas or null to search all areas. * * @return array Search results. * * @since 1.6 */ public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null) { $db = JFactory::getDbo(); $app = JFactory::getApplication(); $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); $searchText = $text; if (is_array($areas)) { if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) { return array(); } } $sContent = $this->params->get('search_content', 1); $sArchived = $this->params->get('search_archived', 1); $limit = $this->params->def('search_limit', 50); $state = array(); if ($sContent) { $state[] = 1; } if ($sArchived) { $state[] = 2; } if (empty($state)) { return array(); } $text = trim($text); if ($text == '') { return array(); } $searchWeblinks = JText::_('PLG_SEARCH_WEBLINKS'); switch ($phrase) { case 'exact': $text = $db->quote('%' . $db->escape($text, true) . '%', false); $wheres2 = array(); $wheres2[] = 'a.url LIKE ' . $text; $wheres2[] = 'a.description LIKE ' . $text; $wheres2[] = 'a.title LIKE ' . $text; $where = '(' . implode(') OR (', $wheres2) . ')'; break; case 'all': case 'any': default: $words = explode(' ', $text); $wheres = array(); foreach ($words as $word) { $word = $db->quote('%' . $db->escape($word, true) . '%', false); $wheres2 = array(); $wheres2[] = 'a.url LIKE ' . $word; $wheres2[] = 'a.description LIKE ' . $word; $wheres2[] = 'a.title LIKE ' . $word; $wheres[] = implode(' OR ', $wheres2); } $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')'; break; } switch ($ordering) { case 'oldest': $order = 'a.created ASC'; break; case 'popular': $order = 'a.hits DESC'; break; case 'alpha': $order = 'a.title ASC'; break; case 'category': $order = 'c.title ASC, a.title ASC'; break; case 'newest': default: $order = 'a.created DESC'; } $query = $db->getQuery(true); // SQLSRV changes. $case_when = ' CASE WHEN '; $case_when .= $query->charLength('a.alias', '!=', '0'); $case_when .= ' THEN '; $a_id = $query->castAsChar('a.id'); $case_when .= $query->concatenate(array($a_id, 'a.alias'), ':'); $case_when .= ' ELSE '; $case_when .= $a_id . ' END as slug'; $case_when1 = ' CASE WHEN '; $case_when1 .= $query->charLength('c.alias', '!=', '0'); $case_when1 .= ' THEN '; $c_id = $query->castAsChar('c.id'); $case_when1 .= $query->concatenate(array($c_id, 'c.alias'), ':'); $case_when1 .= ' ELSE '; $case_when1 .= $c_id . ' END as catslug'; $query->select('a.title AS title, \'\' AS created, a.url, a.description AS text, ' . $case_when . "," . $case_when1)->select($query->concatenate(array($db->quote($searchWeblinks), 'c.title'), " / ") . ' AS section')->select('\'1\' AS browsernav')->from('#__weblinks AS a')->join('INNER', '#__categories as c ON c.id = a.catid')->where('(' . $where . ') AND a.state IN (' . implode(',', $state) . ') AND c.published = 1 AND c.access IN (' . $groups . ')')->order($order); // Filter by language. if ($app->isSite() && JLanguageMultilang::isEnabled()) { $tag = JFactory::getLanguage()->getTag(); $query->where('a.language in (' . $db->quote($tag) . ',' . $db->quote('*') . ')')->where('c.language in (' . $db->quote($tag) . ',' . $db->quote('*') . ')'); } $db->setQuery($query, 0, $limit); $rows = $db->loadObjectList(); $return = array(); if ($rows) { foreach ($rows as $key => $row) { $rows[$key]->href = WeblinksHelperRoute::getWeblinkRoute($row->slug, $row->catslug); } foreach ($rows as $weblink) { if (searchHelper::checkNoHTML($weblink, $searchText, array('url', 'text', 'title'))) { $return[] = $weblink; } } } return $return; }
/** * Weblink Search method * * The sql must return the following fields that are used in a common display * routine: href, title, section, created, text, browsernav * @param string Target search string * @param string mathcing option, exact|any|all * @param string ordering option, newest|oldest|popular|alpha|category * @param mixed An array if the search it to be restricted to areas, null if search all */ function plgSearchWeblinks($text, $phrase = '', $ordering = '', $areas = null) { $db =& JFactory::getDBO(); $user =& JFactory::getUser(); require_once JPATH_SITE . DS . 'components' . DS . 'com_weblinks' . DS . 'helpers' . DS . 'route.php'; if (is_array($areas)) { if (!array_intersect($areas, array_keys(plgSearchWeblinksAreas()))) { return array(); } } // load plugin params info $plugin =& JPluginHelper::getPlugin('search', 'weblinks'); $pluginParams = new JParameter($plugin->params); $limit = $pluginParams->def('search_limit', 50); $text = trim($text); if ($text == '') { return array(); } $section = JText::_('Web Links'); $wheres = array(); switch ($phrase) { case 'exact': $text = $db->Quote('%' . $db->getEscaped($text, true) . '%', false); $wheres2 = array(); $wheres2[] = 'LOWER(a.url) LIKE ' . $text; $wheres2[] = 'LOWER(a.description) LIKE ' . $text; $wheres2[] = 'LOWER(a.title) LIKE ' . $text; $where = '(' . implode(') OR (', $wheres2) . ')'; break; case 'all': case 'any': default: $words = explode(' ', $text); $wheres = array(); foreach ($words as $word) { $word = $db->Quote('%' . $db->getEscaped($word, true) . '%', false); $wheres2 = array(); $wheres2[] = 'LOWER(a.url) LIKE ' . $word; $wheres2[] = 'LOWER(a.description) LIKE ' . $word; $wheres2[] = 'LOWER(a.title) LIKE ' . $word; $wheres[] = implode(' OR ', $wheres2); } $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')'; break; } switch ($ordering) { case 'oldest': $order = 'a.date ASC'; break; case 'popular': $order = 'a.hits DESC'; break; case 'alpha': $order = 'a.title ASC'; break; case 'category': $order = 'b.title ASC, a.title ASC'; break; case 'newest': default: $order = 'a.date DESC'; } $query = 'SELECT a.title AS title, a.description AS text, a.date AS created,' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug, ' . ' CASE WHEN CHAR_LENGTH(b.alias) THEN CONCAT_WS(\':\', b.id, b.alias) ELSE b.id END as catslug, ' . ' CONCAT_WS( " / ", ' . $db->Quote($section) . ', b.title ) AS section,' . ' "1" AS browsernav' . ' FROM #__weblinks AS a' . ' INNER JOIN #__categories AS b ON b.id = a.catid' . ' WHERE (' . $where . ')' . ' AND a.published = 1' . ' AND b.published = 1' . ' AND b.access <= ' . (int) $user->get('aid') . ' ORDER BY ' . $order; $db->setQuery($query, 0, $limit); $rows = $db->loadObjectList(); foreach ($rows as $key => $row) { $rows[$key]->href = WeblinksHelperRoute::getWeblinkRoute($row->slug, $row->catslug); } return $rows; }
/** * Prepares the document */ protected function _prepareDocument() { $app = JFactory::getApplication(); $menus = $app->getMenu(); $pathway = $app->getPathway(); $title = null; // Because the application sets a default page title, // we need to get it from the menu item itself $menu = $menus->getActive(); if ($menu) { $this->params->def('page_heading', $this->params->get('page_title', $menu->title)); } else { $this->params->def('page_heading', JText::_('COM_WEBLINKS_DEFAULT_PAGE_TITLE')); } $id = (int) @$menu->query['id']; if ($menu && ($menu->query['option'] != 'com_weblinks' || $id != $this->category->id)) { $this->params->set('page_subheading', $this->category->title); $path = array(array('title' => $this->category->title, 'link' => '')); $category = $this->category->getParent(); while (($menu->query['option'] != 'com_weblinks' || $id != $category->id) && $category->id > 1) { $path[] = array('title' => $category->title, 'link' => WeblinksHelperRoute::getCategoryRoute($category->id)); $category = $category->getParent(); } $path = array_reverse($path); foreach ($path as $item) { $pathway->addItem($item['title'], $item['link']); } } $title = $this->params->get('page_title', ''); if (empty($title)) { $title = $app->getCfg('sitename'); } elseif ($app->getCfg('sitename_pagetitles', 0) == 1) { $title = JText::sprintf('JPAGETITLE', $app->getCfg('sitename'), $title); } elseif ($app->getCfg('sitename_pagetitles', 0) == 2) { $title = JText::sprintf('JPAGETITLE', $title, $app->getCfg('sitename')); } $this->document->setTitle($title); if ($this->category->metadesc) { $this->document->setDescription($this->category->metadesc); } elseif (!$this->category->metadesc && $this->params->get('menu-meta_description')) { $this->document->setDescription($this->params->get('menu-meta_description')); } if ($this->category->metakey) { $this->document->setMetadata('keywords', $this->category->metakey); } elseif (!$this->category->metakey && $this->params->get('menu-meta_keywords')) { $this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords')); } if ($this->params->get('robots')) { $this->document->setMetadata('robots', $this->params->get('robots')); } if ($app->getCfg('MetaAuthor') == '1') { $this->document->setMetaData('author', $this->category->getMetadata()->get('author')); } $mdata = $this->category->getMetadata()->toArray(); foreach ($mdata as $k => $v) { if ($v) { $this->document->setMetadata($k, $v); } } // Add alternative feed link if ($this->params->get('show_feed_link', 1) == 1) { $link = '&format=feed&limitstart='; $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0'); $this->document->addHeadLink(JRoute::_($link . '&type=rss'), 'alternate', 'rel', $attribs); $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0'); $this->document->addHeadLink(JRoute::_($link . '&type=atom'), 'alternate', 'rel', $attribs); } }
public function getLinks($args) { $wf = WFEditorPlugin::getInstance(); $items = array(); require_once JPATH_SITE . '/includes/application.php'; require_once JPATH_SITE . '/components/com_weblinks/helpers/route.php'; switch ($args->view) { // Get all WebLink categories default: case 'categories': $categories = WFLinkBrowser::getCategory('com_weblinks'); foreach ($categories as $category) { $url = ''; $itemid = WFLinkBrowser::getItemId('com_weblinks', array('categories' => null, 'category' => $category->id)); if (method_exists('WeblinksHelperRoute', 'getCategoryRoute')) { $id = WeblinksHelperRoute::getCategoryRoute($category->id); if (strpos($id, 'index.php?Itemid=') !== false) { $url = $id; $id = 'index.php?option=com_weblinks&view=category&id=' . $category->id; } } else { $id = 'index.php?option=com_weblinks&view=category&id=' . $category->id . $itemid; } $items[] = array('url' => $url, 'id' => $id, 'name' => $category->title . ' / ' . $category->alias, 'class' => 'folder weblink'); } break; // Get all links in the category // Get all links in the category case 'category': if (defined('JPATH_PLATFORM')) { $categories = WFLinkBrowser::getCategory('com_weblinks', $args->id); if (count($categories)) { foreach ($categories as $category) { $children = WFLinkBrowser::getCategory('com_weblinks', $category->id); $url = ''; if ($children) { $id = 'index.php?option=com_weblinks&view=category&id=' . $category->id; } else { $itemid = WFLinkBrowser::getItemId('com_weblinks', array('categories' => null, 'category' => $category->id)); if (method_exists('WeblinksHelperRoute', 'getCategoryRoute')) { $id = WeblinksHelperRoute::getCategoryRoute($category->id); if (strpos($id, 'index.php?Itemid=') !== false) { $url = $id; $id = 'index.php?option=com_weblinks&view=category&id=' . $category->id; } } else { $id = 'index.php?option=com_weblinks&view=category&id=' . $category->id . $itemid; } } $items[] = array('url' => $url, 'id' => $id, 'name' => $category->title . ' / ' . $category->alias, 'class' => 'folder weblink'); } } } $weblinks = self::_weblinks($args->id); foreach ($weblinks as $weblink) { $id = WeblinksHelperRoute::getWeblinkRoute($weblink->slug, $weblink->catslug); if (defined('JPATH_PLATFORM')) { $id .= '&task=weblink.go'; } $items[] = array('id' => $id, 'name' => $weblink->title . ' / ' . $weblink->alias, 'class' => 'file'); } break; } return $items; }
/** * Weblink Search method * * The sql must return the following fields that are used in a common display * routine: href, title, section, created, text, browsernav * @param string Target search string * @param string mathcing option, exact|any|all * @param string ordering option, newest|oldest|popular|alpha|category * @param mixed An array if the search it to be restricted to areas, null if search all */ function onContentSearch($text, $phrase = '', $ordering = '', $areas = null) { $db = JFactory::getDbo(); $app = JFactory::getApplication(); $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); $searchText = $text; if (is_array($areas)) { if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) { return array(); } } $sContent = $this->params->get('search_content', 1); $sArchived = $this->params->get('search_archived', 1); $limit = $this->params->def('search_limit', 50); $state = array(); if ($sContent) { $state[] = 1; } if ($sArchived) { $state[] = 2; } $text = trim($text); if ($text == '') { return array(); } $section = JText::_('PLG_SEARCH_WEBLINKS'); $wheres = array(); switch ($phrase) { case 'exact': $text = $db->Quote('%' . $db->getEscaped($text, true) . '%', false); $wheres2 = array(); $wheres2[] = 'a.url LIKE ' . $text; $wheres2[] = 'a.description LIKE ' . $text; $wheres2[] = 'a.title LIKE ' . $text; $where = '(' . implode(') OR (', $wheres2) . ')'; break; case 'all': case 'any': default: $words = explode(' ', $text); $wheres = array(); foreach ($words as $word) { $word = $db->Quote('%' . $db->getEscaped($word, true) . '%', false); $wheres2 = array(); $wheres2[] = 'a.url LIKE ' . $word; $wheres2[] = 'a.description LIKE ' . $word; $wheres2[] = 'a.title LIKE ' . $word; $wheres[] = implode(' OR ', $wheres2); } $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')'; break; } switch ($ordering) { case 'oldest': $order = 'a.created ASC'; break; case 'popular': $order = 'a.hits DESC'; break; case 'alpha': $order = 'a.title ASC'; break; case 'category': $order = 'c.title ASC, a.title ASC'; break; case 'newest': default: $order = 'a.created DESC'; } $return = array(); if (!empty($state)) { $query = $db->getQuery(true); $query->select('a.title AS title, a.description AS text, a.created AS created, a.url, ' . 'CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug, ' . 'CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as catslug, ' . 'CONCAT_WS(" / ", ' . $db->Quote($section) . ', c.title) AS section, "1" AS browsernav'); $query->from('#__weblinks AS a'); $query->innerJoin('#__categories AS c ON c.id = a.catid'); $query->where('(' . $where . ')' . ' AND a.state in (' . implode(',', $state) . ') AND c.published=1 AND c.access IN (' . $groups . ')'); $query->order($order); // Filter by language if ($app->isSite() && $app->getLanguageFilter()) { $tag = JFactory::getLanguage()->getTag(); $query->where('a.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')'); $query->where('c.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')'); } $db->setQuery($query, 0, $limit); $rows = $db->loadObjectList(); $return = array(); if ($rows) { foreach ($rows as $key => $row) { $rows[$key]->href = WeblinksHelperRoute::getWeblinkRoute($row->slug, $row->catslug); } foreach ($rows as $key => $weblink) { if (searchHelper::checkNoHTML($weblink, $searchText, array('url', 'text', 'title'))) { $return[] = $weblink; } } } } return $return; }
public function testGetFormRouteNewWeblink() { $this->tester->assertContains('weblink.add&w_id=0', WeblinksHelperRoute::getFormRoute(null)); }