PageRenderTime 84ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/extra/modules/news/action.php

http://textmotion.googlecode.com/
PHP | 424 lines | 346 code | 58 blank | 20 comment | 9 complexity | 9c36e5466e1b4dc230afe91f90bd1141 MD5 | raw file
Possible License(s): MIT, CC0-1.0
  1. <?php
  2. /**
  3. * textMotion
  4. * ---
  5. * Written by Jose Carlos Nieto <xiam@menteslibres.org>
  6. * Copyright (c) 2007-2008, Jose Carlos Nieto <xiam@menteslibres.org>
  7. *
  8. * Licensed under The MIT License
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @author Jose Carlos Nieto <xiam@menteslibres.org>
  12. * @package textMotion
  13. * @copyright Copyright (c) 2007-2008, J. Carlos Nieto <xiam@menteslibres.org>
  14. * @link http://www.textmotion.org
  15. * @version $Revision: 1504 $
  16. * @modifiedby $LastChangedBy: xiam.core $
  17. * @lastmodified $Date: 2008-11-07 02:50:31 +1100 (Fri, 07 Nov 2008) $
  18. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  19. *
  20. */
  21. class news_action extends tm_action {
  22. public function user_ajax_submit() {
  23. extract(
  24. $this->using(
  25. 'db',
  26. 'param',
  27. 'auth',
  28. 'services',
  29. 'json',
  30. 'meteora',
  31. 'conf',
  32. 'access'
  33. )
  34. );
  35. if ($access->verify($this, 60*15, $conf->get('news/submissions_per_quarter', 5, 'i'))) {
  36. $param->not_empty('article.title', 'article.content');
  37. $param->from_editor('article.content');
  38. $db->insert(
  39. 'news',
  40. array(
  41. 'article' => array(
  42. 'title',
  43. 'content',
  44. 'status' => 0,
  45. 'sticky' => 0
  46. )
  47. )
  48. );
  49. $access->mark($this, false);
  50. $email = $conf->get('core/email_address');
  51. $param->set('link', $param->create('/module=admin/base=news#incoming', false, true));
  52. $services->send_template_mail(
  53. $email,
  54. __('New article submission on %s', $conf->get('core/site_name')),
  55. 'news/mail_new_submission',
  56. array(
  57. 'reply-to' => $auth->user['user']['email']
  58. )
  59. );
  60. $json->response(
  61. array(
  62. 'successMessage' => __('Thanks for your submission. It will be reviewed by one of the administrations before it can get into the front page.'),
  63. 'execute' => array(
  64. $meteora->rpc_notebook_clean_cache(
  65. 'userNewsNotebook',
  66. 'submissions'
  67. ),
  68. $meteora->rpc_notebook_select_page(
  69. 'userNewsNotebook',
  70. 'submissions'
  71. )
  72. )
  73. )
  74. );
  75. } else {
  76. $json->response(
  77. array(
  78. 'errorMessage' => __('You have sent too many articles in a short period of time, I cannot accept more submissions from you within the next fifteen minutes, please try again later.')
  79. )
  80. );
  81. }
  82. }
  83. public function admin_ajax_create() {
  84. extract(
  85. $this->using(
  86. 'db',
  87. 'param',
  88. 'json',
  89. 'meteora'
  90. )
  91. );
  92. $this->validate();
  93. if ($param->get('article.status') == 1 && !$param->get('article.date_publish')) {
  94. $db->insert(
  95. 'news',
  96. array(
  97. 'article' => array(
  98. 'title',
  99. 'content',
  100. array('date_publish' => 'NOW()'),
  101. 'date_expires',
  102. 'allow_comments',
  103. 'sticky',
  104. 'status'
  105. )
  106. )
  107. );
  108. } else {
  109. $db->insert(
  110. 'news',
  111. array(
  112. 'article' => array(
  113. 'title',
  114. 'content',
  115. 'date_expires',
  116. 'allow_comments',
  117. 'sticky',
  118. 'status'
  119. )
  120. )
  121. );
  122. }
  123. $item_id = $db->last_insert_id();
  124. $categories_model =& $this->load_model('categories');
  125. $categories_model->save_category_relations('news', $item_id, $param->get('article.category'));
  126. $categories_model->save_tag_relations('news', $item_id, $param->get('article.tag'));
  127. $json->response(
  128. array(
  129. 'successMessage' => __('Created.'),
  130. 'execute' => array(
  131. $meteora->rpc_notebook_clean_cache(
  132. 'adminNewsNotebook'
  133. ),
  134. $meteora->rpc_notebook_select_page(
  135. 'adminNewsNotebook',
  136. 'index'
  137. )
  138. )
  139. )
  140. );
  141. }
  142. private function validate() {
  143. extract(
  144. $this->using(
  145. 'param',
  146. 'db'
  147. )
  148. );
  149. $param->not_empty('article.title', 'article.content');
  150. $param->set('article.status', intval($param->get('article.status')));
  151. $param->set('article.sticky', intval($param->get('article.sticky')));
  152. $param->from_editor('article.content');
  153. }
  154. public function admin_ajax_edit() {
  155. extract(
  156. $this->using(
  157. 'db',
  158. 'param',
  159. 'json',
  160. 'meteora'
  161. )
  162. );
  163. if (
  164. $param->get('article.status')
  165. && $db->count('news', $db->bind('id = ? AND status != ? AND date_publish = ?', $param->get('article.id'), 1, $param->get('article.date_publish')))
  166. ) {
  167. $update_pd = true;
  168. }
  169. $this->validate();
  170. $db->update(
  171. 'news',
  172. array(
  173. 'article' => array(
  174. 'title',
  175. 'content',
  176. 'allow_comments',
  177. 'date_publish',
  178. 'date_expires',
  179. 'sticky',
  180. 'status'
  181. )
  182. ),
  183. $db->bind('id = ?', $param->get('article.id'))
  184. );
  185. if ($update_pd) {
  186. // this post was a draft
  187. $db->update(
  188. 'news',
  189. array(
  190. 'post' => array(
  191. array('date_publish' => 'NOW()'),
  192. array('date_created' => 'NOW()')
  193. )
  194. ),
  195. $db->bind('id = ?', $param->get('article.id'))
  196. );
  197. }
  198. $categories_model =& $this->load_model('categories');
  199. $categories_model->save_category_relations('news', $param->get('article.id'), $param->get('article.category'));
  200. $categories_model->save_tag_relations('news', $param->get('article.id'), $param->get('article.tag'));
  201. $json->response(
  202. array(
  203. 'execute' => array(
  204. $meteora->rpc_notebook_clean_cache(
  205. 'adminNewsNotebook'
  206. ),
  207. $meteora->rpc_notebook_close_page(
  208. 'adminNewsNotebook',
  209. 'edit_'.$param->get('article.id')
  210. )
  211. ),
  212. 'successMessage' => __('Updated.')
  213. )
  214. );
  215. }
  216. public function admin_ajax_reopen() {
  217. extract(
  218. $this->using(
  219. 'db',
  220. 'param',
  221. 'json',
  222. 'meteora',
  223. 'auth'
  224. )
  225. );
  226. $param->map('?id=int');
  227. $param->not_empty('id');
  228. $db->update(
  229. 'news',
  230. array(
  231. 'article' => array(
  232. 'editor_note' => '',
  233. 'editor_id' => $auth->user['user']['id'],
  234. 'status' => 0
  235. )
  236. ),
  237. $db->bind('id = ?', $param->get('id'))
  238. );
  239. $json->response(
  240. array(
  241. 'execute' => array(
  242. $meteora->rpc_notebook_update_page(
  243. 'adminNewsNotebook',
  244. 'incoming'
  245. ),
  246. $meteora->rpc_notebook_select_page(
  247. 'adminNewsNotebook',
  248. 'incoming'
  249. )
  250. ),
  251. 'successMessage' => __('Reopened.')
  252. )
  253. );
  254. }
  255. public function admin_ajax_publish() {
  256. extract(
  257. $this->using(
  258. 'db',
  259. 'param',
  260. 'json',
  261. 'meteora',
  262. 'auth'
  263. )
  264. );
  265. $param->not_empty('article.id');
  266. $db->update(
  267. 'news',
  268. array(
  269. 'article' => array(
  270. 'editor_note',
  271. array('date_publish' => 'NOW()'),
  272. 'editor_id' => $auth->user['user']['id'],
  273. 'status' => 1
  274. )
  275. ),
  276. $db->bind('id = ?', $param->get('article.id'))
  277. );
  278. $item_id = $param->get('article.id');
  279. $categories_model =& $this->load_model('categories');
  280. $categories_model->save_category_relations('news', $item_id, $param->get('article.category'));
  281. $categories_model->save_tag_relations('news', $item_id, $param->get('article.tag'));
  282. $json->response(
  283. array(
  284. 'execute' => array(
  285. $meteora->rpc_notebook_clean_cache(
  286. 'adminNewsNotebook'
  287. ),
  288. $meteora->rpc_notebook_close_page(
  289. 'adminNewsNotebook',
  290. 'publish_'.$param->get('article.id')
  291. )
  292. ),
  293. 'successMessage' => __('Published.')
  294. )
  295. );
  296. }
  297. public function admin_ajax_reject() {
  298. extract(
  299. $this->using(
  300. 'db',
  301. 'param',
  302. 'json',
  303. 'meteora',
  304. 'auth'
  305. )
  306. );
  307. $param->not_empty('article.id');
  308. $db->update(
  309. 'news',
  310. array(
  311. 'article' => array(
  312. 'editor_note',
  313. 'editor_id' => $auth->user['user']['id'],
  314. 'status' => 2
  315. )
  316. ),
  317. $db->bind('id = ?', $param->get('article.id'))
  318. );
  319. $json->response(
  320. array(
  321. 'execute' => array(
  322. $meteora->rpc_notebook_close_page(
  323. 'adminNewsNotebook',
  324. 'reject_'.$param->get('article.id')
  325. ),
  326. $meteora->rpc_notebook_update_page(
  327. 'adminNewsNotebook',
  328. 'incoming'
  329. ),
  330. $meteora->rpc_notebook_select_page(
  331. 'adminNewsNotebook',
  332. 'incoming'
  333. )
  334. ),
  335. 'successMessage' => __('Rejected.')
  336. )
  337. );
  338. }
  339. public function admin_ajax_delete() {
  340. extract(
  341. $this->using(
  342. 'db',
  343. 'param',
  344. 'json',
  345. 'meteora'
  346. )
  347. );
  348. $param->not_empty('id');
  349. $db->delete('news', $param->get('id'));
  350. $json->response(
  351. array(
  352. 'execute' => array(
  353. $meteora->rpc_notebook_clean_cache(
  354. 'adminNewsNotebook'
  355. ),
  356. $meteora->rpc_notebook_close_page(
  357. 'adminNewsNotebook',
  358. 'delete_'.$param->get('id')
  359. )
  360. ),
  361. 'successMessage' => __('Deleted.')
  362. )
  363. );
  364. }
  365. }
  366. ?>