コード例 #1
0
function get_papers($sort_by = "added_on", $filters = array())
{
    $query = "SELECT SQL_CALC_FOUND_ROWS * FROM papers_summary WHERE 1";
    $where_clause = "";
    $order_by = " ORDER BY added_on";
    $group_by = "";
    $limit_by = "";
    if ($sort_by == "added_on") {
        $order_by = " ORDER BY added_on DESC";
    }
    if ($sort_by == "pubdate") {
        $order_by = " ORDER BY pubdate DESC";
    }
    # bit of a hack here - historically "pubdate" and "published_on" are both used even though they're the same thing
    if ($sort_by == "published_on") {
        $order_by = " ORDER BY pubdate DESC";
    }
    if ($sort_by == "cited") {
        $order_by = " ORDER BY cited_by DESC";
    }
    if ($sort_by == "journal") {
        $order_by = " ORDER BY journal";
    }
    if ($filters['min_links']) {
        $having_clause .= " HAVING cited_by >= " . $filters['min_links'];
    }
    if ($filters['reviews']) {
        $where_clause .= " AND reviewed >= 1";
    }
    if ($filters['limit']) {
        $limit_by = " LIMIT " . $filters['limit'];
    }
    if ($filters['comment_source']) {
        # get list of papers that have comments from this source
        $comments = get_comments_from_source($filters['comment_source']);
        if (sizeof($comments)) {
            $where_clause .= " AND paper_id IN ('" . implode("','", $comments) . "')";
        } else {
            return array();
        }
    }
    if ($filters['skip']) {
        if ($filters['skip'] < 0) {
            $filters['skip'] = 0;
        }
        $limit_by = " LIMIT " . $filters['skip'] . "," . $GLOBALS["config"]['papers_per_page'];
    }
    if ($filters['category']) {
        $blogs = get_blogs_with_tag($filters['category']);
        #$blogs = "'".implode("','", $blogs)."'";
        #$where_clause .= " AND posts.blog_id IN ($blogs)";
        $blog_counter = 0;
        if ($blogs) {
            $where_clause .= " AND (";
        }
        foreach ($blogs as $blog) {
            if ($blog_counter >= 1) {
                $where_clause .= " OR ";
            }
            #$where_clause .= "FIND_IN_SET($blog, blog_ids)";
            # try a textual IN clause to see if it's any faster:
            $where_clause .= "{$blog} IN (blog_ids)";
            $blog_counter++;
        }
        if ($blogs) {
            $where_clause .= ")";
        }
    }
    if ($filters['tag']) {
        $papers = get_papers_with_tag($filters['tag']);
        $papers = "'" . implode("','", $papers) . "'";
        $where_clause .= " AND paper_id IN ({$papers})";
    }
    if (strtolower($filters['type']) == "books") {
        $where_clause .= " AND !ISNULL(isbn_id)";
    }
    if (strtolower($filters['type']) == "papers") {
        $where_clause .= " AND ISNULL(isbn_id)";
    }
    if ($filters['journal']) {
        $journal = $filters['journal'];
        $where_clause .= " AND journal='{$journal}'";
    }
    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['added_before']) {
        $date = $filters['added_before'];
        $where_clause .= " AND added_on < '{$date}'";
    }
    if ($filters['added_after']) {
        $date = $filters['added_after'];
        $where_clause .= " AND added_on >= '{$date}'";
    }
    if (isset($filters['paper_id'])) {
        if (!is_array($filters['paper_id'])) {
            $where_clause .= " AND paper_id = " . $filters['paper_id'];
        } else {
            if (is_array($filters['paper_id'])) {
                $where_clause .= " AND paper_id IN (" . implode(",", $filters['paper_id']) . ")";
            }
        }
    }
    $papers = array();
    $query = $query . $where_clause . $group_by . $having_clause . $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)) {
        $row['rows_returned'] = $rows;
        $paper = $row;
        array_push($papers, $paper);
    }
    return $papers;
}
コード例 #2
0
    print "<div class='sidebox'>";
    print "<div class='sidebox_title'>Blogs</div>";
    print "<div class='sidebox_content'>";
    print "<p class='description'>Blogs containing posts tagged \"{$safe_tag}\" include...</p>";
    foreach ($blogs as $key => $value) {
        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);
        }
    }