/**
  * Autocomplete box feed
  */
 public function _autocomplete_links()
 {
     $sm = vivvo_lite_site::get_instance();
     $template = $sm->get_template();
     $um = $sm->get_url_manager();
     $pm = $sm->get_plugin_manager();
     $content_template = new template(null, $template);
     $content_template->set_template_file($this->_template_root . 'autocomplete_links.xml');
     $hrefs = array();
     $db = $sm->get_db();
     $name = secure_sql($um->get_param('name'));
     $sql = "(SELECT id, category_name AS title, sefriendly, '' AS category_id,  'Categories' AS type FROM " . VIVVO_DB_PREFIX . "categories WHERE category_name LIKE '{$name}%')\n\t\t\t\t\t UNION\n\t\t\t\t    (SELECT id, title, sefriendly, category_id, 'Articles' AS type FROM " . VIVVO_DB_PREFIX . "articles WHERE title LIKE '{$name}%')";
     if ($pm->is_installed('pages')) {
         $sql .= "UNION (SELECT id, title, sefriendly, '' AS category_id, 'Pages' AS type FROM " . VIVVO_DB_PREFIX . "pages WHERE title LIKE '{$name}%')";
     }
     $sql .= "UNION (SELECT t.id, CONCAT(tg.name,': ',t.name) AS title, t.sefriendly AS sefriendly, tg.url AS category_id, 'Tags' AS type FROM " . VIVVO_DB_PREFIX . "tags AS t INNER JOIN " . VIVVO_DB_PREFIX . "tags_to_tags_groups AS ttg ON ttg.tag_id = t.id INNER JOIN " . VIVVO_DB_PREFIX . "tags_groups AS tg ON ttg.tags_group_id = tg.id WHERE t.name LIKE '{$name}%' GROUP BY t.id, tg.id) " . "UNION (SELECT id, name AS title, url AS sefriendly, '' AS category_id,  'Topics' AS type FROM " . VIVVO_DB_PREFIX . "tags_groups WHERE name LIKE '{$name}%')";
     $res = $db->query($sql);
     if (!PEAR::isError($res)) {
         $i = 0;
         while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
             $hrefs[$i] = array();
             $hrefs[$i]['title'] = $row['title'];
             $hrefs[$i]['id'] = $row['id'];
             $hrefs[$i]['type'] = $row['type'];
             switch ($row['type']) {
                 case 'Articles':
                     if (!$article) {
                         require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/Articles.class.php';
                         $article = new Articles();
                     }
                     $article->id = $row['id'];
                     $article->title = $row['title'];
                     $article->sefriendly = $row['sefriendly'];
                     $article->category_id = $row['category_id'];
                     $hrefs[$i]['href'] = $article->get_href();
                     break;
                 case 'Categories':
                     if (!$cat) {
                         $cat = $sm->get_categories();
                     }
                     $hrefs[$i]['href'] = $cat->list[$row['id']]->get_href();
                     break;
                 case 'Pages':
                     if (!$page) {
                         require_once VIVVO_FS_PLUGIN_ROOT . 'plugins/pages/Pages.class.php';
                         $page = new Pages();
                     }
                     $page->id = $row['id'];
                     $page->title = $row['title'];
                     $page->sefriendly = $row['sefriendly'];
                     $hrefs[$i]['href'] = $page->get_href();
                     break;
                 case 'Tags':
                     if (!$tag) {
                         require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/Tags.class.php';
                         $tag = new Tags();
                     }
                     $tag->id = $row['id'];
                     $tag->name = $row['title'];
                     $tag->sefriendly = $row['sefriendly'];
                     $tag->group_url = $row['category_id'] . '/';
                     $hrefs[$i]['href'] = $tag->get_href();
                     break;
                 case 'Topics':
                     if (!$topic) {
                         require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/TagsGroups.class.php';
                         $topic = new TagsGroups();
                     }
                     $topic->id = $row['id'];
                     $topic->name = $row['title'];
                     $topic->url = $row['sefriendly'];
                     $hrefs[$i]['href'] = rtrim($topic->get_href(), '/');
                     break;
             }
             $i++;
         }
     }
     $content_template->assign('link_list', $hrefs);
     return $content_template;
 }
Esempio n. 2
0
 /**
  * Returns list of tags by article and topic
  *
  * @param	Articles	$article
  * @param	TagsGroups	$topic
  * @return	array
  */
 public function get_tags_by_article_topic($article, $topic, $clone = false)
 {
     $topic_url = $topic->get_href();
     $topic_name = $topic->get_name();
     $this->_query->reset_query();
     $this->_query->set_from(VIVVO_DB_PREFIX . $this->_sql_table . ' AS t');
     $this->_query->add_fields('t.*');
     $this->_query->add_group_by('t.id');
     $this->add_filter('tags_group_id', $topic->get_id());
     $this->add_filter('article_id', $article->get_id());
     $this->set_list();
     if (!empty($this->list)) {
         foreach ($this->list as &$tag) {
             $clone and $tag = clone $tag;
             $tag->set_group_url($topic_url);
             $tag->set_group_name($topic_name);
         }
         unset($tag);
     }
     return $this->list;
 }