2011-12-02 12:22:33 +00:00
< ? php
/**
* Copyright ( C ) 2008 - 2011 e107 Inc ( e107 . org ), Licensed under GNU GPL ( http :// www . gnu . org / licenses / gpl . txt )
* $Id $
*
* News by month menu
*/
if ( ! defined ( 'e107_INIT' )) { exit ; }
2016-02-08 13:54:44 -08:00
$cString = 'nq_news_months_menu_' . md5 ( serialize ( $parm ));
2011-12-02 12:22:33 +00:00
$cached = e107 :: getCache () -> retrieve ( $cString );
2015-04-01 23:02:17 -07:00
if ( ! empty ( $parm ))
{
2016-02-08 13:54:44 -08:00
if ( is_string ( $parm ))
{
parse_str ( $parm , $parms );
}
else
{
$parms = $parm ;
}
2015-04-01 23:02:17 -07:00
}
2016-06-01 18:36:16 -07:00
$cached = false ;
2015-04-01 23:02:17 -07:00
2011-12-02 12:22:33 +00:00
if ( false === $cached )
{
if ( ! function_exists ( 'newsFormatDate' ))
{
function newsFormatDate ( $year , $month , $day = " " ) {
$date = $year ;
$date .= ( strlen ( $month ) < 2 ) ? " 0 " . $month :
$month ;
$date .= ( strlen ( $day ) < 2 && $day != " " ) ? " 0 " . $day :
$day ;
return $date ;
}
}
2015-04-01 23:02:17 -07:00
if ( ! isset ( $parms [ 'showarchive' ]))
{
$parms [ 'showarchive' ] = 0 ;
}
2011-12-02 12:22:33 +00:00
2015-03-29 20:34:17 -07:00
// e107::lan('blogcalendar_menu', e_LANGUAGE); // FIXME decide on language file structure (#743)
e107 :: includeLan ( e_PLUGIN . 'blogcalendar_menu/languages/English.php' );
2011-12-02 12:22:33 +00:00
$tp = e107 :: getParser ();
$sql = e107 :: getDb ();
2014-06-03 11:29:11 +02:00
$marray = e107 :: getDate () -> terms ( 'month' );
2011-12-02 12:22:33 +00:00
2015-04-01 23:02:17 -07:00
2011-12-02 12:22:33 +00:00
//$parms['year'] = "2011 0";
2011-12-06 09:44:28 +00:00
if ( vartrue ( $parms [ 'year' ]))
2011-12-02 12:22:33 +00:00
{
$date = $parms [ 'year' ];
list ( $cur_year , $cur_month ) = explode ( " " , date ( $date ));
$start = mktime ( 0 , 0 , 0 , 1 , 1 , $cur_year );
$end = mktime ( 23 , 59 , 59 , 12 , 31 , $cur_year );
}
else
2014-06-03 11:29:11 +02:00
{
2011-12-02 12:22:33 +00:00
$date = " Y n " ;
list ( $cur_year , $cur_month ) = explode ( " " , date ( $date ));
$start = mktime ( 0 , 0 , 0 , 1 , 1 , $cur_year );
$end = time ();
}
$req_year = $cur_year ;
if ( e_PAGE == 'news.php' && strstr ( e_QUERY , " month " ))
{
$tmp = explode ( '.' , e_QUERY );
$item = $tmp [ 1 ];
$req_month = intval ( substr ( $item , 4 , 2 ));
$req = 'month' ;
}
else
{
$req_month = $cur_month ;
}
$xmonth_cnt = array ();
$month_links = array ();
$sql -> db_Mark_Time ( 'News months menu' );
2016-06-01 18:36:16 -07:00
if ( ! $sql -> select ( " news " , " news_id, news_datestamp " , " news_class IN ( " . USERCLASS_LIST . " ) AND news_datestamp > " . intval ( $start ) . " AND news_datestamp < " . intval ( $end ) . " ORDER BY news_datestamp DESC " ))
2011-12-02 12:22:33 +00:00
{
e107 :: getCache () -> set ( $cString , '' );
return '' ;
}
2016-06-01 18:36:16 -07:00
while ( $news = $sql -> fetch ())
2011-12-02 12:22:33 +00:00
{
$xmonth = date ( " n " , $news [ 'news_datestamp' ]);
if (( ! isset ( $month_links [ $xmonth ]) || ! $month_links [ $xmonth ]))
{
$xmonth_cnt [ $xmonth ] = 0 ;
$month_links [ $xmonth ] = e107 :: getUrl () -> create ( 'news/list/month' , 'id=' . newsFormatDate ( $req_year , $xmonth ));
}
$xmonth_cnt [ $xmonth ] ++ ;
}
2016-06-01 18:36:16 -07:00
e107 :: getDebug () -> log ( $month_links );
2011-12-02 12:22:33 +00:00
// go over the link array and create the option fields
$menu_text = array ();
$template = e107 :: getTemplate ( 'news' , 'news_menu' , 'months' );
$bullet = defined ( 'BULLET' ) ? THEME_ABS . 'images/' . BULLET : THEME_ABS . 'images/bullet2.gif' ;
$vars = new e_vars ( array ( 'bullet' => $bullet ));
foreach ( $month_links as $index => $val )
{
$vars -> addData ( array (
'active' => $index == $req_month ? " active " : '' ,
'url' => $val ,
'month' => $marray [ $index - 1 ],
'count' => $xmonth_cnt [ $index ],
));
$menu_text [] = $tp -> simpleParse ( $template [ 'item' ], $vars );
}
2016-03-13 00:16:08 -08:00
$cached = $template [ 'start' ] . implode ( varset ( $template [ 'separator' ], '' ), $menu_text ) . $template [ 'end' ];
2011-12-02 12:22:33 +00:00
if ( $cached )
{
2012-12-16 14:28:30 -08:00
if ( ! $parms [ 'showarchive' ]) $cached .= '<ul class="nav nav-list e-menu-link news-menu-archive"><li><a href="' . e_PLUGIN_ABS . 'blogcalendar_menu/archive.php">' . BLOGCAL_L2 . '</a></li></ul>' ;
2014-08-26 18:47:36 +02:00
$cached = $ns -> tablerender ( BLOGCAL_L1 . " " . $req_year , $cached , 'news_months_menu' , true );
2011-12-02 12:22:33 +00:00
}
e107 :: getCache () -> set ( $cString , $cached );
}
echo $cached ;