From 97490a16baeab752422569259366b309163cb6e5 Mon Sep 17 00:00:00 2001 From: Chad Little Date: Mon, 26 Jan 2004 06:34:09 +0000 Subject: Template class checking, first round trying to get event templated. --- functions/init.inc.php | 2 +- functions/template.php | 35 ++++++++++++++++++++++++ includes/event.php | 65 +++++++++++++++++---------------------------- templates/default/event.tpl | 2 +- 4 files changed, 62 insertions(+), 42 deletions(-) create mode 100644 functions/template.php 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 @@ +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 @@ (' . $all_day_lang . ')'; } -if ($description) { - $display = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",'\0',$description); - $display .= '
'; -} +if ($description) $description = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",'\0',$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 .= '
'; + $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 .= '
'; -} -if ($status) { - $display .= $status_lang . ' - ' . $status. '
' . "\n"; + $attendee = substr($attendees,0,-2); } + if ($location) { if ($url != '') $location = ''.$location.''; - $display .= $location_lang . ' - ' . $location.'
'; } $sheet_href = BASE.'styles/'.$style_sheet.'/default.css'; +$page = new Page(BASE.'templates/default/event.tpl'); -echo <<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 + + )); - - - - - {$cal} - - - -
- - - - - - - -
{$cal_title_full}
-
-

{$event} {$event_times}

- {$display} -
-
-
- - +$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 @@ {CAL} - +
-- cgit v1.2.3