function get_posts($sort_by = "published_on", $filters = array())
{
    $query = "SELECT SQL_CALC_FOUND_ROWS * FROM posts_summary ";
    $where_clause = " WHERE !ISNULL(post_id)";
    #$where_clause .= " AND p2.post_id = links.post_id AND p2.blog_id != posts.blog_id";
    $order_by = " ORDER BY pubdate DESC";
    $limit_by = "";
    if ($sort_by == "published_on") {
        $order_by = " ORDER BY pubdate DESC";
    }
    if ($sort_by == "added_on") {
        $order_by = " ORDER BY added_on DESC";
    }
    if ($sort_by == "cited") {
        $order_by = " ORDER BY linked_by DESC, pubdate DESC";
    }
    if ($sort_by == "post_freq") {
        if ($filters['post_id']) {
            # we want an order in which elements that appear most frequently in $filters['post_id'] have the highest rankings
            $post_freq = array_count_values($filters['post_id']);
            arsort($post_freq);
            $order_by = " ORDER BY FIELD(post_id";
            foreach ($post_freq as $post_id => $post_freq) {
                $order_by .= ", {$post_id}";
            }
            $order_by .= ")";
        }
    }
    $sort_by .= ", title ASC";
    if (!$filters['limit']) {
        $filters['limit'] = $GLOBALS["config"]['posts_per_page'];
    }
    if ($filters['limit']) {
        $limit_by = " LIMIT " . $filters['limit'];
    }
    if ($filters['skip']) {
        if ($filters['skip'] < 0) {
            $filters['skip'] = 0;
        }
        $limit_by = " LIMIT " . $filters['skip'] . "," . $filters['limit'];
    }
    if ($filters['base_url']) {
        $where_clause .= " AND url LIKE '" . $filters['base_url'] . "%'";
    }
    if ($filters['term']) {
        $tposts = get_posts_with_term($filters['term']);
        $tposts = "'" . implode("','", $tposts) . "'";
        $where_clause .= " AND post_id IN ({$tposts})";
    }
    if ($filters['category']) {
        $blogs = get_blogs_with_tag($filters['category']);
        $blogs = "'" . implode("','", $blogs) . "'";
        $where_clause .= " AND blog_id IN ({$blogs})";
    }
    if ($filters['tag']) {
        $tag = $filters['tag'];
        $tposts = array();
        if ($tag == "original_research") {
            $tposts = get_posts_with_research();
        } elseif ($tag == "conference") {
            $tposts = get_posts_with_conference();
        } elseif ($tag == "review") {
            $tposts = get_posts_with_review();
        } else {
            $tposts = get_posts_with_tag($filters['tag']);
        }
        $tposts = "'" . implode("','", $tposts) . "'";
        $where_clause .= " AND post_id IN ({$tposts})";
    }
    if ($filters['review']) {
        $tposts = get_posts_with_review();
        $tposts = "'" . implode("','", $tposts) . "'";
        $where_clause .= " AND post_id IN ({$tposts})";
    }
    if ($filters['conference']) {
        $tposts = get_posts_with_conference();
        $tposts = "'" . implode("','", $tposts) . "'";
        $where_clause .= " AND post_id IN ({$tposts})";
    }
    if ($filters['original_research']) {
        $tposts = get_posts_with_research();
        $tposts = "'" . implode("','", $tposts) . "'";
        $where_clause .= " AND post_id IN ({$tposts})";
    }
    if ($filters['published_before']) {
        $date = $filters['published_before'];
        $where_clause .= " AND pubdate < '{$date}'";
    }
    if ($filters['published_after']) {
        $date = $filters['published_after'];
        $where_clause .= " AND pubdate >= '{$date}'";
    }
    if ($filters['blog_id']) {
        $where_clause .= " AND blog_id = " . $filters['blog_id'];
    }
    if (isset($filters['post_id'])) {
        if ($filters['post_id']) {
            if (!is_array($filters['post_id'])) {
                $where_clause .= " AND post_id = " . $filters['post_id'];
            } else {
                if (is_array($filters['post_id'])) {
                    $where_clause .= " AND post_id IN (" . implode(",", $filters['post_id']) . ")";
                }
            }
        } else {
            return array();
        }
    }
    if ($filters['min_links']) {
        $where_clause .= " AND linked_by >= " . $filters['min_links'];
    }
    $posts = array();
    $having = "";
    $query = $query . $where_clause . $group_by . $having . $order_by . $limit_by;
    $results = mysql_query($query);
    $rows = mysql_num_rows($results);
    if ($limit_by) {
        $count_query = "SELECT FOUND_ROWS() AS rows";
        $count_results = mysql_query($count_query);
        while ($row = mysql_fetch_assoc($count_results)) {
            $rows = $row['rows'];
        }
    }
    while ($row = mysql_fetch_assoc($results)) {
        $post = $row;
        $post['rows_returned'] = $rows;
        $post['post_request_type'] = "all";
        if ($filters['conference']) {
            $post['post_request_type'] = "conference";
        }
        if ($filters['review']) {
            $post['post_request_type'] = "review";
        }
        if ($filters['originaL_research']) {
            $post['post_request_type'] = "original_research";
        }
        array_push($posts, $post);
    }
    if ($filters['order_by_filenames_array']) {
        $filenames = $filters['order_by_filenames_array'];
        $ordered_posts = array();
        # we need to do some post-ordering
        foreach ($filenames as $filename) {
            # find row with this filename, add it to the array.
            foreach ($posts as $post) {
                if ($post['filename'] == $filename) {
                    array_push($ordered_posts, $post);
                }
            }
        }
        $posts = $ordered_posts;
    }
    return $posts;
}
get_posts_with_tag("数学");
?>
	<?php 
get_posts_with_tag("物理");
?>
	<?php 
get_posts_with_tag("计算机");
?>
	<?php 
get_posts_with_tag("游戏");
?>
	<?php 
get_posts_with_tag("IQ");
?>
	<?php 
get_posts_with_tag("科学大事记");
?>
	<div style="clear:both"></div>
<?php 
corner_end();
?>
</div>



</div></div>

<div id="sidebar"><div id="innersidebar">
<dl>
	<dd class="sc"><?php 
corner_start();
/**
 * Returns true while there are still tagged posts in the array.
 * This replaces the Anchor posts() method
 *
 * @return bool
 */
function tagged_posts()
{
    $tag = extract_tag();
    if ($tag != '') {
        if (!($posts = Registry::get('tagged_posts'))) {
            $tagged_posts = get_posts_with_tag($tag);
            $posts = Post::where_in('id', $tagged_posts)->where('status', '=', 'published')->sort('created', 'desc')->get();
            Registry::set('tagged_posts', $posts = new Items($posts));
        }
        if ($posts instanceof Items) {
            if ($result = $posts->valid()) {
                // register single post
                Registry::set('article', $posts->current());
                // move to next
                $posts->next();
            } else {
                $posts->rewind();
            }
            return $result;
        }
    } else {
        return posts();
    }
    return false;
}
get_posts_with_tag("WordPress相关");
?>
	<?php 
get_posts_with_tag("网站提速", "加速blog:");
?>
	<?php 
get_posts_with_tag("网页技术");
?>
	<?php 
get_posts_with_tag("Google");
?>
	<?php 
get_posts_with_tag("IT评论");
?>
	<?php 
get_posts_with_tag("阅微堂系统");
?>
	<div style="clear:both"></div>
<?php 
corner_end();
?>
</div>



</div></div>

<div id="sidebar"><div id="innersidebar">
<dl>
	<dd class="sc"><?php 
corner_start();
get_posts_with_tag("心理学");
?>
	<?php 
get_posts_with_tag("经济金融");
?>
	<?php 
get_posts_with_tag("哲学");
?>
	<?php 
get_posts_with_tag("历史");
?>
	<?php 
get_posts_with_tag("小说");
?>
	<?php 
get_posts_with_tag("科幻小说");
?>
	<div style="clear:both"></div>
<?php 
corner_end();
?>
</div>



</div></div>

<div id="sidebar"><div id="innersidebar">
<dl>
	<dd class="sc"><?php 
corner_start();
function get_stories_with_tag($tag, $include_posts = true)
{
    $query = "SELECT DISTINCT story_id FROM tags WHERE tag = '{$tag}' AND !ISNULL(story_id)";
    $results = mysql_query($query);
    $stories = array();
    while ($row = mysql_fetch_assoc($results)) {
        array_push($stories, $row['story_id']);
    }
    # there might also be tags attached to posts which link to this paper...
    if ($include_posts) {
        $posts = get_posts_with_tag($tag);
        $posts = "'" . implode("','", $posts) . "'";
        $query = "SELECT DISTINCT story_id FROM links WHERE post_id IN ({$posts}) AND !ISNULL(story_id)";
        $results = mysql_query($query);
        while ($row = mysql_fetch_assoc($results)) {
            array_push($stories, $row['story_id']);
        }
    }
    return $stories;
}
?>
	</div>
	<?php 
get_posts_with_tag("山水");
?>
	<?php 
get_posts_with_tag("人文景观");
?>
	<?php 
get_posts_with_tag("游玩");
?>
	<?php 
get_posts_with_tag("实验室活动");
?>
	<?php 
get_posts_with_tag("美洲");
?>
	<div style="clear:both"></div>
<?php 
corner_end();
?>
</div>



</div></div>

<div id="sidebar"><div id="innersidebar">
<dl>
	<dd class="sc"><?php 
corner_start();
get_posts_with_tag("中国崛起策II正文", "II ");
?>
	<?php 
get_posts_with_tag("中国崛起策I正文", "中国崛起策");
?>
	<?php 
get_posts_with_tag("中国崛起策读者评论");
?>
	<?php 
get_posts_with_tag("中国崛起策副篇", "中国崛起策");
?>
	<?php 
get_posts_with_tag("中国崛起策作者评论");
?>
	<?php 
get_posts_with_tag("中国崛起策大事记");
?>
	<div style="clear:both"></div>
<?php 
corner_end();
?>
</div>



</div></div>

<div id="sidebar"><div id="innersidebar">
<dl>
	<dd class="sc"><?php 
corner_start();
Beispiel #9
0
        print "<p><a href='" . linkto("blog_search.php", $GLOBALS['page_vars'], array("blog_id" => $key)) . "'>{$value}</a>";
    }
    print "</div>";
    print "</div>";
}
print "</div>";
print "<div class='content'>";
if ($safe_tag) {
    print "<h1>Items tagged with \"{$safe_tag}\"</h1>";
    $paper_ids = array();
    $paper_ids = get_papers_with_tag($safe_tag, true);
    if ($paper_ids) {
        print "<h3>Papers</h3>";
        $papers = get_papers("cited", array("paper_id" => $paper_ids));
        foreach ($papers as $paper) {
            print_paper($paper, array("display" => "minimal"));
        }
    }
    $post_ids = get_posts_with_tag($safe_tag);
    if ($post_ids) {
        print "<h3>Posts</h3>";
        $posts = get_posts("cited", array("post_id" => $post_ids));
        foreach ($posts as $post) {
            print_post($post);
        }
    }
    print "</div>";
} else {
    print_error("No tag specified", "You must specify a tag to search for.");
}
include "footer.php";
Beispiel #10
0
<?php 
$blog_ids = array();
$blog_names = array();
$blog_tags = array();
if ($connotea_tags) {
    $valid_tags = validate_tags(array_keys($connotea_tags));
    if (!$valid_tags) {
        print "<h3>Sorry</h3>";
        print "<p>None of the tags in " . $_SAFE['connotea_username'] . "'s library are in the Postgenomic index.";
        print_r($connotea_tags);
    } else {
        print "<h3>Matched Connotea tags</h3>";
        print_tagcloud($valid_tags);
        # try and match up tags with blogs in the database
        foreach ($connotea_tags as $tag => $freq) {
            $post_ids = get_posts_with_tag($tag);
            # what blogs are these posts from?
            if ($post_ids) {
                $done = array();
                $posts = get_posts("cited", array("post_id" => $post_ids));
                if ($posts) {
                    foreach ($posts as $post) {
                        if ($done[$post['blog_id']]) {
                            next;
                        } else {
                            if ($_SAFE['use_weighting']) {
                                $blog_ids[$post['blog_id']] += $freq;
                            } else {
                                $blog_ids[$post['blog_id']]++;
                            }
                            $blog_names[$post['blog_id']] = $post['blog_name'];
get_posts_with_tag("复杂性理论");
?>
	<?php 
get_posts_with_tag("理论计算机初步", "理论计算机");
?>
	<?php 
get_posts_with_tag("理论计算机笔记");
?>
	<?php 
get_posts_with_tag("计算机讲座");
?>
	<?php 
get_posts_with_tag("理论计算机其它");
?>
	<?php 
get_posts_with_tag("计算机大事记");
?>
	<div style="clear:both"></div>
<?php 
corner_end();
?>
</div>



</div></div>

<div id="sidebar"><div id="innersidebar">
<dl>
	<dd class="sc"><?php 
corner_start();