예제 #1
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;
 }
 /**
  * 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;
 }
예제 #3
0
 /**
  * Add tag group
  *
  * @param	string	$name
  * @param	string	$url
  * @param	string	$template
  * @param	array	$metadata
  */
 public function add_tag_group($name, $url, $template, $tag_template, $metadata, $return_id_if_exists = false, $new_tags = '')
 {
     if (!vivvo_hooks_manager::call('tag_addGroup', array(&$name, &$url, &$template, &$tag_template, &$metadata, &$return_id_if_exists, &$new_tags))) {
         return vivvo_hooks_manager::get_status();
     }
     $sm = vivvo_lite_site::get_instance();
     $user = $sm->user;
     if ($user && $user->can('MANAGE_TAGS')) {
         $tag_group_list = new TagsGroups_list();
         $tag_group = new TagsGroups();
         if (!$tag_group->set_name($name = htmlspecialchars($name, ENT_QUOTES, 'UTF-8'))) {
             $this->set_error_code(12, vivvo_lang::get_instance()->get_value('LNG_DB_tags_groups_name'));
             return false;
         }
         if ($existing_group = $tag_group_list->get_group_by_name($name)) {
             if (!$return_id_if_exists) {
                 $this->set_error_code(2417);
                 return false;
             }
             return $existing_group->get_id();
         }
         $um = $sm->get_url_manager();
         if (empty($url)) {
             $url = make_sefriendly($name);
         } else {
             $url = make_sefriendly($url);
         }
         $um->set_param('TAG_GROUP_url', $url);
         $sefriendly = secure_sql($url);
         $sql = 'SELECT id FROM ' . VIVVO_DB_PREFIX . "categories WHERE sefriendly = '{$sefriendly}' LIMIT 1 UNION\n\t\t\t\t\t\tSELECT id FROM " . VIVVO_DB_PREFIX . "tags_groups WHERE url = '{$sefriendly}' LIMIT 1";
         if (($res = $sm->get_db()->query($sql)) && $res->numRows() > 0) {
             $this->set_error_code(2418);
             return false;
         }
         $tag_group->set_url($url);
         $tag_group->set_template($template);
         $tag_group->set_tag_template($tag_template);
         $tag_group->set_metadata($metadata);
         $this->_post_master->set_data_object($tag_group);
         if (!$this->_post_master->sql_insert()) {
             $this->set_error_code(2412);
             return false;
         }
         $work_id = $this->_post_master->get_work_id();
         $um->register_url(urlencode($url), 'lib/vivvo/url_handlers/topic.php', 'topic_url_handler', 'topic_content_handler');
         $um->set_param('search_id', $work_id);
         if ($new_tags) {
             $this->add_tag_names_to_topic($new_tags, $work_id);
         }
         admin_log($user->get_username(), 'Added topic #' . $work_id);
         return $work_id;
     }
     $this->set_error_code(2410);
     return false;
 }