示例#1
0
文件: members.php 项目: rair/yacs
 /**
  * list alphabetically the categories related to a given article or to any other anchor
  *
  * Actually list categories by rank, then by title, then by date.
  * If you select to not use the ranking system, categories will be ordered by title only.
  * Else categories with a low ranking mark will appear first,
  * and categories with a high ranking mark will be put at the end of the list.
  *
  * Only categories matching following criteria are returned:
  * - category is visible (active='Y')
  * - category is restricted (active='R'), but surfer is a logged user
  * - category is restricted (active='N'), but surfer is an associate
  * - an expiry date has not been defined, or is not yet passed
  *
  * @param the target member
  * @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
  * @param string anchor for restricted category parent, if any
  * @return NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $icon)
  *
  * @see articles/view.php
  * @see articles/layout_articles.php
  * @see articles/layout_articles_as_daily.php
  * @see articles/layout_articles_as_slashdot.php
  * @see categories/select.php
  * @see services/blog.php
  */
 public static function &list_categories_by_title_for_member($member, $offset = 0, $count = 10, $variant = 'full', $focus = NULL)
 {
     global $context;
     // display active and restricted items
     $where = "categories.active='Y'";
     if (Surfer::is_logged()) {
         $where .= " OR categories.active='R'";
     }
     if (Surfer::is_empowered()) {
         $where .= " OR categories.active='N'";
     }
     $where = '(' . $where . ')';
     // only consider live categories
     $where .= " AND ((categories.expiry_date is NULL)" . "\tOR (categories.expiry_date <= '" . NULL_DATE . "') OR (categories.expiry_date > '" . $context['now'] . "'))";
     // avoid weekly and monthly publications in list of articles
     if ($variant == 'raw') {
         $where .= " AND (categories.nick_name NOT LIKE 'week%') AND (categories.nick_name NOT LIKE '" . i18n::c('weekly') . "')" . " AND (categories.nick_name NOT LIKE 'month%') AND (categories.nick_name NOT LIKE '" . i18n::c('monthly') . "')";
     }
     if (isset($focus)) {
         $where .= " AND (categories.anchor  = '" . $focus . "' )";
     }
     // the list of categories
     $query = "SELECT categories.* FROM" . " (SELECT DISTINCT CAST(SUBSTRING(members.anchor, 10) AS UNSIGNED) AS target FROM " . SQL::table_name('members') . " AS members" . " WHERE (members.member LIKE '" . SQL::escape($member) . "') AND (members.anchor LIKE 'category:%')) AS ids" . ", " . SQL::table_name('categories') . " AS categories" . " WHERE (categories.id = ids.target)" . "\tAND " . $where . " ORDER BY rank, title, edit_date DESC LIMIT " . $offset . ',' . $count;
     // use existing listing facility
     $output =& Categories::list_selected(SQL::query($query), $variant);
     return $output;
 }
示例#2
0
文件: categories.php 项目: rair/yacs
 /**
  * search for some keywords in all categories
  *
  * Only categories matching following criteria are returned:
  * - category is visible (active='Y')
  * - category is restricted (active='R'), but surfer is a logged user
  * - category is restricted (active='N'), but surfer is an associate
  * - an expiry date has not been defined, or is not yet passed
  *
  * @param string the search string
  * @param float maximum score to look at
  * @param int the number of items to display
  * @param string the list variant, if any
  * @return NULL on error, else an ordered array of array($score, $summary)
  * @see #list_selected for $variant description
  */
 public static function &search($pattern, $offset = 1.0, $count = 50, $variant = 'search')
 {
     global $context;
     // sanity check
     if (!($pattern = trim($pattern))) {
         $output = NULL;
         return $output;
     }
     // limit the scope of the request
     $where = "categories.active='Y'";
     if (Surfer::is_member() || Surfer::is_teased()) {
         $where .= " OR categories.active='R'";
     }
     if (Surfer::is_associate() || Surfer::is_teased()) {
         $where .= " OR categories.active='N'";
     }
     $where = '(' . $where . ')';
     // only consider live categories
     $where .= ' AND ((categories.expiry_date is NULL)' . "\tOR (categories.expiry_date <= '" . NULL_DATE . "') OR (categories.expiry_date > '" . $context['now'] . "'))";
     // how to compute the score for categories
     $score = "(MATCH(title, introduction, description, keywords)" . " AGAINST('" . SQL::escape($pattern) . "' IN BOOLEAN MODE)" . "/SQRT(GREATEST(1.1, DATEDIFF(NOW(), edit_date))))";
     // the list of categories
     $query = "SELECT *," . " " . $score . " AS score" . " FROM " . SQL::table_name('categories') . " AS categories" . " WHERE (" . $score . " < " . $offset . ") AND (" . $score . " > 0)" . " AND " . $where . " ORDER BY score DESC" . " LIMIT " . $count;
     $output =& Categories::list_selected(SQL::query($query), $variant);
     return $output;
 }