diff options
author | Chad Little <clittle@users.sourceforge.net> | 2004-01-26 06:34:09 +0000 |
---|---|---|
committer | Chad Little <clittle@users.sourceforge.net> | 2004-01-26 06:34:09 +0000 |
commit | 97490a16baeab752422569259366b309163cb6e5 (patch) | |
tree | 79aebf19073662d29f489274244a8ab81fa090b5 | |
parent | d951bba0df4dfbf3b6e07e48a22fb8ef0b8a9027 (diff) | |
download | phpicalendar-97490a16baeab752422569259366b309163cb6e5.tar.gz phpicalendar-97490a16baeab752422569259366b309163cb6e5.tar.bz2 phpicalendar-97490a16baeab752422569259366b309163cb6e5.zip |
Template class checking, first round trying to get event templated.
-rw-r--r-- | functions/init.inc.php | 2 | ||||
-rw-r--r-- | functions/template.php | 35 | ||||
-rw-r--r-- | includes/event.php | 65 | ||||
-rw-r--r-- | templates/default/event.tpl | 2 |
4 files changed, 62 insertions, 42 deletions
diff --git a/functions/init.inc.php b/functions/init.inc.php index c6c623c..d2b2d90 100644 --- a/functions/init.inc.php +++ b/functions/init.inc.php @@ -6,7 +6,7 @@ //chmod(BASE.'calendars/School.ics',0666); // uncomment when developing, comment for shipping version -// error_reporting (E_ERROR | E_WARNING | E_PARSE); +error_reporting (E_ERROR | E_WARNING | E_PARSE); // Older versions of PHP do not define $_SERVER. Define it here instead. if (!isset($_SERVER) && isset($HTTP_SERVER_VARS)) { diff --git a/functions/template.php b/functions/template.php new file mode 100644 index 0000000..a1cf2bb --- /dev/null +++ b/functions/template.php @@ -0,0 +1,35 @@ +<?php + +class Page { + var $page; + function Page($template = 'std.tpl') { + if (file_exists($template)) + $this->page = join('', file($template)); + else + die("Template file $template not found."); + } + + function parse($file) { + ob_start(); + include($file); + $buffer = ob_get_contents(); + ob_end_clean(); + return $buffer; + } + + function replace_tags($tags = array()) { + if (sizeof($tags) > 0) + foreach ($tags as $tag => $data) { + $data = (file_exists($data)) ? $this->parse($data) : $data; + $this->page = eregi_replace('{' . $tag . '}', $data, + $this->page); + } + else + die('No tags designated for replacement.'); + } + + function output() { + print($this->page); + } +} +?>
\ No newline at end of file diff --git a/includes/event.php b/includes/event.php index 2f39c3b..7e3f08e 100644 --- a/includes/event.php +++ b/includes/event.php @@ -1,6 +1,8 @@ <?php define('BASE', '../'); include_once(BASE.'functions/init.inc.php'); +require_once(BASE.'functions/template.php'); +error_reporting(E_ALL); function decode_popup ($item) { $item = stripslashes(rawurldecode($item)); @@ -30,10 +32,7 @@ if ($start == '' && $end == '' && (isset($start) && isset($end))) { $event_times=' - <font class="V9">(<i>' . $all_day_lang . '</i>)</font>'; } -if ($description) { - $display = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",'<a target="_new" href="\0">\0</a>',$description); - $display .= '<br>'; -} +if ($description) $description = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",'<a target="_new" href="\0">\0</a>',$description); if ($organizer) { $i=0; $display .= $organizer_lang . ' - '; @@ -41,8 +40,7 @@ if ($organizer) { $organizers .= $organizer[$i]["name"] . ', '; $i++; } - $display .= substr($organizers,0,-2); - $display .= '<br>'; + $organizer = substr($organizers,0,-2); } if ($attendee) { $i=0; @@ -51,48 +49,35 @@ if ($attendee) { $attendees .= $attendee[$i]["name"] . ', '; $i++; } - $display .= substr($attendees,0,-2); - $display .= '<br>'; -} -if ($status) { - $display .= $status_lang . ' - ' . $status. '<br>' . "\n"; + $attendee = substr($attendees,0,-2); } + if ($location) { if ($url != '') $location = '<a href="'.$url.'" target="_blank">'.$location.'</a>'; - $display .= $location_lang . ' - ' . $location.'<br>'; } $sheet_href = BASE.'styles/'.$style_sheet.'/default.css'; +$page = new Page(BASE.'templates/default/event.tpl'); -echo <<<END +$page->replace_tags(array( + 'cal' => $cal, + 'event' => $event, + 'event_times' => $event_times, + 'description' => $description, + 'organizer_lang' => $organizer_lang, + 'organizer' => $organizer, + 'attendee_lang' => $attendee_lang, + 'attendee' => $attendee, + 'status_lang' => $status_lang, + 'status' => $status, + 'location_lang' => $location_lang, + 'location' => $location, + 'sheet_href' => $sheet_href, + 'cal_title_full' => $cal_title_full + + )); - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" - "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> - <html> - <head> - <meta http-equiv="content-type" content="text/html;charset=UTF-8"> - <title>{$cal}</title> - <link rel="stylesheet" type="text/css" href="{$sheet_href}"> - </head> - <body> - <center> - <table border="0" width="430" cellspacing="0" cellpadding="0" class="calborder"> - <tr> - <td align="center" class="sideback"><div style="height: 17px; margin-top: 3px;" class="G10BOLD">{$cal_title_full}</div></td> - </tr> - <tr> - <td align="left" class="V12"> - <div style="margin-left: 10px; margin-bottom:10px;"> - <p>{$event} {$event_times}</p> - {$display} - </div> - </td> - </tr> - </table> - </center> - </body> - </html> +$page->output(); -END; ?> diff --git a/templates/default/event.tpl b/templates/default/event.tpl index 52ec04c..102bbfb 100644 --- a/templates/default/event.tpl +++ b/templates/default/event.tpl @@ -4,7 +4,7 @@ <head> <meta http-equiv="content-type" content="text/html;charset=UTF-8"> <title>{CAL}</title> - <link rel="stylesheet" type="text/css" href="{SHEET_HREF"> + <link rel="stylesheet" type="text/css" href="{SHEET_HREF}"> </head> <body> <center> |