function _autocomplete_tags() { $sm = vivvo_lite_site::get_instance(); $um = $sm->get_url_manager(); $output = ''; if ($um->isset_param('name')) { $name = escape_sql_like(secure_sql($um->get_param('name'))); $res = $sm->get_db()->query('SELECT name FROM ' . VIVVO_DB_PREFIX . "tags WHERE name LIKE '{$name}%'"); if (!PEAR::isError($res)) { $attributes[] = ENT_QUOTES; $attributes[] = 'UTF-8'; $tags = array_map('html_entity_decode', $res->fetchCol(), $attributes); $res->free(); $output = '<ul><li>' . implode('</li><li>', $tags) . '</li></ul>'; } } echo $output; exit; }
function add_filter($type, $condition = '') { $condition = secure_sql($condition); switch ($type) { case 'a.id': $condition = secure_sql_in($condition); $this->_query->add_where("a.id IN ({$condition})"); break; case '!a.id': $condition = secure_sql_in($condition); $this->_query->add_where("a.id NOT IN ({$condition})"); break; case 'a.category_id': $condition = secure_sql_in($condition); $this->_query->add_where("a.category_id IN ({$condition})"); break; case '!a.category_id': $condition = secure_sql_in($condition); $this->_query->add_where("a.category_id NOT IN ({$condition})"); break; case 'a.user_id': $condition = secure_sql_in($condition); $this->_query->add_where("a.user_id IN ({$condition})"); $this->_query->add_where("a.user_domain = '" . VIVVO_USER_SOURCE . "'"); break; case 'a.user_domain': $this->_query->add_where("a.user_domain = '{$condition}'"); break; case 'a.author_exact_name': $this->_query->add_where("a.author = '{$condition}'"); break; case 'a.author': $condition = escape_sql_like($condition); $this->_query->add_where("a.author LIKE '%{$condition}%'"); break; case 'a.title': $condition = escape_sql_like($condition); $this->_query->add_where("a.title LIKE '%{$condition}%'"); break; case 'a.image': $this->_query->add_where("a.image = '{$condition}'"); break; case 'a.created_month': $this->_query->add_where("MONTH(a.created) = '{$condition}'"); break; case 'a.created_year': $this->_query->add_where("YEAR(a.created) = '{$condition}'"); break; case 'a.created_day': $this->_query->add_where("DAY(a.created) = '{$condition}'"); break; case 'a.created_before': $current_time = date('Y-m-d H:i:00', VIVVO_START_TIME); $this->_query->add_where("a.created < (DATE_SUB('{$current_time}', INTERVAL {$condition} DAY))"); break; case 'a.created_after': $current_time = date('Y-m-d H:i:00', VIVVO_START_TIME); $this->_query->add_where("a.created > (DATE_SUB('{$current_time}', INTERVAL {$condition} DAY))"); break; case 'a.created_filter': $current_time = date('Y-m-d H:i:00', VIVVO_START_TIME); $this->_query->add_where("a.created < '{$current_time}'"); break; case 'a.body': $this->_query->add_where("MATCH (title,body,abstract) AGAINST ('{$condition}' IN BOOLEAN MODE)"); break; case 'a.last_read': $this->_query->add_where("a.last_read = '{$condition}'"); break; case 'a.times_read': $this->_query->add_where("a.times_read = '{$condition}'"); break; case 'a.today_read': $this->_query->add_where("a.today_read = '{$condition}'"); break; case 'a.status': $this->_query->add_where("a.status = '{$condition}'"); break; case 'a.not_status': $this->_query->add_where("a.status != '{$condition}'"); break; case 'a.status_limit': $this->_query->add_where('a.status > 0'); break; case 'a.sefriendly': $this->_query->add_where("a.sefriendly = '{$condition}'"); break; case 'a.link': $this->_query->add_where("a.link = '{$condition}'"); break; case 'a.order_num': $this->_query->add_where("a.order_num = '{$condition}'"); break; case 'a.show_poll': $this->_query->add_where("a.show_poll = '{$condition}'"); break; case 'a.rss_feed': $this->_query->add_where("a.rss_feed = '{$condition}'"); break; case 'a.show_comment': $this->_query->add_where("a.show_comment = '{$condition}'"); break; case 'a.keywords': $this->_query->add_where("a.keywords = '{$condition}'"); break; case 'a.description': $this->_query->add_where("a.description = '{$condition}'"); break; case 'a.emailed': $this->_query->add_where("a.emailed = '{$condition}'"); break; case 'a.vote_num': $this->_query->add_where("a.vote_num = '{$condition}'"); break; case 'a.vote_sum': $this->_query->add_where("a.vote_sum = '{$condition}'"); break; case 'a.abstract': $this->_query->add_where("a.abstract = '{$condition}'"); break; case 'related': $this->_query->add_join(' INNER JOIN ' . VIVVO_DB_PREFIX . 'related AS r ON r.related_article_id = a.id ', 'r'); $this->_query->add_order('r.relevance DESC'); $this->_query->add_where('r.article_id = ' . (int) $condition); break; case 'tag': $condition = secure_sql_in($condition, false); $this->_query->add_join(' INNER JOIN ' . VIVVO_DB_PREFIX . 'articles_tags AS at ON at.article_id = a.id ', 'at'); $this->_query->add_join(' INNER JOIN ' . VIVVO_DB_PREFIX . 'tags as t ON t.id = at.tag_id ', 't'); $this->_query->add_where("t.name IN ({$condition})"); $this->_query->add_group_by('a.id'); break; case 'tag_matches': $condition = escape_sql_like($condition); $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_tags AS at ON at.article_id = a.id ', 'at'); $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'tags as t ON t.id = at.tag_id ', 't'); $this->_query->add_where("t.name LIKE '%{$condition}%'"); $this->_query->add_group_by('a.id'); break; case 'tag_id': $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_tags AS at ON at.article_id = a.id ', 'at'); $condition = secure_sql_in($condition); $this->_query->add_where("at.tag_id IN ({$condition})"); $this->_query->add_group_by('a.id'); break; case 'all_tag_ids': is_array($condition) or $condition = explode(',', $condition); $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_tags AS at ON at.article_id = a.id ', 'at'); $value = (int) array_shift($condition); $this->_query->add_where("at.tag_id = {$value}"); $this->_query->add_group_by('a.id'); $tag_ids = array(); foreach ($condition as $value) { $tag_ids[] = (int) $value; } if (!empty($tag_ids)) { $tag_ids = implode(',', $tag_ids); $this->_query->add_where('a.id IN (SELECT article_id FROM ' . VIVVO_DB_PREFIX . "articles_tags WHERE tag_id IN ({$tag_ids}))"); } break; case 'tags_group_id': $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_tags AS at ON at.article_id = a.id ', 'at'); $condition = secure_sql_in($condition); $this->_query->add_where("at.tags_group_id IN ({$condition})"); $this->_query->add_group_by('a.id'); break; case 'user_group_id': $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_tags AS at ON at.article_id = a.id ', 'at'); $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'group_user AS gu ON at.user_id = gu.user_id ', 'gu'); $condition = secure_sql_in($condition); $this->_query->add_where("gu.group_id IN ({$condition})"); $this->_query->add_group_by('a.id'); break; case 'not_user_group_id': $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_tags AS at ON at.article_id = a.id ', 'at'); $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'group_user AS gu ON at.user_id = gu.user_id ', 'gu'); $condition = secure_sql_in($condition); $this->_query->add_where("gu.group_id NOT IN ({$condition})"); $this->_query->add_group_by('a.id'); break; case 'tags_group_name': $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_tags AS at ON at.article_id = a.id ', 'at'); $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'tags_groups as tg ON at.tags_group_id = tg.id ', 'tg'); $condition = explode(',', $condition); foreach ($condition as &$topic) { $topic = "'" . secure_sql($topic) . "'"; } unset($topic); $condition = implode(',', $condition); $this->_query->add_where("tg.name IN ({$condition})"); $this->_query->add_group_by('a.id'); break; case 'sc.id': case 'sc.duration': case 'sc.status': case 'sc.year': $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_schedule AS sc ON sc.article_id = a.id ', 'sc'); $condition = (int) $condition; $this->_query->add_where("{$type} = {$condition}"); break; case 'sc.minute': case 'sc.hour': case 'sc.dom': case 'sc.month': case 'sc.dow': require_once VIVVO_FS_ROOT . 'lib/vivvo/core/ArticlesSchedule.class.php'; $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_schedule AS sc ON sc.article_id = a.id ', 'sc'); $condition = ArticlesSchedule::getHexMask($condition, substr($type, 3)); $this->_query->add_where("{$type} & {$condition}"); break; case 'sc.date': if (!is_array($condition)) { $parts = explode(',', date('i,G,j,n,w,Y', $condition)); $condition = array('minute' => (int) $parts[0], 'hour' => $parts[1], 'dom' => $parts[2], 'month' => $parts[3], 'dow' => $parts[4] + 1, 'year' => $parts[5]); } require_once VIVVO_FS_ROOT . 'lib/vivvo/core/ArticlesSchedule.class.php'; $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_schedule AS sc ON sc.article_id = a.id ', 'sc'); $condition = ArticlesSchedule::getHexMask($condition); foreach ($condition as $name => $value) { if ($name == 'year') { $value = (int) $value; $this->_query->add_where("sc.year = {$value}"); } else { $this->_query->add_where("sc.{$name} & {$value}"); } } break; case 'sc.id_in': case 'sc.duration_in': case 'sc.year_in': $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_schedule AS sc ON sc.article_id = a.id ', 'sc'); $condition = secure_sql_in($condition); $type = substr($type, 0, -3); $this->_query->add_where("{$type} IN ({$condition})"); break; case 'sc.id_not_in': case 'sc.duration_not_in': case 'sc.year_not_in': $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_schedule AS sc ON sc.article_id = a.id ', 'sc'); $condition = secure_sql_in($condition); $type = substr($type, 0, -7); $this->_query->add_where("{$type} NOT IN ({$condition})"); break; case 'sc.duration_lt': case 'sc.year_lt': $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_schedule AS sc ON sc.article_id = a.id ', 'sc'); $condition = (int) $condition; $type = substr($type, 0, -3); $this->_query->add_where("{$type} < {$condition}"); break; case 'sc.duration_lte': case 'sc.year_lte': $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_schedule AS sc ON sc.article_id = a.id ', 'sc'); $condition = (int) $condition; $type = substr($type, 0, -4); $this->_query->add_where("{$type} <= {$condition}"); break; case 'sc.duration_gt': case 'sc.year_lg': $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_schedule AS sc ON sc.article_id = a.id ', 'sc'); $condition = (int) $condition; $type = substr($type, 0, -3); $this->_query->add_where("{$type} > {$condition}"); break; case 'sc.duration_gte': case 'sc.year_gte': $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_schedule AS sc ON sc.article_id = a.id ', 'sc'); $condition = (int) $condition; $type = substr($type, 0, -4); $this->_query->add_where("{$type} >= {$condition}"); break; } }
function add_filter($type, $cond = '') { $condition = secure_sql($cond); switch ($type) { case 'id': $condition = secure_sql_in($condition); $this->_query->add_where("(k.id IN ({$condition}))"); break; case 'notid': $condition = secure_sql_in($condition); $this->_query->add_where("(k.id NOT IN ({$condition}))"); break; case 'asset_id': $this->_query->add_where("(k.asset_id='{$condition}')"); break; case 'asset_id_list': $condition = secure_sql_in($condition); $this->_query->add_where("(k.asset_id IN ({$condition}))"); break; case 'keyword': $this->_query->add_where("(k.keyword='{$condition}')"); break; case 'keyword_starts_with': $this->_query->add_where("(k.keyword LIKE '{$condition}%')"); break; case 'fulltext': $this->_query->add_where("MATCH (k.keyword) AGAINST ('{$condition}' IN BOOLEAN MODE)"); break; case 'like': $condition = escape_sql_like($condition); $this->_query->add_where("k.keyword LIKE '%{$condition}%'"); } }