Dotclear

source: plugins/eventdata/_public.php @ 1002

Revision 1002, 22.6 KB checked in by JcDenis, 14 years ago (diff)

eventdata: oops too fast

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3# This file is part of eventdata, a plugin for Dotclear 2.
4#
5# Copyright (c) 2009 JC Denis and contributors
6# jcdenis@gdwd.com
7#
8# Licensed under the GPL version 2.0 license.
9# A copy of this license is available in LICENSE file or at
10# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11# -- END LICENSE BLOCK ------------------------------------
12
13if (!defined('DC_RC_PATH')) return;
14
15# Localized string we find in template
16__('Event');
17__('Events');
18__('Dates of events');
19__('all');
20__('ongoing');
21__('outgoing');
22__('notstarted');
23__('started');
24__('notfinished');
25__('finished');
26__('From %S to %E');
27
28# Load _wigdets.php
29require dirname(__FILE__).'/_widgets.php';
30
31# Public urls, blocks, values, behaviors...
32if ($core->blog->settings->event_option_active) {
33     $core->addBehavior('publicHeadContent',array('eventdataPublic','publicHeadContent'));
34     $core->addBehavior('publicBeforeDocument',array('eventdataPublic','publicBeforeDocument'));
35     $core->addBehavior('tplBeforeData',array('eventdataPublic','tplBeforeData'));
36
37     if (!$core->blog->settings->event_tpl_dis_bhv) {
38          $core->addBehavior('publicEntryBeforeContent',array('eventdataPublic','publicEntryBeforeContent'));
39          $core->addBehavior('publicEntryAfterContent',array('eventdataPublic','publicEntryAfterContent'));
40     }
41
42     if ($core->blog->settings->event_option_public) {
43          $u = $core->blog->settings->event_tpl_url ? $core->blog->settings->event_tpl_url : 'events';
44          $core->url->register($u,$u,'^'.$u.'(|/.+)$',array('eventdataPublic','events'));
45     }
46     $core->url->register('eventstheme','eventstheme','^eventstheme/(.+)$',array('eventdataPublic','eventstheme'));
47
48     $core->tpl->addBlock('EventEntries',array('eventdataPublic','EventEntries'));
49     $core->tpl->addBlock('EventPagination',array('eventdataPublic','EventPagination'));
50     $core->tpl->addValue('EventPageURL',array('eventdataPublic','EventPageURL'));
51     $core->tpl->addValue('EventPageTitle',array('eventdataPublic','EventPageTitle'));
52     $core->tpl->addValue('EventPageDescription',array('eventdataPublic','EventPageDescription'));
53     $core->tpl->addValue('EventPageNav',array('eventdataPublic','EventPageNav'));
54
55     $core->tpl->addBlock('EntryEventDates',array('eventdataPublic','EntryEventDates'));
56     $core->tpl->addBlock('EventDatesHeader',array('eventdataPublic','EventDatesHeader'));
57     $core->tpl->addBlock('EventDatesFooter',array('eventdataPublic','EventDatesFooter'));
58     $core->tpl->addValue('EventFullDate',array('eventdataPublic','EventFullDate'));
59     $core->tpl->addValue('EventStartDate',array('eventdataPublic','EventStartDate'));
60     $core->tpl->addValue('EventStartTime',array('eventdataPublic','EventStartTime'));
61     $core->tpl->addValue('EventEndDate',array('eventdataPublic','EventEndDate'));
62     $core->tpl->addValue('EventEndTime',array('eventdataPublic','EventEndTime'));
63     $core->tpl->addValue('EventPeriod',array('eventdataPublic','EventPeriod'));
64
65     $core->tpl->addValue('EventThemeURL',array('eventdataPublic','EventThemeURL'));
66     $core->tpl->addValue('EventFeedURL',array('eventdataPublic','EventFeedURL'));
67
68} else {
69     $core->tpl->addBlock('EventEntries',array('eventdataPublic','EventDisableBlock'));
70     $core->tpl->addBlock('EventPagination',array('eventdataPublic','EventDisableBlock'));
71     $core->tpl->addValue('EventPageURL',array('eventdataPublic','EventDisableValue'));
72     $core->tpl->addValue('EventPageTitle',array('eventdataPublic','EventDisableValue'));
73     $core->tpl->addValue('EventPageDescription',array('eventdataPublic','EventDisableValue'));
74     $core->tpl->addValue('EventPageNav',array('eventdataPublic','EventDisableValue'));
75
76     $core->tpl->addBlock('EntryEventDates',array('eventdataPublic','EventDisableBlock'));
77     $core->tpl->addBlock('EventDatesHeader',array('eventdataPublic','EventDisableBlock'));
78     $core->tpl->addBlock('EventDatesFooter',array('eventdataPublic','EventDisableBlock'));
79     $core->tpl->addValue('EventFullDate',array('eventdataPublic','EventDisableValue'));
80     $core->tpl->addValue('EventStartDate',array('eventdataPublic','EventDisableValue'));
81     $core->tpl->addValue('EventStartTime',array('eventdataPublic','EventDisableValue'));
82     $core->tpl->addValue('EventEndDate',array('eventdataPublic','EventDisableValue'));
83     $core->tpl->addValue('EventEndTime',array('eventdataPublic','EventDisableValue'));
84     $core->tpl->addValue('EventPeriod',array('eventdataPublic','EventDisableValue'));
85
86     $core->tpl->addValue('EventThemeURL',array('eventdataPublic','EventDisableValue'));
87     $core->tpl->addValue('EventFeedURL',array('eventdataPublic','EventDisableValue'));
88}
89
90class eventdataPublic extends dcUrlHandlers
91{
92     private static function tpl_root()
93     {
94          return array_pop(explode(PATH_SEPARATOR, DC_PLUGINS_ROOT.'/eventdata/default-templates/eventdata-'));
95     }
96     # Plugin disabled
97     public static function EventDisablePage($a)
98     {
99          self::p404(); exit;
100     }
101     public static function EventDisableBlock($a,$b)
102     {
103          return '';
104     }
105     public static function EventDisableValue($a)
106     {
107          return '';
108     }
109     # return tpl path if exist
110     private static function eventTpl($file='',$strict=false)
111     {
112          global $core;
113          if ($file) { $file = '/'.$file; }
114          // default
115          $default_dir = self::tpl_root().'default';
116          // user
117          $user_dir = self::tpl_root().$core->blog->settings->event_tpl_theme;
118          // theme
119          $theme_dir = self::tpl_root().$core->blog->settings->theme;
120
121          if (file_exists($theme_dir.$file))
122               return $theme_dir;
123          elseif (!$strict && file_exists($user_dir.$file))
124               return $user_dir;
125          elseif (!$strict && file_exists($default_dir.$file))
126               return $default_dir;
127          else
128               return '';
129     }
130     # Find if $_ctx->events or $_ctx->posts exists
131     private static function eventCtx($content)
132     {
133          return '<?php if (!$_ctx->exists("events")) { $eventctx = "posts"; } else { $eventctx = "events"; } ?>'.$content.'<?php unset($eventctx); ?>';
134     }
135     # Specific post_params for event entries
136     public static function eventParams()
137     {
138          global $core, $_ctx;
139          $res = "<?php\n\$params = \$_ctx->post_params;\n?>";
140
141          if (null === $core->blog->settings->event_no_cats)
142               return $res;
143
144          $cats = @unserialize($core->blog->settings->event_no_cats);
145
146          if (!is_array($cats))
147               return $res;
148
149          $res .= "<?php\nif (!isset(\$params['sql'])) { \$params['sql'] = ''; }\n";
150          foreach ($cats AS $k => $cat_id) {
151               $res .= "\$params['sql'] .= \" AND P.cat_id != '$cat_id' \";\n";
152          }
153          return $res.'?>';
154     }
155     # Return full eventdata theme url (? don't need)
156     public static function EventThemeURL($attr)
157     {
158          global $core;
159          return self::eventTpl() ?  $core->blog->url.'eventstheme/' : '';
160     }
161     # Feed Url
162     public static function EventFeedURL($attr)
163     {
164          $type = !empty($attr['type']) ? $attr['type'] : 'atom';
165
166          if (!preg_match('#^(rss2|atom)$#',$type))
167               $type = 'atom';
168         
169          $f = $GLOBALS['core']->tpl->getFilters($attr);
170          return '<?php echo '.sprintf($f,'$core->blog->url.$core->blog->settings->event_tpl_url."/feed/'.$type.'"').'; ?>';
171     }
172     # List of events of a post
173     public static function EntryEventDates($attr,$content)
174     {
175          global $core, $_ctx;
176
177          # Not on post page
178          if ('post.html' != $_ctx->current_tpl || !$_ctx->posts->post_id) return;
179
180          $type = !empty($attr['event_type']) ? '"'.addslashes($attr['event_type']).'"' : '"event"';
181          $lastn = !empty($attr['lastn']) ? abs((integer) $attr['lastn'])+0 : 'null';
182          $period = isset($attr['period']) ? '"'.addslashes($attr['period']).'"' : 'null';
183          $start = isset($attr['start']) ? '"'.addslashes($attr['start']).'"' : 'null';
184          $end = isset($attr['end']) ? '"'.addslashes($attr['end']).'"' : 'null';
185          $sort = isset($attr['order']) && strtoupper($attr['order']) == 'ASC' ? '"ASC"' : '"DESC"';
186
187          return
188          "<?php\n".
189          'if (!isset($event)) { $event = new dcEvent($core); }'."\n".
190          "\$_ctx->events = \$event->getEvent($type,$lastn,$start,$end,\$_ctx->posts->post_id,$period,$sort);\n".
191          'while ($_ctx->events->fetch()) : ?>'.$content.'<?php endwhile; '."\n".
192          '$_ctx->events = null;'."\n".
193          '?>';
194     }
195     # Start of loop of EntryEventDates
196     public static function EventDatesHeader($attr,$content)
197     {
198          return self::eventCtx('<?php if ($_ctx->{$eventctx}->isStart()) : ?>'.$content.'<?php endif; ?>');
199     }
200     # End of loop of EntryEventDates
201     public static function EventDatesFooter($attr,$content)
202     {
203          return self::eventCtx('<?php if ($_ctx->{$eventctx}->isEnd()) : ?>'.$content.'<?php endif; ?>');
204     }
205     # Full date of an event (friendly read)
206     public static function EventFullDate($attr)
207     {
208          $format = !empty($attr['format']) ? addslashes($attr['format']) : '';
209          $start_format = !empty($attr['start_format']) ? addslashes($attr['start_format']) : '';
210          $end_format = !empty($attr['end_format']) ? addslashes($attr['end_format']) : '';
211          $f = $GLOBALS['core']->tpl->getFilters($attr);
212          $fs = $fe = '';
213
214          if (!empty($attr['rfc822']))
215               $fs = sprintf($f,"dt::rfc822(strtotime(\$_ctx->{\$eventctx}->event_start),\$_ctx->posts->post_tz)");
216          elseif (!empty($attr['iso8601']))
217               $fs = sprintf($f,"dt::iso8601(strtotime(\$_ctx->{\$eventctx}->event_start),\$_ctx->posts->post_tz)");
218          elseif ($format)
219               $fs = sprintf($f,"dt::dt2str('".$format."',\$_ctx->{\$eventctx}->event_start)");
220          else 
221               $fs = sprintf($f,"dt::dt2str(\$core->blog->settings->date_format,\$_ctx->{\$eventctx}->event_start)");
222
223          if (!empty($attr['rfc822']))
224               $fe = sprintf($f,"dt::rfc822(strtotime(\$_ctx->{\$eventctx}->event_end),\$_ctx->posts->post_tz)");
225          elseif (!empty($attr['iso8601']))
226               $fe = sprintf($f,"dt::iso8601(strtotime(\$_ctx->{\$eventctx}->event_end),\$_ctx->posts->post_tz)");
227          elseif ($format)
228               $fe = sprintf($f,"dt::dt2str('".$format."',\$_ctx->{\$eventctx}->event_end)");
229          else
230               $fe = sprintf($f,"dt::dt2str(\$core->blog->settings->date_format,\$_ctx->{\$eventctx}->event_end)");
231
232          return self::eventCtx("<?php echo str_replace(array('%S','%E','%%'),array($fs,$fe,'%'),__('From %S to %E')); ?>");
233     }
234     # Start date of an event
235     public static function EventStartDate($attr)
236     {
237          $format = !empty($attr['format']) ? addslashes($attr['format']) : '';
238          $f = $GLOBALS['core']->tpl->getFilters($attr);
239
240          if (!empty($attr['rfc822']))
241               $res = sprintf($f,"dt::rfc822(strtotime(\$_ctx->{\$eventctx}->event_start),\$_ctx->posts->post_tz)");
242          elseif (!empty($attr['iso8601']))
243               $res = sprintf($f,"dt::iso8601(strtotime(\$_ctx->{\$eventctx}->event_start),\$_ctx->posts->post_tz)");
244          elseif ($format)
245               $res = sprintf($f,"dt::dt2str('".$format."',\$_ctx->{\$eventctx}->event_start)");
246          else 
247               $res = sprintf($f,"dt::dt2str(\$core->blog->settings->date_format,\$_ctx->{\$eventctx}->event_start)");
248
249          return self::eventCtx('<?php echo '.$res.'; ?>');
250     }
251     # Start time of an event
252     public static function EventStartTime($attr)
253     {
254          $f = $GLOBALS['core']->tpl->getFilters($attr);
255          $res = sprintf($f,"dt::dt2str(".(!empty($attr['format']) ? "'".addslashes($attr['format'])."'" : '$core->blog->settings->time_format').",\$_ctx->{\$eventctx}->event_start)");
256
257          return self::eventCtx('<?php echo '.$res.'; ?>');
258     }
259     # End date of an event
260     public static function EventEndDate($attr)
261     {
262          $format = !empty($attr['format']) ? addslashes($attr['format']) : '';
263          $f = $GLOBALS['core']->tpl->getFilters($attr);
264
265          if (!empty($attr['rfc822']))
266               $res = sprintf($f,"dt::rfc822(strtotime(\$_ctx->{\$eventctx}->event_end),\$_ctx->posts->post_tz)");
267          elseif (!empty($attr['iso8601']))
268               $res = sprintf($f,"dt::iso8601(strtotime(\$_ctx->{\$eventctx}->event_end),\$_ctx->posts->post_tz)");
269          elseif ($format)
270               $res = sprintf($f,"dt::dt2str('".$format."',\$_ctx->{\$eventctx}->event_end)");
271          else
272               $res = sprintf($f,"dt::dt2str(\$core->blog->settings->date_format,\$_ctx->{\$eventctx}->event_end)");
273
274          return self::eventCtx('<?php echo '.$res.'; ?>');
275     }
276     # End time of an event
277     public static function EventEndTime($attr)
278     {
279          $f = $GLOBALS['core']->tpl->getFilters($attr);
280          $res = sprintf($f,"dt::dt2str(".(!empty($attr['format']) ? "'".addslashes($attr['format'])."'" : '$core->blog->settings->time_format').",\$_ctx->{\$eventctx}->event_end)");
281
282          return self::eventCtx('<?php echo '.$res.'; ?>');
283     }
284     # Period of an event
285     public static function EventPeriod($attr)
286     {
287          $format = !empty($attr['format']) ? addslashes($attr['format']) : '';
288          $f = $GLOBALS['core']->tpl->getFilters($attr);
289         
290          $res = 
291          "if (strtotime(\$_ctx->{\$eventctx}->event_start) > time()) {\n".
292          " echo ".sprintf($f,(empty($attr['strict']) ? "__('scheduled')" : "'scheduled'"))."; }\n".
293          "elseif (strtotime(\$_ctx->{\$eventctx}->event_start) < time() && strtotime(\$_ctx->{\$eventctx}->event_end) > time()) {\n".
294          " echo ".sprintf($f,(empty($attr['strict']) ? "__('ongoing')" : "'ongoing'"))."; }\n".
295          "elseif (strtotime(\$_ctx->{\$eventctx}->event_end) < time()) {\n".
296          " echo ".sprintf($f,(empty($attr['strict']) ? "__('finished')" : "'finished'"))."; }\n";
297
298          return self::eventCtx('<?php '.$res.'; ?>');
299     }
300     # Return events page url
301     public static function EventPageURL($attr)
302     {
303          return '<?php echo $core->blog->url.$core->blog->settings->event_tpl_url; ?>';
304     }
305     # Title of public page
306     public static function EventPageTitle($attr)
307     {
308          global $core,$_ctx;
309          $f = $core->tpl->getFilters($attr);
310          $cats = @unserialize($core->blog->settings->event_tpl_cats);
311          $cat_id = @$_ctx->categories->cat_id;
312
313          if (is_array($cats) && in_array($cat_id,$cats) && !empty($cat_id))
314               return '<?php echo '.sprintf($f,'$_ctx->categories->cat_title').'; ?>';
315          else
316               return '<?php echo '.sprintf($f,'$core->blog->settings->event_tpl_title').'; ?>';
317     }
318     # Description of public page
319     public static function EventPageDescription($attr)
320     {
321          global $core,$_ctx;
322          $f = $core->tpl->getFilters($attr);
323          $cats = unserialize($core->blog->settings->event_tpl_cats);
324          $cat_id = @$_ctx->categories->cat_id;
325
326          if (is_array($cats) && in_array($cat_id,$cats))
327               return '<?php echo '.sprintf($f,'$_ctx->categories->cat_desc').'; ?>';
328          else
329               return '<?php echo '.sprintf($f,'$core->blog->settings->event_tpl_desc').'; ?>';
330     }
331     # Navigation menu for public page
332     public static function EventPageNav($attr)
333     {
334          global $core,$_ctx;
335          $f = $core->tpl->getFilters($attr);
336         
337          $menu = array(
338               __('All') => 'all',
339               __('Ongoing') => 'ongoing',
340               __('Outgoing') => 'outgoing',
341               __('Not started') => 'notstarted',
342               __('Started') => 'started',
343               __('Not finished') => 'notfinished',
344               __('Finished') => 'finished'
345          );
346
347          if (isset($attr['menus'])) {
348               $attr_menu = array();
349               $attr_menus = explode(',',$attr['menus']);
350               foreach($menu AS $k => $v) {
351                    if (in_array($v,$attr_menus))
352                         $attr_menu[$k] = $v;
353               }
354               if (!empty($attr_menu))
355                    $menu = $attr_menu;
356          }
357          $res = '';
358          foreach($menu AS $k => $v) {
359               $res .= $_ctx->post_params['period'] == $v ? '<li class="active">' : '<li>';
360               $res .= '<a href="'.self::EventPageURL('').'/'.$v.'"><?php echo '.sprintf($f,'"'.$k.'"').'; ?></a></li>';
361          }
362
363          return empty($res) ? '' : '<div id="event_nav"><ul>'.$res.'</ul></div>';
364     }
365     # Posts list with events (like Entries)
366     public static function EventEntries($attr,$content)
367     {
368          $res = self::eventParams()."<?php\n";
369
370          # Limit
371          $lastn = 0;
372          if (isset($attr['lastn']))
373               $lastn = abs((integer) $attr['lastn'])+0;
374
375          $res .= 'if (!isset($_page_number)) { $_page_number = 1; }'."\n";
376          if ($lastn > 0)
377               $res .= "\$params['limit'] = ".$lastn.";\n";
378          else
379               $res .= "\$params['limit'] = \$_ctx->nb_entry_per_page;\n";
380
381          # Pagination
382          if (!isset($attr['ignore_pagination']) || $attr['ignore_pagination'] == "0")
383               $res .= "\$params['limit'] = array(((\$_page_number-1)*\$params['limit']),\$params['limit']);\n";
384          else
385               $res .= "\$params['limit'] = array(0, \$params['limit']);\n";
386
387          # Author
388          if (isset($attr['author']))
389               $res .= "\$params['user_id'] = '".addslashes($attr['author'])."';\n";
390
391          # Cat
392          if (isset($attr['category']))
393               $res .= "\$params['cat_url'] = '".addslashes($attr['category'])."';\ncontext::categoryPostParam(\$params);\n";
394
395          # No cat
396          if (isset($attr['no_category']))
397               $res .= "@\$params['sql'] .= ' AND P.cat_id IS NULL ';\nunset(\$params['cat_url']);\n";
398
399          # Post type
400          if (!empty($attr['type']))
401               $res .= "\$params['post_type'] = preg_split('/\s*,\s*/','".addslashes($attr['type'])."',-1,PREG_SPLIT_NO_EMPTY);\n";
402
403          # Post url
404          if (!empty($attr['url']))
405               $res .= "\$params['post_url'] = '".addslashes($attr['url'])."';\n";
406
407          # Context
408          if (empty($attr['no_context']))
409          {
410               $res .=
411               'if ($_ctx->exists("users")) { '.
412                    "\$params['user_id'] = \$_ctx->users->user_id; ".
413               "}\n";
414               
415               $res .=
416               'if ($_ctx->exists("categories")) { '.
417                    "\$params['cat_id'] = \$_ctx->categories->cat_id; ".
418               "}\n";
419               
420               $res .=
421               'if ($_ctx->exists("archives")) { '.
422                    "\$params['post_year'] = \$_ctx->archives->year(); ".
423                    "\$params['post_month'] = \$_ctx->archives->month(); ".
424                    "unset(\$params['limit']); ".
425               "}\n";
426               
427               $res .=
428               'if ($_ctx->exists("langs")) { '.
429                    "\$params['post_lang'] = \$_ctx->langs->post_lang; ".
430               "}\n";
431               
432               $res .=
433               'if (isset($_search)) { '.
434                    "\$params['search'] = \$_search; ".
435               "}\n";
436          }
437          # Event type
438          if (!empty($attr['event_type']))
439               $res .= "\$params['event_type'] = preg_split('/\s*,\s*/','".addslashes($attr['event_type'])."',-1,PREG_SPLIT_NO_EMPTY);\n";
440          else
441               $res .= "\$params['event_type'] = 'event';\n";
442
443          # Sort
444          $sortby = 'event_start';
445          $order = 'desc';
446          if (isset($attr['sortby'])) {
447               switch ($attr['sortby']) {
448                    case 'title': $sortby = 'post_title'; break;
449                    case 'selected' : $sortby = 'post_selected'; break;
450                    case 'author' : $sortby = 'user_id'; break;
451                    case 'date' : $sortby = 'post_dt'; break;
452                    case 'id' : $sortby = 'post_id'; break;
453                    case 'start' : $sortby = 'event_start'; break;
454                    case 'end' : $sortby = 'event_end'; break;
455               }
456          }
457          if (isset($attr['order']) && preg_match('/^(desc|asc)$/i',$attr['order']))
458               $order = $attr['order'];
459
460          $res .= "\$params['order'] = '".$sortby." ".$order."';\n";
461          # No content
462          if (isset($attr['no_content']) && $attr['no_content'])
463               $res .= "\$params['no_content'] = true;\n";
464
465          # Selected
466          if (isset($attr['selected']))
467               $res .= "\$params['post_selected'] = ".(integer) (boolean) $attr['selected'].";";
468
469          # Period
470          if (isset($attr['period'])) //could exists by url
471               $res .= "if (!isset(\$params['period'])) { \$params['period'] = '".addslashes($attr['period'])."'; }\n";
472
473          # Tag
474          if (!empty($attr['meta_id']))
475               $res .= "\$params['meta_id'] = preg_split('/\s*,\s*/','".addslashes($attr['meta_id'])."',-1,PREG_SPLIT_NO_EMPTY);\n";
476
477          $res .= 
478          '$_ctx->post_params = $params;'."\n".
479          '$event = new dcEvent($core);'."\n".
480          '$_ctx->posts = $event->getPostsByEvent($params);'."\n".
481          'unset($params);'."\n".
482          'while ($_ctx->posts->fetch()) : ?>'.$content.'<?php endwhile; '."\n".
483          '$_ctx->posts = null; $_ctx->post_params = null;'."\n".
484          '?>';
485
486          return $res;
487     }
488     # Pagination
489     public function EventPagination($attr,$content)
490     {
491          $res = self::eventParams().
492          "<?php\n\$_ctx->pagination = \$event->getPostsByEvent(\$params,true); unset(\$params);\n?>";
493         
494          if (isset($attr['no_context'])) return $res.$content;
495
496          return
497          $res.
498          '<?php if ($_ctx->pagination->f(0) > $_ctx->posts->count()) : ?>'.
499          $content.
500          '<?php endif; ?>';
501     }
502     # Public page
503     public static function events($args)
504     {
505          $core =& $GLOBALS['core'];
506
507          $n = self::getPageNumber($args);
508
509          # Feeds
510          if (preg_match('%(^|/)feed/(rss2|atom)$%',$args,$m)){
511               $args = preg_replace('#(^|/)feed/(rss2|atom)$#','',$args);
512               $type = $m[2];
513               $file = 'events-'.$type.'.xml';
514               $mime = 'application/xml';
515               $core->tpl->setPath($core->tpl->getPath(),self::tpl_root().'default/feed/');
516          # Normal
517          } else {
518               if ($n)
519                    $GLOBALS['_page_number'] = $n;
520
521               if (preg_match('%(^|/)(started|notstarted|scheduled|ongoing|outgoing|finished|notfinished|all)$%',$args,$m))
522                    $GLOBALS['_ctx']->post_params = array('period' => $m[2]);
523
524               $file = 'events.html';
525               $mime='text/html';
526          }
527
528          self::serveDocument($file,$mime);
529          exit;
530     }
531     # Return file from eventdata theme
532     public static function eventstheme($args)
533     {
534          global $core;
535
536          if (!preg_match('#([^/]+)$#',$args,$m)) {
537               self::p404();
538               exit;
539          }
540
541          $f = $m[1];
542
543          if (strstr($f,"..") !== false) {
544               self::p404();
545               exit;
546          }
547
548          $path = self::eventTpl($f);
549          if (!$path) {
550               self::p404();
551               exit;
552          }
553          $file = $path.'/'.$f;
554
555          $allowed_types = array('png','jpg','jpeg','gif','css','js','swf');
556          if (!file_exists($file) || !in_array(files::getExtension($file),$allowed_types)) {
557               self::p404();
558               exit;
559          }
560
561          http::cache(array_merge(array($file),get_included_files()));
562          $type = files::getMimeType($file);
563          header('Content-Type: '.$type);
564          header('Content-Length: '.filesize($file));
565          if ($type != "text/css" || $core->blog->settings->url_scan == 'path_info') {
566               readfile($file);
567          } else {
568               echo preg_replace('#url\((?!(http:)|/)#','url('.$core->blog->url.'eventstheme/',file_get_contents($file));
569          }
570          exit;
571     }
572     # Set tpl path
573     public static function publicBeforeDocument(&$core)
574     {
575          if ('' != ($path = self::eventTpl()))
576              $core->tpl->setPath($core->tpl->getPath(),$path);
577     }
578     # Include css
579     public static function publicHeadContent(&$core)
580     {
581          if (!file_exists($core->blog->themes_path.'/'.$core->blog->settings->theme.'/tpl/events.html') 
582           && '' != self::eventTpl('eventdata.css'))
583               echo "<style type=\"text/css\">\n@import url(".$core->blog->url."eventstheme/eventdata.css);\n</style>\n";
584     }
585     # Reordered categories redirection to public page
586     public static function tplBeforeData($core)
587     {
588          $_ctx =& $GLOBALS['_ctx'];
589          if (null === $core->blog->settings->event_tpl_cats) return;
590
591          $cats = @unserialize($core->blog->settings->event_tpl_cats);
592
593          if (!is_array($cats) 
594               || 'category.html' != $_ctx->current_tpl 
595               || !in_array($_ctx->categories->cat_id,$cats)) return;
596
597          self::serveDocument('events.html');
598          exit;
599     }
600     # Include evententrybeforecontent.html of a theme if exists
601     public static function publicEntryBeforeContent($core,$_ctx)
602     {
603          if ('' != self::eventTpl('evententrybeforecontent.html',true)) {
604               if ('' != ($fc = $core->tpl->getData('evententrybeforecontent.html'))) {
605                    if (preg_match('|<body[^>]*?>(.*?)</body>|ms',$fc,$matches))
606                         echo $matches[1];
607               }
608          }
609     }
610     # Include evententryaftercontent.html of a theme if exists
611     public static function publicEntryAfterContent($core,$_ctx)
612     {
613          if ('' != self::eventTpl('evententryaftercontent.html',true)) {
614               if ('' != ($fc = $core->tpl->getData('evententryaftercontent.html'))) {
615                    if (preg_match('|<body[^>]*?>(.*?)</body>|ms',$fc,$matches))
616                         echo $matches[1];
617               }
618          }
619     }
620}
621?>
Note: See TracBrowser for help on using the repository browser.

Sites map