2006-12-02 04:36:16 +00:00
< ? php
/*
2008-12-02 16:50:16 +00:00
* e107 website system
*
2013-03-24 13:07:15 +01:00
* Copyright ( C ) 2008 - 2013 e107 Inc ( e107 . org )
2008-12-02 16:50:16 +00:00
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
* News Administration
*
2006-12-02 04:36:16 +00:00
*/
2010-01-11 21:18:13 +00:00
require_once ( '../class2.php' );
2015-06-05 22:00:25 -07:00
if ( ! getperms ( 'H|N|H0|H1|H2|H3|H4|H5' ))
2008-12-07 13:08:54 +00:00
{
2016-01-13 19:17:37 -08:00
e107 :: redirect ( 'admin' );
2006-12-02 04:36:16 +00:00
exit ;
}
2009-01-13 17:09:30 +00:00
2012-12-17 16:57:24 +02:00
e107 :: coreLan ( 'newspost' , true );
2009-01-13 17:09:30 +00:00
2011-12-10 00:00:15 +00:00
2016-08-24 15:51:26 -07:00
e107 :: css ( 'inline' , "
. submitnews . modal - body { height : 500 px ; overflow - y : scroll ; }
" );
2016-01-13 01:31:12 -08:00
2012-05-17 09:19:44 +00:00
class news_admin extends e_admin_dispatcher
{
protected $modes = array (
'main' => array (
'controller' => 'news_admin_ui' ,
'path' => null ,
'ui' => 'news_form_ui' ,
2015-06-05 22:00:25 -07:00
'uipath' => null ,
'perm' => null
2012-05-17 09:19:44 +00:00
),
'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' ,
2015-06-05 22:00:25 -07:00
'uipath' => null ,
'perm' => null
2012-05-17 09:19:44 +00:00
)
);
2015-06-05 22:00:25 -07:00
protected $access = array (); // as below, but uses userclasses instead of admin perms eg. e_UC_* or numeric userclass value.
//Route access. (equivalent of getperms() for each mode/action )
protected $perm = array (
'main/list' => 'H|H0|H1|H2' ,
'main/create' => 'H|H0' ,
'main/edit' => 'H|H1' , // edit button and inline editing in list mode.
'main/delete' => 'H|H2' , // delete button in list mode.
'cat/list' => 'H' ,
'cat/create' => 'H|H3|H4|H5' ,
'cat/edit' => 'H|H4' , // edit button and inline editing in list mode.
'cat/delete' => 'H|H5' , // delete button in list mode.
'main/settings' => '0' ,
'sub/list' => 'N'
);
2012-05-17 09:19:44 +00:00
protected $adminMenu = array (
2017-02-18 15:31:41 -08:00
'main/list' => array ( 'caption' => LAN_LIST ),
'main/create' => array ( 'caption' => NWSLAN_45 ), // Create/Edit News Item
2012-05-17 09:19:44 +00:00
// 'cat/list' => array('caption'=> NWSLAN_46, 'perm' => '7'), // Category List
2017-10-08 09:00:34 -07:00
'other' => array ( 'divider' => true ),
2017-02-18 15:31:41 -08:00
'cat/list' => array ( 'caption' => LAN_CATEGORIES ), // Create Category.
'cat/create' => array ( 'caption' => LAN_NEWS_63 ), // Category List
2017-10-08 09:00:34 -07:00
'other2' => array ( 'divider' => true ),
2017-02-18 15:31:41 -08:00
'main/settings' => array ( 'caption' => LAN_PREFS ), // Preferences
2015-05-02 15:57:07 +02:00
// 'main/submitted' => array('caption'=> LAN_NEWS_64, 'perm' => 'N'), // Submitted News
2017-02-18 15:31:41 -08:00
'sub/list' => array ( 'caption' => NWSLAN_47 ), // Submitted News
2012-05-17 09:19:44 +00:00
// 'main/maint' => array('caption'=> LAN_NEWS_55, 'perm' => '0') // Maintenance
);
2016-11-01 16:42:47 -07:00
protected $adminMenuIcon = 'e-news-24' ;
2015-06-05 22:00:25 -07:00
2012-05-17 09:19:44 +00:00
protected $adminMenuAliases = array (
'main/edit' => 'main/list' ,
'cat/edit' => 'cat/list'
);
2016-10-16 10:20:07 +02:00
protected $menuTitle = ADLAN_0 ;
2012-05-17 09:19:44 +00:00
2016-01-13 01:31:12 -08:00
function init ()
{
2016-03-06 17:42:47 -08:00
if ( ! empty ( $_GET [ 'sub' ]) && $_GET [ 'action' ] == 'create' )
{
$this -> adminMenu [ 'sub/list' ][ 'selected' ] = true ;
$this -> getResponse () -> setTitle ( NWSLAN_47 );
}
2012-05-17 09:19:44 +00:00
2016-01-13 01:31:12 -08:00
}
2017-12-27 20:58:59 -08:00
2012-05-17 09:19:44 +00:00
}
class news_cat_ui extends e_admin_ui
{
2013-02-22 21:34:06 -08:00
protected $pluginTitle = ADLAN_0 ; // "News"
2012-05-17 09:19:44 +00:00
protected $pluginName = 'core' ;
2015-02-09 02:21:41 -08:00
protected $eventName = 'news-category' ;
2012-05-17 09:19:44 +00:00
protected $table = " news_category " ;
protected $pid = " category_id " ;
protected $perPage = 0 ; //no limit
protected $batchDelete = false ;
2017-01-27 18:02:57 -08:00
protected $batchExport = true ;
2013-02-19 18:36:58 +02:00
protected $sortField = 'category_order' ;
protected $listOrder = " category_order ASC " ;
2017-09-28 09:35:56 -07:00
protected $tabs = array ( LAN_GENERAL , LAN_ADVANCED );
2012-05-17 09:19:44 +00:00
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 ),
2016-04-15 10:46:58 -07:00
'category_icon' => array ( 'title' => LAN_ICON , 'type' => 'icon' , 'data' => 'str' , 'width' => '100px' , 'thclass' => 'center' , 'class' => 'center' , 'readParms' => array ( 'legacy' => '{e_IMAGE}icons/' ), 'writeParms' => 'glyphs=1' , 'readonly' => FALSE , 'batch' => FALSE , 'filter' => FALSE ), // thumb=60&thumb_urlraw=0&thumb_aw=60
2017-02-06 11:18:36 -08:00
'category_name' => array ( 'title' => LAN_TITLE , 'type' => 'text' , 'data' => 'str' , 'inline' => true , 'width' => 'auto' , 'thclass' => 'left' , 'readonly' => FALSE , 'validate' => true , 'writeParms' => array ( 'size' => 'xxlarge' )),
2012-05-17 09:19:44 +00:00
2017-02-06 11:18:36 -08:00
'category_meta_description' => array ( 'title' => LAN_DESCRIPTION , 'type' => 'textarea' , 'data' => 'str' , 'inline' => true , 'width' => 'auto' , 'thclass' => 'left' , 'readParms' => 'expand=...&truncate=150&bb=1' , 'readonly' => FALSE , 'writeParms' => array ( 'size' => 'xxlarge' )),
'category_meta_keywords' => array ( 'title' => LAN_KEYWORDS , 'type' => 'tags' , 'data' => 'str' , 'inline' => true , 'width' => 'auto' , 'thclass' => 'left' , 'readonly' => FALSE ),
'category_sef' => array ( 'title' => LAN_SEFURL , 'type' => 'text' , 'data' => 'str' , 'inline' => true , 'width' => 'auto' , 'readonly' => FALSE , 'writeParms' => array ( 'size' => 'xxlarge' , 'sef' => 'category_name' )), // Display name
2017-09-28 09:35:56 -07:00
'category_manager' => array ( 'title' => LAN_MANAGER , 'type' => 'userclass' , 'tab' => 1 , 'inline' => true , 'width' => 'auto' , 'data' => 'int' , 'batch' => TRUE , 'filter' => TRUE ),
2019-06-11 09:17:36 -07:00
'category_template' => array ( 'title' => LAN_TEMPLATE , 'type' => 'layouts' , 'tab' => 1 , 'width' => 'auto' , 'thclass' => 'left' , 'class' => 'left' , 'writeParms' => array (), 'help' => 'Template to use as the default view' ),
2017-10-12 11:03:03 -07:00
'category_order' => array ( 'title' => LAN_ORDER , 'type' => 'text' , 'tab' => 1 , 'width' => 'auto' , 'thclass' => 'right' , 'class' => 'right' ),
'options' => array ( 'title' => LAN_OPTIONS , 'type' => null , 'batch' => true , 'filter' => true , 'width' => '10%' , 'forced' => TRUE , 'thclass' => 'center last' , 'class' => 'center' , 'sort' => true )
2012-05-17 09:19:44 +00:00
);
2016-03-08 13:53:58 -08:00
protected $fieldpref = array ( 'checkboxes' , 'category_icon' , 'category_id' , 'category_name' , 'category_description' , 'category_sef' , 'category_manager' , 'category_order' , 'options' );
2012-05-17 09:19:44 +00:00
2015-04-07 19:49:11 -07:00
// protected $newspost;
2012-05-17 09:19:44 +00:00
function init ()
{
2019-06-11 10:18:11 -07:00
$this -> fields [ 'category_template' ][ 'writeParms' ] = array ( 'plugin' => 'news' , 'id' => 'news' , 'merge' => false , 'default' => '(' . LAN_OPTIONAL . ')' );
2015-04-07 19:49:11 -07:00
// $this->newspost = new admin_newspost;
2012-05-17 09:19:44 +00:00
}
2019-06-11 09:17:36 -07:00
2012-05-17 09:19:44 +00:00
// function createPage()
// {
// $this->newspost->show_categories();
// }
2016-06-09 16:43:36 -07:00
public function beforeCreate ( $new_data , $old_data )
2012-05-17 09:19:44 +00:00
{
2013-02-19 18:36:58 +02:00
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' ]);
}
2015-04-07 19:49:11 -07:00
2013-02-19 18:36:58 +02:00
$sef = e107 :: getParser () -> toDB ( $new_data [ 'category_sef' ]);
if ( e107 :: getDb () -> count ( 'news_category' , '(*)' , " category_sef=' { $sef } ' " ))
{
2015-05-02 15:57:07 +02:00
e107 :: getMessage () -> addError ( LAN_NEWS_65 );
2013-02-19 18:36:58 +02:00
return false ;
}
if ( empty ( $new_data [ 'category_order' ]))
{
$c = e107 :: getDb () -> count ( 'news_category' );
$new_data [ 'category_order' ] = $c ? $c : 0 ;
}
return $new_data ;
2012-05-17 09:19:44 +00:00
}
public function beforeUpdate ( $new_data , $old_data , $id )
{
2016-10-17 10:15:24 -07:00
if ( isset ( $new_data [ 'category_sef' ]) && empty ( $new_data [ 'category_sef' ]))
2013-02-19 18:36:58 +02:00
{
$new_data [ 'category_sef' ] = eHelper :: title2sef ( $new_data [ 'category_name' ]);
}
2016-10-17 10:15:24 -07:00
2013-02-19 18:36:58 +02:00
$sef = e107 :: getParser () -> toDB ( $new_data [ 'category_sef' ]);
2017-09-28 09:35:56 -07:00
/* $message = " Error: sef: " . $sef . " id: " . $id . " \n " ;
$message .= print_r ( $new_data , true );
file_put_contents ( e_LOG . 'uiAjaxResponseInline.log' , $message . " \n \n " , FILE_APPEND ); */
if ( e107 :: getDb () -> count ( 'news_category' , '(*)' , " category_sef=' { $sef } ' AND category_id != " . intval ( $id )))
2013-02-19 18:36:58 +02:00
{
2015-05-08 10:56:33 +02:00
e107 :: getMessage () -> addError ( LAN_NEWS_65 );
2013-02-19 18:36:58 +02:00
return false ;
}
2017-09-28 09:35:56 -07:00
2013-02-19 18:36:58 +02:00
return $new_data ;
2012-05-17 09:19:44 +00:00
}
}
class news_cat_form_ui extends e_admin_form_ui
{
}
2013-02-27 00:44:58 -08:00
2012-05-17 09:19:44 +00:00
// Submitted News Area.
class news_sub_ui extends e_admin_ui
{
2013-02-22 21:34:06 -08:00
protected $pluginTitle = ADLAN_0 ; // "News"
2012-05-17 09:19:44 +00:00
protected $pluginName = 'core' ;
protected $table = " submitnews " ;
protected $pid = " submitnews_id " ;
2012-12-03 13:57:02 -08:00
protected $perPage = 10 ; //no limit
2012-05-17 09:19:44 +00:00
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 ),
2020-02-20 07:30:01 -08:00
'submitnews_datestamp' => array ( 'title' => LAN_NEWS_32 , 'type' => 'datestamp' , 'width' => 'auto' , 'thclass' => '' , 'class' => null , 'nosort' => false ),
2015-04-15 12:45:05 -07:00
'submitnews_title' => array ( 'title' => LAN_TITLE , 'type' => 'method' , 'width' => '35%' , 'thclass' => 'left' , 'readonly' => TRUE ),
2012-05-17 09:19:44 +00:00
'submitnews_category' => array ( 'title' => LAN_CATEGORY , 'type' => 'dropdown' , 'width' => 'auto' , 'thclass' => 'left' , 'readonly' => FALSE ),
2016-08-15 10:06:44 -07:00
'submitnews_description' => array ( 'title' => LAN_DESCRIPTION , 'type' => 'textarea' , 'width' => 'auto' , 'thclass' => 'left' , 'readParms' => 'expand=...&truncate=150&bb=1' , 'readonly' => TRUE ),
2012-05-17 09:19:44 +00:00
'submitnews_name' => array ( 'title' => LAN_AUTHOR , 'type' => 'text' , 'width' => 'auto' , 'thclass' => 'left' , 'readonly' => TRUE ),
2015-05-02 15:57:07 +02:00
'submitnews_ip' => array ( 'title' => LAN_IP , 'type' => 'ip' , 'width' => 'auto' , 'thclass' => 'left' , 'readonly' => TRUE ),
2015-04-15 15:34:58 -07:00
'submitnews_auth' => array ( 'title' => " " , 'type' => 'text' , 'width' => 'auto' , 'thclass' => 'left' , 'class' => 'left' , 'readParms' => " link=1 " ),
2015-02-07 12:56:16 -08:00
'options' => array ( 'title' => LAN_OPTIONS , 'type' => " method " , 'width' => '10%' , 'forced' => TRUE , 'thclass' => 'center last' , 'class' => 'right' )
2012-05-17 09:19:44 +00:00
);
2015-04-15 12:45:05 -07:00
protected $fieldpref = array ( 'checkboxes' , 'submitnews_id' , 'submitnews_datestamp' , 'submitnews_title' , 'submitnews_category' , 'submitnews_name' , 'options' );
2012-05-17 09:19:44 +00:00
protected $newspost ;
protected $cats ;
function init ()
{
$sql = e107 :: getDb ();
2015-04-07 19:49:11 -07:00
$sql -> gen ( " SELECT category_id,category_name FROM #news_category " );
2013-03-24 13:07:15 +01:00
while ( $row = $sql -> fetch ())
2012-05-17 09:19:44 +00:00
{
$cat = $row [ 'category_id' ];
$this -> cats [ $cat ] = $row [ 'category_name' ];
}
asort ( $this -> cats );
$this -> fields [ 'submitnews_category' ][ 'writeParms' ] = $this -> cats ;
2015-04-07 19:49:11 -07:00
// $this->newspost = new admin_newspost;
2012-05-17 09:19:44 +00:00
}
// function createPage()
// {
// $this->newspost->show_categories();
// }
2016-06-09 16:43:36 -07:00
public function beforeCreate ( $new_data , $old_data )
2012-05-17 09:19:44 +00:00
{
}
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' );
2013-02-25 11:29:38 -08:00
// $text .= "<a href='#submitted_".$submitnews_id."' class='e-modal' >";
2012-05-17 09:19:44 +00:00
2015-04-07 19:49:11 -07:00
$text = " <a data-toggle='modal' href='#submitted_ " . $submitnews_id . " ' data-cache='false' data-target='#submitted_ " . $submitnews_id . " ' class='e-tip' title=' " . LAN_PREVIEW . " '> " ;
2013-02-25 11:29:38 -08:00
$text .= $tp -> toHTML ( $submitnews_title , FALSE , 'emotes_off, no_make_clickable' );
2012-05-17 09:19:44 +00:00
$text .= '</a>' ;
2013-02-25 11:29:38 -08:00
$text .= '
2016-03-06 17:42:47 -08:00
< div id = " submitted_'. $submitnews_id .' " class = " modal fade " tabindex = " -1 " role = " dialog " aria - hidden = " true " >
2016-03-16 19:54:10 -07:00
< div class = " modal-dialog modal-lg " >
< div class = " modal-content " >
2013-02-25 11:29:38 -08:00
< div class = " modal-header " >
< button type = " button " class = " close " data - dismiss = " modal " aria - hidden = " true " >& times ; </ button >
2019-02-26 12:22:36 -08:00
< h4 > '.$tp->toHTML($submitnews_title,false,' TITLE ').' </ h4 >
2013-02-25 11:29:38 -08:00
</ div >
2016-08-24 15:51:26 -07:00
< div class = " submitnews modal-body " >
2013-02-25 11:29:38 -08:00
< p > ' ;
$text .= $tp -> toHTML ( $submitnews_item , TRUE );
2012-05-17 09:19:44 +00:00
if ( $submitnews_file )
{
$tmp = explode ( ',' , $submitnews_file );
2013-02-25 11:29:38 -08:00
2012-05-17 09:19:44 +00:00
$text .= " <br /> " ;
2013-02-25 11:29:38 -08:00
2012-05-17 09:19:44 +00:00
foreach ( $tmp as $imgfile )
2016-08-24 15:51:26 -07:00
{
if ( strpos ( " { e_UPLOAD} " , $imgfile ) === false )
{
$imgfile = e_UPLOAD . $imgfile ;
}
$url = $tp -> thumbUrl ( $imgfile , array ( 'aw' => 400 ), true );
2013-02-25 11:29:38 -08:00
$text .= " <br /><img src=' " . $url . " ' alt=' " . $imgfile . " ' /> " ;
2012-05-17 09:19:44 +00:00
}
}
2013-02-25 11:29:38 -08:00
$text .= ' </ p >
</ div >
2016-03-16 19:54:10 -07:00
< div class = " modal-footer " >
< a href = " # " data - dismiss = " modal " class = " btn btn-primary " > '.LAN_NEWS_67.' </ a >
</ div >
2016-03-06 17:42:47 -08:00
</ div >
</ div ></ div > ' ;
2013-02-25 11:29:38 -08:00
return $text ;
2012-05-17 09:19:44 +00:00
}
// Override the default Options field.
function options ( $parms , $value , $id , $attributes )
{
2013-02-25 11:29:38 -08:00
2012-05-17 09:19:44 +00:00
if ( $attributes [ 'mode' ] == 'read' )
{
2013-02-25 11:29:38 -08:00
$text = " <div class='btn-group'> " ;
2012-05-17 09:19:44 +00:00
$approved = $this -> getController () -> getListModel () -> get ( 'submitnews_auth' ); // approved;
2016-03-06 17:42:47 -08:00
$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' >";
2018-01-10 15:06:40 -08:00
$text = " <a class='btn btn-default btn-secondary btn-large' data-toggle='modal' href='#submitted_ " . $submitnews_id . " ' data-cache='false' data-target='#submitted_ " . $submitnews_id . " ' title=' " . LAN_PREVIEW . " '> " . ADMIN_VIEW_ICON . " </a> " ;
2016-03-06 17:42:47 -08:00
2012-05-17 09:19:44 +00:00
if ( $approved == 0 )
{
2013-02-25 11:29:38 -08:00
//$text = $this->submit_image('submitnews['.$id.']', 1, 'execute', NWSLAN_58);
2018-01-10 15:06:40 -08:00
$text .= " <a class='btn btn-default btn-secondary btn-large' title= \" " . LAN_NEWS_96 . " \" href=' " . e_SELF . " ?mode=main&action=create&sub= { $id } '> " . ADMIN_EXECUTE_ICON . " </a> " ;
2012-05-17 09:19:44 +00:00
// NWSLAN_103;
}
2020-12-18 19:55:12 -08:00
2012-05-17 09:19:44 +00:00
2018-01-10 15:06:40 -08:00
$text .= $this -> submit_image ( 'etrigger_delete[' . $id . ']' , $id , 'delete' , LAN_DELETE . ' [ ID: ' . $id . ' ]' , array ( 'class' => 'btn btn-default btn-secondary btn-large action delete' ));
2013-02-25 11:29:38 -08:00
$text .= " </div> " ;
2012-05-17 09:19:44 +00:00
return $text ;
}
}
}
// Main News Area.
class news_admin_ui extends e_admin_ui
{
2012-05-22 04:38:28 +00:00
protected $pluginTitle = ADLAN_0 ; // "News"
protected $pluginName = 'core' ;
2015-04-07 19:49:11 -07:00
protected $eventName = 'news' ;
2012-05-22 04:38:28 +00:00
protected $table = " news " ;
protected $pid = " news_id " ;
2012-12-03 13:57:02 -08:00
protected $perPage = 10 ; //no limit
2012-05-22 04:38:28 +00:00
protected $batchDelete = true ;
2017-01-27 18:02:57 -08:00
protected $batchExport = true ;
2012-05-22 04:38:28 +00:00
protected $batchCopy = true ;
2013-02-26 16:08:08 -08:00
protected $batchLink = true ;
2020-05-21 12:00:54 -07:00
protected $listQry = " SELECT n.*, nc.category_name, nc.category_sef, u.user_id,u.user_name 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 " ; // without any Order or Limit.
2015-04-15 15:34:58 -07:00
2012-05-22 04:38:28 +00:00
protected $listOrder = " news_id desc " ;
2015-04-07 19:49:11 -07:00
protected $tabs = array ( LAN_NEWS_52 , 'SEO' , LAN_NEWS_53 );
2013-02-27 19:36:53 +02:00
protected $url = array (
2020-05-21 12:00:54 -07:00
'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 )
); // 'link' only needed if profile not provided.
2013-02-26 16:08:08 -08:00
2015-04-15 15:34:58 -07:00
2012-05-17 09:19:44 +00:00
2012-05-22 04:38:28 +00:00
protected $fields = array (
2015-04-07 19:49:11 -07:00
'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' ),
2017-02-06 11:18:36 -08:00
'news_thumbnail' => array ( 'title' => NWSLAN_67 , 'type' => 'method' , 'data' => 'str' , 'width' => '110px' , 'thclass' => 'center' , 'class' => " center " , 'nosort' => false , 'readParms' => 'thumb=60&thumb_urlraw=0&thumb_aw=60' , 'readonly' => false ),
2019-06-04 12:59:39 -07:00
'news_title' => array ( 'title' => LAN_TITLE , 'type' => 'text' , 'data' => 'safestr' , 'filter' => true , 'tab' => 0 , 'writeParms' => array ( 'required' => 1 , 'size' => 'block-level' ), 'inline' => true , 'width' => 'auto' , 'thclass' => '' , 'class' => null , 'nosort' => false ),
'news_summary' => array ( 'title' => LAN_SUMMARY , 'type' => 'text' , 'data' => 'safestr' , 'filter' => true , 'tab' => 0 , 'inline' => true , 'writeParms' => 'size=block-level' , 'width' => 'auto' , 'thclass' => 'left' , 'class' => 'left' , 'nosort' => false ),
2017-02-19 10:23:52 -08:00
'news_body' => array ( 'title' => " " , 'type' => 'method' , 'data' => 'str' , 'tab' => 0 , 'nolist' => true , 'writeParms' => 'nolabel=1' , 'width' => 'auto' , 'thclass' => '' , 'class' => null , 'nosort' => false ),
'news_extended' => array ( 'title' => " " , 'type' => null , 'data' => 'str' , 'tab' => 0 , 'nolist' => true , 'writeParms' => 'nolabel=1' , 'width' => 'auto' , 'thclass' => '' , 'class' => null , 'nosort' => false ),
2017-02-06 11:18:36 -08:00
2019-06-04 12:59:39 -07:00
'news_meta_keywords' => array ( 'title' => LAN_KEYWORDS , 'type' => 'tags' , 'data' => 'safestr' , 'filter' => true , 'tab' => 1 , 'inline' => true , 'width' => 'auto' , 'thclass' => '' , 'class' => null , 'nosort' => false ),
'news_meta_description' => array ( 'title' => LAN_DESCRIPTION , 'type' => 'textarea' , 'data' => 'safestr' , 'filter' => true , 'tab' => 1 , 'width' => 'auto' , 'thclass' => '' , 'class' => null , 'nosort' => false , 'writeParms' => array ( 'size' => 'xxlarge' )),
2019-12-02 13:32:21 -08:00
'news_meta_robots' => array ( 'title' => LAN_ROBOTS , 'type' => 'dropdown' , 'data' => 'safestr' , 'tab' => 1 , 'inline' => true , 'readParms' => array ( 'type' => 'checkboxes' ), 'writeParms' => array ( 'multiple' => 1 ), 'width' => 'auto' , 'thclass' => 'left' , 'class' => 'left' , 'nosort' => false , 'batch' => true , 'filter' => true ),
2017-04-02 11:32:32 -07:00
'news_sef' => array ( 'title' => LAN_SEFURL , 'type' => 'text' , 'batch' => 1 , 'data' => 'str' , 'tab' => 1 , 'inline' => true , 'width' => 'auto' , 'thclass' => '' , 'class' => null , 'nosort' => false , 'writeParms' => array ( 'size' => 'xxlarge' , 'show' => 1 , 'sef' => 'news_title' )),
2020-12-05 12:39:50 -08:00
// 'news_ping' => array('title' => LAN_PING, 'type' => 'checkbox', 'tab'=>1, 'data'=>false, 'writeParms'=>'value=0', 'inline'=>true, 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false),
2015-04-07 19:49:11 -07:00
2017-09-23 14:08:47 -07:00
'news_author' => array ( 'title' => LAN_AUTHOR , 'type' => 'method' , 'tab' => 2 , 'readParms' => 'idField=user_id&nameField=user_name' , 'width' => 'auto' , 'thclass' => '' , 'class' => null , 'nosort' => false ),
2020-02-20 07:30:01 -08:00
'news_datestamp' => array ( 'title' => LAN_NEWS_32 , 'type' => 'datestamp' , 'data' => 'int' , 'tab' => 2 , 'writeParms' => 'type=datetime' , 'width' => 'auto' , 'thclass' => '' , 'class' => null , 'nosort' => false , 'filter' => true ),
2017-02-19 10:23:52 -08:00
'news_category' => array ( 'title' => NWSLAN_6 , 'type' => 'dropdown' , 'data' => 'int' , 'tab' => 0 , 'inline' => true , 'width' => 'auto' , 'thclass' => '' , 'class' => null , 'nosort' => false , 'batch' => true , 'filter' => true ),
2020-02-20 07:30:01 -08:00
'news_start' => array ( 'title' => LAN_START , 'type' => 'datestamp' , 'data' => 'int' , 'tab' => 2 , 'writeParms' => 'type=datetime' , 'width' => 'auto' , 'thclass' => '' , 'class' => null , 'nosort' => false ),
'news_end' => array ( 'title' => LAN_END , 'type' => 'datestamp' , 'data' => 'int' , 'tab' => 2 , 'writeParms' => 'type=datetime' , 'width' => 'auto' , 'thclass' => '' , 'class' => null , 'nosort' => false ),
2016-01-31 11:41:29 -08:00
'news_class' => array ( 'title' => LAN_VISIBILITY , 'type' => 'userclass' , 'tab' => 2 , 'inline' => true , 'width' => 'auto' , 'thclass' => '' , 'class' => null , 'batch' => true , 'filter' => true ),
2017-09-23 14:08:47 -07:00
2019-03-19 15:12:17 -07:00
'news_template' => array ( 'title' => LAN_TEMPLATE , 'type' => 'method' , 'data' => 'safestr' , 'tab' => 2 , 'inline' => true , 'writeParms' => array ( 'plugin' => 'news' , 'id' => 'news_view' , 'area' => 'front' , 'merge' => false ), 'width' => 'auto' , 'thclass' => 'left' , 'class' => 'left' , 'nosort' => false , 'batch' => true , 'filter' => true ),
2017-09-23 14:08:47 -07:00
2019-03-19 15:12:17 -07:00
'news_render_type' => array ( 'title' => LAN_LOCATION , 'type' => 'dropdown' , 'data' => 'safestr' , 'tab' => 2 , 'inline' => true , 'readParms' => array ( 'type' => 'checkboxes' ), 'width' => 'auto' , 'thclass' => 'left' , 'class' => 'left' , 'nosort' => false , 'batch' => true , 'filter' => true ),
2017-09-23 14:08:47 -07:00
2020-04-09 17:22:10 -07:00
'news_sticky' => array ( 'title' => LAN_NEWS_28 , 'type' => 'boolean' , 'data' => 'int' , 'tab' => 2 , 'width' => 'auto' , 'thclass' => 'center' , 'inline' => true , 'class' => 'center' , 'nosort' => false , 'batch' => true , 'filter' => true ),
2017-02-19 10:23:52 -08:00
'news_allow_comments' => array ( 'title' => LAN_COMMENTS , 'type' => 'boolean' , 'data' => 'int' , 'tab' => 2 , 'writeParms' => 'inverse=1' , 'width' => 'auto' , 'thclass' => 'center' , 'class' => 'center' , 'nosort' => false , 'batch' => true , 'filter' => true , 'readParms' => 'reverse=1' ),
2017-02-06 11:18:36 -08:00
'news_comment_total' => array ( 'title' => LAN_NEWS_60 , 'type' => 'number' , 'data' => 'int' , 'tab' => 2 , 'noedit' => true , 'width' => '10%' , 'thclass' => '' , 'class' => null , 'nosort' => false ),
2015-05-13 01:22:05 -07:00
// admin_news_notify
2017-02-13 07:54:47 +01:00
'news_email_notify' => array ( 'title' => LAN_NEWS_103 , 'type' => 'checkbox' , 'tab' => 2 , 'data' => false , 'writeParms' => array ( 'show' => 1 , 'tdClassRight' => 'form-inline' ), 'help' => LAN_NEWS_109 ),
2015-05-13 01:22:05 -07:00
'submitted_id' => array ( 'title' => LAN_NEWS_68 , 'type' => 'hidden' , 'tab' => 2 , 'data' => false , 'writeParms' => 'show=0' ),
2015-04-07 19:49:11 -07:00
'options' => array ( 'title' => LAN_OPTIONS , 'type' => null , 'width' => '10%' , 'thclass' => 'center last' , 'class' => 'center' , 'nosort' => true , 'forced' => TRUE )
2012-05-17 09:19:44 +00:00
2012-05-22 04:38:28 +00:00
);
2015-08-31 17:38:31 -07:00
protected $fieldpref = array ( 'checkboxes' , 'news_id' , 'news_thumbnail' , 'news_title' , 'news_datestamp' , 'news_category' , 'news_class' , 'options' );
2015-04-07 19:49:11 -07:00
/* //TODO
protected $prefs = array (
'news_category' => array ( 'title' => NWSLAN_127 , 'type' => 'dropdown' , 'help' => " Determines how the default news page should appear. " ),
);
*/
2012-05-17 09:19:44 +00:00
protected $cats = array ();
protected $newspost ;
2016-08-17 16:27:00 -07:00
protected $addons = array ();
2012-11-01 02:21:58 +00:00
2014-01-30 10:14:13 -08:00
protected $news_renderTypes = array ( // TODO Placement location and template should be separate.
2012-11-01 02:21:58 +00:00
2015-05-02 15:57:07 +02:00
'0' => LAN_NEWS_69 ,
'1' => LAN_NEWS_70 ,
'4' => LAN_NEWS_71 ,
'2' => LAN_NEWS_72 ,
'3' => LAN_NEWS_73 ,
'5' => LAN_NEWS_74 ,
2016-10-16 10:20:07 +02:00
'6' => LAN_NEWS_97 ,
2015-05-02 15:57:07 +02:00
//'5' => LAN_NEWS_75
2012-11-01 02:21:58 +00:00
);
2015-04-07 19:49:11 -07:00
2016-06-09 16:43:36 -07:00
public function beforeCreate ( $new_data , $old_data )
2015-04-07 19:49:11 -07:00
{
2016-03-06 17:42:47 -08:00
if ( ! empty ( $new_data [ 'news_thumbnail' ]) && ! empty ( $_GET [ 'sub' ])) // From SubmitNews.
{
$new_data [ 'news_thumbnail' ] = $this -> processSubNewsImages ( $new_data [ 'news_thumbnail' ]);
}
2015-04-07 19:49:11 -07:00
$new_data [ 'news_thumbnail' ] = $this -> processThumbs ( $new_data [ 'news_thumbnail' ]);
if ( empty ( $new_data [ 'news_datestamp' ]))
{
$new_data [ 'news_datestamp' ] = time ();
}
2016-03-06 17:42:47 -08:00
2015-04-07 19:49:11 -07:00
$new_data [ 'news_sef' ] = empty ( $new_data [ 'news_sef' ]) ? eHelper :: title2sef ( $new_data [ 'news_title' ]) : eHelper :: secureSef ( $new_data [ 'news_sef' ]);
2017-01-16 12:09:31 -08:00
$this -> checkSEFSimilarity ( $new_data );
2015-04-07 19:49:11 -07:00
$tmp = explode ( chr ( 35 ), $new_data [ 'news_author' ]);
$new_data [ 'news_author' ] = intval ( $tmp [ 0 ]);
2015-07-27 12:12:11 -07:00
if ( E107_DBG_SQLQUERIES )
{
e107 :: getMessage () -> addInfo ( " <h3>Raw _POST data</h3> " . print_a ( $_POST , true ));
}
2015-04-07 19:49:11 -07:00
return $new_data ;
}
2016-03-06 17:42:47 -08:00
private function processSubNewsImages ( $row )
{
$new = array ();
foreach ( $row as $k => $v )
{
2016-08-24 15:51:26 -07:00
if ( empty ( $v ))
2016-03-06 17:42:47 -08:00
{
2016-08-24 15:51:26 -07:00
continue ;
}
2016-03-06 17:42:47 -08:00
2016-08-24 15:51:26 -07:00
$f = str_replace ( '{e_UPLOAD}' , '' , $v );
2016-03-06 17:42:47 -08:00
2016-08-24 15:51:26 -07:00
if ( $bbpath = e107 :: getMedia () -> importFile ( $f , 'news' , e_UPLOAD . $f ))
2016-03-06 17:42:47 -08:00
{
2016-08-24 15:51:26 -07:00
$new [] = $bbpath ;
2016-03-06 17:42:47 -08:00
}
}
2016-08-24 15:51:26 -07:00
e107 :: getMessage () -> addDebug ( " <h3>Processing/importing SubNews Images</h3> " . print_a ( $new , true ));
2016-03-06 17:42:47 -08:00
return implode ( " , " , $new );
}
2015-04-07 19:49:11 -07:00
public function beforeUpdate ( $new_data , $old_data , $id )
{
2015-06-22 09:30:47 -07:00
if ( ! empty ( $new_data [ 'news_thumbnail' ]))
{
$new_data [ 'news_thumbnail' ] = $this -> processThumbs ( $new_data [ 'news_thumbnail' ]);
}
2015-04-07 19:49:11 -07:00
2015-09-01 15:53:48 -07:00
if ( isset ( $new_data [ 'news_datestamp' ]) && empty ( $new_data [ 'news_datestamp' ]))
2015-04-07 19:49:11 -07:00
{
$new_data [ 'news_datestamp' ] = time ();
}
2015-09-08 18:48:21 -07:00
if ( isset ( $new_data [ 'news_sef' ]) && empty ( $new_data [ 'news_sef' ]) && ! empty ( $new_data [ 'news_title' ]))
2015-04-07 19:49:11 -07:00
{
$new_data [ 'news_sef' ] = eHelper :: title2sef ( $new_data [ 'news_title' ]);
}
2017-01-16 12:09:31 -08:00
$this -> checkSEFSimilarity ( $new_data );
2015-06-22 09:30:47 -07:00
if ( ! empty ( $new_data [ 'news_author' ]))
{
$tmp = explode ( chr ( 35 ), $new_data [ 'news_author' ]);
$new_data [ 'news_author' ] = intval ( $tmp [ 0 ]);
}
2015-04-07 19:49:11 -07:00
2015-07-27 12:12:11 -07:00
if ( E107_DBG_SQLQUERIES )
{
e107 :: getMessage () -> addInfo ( " <h3>Raw _POST data</h3> " . print_a ( $_POST , true ));
}
2015-04-07 19:49:11 -07:00
return $new_data ;
}
2017-01-16 12:09:31 -08:00
/**
* Display a warning if there is a mismatch with the SEF Url .
* @ param $new_data
*/
private function checkSEFSimilarity ( $new_data )
{
2017-01-16 19:05:27 -08:00
if ( e_LANGUAGE === " Japanese " || e_LANGUAGE === " Korean " )
{
return null ;
}
2017-01-16 12:09:31 -08:00
$expectedSEF = eHelper :: title2sef ( $new_data [ 'news_title' ]);
similar_text ( $expectedSEF , $new_data [ 'news_sef' ], $percSimilar );
if ( $percSimilar < 60 )
{
e107 :: getMessage () -> addWarning ( LAN_NEWS_108 ); // The SEF URL is unlike the title of your news item.
}
}
2015-04-07 19:49:11 -07:00
public function afterCreate ( $new_data , $old_data , $id )
{
2015-04-23 10:55:25 -07:00
2015-05-13 01:22:05 -07:00
if ( ! empty ( $_POST [ 'news_email_notify' ]))
{
$this -> triggerNotify ( $new_data );
}
2015-04-23 10:55:25 -07:00
if ( ! empty ( $new_data [ 'submitted_id' ]))
{
e107 :: getDb () -> update ( 'submitnews' , " submitnews_auth = 1 WHERE submitnews_id = " . intval ( $new_data [ 'submitted_id' ]) . " LIMIT 1 " );
}
2015-11-22 09:00:08 -08:00
if ( ! empty ( $new_data [ 'news_sef' ]) && ( $existingSef = e107 :: getDb () -> retrieve ( 'news' , 'news_sef' , " news_sef = ' " . $new_data [ 'news_sef' ] . " ' AND news_id != " . $id )))
{
$existingLAN = e107 :: getParser () -> lanVars ( LAN_NEWS_95 , $existingSef , true );
e107 :: getMessage () -> addWarning ( $existingLAN );
}
2015-04-23 10:55:25 -07:00
2020-12-05 12:39:50 -08:00
2015-04-07 19:49:11 -07:00
e107 :: getEvent () -> trigger ( 'newspost' , $new_data );
2015-06-05 12:25:32 -07:00
// e107::getEvent()->trigger('admin_news_created',$new_data);
2015-04-07 19:49:11 -07:00
$evdata = array ( 'method' => 'create' , 'table' => 'news' , 'id' => $id , 'plugin' => 'news' , 'function' => 'submit_item' );
e107 :: getMessage () -> addInfo ( e107 :: getEvent () -> triggerHook ( $evdata ));
$this -> clearCache ();
}
public function afterUpdate ( $new_data , $old_data , $id )
{
2015-05-13 01:22:05 -07:00
// e107::getMessage()->addInfo(print_a($new_data,true));
if ( ! empty ( $_POST [ 'news_email_notify' ]))
{
$this -> triggerNotify ( $new_data );
}
2020-12-05 12:39:50 -08:00
2015-04-12 19:45:55 -07:00
2015-04-07 19:49:11 -07:00
e107 :: getEvent () -> trigger ( 'newsupd' , $new_data );
2015-06-05 12:25:32 -07:00
// e107::getEvent()->trigger('admin_news_updated',$new_data);
2015-04-07 19:49:11 -07:00
$this -> clearCache ();
2015-11-22 09:00:08 -08:00
if ( ! empty ( $new_data [ 'news_sef' ]) && ( $existingSef = e107 :: getDb () -> retrieve ( 'news' , 'news_sef' , " news_sef = ' " . $new_data [ 'news_sef' ] . " ' AND news_id != " . $id )))
{
$existingLAN = e107 :: getParser () -> lanVars ( LAN_NEWS_95 , $existingSef , true );
e107 :: getMessage () -> addWarning ( $existingLAN );
}
2015-04-07 19:49:11 -07:00
//$ecache->clear("nq_news_"); - supported by cache::clear() now
//$ecache->clear("nomd5_news_"); supported by cache::clear() now
$evdata = array ( 'method' => 'update' , 'table' => 'news' , 'id' => $id , 'plugin' => 'news' , 'function' => 'submit_item' );
e107 :: getMessage () -> addInfo ( e107 :: getEvent () -> triggerHook ( $evdata ));
}
2015-05-13 01:22:05 -07:00
// Trigger the news email notification trigger. (@see admin->notify )
private function triggerNotify ( $new_data )
{
$visibility = explode ( " , " , $new_data [ 'news_class' ]);
if ( in_array ( e_UC_PUBLIC , $visibility ))
{
e107 :: getEvent () -> trigger ( 'admin_news_notify' , $new_data );
2016-10-16 10:20:07 +02:00
e107 :: getMessage () -> addSuccess ( LAN_NEWS_105 );
2015-05-13 01:22:05 -07:00
}
else
{
2016-10-16 10:20:07 +02:00
e107 :: getMessage () -> addWarning ( LAN_NEWS_106 );
2015-05-13 01:22:05 -07:00
}
}
2016-06-09 16:43:36 -07:00
public function afterDelete ( $deleted_data , $id , $deleted_check )
2015-04-07 19:49:11 -07:00
{
$this -> clearCache ();
}
function clearCache ()
{
$ecache = e107 :: getCache ();
$ecache -> clear ( " news.php " ); //TODO change it to 'news_*' everywhere
$ecache -> clear ( " news_ " , false , true ); //NEW global news cache prefix
2017-01-29 18:33:48 -08:00
$ecache -> clear ( " othernews " ); //TODO change it to 'news_other' everywhere
$ecache -> clear ( " othernews2 " ); //TODO change it to 'news_other2' everywhere
2015-04-07 19:49:11 -07:00
//$ecache->clear("nq_news_"); - supported by cache::clear() now
//$ecache->clear("nomd5_news_"); supported by cache::clear() now
return $this ;
}
/**
* For future use : multiple - images .
*/
private function processThumbs ( $postedImage )
{
if ( is_array ( $postedImage ))
{
2016-07-29 13:36:42 -07:00
return implode ( " , " , $postedImage );
2015-04-07 19:49:11 -07:00
}
else
{
return $postedImage ;
}
}
//
function ukfield ( $a , $b ) // custom sort order on create/edit pags.
{
$newOrder = array (
'checkboxes' ,
'news_id' ,
'news_category' ,
'news_title' ,
'news_summary' ,
2017-09-23 14:08:47 -07:00
'news_template' ,
2015-04-07 19:49:11 -07:00
'news_render_type' ,
2017-09-23 14:08:47 -07:00
2015-04-07 19:49:11 -07:00
'news_body' ,
'news_extended' ,
'news_thumbnail' ,
'news_sef' ,
'news_meta_keywords' ,
'news_meta_description' ,
2019-12-02 13:32:21 -08:00
'news_meta_robots' ,
2020-12-05 12:39:50 -08:00
2015-04-07 19:49:11 -07:00
2016-02-13 12:57:34 -08:00
'news_email_notify' ,
2015-04-07 19:49:11 -07:00
'news_allow_comments' ,
'news_start' ,
'news_end' ,
2017-09-23 14:08:47 -07:00
'news_author' ,
2015-04-07 19:49:11 -07:00
'news_datestamp' ,
'news_class' ,
'news_sticky' ,
'news_comment_total' ,
2016-02-13 12:57:34 -08:00
'submitted_id' ,
2015-04-07 19:49:11 -07:00
'options' );
2016-08-17 16:27:00 -07:00
foreach ( $this -> addons as $plug => $config )
2015-04-07 19:49:11 -07:00
{
2016-12-06 19:26:52 -08:00
if ( ! empty ( $config [ 'fields' ]))
2015-04-07 19:49:11 -07:00
{
2016-12-06 19:26:52 -08:00
foreach ( $config [ 'fields' ] as $field => $tmp )
{
$newOrder [] = " x_ " . $plug . " _ " . $field ;
// echo $field;
}
2015-04-07 19:49:11 -07:00
}
}
$order = array_flip ( $newOrder );
2016-02-13 12:57:34 -08:00
if ( $order [ $a ] == $order [ $b ])
2015-04-07 19:49:11 -07:00
{
return 0 ;
}
2016-02-13 12:57:34 -08:00
2015-04-07 19:49:11 -07:00
return ( $order [ $a ] < $order [ $b ]) ? - 1 : 1 ;
}
2017-12-27 20:58:59 -08:00
function handleListImageBbcodeBatch ( $selected , $field , $value )
{
$sql = e107 :: getDb ();
$status = array ();
$ids = implode ( " , " , e107 :: getParser () -> filter ( $selected , 'int' ));
if ( $data = $sql -> retrieve ( " news " , " news_id,news_body " , " news_id IN ( " . $ids . " ) " , true ))
{
foreach ( $data as $row )
{
$id = $row [ 'news_id' ];
$update = array (
'news_body' => e107 :: getBB () -> imgToBBcode ( $row [ 'news_body' ], true ),
'WHERE' => 'news_id = ' . $row [ 'news_id' ]
);
$status [ $id ] = $sql -> update ( 'news' , $update ) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
}
}
$mes = e107 :: getMessage ();
foreach ( $status as $k => $v )
{
$mes -> add ( LAN_UPDATED . " : " . $k , $v );
}
2017-12-31 13:53:25 -08:00
$this -> clearCache ();
2017-12-27 20:58:59 -08:00
return true ;
}
2012-05-17 09:19:44 +00:00
function init ()
{
2016-08-17 16:27:00 -07:00
$this -> addons = e107 :: getAddonConfig ( 'e_admin' , null , 'config' , $this );
2015-04-07 19:49:11 -07:00
if ( ! empty ( $_POST [ 'save_prefs' ]))
{
$this -> saveSettings ();
}
2016-03-13 22:24:28 -07:00
if ( e_DEBUG == true ) // allowing manual fixing of comment total in DEBUG mode.
{
$this -> fields [ 'news_comment_total' ][ 'noedit' ] = false ;
$this -> fields [ 'news_comment_total' ][ 'inline' ] = true ;
}
2015-04-12 18:45:48 -07:00
2015-07-16 14:02:32 -07:00
$this -> fields [ 'news_email_notify' ][ 'writeParms' ][ 'post' ] = " <span class='radio-inline radio inline'><a class='e-modal btn btn-xs btn-mini btn-primary' data-modal-caption=' " . ADLAN_149 . " ' href='notify.php?iframe=1&type=admin_news_notify#/tab-news-events'> " . LAN_CONFIGURE . " </a></span> " ;
2015-05-13 01:22:05 -07:00
2016-01-13 01:31:12 -08:00
// e107::getMessage()->addDebug(print_a($_POST,true));
2015-04-12 18:45:48 -07:00
2015-04-07 19:49:11 -07:00
if ( $this -> getAction () == 'create' || $this -> getAction () == 'edit' )
{
uksort ( $this -> fields , array ( $this , 'ukfield' ));
// $fieldKeys = array_keys($this->fields);
// print_a($fieldKeys);
if ( ! empty ( $_GET [ 'sub' ]))
{
$this -> loadSubmitted ( $_GET [ 'sub' ]);
}
}
2017-12-27 20:58:59 -08:00
if ( deftrue ( 'e_DEBUG' ))
{
$this -> batchOptions [ 'Modify News body' ] = array ( 'image_bbcode' => " Convert all images in news-body to [img] bbcodes. " );
}
2016-01-16 14:24:44 -08:00
if ( deftrue ( " ADMINUI_NEWS_VISIBILITY_MULTIPLE " )) // bc workaround for those who need it. Add to e107_config.php .
{
$this -> fields [ 'news_class' ][ 'type' ] = 'userclasses' ;
}
2015-04-12 18:45:48 -07:00
2015-04-07 19:49:11 -07:00
// $mod = $this->getModel();
// $info = print_a($mod, true);
// e107::getMessage()->addInfo($info);
2015-04-12 18:45:48 -07:00
2015-04-07 19:49:11 -07:00
$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 );
2016-01-11 20:53:05 -08:00
$this -> fields [ 'news_category' ][ 'writeParms' ][ 'optArray' ] = $this -> cats ;
$this -> fields [ 'news_category' ][ 'writeParms' ][ 'size' ] = 'xlarge' ;
2015-04-07 19:49:11 -07:00
$this -> fields [ 'news_render_type' ][ 'writeParms' ][ 'optArray' ] = $this -> news_renderTypes ; // array(NWSLAN_75,NWSLAN_76,NWSLAN_77,NWSLAN_77." 2","Featurebox");
$this -> fields [ 'news_render_type' ][ 'writeParms' ][ 'multiple' ] = 1 ;
2019-12-02 13:32:21 -08:00
$this -> fields [ 'news_meta_robots' ][ 'writeParms' ][ 'optArray' ] = e107 :: getSingleton ( 'eResponse' ) -> getRobotTypes ();
$this -> fields [ 'news_meta_robots' ][ 'writeParms' ][ 'title' ] = e107 :: getSingleton ( 'eResponse' ) -> getRobotDescriptions ();
$this -> fields [ 'news_meta_robots' ][ 'writeParms' ][ 'multiple' ] = 1 ;
2019-12-02 14:18:25 -08:00
// $this->fields['news_meta_robots']['writeParms']['default'] = 'blank';
2015-04-07 19:49:11 -07:00
// $this->newspost = new admin_newspost;
// $this->newspost->news_renderTypes = $this->news_renderTypes;
// $this->newspost->observer();
}
function saveSettings ()
{
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' ]);
2016-03-16 19:54:10 -07:00
$temp [ 'subnews_attach_minsize' ] = e107 :: getParser () -> filter ( $_POST [ 'subnews_attach_minsize' ]);
2015-04-07 19:49:11 -07:00
$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' ]);
2020-12-05 12:39:50 -08:00
2015-04-07 19:49:11 -07:00
$temp [ 'news_default_template' ] = preg_replace ( '#[^\w\pL\-]#u' , '' , $_POST [ 'news_default_template' ]);
$temp [ 'news_list_limit' ] = intval ( $_POST [ 'news_list_limit' ]);
2015-06-11 19:44:39 -07:00
$temp [ 'news_list_templates' ] = e107 :: getParser () -> toDB ( $_POST [ 'news_list_templates' ]);
2017-01-09 13:09:52 -08:00
$temp [ 'news_cache_timeout' ] = intval ( $_POST [ 'news_cache_timeout' ]);
2015-04-07 19:49:11 -07:00
e107 :: getConfig () -> updatePref ( $temp );
if ( e107 :: getConfig () -> save ( false ))
{
e107 :: getAdminLog () -> logArrayDiffs ( $temp , e107 :: getPref (), 'NEWS_06' );
$this -> clearCache ();
}
}
2012-05-17 09:19:44 +00:00
function submittedPage ()
{
$this -> newspost -> show_submitted_news ();
}
function maintPage ()
{
}
2015-04-07 19:49:11 -07:00
private function _optrange ( $num , $zero = true )
{
$tmp = range ( 0 , $num < 0 ? 0 : $num );
if ( ! $zero ) unset ( $tmp [ 0 ]);
return $tmp ;
}
2012-05-17 09:19:44 +00:00
function settingsPage ()
{
2015-04-07 19:49:11 -07:00
// return $this->newspost->show_news_prefs();
$pref = e107 :: getPref ();
$frm = e107 :: getForm ();
$sefbaseDiz = str_replace ( array ( " [br] " , " [ " , " ] " ), array ( " <br /> " , " <a href=' " . e_ADMIN_ABS . " eurl.php'> " , " </a> " ), NWSLAN_128 );
2020-12-05 12:39:50 -08:00
2015-04-07 19:49:11 -07:00
2017-09-26 12:32:55 -07:00
$newsTemplates = array ();
2015-06-11 19:44:39 -07:00
2019-01-24 17:52:06 +01:00
if ( $newInfo = e107 :: getTemplateInfo ( 'news' , 'news' , null , 'front' , true )) //TODO 'category'=>'Categories'? research 'Use non-standard template for news layout' and integrate here.
2017-09-26 12:32:55 -07:00
{
foreach ( $newInfo as $k => $val )
{
$newsTemplates [ $k ] = $val [ 'title' ];
}
}
else
{
$newsTemplates = array ( 'default' => LAN_DEFAULT , 'list' => LAN_LIST );
}
2015-06-11 19:44:39 -07:00
2015-04-07 19:49:11 -07:00
$text = "
2016-03-16 19:54:10 -07:00
< form method = 'post' action = '".e_REQUEST_URI."' id = 'core-newspost-settings-form' > " ;
2015-04-07 19:49:11 -07:00
$tab1 = "
< table class = 'table adminform' >
< colgroup >
< col class = 'col-label' />
< col class = 'col-control' />
</ colgroup >
< tbody >
< tr >
< td > " .NWSLAN_127. " </ td >
< td >
" . $frm->select ('news_default_template', $newsTemplates , $pref['news_default_template'] ). "
2015-05-02 15:57:07 +02:00
< div class = 'field-help' > " .LAN_NEWS_88. " </ div >
2015-04-07 19:49:11 -07:00
</ td >
</ tr >
2015-06-11 19:44:39 -07:00
2015-04-07 19:49:11 -07:00
< tr >
2015-06-11 19:44:39 -07:00
< td > " .NWSLAN_88. " </ td >
2015-04-07 19:49:11 -07:00
< td >
2017-04-02 08:37:20 -07:00
" . $frm->select ('newsposts', $this->_optrange (50, false), $pref['newsposts'] ). "
2015-04-07 19:49:11 -07:00
</ td >
</ tr >
2015-06-11 19:44:39 -07:00
2015-04-07 19:49:11 -07:00
< tr >
2015-06-11 19:44:39 -07:00
< td > " .LAN_NEWS_91. " </ td >
2015-04-07 19:49:11 -07:00
< td >
2017-04-02 08:37:20 -07:00
" . $frm->select ('news_list_limit', $this->_optrange (50, false), $pref['news_list_limit'] ). "
2015-06-11 19:44:39 -07:00
< div class = 'field-help' > " .LAN_NEWS_92. " </ div >
2015-04-07 19:49:11 -07:00
</ td >
</ tr >
2015-06-11 19:44:39 -07:00
2015-04-07 19:49:11 -07:00
< tr >
2015-06-11 19:44:39 -07:00
< td > " .LAN_NEWS_93. " </ td >
2015-04-07 19:49:11 -07:00
< td >
2015-06-11 19:44:39 -07:00
" . $frm->checkboxes ('news_list_templates', $this->news_renderTypes , varset( $pref['news_list_templates'] ,0), array('useKeyValues' => 1)). "
< div class = 'field-help' > " .LAN_NEWS_94. " </ div >
2015-04-07 19:49:11 -07:00
</ td >
</ tr >
2020-12-05 12:39:50 -08:00
" ;
2017-01-09 13:09:52 -08:00
2017-02-13 07:54:47 +01:00
2017-01-09 13:09:52 -08:00
$tab1 .= "
< tr >
2017-02-13 07:54:47 +01:00
< td > " .LAN_NEWS_110. " </ td >
2017-01-09 13:09:52 -08:00
< td >
" . $frm->number ('news_cache_timeout',varset( $pref['news_cache_timeout'] ,0), 6). "
2017-02-13 07:54:47 +01:00
< div class = 'field-help' > " .LAN_NEWS_111. " </ div >
2017-01-09 13:09:52 -08:00
</ td >
</ tr > " ;
$tab1 .= "
2015-04-07 19:49:11 -07:00
< tr >
2015-06-11 19:44:39 -07:00
< td > " .NWSLAN_86. " </ td >
2015-04-07 19:49:11 -07:00
< td >
2015-06-11 19:44:39 -07:00
" . $frm->radio_switch ('news_cats', $pref['news_cats'] ). "
</ td >
</ tr >
< tr >
< td > " .NWSLAN_87. " </ td >
< td >
2017-04-02 08:37:20 -07:00
" . $frm->select ('nbr_cols', $this->_optrange (6, false), $pref['nbr_cols'] ). "
2015-04-07 19:49:11 -07:00
</ td >
</ tr >
< tr >
< td > " .NWSLAN_115. " </ td >
< td id = 'newsposts-archive-cont' >
2017-04-02 08:37:20 -07:00
" . $frm->select ('newsposts_archive', $this->_optrange (intval( $pref['newsposts'] ) - 1), intval( $pref['newsposts_archive'] )). "
2015-04-07 19:49:11 -07:00
< div class = 'field-help' > " .NWSLAN_116. " </ div >
</ td >
</ tr >
< tr >
< td > " .NWSLAN_117. " </ td >
< td >
" . $frm->text ('newsposts_archive_title', $pref['newsposts_archive_title'] ). "
</ td >
</ tr >
< tr >
< td > " .LAN_NEWS_51. " </ td >
< td >
" . $frm->uc_select ('news_editauthor', vartrue( $pref['news_editauthor'] ), 'nobody,main,admin,classes'). "
</ td >
</ tr >
" ;
2016-03-16 19:54:10 -07:00
$imageSizes = array (
'400× 300' => '400x300' ,
'640× 480' => '640x480' ,
'800× 600' => '800x600' ,
'1024× 768' => '1024x768' ,
2016-08-24 18:26:03 -07:00
'1600× 1200' => '2 MP (1600× 1200)' ,
'2272× 1704' => '4 MP (2272× 1704)' ,
'2816× 2112' => '6 MP (2816× 2112)' ,
'3264× 2448' => '8 MP (3264× 2448)' ,
2016-03-16 19:54:10 -07:00
// 10 MP (3648× 2736)
// 12 MP (4096× 3072)
);
2015-04-07 19:49:11 -07:00
$tab2 = " <table class='table adminform'>
< colgroup >
< col class = 'col-label' />
< col class = 'col-control' />
</ colgroup >
< tbody >
< tr >
< td > " .NWSLAN_106. " </ td >
< td >
" . $frm->uc_select ('subnews_class', $pref['subnews_class'] , 'nobody,public,guest,member,admin,classes'). "
</ td >
</ tr >
< tr >
< td > " .NWSLAN_107. " </ td >
< td >
" . $frm->radio_switch ('subnews_htmlarea', $pref['subnews_htmlarea'] ). "
</ td >
</ tr >
< tr >
< td > " .NWSLAN_100. " </ td >
< td >
" . $frm->radio_switch ('subnews_attach', $pref['subnews_attach'] ). "
</ td >
2016-03-16 19:54:10 -07:00
</ tr >
< tr >
2016-10-16 10:20:07 +02:00
< td > " .LAN_NEWS_99. " </ td >
2016-03-16 19:54:10 -07:00
< td >
2017-12-10 13:25:23 +01:00
" . $frm->select ('subnews_attach_minsize', $imageSizes , varset( $pref['subnews_attach_minsize'] , null), null, LAN_NEWS_100). "
2016-03-16 19:54:10 -07:00
</ td >
2015-04-07 19:49:11 -07:00
</ tr >
< tr >
< td > " .NWSLAN_101. " </ td >
< td >
" . $frm->number ('subnews_resize', $pref['subnews_resize'] , 5, 'size=6&class=tbox'). "
< div class = 'field-help' > " .NWSLAN_102. " </ div >
</ td >
</ tr >
< tr >
< td > " .NWSLAN_120. " </ td >
< td >
" . $frm->bbarea ('news_subheader', stripcslashes(vartrue( $pref['news_subheader'] )), 2, 'helpb'). "
</ td >
</ tr >
</ tbody >
</ table >
" ;
$tab1 .= "
< tr >
< td > " .NWSLAN_111. " </ td >
< td >
< div class = 'auto-toggle-area autocheck' >
" . $frm->radio_switch ('news_newdateheader', $pref['news_newdateheader'] ). "
< div class = 'field-help' > " .NWSLAN_112. " </ div >
</ div >
</ td >
</ tr >
< tr >
< td > " .NWSLAN_113. " </ td >
< td >
< div class = 'auto-toggle-area autocheck' >
" . $frm->radio_switch ('news_unstemplate', vartrue( $pref['news_unstemplate'] )). "
< div class = 'field-help' > " .NWSLAN_114. " </ div >
</ div >
</ td >
</ tr >
</ tbody >
</ table > " ;
$text .= $frm -> tabs ( array (
2016-10-16 10:20:07 +02:00
'general' => array ( 'caption' => LAN_GENERAL , 'text' => $tab1 ),
'subnews' => array ( 'caption' => LAN_NEWS_101 , 'text' => $tab2 )
2015-04-07 19:49:11 -07:00
));
$text .= "
< div class = 'buttons-bar center' >
" . $frm->admin_button ('save_prefs', LAN_UPDATE, 'update'). "
</ div >
</ fieldset >
</ form >
" ;
return e107 :: getMessage () -> render () . $text ;
// e107::getRender()->tablerender(NWSLAN_90, e107::getMessage()->render().$text);
2012-05-17 09:19:44 +00:00
}
function noPermissions ( $qry = '' )
{
$url = e_SELF . ( $qry ? '?' . $qry : '' );
if ( $qry !== e_QUERY )
{
$mes = e107 :: getMessage ();
2019-06-11 10:18:11 -07:00
$mes -> add ( 'Insufficient permissions!' , E_MESSAGE_ERROR , true );
2012-05-17 09:19:44 +00:00
session_write_close ();
header ( 'Location: ' . $url );
}
exit ;
}
2016-08-15 10:06:44 -07:00
private function processSubmittedMedia ( $data )
{
if ( empty ( $data ))
{
return false ;
}
$row = json_decode ( $data , true );
$text = '' ;
foreach ( $row as $k )
{
if ( ! empty ( $k ))
{
$text .= $k . " \n \n " ;
}
}
return $text ;
}
2012-05-17 09:19:44 +00:00
function loadSubmitted ( $id )
{
$sql = e107 :: getDb ();
$tp = e107 :: getParser ();
2016-03-06 17:42:47 -08:00
2013-02-25 11:29:38 -08:00
if ( $sql -> select ( " submitnews " , " * " , " submitnews_id= " . intval ( $id )))
2015-04-07 19:49:11 -07:00
{
$row = $sql -> fetch ();
$data [ 'news_title' ] = $tp -> dataFilter ( $row [ 'submitnews_title' ]);
$data [ 'news_body' ] = $row [ 'submitnews_item' ];
$data [ 'news_category' ] = intval ( $row [ 'submitnews_category' ]);
$data [ 'news_body' ] .= " \n [[b] " . NWSLAN_49 . " { $row [ 'submitnews_name' ] } [/b]] " ;
2015-04-23 10:55:25 -07:00
2016-08-15 10:06:44 -07:00
if ( $mediaData = $this -> processSubmittedMedia ( $row [ 'submitnews_media' ]))
{
2016-08-30 14:22:47 -07:00
$data [ 'news_body' ] .= " \n \n --- \n \n " . $mediaData ;
2016-08-15 10:06:44 -07:00
}
if ( e107 :: getPref ( 'wysiwyg' , false ) !== false )
{
$data [ 'news_body' ] = nl2br ( $data [ 'news_body' ]);
}
2016-08-30 14:22:47 -07:00
$data [ 'news_author' ] = $row [ 'submitnews_user' ];
2016-08-15 10:06:44 -07:00
2016-03-06 17:42:47 -08:00
$data [ 'news_thumbnail' ] = $row [ 'submitnews_file' ]; // implode(",",$thumbs);
$data [ 'news_sef' ] = eHelper :: dasherize ( $data [ 'news_title' ]);
2016-08-15 10:06:44 -07:00
$data [ 'news_meta_keywords' ] = $row [ 'submitnews_keywords' ];
$data [ 'news_summary' ] = $row [ 'submitnews_summary' ];
$data [ 'news_meta_description' ] = $row [ 'submitnews_description' ];
2015-04-23 10:55:25 -07:00
$data [ 'submitted_id' ] = $id ;
2015-04-07 19:49:11 -07:00
foreach ( $data as $k => $v )
{
$this -> getModel () -> setData ( $k , $v ); // Override Table data.
}
2016-08-09 09:26:48 -07:00
if ( e_DEBUG )
{
e107 :: getMessage () -> addDebug ( print_a ( $data , true ));
}
2015-04-07 19:49:11 -07:00
}
2012-05-17 09:19:44 +00:00
2015-04-07 19:49:11 -07:00
2012-05-17 09:19:44 +00:00
}
function preCreate ()
{
if ( $_GET [ 'action' ] == " edit " && ! $_POST [ 'preview' ])
{
if ( ! isset ( $_POST [ 'submit_news' ]))
{
2013-03-24 13:07:15 +01:00
if ( e107 :: getDb () -> select ( 'news' , '*' , 'news_id=' . intval ( $_GET [ 'id' ])))
2012-05-17 09:19:44 +00:00
{
2013-03-24 13:07:15 +01:00
$row = e107 :: getDb () -> fetch ();
2012-05-17 09:19:44 +00:00
// 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' ];
2020-12-14 16:21:48 -08:00
$_POST [ 'comment_total' ] = e107 :: getDb () -> count ( " comments " , " (*) " , " WHERE comment_item_id= { $row [ 'news_id' ] } AND comment_type='0' " );
2012-05-17 09:19:44 +00:00
$_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' ];
}
}
2013-05-08 12:25:43 +03:00
else // on submit
{
if ( ! empty ( $_POST [ 'news_meta_keywords' ])) $_POST [ 'news_meta_keywords' ] = eHelper :: formatMetaKeys ( $_POST [ 'news_meta_keywords' ]);
}
2012-05-17 09:19:44 +00:00
}
}
}
class news_form_ui extends e_admin_form_ui
{
2015-04-07 19:49:11 -07:00
2017-09-23 14:08:47 -07:00
function news_template ( $curVal , $mode )
{
if ( $mode === 'read' )
{
return $curVal ;
}
if ( $mode === 'write' )
{
2017-12-17 19:38:44 -08:00
2017-09-23 14:08:47 -07:00
if ( $tmp = e107 :: getTemplate ( 'news' , 'news' , 'view' ))
{
return LAN_DEFAULT ;
}
2017-12-17 19:38:44 -08:00
if ( $tmp = e107 :: getLayouts ( 'news' , 'news_view' , 'front' , null , false , false ))
2017-09-23 14:08:47 -07:00
{
2017-12-17 19:38:44 -08:00
return $this -> select ( 'news_template' , $tmp , $curVal , array ( 'size' => 'xlarge' ));
2017-09-23 14:08:47 -07:00
}
return LAN_DEFAULT ;
}
}
2015-04-07 19:49:11 -07:00
function news_author ( $curVal , $mode )
2012-07-15 03:01:30 +00:00
{
2015-04-07 19:49:11 -07:00
2015-04-15 15:34:58 -07:00
2015-04-07 19:49:11 -07:00
$pref = e107 :: pref ( 'core' );
$sql = e107 :: getDb ();
2015-04-15 15:34:58 -07:00
if ( $mode == 'read' )
{
$row = $this -> getController () -> getListModel () -> getData ();
// $att = $this->getController()->getFieldAttr('news_author');
// $att = array('readParms'=> array(['__idval']=>$row['user_id'idField=user_id&nameField=user_name');
return $row [ 'user_name' ];
}
2015-04-07 19:49:11 -07:00
$text = " " ;
if ( ! getperms ( '0' ) && ! check_class ( $pref [ 'news_editauthor' ]))
2014-01-31 06:33:01 -08:00
{
2017-02-20 15:22:06 -08:00
2015-04-07 19:49:11 -07:00
$auth = ( $curVal ) ? intval ( $curVal ) : USERID ;
$sql -> select ( " user " , " user_name " , " user_id= { $auth } LIMIT 1 " );
2016-02-14 12:15:55 -08:00
$row = $sql -> fetch ();
2015-04-07 19:49:11 -07:00
$text .= " <input type='hidden' name='news_author' value=' " . $auth . chr ( 35 ) . $row [ 'user_name' ] . " ' /> " ;
2017-02-20 15:22:06 -08:00
$text .= " <a href=' " . e107 :: getUrl () -> create ( 'user/profile/view' , 'name=' . $row [ 'user_name' ] . '&id=' . $curVal ) . " '> " . $row [ 'user_name' ] . " </a> " ;
2014-01-31 06:33:01 -08:00
}
2015-04-07 19:49:11 -07:00
else // allow master admin to
{
2017-09-23 14:08:47 -07:00
$text .= $this -> select_open ( 'news_author' , array ( 'size' => 'xlarge' ));
2016-08-31 10:45:06 -07:00
$qry = " SELECT user_id,user_name,user_admin FROM #user WHERE user_perms = '0' OR user_perms = '0.' OR user_perms REGEXP('(^|,)(H)(,| $ )') " ;
if ( ! empty ( $curVal ))
{
$qry .= " OR user_id = " . intval ( $curVal ); // make sure existing author is included.
}
2015-04-07 19:49:11 -07:00
if ( $pref [ 'subnews_class' ] && $pref [ 'subnews_class' ] != e_UC_GUEST && $pref [ 'subnews_class' ] != e_UC_NOBODY )
{
if ( $pref [ 'subnews_class' ] == e_UC_MEMBER )
{
2016-08-31 10:45:06 -07:00
$qry .= " OR user_ban != 1 ORDER BY user_class DESC, user_name " ; // limit to avoid long page loads.
2015-04-07 19:49:11 -07:00
}
elseif ( $pref [ 'subnews_class' ] == e_UC_ADMIN )
{
2016-08-31 10:45:06 -07:00
$qry .= " OR user_admin = 1 ORDER BY user_name " ;
2015-04-07 19:49:11 -07:00
}
else
{
2016-08-31 10:45:06 -07:00
$qry .= " OR FIND_IN_SET( " . intval ( $pref [ 'subnews_class' ]) . " , user_class) ORDER BY user_name " ;
2015-04-07 19:49:11 -07:00
}
}
2014-01-31 06:33:01 -08:00
2015-04-07 19:49:11 -07:00
// print_a($pref['subnews_class']);
2016-08-31 10:45:06 -07:00
2015-04-07 19:49:11 -07:00
$sql -> gen ( $qry );
while ( $row = $sql -> fetch ())
{
if ( vartrue ( $curVal ))
{
$sel = ( $curVal == $row [ 'user_id' ]);
}
else
{
$sel = ( USERID == $row [ 'user_id' ]);
}
2016-08-31 10:45:06 -07:00
$username = $row [ 'user_name' ];
if ( ! empty ( $row [ 'user_admin' ]))
{
$username .= " * " ;
}
$text .= $this -> option ( $username , $row [ 'user_id' ] . chr ( 35 ) . $row [ 'user_name' ], $sel );
2015-04-07 19:49:11 -07:00
}
$text .= " </select>
" ;
2016-08-31 10:45:06 -07:00
2015-04-07 19:49:11 -07:00
}
return $text ;
}
function news_body ( $curVal , $mode )
{
$frm = e107 :: getForm ();
$tp = e107 :: getParser ();
if ( $mode == 'read' )
2014-01-31 01:09:24 -08:00
{
2015-04-07 19:49:11 -07:00
return '...' ;
2014-01-31 01:09:24 -08:00
}
2015-04-07 19:49:11 -07:00
$curValExt = $this -> getController () -> getModel () -> get ( 'news_extended' );
$text = ' < ul class = " nav nav-tabs " >
< li class = " active " >< a href = " #news-body-container " data - toggle = " tab " > '.NWSLAN_13.' </ a ></ li >
< li >< a href = " #news-extended-container " data - toggle = " tab " > '.NWSLAN_14.' </ a ></ li >
</ ul >
< div class = " tab-content " > ' ;
2020-12-20 11:50:10 -08:00
$val = strpos ( $curVal , " [img]http " ) !== false ? $curVal : str_replace ( " [img]../ " , " [img] " , $curVal );
2015-04-07 19:49:11 -07:00
$text .= " <div id='news-body-container' class='tab-pane active'> " ;
$text .= $frm -> bbarea ( 'news_body' , $val , 'news' , 'news' , 'large' );
$text .= " </div> " ;
$text .= " <div id='news-extended-container' class='tab-pane'> " ;
2020-12-20 11:50:10 -08:00
$val = ( strpos ( $curValExt , " [img]http " ) !== false ? $curValExt : str_replace ( " [img]../ " , " [img] " , $curValExt ));
2015-04-07 19:49:11 -07:00
$text .= $frm -> bbarea ( 'news_extended' , $val , 'extended' , 'news' , 'large' );
$text .= " </div>
</ div > " ;
return $text ;
}
function news_thumbnail ( $curval , $mode )
{
if ( $mode == 'read' )
2012-07-15 03:01:30 +00:00
{
2015-04-07 19:49:11 -07:00
if ( strpos ( $curval , " , " ) !== false )
{
$tmp = explode ( " , " , $curval );
$curval = $tmp [ 0 ];
}
2016-08-24 15:51:26 -07:00
if ( empty ( $curval ))
{
return '' ;
}
2015-04-07 19:49:11 -07:00
$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 );
2016-12-17 09:43:37 -08:00
return " <a class='e-modal' href=' { $link } '><img src=' { $url } ' alt=' " . basename ( $curval ) . " ' /></a> " ;
2012-07-15 03:01:30 +00:00
}
2015-04-07 19:49:11 -07:00
if ( $mode == 'write' )
{
2016-08-24 15:51:26 -07:00
$paths = array ();
2016-03-06 17:42:47 -08:00
if ( ! empty ( $_GET [ 'sub' ]))
{
$thumbTmp = explode ( " , " , $curval );
foreach ( $thumbTmp as $key => $path )
{
2016-08-24 15:51:26 -07:00
$url = ( $path [ 0 ] == '{' ) ? $path : e_TEMP . $path ;
$paths [] = e107 :: getParser () -> thumbUrl ( $url , 'aw=800' ); ;
2016-03-06 17:42:47 -08:00
}
}
2015-04-07 19:49:11 -07:00
$tp = e107 :: getParser ();
$frm = e107 :: getForm ();
// $text .= $frm->imagepicker('news_thumbnail[0]', $curval ,'','media=news&video=1');
$thumbTmp = explode ( " , " , $curval );
2018-09-03 14:35:03 -07:00
$text = " <div class='mediaselector-multi'> " ;
$text .= $frm -> imagepicker ( 'news_thumbnail[0]' , varset ( $thumbTmp [ 0 ]), varset ( $paths [ 0 ]), array ( 'media' => 'news+' , 'video' => 1 , 'legacyPath' => '{e_IMAGE}newspost_images' ));
2018-08-22 18:09:46 -07:00
$text .= $frm -> imagepicker ( 'news_thumbnail[1]' , varset ( $thumbTmp [ 1 ]), varset ( $paths [ 1 ]), array ( 'media' => 'news+' , 'video' => 1 , 'legacyPath' => '{e_IMAGE}newspost_images' ));
$text .= $frm -> imagepicker ( 'news_thumbnail[2]' , varset ( $thumbTmp [ 2 ]), varset ( $paths [ 2 ]), array ( 'media' => 'news+' , 'video' => 1 , 'legacyPath' => '{e_IMAGE}newspost_images' ));
$text .= $frm -> imagepicker ( 'news_thumbnail[3]' , varset ( $thumbTmp [ 3 ]), varset ( $paths [ 3 ]), array ( 'media' => 'news+' , 'video' => 1 , 'legacyPath' => '{e_IMAGE}newspost_images' ));
$text .= $frm -> imagepicker ( 'news_thumbnail[4]' , varset ( $thumbTmp [ 4 ]), varset ( $paths [ 4 ]), array ( 'media' => 'news+' , 'video' => 1 , 'legacyPath' => '{e_IMAGE}newspost_images' ));
2018-09-03 14:35:03 -07:00
$text .= " </div> " ;
2016-01-11 20:53:05 -08:00
// $text .= "<div class='field-help'>Insert image/video into designated area of template.</div>";
2015-04-07 19:49:11 -07:00
return $text ;
}
2012-07-15 03:01:30 +00:00
}
2015-04-07 19:49:11 -07:00
2012-12-21 10:26:32 +02:00
function news_title ( $value , $mode )
{
if ( $mode == 'read' )
{
$news_item = $this -> getController () -> getListModel () -> toArray ();
$url = e107 :: getUrl () -> create ( 'news/view/item' , $news_item );
2016-10-16 10:20:07 +02:00
return " <a class='e-tip' href=' { $url } ' title=' " . LAN_NEWS_102 . " ' rel='external'> " . $value . " </a> " ;
2012-12-21 10:26:32 +02:00
}
return $value ;
}
2012-05-17 09:19:44 +00:00
}
2006-12-02 04:36:16 +00:00
2017-02-19 10:23:52 -08:00
new news_admin ();
require_once ( e_ADMIN . " auth.php " );
e107 :: getAdminUI () -> runPage ();
2006-12-02 04:36:16 +00:00
2008-06-15 20:20:28 +00:00
2017-02-20 15:22:06 -08:00
2017-02-19 10:23:52 -08:00
if ( ! e_AJAX_REQUEST )
{
require_once ( " footer.php " );
2006-12-02 04:36:16 +00:00
}
exit ;