/e107_admin/newspost.php

https://github.com/CasperGemini/e107 · PHP · 3426 lines · 2259 code · 542 blank · 625 comment · 232 complexity · eee86931ae93c22b5a98a91e6aadad3f MD5 · raw file

Large files are truncated click here to view the full file

  1. <?php
  2. /*
  3. * e107 website system
  4. *
  5. * Copyright (C) 2008-2013 e107 Inc (e107.org)
  6. * Released under the terms and conditions of the
  7. * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
  8. *
  9. * News Administration
  10. *
  11. */
  12. require_once('../class2.php');
  13. if (!getperms('H|N'))
  14. {
  15. header('Location:'.e_BASE.'index.php');
  16. exit;
  17. }
  18. //include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE);
  19. e107::coreLan('newspost', true);
  20. // ------------------------------
  21. // done in class2: require_once(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_admin.php"); // maybe this should be put in class2.php when 'admin' is detected.
  22. $newspost = new admin_newspost(e_QUERY);
  23. e107::setRegistry('_newspost_admin', $newspost);
  24. $gen = new convert();
  25. //Handle Ajax Calls
  26. if($newspost->ajax_observer()) exit;
  27. // e107::js('core','core/admin.js','prototype');
  28. //e107::getJs()->requireCoreLib('core/admin.js');
  29. class news_admin extends e_admin_dispatcher
  30. {
  31. protected $modes = array(
  32. 'main' => array(
  33. 'controller' => 'news_admin_ui',
  34. 'path' => null,
  35. 'ui' => 'news_form_ui',
  36. 'uipath' => null
  37. ),
  38. 'cat' => array(
  39. 'controller' => 'news_cat_ui',
  40. 'path' => null,
  41. 'ui' => 'news_cat_form_ui',
  42. 'uipath' => null
  43. ),
  44. 'sub' => array(
  45. 'controller' => 'news_sub_ui',
  46. 'path' => null,
  47. 'ui' => 'news_sub_form_ui',
  48. 'uipath' => null
  49. )
  50. );
  51. protected $adminMenu = array(
  52. 'main/list' => array('caption'=> LAN_LIST, 'perm' => 'H'),
  53. 'main/create' => array('caption'=> NWSLAN_45, 'perm' => 'H'), // Create/Edit News Item
  54. // 'cat/list' => array('caption'=> NWSLAN_46, 'perm' => '7'), // Category List
  55. 'cat/list' => array('caption'=> LAN_CATEGORIES, 'perm' => 'H'), // Create Category.
  56. 'cat/create' => array('caption'=> "Create Category", 'perm' => 'H'), // Category List
  57. 'main/settings' => array('caption'=> LAN_PREFS, 'perm' => '0'), // Preferences
  58. // 'main/submitted' => array('caption'=> "Old Submitted ", 'perm' => 'N'), // Submitted News
  59. 'sub/list' => array('caption'=> NWSLAN_47, 'perm' => 'N'), // Submitted News
  60. // 'main/maint' => array('caption'=> LAN_NEWS_55, 'perm' => '0') // Maintenance
  61. );
  62. protected $adminMenuAliases = array(
  63. 'main/edit' => 'main/list',
  64. 'cat/edit' => 'cat/list'
  65. );
  66. protected $menuTitle = "News";
  67. }
  68. class news_cat_ui extends e_admin_ui
  69. {
  70. protected $pluginTitle = ADLAN_0; // "News"
  71. protected $pluginName = 'core';
  72. protected $table = "news_category";
  73. protected $pid = "category_id";
  74. protected $perPage = 0; //no limit
  75. protected $batchDelete = false;
  76. protected $sortField = 'category_order';
  77. protected $listOrder = "category_order ASC";
  78. protected $fields = array(
  79. 'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
  80. 'category_id' => array('title'=> LAN_ID, 'type' => 'number', 'width' =>'5%', 'forced'=> TRUE, 'readonly'=>TRUE),
  81. 'category_icon' => array('title'=> LAN_ICON, 'type' => 'icon', 'data' => 'str', 'width' => '100px', 'thclass' => 'center', 'class'=>'center', 'readParms'=>'thumb=60&thumb_urlraw=0&thumb_aw=60','readonly'=>FALSE, 'batch' => FALSE, 'filter'=>FALSE),
  82. 'category_name' => array('title'=> LAN_TITLE, 'type' => 'text', 'inline'=>true, 'width' => 'auto', 'thclass' => 'left', 'readonly'=>FALSE, 'validate' => true, 'inline' => true),
  83. 'category_meta_description' => array('title'=> LAN_DESCRIPTION, 'type' => 'textarea', 'inline'=>true, 'width' => 'auto', 'thclass' => 'left','readParms' => 'expand=...&truncate=150&bb=1', 'readonly'=>FALSE),
  84. 'category_meta_keywords' => array('title'=> LAN_KEYWORDS, 'type' => 'tags', 'inline'=>true, 'width' => 'auto', 'thclass' => 'left', 'readonly'=>FALSE),
  85. 'category_sef' => array('title'=> LAN_SEFURL, 'type' => 'text', 'inline'=>true, 'width' => 'auto', 'readonly'=>FALSE), // Display name
  86. 'category_manager' => array('title'=> "Manage Permissions",'type' => 'userclass', 'inline'=>true, 'width' => 'auto', 'data' => 'int','batch'=>TRUE, 'filter'=>TRUE),
  87. 'category_order' => array('title'=> LAN_ORDER, 'type' => 'text', 'width' => 'auto', 'thclass' => 'right', 'class'=> 'right' ),
  88. 'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'width' => '10%', 'forced'=>TRUE, 'thclass' => 'center last', 'class' => 'center', 'sort' => true)
  89. );
  90. protected $fieldpref = array('checkboxes', 'category_icon', 'category_id', 'category_name', 'category_description','category_manager', 'category_order', 'options');
  91. protected $newspost;
  92. function init()
  93. {
  94. $this->newspost = new admin_newspost;
  95. }
  96. // function createPage()
  97. // {
  98. // $this->newspost->show_categories();
  99. // }
  100. public function beforeCreate($new_data)
  101. {
  102. if(empty($new_data['category_sef']))
  103. {
  104. $new_data['category_sef'] = eHelper::title2sef($new_data['category_name']);
  105. }
  106. else
  107. {
  108. $new_data['category_sef'] = eHelper::secureSef($new_data['category_sef']);
  109. }
  110. $sef = e107::getParser()->toDB($new_data['category_sef']);
  111. if(e107::getDb()->count('news_category', '(*)', "category_sef='{$sef}'"))
  112. {
  113. e107::getMessage()->addError('Please choose unique SEF URL string for this category');
  114. return false;
  115. }
  116. if(empty($new_data['category_order']))
  117. {
  118. $c = e107::getDb()->count('news_category');
  119. $new_data['category_order'] = $c ? $c : 0;
  120. }
  121. return $new_data;
  122. }
  123. public function beforeUpdate($new_data, $old_data, $id)
  124. {
  125. if(empty($new_data['category_sef']))
  126. {
  127. $new_data['category_sef'] = eHelper::title2sef($new_data['category_name']);
  128. }
  129. $sef = e107::getParser()->toDB($new_data['category_sef']);
  130. if(e107::getDb()->count('news_category', '(*)', "category_sef='{$sef}' AND category_id!=".intval($id)))
  131. {
  132. e107::getMessage()->addError('Please choose unique SEF URL string for this category');
  133. return false;
  134. }
  135. return $new_data;
  136. }
  137. }
  138. class news_cat_form_ui extends e_admin_form_ui
  139. {
  140. }
  141. // Submitted News Area.
  142. class news_sub_ui extends e_admin_ui
  143. {
  144. protected $pluginTitle = ADLAN_0; // "News"
  145. protected $pluginName = 'core';
  146. protected $table = "submitnews";
  147. protected $pid = "submitnews_id";
  148. protected $perPage = 10; //no limit
  149. protected $batchDelete = true;
  150. protected $formQuery = "mode=main&amp;action=create";
  151. protected $listOrder = "submitnews_id desc";
  152. // submitnews_id submitnews_name submitnews_email submitnews_title submitnews_category submitnews_item submitnews_datestamp submitnews_ip submitnews_auth submitnews_file
  153. protected $fields = array(
  154. 'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
  155. 'submitnews_id' => array('title'=> LAN_ID, 'type' => 'number', 'width' =>'5%', 'forced'=> TRUE, 'readonly'=>TRUE),
  156. 'submitnews_title' => array('title'=> LAN_TITLE, 'type' => 'method', 'width' => '35%', 'thclass' => 'left', 'readonly'=>TRUE),
  157. 'submitnews_datestamp' => array('title' => LAN_NEWS_32, 'type' => 'datestamp', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'parms' => 'mask=%A %d %B %Y'),
  158. 'submitnews_category' => array('title'=> LAN_CATEGORY, 'type' => 'dropdown', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>FALSE),
  159. // 'submitnews_item' => array('title'=> LAN_DESCRIPTION, 'type' => 'method', 'width' => 'auto', 'thclass' => 'left','readParms' => 'expand=...&truncate=150&bb=1', 'readonly'=>TRUE),
  160. 'submitnews_name' => array('title'=> LAN_AUTHOR, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>TRUE),
  161. 'submitnews_ip' => array('title'=> "IP", 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>TRUE),
  162. 'submitnews_auth' => array('title'=> "User", 'type' => 'user', 'width' => 'auto', 'thclass' => 'right', 'class'=> 'right' ),
  163. 'options' => array('title'=> LAN_OPTIONS, 'type' => "method", 'width' => '10%', 'forced'=>TRUE, 'thclass' => 'center last', 'class' => 'center')
  164. );
  165. protected $fieldpref = array('checkboxes', 'submitnews_id', 'submitnews_title', 'submitnews_category', 'options');
  166. protected $newspost;
  167. protected $cats;
  168. function init()
  169. {
  170. $sql = e107::getDb();
  171. $sql->db_Select_gen("SELECT category_id,category_name FROM #news_category");
  172. while($row = $sql->fetch())
  173. {
  174. $cat = $row['category_id'];
  175. $this->cats[$cat] = $row['category_name'];
  176. }
  177. asort($this->cats);
  178. $this->fields['submitnews_category']['writeParms'] = $this->cats;
  179. $this->newspost = new admin_newspost;
  180. }
  181. // function createPage()
  182. // {
  183. // $this->newspost->show_categories();
  184. // }
  185. public function beforeCreate($new_data)
  186. {
  187. }
  188. public function beforeUpdate($new_data, $old_data, $id)
  189. {
  190. }
  191. }
  192. class news_sub_form_ui extends e_admin_form_ui
  193. {
  194. function submitnews_title($cur,$val)
  195. {
  196. $tp = e107::getParser();
  197. $row = $this->getController()->getListModel();
  198. $submitnews_id = $row->get('submitnews_id');
  199. $submitnews_title = $row->get('submitnews_title');
  200. $submitnews_file = $row->get('submitnews_file');
  201. $submitnews_item = $row->get('submitnews_item');
  202. // $text .= "<a href='#submitted_".$submitnews_id."' class='e-modal' >";
  203. $text .= "<a data-toggle='modal' href='#submitted_".$submitnews_id."' data-cache='false' data-target='#submitted_".$submitnews_id."' class='e-tip' title='".LAN_PREVIEW."'>";
  204. $text .= $tp->toHTML($submitnews_title,FALSE,'emotes_off, no_make_clickable');
  205. $text .= '</a>';
  206. $text .= '
  207. <div id="submitted_'.$submitnews_id.'" class="modal hide fade" tabindex="-1" role="dialog" aria-hidden="true">
  208. <div class="modal-header">
  209. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
  210. <h4>'.$tp->toHtml($submitnews_title,false,'TITLE').'</h4>
  211. </div>
  212. <div class="modal-body">
  213. <p>';
  214. $text .= $tp->toHTML($submitnews_item,TRUE);
  215. if($submitnews_file)
  216. {
  217. $tmp = explode(',',$submitnews_file);
  218. $text .= "<br />";
  219. foreach($tmp as $imgfile)
  220. {
  221. $url = $tp->thumbUrl(e_UPLOAD.$imgfile,array('aw'=>400),true);
  222. $text .= "<br /><img src='".$url."' alt='".$imgfile."' />";
  223. }
  224. }
  225. $text .= '</p>
  226. </div>
  227. <div class="modal-footer">
  228. <a href="#" data-dismiss="modal" class="btn btn-primary">Close</a>
  229. </div>
  230. </div>';
  231. return $text;
  232. }
  233. // Override the default Options field.
  234. function options($parms, $value, $id, $attributes)
  235. {
  236. if($attributes['mode'] == 'read')
  237. {
  238. $text = "<div class='btn-group'>";
  239. $approved = $this->getController()->getListModel()->get('submitnews_auth'); // approved;
  240. if($approved == 0)
  241. {
  242. //$text = $this->submit_image('submitnews['.$id.']', 1, 'execute', NWSLAN_58);
  243. $text = "<a class='btn btn-large' href='".e_SELF."?mode=main&action=create&sub={$id}'>".ADMIN_EXECUTE_ICON."</a>";
  244. // NWSLAN_103;
  245. }
  246. else // Already submitted;
  247. {
  248. }
  249. $text .= $this->submit_image('etrigger_delete['.$id.']', $id, 'delete', LAN_DELETE.' [ ID: '.$id.' ]', array('class' => 'btn btn-large action delete'.$delcls));
  250. $text .= "</div>";
  251. return $text;
  252. }
  253. }
  254. }
  255. // Main News Area.
  256. class news_admin_ui extends e_admin_ui
  257. {
  258. protected $pluginTitle = ADLAN_0; // "News"
  259. protected $pluginName = 'core';
  260. protected $table = "news";
  261. protected $pid = "news_id";
  262. protected $perPage = 10; //no limit
  263. protected $batchDelete = true;
  264. protected $batchCopy = true;
  265. protected $batchLink = true;
  266. protected $listOrder = "news_id desc";
  267. // true for 'vars' value means use same var
  268. protected $url = array(
  269. 'route'=>'news/view/item',
  270. 'name' => 'news_title',
  271. 'description' => 'news_summary',
  272. 'vars'=> array('news_id' => true, 'news_sef' => true, 'category_id' => 'news_category', 'category_sef' => true) // FIXME category_sef missing, we have to retrieve category data on the list view
  273. ); // 'link' only needed if profile not provided.
  274. protected $listQry = "SELECT n.*,u.user_id,u.user_name FROM #news AS n LEFT JOIN #user AS u ON n.news_author = u.user_id "; // without any Order or Limit.
  275. protected $fields = array(
  276. 'checkboxes' => array('title' => '', 'type' => null, 'width' => '3%', 'thclass' => 'center first', 'class' => 'center', 'nosort' => true, 'toggle' => 'news_selected', 'forced' => TRUE),
  277. 'news_id' => array('title' => LAN_ID, 'type' => 'text', 'width' => '5%', 'thclass' => 'center', 'class' => 'center', 'nosort' => false, 'readParms'=>'link=sef&target=blank'),
  278. 'news_thumbnail' => array('title' => NWSLAN_67, 'type' => 'method', 'width' => '110px', 'thclass' => 'center', 'class' => "center", 'nosort' => false, 'readParms'=>'thumb=60&thumb_urlraw=0&thumb_aw=60','readonly'=>false),
  279. 'news_title' => array('title' => LAN_TITLE, 'type' => 'text', 'inline'=>true, 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
  280. 'news_summary' => array('title' => LAN_NEWS_27, 'type' => 'text', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
  281. 'news_meta_keywords' => array('title' => LAN_KEYWORDS, 'type' => 'text', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
  282. 'news_meta_description' => array('title' => LAN_DESCRIPTION,'type' => 'text', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
  283. 'news_sef' => array('title' => LAN_SEFURL, 'type' => 'text', 'inline'=>true, 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
  284. 'user_name' => array('title' => LAN_AUTHOR, 'type' => 'text', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'noedit' => true),
  285. 'news_datestamp' => array('title' => LAN_NEWS_32, 'type' => 'datestamp', 'data' => 'int', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'parms' => 'mask=%A %d %B %Y', 'filter'=>true),
  286. 'news_category' => array('title' => NWSLAN_6, 'type' => 'dropdown', 'data' => 'int', 'inline'=>true, 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'batch'=>true, 'filter'=>true),
  287. 'news_start' => array('title' => "Start", 'type' => 'datestamp', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'parms' => 'mask=%A %d %B %Y'),
  288. 'news_end' => array('title' => "End", 'type' => 'datestamp', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'parms' => 'mask=%A %d %B %Y'),
  289. 'news_class' => array('title' => LAN_VISIBILITY, 'type' => 'userclasses', 'inline'=>true, 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'batch'=>true, 'filter'=>true),
  290. 'news_render_type' => array('title' => LAN_TEMPLATE, 'type' => 'comma', 'inline'=>false, 'width' => 'auto', 'thclass' => 'center', 'class' => null, 'nosort' => false, 'batch'=>true, 'filter'=>true),
  291. 'news_sticky' => array('title' => LAN_NEWS_28, 'type' => 'boolean', 'data' => 'int' , 'width' => 'auto', 'thclass' => 'center', 'class' => 'center', 'nosort' => false, 'batch'=>true, 'filter'=>true),
  292. 'news_allow_comments' => array('title' => NWSLAN_15, 'type' => 'boolean', 'data' => 'int', 'width' => 'auto', 'thclass' => 'center', 'class' => 'center', 'nosort' => false,'batch'=>true, 'filter'=>true,'readParms'=>'reverse=1','writeParms'=>'reverse=1'),
  293. 'news_comment_total' => array('title' => LAN_NEWS_60, 'type' => 'number', 'width' => '10%', 'thclass' => '', 'class' => null, 'nosort' => false),
  294. 'options' => array('title' => LAN_OPTIONS, 'type' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center', 'nosort' => true, 'forced' => TRUE)
  295. );
  296. protected $fieldpref = array('checkboxes','news_id', 'news_thumbnail', 'news_title', 'news_datestamp', 'news_category', 'options');
  297. protected $cats = array();
  298. protected $newspost;
  299. protected $news_renderTypes = array( // TODO Placement location and template should be separate.
  300. '0' => "Default Area",
  301. '1' => "Default Area - Title",
  302. '4' => "Default Area - Title/Summary",
  303. '2' => "Sidebar - Othernews",
  304. '3' => "Sidebar - Othernews 2",
  305. '5' => "Carousel",
  306. //'5' => "Featurebox"
  307. );
  308. function init()
  309. {
  310. // Ping Changes to Services.
  311. $pingServices = e107::getPref('news_ping_services');
  312. //TODO Use Ajax with progress-bar.
  313. $mes = e107::getMessage();
  314. if(vartrue($_POST['news_ping'],false) && (count($pingServices)>0) && in_array(e_UC_PUBLIC, $_POST['news_userclass']))
  315. {
  316. $mes->addDebug("Initiating ping",'default',true);
  317. include (e_HANDLER.'xmlrpc/xmlrpc.inc.php');
  318. include (e_HANDLER.'xmlrpc/xmlrpcs.inc.php');
  319. include (e_HANDLER.'xmlrpc/xmlrpc_wrappers.inc.php');
  320. $extendedServices = array('blogsearch.google.com');
  321. $port = 80;
  322. foreach($pingServices as $fullUrl)
  323. {
  324. $fullUrl = str_replace("http://","", trim($fullUrl));
  325. list($server,$path) = explode("/",$fullUrl, 2);
  326. $path = "/".$path;
  327. $weblog_name = SITENAME;
  328. $weblog_url = $_SERVER['HTTP_HOST'].e_HTTP;
  329. $changes_url = $_SERVER['HTTP_HOST'].e107::getUrl()->create('news/view/item', $_POST); // $_SERVER['HTTP_HOST'].e_HTTP."news.php?extend.".$_POST['news_id'];
  330. $cat_or_rss = $_SERVER['HTTP_HOST'].e_PLUGIN_ABS."rss_menu/rss.php?1.2";
  331. $extended = (in_array($server, $extendedServices)) ? true : false;
  332. if($this->ping($server, $port, $path, $weblog_name, $weblog_url, $changes_url, $cat_or_rss, $extended))
  333. {
  334. e107::getMessage()->addDebug("Successfully Pinged: ".$server .' with '.$changes_url , 'default', true);
  335. }
  336. }
  337. }
  338. $sql = e107::getDb();
  339. $sql->gen("SELECT category_id,category_name FROM #news_category");
  340. while($row = $sql->fetch())
  341. {
  342. $cat = $row['category_id'];
  343. $this->cats[$cat] = $row['category_name'];
  344. }
  345. asort($this->cats);
  346. $this->fields['news_category']['writeParms'] = $this->cats;
  347. $this->fields['news_render_type']['writeParms'] = $this->news_renderTypes; // array(NWSLAN_75,NWSLAN_76,NWSLAN_77,NWSLAN_77." 2","Featurebox");
  348. $this->newspost = new admin_newspost;
  349. $this->newspost->news_renderTypes = $this->news_renderTypes;
  350. $this->newspost->observer();
  351. }
  352. /* Multi-purpose ping for any XML-RPC server that supports the Weblogs.Com interface. */
  353. function ping($xml_rpc_server, $xml_rpc_port, $xml_rpc_path, $weblog_name, $weblog_url, $changes_url, $cat_or_rss='', $extended = false)
  354. {
  355. $mes = e107::getMessage();
  356. $log = e107::getAdminLog();
  357. $mes->addDebug("Attempting to ping: ".$xml_rpc_server, 'default', true);
  358. $name_param = new xmlrpcval($weblog_name, 'string');
  359. $url_param = new xmlrpcval($weblog_url, 'string');
  360. $changes_param = new xmlrpcval($changes_url, 'string');
  361. $cat_or_rss_param = new xmlrpcval($cat_or_rss, 'string');
  362. $method_name = ($extended) ? "weblogUpdates.extendedPing" : "weblogUpdates.ping";
  363. if ($cat_or_rss != "")
  364. {
  365. $params = array($name_param, $url_param, $changes_param, $cat_or_rss_param);
  366. $call_text = "$method_name(\"$weblog_name\", \"$weblog_url\", \"$changes_url\", \"$cat_or_rss\")";
  367. }
  368. else
  369. {
  370. if ($changes_url != "")
  371. {
  372. $params = array($name_param, $url_param, $changes_param);
  373. $call_text = "$method_name(\"$weblog_name\", \"$weblog_url\", \"$changes_url\")";
  374. }
  375. else
  376. {
  377. $params = array($name_param, $url_param);
  378. $call_text = "$method_name(\"$weblog_name\", \"$weblog_url\")";
  379. }
  380. }
  381. // create the message
  382. $message = new xmlrpcmsg($method_name, $params);
  383. $client = new xmlrpc_client($xml_rpc_path, $xml_rpc_server, $xml_rpc_port);
  384. $response = $client->send($message);
  385. $this->log_ping("Request: " . $call_text);
  386. $this->log_ping($message->serialize(), true);
  387. if ($response == 0)
  388. {
  389. $error_text = "Error: " . $xml_rpc_server . ": " . $client->errno . " " . $client->errstring;
  390. $this->report_error($error_text);
  391. $this->log_ping($error_text);
  392. $log->addArray(array('status'=>LAN_ERROR, 'service'=>$xml_rpc_server, 'url'=> $changes_url, 'response'=>$client->errstring))->save('PING_01');
  393. return false;
  394. }
  395. if ($response->faultCode() != 0)
  396. {
  397. $error_text = "Error: " . $xml_rpc_server . ": " . $response->faultCode() . " " . $response->faultString();
  398. $this->report_error($error_text);
  399. $log->addArray(array('status'=>LAN_ERROR, 'service'=>$xml_rpc_server, 'url'=> $changes_url, 'response'=>$response->faultString()))->save('PING_01');
  400. return false;
  401. }
  402. $response_value = $response->value();
  403. if ($this->debug)
  404. {
  405. $this->report_error($response_value->serialize());
  406. }
  407. $this->log_ping($response_value->serialize(), true);
  408. $fl_error = $response_value->structmem('flerror');
  409. $message = $response_value->structmem('message');
  410. // read the response
  411. if ($fl_error->scalarval() != false)
  412. {
  413. $error_text = "Error: " . $xml_rpc_server . ": " . $message->scalarval();
  414. $this->report_error($error_text);
  415. $log->addArray(array('status'=>LAN_ERROR, 'service'=>$xml_rpc_server, 'url'=> $changes_url, 'response'=>$message->scalarval()))->save('PING_01');
  416. // $this->log_ping($error_text);
  417. return false;
  418. }
  419. $log->addArray(array('status'=>LAN_OK, 'service'=>$xml_rpc_server, 'url'=> $changes_url, 'response'=>$message->scalarval()))->save('PING_01');
  420. return true;
  421. }
  422. // save ping data to a log file
  423. function log_ping($message, $xml_data = false)
  424. {
  425. $message = $xml_data." ".$message;
  426. file_put_contents(e_LOG."news_ping.log", $message, FILE_APPEND);
  427. }
  428. // sDisplay Ping errors.
  429. function report_error($message)
  430. {
  431. e107::getMessage()->addError($message, 'default', true);
  432. }
  433. function createPage()
  434. {
  435. // print_a($_POST);
  436. if(isset($_GET['sub']))
  437. {
  438. $id = intval($_GET['sub']);
  439. $this->loadSubmitted($id);
  440. }
  441. else
  442. {
  443. $this->preCreate();
  444. }
  445. $this->newspost->show_create_item();
  446. }
  447. function categoryPage()
  448. {
  449. if(!getperms('0|7'))
  450. {
  451. $this->noPermissions();
  452. }
  453. $this->newspost->show_categories();
  454. // $newspost->show_create_item();
  455. }
  456. function submittedPage()
  457. {
  458. $this->newspost->show_submitted_news();
  459. }
  460. function maintPage()
  461. {
  462. }
  463. function settingsPage()
  464. {
  465. return $this->newspost->show_news_prefs();
  466. }
  467. function noPermissions($qry = '')
  468. {
  469. $url = e_SELF.($qry ? '?'.$qry : '');
  470. if($qry !== e_QUERY)
  471. {
  472. $mes = e107::getMessage();
  473. $this->show_message('Insufficient permissions!', E_MESSAGE_ERROR, true);
  474. session_write_close();
  475. header('Location: '.$url);
  476. }
  477. exit;
  478. }
  479. function loadSubmitted($id)
  480. {
  481. $sql = e107::getDb();
  482. $tp = e107::getParser();
  483. if ($sql->select("submitnews", "*", "submitnews_id=".intval($id)))
  484. {
  485. //list($id, $submitnews_name, $submitnews_email, $_POST['news_title'], $submitnews_category, $_POST['news_body'], $submitnews_datestamp, $submitnews_ip, $submitnews_auth, $submitnews_file) = $sql->fetch();
  486. $row = $sql->fetch();
  487. $_POST['news_title'] = $row['submitnews_title'];
  488. $_POST['news_body'] = $row['submitnews_item'];
  489. $_POST['cat_id'] = $row['submitnews_category'];
  490. // if (defsettrue('e_WYSIWYG'))
  491. // {
  492. // if (substr($_POST['news_body'],-7,7) == '[/html]') $_POST['news_body'] = substr($_POST['news_body'],0,-7);
  493. // if (substr($_POST['news_body'],0,6) == '[html]') $_POST['news_body'] = substr($_POST['news_body'],6);
  494. // $_POST['news_body'] .= "<br /><b>".NWSLAN_49." {$row['submitnews_name']}</b>";
  495. // $_POST['news_body'] .= ($row['submitnews_file'])? "<br /><br /><img src='{e_NEWSIMAGE}{$row['submitnews_file']}' class='f-right' />": '';
  496. // }
  497. // else
  498. {
  499. $_POST['news_body'] .= "\n[[b]".NWSLAN_49." {$row['submitnews_name']}[/b]]";
  500. if($row['submitnews_file'])
  501. {
  502. $files = explode(",",$row['submitnews_file']);
  503. foreach($files as $f)
  504. {
  505. if($bbpath = e107::getMedia()->importFile($f,'news'))
  506. {
  507. $_POST['news_body'] .= "\n\n[img]".$bbpath."[/img]";
  508. }
  509. }
  510. }
  511. }
  512. $_POST['data'] = $tp->dataFilter($_POST['data']); // Filter any nasties
  513. $_POST['news_title'] = $tp->dataFilter($_POST['news_title']);
  514. }
  515. }
  516. function preCreate()
  517. {
  518. if($_GET['action'] == "edit" && !$_POST['preview'])
  519. {
  520. if(!isset($_POST['submit_news']))
  521. {
  522. if(e107::getDb()->select('news', '*', 'news_id='.intval($_GET['id'])))
  523. {
  524. $row = e107::getDb()->fetch();
  525. // if(!isset($this->news_categories[$row['news_category']]))
  526. {
  527. // $this->noPermissions();
  528. }
  529. $_POST['news_title'] = $row['news_title'];
  530. $_POST['news_sef'] = $row['news_sef'];
  531. $_POST['news_body'] = $row['news_body'];
  532. $_POST['news_author'] = $row['news_author'];
  533. $_POST['news_extended'] = $row['news_extended'];
  534. $_POST['news_allow_comments'] = $row['news_allow_comments'];
  535. $_POST['news_class'] = $row['news_class'];
  536. $_POST['news_summary'] = $row['news_summary'];
  537. $_POST['news_sticky'] = $row['news_sticky'];
  538. $_POST['news_datestamp'] = ($_POST['news_datestamp']) ? $_POST['news_datestamp'] : $row['news_datestamp'];
  539. $_POST['cat_id'] = $row['news_category'];
  540. $_POST['news_start'] = $row['news_start'];
  541. $_POST['news_end'] = $row['news_end'];
  542. $_POST['comment_total'] = e107::getDb()->db_Count("comments", "(*)", " WHERE comment_item_id={$row['news_id']} AND comment_type='0'");
  543. $_POST['news_render_type'] = $row['news_render_type'];
  544. $_POST['news_thumbnail'] = $row['news_thumbnail'];
  545. $_POST['news_meta_keywords'] = $row['news_meta_keywords'];
  546. $_POST['news_meta_description'] = $row['news_meta_description'];
  547. }
  548. }
  549. else // on submit
  550. {
  551. if(!empty($_POST['news_meta_keywords'])) $_POST['news_meta_keywords'] = eHelper::formatMetaKeys($_POST['news_meta_keywords']);
  552. }
  553. }
  554. }
  555. }
  556. class news_form_ui extends e_admin_form_ui
  557. {
  558. function news_thumbnail($curval,$mode)
  559. {
  560. if(!vartrue($curval)) return;
  561. if(strpos($curval, ",")!==false)
  562. {
  563. $tmp = explode(",",$curval);
  564. $curval = $tmp[0];
  565. }
  566. $vparm = array('thumb'=>'tag','w'=> 80);
  567. if($thumb = e107::getParser()->toVideo($curval,$vparm))
  568. {
  569. return $thumb;
  570. }
  571. if($curval[0] != "{")
  572. {
  573. $curval = "{e_IMAGE}newspost_images/".$curval;
  574. }
  575. $url = e107::getParser()->thumbUrl($curval,'aw=80');
  576. $link = e107::getParser()->replaceConstants($curval);
  577. return "<a class='e-dialog' href='{$link}'><img src='{$url}' alt='{$curval}' /></a>";
  578. }
  579. function news_title($value, $mode)
  580. {
  581. if($mode == 'read')
  582. {
  583. $news_item = $this->getController()->getListModel()->toArray();
  584. $url = e107::getUrl()->create('news/view/item', $news_item);
  585. return "<a class='e-tip' href='{$url}' title='Open in new tab' rel='external'>".$value."</a>";
  586. }
  587. return $value;
  588. }
  589. }
  590. new news_admin();
  591. require_once(e_ADMIN."auth.php");
  592. e107::getAdminUI()->runPage();
  593. if(!e_AJAX_REQUEST) require_once("footer.php");
  594. exit;
  595. function headerjs()
  596. {
  597. return;
  598. $newspost = e107::getRegistry('_newspost_admin');
  599. /*
  600. $ret .= "<script type='text/javascript'>
  601. function UpdateForm(id)
  602. {
  603. new e107Ajax.Updater('filterValue', '".e_SELF."?searchValue', {
  604. method: 'post',
  605. evalScripts: true,
  606. parameters: {filtertype: id}
  607. });
  608. }
  609. </script>";
  610. */
  611. // TODO - REMOVE
  612. $ret .= "
  613. <script type='text/javascript'>
  614. if(typeof e107Admin == 'undefined') var e107Admin = {}
  615. /**
  616. * OnLoad Init Control
  617. */
  618. e107Admin.initRules = {
  619. 'Helper': true,
  620. 'AdminMenu': false
  621. }
  622. //custom expand
  623. Element.addMethods( {
  624. newsDescToggle: function(element) {
  625. element = \$(element);
  626. if(!element.visible())
  627. element.fxToggle();
  628. return element;
  629. },
  630. newsScrollToMe: function(element) {
  631. element = \$(element);
  632. new Effect.ScrollTo(element);
  633. return element;
  634. },
  635. newsUpdateButtonSpan: function(element, str, swapClass) {
  636. element = \$(element);
  637. if(swapClass) {
  638. var swapO = swapClass.split('::');
  639. element.removeClassName(swapO[0]).addClassName(swapO[1]);
  640. }
  641. if(element.down('span')) {
  642. element.down('span').update(str);
  643. }
  644. return element;
  645. }
  646. });
  647. //fix form action if needed
  648. document.observe('dom:loaded', function() {
  649. if(\$('core-newspost-create-form')) {
  650. \$('core-newspost-create-form').observe('submit', function(event) {
  651. var form = event.element();
  652. action = form.readAttribute('action') + document.location.hash;
  653. //if(\$('create-edit-stay-1') && \$('create-edit-stay-1').checked)
  654. form.writeAttribute('action', action);
  655. });
  656. }
  657. });
  658. </script>
  659. ";
  660. if($newspost->getAction() == 'cat')
  661. {
  662. $ret .= "
  663. <script type='text/javascript'>
  664. var e_npadmin_ajaxsave = function(action, element) {
  665. var id = element.name.gsub(/[^\d]/, ''),
  666. cl = element.value,
  667. url = '#{e_ADMIN}newspost.php?' + action + '.' + id + '.' + cl;
  668. element.startLoading();
  669. new e107Ajax.Request(url.parsePath(), {
  670. onComplete: function(transport) {
  671. element.stopLoading();
  672. if(transport.responseText)
  673. alert(transport.responseText);//error
  674. }
  675. });
  676. }
  677. //e107 onload custom event
  678. e107.runOnLoad( function(event) {
  679. var celement = event.memo['element'] ? \$(event.memo.element) : \$\$('body')[0];
  680. //Unobtrusive AJAX category list reload
  681. if(\$('trigger-list-refresh')) {
  682. \$('trigger-list-refresh').observe('click', function(event) {
  683. event.stop();
  684. \$('core-newspost-cat-list-form').submitForm(
  685. 'core-newspost-cat-list-cont',
  686. { overlayPage: \$\$('body')[0] },
  687. \$('core-newspost-cat-list-form').action + '_list_refresh'
  688. );
  689. });
  690. }
  691. //Unobtrusive AJAX save category manage permissions
  692. celement.select('select[name^=multi_category_manager]').invoke('observe', 'change', function(event) {
  693. e_npadmin_ajaxsave('catmanager', event.element());
  694. });
  695. //Category order fields - user convenience
  696. celement.select('input[name^=multi_category_order]').invoke('observe', 'focus', function(event) {
  697. event.element().select();
  698. });
  699. //Unobtrusive AJAX save category order
  700. celement.select('input[name^=multi_category_order]').invoke('observe', 'blur', function(event) {
  701. e_npadmin_ajaxsave('catorder', event.element());
  702. });
  703. //Fill form - click observer (Unobtrusive AJAX edit category)
  704. \$\$('a.action[id^=core-news-catedit-]').each(function(element) {
  705. element.observe('click', function(event) {
  706. event.stop();
  707. var el = event.findElement('a');
  708. $('core-newspost-cat-create-form').fillForm(\$\$('body')[0], { handler: el.readAttribute('href') });
  709. });
  710. });
  711. }, null, true);
  712. </script>
  713. ";
  714. }
  715. elseif ($newspost->getAction() == 'pref')
  716. {
  717. $ret .= "
  718. <script type='text/javascript'>
  719. document.observe('dom:loaded', function(){
  720. \$('newsposts').observe('change', function(event) {
  721. new e107Ajax.Updater(
  722. 'newsposts-archive-cont',
  723. '".e_SELF."?pref_archnum.' + (event.element().selectedIndex + 1) + '.' + event.element().readAttribute('tabindex'),
  724. { overlayElement: 'newsposts-archive-cont' }
  725. );
  726. });
  727. });
  728. </script>
  729. ";
  730. }
  731. $ret .= $newspost->_cal->load_files();
  732. return $ret;
  733. }
  734. $e_sub_cat = 'news';
  735. require_once('auth.php');
  736. /*
  737. * Observe for delete action
  738. */
  739. $newspost->observer();
  740. /*
  741. * Show requested page
  742. */
  743. $newspost->show_page();
  744. /* OLD JS? Can't find references to this func
  745. echo "
  746. <script type=\"text/javascript\">
  747. function fclear() {
  748. document.getElementById('core-newspost-create-form').data.value = \"\";
  749. document.getElementById('core-newspost-create-form').news_extended.value = \"\";
  750. }
  751. </script>\n";
  752. */
  753. require_once("footer.php");
  754. exit;
  755. class admin_newspost
  756. {
  757. var $_request = array();
  758. var $_cal = array();
  759. var $_pst;
  760. var $_fields;
  761. var $_sort_order;
  762. var $_sort_link;
  763. var $fieldpref;
  764. var $news_categories;
  765. public $news_renderTypes = array();
  766. public $error = false;
  767. function __construct($qry='')
  768. {
  769. global $user_pref;
  770. $qry = "";
  771. $this->parseRequest($qry);
  772. require_once(e_HANDLER."cache_handler.php");
  773. require_once(e_HANDLER."news_class.php");
  774. $this->fieldpref = varset($user_pref['admin_news_columns'], array('news_id', 'news_title', 'news_author', 'news_render_type', 'options'));
  775. $this->fields = array(
  776. 'checkboxes' => array('title' => '', 'type' => null, 'data'=> false, 'width' => '3%', 'thclass' => 'center first', 'class' => 'center', 'nosort' => true, 'toggle' => 'news_selected', 'forced' => TRUE),
  777. 'news_id' => array('title' => LAN_ID, 'type' => 'number', 'data'=> 'int', 'width' => '5%', 'thclass' => 'center', 'class' => 'center', 'nosort' => false),
  778. 'news_thumbnail' => array('title' => NWSLAN_67, 'type' => 'image', 'data'=> 'str', 'width' => '110px', 'thclass' => 'center', 'class' => "center", 'nosort' => false, 'readParms'=>'thumb=60&thumb_urlraw=0&thumb_aw=60','writeParams' => 'path={e_MEDIA}','readonly'=>false),
  779. 'news_title' => array('title' => LAN_TITLE, 'type' => 'text', 'data'=> 'str','width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
  780. 'news_summary' => array('title' => LAN_NEWS_27, 'type' => 'text', 'data'=> 'str','width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
  781. 'news_meta_keywords' => array('title' => LAN_KEYWORDS, 'type' => 'text', 'data'=> 'str','width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
  782. 'news_meta_description' => array('title' => LAN_DESCRIPTION,'type' => 'text', 'data'=> 'str','width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
  783. 'news_sef' => array('title' => LAN_SEFURL, 'type' => 'text', 'data'=> 'str','width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
  784. 'user_name' => array('title' => LAN_AUTHOR, 'type' => 'text', 'data'=> 'str','width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
  785. 'news_datestamp' => array('title' => LAN_NEWS_32, 'type' => 'datestamp', 'data'=> 'str','width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'parms' => 'mask=%A %d %B %Y'),
  786. 'category_name' => array('title' => NWSLAN_6, 'type' => 'text', 'data'=> 'str','width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
  787. 'news_start' => array('title' => "Start", 'type' => 'datestamp', 'data'=> 'str','width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'parms' => 'mask=%A %d %B %Y'),
  788. 'news_end' => array('title' => "End", 'type' => 'datestamp', 'data'=> 'str','width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'parms' => 'mask=%A %d %B %Y'),
  789. 'news_class' => array('title' => LAN_VISIBILITY, 'type' => 'userclass', 'data'=> 'str', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
  790. 'news_render_type' => array('title' => LAN_NEWS_49, 'type' => 'dropdown', 'data'=> 'comma', 'width' => 'auto', 'thclass' => 'center', 'class' => null, 'nosort' => false),
  791. 'news_sticky' => array('title' => LAN_NEWS_28, 'type' => 'boolean', 'data'=> 'int', 'width' => 'auto', 'thclass' => 'center', 'class' => 'center', 'nosort' => false),
  792. 'news_allow_comments' => array('title' => NWSLAN_15, 'type' => 'boolean', 'data'=> 'int', 'width' => 'auto', 'thclass' => 'center', 'class' => 'center', 'nosort' => false),
  793. 'news_comment_total' => array('title' => LAN_NEWS_60, 'type' => 'number', 'data'=> 'int', 'width' => '10%', 'thclass' => '', 'class' => null, 'nosort' => false),
  794. 'options' => array('title' => LAN_OPTIONS, 'type' => null, 'data'=> false, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center', 'nosort' => true, 'forced' => TRUE)
  795. );
  796. /* $ren_type = array(NWSLAN_75,NWSLAN_76,NWSLAN_77,NWSLAN_77." 2");
  797. $r_array = array();
  798. foreach($ren_type as $key=>$value)
  799. {
  800. $this->news_renderTypes[$key] = $value;
  801. }*/
  802. // $this->news_renderTypes = array('0'=>NWSLAN_75,'1'=>NWSLAN_76,'2'=>NWSLAN_77,'3'=>NWSLAN_77." 2",'4'=>"Featurebox");
  803. // $this->news_renderTypes = array('0'=>"FrontPage",'1'=>"FrontPage - Linkonly",'2'=>"Othernews Sidebar",'3'=>"Othernews Sidebar"." 2",'4'=>"Featurebox");
  804. }
  805. function parseRequest($qry)
  806. {
  807. $tmp = explode(".", $qry);
  808. $action = varsettrue($tmp[0], 'main');
  809. $sub_action = varset($tmp[1], '');
  810. $id = isset($tmp[2]) && is_numeric($tmp[2]) ? intval($tmp[2]) : 0;
  811. $this->_sort_order = isset($tmp[2]) && !is_numeric($tmp[2]) ? $tmp[2] : 'desc';
  812. $from = intval(varset($tmp[3],0));
  813. unset($tmp);
  814. $action = vartrue($_GET['action'],'main');
  815. $sub_action = varset($_GET['sub'],'');
  816. $id = isset($_GET['id']) && is_numeric($_GET['id']) ? intval($_GET['id']) : 0;
  817. $this->_sort_order = isset($_GET['id']) && !is_numeric($_GET['id']) ? $_GET['id'] : 'desc';
  818. $from = intval(varset($_GET['frm'],0));
  819. if ($this->_sort_order != 'asc') $this->_sort_order = 'desc';
  820. $this->_sort_link = ($this->_sort_order) == 'asc' ? 'desc' : 'asc';
  821. $sort_order = 'desc';
  822. $this->_request = array($action, $sub_action, $id, $sort_order, $from);
  823. }
  824. function getAction()
  825. {
  826. return $this->_request[0];
  827. }
  828. /**
  829. * @param string $action
  830. * @return admin_newspost
  831. */
  832. function setAction($action)
  833. {
  834. $this->_request[0] = $action;
  835. return $this;
  836. }
  837. function getSubAction()
  838. {
  839. return $this->_request[1];
  840. }
  841. /**
  842. * @param string $action
  843. * @return admin_newspost
  844. */
  845. function setSubAction($action)
  846. {
  847. $this->_request[1] = $action;
  848. return $this;
  849. }
  850. function getId()
  851. {
  852. return $this->_request[2];
  853. }
  854. /**
  855. * @param integer $id
  856. * @return admin_newspost
  857. */
  858. function setId($id)
  859. {
  860. $this->_request[2] = intval($id);
  861. return $this;
  862. }
  863. function getSortOrder()
  864. {
  865. return $this->_request[3];
  866. }
  867. function getFrom()
  868. {
  869. return $this->_request[4];
  870. }
  871. function clear_cache()
  872. {
  873. $ecache = e107::getCache();
  874. $ecache->clear("news.php"); //TODO change it to 'news_*' everywhere
  875. $ecache->clear("news_", false, true); //NEW global news cache prefix
  876. //$ecache->clear("nq_news_"); - supported by cache::clear() now
  877. //$ecache->clear("nomd5_news_"); supported by cache::clear() now
  878. $ecache->clear("othernews"); //TODO change it to 'news_othernews' everywhere
  879. $ecache->clear("othernews2"); //TODO change it to 'news_othernews2' everywhere
  880. return $this;
  881. }
  882. function clear_rwcache($sefstr = '')
  883. {
  884. // obsolete
  885. }
  886. function set_rwcache($sefstr, $data)
  887. {
  888. // obsolete
  889. }
  890. function ajax_observer()
  891. {
  892. $method = 'ajax_exec_'.$this->getAction();
  893. if(e_AJAX_REQUEST && method_exists($this, $method))
  894. {
  895. $this->$method();
  896. return true;
  897. }
  898. return false;
  899. }
  900. function observer()
  901. {
  902. e107::getDb()->db_Mark_Time('News Administration');
  903. $this->news_categories = array();
  904. if(e107::getDb()->select('news_category', '*', (getperms('0') ? '' : 'category_manager IN ('.USERCLASS_LIST.')')))
  905. {
  906. $this->news_categories = e107::getDb()->db_getList('ALL', FALSE, FALSE, 'category_id');
  907. }
  908. //Required on create & savepreset action triggers
  909. if(isset($_POST['news_userclass']) && is_array($_POST['news_userclass']))
  910. {
  911. $_POST['news_class'] = implode(",", $_POST['news_userclass']);
  912. unset($_POST['news_userclass']);
  913. }
  914. $main = getperms('0');
  915. if(isset($_POST['delete']) && is_array($_POST['delete']))
  916. {
  917. $this->_observe_delete();
  918. }
  919. elseif(isset($_POST['execute_batch']))
  920. {
  921. $this->process_batch($_POST['news_selected']);
  922. }
  923. elseif(isset($_POST['submit_news']))
  924. {
  925. $this->_observe_submit_item($this->getSubAction(), $this->getId());
  926. }
  927. elseif($main && isset($_POST['create_category']))
  928. {
  929. $this->_observe_create_category();
  930. }
  931. elseif($main && isset($_POST['update_category']))
  932. {
  933. $this->_observe_update_category();
  934. }
  935. elseif($main && isset($_POST['multi_update_category']))
  936. {
  937. $this->_observe_multi_create_category();
  938. }
  939. elseif($main && isset($_POST['save_prefs']))
  940. {
  941. $this->_observe_save_prefs();
  942. }
  943. elseif(isset($_POST['submitupload']))
  944. {
  945. $this->_observe_upload();
  946. }
  947. elseif(isset($_POST['news_comments_recalc']))
  948. {
  949. $this->_observe_newsCommentsRecalc();
  950. }
  951. if(isset($_POST['etrigger_ecolumns'])) //elseif fails.
  952. {
  953. // $this->_observe_saveColumns();
  954. }
  955. }
  956. function show_page()
  957. {
  958. // print_a($POST);
  959. switch ($this->getAction()) {
  960. case 'create':
  961. $this->_pst->read_preset('admin_newspost'); //only works here because $_POST is used.
  962. $this->show_create_item();
  963. break;
  964. case 'cat':
  965. if(!getperms('0|7'))
  966. {
  967. $this->noPermissions();
  968. }
  969. $this->show_categories();
  970. break;
  971. case 'sn':
  972. $this->show_submitted_news();
  973. break;
  974. case 'pref':
  975. if(!getperms('0'))
  976. {
  977. $this->noPermissions();
  978. }
  979. $this->show_news_prefs();
  980. break;
  981. case 'maint' :
  982. if(!getperms('0'))
  983. {
  984. $this->noPermissions();
  985. }
  986. $this->showMaintenance();
  987. break;
  988. default:
  989. $this->show_existing_items();
  990. break;
  991. }
  992. }
  993. function _observe_delete()
  994. {
  995. $admin_log = e107::getAdminLog();
  996. //FIXME - SEF URL cache
  997. $tmp = array_keys($_POST['delete']);
  998. list($delete, $del_id) = explode("_", $tmp[0]);
  999. $del_id = intval($del_id);
  1000. if(!$del_id) return false;
  1001. $e107 = e107::getInstance();
  1002. switch ($delete) {
  1003. case 'main':
  1004. if ($sql->count('news','(*)',"news_id={$del_id}"))
  1005. {
  1006. e107::getEvent()->trigger("newsdel", $del_id);
  1007. if($sql->delete("news", "news_id={$del_id}"))
  1008. {
  1009. $admin_log->log_event('NEWS_01',$del_id,E_LOG_INFORMATIVE,'');
  1010. $this->show_message(NWSLAN_31." #".$del_id." ".NWSLAN_32, E_MESSAGE_SUCCESS);
  1011. $this->clear_cache();
  1012. $data = array('method'=>'delete', 'table'=>'news', 'id'=>$del_id, 'plugin'=>'news', 'function'=>'delete');
  1013. $this->show_message(e107::getEvent()->triggerHook($data), E_MESSAGE_WARNING);
  1014. admin_purge_related("news", $del_id);
  1015. }
  1016. }
  1017. break;
  1018. case 'category':
  1019. if(!getperms('0|7')) $this->noPermissions();
  1020. if (($count = $sql->count('news','(news_id)',"news_category={$del_id}")) === false || $count > 0)
  1021. {
  1022. $this->show_message('Category is in used in <strong>'.$count.'</strong> news items and cannot be deleted.', E_MESSAGE_ERROR);
  1023. return false;
  1024. }
  1025. if ($sql->count('news_category','(*)',"category_id={$del_id}"))
  1026. {
  1027. e107::getEvent()->trigger("newscatdel", $del_id);
  1028. if ($sql->delete("news_category", "category_id={$del_id}"))
  1029. {
  1030. $admin_log->log_event('NEWS_02',$del_id,E_LOG_INFORMATIVE,'');
  1031. $this->show_message(NWSLAN_33." #".$del_id." ".NWSLAN_32, E_MESSAGE_SUCCESS);
  1032. $this->clear_cache();
  1033. }
  1034. }
  1035. break;
  1036. case 'sn':
  1037. if ($sql->delete("submitnews", "submitnews_id={$del_id}"))
  1038. {
  1039. $admin_log->log_event('NEWS_03',$del_id,E_LOG_INFORMATIVE,'');
  1040. $this->show_message(NWSLAN_34." #".$del_id." ".NWSLAN_32);
  1041. $this->clear_cache();
  1042. }
  1043. break;
  1044. default:
  1045. return false;
  1046. }
  1047. return true;
  1048. }
  1049. /**
  1050. * For future use: multiple-images.
  1051. */
  1052. private function processThumbs($postedImage)
  1053. {
  1054. if(is_array($postedImage))
  1055. {
  1056. return implode(",",array_filter($postedImage));
  1057. }
  1058. else
  1059. {
  1060. return $postedImage;
  1061. }
  1062. }
  1063. // In USE.
  1064. function _observe_submit_item($sub_action, $id)
  1065. {
  1066. // ##### Format and submit item to DB
  1067. $ix = new news;
  1068. // jQuery UI temporary date-time fix - inputdatetime -> inputdate
  1069. $_POST['news_start'] = vartrue(e107::getDate()->convert($_POST['news_start'],'inputdatetime'), 0);
  1070. if($_POST['news_start'])
  1071. {
  1072. // $_POST['news_start'] = e107::getDate()->convert($_POST['news_start']);
  1073. }
  1074. else
  1075. {
  1076. // $_POST['news_start'] = 0;
  1077. }
  1078. if($_POST['news_end'])
  1079. {
  1080. $_POST['news_end'] = e107::getDate()->convert($_POST['news_end'],'inputdatetime');
  1081. }
  1082. else
  1083. {
  1084. $_POST['news_end'] = 0;
  1085. }
  1086. if($_POST['news_datestamp'])
  1087. {
  1088. $_POST['news_datestamp'] = e107::getDate()->convert($_POST['news_datestamp'],'inputdatetime');
  1089. }
  1090. else
  1091. {
  1092. $_POST['news_datestamp'] = time();
  1093. }
  1094. $_POST['news_thumbnail'] = $this->processThumbs($_POST['news_thumbnail']);
  1095. /*
  1096. $matches = array();
  1097. if(preg_match('#(.*?)/(.*?)/(.*?) (.*?):(.*?):(.*?)$#', $_POST['news_datestamp'], $matches))
  1098. {
  1099. $_POST['news_datestamp'] = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[1], $matches[3]);
  1100. }
  1101. else
  1102. {
  1103. $_POST['news_datestamp'] = time();
  1104. }
  1105. if($_POST['update_datestamp'])
  1106. {
  1107. $_POST['news_datestamp'] = time();
  1108. }
  1109. */
  1110. if ($id && $sub_action != "sn" && $sub_action != "upload")
  1111. {
  1112. $_POST['news_id'] = $id;
  1113. }
  1114. else
  1115. {
  1116. e107::getDb()->db_Update('submitnews', "submitnews_auth=1 WHERE submitnews_id ={$id}");
  1117. e107::getAdminLog()->log_event('NEWS_07', $id, E_LOG_INFORMATIVE,'');
  1118. }
  1119. if (!isset($_POST['cat_id']))
  1120. {
  1121. $_POST['cat_id'] = 0;
  1122. }
  1123. $_POST['news_category'] = $_POST['cat_id'];
  1124. if(!isset($this->news_categories[$_POST['news_category']]))
  1125. {
  1126. $this->noPermissions();
  1127. }
  1128. /*if(isset($_POST['news_thumbnail']))
  1129. {
  1130. $_POST['news_thumbnail'] = urldecode(basename($_POST['news_thumbnail']));
  1131. }*/
  1132. $_POST['news_render_type'] = implode(",",$_POST['news_render_type']);
  1133. // print_a($_POST);
  1134. // exit;
  1135. $tmp = explode(chr(35), $_POST['news_author']);
  1136. $_POST['news_author'] = $tmp[0];
  1137. $ret = $ix->submit_item($_POST, !vartrue($_POST['create_edit_stay']));
  1138. if($ret['error'])
  1139. {
  1140. e107::getMessage()->mergeWithSession() //merge with session messages
  1141. ->add(($id ? LAN_UPDATED_FAILED : LAN_CREATED_FAILED), E_MESSAGE_ERROR);
  1142. $_POST['news_sef'] = $ret['data']['news_sef'];
  1143. return false;
  1144. }
  1145. $this->clear_cache();
  1146. if(isset($_POST['create_edit_stay']) && !empty($_POST['create_edit_stay']))
  1147. {
  1148. if($this->getAction() != 'edit')
  1149. {
  1150. session_write_close();
  1151. $rurl = e_SELF.(vartrue($ret['news_id']) ? '?mode='.$_GET['mode'].'&action=edit&id='.$ret['news_id'] : '');
  1152. header('Location: '.$rurl);
  1153. exit;
  1154. }
  1155. }
  1156. else
  1157. {
  1158. session_write_close();
  1159. header('Location:'.e_SELF);
  1160. exit;
  1161. }
  1162. }
  1163. function _observe_create_category()
  1164. {
  1165. if(!getperms('0|7'))
  1166. {
  1167. $this->noPermissions();
  1168. }
  1169. //FIXME - lan, e_model based news administration model
  1170. $this->error = false;
  1171. if(empty($_POST['category_name']))
  1172. {
  1173. $this->show_message('Validation Error: Missing Category name', E_MESSAGE_ERROR);
  1174. $this->error = true;
  1175. if(!empty($_POST['category_sef']))
  1176. {
  1177. $_POST['category_sef'] = eHelper::secureSef($_POST['category_sef']);
  1178. }
  1179. }
  1180. else
  1181. {
  1182. // first format sef...
  1183. if(empty($_POST['category_sef']))
  1184. {
  1185. $_POST['category_sef'] = eHelper::title2sef($_POST['category_name']);
  1186. }
  1187. else
  1188. {
  1189. $_POST['category_sef'] = eHelper::secureSef($_POST['category_sef']);
  1190. }
  1191. }
  1192. // ...then check it
  1193. if(empty($_POST['category_sef']))
  1194. {
  1195. $this->error = true;
  1196. $this->show_message('Validation error: News Category SEF URL value is required field and can\'t be empty!', E_MESSAGE_ERROR);
  1197. }
  1198. elseif(e107::getDb()->db_Count('news_category', '(category_id)', "category_sef='".e107::getParser()->toDB($_POST['category_sef'])."'"))
  1199. {
  1200. $this->error = true;
  1201. $this->show_message('Validation error: News Category SEF URL is unique field - current value already in use! Please choose another SEF URL value.', E_MESSAGE_ERROR);
  1202. }
  1203. if (!$this->error)
  1204. {
  1205. $inserta = array();
  1206. $inserta['data']['category_icon'] = $_POST['category_icon'];
  1207. $inserta['_FIELD_TYPES']['category_icon'] = 'todb';
  1208. $inserta['data']['category_name'] = $_POST['category_name'];
  1209. $inserta['_FIELD_TYPES']['category_name'] = 'todb';
  1210. $inserta['data']['category_sef'] = $_POST['category_sef'];
  1211. $inserta['_FIELD_TYPES']['category_sef'] = 'todb';
  1212. $inserta['data']['category_meta_description'] = eHelper::formatMetaDescription($_POST['category_meta_description']);
  1213. $inserta['_FIELD_TYPES']['category_meta_description'] = 'todb';
  1214. $inserta['data']['category_meta_keywords'] = eHelper::formatMetaKeys($_POST['category_meta_keywords']);
  1215. $inserta['_FIELD_TYPES']['category_meta_keywords'] = 'todb';
  1216. $inserta['data']['category_manager'] = $_POST['category_manager'];
  1217. $inserta['_FIELD_TYPES']['category_manager'] = 'int';
  1218. $inserta['data']['category_order'] = $_POST['category_order'];
  1219. $inserta['_FIELD_TYPES']['category_order'] = 'int';
  1220. $id = e107::getDb()->db_Insert('news_category', $inserta);
  1221. if($id)
  1222. {
  1223. $inserta['data']['category_id'] = $id;
  1224. //admin log now supports DB array and method chaining
  1225. e107::getAdminLog()->log_event('NEWS_04', $inserta, E_LOG_INFORMA