示例#1
0
 /**
  *
  * filters query results for only news that should be shown. (that is fit to print?)
  * @param $sql query to return all candidates of interest
  * @param $offset skip this many legitimate items (used for pagination)
  * @param $limit return only this many items
  */
 private function siftResults($sql, $offset, $limit)
 {
     $resource = $result = query($sql);
     if ($resource) {
         $result = array();
         while ($item = db_fetch_assoc($resource)) {
             if ($item['type'] == 'news') {
                 $article = new ZenpageNews($item['titlelink']);
                 if (!$article->categoryIsVisible()) {
                     continue;
                 }
             }
             $offset--;
             if ($offset < 0) {
                 $result[] = $item;
                 if ($limit && count($result) >= $limit) {
                     break;
                 }
             }
         }
         db_free_result($resource);
     }
     return $result;
 }
 /**
  * Gets news articles titlelinks this category is attached to
  *
  * NOTE: Since this function only returns titlelinks for use with the object model it does not exclude articles that are password protected via a category
  *
  *
  * @param int $articles_per_page The number of articles to get
  * @param string $published "published" for published articles
  *													"published-unpublished" for published articles only from an unpublished category,
  * 													"unpublished" for unpublished articles,
  * 													"sticky" for sticky articles (published or not!) for Admin page use only,
  * 													"all" for all articles
  * @param boolean $ignorepagination Since also used for the news loop this function automatically paginates the results if the "page" GET variable is set. To avoid this behaviour if using it directly to get articles set this TRUE (default FALSE)
  * @param string $sortorder "date" for sorting by date (default)
  * 													"title" for sorting by title
  * 													This parameter is not used for date archives
  * @param string $sortdirection "desc" (default) for descending sort order
  * 													    "asc" for ascending sort order
  * 											        This parameter is not used for date archives
  * @param bool $sticky set to true to place "sticky" articles at the front of the list.
  * @return array
  */
 function getArticles($articles_per_page = '', $published = NULL, $ignorepagination = false, $sortorder = "date", $sortdirection = "desc", $sticky = true)
 {
     global $_zp_current_category, $_zp_post_date, $_zp_zenpage;
     $_zp_zenpage->processExpired('news');
     if (empty($published)) {
         $published = "published";
         if (zp_loggedin(ZENPAGE_NEWS_RIGHTS | VIEW_NEWS_RIGHTS)) {
             $published = "all";
         }
     }
     $show = "";
     // new code to get nested cats
     $catid = $this->getID();
     $subcats = $this->getSubCategories();
     if ($subcats) {
         $cat = " (cat.cat_id = '" . $catid . "'";
         foreach ($subcats as $subcat) {
             $subcatobj = new ZenpageCategory($subcat);
             $cat .= "OR cat.cat_id = '" . $subcatobj->getID() . "' ";
         }
         $cat .= ") AND cat.news_id = news.id ";
     } else {
         $cat = " cat.cat_id = '" . $catid . "' AND cat.news_id = news.id ";
     }
     if (in_context(ZP_ZENPAGE_NEWS_DATE)) {
         $postdate = $_zp_post_date;
     } else {
         $postdate = NULL;
     }
     if ($sticky) {
         $sticky = 'sticky DESC,';
     }
     // sortorder and sortdirection
     switch ($sortorder) {
         case "date":
         default:
             $sort1 = "date";
             break;
         case "title":
             $sort1 = "title";
             break;
     }
     switch ($sortdirection) {
         case "desc":
         default:
             $dir = "DESC";
             break;
         case "asc":
             $dir = "ASC";
             $sticky = false;
             //makes no sense
             break;
     }
     /*** get articles by category ***/
     switch ($published) {
         case "published":
             $show = " AND `show` = 1 AND date <= '" . date('Y-m-d H:i:s') . "'";
             $getUnpublished = false;
             break;
         case "published-unpublished":
             $show = " AND `show` = 1 AND date <= '" . date('Y-m-d H:i:s') . "'";
             $getUnpublished = true;
             break;
         case "unpublished":
             $show = " AND `show` = 0 AND date <= '" . date('Y-m-d H:i:s') . "'";
             $getUnpublished = true;
             break;
         case 'sticky':
             $show = ' AND `sticky` <> 0';
             $getUnpublished = true;
             break;
         case "all":
             $getUnpublished = true;
             $show = "";
             break;
     }
     $order = " ORDER BY " . $sticky . "news.{$sort1} {$dir}";
     $sql = "SELECT DISTINCT news.titlelink FROM " . prefix('news') . " as news, " . prefix('news2cat') . " as cat WHERE" . $cat . $show . $order;
     $resource = $result = query($sql);
     if ($resource) {
         if ($ignorepagination) {
             $offset = 0;
         } else {
             $offset = $_zp_zenpage->getOffset($articles_per_page);
         }
         if (is_object($_zp_current_category)) {
             $currentcategory = $_zp_current_category->getTitlelink();
         } else {
             $currentcategory = false;
         }
         $result = array();
         while ($item = db_fetch_assoc($resource)) {
             $article = new ZenpageNews($item['titlelink']);
             if ($getUnpublished || $currentcategory && $article->inNewsCategory($currentcategory) || $article->categoryIsVisible()) {
                 $offset--;
                 if ($offset < 0) {
                     $result[] = $item;
                     if ($articles_per_page && count($result) >= $articles_per_page) {
                         break;
                     }
                 }
             }
         }
     }
     return $result;
 }