Code cleanup.
This commit is contained in:
parent
97b4ac60ac
commit
01aae41d74
@ -109,7 +109,7 @@ class CalendarView_Controller extends Controller {
|
|||||||
$calendar_breadcrumbs[1] = new Calendar_Breadcrumb($display_year, url::site("calendarview/calendar/" . $display_year . "/" . $display_user));
|
$calendar_breadcrumbs[1] = new Calendar_Breadcrumb($display_year, url::site("calendarview/calendar/" . $display_year . "/" . $display_user));
|
||||||
$calendar_breadcrumbs[2] = new Calendar_Breadcrumb(t(date("F", mktime(0, 0, 0, $display_month, $display_day, $display_year))), url::site("calendarview/month/" . $display_year . "/" . $display_user . "/" . $display_month));
|
$calendar_breadcrumbs[2] = new Calendar_Breadcrumb(t(date("F", mktime(0, 0, 0, $display_month, $display_day, $display_year))), url::site("calendarview/month/" . $display_year . "/" . $display_user . "/" . $display_month));
|
||||||
$calendar_breadcrumbs[3] = new Calendar_Breadcrumb($display_day, "");
|
$calendar_breadcrumbs[3] = new Calendar_Breadcrumb($display_day, "");
|
||||||
$template->set_global("breadcrumbs", $calendar_breadcrumbs);
|
$template->set_global("breadcrumbs", $calendar_breadcrumbs);
|
||||||
|
|
||||||
// Finish setting up and then display the page.
|
// Finish setting up and then display the page.
|
||||||
$template->set_global("children_count", $day_count);
|
$template->set_global("children_count", $day_count);
|
||||||
@ -181,10 +181,10 @@ class CalendarView_Controller extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set up breadcrumbs
|
// Set up breadcrumbs
|
||||||
$calendar_breadcrumbs[0] = new Calendar_Breadcrumb(item::root()->title, item::root()->url());
|
$calendar_breadcrumbs[0] = new Calendar_Breadcrumb(item::root()->title, item::root()->url());
|
||||||
$calendar_breadcrumbs[1] = new Calendar_Breadcrumb($display_year, url::site("calendarview/calendar/" . $display_year . "/" . $display_user));
|
$calendar_breadcrumbs[1] = new Calendar_Breadcrumb($display_year, url::site("calendarview/calendar/" . $display_year . "/" . $display_user));
|
||||||
$calendar_breadcrumbs[2] = new Calendar_Breadcrumb(t(date("F", mktime(0, 0, 0, $display_month, 1, $display_year))), "");
|
$calendar_breadcrumbs[2] = new Calendar_Breadcrumb(t(date("F", mktime(0, 0, 0, $display_month, 1, $display_year))), "");
|
||||||
$template->set_global("breadcrumbs", $calendar_breadcrumbs);
|
$template->set_global("breadcrumbs", $calendar_breadcrumbs);
|
||||||
|
|
||||||
// Finish setting up and then display the page.
|
// Finish setting up and then display the page.
|
||||||
$template->set_global("children_count", $day_count);
|
$template->set_global("children_count", $day_count);
|
||||||
|
@ -1,88 +1,89 @@
|
|||||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||||
|
|
||||||
class PHPCalendar_Core {
|
class PHPCalendar_Core {
|
||||||
// Month and year to use for calendaring
|
// Month and year to use for calendaring
|
||||||
protected $month;
|
protected $month;
|
||||||
protected $year;
|
protected $year;
|
||||||
protected $month_url;
|
protected $month_url;
|
||||||
|
|
||||||
// First Day of the Week (0 = Sunday, 1 = Monday, etc.).
|
// First Day of the Week (0 = Sunday, 1 = Monday, etc.).
|
||||||
protected $week_start = 1;
|
protected $week_start = 1;
|
||||||
|
|
||||||
// Events for the current month.
|
// Events for the current month.
|
||||||
protected $event_data = Array();
|
protected $event_data = Array();
|
||||||
|
|
||||||
public function __construct($month = NULL, $year = NULL, $url = NULL)
|
public function __construct($month = NULL, $year = NULL, $url = NULL)
|
||||||
{
|
{
|
||||||
empty($month) and $month = date('n'); // Current month
|
empty($month) and $month = date('n'); // Current month
|
||||||
empty($year) and $year = date('Y'); // Current year
|
empty($year) and $year = date('Y'); // Current year
|
||||||
|
|
||||||
// Set the month and year
|
// Set the month and year
|
||||||
$this->month = (int) $month;
|
$this->month = (int) $month;
|
||||||
$this->year = (int) $year;
|
$this->year = (int) $year;
|
||||||
$this->month_url = $url;
|
$this->month_url = $url;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
public function event($day_of_the_week, $event_url = NULL, $css_id = NULL, $custom_text = NULL)
|
||||||
|
{
|
||||||
|
$this->event_data += Array($day_of_the_week => Array($event_url, $css_id, $custom_text));
|
||||||
|
}
|
||||||
|
|
||||||
public function event($day_of_the_week, $event_url = NULL, $css_id = NULL, $custom_text = NULL) {
|
public function render()
|
||||||
$this->event_data += Array($day_of_the_week => Array($event_url, $css_id, $custom_text));
|
{
|
||||||
}
|
return $this->generate_calendar($this->year, $this->month, $this->event_data, 2, $this->month_url, $this->week_start, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
public function render()
|
# PHP Calendar (version 2.3), written by Keith Devens
|
||||||
{
|
# http://keithdevens.com/software/php_calendar
|
||||||
return $this->generate_calendar($this->year, $this->month, $this->event_data, 2, $this->month_url, $this->week_start, NULL);
|
# see example at http://keithdevens.com/weblog
|
||||||
}
|
# License: http://keithdevens.com/software/license
|
||||||
|
function generate_calendar($year, $month, $days = array(), $day_name_length = 3, $month_href = NULL, $first_day = 0, $pn = array())
|
||||||
|
{
|
||||||
|
$first_of_month = gmmktime(0,0,0,$month,1,$year);
|
||||||
|
#remember that mktime will automatically correct if invalid dates are entered
|
||||||
|
# for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998
|
||||||
|
# this provides a built in "rounding" feature to generate_calendar()
|
||||||
|
|
||||||
# PHP Calendar (version 2.3), written by Keith Devens
|
$day_names = array(); #generate all the day names according to the current locale
|
||||||
# http://keithdevens.com/software/php_calendar
|
for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400) #January 4, 1970 was a Sunday
|
||||||
# see example at http://keithdevens.com/weblog
|
$day_names[$n] = ucfirst(gmstrftime('%A',$t)); #%A means full textual day name
|
||||||
# License: http://keithdevens.com/software/license
|
|
||||||
function generate_calendar($year, $month, $days = array(), $day_name_length = 3, $month_href = NULL, $first_day = 0, $pn = array()){
|
|
||||||
$first_of_month = gmmktime(0,0,0,$month,1,$year);
|
|
||||||
#remember that mktime will automatically correct if invalid dates are entered
|
|
||||||
# for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998
|
|
||||||
# this provides a built in "rounding" feature to generate_calendar()
|
|
||||||
|
|
||||||
$day_names = array(); #generate all the day names according to the current locale
|
list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));
|
||||||
for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400) #January 4, 1970 was a Sunday
|
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
|
||||||
$day_names[$n] = ucfirst(gmstrftime('%A',$t)); #%A means full textual day name
|
$title = htmlentities(ucfirst($month_name)).' '.$year; #note that some locales don't capitalize month and day names
|
||||||
|
|
||||||
list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));
|
#Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03
|
||||||
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
|
@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
|
||||||
$title = htmlentities(ucfirst($month_name)).' '.$year; #note that some locales don't capitalize month and day names
|
if($p) $p = '<span class="calendar-prev">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
|
||||||
|
if($n) $n = ' <span class="calendar-next">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
|
||||||
|
$calendar = '<table class="calendar">'."\n".
|
||||||
|
'<td class="title" colspan="7" align="center">'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n."</td></tr>\n<tr>";
|
||||||
|
|
||||||
#Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03
|
if($day_name_length){ #if the day names should be shown ($day_name_length > 0)
|
||||||
@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
|
#if day_name_length is >3, the full name of the day will be printed
|
||||||
if($p) $p = '<span class="calendar-prev">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
|
foreach($day_names as $d)
|
||||||
if($n) $n = ' <span class="calendar-next">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
|
$calendar .= '<th abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
|
||||||
$calendar = '<table class="calendar">'."\n".
|
$calendar .= "</tr>\n<tr>";
|
||||||
'<td class="title" colspan="7" align="center">'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n."</td></tr>\n<tr>";
|
}
|
||||||
|
|
||||||
if($day_name_length){ #if the day names should be shown ($day_name_length > 0)
|
if($weekday > 0) $calendar .= '<td colspan="'.$weekday.'"> </td>'; #initial 'empty' days
|
||||||
#if day_name_length is >3, the full name of the day will be printed
|
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
|
||||||
foreach($day_names as $d)
|
if($weekday == 7){
|
||||||
$calendar .= '<th abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
|
$weekday = 0; #start a new week
|
||||||
$calendar .= "</tr>\n<tr>";
|
$calendar .= "</tr>\n<tr>";
|
||||||
}
|
}
|
||||||
|
if(isset($days[$day]) and is_array($days[$day])){
|
||||||
|
@list($link, $classes, $content) = $days[$day];
|
||||||
|
if(is_null($content)) $content = $day;
|
||||||
|
$calendar .= '<td'.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').
|
||||||
|
($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
|
||||||
|
}
|
||||||
|
else $calendar .= "<td class=\"day\">$day</td>";
|
||||||
|
}
|
||||||
|
if($weekday != 7) $calendar .= '<td colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
|
||||||
|
|
||||||
if($weekday > 0) $calendar .= '<td colspan="'.$weekday.'"> </td>'; #initial 'empty' days
|
return $calendar."</tr>\n</table>\n";
|
||||||
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
|
}
|
||||||
if($weekday == 7){
|
|
||||||
$weekday = 0; #start a new week
|
|
||||||
$calendar .= "</tr>\n<tr>";
|
|
||||||
}
|
|
||||||
if(isset($days[$day]) and is_array($days[$day])){
|
|
||||||
@list($link, $classes, $content) = $days[$day];
|
|
||||||
if(is_null($content)) $content = $day;
|
|
||||||
$calendar .= '<td'.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').
|
|
||||||
($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
|
|
||||||
}
|
|
||||||
else $calendar .= "<td class=\"day\">$day</td>";
|
|
||||||
}
|
|
||||||
if($weekday != 7) $calendar .= '<td colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
|
|
||||||
|
|
||||||
return $calendar."</tr>\n</table>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
@ -10,7 +10,7 @@
|
|||||||
while ($counter_months <12) {
|
while ($counter_months <12) {
|
||||||
print "<td>";
|
print "<td>";
|
||||||
|
|
||||||
$month_url = url::site("calendarview/month/" . $calendar_year . "/" . $calendar_user . "/" . $counter_months . "/");
|
$month_url = url::site("calendarview/month/" . $calendar_year . "/" . $calendar_user . "/" . $counter_months . "/");
|
||||||
$calendar = new PHPCalendar($counter_months, $calendar_year, $month_url);
|
$calendar = new PHPCalendar($counter_months, $calendar_year, $month_url);
|
||||||
|
|
||||||
// Figure out if any photos were taken for the current month.
|
// Figure out if any photos were taken for the current month.
|
||||||
@ -57,14 +57,7 @@
|
|||||||
->count();
|
->count();
|
||||||
}
|
}
|
||||||
if ($day_count > 0) {
|
if ($day_count > 0) {
|
||||||
$calendar->event($curr_day, url::site("calendarview/day/" . $calendar_year . "/" . $calendar_user . "/" . $counter_months . "/" . $curr_day));
|
$calendar->event($curr_day, url::site("calendarview/day/" . $calendar_year . "/" . $calendar_user . "/" . $counter_months . "/" . $curr_day));
|
||||||
/*
|
|
||||||
$calendar -> attach($calendar -> event()
|
|
||||||
-> condition('year', $calendar_year)
|
|
||||||
-> condition('month', $counter_months)
|
|
||||||
-> condition('day', $curr_day)
|
|
||||||
-> output(html::anchor(url::site("calendarview/day/" . $calendar_year . "/" . $calendar_user . "/" . $counter_months . "/" . $curr_day), $day_count)));
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
$curr_day++;
|
$curr_day++;
|
||||||
}
|
}
|
||||||
@ -90,13 +83,6 @@
|
|||||||
}
|
}
|
||||||
if ($day_count > 0) {
|
if ($day_count > 0) {
|
||||||
$calendar->event($MAX_DAYS, url::site("calendarview/day/" . $calendar_year . "/" . $calendar_user . "/" . $counter_months . "/" . $MAX_DAYS));
|
$calendar->event($MAX_DAYS, url::site("calendarview/day/" . $calendar_year . "/" . $calendar_user . "/" . $counter_months . "/" . $MAX_DAYS));
|
||||||
/*
|
|
||||||
$calendar -> attach($calendar -> event()
|
|
||||||
-> condition('year', $calendar_year)
|
|
||||||
-> condition('month', $counter_months)
|
|
||||||
-> condition('day', $MAX_DAYS)
|
|
||||||
-> output(html::anchor(url::site("calendarview/day/" . $calendar_year . "/" . $calendar_user . "/" . $counter_months . "/" . $MAX_DAYS), $day_count)));
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo $calendar->render();
|
echo $calendar->render();
|
||||||
@ -152,14 +138,7 @@
|
|||||||
->count();
|
->count();
|
||||||
}
|
}
|
||||||
if ($day_count > 0) {
|
if ($day_count > 0) {
|
||||||
$calendar->event($curr_day, url::site("calendarview/day/" . $calendar_year . "/" . $calendar_user . "/" . $counter_months . "/" . $curr_day));
|
$calendar->event($curr_day, url::site("calendarview/day/" . $calendar_year . "/" . $calendar_user . "/" . $counter_months . "/" . $curr_day));
|
||||||
/*
|
|
||||||
$calendar -> attach($calendar -> event()
|
|
||||||
-> condition('year', $calendar_year)
|
|
||||||
-> condition('month', $counter_months)
|
|
||||||
-> condition('day', $curr_day)
|
|
||||||
-> output(html::anchor(url::site("calendarview/day/" . $calendar_year . "/" . $calendar_user . "/" . $counter_months . "/" . $curr_day), $day_count)));
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
$curr_day++;
|
$curr_day++;
|
||||||
}
|
}
|
||||||
@ -182,14 +161,7 @@
|
|||||||
->count();
|
->count();
|
||||||
}
|
}
|
||||||
if ($day_count > 0) {
|
if ($day_count > 0) {
|
||||||
$calendar->event($MAX_DAYS, url::site("calendarview/day/" . $calendar_year . "/" . $calendar_user . "/" . $counter_months . "/" . $MAX_DAYS));
|
$calendar->event($MAX_DAYS, url::site("calendarview/day/" . $calendar_year . "/" . $calendar_user . "/" . $counter_months . "/" . $MAX_DAYS));
|
||||||
/*
|
|
||||||
$calendar -> attach($calendar -> event()
|
|
||||||
-> condition('year', $calendar_year)
|
|
||||||
-> condition('month', $counter_months)
|
|
||||||
-> condition('day', $MAX_DAYS)
|
|
||||||
-> output(html::anchor(url::site("calendarview/day/" . $calendar_year . "/" . $calendar_user . "/" . $counter_months . "/" . $MAX_DAYS), $day_count)));
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$counter_months++;
|
$counter_months++;
|
||||||
|
@ -96,9 +96,9 @@
|
|||||||
<?= $theme->header_bottom() ?>
|
<?= $theme->header_bottom() ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<? // The following code was modifed to allow module-defined breadcrumbs.
|
<? // The following code was modifed to allow module-defined breadcrumbs.
|
||||||
// Everything else in this file is a copy of the default page.html.php file.
|
// Everything else in this file is a copy of the default page.html.php file.
|
||||||
?>
|
?>
|
||||||
<? if (!empty($breadcrumbs)): ?>
|
<? if (!empty($breadcrumbs)): ?>
|
||||||
<ul class="g-breadcrumbs">
|
<ul class="g-breadcrumbs">
|
||||||
<? $i = 0 ?>
|
<? $i = 0 ?>
|
||||||
@ -108,17 +108,17 @@
|
|||||||
containing that photo. For now, we just do it for
|
containing that photo. For now, we just do it for
|
||||||
the immediate parent so that when you go back up a
|
the immediate parent so that when you go back up a
|
||||||
level you're on the right page. -->
|
level you're on the right page. -->
|
||||||
<? if ($breadcrumb->url) : ?>
|
<? if ($breadcrumb->url) : ?>
|
||||||
<a href="<?= $breadcrumb->url ?>"><?= html::purify($breadcrumb->title) ?></a>
|
<a href="<?= $breadcrumb->url ?>"><?= html::purify($breadcrumb->title) ?></a>
|
||||||
<? else : ?>
|
<? else : ?>
|
||||||
<?= html::purify($breadcrumb->title) ?>
|
<?= html::purify($breadcrumb->title) ?>
|
||||||
<? endif ?>
|
<? endif ?>
|
||||||
</li>
|
</li>
|
||||||
<? $i++ ?>
|
<? $i++ ?>
|
||||||
<? endforeach ?>
|
<? endforeach ?>
|
||||||
</ul>
|
</ul>
|
||||||
<? endif ?>
|
<? endif ?>
|
||||||
<? // End modified code ?>
|
<? // End modified code ?>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div id="bd">
|
<div id="bd">
|
||||||
|
Reference in New Issue
Block a user