/extra/modules/news/action.php
PHP | 424 lines | 346 code | 58 blank | 20 comment | 9 complexity | 9c36e5466e1b4dc230afe91f90bd1141 MD5 | raw file
Possible License(s): MIT, CC0-1.0
- <?php
- /**
- * textMotion
- * ---
- * Written by Jose Carlos Nieto <xiam@menteslibres.org>
- * Copyright (c) 2007-2008, Jose Carlos Nieto <xiam@menteslibres.org>
- *
- * Licensed under The MIT License
- * Redistributions of files must retain the above copyright notice.
- *
- * @author Jose Carlos Nieto <xiam@menteslibres.org>
- * @package textMotion
- * @copyright Copyright (c) 2007-2008, J. Carlos Nieto <xiam@menteslibres.org>
- * @link http://www.textmotion.org
- * @version $Revision: 1504 $
- * @modifiedby $LastChangedBy: xiam.core $
- * @lastmodified $Date: 2008-11-07 02:50:31 +1100 (Fri, 07 Nov 2008) $
- * @license http://www.opensource.org/licenses/mit-license.php The MIT License
- *
- */
- class news_action extends tm_action {
- public function user_ajax_submit() {
- extract(
- $this->using(
- 'db',
- 'param',
- 'auth',
- 'services',
- 'json',
- 'meteora',
- 'conf',
- 'access'
- )
- );
- if ($access->verify($this, 60*15, $conf->get('news/submissions_per_quarter', 5, 'i'))) {
- $param->not_empty('article.title', 'article.content');
-
- $param->from_editor('article.content');
-
- $db->insert(
- 'news',
- array(
- 'article' => array(
- 'title',
- 'content',
- 'status' => 0,
- 'sticky' => 0
- )
- )
- );
- $access->mark($this, false);
- $email = $conf->get('core/email_address');
- $param->set('link', $param->create('/module=admin/base=news#incoming', false, true));
-
- $services->send_template_mail(
- $email,
- __('New article submission on %s', $conf->get('core/site_name')),
- 'news/mail_new_submission',
- array(
- 'reply-to' => $auth->user['user']['email']
- )
- );
- $json->response(
- array(
- 'successMessage' => __('Thanks for your submission. It will be reviewed by one of the administrations before it can get into the front page.'),
- 'execute' => array(
- $meteora->rpc_notebook_clean_cache(
- 'userNewsNotebook',
- 'submissions'
- ),
- $meteora->rpc_notebook_select_page(
- 'userNewsNotebook',
- 'submissions'
- )
- )
- )
- );
- } else {
- $json->response(
- array(
- '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.')
- )
- );
- }
- }
- public function admin_ajax_create() {
- extract(
- $this->using(
- 'db',
- 'param',
- 'json',
- 'meteora'
- )
- );
- $this->validate();
- if ($param->get('article.status') == 1 && !$param->get('article.date_publish')) {
- $db->insert(
- 'news',
- array(
- 'article' => array(
- 'title',
- 'content',
- array('date_publish' => 'NOW()'),
- 'date_expires',
- 'allow_comments',
- 'sticky',
- 'status'
- )
- )
- );
- } else {
- $db->insert(
- 'news',
- array(
- 'article' => array(
- 'title',
- 'content',
- 'date_expires',
- 'allow_comments',
- 'sticky',
- 'status'
- )
- )
- );
- }
- $item_id = $db->last_insert_id();
- $categories_model =& $this->load_model('categories');
- $categories_model->save_category_relations('news', $item_id, $param->get('article.category'));
- $categories_model->save_tag_relations('news', $item_id, $param->get('article.tag'));
- $json->response(
- array(
- 'successMessage' => __('Created.'),
- 'execute' => array(
- $meteora->rpc_notebook_clean_cache(
- 'adminNewsNotebook'
- ),
- $meteora->rpc_notebook_select_page(
- 'adminNewsNotebook',
- 'index'
- )
- )
- )
- );
- }
- private function validate() {
- extract(
- $this->using(
- 'param',
- 'db'
- )
- );
- $param->not_empty('article.title', 'article.content');
- $param->set('article.status', intval($param->get('article.status')));
- $param->set('article.sticky', intval($param->get('article.sticky')));
- $param->from_editor('article.content');
- }
- public function admin_ajax_edit() {
- extract(
- $this->using(
- 'db',
- 'param',
- 'json',
- 'meteora'
- )
- );
-
- if (
- $param->get('article.status')
- && $db->count('news', $db->bind('id = ? AND status != ? AND date_publish = ?', $param->get('article.id'), 1, $param->get('article.date_publish')))
- ) {
- $update_pd = true;
- }
- $this->validate();
- $db->update(
- 'news',
- array(
- 'article' => array(
- 'title',
- 'content',
- 'allow_comments',
- 'date_publish',
- 'date_expires',
- 'sticky',
- 'status'
- )
- ),
- $db->bind('id = ?', $param->get('article.id'))
- );
-
- if ($update_pd) {
- // this post was a draft
- $db->update(
- 'news',
- array(
- 'post' => array(
- array('date_publish' => 'NOW()'),
- array('date_created' => 'NOW()')
- )
- ),
- $db->bind('id = ?', $param->get('article.id'))
- );
- }
- $categories_model =& $this->load_model('categories');
- $categories_model->save_category_relations('news', $param->get('article.id'), $param->get('article.category'));
- $categories_model->save_tag_relations('news', $param->get('article.id'), $param->get('article.tag'));
- $json->response(
- array(
- 'execute' => array(
- $meteora->rpc_notebook_clean_cache(
- 'adminNewsNotebook'
- ),
- $meteora->rpc_notebook_close_page(
- 'adminNewsNotebook',
- 'edit_'.$param->get('article.id')
- )
- ),
- 'successMessage' => __('Updated.')
- )
- );
- }
-
- public function admin_ajax_reopen() {
- extract(
- $this->using(
- 'db',
- 'param',
- 'json',
- 'meteora',
- 'auth'
- )
- );
- $param->map('?id=int');
- $param->not_empty('id');
- $db->update(
- 'news',
- array(
- 'article' => array(
- 'editor_note' => '',
- 'editor_id' => $auth->user['user']['id'],
- 'status' => 0
- )
- ),
- $db->bind('id = ?', $param->get('id'))
- );
- $json->response(
- array(
- 'execute' => array(
- $meteora->rpc_notebook_update_page(
- 'adminNewsNotebook',
- 'incoming'
- ),
- $meteora->rpc_notebook_select_page(
- 'adminNewsNotebook',
- 'incoming'
- )
- ),
- 'successMessage' => __('Reopened.')
- )
- );
- }
-
- public function admin_ajax_publish() {
- extract(
- $this->using(
- 'db',
- 'param',
- 'json',
- 'meteora',
- 'auth'
- )
- );
- $param->not_empty('article.id');
- $db->update(
- 'news',
- array(
- 'article' => array(
- 'editor_note',
- array('date_publish' => 'NOW()'),
- 'editor_id' => $auth->user['user']['id'],
- 'status' => 1
- )
- ),
- $db->bind('id = ?', $param->get('article.id'))
- );
- $item_id = $param->get('article.id');
-
- $categories_model =& $this->load_model('categories');
- $categories_model->save_category_relations('news', $item_id, $param->get('article.category'));
- $categories_model->save_tag_relations('news', $item_id, $param->get('article.tag'));
- $json->response(
- array(
- 'execute' => array(
- $meteora->rpc_notebook_clean_cache(
- 'adminNewsNotebook'
- ),
- $meteora->rpc_notebook_close_page(
- 'adminNewsNotebook',
- 'publish_'.$param->get('article.id')
- )
- ),
- 'successMessage' => __('Published.')
- )
- );
- }
-
- public function admin_ajax_reject() {
- extract(
- $this->using(
- 'db',
- 'param',
- 'json',
- 'meteora',
- 'auth'
- )
- );
- $param->not_empty('article.id');
- $db->update(
- 'news',
- array(
- 'article' => array(
- 'editor_note',
- 'editor_id' => $auth->user['user']['id'],
- 'status' => 2
- )
- ),
- $db->bind('id = ?', $param->get('article.id'))
- );
- $json->response(
- array(
- 'execute' => array(
- $meteora->rpc_notebook_close_page(
- 'adminNewsNotebook',
- 'reject_'.$param->get('article.id')
- ),
- $meteora->rpc_notebook_update_page(
- 'adminNewsNotebook',
- 'incoming'
- ),
- $meteora->rpc_notebook_select_page(
- 'adminNewsNotebook',
- 'incoming'
- )
- ),
- 'successMessage' => __('Rejected.')
- )
- );
- }
- public function admin_ajax_delete() {
- extract(
- $this->using(
- 'db',
- 'param',
- 'json',
- 'meteora'
- )
- );
- $param->not_empty('id');
- $db->delete('news', $param->get('id'));
- $json->response(
- array(
- 'execute' => array(
- $meteora->rpc_notebook_clean_cache(
- 'adminNewsNotebook'
- ),
- $meteora->rpc_notebook_close_page(
- 'adminNewsNotebook',
- 'delete_'.$param->get('id')
- )
- ),
- 'successMessage' => __('Deleted.')
- )
- );
- }
- }
- ?>