1: <?php
   2:    3:    4:    5:    6:    7:    8: 
   9: 
  10:   11: 
  12: 
  13: 
  14: 
  15:   16: 
  17: 
  18:   19:   20:   21:   22: 
  23: function is_News() {
  24:     global $_zp_current_zenpage_news;
  25:     return(!is_null($_zp_current_zenpage_news));
  26: }
  27: 
  28:   29:   30:   31:   32: 
  33: function is_NewsPage() {
  34:     global $_zp_gallery_page;
  35:     return $_zp_gallery_page == 'news.php';
  36: }
  37: 
  38:   39:   40:   41:   42: 
  43: function is_NewsArticle() {
  44:     return is_News() && in_context(ZP_ZENPAGE_SINGLE);
  45: }
  46: 
  47:   48:   49:   50:   51: 
  52: function is_NewsCategory() {
  53:     return in_context(ZP_ZENPAGE_NEWS_CATEGORY);
  54: }
  55: 
  56:   57:   58:   59:   60: 
  61: function is_NewsArchive() {
  62:     return in_context(ZP_ZENPAGE_NEWS_DATE);
  63: }
  64: 
  65:   66:   67:   68:   69: 
  70: function is_Pages() {
  71:     return in_context(ZP_ZENPAGE_PAGE);
  72: }
  73: 
  74:   75:   76:   77:   78: 
  79: function stickyNews($newsobj = NULL) {
  80:     global $_zp_current_zenpage_news;
  81:     if (is_null($newsobj)) {
  82:         $newsobj = $_zp_current_zenpage_news;
  83:     }
  84:     return $newsobj->getSticky();
  85: 
  86:     return false;
  87: }
  88: 
  89:   90:   91:   92:   93:   94:   95: 
  96: function getAuthor($fullname = false) {
  97:     global $_zp_current_zenpage_page, $_zp_current_zenpage_news;
  98: 
  99:     if (is_Pages()) {
 100:         $obj = $_zp_current_zenpage_page;
 101:     } else if (is_News()) {
 102:         $obj = $_zp_current_zenpage_news;
 103:     } else {
 104:         $obj = false;
 105:     }
 106:     if ($obj) {
 107:         if ($fullname) {
 108:             $admin = Zenphoto_Authority::getAnAdmin(array('`user`=' => $obj->getAuthor(), '`valid`=' => 1));
 109:             if (is_object($admin) && $admin->getName()) {
 110:                 return $admin->getName();
 111:             }
 112:         }
 113:         return $obj->getAuthor();
 114:     }
 115:     return false;
 116: }
 117: 
 118: 
 119:  120: 
 121: 
 122:  123:  124:  125:  126:  127:  128:  129:  130:  131:  132: 
 133: function getLatestNews($number = 2, $category = '', $sticky = true, $sortdirection = 'desc') {
 134:     global $_zp_zenpage, $_zp_current_zenpage_news;
 135:     
 136:     $args = func_get_args();
 137:     $deprecated = array(
 138:                     "none",
 139:                     "with_latest_images",
 140:                     "with_latest_images_date",
 141:                     "with_latest_images_mtime",
 142:                     "with_latest_images_publishdate",
 143:                     "with_latest_albums",
 144:                     "with_latest_albums_date",
 145:                     "with_latest_albums_mtime",
 146:                     "with_latest_albums_publishdate",
 147:                     "with_latestupdated_albums");
 148:     if (in_array($category, $deprecated)) {
 149:         
 150:         Zenpage_internal_deprecations::getLatestNews();
 151:         list($number, $category, $sticky, $sortdirection ) = array_merge($args, array(NULL, NULL, NULL, NULL, NULL));
 152:     }
 153:     $sortdir = strtolower($sortdirection) != 'asc';
 154:     if (empty($category)) {
 155:         $latest = $_zp_zenpage->getArticles($number, NULL, true, NULL, $sortdir, $sticky, NULL);
 156:     } else {
 157:         $catobj = new ZenpageCategory($category);
 158:         $latest = $catobj->getArticles($number, NULL, true, NULL, $sortdir, $sticky);
 159:     }
 160:     return $latest;
 161: }
 162: 
 163:  164:  165:  166:  167:  168:  169:  170:  171:  172:  173:  174:  175:  176:  177: 
 178: function printLatestNews($number = 5, $category = '', $showdate = true, $showcontent = true, $contentlength = 70, $showcat = true, $readmore = NULL, $sticky = true) {
 179:     global $_zp_gallery, $_zp_current_zenpage_news;
 180:     
 181:     $args = func_get_args();
 182:     $deprecated = array(
 183:                     "none",
 184:                     "with_latest_images",
 185:                     "with_latest_images_date",
 186:                     "with_latest_images_mtime",
 187:                     "with_latest_images_publishdate",
 188:                     "with_latest_albums",
 189:                     "with_latest_albums_date",
 190:                     "with_latest_albums_mtime",
 191:                     "with_latest_albums_publishdate",
 192:                     "with_latestupdated_albums");
 193:     if (in_array($category, $deprecated)) {
 194:         
 195:         Zenpage_internal_deprecations::printLatestNews();
 196:         list($number, $option, $category, $showdate, $showcontent, $contentlength, $showcat, $readmore, $sticky) = array_merge($args, array(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL));
 197:     }
 198: 
 199:     $latest = getLatestNews($number, $category, $sticky);
 200:     echo "\n<ul id=\"latestnews\">\n";
 201:     $count = "";
 202:     foreach ($latest as $item) {
 203:         $count++;
 204:         $category = "";
 205:         $categories = "";
 206: 
 207:         $obj = new ZenpageNews($item['titlelink']);
 208:         $title = html_encode($obj->getTitle());
 209:         $link = html_encode(getNewsURL($item['titlelink']));
 210:         $count2 = 0;
 211:         $category = $obj->getCategories();
 212:         foreach ($category as $cat) {
 213:             $catobj = new ZenpageCategory($cat['titlelink']);
 214:             $count2++;
 215:             if ($count2 != 1) {
 216:                 $categories = $categories . ", ";
 217:             }
 218:             $categories = $categories . $catobj->getTitle();
 219:         }
 220:         $thumb = "";
 221:         $content = $obj->getContent();
 222:         if ($obj->getTruncation()) {
 223:             $shorten = true;
 224:         }
 225:         $date = zpFormattedDate(DATE_FORMAT, strtotime($item['date']));
 226:         echo "<li>";
 227:         echo "<h3><a href=\"" . $link . "\" title=\"" . getBare(html_encode($title)) . "\">" . $title . "</a></h3>\n";
 228:         if ($showdate) {
 229:             echo "<span class=\"latestnews-date\">" . $date . "</span>\n";
 230:         }
 231:         if ($showcontent) {
 232:             echo "<span class=\"latestnews-desc\">" . getContentShorten($content, $contentlength, '', $readmore, $link) . "</span>\n";
 233:         }
 234:         if ($showcat && !empty($categories)) {
 235:             echo "<span class=\"latestnews-cats\">(" . html_encode($categories) . ")</span>\n";
 236:         }
 237:         echo "</li>\n";
 238:         if ($count == $number) {
 239:             break;
 240:         }
 241:     }
 242:     echo "</ul>\n";
 243: }
 244: 
 245:  246:  247:  248:  249:  250:  251:  252:  253: 
 254: function getNumNews($total = false) {
 255:     global $_zp_zenpage, $_zp_current_zenpage_news, $_zp_current_zenpage_news_restore, $_zp_zenpage_articles, $_zp_gallery, $_zp_current_search;
 256:     if ($total) {
 257:         return count($_zp_zenpage->getArticles(0));
 258:     } else if (in_context(ZP_SEARCH)) {
 259:         return count($_zp_current_search->getArticles());
 260:     } else {
 261:         return count($_zp_zenpage->getArticles(0));
 262:     }
 263: }
 264: 
 265:  266:  267:  268:  269:  270:  271: 
 272: function next_news() {
 273:     global $_zp_zenpage, $_zp_current_zenpage_news, $_zp_current_zenpage_news_restore, $_zp_zenpage_articles, $_zp_current_category, $_zp_gallery, $_zp_current_search;
 274:     if (func_num_args() != 0) {
 275:         
 276:         Zenpage_internal_deprecations::next_news();
 277:     }
 278: 
 279:     if (is_null($_zp_zenpage_articles)) {
 280:         if (in_context(ZP_SEARCH)) {
 281:             
 282:             $_zp_zenpage_articles = $_zp_current_search->getArticles(ZP_ARTICLES_PER_PAGE, NULL, true, NULL, NULL);
 283:         } else {
 284:             if (in_context(ZP_ZENPAGE_NEWS_CATEGORY)) {
 285:                 $_zp_zenpage_articles = $_zp_current_category->getArticles(ZP_ARTICLES_PER_PAGE, NULL, false, NULL, NULL);
 286:             } else {
 287:                 $_zp_zenpage_articles = $_zp_zenpage->getArticles(ZP_ARTICLES_PER_PAGE, NULL, false, NULL, NULL);
 288:             }
 289:             if (empty($_zp_zenpage_articles)) {
 290:                 return NULL;
 291:             }
 292:         }
 293:         $_zp_current_zenpage_news_restore = $_zp_current_zenpage_news;
 294:     }
 295:     if (!empty($_zp_zenpage_articles)) {
 296:         $news = array_shift($_zp_zenpage_articles);
 297:         if (is_array($news)) {
 298:             add_context(ZP_ZENPAGE_NEWS_ARTICLE);
 299:             $_zp_current_zenpage_news = new ZenpageNews($news['titlelink']);
 300:             return true;
 301:         }
 302:     }
 303: 
 304:     $_zp_zenpage_articles = NULL;
 305:     $_zp_current_zenpage_news = $_zp_current_zenpage_news_restore;
 306:     rem_context(ZP_ZENPAGE_NEWS_ARTICLE);
 307:     return false;
 308: }
 309: 
 310:  311:  312:  313:  314: 
 315: function getNewsID() {
 316:     global $_zp_current_zenpage_news;
 317:     if (!is_null($_zp_current_zenpage_news)) {
 318:         return $_zp_current_zenpage_news->getID();
 319:     }
 320: }
 321: 
 322:  323:  324:  325:  326: 
 327: function getNewsTitle() {
 328:     global $_zp_current_zenpage_news;
 329:     if (!is_null($_zp_current_zenpage_news)) {
 330:         return $_zp_current_zenpage_news->getTitle();
 331:     }
 332: }
 333: 
 334:  335:  336:  337:  338: 
 339: function printNewsTitle($before = '') {
 340:     if ($title = getNewsTitle()) {
 341:         if ($before) {
 342:             echo '<span class="beforetext">' . html_encode($before) . '</span>';
 343:         }
 344:         echo html_encode($title);
 345:     }
 346: }
 347: 
 348:  349:  350:  351:  352:  353: 
 354: function getBareNewsTitle() {
 355:     return getBare(getNewsTitle());
 356: }
 357: 
 358: function printBareNewsTitle() {
 359:     echo html_encode(getBareNewsTitle());
 360: }
 361: 
 362:  363:  364:  365:  366:  367:  368: 
 369: function getNewsURL($titlelink = NULL) {
 370:     global $_zp_current_zenpage_news;
 371:     if (empty($titlelink)) {
 372:         $obj = $_zp_current_zenpage_news;
 373:     } else {
 374:         $obj = new ZenpageNews($titlelink);
 375:     }
 376:     if (!is_null($obj))
 377:         return $obj->getLink();
 378: }
 379: 
 380:  381:  382:  383:  384: 
 385: function printNewsURL($before = '') {
 386:     if (getNewsTitle()) {
 387:         if ($before) {
 388:             $before = '<span class="beforetext">' . html_encode($before) . '</span>';
 389:         }
 390:         echo "<a href=\"" . html_encode(getNewsURL()) . "\" title=\"" . getBareNewsTitle() . "\">" . $before . html_encodeTagged(getNewsTitle()) . "</a>";
 391:     }
 392: }
 393: 
 394:  395:  396:  397:  398:  399:  400:  401:  402:  403:  404: 
 405: function getNewsContent($shorten = false, $shortenindicator = NULL, $readmore = NULL) {
 406:     global $_zp_current_image, $_zp_gallery, $_zp_current_zenpage_news, $_zp_page;
 407:     if (!$_zp_current_zenpage_news->checkAccess()) {
 408:         return '<p>' . gettext('<em>This entry belongs to a protected category.</em>') . '</p>';
 409:     }
 410:     $excerptbreak = false;
 411:     if (!$shorten && !is_NewsArticle()) {
 412:         $shorten = ZP_SHORTEN_LENGTH;
 413:     }
 414: 
 415:     $articlecontent = $_zp_current_zenpage_news->getContent();
 416:     if (!is_NewsArticle()) {
 417:         if ($_zp_current_zenpage_news->getTruncation()) {
 418:             $shorten = true;
 419:         }
 420:         $articlecontent = getContentShorten($articlecontent, $shorten, $shortenindicator, $readmore, $_zp_current_zenpage_news->getLink());
 421:     }
 422: 
 423:     return $articlecontent;
 424: }
 425: 
 426:  427:  428:  429:  430:  431:  432:  433:  434:  435: 
 436: function printNewsContent($shorten = false, $shortenindicator = NULL, $readmore = NULL) {
 437:     global $_zp_current_zenpage_news, $_zp_page;
 438:     $newscontent = getNewsContent($shorten, $shortenindicator, $readmore);
 439:     echo html_encodeTagged($newscontent);
 440: }
 441: 
 442:  443:  444:  445:  446:  447:  448:  449:  450:  451:  452:  453:  454: 
 455: function getContentShorten($text, $shorten, $shortenindicator = NULL, $readmore = NULL, $readmoreurl = NULL) {
 456:     $readmorelink = '';
 457:     if (is_null($shortenindicator)) {
 458:         $shortenindicator = ZP_SHORTENINDICATOR;
 459:     }
 460:     if (is_null($readmore)) {
 461:         $readmore = get_language_string(ZP_READ_MORE);
 462:     }
 463:     if (!is_null($readmoreurl)) {
 464:         $readmorelink = '<p class="readmorelink"><a href="' . html_encode($readmoreurl) . '" title="' . html_encode($readmore) . '">' . html_encode($readmore) . '</a></p>';
 465:     }
 466: 
 467:     if (!$shorten && !is_NewsArticle()) {
 468:         $shorten = ZP_SHORTEN_LENGTH;
 469:     }
 470:     $contentlenght = mb_strlen($text);
 471:     if (!empty($shorten) && ($contentlenght > (int) $shorten)) {
 472:         if (stristr($text, '<!-- pagebreak -->')) {
 473:             $array = explode('<!-- pagebreak -->', $text);
 474:             $newtext = array_shift($array);
 475:             while (!empty($array) && (mb_strlen($newtext) + mb_strlen($array[0])) < $shorten) { 
 476:                 $newtext .= array_shift($array);
 477:             }
 478:             if ($shortenindicator && empty($array) || ($array[0] == '</p>' || trim($array[0]) == '')) { 
 479:                 $text = shortenContent($newtext, $shorten, '') . $readmorelink;
 480:             } else {
 481:                 $text = shortenContent($newtext, $shorten, $shortenindicator, true) . $readmorelink;
 482:             }
 483:         } else {
 484:             if (!is_bool($shorten)) {
 485:                 $newtext = shortenContent($text, $shorten, $shortenindicator);
 486:                 if ($newtext != $text) {
 487:                     $text = $newtext . $readmorelink;
 488:                 }
 489:             }
 490:         }
 491:     }
 492:     return $text;
 493: }
 494: 
 495:  496:  497:  498:  499: 
 500: function getNewsExtraContent() {
 501:     global $_zp_current_zenpage_news;
 502:     if (is_News()) {
 503:         $extracontent = $_zp_current_zenpage_news->getExtraContent();
 504:         return $extracontent;
 505:     } else {
 506:         return FALSE;
 507:     }
 508: }
 509: 
 510:  511:  512:  513:  514: 
 515: function printNewsExtraContent() {
 516:     echo getNewsExtraContent();
 517: }
 518: 
 519:  520:  521:  522:  523: 
 524: function getNewsReadMore() {
 525:     global $_zp_current_zenpage_news;
 526:     $readmore = get_language_string(ZP_READ_MORE);
 527:     return $readmore;
 528: }
 529: 
 530:  531:  532:  533:  534: 
 535: function getNewsCustomData() {
 536:     global $_zp_current_zenpage_news;
 537:     if (!is_null($_zp_current_zenpage_news)) {
 538:         return $_zp_current_zenpage_news->getCustomData();
 539:     }
 540: }
 541: 
 542:  543:  544:  545: 
 546: function printNewsCustomData() {
 547:     echo getNewsCustomData();
 548: }
 549: 
 550:  551:  552:  553:  554: 
 555: function getNewsAuthor($fullname = false) {
 556:     global $_zp_current_zenpage_news;
 557:     if (is_News()) {
 558:         return getAuthor($fullname);
 559:     }
 560:     return false;
 561: }
 562: 
 563:  564:  565:  566:  567: 
 568: function printNewsAuthor($fullname = false) {
 569:     if (getNewsTitle()) {
 570:         echo html_encode(getNewsAuthor($fullname));
 571:     }
 572: }
 573: 
 574:  575:  576:  577:  578: 
 579: function printCurrentNewsCategory($before = '') {
 580:     global $_zp_current_category;
 581:     if (in_context(ZP_ZENPAGE_NEWS_CATEGORY)) {
 582:         if ($before) {
 583:             echo '<span class="beforetext">' . html_encode($before) . '</span>';
 584:         }
 585:         echo html_encode($_zp_current_category->getTitle());
 586:     }
 587: }
 588: 
 589:  590:  591:  592:  593: 
 594: function getNewsCategoryDesc() {
 595:     global $_zp_current_category;
 596:     if (!is_null($_zp_current_category)) {
 597:         return $_zp_current_category->getDesc();
 598:     }
 599: }
 600: 
 601:  602:  603:  604: 
 605: function printNewsCategoryDesc() {
 606:     echo html_encodeTagged(getNewsCategoryDesc());
 607: }
 608: 
 609:  610:  611:  612:  613: 
 614: function getNewsCategoryCustomData() {
 615:     global $_zp_current_category;
 616:     if (!is_null($_zp_current_category)) {
 617:         return $_zp_current_category->getCustomData();
 618:     }
 619: }
 620: 
 621:  622:  623:  624: 
 625: function printNewsCategoryCustomData() {
 626:     echo getNewsCategoryCustomData();
 627: }
 628: 
 629:  630:  631:  632:  633: 
 634: function getNewsCategories() {
 635:     global $_zp_current_zenpage_news;
 636:     if (!is_null($_zp_current_zenpage_news)) {
 637:         $categories = $_zp_current_zenpage_news->getCategories();
 638:         return $categories;
 639:     }
 640:     return false;
 641: }
 642: 
 643:  644:  645:  646:  647:  648:  649: 
 650: function printNewsCategories($separator = '', $before = '', $class = '') {
 651:     $categories = getNewsCategories();
 652:     $catcount = count($categories);
 653:     if ($catcount != 0) {
 654:         if ($before) {
 655:             echo '<span class="beforetext">' . html_encode($before) . '</span>';
 656:         }
 657:         echo "<ul class=\"$class\">\n";
 658:         $count = 0;
 659:         if ($separator) {
 660:             $separator = '<span class="betweentext">' . html_encode($separator) . '</span>';
 661:         }
 662:         foreach ($categories as $cat) {
 663:             $count++;
 664:             $catobj = new ZenpageCategory($cat['titlelink']);
 665:             if ($count >= $catcount) {
 666:                 $separator = "";
 667:             }
 668:             echo "<li><a href=\"" . $catobj->getLink() . "\" title=\"" . html_encode($catobj->getTitle()) . "\">" . $catobj->getTitle() . '</a>' . $separator . "</li>\n";
 669:         }
 670:         echo "</ul>\n";
 671:     }
 672: }
 673: 
 674:  675:  676:  677:  678: 
 679: function getNewsDate() {
 680:     global $_zp_current_zenpage_news;
 681:     if (!is_null($_zp_current_zenpage_news)) {
 682:         $d = $_zp_current_zenpage_news->getDateTime();
 683:         return zpFormattedDate(DATE_FORMAT, strtotime($d));
 684:     }
 685:     return false;
 686: }
 687: 
 688:  689:  690:  691:  692: 
 693: function printNewsDate() {
 694:     echo html_encode(getNewsDate());
 695: }
 696: 
 697:  698:  699:  700:  701:  702:  703:  704:  705:  706:  707: 
 708: function printNewsArchive($class = 'archive', $yearclass = 'year', $monthclass = 'month', $activeclass = "archive-active", $yearsonly = false, $order = 'desc') {
 709:     global $_zp_zenpage;
 710:     if (!empty($class)) {
 711:         $class = "class=\"$class\"";
 712:     }
 713:     if (!empty($yearclass)) {
 714:         $yearclass = "class=\"$yearclass\"";
 715:     }
 716:     if (!empty($monthclass)) {
 717:         $monthclass = "class=\"$monthclass\"";
 718:     }
 719:     if (!empty($activeclass)) {
 720:         $activeclass = "class=\"$activeclass\"";
 721:     }
 722:     $datecount = $_zp_zenpage->getAllArticleDates($yearsonly, $order);
 723:     $lastyear = "";
 724:     $nr = "";
 725:     echo "\n<ul $class>\n";
 726:     while (list($key, $val) = each($datecount)) {
 727:         $nr++;
 728:         if ($key == '0000-00-01') {
 729:             $year = "no date";
 730:             $month = "";
 731:         } else {
 732:             $dt = strftime('%Y-%B', strtotime($key));
 733:             $year = substr($dt, 0, 4);
 734:             $month = substr($dt, 5);
 735:         }
 736:         if ($lastyear != $year) {
 737:             $lastyear = $year;
 738:             if (!$yearsonly) {
 739:                 if ($nr != 1) {
 740:                     echo "</ul>\n</li>\n";
 741:                 }
 742:                 echo "<li $yearclass>$year\n<ul $monthclass>\n";
 743:             }
 744:         }
 745:         if ($yearsonly) {
 746:             $datetosearch = $key;
 747:         } else {
 748:             $datetosearch = strftime('%Y-%B', strtotime($key));
 749:         }
 750:         if (getCurrentNewsArchive('plain') == $datetosearch) {
 751:             $active = $activeclass;
 752:         } else {
 753:             $active = "";
 754:         }
 755:         if ($yearsonly) {
 756:             echo "<li $active><a href=\"" . html_encode(getNewsArchivePath($key, 1)) . "\" title=\"" . $key . " (" . $val . ")\" rel=\"nofollow\">$key ($val)</a></li>\n";
 757:         } else {
 758:             echo "<li $active><a href=\"" . html_encode(getNewsArchivePath(substr($key, 0, 7), 1)) . "\" title=\"" . $month . " (" . $val . ")\" rel=\"nofollow\">$month ($val)</a></li>\n";
 759:         }
 760:     }
 761:     if ($yearsonly) {
 762:         echo "</ul>\n";
 763:     } else {
 764:         echo "</ul>\n</li>\n</ul>\n";
 765:     }
 766: }
 767: 
 768:  769:  770:  771:  772:  773:  774: 
 775: function getCurrentNewsArchive($mode = 'formatted', $format = '%B %Y') {
 776:     global $_zp_post_date;
 777:     if (in_context(ZP_ZENPAGE_NEWS_DATE)) {
 778:         $archivedate = $_zp_post_date;
 779:         if ($mode == "formatted") {
 780:             $archivedate = strtotime($archivedate);
 781:             $archivedate = strftime($format, $archivedate);
 782:         }
 783:         return $archivedate;
 784:     }
 785:     return false;
 786: }
 787: 
 788:  789:  790:  791:  792:  793:  794:  795: 
 796: function printCurrentNewsArchive($before = '', $mode = 'formatted', $format = '%B %Y') {
 797:     if ($date = getCurrentNewsArchive($mode, $format)) {
 798:         if ($before) {
 799:             echo '<span class="beforetext">' . html_encode($before) . '</span>';
 800:         }
 801:         echo html_encode($date);
 802:     }
 803: }
 804: 
 805:  806:  807:  808:  809:  810:  811:  812:  813:  814:  815:  816:  817:  818:  819:  820:  821:  822:  823: 
 824: function printAllNewsCategories($newsindex = 'All news', $counter = TRUE, $css_id = '', $css_class_topactive = '', $startlist = true, $css_class = '', $css_class_active = '', $option = 'list', $showsubs = false, $limit = NULL) {
 825:     printNestedMenu($option, 'allcategories', $counter, $css_id, $css_class_topactive, $css_class, $css_class_active, $newsindex, $showsubs, $startlist, $limit);
 826: }
 827: 
 828: 
 829:  830: 
 831: 
 832:  833:  834:  835:  836:  837:  838: 
 839: function getNewsCategoryURL($cat = NULL) {
 840:     global $_zp_zenpage, $_zp_current_category;
 841:     if (empty($cat)) {
 842:         $obj = $_zp_current_category->getTitlelink();
 843:     } else {
 844:         $obj = new ZenpageCategory($cat);
 845:     }
 846:     return $obj->getLink(1);
 847: }
 848: 
 849:  850:  851:  852:  853:  854:  855:  856: 
 857: function printNewsCategoryURL($before = '', $catlink = '') {
 858:     $catobj = new ZenpageCategory($catlink);
 859:     echo "<a href=\"" . html_encode($catobj->getLink()) . "\" title=\"" . html_encode($catobj->getTitle()) . "\">";
 860:     if ($before) {
 861:         echo '<span class="beforetext">' . html_encode($before) . '</span>';
 862:     }
 863:     echo html_encode($catobj->getTitle()) . "</a>";
 864: }
 865: 
 866:  867:  868:  869:  870:  871:  872:  873: 
 874: function printNewsIndexURL($name = NULL, $before = '', $archive = NULL, $page = '') {
 875:     global $_zp_post_date;
 876:     if ($_zp_post_date) {
 877:         if (is_null($archive)) {
 878:             $name = '<em>' . gettext('Archive') . '</em>';
 879:         } else {
 880:             $name = getBare(html_encode($archive));
 881:         }
 882:         $link = zp_apply_filter('getLink', rewrite_path(_ARCHIVE_ . '/', "/index.php?p=archive"), 'archive.php', NULL);
 883:     } else {
 884:         if (is_null($name)) {
 885:             $name = gettext('News');
 886:         } else {
 887:             $name = getBare(html_encode($name));
 888:         }
 889:         $link = getNewsIndexURL($page);
 890:     }
 891:     if ($before) {
 892:         echo '<span class="beforetext">' . html_encode($before) . '</span>';
 893:     }
 894:     echo "<a href=\"" . html_encode($link) . "\" title=\"" . getBare($name) . "\">" . $name . "</a>";
 895: }
 896: 
 897:  898:  899:  900:  901: 
 902: function getNewsArchivePath($date, $page) {
 903:     $rewrite = '/' . _NEWS_ARCHIVE_ . '/' . $date . '/';
 904:     $plain = "/index.php?p=news&date=$date";
 905:     if ($page > 1) {
 906:         $rewrite .=  $page . '/';
 907:         $plain .= "&page=$page";
 908:     }
 909:     return zp_apply_filter('getLink', rewrite_path($rewrite, $plain), 'archive.php', $page);
 910: }
 911: 
 912: 
 913:  914: 
 915: 
 916: function getNewsPathNav($page) {
 917:     global $_zp_current_category, $_zp_post_date;
 918:     if (in_context(ZP_ZENPAGE_NEWS_CATEGORY)) {
 919:         return $_zp_current_category->getLink($page);
 920:     }
 921:     if (in_context(ZP_ZENPAGE_NEWS_DATE)) {
 922:         return getNewsArchivePath($_zp_post_date, $page);
 923:     }
 924:     $rewrite = '/' . _NEWS_ . '/';
 925:     $plain = 'index.php?p=news';
 926:     if ($page > 1) {
 927:         $rewrite .= $page . '/';
 928:         $plain .= '&page=' . $page;
 929:     }
 930:     return zp_apply_filter('getLink', rewrite_path($rewrite, $plain), 'news.php', $page);
 931: }
 932: 
 933:  934:  935:  936:  937: 
 938: function getPrevNewsPageURL() {
 939:     global $_zp_page;
 940:     if ($_zp_page > 1) {
 941:         return getNewsPathNav($_zp_page - 1);
 942:     } else {
 943:         return false;
 944:     }
 945: }
 946: 
 947:  948:  949:  950:  951:  952:  953:  954: 
 955: function printPrevNewsPageLink($prev = '« prev', $class = 'disabledlink') {
 956:     global $_zp_zenpage, $_zp_page;
 957:     if ($link = getPrevNewsPageURL()) {
 958:         echo "<a href='" . html_encode($link) . "' title='" . gettext("Prev page") . " " . ($_zp_page - 1) . "' >" . html_encode($prev) . "</a>\n";
 959:     } else {
 960:         echo "<span class=\"$class\">" . html_encode($prev) . "</span>\n";
 961:     }
 962: }
 963: 
 964:  965:  966:  967:  968: 
 969: function getNextNewsPageURL() {
 970:     global $_zp_zenpage, $_zp_page;
 971:     $total_pages = ceil($_zp_zenpage->getTotalArticles() / ZP_ARTICLES_PER_PAGE);
 972:     if ($_zp_page < $total_pages) {
 973:         return getNewsPathNav($_zp_page + 1);
 974:     } else {
 975:         return false;
 976:     }
 977: }
 978: 
 979:  980:  981:  982:  983:  984:  985:  986: 
 987: function printNextNewsPageLink($next = 'next »', $class = 'disabledlink') {
 988:     global $_zp_page;
 989:     if (getNextNewsPageURL()) {
 990:         echo "<a href='" . getNextNewsPageURL() . "' title='" . gettext("Next page") . " " . ($_zp_page + 1) . "'>" . html_encode($next) . "</a>\n";
 991:     } else {
 992:         echo "<span class=\"$class\">" . html_encode($next) . "</span>\n";
 993:     }
 994: }
 995: 
 996:  997:  998:  999: 1000: 1001: 1002: 
1003: function printNewsPageList($class = 'pagelist') {
1004:     printNewsPageListWithNav("", "", false, $class, true);
1005: }
1006: 
1007: 1008: 1009: 1010: 1011: 1012: 1013: 1014: 1015: 1016: 1017: 1018: 
1019: function printNewsPageListWithNav($next, $prev, $nextprev = true, $class = 'pagelist', $firstlast = true, $navlen = 9) {
1020:     global $_zp_zenpage, $_zp_page;
1021:     $total = ceil($_zp_zenpage->getTotalArticles() / ZP_ARTICLES_PER_PAGE);
1022:     if ($total > 1) {
1023:         if ($navlen == 0)
1024:             $navlen = $total;
1025:         $extralinks = 2;
1026:         if ($firstlast)
1027:             $extralinks = $extralinks + 2;
1028:         $len = floor(($navlen - $extralinks) / 2);
1029:         $j = max(round($extralinks / 2), min($_zp_page - $len - (2 - round($extralinks / 2)), $total - $navlen + $extralinks - 1));
1030:         $ilim = min($total, max($navlen - round($extralinks / 2), $_zp_page + floor($len)));
1031:         $k1 = round(($j - 2) / 2) + 1;
1032:         $k2 = $total - round(($total - $ilim) / 2);
1033:         echo "<ul class=\"$class\">\n";
1034:         if ($nextprev) {
1035:             echo "<li class=\"prev\">";
1036:             printPrevNewsPageLink($prev);
1037:             echo "</li>\n";
1038:         }
1039:         if ($firstlast) {
1040:             echo '<li class = "' . ($_zp_page == 1 ? 'current' : 'first') . '">';
1041:             if ($_zp_page == 1) {
1042:                 echo "1";
1043:             } else {
1044:                 echo '<a href = "' . html_encode(getNewsPathNav(1)) . '" title = "' . gettext("Page") . ' 1">1</a>';
1045:             }
1046:             echo "</li>\n";
1047:             if ($j > 2) {
1048:                 echo "<li>";
1049:                 $linktext = ($j - 1 > 2) ? '...' : $k1;
1050:                 echo '<a href = "' . html_encode(getNewsPathNav($k1)) . '" title = "' . sprintf(ngettext('Page %u', 'Page %u', $k1), $k1) . '">' . $linktext . '</a>';
1051:                 echo "</li>\n";
1052:             }
1053:         }
1054:         for ($i = $j; $i <= $ilim; $i++) {
1055:             echo "<li" . (($i == $_zp_page) ? " class=\"current\"" : "") . ">";
1056:             if ($i == $_zp_page) {
1057:                 echo $i;
1058:             } else {
1059:                 echo '<a href = "' . html_encode(getNewsPathNav($i)) . '" title = "' . sprintf(ngettext('Page %1$u', 'Page %1$u', $i), $i) . '">' . $i . '</a>';
1060:             }
1061:             echo "</li>\n";
1062:         }
1063:         if ($i < $total) {
1064:             echo "<li>";
1065:             $linktext = ($total - $i > 1) ? '...' : $k2;
1066:             echo '<a href = "' . html_encode(getNewsPathNav($k2)) . '" title = "' . sprintf(ngettext('Page %u', 'Page %u', $k2), $k2) . '">' . $linktext . '</a>';
1067:             echo "</li>\n";
1068:         }
1069:         if ($firstlast && $i <= $total) {
1070:             echo "\n  <li class=\"last\">";
1071:             if ($_zp_page == $total) {
1072:                 echo $total;
1073:             } else {
1074:                 echo '<a href = "' . html_encode(getNewsPathNav($total)) . '" title = "' . sprintf(ngettext('Page {%u}', 'Page {%u}', $total), $total) . '">' . $total . '</a>';
1075:             }
1076:             echo "</li>\n";
1077:         }
1078:         if ($nextprev) {
1079:             echo '<li class = "next">';
1080:             printNextNewsPageLink($next);
1081:             echo "</li>\n";
1082:         }
1083:         echo "</ul>\n";
1084:     }
1085: }
1086: 
1087: function getTotalNewsPages() {
1088:     global $_zp_zenpage;
1089:     return ceil($_zp_zenpage->getTotalArticles() / ZP_ARTICLES_PER_PAGE);
1090: }
1091: 
1092: 
1093: 1094: 
1095: 
1096: 1097: 1098: 1099: 1100: 1101: 1102: 1103: 1104: 1105: 
1106: function getNextPrevNews($option = '') {
1107:     global $_zp_zenpage, $_zp_current_zenpage_news;
1108:  if (func_num_args() != 1) {
1109:    Zenpage_internal_deprecations::getNextPrevNews();
1110:  }
1111:     if (!empty($option)) {
1112:         switch ($option) {
1113:             case "prev":
1114:                 $article = $_zp_current_zenpage_news->getPrevArticle();
1115:                 if (!$article)
1116:                     return false;
1117:                 return array("link" => $article->getLink(), "title" => $article->getTitle());
1118:             case "next":
1119:                 $article = $_zp_current_zenpage_news->getNextArticle();
1120:                 if (!$article)
1121:                     return false;
1122:                 return array("link" => $article->getLink(), "title" => $article->getTitle());
1123:         }
1124:     }
1125:     return false;
1126: }
1127: 
1128: 1129: 1130: 1131: 1132: 1133: 1134: 1135: 
1136: function getNextNewsURL() {
1137:     return getNextPrevNews("next");
1138: }
1139: 
1140: 1141: 1142: 1143: 1144: 1145: 1146: 1147: 
1148: function getPrevNewsURL() {
1149:     return getNextPrevNews("prev");
1150: }
1151: 
1152: 1153: 1154: 1155: 1156: 1157: 1158: 1159: 
1160: function printNextNewsLink($next = " »") {
1161:     $article_url = getNextPrevNews("next");
1162:     if ($article_url && array_key_exists('link', $article_url) && $article_url['link'] != "") {
1163:         echo "<a href=\"" . html_encode($article_url['link']) . "\" title=\"" . html_encode(getBare($article_url['title'])) . "\">" . $article_url['title'] . "</a> " . html_encode($next);
1164:     }
1165: }
1166: 
1167: 1168: 1169: 1170: 1171: 1172: 1173: 1174: 
1175: function printPrevNewsLink($prev = "« ") {
1176:     $article_url = getNextPrevNews("prev");
1177:     if ($article_url && array_key_exists('link', $article_url) && $article_url['link'] != "") {
1178:         echo html_encode($prev) . " <a href=\"" . html_encode($article_url['link']) . "\" title=\"" . html_encode(getBare($article_url['title'])) . "\">" . $article_url['title'] . "</a>";
1179:     }
1180: }
1181: 
1182: 
1183: 1184: 
1185: 
1186: 1187: 1188: 1189: 1190: 1191: 1192: 1193: 1194: 1195: 1196: 1197: 1198: 1199: 1200: 
1201: function getZenpageStatistic($number = 10, $option = "all", $mode = "popular", $sortdirection = 'desc') {
1202:     global $_zp_zenpage, $_zp_current_zenpage_news, $_zp_current_zenpage_pages;
1203:     $sortdir = strtolower($sortdirection) != 'asc';
1204:     $statsarticles = array();
1205:     $statscats = array();
1206:     $statspages = array();
1207:     if ($option == "all" || $option == "news") {
1208:         $articles = $_zp_zenpage->getArticles($number, NULL, true, $mode, $sortdir, false);
1209:         $counter = "";
1210:         $statsarticles = array();
1211:         foreach ($articles as $article) {
1212:             $counter++;
1213:             $obj = new ZenpageNews($article['titlelink']);
1214:             $statsarticles[$counter] = array(
1215:                             "id"                     => $obj->getID(),
1216:                             "title"              => $obj->getTitle(),
1217:                             "titlelink"      => $article['titlelink'],
1218:                             "hitcounter"     => $obj->getHitcounter(),
1219:                             "total_votes"    => $obj->getTotal_votes(),
1220:                             "rating"             => $obj->getRating(),
1221:                             "content"            => $obj->getContent(),
1222:                             "date"               => $obj->getDateTime(),
1223:                             "type"               => "News"
1224:             );
1225:         }
1226:         $stats = $statsarticles;
1227:     }
1228:     if (($option == "all" || $option == "categories") && $mode != "mostrated" && $mode != "toprated") {
1229:         $categories = $_zp_zenpage->getAllCategories(true, $mode, $sortdir);
1230:         $counter = "";
1231:         $statscats = array();
1232:         foreach ($categories as $cat) {
1233:             $counter++;
1234:             $statscats[$counter] = array(
1235:                             "id"                     => $cat['id'],
1236:                             "title"              => html_encode(get_language_string($cat['title'])),
1237:                             "titlelink"      => getNewsCategoryURL($cat['titlelink']),
1238:                             "hitcounter"     => $cat['hitcounter'],
1239:                             "total_votes"    => "",
1240:                             "rating"             => "",
1241:                             "content"            => '',
1242:                             "date"               => '',
1243:                             "type"               => "Category"
1244:             );
1245:         }
1246:         $stats = $statscats;
1247:     }
1248:     if ($option == "all" || $option == "pages") {
1249:         $pages = $_zp_zenpage->getPages(NULL, false, $number, $mode, $sortdir);
1250:         $counter = "";
1251:         $statspages = array();
1252:         foreach ($pages as $page) {
1253:             $counter++;
1254:             $pageobj = new ZenpagePage($page['titlelink']);
1255:             $statspages[$counter] = array(
1256:                             "id"                     => $pageobj->getID(),
1257:                             "title"              => $pageobj->getTitle(),
1258:                             "titlelink"      => $page['titlelink'],
1259:                             "hitcounter"     => $pageobj->getHitcounter(),
1260:                             "total_votes"    => $pageobj->get('total_votes'),
1261:                             "rating"             => $pageobj->get('rating'),
1262:                             "content"            => $pageobj->getContent(),
1263:                             "date"               => $pageobj->getDateTime(),
1264:                             "type"               => "Page"
1265:             );
1266:         }
1267:         $stats = $statspages;
1268:     }
1269:     if ($option == "all") {
1270:         $stats = array_merge($statsarticles, $statscats, $statspages);
1271:         if ($mode == 'random') {
1272:             shuffle($stats);
1273:         } else {
1274:             switch ($sortdir) {
1275:                 case 'asc':
1276:                     $desc = false;
1277:                     break;
1278:                 case 'desc':
1279:                     $desc = true;
1280:                     break;
1281:             }
1282:             $stats = sortMultiArray($stats, $mode, $desc);
1283:         }
1284:     }
1285:     return $stats;
1286: }
1287: 
1288: 1289: 1290: 1291: 1292: 1293: 1294: 1295: 1296: 1297: 1298: 1299: 1300: 1301: 1302: 1303: 1304: 1305: 
1306: function printZenpageStatistic($number = 10, $option = "all", $mode = "popular", $showstats = true, $showtype = true, $showdate = true, $showcontent = true, $contentlength = 40, $sortdir = 'desc') {
1307:     $stats = getZenpageStatistic($number, $option, $mode);
1308:     $contentlength = sanitize_numeric($contentlength);
1309:     switch ($mode) {
1310:         case 'popular':
1311:             $cssid = "'zenpagemostpopular'";
1312:             break;
1313:         case 'mostrated':
1314:             $cssid = "'zenpagemostrated'";
1315:             break;
1316:         case 'toprated':
1317:             $cssid = "'zenpagetoprated'";
1318:             break;
1319:         case 'random':
1320:             $cssid = "'zenpagerandom'";
1321:             break;
1322:     }
1323:     echo "<ul id=$cssid>";
1324:     foreach ($stats as $item) {
1325:         switch ($mode) {
1326:             case 'popular':
1327:                 $statsvalue = $item['hitcounter'];
1328:                 break;
1329:             case 'mostrated':
1330:                 $statsvalue = $item['total_votes'];
1331:                 break;
1332:             case 'toprated':
1333:                 $statsvalue = $item['rating'];
1334:                 break;
1335:         }
1336:         switch ($item['type']) {
1337:             case 'Page':
1338:                 $titlelink = html_encode(getPageURL($item['titlelink']));
1339:             case 'News':
1340:                 $titlelink = html_encode(getNewsURL($item['titlelink']));
1341:                 break;
1342:             case 'Category':
1343:                 $titlelink = html_encode(getNewsCategoryURL($item['titlelink']));
1344:                 break;
1345:         }
1346:         echo '<li><a href = "' . $titlelink . '" title = "' . html_encode(getBare($item['title'])) . '"><h3>' . $item['title'];
1347:         echo '<small>';
1348:         if ($showtype) {
1349:             echo ' [' . $item['type'] . ']';
1350:         }
1351:         if ($showstats && ($item['type'] != 'Category' && $mode != 'mostrated' && $mode != 'toprated')) {
1352:             echo ' (' . $statsvalue . ')';
1353:         }
1354:         echo '</small>';
1355:         echo '</h3></a>';
1356:         if ($showdate && $item['type'] != 'Category') {
1357:             echo "<p>" . zpFormattedDate(DATE_FORMAT, strtotime($item['date'])) . "</p>";
1358:         }
1359:         if ($showcontent && $item['type'] != 'Category') {
1360:             echo '<p>' . truncate_string($item['content'], $contentlength) . '</p>';
1361:         }
1362:         echo '</li>';
1363:     }
1364:     echo '</ul>';
1365: }
1366: 
1367: 1368: 1369: 1370: 1371: 1372: 1373: 1374: 1375: 1376: 1377: 1378: 1379: 
1380: function printMostPopularItems($number = 10, $option = "all", $showstats = true, $showtype = true, $showdate = true, $showcontent = true, $contentlength = 40) {
1381:     printZenpageStatistic($number, $option, "popular", $showstats, $showtype, $showdate, $showcontent, $contentlength);
1382: }
1383: 
1384: 1385: 1386: 1387: 1388: 1389: 1390: 1391: 1392: 1393: 1394: 1395: 1396: 
1397: function printMostRatedItems($number = 10, $option = "all", $showstats = true, $showtype = true, $showdate = true, $showcontent = true, $contentlength = 40) {
1398:     printZenpageStatistic($number, $option, "mostrated", $showstats, $showtype, $showdate, $showcontent, $contentlength);
1399: }
1400: 
1401: 1402: 1403: 1404: 1405: 1406: 1407: 1408: 1409: 1410: 1411: 1412: 1413: 
1414: function printTopRatedItems($number = 10, $option = "all", $showstats = true, $showtype = true, $showdate = true, $showcontent = true, $contentlength = 40) {
1415:     printZenpageStatistic($number, $option, "toprated", $showstats, $showtype, $showdate, $showcontent, $contentlength);
1416: }
1417: 
1418: 1419: 1420: 1421: 1422: 1423: 1424: 1425: 1426: 1427: 1428: 1429: 1430: 1431: 1432: 1433: 1434: 1435: 1436: 1437: 
1438: function printNestedMenu($option = 'list', $mode = NULL, $counter = TRUE, $css_id = NULL, $css_class_topactive = NULL, $css_class = NULL, $css_class_active = NULL, $indexname = NULL, $showsubs = 0, $startlist = true, $limit = NULL) {
1439:     global $_zp_zenpage, $_zp_gallery_page, $_zp_current_zenpage_news, $_zp_current_zenpage_page, $_zp_current_category;
1440:     if (is_null($limit)) {
1441:         $limit = MENU_TRUNCATE_STRING;
1442:     }
1443:     if (is_null($css_id)) {
1444:         switch ($mode) {
1445:             case 'pages':
1446:                 $css_id = 'menu_pages';
1447:                 break;
1448:             case 'categories':
1449:             case 'allcategories':
1450:                 $css_id = 'menu_categories';
1451:                 break;
1452:         }
1453:     }
1454:     if (is_null($css_class_topactive)) {
1455:         $css_class_topactive = 'menu_topactive';
1456:     }
1457:     if (is_null($css_class)) {
1458:         $css_class = 'submenu';
1459:     }
1460:     if (is_null($css_class_active)) {
1461:         $css_class_active = 'menu-active';
1462:     }
1463:     if ($showsubs === true)
1464:         $showsubs = 9999999999;
1465:     switch ($mode) {
1466:         case 'pages':
1467:             $items = $_zp_zenpage->getPages();
1468:             $currentitem_id = getPageID();
1469:             if (is_object($_zp_current_zenpage_page)) {
1470:                 $currentitem_parentid = $_zp_current_zenpage_page->getParentID();
1471:             } else {
1472:                 $currentitem_parentid = NULL;
1473:             }
1474:             $currentitem_sortorder = getPageSortorder();
1475:             break;
1476:         case 'categories':
1477:         case 'allcategories':
1478:             $items = $_zp_zenpage->getAllCategories();
1479:             if (is_object($_zp_current_category) && $mode == 'categories') {
1480:                 $currentitem_sortorder = $_zp_current_category->getSortOrder();
1481:                 $currentitem_id = $_zp_current_category->getID();
1482:                 $currentitem_parentid = $_zp_current_category->getParentID();
1483:             } else {
1484:                 $currentitem_sortorder = NULL;
1485:                 $currentitem_id = NULL;
1486:                 $currentitem_parentid = NULL;
1487:             }
1488:             break;
1489:     }
1490: 
1491:     
1492:     if (in_context(ZP_SEARCH) && $mode == 'pages') { 
1493:         $css_class_topactive = "";
1494:         $css_class_active = "";
1495:         rem_context(ZP_ZENPAGE_PAGE);
1496:     }
1497:     if (0 == count($items) + (int) ($mode == 'allcategories'))
1498:         return; 
1499:     $startlist = $startlist && !($option == 'omit-top' || $option == 'list-sub');
1500:     if ($startlist)
1501:         echo '<ul id="' . $css_id . '">';
1502:     
1503:     if (!empty($indexname)) {
1504:         if ($limit) {
1505:             $display = shortenContent($indexname, $limit, MENU_TRUNCATE_INDICATOR);
1506:         } else {
1507:             $display = $indexname;
1508:         }
1509:         switch ($mode) {
1510:             case 'pages':
1511:                 if ($_zp_gallery_page == "index.php") {
1512:                     echo '<li class="' . $css_class_topactive . '">' . html_encode($display) . '</li>';
1513:                 } else {
1514:                     echo "<li><a href='" . html_encode(getGalleryIndexURL()) . "' title='" . html_encode($indexname) . "'>" . html_encode($display) . "</a></li>";
1515:                 }
1516:                 break;
1517:             case 'categories':
1518:             case 'allcategories':
1519:                 if (($_zp_gallery_page == "news.php") && !is_NewsCategory() && !is_NewsArchive() && !is_NewsArticle()) {
1520:                     echo '<li class="' . $css_class_topactive . '">' . html_encode($display);
1521:                 } else {
1522:                     echo "<li><a href=\"" . html_encode(getNewsIndexURL()) . "\" title=\"" . html_encode($indexname) . "\">" . html_encode($display) . "</a>";
1523:                 }
1524:                 if ($counter) {
1525:                     if (in_context(ZP_ZENPAGE_NEWS_CATEGORY) && $mode == 'categories') {
1526:                         $totalcount = count($_zp_current_category->getArticles(0));
1527:                     } else {
1528:                         save_context();
1529:                         rem_context(ZP_ZENPAGE_NEWS_DATE);
1530:                         $totalcount = count($_zp_zenpage->getArticles(0));
1531:                         restore_context();
1532:                     }
1533:                     echo ' <span style="white-space:nowrap;"><small>(' . sprintf(ngettext('%u article', '%u articles', $totalcount), $totalcount) . ')</small></span>';
1534:                 }
1535:                 echo "</li>\n";
1536:                 break;
1537:         }
1538:     }
1539:     $baseindent = max(1, count(explode("-", $currentitem_sortorder)));
1540:     $indent = 1;
1541:     $open = array($indent => 0);
1542:     $parents = array(NULL);
1543:     $order = explode('-', $currentitem_sortorder);
1544:     $mylevel = count($order);
1545:     $myparentsort = array_shift($order);
1546:     for ($c = 0; $c <= $mylevel; $c++) {
1547:         $parents[$c] = NULL;
1548:     }
1549:     foreach ($items as $item) {
1550:         $password_class = '';
1551:         switch ($mode) {
1552:             case 'pages':
1553:                 $catcount = 1; 
1554:                 $pageobj = new ZenpagePage($item['titlelink']);
1555:                 $itemtitle = $pageobj->getTitle();
1556:                 $itemsortorder = $pageobj->getSortOrder();
1557:                 $itemid = $pageobj->getID();
1558:                 $itemparentid = $pageobj->getParentID();
1559:                 $itemtitlelink = $pageobj->getTitlelink();
1560:                 $itemurl = $pageobj->getLink();
1561:                 $count = '';
1562:                 if ($pageobj->isProtected()) {
1563:                     $password_class = ' has_password';
1564:                 }
1565:                 break;
1566:             case 'categories':
1567:             case 'allcategories':
1568:                 $catobj = new ZenpageCategory($item['titlelink']);
1569:                 $itemtitle = $catobj->getTitle();
1570:                 $itemsortorder = $catobj->getSortOrder();
1571:                 $itemid = $catobj->getID();
1572:                 $itemparentid = $catobj->getParentID();
1573:                 $itemtitlelink = $catobj->getTitlelink();
1574:                 $itemurl = $catobj->getLink();
1575:                 $catcount = count($catobj->getArticles());
1576:                 if ($counter) {
1577:                     $count = ' <span style="white-space:nowrap;"><small>(' . sprintf(ngettext('%u article', '%u articles', $catcount), $catcount) . ')</small></span>';
1578:                 } else {
1579:                     $count = '';
1580:                 }
1581:                 if ($catobj->isProtected()) {
1582:                     $password_class = ' has_password';
1583:                 }
1584:                 break;
1585:         }
1586:         if ($catcount) {
1587:             $level = max(1, count(explode('-', $itemsortorder)));
1588:             $process = (($level <= $showsubs && $option == "list") 
1589:                             || ($option == 'list' || $option == 'list-top') && $level == 1 
1590:                             || (($option == 'list' || ($option == 'omit-top' && $level > 1)) && (($itemid == $currentitem_id) 
1591:                             || ($itemparentid == $currentitem_id) 
1592:                             || ($level < $mylevel && $level > 1 && (strpos($itemsortorder, $myparentsort) === 0) )
1593:                             || (($level == $mylevel) && ($currentitem_parentid == $itemparentid)) 
1594:                             )
1595:                             ) || ($option == 'list-sub' && ($itemparentid == $currentitem_id) 
1596:                             )
1597:                             );
1598: 
1599:             if ($process) {
1600:                 if ($level > $indent) {
1601:                     echo "\n" . str_pad("\t", $indent, "\t") . '<ul class="' . $css_class . '">'."\n";
1602:                     $indent++;
1603:                     $parents[$indent] = NULL;
1604:                     $open[$indent] = 0;
1605:                 } else if ($level < $indent) {
1606:                     $parents[$indent] = NULL;
1607:                     while ($indent > $level) {
1608:                         if ($open[$indent]) {
1609:                             $open[$indent] --;
1610:                             echo "</li>\n";
1611:                         }
1612:                         $indent--;
1613:                         echo str_pad("\t", $indent, "\t") . "</ul>\n";
1614:                     }
1615:                 } else { 
1616:                     if ($open[$indent]) { 
1617:                         echo str_pad("\t", $indent, "\t") . "</li>\n";
1618:                         $open[$indent] --;
1619:                     } else {
1620:                         echo "\n";
1621:                     }
1622:                 }
1623:                 if ($open[$indent]) { 
1624:                     echo "</li>\n";
1625:                     $open[$indent] --;
1626:                 }
1627:                 echo str_pad("\t", $indent - 1, "\t");
1628:                 $open[$indent] ++;
1629:                 $parents[$indent] = $itemid;
1630:                 if ($level == 1) { 
1631:                     $class = $css_class_topactive . $password_class;
1632:                 } else {
1633:                     $class = $css_class_active . $password_class;
1634:                 }
1635:                 if (!is_null($_zp_current_zenpage_page)) {
1636:                     $gettitle = $_zp_current_zenpage_page->getTitle();
1637:                     $getname = $_zp_current_zenpage_page->getTitlelink();
1638:                 } else if (!is_null($_zp_current_category)) {
1639:                     $gettitle = $_zp_current_category->getTitle();
1640:                     $getname = $_zp_current_category->getTitlelink();
1641:                 } else {
1642:                     $gettitle = '';
1643:                     $getname = '';
1644:                 }
1645:                 $current = "";
1646:                 if ($itemtitlelink == $getname && !in_context(ZP_SEARCH)) {
1647:                     switch ($mode) {
1648:                         case 'pages':
1649:                             if ($_zp_gallery_page == 'pages.php') {
1650:                                 $current = $class;
1651:                             }
1652:                             break;
1653:                         case 'categories':
1654:                         case 'allcategories':
1655:                             if ($_zp_gallery_page == 'news.php') {
1656:                                 $current = $class;
1657:                             }
1658:                             break;
1659:                     }
1660:                 }
1661:                 if(empty($current)) {
1662:                     $current =  trim($password_class);
1663:                 }
1664:                 if ($limit) {
1665:                     $itemtitle = shortenContent($itemtitle, $limit, MENU_TRUNCATE_INDICATOR);
1666:                 }
1667:                 echo '<li><a class="' . $current. '" href="' . html_encode($itemurl) . '" title="' . html_encode(getBare($itemtitle)) . '">' . html_encode($itemtitle) . '</a>' . $count;
1668:             }
1669:         }
1670:     }
1671:     
1672:     while ($indent > 1) {
1673:         if ($open[$indent]) {
1674:             echo "</li>\n";
1675:             $open[$indent] --;
1676:         }
1677:         $indent--;
1678:         echo str_pad("\t", $indent, "\t") . "</ul>";
1679:     }
1680:     if ($open[$indent]) {
1681:         echo "</li>\n";
1682:         $open[$indent] --;
1683:     } else {
1684:         echo "\n";
1685:     }
1686:     if ($startlist)
1687:         echo "</ul>\n";
1688: }
1689: 
1690: 1691: 1692: 1693: 1694: 1695: 
1696: function printZenpageItemsBreadcrumb($before = NULL, $after = NULL) {
1697:     global $_zp_current_zenpage_page, $_zp_current_zenpage_news, $_zp_current_category;
1698:     if (is_NewsPage()) {
1699:         $page = '';
1700:         if (is_NewsArticle()) {
1701:             $page = $_zp_current_zenpage_news->getNewsLoopPage();
1702:         }
1703:         printNewsIndexURL(NULL, '', '', $page);
1704:     }
1705:     if (is_Pages() || is_NewsCategory()) {
1706:         $parentitems = array();
1707:         if (is_Pages()) {
1708:             $parentitems = $_zp_current_zenpage_page->getParents();
1709:         }
1710:         if (is_NewsCategory()) {
1711:             $parentitems = $_zp_current_category->getParents();
1712:         }
1713:         foreach ($parentitems as $item) {
1714:             if (is_Pages()) {
1715:                 $pageobj = new ZenpagePage($item);
1716:                 $parentitemurl = html_encode($pageobj->getLink());
1717:                 $parentitemtitle = $pageobj->getTitle();
1718:             }
1719:             if (is_NewsCategory()) {
1720:                 $catobj = new ZenpageCategory($item);
1721:                 $parentitemurl = $catobj->getLink();
1722:                 $parentitemtitle = $catobj->getTitle();
1723:             }
1724:             if ($before) {
1725:                 echo '<span class="beforetext">' . html_encode($before) . '</span>';
1726:             }
1727:             echo"<a href='" . $parentitemurl . "'>" . html_encode($parentitemtitle) . "</a>";
1728:             if ($after) {
1729:                 echo '<span class="aftertext">' . html_encode($after) . '</span>';
1730:             }
1731:         }
1732:     }
1733: }
1734: 
1735: 
1736: 1737: 
1738: $_zp_zenpage_pagelist = NULL;
1739: 
1740: 1741: 1742: 1743: 1744: 1745: 1746: 1747: 1748: 1749: 1750: 
1751: function getNumPages($total = false) {
1752:     global $_zp_zenpage, $_zp_zenpage_pagelist, $_zp_current_search, $_zp_current_zenpage_page;
1753:     $addquery = '';
1754:     if (!$total) {
1755:         if (in_context(ZP_SEARCH)) {
1756:             $_zp_zenpage_pagelist = $_zp_current_search->getPages();
1757:             return count($_zp_zenpage_pagelist);
1758:         } else if (in_context(ZP_ZENPAGE_PAGE)) {
1759:             if (!zp_loggedin(ADMIN_RIGHTS | ZENPAGE_PAGES_RIGHTS)) {
1760:                 $addquery = ' AND `show` = 1';
1761:             }
1762:             return db_count('pages', 'WHERE parentid=' . $_zp_current_zenpage_page->getID() . $addquery);
1763:         }
1764:     }
1765:     if (!zp_loggedin(ADMIN_RIGHTS | ZENPAGE_PAGES_RIGHTS)) {
1766:         $addquery = ' WHERE `show` = 1';
1767:     }
1768:     return db_count('pages', $addquery);
1769: }
1770: 
1771: 1772: 1773: 1774: 1775: 
1776: function next_page() {
1777:     global $_zp_zenpage, $_zp_next_pagelist, $_zp_current_search, $_zp_current_zenpage_page, $_zp_current_page_restore;
1778:     if (func_num_args() != 0) {
1779:         
1780:         Zenpage_internal_deprecations::next_page();
1781:     }
1782: 
1783:     if (is_null($_zp_next_pagelist)) {
1784:         if (in_context(ZP_SEARCH)) {
1785:             $_zp_next_pagelist = $_zp_current_search->getPages(NULL, false, NULL, NULL, NULL);
1786:         } else if (in_context(ZP_ZENPAGE_PAGE)) {
1787:             if (!is_null($_zp_current_zenpage_page)) {
1788:                 $_zp_next_pagelist = $_zp_current_zenpage_page->getPages(NULL, false, NULL, NULL, NULL);
1789:             }
1790:         } else {
1791:             $_zp_next_pagelist = $_zp_zenpage->getPages(NULL, true, NULL, NULL, NULL);
1792:         }
1793:         save_context();
1794:         add_context(ZP_ZENPAGE_PAGE);
1795:         $_zp_current_page_restore = $_zp_current_zenpage_page;
1796:     }
1797:     while (!empty($_zp_next_pagelist)) {
1798:         $page = new ZenpagePage(array_shift($_zp_next_pagelist));
1799:         if ((zp_loggedin() && $page->isMyItem(LIST_RIGHTS)) || $page->checkForGuest()) {
1800:             $_zp_current_zenpage_page = $page;
1801:             return true;
1802:         }
1803:     }
1804:     $_zp_next_pagelist = NULL;
1805:     $_zp_current_zenpage_page = $_zp_current_page_restore;
1806:     restore_context();
1807:     return false;
1808: }
1809: 
1810: 1811: 1812: 1813: 1814: 
1815: function getPageTitle() {
1816:     global $_zp_current_zenpage_page;
1817:     if (!is_null($_zp_current_zenpage_page)) {
1818:         return $_zp_current_zenpage_page->getTitle();
1819:     }
1820: }
1821: 
1822: 1823: 1824: 1825: 1826: 
1827: function printPageTitle($before = NULL) {
1828:     echo html_encodeTagged($before) . html_encode(getPageTitle());
1829: }
1830: 
1831: 1832: 1833: 1834: 1835: 
1836: function getBarePageTitle() {
1837:     return getBare(getPageTitle());
1838: }
1839: 
1840: 1841: 1842: 1843: 1844: 
1845: function printBarePageTitle() {
1846:     echo html_encode(getBarePageTitle());
1847: }
1848: 
1849: 1850: 1851: 1852: 1853: 
1854: function getPageTitleLink() {
1855:     global $_zp_current_zenpage_page;
1856:     if (is_Pages()) {
1857:         return $_zp_current_zenpage_page->getTitlelink();
1858:     }
1859: }
1860: 
1861: 1862: 1863: 1864: 1865: 1866: 
1867: function printPageTitleLink() {
1868:     global $_zp_current_zenpage_page;
1869:     echo html_encode(getPageURL(getPageTitleLink()));
1870: }
1871: 
1872: 1873: 1874: 1875: 1876: 
1877: function getPageID() {
1878:     global $_zp_current_zenpage_page;
1879:     if (is_Pages()) {
1880:         return $_zp_current_zenpage_page->getID();
1881:     }
1882: }
1883: 
1884: 1885: 1886: 1887: 1888: 
1889: function printPageID() {
1890:     echo getPageID();
1891: }
1892: 
1893: 1894: 1895: 1896: 1897: 
1898: function getPageParentID() {
1899:     global $_zp_current_zenpage_page;
1900:     if (is_Pages()) {
1901:         return $_zp_current_zenpage_page->getParentid();
1902:     }
1903: }
1904: 
1905: 1906: 1907: 1908: 1909: 
1910: function getPageDate() {
1911:     global $_zp_current_zenpage_page;
1912:     if (!is_null($_zp_current_zenpage_page)) {
1913:         $d = $_zp_current_zenpage_page->getDatetime();
1914:         return zpFormattedDate(DATE_FORMAT, strtotime($d));
1915:     }
1916:     return false;
1917: }
1918: 
1919: 1920: 1921: 1922: 1923: 
1924: function printPageDate() {
1925:     echo html_encode(getPageDate());
1926: }
1927: 
1928: 1929: 1930: 1931: 1932: 
1933: function getPageLastChangeDate() {
1934:     global $_zp_current_zenpage_page;
1935:     if (!is_null($_zp_current_zenpage_page)) {
1936:         $d = $_zp_current_zenpage_page->getLastchange();
1937:         return zpFormattedDate(DATE_FORMAT, strtotime($d));
1938:     }
1939:     return false;
1940: }
1941: 
1942: 1943: 1944: 1945: 1946: 1947: 
1948: function printPageLastChangeDate($before) {
1949:     echo html_encode($before . getPageLastChangeDate());
1950: }
1951: 
1952: 1953: 1954: 1955: 1956: 1957: 1958: 1959: 1960: 
1961: function getPageContent($titlelink = NULL, $published = true) {
1962:     global $_zp_current_zenpage_page;
1963:     if (is_Pages() AND empty($titlelink)) {
1964:         return $_zp_current_zenpage_page->getContent();
1965:     }
1966:     
1967:     if (!empty($titlelink)) {
1968:         $page = new ZenpagePage($titlelink);
1969:         if ($page->getShow() OR ( !$page->getShow() AND ! $published)) {
1970:             return $page->getContent();
1971:         }
1972:     }
1973:     return false;
1974: }
1975: 
1976: 1977: 1978: 1979: 1980: 1981: 1982: 1983: 
1984: function printPageContent($titlelink = NULL, $published = true) {
1985:     echo html_encodeTagged(getPageContent($titlelink, $published));
1986: }
1987: 
1988: 1989: 1990: 1991: 1992: 1993: 1994: 1995: 
1996: function getPageExtraContent($titlelink = '', $published = true) {
1997:     global $_zp_current_zenpage_page;
1998:     if (is_Pages() AND empty($titlelink)) {
1999:         return $_zp_current_zenpage_page->getExtracontent();
2000:     }
2001:     
2002:     if (!empty($titlelink)) {
2003:         $page = new ZenpagePage($titlelink);
2004:         if ($page->getShow() OR ( !$page->getShow() AND ! $published)) {
2005:             return $page->getExtracontent();
2006:         }
2007:     }
2008:     return false;
2009: }
2010: 
2011: 2012: 2013: 2014: 2015: 2016: 2017: 2018: 
2019: function printPageExtraContent($titlelink = NULL, $published = true) {
2020:     echo getPageExtraContent($titlelink, $published);
2021: }
2022: 
2023: 2024: 2025: 2026: 2027: 
2028: function getPageCustomData() {
2029:     global $_zp_current_zenpage_page;
2030:     if (!is_null($_zp_current_zenpage_page)) {
2031:         return $_zp_current_zenpage_page->getCustomData();
2032:     }
2033: }
2034: 
2035: 2036: 2037: 2038: 
2039: function printPageCustomData() {
2040:     echo getPageCustomData();
2041: }
2042: 
2043: 2044: 2045: 2046: 2047: 2048: 2049: 
2050: function getPageAuthor($fullname = false) {
2051:     if (is_Pages()) {
2052:         return getAuthor($fullname);
2053:     }
2054:     return false;
2055: }
2056: 
2057: 2058: 2059: 2060: 2061: 2062: 
2063: function printPageAuthor($fullname = false) {
2064:     if (getNewsTitle()) {
2065:         echo html_encode(getPageAuthor($fullname));
2066:     }
2067: }
2068: 
2069: 2070: 2071: 2072: 2073: 
2074: function getPageSortorder() {
2075:     global $_zp_current_zenpage_page;
2076:     if (is_Pages()) {
2077:         return $_zp_current_zenpage_page->getSortOrder();
2078:     }
2079:     return false;
2080: }
2081: 
2082: 2083: 2084: 2085: 2086: 
2087: function getPageURL($titlelink = '') {
2088:     global $_zp_zenpage, $_zp_current_zenpage_page;
2089:     if (empty($titlelink)) {
2090:         $obj = $_zp_current_zenpage_page;
2091:     } else {
2092:         $obj = new ZenpagePage($titlelink);
2093:     }
2094:     return $obj->getLink();
2095: }
2096: 
2097: 2098: 2099: 2100: 2101: 2102: 2103: 2104: 2105: 
2106: function printPageURL($linktext = NULL, $titlelink = NULL, $prev = '', $next = '', $class = NULL) {
2107:     if (!is_null($class)) {
2108:         $class = 'class="' . $class . '"';
2109:     }
2110:     if (is_null($linktext)) {
2111:         $linktext = getPageTitle();
2112:     }
2113:     echo $prev . "<a href=\"" . html_encode(getPageURL($titlelink)) . "\" $class title=\"" . html_encode($linktext) . "\">" . html_encode($linktext) . "</a>" . $next;
2114: }
2115: 
2116: 2117: 2118: 2119: 2120: 2121: 2122: 2123: 2124: 2125: 2126: 2127: 2128: 
2129: function printSubPagesExcerpts($excerptlength = NULL, $readmore = NULL, $shortenindicator = NULL) {
2130:     global $_zp_current_zenpage_page;
2131:     if (is_null($readmore)) {
2132:         $readmore = get_language_string(ZP_READ_MORE);
2133:     }
2134:     $pages = $_zp_current_zenpage_page->getPages();
2135:     $subcount = 0;
2136:     if (is_null($excerptlength)) {
2137:         $excerptlength = ZP_SHORTEN_LENGTH;
2138:     }
2139:     foreach ($pages as $page) {
2140:         $pageobj = new ZenpagePage($page['titlelink']);
2141:         if ($pageobj->getParentID() == $_zp_current_zenpage_page->getID()) {
2142:             $subcount++;
2143:             $pagetitle = html_encode($pageobj->getTitle());
2144:             $pagecontent = $pageobj->getContent();
2145:             if ($pageobj->checkAccess()) {
2146:                 $pagecontent = getContentShorten($pagecontent, $excerptlength, $shortenindicator, $readmore, $pageobj->getLink());
2147:             } else {
2148:                 $pagecontent = '<p><em>' . gettext('This page is password protected') . '</em></p>';
2149:             }
2150:             echo '<div class="pageexcerpt">';
2151:             echo '<h4><a href="' . html_encode($pageobj->getLink()) . '" title="' . getBare($pagetitle) . '">' . $pagetitle . '</a></h4>';
2152:             echo $pagecontent;
2153:             echo '</div>';
2154:         }
2155:     }
2156: }
2157: 
2158: 2159: 2160: 2161: 2162: 2163: 2164: 2165: 2166: 2167: 2168: 2169: 2170: 2171: 2172: 2173: 2174: 2175: 
2176: function printPageMenu($option = 'list', $css_id = NULL, $css_class_topactive = NULL, $css_class = NULL, $css_class_active = NULL, $indexname = NULL, $showsubs = 0, $startlist = true, $limit = NULL) {
2177:     printNestedMenu($option, 'pages', false, $css_id, $css_class_topactive, $css_class, $css_class_active, $indexname, $showsubs, $startlist, $limit);
2178: }
2179: 
2180: 2181: 2182: 2183: 2184: 2185: 2186: 2187: 
2188: function checkForPage($titlelink) {
2189:     if (!empty($titlelink)) {
2190:         load_zenpage_pages($titlelink);
2191:         return in_context(ZP_ZENPAGE_PAGE);
2192:     }
2193:     return false;
2194: }
2195: 
2196: 
2197: 2198: 
2199: 
2200: 2201: 2202: 2203: 2204: 2205: 2206: 2207: 2208: 
2209: function getLatestZenpageComments($number, $type = "all", $itemID = "") {
2210:     $itemID = sanitize_numeric($itemID);
2211:     $number = sanitize_numeric($number);
2212:     $checkauth = zp_loggedin();
2213: 
2214:     if ($type == 'all' || $type == 'news') {
2215:         $newspasswordcheck = "";
2216:         if (zp_loggedin(MANAGE_ALL_NEWS_RIGHTS)) {
2217:             $newsshow = '';
2218:         } else {
2219:             $newsshow = 'news.show=1 AND';
2220:             $newscheck = query_full_array("SELECT * FROM " . prefix('news') . " ORDER BY date");
2221:             foreach ($newscheck as $articlecheck) {
2222:                 $obj = new ZenpageNews($articlecheck['titlelink']);
2223:                 if ($obj->inProtectedCategory()) {
2224:                     if ($checkauth && $obj->isMyItem(LIST_RIGHTS)) {
2225:                         $newsshow = '';
2226:                     } else {
2227:                         $excludenews = " AND id != " . $articlecheck['id'];
2228:                         $newspasswordcheck = $newspasswordcheck . $excludenews;
2229:                     }
2230:                 }
2231:             }
2232:         }
2233:     }
2234:     if ($type == 'all' || $type == 'page') {
2235:         $pagepasswordcheck = "";
2236:         if (zp_loggedin(MANAGE_ALL_PAGES_RIGHTS)) {
2237:             $pagesshow = '';
2238:         } else {
2239:             $pagesshow = 'pages.show=1 AND';
2240:             $pagescheck = query_full_array("SELECT * FROM " . prefix('pages') . " ORDER BY date");
2241:             foreach ($pagescheck as $pagecheck) {
2242:                 $obj = new ZenpagePage($pagecheck['titlelink']);
2243:                 if ($obj->isProtected()) {
2244:                     if ($checkauth && $obj->isMyItem(LIST_RIGHTS)) {
2245:                         $pagesshow = '';
2246:                     } else {
2247:                         $excludepages = " AND pages.id != " . $pagecheck['id'];
2248:                         $pagepasswordcheck = $pagepasswordcheck . $excludepages;
2249:                     }
2250:                 }
2251:             }
2252:         }
2253:     }
2254:     switch ($type) {
2255:         case "news":
2256:             $whereNews = " WHERE $newsshow news.id = " . $itemID . " AND c.ownerid = news.id AND c.type = 'news' AND c.private = 0 AND c.inmoderation = 0" . $newspasswordcheck;
2257:             break;
2258:         case "page":
2259:             $wherePages = " WHERE $pagesshow pages.id = " . $itemID . " AND c.ownerid = pages.id AND c.type = 'pages' AND c.private = 0 AND c.inmoderation = 0" . $pagepasswordcheck;
2260:             break;
2261:         case "all":
2262:             $whereNews = " WHERE $newsshow c.ownerid = news.id AND c.type = 'news' AND c.private = 0 AND c.inmoderation = 0" . $newspasswordcheck;
2263:             $wherePages = " WHERE $pagesshow c.ownerid = pages.id AND c.type = 'pages' AND c.private = 0 AND c.inmoderation = 0" . $pagepasswordcheck;
2264:             break;
2265:     }
2266:     $comments_news = array();
2267:     $comments_pages = array();
2268:     if ($type == "all" OR $type == "news") {
2269:         $comments_news = query_full_array("SELECT c.id, c.name, c.type, c.website,"
2270:                         . " c.date, c.anon, c.comment, news.title, news.titlelink FROM " . prefix('comments') . " AS c, " . prefix('news') . " AS news "
2271:                         . $whereNews
2272:                         . " ORDER BY c.id DESC LIMIT $number");
2273:     }
2274:     if ($type == "all" OR $type == "page") {
2275:         $comments_pages = query_full_array($sql = "SELECT c.id, c.name, c.type, c.website,"
2276:                         . " c.date, c.anon, c.comment, pages.title, pages.titlelink FROM " . prefix('comments') . " AS c, " . prefix('pages') . " AS pages "
2277:                         . $wherePages
2278:                         . " ORDER BY c.id DESC LIMIT $number");
2279:     }
2280:     $comments = array();
2281:     foreach ($comments_news as $comment) {
2282:         $comments[$comment['id']] = $comment;
2283:     }
2284:     foreach ($comments_pages as $comment) {
2285:         $comments[$comment['id']] = $comment;
2286:     }
2287:     krsort($comments);
2288:     return array_slice($comments, 0, $number);
2289: }
2290: 
2291: 2292: 2293: 2294: 2295: 2296: 2297: 2298: 2299: 2300: 2301: 
2302: function zenpageAlbumImage($albumname, $imagename = NULL, $size = NULL, $linkalbum = false) {
2303:     global $_zp_gallery;
2304:     echo '<br />';
2305:     $album = newAlbum($albumname);
2306:     if ($album->loaded) {
2307:         if (is_null($size)) {
2308:             $size = floor(getOption('image_size') * 0.5);
2309:         }
2310:         $image = NULL;
2311:         if (is_null($imagename)) {
2312:             $linkalbum = true;
2313:             $image = $album->getAlbumThumbImage();
2314:         } else {
2315:             $image = newImage($album, $imagename);
2316:         }
2317:         if ($image && $image->loaded) {
2318:             makeImageCurrent($image);
2319:             if ($linkalbum) {
2320:                 rem_context(ZP_IMAGE);
2321:                 echo '<a href="' . html_encode($album->getLink()) . '"   title="' . sprintf(gettext('View the %s album'), $albumname) . '">';
2322:                 add_context(ZP_IMAGE);
2323:                 printCustomSizedImage(sprintf(gettext('View the album %s'), $albumname), $size);
2324:                 rem_context(ZP_IMAGE | ZP_ALBUM);
2325:                 echo '</a>';
2326:             } else {
2327:                 echo '<a href="' . html_encode(getImageURL()) . '" title="' . sprintf(gettext('View %s'), $imagename) . '">';
2328:                 printCustomSizedImage(sprintf(gettext('View %s'), $imagename), $size);
2329:                 rem_context(ZP_IMAGE | ZP_ALBUM);
2330:                 echo '</a>';
2331:             }
2332:         } else {
2333:             ?>
2334:             <span style="background:red;color:black;">
2335:                 <?php
2336:                 printf(gettext('<code>zenpageAlbumImage()</code> did not find the image %1$s:%2$s'), $albumname, $imagename);
2337:                 ?>
2338:             </span>
2339:             <?php
2340:         }
2341:     } else {
2342:         ?>
2343:         <span style="background:red;color:black;">
2344:             <?php
2345:             printf(gettext('<code>zenpageAlbumImage()</code> did not find the album %1$s'), $albumname);
2346:             ?>
2347:         </span>
2348:         <?php
2349:     }
2350: }
2351: 
2352: Zenpage::expiry();
2353: ?>