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:
<?php
function updateItemsSortorder() {
if (empty($_POST['order'])) {
return '<p class="notebox fade-message">' . gettext('Nothing changed') . '</p>';
} else {
$order = processOrder($_POST['order']);
$parents = array('NULL');
foreach ($order as $id => $orderlist) {
$sortstring = implode('-', $orderlist);
$level = count($orderlist);
$parents[$level] = $id;
$myparent = $parents[$level - 1];
$sql = "UPDATE " . prefix('menu') . " SET `sort_order` = " . db_quote($sortstring) . ", `parentid`= " . db_quote($myparent) . " WHERE `id`=" . sanitize_numeric($id);
query($sql);
}
return "<p class='messagebox fade-message'>" . gettext("Sort order saved.") . "</p>";
}
}
function printItemsListTable($item, $flag) {
global $_zp_gallery;
$menuset = checkChosenMenuset('');
$link = '';
$array = getItemTitleAndURL($item);
if ($array['valid']) {
switch ($item['type']) {
case "album":
$link = '<a href="../../admin-edit.php?page=edit&album=' . html_encode($item['link']) . '">' . html_encode(truncate_string($item['link'], 40, '...')) . '</a>';
break;
case "zenpagenewsindex":
if(!class_exists('zenpage')) {
$link = '<span class="notebox">'.gettext('Zenpage CMS plugin required for this item type!').'</span>';
}
break;
case "zenpagepage":
if(class_exists('zenpage')) {
$link = '<a href="../zenpage/admin-edit.php?page&titlelink=' . html_encode($item['link']) . '">' . html_encode(truncate_string($item['link'], 40, '...')) . '</a>';
} else {
$link = '<span class="notebox">'.gettext('Zenpage CMS plugin required for this item type!').'</span>';
}
break;
case "zenpagecategory":
if(class_exists('zenpage')) {
$link = '<a href="../zenpage/admin-edit.php?newscategory&titlelink=' . html_encode($item['link']) . '">' . html_encode(truncate_string($item['link'], 40, '...')) . '</a>';
} else {
$link = '<span class="notebox">'.gettext('Zenpage CMS plugin required for this item type!').'</span>';
}
break;
case 'customlink':
$link = '<a href="' . html_encode($item['link']) . '">' . html_encode(truncate_string($item['link'], 40, '...')) . '</a>';
break;
case 'menulabel':
$link = '';
break;
default:
$link = html_encode(truncate_string($item['link'], 40, '...'));
break;
}
} else {
$link = '<span class="notebox">' . sprintf(gettext('Target does not exists in <em>%1$s</em> theme'), $array['theme']) . '</span>';
}
?>
<div class="page-list_row">
<div class="page-list_title">
<?php
printItemEditLink($item);
?>
</div>
<div class="page-list_extra">
<em><?php echo $item['type']; ?></em>
</div>
<div class="page-list_extra">
<?php echo $link; ?>
</div>
<div class="page-list_iconwrapper">
<div class="page-list_icon">
<?php
if ($array['protected']) {
?>
<img src="../../images/lock_2.png" alt="<?php echo gettext("The object of this menu is under password protection"); ?>" title="<?php echo gettext("The object of this menu is under password protection"); ?>" style="border: 0px;" />
<?php
} else {
?>
<img src="../../images/place_holder_icon.png" alt="<?php echo gettext("under password protection"); ?>" style="border: 0px;" />
<?php
}
?>
</div>
<div class="page-list_icon">
<?php
if ($item['show'] === '1') {
?>
<a href="menu_tab.php?publish&id=<?php echo $item['id'] . "&show=0"; ?>&add&XSRFToken=<?php echo getXSRFToken('update_menu') ?>&menuset=<?php echo sanitize($menuset); ?>" title="<?php echo gettext('hide'); ?>" >
<img src="../../images/pass.png" alt="<?php echo gettext('hide'); ?>" style="border: 0px;" />
</a>
<?php
} else {
?>
<a href="menu_tab.php?publish&id=<?php echo $item['id'] . "&show=1"; ?>&add&XSRFToken=<?php echo getXSRFToken('update_menu') ?>&menuset=<?php echo sanitize($menuset); ?>" title="<?php echo gettext('show'); ?>">
<img src="../../images/action.png" alt="<?php echo gettext('show'); ?>" style="border: 0px;" />
</a>
<?php
}
?>
</div>
<div class="page-list_icon">
<?php
switch ($item['type']) {
default:
if (!empty($array['url'])) {
?>
<a href="<?php echo $array['url']; ?>">
<img src="../../images/view.png" alt="<?php echo gettext('view'); ?>" title="<?php echo gettext('view'); ?>" style="border: 0px;" />
</a>
<?php
break;
}
case 'menulabel':
case 'menufunction':
case 'html':
?>
<img src="../../images/icon_inactive.png" alt="" style="border: 0px;" />
<?php
break;
}
?>
</div>
<div class="page-list_icon">
<a href="javascript:deleteMenuItem('<?php echo $item['id']; ?>','<?php printf(gettext('Ok to delete %s? This cannot be undone.'), html_encode($array['name'])); ?>');" >
<img src="../../images/fail.png" alt="<?php echo gettext('delete'); ?>" title="<?php echo gettext('delete'); ?>" style="border: 0px;" />
</a>
</div>
<div class="page-list_icon">
<input class="checkbox" type="checkbox" name="ids[]" value="<?php echo html_encode($item['id']); ?>" onclick="triggerAllBox(this.form, 'ids[]', this.form.allbox);" />
</div>
</div>
</div>
<?php
}
function printItemsList($items) {
$indent = 1;
$open = array(1 => 0);
$rslt = false;
foreach ($items as $item) {
$order = explode('-', $item['sort_order']);
$level = max(1, count($order));
if ($toodeep = $level > 1 && $order[$level - 1] === '') {
$rslt = true;
}
if ($level > $indent) {
echo "\n" . str_pad("\t", $indent, "\t") . "<ul class=\"page-list\">\n";
$indent++;
$open[$indent] = 0;
} else if ($level < $indent) {
while ($indent > $level) {
$open[$indent] --;
$indent--;
echo "</li>\n" . str_pad("\t", $indent, "\t") . "</ul>\n";
}
} else {
if ($open[$indent]) {
echo str_pad("\t", $indent, "\t") . "</li>\n";
$open[$indent] --;
} else {
echo "\n";
}
}
if ($open[$indent]) {
echo str_pad("\t", $indent, "\t") . "</li>\n";
$open[$indent] --;
}
echo str_pad("\t", $indent - 1, "\t") . "<li id=\"id_" . $item['id'] . "\">";
echo printItemsListTable($item, $toodeep);
$open[$indent] ++;
}
while ($indent > 1) {
echo "</li>\n";
$open[$indent] --;
$indent--;
echo str_pad("\t", $indent, "\t") . "</ul>";
}
if ($open[$indent]) {
echo "</li>\n";
} else {
echo "\n";
}
return $rslt;
}
function printItemEditLink($item) {
$link = "";
$array = getItemTitleAndURL($item);
$title = html_encode($array['title']);
$link = '<a href="menu_tab_edit.php?edit&id=' . $item['id'] . "&type=" . $item['type'] . "&menuset=" . html_encode(checkChosenMenuset()) . '">' . $title . '</a>';
echo $link;
}
function printItemStatusDropdown() {
$all = "";
$visible = "";
$hidden = "";
$status = checkChosenItemStatus();
$menuset = checkChosenMenuset();
?>
<select name="ListBoxURL" id="ListBoxURL" class="dirtyignore" size="1" onchange="window.location = '?menuset=<?php echo urlencode($menuset); ?>&visible=' + $('#ListBoxURL').val()">
<?php
switch ($status) {
case "hidden":
$hidden = 'selected="selected"';
break;
case "visible":
$visible = 'selected="selected"';
break;
default:
$all = 'selected="selected"';
break;
}
echo "<option $all value='all'>" . gettext("Hidden and visible items") . "</option>\n";
echo "<option $visible value='visible'>" . gettext("Visible items") . "</option>\n";
echo "<option $hidden value='hidden'>" . gettext("hidden items") . "</option>\n";
?>
</select>
<?php
}
function getMenuSetSelector($active) {
$menuset = checkChosenMenuset();
$menusets = array($menuset => $menuset);
$result = query_full_array("SELECT DISTINCT menuset FROM " . prefix('menu') . " ORDER BY menuset");
if ($result) {
foreach ($result as $set) {
$menusets[$set['menuset']] = $set['menuset'];
}
sortArray($menusets);
} else {
return NULL;
}
if ($active) {
$selector = '<select name="menuset" id="menuset" class="dirtyignore" size="1" onchange="window.location=\'?menuset=\'+encodeURIComponent($(\'#menuset\').val())">' . "\n";
} else {
$selector = '<select name="menuset" size="1">' . "\n";
}
foreach ($menusets as $set) {
if ($menuset == $set) {
$selected = 'selected="selected"';
} else {
$selected = '';
}
$selector .= '<option ' . $selected . ' value="' . html_encode($set) . '">' . html_encode($set) . "</option>\n";
}
$selector .= "</select>\n";
return $selector;
}
function publishItem($id, $show, $menuset) {
query("UPDATE " . prefix('menu') . " SET `show` = '" . $show . "' WHERE id = " . $id, true . " AND menuset = " . db_quote($menuset));
}
function addSubalbumMenus($menuset, $id, $link, $sort) {
$album = newAlbum($link);
$show = $album->isPublished();
$title = $album->getTitle();
$sql = "INSERT INTO " . prefix('menu') . " (`link`,`type`,`title`,`show`,`menuset`,`sort_order`, `parentid`) " .
'VALUES (' . db_quote($link) . ', "album",' . db_quote($album->name) . ', ' . $show . ',' . db_quote($menuset) . ',' . db_quote($sort) . ',' . $id . ')';
$result = query($sql, false);
if ($result) {
$id = db_insert_id();
} else {
$result = query_single_row('SELECT `id` FROM' . prefix('menu') . ' WHERE `type`="album" AND `link`=' . db_quote($link));
$id = $result['id'];
}
if (!$album->isDynamic()) {
$albums = $album->getAlbums();
foreach ($albums as $key => $link) {
addSubalbumMenus($menuset, $id, $link, $sort . '-' . sprintf('%03u', $key));
}
}
}
function addalbumsToDatabase($menuset, $base = NULL) {
global $_zp_gallery;
if (is_null($base)) {
$albumbase = db_count('menu', 'WHERE menuset=' . db_quote($menuset));
$sortbase = '';
} else {
$albumbase = array_pop($base);
$sortbase = '';
for ($i = 0; $i < count($base); $i++) {
$sortbase .= sprintf('%03u', $base[$i]) . '-';
}
}
$result = $albumbase;
$albums = $_zp_gallery->getAlbums();
foreach ($albums as $key => $link) {
addSubalbumMenus($menuset, 'NULL', $link, $sortbase . sprintf('%03u', $result = $key + $albumbase));
}
return $result;
}
function addPagesToDatabase($menuset, $base = NULL) {
if (is_null($base)) {
$pagebase = db_count('menu', 'WHERE menuset=' . db_quote($menuset));
$sortbase = '';
} else {
$pagebase = array_pop($base);
$sortbase = '';
for ($i = 0; $i < count($base); $i++) {
$sortbase .= sprintf('%03u', $base[$i]) . '-';
}
}
$result = $pagebase;
$parents = array('NULL');
$result = query_full_array("SELECT * FROM " . prefix('pages') . " ORDER BY sort_order");
foreach ($result as $key => $item) {
if(empty($item['sort_order'])) {
$sorts = array($key);
} else {
$sorts = explode('-', $item['sort_order']);
}
$level = count($sorts);
$sorts[0] = sprintf('%03u', $result = $sorts[0] + $pagebase);
$order = $sortbase . implode('-', $sorts);
$show = $item['show'];
$link = $item['titlelink'];
$parent = $parents[$level - 1];
$sql = "INSERT INTO " . prefix('menu') . " (`title`, `link`, `type`, `show`,`menuset`,`sort_order`, `parentid`) " .
'VALUES (' . db_quote($item['title']) . ',' . db_quote($link) . ',"zenpagepage",' . $show . ',' . db_quote($menuset) . ',' . db_quote($order) . ',' . $parent . ')';
if (query($sql, false)) {
$id = db_insert_id();
} else {
$rslt = query_single_row('SELECT `id` FROM' . prefix('menu') . ' WHERE `type`="zenpagepage" AND `link`="' . $link . '"');
$id = $rslt['id'];
}
$parents[$level] = $id;
}
return $result;
}
function addCategoriesToDatabase($menuset, $base = NULL) {
if (is_null($base)) {
$categorybase = db_count('menu', 'WHERE menuset=' . db_quote($menuset));
$sortbase = '';
} else {
$categorybase = array_pop($base);
$sortbase = '';
for ($i = 0; $i < count($base); $i++) {
$sortbase .= sprintf('%03u', $base[$i]) . '-';
}
}
$result = $categorybase;
$parents = array('NULL');
$cats = query_full_array("SELECT * FROM " . prefix('news_categories') . " ORDER BY sort_order");
foreach ($cats as $key => $item) {
if(empty($item['sort_order'])) {
$sorts = array($key);
} else {
$sorts = explode('-', $item['sort_order']);
}
$level = count($sorts);
$result = $sorts[0] + $categorybase;
$sorts[0] = sprintf('%03u', $result);
$order = $sortbase . implode('-', $sorts);
$link = $item['titlelink'];
$parent = $parents[$level - 1];
$sql = "INSERT INTO " . prefix('menu') . " (`title`, `link`, `type`, `show`,`menuset`,`sort_order`,`parentid`) " .
'VALUES (' . db_quote($item['title']) . ',' . db_quote($link) . ',"zenpagecategory", 1,' . db_quote($menuset) . ',' . db_quote($order) . ',' . $parent . ')';
if (query($sql, false)) {
$id = db_insert_id();
} else {
$rslt = query_single_row('SELECT `id` FROM' . prefix('menu') . ' WHERE `type`="zenpagecategory" AND `link`="' . $link . '"');
$id = $rslt['id'];
}
$parents[$level] = $id;
}
return $result;
}
function addItem(&$reports) {
$menuset = checkChosenMenuset();
$result['type'] = sanitize($_POST['type']);
$result['show'] = getCheckboxState('show');
$result['include_li'] = getCheckboxState('include_li');
$result['id'] = 0;
if (getCheckboxState('span')) {
$result['span_id'] = sanitize($_POST['span_id']);
$result['span_class'] = sanitize($_POST['span_class']);
} else {
$result['span_id'] = '';
$result['span_class'] = '';
}
switch ($result['type']) {
case 'all_items':
query("INSERT INTO " . prefix('menu') . " (`title`,`link`,`type`,`show`,`menuset`,`sort_order`) " .
"VALUES ('" . gettext('Home') . "', '" . WEBPATH . '/' . "','galleryindex','1'," . db_quote($menuset) . ",'000')", true);
addAlbumsToDatabase($menuset);
if (extensionEnabled('zenpage')) {
query("INSERT INTO " . prefix('menu') . " (`title`,`link`,`type`,`show`,`menuset`,`sort_order`) " .
"VALUES ('" . gettext('News index') . "', '" . getNewsIndexURL() . "', 'zenpagenewsindex', '1', " . db_quote($menuset) . ", '001')", true);
addPagesToDatabase($menuset);
addCategoriesToDatabase($menuset);
}
$reports[] = "<p class = 'messagebox fade-message'>" . gettext("Menu items for all Zenphoto objects added.") . " </p>";
return NULL;
case 'all_albums':
addAlbumsToDatabase($menuset);
$reports[] = "<p class = 'messagebox fade-message'>" . gettext("Menu items for all albums added.") . " </p>";
return NULL;
case 'all_zenpagepages':
addPagesToDatabase($menuset);
$reports[] = "<p class = 'messagebox fade-message'>" . gettext("Menu items for all Zenpage pages added.") . " </p>";
return NULL;
case 'all_zenpagecategorys':
addCategoriesToDatabase($menuset);
$reports[] = "<p class = 'messagebox fade-message'>" . gettext("Menu items for all Zenpage categories added.") . " </p>";
return NULL;
case 'album':
$result['title'] = $result['link'] = sanitize($_POST['albumselect']);
if (empty($result['link'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to select an album.") . " </p>";
return $result;
}
$successmsg = sprintf(gettext("Album menu item <em>%s</em> added"), $result['link']);
break;
case 'homepage':
$result['title'] = process_language_string_save("title", 2);
$result['link'] = NULL;
if (empty($result['title'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
return $result;
}
$successmsg = sprintf(gettext("Home page menu item <em>%s</em> added"), $result['link']);
break;
case 'galleryindex':
$result['title'] = process_language_string_save("title", 2);
$result['link'] = NULL;
if (empty($result['title'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
return $result;
}
$successmsg = sprintf(gettext("Gallery index menu item <em>%s</em> added"), $result['link']);
break;
case 'zenpagepage':
$result['title'] = NULL;
$result['link'] = sanitize($_POST['pageselect']);
if (empty($result['link'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>link</strong>!") . " </p>";
return $result;
}
$successmsg = sprintf(gettext("Zenpage page menu item <em>%s</em> added"), $result['link']);
break;
case 'zenpagenewsindex':
$result['title'] = process_language_string_save("title", 2);
$result['link'] = NULL;
if (empty($result['title'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
return $result;
}
$successmsg = sprintf(gettext("Zenpage news index menu item <em>%s</em> added"), $result['link']);
break;
case 'zenpagecategory':
$result['title'] = NULL;
$result['link'] = sanitize($_POST['categoryselect']);
if (empty($result['link'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>link</strong>!") . " </p>";
return $result;
}
$successmsg = sprintf(gettext("Zenpage news category menu item <em>%s</em> added"), $result['link']);
break;
case 'custompage':
$result['title'] = process_language_string_save("title", 2);
$result['link'] = sanitize($_POST['custompageselect']);
if (empty($result['title'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
return $result;
}
$successmsg = sprintf(gettext("Custom page menu item <em>%s</em> added"), $result['link']);
break;
case 'customlink':
$result['title'] = process_language_string_save("title", 2);
if (empty($result['title'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
return $result;
}
$result['link'] = sanitize($_POST['link']);
if (empty($result['link'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to provide a <strong>function</strong>!") . " </p>";
return $result;
}
$successmsg = sprintf(gettext("Custom page menu item <em>%s</em> added"), $result['link']);
break;
case 'menulabel':
$result['title'] = process_language_string_save("title", 2);
$result['link'] = NULL;
if (empty($result['title'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
return $result;
}
$successmsg = gettext("Custom label added");
break;
case 'menufunction':
$result['title'] = process_language_string_save("title", 2);
if (empty($result['title'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
return $result;
}
$result['link'] = sanitize($_POST['link'], 4);
if (empty($result['link'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to provide a <strong>function</strong>!") . " </p>";
return $result;
}
$successmsg = sprintf(gettext("Function menu item <em>%s</em> added"), $result['link']);
break;
case 'html':
$result['title'] = process_language_string_save("title", 2);
if (empty($result['title'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
return $result;
}
$result['link'] = sanitize($_POST['link'], 4);
if (empty($result['link'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to provide a <strong>function</strong>!") . " </p>";
return $result;
}
$successmsg = gettext("<em>HTML</em> added");
break;
default:
break;
}
$count = db_count('menu', 'WHERE menuset=' . db_quote($menuset));
$order = sprintf('%03u', $count);
$sql = "INSERT INTO " . prefix('menu') . " ( `title`, `link`, `type`, `show`, `menuset`, `sort_order`, `include_li`, `span_id`, `span_class`) " .
"VALUES (" . db_quote($result['title']) .
", " . db_quote($result['link']) .
", " . db_quote($result['type']) . ", " . $result['show'] .
", " . db_quote($menuset) . ", " . db_quote($order) . ", " . $result['include_li'] .
", " . db_quote($result['span_id']) . ", " . db_quote($result['span_class']) .
")";
if (query($sql, true)) {
$reports[] = "<p class = 'messagebox fade-message'>" . $successmsg . "</p>";
$result['id'] = db_insert_id();
return $result;
} else {
if (empty($result['link'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . sprintf(gettext('A <em>%1$s</em> item already exists in <em>%2$s </em>!'), $result['type'], $menuset) . "</p>";
} else {
$reports[] = "<p class = 'errorbox fade-message'>" . sprintf(gettext('A <em>%1$s</em> item with the link <em>%2$s</em> already exists in <em>%3$s </em>!'), $result['type'], $result['link'], $menuset) . "</p>";
}
return NULL;
}
}
function updateMenuItem(&$reports) {
$menuset = checkChosenMenuset();
$result = array();
$result['id'] = sanitize($_POST['id']);
$result['show'] = getCheckboxState('show');
$result['type'] = sanitize($_POST['type']);
$result['title'] = process_language_string_save("title", 2);
$result['include_li'] = getCheckboxState('include_li');
if (getCheckboxState('span')) {
$result['span_id'] = sanitize($_POST['span_id']);
$result['span_class'] = sanitize($_POST['span_class']);
} else {
$result['span_id'] = '';
$result['span_class'] = '';
}
switch ($result['type']) {
case 'album':
$result['title'] = $result['link'] = sanitize($_POST['albumselect']);
if (empty($result['link'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to select an album.") . " </p>";
return $result;
}
break;
case 'homepage':
$result['title'] = process_language_string_save("title", 2);
$result['link'] = NULL;
if (empty($result['title'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
return $result;
}
break;
case 'galleryindex':
$result['title'] = process_language_string_save("title", 2);
$result['link'] = NULL;
if (empty($result['title'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
return $result;
}
break;
case 'zenpagepage':
$result['title'] = NULL;
$result['link'] = sanitize($_POST['pageselect']);
if (empty($result['link'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>link</strong>!") . " </p>";
return $result;
}
break;
case 'zenpagenewsindex':
$result['title'] = process_language_string_save("title", 2);
$result['link'] = NULL;
if (empty($result['title'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
return $result;
}
break;
case 'zenpagecategory':
$result['title'] = NULL;
$result['link'] = sanitize($_POST['categoryselect']);
if (empty($result['link'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>link</strong>!") . " </p>";
return $result;
}
break;
case 'custompage':
$result['title'] = process_language_string_save("title", 2);
$result['link'] = sanitize($_POST['custompageselect']);
if (empty($result['title'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
return $result;
}
break;
case 'customlink':
$result['title'] = process_language_string_save("title", 2);
if (empty($result['title'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
return $result;
}
$result['link'] = sanitize($_POST['link']);
if (empty($result['link'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to provide a <strong>function</strong>!") . " </p>";
return $result;
}
break;
case 'menulabel':
$result['title'] = process_language_string_save("title", 2);
$result['link'] = NULL;
if (empty($result['title'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
return $result;
}
break;
case 'menufunction':
$result['title'] = process_language_string_save("title", 2);
if (empty($result['title'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
return $result;
}
$result['link'] = sanitize($_POST['link'], 4);
if (empty($result['link'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to provide a <strong>function</strong>!") . " </p>";
return $result;
}
break;
case 'html':
$result['title'] = process_language_string_save("title", 2);
if (empty($result['title'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
return $result;
}
$result['link'] = sanitize($_POST['link'], 4);
if (empty($result['link'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to provide a <strong>function</strong>!") . " </p>";
return $result;
}
break;
default:
$result['link'] = sanitize($_POST['link'], 4);
break;
}
$sql = "UPDATE " . prefix('menu') . " SET title = " . db_quote($result['title']) .
", link = " . db_quote($result['link']) .
", type = " . db_quote($result['type']) . ", `show` = " . db_quote($result['show']) .
", menuset = " . db_quote($menuset) . ", include_li = " . $result['include_li'] .
", span_id = " . db_quote($result['span_id']) . ", span_class = " . db_quote($result['span_class']) .
" WHERE `id` = " . $result['id'];
if (query($sql)) {
if (isset($_POST['title']) && empty($result['title'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>title</strong>!") . " </p>";
} else if (isset($_POST['link']) && empty($result['link'])) {
$reports[] = "<p class = 'errorbox fade-message'>" . gettext("You forgot to give your menu item a <strong>link</strong>!") . " </p>";
} else {
$reports[] = "<p class = 'messagebox fade-message'>" . gettext("Menu item updated!") . " </p>";
}
}
return $result;
}
function deleteItem(&$reports) {
if (isset($_GET['delete'])) {
$delete = sanitize_numeric($_GET['delete'], 3);
query("DELETE FROM " . prefix('menu') . " WHERE `id` = $delete");
$reports[] = "<p class = 'messagebox fade-message'>" . gettext("Custom menu item successfully deleted!") . " </p>";
}
}
function printAlbumsSelector($current) {
global $_zp_gallery;
$albumlist = $_zp_gallery->getAllAlbumsFromDB(false, null, ALL_ALBUMS_RIGHTS);
?>
<select id="albumselector" name="albumselect">
<?php
foreach ($albumlist as $key => $value) {
$albumobj = newAlbum($key);
$albumname = $albumobj->name;
if ($albumname == $current) {
$selected = ' selected="selected"';
} else {
$selected = '';
}
$level = substr_count($albumname, "/");
$arrow = "";
for ($count = 1; $count <= $level; $count++) {
$arrow .= "– ";
}
echo "<option value = '" . html_encode($albumobj->name) . "'" . $selected . '>';
echo $arrow . $albumobj->getTitle() . unpublishedZenphotoItemCheck($albumobj) . "</option>";
}
?>
</select>
<?php
}
function printZenpagePagesSelector($current) {
global $_zp_gallery, $_zp_zenpage;
?>
<select id="pageselector" name="pageselect">
<?php
$pages = $_zp_zenpage->getPages(false);
foreach ($pages as $key => $page) {
if ($page['titlelink'] == $current) {
$selected = ' selected= "selected
"';
} else {
$selected = '';
}
$pageobj = new ZenpagePage($page['titlelink']);
$level = substr_count($pageobj->getSortOrder(), "-");
$arrow = "";
for ($count = 1; $count <= $level; $count++) {
$arrow .= "» ";
}
echo "<option value = '" . html_encode($pageobj->getTitlelink()) . "'" . $selected . '>';
echo $arrow . $pageobj->getTitle() . unpublishedZenphotoItemCheck($pageobj) . "</option>";
}
?>
</select>
<?php
}
function printZenpageNewsCategorySelector($current) {
global $_zp_gallery, $_zp_zenpage;
?>
<select id="categoryselector" name="categoryselect">
<?php
$cats = $_zp_zenpage->getAllCategories(false);
foreach ($cats as $cat) {
if ($cat['titlelink'] == $current) {
$selected = ' selected="selected"';
} else {
$selected = '';
}
$catobj = new ZenpageCategory($cat['titlelink']);
$getparents = $catobj->getParents();
$levelmark = '';
foreach ($getparents as $parent) {
$levelmark .= '» ';
}
echo "<option value = '" . html_encode($catobj->getTitlelink()) . "'" . $selected . '>';
echo $levelmark . $catobj->getTitle() . "</option>"
;
}
?>
</select>
<?php
}
function printCustomPageSelector($current) {
global $_zp_gallery;
?>
<select id="custompageselector" name="custompageselect">
<?php
$curdir = getcwd();
$themename = $_zp_gallery->getCurrentTheme();
$root = SERVERPATH . '/' . THEMEFOLDER . '/' . $themename . '/';
chdir($root);
$filelist = safe_glob('*.php');
$list = array();
$exclude = array(
'404.php',
'index.php',
'main.php',
'gallery.php',
'album.php',
'image.php',
'pages.php',
'news.php',
'functions.php',
'inc-footer.php',
'footer.php',
'inc-header.php',
'header.php',
'inc-sidebar.php',
'sidebar.php',
'slideshow.php',
'theme_description.php',
'themeoptions.php'
);
foreach ($filelist as $file) {
if(!in_array($file, $exclude)) {
$file = filesystemToInternal($file);
$list[$file] = str_replace('.php', '', $file);
}
}
generateListFromArray(array($current), $list, false, true);
chdir($curdir);
?>
</select>
<?php
}
function unpublishedZenphotoItemCheck($obj, $dropdown = true) {
if ($obj->isPublished()) {
$show = "";
} else {
$show = "*";
}
return $show;
}
function processMenuBulkActions() {
$report = NULL;
if (isset($_POST['ids'])) {
$action = sanitize($_POST['checkallaction']);
$ids = $_POST['ids'];
$total = count($ids);
$message = NULL;
if ($action != 'noaction') {
if ($total > 0) {
$n = 0;
switch ($action) {
case 'deleteall':
$sql = "DELETE FROM " . prefix('menu') . " WHERE ";
$message = gettext('Selected items deleted');
break;
case 'showall':
$sql = "UPDATE " . prefix('menu') . " SET `show` = 1 WHERE ";
$message = gettext('Selected items published');
break;
case 'hideall':
$sql = "UPDATE " . prefix('menu') . " SET `show` = 0 WHERE ";
$message = gettext('Selected items unpublished');
break;
}
foreach ($ids as $id) {
$n++;
$sql .= " id = '" . sanitize_numeric($id) . "' ";
if ($n < $total)
$sql .= "OR ";
}
query($sql);
}
if (!is_null($message))
$report = "<p class = 'messagebox fade-message'>" . $message . "</p>";
}
}
return $report;
}
?>