From c143f2891418cb0f0ae0f80f7d2d58e69879a722 Mon Sep 17 00:00:00 2001 From: Chad Little Date: Sat, 31 Jan 2004 07:07:37 +0000 Subject: Many many changes. Faster templating. --- functions/date_functions.php | 15 +-- functions/template.php | 212 ++++++++++++++++++++------------------ month.php | 5 - preferences.php | 2 - templates/default/header.tpl | 2 +- templates/default/month.tpl | 4 +- templates/default/month_large.tpl | 37 ++----- 7 files changed, 130 insertions(+), 147 deletions(-) diff --git a/functions/date_functions.php b/functions/date_functions.php index 72b9a9c..02cfa77 100644 --- a/functions/date_functions.php +++ b/functions/date_functions.php @@ -195,21 +195,22 @@ function openevent($calendar_name, $start, $end, $arr, $lines, $wrap, $pre_text, $escaped_end = addslashes($end); // fix for URL-length bug in IE: populate and submit a hidden form on click static $popup_data_index = 0; -echo << + // -->"; -END; - echo ''; + $return .= ''; $popup_data_index++; } else { - echo ''; + $return .= ''; } - echo $pre_text.$event_text.$post_text.''."\n"; + $return .= $pre_text.$event_text.$post_text.''."\n"; } + + return $return; } diff --git a/functions/template.php b/functions/template.php index ca214da..856d926 100644 --- a/functions/template.php +++ b/functions/template.php @@ -2,98 +2,111 @@ //print_r($master_array); -function draw_month($template, $offset = '+0', $type) { - global $getdate, $master_array, $this_year, $this_month, $dateFormat_month, $week_start_day, $cal, $minical_view, $daysofweekreallyshort_lang, $daysofweek_lang; - ob_start(); - include($template); - $template = ob_get_contents(); - ob_end_clean(); - preg_match("!<\!-- loop weekday on -->(.*)<\!-- loop weekday off -->!is", $template, $match1); - preg_match("!<\!-- loop monthdays on -->(.*)<\!-- loop monthdays off -->!is", $template, $match2); - preg_match("!<\!-- loop monthweeks on -->(.*)<\!-- loop monthdays on -->!is", $template, $match6); - preg_match("!<\!-- loop monthdays off -->(.*)<\!-- loop monthweeks off -->!is", $template, $match7); - - $loop_wd = trim($match1[1]); - $loop_md = trim($match2[1]); - $startweek = trim($match6[1]); - $endweek = trim($match7[1]); - $fake_getdate_time = strtotime($this_year.'-'.$this_month.'-15'); - $fake_getdate_time = strtotime("$offset month", $fake_getdate_time); - $start_day = strtotime($week_start_day); - $month_title = localizeDate ($dateFormat_month, $fake_getdate_time); - if ($type == 'small') { - $type = $daysofweekreallyshort_lang; - } elseif ($type == 'medium') { - $type = $daysofweekshort_lang; - } elseif ($type == 'large') { - $type = $daysofweek_lang; - } - - for ($i=0; $i<7; $i++) { - $day_num = date("w", $start_day); - $weekday = $type[$day_num]; - $start_day = strtotime("+1 day", $start_day); - $loop_tmp = str_replace('{LOOP_WEEKDAY}', $weekday, $loop_wd); - $weekday_loop .= $loop_tmp; - } - - $minical_month = date("m", $fake_getdate_time); - $minical_year = date("Y", $fake_getdate_time); - $first_of_month = $minical_year.$minical_month."01"; - $start_day = strtotime(dateOfWeek($first_of_month, $week_start_day)); - $i = 0; - $whole_month = TRUE; - - do { - if ($i == 0) $middle .= $startweek; $i++; - $temp_middle = $loop_md; - $switch = array('notthismonth' => '', 'istoday' => '', 'ismonth' => '', 'noevent' => '', 'anyevent' => '', 'allday' => '', 'event_title' => '', 'cal' => $cal, 'minical_view' => $minical_view); - $check_month = date ("m", $start_day); - $daylink = date ("Ymd", $start_day); - $switch['day'] = date ("j", $start_day); - $switch['daylink'] = date ("Ymd", $start_day); - $switch['notthismonth'] = ($check_month != $minical_month) ? 'set' : ''; - $switch['istoday'] = ($switch['daylink'] == $getdate) ? 'set' : ''; - $switch['ismonth'] = (($switch['istoday'] == '') && ($switch['notthismonth'] == '')) ? 'set' : ''; - if (isset($master_array[$daylink]['-1'])) { - $switch['anyevent'] = 'set'; - $switch['allday'] = 'set'; - //$switch['event_title'] = $master_array[$daylink]['-1']['0']['event_text']; - //print_r ($master_array[$daylink]['-1']); - } elseif (isset($master_array[$daylink])) { - $switch['anyevent'] = 'set'; - } else { - $switch['noevent'] = 'set'; - } + + +class Page { + var $page; + function draw_month($template, $offset = '+0', $type) { + global $getdate, $master_array, $this_year, $this_month, $dateFormat_month, $week_start_day, $cal, $minical_view, $daysofweekreallyshort_lang, $daysofweek_lang, $timeFormat_small, $timeFormat; + preg_match("!<\!-- loop weekday on -->(.*)<\!-- loop weekday off -->!is", $template, $match1); + preg_match("!<\!-- loop monthdays on -->(.*)<\!-- loop monthdays off -->!is", $template, $match2); + preg_match("!<\!-- loop monthweeks on -->(.*)<\!-- loop monthdays on -->!is", $template, $match6); + preg_match("!<\!-- loop monthdays off -->(.*)<\!-- loop monthweeks off -->!is", $template, $match7); - foreach ($switch as $tag => $data) { - if (!$data) { - $temp_middle = eregi_replace('(.*)', '', $temp_middle); - } else { - $temp_middle = eregi_replace('{' . $tag . '}', $data, $temp_middle); - } + $loop_wd = trim($match1[1]); + $loop_md = trim($match2[1]); + $startweek = trim($match6[1]); + $endweek = trim($match7[1]); + $fake_getdate_time = strtotime($this_year.'-'.$this_month.'-15'); + $fake_getdate_time = strtotime("$offset month", $fake_getdate_time); + $start_day = strtotime($week_start_day); + $month_title = localizeDate ($dateFormat_month, $fake_getdate_time); + if ($type == 'small') { + $type = $daysofweekreallyshort_lang; + } elseif ($type == 'medium') { + $type = $daysofweekshort_lang; + } elseif ($type == 'large') { + $type = $daysofweek_lang; } - $middle .= $temp_middle; - $start_day = strtotime("+1 day", $start_day); - if ($i == 7) { - $i = 0; - $middle .= $endweek; - $checkagain = date ("m", $start_day); - if ($checkagain != $minical_month) $whole_month = FALSE; + for ($i=0; $i<7; $i++) { + $day_num = date("w", $start_day); + $weekday = $type[$day_num]; + $start_day = strtotime("+1 day", $start_day); + $loop_tmp = str_replace('{LOOP_WEEKDAY}', $weekday, $loop_wd); + $weekday_loop .= $loop_tmp; } - } while ($whole_month == TRUE); - - $return = eregi_replace('(.*)', $weekday_loop, $template); - $return = eregi_replace('(.*)', $middle, $return); - $return = str_replace('{MONTH_TITLE}', $month_title, $return); + + $minical_month = date("m", $fake_getdate_time); + $minical_year = date("Y", $fake_getdate_time); + $first_of_month = $minical_year.$minical_month."01"; + $start_day = strtotime(dateOfWeek($first_of_month, $week_start_day)); + $i = 0; + $whole_month = TRUE; + + do { + if ($i == 0) $middle .= $startweek; $i++; + $temp_middle = $loop_md; + $switch = array('notthismonth' => '', 'istoday' => '', 'ismonth' => '', 'noevent' => '', 'anyevent' => '', 'allday' => '', 'cal' => $cal, 'minical_view' => $minical_view); + $check_month = date ("m", $start_day); + $daylink = date ("Ymd", $start_day); + $switch['day'] = date ("j", $start_day); + $switch['daylink'] = date ("Ymd", $start_day); + $switch['notthismonth'] = ($check_month != $minical_month) ? 'set' : ''; + $switch['istoday'] = ($switch['daylink'] == $getdate) ? 'set' : ''; + $switch['ismonth'] = (($switch['istoday'] == '') && ($switch['notthismonth'] == '')) ? 'set' : ''; + if ($master_array[$daylink]) { + $switch['anyevent'] = 'set'; + foreach ($master_array[$daylink] as $event_times) { + foreach ($event_times as $val) { + $event_calno = $val['calnumber']; + $event_calna = $val['calname']; + $event_url = $val['url']; + if (!isset($val['event_start'])) { + $switch['allday'] .= '
'; + $switch['allday'] .= openevent($event_calna, '', '', $val, $month_event_lines, 15, '', '', 'psf', $event_url); + $switch['allday'] .= '
'; + } else { + $event_start = $val['start_unixtime']; + $event_end = (isset($val['display_end'])) ? $val['display_end'] : $val["event_end"]; + $event_start = date($timeFormat, $val['start_unixtime']); + $start2 = date($timeFormat_small, $val['start_unixtime']); + $event_end = date($timeFormat, @strtotime ($event_end)); + $switch['event'] .= '
'; + $switch['event'] .= openevent($event_calna, $event_start, $event_end, $val, $month_event_lines, 10, "$start2 ", '', 'ps3', $event_url); + $switch['event'] .= '
'; + } + } + } + } + + foreach ($switch as $tag => $data) { + if (!$data) { + $temp_middle = ereg_replace('(.*)', '', $temp_middle); + } else { + $temp_middle = str_replace('{' . strtoupper($tag) . '}', $data, $temp_middle); + } + } + $middle .= $temp_middle; + + $start_day = strtotime("+1 day", $start_day); + if ($i == 7) { + $i = 0; + $middle .= $endweek; + $checkagain = date ("m", $start_day); + if ($checkagain != $minical_month) $whole_month = FALSE; + } + } while ($whole_month == TRUE); + + $return = preg_replace('!<\!-- loop weekday on -->(.*)<\!-- loop weekday off -->!is', $weekday_loop, $template); + $return = ereg_replace('(.*)', $middle, $return); + $return = str_replace('{MONTH_TITLE}', $month_title, $return); + + return $return; + + } - return $return; -} - -class Page { - var $page; function Page($template = 'std.tpl') { if (file_exists($template)) $this->page = join('', file($template)); @@ -118,33 +131,27 @@ class Page { // This removes any unfilled tags if ($data == '') { - $this->page = eregi_replace('(.*)', '', $this->page); + $this->page = ereg_replace('(.*)', '', $this->page); } // This replaces any tags - $this->page = eregi_replace('{' . $tag . '}', $data, $this->page); + $this->page = str_replace('{' . strtoupper($tag) . '}', $data, $this->page); } else die('No tags designated for replacement.'); } - function replace_langs($langs = array()) { - foreach ($langs as $tag => $data) { - $this->page = eregi_replace('{' . $tag . '}', $data, $this->page); - } - } - function output() { - global $template; + global $template, $php_started, $lang; // Small month builder preg_match_all ('!(\{MONTH_SMALL\|[+|-][0-9]\})!is', $this->page, $match); if (sizeof($match) > 0) { + $template_file = $this->parse('templates/'.$template.'/month_small.tpl'); foreach ($match[1] as $key => $val) { - $template_file = 'templates/'.$template.'/month_small.tpl'; $offset = str_replace('}', '', $val); $offset = str_replace('{MONTH_SMALL|', '', $offset); - $data = draw_month($template_file, $offset, 'small'); + $data = $this->draw_month($template_file, $offset, 'small'); $this->page = str_replace($val, $data, $this->page); } } @@ -152,14 +159,21 @@ class Page { // Small month builder preg_match_all ('!(\{MONTH_LARGE\|[+|-][0-9]\})!is', $this->page, $match); if (sizeof($match) > 0) { + $template_file = $this->parse('templates/'.$template.'/month_large.tpl'); foreach ($match[1] as $key => $val) { - $template_file = 'templates/'.$template.'/month_large.tpl'; $offset = str_replace('}', '', $val); $offset = str_replace('{MONTH_LARGE|', '', $offset); - $data = draw_month($template_file, $offset, 'large'); + $data = $this->draw_month($template_file, $offset, 'large'); $this->page = str_replace($val, $data, $this->page); } } + foreach ($lang as $tag => $data) { + $this->page = str_replace('{' . strtoupper($tag) . '}', $data, $this->page); + } + + $php_ended = getmicrotime(); + $generated = number_format(($php_ended-$php_started),3); + echo $generated; print($this->page); } } diff --git a/month.php b/month.php index c3207b1..b87d662 100644 --- a/month.php +++ b/month.php @@ -44,9 +44,6 @@ $list_years = list_years(); $list_months = list_months(); $list_weeks = list_weeks(); -$php_ended = getmicrotime(); -$generated = number_format(($php_ended-$php_started),3); - $page = new Page(BASE.'templates/'.$template.'/month.tpl'); $page->replace_tags(array( @@ -76,8 +73,6 @@ $page->replace_tags(array( )); -$page->replace_langs($lang); - $page->output(); diff --git a/preferences.php b/preferences.php index 402716e..6520331 100644 --- a/preferences.php +++ b/preferences.php @@ -156,8 +156,6 @@ $page->replace_tags(array( )); -$page->replace_langs($lang); - $page->output(); ?> diff --git a/templates/default/header.tpl b/templates/default/header.tpl index 7707874..9f680e1 100644 --- a/templates/default/header.tpl +++ b/templates/default/header.tpl @@ -9,7 +9,7 @@ - {TODO_JS} + {TODO_JS} \ No newline at end of file diff --git a/templates/default/month.tpl b/templates/default/month.tpl index c33987d..dc24b50 100644 --- a/templates/default/month.tpl +++ b/templates/default/month.tpl @@ -55,7 +55,7 @@ - - @@ -40,18 +31,10 @@ {DAY} -
-
- {JS_OPEN_EVENT} {EVENT_TITLE} -
-
+ {ALLDAY} -
-
-   {JS_OPEN_EVENT} {EVENT_TIME} {EVENT_TITLE} -
-
+ {EVENT} @@ -61,18 +44,10 @@ {DAY} -
-
- {JS_OPEN_EVENT} {EVENT_TITLE} -
-
+ {ALLDAY} -
-
-   {JS_OPEN_EVENT} {EVENT_TIME} {EVENT_TITLE} -
-
+ {EVENT} -- cgit v1.2.3
+ {START_DATE} ({START_TIME}) @@ -65,7 +65,7 @@
+ {START_DATE} ({START_TIME}) diff --git a/templates/default/month_large.tpl b/templates/default/month_large.tpl index 0290a1d..7e63d0a 100644 --- a/templates/default/month_large.tpl +++ b/templates/default/month_large.tpl @@ -13,23 +13,14 @@ - -
-
- {JS_OPEN_EVENT} {EVENT_TITLE} -
-
+ {ALLDAY} -
-
-   {JS_OPEN_EVENT} {EVENT_TIME} {EVENT_TITLE} -
-
+ {EVENT}