Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

  1. Index
  2. » Archives
  3. » Calendar?

#109 2005-04-17 20:57:15

theturninggate
Member
Registered: 2004-11-07
Posts: 185
Website

Re: Calendar?

koopd: I’ve made several hacks to this plugin to get it working with messy URLs. The only outstanding problem with the one I’ve notice in my previous post. Here’s the plugin code I’m using for messy URLs; just copy and paste it into the plugin edit window.

// Version 3.0

// To install smallformat properly:
// change line #435 of publish.php, where it says ‘{$month}%’ to be ‘$month%’ (remove the braces)
// instead of using article_custom or article_list on the page to display your article, use txp:mdp_calarticle.

// title attribute to links

include_once txpath.’/lib/mdp_lib.php’;

function mdp_calendar($atts)
{ fixOptions($atts,‘smallformat,displayfuture,static,class,id’); // Options and data $dates = mdp_calendar_calculateDates($atts); // dates $rows = mdp_calendar_sqlOperations($atts, $dates); // article data

// Format Calendar $id = (!empty($atts[‘id’]))? $atts[‘id’] : ‘calendar’; $classattri = (!empty($atts[‘class’]))? $atts[‘class’] : ‘mdp_calendar’; $classattri = ($atts[‘smallformat’]) ? ‘mdp_smallcalendar’ : $classattri;

$output[] = ‘<table id=”’.$id.’” class=”’.$classattri.’”>’; // open the table $output[] = mdp_calendar_tableHead($atts, $dates); // Create header cells $output[] = mdp_calendar_outputDates($rows, $dates, $atts); // create actual dates $output[] = “</table>”; // close the table

return implode(‘’,$output);
}

/* mdp_calendar_sqlOperations($atts, $dates) * Figures out options for posts to retrieve, properly adjusts Posted date for the time offset. * Returns array of $rows from “safe_rows()” */
function mdp_calendar_sqlOperations($atts, $dates)
{ $extrasql = “”; if(isset($atts[“category”])) { // category option $extrasql .= “ AND (Category1=’”.$atts[“category”].”’ OR Category2=’”.$atts[“category”].”’) “; } if(isset($atts[“section”])) { // section option $extrasql .= “ AND Section=’”.$atts[“section”].”’ “; } if(isset($atts[“author”])) { // author option $extrasql .= “ AND AuthorID=’”.$atts[“author”].”’ “; } $sql = “Posted BETWEEN FROM_UNIXTIME(‘”.$dates[‘start’].”’) AND FROM_UNIXTIME(‘”.$dates[‘end’].”’) AND Status=‘4’ “. $extrasql .” ORDER BY Posted ASC”; $rows = safe_rows(‘*’,‘textpattern’,$sql);

// go through each record and adjust the ‘Posted’ date by the timeoffset if($rows) { for($i = 0; $i < count($rows); $i++) { $ts = getOffsetTimestamp(strtotime($rows[$i][‘Posted’])); $rows[$i][‘fPosted’] = date(‘Y-m-d H:i:s’,$ts); //2004-04-11 16:38:00 (datetime) format } }

return $rows;
}

/* mdp_calendar_tableHead($atts,$dates) * Outputs the header cells for the table */
function mdp_calendar_tableHead($atts,$dates)
{ $datestamp = $dates[‘effective’][‘month’] .’ ‘. $dates[‘effective’][‘year’];

// Navigation links for static or navigation calendar if($atts[‘static’] == 1) { $backnav = $fwdnav = ‘’; $colspan = 7; } else { $backnav = hCell(‘<a href=”’.mdp_calendar_navlink($dates[‘effective’],0).’”><</a>’); if($atts[‘displayfuture’] || !$dates[‘inpresentmonth’]) { $fwdnav = hCell(‘<a href=”’.mdp_calendar_navlink($dates[‘effective’],1).’”>></a>’); } else { $fwdnav = hCell(); } $colspan = 5; }

/* Table Headers */ $output[] = tag($backnav.’<th colspan=”’.$colspan.’”>’.$datestamp.’</th>’.$fwdnav,‘tr’); $output[] = ‘<tr><th>S</th><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th></tr>’;

return implode(‘’,$output);
}

/* * Returns an keyed array * start -> starting date of our range * end -> ending date of our range * effective -> array of getDate for either current date or first day in other month/year */
function mdp_calendar_calculateDates($atts)
{ $date = getOffsetDate(); $curdate = getOffsetDate();

// Modify date to reflect navigation or nessecary static changes. if($atts[“static”] == 1) {// don’t let user navigate calendar // default values $t_mon = $curdate[‘mon’]; $t_year = $curdate[‘year’];

if(isset($atts[‘month’])) { $t_mon = $atts[‘month’]; } if(isset($atts[‘year’])) { $t_year = $atts[‘year’]; }

$d = mdp_calendar_validateMonthYear($t_mon,$t_year); $date = getOffsetDate(mktime(0,0,0,$d[“month”],1,$d[“year”])); // first day of the month } else { // allow user to navigate calendar // handle changing months and years if( (isset($_GET[“month”]) && isset($_GET[“year”])) || (isset($atts[“month”]) && isset($atts[“year”])) ) { // get variables override options (isset($_GET[“month”])) ? $t_mon = $_GET[“month”] : $t_mon = $atts[“month”]; (isset($_GET[“year”]) ) ? $t_year = $_GET[“year”] : $t_year = $atts[“year”];

$d = mdp_calendar_validateMonthYear($t_mon,$t_year); $date = getDate(mktime(0,0,0,$d[“month”],1,$d[“year”])); // first day of the month } // handle only month option if(isset($atts[“month”]) && !isset($_GET[“month”])) { $d = mdp_calendar_ValidateMonthYear($atts[“month”],$curdate[“year”]); $date = getDate(mktime(0,0,0,$d[‘month’],1,$d[‘year’])); // first day of the month } }

$end = mdp_calendar_ValidateMonthYear($date[“mon”] + 1, $date[“year”]); $startdate = mktime(0,0,0,$date[‘mon’],1,$date[‘year’]);

$inpresentmonth = ($date[‘mon’] $curdate['mon']) && ($date['year'] $curdate[‘year’]); if($atts[“displayfuture”] == 1 || !$inpresentmonth) { // entire month $enddate = mktime(0,0,0,$end[‘month’],1,$end[‘year’]); } else { // entire month up to but including current date $enddate = mktime(0,0,0,$curdate[‘mon’],$curdate[‘mday’]+1,$curdate[‘year’]); }

return array(‘start’=>$startdate, ‘end’=>$enddate, ‘effective’=>$date, ‘inpresentmonth’=>$inpresentmonth);
}

/* mdp_calendar_createValidateMonthYear($month, $year) * Converts 13/2003 to 1/2004 and -1/2003 to 12/2002 * Returns keyed array: month -> new month, year -> new year. */
function mdp_calendar_ValidateMonthYear($month, $year)
{ if(! checkdate($month,01,$year) ) { if($month > 12) { $month -= 12; $year++; } if($month < 1) { $month = 12; $year—; } } return array(‘month’=>$month,‘year’=>$year);
}

function mdp_calendar_outputDates($rows, $dates, $atts)
{ $week_count = 0;

/* Figure out how many days in the month, and first day */ $daysinmonth = date(‘t’,$dates[‘start’]); $firstdayinmonth = getOffsetDate($dates[‘start’]); $today = getOffsetDate();

$output[] = mdp_calendar_invalidDays(0, $firstdayinmonth[‘wday’]); $week_count = $firstdayinmonth[‘wday’];

// Actual days in the month for($day = 1; $day <= $daysinmonth; $day++) { if($atts[“smallformat”] == 1) { $atts[‘month’] = $firstdayinmonth[‘mon’]; $atts[‘year’] = $firstdayinmonth[‘year’]; $info[] = mdp_calendar_specificDate($rows, $day, $atts); // articles for each day } else { $info[] = ‘<div class=“date”>’.$day.’</div>’; $info[] = mdp_calendar_specificDate($rows, $day, $atts); // articles for each day }

$output[] = mdp_calendar_outputDateCell(implode(‘’,$info), $day, $today, $dates, $atts); $info = NULL;

/* New row for each week */ if($week_count == 6) { $tablerows[] = tag(implode(‘’,$output),‘tr’); $week_count = 0; $output = NULL;} else { $week_count++; } }

// zero fill the rest of the dates if($week_count != 0) { // stops from outputting an entire empty row $output[] = mdp_calendar_invalidDays($week_count, 7); $tablerows[] = tag(implode(‘’,$output),‘tr’); }

return implode(‘’,$tablerows);
}

/*
mdp_calendar_outputDateCell

$info = string returned from specificDate
$day = current day of the calendar
$today = current date
$dates = date array returned by calculateDates
$atts = TXP attributes

Returns the table cell for $day
*/
function mdp_calendar_outputDateCell($info, $day, $today, $dates, $atts)
{ $cellclass = $todayid = ‘’;

if( strpos($info,’ ‘) === false ) { $cellclass = ‘hasarticle’; }

if( $atts[‘smallformat’] == 1 && $info0 != “<” ) { $cellclass = ‘’; }

if($day == $today[‘mday’] && $dates[‘inpresentmonth’]) { $todayid = ‘today’; }

return td($info,’‘,$cellclass,$todayid);
}

// Added by Manfre 2004-06-10 http://www.manfre.net/
// Makes easy
function formatEventHref($pfr,$Section,$Date,$Linktext,$class=”“)
{ global $url_mode; $class = ($class) ? ‘ class=”’.$class.’”’ :’‘; return ($url_mode==1) ? ‘<a href=”’.$pfr.$Section.’/?date=’.$Date.’”’. $class.’ title=”’.$Date.’”>’.$Linktext.’</a>’ : ‘<a href=”’.$pfr.‘index.php?s=’.$Section.’&date=’.$Date.’&month=’.$_GET[“month”].’&year=’.$_GET[“year”].’”’.$class.’ title=”’.$Date.’”>’.$Linktext.’</a>’;
}

/* mdp_calendar_specificDate($rows, $day, $date[“month”], $date[“year”]); * Retrives article’s for a specific date.

* Input: * $rows => array of all rows returned for current month * $day => current day * * Output: * Link(s) to the article(s) that appear on $year-$month-$day (currently only messy links) * if none (non breaking space) */ function mdp_calendar_specificDate($rows, $day, $atts) { global $pfr; /* Find the articles posted on specific day */ foreach($rows as $row) { $postedday = substr($row[‘fPosted’],8,2);

if($postedday == $day) { $title = mdp_calendar_excerpt($row[‘Title’]);

if($atts[“smallformat”] == 1) { $datestamp = substr($row[‘fPosted’],0,10); $links[] = formatEventHref($pfr,$row[‘Section’],$datestamp, $day); break; // This will only output the first article on that day } else { $links[] = tag(formatHref($pfr, $row[‘Section’], $row[‘ID’], $title, $row[‘Title’]),‘span’,’ class=“permalink”’); } } if($postedday > $day) { break; // No need to go through days that are beyond our specific day

} }

if(empty($links)) { $links[] = ($atts[‘smallformat’]) ? $day : ‘ ‘; }

return implode(‘’,$links);
}

/* truncates and add’s ellipses at end of strings greater than $len */
function mdp_calendar_excerpt($str,$len=15) { return (strlen($str) > $len) ? substr($str,0,$len) . ‘…’ : $str;
}

// mdp_calendar_navlink(array $date,int $direction)
// direction: 0 -> backwards. 1 -> forwards */
function mdp_calendar_navlink($date,$direction)
{ global $url_mode, $s;

if($direction 0) { $d = mdp_calendar_ValidateMonthYear($date['mon']-1,$date['year']); } else { //forwards $d = mdp_calendar_ValidateMonthYear($date['mon']+1,$date['year']); } // Remove any other month or year variables first if($url_mode 1) { $str = preg_replace(“([&|?](month|year)=([0-9]*))”,’‘,$_SERVER[‘REQUEST_URI’]); $have_seperator = strpos($str,’?’); (!$have_seperator) ? $str .= ‘?’ : $str .= ‘&’; $str .= ‘month=’ . $d[‘month’] . ‘&’ . ‘year=’ . $d[‘year’]; } else { $messy = $_REQUEST; $messy[‘month’] = $d[‘month’]; $messy[‘year’] = $d[‘year’]; $str = buildGetURL($messy, $section); }

return $str;
}

function mdp_calendar_invalidDays($start, $end)
{ $output[] = ‘’; for($i = $start; $i < $end; $i++) { $output[] = td(’ ‘,’‘,‘invalidDay’,’‘); } return implode(‘’,$output);
}

// mdp_calarticle($atts)
// Behaves just like article_custom for lists, and article for a single ID
// If the URL string has a date variable in it, outputs all the days
// on that date.
function mdp_calarticle($atts)
{ if( gps(‘date’) != ‘’ ) { $date = date(‘Y-m-d’,getReverseOffsetTimestamp(strtotime(gps(‘date’)))); $atts[‘month’] = $date; return article_custom($atts); } else { return article($atts); }
}

Offline

#110 2005-04-20 05:00:17

Freigeist
Member
Registered: 2004-11-01
Posts: 13
Website

Re: Calendar?

The search function of textpattern.com isn’t working properly for last week so I am not sure if this if this was mention before, if yes sorry!

I try to get the mdp_calendar working but I get just the following error message:

Fatal error: Call to undefined function: formathref() in /home/www/web171/html/textpattern/lib/txplib_misc.php(304) : eval()’d code on line 1059

I am using textpattern RC3 Rev.280 in clean url mode, mdp_lib.php is installed end everythin works fine so far on raedan: !

Anybody an idea what goes wrong?

Offline

#111 2005-04-21 02:30:57

badeand
New Member
From: Norway
Registered: 2005-04-19
Posts: 2
Website

Re: Calendar?

I’d like to get a solution for this problem, myself.
If I got an earlier post right, this isn’t a problem with smallformat, but then again, it might be handy to have them both working!


Webdesigner
www.comart.no

Offline

#112 2005-04-21 03:46:15

badeand
New Member
From: Norway
Registered: 2005-04-19
Posts: 2
Website

Re: Calendar?

..and if someone could come up with a solution to view the future posted events, I’d be SO glad.


Webdesigner
www.comart.no

Offline

#113 2005-04-21 04:22:35

blumie607
Member
Registered: 2004-03-08
Posts: 175
Website

Re: Calendar?

> Freigeist wrote:

> The search function of textpattern.com isn’t working properly for last week so I am not sure if this if this was mention before, if yes sorry!

> I try to get the mdp_calendar working but I get just the following error message:

> Fatal error: Call to undefined function: formathref() in /home/www/web171/html/textpattern/lib/txplib_misc.php(304) : eval()’d code on line 1059

> I am using textpattern RC3 Rev.280 in clean url mode, mdp_lib.php is installed end everythin works fine so far on raedan: !

> Anybody an idea what goes wrong?

I’m getting these problems too! It is probably an error with RC3 and mdp_calendar. Greenrift, we hope you return soon.


bludrop studios .::. Creative Expression

Offline

#114 2005-04-26 22:15:45

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: Calendar?

what i would loooove to see, is the calendar dates link to the archives… the same way the rss_suparchive category/month lists do. this would also negate the dependency on the <txp:article /> tag having to be changed to <txp:mdp_calarticle />

any chance in the nearish future?


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#115 2005-04-27 20:09:56

theturninggate
Member
Registered: 2004-11-07
Posts: 185
Website

Re: Calendar?

I’ve just noticed that my calendar is off by a day. April 30 is supposed to be a Saturday, but in my calendar it’s shown as a Friday. Anyone know how to fix this?

Here’s a link to the calendar if anyone would like to see:
http://new.garthnewel.org/?s=calendar&month=4&year=2005

Offline

#116 2005-04-28 17:08:46

greenrift
Archived Plugin Author
Registered: 2004-03-08
Posts: 186
Website

Re: Calendar?

> alicson wrote:

> what i would loooove to see, is the calendar dates link to the archives… the same way the rss_suparchive category/month lists do. this would also negate the dependency on the <txp:article /> tag having to be changed to <txp:mdp_calarticle />

I’m a little confused on what exactly you mean? I understand the removal on mdp_calarticle, thats going to be gone. What do you mean by “calendar dates link to the archives”?

Quick update: I’ve done a fair amount of work on this plugin, and its very close to being released. It’s also quite different (the actual calendar output was completely rewritten), but produces the same output and takes the same options.

Some new “features”:
  • Starting day of the month is now user selectable, if you feel that your week starts on Wendesday the calendar has no problem respecting that.
  • The names of days and months should obey internationalization, and their format can also be changed (so full or abbreviated names occuring to strftime formatting.
  • Wacky time offset problems should be hopefully corrected.
  • Navigation will work with messy url’s.
  • mdp_calarticle won’t be needed anymore.
  • The big and small calendars are now seperate tags.

Last edited by greenrift (2005-04-28 23:12:37)

Offline

#117 2005-04-28 20:07:51

blumie607
Member
Registered: 2004-03-08
Posts: 175
Website

Re: Calendar?

Sounds yummy. Can’t wait.


bludrop studios .::. Creative Expression

Offline

#118 2005-05-11 15:38:37

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: Calendar?

I’ve got may calendar styled just fine. I’d like to start using it as an events calendar for future events. I installed the mdp_upcomingEventsList plugin, but I’m unclear where to control the behaviour when one of these events is clicked. Anyone willing to help with an explain…

Much Thanks

Offline

#119 2005-05-12 04:24:15

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: Calendar?

> greenrift wrote:
> What do you mean by “calendar dates link to the archives”?

sorry! i should have answered this a long time ago…
i meant that instead of clicking the calendar date and going to an article list page of articles, it would go to an archive page of that day.
but it’sokay… i found a different solution. thank you much, though.

your new calendar plugin sounds cool too :)


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#120 2005-05-14 02:48:18

blumie607
Member
Registered: 2004-03-08
Posts: 175
Website

Re: Calendar?

Greenrift released his updated plugin. Find it in a different forum.


bludrop studios .::. Creative Expression

Offline

  1. Index
  2. » Archives
  3. » Calendar?

Board footer

Powered by FluxBB