form = "core-newspost-create-form"; // form id of the form that will have it's values saved.
$pst->page = "newspost.php?create"; // display preset options on which page(s).
$pst->id = "admin_newspost";
// ------------------------------
// 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, $pst);
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'=> NWSLAN_44, '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'=> NWSLAN_46, 'perm' => '7'), // Create Category.
'cat/create' => array('caption'=> "Create Category", 'perm' => '7'), // 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 = 'News Categories';
protected $pluginName = 'core';
protected $table = "news_category";
protected $pid = "category_id";
protected $perPage = 0; //no limit
protected $batchDelete = false;
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', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>FALSE),
'category_meta_description' => array('title'=> LAN_DESCRIPTION, 'type' => 'textarea', 'width' => 'auto', 'thclass' => 'left','readParms' => 'expand=...&truncate=150&bb=1', 'readonly'=>FALSE),
'category_meta_keywords' => array('title'=> "Meta Keywords", 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>FALSE),
'category_sef' => array('title'=> "SEF Url String", 'type' => 'text', 'width' => 'auto', 'readonly'=>FALSE), // Display name
'category_manager' => array('title'=> "Manage Permissions",'type' => 'userclass', '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')
);
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)
{
}
public function beforeUpdate($new_data, $old_data, $id)
{
}
}
class news_cat_form_ui extends e_admin_form_ui
{
}
// Submitted News Area.
class news_sub_ui extends e_admin_ui
{
protected $pluginTitle = NWSLAN_47;
protected $pluginName = 'core';
protected $table = "submitnews";
protected $pid = "submitnews_id";
protected $perPage = 20; //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' => '65%', 'thclass' => 'left', 'readonly'=>TRUE),
'submitnews_datestamp' => array('title' => LAN_NEWS_32, 'type' => 'date', '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->db_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 .= "";
$text .= $tp->toHTML($submitnews_title,FALSE,'emotes_off, no_make_clickable');
$text .= '';
$text .= "
".$tp->toHTML($submitnews_item,TRUE);
if($submitnews_file)
{
$tmp = explode(',',$submitnews_file);
$text .= "
";
foreach($tmp as $imgfile)
{
$text .= "
![".$imgfile."](".e_UPLOAD.$imgfile.")
";
}
}
$text .= "\n
";
return $text;
}
// Override the default Options field.
function options($parms, $value, $id, $attributes)
{
if($attributes['mode'] == 'read')
{
$approved = $this->getController()->getListModel()->get('submitnews_auth'); // approved;
if($approved == 0)
{
$text = $this->submit_image('submitnews['.$id.']', 1, 'execute', NWSLAN_58);
// NWSLAN_103;
}
else // Already submitted;
{
}
$text .= $this->submit_image('etrigger_delete['.$id.']', $id, 'delete', LAN_DELETE.' [ ID: '.$id.' ]', array('class' => 'action delete'.$delcls));
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 = 20; //no limit
protected $batchDelete = true;
protected $batchCopy = true;
protected $listOrder = "news_id desc";
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_NEWS_45, 'type' => 'number', 'width' => '5%', 'thclass' => 'center', 'class' => 'center', 'nosort' => false),
'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' => NWSLAN_40, 'type' => 'text', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'readParms'=>'link={e_BASE}news.php?extend.[id]&dialog=1'),
'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' => 'SEF URL', 'type' => 'text', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
'user_name' => array('title' => LAN_NEWS_50, 'type' => 'text', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
'news_datestamp' => array('title' => LAN_NEWS_32, 'type' => 'datestamp', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'parms' => 'mask=%A %d %B %Y'),
'news_category' => array('title' => NWSLAN_6, 'type' => 'dropdown', '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' => NWSLAN_22, 'type' => 'userclasses', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'batch'=>true, 'filter'=>true),
'news_render_type' => array('title' => LAN_NEWS_49, 'type' => 'dropdown', 'data' => 'int', 'width' => 'auto', 'thclass' => 'center', 'class' => null, 'nosort' => false, 'batch'=>true, 'filter'=>true),
'news_sticky' => array('title' => LAN_NEWS_28, 'type' => 'boolean', 'width' => 'auto', 'thclass' => 'center', 'class' => 'center', 'nosort' => false, 'batch'=>true, 'filter'=>true),
'news_allow_comments' => array('title' => NWSLAN_15, 'type' => 'boolean', 'width' => 'auto', 'thclass' => 'center', 'class' => 'center', 'nosort' => false),
'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;
function init()
{
$sql = e107::getDb();
$sql->db_Select_gen("SELECT category_id,category_name FROM #news_category");
while($row = $sql->db_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'] = array(NWSLAN_75,NWSLAN_76,NWSLAN_77,NWSLAN_77." 2");
$this->newspost = new admin_newspost;
$this->newspost->observer();
}
function createPage()
{
// print_a($_POST);
if(isset($_POST['submitnews']))
{
$id = key($_POST['submitnews']);
$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()
{
$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->db_Select("submitnews", "*", "submitnews_id=".intval($id), TRUE))
{
//list($id, $submitnews_name, $submitnews_email, $_POST['news_title'], $submitnews_category, $_POST['news_body'], $submitnews_datestamp, $submitnews_ip, $submitnews_auth, $submitnews_file) = $sql->db_Fetch();
$row = $sql->db_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'] .= "
".NWSLAN_49." {$row['submitnews_name']}";
$_POST['news_body'] .= ($row['submitnews_file'])? "
": '';
}
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()->db_Select('news', '*', 'news_id='.intval($_GET['id'])))
{
$row = e107::getDb()->db_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'];
}
}
}
}
}
class news_form_ui extends e_admin_form_ui
{
function news_thumbnail($curval,$mode)
{
if(!vartrue($curval)) return;
if($curval[0] != "{")
{
$curval = "{e_IMAGE}newspost_images/".$curval;
}
$url = e107::getParser()->thumbUrl($curval,'aw=80');
$link = e107::getParser()->replaceConstants($curval);
return "
";
}
}
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 .= "";
*/
// TODO - move this to external JS when news becomes a plugin
$ret .= "
";
if($newspost->getAction() == 'cat')
{
$ret .= "
";
}
elseif ($newspost->getAction() == 'pref')
{
$ret .= "
";
}
$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 "
\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;
var $news_renderTypes = array();
public $error = false;
function __construct($qry, $pstobj)
{
global $user_pref;
$qry = "";
$this->parseRequest($qry);
require_once(e_HANDLER."cache_handler.php");
require_once(e_HANDLER."news_class.php");
$this->_pst = $pstobj;
$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, 'width' => '3%', 'thclass' => 'center first', 'class' => 'center', 'nosort' => true, 'toggle' => 'news_selected', 'forced' => TRUE),
'news_id' => array('title' => LAN_NEWS_45, 'type' => 'number', 'width' => '5%', 'thclass' => 'center', 'class' => 'center', 'nosort' => false),
'news_thumbnail' => array('title' => NWSLAN_67, 'type' => 'image', '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' => NWSLAN_40, 'type' => 'text', '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' => 'SEF URL', 'type' => 'text', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
'user_name' => array('title' => LAN_NEWS_50, 'type' => 'text', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
'news_datestamp' => array('title' => LAN_NEWS_32, 'type' => 'datestamp', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'parms' => 'mask=%A %d %B %Y'),
'category_name' => array('title' => NWSLAN_6, 'type' => 'text', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
'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' => NWSLAN_22, 'type' => 'userclass', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
'news_render_type' => array('title' => LAN_NEWS_49, 'type' => 'number', 'width' => 'auto', 'thclass' => 'center', 'class' => null, 'nosort' => false),
'news_sticky' => array('title' => LAN_NEWS_28, 'type' => 'boolean', 'width' => 'auto', 'thclass' => 'center', 'class' => 'center', 'nosort' => false),
'news_allow_comments' => array('title' => NWSLAN_15, 'type' => 'boolean', 'width' => 'auto', 'thclass' => 'center', 'class' => 'center', 'nosort' => false),
'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)
);
/* $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(NWSLAN_75,NWSLAN_76,NWSLAN_77,NWSLAN_77." 2");
}
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()->db_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 'savepreset':
case 'clr_preset':
$this->_pst->save_preset('news_datestamp', false); // save and render result using unique name. Don't save item datestamp
$_POST = array();
$this->parseRequest('');
$this->show_existing_items();
break;
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 ($e107->sql->db_Count('news','(*)',"news_id={$del_id}"))
{
e107::getEvent()->trigger("newsdel", $del_id);
if($e107->sql->db_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 = $e107->sql->db_Count('news','(news_id)',"news_category={$del_id}")) === false || $count > 0)
{
$this->show_message('Category is in used in '.$count.' news items and cannot be deleted.', E_MESSAGE_ERROR);
return false;
}
if ($e107->sql->db_Count('news_category','(*)',"category_id={$del_id}"))
{
e107::getEvent()->trigger("newscatdel", $del_id);
if ($e107->sql->db_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 ($e107->sql->db_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;
}
function _observe_submit_item($sub_action, $id)
{
// ##### Format and submit item to DB
$ix = new news;
$_POST['news_start'] = vartrue(e107::getDate()->convert($_POST['news_start'],'inputdatetime'), 0);
// echo "date=".$_POST['news_start'];
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();
}
/*
$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']));
}*/
$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->getSubAction() != 'edit')
{
session_write_close();
$rurl = e_SELF.(varsettrue($ret['id']) ? "?create.edit.".$ret['id'] : '');
header('Location:'.($rurl ? $rurl : e_SELF));
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_INFORMATIVE, '');
$this->show_message(NWSLAN_35, E_MESSAGE_SUCCESS);
$this->clear_cache();
//TODO - add to WIKI docs
e107::getEvent()->trigger("newscatpost", array_merge($inserta['data'], $rwinserta['data']));
}
else
{
//debug + error message
if(e107::getDb()->getLastErrorNumber())
{
$this->error = true;
$this->show_message('mySQL Error detected!', E_MESSAGE_ERROR);
eMessage::getInstance()->addS('mySQL error #'.e107::getDb()->getLastErrorNumber().': '.e107::getDb()->getLastErrorText(), E_MESSAGE_DEBUG);
}
}
}
}
function _observe_update_category()
{
if(!getperms('0|7'))
{
$this->noPermissions();
}
$this->setId(intval($_POST['category_id']));
if(!$this->getId())
{
return;
}
//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_id<>".$this->getId()." AND 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)
{
$updatea = array();
$updatea['data']['category_icon'] = $_POST['category_icon'];
$updatea['_FIELD_TYPES']['category_icon'] = 'todb';
$updatea['data']['category_name'] = $_POST['category_name'];
$updatea['_FIELD_TYPES']['category_name'] = 'todb';
$updatea['data']['category_sef'] = $_POST['category_sef'];
$updatea['_FIELD_TYPES']['category_sef'] = 'todb';
$updatea['data']['category_meta_description'] = strip_tags($_POST['category_meta_description']);
$updatea['_FIELD_TYPES']['category_meta_description'] = 'str';
$updatea['data']['category_meta_keywords'] = $_POST['category_meta_keywords'];
$updatea['_FIELD_TYPES']['category_meta_keywords'] = 'str';
$updatea['data']['category_manager'] = $_POST['category_manager'];
$updatea['_FIELD_TYPES']['category_manager'] = 'int';
$updatea['data']['category_order'] = $_POST['category_order'];
$updatea['_FIELD_TYPES']['category_order'] = 'int';
$updatea['WHERE'] = 'category_id='.$this->getId();
$inserta = array();
$rid = 0;
$upcheck = e107::getDb()->db_Update("news_category", $updatea);
$rwupcheck = false;
if($upcheck || !e107::getDb()->getLastErrorNumber())
{
if ($upcheck || $rwupcheck)
{
//admin log now supports DB array and method chaining
$updatea['data']['category_id'] = $this->getId();
if($upcheck) e107::getAdminLog()->log_event('NEWS_05', $updatea['data'], E_LOG_INFORMATIVE, '');
if($rwupcheck && $inserta['data']) e107::getAdminLog()->log_event('NEWS_10', $inserta['data'], E_LOG_INFORMATIVE, '');
$this->show_message(NWSLAN_36, E_MESSAGE_SUCCESS);
$this->clear_cache();
//TODO - add to WIKI docs
e107::getEvent()->trigger("newscatupd", array_merge($updatea['data'], $inserta['data']));
}
else
{
$this->show_message(LAN_NO_CHANGE);
}
$this->setId(0);
}
else
{
$this->error = true;
$this->setSubAction('edit');
$this->show_message('mySQL Error detected!', E_MESSAGE_ERROR);
$this->show_message('#'.e107::getDb()->getLastErrorNumber().': '.e107::getDb()->getLastErrorText(), E_MESSAGE_DEBUG);
return;
}
}
}
function _observe_multi_create_category()
{
if(!getperms('0|7'))
{
$this->noPermissions();
}
$cnt = 0;
foreach ($_POST['multi_category_manager'] as $cid => $val)
{
$order = $_POST['multi_category_order'][$cid];
$cnt += (int) e107::getDb()->db_Update('news_category', 'category_manager='.intval($val).', category_order='.intval($order).' WHERE category_id='.intval($cid));
}
if($cnt) eMessage::getInstance()->add(LAN_UPDATED, E_MESSAGE_SUCCESS);
}
function _observe_save_prefs()
{
if(!getperms('0'))
{
$this->noPermissions();
}
$temp = array();
$temp['newsposts'] = intval($_POST['newsposts']);
$temp['newsposts_archive'] = intval($_POST['newsposts_archive']);
$temp['newsposts_archive_title'] = e107::getParser()->toDB($_POST['newsposts_archive_title']);
$temp['news_cats'] = intval($_POST['news_cats']);
$temp['nbr_cols'] = intval($_POST['nbr_cols']);
$temp['subnews_attach'] = intval($_POST['subnews_attach']);
$temp['subnews_resize'] = intval($_POST['subnews_resize']);
$temp['subnews_class'] = intval($_POST['subnews_class']);
$temp['subnews_htmlarea'] = intval($_POST['subnews_htmlarea']);
$temp['news_subheader'] = e107::getParser()->toDB($_POST['news_subheader']);
$temp['news_newdateheader'] = intval($_POST['news_newdateheader']);
$temp['news_unstemplate'] = intval($_POST['news_unstemplate']);
$temp['news_editauthor'] = intval($_POST['news_editauthor']);
$temp['news_sefbase'] = preg_replace('#[^\w\pL\-]#u', '', $_POST['news_sefbase']);
e107::getConfig()->updatePref($temp);
if(e107::getConfig()->save(false))
{
e107::getAdminLog()->logArrayDiffs($temp, e107::getPref(), 'NEWS_06');
$this->clear_cache();
//$this->show_message(NWSLAN_119, E_MESSAGE_SUCCESS);
}
}
function _observe_upload()
{
//$pref['upload_storagetype'] = "1";
require_once(e_HANDLER."upload_handler.php");
$uploaded = file_upload(e_NEWSIMAGE);
foreach($_POST['uploadtype'] as $key=>$uploadtype)
{
if($uploadtype == "thumb")
{
rename(e_NEWSIMAGE.$uploaded[$key]['name'],e_NEWSIMAGE."thumb_".$uploaded[$key]['name']);
}
if($uploadtype == "file")
{
rename(e_NEWSIMAGE.$uploaded[$key]['name'],e_DOWNLOAD.$uploaded[$key]['name']);
}
if ($uploadtype == "resize" && $_POST['resize_value'])
{
require_once(e_HANDLER."resize_handler.php");
resize_image(e_NEWSIMAGE.$uploaded[$key]['name'], e_NEWSIMAGE.$uploaded[$key]['name'], $_POST['resize_value'], "copy");
}
}
}
function _observe_saveColumns()
{
global $user_pref,$admin_log;
$user_pref['admin_news_columns'] = $_POST['e-columns'];
save_prefs('user');
$this->fieldpref = $user_pref['admin_news_columns'];
}
function show_existing_items()
{
$user_pref = e107::getUser()->getPref();
$sql = e107::getDb();
if(!getperms('H'))
{
return;
}
//require_once(e_HANDLER."form_handler.php");
$frm = e107::getForm(true); //enable inner tabindex counter
// Effectively toggle setting for headings
$amount = 10;//TODO - pref
if(!is_array($user_pref['admin_news_columns']))
{
$user_pref['admin_news_columns'] = array("news_id","news_title","news_author","news_render_type");
}
$field_columns = $this->fields;
$e107 = e107::getInstance();
// ------ Search Filter ------
$text .= "
";
// --------------------------------------------
$query = "
SELECT n.*, nc.*, u.user_name, u.user_id FROM #news AS n
LEFT JOIN #news_category AS nc ON n.news_category=nc.category_id
LEFT JOIN #user AS u ON n.news_author=u.user_id
";
$check_perms = !getperms('0') ? " nc.category_manager IN (".USERCLASS_LIST.") " : '';
// Quick qry fix.
$check_perms .= (vartrue($_GET['filter'])) ? " n.news_category = ".intval($_GET['filter'])." " : "";
if (vartrue($_GET['srch']))
{
$query .= "WHERE {$check_perms}n.news_title REGEXP('".$_GET['srch']."') OR n.news_body REGEXP('".$_GET['srch']."') OR n.news_extended REGEXP('".$_GET['srch']."') ORDER BY n.news_datestamp DESC";
}
else
{
$ordfield = 'n.news_datestamp';
if($this->getSubAction() == 'user_name')
{
$ordfield = "u.user_name";
}
elseif(strpos($this->getSubAction(), 'category_'))
{
$ordfield = 'nc.'.$this->getSubAction();
}
elseif($this->getSubAction())
{
$ordfield = 'n.'.$this->getSubAction();
}
$query .= ($check_perms ? "WHERE {$check_perms}" : '')."ORDER BY {$ordfield} ".strtoupper($this->_sort_order);
}
$newsposts = $sql->db_Select_gen($query);
//echo "sql=".$query;
if ($sql->db_Select_gen($query." LIMIT ".$this->getFrom().", {$amount}"))
{
$newsarray = $e107->sql->db_getList();
$text .= "
";
}
else
{
$tmp = NWSLAN_43;
if(vartrue($_GET['srch']))
{
$tmp = sprintf(NWSLAN_121, '"'.$_GET['srch'])."" « ".LAN_BACK."";
}
$text = "{$tmp}
";
}
// $newsposts = $e107->sql->db_Count('news');
if ($newsposts > $amount)
{
// $parms = $newsposts.",".$amount.",".$this->getFrom().",".e_SELF."?".$this->getAction().'.'.($this->getSubAction() ? $this->getSubAction() : 0).'.'.$this->_sort_order.".[FROM]";
$parms = $newsposts.",".$amount.",".$this->getFrom().",".e_SELF."?action=".$this->getAction().'&sub='.($this->getSubAction() ? $this->getSubAction() : 0).'&id='.$this->_sort_order.'&filter='.intval($_GET['filter']).'&srch='.$_GET['srch']."&frm=[FROM]";
$nextprev = $e107->tp->parseTemplate("{NEXTPREV={$parms}}");
if ($nextprev) $text .= "".$nextprev."
";
}
e107::getRender()->tablerender(NWSLAN_4, e107::getMessage()->render().$text);
}
function show_batch_options()
{
$classes = e107::getUserClass()->uc_get_classlist();
// Grab news Category Names;
e107::getDb()->db_Select('news_category', '*');
$newscatarray = e107::getDb()->db_getList();
$news_category = $news_manage = array();
foreach($newscatarray as $val)
{
$news_category[$val['category_id']] = $val['category_name'];
$news_manage[$val['category_id']] = $val['category_manager'];
}
$comments_array = array('Allow Comments', 'Disable Comments', 'Reverse Allow/Disalow');
$sticky_array = array(1 => 'Sticky', 0 => 'Not Sticky', 2 => 'Reverse Them'); // more proper controls order
return e107::getForm()->batchoptions(
array(
'delete_selected' => LAN_DELETE,
'category' => array('Modify Category', $news_category),
'sticky_selected' => array('Modify Sticky', $sticky_array),
'rendertype' => array('Modify Render-type', $this->news_renderTypes),
'comments' => array('Modify Comments', $comments_array),
'__check_class' => array('category' => $news_manage)
),
array(
'userclass' => array('Assign Visibility...',$classes),
)
);
}
function batch_category($ids, $value)
{
if(!isset($this->news_categories[$value]))
{
$this->noPermissions();
}
$sql = e107::getDb();
$count = $sql->db_Update("news","news_category = ".$value." WHERE news_id IN (".implode(",",$ids).") ");
}
function batch_comments($ids, $value)
{
$sql = e107::getDb();
$value = intval($value);
if(2 === $value) //reverse it
{
$count = $sql->db_Update("news","news_allow_comments=1-news_allow_comments WHERE news_id IN (".implode(",",$ids).") ");
}
else //set it
{
$count = $sql->db_Update("news","news_allow_comments=".$value." WHERE news_id IN (".implode(",",$ids).") ");
}
}
function batch_rendertype($ids, $value)
{
$sql = e107::getDb();
$count = $sql->db_Update("news","news_render_type = ".$value." WHERE news_id IN (".implode(",",$ids).") ");
}
function batch_userclass($ids, $value)
{
$sql = e107::getDb();
$count = $sql->db_Update("news","news_class = ".$value." WHERE news_id IN (".implode(",",$ids).") ");
}
function batch_delete($ids, $value)
{
$sql = e107::getDb();
$count = $sql->db_Delete("news","news_id IN (".implode(",",$ids).") ");
}
function batch_subdelete($ids, $value)
{
$sql = e107::getDb();
$count = $sql->db_Delete("submitnews","submitnews_id IN (".implode(",",$ids).") ");
}
function batch_subcategory($ids, $value)
{
if(!isset($this->news_categories[$value]))
{
$this->noPermissions();
}
$sql = e107::getDb();
$count = $sql->db_Update("submitnews","submitnews_category = ".$value." WHERE submitnews_id IN (".implode(",",$ids).") ");
}
function batch_sticky($ids, $value)
{
$sql = e107::getDb();
$value = intval($value);
if(2 === $value) //reverse it
{
$count = $sql->db_Update("news","news_sticky=1-news_sticky WHERE news_id IN (".implode(",",$ids).") ");
}
else //set it
{
$count = $sql->db_Update("news","news_sticky=".$value." WHERE news_id IN (".implode(",",$ids).") ");
}
}
function process_batch($id_array)
{
list($type, $tmp, $value) = explode("_",$_POST['execute_batch']);
$method = "batch_".$type;
if (method_exists($this,$method) && isset($id_array) )
{
$this->$method($id_array,$value);
}
}
function _pre_create()
{
if($this->getSubAction() == "edit" && !$_POST['preview'])
{
if(!isset($_POST['submit_news']))
{
if(e107::getDb()->db_Select('news', '*', 'news_id='.intval($this->getId())))
{
$row = e107::getDb()->db_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'];
}
}
}
}
function show_create_item()
{
$pref = e107::getPref();
$this->_pre_create();
require_once(e_HANDLER."userclass_class.php");
// require_once(e_HANDLER."form_handler.php");
// $frm = new e_form(true); //enable inner tabindex counter
$frm = e107::getForm();
$text = '';
if (isset($_POST['preview']))
{
$text = $this->preview_item($this->getId());
}
$sub_action = $this->getSubAction();
$id = $this->getSubAction() != 'sn' && $this->getSubAction() != 'upload' ? $this->getId() : 0;
$e107 = e107::getInstance();
$tp = e107::getParser();
$sql = e107::getDb();
if ($sub_action == "sn" && !varset($_POST['preview']))
{
if ($sql->db_Select("submitnews", "*", "submitnews_id=".$this->getId(), TRUE))
{
//list($id, $submitnews_name, $submitnews_email, $_POST['news_title'], $submitnews_category, $_POST['news_body'], $submitnews_datestamp, $submitnews_ip, $submitnews_auth, $submitnews_file) = $sql->db_Fetch();
$row = $sql->db_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'] .= "
".NWSLAN_49." {$row['submitnews_name']}";
$_POST['news_body'] .= ($row['submitnews_file'])? "
": '';
}
else
{
$_POST['news_body'] .= "\n[[b]".NWSLAN_49." {$row['submitnews_name']}[/b]]";
$_POST['news_body'] .= ($row['submitnews_file'])?"\n\n[img]{e_NEWSIMAGE}{$row['submitnews_file']}[/img]": "";
}
$_POST['data'] = $tp->dataFilter($_POST['data']); // Filter any nasties
$_POST['news_title'] = $tp->dataFilter($_POST['news_title']);
}
}
/*
if ($sub_action == "upload" && !varset($_POST['preview']))
{
if ($sql->db_Select('upload', '*', "upload_id=".$this->getId())) {
$row = $sql->db_Fetch();
$post_author_id = substr($row['upload_poster'], 0, strpos($row['upload_poster'], "."));
$post_author_name = substr($row['upload_poster'], (strpos($row['upload_poster'], ".")+1));
$match = array();
//XXX DB UPLOADS STILL SUPPORTED?
$upload_file = "pub_" . (preg_match('#Binary\s(.*?)\/#', $row['upload_file'], $match) ? $match[1] : $row['upload_file']);
$_POST['news_title'] = LAN_UPLOAD.": ".$row['upload_name'];
$_POST['news_body'] = $row['upload_description']."\n[b]".NWSLAN_49." [link=".$e107->url->create('user/profile/view', 'id='.$post_author_id.'&name='.$post_author_name)."]".$post_author_name."[/link][/b]\n\n[file=request.php?".$upload_file."]{$row['upload_name']}[/file]\n";
}
}
*/
$text .= "
";
$emessage = eMessage::getInstance();
echo $emessage->render().$text;
// $e107->ns->tablerender($this->getSubAction() == 'edit' ? NWSLAN_29a : NWSLAN_29, $emessage->render().$text);
}
function preview_item($id)
{
$ix = new news;
$e107 = &e107::getInstance();
$_POST['news_title'] = $e107->tp->toDB($_POST['news_title']);
$_POST['news_summary'] = $e107->tp->toDB($_POST['news_summary']);
$_POST['news_id'] = $id;
if($_POST['news_start'])
{
$tmp = explode("/", $_POST['news_start']);
$_POST['news_start'] = mktime(0, 0, 0, $tmp[1], $tmp[0], $tmp[2]);
}
else
{
$_POST['news_start'] = 0;
}
if($_POST['news_end'])
{
$tmp = explode("/", $_POST['news_end']);
$_POST['news_end'] = mktime(0, 0, 0, $tmp[1], $tmp[0], $tmp[2]);
}
else
{
$_POST['news_end'] = 0;
}
$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();
}
$e107->sql->db_Select("news_category", "*", "category_id='".intval($_POST['cat_id'])."'");
list($_POST['category_id'], $_POST['category_name'], $_POST['category_icon']) = $e107->sql->db_Fetch();
list($_POST['user_id'],$_POST['user_name']) = explode(chr(35), $_POST['news_author']);
$_POST['news_author'] = $_POST['user_id'];
$_POST['comment_total'] = $id ? $e107->sql->db_Count("comments", "(*)", " WHERE comment_item_id={$id} AND comment_type='0'") : 0;
$_PR = $_POST;
$_PR['news_body'] = $e107->tp->post_toHTML($_PR['news_body'],FALSE);
$_PR['news_title'] = $e107->tp->post_toHTML($_PR['news_title'],FALSE,"emotes_off, no_make_clickable");
$_PR['news_summary'] = $e107->tp->post_toHTML($_PR['news_summary']);
$_PR['news_extended'] = $e107->tp->post_toHTML($_PR['news_extended']);
$_PR['news_file'] = $_POST['news_file'];
$_PR['news_thumbnail'] = basename($_POST['news_thumbnail']);
//$ix->render_newsitem($_PR);
return "
";
}
function ajax_exec_cat()
{
if(!getperms('0|7'))
{
exit;
}
//require_once (e_HANDLER.'js_helper.php');
$e107 = e107::getInstance();
$category = array();
if ($e107->sql->db_Select("news_category", "*", "category_id=".$this->getId()))
{
$category = $e107->sql->db_Fetch();
}
if(empty($category))
{
e_jshelper::sendAjaxError(404, 'Page not found!', 'Requested news category was not found in the DB.', true);
}
$jshelper = new e_jshelper();
$jshelper->addResponseAction('fill-form', $category);
//show cancel and update, hide create buttons; disable create button (just in case)
$jshelper->addResponseAction('element-invoke-by-id', array(
'show' => 'category-clear,update-category',
'disabled,1' => 'create-category',
'hide' => 'create-category',
'newsScrollToMe' => 'core-newspost-cat-create'
));
//Send the prefered response type
$jshelper->sendResponse('XML');
}
function ajax_exec_cat_list_refresh()
{
if(!getperms('0|7'))
{
exit;
}
echo $this->show_categoriy_list();
}
function ajax_exec_catorder()
{
if(!getperms('0|7'))
{
exit;
}
//interactive category order
$check = e107::getDb()->db_Update('news_category', 'category_order='.intval($this->getId()).' WHERE category_id='.intval($this->getSubAction()));
if(e107::getDb()->getLastErrorNumber())
{
echo 'mySQL Error #'.e107::getDb()->getLastErrorNumber().': '.e107::getDb()->getLastErrorText();
return;
}
if($check)
{
e107::getAdminLog()->log_event('NEWS_05', 'category_id='.intval($this->getSubAction()).', category_order='.intval($this->getId()), E_LOG_INFORMATIVE, '');
}
}
function ajax_exec_catmanager()
{
if(!getperms('0|7'))
{
exit;
}
//interactive category manage permissions
$check = e107::getDb()->db_Update('news_category', 'category_manager='.intval($this->getId()).' WHERE category_id='.intval($this->getSubAction()));
if(e107::getDb()->getLastErrorNumber())
{
echo 'mySQL Error #'.e107::getDb()->getLastErrorNumber().': '.e107::getDb()->getLastErrorText();
retrun;
}
if($check)
{
$class_name = e107::getUserClass()->uc_get_classname($this->getId());
e107::getAdminLog()->log_event('NEWS_05', 'category_id='.intval($this->getSubAction()).', category_manager='.intval($this->getId()).' ('.$class_name.')', E_LOG_INFORMATIVE, '');
}
}
function show_categories()
{
$frm = e107::getForm(false, true);
$category = array();
if ($this->getSubAction() == "edit" && !isset($_POST['update_category']))
{
if (e107::getDb()->db_Select("news_category", "*", "category_id=".$this->getId()))
{
$category = e107::getDb()->db_Fetch();
}
}
if($this->error && (isset($_POST['update_category']) || isset($_POST['create_category'])))
{
foreach ($_POST as $k=>$v)
{
if(strpos($k, 'category_') === 0)
{
$category[$k] = e107::getParser()->post_toForm($v);
continue;
}
if(strpos($k, 'news_rewrite_') === 0)
{
$category_rewrite[$k] = e107::getParser()->post_toForm($v);
continue;
}
}
}
//FIXME - lan
$text = "
".$this->show_categoriy_list()."
";
echo e107::getMessage()->render().$text;
// e107::getRender()->tablerender(NWSLAN_46a, e107::getMessage()->render().$text);
}
function show_categoriy_list()
{
$frm = e107::getForm();
//FIXME - lan
$text = "
";
return $text;
}
function _optrange($num, $zero = true)
{
$tmp = range(0, $num < 0 ? 0 : $num);
if(!$zero) unset($tmp[0]);
return $tmp;
}
function ajax_exec_pref_archnum()
{
$frm = e107::getForm();
echo $frm->selectbox('newsposts_archive', $this->_optrange(intval($this->getSubAction()) - 1), intval(e107::getPref('newsposts_archive')), 'class=tbox&tabindex='.intval($this->getId()));
}
/*
function ajax_exec_searchValue()
{
$frm = e107::getForm();
echo $frm->filterValue($_POST['filtertype'], $this->fields);
}
*/
function show_news_prefs()
{
$pref = e107::getPref();
$frm = e107::getForm();
$text = "
";
echo e107::getMessage()->render().$text;
// e107::getRender()->tablerender(NWSLAN_90, e107::getMessage()->render().$text);
}
function show_submitted_news()
{
//TODO - image upload path should be e_MEDIA and using generic upload handler on submitnews.php.
$e107 = e107::getInstance();
$frm = e107::getForm();
$tp = e107::getParser();
$sql = e107::getDb();
$newsCat = array();
$sql->db_Select('news_category');
while($row = $sql->db_Fetch())
{
$newsCat[$row['category_id']] = $tp->toHTML($row['category_name'],FALSE,'TITLE');
}
if ($sql->db_Select("submitnews", "*", "submitnews_id !='' ORDER BY submitnews_id DESC"))
{
$text .= "
";
}
else
{
$text .= "".NWSLAN_59."
";
}
e107::getRender()->tablerender(NWSLAN_47, e107::getMessage()->render().$text);
}
function showMaintenance()
{
require_once(e_HANDLER."form_handler.php");
$frm = e107::getForm();
$text = "
";
e107::getRender()->tablerender(LAN_NEWS_59, e107::getMessage()->render().$text);
}
function _observe_newsCommentsRecalc()
{
if(!getperms('0'))
{
$this->noPermissions();
}
$qry = "SELECT
COUNT(`comment_id`) AS c_count,
`news_id`, `news_comment_total`, `news_allow_comments`
FROM `#news` LEFT JOIN `#comments` ON `news_id`=`comment_item_id`
WHERE (`comment_type`='0') OR (`comment_type`='news')
GROUP BY `comment_item_id`";
$deleteCount = 0;
$updateCount = 0;
$canDelete = isset($_POST['newsdeletecomments']);
if ($result = e107::getDb()->db_Select_gen($qry))
{
while ($row = e107::getDb()->db_Fetch(MYSQL_ASSOC))
{
if ($canDelete && ($row['news_allow_comments'] != 0) && ($row['c_count'] > 0)) // N.B. sense of 'news_allow_comments' is 0 = allow!!!
{ // Delete comments
e107::getDb('sql2')->db_Delete('comments', 'comment_item_id='.$row['news_id']);
$deleteCount = $deleteCount + $row['c_count'];
$row['c_count'] = 0; // Forces update of news table if necessary
}
if ($row['news_comment_total'] != $row['c_count'])
{
e107::getDb('sql2')->db_Update('news', 'news_comment_total = '.$row['c_count'].' WHERE news_id='.$row['news_id']);
$updateCount++;
}
}
$this->show_message(str_replace(array('--UPDATE--', '--DELETED--'), array($updateCount, $deleteCount), LAN_NEWS_58), E_MESSAGE_SUCCESS);
}
else
{
$this->show_message(LAN_NEWS_62, E_MESSAGE_WARNING);
}
}
function show_message($message, $type = E_MESSAGE_INFO, $session = false)
{
// ##### Display comfort ---------
e107::getMessage()->add($message, $type, $session);
}
function noPermissions($qry = '')
{
$url = e_SELF.($qry ? '?'.$qry : '');
if($qry !== e_QUERY)
{
$this->show_message('Insufficient permissions!', E_MESSAGE_ERROR, true);
session_write_close();
header('Location: '.$url);
}
exit;
}
/*
function show_options()
{
$e107 = e107::getInstance();
$var['main']['text'] = NWSLAN_44;
$var['main']['link'] = e_SELF;
$var['main']['perm'] = "H";
$var['create']['text'] = NWSLAN_45;
$var['create']['link'] = e_SELF."?action=create";
$var['create']['perm'] = "H";
$var['cat']['text'] = NWSLAN_46;
$var['cat']['link'] = e_SELF."?action=cat";
$var['cat']['perm'] = "7";
$var['pref']['text'] = NWSLAN_90;
$var['pref']['link'] = e_SELF."?action=pref";
$var['pref']['perm'] = "0";
//TODO remove commented code before release.
// $c = $e107->sql->db_Count('submitnews');
// if ($c) {
$var['sn']['text'] = NWSLAN_47." ({$c})";
$var['sn']['link'] = e_SELF."?action=sn";
$var['sn']['perm'] = "N";
// }
if (getperms('0'))
{
$var['maint']['text'] = LAN_NEWS_55;
$var['maint']['link'] = e_SELF."?action=maint";
$var['maint']['perm'] = "N";
}
e_admin_menu(NWSLAN_48, $this->getAction(), $var);
}
*/
}
function newspost_adminmenu()
{
// e107::getRegistry('_newspost_admin')->show_options();
}