/**
 * Gets latest comments for news articles and pages
 *
 * @param int $number how many comments you want.
 * @param string $type 	"all" for all latest comments for all news articles and all pages
 * 											"news" for the lastest comments of one specific news article
 * 											"page" for the lastest comments of one specific page
 * @param int $itemID the ID of the element to get the comments for if $type != "all"
 */
function getLatestZenpageComments($number, $type = "all", $itemID = "")
{
    $itemID = sanitize_numeric($itemID);
    $number = sanitize_numeric($number);
    $checkauth = zp_loggedin();
    if ($type == 'all' || $type == 'news') {
        $newspasswordcheck = "";
        if (zp_loggedin(MANAGE_ALL_NEWS_RIGHTS)) {
            $newsshow = '';
        } else {
            $newsshow = 'news.show=1 AND';
            $newscheck = query_full_array("SELECT * FROM " . prefix('news') . " ORDER BY date");
            foreach ($newscheck as $articlecheck) {
                $obj = new ZenpageNews($articlecheck['titlelink']);
                if ($obj->inProtectedCategory()) {
                    if ($checkauth && $obj->isMyItem(LIST_RIGHTS)) {
                        $newsshow = '';
                    } else {
                        $excludenews = " AND id != " . $articlecheck['id'];
                        $newspasswordcheck = $newspasswordcheck . $excludenews;
                    }
                }
            }
        }
    }
    if ($type == 'all' || $type == 'page') {
        $pagepasswordcheck = "";
        if (zp_loggedin(MANAGE_ALL_PAGES_RIGHTS)) {
            $pagesshow = '';
        } else {
            $pagesshow = 'pages.show=1 AND';
            $pagescheck = query_full_array("SELECT * FROM " . prefix('pages') . " ORDER BY date");
            foreach ($pagescheck as $pagecheck) {
                $obj = new ZenpagePage($pagecheck['titlelink']);
                if ($obj->isProtected()) {
                    if ($checkauth && $obj->isMyItem(LIST_RIGHTS)) {
                        $pagesshow = '';
                    } else {
                        $excludepages = " AND pages.id != " . $pagecheck['id'];
                        $pagepasswordcheck = $pagepasswordcheck . $excludepages;
                    }
                }
            }
        }
    }
    switch ($type) {
        case "news":
            $whereNews = " WHERE {$newsshow} news.id = " . $itemID . " AND c.ownerid = news.id AND c.type = 'news' AND c.private = 0 AND c.inmoderation = 0" . $newspasswordcheck;
            break;
        case "page":
            $wherePages = " WHERE {$pagesshow} pages.id = " . $itemID . " AND c.ownerid = pages.id AND c.type = 'pages' AND c.private = 0 AND c.inmoderation = 0" . $pagepasswordcheck;
            break;
        case "all":
            $whereNews = " WHERE {$newsshow} c.ownerid = news.id AND c.type = 'news' AND c.private = 0 AND c.inmoderation = 0" . $newspasswordcheck;
            $wherePages = " WHERE {$pagesshow} c.ownerid = pages.id AND c.type = 'pages' AND c.private = 0 AND c.inmoderation = 0" . $pagepasswordcheck;
            break;
    }
    $comments_news = array();
    $comments_pages = array();
    if ($type == "all" or $type == "news") {
        $comments_news = query_full_array("SELECT c.id, c.name, c.type, c.website," . " c.date, c.anon, c.comment, news.title, news.titlelink FROM " . prefix('comments') . " AS c, " . prefix('news') . " AS news " . $whereNews . " ORDER BY c.id DESC LIMIT {$number}");
    }
    if ($type == "all" or $type == "page") {
        $comments_pages = query_full_array($sql = "SELECT c.id, c.name, c.type, c.website," . " c.date, c.anon, c.comment, pages.title, pages.titlelink FROM " . prefix('comments') . " AS c, " . prefix('pages') . " AS pages " . $wherePages . " ORDER BY c.id DESC LIMIT {$number}");
    }
    $comments = array();
    foreach ($comments_news as $comment) {
        $comments[$comment['id']] = $comment;
    }
    foreach ($comments_pages as $comment) {
        $comments[$comment['id']] = $comment;
    }
    krsort($comments);
    return array_slice($comments, 0, $number);
}
Beispiel #2
0
 /**
  * Gets all news articles titlelink.
  *
  * 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 an published articles,
  * 													"unpublished" for an unpublised articles,
  * 													"published-unpublished" for published articles only from an unpublished category,
  * 													"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" (default), "title", "id, "popular", "mostrated", "toprated", "random"
  * 													This parameter is not used for date archives
  * @param bool $sortdirection TRUE for descending, FALSE for ascending. Note: 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 = 0, $published = NULL, $ignorepagination = false, $sortorder = NULL, $sortdirection = NULL, $sticky = NULL, $category = NULL)
 {
     global $_zp_current_category, $_zp_post_date, $_zp_newsCache;
     if (empty($published)) {
         if (zp_loggedin() || $category && $category->isMyItem(ZENPAGE_NEWS_RIGHTS)) {
             $published = "all";
         } else {
             $published = "published";
         }
     }
     if ($category) {
         $sortObj = $category;
     } else {
         $sortObj = $this;
     }
     if (is_null($sticky)) {
         $sticky = $sortObj->getSortSticky();
     }
     if (is_null($sortdirection)) {
         $sortdirection = $sortObj->getSortDirection('news');
     }
     if (is_null($sortorder)) {
         $sortorder = $sortObj->getSortType('news');
     }
     $newsCacheIndex = "{$sortorder}-{$sortdirection}-{$published}-" . (bool) $sticky;
     if ($category) {
         $newsCacheIndex .= '-' . $category->getTitlelink();
     }
     if (isset($_zp_newsCache[$newsCacheIndex])) {
         $result = $_zp_newsCache[$newsCacheIndex];
     } else {
         $show = $currentcategory = false;
         if ($category) {
             if (is_object($_zp_current_category)) {
                 $currentcategory = $_zp_current_category->getTitlelink();
             }
             $showConjunction = ' AND ';
             // new code to get nested cats
             $catid = $category->getID();
             $subcats = $category->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 ";
             }
         } else {
             $showConjunction = ' WHERE ';
         }
         if ($sticky) {
             $sticky = 'sticky DESC,';
         }
         if ($sortdirection) {
             $dir = " DESC";
         } else {
             $dir = " ASC";
         }
         // sortorder and sortdirection (only used for all news articles and categories naturally)
         switch ($sortorder) {
             case "date":
             default:
                 $sort1 = "date" . $dir;
                 break;
             case 'lastchange':
                 $sort1 = 'lastchange' . $dir;
                 break;
             case "id":
                 $sort1 = "id" . $dir;
                 break;
             case "title":
                 $sort1 = "title" . $dir;
                 break;
             case "popular":
                 $sort1 = 'hitcounter' . $dir;
                 break;
             case "mostrated":
                 $sort1 = 'total_votes' . $dir;
                 break;
             case "toprated":
                 $sort1 = '(total_value/total_votes) DESC, total_value';
                 break;
             case "random":
                 $sort1 = 'RAND()';
                 break;
         }
         /** get all articles * */
         switch ($published) {
             case "published":
                 $show = "{$showConjunction} `show` = 1 AND date <= '" . date('Y-m-d H:i:s') . "'";
                 $getUnpublished = false;
                 break;
             case "published-unpublished":
                 $show = "{$showConjunction} `show` = 1 AND date <= '" . date('Y-m-d H:i:s') . "'";
                 $getUnpublished = true;
                 break;
             case "unpublished":
                 $show = "{$showConjunction} `show` = 0 AND date <= '" . date('Y-m-d H:i:s') . "'";
                 $getUnpublished = true;
                 break;
             case 'sticky':
                 $show = "{$showConjunction} `sticky` <> 0";
                 $getUnpublished = true;
                 break;
             case "all":
                 $getUnpublished = true;
                 $show = false;
                 break;
         }
         $order = " ORDER BY {$sticky}";
         if (in_context(ZP_ZENPAGE_NEWS_DATE)) {
             $datesearch = '';
             switch ($published) {
                 case "published":
                     $datesearch = "date LIKE '{$_zp_post_date}%' ";
                     break;
                 case "unpublished":
                     $datesearch = "date LIKE '{$_zp_post_date}%' ";
                     break;
                 case "all":
                     $datesearch = "date LIKE '{$_zp_post_date}%' ";
                     break;
             }
             if ($datesearch) {
                 if ($show) {
                     $datesearch = ' AND ' . $datesearch;
                 } else {
                     $datesearch = ' WHERE ' . $datesearch;
                 }
             }
             $order .= " date DESC";
         } else {
             $datesearch = "";
             if ($category) {
                 $order .= ' news.';
             } else {
                 $order .= ' ';
             }
             $order .= $sort1;
         }
         if ($category) {
             $sql = "SELECT DISTINCT news.date, news.title, news.titlelink, news.sticky FROM " . prefix('news') . " as news, " . prefix('news2cat') . " as cat WHERE" . $cat . $show . $order;
         } else {
             $sql = "SELECT date, title, titlelink, sticky FROM " . prefix('news') . $show . $datesearch . " " . $order;
         }
         $resource = query($sql);
         $result = array();
         if ($resource) {
             while ($item = db_fetch_assoc($resource)) {
                 $article = new ZenpageNews($item['titlelink']);
                 if ($getUnpublished || $article->isMyItem(ZENPAGE_NEWS_RIGHTS) || $currentcategory && $article->inNewsCategory($currentcategory) || $article->categoryIsVisible()) {
                     $result[] = $item;
                 }
             }
             db_free_result($resource);
             if ($sortorder == 'title') {
                 // multi-lingual field!
                 $result = sortByMultilingual($result, 'title', $sortdirection);
                 if ($sticky) {
                     $stickyItems = array();
                     foreach ($result as $key => $element) {
                         if ($element['sticky']) {
                             array_unshift($stickyItems, $element);
                             unset($result[$key]);
                         }
                     }
                     $stickyItems = sortMultiArray($stickyItems, 'sticky', true);
                     $result = array_merge($stickyItems, $result);
                 }
             }
         }
         $_zp_newsCache[$newsCacheIndex] = $result;
     }
     if ($articles_per_page) {
         if ($ignorepagination) {
             $offset = 0;
         } else {
             $offset = self::getOffset($articles_per_page);
         }
         $result = array_slice($result, $offset, $articles_per_page);
     }
     return $result;
 }
    $resultU = $catobj->getArticles(0, 'unpublished', false);
    $result = $catobj->getArticles(0, $published, false);
} else {
    $catobj = NULL;
    $resultU = $_zp_zenpage->getNewsArticles(0, 'unpublished', false);
    $result = $_zp_zenpage->getNewsArticles(0, $published, false);
}
foreach ($result as $key => $article) {
    $article = new ZenpageNews($article['titlelink']);
    if (!$article->isMyItem(ZENPAGE_NEWS_RIGHTS)) {
        unset($result[$key]);
    }
}
foreach ($resultU as $key => $article) {
    $article = new ZenpageNews($article['titlelink']);
    if (!$article->isMyItem(ZENPAGE_NEWS_RIGHTS)) {
        unset($resultU[$key]);
    }
}
$total = 1;
$articles = count($result);
$articles_page = 15;
if (isset($_GET['articles_page'])) {
    if ($_GET['articles_page'] == 'all') {
        $articles_page = 0;
    } else {
        $articles_page = sanitize_numeric($_GET['articles_page']);
    }
}
if ($articles_page) {
    $offset = $_zp_zenpage->getOffset($articles_page);