|
Calendar addon modification
The difference is that when you change the month in the calendar, the image also changes to the first image of the month you browse to, and when you browse images, the months on the calendar change with the dates of the images. This addon works only for the horizontal style.
Works for me on pixelpost 1.4.3 and php 4.4.2
PHP Code:
<?php
$addon_name = "Simple Horizontal Calendar";
$addon_description = "A modification of the horizontal pixelpost calendar. Highlights days on which images are posted and will always show the month in which the currently viewed image was posted. This way no duplicate pages are generated.<br />
Uses the language-files for months and weekdays.<br />";
$addon_version = "1.0";
if($_GET['x'] == "") {
// use the language-variables from the active language file
$days = array("$lang_monday","$lang_tuesday","$lang_wednesday","$lang_thursday","$lang_friday","$lang_saturday","$lang_sunday");
$months = array("","$lang_january","$lang_february","$lang_march","$lang_april","$lang_may","$lang_june","$lang_july","$lang_august","$lang_september","$lang_october","$lang_november","$lang_december");
// Don't use calendar, if not actived in Admin-Panel / Options
if ($cfgrow['calendar'] == "No Calendar") {
$tpl = ereg_replace("<SITE_CALENDAR>"," ",$tpl);
}
if ($cfgrow['calendar'] == "Horizontal") {
// horizontal
$cal_hz = "";
$curr_month = $image_date_month;
if (substr($curr_month,0,1) == "0") {
$curr_month = substr($curr_month,1);
}
$curr_year = $image_date_year_full;
$total_days = array(0,31,28,31,30,31,30,31,31,30,31,30,31);
if (date("L", mktime(0,0,0,$curr_month,1,$curr_year))) {
$total_days[2] = 29;
}
// first day of month
$first_day_month = date("w", mktime(0,0,0,$curr_month,1,$curr_year));
$cal_hz .= "<table class='table-calendar' cellspacing='0'><tr>";
// print the calendar days
$day_count=1;
while ($day_count <= $total_days[$curr_month]) {
if ($day_count <= 9) {
$day_count = "0$day_count";
}
$thismonth = $curr_month;
if ($curr_month <= 9) {
$thismonth = "0$curr_month";
}
if ($day_count <= date("j") && $curr_year == date("Y") && $curr_month == date("n") OR ($curr_month < date("m") AND $curr_year <= date("Y"))) {
$class = "td-calendar-days";
} else {
$class = "td-calendar-days";
}
$image_search = "$curr_year-$thismonth-$day_count"; // correct queryformat to check if any image are present the current day
// search for image for this day
$link_start = "";
$link_end = "";
$dayimage = "false";
$query = mysql_query("select * from ".$pixelpost_db_prefix."pixelpost where (datetime like '$image_search%') and (datetime<='$cdate')");
while (list($img_id, $img_datetime, $img_headline, $img_body, $img_image) = mysql_fetch_row($query)) {
$dayimage = "true";
$curr_image_id = $img_id;
$curr_image_headline = $img_headline;
}
if ($dayimage == "true") {
$class = "td-calendar-days-imagefound";
$link_start = "<a href=\"/?showimage=$curr_image_id\" title=\"$curr_image_headline\">";
$link_end = "</a>";
}
$cal_hz .= "<td class=\"$class\">$link_start$day_count$link_end</td>";
$day_count++;
$row_count++;
}
$asc_month = $months[$curr_month];
$query = mysql_query("select datetime from ".$pixelpost_db_prefix."pixelpost where id = '1'");
$img_first_datetime = mysql_result($query,0);
$first_month = substr($img_first_datetime,5,2);
if (substr($first_month,0,1) == "0") {
$first_month = substr($first_month,1);
}
$first_year = substr($img_first_datetime,0,4);
if ($curr_year > $first_year || ($curr_year == $first_year && $curr_month > $first_month)) {
if ($curr_month == "1") {
$prev_month = "12";
$prev_year = $curr_year-1;
} else {
$prev_month = $curr_month-1;
$prev_year = $curr_year;
}
} else {
$prev_month = $curr_month;
$prev_year = $curr_year;
}
$query = mysql_query("select datetime from ".$pixelpost_db_prefix."pixelpost where datetime<='$cdate' order by datetime desc limit 0,1");
$img_last_datetime = mysql_result($query,0);
$last_month = substr($img_last_datetime,5,2);
if (substr($last_month,0,1) == "0") {
$last_month = substr($last_month,1);
}
$last_year = substr($img_last_datetime,0,4);
if ($curr_year < $last_year || ($curr_year == $last_year && $curr_month < $last_month)) {
if ($curr_month == "12") {
$next_month = "1";
$next_year = $curr_year+1;
} else {
$next_month = $curr_month+1;
$next_year = $curr_year;
}
} else {
$next_month = $curr_month;
$next_year = $curr_year;
}
while (!$prev_month_image_id) {
if (strlen($prev_month) == 1) {
$search = "$prev_year-0$prev_month-%";
} else {
$search = "$prev_year-$prev_month-%";
}
$result = mysql_query("select id,headline from ".$pixelpost_db_prefix."pixelpost where (datetime like '$search') order by datetime asc limit 0,1");
list($prev_month_image_id, $prev_month_image_headline) = mysql_fetch_row($result);
$prev_month--;
}
while (!$next_month_image_id) {
if (strlen($next_month) == 1) {
$search = "$next_year-0$next_month-%";
} else {
$search = "$next_year-$next_month-%";
}
$result = mysql_query("select id,headline from ".$pixelpost_db_prefix."pixelpost where (datetime like '$search') order by datetime asc limit 0,1");
list($next_month_image_id, $next_month_image_headline) = mysql_fetch_row($result);
$next_month++;
}
$cal_hz .= "</tr><tr><td colspan='31' class='td-calendar-navi'><a href=\"/?showimage=$prev_month_image_id\" title=\"vorige maand, eerste foto: $prev_month_image_headline\">«</a> $asc_month $curr_year <a href=\"/?showimage=$next_month_image_id\" title=\"volgende maand, eerste foto: $next_month_image_headline\">»</a></td>";
$cal_hz .= "</tr></table>";
$tpl = str_replace("<SITE_CALENDAR>",$cal_hz,$tpl);
}
}
?>
--
JvA fotoblog
Last edited by jvalph; 04-05-2006 at 07:49 PM.
|