Пример #1
0
function search_tags($tags, $start = 0){
	
	global $db, $config;
	
	$topics_count = (int) $db->sql_fetchfield('num_topics');

	$end = $config['topics_per_page'];
	$tag_array = filter_tags($tags);
	
	$sql = "SELECT top.*, COUNT(top.topic_id) count
			FROM ". TAGS_TABLE ." t, ". TOPICS_TABLE ." top
			WHERE (t.tag IN (";
	$sql .= prepare_search_string($tag_array['include']);
	$sql .= "))";
	
	if(!empty($tag_array['exclude'])){
		$sql .= "AND (top.topic_id NOT IN ( 
						SELECT top2.topic_id
						FROM ". TAGS_TABLE ." t2, ". TOPICS_TABLE ." top2
						WHERE t2.topic_id = top2.topic_id";
		$sql .= prep_exclusion_string($tag_array['exclude']);
		$sql .= "))";
	}

	$sql .= "AND top.topic_id = t.topic_id
			 GROUP BY top.topic_id
			 ORDER BY count DESC
			 LIMIT $start, $end";
	
	//echo '<pre>';	
	//echo $sql;

	if(!($result = $db->sql_query($sql)))
	{
		message_die(GENERAL_ERROR, 'Error retrieving search results', '', __LINE__, __FILE__, $sql);
	}
	
	$result_set = $db->sql_fetchrowset($result);


	//echo '<pre>';
	//echo var_dump($result_set);
		
	return $result_set;
	
}
function search_tags($tags, $start = 0, $end = false)
{
    global $db, $config, $auth;
    $topics_count = (int) $db->sql_fetchfield('num_topics');
    if ($end === false) {
        $end = $config['topics_per_page'];
    }
    $tag_array = filter_tags($tags);
    $sql = "SELECT topi.topic_id,\n\t\t\ttopi.forum_id,\n\t\t\ttopi.topic_type,\n\t\t\ttopi.topic_replies_real,\n\t\t\ttopi.topic_replies,\n\t\t\ttopi.topic_status,\n\t\t\ttopi.topic_moved_id,\n\t\t\ttopi.topic_last_post_time,\n\t\t\ttopi.topic_approved,\n\t\t\ttopi.topic_poster,\n\t\t\ttopi.topic_first_poster_name,\n\t\t\ttopi.topic_time,\n\t\t\ttopi.topic_last_post_subject,\n\t\t\ttopi.topic_last_post_time,\n\t\t\ttopi.topic_last_poster_id,\n\t\t\ttopi.topic_views,\n\t\t\ttopi.topic_title,\n\t\t\ttopi.icon_id,\n\t\t\ttopi.topic_attachment,\n\t\t\ttopi.topic_first_poster_name,\n\t\t\ttopi.topic_last_post_id,\n\t\t\ttopi.topic_last_poster_id,\n\t\t\ttopi.topic_last_poster_name,\n\t\t\ttopi.topic_last_poster_colour,\n\t\t\ttopi.topic_last_post_subject,\n\t\t\ttopi.topic_last_post_time,\n\t\t\ttopi.topic_last_view_time,\n            topi.poll_start,\n\t\t\tCOUNT(topi.topic_id) count\n\t\t\tFROM " . TAGS_TABLE . " t, " . TOPICS_TABLE . " topi";
    if (!empty($tag_array['include'])) {
        $sql .= " WHERE (t.tag IN (";
        $sql .= prepare_search_string($tag_array['include']);
        $sql .= "))";
    }
    if (!empty($tag_array['include']) && !empty($tag_array['exclude'])) {
        $sql .= " AND ";
    } else {
        if (empty($tag_array['include']) && !empty($tag_array['exclude'])) {
            $sql .= " WHERE ";
        }
    }
    if (!empty($tag_array['exclude'])) {
        $sql .= "(topi.topic_id NOT IN ( \n\t\t\t\t\t\tSELECT top2.topic_id\n\t\t\t\t\t\tFROM " . TAGS_TABLE . " t2, " . TOPICS_TABLE . " top2\n\t\t\t\t\t\tWHERE t2.topic_id = top2.topic_id";
        $sql .= prep_exclusion_string($tag_array['exclude']);
        $sql .= "))";
    }
    $sql .= "AND topi.topic_id = t.topic_id\n\t\t\t GROUP BY topi.topic_id,\n\t\t\t topi.forum_id,\n\t\t\t topi.topic_type,\n\t\t\t topi.topic_replies_real,\n\t\t\t topi.topic_replies,\n\t\t\t topi.topic_status,\n\t\t\t topi.topic_moved_id,\n\t\t\t topi.topic_last_post_time,\n\t\t\t topi.topic_approved,\n\t\t\t topi.topic_poster,\n\t\t\t topi.topic_first_poster_name,\n\t\t\t topi.topic_time,\n\t\t\t topi.topic_last_post_subject,\n\t\t\t topi.topic_last_post_time,\n\t\t\t topi.topic_last_poster_id,\n\t\t\t topi.topic_views,\n\t\t\t topi.topic_title,\n\t\t\t topi.icon_id,\n\t\t\t topi.topic_attachment,\n\t\t\t topi.topic_first_poster_name,\n\t\t\t topi.topic_last_post_id,\n\t\t\t topi.topic_last_poster_id,\n\t\t\t topi.topic_last_poster_name,\n\t\t\t topi.topic_last_poster_colour,\n\t\t\t topi.topic_last_post_subject,\n\t\t\t topi.topic_last_post_time,\n\t\t\t topi.topic_last_view_time\n\t\t\t ORDER BY topic_time DESC";
    if (!($result = $db->sql_query_limit($sql, $end, $start))) {
        message_die(GENERAL_ERROR, 'Error retrieving search results', '', __LINE__, __FILE__, $sql);
    }
    $topic_list = array();
    while ($row = $db->sql_fetchrow($result)) {
        // Do not include those topics the user has no permission to access
        if ($auth->acl_get('f_read', $row['forum_id'])) {
            $topic_list[] = $row;
        }
    }
    return $topic_list;
}