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