1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 03:40:37 +02:00

Blog calendar menu was not functioning at all. Fixed. Bootstrap carousel enhancements added.

This commit is contained in:
Cameron
2013-04-25 17:34:47 -07:00
parent 9c720ef696
commit e624d32789
2 changed files with 145 additions and 50 deletions

View File

@@ -19,21 +19,21 @@
*/ */
if (!defined('e107_INIT')) { exit; } if (!defined('e107_INIT')) { exit; }
$cString = 'nq_news_blogacalendar_menu_'.preg_replace('#[^\w]#', '', $parm); $cString = 'nq_news_blogacalendar_menu_'.preg_replace('#[^\w]#', '', $parm);
$cached = e107::getCache()->retrieve($cString); $cached = e107::getCache()->retrieve($cString);
if(false === $cached) if(false === $cached)
{ {
require_once(e_PLUGIN."blogcalendar_menu/calendar.php"); require_once(e_PLUGIN."blogcalendar_menu/calendar.php");
require_once(e_PLUGIN."blogcalendar_menu/functions.php"); require_once(e_PLUGIN."blogcalendar_menu/functions.php");
// ------------------------------ // ------------------------------
// initialization + fetch options // initialization + fetch options
// ------------------------------ // ------------------------------
$prefix = e_PLUGIN."blogcalendar_menu"; $prefix = e_PLUGIN."blogcalendar_menu";
$marray = array(BLOGCAL_M1, BLOGCAL_M2, BLOGCAL_M3, BLOGCAL_M4, $marray = array(BLOGCAL_M1, BLOGCAL_M2, BLOGCAL_M3, BLOGCAL_M4, BLOGCAL_M5, BLOGCAL_M6, BLOGCAL_M7, BLOGCAL_M8, BLOGCAL_M9, BLOGCAL_M10, BLOGCAL_M11, BLOGCAL_M12);
BLOGCAL_M5, BLOGCAL_M6, BLOGCAL_M7, BLOGCAL_M8,
BLOGCAL_M9, BLOGCAL_M10, BLOGCAL_M11, BLOGCAL_M12);
$pref['blogcal_ws'] = "monday"; $pref['blogcal_ws'] = "monday";
// ---------------------------------------------- // ----------------------------------------------
@@ -98,12 +98,20 @@ if(false === $cached)
// ------------------------------------------- // -------------------------------------------
// get links to all newsitems in current month // get links to all newsitems in current month
// ------------------------------------------- // -------------------------------------------
$month_start = mktime(0, 0, 0, $req_month, 1, $req_year); $month_start = mktime(0, 0, 0, $req_month, 1, $req_year);
$lastday = date("t", $month_start); $lastday = date("t", $month_start);
$month_end = mktime(23, 59, 59, $req_month, $lastday, $req_year); $month_end = mktime(23, 59, 59, $req_month, $lastday, $req_year);
$start = mktime(0, 0, 0, 1, 1, $req_year); $start = mktime(0, 0, 0, 1, 1, $req_year);
$end = time(); $end = time();
$year_start = mktime(0, 0, 0, 1, 1, $req_year);
$year_end = mktime(23, 59, 59, 12, 31, $req_year);
$sql->db_Select("news", "news_id, news_datestamp", "news_class IN (".USERCLASS_LIST.") AND news_datestamp > ".intval($start)." AND news_datestamp < ".intval($end)); $sql->db_Select("news", "news_id, news_datestamp", "news_class IN (".USERCLASS_LIST.") AND news_datestamp > ".intval($start)." AND news_datestamp < ".intval($end));
$links = array();
$months = array();
while ($news = $sql->db_Fetch()) while ($news = $sql->db_Fetch())
{ {
$xmonth = date("n", $news['news_datestamp']); $xmonth = date("n", $news['news_datestamp']);
@@ -111,14 +119,18 @@ if(false === $cached)
{ {
$month_links[$xmonth] = e107::getUrl()->create('news/list/month', 'idv='.formatDate($req_year, $xmonth));//e_BASE."news.php?month.".formatDate($req_year, $xmonth); $month_links[$xmonth] = e107::getUrl()->create('news/list/month', 'idv='.formatDate($req_year, $xmonth));//e_BASE."news.php?month.".formatDate($req_year, $xmonth);
} }
if($news['news_datestamp'] >= $month_start AND $news['news_datestamp'] <= $month_end) if(($news['news_datestamp'] >= $month_start && $news['news_datestamp'] <= $month_end) || (deftrue('e_BOOTSTRAP') && $news['news_datestamp'] >= $year_start && $news['news_datestamp'] <= $year_end))
{ {
$xday = date("j", $news['news_datestamp']); $xday = date("j", $news['news_datestamp']);
if (!isset($day_links[$xday]) || !$day_links[$xday]) if (!isset($day_links[$xday]) || !$day_links[$xday])
{ {
$links[$xmonth][$xday] = e107::getUrl()->create('news/list/day', 'id='.formatDate($req_year, $xmonth, $xday));//e_BASE."news.php?day.".formatDate($req_year, $req_month, $xday);
$day_links[$xday] = e107::getUrl()->create('news/list/day', 'id='.formatDate($req_year, $xmonth, $xday));//e_BASE."news.php?day.".formatDate($req_year, $req_month, $xday); $day_links[$xday] = e107::getUrl()->create('news/list/day', 'id='.formatDate($req_year, $xmonth, $xday));//e_BASE."news.php?day.".formatDate($req_year, $req_month, $xday);
} }
} }
$months[$xmonth] = 1;
} }
// if we're listing the current year, add the current month to the list regardless of posts // if we're listing the current year, add the current month to the list regardless of posts
@@ -138,19 +150,55 @@ if(false === $cached)
// close the select item // close the select item
$month_selector .= "</select></div>"; $month_selector .= "</select></div>";
if(deftrue('e_BOOTSTRAP'))
{
$month_selector = '<div class="btn-group pull-right"><a class="btn btn-mini " href="#blogCalendar" data-slide="prev"></a>
<a class="btn btn-mini" href="#blogCalendar" data-slide="next"></a></div>';
$caption = "<div class='inline-text'>".BLOGCAL_L1." ".$req_year.$month_selector."</div>";
}
else
{
$caption = "<div class='form-inline'>".BLOGCAL_L1." ".$req_year."</div>";
}
// ------------------------ // ------------------------
// create and show calendar // create and show calendar
// ------------------------ // ------------------------
/*
$menu = "<div style='text-align: center;'><table border='0' cellspacing='7'>"; $menu = "<div style='text-align: center;'><table border='0' cellspacing='7'>";
$menu .= "<tr><td>$month_selector"; $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 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 .= "<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>"; $menu .= "</table></div>";
$cached = $ns->tablerender(BLOGCAL_L1." ".$req_year, $menu, 'blog_calendar', true); */
$menu = "<div id='blogCalendar' data-interval='false' class='carousel slide blogcalendar-block' style='text-align: center;'><table class='table blogcalendar-table' border='0' cellspacing='7'>";
$menu .= "<tr><td class='blogcalendar-month-selector'>"; // .$month_selector;
if(!defset('e_BOOTSTRAP')) // BC
{
$menu .= $month_selector;
}
$menu .= "<div class='blogcalendar-day-selector carousel-inner' style='text-align:center'>";
foreach($months as $k=>$v)
{
$menu .= calendar($req_day, $k, $req_year, $links[$k], $pref['blogcal_ws']);
}
$menu .= "</div>";
$menu .= "<div class='forumheader blogcalendar-archive-link' style='text-align: center; margin-top:2px;'><span class='smalltext'><a class='blogcalendar-archive-link btn btn-small' href='$prefix/archive.php'>".BLOGCAL_L2."</a></span></div>
</td></tr>";
$menu .= "</table></div>";
$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);
$cached = e107::getCache()->set($cString, $menu_text);
} }
echo $cached; echo $cached;

View File

@@ -17,85 +17,132 @@
| Based on code by: Thomas Bouve (crahan@gmx.net) and | Based on code by: Thomas Bouve (crahan@gmx.net) and
| and Based on: PHP Calendar by Keith Devens http://www.keithdevens.com/software/php_calendar/ | and Based on: PHP Calendar by Keith Devens http://www.keithdevens.com/software/php_calendar/
*/ */
if (!defined('e107_INIT')) { exit; } if (!defined('e107_INIT')) { exit; }
function calendar($req_day, $req_month, $req_year, $links = NULL, $ws = "sunday") { function calendar($req_day, $req_month, $req_year, $links = NULL, $ws = "sunday")
// get access to the preferences {
global $pref;
$pref = e107::getPref();
// prepare the day array // prepare the day array
$darray = array(BLOGCAL_D1, BLOGCAL_D2, BLOGCAL_D3, BLOGCAL_D4, $darray = array(BLOGCAL_D1, BLOGCAL_D2, BLOGCAL_D3, BLOGCAL_D4, BLOGCAL_D5, BLOGCAL_D6, BLOGCAL_D7);
BLOGCAL_D5, BLOGCAL_D6, BLOGCAL_D7); $marray = array('',BLOGCAL_M1, BLOGCAL_M2, BLOGCAL_M3, BLOGCAL_M4, BLOGCAL_M5, BLOGCAL_M6, BLOGCAL_M7, BLOGCAL_M8, BLOGCAL_M9, BLOGCAL_M10, BLOGCAL_M11, BLOGCAL_M12);
// what day does the week start on? // what day does the week start on?
switch($ws) { switch($ws)
{
case "monday": case "monday":
$ws = "1"; $ws = "1";
break; break;
case "sunday": case "sunday":
array_unshift($darray, array_pop($darray)); array_unshift($darray, array_pop($darray));
$ws = "0"; $ws = "0";
} }
// what's the padding we should use for the cells? // what's the padding we should use for the cells?
$padding = (isset($pref['blogcal_padding']) && $pref['blogcal_padding']) ? $pref['blogcal_padding']: "2"; $padding = (isset($pref['blogcal_padding']) && $pref['blogcal_padding']) ? $pref['blogcal_padding']: "2";
$date = mktime(0, 0, 0, $req_month, 1, $req_year); $date = mktime(0, 0, 0, $req_month, 1, $req_year);
$last_day = date('t', $date); $last_day = date('t', $date);
$date_info = getdate($date); $date_info = getdate($date);
$day_of_week = $date_info['wday']; $day_of_week = $date_info['wday'];
if ($ws && $day_of_week == 0) $day_of_week = 7;
if ($ws && $day_of_week == 0)
{
$day_of_week = 7;
}
// print the daynames // print the daynames
$calendar = "<table class='fborder'>"; $calendar = "<table class='table blogcalendar fborder'>";
$calendar .= '<tr>'; $calendar .= '<thead><tr>';
foreach($darray as $dheader) {
$calendar .= "<td class='forumheader' style='padding: ".$padding."px;'><span class='smalltext'>$dheader</span></td>"; foreach($darray as $dheader)
{
$calendar .= "<th class='forumheader blogcalendar-day-name'><span class='smalltext'>$dheader</span></th>";
} }
$calendar .= "</tr>";
$calendar .= "</tr>
</thead>
<tbody>";
$calendar .= '<tr>'; $calendar .= '<tr>';
$day_of_month = 1; $day_of_month = 1;
$tablerow = 1; $tablerow = 1;
// take care of the first "empty" days of the month // take care of the first "empty" days of the month
if ($day_of_week-$ws > 0) { if ($day_of_week-$ws > 0)
$calendar .= "<td colspan='"; {
$calendar .= "<td class='muted blogcalendar-day-empty' colspan='";
$calendar .= $day_of_week-$ws; $calendar .= $day_of_week-$ws;
$calendar .= "'>&nbsp;</td>"; $calendar .= "'>&nbsp;</td>";
} }
// print the days of the month (take the $ws into account) // print the days of the month (take the $ws into account)
while ($day_of_month <= $last_day) { while ($day_of_month <= $last_day)
if ($day_of_week-$ws == 7) { {
if ($day_of_week-$ws == 7)
{
#start a new week #start a new week
$calendar .= "</tr><tr>"; $calendar .= "</tr><tr>";
$day_of_week = 0+$ws; $day_of_week = 0+$ws;
$tablerow++; $tablerow++;
} }
if ($day_of_month == $req_day) {
$day_style = isset($links[$day_of_month]) ? "indent" : "forumheader3"; if ($day_of_month == $req_day)
} else { {
$day_style = isset($links[$day_of_month]) ? "indent" : "forumheader3"; $day_style = isset($links[$day_of_month]) ? "indent blogcalendar-day-active" : "forumheader3 blogcalendar-day";
} }
$calendar .= "<td class='$day_style' style='padding: ".$padding."px;'><span class='smalltext'>"; else
$calendar .= isset($links[$day_of_month]) ? "<a href='".$links[$day_of_month]."'>":""; {
$day_style = isset($links[$day_of_month]) ? "indent blogcalendar-day-active" : "forumheader3 blogcalendar-day";
}
$calendar .= "<td class='$day_style' ><span class='smalltext blogcalendar-day-link'>";
$calendar .= isset($links[$day_of_month]) ? "<a class='blogcalendar-day-link' href='".$links[$day_of_month]."'>":"";
$calendar .= $day_of_month; $calendar .= $day_of_month;
$calendar .= isset($links[$day_of_month]) ? "</a>" : ""; $calendar .= isset($links[$day_of_month]) ? "</a>" : "";
$calendar .= "</span></td>"; $calendar .= "</span></td>";
$day_of_month++; $day_of_month++;
$day_of_week++; $day_of_week++;
} }
if ($day_of_week-$ws != 7) {
$calendar .= '<td colspan="' . (7 - $day_of_week+$ws) . '">&nbsp;</td>'; if ($day_of_week-$ws != 7)
{
$calendar .= '<td class="blogcalendar-day-empty" colspan="' . (7 - $day_of_week+$ws) . '">&nbsp;</td>';
} }
$calendar .= "</tr>"; $calendar .= "</tr>";
if ($tablerow != 6) {
$calendar .= "<tr><td style='padding: ".$padding."px;' colspan='6'>&nbsp;</td></tr>"; if ($tablerow != 5)
{
$calendar .= "<tr><td class='blogcalendar-day-empty' style='padding: ".$padding."px;' colspan='6'>&nbsp;</td></tr>";
} }
$calendar .= "</table>"; $calendar .= "</tbody></table>";
return $calendar;
// $calendar .= "tablerow = ".$tablerow;
if(deftrue('e_BOOTSTRAP'))
{
$active = date("n") == $req_month ? 'active' : '';
$text = "<div class='item {$active}'>";
$text .= "<h5>".$marray[$req_month]." ".$req_year."</h5>";
$text .= $calendar;
$text .= "</div>";
}
else // BC
{
$text = $calendar;
}
return $text;
} }
?> ?>