1<?php
2/**
3 * zenpage admin-news-articles.php
4 *
5 * @author Malte Müller (acrylian)
6 * @package plugins
7 * @subpackage zenpage
8 */
9define("OFFSET_PATH", 4);
10require_once(dirname(dirname(dirname(__FILE__))) . '/admin-globals.php');
11require_once("zenpage-admin-functions.php");
12
13admin_securityChecks(ZENPAGE_NEWS_RIGHTS, currentRelativeURL());
14
15$reports = array();
16if (isset($_GET['bulkaction'])) {
17	$reports[] = zenpageBulkActionMessage(sanitize($_GET['bulkaction']));
18}
19if (isset($_GET['deleted'])) {
20	$reports[] = "<p class='messagebox fade-message'>" . gettext("Article successfully deleted!") . "</p>";
21}
22if (isset($_POST['checkallaction'])) { // true if apply is pressed
23	XSRFdefender('checkeditems');
24	if ($action = processZenpageBulkActions('News')) {
25		bulkActionRedirect($action);
26	}
27}
28if (isset($_GET['delete'])) {
29	XSRFdefender('delete');
30	$msg = deleteArticle(sanitize($_GET['delete']));
31	if (!empty($msg)) {
32		$reports[] = $msg;
33	}
34}
35// publish or un-publish page by click
36if (isset($_GET['publish'])) {
37	XSRFdefender('update');
38	$obj = new ZenpageNews(sanitize($_GET['titlelink']));
39	zenpagePublish($obj, sanitize_numeric($_GET['publish']));
40}
41if (isset($_GET['skipscheduling'])) {
42	XSRFdefender('update');
43	$obj = new ZenpageNews(sanitize($_GET['titlelink']));
44	skipScheduledPublishing($obj, 'futuredate');
45}
46if (isset($_GET['skipexpiration'])) {
47	XSRFdefender('update');
48	$obj = new ZenpageNews(sanitize($_GET['titlelink']));
49	skipScheduledPublishing($obj, 'expiredate');
50}
51if (isset($_GET['commentson'])) {
52	XSRFdefender('update');
53	$obj = new ZenpageNews(sanitize($_GET['titlelink']));
54	$obj->setCommentsAllowed(sanitize_numeric($_GET['commentson']));
55	$obj->setLastchangeUser($_zp_current_admin_obj->getUser());
56	$obj->save();
57}
58if (isset($_GET['hitcounter'])) {
59	XSRFdefender('hitcounter');
60	$obj = new ZenpageNews(sanitize($_GET['titlelink']));
61	$obj->set('hitcounter', 0);
62	$obj->setLastchangeUser($_zp_current_admin_obj->getUser());
63	$obj->save();
64	$reports[] = '<p class="messagebox fade-message">' . gettext("Hitcounter reset") . '</p>';
65}
66
67printAdminHeader('news', 'articles');
68zenpageJSCSS();
69datepickerJS();
70?>
71
72<script type="text/javascript">
73	//<!-- <![CDATA[
74	var deleteArticle = "<?php echo gettext("Are you sure you want to delete this article? THIS CANNOT BE UNDONE!"); ?>";
75	function confirmAction() {
76		if ($('#checkallaction').val() == 'deleteall') {
77			return confirm('<?php echo js_encode(gettext("Are you sure you want to delete the checked items?")); ?>');
78		} else {
79			return true;
80		}
81	}
82	// ]]> -->
83</script>
84</head>
85<body>
86	<?php
87	printLogoAndLinks();
88	?>
89  <div id="main">
90		<?php
91		printTabs();
92		?>
93    <div id="content">
94			<?php $subtab = printSubtabs(); ?>
95      <div id="tab_articles" class="tabbox">
96				<?php
97				zp_apply_filter('admin_note', 'news', $subtab);
98				if ($reports) {
99					$show = array();
100					preg_match_all('/<p class=[\'"](.*?)[\'"]>(.*?)<\/p>/', implode('', $reports), $matches);
101					foreach ($matches[1] as $key => $report) {
102						$show[$report][] = $matches[2][$key];
103					}
104					foreach ($show as $type => $list) {
105						echo '<p class="' . $type . '">' . implode('<br />', $list) . '</p>';
106					}
107				}
108				?>
109        <h1><?php echo gettext('Articles'); ?>
110					<?php
111					if (isset($_GET['category'])) {
112						echo "<em>" . html_encode(sanitize($_GET['category'])) . '</em>';
113					}
114					if (isset($_GET['date'])) {
115						$_zp_post_date = sanitize($_GET['date']);
116						echo '<em><small> (' . html_encode($_zp_post_date) . ')</small></em>';
117						// require so the date dropdown is working
118						set_context(ZP_ZENPAGE_NEWS_DATE);
119					}
120					if (isset($_GET['published'])) {
121						switch ($_GET['published']) {
122							case 'no':
123								$published = 'unpublished';
124								break;
125							case 'yes':
126								$published = 'published';
127								break;
128							case 'sticky':
129								$published = 'sticky';
130						}
131					} else {
132						$published = 'all';
133					}
134					$sortorder = 'date';
135					$sortdirection = $direction = true;
136					if (isset($_GET['sortorder'])) {
137						list($sortorder, $sortdirection) = explode('-', $_GET['sortorder']);
138						if($sortdirection == 'asc') {
139							$direction = false;
140						}
141					}
142					$catobj = NULL;
143					if (isset($_GET['category'])) {
144						$catobj = new ZenpageCategory(sanitize($_GET['category']));
145					}
146					$author = null;
147					if (isset($_GET['author'])) {
148						$author = sanitize($_GET['author']);
149						if($author == 'all') {
150							$author = null;
151						}
152					}
153					$resultU = $_zp_zenpage->getArticles(0, 'unpublished', false, $sortorder, $sortdirection, false, $catobj, $author);
154					$result = $_zp_zenpage->getArticles(0, $published, false, $sortorder, $direction, false, $catobj, $author);
155					foreach ($result as $key => $article) {
156						$article = new ZenpageNews($article['titlelink']);
157						if (!$article->isMyItem(ZENPAGE_NEWS_RIGHTS)) {
158							unset($result[$key]);
159						}
160					}
161					foreach ($resultU as $key => $article) {
162						$article = new ZenpageNews($article['titlelink']);
163						if (!$article->isMyItem(ZENPAGE_NEWS_RIGHTS)) {
164							unset($resultU[$key]);
165						}
166					}
167					$total = 1;
168					$articles = count($result);
169					$articles_page = max(1, getOption('articles_per_page'));
170					if (isset($_GET['articles_page'])) {
171						if ($_GET['articles_page'] == 'all') {
172							$articles_page = 0;
173						} else {
174							$articles_page = sanitize_numeric($_GET['articles_page']);
175						}
176					}
177					// Basic setup for the global for the current admin page first
178					if (!isset($_GET['subpage'])) {
179						$subpage = 0;
180					} else {
181						$subpage = sanitize_numeric($_GET['subpage']);
182					}
183					if ($articles_page) {
184						$total = ceil($articles / $articles_page);
185						//Needed check if we really have articles for page x or not otherwise we are just on page 1
186						if ($total <= $subpage) {
187							$subpage = 0;
188						}
189						$offset = Zenpage::getOffset($articles_page);
190						$list = array();
191						foreach ($result as $article) {
192							$list[] = $article;
193						}
194						if ($sortorder == 'date') {
195							$rangeset = getPageSelector($list, $articles_page, 'dateDiff');
196						} else {
197							$rangeset = getPageSelector($list, $articles_page);
198						}
199						$options = array_merge(array('page' => 'news', 'tab' => 'articles'), getNewsAdminOption(array('category' => 0, 'date' => 0, 'published' => 0, 'sortorder' => 0, 'articles_page' => 1, 'author' => 0)));
200						$result = array_slice($result, $offset, $articles_page);
201					} else {
202						$rangeset = $options = array();
203					}
204					?>
205          <span class="zenpagestats"><?php printNewsStatistic($articles, count($resultU)); ?></span></h1>
206        <div class="news-dropdowns floatright">
207					<?php
208					printCategoryDropdown();
209					printArticleDatesDropdown($subpage);
210					printUnpublishedDropdown();
211					printSortOrderDropdown();
212					printArticlesPerPageDropdown($subpage, $articles_page);
213					printAuthorDropdown();
214					?>
215          <span class="buttons">
216            <a href="admin-edit.php?newsarticle&amp;add&amp;XSRFToken=<?php echo getXSRFToken('add') ?>"> <img src="images/add.png" alt="" /> <strong><?php echo gettext("New Article"); ?></strong></a>
217          </span>
218          <br style="clear: both" />
219        </div>
220				<?php
221				$option = getNewsAdminOptionPath(getNewsAdminOption(array('category' => 0, 'date' => 0, 'published' => 0, 'sortorder' => 0, 'articles_page' => 1, 'subpage' => 1, 'author' => 0), '?'));
222				?>
223        <form class="dirty-check" action="admin-news-articles.php<?php echo $option; ?>" method="post" name="checkeditems" id="form_zenpageitemlist" onsubmit="return confirmAction();" autocomplete="off">
224					<?php XSRFToken('checkeditems'); ?>
225          <div class="buttons">
226            <button type="submit" title="<?php echo gettext('Apply'); ?>"><img src="../../images/pass.png" alt="" /><strong><?php echo gettext('Apply'); ?></strong>
227            </button>
228          </div>
229          <br style="clear: both" /><br />
230
231          <table class="bordered">
232            <tr>
233              <th colspan="12" id="imagenav">
234								<?php printPageSelector($subpage, $rangeset, PLUGIN_FOLDER . '/zenpage/admin-news-articles.php', $options); ?>
235              </th>
236            </tr>
237            <tr>
238              <th colspan="7"><?php echo gettext('Edit this article'); ?>
239
240              </th>
241
242
243              <th colspan="5">
244								<?php
245								$checkarray = array(
246												gettext('*Bulk actions*')			 => 'noaction',
247												gettext('Delete')							 => 'deleteall',
248												gettext('Set to published')		 => 'showall',
249												gettext('Set to unpublished')	 => 'hideall',
250												gettext('Add tags')						 => 'addtags',
251												gettext('Clear tags')					 => 'cleartags',
252												gettext('Add categories')			 => 'addcats',
253												gettext('Clear categories')		 => 'clearcats'
254								);
255								if(extensionEnabled('comment_form')) {
256									$checkarray[gettext('Disable comments')] = 'commentsoff';
257									$checkarray[gettext('Enable comments')] = 'commentson';
258								}
259								if (extensionEnabled('hitcounter')) {
260									$checkarray[gettext('Reset hitcounter')] = 'resethitcounter';
261								}
262								printBulkActions($checkarray);
263								?>
264              </th>
265            </tr>
266            <tr class="newstr">
267              <td class="subhead" colspan="12">
268                <label style="float: right"><?php echo gettext("Check All"); ?> <input type="checkbox" name="allbox" id="allbox" onclick="checkAll(this.form, 'ids[]', this.checked);" />
269                </label>
270              </td>
271            </tr>
272						<?php
273						foreach ($result as $article) {
274							$article = new ZenpageNews($article['titlelink']);
275							?>
276							<tr class="newstr">
277								<td>
278									<?php
279									switch ($article->getSticky()) {
280										case 1:
281											$sticky = ' <small>[' . gettext('sticky') . ']</small>';
282											break;
283										case 9:
284											$sticky = ' <small><strong>[' . gettext('sticky') . ']</strong></small>';
285											break;
286										default:
287											$sticky = '';
288											break;
289									}
290
291									if (checkIfLockedNews($article)) {
292										echo '<a href="admin-edit.php' . getNewsAdminOptionPath(array_merge(array('newsarticle' => NULL, 'titlelink' => urlencode($article->getTitlelink())), getNewsAdminOption(array('category' => 0, 'date' => 0, 'published' => 0, 'sortorder' => 0, 'articles_page' => 1, 'subpage' => 1)))) . '">';
293										checkForEmptyTitle($article->getTitle(), "news");
294										echo '</a>' . checkHitcounterDisplay($article->getHitcounter()) . $sticky;
295									} else {
296										echo checkForEmptyTitle($article->getTitle(), "news") . '</a>' . checkHitcounterDisplay($article->getHitcounter());
297									}
298									?>
299
300								</td>
301								<td>
302									<?php printArticleCategories($article) ?><br />
303								</td>
304								<td>
305									<?php echo html_encode($article->getAuthor()); ?>
306								</td>
307								<td>
308									<?php printPublished($article); ?>
309								</td>
310								<td>
311									<?php printExpired($article); ?>
312								</td>
313								<td class="page-list_icon">
314									<?php
315									if ($article->inProtectedCategory()) {
316										echo '<img src="../../images/lock.png" style="border: 0px;" alt="' . gettext('Password protected') . '" title="' . gettext('Password protected') . '" />';
317									}
318									?>
319								</td>
320
321								<?php
322        $option = getNewsAdminOptionPath(getNewsAdminOption(array('category' => 0, 'date' => 0, 'published' => 0, 'sortorder' => 0, 'articles_page' => 1, 'subpage' => 1)));
323        if (empty($option)) {
324          $divider = '?';
325        } else {
326          $divider = '&amp;';
327        }
328        if (checkIfLockedNews($article)) {
329									?>
330									<td class="page-list_icon">
331										<?php printPublishIconLink($article, 'news'); ?>
332									</td>
333									<?php if(extensionEnabled('comment_form')) { ?>
334									<td class="page-list_icon">
335										<?php
336										if ($article->getCommentsAllowed()) {
337
338											?>
339											<a href="<?php echo $option.$divider; ?>commentson=0&amp;titlelink=<?php
340											echo html_encode($article->getTitlelink());
341											?>&amp;XSRFToken=<?php echo getXSRFToken('update') ?>" title="<?php echo gettext('Disable comments'); ?>">
342												<img src="../../images/comments-on.png" alt="" title="<?php echo gettext("Comments on"); ?>" style="border: 0px;"/>
343											</a>
344											<?php
345										} else {
346											?>
347											<a href="<?php echo $option.$divider; ?>commentson=1&amp;titlelink=<?php
348											echo html_encode($article->getTitlelink());
349											?>&amp;XSRFToken=<?php echo getXSRFToken('update') ?>" title="<?php echo gettext('Enable comments'); ?>">
350												<img src="../../images/comments-off.png" alt="" title="<?php echo gettext("Comments off"); ?>" style="border: 0px;"/>
351											</a>
352											<?php
353										}
354										?>
355									</td>
356									<?php
357									}
358								} else {
359									?>
360									<td class="page-list_icon">
361										<img src="../../images/icon_inactive.png" alt="<?php gettext('locked'); ?>" />
362									</td>
363									<td class="page-list_icon">
364										<img src="../../images/icon_inactive.png" alt="<?php gettext('locked'); ?>" />
365									</td>
366								<?php } ?>
367
368								<td class="page-list_icon">
369									<a target="_blank" href="../../../index.php?p=news&amp;title=<?php
370									echo $article->getTitlelink();
371									?>" title="<?php echo gettext('View article'); ?>">
372										<img src="images/view.png" alt="" title="<?php echo gettext('View article'); ?>" />
373									</a>
374								</td>
375
376								<?php
377								if (checkIfLockedNews($article)) {
378									if (extensionEnabled('hitcounter')) {
379										?>
380										<td class="page-list_icon">
381											<a href="<?php echo $option.$divider; ?>hitcounter=1&amp;titlelink=<?php
382											echo html_encode($article->getTitlelink());
383											?>&amp;XSRFToken=<?php echo getXSRFToken('hitcounter') ?>" title="<?php echo gettext('Reset hitcounter'); ?>">
384												<img src="../../images/reset.png" alt="" title="<?php echo gettext('Reset hitcounter'); ?>" /></a>
385										</td>
386										<?php
387									}
388									?>
389									<td class="page-list_icon">
390										<a href="javascript:confirmDelete('admin-news-articles.php?delete=<?php
391										echo $article->getTitlelink();
392										echo $option;
393										?>&amp;XSRFToken=<?php echo getXSRFToken('delete') ?>','<?php echo js_encode(gettext('Are you sure you want to delete this article? THIS CANNOT BE UNDONE!')); ?>')" title="<?php echo gettext('Delete article'); ?>">
394											<img src="../../images/fail.png" alt="" title="<?php echo gettext('Delete article'); ?>" /></a>
395									</td>
396									<td class="page-list_icon">
397										<input type="checkbox" name="ids[]" value="<?php echo $article->getTitlelink(); ?>" onclick="triggerAllBox(this.form, 'ids[]', this.form.allbox);" />
398									</td>
399								<?php } else { ?>
400									<td class="page-list_icon">
401										<img src="../../images/icon_inactive.png" alt="" title="<?php gettext('locked'); ?>" />
402									</td>
403									<td class="page-list_icon">
404										<img src="../../images/icon_inactive.png" alt="" title="<?php gettext('locked'); ?>" />
405									</td>
406									<td class="page-list_icon">
407										<img src="../../images/icon_inactive.png" alt="" title="<?php gettext('locked'); ?>" />
408									</td>
409									<?php
410								}
411								?>
412							</tr>
413							<?php
414						}
415						?>
416            <tr>
417              <td id="imagenavb" colspan="11"><?php printPageSelector($subpage, $rangeset, PLUGIN_FOLDER . '/zenpage/admin-news-articles.php', $options); ?>	</td>
418            </tr>
419          </table>
420
421
422          <p class="buttons"><button type="submit" title="<?php echo gettext('Apply'); ?>"><img src="../../images/pass.png" alt="" /><strong><?php echo gettext('Apply'); ?></strong></button></p>
423        </form>
424				<?php printZenpageIconLegend(); ?>
425        <br class="clearall" />
426      </div> <!-- tab_articles -->
427    </div> <!-- content -->
428  </div> <!-- main -->
429
430	<?php printAdminFooter(); ?>
431</body>
432</html>
433