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 ; }
2022-04-04 10:54:24 -07:00
/**
*
*/
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
2022-04-04 10:54:24 -07:00
/**
* @ param $news
* @ param $smessages
* @ return array
*/
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 ();
2020-12-22 09:36:02 -08:00
$admin_log = e107 :: getLog ();
2011-12-10 00:00:15 +00:00
$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 ;
2018-05-08 08:26:17 +02:00
$message = LAN_ERROR_47 ;
$emessage -> add ( LAN_ERROR_47 , 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 ;
2018-05-08 08:26:17 +02:00
$message = LAN_ERROR_48 ;
$emessage -> add ( LAN_ERROR_48 , E_MESSAGE_ERROR , $smessages );
2011-12-10 00:00:15 +00:00
}
2020-12-14 16:21:48 -08:00
elseif ( $sql -> count ( 'news' , '(news_id)' , ( $news [ 'news_sef' ] ? 'news_id<>' . intval ( $news [ 'news_id' ]) . ' AND ' : '' ) . " news_sef=' " . $tp -> toDB ( $news [ 'news_sef' ]) . " ' " ))
2011-12-10 00:00:15 +00:00
{
$error = true ;
2018-05-08 08:26:17 +02:00
$message = LAN_ERROR_49 ;
$emessage -> add ( LAN_ERROR_49 , 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 ;
2018-05-08 08:26:17 +02:00
$message = LAN_ERROR_50 ;
$emessage -> add ( LAN_ERROR_50 , E_MESSAGE_ERROR , $smessages );
2009-09-25 20:13:47 +00:00
}
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'])."' ";
2020-12-14 16:21:48 -08:00
if ( $sql -> update ( 'news' , $data ))
2009-08-21 13:20:36 +00:00
{
2011-07-06 23:37:49 +00:00
2020-12-22 09:36:02 -08:00
e107 :: getLog () -> addArray ( $logData ) -> save ( 'NEWS_09' );
2009-11-19 20:24:21 +00:00
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 ;
2022-12-10 07:06:47 -08:00
$emessage -> add ( defset ( 'LAN_UPDATED_FAILED' , " Update Failed " ), E_MESSAGE_ERROR , $smessages );
$message = " <strong> " . defset ( 'LAN_UPDATED_FAILED' , " Update Failed " ) . " </strong> " ;
2009-09-25 20:13:47 +00:00
}
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
2020-12-14 16:21:48 -08:00
$data [ 'data' ][ 'news_id' ] = $sql -> insert ( 'news' , $data );
2009-09-25 20:13:47 +00:00
$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' ];
2022-12-10 07:06:47 -08:00
$message = defset ( 'LAN_SAVED' , " Saved " );
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
2020-12-22 09:36:02 -08:00
e107 :: getLog () -> addArray ( $logData ) -> save ( 'NEWS_08' );
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 ;
2022-12-10 07:06:47 -08:00
$message = " <strong> " . defset ( 'LAN_CREATED_FAILED' ) . " </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
}
2022-04-04 10:54:24 -07:00
/**
* @ param $news
* @ param $mode
* @ param $n_restrict
* @ param $NEWS_TEMPLATE
* @ param $param
* @ return bool | string | null
*/
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' )
{
2020-02-10 12:01:38 -08:00
return null ;
2009-09-25 20:13:47 +00:00
}
}
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 ();
2021-12-03 14:58:33 -08:00
2017-06-05 14:35:25 -07:00
$tmp [ 'commentoffstring' ] = defset ( 'COMMENTOFFSTRING' , '' );
$tmp [ 'commentlink' ] = defset ( 'COMMENTLINK' , e107 :: getParser () -> toGlyph ( 'fa-comment' ));
2020-12-29 10:04:33 -08:00
/* $tmp [ 'trackbackstring' ] = defset ( 'TRACKBACKSTRING' );
2012-12-16 21:05:54 -08:00
$tmp [ 'trackbackbeforestring' ] = defset ( 'TRACKBACKBEFORESTRING' );
2020-12-29 10:04:33 -08:00
$tmp [ 'trackbackafterstring' ] = defset ( 'TRACKBACKAFTERSTRING' ); */
2012-12-16 21:05:54 -08:00
$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
{
2021-01-13 17:38:34 -08:00
/* if ( ! defined ( " IMAGE_nonew_small " ))
2009-09-25 20:13:47 +00:00
{
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='' /> " ));
2021-01-13 17:38:34 -08:00
} */
$param [ '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='' /> " );
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
{
2021-01-13 17:38:34 -08:00
/* if ( ! defined ( " IMAGE_new_small " ))
2009-09-25 20:13:47 +00:00
{
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='' /> " ));
}
2021-01-13 17:38:34 -08:00
*/
$param [ '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='' /> " );
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
{
2021-01-13 17:38:34 -08:00
/* if ( ! defined ( " IMAGE_sticky " ))
2009-09-25 20:13:47 +00:00
{
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' /> " ));
2021-01-13 17:38:34 -08:00
} */
$param [ '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' /> " );
2009-09-12 18:25:41 +00:00
}
2020-12-14 16:21:48 -08:00
e107 :: setRegistry ( 'current_news_item' , $news );
e107 :: setRegistry ( 'current_news_param' , $param );
2009-09-25 20:13:47 +00:00
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
{
2021-01-16 14:32:55 -08:00
$NEWS_PARSE = " { NEWSICON} <b> { NEWSTITLELINK}</b><div class='smalltext'> { NEWSAUTHOR} " . defset ( 'LAN_NEWS_300' , 'On' ) . " { 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
2017-09-23 14:08:47 -07:00
$wrapperKey = ( ! empty ( $param [ 'template_key' ])) ? $param [ 'template_key' ] . '/item' : 'news/view/item' ;
2016-03-10 15:13:32 -08:00
2016-05-31 13:04:05 -07:00
$editable = array (
'table' => 'news' ,
'pid' => 'news_id' ,
'vars' => 'news_item' ,
2016-11-15 12:33:16 -08:00
'perms' => 'H|H4' ,
2016-05-31 13:04:05 -07:00
'shortcodes' => array (
2016-05-31 17:44:07 -07:00
'news_title' => array ( 'field' => 'news_title' , 'type' => 'text' , 'container' => 'span' ),
2016-06-01 18:36:16 -07:00
'news_description' => array ( 'field' => 'news_meta_description' , 'type' => 'text' , 'container' => 'span' ),
2016-05-31 17:44:07 -07:00
'news_body' => array ( 'field' => 'news_body' , 'type' => 'html' , 'container' => 'div' ),
'news_summary' => array ( 'field' => 'news_summary' , 'type' => 'text' , 'container' => 'span' ),
2016-05-31 13:04:05 -07:00
)
);
2016-05-31 17:44:07 -07:00
2016-05-31 13:04:05 -07:00
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 )
2016-05-31 13:04:05 -07:00
-> setScVar ( 'param' , $param )
-> editable ( $editable );
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
2019-06-12 20:20:09 -07:00
if ( $mode == 'return' || ! empty ( $param [ 'return' ]))
2009-09-25 20:13:47 +00:00
{
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?
2022-04-04 10:54:24 -07:00
/**
* @ param $original
* @ return string
*/
2009-09-25 20:13:47 +00:00
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 );
}
2017-03-15 14:07:43 -07:00
/**
* Render a news Grid . ( currently used in news_grid_menu ) // new v2.1.5
2022-04-04 10:54:24 -07:00
* @ param array $parm = [
* 'caption' => ( string ) text or constant
* 'titleLimit' => ( integer ) number of chars fo news title
* 'summaryLimit' => ( integer ) number of chars for new summary
* 'source' => ( string ) latest ( latest news items ) | sticky ( news items ) | template ( assigned to news - grid layout )
* 'order' => ( integer ) n . news_datestamp DESC
* 'limit' => ( integer ) 10
* 'template' => ( string ) default | or any key as defined in news_grid_template . php
* ]
2017-03-15 14:07:43 -07:00
* @ return string
*/
function render_newsgrid ( $parm = null )
{
2021-01-08 09:56:33 -08:00
2017-03-15 14:07:43 -07:00
$cacheString = 'nq_news_grid_menu_' . md5 ( serialize ( $parm ));
$cached = e107 :: getCache () -> retrieve ( $cacheString );
if ( false === $cached )
{
2021-01-08 09:56:33 -08:00
e107 :: plugLan ( 'news' , null );
2017-03-15 14:07:43 -07:00
if ( is_string ( $parm ))
{
parse_str ( $parm , $parms );
}
else
{
$parms = $parm ;
e107 :: getDebug () -> log ( $parms );
}
if ( isset ( $parms [ 'caption' ][ e_LANGUAGE ]))
{
$parms [ 'caption' ] = $parms [ 'caption' ][ e_LANGUAGE ];
}
if ( ! empty ( $parms [ 'caption' ]) && defined ( $parms [ 'caption' ]))
{
$parms [ 'caption' ] = constant ( $parms [ 'caption' ]);
}
2019-06-03 16:46:40 -07:00
/** @var e_news_tree $ntree */
2017-03-15 14:07:43 -07:00
$ntree = e107 :: getObject ( 'e_news_tree' );
if ( $legacyTemplate = e107 :: getTemplate ( 'news' , 'news_menu' , 'grid' )) // BC
{
$template = $legacyTemplate ;
$parms [ 'tmpl' ] = 'news_menu' ;
$parms [ 'tmpl_key' ] = 'grid' ;
}
else // New in v2.1.5
{
$tmpl = ! empty ( $parms [ 'layout' ]) ? $parms [ 'layout' ] : 'col-md-4' ;
$template = e107 :: getTemplate ( 'news' , 'news_grid' , $tmpl );
$parms [ 'tmpl' ] = 'news_grid' ;
$parms [ 'tmpl_key' ] = $tmpl ;
}
2019-05-12 15:29:20 -07:00
if ( empty ( $parms [ 'mode' ]))
{
$parms [ 'mode' ] = 'news_grid_menu' ;
}
2017-03-15 14:07:43 -07:00
// $gridSize = vartrue($parms['layout'],'col-md-4');
$parmSrch = array (
'{NEWSGRID}' ,
'_titleLimit_' ,
'_summaryLimit_'
);
$parmReplace = array (
// $gridSize,
// vartrue($parms['titleLimit'], 0),
// vartrue($parms['summaryLimit'], 0)
);
$template = str_replace ( $parmSrch , '' , $template ); // clean up deprecated elements.
$render = ( empty ( $parms [ 'caption' ])) ? false : true ;
if ( empty ( $parms [ 'count' ]))
{
$parms [ 'count' ] = 3 ;
}
2020-02-10 12:01:38 -08:00
$parms [ 'order' ] = empty ( $parms [ 'order' ]) ? 'n.news_datestamp DESC' : $parms [ 'order' ];
2017-03-15 14:07:43 -07:00
$treeparm = array ();
if ( ! empty ( $parms [ 'count' ]))
{
$treeparm [ 'db_limit' ] = '0, ' . intval ( $parms [ 'count' ]);
}
if ( ! empty ( $parms [ 'limit' ]))
{
$treeparm [ 'db_limit' ] = '0, ' . intval ( $parms [ 'limit' ]);
}
if ( ! empty ( $parms [ 'order' ]))
{
2019-05-12 15:29:20 -07:00
$treeparm [ 'db_order' ] = e107 :: getParser () -> toDB ( $parms [ 'order' ]);
2017-03-15 14:07:43 -07:00
}
$parms [ 'return' ] = true ;
if ( varset ( $parms [ 'source' ]) == 'template' )
{
$treeparm [ 'db_where' ] = 'FIND_IN_SET(6, n.news_render_type)' ;
}
if ( varset ( $parms [ 'source' ]) == 'sticky' )
{
$treeparm [ 'db_where' ] = 'n.news_sticky=1' ;
}
$cached = $ntree -> loadJoinActive ( vartrue ( $parms [ 'category' ], 0 ), false , $treeparm ) -> render ( $template , $parms , $render );
e107 :: getCache () -> set ( $cacheString , $cached );
}
return $cached ;
}
2009-09-25 20:13:47 +00:00
}
//EXPERIMENTAL
require_once ( e_HANDLER . 'model_class.php' );
2022-04-04 10:54:24 -07:00
/**
*
*/
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' ;
2018-01-16 14:41:51 -08:00
protected $_cache_string = 'news_item_{ID}' ;
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 .
*
2022-04-04 10:54:24 -07:00
* @ param null $parm
2009-09-25 20:13:47 +00:00
* @ return string field value
*/
2020-12-05 14:13:18 -08:00
public function sc_news_field ( $parm = null )
2009-09-25 20:13:47 +00:00
{
$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
2020-12-05 14:13:18 -08:00
if ( ! empty ( $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)
2021-11-25 10:18:53 -08:00
return eShims :: strftime ( varset ( $parm [ 'arg' ], e107 :: getPref ( 'shortdate' )), $val );
2009-09-25 20:13:47 +00:00
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
2022-04-01 12:00:37 -07:00
$query = " SELECT n.*, u.user_id, u.user_name, u.user_customtitle, u.user_image, 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 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
2022-04-04 10:54:24 -07: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 ;
}
2022-04-04 10:54:24 -07:00
/**
* @ return array | int
*/
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 ;
}
2022-04-04 10:54:24 -07:00
/**
* @ return bool
*/
2011-12-02 12:24:26 +00:00
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
*
2021-01-14 10:30:22 -08:00
* @ param integer $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
*/
2021-01-14 10:30:22 -08:00
public function load ( $id = 0 , $force = false , $params = array ())
2009-09-25 20:13:47 +00:00
{
2021-01-14 10:30:22 -08:00
$id = intval ( $id );
if ( ! $this -> hasCurrentCategoryId () || $force ) $this -> setCurrentCategoryId ( $id );
2011-12-02 12:24:26 +00:00
$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' ))
2021-01-14 10:30:22 -08:00
-> setParam ( 'db_where' , $id ? 'news_category=' . $id : '' )
2011-12-02 12:24:26 +00:00
-> 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
2019-06-03 16:29:38 -07:00
* @ return e_news_tree | e_tree_model
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' );
2017-03-03 13:04:49 -08:00
$query = " SELECT SQL_CALC_FOUND_ROWS n.*, u.user_id, u.user_name, u.user_customtitle, u.user_image, 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 ;
2017-12-19 11:24:36 -08:00
2011-12-02 12:24:26 +00:00
$this -> setParam ( 'db_query' , $query );
2019-06-03 16:29:38 -07:00
return parent :: loadBatch ( $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 ;
2017-12-19 11:24:36 -08:00
$this -> _cache_string = null ; // disable sys cache, otherwise we get a new cache file every time the time() changes.
2013-03-21 15:52:27 +02:00
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
2017-09-25 15:43:24 -07:00
if ( is_string ( $template ) || empty ( $template ))
{
return " <div class='alert alert-danger'>Couldn't find template/layout with the following params: " . print_a ( $parms , true ) . " </div> " ;
}
2011-12-02 12:24:26 +00:00
$ret = array ();
$tp = e107 :: getParser ();
2017-09-25 15:43:24 -07:00
$start = '' ;
$end = '' ;
2017-02-13 18:14:26 -08:00
$param = $parms ;
2011-12-02 12:24:26 +00:00
$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 );
2016-04-09 16:12:08 -07:00
$wrapperKey = ( $parms [ 'tmpl' ] . '/' . $parms [ 'tmpl_key' ]);
$batch -> wrapper ( $wrapperKey );
2011-12-02 12:24:26 +00:00
$i = 1 ;
2015-02-07 23:43:21 -08:00
2016-04-09 16:12:08 -07:00
2016-02-06 18:33:35 -08:00
$items = $this -> getTree ();
if ( ! empty ( $items ))
{
2019-01-26 10:28:08 -08:00
/** @var e_tree_model $news */
2017-02-12 09:09:11 -08:00
foreach ( $items as $news )
{
$d = $news -> toArray ();
$batch -> setScVar ( 'news_item' , $d ); // set news category.
break ;
}
$start = $parser -> parseTemplate ( $template [ 'start' ], true , $batch , $vars ); // must be here in case {SETIMAGE} is present and used for items below.
2016-02-06 18:33:35 -08:00
}
2017-02-06 19:27:23 -08:00
$featuredCount = ! empty ( $parms [ 'featured' ]) ? intval ( $parms [ 'featured' ]) : 0 ;
2016-02-06 18:33:35 -08:00
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 ());
2017-02-06 19:27:23 -08:00
$tmpl = ( isset ( $template [ 'featured' ]) && $i <= $featuredCount ) ? 'featured' : 'item' ;
$ret [] = $parser -> parseTemplate ( $template [ $tmpl ], 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
2017-03-29 13:56:53 -07:00
if ( ! empty ( $parms [ 'caption' ][ e_LANGUAGE ]))
{
$caption = $parms [ 'caption' ][ e_LANGUAGE ];
}
2011-12-02 12:24:26 +00:00
$mod = true === $tablerender ? 'news_latest_menu' : $tablerender ;
2019-06-16 13:45:05 -07:00
return e107 :: getRender () -> tablerender ( $caption , $ret , varset ( $parms [ 'mode' ], $mod ), $return );
2011-12-02 12:24:26 +00:00
}
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
}
}
2022-04-04 10:54:24 -07: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
2022-04-04 10:54:24 -07:00
/**
* @ param $parm
* @ return array | string
*/
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' ));
}
2019-02-26 12:22:36 -08:00
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
2022-04-04 10:54:24 -07:00
/**
* @ param $parm
* @ return string
*/
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
2022-04-04 10:54:24 -07:00
/**
* @ return string
*/
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
2022-04-04 10:54:24 -07:00
/**
* @ param $parm
* @ return array | string
*/
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
2022-04-04 10:54:24 -07:00
/**
* @ param $parm
* @ return string
*/
2019-06-20 11:33:05 -07:00
public function sc_news_category_news_count ( $parm = null )
2009-09-25 20:13:47 +00:00
{
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
}
2017-11-09 10:15:36 -08:00
if ( $parm === 'raw' )
{
return ( string ) $this -> cat ( 'news_count' );
}
2019-06-20 11:33:05 -07:00
return ( string ) e107 :: getParser () -> toBadge ( $this -> cat ( 'news_count' ), $parm );
2009-09-14 18:22:16 +00:00
}
2010-02-10 21:53:56 +00:00
}
2009-09-25 20:13:47 +00:00
2022-04-04 10:54:24 -07: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
2019-06-03 16:29:38 -07:00
* @ return e_tree_model
2009-09-25 20:13:47 +00:00
*/
2019-06-03 16:29:38 -07:00
public function loadBatch ( $force = false )
2009-09-25 20:13:47 +00:00
{
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' );
2019-06-03 16:29:38 -07:00
return parent :: loadBatch ( $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
2019-01-26 10:28:08 -08:00
* @ return e_tree_model | e_news_category_tree
2009-09-25 20:13:47 +00:00
*/
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' );
2019-06-03 16:29:38 -07:00
return parent :: loadBatch ( $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
2017-02-06 19:27:23 -08: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 );
2020-07-03 13:49:12 -07:00
if ( ! empty ( $tmp [ 1 ])) $active = $tmp [ 1 ];
2011-11-30 15:17:19 +00:00
}
2011-12-02 12:24:26 +00:00
$bullet = defined ( 'BULLET' ) ? THEME_ABS . 'images/' . BULLET : THEME_ABS . 'images/bullet2.gif' ;
2020-07-03 13:49:12 -07:00
$obj = new e_vars ( array ( 'BULLET' => $bullet ));
2017-02-06 19:27:23 -08:00
2019-01-26 10:28:08 -08:00
/** @var e_tree_model $cat */
2009-09-25 20:13:47 +00:00
foreach ( $this -> getTree () as $cat )
{
2020-07-03 13:49:12 -07:00
$obj -> ACTIVE = '' ;
2011-11-30 15:17:19 +00:00
if ( $active && $active == $cat -> getId ())
{
2020-07-03 13:49:12 -07:00
$obj -> ACTIVE = ' active' ;
2011-11-30 15:17:19 +00:00
}
2017-02-06 19:27:23 -08:00
2011-11-30 15:17:19 +00:00
$ret [] = $cat -> toHTML ( $template [ 'item' ], $parsesc , $obj );
2017-02-06 19:27:23 -08:00
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
2017-03-29 13:56:53 -07:00
if ( ! empty ( $parms [ 'caption' ][ e_LANGUAGE ]))
{
$caption = $parms [ 'caption' ][ e_LANGUAGE ];
}
2009-10-09 15:06:44 +00:00
$mod = true === $tablerender ? 'news_categories_menu' : $tablerender ;
2019-06-16 13:45:05 -07:00
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
}
}