2006-12-02 04:36:16 +00:00
< ? php
/*
+ ----------------------------------------------------------------------------+
| e107 website system
|
2009-11-18 01:06:08 +00:00
| Copyright ( C ) 2008 - 2009 e107 Inc ( e107 . org )
2006-12-02 04:36:16 +00:00
| http :// e107 . org
2009-11-18 01:06:08 +00:00
|
2006-12-02 04:36:16 +00:00
|
| Released under the terms and conditions of the
| GNU General Public License ( http :// gnu . org ) .
|
| $Source : / cvs_backup / e107_0 . 8 / e107_plugins / blogcalendar_menu / blogcalendar_menu . php , v $
2010-02-10 18:18:01 +00:00
| $Revision $
| $Date $
| $Author $
2006-12-02 04:36:16 +00:00
+----------------------------------------------------------------------------+
| Based on code by : Thomas Bouve ( crahan @ gmx . net )
*/
if ( ! defined ( 'e107_INIT' )) { exit ; }
2021-09-04 15:06:19 +02:00
$parm = isset ( $parm ) && is_string ( $parm ) ? $parm : '' ;
2009-09-25 20:20:23 +00:00
$cString = 'nq_news_blogacalendar_menu_' . preg_replace ( '#[^\w]#' , '' , $parm );
$cached = e107 :: getCache () -> retrieve ( $cString );
2013-07-08 10:37:04 -07:00
2009-09-25 20:20:23 +00:00
if ( false === $cached )
2009-09-23 16:21:09 +00:00
{
2021-01-22 06:32:59 -08:00
$sql = e107 :: getDb ();
2009-09-25 20:20:23 +00:00
require_once ( e_PLUGIN . " blogcalendar_menu/calendar.php " );
require_once ( e_PLUGIN . " blogcalendar_menu/functions.php " );
2013-04-25 17:34:47 -07:00
2009-09-25 20:20:23 +00:00
// ------------------------------
// initialization + fetch options
// ------------------------------
2013-07-23 07:14:18 -07:00
$prefix = e_PLUGIN_ABS . " blogcalendar_menu " ;
2014-06-02 17:07:02 -07:00
$marray = e107 :: getDate () -> terms ( 'month' );
2009-09-25 20:20:23 +00:00
$pref [ 'blogcal_ws' ] = " monday " ;
// ----------------------------------------------
// get the requested and current date information
// ----------------------------------------------
list ( $cur_year , $cur_month , $cur_day ) = explode ( " " , date ( " Y n j " ));
2020-12-20 11:50:10 -08:00
if ( e_PAGE == 'news.php' && strpos ( e_QUERY , " day " ) !== false )
2009-09-23 16:21:09 +00:00
{
2011-11-26 18:17:42 +00:00
$tmp = explode ( " . " , e_QUERY );
// Core now support legacy queries - use just the old way
//$tmp = e107::getUrl()->parseRequest('core:news', 'main', urldecode(e_QUERY));
2009-09-25 20:20:23 +00:00
$item = $tmp [ 1 ];
$req_year = intval ( substr ( $item , 0 , 4 ));
$req_month = intval ( substr ( $item , 4 , 2 ));
// decide on the behaviour here, do we highlight
// the day being viewed? or only 'today'?
//$req_day = substr($item, 6, 2);
// if the requested year and month are the current, then add
// the current day to the mix so the calendar highlights it
if (( $req_year == $cur_year ) && ( $req_month == $cur_month ))
{
$req_day = $cur_day ;
}
else
{
$req_day = " " ;
}
2006-12-02 04:36:16 +00:00
}
2020-12-20 11:50:10 -08:00
elseif ( e_PAGE == 'news.php' && strpos ( e_QUERY , " month " ) !== false )
2009-09-23 16:21:09 +00:00
{
2011-11-26 18:17:42 +00:00
$tmp = explode ( " . " , e_QUERY );
// Core now support legacy queries - use just the old way
//$tmp = e107::getUrl()->parseRequest('core:news', 'main', urldecode(e_QUERY));
2009-09-25 20:20:23 +00:00
$item = $tmp [ 1 ];
$req_year = intval ( substr ( $item , 0 , 4 ));
$req_month = intval ( substr ( $item , 4 , 2 ));
// if the requested year and month are the current, then add
// the current day to the mix so the calendar highlights it
if (( $req_year == $cur_year ) && ( $req_month == $cur_month ))
{
$req_day = $cur_day ;
}
else
{
$req_day = " " ;
}
2009-09-23 16:21:09 +00:00
}
else
{
2009-09-25 20:20:23 +00:00
$req_year = $cur_year ;
$req_month = $cur_month ;
$req_day = $cur_day ;
2006-12-02 04:36:16 +00:00
}
2009-09-25 20:20:23 +00:00
// -------------------------------
// create the month selection item
// -------------------------------
2013-05-05 14:42:40 -07:00
2006-12-02 04:36:16 +00:00
2009-09-25 20:20:23 +00:00
// get all newsposts since the beginning of the year till now
// -------------------------------------------
// get links to all newsitems in current month
// -------------------------------------------
2013-04-25 17:34:47 -07:00
$month_start = mktime ( 0 , 0 , 0 , $req_month , 1 , $req_year );
$lastday = date ( " t " , $month_start );
$month_end = mktime ( 23 , 59 , 59 , $req_month , $lastday , $req_year );
2013-04-26 18:19:54 -07:00
$start = mktime ( 0 , 0 , 0 , 1 , 1 , 1980 );
2013-04-25 17:34:47 -07:00
$end = time ();
$year_start = mktime ( 0 , 0 , 0 , 1 , 1 , $req_year );
$year_end = mktime ( 23 , 59 , 59 , 12 , 31 , $req_year );
2019-10-02 11:41:47 +02:00
$sql -> select ( " news " , " news_id, news_datestamp " , " news_class IN ( " . USERCLASS_LIST . " ) AND (FIND_IN_SET('0', news_render_type) OR FIND_IN_SET(1, news_render_type)) AND news_datestamp > " . intval ( $start ) . " AND news_datestamp < " . intval ( $end ));
2013-04-25 17:34:47 -07:00
$links = array ();
$months = array ();
2013-07-08 10:37:04 -07:00
while ( $news = $sql -> fetch ())
2006-12-02 04:36:16 +00:00
{
2009-09-25 20:20:23 +00:00
$xmonth = date ( " n " , $news [ 'news_datestamp' ]);
2013-04-26 18:19:54 -07:00
$xyear = date ( " Y " , $news [ 'news_datestamp' ]);
2021-12-03 14:58:33 -08:00
if ( empty ( $month_links [ $xmonth ]))
2009-09-25 20:20:23 +00:00
{
2018-09-04 17:10:03 -07:00
$month_links [ $xmonth ] = e107 :: getUrl () -> create ( 'news/list/month' , 'id=' . formatDate ( $xyear , $xmonth )); //e_BASE."news.php?month.".formatDate($req_year, $xmonth);
2009-09-25 20:20:23 +00:00
}
2013-06-17 16:03:33 -07:00
// if(($news['news_datestamp'] >= $month_start && $news['news_datestamp'] <= $month_end) || (deftrue('BOOTSTRAP') && $news['news_datestamp'] >= $year_start && $news['news_datestamp'] <= $year_end))
2006-12-02 04:36:16 +00:00
{
2009-09-25 20:20:23 +00:00
$xday = date ( " j " , $news [ 'news_datestamp' ]);
2014-02-04 03:03:45 -08:00
if ( ! isset ( $links [ $xyear ][ $xmonth ][ $xday ]))
2009-09-25 20:20:23 +00:00
{
2018-09-04 17:10:03 -07:00
$links [ $xyear ][ $xmonth ][ $xday ] = e107 :: getUrl () -> create ( 'news/list/day' , 'id=' . formatDate ( $xyear , $xmonth , $xday )); //e_BASE."news.php?day.".formatDate($req_year, $req_month, $xday);
2013-04-25 17:34:47 -07:00
2018-09-04 17:10:03 -07:00
$day_links [ $xday ] = e107 :: getUrl () -> create ( 'news/list/day' , 'id=' . formatDate ( $xyear , $xmonth , $xday )); //e_BASE."news.php?day.".formatDate($req_year, $req_month, $xday);
2009-09-25 20:20:23 +00:00
}
2006-12-02 04:36:16 +00:00
}
2013-04-25 17:34:47 -07:00
2013-04-26 18:19:54 -07:00
$months [ $xyear ][ $xmonth ] = 1 ;
2006-12-02 04:36:16 +00:00
}
2009-09-25 20:20:23 +00:00
// if we're listing the current year, add the current month to the list regardless of posts
if ( $req_year == $cur_year )
{
2011-11-26 18:17:42 +00:00
$month_links [ $cur_month ] = e107 :: getUrl () -> create ( 'news/list/month' , 'id=' . formatDate ( $cur_year , $cur_month )); //e_BASE."news.php?month.".formatDate($cur_year, $cur_month);
2009-09-25 20:20:23 +00:00
}
// go over the link array and create the option fields
2013-04-25 17:34:47 -07:00
2013-07-08 10:37:04 -07:00
if ( ! isset ( $months [ $cur_year ][ $cur_month ])) // display current month even if no links available.
{
$months [ $cur_year ][ $cur_month ] = 1 ;
}
2013-05-05 14:42:40 -07:00
2013-07-23 07:14:18 -07:00
2009-09-25 20:20:23 +00:00
// ------------------------
// create and show calendar
// ------------------------
2013-04-25 17:34:47 -07:00
/*
2009-09-25 20:20:23 +00:00
$menu = " <div style='text-align: center;'><table border='0' cellspacing='7'> " ;
$menu .= " <tr><td> $month_selector " ;
$menu .= " <div style='text-align:center'> " . calendar ( $req_day , $req_month , $req_year , $day_links , $pref [ 'blogcal_ws' ]) . " </div> " ;
$menu .= " <div class='forumheader' style='text-align: center; margin-top:2px;'><span class='smalltext'><a href=' $prefix /archive.php'> " . BLOGCAL_L2 . " </a></span></div></td></tr> " ;
$menu .= " </table></div> " ;
2013-04-25 17:34:47 -07:00
*/
2013-05-05 14:42:40 -07:00
2013-06-17 16:03:33 -07:00
if ( deftrue ( 'BOOTSTRAP' )) // v2.x
2013-04-25 17:34:47 -07:00
{
2021-01-02 12:06:46 -08:00
$month_selector = ' < span class = " btn-group pull-right float-right float-end " >< a class = " btn btn-mini btn-default btn-secondary btn-sm btn-xs " href = " #blogCalendar " data - slide = " prev " data - bs - slide = " prev " > ‹ </ a >
2021-01-01 09:33:51 -08:00
< a class = " btn btn-mini btn-default btn-secondary btn-sm btn-xs " href = " #blogCalendar " data - slide = " next " data - bs - slide = " next " > › </ a ></ span > ' ;
2013-05-05 14:42:40 -07:00
2021-04-16 13:43:26 -07:00
$caption = " <span class='inline-text'> " . defset ( 'BLOGCAL_L1' ) . " " . $month_selector . " </span> " ;
2013-05-05 14:42:40 -07:00
$menu = " <div id='blogCalendar' data-interval='false' class='carousel slide blogcalendar-block text-center'> " ;
$menu .= " <div class='blogcalendar-day-selector carousel-inner'> " ;
foreach ( $months as $year => $val )
{
foreach ( $val as $month => $v )
{
2016-02-13 11:54:24 -08:00
$menu .= calendar ( $req_day , $month , $year , varset ( $links [ $year ][ $month ], array ()), $pref [ 'blogcal_ws' ]);
2013-05-05 14:42:40 -07:00
}
}
$menu .= " </div> " ;
$menu .= " <div class='blogcalendar-archive-link' >
2021-01-02 09:43:54 -08:00
< a class = 'blogcalendar-archive-link btn btn-small btn-sm btn-primary' href = '$prefix/archive.php' > " .BLOGCAL_L2. " </ a >
2013-05-05 14:42:40 -07:00
</ div >
</ div > " ;
2013-04-25 17:34:47 -07:00
}
2013-05-05 14:42:40 -07:00
else // BC
2013-04-25 17:34:47 -07:00
{
2013-05-05 14:42:40 -07:00
$month_selector = " <div class='forumheader' style='text-align: center; margin-bottom: 2px;'> " ;
$month_selector .= " <select name='activate' onchange='urljump(this.options[selectedIndex].value)' class='tbox'> " ;
foreach ( $month_links as $index => $val )
2013-04-26 18:19:54 -07:00
{
2013-05-05 14:42:40 -07:00
$month_selector .= " <option value=' " . $val . " ' " ;
$month_selector .= ( $index == $req_month ) ? " selected='selected' " : " " ;
2017-04-06 11:02:54 -07:00
$month_selector .= " > " . $marray [ $index ] . " </option> " ;
2013-04-26 18:19:54 -07:00
}
2013-05-05 14:42:40 -07:00
$month_selector .= " </select></div> " ;
2013-05-05 16:49:19 -07:00
$menu = " <div class='blogcalendar-block' style='text-align: center; max-width: 100%; overflow: hidden;'>
< table class = 'blogcalendar-table' border = '0' cellspacing = '7' cellpadding = '0' > " ;
2013-05-05 14:42:40 -07:00
$menu .= " <tr><td class='blogcalendar-month-selector'> " . $month_selector ;
$menu .= " <div class='blogcalendar-day-selector' style='text-align:center'> " . calendar ( $req_day , $req_month , $req_year , $day_links , $pref [ 'blogcal_ws' ]) . " </div> " ;
$menu .= " <div class='forumheader blogcalendar-archive-link' style='text-align: center; margin-top:2px;'><span class='smalltext'><a class='blogcalendar-archive-link' href=' $prefix /archive.php'> " . BLOGCAL_L2 . " </a></span></div></td></tr> " ;
$menu .= " </table></div> " ;
2013-07-14 02:37:02 -07:00
$caption = " <span class='form-inline'> " . BLOGCAL_L1 . " " . $req_year . " </span> " ;
2013-04-25 17:34:47 -07:00
}
2013-05-05 14:42:40 -07:00
2013-04-25 17:34:47 -07:00
$cached = $ns -> tablerender ( $caption , $menu , 'blog_calendar' , true );
// echo "day= ".$req_day. " month=".$req_month." year=".$req_year." links=".print_a($day_links)." ws=".$pref['blogcal_ws'];
e107 :: getCache () -> set ( $cString , $menu );
2006-12-02 04:36:16 +00:00
2009-09-25 20:20:23 +00:00
}
echo $cached ;