PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tiki-admin_rssmodules.php

https://gitlab.com/ElvisAns/tiki
PHP | 254 lines | 225 code | 14 blank | 15 comment | 64 complexity | 32f524943d06669df6db351d0a0bc6ef MD5 | raw file
  1. <?php
  2. /**
  3. * @package tikiwiki
  4. */
  5. // (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
  6. //
  7. // All Rights Reserved. See copyright.txt for details and a complete list of authors.
  8. // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
  9. // $Id$
  10. require_once('tiki-setup.php');
  11. /** @var RSSLib $rsslib */
  12. $rsslib = TikiLib::lib('rss');
  13. //get_strings tra('External Feeds')
  14. $auto_query_args = [
  15. 'rssId',
  16. 'offset',
  17. 'maxRecords',
  18. 'sort_mode',
  19. 'find'
  20. ];
  21. $access->check_permission('tiki_p_admin_rssmodules');
  22. if (isset($_REQUEST["rssId"])) {
  23. $smarty->assign('rssId', $_REQUEST["rssId"]);
  24. $cookietab = 2;
  25. }
  26. $smarty->assign('preview', 'n');
  27. if (isset($_REQUEST["view"])) {
  28. $smarty->assign('preview', 'y');
  29. $data = $rsslib->get_rss_module($_REQUEST["view"]);
  30. if ($data['sitetitle']) {
  31. $smarty->assign(
  32. 'feedtitle',
  33. [
  34. 'title' => $data['sitetitle'],
  35. 'link' => $data['siteurl']
  36. ]
  37. );
  38. }
  39. $smarty->assign('items', $rsslib->get_feed_items($_REQUEST['view']));
  40. }
  41. if (isset($_REQUEST["rssId"])) {
  42. $info = $rsslib->get_rss_module($_REQUEST["rssId"]);
  43. } else {
  44. $info = [];
  45. // default for new rss feed:
  46. $info["name"] = '';
  47. $info["description"] = '';
  48. $info["url"] = '';
  49. $info["refresh"] = 1800;
  50. $info["showTitle"] = 'n';
  51. $info["showPubDate"] = 'n';
  52. }
  53. $smarty->assign('name', $info["name"]);
  54. $smarty->assign('description', $info["description"]);
  55. $smarty->assign('url', $info["url"]);
  56. $smarty->assign('refreshSeconds', $info["refresh"]);
  57. $smarty->assign('showTitle', $info["showTitle"]);
  58. $smarty->assign('showPubDate', $info["showPubDate"]);
  59. if ((isset($_REQUEST["refresh_all"]) || ! empty($_REQUEST["refresh"])) && $access->checkCsrf()) {
  60. if (isset($_REQUEST["refresh_all"])) {
  61. // Refresh all feeds button
  62. $result = $rsslib->refresh_all_rss_modules();
  63. } else {
  64. // Refreshing a single feed
  65. $result = $rsslib->refresh_rss_module($_REQUEST["refresh"]);
  66. }
  67. if (is_array($result)) {
  68. if ($result['entries']['feed'] === 1) {
  69. $msg = tr('Refresh resulted in %0 updated feed entry', $result['entries']['feed']);
  70. } elseif ($result['entries']['feed'] > 1) {
  71. $msg = tr('Refresh resulted in %0 updated feed entries', $result['entries']['feed']);
  72. } else {
  73. $msg = tr('Feed entries already up to date, no changes made');
  74. }
  75. if (isset($result['entries']['articles']) && $result['entries']['articles'] === 1) {
  76. $msg .= '. ' . tr('In addition, %0 article was created from the feed items.', $result['entries']['articles']);
  77. } elseif (! empty($result['entries']['articles'])) {
  78. $msg .= '. ' . tr('In addition, %0 articles were created from the feed items.', $result['entries']['articles']);
  79. }
  80. Feedback::success($msg);
  81. } else {
  82. Feedback::error(tr('Feeds not refreshed'));
  83. }
  84. }
  85. if (isset($_REQUEST['clear']) && $access->checkCsrf()) {
  86. $count = $rsslib->table('tiki_rss_items')->fetchCount(
  87. ['rssId' => $_REQUEST['clear']]
  88. );
  89. if ($count == 0) {
  90. Feedback::note(tr(
  91. 'No cached items to clear for external feed ID %0.',
  92. htmlspecialchars($_REQUEST['clear'])
  93. ));
  94. } else {
  95. $result = $rsslib->clear_rss_cache($_REQUEST['clear']);
  96. if ($result && $result->numRows()) {
  97. Feedback::success(tr('Cache cleared'));
  98. } else {
  99. Feedback::error(tr('Cache not cleared'));
  100. }
  101. }
  102. }
  103. if (isset($_REQUEST["remove"]) && $access->checkCsrf(true)) {
  104. $result = $rsslib->remove_rss_module($_REQUEST["remove"]);
  105. if ($result['feed'] && $result['feed']->numRows()) {
  106. if ($result['items'] && $result['items']->numRows()) {
  107. if ($result['items']->numRows() === 1) {
  108. Feedback::success(tr('External feed with 1 item deleted'));
  109. } else {
  110. Feedback::success(tr('External feed with %0 items deleted', $result['items']->numRows()));
  111. }
  112. } else {
  113. Feedback::success(tr('External feed with no items deleted'));
  114. }
  115. } else {
  116. Feedback::error(tr('No external feeds were deleted'));
  117. }
  118. }
  119. if (isset($_REQUEST['article']) && $prefs['feature_articles'] == 'y') {
  120. if ($_SERVER['REQUEST_METHOD'] == 'POST' && $access->checkCsrf()) {
  121. $result = $rsslib->set_article_generator(
  122. $_REQUEST['article'],
  123. [
  124. 'active' => isset($_POST['enable']),
  125. 'expiry' => $jitPost->expiry->int(),
  126. 'atype' => $jitPost->type->text(),
  127. 'custom_atype' => $jitPost->asArray('custom_atype'),
  128. 'topic' => $jitPost->topic->int(),
  129. 'custom_topic' => $jitPost->asArray('custom_topic'),
  130. 'future_publish' => $jitPost->future_publish->int(),
  131. 'categories' => (array) $jitPost->cat_categories->int(),
  132. 'rating' => $jitPost->rating->int(),
  133. 'custom_rating' => $jitPost->asArray('custom_rating'),
  134. 'submission' => isset($_POST['submission']),
  135. 'custom_priority' => $jitPost->asArray('custom_priority'),
  136. 'a_lang' => $jitPost->a_lang->word(),
  137. ]
  138. );
  139. $cookietab = 1;
  140. if ($result && $result->numRows()) {
  141. Feedback::success(tr('Article generator settings updated'));
  142. } else {
  143. Feedback::note(tr('No changes made to article generator settings'));
  144. }
  145. } else {
  146. $cookietab = 3;
  147. }
  148. $config = $rsslib->get_article_generator($_REQUEST['article']);
  149. $smarty->assign('articleConfig', $config);
  150. $smarty->assign('ratingOptions', array_map('strval', range(0, 10)));
  151. $sourcecats = $rsslib->get_feed_source_categories($_REQUEST["article"]);
  152. $smarty->assign('sourcecats', $sourcecats);
  153. $article_custom_info = $rsslib->get_article_custom_info($_REQUEST["article"]);
  154. $smarty->assign('article_custom_info', $article_custom_info);
  155. $artlib = TikiLib::lib('art');
  156. $smarty->assign('topics', $artlib->list_topics());
  157. $smarty->assign('types', $artlib->list_types());
  158. $cat_type = 'null';
  159. $cat_objid = 'null';
  160. $_REQUEST['cat_categorize'] = 'on';
  161. $_REQUEST['cat_categories'] = $config['categories'];
  162. include 'categorize_list.php';
  163. }
  164. if (isset($_REQUEST["save"]) && $access->checkCsrf()) {
  165. if (isset($_REQUEST['showTitle']) == 'on') {
  166. $smarty->assign('showTitle', 'y');
  167. $info["showTitle"] = 'y';
  168. } else {
  169. $smarty->assign('showTitle', 'n');
  170. $info["showTitle"] = 'n';
  171. }
  172. if (isset($_REQUEST['showPubDate']) == 'on') {
  173. $smarty->assign('showPubDate', 'y');
  174. $info["showPubDate"] = 'y';
  175. } else {
  176. $smarty->assign('showPubDate', 'n');
  177. $info["showPubDate"] = 'n';
  178. }
  179. $result = $rsslib->replace_rss_module(
  180. $_REQUEST["rssId"],
  181. $_REQUEST["name"],
  182. $_REQUEST["description"],
  183. $_REQUEST["url"],
  184. $_REQUEST["refreshMinutes"],
  185. $info["showTitle"],
  186. $info["showPubDate"]
  187. );
  188. $smarty->assign('rssId', 0);
  189. $smarty->assign('name', '');
  190. $smarty->assign('description', '');
  191. $smarty->assign('url', '');
  192. $smarty->assign('refreshSeconds', 900);
  193. $smarty->assign('showTitle', 'n');
  194. $smarty->assign('showPubDate', 'n');
  195. $cookietab = 1;
  196. if (is_numeric($result)) {
  197. if (! empty($_REQUEST["rssId"])) {
  198. $msg = tr('External feed updated');
  199. } else {
  200. $msg = tr('External feed saved');
  201. }
  202. Feedback::success($msg);
  203. } else {
  204. Feedback::note(tr('No changes made to external feed'));
  205. }
  206. }
  207. if (! isset($_REQUEST["sort_mode"])) {
  208. $sort_mode = 'name_desc';
  209. } else {
  210. $sort_mode = $_REQUEST["sort_mode"];
  211. }
  212. if (! isset($_REQUEST["offset"])) {
  213. $offset = 0;
  214. } else {
  215. $offset = $_REQUEST["offset"];
  216. }
  217. $smarty->assign_by_ref('offset', $offset);
  218. if (isset($_REQUEST["find"])) {
  219. $find = $_REQUEST["find"];
  220. } else {
  221. $find = '';
  222. }
  223. if ($prefs['feature_multilingual'] == 'y') {
  224. $languages = [];
  225. $langLib = TikiLib::lib('language');
  226. $languages = $langLib->list_languages();
  227. $smarty->assign_by_ref('languages', $languages);
  228. }
  229. $smarty->assign('find', $find);
  230. $smarty->assign_by_ref('sort_mode', $sort_mode);
  231. $channels = $rsslib->list_rss_modules($offset, $maxRecords, $sort_mode, $find);
  232. $cant = $channels['cant'];
  233. $smarty->assign_by_ref('cant', $cant);
  234. $temp_max = count($channels["data"]);
  235. $smarty->assign_by_ref('channels', $channels["data"]);
  236. // disallow robots to index page:
  237. $smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
  238. // Display the template
  239. $smarty->assign('mid', 'tiki-admin_rssmodules.tpl');
  240. $smarty->display("tiki.tpl");