I wrote this for a client as well, but still he just rented some of my time and knowledge. He doesn't own it. Therefor it should still be available for the community that served me wel for some time now.
Here's Olivers' phpwcmsCalendar.class.php, but a bit modified to properly include all the information you can fill in in the backend. I included the whole file as code for easy replacement. Also a full template's code with possible reptags. I left {TEXT} intact, but also added {TEASER} as i found that more logical. Both can be used for the same line of text from the backend.
Some extra info:
I use, two templates in two pages. To be able to show a list of events in one article, and show the full text in another article, using the "href" tag in the REPTAG. Because the HREF tag in the templates adds the "show_date" and the ID to the browsers URL the calendar class now knows to select only that calendar item. Using the LONGTEXT reptag in a different template i can now show the full article. Using this method i have different calendars on different pages showing different events based on the "tag=birthdays, reservations" settings in the reptags.
Images work, caption work, url works that should be a small help for some.
Added a extra REPTAG feature :
Code: Select all
{CALENDAR:
items=10
template=home_dates_de.html
lang=
tag=
tagmode=OR
href=index.php?agenda-full
WxHxCxQ=75x100x1x75}
This allows ofcourse for an easier setting of the width,height, crop and quality of the image presented.
And last but not least added support for zoom and light box.
NOTE TO Oliver.
How to you asure that the meta tags needed in the header of the page for mootools and such get in the header the moment lightbox is enabled somewhere. You must have some trick to do that as gallery, or article pages that dont have lightbox also dont include the meta tags like mootools. Or....it must be magic
![Smile :-)](./images/smilies/icon_smile.gif)
. I now get the meta tags in using the option in the template used for the page.
phpwcmsCalendar.class.php :
Code: Select all
<?php
/*************************************************************************************
Copyright notice
(c) 2002-2008 Oliver Georgi (oliver@phpwcms.de) // All rights reserved.
This script is part of PHPWCMS. The PHPWCMS web content management system is
free software; you can redistribute it and/or modify it under the terms of
the GNU General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.
The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
A copy is found in the textfile GPL.txt and important notices to the license
from the author is found in LICENSE.txt distributed with these scripts.
This script is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
This copyright notice MUST APPEAR in all copies of the script!
*************************************************************************************/
/**
* phpwcms Calendar frontend render class
*/
class phpwcmsCalendar {
var $mode = 'simple';
var $dates = array();
/**
* Initialize class
*/
function phpwcmsCalendar($date=false) {
// current
if(!isset($_GET['show_date'])) {
$this->current_date = getdate();
// print_r($this->current_date);
}
// If there's only one ! We need to select only ONE ! By the ID give in the U R L
if(isset($_GET['show_date']) && mysql_real_escape_string($_GET['show_date']) != "") {
$show_date = mysql_real_escape_string($_GET['show_date']);
list($year, $month, $day, $event_id) = split('[-_]', $show_date);
$this->event_id = $event_id;
}
// set today 00:00:00 as start date
$this->date_start = mktime(0, 0, 0, $this->current_date['mon'], $this->current_date['mday'], $this->current_date['year']);
// by default date_start + 1 year
$this->date_end = mktime(0, 0, 0, $this->current_date['mon'], $this->current_date['mday'], $this->current_date['year'] + 1) - 1;
$this->dbReset();
}
/**
* Reset db base vars
*/
function dbReset() {
$this->where = '';
$this->select = '*';
$this->join_on = '';
$this->group_by = '';
$this->order_by = 'calendar_start ASC';
$this->limit = 0;
}
function defaultTemplate() {
$this->template = '';
$this->href = '';
}
/**
* search string for calendar tag and parse
*/
function parse(& $string) {
if( preg_match_all('/\{CALENDAR:(.*?)\}/s', $string, $matches) ) {
if( isset($matches[1]) ) {
foreach($matches[1] as $key => $value) {
$this->parse_match($value);
$result = $this->render();
// replace calendar by result
$string = str_replace($matches[0][$key], $result, $string);
}
$string = html_parser($string);
}
}
}
function render() {
$items = array();
foreach($this->dates as $key => $date) {
// print_r($items);
$date['calendar_refid'] = intval($date['calendar_refid']);
if($date['calendar_refid'] > 0) {
$href = 'index.php?aid='.$date['calendar_refid'];
} else {
$href = $this->href ? $this->href . '&show_date='.date('Y-m-d', $date['calendar_start_date']).'_'.$date['calendar_id'] : '';
}
$items[$key] = $this->template;
$items[$key] = render_cnt_template($items[$key], 'HREF', $href);
$items[$key] = render_cnt_template($items[$key], 'TITLE', html_specialchars($date['calendar_title']));
$items[$key] = render_cnt_template($items[$key], 'TEXT', plaintext_htmlencode($date['calendar_teaser']));
$items[$key] = render_cnt_template($items[$key], 'PLACE', html_specialchars($date['calendar_where']));
$items[$key] = render_cnt_date($items[$key], $date['calendar_start_date'], $date['calendar_start_date'], $date['calendar_end_date']);
// The long or FULL text
$items[$key] = render_cnt_template($items[$key], 'TEXTLONG', $date['calendar_text']);
// I use teaser, but left the {TEXT} code intact, but {TEASER} seems more appropriate
$items[$key] = render_cnt_template($items[$key], 'TEASER', $date['calendar_teaser']);
// Now for the image part
/**
* Get Image ID from DB String
*/
// print $date['calendar_object'];
$image_temp = explode(":", $date['calendar_object']);
$image_temp = explode(";", $image_temp[9]);
$image_id_temp = $image_temp[0];
// Image URL
// $image_temp2 = explode(":", $date['calendar_object']);
// 13 = filename
// 16 = Zoom yes / no
// 19 = lightbox yes or no
// 23 = caption tekst
// 25 = link yes / no
// 27 = URL
// Get the right url for the image
$image_temp = explode(":", $date['calendar_object']);
$image_temp = explode(";", $image_temp[27]);
$image_url = $image_temp[0];
// Zoomin' yes or ........nooooo
$image_temp = explode(":", $date['calendar_object']);
$image_temp = explode(";", $image_temp[16]);
$image_zoom = $image_temp[0];
// Lightbox' yes or ........nooooo
$image_temp = explode(":", $date['calendar_object']);
$image_temp = explode(";", $image_temp[19]);
$image_lightbox = $image_temp[0];
// Caption info, same ol same ol
$image_temp = explode(":", $date['calendar_object']);
$image_temp = explode(";", $image_temp[23]);
$image_caption = $image_temp[0];
// Strip some nasty quotes
$image_caption = substr($image_caption, 1, -1);
/**
* Get Image from DB table 'phpwcms_file'
*/
$sql_hash = _dbQuery('SELECT * FROM '.DB_PREPEND.'phpwcms_file WHERE f_id = '.$image_id_temp.' AND f_trash = 0 LIMIT 0,1');
// print_r($sql_hash);
if($sql_hash[0][f_hash] != "") {
$image_calendar_name = $sql_hash[0][f_hash].'.'.$sql_hash[0][f_ext];
// Set the image using the PHPWCMS image All in One wonder call
$image_calendar = "<img border=\"0\" src=\"".PHPWCMS_URL."img/cmsimage.php/".$this->WxHxCxQ."/".$image_calendar_name."\" title=\"".$image_caption."\" alt=\"".$image_caption."\">";
if($image_zoom == '1') {
$image_calendar_link = "<a href=\"".PHPWCMS_URL."img/cmsimage.php/800x600/".$image_calendar_name."\"";
if($image_lightbox == '1') {
$image_calendar_link.= " border=\"0\" target=\"_blank\" rel=\"lightbox\" alt=\"".$image_caption."\">";
}
$image_calendar_link.= $image_calendar."</a>";
$image_calendar = $image_calendar_link;
}
}
// Just needs to be here, otherwise it will use the last image from the event before this one. (STrange brew !!)
else {
$image_calendar = "";
}
// Now the rest of the items the backend has provided us with.
$items[$key] = render_cnt_template($items[$key], 'IMAGE_CALENDAR', $image_calendar);
$items[$key] = render_cnt_template($items[$key], 'URL', $image_url);
$items[$key] = render_cnt_template($items[$key], 'CAPTION', $image_caption);
}
return implode(LF, $items);
}
/**
* Parse matched replacement tag
*/
function parse_match($match='') {
$default = array();
$match = trim($match);
// set query defaults
$this->dbReset();
$this->defaultTemplate();
if($match !== '' && strpos($match, '=') !== FALSE ) {
// oh yes fix, in case LF was converted to <br /> by phpwcms
$match = str_replace('<br />', LF, $match);
// result is a normal array
$match = parse_ini_str($match, false);
$default['items'] = isset($match['items']) ? intval($match['items']) : 0;
$default['template'] = empty($match['template']) ? '' : trim($match['template']);
$default['lang'] = empty($match['lang']) ? '' : trim($match['lang']);
$default['tag'] = empty($match['tag']) ? '' : trim($match['tag']);
$default['tagmode'] = empty($match['tagmode']) ? 'OR' : ( trim($match['tagmode']) == 'AND' ? 'AND' : 'OR' );
$default['href'] = empty($match['href']) ? '' : trim($match['href']);
// We want to set the size of the image, and such more in the reptag.
$default['WxHxCxQ'] = empty($match['WxHxCxQ']) ? '' : trim($match['WxHxCxQ']);
// This was added for a reason that i cant remember right now. Having to do with displaying the full article.
$default['mode'] = empty($match['mode']) ? '' : trim($match['mode']);
} else {
// base format
// 2,main_page.tmpl,de en, href, tag1, tag2 tag2, tag3
// [item count,[template[,language(en de - separated by space)[, href, tags, tag, tag, tag]]]]
$match = explode(',', $match, 5);
$default['items'] = intval($match[0]);
$default['lang'] = empty($match[1]) ? '' : $match[1];
$default['template'] = empty($match[2]) ? '' : trim($match[2]) ;
$default['href'] = empty($match[3]) ? '' : trim($match[3]);
$default['tag'] = empty($match[4]) ? '' : $match[4];
$default['tagmode'] = 'OR';
// We want to set the size of the image, and such more in the reptag.
$default['WxHxCxQ'] = '100x100x1x90';
$default['mode'] = '';
}
$this->WxHxCxQ = $default['WxHxCxQ'];
$this->limit = $default['items'];
$this->href = $default['href'];
// Remeber the one with the "i cant remember....."? Same here
$this->mode = $default['mode'];
if($default['template'] !== '') {
$default['template'] = preg_replace('/[\/\\:]/', '', $default['template']);
if(is_file(PHPWCMS_TEMPLATE.'calendar/'.$default['template'])) {
$this->template = file_get_contents(PHPWCMS_TEMPLATE.'calendar/'.$default['template']);
$this->template = str_replace('{STARTDATE', '{LIVEDATE', $this->template);
$this->template = str_replace('{ENDDATE', '{KILLDATE', $this->template);
} else {
$default['template'] = '';
}
}
$where = array();
if($default['lang'] !== '') {
$default['lang'] = str_replace(',', ' ', preg_replace('/[^a-z\-]/', '', strtolower($default['lang'])));
$default['lang'] = array_intersect( convertStringToArray( $default['lang'], ' '), $GLOBALS['phpwcms']['allowed_lang']);
if(count($default['lang'])) {
$where[] = "calendar_lang IN ('" . implode("','", $default['lang']) . "')";
}
}
if($default['tag'] !== '') {
$default['tag'] = convertStringToArray( strtolower( $default['tag'] ), ',');
if(count($default['tag'])) {
$tag_where = array();
foreach($default['tag'] as $tag) {
$tag_where[] = "cat_name='".aporeplace($tag)."'";
}
if(count($tag_where)) {
$where[] = '(' . implode(' '.$default['tagmode'] . ' ', $tag_where) . ')';
$this->join_on = 'LEFT JOIN '.DB_PREPEND.'phpwcms_categories ON cat_pid=calendar_id';
$this->group_by = 'calendar_id';
}
};
}
$this->where = implode(' AND ', $where);
$this->getDate();
return $default;
}
function getDate() {
// 1 daily
// 2 Every weekday (Mon-Fri)
// 3 Every Mon., Wed. and Fri.
// 4 Every Tues. and Thurs.
// 5 Weekly
// 6 Monthly
// 7 yearly
if(is_string($this->order_by) && trim($this->order_by) != '') {
$this->order_by = ' ORDER BY '.$this->order_by;
} else {
$this->order_by = '';
}
if(is_int($this->limit) && $this->limit > 0) {
$this->limit = ' LIMIT '.$this->limit;
} else {
$this->limit = '';
}
if(is_string($this->group_by) && trim($this->group_by) != '') {
$this->group_by = ' GROUP BY '.$this->group_by;
} else {
$this->group_by = '';
}
$sql = 'SELECT '. $this->select .', ';
$sql .= "UNIX_TIMESTAMP(calendar_start) AS calendar_start_date, ";
$sql .= "UNIX_TIMESTAMP(calendar_end) AS calendar_end_date ";
$sql .= ' FROM '.DB_PREPEND.'phpwcms_calendar pc ';
$sql .= $this->join_on;
$sql .= ' WHERE ';
$sql .= 'calendar_status = 1 AND ';
$sql .= "calendar_start >= '".aporeplace( date('Y-m-d H:i:s', $this->date_start) )."' AND ";
$sql .= "calendar_start <= '".aporeplace( date('Y-m-d H:i:s', $this->date_end) )."'";
if(!empty($this->where)) {
$sql .= ' AND ' . $this->where;
}
$sql .= $this->group_by;
$sql .= $this->order_by;
$sql .= $this->limit;
// If the url given by the link in the list of events, gives us an ID at the end,
// we need to limit the sql statement to just the event from the ID given. We stripped
// this from the showdate.
if(isset($this->event_id) && isset($this->event_id) == 'full') {
$sql = "SELECT *, UNIX_TIMESTAMP(calendar_start) AS calendar_start_date, UNIX_TIMESTAMP(calendar_end) AS calendar_end_date FROM phpwcms_calendar pc WHERE calendar_status = 1 AND calendar_id >= '".$this->event_id."' LIMIT 0,1";
}
// Now we know when to select a list or just the one item.
$this->dates = _dbQuery($sql);
if( !$this->dates ) {
$this->dates = array();
}
}
}
?>
template example :
Code: Select all
<div class="calendar" style="clear : both; padding : 10px;">
<div class="calendar_image" style="float : left;">
[IMAGE_CALENDAR]
{IMAGE_CALENDAR}
[/IMAGE_CALENDAR]
<br/>
[CAPTION]<span style="color : black;">{CAPTION}</span>[/CAPTION]
</div>
<div class="calendar_text" style="padding : 10px; float : right;">
[TITLE]<h3>[HREF]<a href="{HREF}">[/HREF]{TITLE}[HREF]</a>[/HREF]</h3>[/TITLE]
[PLACE]<p><b>Plaats :</b> {PLACE}</p>[/PLACE]
[TEASER]<p>{TEASER}</p>[/TEASER]
[TEXTLONG]<p>{TEXTLONG}</p>[/TEXTLONG]
</div>
<div class="calendar_date">
[HREF]<a href="{HREF}">[/HREF]
<strong>Datum :</strong> {STARTDATE:d.m.Y}<br/>
<strong>Tijd :</strong> {STARTDATE:H:i} - {ENDDATE:H:i}
[HREF]</a>[/HREF]
</div>
<div class="calendar_url">
[URL]<a href={URL}>Meer..{URL}</a>[/URL]
</div>
</div>
Oh ... before i forget......this works on r304+