Pixelpost

Authentic Photoblog Flavour


Go Back   Pixelpost Forum > DEVELOPMENT > Addons

Post Reply
 
Thread Tools
  #1  
Old 04-05-2006, 11:22 AM
jvalph Offline
forum loafer
 
Join Date: Feb 2006
Posts: 12
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\">&laquo;</a> $asc_month $curr_year <a href=\"/?showimage=$next_month_image_id\" title=\"volgende maand, eerste foto: $next_month_image_headline\">&raquo;</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.
Reply With Quote
  #2  
Old 04-22-2006, 11:45 AM
jvalph Offline
forum loafer
 
Join Date: Feb 2006
Posts: 12
I forgot to mention: because the curr_month and curr_year variables are no longer used, you don't get duplicate content because of the calendar, which some people might find usefull.
__________________
JvA fotoblog
Reply With Quote
  #3  
Old 04-25-2006, 08:23 AM
raminia's Avatar
raminia+ Offline
Team Pixelpost
 
Join Date: Jan 2005
Location: FL, US
Posts: 3,706
Send a message via Yahoo to raminia
please upload it to pixelpost.org/v1 in the developers section
__________________
Photoblog: http://pblog.raminia.com Powered by Pixelpost 1.7
Reply With Quote
  #4  
Old 05-23-2006, 11:25 AM
jdleung Offline
pixelpost guru
 
Join Date: Feb 2006
Location: Foshan, China
Posts: 553
Smile

good modification!
three suggestions:
1.the link "/?" should be replace with "$PHP_SELF?".
2.going to the last image of the month should fit for a blog.
3.adding a choice for displaying number-month.

one question:
the browser turns very very very slow after changing month and clicking 5-6 times on days, and then following the computer speed.

but I had tested on your website,it works well. updated?

Thanks.
__________________
jdleung's.com @ flickr @ fotoblogs.cn & Addons:Month Calendar & Slideshow & Flickr comment & Modified Addon: Calendar
Reply With Quote
Post Reply


Thread Tools




All times are GMT. The time now is 05:35 AM.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd. | Style Design: d3 designs