/** * 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); }
/** * Gets all pages or published ones. * * NOTE: Since this function only returns titlelinks for use with the object model it does not exclude pages that are password protected * * @param bool $published TRUE for published or FALSE for all pages including un-published * @param bool $toplevel TRUE for only the toplevel pages * @param int $number number of pages to get (NULL by default for all) * @param string $sorttype NULL for the standard order as sorted on the backend, "title", "date", "id", "popular", "mostrated", "toprated", "random" * @param string $sortdirection false for ascenting, true for descending * @return array */ function getPages($published = NULL, $toplevel = false, $number = NULL, $sorttype = NULL, $sortdirection = NULL) { global $_zp_loggedin; if (is_null($sortdirection)) { $sortdirection = $this->getSortDirection('pages'); } if (is_null($sorttype)) { $sorttype = $this->getSortType('pages'); } if (is_null($published)) { $published = !zp_loggedin(); $all = zp_loggedin(MANAGE_ALL_PAGES_RIGHTS); } else { $all = !$published; } $gettop = ''; if ($published) { if ($toplevel) { $gettop = " AND parentid IS NULL"; } $show = " WHERE `show` = 1 AND date <= '" . date('Y-m-d H:i:s') . "'" . $gettop; } else { if ($toplevel) { $gettop = " WHERE parentid IS NULL"; } $show = $gettop; } if ($sortdirection) { $sortdir = ' DESC'; } else { $sortdir = ' ASC'; } switch ($sorttype) { default: case 'date': $sortorder = 'date'; break; case 'lastchange': $sortorder = 'lastchange'; break; case 'title': $sortorder = 'title'; break; case 'id': $sortorder = 'id'; break; case 'popular': $sortorder = 'hitcounter'; break; case 'mostrated': $sortorder = 'total_votes'; break; case 'toprated': if (empty($sortdir)) { $sortdir = ' DESC'; } $sortorder = '(total_value/total_votes) ' . $sortdir . ', total_value'; break; case 'random': $sortorder = 'RAND()'; $sortdir = ''; break; default: $sortorder = 'sort_order'; $sortdir = ''; break; } $all_pages = array(); // Disabled cache var for now because it does not return un-publishded and published if logged on index.php somehow if logged in. $result = query('SELECT * FROM ' . prefix('pages') . $show . ' ORDER by `' . $sortorder . '`' . $sortdir); if ($result) { while ($row = db_fetch_assoc($result)) { if ($all || $row['show']) { $all_pages[] = $row; } else { if ($_zp_loggedin) { $page = new ZenpagePage($row['titlelink']); if ($page->isMyItem(LIST_RIGHTS)) { $all_pages[] = $row; if ($number && count($result) >= $number) { break; } } } } } db_free_result($result); } return $all_pages; }
/** * Prints the nested list for pages and categories * * @param string $listtype 'cats-checkboxlist' for a fake nested checkbock list of categories for the news article edit/add page * 'cats-sortablelist' for a sortable nested list of categories for the admin categories page * 'pages-sortablelist' for a sortable nested list of pages for the admin pages page * @param int $articleid Only for $listtype = 'cats-checkboxlist': For ID of the news article if the categories an existing articles is assigned to shall be shown, empty if this is a new article to be added. * @param string $option Only for $listtype = 'cats-checkboxlist': "all" to show all categories if creating a new article without categories assigned, empty if editing an existing article that already has categories assigned. * @return string | bool */ function printNestedItemsList($listtype = 'cats-sortablelist', $articleid = '', $option = '') { global $_zp_zenpage; switch ($listtype) { case 'cats-checkboxlist': default: $ulclass = ""; break; case 'cats-sortablelist': case 'pages-sortablelist': $ulclass = " class=\"page-list\""; break; } switch ($listtype) { case 'cats-checkboxlist': case 'cats-sortablelist': $items = $_zp_zenpage->getAllCategories(false); break; case 'pages-sortablelist': $items = $_zp_zenpage->getPages(false); break; default: $items = array(); break; } $indent = 1; $open = array(1 => 0); $rslt = false; foreach ($items as $item) { switch ($listtype) { case 'cats-checkboxlist': case 'cats-sortablelist': $itemobj = new ZenpageCategory($item['titlelink']); $ismypage = $itemobj->isMyItem(ZENPAGE_NEWS_RIGHTS); break; case 'pages-sortablelist': $itemobj = new ZenpagePage($item['titlelink']); $ismypage = $itemobj->isMyItem(ZENPAGE_PAGES_RIGHTS); break; } $itemsortorder = $itemobj->getSortOrder(); $itemid = $itemobj->getID(); if ($ismypage) { $order = explode('-', $itemsortorder); $level = max(1, count($order)); if ($toodeep = $level > 1 && $order[$level - 1] === '') { $rslt = true; } if ($level > $indent) { echo "\n" . str_pad("\t", $indent, "\t") . "<ul" . $ulclass . ">\n"; $indent++; $open[$indent] = 0; } else { if ($level < $indent) { while ($indent > $level) { $open[$indent]--; $indent--; echo "</li>\n" . str_pad("\t", $indent, "\t") . "</ul>\n"; } } else { // indent == level if ($open[$indent]) { echo str_pad("\t", $indent, "\t") . "</li>\n"; $open[$indent]--; } else { echo "\n"; } } } if ($open[$indent]) { echo str_pad("\t", $indent, "\t") . "</li>\n"; $open[$indent]--; } switch ($listtype) { case 'cats-checkboxlist': echo "<li>\n"; printCategoryCheckboxListEntry($itemobj, $articleid, $option); break; case 'cats-sortablelist': echo str_pad("\t", $indent - 1, "\t") . "<li id=\"id_" . $itemid . "\" class=\"clear-element page-item1 left\">"; printCategoryListSortableTable($itemobj, $toodeep); break; case 'pages-sortablelist': echo str_pad("\t", $indent - 1, "\t") . "<li id=\"id_" . $itemid . "\">"; printPagesListTable($itemobj, $toodeep); break; } $open[$indent]++; } } while ($indent > 1) { echo "</li>\n"; $open[$indent]--; $indent--; echo str_pad("\t", $indent, "\t") . "</ul>"; } if ($open[$indent]) { echo "</li>\n"; } else { echo "\n"; } return $rslt; }