Пример #1
0
 /**
  * list articles of one user
  *
  * This function that are either:
  * - owned by the user
  * - or assigned to the user
  *
  * @param string passed to _get_order()
  * @param int the id of the target surfer
  * @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 the outcome of the layout
  *
  * @see users/print.php
  * @see users/view.php
  */
 public static function &list_for_user_by($order, $user_id, $offset = 0, $count = 10, $variant = 'full')
 {
     global $context;
     // sanity check
     if (!$user_id) {
         return NULL;
     }
     // limit the scope of the request
     $where = Articles::get_sql_where();
     // show only published articles if not looking at self record
     if (Surfer::get_id() != $user_id && !Surfer::is_associate()) {
         $where .= " AND NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')";
     }
     // strip dead pages
     if (Surfer::get_id() != $user_id && !Surfer::is_associate()) {
         $where .= " AND ((articles.expiry_date is NULL) " . "OR (articles.expiry_date <= '" . NULL_DATE . "') OR (articles.expiry_date > '" . $context['now'] . "'))";
     }
     // order these pages
     $order = Articles::_get_order($order);
     // the list of watched sections
     $watched_sections = "(SELECT CONCAT('section:', sections.id) AS target" . "\tFROM (" . SQL::table_name('members') . " AS members" . ", " . SQL::table_name('sections') . " AS sections)" . " WHERE (members.member = 'user:"******"')" . "\tAND (members.anchor LIKE 'section:%')" . "\tAND (sections.id = SUBSTRING(members.anchor, 9))" . " ORDER BY sections.edit_date DESC, sections.title LIMIT 0, 1000)";
     // the list of forwarding sections
     $forwarding_sections = "(SELECT CONCAT('section:', sections.id) AS target" . " FROM " . $watched_sections . " AS anchors" . ", " . SQL::table_name('sections') . " AS sections" . " WHERE (sections.anchor = anchors.target) AND (sections.options LIKE '%forward_notifications%')" . " ORDER BY sections.edit_date DESC, sections.title LIMIT 0, 1000)";
     // look for pages in watched sections
     $query = "(SELECT articles.* FROM (" . $watched_sections . " UNION " . $forwarding_sections . ") AS anchors" . ", " . SQL::table_name('articles') . " AS articles" . " WHERE (articles.anchor = anchors.target)" . "\tAND " . $where . ") UNION ";
     // look for watched pages
     $query .= "(SELECT articles.* FROM (SELECT DISTINCT CAST(SUBSTRING(members.anchor, 9) AS UNSIGNED) AS target FROM " . SQL::table_name('members') . " AS members WHERE (members.member LIKE 'user:"******"') AND (members.anchor LIKE 'article:%')) AS ids" . ", " . SQL::table_name('articles') . " AS articles" . " WHERE (articles.id = ids.target)" . "\tAND " . $where . ")";
     // include articles assigned to this surfer
     if ($these_items = Surfer::assigned_articles($user_id)) {
         $query = "(SELECT articles.* FROM " . SQL::table_name('articles') . " AS articles" . " WHERE articles.id IN (" . join(', ', $these_items) . ")" . "\tAND " . $where . ")" . " UNION " . $query;
     }
     // include articles owned by this surfer
     $query = "(SELECT articles.* FROM " . SQL::table_name('articles') . " AS articles" . " WHERE articles.owner_id = " . $user_id . "\tAND " . $where . ")" . " UNION " . $query;
     // finalize the query
     $query .= " ORDER BY " . $order . " LIMIT " . $offset . ',' . $count;
     // use existing listing facility
     $output =& Articles::list_selected(SQL::query($query), $variant);
     return $output;
 }
Пример #2
0
 /**
  * search for some keywords in all files
  *
  * Only files matching following criteria are returned:
  * - file is visible (active='Y')
  * - file is restricted (active='R'), but surfer is a logged user
  * - file is restricted (active='N'), but surfer is an associate
  *
  * @param string searched tokens
  * @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)
  */
 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 = "active='Y'";
     if (Surfer::is_logged() || Surfer::is_teased()) {
         $where .= " OR active='R'";
     }
     if (Surfer::is_associate() || Surfer::is_teased()) {
         $where .= " OR active='N'";
     } else {
         // files attached to managed sections
         if ($my_sections = Surfer::assigned_sections()) {
             $where .= " OR anchor IN ('section:" . join("', 'section:", $my_sections) . "')";
             // files attached to pages in managed sections
             $where .= " OR anchor IN (SELECT CONCAT('article:', id) FROM " . SQL::table_name('articles') . "  WHERE anchor IN ('section:" . join("', 'section:", $my_sections) . "'))";
         }
         // files attached to managed articles
         if ($my_articles = Surfer::assigned_articles()) {
             $where .= " OR anchor IN ('article:" . join("', 'article:", $my_articles) . "')";
         }
     }
     // how to compute the score for files
     $score = "(MATCH(title, source, keywords)" . " AGAINST('" . SQL::escape($pattern) . "' IN BOOLEAN MODE)" . "/SQRT(GREATEST(1.1, DATEDIFF(NOW(), edit_date))))";
     // the list of files
     $query = "SELECT *, " . $score . " AS score FROM " . SQL::table_name('files') . " AS files" . " WHERE (" . $score . " < " . $offset . ") AND (" . $score . " > 0)" . "  AND (" . $where . ")" . " ORDER BY score DESC" . " LIMIT " . $count;
     // do the query
     $output =& Files::list_selected(SQL::query($query), $variant);
     return $output;
 }
Пример #3
0
 /**
  * list the articles by rating sum related to a given category or to any other anchor
  *
  * Actually list articles by rating sum, then by date. Note that articles are never ranked into a category list.
  *
  * Only articles matching following criteria are returned:
  * - article is visible (active='Y')
  * - article is restricted (active='R'), but surfer is a logged user
  * - article is restricted (active='N'), but surfer is an associate
  * - article has been officially published
  * - an expiry date has not been defined, or is not yet passed
  *
  * @param the target anchor
  * @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 categories/print.php
  * @see categories/view.php
  */
 public static function &list_articles_by_rating_for_anchor($anchor, $offset = 0, $count = 10, $variant = NULL, $lang = false)
 {
     global $context;
     // locate where we are
     if (!$variant) {
         $variant = $anchor;
     }
     // limit the scope of the request
     $where = "(articles.active='Y'";
     if (Surfer::is_logged()) {
         $where .= " OR articles.active='R'";
     }
     if (Surfer::is_empowered('S')) {
         $where .= " OR articles.active='N'";
     }
     // include managed sections
     if ($my_sections = Surfer::assigned_sections()) {
         $where .= " OR articles.anchor IN ('section:" . join("', 'section:", $my_sections) . "')";
     }
     // include managed pages for editors
     if ($my_articles = Surfer::assigned_articles()) {
         $where .= " OR articles.id IN (" . join(', ', $my_articles) . ")";
     }
     $where .= ")";
     // limit the scope by language
     if ($lang) {
         $where .= " AND ( articles.language='" . SQL::escape($lang) . "' OR articles.language='')";
     }
     // see only published articles in categories
     $where .= " AND 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'] . "'))";
     // the list of articles
     $query = "SELECT articles.*" . " FROM (" . SQL::table_name('members') . " AS members" . ", " . SQL::table_name('articles') . " AS articles)" . " WHERE (members.anchor LIKE '" . SQL::escape($anchor) . "')" . "\tAND (members.member_type LIKE 'article')" . "\tAND (articles.id = members.member_id)" . "\tAND " . $where . " ORDER BY rating_sum, edit_date DESC LIMIT " . $offset . ',' . $count;
     // use existing listing facility
     $output =& Articles::list_selected(SQL::query($query), $variant);
     return $output;
 }