aboutsummaryrefslogtreecommitdiffstats
path: root/functions
diff options
context:
space:
mode:
authorChad Little <clittle@users.sourceforge.net>2004-01-31 07:07:37 +0000
committerChad Little <clittle@users.sourceforge.net>2004-01-31 07:07:37 +0000
commitc143f2891418cb0f0ae0f80f7d2d58e69879a722 (patch)
tree334840b988d61e27d5ae3ab1b9ee29a2cf0bdd0a /functions
parent90f43e0c205d2e511bb0255fa20d422d15cffc64 (diff)
downloadphpicalendar-c143f2891418cb0f0ae0f80f7d2d58e69879a722.tar.gz
phpicalendar-c143f2891418cb0f0ae0f80f7d2d58e69879a722.tar.bz2
phpicalendar-c143f2891418cb0f0ae0f80f7d2d58e69879a722.zip
Many many changes. Faster templating.
Diffstat (limited to 'functions')
-rw-r--r--functions/date_functions.php15
-rw-r--r--functions/template.php212
2 files changed, 121 insertions, 106 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
+$return = "
- <script language="Javascript" type="text/javascript"><!--
+ <script language=\"Javascript\" type=\"text/javascript\"><!--
var eventData = new EventData('$escaped_event', '$escaped_calendar', '$escaped_start', '$escaped_end', '$description', '$status', '$location', '$organizer', '$attendee', '$url');
document.popup_data[$popup_data_index] = eventData;
- // --></script>
+ // --></script>";
-END;
- echo '<a class="'.$link_class.'" href="#" onclick="openEventWindow('.$popup_data_index.'); return false;">';
+ $return .= '<a class="'.$link_class.'" href="#" onclick="openEventWindow('.$popup_data_index.'); return false;">';
$popup_data_index++;
} else {
- echo '<a class="'.$link_class.'" href="'.$res[1].'">';
+ $return .= '<a class="'.$link_class.'" href="'.$res[1].'">';
}
- echo $pre_text.$event_text.$post_text.'</a>'."\n";
+ $return .= $pre_text.$event_text.$post_text.'</a>'."\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('<!-- switch ' . $tag . ' on -->(.*)<!-- switch ' . $tag . ' off -->', '', $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('<!-- loop weekday on -->(.*)<!-- loop weekday off -->', $weekday_loop, $template);
- $return = eregi_replace('<!-- loop monthweeks on -->(.*)<!-- loop monthweeks off -->', $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'] .= '<div align="left" class="V10">';
+ $switch['allday'] .= openevent($event_calna, '', '', $val, $month_event_lines, 15, '', '', 'psf', $event_url);
+ $switch['allday'] .= '</div>';
+ } 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'] .= '<div align="left" class="V9">';
+ $switch['event'] .= openevent($event_calna, $event_start, $event_end, $val, $month_event_lines, 10, "$start2 ", '', 'ps3', $event_url);
+ $switch['event'] .= '</div>';
+ }
+ }
+ }
+ }
+
+ foreach ($switch as $tag => $data) {
+ if (!$data) {
+ $temp_middle = ereg_replace('<!-- switch ' . $tag . ' on -->(.*)<!-- switch ' . $tag . ' off -->', '', $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('<!-- loop monthweeks on -->(.*)<!-- loop monthweeks off -->', $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('<!-- switch ' . $tag . ' on -->(.*)<!-- switch ' . $tag . ' off -->', '', $this->page);
+ $this->page = ereg_replace('<!-- switch ' . $tag . ' on -->(.*)<!-- switch ' . $tag . ' off -->', '', $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);
}
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy