PageRenderTime 53ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/FSN/mediatheque/zp-core/zp-extensions/zenpage/admin-news-articles.php

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