2006-12-02 04:36:16 +00:00
< ? php
/*
2008-12-02 16:50:16 +00:00
* e107 website system
*
2013-03-18 13:35:09 +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 handler
*
2006-12-02 04:36:16 +00:00
*/
2010-04-24 11:48:19 +00:00
/**
*
* @ package e107
* @ subpackage e107_handlers
* @ author e107inc
*
* Classes :
* news - old news class
* e_news_item - news data model - the future
* e_news_tree - news items collection
* e_news_category_item - news category data model
* e_news_category_tree - news category items collection
*/
2006-12-02 04:36:16 +00:00
if ( ! defined ( 'e107_INIT' )) { exit ; }
2009-09-25 20:13:47 +00:00
class news {
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
protected static $_rewrite_data = array ();
protected static $_rewrite_map = null ;
//FIXME - LANs
//TODO - synch WIKI docs, add rewrite data to the event data
2015-04-07 19:49:11 -07:00
//@Deprecated and no longer used by newspost.php
2009-09-25 20:13:47 +00:00
function submit_item ( $news , $smessages = false )
2009-08-21 13:20:36 +00:00
{
2009-09-25 20:13:47 +00:00
$tp = e107 :: getParser ();
$sql = e107 :: getDb ();
2011-12-10 00:00:15 +00:00
$admin_log = e107 :: getAdminLog ();
$pref = e107 :: getPref ();
$e_event = e107 :: getEvent ();
$e107cache = e107 :: getCache ();
2010-04-24 11:39:14 +00:00
$emessage = e107 :: getMessage ();
2011-12-10 00:00:15 +00:00
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
$error = false ;
if ( empty ( $news [ 'news_title' ]))
2009-08-21 13:20:36 +00:00
{
2009-09-25 20:13:47 +00:00
$error = true ;
$emessage -> add ( 'Validation error: News title can\'t be empty!' , E_MESSAGE_ERROR , $smessages );
2011-12-10 00:00:15 +00:00
if ( ! empty ( $news [ 'news_sef' ]))
{
$news [ 'news_sef' ] = eHelper :: secureSef ( $news [ 'news_sef' ]);
}
}
else
{
// first format sef...
if ( empty ( $news [ 'news_sef' ]))
{
$news [ 'news_sef' ] = eHelper :: title2sef ( $news [ 'news_title' ]);
}
else
{
$news [ 'news_sef' ] = eHelper :: secureSef ( $news [ 'news_sef' ]);
}
}
// ...then check it
if ( empty ( $news [ 'news_sef' ]))
{
$error = true ;
$emessage -> add ( 'Validation error: News SEF URL value is required field and can\'t be empty!' , E_MESSAGE_ERROR , $smessages );
}
elseif ( $sql -> db_Count ( 'news' , '(news_id)' , ( $news [ 'news_sef' ] ? 'news_id<>' . intval ( $news [ 'news_id' ]) . ' AND ' : '' ) . " news_sef=' " . $tp -> toDB ( $news [ 'news_sef' ]) . " ' " ))
{
$error = true ;
$emessage -> add ( 'Validation error: News SEF URL is unique field - current value already in use! Please choose another SEF URL value.' , E_MESSAGE_ERROR , $smessages );
2009-08-21 13:20:36 +00:00
}
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
if ( empty ( $news [ 'news_category' ]))
2009-08-21 13:20:36 +00:00
{
2009-09-25 20:13:47 +00:00
$error = true ;
$emessage -> add ( 'Validation error: News category can\'t be empty!' , E_MESSAGE_ERROR , $smessages );
}
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
$data = array ();
//DB Array
$data [ 'data' ][ 'news_title' ] = $news [ 'news_title' ];
$data [ '_FIELD_TYPES' ][ 'news_title' ] = 'todb' ;
2011-12-10 00:00:15 +00:00
$data [ 'data' ][ 'news_sef' ] = $news [ 'news_sef' ];
$data [ '_FIELD_TYPES' ][ 'news_sef' ] = 'todb' ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
$data [ 'data' ][ 'news_body' ] = $news [ 'news_body' ];
$data [ '_FIELD_TYPES' ][ 'news_body' ] = 'todb' ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
$data [ 'data' ][ 'news_extended' ] = $news [ 'news_extended' ];
$data [ '_FIELD_TYPES' ][ 'news_extended' ] = 'todb' ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
$data [ 'data' ][ 'news_datestamp' ] = $news [ 'news_datestamp' ];
$data [ '_FIELD_TYPES' ][ 'news_datestamp' ] = 'int' ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
$data [ 'data' ][ 'news_author' ] = $news [ 'news_author' ] ? $news [ 'news_author' ] : USERID ;
$data [ '_FIELD_TYPES' ][ 'news_author' ] = 'int' ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
$data [ 'data' ][ 'news_category' ] = $news [ 'news_category' ];
$data [ '_FIELD_TYPES' ][ 'news_category' ] = 'int' ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
$data [ 'data' ][ 'news_allow_comments' ] = $news [ 'news_allow_comments' ];
$data [ '_FIELD_TYPES' ][ 'news_allow_comments' ] = 'int' ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
$data [ 'data' ][ 'news_start' ] = $news [ 'news_start' ];
$data [ '_FIELD_TYPES' ][ 'news_start' ] = 'int' ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
$data [ 'data' ][ 'news_end' ] = $news [ 'news_end' ];
$data [ '_FIELD_TYPES' ][ 'news_end' ] = 'int' ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
$data [ 'data' ][ 'news_class' ] = $news [ 'news_class' ];
$data [ '_FIELD_TYPES' ][ 'news_class' ] = 'todb' ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
$data [ 'data' ][ 'news_render_type' ] = $news [ 'news_render_type' ];
2012-10-11 02:24:43 +00:00
$data [ '_FIELD_TYPES' ][ 'news_render_type' ] = 'todb' ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
//news_comment_total
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
$data [ 'data' ][ 'news_summary' ] = $news [ 'news_summary' ];
$data [ '_FIELD_TYPES' ][ 'news_summary' ] = 'todb' ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
$data [ 'data' ][ 'news_thumbnail' ] = $news [ 'news_thumbnail' ];
$data [ '_FIELD_TYPES' ][ 'news_thumbnail' ] = 'todb' ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
$data [ 'data' ][ 'news_sticky' ] = $news [ 'news_sticky' ];
$data [ '_FIELD_TYPES' ][ 'news_sticky' ] = 'int' ;
2009-10-21 20:05:55 +00:00
2011-12-10 00:00:15 +00:00
$data [ 'data' ][ 'news_meta_keywords' ] = eHelper :: formatMetaKeys ( $news [ 'news_meta_keywords' ]);
2009-09-25 20:13:47 +00:00
$data [ '_FIELD_TYPES' ][ 'news_meta_keywords' ] = 'todb' ;
2010-02-10 21:53:56 +00:00
2011-12-10 00:00:15 +00:00
$data [ 'data' ][ 'news_meta_description' ] = eHelper :: formatMetaDescription ( $news [ 'news_meta_description' ]); //handle bbcodes
2009-09-25 20:13:47 +00:00
$data [ '_FIELD_TYPES' ][ 'news_meta_description' ] = 'todb' ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
if ( $error )
{
$data [ 'error' ] = true ;
return $data ;
}
2009-11-19 20:24:21 +00:00
2012-11-01 02:21:58 +00:00
2009-11-19 20:24:21 +00:00
// Calculate short strings for admin logging - no need to clog up the log with potentially long items
$logData = $data [ 'data' ];
if ( isset ( $logData [ 'news_body' ])) $logData [ 'news_body' ] = $tp -> text_truncate ( $tp -> toDB ( $logData [ 'news_body' ]), 300 , '...' );
if ( isset ( $logData [ 'news_extended' ])) $logData [ 'news_extended' ] = $tp -> text_truncate ( $tp -> toDB ( $logData [ 'news_extended' ]), 300 , '...' );
//XXX - Now hooks are executed only if no mysql error is found. Should it stay so? Seems sensible to me!
2009-09-25 20:13:47 +00:00
if ( $news [ 'news_id' ])
2010-02-10 21:53:56 +00:00
{
2009-09-25 20:13:47 +00:00
// Updating existing item
$data [ 'WHERE' ] = 'news_id=' . intval ( $news [ 'news_id' ]);
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
//$vals = "news_datestamp = '".intval($news['news_datestamp'])."', ".$author_insert." news_title='".$news['news_title']."', news_body='".$news['news_body']."', news_extended='".$news['news_extended']."', news_category='".intval($news['cat_id'])."', news_allow_comments='".intval($news['news_allow_comments'])."', news_start='".intval($news['news_start'])."', news_end='".intval($news['news_end'])."', news_class='".$tp->toDB($news['news_class'])."', news_render_type='".intval($news['news_rendertype'])."' , news_summary='".$news['news_summary']."', news_thumbnail='".$tp->toDB($news['news_thumbnail'])."', news_sticky='".intval($news['news_sticky'])."' WHERE news_id='".intval($news['news_id'])."' ";
if ( $sql -> db_Update ( 'news' , $data ))
2009-08-21 13:20:36 +00:00
{
2011-07-06 23:37:49 +00:00
2009-11-19 20:24:21 +00:00
e107 :: getAdminLog () -> logArrayAll ( 'NEWS_09' , $logData );
2011-07-06 23:37:49 +00:00
2009-09-25 20:13:47 +00:00
$data [ 'data' ][ 'news_id' ] = $news [ 'news_id' ];
2011-07-06 23:37:49 +00:00
2009-09-25 20:13:47 +00:00
e107 :: getEvent () -> trigger ( 'newsupd' , $data [ 'data' ]);
2015-02-13 02:30:31 -08:00
e107 :: getEvent () -> trigger ( 'admin_news_updated' , $data [ 'data' ]);
2013-02-27 00:44:58 -08:00
$message = LAN_UPDATED ;
$emessage -> add ( LAN_UPDATED , E_MESSAGE_SUCCESS , $smessages );
2009-09-25 20:13:47 +00:00
e107 :: getCache () -> clear ( 'news.php' );
2009-08-21 13:20:36 +00:00
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
//FIXME - triggerHook should return array(message, message_type)
$evdata = array ( 'method' => 'update' , 'table' => 'news' , 'id' => $news [ 'news_id' ], 'plugin' => 'news' , 'function' => 'submit_item' );
$emessage -> add ( e107 :: getEvent () -> triggerHook ( $evdata ), E_MESSAGE_INFO , $smessages );
}
else
2009-08-17 18:47:29 +00:00
{
2009-09-25 20:13:47 +00:00
if ( $sql -> getLastErrorNumber ())
{
$error = true ;
$emessage -> add ( LAN_NEWS_5 , E_MESSAGE_ERROR , $smessages );
$message = " <strong> " . LAN_NEWS_5 . " </strong> " ;
}
else
{
$data [ 'data' ][ 'news_id' ] = $news [ 'news_id' ];
2011-07-06 23:37:49 +00:00
2013-03-18 13:35:09 +01:00
$emessage -> add ( LAN_NO_CHANGE , E_MESSAGE_INFO , $smessages );
$message = " <strong> " . LAN_NO_CHANGE . " </strong> " ;
2011-07-06 23:37:49 +00:00
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
//FIXME - triggerHook should return array(message, message_type)
$evdata = array ( 'method' => 'update' , 'table' => 'news' , 'id' => $news [ 'news_id' ], 'plugin' => 'news' , 'function' => 'submit_item' );
$emessage -> add ( e107 :: getEvent () -> triggerHook ( $evdata ), E_MESSAGE_INFO , $smessages );
}
}
}
else
2010-02-10 21:53:56 +00:00
{
2009-09-25 20:13:47 +00:00
// Adding item
$data [ 'data' ][ 'news_id' ] = $sql -> db_Insert ( 'news' , $data );
$news [ 'news_id' ] = $data [ 'data' ][ 'news_id' ];
//$news['news_id'] = $sql ->db_Insert('news', "0, '".$news['news_title']."', '".$news['news_body']."', '".$news['news_extended']."', ".intval($news['news_datestamp']).", ".intval($news['news_author']).", '".intval($news['cat_id'])."', '".intval($news['news_allow_comments'])."', '".intval($news['news_start'])."', '".intval($news['news_end'])."', '".$tp->toDB($news['news_class'])."', '".intval($news['news_rendertype'])."', '0' , '".$news['news_summary']."', '".$tp->toDB($news['news_thumbnail'])."', '".intval($news['news_sticky'])."' ")
if ( $data [ 'data' ][ 'news_id' ])
{
2009-11-19 20:24:21 +00:00
$data [ 'news_id' ] = $news [ 'news_id' ];
2009-09-25 20:13:47 +00:00
$message = LAN_NEWS_6 ;
2013-02-24 01:07:19 -08:00
$emessage -> add ( LAN_CREATED , E_MESSAGE_SUCCESS , $smessages );
2009-09-25 20:13:47 +00:00
e107 :: getCache () -> clear ( 'news.php' );
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
//moved down - prevent wrong mysql_insert_id
2009-11-19 20:24:21 +00:00
e107 :: getAdminLog () -> logArrayAll ( 'NEWS_08' , $logData );
2009-09-25 20:13:47 +00:00
e107 :: getEvent () -> trigger ( 'newspost' , $data [ 'data' ]);
2015-02-13 02:30:31 -08:00
e107 :: getEvent () -> trigger ( 'admin_news_created' , $data [ 'data' ]);
2010-02-10 21:53:56 +00:00
2009-11-19 20:24:21 +00:00
//XXX - triggerHook after trigger?
2009-09-25 20:13:47 +00:00
$evdata = array ( 'method' => 'create' , 'table' => 'news' , 'id' => $data [ 'data' ][ 'news_id' ], 'plugin' => 'news' , 'function' => 'submit_item' );
$emessage -> add ( $e_event -> triggerHook ( $evdata ), E_MESSAGE_INFO , $smessages );
}
else
{
$error = true ;
$message = " <strong> " . LAN_NEWS_7 . " </strong> " ;
2013-02-24 01:07:19 -08:00
$emessage -> add ( LAN_UPDATED , E_MESSAGE_ERROR , $smessages );
2009-08-17 18:47:29 +00:00
}
}
2009-09-25 20:13:47 +00:00
//return $message;
$data [ 'message' ] = $message ;
$data [ 'error' ] = $error ;
return $data ;
2009-08-17 18:47:29 +00:00
}
2011-07-06 23:37:49 +00:00
2009-09-25 20:13:47 +00:00
function render_newsitem ( $news , $mode = 'default' , $n_restrict = '' , $NEWS_TEMPLATE = '' , $param = array ())
2009-08-17 18:47:29 +00:00
{
2010-04-24 11:39:14 +00:00
global $NEWSSTYLE , $NEWSLISTSTYLE ;
2011-11-29 12:09:05 +00:00
if ( $override_newsitem = e107 :: getSingleton ( 'override' , true ) -> override_check ( 'render_newsitem' ))
{
2009-09-25 20:13:47 +00:00
$result = call_user_func ( $override_newsitem , $news , $mode , $n_restrict , $NEWS_TEMPLATE , $param );
if ( $result == 'return' )
{
return ;
}
}
if ( $n_restrict == 'userclass' )
2009-08-17 18:47:29 +00:00
{
2012-12-16 21:05:54 -08:00
$news [ 'news_id' ] = 0 ;
$news [ 'news_title' ] = LAN_NEWS_1 ;
$news [ 'data' ] = LAN_NEWS_2 ;
$news [ 'news_extended' ] = " " ;
$news [ 'news_allow_comments' ] = 1 ;
$news [ 'news_start' ] = 0 ;
$news [ 'news_end' ] = 0 ;
$news [ 'news_render_type' ] = 0 ;
$news [ 'comment_total' ] = 0 ;
2009-08-17 18:47:29 +00:00
}
2009-09-25 20:13:47 +00:00
$tmp = array ();
2012-12-16 21:05:54 -08:00
$tmp [ 'caticon' ] = defset ( 'ICONSTYLE' );
$tmp [ 'commentoffstring' ] = defset ( 'COMMENTOFFSTRING' );
$tmp [ 'commentlink' ] = defset ( 'COMMENTLINK' );
$tmp [ 'trackbackstring' ] = defset ( 'TRACKBACKSTRING' );
$tmp [ 'trackbackbeforestring' ] = defset ( 'TRACKBACKBEFORESTRING' );
$tmp [ 'trackbackafterstring' ] = defset ( 'TRACKBACKAFTERSTRING' );
$tmp [ 'itemlink' ] = defset ( 'NEWSLIST_ITEMLINK' );
$tmp [ 'thumbnail' ] = defset ( 'NEWSLIST_THUMB' , " border:0px " );
$tmp [ 'catlink' ] = defset ( 'NEWSLIST_CATLINK' );
$tmp [ 'caticon' ] = defset ( 'NEWSLIST_CATICON' , defset ( 'ICONSTYLE' ));
2006-12-02 04:36:16 +00:00
2009-09-25 20:13:47 +00:00
if ( ! $param ) $param = array ();
2010-02-10 21:53:56 +00:00
$param = array_merge ( $tmp , $param );
2009-09-25 20:13:47 +00:00
// Next three images aren't always defined by the caller, even if most of $param is.
2012-12-16 21:05:54 -08:00
//XXX All of this should be done via CSS from v2 on.
2009-09-25 20:13:47 +00:00
if ( ! isset ( $param [ 'image_nonew_small' ]))
2009-09-12 18:25:41 +00:00
{
2009-09-25 20:13:47 +00:00
if ( ! defined ( " IMAGE_nonew_small " ))
{
define ( " IMAGE_nonew_small " , ( file_exists ( THEME . " images/nonew_comments.png " ) ? " <img src=' " . THEME_ABS . " images/nonew_comments.png' alt='' /> " : " <img src=' " . e_IMAGE_ABS . " generic/nonew_comments.png' alt='' /> " ));
}
$param [ 'image_nonew_small' ] = IMAGE_nonew_small ;
2009-09-12 18:25:41 +00:00
}
2009-09-25 20:13:47 +00:00
if ( ! isset ( $param [ 'image_new_small' ]))
2009-09-12 18:25:41 +00:00
{
2009-09-25 20:13:47 +00:00
if ( ! defined ( " IMAGE_new_small " ))
{
define ( " IMAGE_new_small " , ( file_exists ( THEME . " images/new_comments.png " ) ? " <img src=' " . THEME_ABS . " images/new_comments.png' alt='' /> " : " <img src=' " . e_IMAGE_ABS . " generic/new_comments.png' alt='' /> " ));
}
$param [ 'image_new_small' ] = IMAGE_new_small ;
2009-09-12 18:25:41 +00:00
}
2006-12-02 04:36:16 +00:00
2009-09-25 20:13:47 +00:00
if ( ! isset ( $param [ 'image_sticky' ]))
2009-09-12 18:25:41 +00:00
{
2009-09-25 20:13:47 +00:00
if ( ! defined ( " IMAGE_sticky " ))
{
define ( " IMAGE_sticky " , ( file_exists ( THEME . " images/sticky.png " ) ? " <img src=' " . THEME_ABS . " images/sticky.png' alt='' /> " : " <img src=' " . e_IMAGE_ABS . " generic/sticky.png' alt='' style='width: 14px; height: 14px; vertical-align: bottom' /> " ));
}
$param [ 'image_sticky' ] = IMAGE_sticky ;
2009-09-12 18:25:41 +00:00
}
2009-09-25 20:13:47 +00:00
cachevars ( 'current_news_item' , $news );
cachevars ( 'current_news_param' , $param );
2012-12-16 21:05:54 -08:00
if ( $news [ 'news_render_type' ] == 1 && $mode != " extend " )
{
if ( function_exists ( " news_list " ))
{
2009-09-25 20:13:47 +00:00
$NEWS_PARSE = news_list ( $news );
2012-12-16 21:05:54 -08:00
}
else if ( $NEWSLISTSTYLE )
{
2009-09-25 20:13:47 +00:00
$NEWS_PARSE = $NEWSLISTSTYLE ;
2012-12-16 21:05:54 -08:00
}
else
{
2009-09-25 20:13:47 +00:00
$NEWS_PARSE = " { NEWSICON} <b> { NEWSTITLELINK}</b><div class='smalltext'> { NEWSAUTHOR} " . LAN_NEWS_100 . " { NEWSDATE} | { NEWSCOMMENTS}</div> " ;
2009-01-07 19:57:09 +00:00
}
2012-12-16 21:05:54 -08:00
}
else
{
if ( $NEWS_TEMPLATE )
{
2009-09-25 20:13:47 +00:00
$NEWS_PARSE = $NEWS_TEMPLATE ;
2012-12-16 21:05:54 -08:00
}
else
{
2011-11-29 12:09:05 +00:00
if ( function_exists ( " news_style " ))
{
$action = varset ( $param [ 'current_action' ], 'default' );
$NEWS_PARSE = news_style ( $news , $action , $param );
2012-12-16 21:05:54 -08:00
}
else
{
2009-09-25 20:13:47 +00:00
$NEWS_PARSE = $NEWSSTYLE ;
2009-05-24 15:34:37 +00:00
}
2009-09-25 20:13:47 +00:00
}
}
2010-04-24 11:39:14 +00:00
//$loop_uid = $news['news_author']; - no references found
2009-09-25 20:13:47 +00:00
2010-04-25 13:52:14 +00:00
//require_once(e_CORE.'shortcodes/batch/news_shortcodes.php');
2010-04-24 11:39:14 +00:00
/* DEPRECATED
2009-09-25 20:13:47 +00:00
setScVar ( 'news_shortcodes' , 'news_item' , $news );
setScVar ( 'news_shortcodes' , 'param' , $param );
2010-04-24 11:39:14 +00:00
*/
2015-06-08 00:12:19 -07:00
// Set the Values for the social shortcode usage.
$tp = e107 :: getParser ();
$socialArray = array ( 'url' => e107 :: getUrl () -> create ( 'news/view/item' , $news , 'full=1' ), 'title' => $tp -> toText ( $news [ 'news_title' ]), 'tags' => $news [ 'news_meta_keywords' ]);
$socialObj = e107 :: getScBatch ( 'social' );
if ( is_object ( $socialObj ))
{
$socialObj -> setVars ( $socialArray );
}
2010-04-24 11:39:14 +00:00
// Retrieve batch sc object, set required vars
2016-03-10 15:13:32 -08:00
$wrapperKey = ( ! empty ( $param [ 'template_key' ])) ? 'news/' . $param [ 'template_key' ] . '/item' : 'news/view/item' ;
2013-05-31 18:40:56 -07:00
$sc = e107 :: getScBatch ( 'news' )
2016-03-10 15:13:32 -08:00
-> wrapper ( $wrapperKey )
2010-04-24 11:39:14 +00:00
-> setScVar ( 'news_item' , $news )
-> setScVar ( 'param' , $param );
2015-08-22 00:17:07 -07:00
2016-03-10 15:13:32 -08:00
2013-05-31 18:40:56 -07:00
$text = e107 :: getParser () -> parseTemplate ( $NEWS_PARSE , true , $sc );
2009-09-25 20:13:47 +00:00
if ( $mode == 'return' )
{
return $text ;
}
else
{
echo $text ;
return TRUE ;
}
}
2009-01-15 15:42:24 +00:00
2009-09-25 20:13:47 +00:00
//@TDODO deprecated?
function make_xml_compatible ( $original )
{
2010-04-24 11:39:14 +00:00
$original = e107 :: getParser () -> toHTML ( $original , TRUE );
2009-09-25 20:13:47 +00:00
$original = str_replace ( '£' , '&#163;' , $original );
$original = str_replace ( '©' , '(c)' , $original );
return htmlspecialchars ( $original , ENT_COMPAT , CHARSET );
}
}
//EXPERIMENTAL
require_once ( e_HANDLER . 'model_class.php' );
2011-12-02 12:24:26 +00:00
class e_news_item extends e_front_model
2009-09-25 20:13:47 +00:00
{
2011-12-02 12:24:26 +00:00
protected $_db_table = 'news' ;
protected $_field_id = 'news_id' ;
protected $_cache_string = 'news_item_' ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
/**
* Shortcodes - simple field getter ( basic formatting )
* THIS IS ONLY TEST , maybe useful for fields requiring simple formatting - it ' s a way too complicated for designers ,
* could be inner used inside the rest of news SCs .
*
* @ param string $news_field name without the leading 'news_' prefix
* @ param mixed $default
* @ return string field value
*/
public function sc_news_field ( $parm = '' )
{
$tmp = explode ( '|' , $parm , 2 );
$field = $tmp [ 0 ];
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
if ( ! is_array ( $parm ))
{
parse_str ( varset ( $tmp [ 1 ]), $parm );
2009-01-07 19:57:09 +00:00
}
2011-12-02 12:24:26 +00:00
$val = $this -> field ( $field , '' );
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
//do more with $parm array, just an example here
2015-02-14 23:34:15 -08:00
if ( vartrue ( $parm [ 'format' ]))
2009-09-25 20:13:47 +00:00
{
switch ( $parm [ 'format' ])
2008-12-07 13:08:54 +00:00
{
2009-09-25 20:13:47 +00:00
//USAGE: {NEWS_FIELD=body|format=html&arg=1,BODY} -> callback e107->toHTML($value, true, 'BODY');
2010-02-10 21:53:56 +00:00
case 'html' :
2009-09-25 20:13:47 +00:00
$method = 'toHTML' ;
$callback = e107 :: getParser ();
$parm [ 'arg' ] = explode ( ',' , varset ( $parm [ 'arg' ]));
2015-02-14 23:34:15 -08:00
$parm [ 'arg' ][ 0 ] = vartrue ( $parm [ 'arg' ][ 0 ]) ? true : false ; //to boolean
2009-09-25 20:13:47 +00:00
$params = array ( $val ); //value is always the first callback argument
$params += $parm [ 'arg' ];
break ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
//USAGE: {NEWS_FIELD=body|format=html_truncate&arg=200,...} -> callback e107->html_truncate($value, 200, '...');
case 'html_truncate' :
$val = e107 :: getParser () -> toHTML ( $val , true );
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
//USAGE: {NEWS_FIELD=title|format=text_truncate&arg=100,...} -> callback e107->text_truncate($value, 200, '...');
case 'text_truncate' :
$method = $parm [ 'format' ];
$callback = e107 :: getParser ();
$params = array ( $val ); //value is always the first callback argument
$params = array_merge ( $params , explode ( ',' , $parm [ 'arg' ]));
break ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
//USAGE: {NEWS_FIELD=title|format=date} -> strftime($pref[shortdate], $value);
//USAGE: {NEWS_FIELD=title|format=date&arg=%Y} -> strftime('%Y', $value);
case 'date' :
$method = $parm [ 'format' ];
$callback = e107 :: getParser ();
$params = array ( $val ); //value is always the first callback argument
$params = array_merge ( $params , explode ( ',' , $parm [ 'arg' ]));
//should be done with date handler (awaiting for modifications)
return strftime ( varset ( $parm [ 'arg' ], e107 :: getPref ( 'shortdate' )), $val );
break ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
default :
return $val ;
break ;
2010-02-10 21:53:56 +00:00
2006-12-02 04:36:16 +00:00
}
2009-09-25 20:13:47 +00:00
return call_user_func_array ( array ( $callback , $method ), $params );
2006-12-02 04:36:16 +00:00
}
2009-09-25 20:13:47 +00:00
return $val ;
}
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
/**
* Shorthand getter for news fields
*
* @ param string $news_field name without the leading 'news_' prefix
* @ param mixed $default
* @ return mixed data
*/
2011-12-02 12:24:26 +00:00
public function field ( $news_field , $default = null )
2009-09-25 20:13:47 +00:00
{
return parent :: get ( 'news_' . $news_field , $default );
}
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
/**
* Load news item by id
*
* @ param integer $id
* @ param boolean $force
* @ return e_news_item
*/
2016-02-14 19:00:12 -08:00
public function load ( $id = null , $force = false )
2009-09-25 20:13:47 +00:00
{
2011-12-02 12:24:26 +00:00
$id = intval ( $id );
$nobody_regexp = " '(^|,)( " . str_replace ( " , " , " | " , e_UC_NOBODY ) . " )(,| $ )' " ;
2010-02-10 21:53:56 +00:00
2011-12-10 00:00:15 +00:00
$query = " SELECT n.*, u.user_id, u.user_name, u.user_customtitle, nc.category_name, nc.category_sef, nc.category_icon FROM #news AS n
2011-12-02 12:24:26 +00:00
LEFT JOIN #user AS u ON n.news_author = u.user_id
LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id
WHERE n . news_id = { $id } AND n . news_class REGEXP '".e_CLASS_REGEXP."' AND NOT ( n . news_class REGEXP " . $nobody_regexp . " )
AND n . news_start < " .time(). " AND ( n . news_end = 0 || n . news_end > " .time(). " ) " ;
2010-02-10 21:53:56 +00:00
2011-12-02 12:24:26 +00:00
$this -> setParam ( 'db_query' , $query );
parent :: load ( $id , $force );
2009-09-25 20:13:47 +00:00
return $this ;
}
}
2006-12-02 04:36:16 +00:00
2011-12-02 12:24:26 +00:00
class e_news_tree extends e_front_tree_model
2009-09-25 20:13:47 +00:00
{
2011-12-02 12:24:26 +00:00
protected $_db_table = 'news' ;
protected $_field_id = 'news_id' ;
protected $_cache_string = 'news_tree_' ;
2009-09-25 20:13:47 +00:00
/**
* Current tree news category id
*
2014-07-30 17:17:37 +03:00
* @ var integer | array
2009-09-25 20:13:47 +00:00
*/
protected $_current_category_id ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
/**
* Set current category Id
*
2014-07-30 17:17:37 +03:00
* @ param mixed $category_id
2009-09-25 20:13:47 +00:00
* @ return e_news_tree
*/
function setCurrentCategoryId ( $category_id )
{
2011-12-02 12:24:26 +00:00
$this -> _current_category_id = $category_id ;
2009-09-25 20:13:47 +00:00
return $this ;
}
2011-12-02 12:24:26 +00:00
public function getCurrentCategoryId ()
2009-09-25 20:13:47 +00:00
{
2011-12-02 12:24:26 +00:00
return $this -> _current_category_id ;
}
public function hasCurrentCategoryId ()
{
return $this -> _current_category_id !== null ;
2009-09-25 20:13:47 +00:00
}
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
/**
2011-12-02 12:24:26 +00:00
* Load tree by category id
2009-09-25 20:13:47 +00:00
*
2011-12-02 12:24:26 +00:00
* @ param integer $category_id
* @ param boolean $force
* @ param array $params DB query parameters
2009-09-25 20:13:47 +00:00
* @ return e_news_tree
*/
2011-12-02 12:24:26 +00:00
public function load ( $category_id = 0 , $force = false , $params = array ())
2009-09-25 20:13:47 +00:00
{
2011-12-02 12:24:26 +00:00
$category_id = intval ( $category_id );
if ( ! $this -> hasCurrentCategoryId () || $force ) $this -> setCurrentCategoryId ( $category_id );
$this -> setParam ( 'model_class' , 'e_news_item' )
-> setParam ( 'db_order' , vartrue ( $params [ 'db_order' ], 'news_datestamp DESC' ))
-> setParam ( 'db_limit' , vartrue ( $params [ 'db_limit' ], '0,10' ))
-> setParam ( 'db_where' , $category_id ? 'news_category=' . $category_id : '' )
-> setParam ( 'noCacheStringModify' , false );
return parent :: load ( $force );
2006-12-02 04:36:16 +00:00
}
2011-12-02 12:24:26 +00:00
2009-09-12 18:25:41 +00:00
/**
2011-12-02 12:24:26 +00:00
* Load joined tree by category id
2009-09-25 20:13:47 +00:00
*
2014-07-30 17:17:37 +03:00
* @ param mixed $category_id
2011-12-02 12:24:26 +00:00
* @ param boolean $force
* @ param array $params DB query parameters
2009-09-25 20:13:47 +00:00
* @ return e_news_tree
2009-09-12 18:25:41 +00:00
*/
2011-12-02 12:24:26 +00:00
public function loadJoin ( $category_id = 0 , $force = false , $params = array ())
2009-09-12 18:25:41 +00:00
{
2014-07-30 17:17:37 +03:00
if ( is_string ( $category_id ) && strpos ( $category_id , ',' ))
{
$category_id = array_map ( 'trim' , explode ( ',' , $category_id ));
}
if ( is_array ( $category_id ))
{
$category_id = array_map ( 'intval' , $category_id );
}
else $category_id = intval ( $category_id );
2011-12-02 12:24:26 +00:00
if ( ! $this -> hasCurrentCategoryId () || $force ) $this -> setCurrentCategoryId ( $category_id );
$where = vartrue ( $params [ 'db_where' ]);
if ( $category_id )
2009-09-13 16:37:18 +00:00
{
2014-07-30 17:17:37 +03:00
if ( is_array ( $category_id ))
{
$where .= ( $where ? ' AND ' : '' ) . ' n.news_category IN (' . implode ( ',' , $category_id ) . ')' ;
}
else $where .= ( $where ? ' AND ' : '' ) . ' n.news_category=' . $category_id ;
2009-09-13 16:37:18 +00:00
}
2011-12-02 12:24:26 +00:00
if ( $where ) $where = 'WHERE ' . $where ;
$this -> setParam ( 'model_class' , 'e_news_item' );
2013-03-21 15:52:27 +02:00
$db_order = vartrue ( $params [ 'db_order' ], 'n.news_datestamp DESC' );
2011-12-02 12:24:26 +00:00
$db_limit = vartrue ( $params [ 'db_limit' ], '0,10' );
2013-04-02 10:19:21 +03:00
$query = " SELECT SQL_CALC_FOUND_ROWS n.*, u.user_id, u.user_name, u.user_customtitle, nc.category_id, nc.category_name, nc.category_sef, nc.category_icon FROM #news AS n
2011-12-02 12:24:26 +00:00
LEFT JOIN #user AS u ON n.news_author = u.user_id
LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id
{ $where }
ORDER BY " . $db_order . " LIMIT " . $db_limit ;
$this -> setParam ( 'db_query' , $query );
return parent :: load ( $force );
2009-09-25 20:13:47 +00:00
}
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
/**
2011-12-02 12:24:26 +00:00
* Load active joined tree by category id
2009-09-25 20:13:47 +00:00
*
2014-07-30 17:17:37 +03:00
* @ param mixed $category_id
2011-12-02 12:24:26 +00:00
* @ param boolean $force
* @ param array $params DB query parameters
* @ return e_news_tree
2009-09-25 20:13:47 +00:00
*/
2011-12-02 12:24:26 +00:00
public function loadJoinActive ( $category_id = 0 , $force = false , $params = array ())
2009-09-25 20:13:47 +00:00
{
2011-12-02 12:24:26 +00:00
$where = vartrue ( $params [ 'db_where' ]);
$nobody_regexp = " '(^|,)( " . str_replace ( " , " , " | " , e_UC_NOBODY ) . " )(,| $ )' " ;
$time = time ();
2014-04-06 00:43:44 +02:00
$where .= ( $where ? ' AND ' : '' ) . " n.news_start < { $time } AND (n.news_end=0 || n.news_end> { $time } )
2011-12-02 12:24:26 +00:00
AND n . news_class REGEXP '".e_CLASS_REGEXP."' AND NOT ( n . news_class REGEXP " . $nobody_regexp . " )
" ;
2013-03-21 15:52:27 +02:00
$params [ 'db_where' ] = $where ;
2011-12-02 12:24:26 +00:00
return $this -> loadJoin ( $category_id , $force , $params );
2009-09-25 20:13:47 +00:00
}
2011-12-02 12:24:26 +00:00
2009-09-25 20:13:47 +00:00
/**
2011-12-02 12:24:26 +00:00
* Render Category tree
*
* @ param array $template
* @ param array $parms [ return , parsesc => 1 | 0 , mode => string ]
* @ param boolean $tablerender
* @ return string
2009-09-25 20:13:47 +00:00
*/
2011-12-02 12:24:26 +00:00
function render ( $template = array (), $parms = array (), $tablerender = true )
2009-09-25 20:13:47 +00:00
{
2011-12-02 12:24:26 +00:00
if ( ! $this -> hasTree ())
2009-09-12 18:25:41 +00:00
{
2011-12-02 12:24:26 +00:00
return '' ;
2009-09-12 18:25:41 +00:00
}
2010-02-10 21:53:56 +00:00
2011-12-02 12:24:26 +00:00
$ret = array ();
$tp = e107 :: getParser ();
$param [ 'current_action' ] = 'list' ;
// TODO more default parameters
$bullet = defined ( 'BULLET' ) ? THEME_ABS . 'images/' . BULLET : THEME_ABS . 'images/bullet2.gif' ;
$vars = new e_vars ( array (
'bullet' => $bullet ,
'total' => $this -> getTotal (),
'currentTotal' => count ( $this -> getTree ()),
));
$parser = e107 :: getParser ();
$batch = e107 :: getScBatch ( 'news' )
-> setScVar ( 'param' , $param );
2015-02-07 23:43:21 -08:00
$batch -> wrapper ( 'news_menu/latest' ); //@SecretR - Please FIXME, I'm lost in here. (Cam)
2011-12-02 12:24:26 +00:00
$i = 1 ;
2015-02-07 23:43:21 -08:00
2016-02-06 18:33:35 -08:00
$items = $this -> getTree ();
if ( ! empty ( $items ))
{
$start = $parser -> parseTemplate ( $template [ 'start' ], true , $vars ); // must be here in case {SETIMAGE} is present and used for items below.
}
foreach ( $items as $news )
2009-09-14 18:22:16 +00:00
{
2011-12-02 12:24:26 +00:00
$vars -> counter = $i ;
$batch -> setScVar ( 'news_item' , $news -> getData ());
2011-12-06 09:44:28 +00:00
$ret [] = $parser -> parseTemplate ( $template [ 'item' ], true , $batch , $vars );
2011-12-02 12:24:26 +00:00
$i ++ ;
2009-09-14 18:22:16 +00:00
}
2010-02-10 21:53:56 +00:00
2016-02-06 18:33:35 -08:00
if ( ! empty ( $items ))
{
$end = $parser -> parseTemplate ( $template [ 'end' ], true , $vars );
}
2011-12-02 12:24:26 +00:00
if ( $ret )
2009-09-25 20:13:47 +00:00
{
2016-02-06 18:33:35 -08:00
2011-12-02 12:24:26 +00:00
$separator = varset ( $template [ 'separator' ], '' );
2016-02-06 18:33:35 -08:00
$ret = $start . implode ( $separator , $ret ) . $end ;
2011-12-02 12:24:26 +00:00
$return = isset ( $parms [ 'return' ]) ? true : false ;
2010-02-10 21:53:56 +00:00
2011-12-02 12:24:26 +00:00
if ( $tablerender )
{
$caption = vartrue ( $parms [ 'caption' ]) ? defset ( $parms [ 'caption' ], $parms [ 'caption' ]) : LAN_NEWSLATEST_MENU_TITLE ; // found in plugins/news/languages/English.php
$mod = true === $tablerender ? 'news_latest_menu' : $tablerender ;
return e107 :: getRender () -> tablerender ( $caption , $ret , varset ( $parms [ 'mode' ], $mod ), $return );
}
2010-02-10 21:53:56 +00:00
2011-12-02 12:24:26 +00:00
if ( $return ) return $ret ;
echo $ret ;
2009-09-25 20:13:47 +00:00
}
2010-02-10 21:53:56 +00:00
2011-12-02 12:24:26 +00:00
return '' ;
2009-09-25 20:13:47 +00:00
}
}
2011-11-30 15:17:19 +00:00
class e_news_category_item extends e_front_model
2009-09-25 20:13:47 +00:00
{
2011-11-30 15:17:19 +00:00
protected $_db_table = 'news_category' ;
protected $_field_id = 'category_id' ;
2009-09-25 20:13:47 +00:00
/**
* Shorthand getter for news category fields
*
* @ param string $category_field name without the leading 'category_' prefix
* @ param mixed $default
* @ return mixed data
*/
2011-11-30 15:17:19 +00:00
public function cat ( $category_field , $default = null )
2009-09-25 20:13:47 +00:00
{
return parent :: get ( 'category_' . $category_field , $default );
}
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
public function sc_news_category_title ( $parm = '' )
{
2014-01-20 16:12:24 -08:00
if ( 'attribute' == $parm )
{
return e107 :: getParser () -> toAttribute ( $this -> cat ( 'name' ));
}
return e107 :: getParser () -> toHtml ( $this -> cat ( 'name' ), true , 'TITLE_PLAIN' );
2009-09-25 20:13:47 +00:00
}
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
public function sc_news_category_url ( $parm = '' )
{
2010-02-10 21:53:56 +00:00
2011-12-10 00:00:15 +00:00
$url = e107 :: getUrl () -> create ( 'news/list/category' , array ( 'id' => $this -> getId (), 'name' => $this -> cat ( 'sef' )));
2009-09-25 20:13:47 +00:00
switch ( $parm )
2009-09-14 18:22:16 +00:00
{
2009-09-25 20:13:47 +00:00
case 'link' :
return '<a href="' . $url . '" class="news-category">' . $this -> sc_news_category_title () . '</a>' ;
break ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
case 'link_icon' :
return '<a href="' . $url . '" class="news-category">' . $this -> sc_news_category_icon () . ' ' . $this -> sc_news_category_title () . '</a>' ;
break ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
default :
return $url ;
break ;
}
2009-09-14 18:22:16 +00:00
}
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
public function sc_news_category_link ()
2009-09-14 18:22:16 +00:00
{
2009-09-25 20:13:47 +00:00
return $this -> sc_news_category_url ( 'link' );
}
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
public function sc_news_category_icon ( $parm = '' )
{
2011-11-30 15:17:19 +00:00
if ( ! $this -> cat ( 'icon' ))
2009-09-14 18:22:16 +00:00
{
2009-09-25 20:13:47 +00:00
return '' ;
2009-09-14 18:22:16 +00:00
}
2011-11-30 15:17:19 +00:00
if ( strpos ( $this -> cat ( 'icon' ), '{' ) === 0 )
2009-09-14 18:22:16 +00:00
{
2011-11-30 15:17:19 +00:00
$src = e107 :: getParser () -> replaceConstants ( $this -> cat ( 'icon' ));
2009-09-14 18:22:16 +00:00
}
2010-02-10 21:53:56 +00:00
else
2009-09-14 18:22:16 +00:00
{
2011-11-30 15:17:19 +00:00
$src = e_IMAGE_ABS . 'icons/' . $this -> cat ( 'icon' );
2009-09-14 18:22:16 +00:00
}
2009-09-25 20:13:47 +00:00
switch ( $parm )
{
case 'src' :
return $src ;
break ;
case 'link' :
return '<a href="' . $this -> sc_news_category_url () . '" class="news-category" title="' . $this -> sc_news_category_title ( 'attribute' ) . '"><img src="' . $src . '" class="icon news-category" alt="' . $this -> sc_news_category_title ( 'attribute' ) . '" /></a>' ;
break ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
default :
return '<img src="' . $src . '" class="icon news-category" alt="' . $this -> sc_news_category_title ( 'attribute' ) . '" />' ;
break ;
}
}
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
public function sc_news_category_news_count ( $parm = '' )
{
if ( ! $this -> is ( 'category_news_count' ))
2009-09-14 18:22:16 +00:00
{
2009-09-25 20:13:47 +00:00
return '' ;
2009-09-14 18:22:16 +00:00
}
2011-11-30 15:17:19 +00:00
return ( string ) $this -> cat ( 'news_count' );
2009-09-14 18:22:16 +00:00
}
2010-02-10 21:53:56 +00:00
}
2009-09-25 20:13:47 +00:00
2011-11-30 15:17:19 +00:00
class e_news_category_tree extends e_front_tree_model
2009-09-25 20:13:47 +00:00
{
2011-11-30 15:17:19 +00:00
protected $_field_id = 'category_id' ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
/**
* Load category data from the DB
2010-02-10 21:53:56 +00:00
*
2009-09-25 20:13:47 +00:00
* @ param boolean $force
* @ return e_news_category_tree
*/
public function load ( $force = false )
{
2011-11-30 15:17:19 +00:00
$this -> setParam ( 'model_class' , 'e_news_category_item' )
-> setParam ( 'nocount' , true )
-> setParam ( 'db_order' , 'category_order ASC' )
-> setParam ( 'noCacheStringModify' , true )
-> setCacheString ( 'news_category_tree' )
-> setModelTable ( 'news_category' );
return parent :: load ( $force );
2009-09-25 20:13:47 +00:00
}
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
/**
* Load active categories only ( containing active news items )
2010-02-10 21:53:56 +00:00
*
2009-09-25 20:13:47 +00:00
* @ param boolean $force
* @ return e_news_category_tree
*/
public function loadActive ( $force = false )
{
2011-11-30 15:17:19 +00:00
2009-09-25 20:13:47 +00:00
$nobody_regexp = " '(^|,)( " . str_replace ( " , " , " | " , e_UC_NOBODY ) . " )(,| $ )' " ;
$time = time ();
2011-07-06 23:37:49 +00:00
2009-09-25 20:13:47 +00:00
$qry = "
SELECT COUNT ( n . news_id ) AS category_news_count , nc .* FROM #news_category AS nc
LEFT JOIN #news AS n ON n.news_category=nc.category_id
WHERE n . news_class REGEXP '".e_CLASS_REGEXP."' AND NOT ( n . news_class REGEXP " . $nobody_regexp . " )
AND n . news_start < " . $time . " AND ( n . news_end = 0 || n . news_end > " . $time . " )
GROUP BY nc . category_id
ORDER BY nc . category_order ASC
" ;
2011-11-30 15:17:19 +00:00
$this -> setParam ( 'model_class' , 'e_news_category_item' )
-> setParam ( 'db_query' , $qry )
-> setParam ( 'nocount' , true )
-> setParam ( 'db_debug' , false )
-> setCacheString ( true )
-> setModelTable ( 'news_category' );
$this -> setModelTable ( 'news_category' );
return parent :: load ( $force );
2006-12-02 04:36:16 +00:00
}
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
/**
* Render Category tree
2010-02-10 21:53:56 +00:00
*
2011-12-02 12:24:26 +00:00
* @ param array $template
2009-09-25 20:13:47 +00:00
* @ param array $parms [ return , parsesc => 1 | 0 , mode => string ]
* @ param boolean $tablerender
* @ return string
*/
2011-12-02 12:24:26 +00:00
function render ( $template = array (), $parms = array (), $tablerender = true )
2008-12-07 13:08:54 +00:00
{
2011-11-30 15:17:19 +00:00
if ( ! $this -> hasTree ())
2009-09-25 20:13:47 +00:00
{
return '' ;
}
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
$ret = array ();
$tp = e107 :: getParser ();
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
if ( ! isset ( $parms [ 'parsesc' ])) $parms [ 'parsesc' ] = true ;
$parsesc = $parms [ 'parsesc' ] ? true : false ;
2011-11-30 15:17:19 +00:00
$active = '' ;
if ( e_PAGE == 'news.php' )
{
$tmp = explode ( '.' , e_QUERY );
if ( vartrue ( $tmp [ 1 ])) $active = $tmp [ 1 ];
}
2011-12-02 12:24:26 +00:00
$bullet = defined ( 'BULLET' ) ? THEME_ABS . 'images/' . BULLET : THEME_ABS . 'images/bullet2.gif' ;
$obj = new e_vars ( array ( 'bullet' => $bullet ));
2011-11-30 15:17:19 +00:00
2009-09-25 20:13:47 +00:00
foreach ( $this -> getTree () as $cat )
{
2011-12-02 12:24:26 +00:00
$obj -> active = '' ;
2011-11-30 15:17:19 +00:00
if ( $active && $active == $cat -> getId ())
{
2011-12-02 12:24:26 +00:00
$obj -> active = ' active' ;
2011-11-30 15:17:19 +00:00
}
$ret [] = $cat -> toHTML ( $template [ 'item' ], $parsesc , $obj );
2009-09-25 20:13:47 +00:00
}
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
if ( $ret )
{
$separator = varset ( $template [ 'separator' ], '' );
2011-12-06 09:44:28 +00:00
$ret = $template [ 'start' ] . implode ( $separator , $ret ) . $template [ 'end' ];
2009-09-25 20:13:47 +00:00
$return = isset ( $parms [ 'return' ]) ? true : false ;
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
if ( $tablerender )
{
2009-10-09 15:06:44 +00:00
$caption = vartrue ( $parms [ 'caption' ]) ? defset ( $parms [ 'caption' ], $parms [ 'caption' ]) : LAN_NEWSCAT_MENU_TITLE ; // found in plugins/news/languages/English.php
$mod = true === $tablerender ? 'news_categories_menu' : $tablerender ;
return e107 :: getRender () -> tablerender ( $caption , $ret , varset ( $parms [ 'mode' ], $mod ), $return );
2009-09-25 20:13:47 +00:00
}
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
if ( $return ) return $ret ;
echo $ret ;
}
2010-02-10 21:53:56 +00:00
2009-09-25 20:13:47 +00:00
return '' ;
2006-12-02 04:36:16 +00:00
}
}