本文整理汇总了PHP中Articles::get_sql_where方法的典型用法代码示例。如果您正苦于以下问题:PHP Articles::get_sql_where方法的具体用法?PHP Articles::get_sql_where怎么用?PHP Articles::get_sql_where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Articles
的用法示例。
在下文中一共展示了Articles::get_sql_where方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: stat_for_anchor
/**
* get some statistics for one anchor
*
* Only articles matching following criteria are returned:
* - article is visible (active='Y')
* - article is restricted (active='R'), but the surfer is an authenticated member,
* or YACS is allowed to show restricted teasers
* - article is protected (active='N'), but surfer is an associate, and we are not feeding someone
* - surfer is anonymous or the variant is 'boxes', and article has been officially published
* - logged surfers are restricted to their own articles, plus published articles
* - an expiry date has not been defined, or is not yet passed
*
* @param the selected anchor (e.g., 'section:12')
* @param boolean FALSE to include sticky pages, TRUE otherwise
* @return the resulting ($count, $min_date, $max_date) array
*
* @see sections/view.php
*/
public static function stat_for_anchor($anchor, $without_sticky = FALSE)
{
global $context;
// sanity check
if (!$anchor) {
return NULL;
}
// restrict the query to addressable content
$where = Articles::get_sql_where();
// avoid sticky articles
if ($without_sticky) {
$where .= " AND (articles.rank >= 10000)";
}
// anonymous surfers and subscribers will see only published articles
if (!Surfer::is_member()) {
$where .= " AND NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')";
// logged surfers that are non-associates are restricted to their own articles, plus published articles
} elseif (!Surfer::is_empowered()) {
$where .= " AND ((articles.create_id=" . Surfer::get_id() . ") OR (NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')))";
}
// only consider live articles
$where .= " AND ((articles.expiry_date is NULL) " . "OR (articles.expiry_date <= '" . NULL_DATE . "') OR (articles.expiry_date > '" . $context['now'] . "'))";
// select among available items
$query = "SELECT COUNT(*) as count, MIN(edit_date) as oldest_date, MAX(edit_date) as newest_date" . " FROM " . SQL::table_name('articles') . " AS articles" . " WHERE (articles.anchor LIKE '" . SQL::escape($anchor) . "') AND (" . $where . ")";
$output = SQL::query_first($query);
return $output;
}
示例2: NOT
/**
* thread newest comments
*
* Result of this query should be processed with a layout adapted to articles
*
* @param int the offset from the start of the list; usually, 0 or 1
* @param int the number of items to display
* @param string the list variant, if any
* @return NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $icon)
*
* @see comments/index.php
*/
public static function &list_threads_by_date_for_anchor($anchor, $offset = 0, $count = 10, $variant = 'date')
{
global $context;
// restrict the query to addressable content
$where = Articles::get_sql_where();
// provide published pages to anonymous surfers
if (!Surfer::is_logged()) {
$where .= " AND NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')";
// logged surfers that are non-associates are restricted to their own articles, plus published articles
} elseif (!Surfer::is_empowered()) {
$where .= " AND ((articles.create_id=" . Surfer::get_id() . ") OR (NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')))";
}
// only consider live articles for non-associates
if (!Surfer::is_empowered()) {
$where .= " AND ((articles.expiry_date is NULL) " . "OR (articles.expiry_date <= '" . NULL_DATE . "') OR (articles.expiry_date > '" . $context['now'] . "'))";
}
// if not associate, restrict to comments at public published not expired pages
if (!Surfer::is_associate()) {
$where = " AND NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND ((articles.expiry_date is NULL)" . "\tOR (articles.expiry_date <= '" . NULL_DATE . "') OR (articles.expiry_date > '" . gmstrftime('%Y-%m-%d %H:%M:%S') . "'))";
}
// avoid blank records on join
$where .= ' AND (articles.id > 0)';
// several anchors
if (is_array($anchor)) {
$items = array();
foreach ($anchor as $token) {
$items[] = "articles.anchor LIKE '" . SQL::escape($token) . "'";
}
$where_anchor = join(' OR ', $items);
} else {
$where_anchor = "articles.anchor LIKE '" . SQL::escape($anchor) . "'";
}
// the list of comments
$query = "SELECT articles.* FROM " . SQL::table_name('comments') . " AS comments" . ", " . SQL::table_name('articles') . " AS articles" . " WHERE ((comments.anchor_type LIKE 'article') AND (comments.anchor_id = articles.id))" . "\tAND (" . $where_anchor . ") AND " . $where . " GROUP BY articles.id" . " ORDER BY articles.edit_date DESC LIMIT " . $offset . ',' . $count;
// return a list of articles
$output =& Articles::list_selected(SQL::query($query), $variant);
return $output;
}
示例3: stat_past_for_anchor
/**
* get some statistics for one anchor
*
* @param the selected anchor (e.g., 'article:12')
* @return the resulting ($count, $min_date, $max_date) array
*/
public static function stat_past_for_anchor($anchor)
{
global $context;
// restrict the query to addressable content
$where = Articles::get_sql_where();
// put only published pages in boxes
if (isset($variant) && $variant == 'boxes') {
$where .= " AND NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')";
// provide published pages to anonymous surfers
} elseif (!Surfer::is_logged()) {
$where .= " AND NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')";
// logged surfers that are non-associates are restricted to their own articles, plus published articles
} elseif (!Surfer::is_empowered()) {
$where .= " AND ((articles.create_id=" . Surfer::get_id() . ") OR (NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')))";
}
// now
$match = gmstrftime('%Y-%m-%d %H:%M:%S');
// select among available items
$query = "SELECT COUNT(*) as count, MIN(articles.edit_date) as oldest_date, MAX(articles.edit_date) as newest_date " . " FROM " . SQL::table_name('dates') . " as dates " . ", " . SQL::table_name('articles') . " AS articles" . " WHERE ((dates.anchor_type LIKE 'article') AND (dates.anchor_id = articles.id))" . "\tAND (dates.date_stamp < '" . SQL::escape($match) . "') AND\t(articles.anchor = '" . SQL::escape($anchor) . "') AND " . $where;
$output = SQL::query_first($query);
return $output;
}