1: <?php
2: 3: 4: 5: 6: 7: 8:
9: global $_zp_zenpage, $_zp_current_zenpage_news, $_zp_current_zenpage_page, $_zp_current_category;
10: Zenpage::expiry();
11:
12: 13: 14: 15: 16: 17: 18:
19: function getExpiryDatePost() {
20: $expiredate = sanitize($_POST['expiredate']);
21: if ($expiredate > date(date('Y-m-d H:i:s')))
22: return $expiredate;
23: return NULL;
24: }
25:
26: 27: 28: 29: 30:
31: function processTags($object) {
32: $tagsprefix = 'tags_';
33: $tags = array();
34: $l = strlen($tagsprefix);
35: foreach ($_POST as $key => $value) {
36: $key = postIndexDecode($key);
37: if (substr($key, 0, $l) == $tagsprefix) {
38: if ($value) {
39: $tags[] = substr($key, $l);
40: }
41: }
42: }
43: $tags = array_unique($tags);
44: $object->setTags(sanitize($tags, 3));
45: }
46:
47: 48: 49:
50:
51: 52: 53: 54: 55: 56: 57: 58:
59: function updatePage(&$reports, $newpage = false) {
60: $title = process_language_string_save("title", 2);
61: $author = sanitize($_POST['author']);
62: $content = zpFunctions::updateImageProcessorLink(process_language_string_save("content", EDITOR_SANITIZE_LEVEL));
63: $extracontent = zpFunctions::updateImageProcessorLink(process_language_string_save("extracontent", EDITOR_SANITIZE_LEVEL));
64: $custom = process_language_string_save("custom_data", 1);
65: $show = getcheckboxState('show');
66: $date = sanitize($_POST['date']);
67: $lastchange = sanitize($_POST['lastchange']);
68: $lastchangeauthor = sanitize($_POST['lastchangeauthor']);
69: $expiredate = getExpiryDatePost();
70: $commentson = getcheckboxState('commentson');
71: $permalink = getcheckboxState('permalink');
72: if (zp_loggedin(CODEBLOCK_RIGHTS)) {
73: $codeblock = processCodeblockSave(0);
74: }
75: $locked = getcheckboxState('locked');
76: $date = sanitize($_POST['date']);
77: if ($newpage) {
78: $titlelink = seoFriendly(get_language_string($title));
79: if (empty($titlelink)) {
80: $titlelink = seoFriendly($date);
81: }
82: $sql = 'SELECT `id` FROM ' . prefix('pages') . ' WHERE `titlelink`=' . db_quote($titlelink);
83: $rslt = query_single_row($sql, false);
84: if ($rslt) {
85:
86: $time = explode(' ', microtime());
87: $titlelink = $titlelink . '_' . ($time[1] + $time[0]);
88: $reports[] = "<p class='warningbox fade-message'>" . gettext('Duplicate page title') . '</p>';
89: }
90: $oldtitlelink = $titlelink;
91: } else {
92: $titlelink = $oldtitlelink = sanitize($_POST['titlelink-old']);
93: }
94: if (getcheckboxState('edittitlelink')) {
95: $titlelink = sanitize($_POST['titlelink'], 3);
96: if (empty($titlelink)) {
97: $titlelink = seoFriendly(get_language_string($title));
98: if (empty($titlelink)) {
99: $titlelink = seoFriendly($date);
100: }
101: }
102: } else {
103: if (!$permalink) {
104: $link = seoFriendly(get_language_string($title));
105: if (!empty($link)) {
106: $titlelink = $link;
107: }
108: }
109: }
110: $id = sanitize($_POST['id']);
111: $rslt = true;
112: if ($titlelink != $oldtitlelink) {
113: $rslt = query('UPDATE ' . prefix('pages') . ' SET `titlelink`=' . db_quote($titlelink) . ' WHERE `id`=' . $id, false);
114: if (!$rslt) {
115: $titlelink = $oldtitlelink;
116: } else {
117: SearchEngine::clearSearchCache();
118: }
119: }
120:
121: $page = new ZenpagePage($titlelink, true);
122:
123: $notice = processCredentials($page);
124: $page->setTitle($title);
125: $page->setContent($content);
126: $page->setExtracontent($extracontent);
127: $page->setCustomData(zp_apply_filter('save_page_custom_data', $custom, $page));
128: $page->setShow($show);
129: $page->setDateTime($date);
130: $page->setCommentsAllowed($commentson);
131: if (zp_loggedin(CODEBLOCK_RIGHTS)) {
132: $page->setCodeblock($codeblock);
133: }
134: $page->setAuthor($author);
135: $page->setLastchange($lastchange);
136: $page->setLastchangeauthor($lastchangeauthor);
137: $page->setPermalink($permalink);
138: $page->setLocked($locked);
139: $page->setExpiredate($expiredate);
140: if (getcheckboxState('resethitcounter')) {
141: $page->set('hitcounter', 0);
142: }
143: if (getcheckboxState('reset_rating')) {
144: $page->set('total_value', 0);
145: $page->set('total_votes', 0);
146: $page->set('used_ips', 0);
147: }
148: processTags($page);
149: if ($newpage) {
150: $msg = zp_apply_filter('new_page', '', $page);
151: if (empty($title)) {
152: $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("Page <em>%s</em> added but you need to give it a <strong>title</strong> before publishing!"), get_language_string($titlelink)) . '</p>';
153: } else if ($notice == '?mismatch=user') {
154: $reports[] = "<p class='errorbox fade-message'>" . gettext('You must supply a password for the Protected Page user') . '</p>';
155: } else if ($notice) {
156: $reports[] = "<p class='errorbox fade-message'>" . gettext('Your passwords were empty or did not match') . '</p>';
157: } else {
158: $reports[] = "<p class='messagebox fade-message'>" . sprintf(gettext("Page <em>%s</em> added"), $titlelink) . '</p>';
159: }
160: } else {
161: $msg = zp_apply_filter('update_page', '', $page, $oldtitlelink);
162: if (!$rslt) {
163: $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("A page with the title/titlelink <em>%s</em> already exists!"), $titlelink) . '</p>';
164: } else if (empty($title)) {
165: $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("Page <em>%s</em> updated but you need to give it a <strong>title</strong> before publishing!"), get_language_string($titlelink)) . '</p>';
166: } else if ($notice == '?mismatch=user') {
167: $reports[] = "<p class='errorbox fade-message'>" . gettext('You must supply a password for the Protected Page user') . '</p>';
168: } else if ($notice) {
169: echo "<p class='errorbox fade-message'>" . gettext('Your passwords were empty or did not match') . '</p>';
170: } else {
171: $reports[] = "<p class='messagebox fade-message'>" . sprintf(gettext("Page <em>%s</em> updated"), $titlelink) . '</p>';
172: }
173: }
174: $page->save();
175: if ($msg) {
176: $reports[] = $msg;
177: }
178: return $page;
179: }
180:
181: 182: 183: 184:
185: function deletePage($titlelink) {
186: if (is_object($titlelink)) {
187: $obj = $titlelink;
188: } else {
189: $obj = new ZenpagePage($titlelink);
190: }
191: $result = $obj->remove();
192: if ($result) {
193: if (is_object($titlelink)) {
194: header('Location: ' . FULLWEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/zenpage/admin-pages.php?deleted');
195: exitZP();
196: }
197: SearchEngine::clearSearchCache();
198: return "<p class='messagebox fade-message'>" . gettext("Page successfully deleted!") . "</p>";
199: }
200: return "<p class='errorbox fade-message'>" . gettext("Page delete failed!") . "</p>";
201: }
202:
203: 204: 205: 206: 207: 208:
209: function printPagesListTable($page, $flag) {
210: if ($flag) {
211: $img = '../../images/drag_handle_flag.png';
212: } else {
213: $img = '../../images/drag_handle.png';
214: }
215: ?>
216: <div class='page-list_row'>
217: <div class="page-list_title">
218: <?php
219: if (checkIfLockedPage($page)) {
220: echo "<a href='admin-edit.php?page&titlelink=" . urlencode($page->getTitlelink()) . "'> ";
221: checkForEmptyTitle($page->getTitle(), "page");
222: echo "</a>" . checkHitcounterDisplay($page->getHitcounter());
223: } else {
224: checkForEmptyTitle($page->getTitle(), "page");
225: checkHitcounterDisplay($page->getShow());
226: }
227: ?>
228: </div>
229: <div class="page-list_extra">
230: <span>
231: <?php echo html_encode($page->getAuthor()); ?>
232: </span>
233: </div>
234: <div class="page-list_extra">
235: <?php printPublished($page); ?>
236: </div>
237: <div class="page-list_extra">
238: <?php printExpired($page); ?>
239: </div>
240: <div class="page-list_iconwrapper">
241: <div class="page-list_icon">
242: <?php
243: if ($page->getPassword()) {
244: echo '<img src="../../images/lock.png" style="border: 0px;" alt="' . gettext('Password protected') . '" title="' . gettext('Password protected') . '" />';
245: }
246: ?>
247: </div>
248:
249: <?php if (checkIfLockedPage($page)) { ?>
250: <div class="page-list_icon">
251: <?php printPublishIconLink($page, "page"); ?>
252: </div>
253: <div class="page-list_icon">
254: <?php
255: if ($page->getCommentsAllowed()) {
256: ?>
257: <a href="?commentson=0&titlelink=<?php echo html_encode($page->getTitlelink()); ?>&XSRFToken=<?php echo getXSRFToken('update') ?>" title="<?php echo gettext('Disable comments'); ?>">
258: <img src="../../images/comments-on.png" alt="" title="<?php echo gettext("Comments on"); ?>" style="border: 0px;"/>
259: </a>
260: <?php
261: } else {
262: ?>
263: <a href="?commentson=1&titlelink=<?php echo html_encode($page->getTitlelink()); ?>&XSRFToken=<?php echo getXSRFToken('update') ?>" title="<?php echo gettext('Enable comments'); ?>">
264: <img src="../../images/comments-off.png" alt="" title="<?php echo gettext("Comments off"); ?>" style="border: 0px;"/>
265: </a>
266: <?php
267: }
268: ?>
269: </div>
270: <?php } else { ?>
271: <div class="page-list_icon">
272: <img src="../../images/icon_inactive.png" alt="" title="<?php gettext('locked'); ?>" />
273: </div>
274: <div class="page-list_icon">
275: <img src="../../images/icon_inactive.png" alt="" title="<?php gettext('locked'); ?>" />
276: </div>
277: <?php } ?>
278:
279: <div class="page-list_icon">
280: <a href="../../../index.php?p=pages&title=<?php echo js_encode($page->getTitlelink()); ?>" title="<?php echo gettext("View page"); ?>">
281: <img src="images/view.png" alt="" title="<?php echo gettext("view"); ?>" />
282: </a>
283: </div>
284:
285: <?php
286: if (checkIfLockedPage($page)) {
287: if (extensionEnabled('hitcounter')) {
288: ?>
289: <div class="page-list_icon">
290: <a href="?hitcounter=1&titlelink=<?php echo html_encode($page->getTitlelink()); ?>&add&XSRFToken=<?php echo getXSRFToken('hitcounter') ?>" title="<?php echo gettext("Reset hitcounter"); ?>">
291: <img src="../../images/reset.png" alt="" title="<?php echo gettext("Reset hitcounter"); ?>" /></a>
292: </div>
293: <?php
294: }
295: ?>
296: <div class="page-list_icon">
297: <a href="javascript:confirmDelete('admin-pages.php?delete=<?php echo $page->getTitlelink(); ?>&add&XSRFToken=<?php echo getXSRFToken('delete') ?>',deletePage)" title="<?php echo gettext("Delete page"); ?>">
298: <img src="../../images/fail.png" alt="" title="<?php echo gettext("delete"); ?>" /></a>
299: </div>
300: <div class="page-list_icon">
301: <input class="checkbox" type="checkbox" name="ids[]" value="<?php echo $page->getTitlelink(); ?>" onclick="triggerAllBox(this.form, 'ids[]', this.form.allbox);" />
302: </div>
303: <?php } else { ?>
304: <div class="page-list_icon">
305: <img src="../../images/icon_inactive.png" alt="" title="<?php gettext('locked'); ?>" />
306: </div>
307: <div class="page-list_icon">
308: <img src="../../images/icon_inactive.png" alt="" title="<?php gettext('locked'); ?>" />
309: </div>
310: <div class="page-list_icon">
311: <img src="../../images/icon_inactive.png" alt="" title="<?php gettext('locked'); ?>" />
312: </div>
313: <?php } ?>
314: </div><!-- icon wrapper end -->
315: </div>
316: <?php
317: }
318:
319: 320: 321:
322:
323: 324: 325: 326: 327: 328: 329: 330:
331: function updateArticle(&$reports, $newarticle = false) {
332: $date = date('Y-m-d_H-i-s');
333: $title = process_language_string_save("title", 2);
334: $author = sanitize($_POST['author']);
335: $content = zpFunctions::updateImageProcessorLink(process_language_string_save("content", EDITOR_SANITIZE_LEVEL));
336: $extracontent = zpFunctions::updateImageProcessorLink(process_language_string_save("extracontent", EDITOR_SANITIZE_LEVEL));
337: $custom = process_language_string_save("custom_data", 1);
338: $show = getcheckboxState('show');
339: $date = sanitize($_POST['date']);
340: $expiredate = getExpiryDatePost();
341: $permalink = getcheckboxState('permalink');
342: $lastchange = sanitize($_POST['lastchange']);
343: $lastchangeauthor = sanitize($_POST['lastchangeauthor']);
344: $commentson = getcheckboxState('commentson');
345: if (zp_loggedin(CODEBLOCK_RIGHTS)) {
346: $codeblock = processCodeblockSave(0);
347: }
348: $locked = getcheckboxState('locked');
349: if ($newarticle) {
350: $titlelink = seoFriendly(get_language_string($title));
351: if (empty($titlelink)) {
352: $titlelink = seoFriendly($date);
353: }
354: $sql = 'SELECT `id` FROM ' . prefix('news') . ' WHERE `titlelink`=' . db_quote($titlelink);
355: $rslt = query_single_row($sql, false);
356: if ($rslt) {
357:
358: $time = explode(' ', microtime());
359: $titlelink = $titlelink . '_' . ($time[1] + $time[0]);
360: $reports[] = "<p class='warningbox fade-message'>" . gettext('Duplicate article title') . '</p>';
361: }
362: $oldtitlelink = $titlelink;
363: $id = 0;
364: } else {
365: $titlelink = $oldtitlelink = sanitize($_POST['titlelink-old'], 3);
366: $id = sanitize($_POST['id']);
367: }
368:
369: if (getcheckboxState('edittitlelink')) {
370: $titlelink = sanitize($_POST['titlelink'], 3);
371: if (empty($titlelink)) {
372: $titlelink = seoFriendly(get_language_string($title));
373: if (empty($titlelink)) {
374: $titlelink = seoFriendly($date);
375: }
376: }
377: } else {
378: if (!$permalink) {
379: $link = seoFriendly(get_language_string($title));
380: if (!empty($link)) {
381: $titlelink = $link;
382: }
383: }
384: }
385:
386: $rslt = true;
387: if ($titlelink != $oldtitlelink) {
388: $rslt = query('UPDATE ' . prefix('news') . ' SET `titlelink`=' . db_quote($titlelink) . ' WHERE `id`=' . $id, false);
389: if (!$rslt) {
390: $titlelink = $oldtitlelink;
391: } else {
392: SearchEngine::clearSearchCache();
393: }
394: }
395:
396: $article = new ZenpageNews($titlelink, true);
397: $article->setTitle($title);
398: $article->setContent($content);
399: $article->setExtracontent($extracontent);
400: $article->setCustomData(zp_apply_filter('save_article_custom_data', $custom, $article));
401: $article->setShow($show);
402: $article->setDateTime($date);
403: $article->setCommentsAllowed($commentson);
404: if (zp_loggedin(CODEBLOCK_RIGHTS)) {
405: $article->setCodeblock($codeblock);
406: }
407: $article->setAuthor($author);
408: $article->setLastchange($lastchange);
409: $article->setLastchangeauthor($lastchangeauthor);
410: $article->setPermalink($permalink);
411: $article->setLocked($locked);
412: $article->setExpiredate($expiredate);
413: $article->setSticky(sanitize_numeric($_POST['sticky']));
414: if (getcheckboxState('resethitcounter')) {
415: $article->set('hitcounter', 0);
416: }
417: if (getcheckboxState('reset_rating')) {
418: $article->set('total_value', 0);
419: $article->set('total_votes', 0);
420: $article->set('used_ips', 0);
421: }
422: $article->setTruncation(getcheckboxState('truncation'));
423: processTags($article);
424: $categories = array();
425: $result2 = query_full_array("SELECT * FROM " . prefix('news_categories') . " ORDER BY titlelink");
426: foreach ($result2 as $cat) {
427: if (isset($_POST["cat" . $cat['id']])) {
428: $categories[] = $cat['titlelink'];
429: }
430: }
431: $article->setCategories($categories);
432: if ($newarticle) {
433: $msg = zp_apply_filter('new_article', '', $article);
434: if (empty($title)) {
435: $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("Article <em>%s</em> added but you need to give it a <strong>title</strong> before publishing!"), get_language_string($titlelink)) . '</p>';
436: } else {
437: $reports[] = "<p class='messagebox fade-message'>" . sprintf(gettext("Article <em>%s</em> added"), $titlelink) . '</p>';
438: }
439: } else {
440: $msg = zp_apply_filter('update_article', '', $article, $oldtitlelink);
441: if (!$rslt) {
442: $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("An article with the title/titlelink <em>%s</em> already exists!"), $titlelink) . '</p>';
443: } else if (empty($title)) {
444: $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("Article <em>%s</em> updated but you need to give it a <strong>title</strong> before publishing!"), get_language_string($titlelink)) . '</p>';
445: } else {
446: $reports[] = "<p class='messagebox fade-message'>" . sprintf(gettext("Article <em>%s</em> updated"), $titlelink) . '</p>';
447: }
448: }
449: $article->save();
450:
451: if ($msg) {
452: $reports[] = $msg;
453: }
454: return $article;
455: }
456:
457: 458: 459: 460:
461: function deleteArticle($titlelink) {
462: if (is_object($titlelink)) {
463: $obj = $titlelink;
464: } else {
465: $obj = new ZenpageNews($titlelink);
466: }
467: $result = $obj->remove();
468: if ($result) {
469: if (is_object($titlelink)) {
470: header('Location: ' . FULLWEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/zenpage/admin-news-articles.php?deleted');
471: exitZP();
472: }
473: SearchEngine::clearSearchCache();
474: return "<p class='messagebox fade-message'>" . gettext("Article successfully deleted!") . "</p>";
475: }
476: return "<p class='errorbox fade-message'>" . gettext("Article delete failed!") . "</p>";
477: }
478:
479: 480: 481: 482: 483:
484: function printArticleCategories($obj) {
485: $cat = $obj->getCategories();
486: $number = 0;
487: foreach ($cat as $cats) {
488: $number++;
489: if ($number != 1) {
490: echo ", ";
491: }
492: echo get_language_string($cats['title']);
493: }
494: }
495:
496: 497: 498: 499: 500:
501: function printPageArticleTags($obj) {
502: $tags = $obj->getTags();
503: $number = 0;
504: foreach ($tags as $tag) {
505: $number++;
506: if ($number != 1) {
507: echo ", ";
508: }
509: echo get_language_string($tag);
510: }
511: }
512:
513: 514: 515: 516: 517: 518:
519: function printCategorySelection($id = '', $option = '') {
520: global $_zp_zenpage;
521:
522: $selected = '';
523: echo "<ul class='zenpagechecklist'>\n";
524: $all_cats = $_zp_zenpage->getAllCategories(false);
525: foreach ($all_cats as $cats) {
526: $catobj = new ZenpageCategory($cats['titlelink']);
527: if ($option != "all") {
528: $cat2news = query_single_row("SELECT cat_id FROM " . prefix('news2cat') . " WHERE news_id = " . $id . " AND cat_id = " . $catobj->getID());
529: if ($cat2news['cat_id'] != "") {
530: $selected = "checked ='checked'";
531: }
532: }
533: $catname = $catobj->getTitle();
534: $catlink = $catobj->getTitlelink();
535: if ($catobj->getPassword()) {
536: $protected = '<img src="' . WEBPATH . '/' . ZENFOLDER . '/images/lock.png" alt="' . gettext('password protected') . '" />';
537: } else {
538: $protected = '';
539: }
540: $catid = $catobj->getID();
541: echo "<li class=\"hasimage\" ><label for='cat" . $catid . "'><input name='cat" . $catid . "' id='cat" . $catid . "' type='checkbox' value='" . $catid . "' " . $selected . " />" . $catname . " " . $protected . "</label></li>\n";
542: }
543: echo "</ul>\n";
544: }
545:
546: 547: 548: 549:
550: function printArticleDatesDropdown() {
551: global $_zp_zenpage, $subpage;
552: $datecount = $_zp_zenpage->getAllArticleDates();
553: $lastyear = "";
554: $nr = "";
555: $option = getNewsAdminOption(array('category' => 0, 'published' => 0, 'sortorder' => 0, 'articles_page' => 1));
556: if (!isset($_GET['date'])) {
557: $selected = 'selected="selected"';
558: } else {
559: $selected = "";
560: }
561: ?>
562: <form name="AutoListBox1" id="articledatesdropdown" style="float:left; margin-left: 10px;" action="#" >
563: <select name="ListBoxURL" size="1" onchange="gotoLink(this.form)">
564: <?php
565: echo "<option $selected value='admin-news-articles.php" . getNewsAdminOptionPath(array_merge(array('' => ''), $option)) . "'>" . gettext("View all months") . "</option>";
566: while (list($key, $val) = each($datecount)) {
567: $nr++;
568: if ($key == '0000-00-01') {
569: $year = "no date";
570: $month = "";
571: } else {
572: $dt = strftime('%Y-%B', strtotime($key));
573: $year = substr($dt, 0, 4);
574: $month = substr($dt, 5);
575: }
576: if (isset($_GET['category'])) {
577: $catlink = "&category=" . sanitize($_GET['category']);
578: } else {
579: $catlink = "";
580: }
581: $check = $month . "-" . $year;
582: if (isset($_GET['date']) AND $_GET['date'] == substr($key, 0, 7)) {
583: $selected = "selected='selected'";
584: } else {
585: $selected = "";
586: }
587: echo "<option $selected value='admin-news-articles.php" . getNewsAdminOptionPath(array_merge(array('date' => substr($key, 0, 7)), $option)) . "'>$month $year ($val)</option>\n";
588: }
589: ?>
590: </select>
591: <script type="text/javascript" >
592:
593: function gotoLink(form) {
594: var OptionIndex = form.ListBoxURL.selectedIndex;
595: parent.location = form.ListBoxURL.options[OptionIndex].value;
596: }
597:
598: </script>
599: </form>
600: <?php
601: }
602:
603: 604: 605: 606: 607: 608:
609: function getNewsAdminOption($test) {
610: $list = array();
611: foreach ($test as $item => $type) {
612: if (isset($_GET[$item])) {
613: if ($type) {
614: $list[$item] = (int) sanitize_numeric($_GET[$item]);
615: } else {
616: $list[$item] = sanitize($_GET[$item]);
617: }
618: }
619: }
620: return $list;
621: }
622:
623: 624: 625: 626: 627: 628:
629: function getNewsAdminOptionPath($list) {
630: $optionpath = '';
631: $char = '?';
632: foreach ($list as $p => $q) {
633: if ($q) {
634: $optionpath .= $char . $p . '=' . $q;
635: } else {
636: $optionpath .= $char . $p;
637: }
638: $char = '&';
639: }
640: return $optionpath;
641: }
642:
643: 644: 645: 646:
647: function printUnpublishedDropdown() {
648: global $_zp_zenpage;
649: ?>
650: <form name="AutoListBox3" id="unpublisheddropdown" style="float: left; margin-left: 10px;" action="#">
651: <select name="ListBoxURL" size="1" onchange="gotoLink(this.form)">
652: <?php
653: $all = "";
654: $published = "";
655: $unpublished = "";
656: $sticky = '';
657: if (isset($_GET['published'])) {
658: switch ($_GET['published']) {
659: case "no":
660: $unpublished = "selected='selected'";
661: break;
662: case "yes":
663: $published = "selected='selected'";
664: break;
665: case 'sticky':
666: $sticky = "selected='selected'";
667: break;
668: }
669: } else {
670: $all = "selected='selected'";
671: }
672: $option = getNewsAdminOption(array('category' => 0, 'date' => 0, 'sortorder' => 0, 'articles_page' => 1));
673: echo "<option $all value='admin-news-articles.php" . getNewsAdminOptionPath($option) . "'>" . gettext("All articles") . "</option>\n";
674: echo "<option $published value='admin-news-articles.php" . getNewsAdminOptionPath(array_merge(array('published' => 'yes'), $option)) . "'>" . gettext("Published") . "</option>\n";
675: echo "<option $unpublished value='admin-news-articles.php" . getNewsAdminOptionPath(array_merge(array('published' => 'no'), $option)) . "'>" . gettext("Un-published") . "</option>\n";
676: echo "<option $sticky value='admin-news-articles.php" . getNewsAdminOptionPath(array_merge(array('published' => 'sticky'), $option)) . "'>" . gettext("Sticky") . "</option>\n";
677: ?>
678: </select>
679: <script type="text/javascript">
680:
681: function gotoLink(form) {
682: var OptionIndex = form.ListBoxURL.selectedIndex;
683: parent.location = form.ListBoxURL.options[OptionIndex].value;
684: }
685:
686: </script>
687: </form>
688: <?php
689: }
690:
691: 692: 693: 694:
695: function printSortOrderDropdown() {
696: global $_zp_zenpage;
697: ?>
698: <form name="AutoListBox4" id="sortorderdropdown" style="float: left; margin-left: 10px;" action="#">
699: <select name="ListBoxURL" size="1" onchange="gotoLink(this.form)">
700: <?php
701: $orderdate_desc = '';
702: $orderdate_asc = '';
703: $ordertitle_desc = '';
704: $ordertitle_asc = '';
705: if (isset($_GET['sortorder'])) {
706: switch ($_GET['sortorder']) {
707: case "date-desc":
708: $orderdate_desc = "selected='selected'";
709: break;
710: case "date-asc":
711: $orderdate_asc = "selected='selected'";
712: break;
713: case "title-desc":
714: $ordertitle_desc = "selected='selected'";
715: break;
716: case "title-asc":
717: $ordertitle_asc = "selected='selected'";
718: break;
719: }
720: } else {
721: $orderdate_desc = "selected='selected'";
722: }
723: $option = getNewsAdminOption(array('category' => 0, 'date' => 0, 'published' => 0, 'articles_page' => 1));
724: echo "<option $orderdate_desc value='admin-news-articles.php" . getNewsAdminOptionPath(array_merge(array('sortorder' => 'date-desc'), $option)) . "'>" . gettext("Order by date descending") . "</option>\n";
725: echo "<option $orderdate_asc value='admin-news-articles.php" . getNewsAdminOptionPath(array_merge(array('sortorder' => 'date-asc'), $option)) . "'>" . gettext("Order by date ascending") . "</option>\n";
726: echo "<option $ordertitle_desc value='admin-news-articles.php" . getNewsAdminOptionPath(array_merge(array('sortorder' => 'title-desc'), $option)) . "'>" . gettext("Order by title descending") . "</option>\n";
727: echo "<option $ordertitle_asc value='admin-news-articles.php" . getNewsAdminOptionPath(array_merge(array('sortorder' => 'title-asc'), $option)) . "'>" . gettext("Order by title ascending") . "</option>\n";
728: ?>
729: </select>
730: <script type="text/javascript">
731:
732: function gotoLink(form) {
733: var OptionIndex = form.ListBoxURL.selectedIndex;
734: parent.location = form.ListBoxURL.options[OptionIndex].value;
735: }
736:
737: </script>
738: </form>
739: <?php
740: }
741:
742: 743: 744: 745:
746: function printCategoryDropdown() {
747: global $_zp_zenpage;
748: $result = $_zp_zenpage->getAllCategories(false);
749: if (isset($_GET['date'])) {
750: $datelink = "&date=" . sanitize($_GET['date']);
751: $datelinkall = "?date=" . sanitize($_GET['date']);
752: } else {
753: $datelink = "";
754: $datelinkall = "";
755: }
756:
757: if (isset($_GET['category'])) {
758: $selected = '';
759: $category = sanitize($_GET['category']);
760: } else {
761: $selected = "selected='selected'";
762: $category = "";
763: }
764: ?>
765: <form name ="AutoListBox2" id="categorydropdown" style="float:left" action="#" >
766: <select name="ListBoxURL" size="1" onchange="gotoLink(this.form)">
767: <?php
768: $option = getNewsAdminOption(array('date' => 0, 'published' => 0, 'sortorder' => 0, 'articles_page' => 1));
769: echo "<option $selected value='admin-news-articles.php" . getNewsAdminOptionPath($option) . "'>" . gettext("All categories") . "</option>\n";
770:
771: foreach ($result as $cat) {
772: $catobj = new ZenpageCategory($cat['titlelink']);
773:
774: $count = count($catobj->getArticles(0, 'all'));
775: $count = " (" . $count . ")";
776: if ($category == $cat['titlelink']) {
777: $selected = "selected='selected'";
778: } else {
779: $selected = "";
780: }
781:
782: $getparents = $catobj->getParents();
783: $levelmark = '';
784: foreach ($getparents as $parent) {
785: $levelmark .= '» ';
786: }
787: $title = $catobj->getTitle();
788: if (empty($title)) {
789: $title = '*' . $catobj->getTitlelink() . '*';
790: }
791: if ($count != " (0)") {
792: echo "<option $selected value='admin-news-articles.php" . getNewsAdminOptionPath(array_merge(array('category' => $catobj->getTitlelink()), $option)) . "'>" . $levelmark . $title . $count . "</option>\n";
793: }
794: }
795: ?>
796: </select>
797: <script type="text/javascript" >
798:
799: function gotoLink(form) {
800: var OptionIndex = form.ListBoxURL.selectedIndex;
801: parent.location = form.ListBoxURL.options[OptionIndex].value;
802: }
803:
804: </script>
805: </form>
806: <?php
807: }
808:
809: 810: 811: 812:
813: function printArticlesPerPageDropdown() {
814: global $_zp_zenpage, $subpage, $articles_page;
815: ?>
816: <form name="AutoListBox5" id="articlesperpagedropdown" method="POST" style="float: left; margin-left: 10px;" action="#">
817: <select name="ListBoxURL" size="1" onchange="gotoLink(this.form)">
818: <?php
819: $option = getNewsAdminOption(array('category' => 0, 'date' => 0, 'published' => 0, 'sortorder' => 0));
820: $list = array_unique(array(15, 30, 60, max(1, getOption('articles_per_page'))));
821: sort($list);
822: foreach ($list as $count) {
823: ?>
824: <option <?php if ($articles_page == $count) echo 'selected="selected"'; ?> value="admin-news-articles.php<?php echo getNewsAdminOptionPath(array_merge(array('articles_page' => $count, 'subpage' => (int) ($subpage * $articles_page / $count)), $option)); ?>"><?php printf(gettext('%u per page'), $count); ?></option>
825: <?php
826: }
827: ?>
828: <option <?php if ($articles_page == 0) echo 'selected="selected"'; ?> value="admin-news-articles.php<?php echo getNewsAdminOptionPath(array_merge(array('articles_page' => 'all'), $option)); ?>"><?php echo gettext("All"); ?></option>
829:
830: </select>
831: <script type="text/javascript">
832:
833: function gotoLink(form) {
834: var OptionIndex = form.ListBoxURL.selectedIndex;
835: parent.location = form.ListBoxURL.options[OptionIndex].value;
836: }
837:
838: </script>
839:
840: </form>
841: <?php
842: }
843:
844: 845: 846:
847:
848: 849: 850: 851: 852: 853: 854:
855: function updateCategory(&$reports, $newcategory = false) {
856: $date = date('Y-m-d_H-i-s');
857: $id = sanitize_numeric($_POST['id']);
858: $permalink = getcheckboxState('permalink');
859: $title = process_language_string_save("title", 2);
860: $desc = process_language_string_save("desc", EDITOR_SANITIZE_LEVEL);
861: $custom = process_language_string_save("custom_data", 1);
862:
863: if ($newcategory) {
864: $titlelink = seoFriendly(get_language_string($title));
865: if (empty($titlelink))
866: $titlelink = seoFriendly($date);
867: $sql = 'SELECT `id` FROM ' . prefix('news_categories') . ' WHERE `titlelink`=' . db_quote($titlelink);
868: $rslt = query_single_row($sql, false);
869: if ($rslt) {
870:
871: $time = explode(' ', microtime());
872: $titlelink = $titlelink . '_' . ($time[1] + $time[0]);
873: $reports[] = "<p class='warningbox fade-message'>" . gettext('Duplicate category title') . '</p>';
874: }
875: $oldtitlelink = $titlelink;
876: } else {
877: $titlelink = $oldtitlelink = sanitize($_POST['titlelink-old'], 3);
878: if (getcheckboxState('edittitlelink')) {
879: $titlelink = sanitize($_POST['titlelink'], 3);
880: if (empty($titlelink)) {
881: $titlelink = seoFriendly(get_language_string($title));
882: if (empty($titlelink)) {
883: $titlelink = seoFriendly($date);
884: }
885: }
886: } else {
887: if (!$permalink) {
888: $link = seoFriendly(get_language_string($title));
889: if (!empty($link)) {
890: $titlelink = $link;
891: }
892: }
893: }
894: }
895: $titleok = true;
896: if ($titlelink != $oldtitlelink) {
897: $titleok = query('UPDATE ' . prefix('news_categories') . ' SET `titlelink`=' . db_quote($titlelink) . ' WHERE `id`=' . $id, false);
898: if (!$titleok) {
899: $titlelink = $oldtitlelink;
900: } else {
901: SearchEngine::clearSearchCache();
902: }
903: }
904:
905: $show = getcheckboxState('show');
906: $cat = new ZenpageCategory($titlelink, true);
907: $notice = processCredentials($cat);
908: $cat->setPermalink(getcheckboxState('permalink'));
909: $cat->set('title', $title);
910: $cat->setDesc($desc);
911: $cat->setCustomData(zp_apply_filter('save_category_custom_data', $custom, $cat));
912: $cat->setShow($show);
913: if (getcheckboxState('resethitcounter')) {
914: $cat->set('hitcounter', 0);
915: }
916: if (getcheckboxState('reset_rating')) {
917: $cat->set('total_value', 0);
918: $cat->set('total_votes', 0);
919: $cat->set('used_ips', 0);
920: }
921:
922: if ($newcategory) {
923: $msg = zp_apply_filter('new_category', '', $cat);
924: if (empty($title)) {
925: $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("Category <em>%s</em> added but you need to give it a <strong>title</strong> before publishing!"), $titlelink) . '</p>';
926: } else if ($notice == '?mismatch=user') {
927: $reports[] = "<p class='errorbox fade-message'>" . gettext('You must supply a password for the Protected Category user') . '</p>';
928: } else if ($notice) {
929: $reports[] = "<p class='errorbox fade-message'>" . gettext('Your passwords were empty or did not match') . '</p>';
930: } else {
931: $reports[] = "<p class='messagebox fade-message'>" . sprintf(gettext("Category <em>%s</em> added"), $titlelink) . '</p>';
932: }
933: } else {
934: $msg = zp_apply_filter('update_category', '', $cat, $oldtitlelink);
935: if ($titleok) {
936: if (empty($titlelink) OR empty($title)) {
937: $reports[] = "<p class='errorbox fade-message'>" . gettext("You forgot to give your category a <strong>title or titlelink</strong>!") . "</p>";
938: } else if ($notice == '?mismatch=user') {
939: $reports[] = "<p class='errorbox fade-message'>" . gettext('You must supply a password for the Protected Category user') . '</p>';
940: } else if ($notice) {
941: $reports[] = "<p class='errorbox fade-message'>" . gettext('Your passwords were empty or did not match') . '</p>';
942: } else {
943: $reports[] = "<p class='messagebox fade-message'>" . gettext("Category updated!") . "</p>";
944: }
945: } else {
946: $reports[] = "<p class='errorbox fade-message'>" . sprintf(gettext("A category with the title/titlelink <em>%s</em> already exists!"), html_encode($cat->getTitle())) . "</p>";
947: }
948: }
949: $cat->save();
950: if ($msg) {
951: $reports[] = $msg;
952: }
953: return $cat;
954: }
955:
956: 957: 958: 959:
960: function deleteCategory($titlelink) {
961: $obj = new ZenpageCategory($titlelink);
962: $result = $obj->remove();
963: if ($result) {
964: SearchEngine::clearSearchCache();
965: return "<p class='messagebox fade-message'>" . gettext("Category successfully deleted!") . "</p>";
966: }
967: return "<p class='errorbox fade-message'>" . gettext("Category delete failed!") . "</p>";
968: }
969:
970: 971: 972: 973: 974: 975: 976:
977: function printCategoryListSortableTable($cat, $flag) {
978: global $_zp_zenpage;
979: if ($flag) {
980: $img = '../../images/drag_handle_flag.png';
981: } else {
982: $img = '../../images/drag_handle.png';
983: }
984: $count = count($cat->getArticles(0, false));
985: if ($cat->getTitle()) {
986: $cattitle = $cat->getTitle();
987: } else {
988: $cattitle = "<span style='color:red; font-weight: bold'> <strong>*</strong>" . $cat->getTitlelink() . "*</span>";
989: }
990: ?>
991: <div class='page-list_row'>
992: <div class='page-list_title' >
993: <?php echo "<a href='admin-edit.php?newscategory&titlelink=" . $cat->getTitlelink() . "' title='" . gettext('Edit this category') . "'>" . $cattitle . "</a>" . checkHitcounterDisplay($cat->getHitcounter()); ?>
994: </div>
995: <div class="page-list_extra">
996: <?php echo $count; ?>
997: <?php echo gettext("articles"); ?>
998: </div>
999:
1000: <div class="page-list_iconwrapper">
1001: <div class="page-list_icon"><?php
1002: $password = $cat->getPassword();
1003: if (!empty($password)) {
1004: echo '<img src="../../images/lock.png" style="border: 0px;" alt="' . gettext('Password protected') . '" title="' . gettext('Password protected') . '" />';
1005: }
1006: ?>
1007: </div>
1008: <div class="page-list_icon">
1009: <?php
1010: if ($cat->getShow()) {
1011: $title = gettext("Un-publish");
1012: ?>
1013: <a href="?publish=0&titlelink=<?php echo html_encode($cat->getTitlelink()); ?>&XSRFToken=<?php echo getXSRFToken('update') ?>" title="<?php echo $title; ?>">
1014: <img src="../../images/pass.png" alt="<?php gettext("Scheduled for published"); ?>" title="<?php echo $title; ?>" /></a>
1015: <?php
1016: } else {
1017: $title = gettext("Publish");
1018: ?>
1019: <a href="?publish=1&titlelink=<?php echo html_encode($cat->getTitlelink()); ?>&XSRFToken=<?php echo getXSRFToken('update') ?>" title="<?php echo $title; ?>">
1020: <img src="../../images/action.png" alt="<?php echo gettext("Un-published"); ?>" title="<?php echo $title; ?>" /></a>
1021: <?php
1022: }
1023: ?>
1024: </div>
1025: <div class="page-list_icon">
1026: <?php if ($count == 0) { ?>
1027: <img src="../../images/icon_inactive.png" alt="<?php gettext('locked'); ?>" />
1028: <?php
1029: } else {
1030: ?>
1031: <a href="../../../index.php?p=news&category=<?php echo js_encode($cat->getTitlelink()); ?>" title="<?php echo gettext("View category"); ?>">
1032: <img src="images/view.png" alt="view" />
1033: </a>
1034: <?php } ?>
1035: </div>
1036: <?php
1037: if (extensionEnabled('hitcounter')) {
1038: ?>
1039: <div class="page-list_icon"><a
1040: href="?hitcounter=1&id=<?php echo $cat->getID(); ?>&tab=categories&XSRFToken=<?php echo getXSRFToken('hitcounter') ?>"
1041: title="<?php echo gettext("Reset hitcounter"); ?>"> <img
1042: src="../../images/reset.png"
1043: alt="<?php echo gettext("Reset hitcounter"); ?>" /> </a>
1044: </div>
1045: <?php
1046: }
1047: ?>
1048: <div class="page-list_icon"><a
1049: href="javascript:confirmDelete('admin-categories.php?delete=<?php echo js_encode($cat->getTitlelink()); ?>&tab=categories&XSRFToken=<?php echo getXSRFToken('delete_category') ?>',deleteCategory)"
1050: title="<?php echo gettext("Delete Category"); ?>"><img
1051: src="../../images/fail.png" alt="<?php echo gettext("Delete"); ?>"
1052: title="<?php echo gettext("Delete Category"); ?>" /></a>
1053: </div>
1054: <div class="page-list_icon"><input class="checkbox" type="checkbox" name="ids[]" value="<?php echo $cat->getTitlelink(); ?>"
1055: onclick="triggerAllBox(this.form, 'ids[]', this.form.allbox);" />
1056: </div>
1057: </div>
1058: </div>
1059: <?php
1060: }
1061:
1062: 1063: 1064: 1065: 1066: 1067:
1068: function printCategoryCheckboxListEntry($cat, $articleid, $option, $class = '') {
1069: $selected = '';
1070: if (($option != "all") && !$cat->transient && !empty($articleid)) {
1071: $cat2news = query_single_row("SELECT cat_id FROM " . prefix('news2cat') . " WHERE news_id = " . $articleid . " AND cat_id = " . $cat->getID());
1072: if ($cat2news['cat_id'] != "") {
1073: $selected = "checked ='checked'";
1074: } else {
1075: $selected = "";
1076: }
1077: }
1078: $catname = $cat->getTitle();
1079: $catlink = $cat->getTitlelink();
1080: if ($cat->getPassword()) {
1081: $protected = '<img src="' . WEBPATH . '/' . ZENFOLDER . '/images/lock.png" alt="' . gettext('password protected') . '" />';
1082: } else {
1083: $protected = '';
1084: }
1085: $catid = $cat->getID();
1086: echo '<label for="cat' . $catid . '"><input name="cat' . $catid . '" class="' . $class . '" id="cat' . $catid . '" type="checkbox" value="' . $catid . '"' . $selected . ' />' . $catname . ' ' . $protected . "</label>\n";
1087: }
1088:
1089: 1090: 1091:
1092:
1093: 1094: 1095: 1096: 1097: 1098: 1099: 1100: 1101: 1102:
1103: function printNestedItemsList($listtype = 'cats-sortablelist', $articleid = '', $option = '', $class = 'nestedItem') {
1104: global $_zp_zenpage;
1105: switch ($listtype) {
1106: case 'cats-checkboxlist':
1107: default:
1108: $ulclass = "";
1109: break;
1110: case 'cats-sortablelist':
1111: case 'pages-sortablelist':
1112: $ulclass = " class=\"page-list\"";
1113: break;
1114: }
1115: switch ($listtype) {
1116: case 'cats-checkboxlist':
1117: case 'cats-sortablelist':
1118:
1119: $_zp_zenpage = new Zenpage();
1120: $items = $_zp_zenpage->getAllCategories(false);
1121: break;
1122: case 'pages-sortablelist':
1123: $items = $_zp_zenpage->getPages(false);
1124: break;
1125: default:
1126: $items = array();
1127: break;
1128: }
1129: $indent = 1;
1130: $open = array(1 => 0);
1131: $rslt = false;
1132: foreach ($items as $item) {
1133: switch ($listtype) {
1134: case 'cats-checkboxlist':
1135: case 'cats-sortablelist':
1136: $itemobj = new ZenpageCategory($item['titlelink']);
1137: $ismypage = $itemobj->isMyItem(ZENPAGE_NEWS_RIGHTS);
1138: break;
1139: case 'pages-sortablelist':
1140: $itemobj = new ZenpagePage($item['titlelink']);
1141: $ismypage = $itemobj->isMyItem(ZENPAGE_PAGES_RIGHTS);
1142: break;
1143: }
1144: $itemsortorder = $itemobj->getSortOrder();
1145: $itemid = $itemobj->getID();
1146: if ($ismypage) {
1147: $order = explode('-', $itemsortorder);
1148: $level = max(1, count($order));
1149: if ($toodeep = $level > 1 && $order[$level - 1] === '') {
1150: $rslt = true;
1151: }
1152: if ($level > $indent) {
1153: echo "\n" . str_pad("\t", $indent, "\t") . "<ul" . $ulclass . ">\n";
1154: $indent++;
1155: $open[$indent] = 0;
1156: } else if ($level < $indent) {
1157: while ($indent > $level) {
1158: $open[$indent] --;
1159: $indent--;
1160: echo "</li>\n" . str_pad("\t", $indent, "\t") . "</ul>\n";
1161: }
1162: } else {
1163: if ($open[$indent]) {
1164: echo str_pad("\t", $indent, "\t") . "</li>\n";
1165: $open[$indent] --;
1166: } else {
1167: echo "\n";
1168: }
1169: }
1170: if ($open[$indent]) {
1171: echo str_pad("\t", $indent, "\t") . "</li>\n";
1172: $open[$indent] --;
1173: }
1174: switch ($listtype) {
1175: case 'cats-checkboxlist':
1176: echo "<li>\n";
1177: printCategoryCheckboxListEntry($itemobj, $articleid, $option, $class);
1178: break;
1179: case 'cats-sortablelist':
1180: echo str_pad("\t", $indent - 1, "\t") . "<li id=\"id_" . $itemid . "\">";
1181: printCategoryListSortableTable($itemobj, $toodeep);
1182: break;
1183: case 'pages-sortablelist':
1184: echo str_pad("\t", $indent - 1, "\t") . "<li id=\"id_" . $itemid . "\">";
1185: printPagesListTable($itemobj, $toodeep);
1186: break;
1187: }
1188: $open[$indent] ++;
1189: }
1190: }
1191: while ($indent > 1) {
1192: echo "</li>\n";
1193: $open[$indent] --;
1194: $indent--;
1195: echo str_pad("\t", $indent, "\t") . "</ul>";
1196: }
1197: if ($open[$indent]) {
1198: echo "</li>\n";
1199: } else {
1200: echo "\n";
1201: }
1202: return $rslt;
1203: }
1204:
1205: 1206: 1207: 1208: 1209: 1210:
1211: function updateItemSortorder($mode = 'pages') {
1212: if (!empty($_POST['order'])) {
1213: $order = processOrder($_POST['order']);
1214: $parents = array('NULL');
1215: foreach ($order as $id => $orderlist) {
1216: $id = str_replace('id_', '', $id);
1217: $level = count($orderlist);
1218: $parents[$level] = $id;
1219: $myparent = $parents[$level - 1];
1220: switch ($mode) {
1221: case 'pages':
1222: $dbtable = prefix('pages');
1223: break;
1224: case 'categories':
1225: $dbtable = prefix('news_categories');
1226: break;
1227: }
1228: $sql = "UPDATE " . $dbtable . " SET `sort_order` = " . db_quote(implode('-', $orderlist)) . ", `parentid`= " . $myparent . " WHERE `id`=" . $id;
1229: query($sql);
1230: }
1231: return true;
1232: }
1233: return false;
1234: }
1235:
1236: 1237: 1238: 1239: 1240: 1241:
1242: function checkForEmptyTitle($titlefield, $type, $truncate = true) {
1243: switch ($type) {
1244: case "page":
1245: $text = gettext("Untitled page");
1246: break;
1247: case "news":
1248: $text = gettext("Untitled article");
1249: break;
1250: case "category":
1251: $text = gettext("Untitled category");
1252: break;
1253: }
1254: $title = getBare($titlefield);
1255: if ($title) {
1256: if ($truncate) {
1257: $title = truncate_string($title, 40);
1258: }
1259: } else {
1260: $title = "<span style='color:red; font-weight: bold'>" . $text . "</span>";
1261: }
1262: echo $title;
1263: }
1264:
1265: 1266: 1267: 1268: 1269: 1270: 1271:
1272: function zenpagePublish($obj, $show) {
1273: if ($show > 1) {
1274: $obj->setExpireDate(NULL);
1275: }
1276: $obj->setShow((int) ($show && 1));
1277: $obj->save();
1278: }
1279:
1280: 1281: 1282: 1283: 1284: 1285:
1286: function skipScheduledPublishing($obj) {
1287: $obj->setDateTime(date('Y-m-d H:i:s'));
1288: $obj->setShow(1);
1289: $obj->save();
1290: }
1291:
1292: 1293: 1294: 1295: 1296: 1297:
1298: function checkHitcounterDisplay($item) {
1299: if ($item == 0) {
1300: $hitcount = "";
1301: } else {
1302: if ($item == 1) {
1303: $hits = gettext("hit");
1304: } else {
1305: $hits = gettext("hits");
1306: }
1307: $hitcount = " (" . $item . " " . $hits . ")";
1308: }
1309: return $hitcount;
1310: }
1311:
1312: 1313: 1314: 1315: 1316:
1317: function getNewsPagesStatistic($option) {
1318: global $_zp_zenpage;
1319: switch ($option) {
1320: case "news":
1321: $items = $_zp_zenpage->getArticles();
1322: $type = gettext("Articles");
1323: break;
1324: case "pages":
1325: $items = $_zp_zenpage->getPages(false);
1326: $type = gettext("Pages");
1327: break;
1328: case "categories":
1329: $type = gettext("Categories");
1330: $items = $_zp_zenpage->getAllCategories(false);
1331: break;
1332: }
1333: $total = count($items);
1334: $pub = 0;
1335: foreach ($items as $item) {
1336: switch ($option) {
1337: case "news":
1338: $itemobj = new ZenpageNews($item['titlelink']);
1339: break;
1340: case "pages":
1341: $itemobj = new ZenpagePage($item['titlelink']);
1342: break;
1343: case "categories":
1344: $itemobj = new ZenpageCategory($item['titlelink']);
1345: break;
1346: }
1347: if ($itemobj->getShow() == 1) {
1348: $pub++;
1349: }
1350: }
1351: $unpub = $total - $pub;
1352: return array($total, $type, $unpub);
1353: }
1354:
1355: function printPagesStatistic() {
1356: list($total, $type, $unpub) = getNewsPagesStatistic("pages");
1357: if (empty($unpub)) {
1358: printf(ngettext('<strong>%1$u</strong> page', '<strong>%1$u</strong> pages', $total), $total);
1359: } else {
1360: printf(ngettext('<strong>%1$u</strong> page (<strong>%2$u</strong> un-published)', '<strong>%1$u</strong> pages (<strong>%2$u</strong> un-published)', $total), $total, $unpub);
1361: }
1362: }
1363:
1364: function printNewsStatistic() {
1365: list($total, $type, $unpub) = getNewsPagesStatistic("news");
1366: if (empty($unpub)) {
1367: printf(ngettext('<strong>%1$u</strong> article', '<strong>%1$u</strong> articles', $total), $total);
1368: } else {
1369: printf(ngettext('<strong>%1$u</strong> article (<strong>%2$u</strong> un-published)', '<strong>%1$u</strong> articles (<strong>%2$u</strong> un-published)', $total), $total, $unpub);
1370: }
1371: }
1372:
1373: function printCategoriesStatistic() {
1374: list($total, $type, $unpub) = getNewsPagesStatistic("categories");
1375: if (empty($unpub)) {
1376: printf(ngettext('<strong>%1$u</strong> category', '<strong>%1$u</strong> categories', $total), $total);
1377: } else {
1378: printf(ngettext('<strong>%1$u</strong> category (<strong>%2$u</strong> un-published)', '<strong>%1$u</strong> categories (<strong>%2$u</strong> un-published)', $total), $total, $unpub);
1379: }
1380: }
1381:
1382: 1383: 1384: 1385: 1386: 1387: 1388:
1389: function zenpageJSCSS() {
1390: ?>
1391: <link rel="stylesheet" href="zenpage.css" type="text/css" />
1392: <script type="text/javascript">
1393:
1394: $(document).ready(function() {
1395: $("#tip a").click(function() {
1396: $("#tips").toggle("slow");
1397: });
1398: });
1399:
1400: </script>
1401: <?php
1402: }
1403:
1404: function printZenpageIconLegend() {
1405: ?>
1406: <ul class="iconlegend">
1407: <?php
1408: if (GALLERY_SECURITY == 'public') {
1409: ?>
1410: <li><img src="../../images/lock.png" alt="" /><?php echo gettext("Has Password"); ?></li> <li><img src="../../images/pass.png" alt="" /><img src="../../images/action.png" alt="" /><img src="images/clock.png" alt="" /><?php echo gettext("Published/Not published/Scheduled for publishing"); ?></li>
1411: <?php
1412: }
1413: ?>
1414: <li><img src="../../images/comments-on.png" alt="" /><img src="../../images/comments-off.png" alt="" /><?php echo gettext("Comments on/off"); ?></li>
1415: <li><img src="../../images/view.png" alt="" /><?php echo gettext("View"); ?></li>
1416: <?php
1417: if (extensionEnabled('hitcounter')) {
1418: ?>
1419: <li><img src="../../images/reset.png" alt="" /><?php echo gettext("Reset hitcounter"); ?></li>
1420: <?php
1421: }
1422: ?>
1423: <li><img src="../../images/fail.png" alt="" /><?php echo gettext("Delete"); ?></li>
1424: </ul>
1425: <?php
1426: }
1427:
1428: 1429: 1430: 1431: 1432:
1433: function authorSelector($author = NULL) {
1434: global $_zp_authority, $_zp_current_admin_obj;
1435: if (empty($author)) {
1436: $author = $_zp_current_admin_obj->getUser();
1437: }
1438: $authors = array($author => $author);
1439: if (zp_loggedin(MANAGE_ALL_PAGES_RIGHTS | MANAGE_ALL_NEWS_RIGHTS)) {
1440: $admins = $_zp_authority->getAdministrators();
1441: foreach ($admins as $admin) {
1442: if ($admin['rights'] & (ADMIN_RIGHTS | ZENPAGE_PAGES_RIGHTS | ZENPAGE_NEWS_RIGHTS)) {
1443: $authors[$admin['user']] = $admin['user'];
1444: }
1445: }
1446: }
1447: ?>
1448: <select size='1' name="author" id="author">
1449: <?php
1450: generateListFromArray(array($author), $authors, false, false);
1451: ?>
1452: </select>
1453: <?php
1454: }
1455:
1456: 1457: 1458: 1459: 1460: 1461:
1462: function printPublished($object) {
1463: $dt = $object->getDateTime();
1464: if ($dt > date('Y-m-d H:i:s')) {
1465: if ($object->getShow() != 1) {
1466: echo '<span class="inactivescheduledate">' . $dt . '</strong>';
1467: } else {
1468: echo '<span class="scheduledate">' . $dt . '</strong>';
1469: }
1470: } else {
1471: echo '<span>' . $dt . '</span>';
1472: }
1473: }
1474:
1475: 1476: 1477: 1478: 1479: 1480:
1481: function printExpired($object) {
1482: $dt = $object->getExpireDate();
1483: if (!empty($dt)) {
1484: $expired = $dt < date('Y-m-d H:i:s');
1485: if ($expired) {
1486: echo ' <span class="expired">' . $dt . "</span>";
1487: } else {
1488: echo ' <span class="expiredate">' . $dt . "</span>";
1489: }
1490: }
1491: }
1492:
1493: 1494: 1495: 1496: 1497: 1498:
1499: function printPublishIconLink($object, $type, $linkback = '') {
1500: $urladd = '';
1501: if ($type == "news") {
1502: if (isset($_GET['subpage'])) {
1503: $urladd .= "&subpage=" . sanitize($_GET['subpage']);
1504: }
1505: if (isset($_GET['date'])) {
1506: $urladd .= "&date=" . sanitize($_GET['date']);
1507: }
1508: if (isset($_GET['category'])) {
1509: $urladd .= "&category=" . sanitize($_GET['category']);
1510: }
1511: if (isset($_GET['sortorder'])) {
1512: $urladd .= "&sortorder=" . sanitize($_GET['sortorder']);
1513: }
1514: if (isset($_GET['articles_page'])) {
1515: $urladd .= "&articles_page=" . sanitize_numeric($_GET['articles_page']);
1516: }
1517: }
1518: if ($object->getDateTime() > date('Y-m-d H:i:s')) {
1519: if ($object->getShow()) {
1520: $title = gettext("Publish immediately (skip scheduling)");
1521: ?>
1522: <a href="?skipscheduling=1&titlelink=<?php echo html_encode($object->getTitlelink()) . $urladd; ?>&XSRFToken=<?php echo getXSRFToken('update') ?>" title="<?php echo $title; ?>">
1523: <img src="images/clock.png" alt="<?php gettext("Scheduled for published"); ?>" title="<?php echo $title; ?>" /></a>
1524: <?php
1525: } else {
1526: $title = gettext("Enable scheduled publishing");
1527: ?>
1528: <a href="?publish=1&titlelink=<?php echo html_encode($object->getTitlelink()) . $urladd; ?>&XSRFToken=<?php echo getXSRFToken('update') ?>" title="<?php echo $title; ?>">
1529: <img src="../../images/action.png" alt="<?php echo gettext("Un-published"); ?>" title="<?php echo $title; ?>" /></a>
1530: <?php
1531: }
1532: } else {
1533: if ($object->getShow()) {
1534: $title = gettext("Un-publish");
1535: ?>
1536: <a href="?publish=0&titlelink=<?php echo html_encode($object->getTitlelink()) . $urladd; ?>&XSRFToken=<?php echo getXSRFToken('update') ?>" title="<?php echo $title; ?>">
1537: <img src="../../images/pass.png" alt="<?php echo gettext("Published"); ?>" title="<?php echo $title; ?>" /></a>
1538: <?php
1539: } else {
1540: $dt = $object->getExpireDate();
1541: if (empty($dt)) {
1542: $title = gettext("Publish");
1543: ?>
1544: <a href="?publish=1&titlelink=<?php echo html_encode($object->getTitlelink()) . $urladd; ?>&XSRFToken=<?php echo getXSRFToken('update') ?>">
1545: <?php
1546: } else {
1547: $title = gettext("Publish (override expiration)");
1548: ?>
1549: <a href="?publish=2&titlelink=<?php echo html_encode($object->getTitlelink()) . $urladd; ?>&XSRFToken=<?php echo getXSRFToken('update') ?>">
1550: <?php
1551: }
1552: ?>
1553: <img src="../../images/action.png" alt="<?php echo gettext("Un-published"); ?>" title= "<?php echo $title; ?>" /></a>
1554: <?php
1555: }
1556: }
1557: }
1558:
1559: 1560: 1561: 1562: 1563:
1564: function checkIfChecked($field) {
1565: if ($field) {
1566: echo 'checked="checked"';
1567: }
1568: }
1569:
1570: 1571: 1572: 1573: 1574: 1575: 1576:
1577: function checkIfLockedPage($page) {
1578: if (zp_loggedin(ADMIN_RIGHTS))
1579: return true;
1580: if ($page->getLocked()) {
1581: return $page->isMyItem(ZENPAGE_PAGES_RIGHTS);
1582: } else {
1583: return true;
1584: }
1585: }
1586:
1587: 1588: 1589: 1590: 1591: 1592: 1593:
1594: function checkIfLockedNews($news) {
1595: if (zp_loggedin(ADMIN_RIGHTS))
1596: return true;
1597: if ($news->getLocked()) {
1598: return $news->isMyItem(ZENPAGE_NEWS_RIGHTS);
1599: } else {
1600: return true;
1601: }
1602: }
1603:
1604: 1605: 1606: 1607: 1608: 1609:
1610: function is_AdminEditPage($page) {
1611: return isset($_GET[$page]);
1612: }
1613:
1614: 1615: 1616: 1617:
1618: function processZenpageBulkActions($type) {
1619: global $_zp_zenpage;
1620: $action = false;
1621: if (isset($_POST['ids'])) {
1622:
1623: $action = sanitize($_POST['checkallaction']);
1624: $links = sanitize($_POST['ids']);
1625: $total = count($links);
1626: $message = NULL;
1627: $sql = '';
1628: if ($action != 'noaction') {
1629: if ($total > 0) {
1630: if ($action == 'addtags' || $action == 'alltags') {
1631: $tags = bulkTags();
1632: }
1633: if ($action == 'addcats') {
1634: foreach ($_POST as $key => $value) {
1635: $key = postIndexDecode($key);
1636: if (substr($key, 0, 3) == 'cat') {
1637: if ($value) {
1638: $cats[] = substr($key, 3);
1639: }
1640: }
1641: }
1642: $cats = sanitize($cats, 3);
1643: }
1644: $n = 0;
1645: foreach ($links as $titlelink) {
1646: $class = 'Zenpage' . $type;
1647: $obj = new $class($titlelink);
1648:
1649: switch ($action) {
1650: case 'deleteall':
1651: $obj->remove();
1652: SearchEngine::clearSearchCache();
1653: break;
1654: case 'addtags':
1655: $mytags = array_unique(array_merge($tags, $obj->getTags()));
1656: $obj->setTags($mytags);
1657: break;
1658: case 'cleartags':
1659: $obj->setTags(array());
1660: break;
1661: case 'alltags':
1662: $allarticles = $obj->getArticles('', 'all', true);
1663: foreach ($allarticles as $article) {
1664: $newsobj = new ZenpageNews($article['titlelink']);
1665: $mytags = array_unique(array_merge($tags, $newsobj->getTags()));
1666: $newsobj->setTags($mytags);
1667: $newsobj->save();
1668: }
1669: break;
1670: case 'clearalltags':
1671: $allarticles = $obj->getArticles('', 'all', true);
1672: foreach ($allarticles as $article) {
1673: $newsobj = new ZenpageNews($article['titlelink']);
1674: $newsobj->setTags(array());
1675: $newsobj->save();
1676: }
1677: break;
1678: case 'addcats':
1679: $catarray = array();
1680: $allcats = $obj->getCategories();
1681: foreach ($cats as $cat) {
1682: $catitem = $_zp_zenpage->getCategory($cat);
1683: $catarray[] = $catitem['titlelink'];
1684: }
1685: $allcatsarray = array();
1686: foreach ($allcats as $allcat) {
1687: $allcatsarray[] = $allcat['titlelink'];
1688: }
1689: $mycats = array_unique(array_merge($catarray, $allcatsarray));
1690: $obj->setCategories($mycats);
1691: break;
1692: case 'clearcats':
1693: $obj->setCategories(array());
1694: break;
1695: case 'showall':
1696: $obj->set('show', 1);
1697: break;
1698: case 'hideall':
1699: $obj->set('show', 0);
1700: break;
1701: case 'commentson':
1702: $obj->set('commentson', 1);
1703: break;
1704: case 'commentsoff':
1705: $obj->set('commentson', 0);
1706: break;
1707: case 'resethitcounter':
1708: $obj->set('hitcounter', 0);
1709: break;
1710: }
1711: $obj->save();
1712: }
1713: }
1714: }
1715: }
1716: return $action;
1717: }
1718:
1719: function zenpageBulkActionMessage($action) {
1720: switch ($action) {
1721: case 'deleteall':
1722: $message = gettext('Selected items deleted');
1723: break;
1724: case 'showall':
1725: $message = gettext('Selected items published');
1726: break;
1727: case 'hideall':
1728: $message = gettext('Selected items unpublished');
1729: break;
1730: case 'commentson':
1731: $message = gettext('Comments enabled for selected items');
1732: break;
1733: case 'commentsoff':
1734: $message = gettext('Comments disabled for selected items');
1735: break;
1736: case 'resethitcounter':
1737: $message = gettext('Hitcounter for selected items');
1738: break;
1739: case 'addtags':
1740: $message = gettext('Tags added to selected items');
1741: break;
1742: case 'cleartags':
1743: $message = gettext('Tags cleared from selected items');
1744: break;
1745: case 'alltags':
1746: $message = gettext('Tags added to articles of selected items');
1747: break;
1748: case 'clearalltags':
1749: $message = gettext('Tags cleared from articles of selected items');
1750: break;
1751: case 'addcats':
1752: $message = gettext('Categories added to selected items');
1753: break;
1754: case 'clearcats':
1755: $message = gettext('Categories cleared from selected items');
1756: break;
1757: default:
1758: return "<p class='notebox fade-message'>" . gettext('Nothing changed') . "</p>";
1759: }
1760: if (isset($message)) {
1761: return "<p class='messagebox fade-message'>" . $message . "</p>";
1762: }
1763: return false;
1764: }
1765: ?>
1766: