/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
- <?php
- /*
- * e107 website system
- *
- * Copyright (C) 2008-2013 e107 Inc (e107.org)
- * Released under the terms and conditions of the
- * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
- *
- * News Administration
- *
- */
- require_once('../class2.php');
- if (!getperms('H|N'))
- {
- header('Location:'.e_BASE.'index.php');
- exit;
- }
- //include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE);
- e107::coreLan('newspost', true);
- // ------------------------------
- // 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.
- $newspost = new admin_newspost(e_QUERY);
- e107::setRegistry('_newspost_admin', $newspost);
- $gen = new convert();
- //Handle Ajax Calls
- if($newspost->ajax_observer()) exit;
- // e107::js('core','core/admin.js','prototype');
- //e107::getJs()->requireCoreLib('core/admin.js');
- class news_admin extends e_admin_dispatcher
- {
- protected $modes = array(
- 'main' => array(
- 'controller' => 'news_admin_ui',
- 'path' => null,
- 'ui' => 'news_form_ui',
- 'uipath' => null
- ),
- 'cat' => array(
- 'controller' => 'news_cat_ui',
- 'path' => null,
- 'ui' => 'news_cat_form_ui',
- 'uipath' => null
- ),
- 'sub' => array(
- 'controller' => 'news_sub_ui',
- 'path' => null,
- 'ui' => 'news_sub_form_ui',
- 'uipath' => null
- )
- );
- protected $adminMenu = array(
- 'main/list' => array('caption'=> LAN_LIST, 'perm' => 'H'),
- 'main/create' => array('caption'=> NWSLAN_45, 'perm' => 'H'), // Create/Edit News Item
- // 'cat/list' => array('caption'=> NWSLAN_46, 'perm' => '7'), // Category List
- 'cat/list' => array('caption'=> LAN_CATEGORIES, 'perm' => 'H'), // Create Category.
- 'cat/create' => array('caption'=> "Create Category", 'perm' => 'H'), // Category List
- 'main/settings' => array('caption'=> LAN_PREFS, 'perm' => '0'), // Preferences
- // 'main/submitted' => array('caption'=> "Old Submitted ", 'perm' => 'N'), // Submitted News
- 'sub/list' => array('caption'=> NWSLAN_47, 'perm' => 'N'), // Submitted News
- // 'main/maint' => array('caption'=> LAN_NEWS_55, 'perm' => '0') // Maintenance
- );
- protected $adminMenuAliases = array(
- 'main/edit' => 'main/list',
- 'cat/edit' => 'cat/list'
- );
- protected $menuTitle = "News";
- }
- class news_cat_ui extends e_admin_ui
- {
- protected $pluginTitle = ADLAN_0; // "News"
- protected $pluginName = 'core';
- protected $table = "news_category";
- protected $pid = "category_id";
- protected $perPage = 0; //no limit
- protected $batchDelete = false;
- protected $sortField = 'category_order';
- protected $listOrder = "category_order ASC";
-
- protected $fields = array(
- 'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
- 'category_id' => array('title'=> LAN_ID, 'type' => 'number', 'width' =>'5%', 'forced'=> TRUE, 'readonly'=>TRUE),
- '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),
- 'category_name' => array('title'=> LAN_TITLE, 'type' => 'text', 'inline'=>true, 'width' => 'auto', 'thclass' => 'left', 'readonly'=>FALSE, 'validate' => true, 'inline' => true),
-
- 'category_meta_description' => array('title'=> LAN_DESCRIPTION, 'type' => 'textarea', 'inline'=>true, 'width' => 'auto', 'thclass' => 'left','readParms' => 'expand=...&truncate=150&bb=1', 'readonly'=>FALSE),
- 'category_meta_keywords' => array('title'=> LAN_KEYWORDS, 'type' => 'tags', 'inline'=>true, 'width' => 'auto', 'thclass' => 'left', 'readonly'=>FALSE),
- 'category_sef' => array('title'=> LAN_SEFURL, 'type' => 'text', 'inline'=>true, 'width' => 'auto', 'readonly'=>FALSE), // Display name
- 'category_manager' => array('title'=> "Manage Permissions",'type' => 'userclass', 'inline'=>true, 'width' => 'auto', 'data' => 'int','batch'=>TRUE, 'filter'=>TRUE),
- 'category_order' => array('title'=> LAN_ORDER, 'type' => 'text', 'width' => 'auto', 'thclass' => 'right', 'class'=> 'right' ),
- 'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'width' => '10%', 'forced'=>TRUE, 'thclass' => 'center last', 'class' => 'center', 'sort' => true)
- );
- protected $fieldpref = array('checkboxes', 'category_icon', 'category_id', 'category_name', 'category_description','category_manager', 'category_order', 'options');
-
- protected $newspost;
-
- function init()
- {
- $this->newspost = new admin_newspost;
- }
-
- // function createPage()
- // {
- // $this->newspost->show_categories();
- // }
-
- public function beforeCreate($new_data)
- {
- if(empty($new_data['category_sef']))
- {
- $new_data['category_sef'] = eHelper::title2sef($new_data['category_name']);
- }
- else
- {
- $new_data['category_sef'] = eHelper::secureSef($new_data['category_sef']);
- }
- $sef = e107::getParser()->toDB($new_data['category_sef']);
-
- if(e107::getDb()->count('news_category', '(*)', "category_sef='{$sef}'"))
- {
- e107::getMessage()->addError('Please choose unique SEF URL string for this category');
- return false;
- }
-
- if(empty($new_data['category_order']))
- {
- $c = e107::getDb()->count('news_category');
- $new_data['category_order'] = $c ? $c : 0;
- }
-
- return $new_data;
- }
-
-
- public function beforeUpdate($new_data, $old_data, $id)
- {
- if(empty($new_data['category_sef']))
- {
- $new_data['category_sef'] = eHelper::title2sef($new_data['category_name']);
- }
- $sef = e107::getParser()->toDB($new_data['category_sef']);
- if(e107::getDb()->count('news_category', '(*)', "category_sef='{$sef}' AND category_id!=".intval($id)))
- {
- e107::getMessage()->addError('Please choose unique SEF URL string for this category');
- return false;
- }
- return $new_data;
- }
- }
- class news_cat_form_ui extends e_admin_form_ui
- {
- }
- // Submitted News Area.
- class news_sub_ui extends e_admin_ui
- {
- protected $pluginTitle = ADLAN_0; // "News"
- protected $pluginName = 'core';
- protected $table = "submitnews";
- protected $pid = "submitnews_id";
- protected $perPage = 10; //no limit
- protected $batchDelete = true;
- protected $formQuery = "mode=main&action=create";
- protected $listOrder = "submitnews_id desc";
-
-
- // submitnews_id submitnews_name submitnews_email submitnews_title submitnews_category submitnews_item submitnews_datestamp submitnews_ip submitnews_auth submitnews_file
- protected $fields = array(
- 'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
- 'submitnews_id' => array('title'=> LAN_ID, 'type' => 'number', 'width' =>'5%', 'forced'=> TRUE, 'readonly'=>TRUE),
- 'submitnews_title' => array('title'=> LAN_TITLE, 'type' => 'method', 'width' => '35%', 'thclass' => 'left', 'readonly'=>TRUE),
- 'submitnews_datestamp' => array('title' => LAN_NEWS_32, 'type' => 'datestamp', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'parms' => 'mask=%A %d %B %Y'),
-
- 'submitnews_category' => array('title'=> LAN_CATEGORY, 'type' => 'dropdown', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>FALSE),
- // 'submitnews_item' => array('title'=> LAN_DESCRIPTION, 'type' => 'method', 'width' => 'auto', 'thclass' => 'left','readParms' => 'expand=...&truncate=150&bb=1', 'readonly'=>TRUE),
- 'submitnews_name' => array('title'=> LAN_AUTHOR, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>TRUE),
- 'submitnews_ip' => array('title'=> "IP", 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>TRUE),
- 'submitnews_auth' => array('title'=> "User", 'type' => 'user', 'width' => 'auto', 'thclass' => 'right', 'class'=> 'right' ),
- 'options' => array('title'=> LAN_OPTIONS, 'type' => "method", 'width' => '10%', 'forced'=>TRUE, 'thclass' => 'center last', 'class' => 'center')
- );
- protected $fieldpref = array('checkboxes', 'submitnews_id', 'submitnews_title', 'submitnews_category', 'options');
-
- protected $newspost;
-
- protected $cats;
-
- function init()
- {
- $sql = e107::getDb();
- $sql->db_Select_gen("SELECT category_id,category_name FROM #news_category");
- while($row = $sql->fetch())
- {
- $cat = $row['category_id'];
- $this->cats[$cat] = $row['category_name'];
- }
- asort($this->cats);
- $this->fields['submitnews_category']['writeParms'] = $this->cats;
- $this->newspost = new admin_newspost;
- }
-
- // function createPage()
- // {
- // $this->newspost->show_categories();
- // }
-
- public function beforeCreate($new_data)
- {
-
- }
-
-
- public function beforeUpdate($new_data, $old_data, $id)
- {
-
- }
- }
- class news_sub_form_ui extends e_admin_form_ui
- {
-
-
-
- function submitnews_title($cur,$val)
- {
- $tp = e107::getParser();
- $row = $this->getController()->getListModel();
-
- $submitnews_id = $row->get('submitnews_id');
- $submitnews_title = $row->get('submitnews_title');
- $submitnews_file = $row->get('submitnews_file');
- $submitnews_item = $row->get('submitnews_item');
- // $text .= "<a href='#submitted_".$submitnews_id."' class='e-modal' >";
-
-
- $text .= "<a data-toggle='modal' href='#submitted_".$submitnews_id."' data-cache='false' data-target='#submitted_".$submitnews_id."' class='e-tip' title='".LAN_PREVIEW."'>";
- $text .= $tp->toHTML($submitnews_title,FALSE,'emotes_off, no_make_clickable');
- $text .= '</a>';
-
- $text .= '
- <div id="submitted_'.$submitnews_id.'" class="modal hide fade" tabindex="-1" role="dialog" aria-hidden="true">
- <div class="modal-header">
- <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
- <h4>'.$tp->toHtml($submitnews_title,false,'TITLE').'</h4>
- </div>
- <div class="modal-body">
- <p>';
-
- $text .= $tp->toHTML($submitnews_item,TRUE);
-
- if($submitnews_file)
- {
- $tmp = explode(',',$submitnews_file);
-
- $text .= "<br />";
-
-
- foreach($tmp as $imgfile)
- {
- $url = $tp->thumbUrl(e_UPLOAD.$imgfile,array('aw'=>400),true);
- $text .= "<br /><img src='".$url."' alt='".$imgfile."' />";
- }
- }
-
-
- $text .= '</p>
- </div>
- <div class="modal-footer">
- <a href="#" data-dismiss="modal" class="btn btn-primary">Close</a>
- </div>
- </div>';
-
- return $text;
-
- }
-
- // Override the default Options field.
- function options($parms, $value, $id, $attributes)
- {
-
- if($attributes['mode'] == 'read')
- {
- $text = "<div class='btn-group'>";
- $approved = $this->getController()->getListModel()->get('submitnews_auth'); // approved;
- if($approved == 0)
- {
- //$text = $this->submit_image('submitnews['.$id.']', 1, 'execute', NWSLAN_58);
- $text = "<a class='btn btn-large' href='".e_SELF."?mode=main&action=create&sub={$id}'>".ADMIN_EXECUTE_ICON."</a>";
- // NWSLAN_103;
- }
- else // Already submitted;
- {
-
- }
-
- $text .= $this->submit_image('etrigger_delete['.$id.']', $id, 'delete', LAN_DELETE.' [ ID: '.$id.' ]', array('class' => 'btn btn-large action delete'.$delcls));
- $text .= "</div>";
- return $text;
- }
- }
-
- }
- // Main News Area.
- class news_admin_ui extends e_admin_ui
- {
- protected $pluginTitle = ADLAN_0; // "News"
- protected $pluginName = 'core';
- protected $table = "news";
- protected $pid = "news_id";
- protected $perPage = 10; //no limit
- protected $batchDelete = true;
- protected $batchCopy = true;
- protected $batchLink = true;
- protected $listOrder = "news_id desc";
- // true for 'vars' value means use same var
- protected $url = array(
- 'route'=>'news/view/item',
- 'name' => 'news_title',
- 'description' => 'news_summary',
- '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
- ); // 'link' only needed if profile not provided.
-
-
- 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.
-
-
- protected $fields = array(
- 'checkboxes' => array('title' => '', 'type' => null, 'width' => '3%', 'thclass' => 'center first', 'class' => 'center', 'nosort' => true, 'toggle' => 'news_selected', 'forced' => TRUE),
- 'news_id' => array('title' => LAN_ID, 'type' => 'text', 'width' => '5%', 'thclass' => 'center', 'class' => 'center', 'nosort' => false, 'readParms'=>'link=sef&target=blank'),
- '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),
- 'news_title' => array('title' => LAN_TITLE, 'type' => 'text', 'inline'=>true, 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
- 'news_summary' => array('title' => LAN_NEWS_27, 'type' => 'text', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
-
- 'news_meta_keywords' => array('title' => LAN_KEYWORDS, 'type' => 'text', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
- 'news_meta_description' => array('title' => LAN_DESCRIPTION,'type' => 'text', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
- 'news_sef' => array('title' => LAN_SEFURL, 'type' => 'text', 'inline'=>true, 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
- 'user_name' => array('title' => LAN_AUTHOR, 'type' => 'text', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'noedit' => true),
- '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),
- 'news_category' => array('title' => NWSLAN_6, 'type' => 'dropdown', 'data' => 'int', 'inline'=>true, 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'batch'=>true, 'filter'=>true),
-
- 'news_start' => array('title' => "Start", 'type' => 'datestamp', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'parms' => 'mask=%A %d %B %Y'),
- 'news_end' => array('title' => "End", 'type' => 'datestamp', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'parms' => 'mask=%A %d %B %Y'),
-
- 'news_class' => array('title' => LAN_VISIBILITY, 'type' => 'userclasses', 'inline'=>true, 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'batch'=>true, 'filter'=>true),
- 'news_render_type' => array('title' => LAN_TEMPLATE, 'type' => 'comma', 'inline'=>false, 'width' => 'auto', 'thclass' => 'center', 'class' => null, 'nosort' => false, 'batch'=>true, 'filter'=>true),
- 'news_sticky' => array('title' => LAN_NEWS_28, 'type' => 'boolean', 'data' => 'int' , 'width' => 'auto', 'thclass' => 'center', 'class' => 'center', 'nosort' => false, 'batch'=>true, 'filter'=>true),
- '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'),
- 'news_comment_total' => array('title' => LAN_NEWS_60, 'type' => 'number', 'width' => '10%', 'thclass' => '', 'class' => null, 'nosort' => false),
- 'options' => array('title' => LAN_OPTIONS, 'type' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center', 'nosort' => true, 'forced' => TRUE)
- );
-
- protected $fieldpref = array('checkboxes','news_id', 'news_thumbnail', 'news_title', 'news_datestamp', 'news_category', 'options');
-
-
- protected $cats = array();
- protected $newspost;
-
- protected $news_renderTypes = array( // TODO Placement location and template should be separate.
-
- '0' => "Default Area",
- '1' => "Default Area - Title",
- '4' => "Default Area - Title/Summary",
- '2' => "Sidebar - Othernews",
- '3' => "Sidebar - Othernews 2",
- '5' => "Carousel",
- //'5' => "Featurebox"
- );
-
- function init()
- {
- // Ping Changes to Services.
- $pingServices = e107::getPref('news_ping_services');
- //TODO Use Ajax with progress-bar.
-
- $mes = e107::getMessage();
-
- if(vartrue($_POST['news_ping'],false) && (count($pingServices)>0) && in_array(e_UC_PUBLIC, $_POST['news_userclass']))
- {
- $mes->addDebug("Initiating ping",'default',true);
-
- include (e_HANDLER.'xmlrpc/xmlrpc.inc.php');
- include (e_HANDLER.'xmlrpc/xmlrpcs.inc.php');
- include (e_HANDLER.'xmlrpc/xmlrpc_wrappers.inc.php');
- $extendedServices = array('blogsearch.google.com');
- $port = 80;
- foreach($pingServices as $fullUrl)
- {
- $fullUrl = str_replace("http://","", trim($fullUrl));
- list($server,$path) = explode("/",$fullUrl, 2);
- $path = "/".$path;
- $weblog_name = SITENAME;
- $weblog_url = $_SERVER['HTTP_HOST'].e_HTTP;
- $changes_url = $_SERVER['HTTP_HOST'].e107::getUrl()->create('news/view/item', $_POST); // $_SERVER['HTTP_HOST'].e_HTTP."news.php?extend.".$_POST['news_id'];
- $cat_or_rss = $_SERVER['HTTP_HOST'].e_PLUGIN_ABS."rss_menu/rss.php?1.2";
- $extended = (in_array($server, $extendedServices)) ? true : false;
- if($this->ping($server, $port, $path, $weblog_name, $weblog_url, $changes_url, $cat_or_rss, $extended))
- {
- e107::getMessage()->addDebug("Successfully Pinged: ".$server .' with '.$changes_url , 'default', true);
- }
-
- }
-
- }
-
-
- $sql = e107::getDb();
- $sql->gen("SELECT category_id,category_name FROM #news_category");
- while($row = $sql->fetch())
- {
- $cat = $row['category_id'];
- $this->cats[$cat] = $row['category_name'];
- }
- asort($this->cats);
- $this->fields['news_category']['writeParms'] = $this->cats;
- $this->fields['news_render_type']['writeParms'] = $this->news_renderTypes; // array(NWSLAN_75,NWSLAN_76,NWSLAN_77,NWSLAN_77." 2","Featurebox");
- $this->newspost = new admin_newspost;
- $this->newspost->news_renderTypes = $this->news_renderTypes;
- $this->newspost->observer();
-
- }
- /* Multi-purpose ping for any XML-RPC server that supports the Weblogs.Com interface. */
- function ping($xml_rpc_server, $xml_rpc_port, $xml_rpc_path, $weblog_name, $weblog_url, $changes_url, $cat_or_rss='', $extended = false)
- {
- $mes = e107::getMessage();
- $log = e107::getAdminLog();
-
- $mes->addDebug("Attempting to ping: ".$xml_rpc_server, 'default', true);
-
- $name_param = new xmlrpcval($weblog_name, 'string');
- $url_param = new xmlrpcval($weblog_url, 'string');
- $changes_param = new xmlrpcval($changes_url, 'string');
- $cat_or_rss_param = new xmlrpcval($cat_or_rss, 'string');
- $method_name = ($extended) ? "weblogUpdates.extendedPing" : "weblogUpdates.ping";
-
- if ($cat_or_rss != "")
- {
- $params = array($name_param, $url_param, $changes_param, $cat_or_rss_param);
- $call_text = "$method_name(\"$weblog_name\", \"$weblog_url\", \"$changes_url\", \"$cat_or_rss\")";
- }
- else
- {
- if ($changes_url != "")
- {
- $params = array($name_param, $url_param, $changes_param);
- $call_text = "$method_name(\"$weblog_name\", \"$weblog_url\", \"$changes_url\")";
- }
- else
- {
- $params = array($name_param, $url_param);
- $call_text = "$method_name(\"$weblog_name\", \"$weblog_url\")";
- }
- }
- // create the message
- $message = new xmlrpcmsg($method_name, $params);
- $client = new xmlrpc_client($xml_rpc_path, $xml_rpc_server, $xml_rpc_port);
- $response = $client->send($message);
-
- $this->log_ping("Request: " . $call_text);
- $this->log_ping($message->serialize(), true);
-
- if ($response == 0)
- {
- $error_text = "Error: " . $xml_rpc_server . ": " . $client->errno . " " . $client->errstring;
- $this->report_error($error_text);
- $this->log_ping($error_text);
- $log->addArray(array('status'=>LAN_ERROR, 'service'=>$xml_rpc_server, 'url'=> $changes_url, 'response'=>$client->errstring))->save('PING_01');
-
- return false;
- }
-
- if ($response->faultCode() != 0)
- {
- $error_text = "Error: " . $xml_rpc_server . ": " . $response->faultCode() . " " . $response->faultString();
- $this->report_error($error_text);
- $log->addArray(array('status'=>LAN_ERROR, 'service'=>$xml_rpc_server, 'url'=> $changes_url, 'response'=>$response->faultString()))->save('PING_01');
-
- return false;
- }
-
- $response_value = $response->value();
- if ($this->debug)
- {
- $this->report_error($response_value->serialize());
- }
-
- $this->log_ping($response_value->serialize(), true);
-
- $fl_error = $response_value->structmem('flerror');
- $message = $response_value->structmem('message');
- // read the response
- if ($fl_error->scalarval() != false)
- {
- $error_text = "Error: " . $xml_rpc_server . ": " . $message->scalarval();
- $this->report_error($error_text);
- $log->addArray(array('status'=>LAN_ERROR, 'service'=>$xml_rpc_server, 'url'=> $changes_url, 'response'=>$message->scalarval()))->save('PING_01');
-
- // $this->log_ping($error_text);
- return false;
- }
- $log->addArray(array('status'=>LAN_OK, 'service'=>$xml_rpc_server, 'url'=> $changes_url, 'response'=>$message->scalarval()))->save('PING_01');
-
- return true;
- }
- // save ping data to a log file
- function log_ping($message, $xml_data = false)
- {
- $message = $xml_data." ".$message;
- file_put_contents(e_LOG."news_ping.log", $message, FILE_APPEND);
- }
- // sDisplay Ping errors.
- function report_error($message)
- {
- e107::getMessage()->addError($message, 'default', true);
- }
-
- function createPage()
- {
- // print_a($_POST);
- if(isset($_GET['sub']))
- {
- $id = intval($_GET['sub']);
-
- $this->loadSubmitted($id);
- }
- else
- {
- $this->preCreate();
- }
-
- $this->newspost->show_create_item();
- }
- function categoryPage()
- {
- if(!getperms('0|7'))
- {
- $this->noPermissions();
- }
- $this->newspost->show_categories();
- // $newspost->show_create_item();
- }
-
- function submittedPage()
- {
- $this->newspost->show_submitted_news();
- }
-
- function maintPage()
- {
-
- }
-
- function settingsPage()
- {
- return $this->newspost->show_news_prefs();
- }
- function noPermissions($qry = '')
- {
- $url = e_SELF.($qry ? '?'.$qry : '');
- if($qry !== e_QUERY)
- {
- $mes = e107::getMessage();
- $this->show_message('Insufficient permissions!', E_MESSAGE_ERROR, true);
- session_write_close();
- header('Location: '.$url);
- }
- exit;
- }
-
-
- function loadSubmitted($id)
- {
- $sql = e107::getDb();
- $tp = e107::getParser();
-
- if ($sql->select("submitnews", "*", "submitnews_id=".intval($id)))
- {
-
- //list($id, $submitnews_name, $submitnews_email, $_POST['news_title'], $submitnews_category, $_POST['news_body'], $submitnews_datestamp, $submitnews_ip, $submitnews_auth, $submitnews_file) = $sql->fetch();
- $row = $sql->fetch();
- $_POST['news_title'] = $row['submitnews_title'];
- $_POST['news_body'] = $row['submitnews_item'];
- $_POST['cat_id'] = $row['submitnews_category'];
- // if (defsettrue('e_WYSIWYG'))
- // {
- // if (substr($_POST['news_body'],-7,7) == '[/html]') $_POST['news_body'] = substr($_POST['news_body'],0,-7);
- // if (substr($_POST['news_body'],0,6) == '[html]') $_POST['news_body'] = substr($_POST['news_body'],6);
- // $_POST['news_body'] .= "<br /><b>".NWSLAN_49." {$row['submitnews_name']}</b>";
- // $_POST['news_body'] .= ($row['submitnews_file'])? "<br /><br /><img src='{e_NEWSIMAGE}{$row['submitnews_file']}' class='f-right' />": '';
- // }
- // else
- {
- $_POST['news_body'] .= "\n[[b]".NWSLAN_49." {$row['submitnews_name']}[/b]]";
-
- if($row['submitnews_file'])
- {
- $files = explode(",",$row['submitnews_file']);
- foreach($files as $f)
- {
- if($bbpath = e107::getMedia()->importFile($f,'news'))
- {
- $_POST['news_body'] .= "\n\n[img]".$bbpath."[/img]";
- }
-
- }
- }
-
-
-
- }
- $_POST['data'] = $tp->dataFilter($_POST['data']); // Filter any nasties
- $_POST['news_title'] = $tp->dataFilter($_POST['news_title']);
- }
-
-
- }
-
-
-
-
-
- function preCreate()
- {
- if($_GET['action'] == "edit" && !$_POST['preview'])
- {
- if(!isset($_POST['submit_news']))
- {
- if(e107::getDb()->select('news', '*', 'news_id='.intval($_GET['id'])))
- {
- $row = e107::getDb()->fetch();
- // if(!isset($this->news_categories[$row['news_category']]))
- {
- // $this->noPermissions();
- }
- $_POST['news_title'] = $row['news_title'];
- $_POST['news_sef'] = $row['news_sef'];
- $_POST['news_body'] = $row['news_body'];
- $_POST['news_author'] = $row['news_author'];
- $_POST['news_extended'] = $row['news_extended'];
- $_POST['news_allow_comments'] = $row['news_allow_comments'];
- $_POST['news_class'] = $row['news_class'];
- $_POST['news_summary'] = $row['news_summary'];
- $_POST['news_sticky'] = $row['news_sticky'];
- $_POST['news_datestamp'] = ($_POST['news_datestamp']) ? $_POST['news_datestamp'] : $row['news_datestamp'];
- $_POST['cat_id'] = $row['news_category'];
- $_POST['news_start'] = $row['news_start'];
- $_POST['news_end'] = $row['news_end'];
- $_POST['comment_total'] = e107::getDb()->db_Count("comments", "(*)", " WHERE comment_item_id={$row['news_id']} AND comment_type='0'");
- $_POST['news_render_type'] = $row['news_render_type'];
- $_POST['news_thumbnail'] = $row['news_thumbnail'];
- $_POST['news_meta_keywords'] = $row['news_meta_keywords'];
- $_POST['news_meta_description'] = $row['news_meta_description'];
- }
- }
- else // on submit
- {
- if(!empty($_POST['news_meta_keywords'])) $_POST['news_meta_keywords'] = eHelper::formatMetaKeys($_POST['news_meta_keywords']);
- }
-
- }
- }
- }
- class news_form_ui extends e_admin_form_ui
- {
- function news_thumbnail($curval,$mode)
- {
- if(!vartrue($curval)) return;
-
-
- if(strpos($curval, ",")!==false)
- {
- $tmp = explode(",",$curval);
- $curval = $tmp[0];
- }
-
-
-
- $vparm = array('thumb'=>'tag','w'=> 80);
-
- if($thumb = e107::getParser()->toVideo($curval,$vparm))
- {
- return $thumb;
- }
-
-
- if($curval[0] != "{")
- {
- $curval = "{e_IMAGE}newspost_images/".$curval;
- }
-
- $url = e107::getParser()->thumbUrl($curval,'aw=80');
- $link = e107::getParser()->replaceConstants($curval);
-
- return "<a class='e-dialog' href='{$link}'><img src='{$url}' alt='{$curval}' /></a>";
- }
-
- function news_title($value, $mode)
- {
- if($mode == 'read')
- {
- $news_item = $this->getController()->getListModel()->toArray();
- $url = e107::getUrl()->create('news/view/item', $news_item);
- return "<a class='e-tip' href='{$url}' title='Open in new tab' rel='external'>".$value."</a>";
- }
- return $value;
- }
- }
- new news_admin();
- require_once(e_ADMIN."auth.php");
- e107::getAdminUI()->runPage();
- if(!e_AJAX_REQUEST) require_once("footer.php");
- exit;
- function headerjs()
- {
- return;
- $newspost = e107::getRegistry('_newspost_admin');
- /*
- $ret .= "<script type='text/javascript'>
- function UpdateForm(id)
- {
- new e107Ajax.Updater('filterValue', '".e_SELF."?searchValue', {
- method: 'post',
- evalScripts: true,
- parameters: {filtertype: id}
- });
- }
- </script>";
- */
- // TODO - REMOVE
- $ret .= "
- <script type='text/javascript'>
- if(typeof e107Admin == 'undefined') var e107Admin = {}
- /**
- * OnLoad Init Control
- */
- e107Admin.initRules = {
- 'Helper': true,
- 'AdminMenu': false
- }
- //custom expand
- Element.addMethods( {
- newsDescToggle: function(element) {
- element = \$(element);
- if(!element.visible())
- element.fxToggle();
- return element;
- },
- newsScrollToMe: function(element) {
- element = \$(element);
- new Effect.ScrollTo(element);
- return element;
- },
- newsUpdateButtonSpan: function(element, str, swapClass) {
- element = \$(element);
- if(swapClass) {
- var swapO = swapClass.split('::');
- element.removeClassName(swapO[0]).addClassName(swapO[1]);
- }
- if(element.down('span')) {
- element.down('span').update(str);
- }
- return element;
- }
- });
- //fix form action if needed
- document.observe('dom:loaded', function() {
- if(\$('core-newspost-create-form')) {
- \$('core-newspost-create-form').observe('submit', function(event) {
- var form = event.element();
- action = form.readAttribute('action') + document.location.hash;
- //if(\$('create-edit-stay-1') && \$('create-edit-stay-1').checked)
- form.writeAttribute('action', action);
- });
- }
- });
- </script>
- ";
- if($newspost->getAction() == 'cat')
- {
- $ret .= "
- <script type='text/javascript'>
- var e_npadmin_ajaxsave = function(action, element) {
- var id = element.name.gsub(/[^\d]/, ''),
- cl = element.value,
- url = '#{e_ADMIN}newspost.php?' + action + '.' + id + '.' + cl;
- element.startLoading();
- new e107Ajax.Request(url.parsePath(), {
- onComplete: function(transport) {
- element.stopLoading();
- if(transport.responseText)
- alert(transport.responseText);//error
- }
- });
- }
- //e107 onload custom event
- e107.runOnLoad( function(event) {
- var celement = event.memo['element'] ? \$(event.memo.element) : \$\$('body')[0];
- //Unobtrusive AJAX category list reload
- if(\$('trigger-list-refresh')) {
- \$('trigger-list-refresh').observe('click', function(event) {
- event.stop();
- \$('core-newspost-cat-list-form').submitForm(
- 'core-newspost-cat-list-cont',
- { overlayPage: \$\$('body')[0] },
- \$('core-newspost-cat-list-form').action + '_list_refresh'
- );
- });
- }
- //Unobtrusive AJAX save category manage permissions
- celement.select('select[name^=multi_category_manager]').invoke('observe', 'change', function(event) {
- e_npadmin_ajaxsave('catmanager', event.element());
- });
- //Category order fields - user convenience
- celement.select('input[name^=multi_category_order]').invoke('observe', 'focus', function(event) {
- event.element().select();
- });
- //Unobtrusive AJAX save category order
- celement.select('input[name^=multi_category_order]').invoke('observe', 'blur', function(event) {
- e_npadmin_ajaxsave('catorder', event.element());
- });
- //Fill form - click observer (Unobtrusive AJAX edit category)
- \$\$('a.action[id^=core-news-catedit-]').each(function(element) {
- element.observe('click', function(event) {
- event.stop();
- var el = event.findElement('a');
- $('core-newspost-cat-create-form').fillForm(\$\$('body')[0], { handler: el.readAttribute('href') });
- });
- });
- }, null, true);
- </script>
- ";
- }
- elseif ($newspost->getAction() == 'pref')
- {
- $ret .= "
- <script type='text/javascript'>
- document.observe('dom:loaded', function(){
- \$('newsposts').observe('change', function(event) {
- new e107Ajax.Updater(
- 'newsposts-archive-cont',
- '".e_SELF."?pref_archnum.' + (event.element().selectedIndex + 1) + '.' + event.element().readAttribute('tabindex'),
- { overlayElement: 'newsposts-archive-cont' }
- );
- });
- });
- </script>
- ";
- }
- $ret .= $newspost->_cal->load_files();
- return $ret;
- }
- $e_sub_cat = 'news';
- require_once('auth.php');
- /*
- * Observe for delete action
- */
- $newspost->observer();
- /*
- * Show requested page
- */
- $newspost->show_page();
- /* OLD JS? Can't find references to this func
- echo "
- <script type=\"text/javascript\">
- function fclear() {
- document.getElementById('core-newspost-create-form').data.value = \"\";
- document.getElementById('core-newspost-create-form').news_extended.value = \"\";
- }
- </script>\n";
- */
- require_once("footer.php");
- exit;
- class admin_newspost
- {
- var $_request = array();
- var $_cal = array();
- var $_pst;
- var $_fields;
- var $_sort_order;
- var $_sort_link;
- var $fieldpref;
- var $news_categories;
- public $news_renderTypes = array();
- public $error = false;
- function __construct($qry='')
- {
- global $user_pref;
-
-
- $qry = "";
- $this->parseRequest($qry);
- require_once(e_HANDLER."cache_handler.php");
- require_once(e_HANDLER."news_class.php");
- $this->fieldpref = varset($user_pref['admin_news_columns'], array('news_id', 'news_title', 'news_author', 'news_render_type', 'options'));
- $this->fields = array(
- 'checkboxes' => array('title' => '', 'type' => null, 'data'=> false, 'width' => '3%', 'thclass' => 'center first', 'class' => 'center', 'nosort' => true, 'toggle' => 'news_selected', 'forced' => TRUE),
- 'news_id' => array('title' => LAN_ID, 'type' => 'number', 'data'=> 'int', 'width' => '5%', 'thclass' => 'center', 'class' => 'center', 'nosort' => false),
- '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),
- 'news_title' => array('title' => LAN_TITLE, 'type' => 'text', 'data'=> 'str','width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
- 'news_summary' => array('title' => LAN_NEWS_27, 'type' => 'text', 'data'=> 'str','width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
-
- 'news_meta_keywords' => array('title' => LAN_KEYWORDS, 'type' => 'text', 'data'=> 'str','width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
- 'news_meta_description' => array('title' => LAN_DESCRIPTION,'type' => 'text', 'data'=> 'str','width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
- 'news_sef' => array('title' => LAN_SEFURL, 'type' => 'text', 'data'=> 'str','width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
- 'user_name' => array('title' => LAN_AUTHOR, 'type' => 'text', 'data'=> 'str','width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
- 'news_datestamp' => array('title' => LAN_NEWS_32, 'type' => 'datestamp', 'data'=> 'str','width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'parms' => 'mask=%A %d %B %Y'),
- 'category_name' => array('title' => NWSLAN_6, 'type' => 'text', 'data'=> 'str','width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
-
- 'news_start' => array('title' => "Start", 'type' => 'datestamp', 'data'=> 'str','width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'parms' => 'mask=%A %d %B %Y'),
- 'news_end' => array('title' => "End", 'type' => 'datestamp', 'data'=> 'str','width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'parms' => 'mask=%A %d %B %Y'),
-
-
- 'news_class' => array('title' => LAN_VISIBILITY, 'type' => 'userclass', 'data'=> 'str', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
- 'news_render_type' => array('title' => LAN_NEWS_49, 'type' => 'dropdown', 'data'=> 'comma', 'width' => 'auto', 'thclass' => 'center', 'class' => null, 'nosort' => false),
- 'news_sticky' => array('title' => LAN_NEWS_28, 'type' => 'boolean', 'data'=> 'int', 'width' => 'auto', 'thclass' => 'center', 'class' => 'center', 'nosort' => false),
- 'news_allow_comments' => array('title' => NWSLAN_15, 'type' => 'boolean', 'data'=> 'int', 'width' => 'auto', 'thclass' => 'center', 'class' => 'center', 'nosort' => false),
- 'news_comment_total' => array('title' => LAN_NEWS_60, 'type' => 'number', 'data'=> 'int', 'width' => '10%', 'thclass' => '', 'class' => null, 'nosort' => false),
- 'options' => array('title' => LAN_OPTIONS, 'type' => null, 'data'=> false, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center', 'nosort' => true, 'forced' => TRUE)
- );
- /* $ren_type = array(NWSLAN_75,NWSLAN_76,NWSLAN_77,NWSLAN_77." 2");
- $r_array = array();
- foreach($ren_type as $key=>$value)
- {
- $this->news_renderTypes[$key] = $value;
- }*/
- // $this->news_renderTypes = array('0'=>NWSLAN_75,'1'=>NWSLAN_76,'2'=>NWSLAN_77,'3'=>NWSLAN_77." 2",'4'=>"Featurebox");
- // $this->news_renderTypes = array('0'=>"FrontPage",'1'=>"FrontPage - Linkonly",'2'=>"Othernews Sidebar",'3'=>"Othernews Sidebar"." 2",'4'=>"Featurebox");
-
- }
- function parseRequest($qry)
- {
- $tmp = explode(".", $qry);
- $action = varsettrue($tmp[0], 'main');
- $sub_action = varset($tmp[1], '');
- $id = isset($tmp[2]) && is_numeric($tmp[2]) ? intval($tmp[2]) : 0;
- $this->_sort_order = isset($tmp[2]) && !is_numeric($tmp[2]) ? $tmp[2] : 'desc';
- $from = intval(varset($tmp[3],0));
- unset($tmp);
-
- $action = vartrue($_GET['action'],'main');
- $sub_action = varset($_GET['sub'],'');
- $id = isset($_GET['id']) && is_numeric($_GET['id']) ? intval($_GET['id']) : 0;
- $this->_sort_order = isset($_GET['id']) && !is_numeric($_GET['id']) ? $_GET['id'] : 'desc';
- $from = intval(varset($_GET['frm'],0));
- if ($this->_sort_order != 'asc') $this->_sort_order = 'desc';
- $this->_sort_link = ($this->_sort_order) == 'asc' ? 'desc' : 'asc';
- $sort_order = 'desc';
- $this->_request = array($action, $sub_action, $id, $sort_order, $from);
- }
- function getAction()
- {
- return $this->_request[0];
- }
- /**
- * @param string $action
- * @return admin_newspost
- */
- function setAction($action)
- {
- $this->_request[0] = $action;
- return $this;
- }
- function getSubAction()
- {
- return $this->_request[1];
- }
- /**
- * @param string $action
- * @return admin_newspost
- */
- function setSubAction($action)
- {
- $this->_request[1] = $action;
- return $this;
- }
- function getId()
- {
- return $this->_request[2];
- }
- /**
- * @param integer $id
- * @return admin_newspost
- */
- function setId($id)
- {
- $this->_request[2] = intval($id);
- return $this;
- }
- function getSortOrder()
- {
- return $this->_request[3];
- }
- function getFrom()
- {
- return $this->_request[4];
- }
- function clear_cache()
- {
- $ecache = e107::getCache();
- $ecache->clear("news.php"); //TODO change it to 'news_*' everywhere
- $ecache->clear("news_", false, true); //NEW global news cache prefix
- //$ecache->clear("nq_news_"); - supported by cache::clear() now
- //$ecache->clear("nomd5_news_"); supported by cache::clear() now
- $ecache->clear("othernews"); //TODO change it to 'news_othernews' everywhere
- $ecache->clear("othernews2"); //TODO change it to 'news_othernews2' everywhere
- return $this;
- }
- function clear_rwcache($sefstr = '')
- {
- // obsolete
- }
- function set_rwcache($sefstr, $data)
- {
- // obsolete
- }
- function ajax_observer()
- {
- $method = 'ajax_exec_'.$this->getAction();
- if(e_AJAX_REQUEST && method_exists($this, $method))
- {
- $this->$method();
- return true;
- }
- return false;
- }
- function observer()
- {
- e107::getDb()->db_Mark_Time('News Administration');
- $this->news_categories = array();
- if(e107::getDb()->select('news_category', '*', (getperms('0') ? '' : 'category_manager IN ('.USERCLASS_LIST.')')))
- {
- $this->news_categories = e107::getDb()->db_getList('ALL', FALSE, FALSE, 'category_id');
- }
- //Required on create & savepreset action triggers
- if(isset($_POST['news_userclass']) && is_array($_POST['news_userclass']))
- {
- $_POST['news_class'] = implode(",", $_POST['news_userclass']);
- unset($_POST['news_userclass']);
- }
- $main = getperms('0');
- if(isset($_POST['delete']) && is_array($_POST['delete']))
- {
- $this->_observe_delete();
- }
- elseif(isset($_POST['execute_batch']))
- {
- $this->process_batch($_POST['news_selected']);
- }
- elseif(isset($_POST['submit_news']))
- {
- $this->_observe_submit_item($this->getSubAction(), $this->getId());
- }
- elseif($main && isset($_POST['create_category']))
- {
- $this->_observe_create_category();
- }
- elseif($main && isset($_POST['update_category']))
- {
- $this->_observe_update_category();
- }
- elseif($main && isset($_POST['multi_update_category']))
- {
- $this->_observe_multi_create_category();
- }
- elseif($main && isset($_POST['save_prefs']))
- {
- $this->_observe_save_prefs();
- }
- elseif(isset($_POST['submitupload']))
- {
- $this->_observe_upload();
- }
- elseif(isset($_POST['news_comments_recalc']))
- {
- $this->_observe_newsCommentsRecalc();
- }
- if(isset($_POST['etrigger_ecolumns'])) //elseif fails.
- {
- // $this->_observe_saveColumns();
- }
- }
- function show_page()
- {
-
- // print_a($POST);
-
- switch ($this->getAction()) {
- case 'create':
- $this->_pst->read_preset('admin_newspost'); //only works here because $_POST is used.
- $this->show_create_item();
- break;
- case 'cat':
- if(!getperms('0|7'))
- {
- $this->noPermissions();
- }
- $this->show_categories();
- break;
- case 'sn':
- $this->show_submitted_news();
- break;
- case 'pref':
- if(!getperms('0'))
- {
- $this->noPermissions();
- }
- $this->show_news_prefs();
- break;
- case 'maint' :
- if(!getperms('0'))
- {
- $this->noPermissions();
- }
- $this->showMaintenance();
- break;
- default:
- $this->show_existing_items();
- break;
- }
- }
- function _observe_delete()
- {
- $admin_log = e107::getAdminLog();
- //FIXME - SEF URL cache
- $tmp = array_keys($_POST['delete']);
- list($delete, $del_id) = explode("_", $tmp[0]);
- $del_id = intval($del_id);
- if(!$del_id) return false;
- $e107 = e107::getInstance();
- switch ($delete) {
- case 'main':
-
- if ($sql->count('news','(*)',"news_id={$del_id}"))
- {
- e107::getEvent()->trigger("newsdel", $del_id);
- if($sql->delete("news", "news_id={$del_id}"))
- {
- $admin_log->log_event('NEWS_01',$del_id,E_LOG_INFORMATIVE,'');
- $this->show_message(NWSLAN_31." #".$del_id." ".NWSLAN_32, E_MESSAGE_SUCCESS);
- $this->clear_cache();
- $data = array('method'=>'delete', 'table'=>'news', 'id'=>$del_id, 'plugin'=>'news', 'function'=>'delete');
- $this->show_message(e107::getEvent()->triggerHook($data), E_MESSAGE_WARNING);
- admin_purge_related("news", $del_id);
- }
- }
- break;
- case 'category':
-
- if(!getperms('0|7')) $this->noPermissions();
- if (($count = $sql->count('news','(news_id)',"news_category={$del_id}")) === false || $count > 0)
- {
- $this->show_message('Category is in used in <strong>'.$count.'</strong> news items and cannot be deleted.', E_MESSAGE_ERROR);
- return false;
- }
-
- if ($sql->count('news_category','(*)',"category_id={$del_id}"))
- {
- e107::getEvent()->trigger("newscatdel", $del_id);
- if ($sql->delete("news_category", "category_id={$del_id}"))
- {
- $admin_log->log_event('NEWS_02',$del_id,E_LOG_INFORMATIVE,'');
- $this->show_message(NWSLAN_33." #".$del_id." ".NWSLAN_32, E_MESSAGE_SUCCESS);
- $this->clear_cache();
- }
- }
- break;
- case 'sn':
- if ($sql->delete("submitnews", "submitnews_id={$del_id}"))
- {
- $admin_log->log_event('NEWS_03',$del_id,E_LOG_INFORMATIVE,'');
- $this->show_message(NWSLAN_34." #".$del_id." ".NWSLAN_32);
- $this->clear_cache();
- }
- break;
- default:
- return false;
- }
- return true;
- }
- /**
- * For future use: multiple-images.
- */
- private function processThumbs($postedImage)
- {
- if(is_array($postedImage))
- {
- return implode(",",array_filter($postedImage));
- }
- else
- {
- return $postedImage;
- }
-
- }
- // In USE.
- function _observe_submit_item($sub_action, $id)
- {
- // ##### Format and submit item to DB
-
- $ix = new news;
- // jQuery UI temporary date-time fix - inputdatetime -> inputdate
- $_POST['news_start'] = vartrue(e107::getDate()->convert($_POST['news_start'],'inputdatetime'), 0);
- if($_POST['news_start'])
- {
- // $_POST['news_start'] = e107::getDate()->convert($_POST['news_start']);
- }
- else
- {
- // $_POST['news_start'] = 0;
- }
- if($_POST['news_end'])
- {
- $_POST['news_end'] = e107::getDate()->convert($_POST['news_end'],'inputdatetime');
- }
- else
- {
- $_POST['news_end'] = 0;
- }
-
- if($_POST['news_datestamp'])
- {
- $_POST['news_datestamp'] = e107::getDate()->convert($_POST['news_datestamp'],'inputdatetime');
- }
- else
- {
- $_POST['news_datestamp'] = time();
- }
-
-
- $_POST['news_thumbnail'] = $this->processThumbs($_POST['news_thumbnail']);
-
-
-
-
-
- /*
- $matches = array();
- if(preg_match('#(.*?)/(.*?)/(.*?) (.*?):(.*?):(.*?)$#', $_POST['news_datestamp'], $matches))
- {
- $_POST['news_datestamp'] = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[1], $matches[3]);
- }
- else
- {
- $_POST['news_datestamp'] = time();
- }
-
- if($_POST['update_datestamp'])
- {
- $_POST['news_datestamp'] = time();
- }
- */
-
-
- if ($id && $sub_action != "sn" && $sub_action != "upload")
- {
- $_POST['news_id'] = $id;
- }
- else
- {
- e107::getDb()->db_Update('submitnews', "submitnews_auth=1 WHERE submitnews_id ={$id}");
- e107::getAdminLog()->log_event('NEWS_07', $id, E_LOG_INFORMATIVE,'');
- }
- if (!isset($_POST['cat_id']))
- {
- $_POST['cat_id'] = 0;
- }
- $_POST['news_category'] = $_POST['cat_id'];
- if(!isset($this->news_categories[$_POST['news_category']]))
- {
- $this->noPermissions();
- }
- /*if(isset($_POST['news_thumbnail']))
- {
- $_POST['news_thumbnail'] = urldecode(basename($_POST['news_thumbnail']));
- }*/
- $_POST['news_render_type'] = implode(",",$_POST['news_render_type']);
- // print_a($_POST);
- // exit;
- $tmp = explode(chr(35), $_POST['news_author']);
- $_POST['news_author'] = $tmp[0];
-
- $ret = $ix->submit_item($_POST, !vartrue($_POST['create_edit_stay']));
- if($ret['error'])
- {
- e107::getMessage()->mergeWithSession() //merge with session messages
- ->add(($id ? LAN_UPDATED_FAILED : LAN_CREATED_FAILED), E_MESSAGE_ERROR);
-
- $_POST['news_sef'] = $ret['data']['news_sef'];
- return false;
- }
- $this->clear_cache();
-
- if(isset($_POST['create_edit_stay']) && !empty($_POST['create_edit_stay']))
- {
- if($this->getAction() != 'edit')
- {
- session_write_close();
- $rurl = e_SELF.(vartrue($ret['news_id']) ? '?mode='.$_GET['mode'].'&action=edit&id='.$ret['news_id'] : '');
- header('Location: '.$rurl);
- exit;
- }
- }
- else
- {
- session_write_close();
- header('Location:'.e_SELF);
- exit;
- }
- }
- function _observe_create_category()
- {
- if(!getperms('0|7'))
- {
- $this->noPermissions();
- }
- //FIXME - lan, e_model based news administration model
- $this->error = false;
- if(empty($_POST['category_name']))
- {
- $this->show_message('Validation Error: Missing Category name', E_MESSAGE_ERROR);
- $this->error = true;
- if(!empty($_POST['category_sef']))
- {
- $_POST['category_sef'] = eHelper::secureSef($_POST['category_sef']);
- }
- }
- else
- {
- // first format sef...
- if(empty($_POST['category_sef']))
- {
- $_POST['category_sef'] = eHelper::title2sef($_POST['category_name']);
- }
- else
- {
- $_POST['category_sef'] = eHelper::secureSef($_POST['category_sef']);
- }
- }
-
- // ...then check it
- if(empty($_POST['category_sef']))
- {
- $this->error = true;
- $this->show_message('Validation error: News Category SEF URL value is required field and can\'t be empty!', E_MESSAGE_ERROR);
- }
- elseif(e107::getDb()->db_Count('news_category', '(category_id)', "category_sef='".e107::getParser()->toDB($_POST['category_sef'])."'"))
- {
- $this->error = true;
- $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);
- }
- if (!$this->error)
- {
- $inserta = array();
- $inserta['data']['category_icon'] = $_POST['category_icon'];
- $inserta['_FIELD_TYPES']['category_icon'] = 'todb';
- $inserta['data']['category_name'] = $_POST['category_name'];
- $inserta['_FIELD_TYPES']['category_name'] = 'todb';
-
- $inserta['data']['category_sef'] = $_POST['category_sef'];
- $inserta['_FIELD_TYPES']['category_sef'] = 'todb';
- $inserta['data']['category_meta_description'] = eHelper::formatMetaDescription($_POST['category_meta_description']);
- $inserta['_FIELD_TYPES']['category_meta_description'] = 'todb';
- $inserta['data']['category_meta_keywords'] = eHelper::formatMetaKeys($_POST['category_meta_keywords']);
- $inserta['_FIELD_TYPES']['category_meta_keywords'] = 'todb';
- $inserta['data']['category_manager'] = $_POST['category_manager'];
- $inserta['_FIELD_TYPES']['category_manager'] = 'int';
- $inserta['data']['category_order'] = $_POST['category_order'];
- $inserta['_FIELD_TYPES']['category_order'] = 'int';
- $id = e107::getDb()->db_Insert('news_category', $inserta);
- if($id)
- {
- $inserta['data']['category_id'] = $id;
-
- //admin log now supports DB array and method chaining
- e107::getAdminLog()->log_event('NEWS_04', $inserta, E_LOG_INFORMA…