PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/phpmyfaq/admin/news.php

https://github.com/cyrke/phpMyFAQ
PHP | 467 lines | 403 code | 43 blank | 21 comment | 40 complexity | 80f0bcf64ff23b4508d386edd128a85e MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * The main administration file for the news.
  4. *
  5. * PHP Version 5.3
  6. *
  7. * This Source Code Form is subject to the terms of the Mozilla Public License,
  8. * v. 2.0. If a copy of the MPL was not distributed with this file, You can
  9. * obtain one at http://mozilla.org/MPL/2.0/.
  10. *
  11. * @category phpMyFAQ
  12. * @package Administration
  13. * @author Thorsten Rinne <thorsten@phpmyfaq.de>
  14. * @author Matteo Scaramuccia <matteo@phpmyfaq.de>
  15. * @copyright 2003-2012 phpMyFAQ Team
  16. * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
  17. * @link http://www.phpmyfaq.de
  18. * @since 2003-02-23
  19. */
  20. if (!defined('IS_VALID_PHPMYFAQ')) {
  21. header('Location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']));
  22. exit();
  23. }
  24. $news = new PMF_News($faqConfig);
  25. // Re-evaluate $user
  26. $user = PMF_User_CurrentUser::getFromSession($faqConfig);
  27. if ('addnews' == $action && $permission["addnews"]) {
  28. ?>
  29. <header>
  30. <h2><?php print $PMF_LANG['ad_news_data']; ?></h2>
  31. </header>
  32. <form class="form-horizontal" id="faqEditor" name="faqEditor" action="?action=savenews" method="post">
  33. <fieldset>
  34. <legend><?php print $PMF_LANG['ad_news_add']; ?></legend>
  35. <div class="control-group">
  36. <label class="control-label" for="newsheader"><?php print $PMF_LANG['ad_news_header']; ?></label>
  37. <div class="controls">
  38. <input class="input-xxlarge" type="text" name="newsheader" id="newsheader" />
  39. </div>
  40. </div>
  41. <div class="control-group">
  42. <label class="control-label" for="news"><?php print $PMF_LANG['ad_news_text']; ?>:</label>
  43. <div class="controls">
  44. <noscript>Please enable JavaScript to use the WYSIWYG editor!</noscript>
  45. <textarea id="news" name="news" cols="84" rows="5"></textarea>
  46. </div>
  47. </div>
  48. <div class="control-group">
  49. <label class="control-label" for="authorName"><?php print $PMF_LANG['ad_news_author_name']; ?></label>
  50. <div class="controls">
  51. <input class="input-xxlarge" type="text" name="authorName" id="authorName" value="<?php print $user->getUserData('display_name'); ?>"/>
  52. </div>
  53. </div>
  54. <div class="control-group">
  55. <label class="control-label" for="authorEmail"><?php print $PMF_LANG['ad_news_author_email']; ?></label>
  56. <div class="controls">
  57. <input class="input-xxlarge" type="email" name="authorEmail" id="authorEmail" value="<?php print $user->getUserData('email'); ?>"/>
  58. </div>
  59. </div>
  60. <div class="control-group">
  61. <label class="control-label" for="active"><?php print $PMF_LANG['ad_news_set_active']; ?></label>
  62. <div class="controls">
  63. <label class="checkbox">
  64. <input type="checkbox" name="active" id="active" value="y" />
  65. <?php print $PMF_LANG['ad_gen_yes']; ?>
  66. </label>
  67. </div>
  68. </div>
  69. <div class="control-group">
  70. <label class="control-label" for="comment"><?php print $PMF_LANG['ad_news_allowComments']; ?></label>
  71. <div class="controls">
  72. <label class="checkbox">
  73. <input type="checkbox" name="comment" id="comment" value="y" />
  74. <?php print $PMF_LANG['ad_gen_yes']; ?>
  75. </label>
  76. </div>
  77. </div>
  78. <div class="control-group">
  79. <label class="control-label" for="link"><?php print $PMF_LANG['ad_news_link_url']; ?></label>
  80. <div class="controls">
  81. <input class="input-xxlarge" type="url" name="link" id="link" value="http://" />
  82. </div>
  83. </div>
  84. <div class="control-group">
  85. <label class="control-label" for="linkTitle"><?php print $PMF_LANG['ad_news_link_title']; ?></label>
  86. <div class="controls">
  87. <input type="text" name="linkTitle" id="linkTitle" />
  88. </div>
  89. </div>
  90. <div class="control-group">
  91. <label class="control-label" ><?php print $PMF_LANG['ad_news_link_target']; ?></label>
  92. <div class="controls">
  93. <label class="radio">
  94. <input type="radio" name="target" value="blank" />
  95. <?php print $PMF_LANG['ad_news_link_window'] ?>
  96. </label>
  97. <label class="radio">
  98. <input type="radio" name="target" value="self" />
  99. <?php print $PMF_LANG['ad_news_link_faq'] ?>
  100. </label>
  101. <label class="radio">
  102. <input type="radio" name="target" value="parent" />
  103. <?php print $PMF_LANG['ad_news_link_parent'] ?>
  104. </label>
  105. </div>
  106. </div>
  107. <div class="control-group">
  108. <label class="control-label" for="langTo"><?php print $PMF_LANG["ad_entry_locale"]; ?>:</label>
  109. <div class="controls">
  110. <?php print PMF_Language::selectLanguages($LANGCODE, false, array(), 'langTo'); ?>
  111. </div>
  112. </div>
  113. </fieldset>
  114. <fieldset>
  115. <legend><?php print $PMF_LANG['ad_news_expiration_window']; ?></legend>
  116. <div class="control-group">
  117. <label class="control-label" for="dateStart"><?php print $PMF_LANG['ad_news_from']; ?></label>
  118. <div class="controls">
  119. <input type="date" name="dateStart" id="dateStart" class="date-pick" />
  120. </div>
  121. </div>
  122. <div class="control-group">
  123. <label class="control-label" for="dateEnd"><?php print $PMF_LANG['ad_news_to']; ?></label>
  124. <div class="controls">
  125. <input type="date" name="dateEnd" id="dateEnd" class="date-pick" />
  126. </div>
  127. </fieldset>
  128. <div class="form-actions">
  129. <button class="btn btn-primary" type="submit">
  130. <?php print $PMF_LANG['ad_news_add']; ?>
  131. </button>
  132. <a class="btn btn-info" href="?action=news">
  133. <?php echo $PMF_LANG['ad_entry_back']; ?>
  134. </a>
  135. </div>
  136. </form>
  137. <?php
  138. } elseif ('news' == $action && $permission["editnews"]) {
  139. ?>
  140. <header>
  141. <h2><?php print $PMF_LANG["msgNews"]; ?></h2>
  142. </header>
  143. <p>
  144. <a class="btn btn-success" href="?action=addnews">
  145. <i class="icon-plus icon-white"></i> <?php print $PMF_LANG["ad_menu_news_add"]; ?>
  146. </a>
  147. </p>
  148. <table class="table table-striped">
  149. <thead>
  150. <tr>
  151. <th><?php print $PMF_LANG["ad_news_headline"]; ?></th>
  152. <th><?php print $PMF_LANG["ad_news_date"]; ?></th>
  153. <th>&nbsp;</th>
  154. </tr>
  155. </thead>
  156. <tbody>
  157. <?php
  158. $newsHeader = $news->getNewsHeader();
  159. $date = new PMF_Date($faqConfig);
  160. if (count($newsHeader)) {
  161. foreach($newsHeader as $newsItem) {
  162. ?>
  163. <tr>
  164. <td><?php print $newsItem['header']; ?></td>
  165. <td><?php print $date->format($newsItem['date']); ?></td>
  166. <td>
  167. <a href="?action=editnews&amp;id=<?php print $newsItem['id']; ?>" title="<?php print $PMF_LANG["ad_news_update"]; ?>">
  168. <span title="<?php print $PMF_LANG["ad_news_update"]; ?>" class="icon-edit"></span>
  169. </a>
  170. &nbsp;&nbsp;
  171. <a href="?action=deletenews&amp;id=<?php print $newsItem['id']; ?>" title="<?php print $PMF_LANG["ad_news_delete"]; ?>">
  172. <span title="<?php print $PMF_LANG["ad_news_delete"]; ?>" class="icon-trash"></span>
  173. </a>
  174. </td>
  175. </tr>
  176. <?php
  177. }
  178. } else {
  179. printf('<tr><td colspan="3">%s</td></tr>',
  180. $PMF_LANG['ad_news_nodata']);
  181. }
  182. ?>
  183. </tbody>
  184. </table>
  185. <?php
  186. } elseif ('editnews' == $action && $permission['editnews']) {
  187. $id = PMF_Filter::filterInput(INPUT_GET, 'id', FILTER_VALIDATE_INT);
  188. $newsData = $news->getNewsEntry($id, true);
  189. ?>
  190. <header>
  191. <h2><?php print $PMF_LANG['ad_news_data']; ?></h2>
  192. </header>
  193. <form class="form-horizontal" action="?action=updatenews" method="post">
  194. <fieldset>
  195. <legend><?php print $PMF_LANG['ad_news_edit']; ?></legend>
  196. <input type="hidden" name="id" value="<?php print $newsData['id']; ?>" />
  197. <div class="control-group">
  198. <label class="control-label" for="newsheader"><?php print $PMF_LANG['ad_news_header']; ?></label>
  199. <div class="controls">
  200. <input type="text" name="newsheader" id="newsheader"
  201. value="<?php if (isset($newsData['header'])) { print $newsData['header']; } ?>" />
  202. </div>
  203. </div>
  204. <div class="control-group">
  205. <label class="control-label" for="news"><?php print $PMF_LANG['ad_news_text']; ?>:</label>
  206. <div class="controls">
  207. <noscript>Please enable JavaScript to use the WYSIWYG editor!</noscript>
  208. <textarea id="news" name="news" cols="84" rows="5"><?php if (isset($newsData['content'])) { print htmlspecialchars($newsData['content'], ENT_QUOTES); } ?></textarea>
  209. </div>
  210. </div>
  211. <div class="control-group">
  212. <label class="control-label" for="authorName"><?php print $PMF_LANG['ad_news_author_name']; ?></label>
  213. <div class="controls">
  214. <input type="text" name="authorName" value="<?php print $newsData['authorName']; ?>" />
  215. </div>
  216. </div>
  217. <div class="control-group">
  218. <label class="control-label" for="authorEmail"><?php print $PMF_LANG['ad_news_author_email']; ?></label>
  219. <div class="controls">
  220. <input type="email" name="authorEmail" value="<?php print $newsData['authorEmail']; ?>" />
  221. </div>
  222. </div>
  223. <div class="control-group">
  224. <label class="control-label" for="active"><?php print $PMF_LANG['ad_news_set_active']; ?></label>
  225. <div class="controls">
  226. <label class="checkbox">
  227. <input type="checkbox" name="active" id="active" value="y"<?php if (isset($newsData['active']) && $newsData['active']) { print " checked"; } ?> />
  228. <?php print $PMF_LANG['ad_gen_yes']; ?>
  229. </label>
  230. </div>
  231. </div>
  232. <div class="control-group">
  233. <label class="control-label" for="comment"><?php print $PMF_LANG['ad_news_allowComments']; ?></label>
  234. <div class="controls">
  235. <label class="checkbox">
  236. <input type="checkbox" name="comment" id="comment" value="y"<?php if (isset($newsData['allowComments']) && $newsData['allowComments']) { print " checked"; } ?> />
  237. <?php print $PMF_LANG['ad_gen_yes']; ?>
  238. </label>
  239. </div>
  240. </div>
  241. <div class="control-group">
  242. <label class="control-label" for="link"><?php print $PMF_LANG['ad_news_link_url']; ?></label>
  243. <div class="controls">
  244. <input type="url" name="link" value="<?php print $newsData['link']; ?>" />
  245. </div>
  246. </div>
  247. <div class="control-group">
  248. <label class="control-label" for="linkTitle"><?php print $PMF_LANG['ad_news_link_title']; ?></label>
  249. <div class="controls">
  250. <input type="text" name="linkTitle" value="<?php print $newsData['linkTitle']; ?>" />
  251. </div>
  252. </div>
  253. <div class="control-group">
  254. <label class="control-label" for="linkTarget"><?php print $PMF_LANG['ad_news_link_target']; ?></label>
  255. <div class="controls">
  256. <label class="radio">
  257. <input type="radio" name="target" value="blank" <?php if ('blank' == $newsData['target']) { ?>
  258. checked="checked"<?php } ?> />
  259. <?php print $PMF_LANG['ad_news_link_window'] ?>
  260. </label>
  261. <label class="radio">
  262. <input type="radio" name="target" value="self" <?php if ('self' == $newsData['target']) { ?>
  263. checked="checked"<?php } ?> />
  264. <?php print $PMF_LANG['ad_news_link_faq'] ?>
  265. </label>
  266. <label class="radio">
  267. <input type="radio" name="target" value="parent" <?php if ('parent' == $newsData['target']) { ?>
  268. checked="checked"<?php } ?> />
  269. <?php print $PMF_LANG['ad_news_link_parent'] ?>
  270. </label>
  271. </div>
  272. </div>
  273. <div class="control-group">
  274. <label class="control-label" for="langTo"><?php print $PMF_LANG["ad_entry_locale"]; ?>:</label>
  275. <div class="controls">
  276. <?php print PMF_Language::selectLanguages($newsData['lang'], false, array(), 'langTo'); ?>
  277. </div>
  278. </fieldset>
  279. <?php
  280. $dateStart = ($newsData['dateStart'] != '00000000000000' ? PMF_Date::createIsoDate($newsData['dateStart'], 'Y-m-d') : '');
  281. $dateEnd = ($newsData['dateEnd'] != '99991231235959' ? PMF_Date::createIsoDate($newsData['dateEnd'], 'Y-m-d') : '');
  282. ?>
  283. <fieldset>
  284. <legend><?php print $PMF_LANG['ad_news_expiration_window']; ?></legend>
  285. <div class="control-group">
  286. <label class="control-label" for="dateStart"><?php print $PMF_LANG['ad_news_from']; ?></label>
  287. <div class="controls">
  288. <input name="dateStart" id="dateStart" class="date-pick" value="<?php print $dateStart; ?>" />
  289. </div>
  290. <div class="control-group">
  291. <label class="control-label" for="dateEnd"><?php print $PMF_LANG['ad_news_to']; ?></label>
  292. <div class="controls">
  293. <input name="dateEnd" id="dateEnd" class="date-pick" value="<?php print $dateEnd; ?>" />
  294. </div>
  295. </fieldset>
  296. <div class="form-actions">
  297. <button class="btn btn-primary" type="submit">
  298. <?php print $PMF_LANG['ad_news_edit']; ?>
  299. </button>
  300. <a class="btn btn-info" href="?action=news">
  301. <?php echo $PMF_LANG['ad_entry_back']; ?>
  302. </a>
  303. </div>
  304. </form>
  305. <?php
  306. $newsId = PMF_Filter::filterInput(INPUT_GET, 'id', FILTER_VALIDATE_INT);
  307. $oComment = new PMF_Comment($faqConfig);
  308. $comments = $oComment->getCommentsData($newsId, PMF_Comment::COMMENT_TYPE_NEWS);
  309. if (count($comments) > 0) {
  310. ?>
  311. <div class="control-group"><strong><?php print $PMF_LANG["ad_entry_comment"] ?></strong></p>
  312. <?php
  313. }
  314. foreach ($comments as $item) {
  315. ?>
  316. <div class="control-group"><?php print $PMF_LANG["ad_entry_commentby"] ?> <a href="mailto:<?php print($item['email']); ?>"><?php print($item['user']); ?></a>:<br /><?php print($item['content']); ?><br /><?php print($PMF_LANG['newsCommentDate'].PMF_Date::createIsoDate($item['date'], 'Y-m-d H:i', false)); ?><a href="?action=delcomment&amp;artid=<?php print($newsId); ?>&amp;cmtid=<?php print($item['id']); ?>&amp;type=<?php print(PMF_Comment::COMMENT_TYPE_NEWS);?>"><img src="images/delete.gif" alt="<?php print $PMF_LANG["ad_entry_delete"] ?>" title="<?php print $PMF_LANG["ad_entry_delete"] ?>" border="0" width="17" height="18" align="right" /></a></p>
  317. <?php
  318. }
  319. } elseif ('savenews' == $action && $permission["addnews"]) {
  320. $dateStart = PMF_Filter::filterInput(INPUT_POST, 'dateStart', FILTER_SANITIZE_STRING);
  321. $dateEnd = PMF_Filter::filterInput(INPUT_POST, 'dateEnd', FILTER_SANITIZE_STRING);
  322. $header = PMF_Filter::filterInput(INPUT_POST, 'newsheader', FILTER_SANITIZE_STRIPPED);
  323. $content = PMF_Filter::filterInput(INPUT_POST, 'news', FILTER_SANITIZE_SPECIAL_CHARS);
  324. $author = PMF_Filter::filterInput(INPUT_POST, 'authorName', FILTER_SANITIZE_STRIPPED);
  325. $email = PMF_Filter::filterInput(INPUT_POST, 'authorEmail', FILTER_VALIDATE_EMAIL);
  326. $active = PMF_Filter::filterInput(INPUT_POST, 'active', FILTER_SANITIZE_STRING);
  327. $comment = PMF_Filter::filterInput(INPUT_POST, 'comment', FILTER_SANITIZE_STRING);
  328. $link = PMF_Filter::filterInput(INPUT_POST, 'link', FILTER_VALIDATE_URL);
  329. $linktitle = PMF_Filter::filterInput(INPUT_POST, 'linkTitle', FILTER_SANITIZE_STRIPPED);
  330. $newslang = PMF_Filter::filterInput(INPUT_POST, 'langTo', FILTER_SANITIZE_STRING);
  331. $target = PMF_Filter::filterInput(INPUT_POST, 'target', FILTER_SANITIZE_STRIPPED);
  332. $newsData = array(
  333. 'lang' => $newslang,
  334. 'header' => $header,
  335. 'content' => html_entity_decode($content),
  336. 'authorName' => $author,
  337. 'authorEmail' => $email,
  338. 'active' => (is_null($active)) ? 'n' : 'y',
  339. 'comment' => (is_null($comment)) ? 'n' : 'y',
  340. 'dateStart' => (empty($dateStart)) ? '00000000000000' : str_replace('-', '', $dateStart) . '000000',
  341. 'dateEnd' => (empty($dateEnd)) ? '99991231235959' : str_replace('-', '', $dateEnd) . '235959',
  342. 'link' => $link,
  343. 'linkTitle' => $linktitle,
  344. 'date' => date('YmdHis'),
  345. 'target' => (is_null($target)) ? '' : $target
  346. );
  347. if ($news->addNewsEntry($newsData)) {
  348. printf('<p class="alert alert-success">%s</p>', $PMF_LANG['ad_news_updatesuc']);
  349. } else {
  350. printf('<p class="alert alert-error">%s</p>', $PMF_LANG['ad_news_insertfail']);
  351. }
  352. printf('<div class="control-group">&rarr; <a href="?action=news">%s</a></p>', $PMF_LANG['msgNews']);
  353. } elseif ('updatenews' == $action && $permission["editnews"]) {
  354. $dateStart = PMF_Filter::filterInput(INPUT_POST, 'dateStart', FILTER_SANITIZE_STRING);
  355. $dateEnd = PMF_Filter::filterInput(INPUT_POST, 'dateEnd', FILTER_SANITIZE_STRING);
  356. $header = PMF_Filter::filterInput(INPUT_POST, 'newsheader', FILTER_SANITIZE_STRIPPED);
  357. $content = PMF_Filter::filterInput(INPUT_POST, 'news', FILTER_SANITIZE_SPECIAL_CHARS);
  358. $author = PMF_Filter::filterInput(INPUT_POST, 'authorName', FILTER_SANITIZE_STRIPPED);
  359. $email = PMF_Filter::filterInput(INPUT_POST, 'authorEmail', FILTER_VALIDATE_EMAIL);
  360. $active = PMF_Filter::filterInput(INPUT_POST, 'active', FILTER_SANITIZE_STRING);
  361. $comment = PMF_Filter::filterInput(INPUT_POST, 'comment', FILTER_SANITIZE_STRING);
  362. $link = PMF_Filter::filterInput(INPUT_POST, 'link', FILTER_VALIDATE_URL);
  363. $linktitle = PMF_Filter::filterInput(INPUT_POST, 'linkTitle', FILTER_SANITIZE_STRIPPED);
  364. $newslang = PMF_Filter::filterInput(INPUT_POST, 'langTo', FILTER_SANITIZE_STRING);
  365. $target = PMF_Filter::filterInput(INPUT_POST, 'target', FILTER_SANITIZE_STRIPPED);
  366. $newsData = array(
  367. 'lang' => $newslang,
  368. 'header' => $header,
  369. 'content' => html_entity_decode($content),
  370. 'authorName' => $author,
  371. 'authorEmail' => $email,
  372. 'active' => (is_null($active)) ? 'n' : 'y',
  373. 'comment' => (is_null($comment)) ? 'n' : 'y',
  374. 'dateStart' => (empty($dateStart)) ? '00000000000000' : str_replace('-', '', $dateStart) . '000000',
  375. 'dateEnd' => (empty($dateEnd)) ? '99991231235959' : str_replace('-', '', $dateEnd) . '235959',
  376. 'link' => $link,
  377. 'linkTitle' => $linktitle,
  378. 'date' => date('YmdHis'),
  379. 'target' => (is_null($target)) ? '' : $target);
  380. $newsId = PMF_Filter::filterInput(INPUT_POST, 'id', FILTER_VALIDATE_INT);
  381. if ($news->updateNewsEntry($newsId, $newsData)) {
  382. printf('<p class="alert alert-success">%s</p>', $PMF_LANG['ad_news_updatesuc']);
  383. } else {
  384. printf('<p class="alert alert-error">%s</p>', $PMF_LANG['ad_news_updatefail']);
  385. }
  386. printf('<div class="control-group">&rarr; <a href="?action=news">%s</a></p>', $PMF_LANG['msgNews']);
  387. } elseif ('deletenews' == $action && $permission["delnews"]) {
  388. $precheck = PMF_Filter::filterInput(INPUT_POST, 'really', FILTER_SANITIZE_STRING, 'no');
  389. $delete_id = PMF_Filter::filterInput(INPUT_GET, 'id', FILTER_VALIDATE_INT);
  390. if ('no' == $precheck) {
  391. ?>
  392. <div class="control-group"><?php print $PMF_LANG["ad_news_del"]; ?></div>
  393. <div align="center">
  394. <form action="?action=deletenews" method="post">
  395. <input type="hidden" name="id" value="<?php print $delete_id; ?>" />
  396. <input type="hidden" name="really" value="yes" />
  397. <button class="btn btn-warning" type="submit" name="submit">
  398. <?php print $PMF_LANG["ad_news_yesdelete"]; ?>
  399. </button>
  400. <a class="btn btn-inverse" onclick="javascript:history.back();">
  401. <?php print $PMF_LANG["ad_news_nodelete"]; ?>
  402. </a>
  403. </form>
  404. </div>
  405. <script type="text/javascript">
  406. /* <![CDATA[ */
  407. if (!Modernizr.inputtypes.date) {
  408. $(function()
  409. {
  410. $('.date-pick').datePicker();
  411. });
  412. }
  413. /* ]]> */
  414. </script>
  415. <?php
  416. } else {
  417. $delete_id = PMF_Filter::filterInput(INPUT_POST, 'id', FILTER_VALIDATE_INT);
  418. $news->deleteNews($delete_id);
  419. printf('<p class="alert alert-success">%s</p>', $PMF_LANG['ad_news_delsuc']);
  420. printf('<div class="control-group">&rarr; <a href="?action=news">%s</a></p>', $PMF_LANG['msgNews']);
  421. }
  422. } else {
  423. print $PMF_LANG["err_NotAuth"];
  424. }