Dotclear

source: plugins/eventHandler/_public.php @ 3059

Revision 3059, 55.4 KB checked in by JcDenis, 12 years ago (diff)

eventHanlder oldies

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3# This file is part of eventHandler, a plugin for Dotclear 2.
4#
5# Copyright (c) 2009-2010 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;}
14if (version_compare(str_replace("-r","-p",DC_VERSION),'2.2-alpha','<')){return;}
15
16# set ns
17$core->blog->settings->addNamespace('eventHandler');
18
19# Localisation
20__('scheduled');
21__('ongoing');
22__('finished');
23
24# Load _wigdets.php
25require dirname(__FILE__).'/_widgets.php';
26
27# Default tpl path
28$core->tpl->setPath($core->tpl->getPath(),dirname(__FILE__).'/default-templates');
29
30# Public behaviors
31$core->addBehavior('publicHeadContent',array('publicEventHandler','publicHeadContent'));
32$core->addBehavior('publicEntryBeforeContent',array('publicEventHandler','publicEntryBeforeContent'));
33$core->addBehavior('publicEntryAfterContent',array('publicEventHandler','publicEntryAfterContent'));
34
35# Missing values
36$core->tpl->addValue('BlogTimezone',array('tplEventHandler','BlogTimezone'));
37
38# Page of events
39$core->tpl->addBlock('EventsIf',array('tplEventHandler','EventsIf'));
40$core->tpl->addValue('EventsMenuPeriod',array('tplEventHandler','EventsMenuPeriod'));
41$core->tpl->addValue('EventsMenuSortOrder',array('tplEventHandler','EventsMenuSortOrder'));
42$core->tpl->addValue('EventsFeedURL',array('tplEventHandler','EventsFeedURL'));
43$core->tpl->addValue('EventsURL',array('tplEventHandler','EventsURL'));
44$core->tpl->addValue('EventsPeriod',array('tplEventHandler','EventsPeriod'));
45$core->tpl->addValue('EventsInterval',array('tplEventHandler','EventsInterval'));
46
47$core->tpl->addBlock('EventsEntries',array('tplEventHandler','EventsEntries'));
48$core->tpl->addBlock('EventsPagination',array('tplEventHandler','EventsPagination'));
49$core->tpl->addBlock('EventsEntryIf',array('tplEventHandler','EventsEntryIf'));
50$core->tpl->addBlock('EventsDateHeader',array('tplEventHandler','EventsDateHeader'));
51$core->tpl->addBlock('EventsDateFooter',array('tplEventHandler','EventsDateFooter'));
52$core->tpl->addValue('EventsEntryDate',array('tplEventHandler','EventsEntryDate'));
53$core->tpl->addValue('EventsEntryTime',array('tplEventHandler','EventsEntryTime'));
54$core->tpl->addValue('EventsEntryCategoryURL',array('tplEventHandler','EventsEntryCategoryURL'));
55$core->tpl->addValue('EventsEntryAddress',array('tplEventHandler','EventsEntryAddress'));
56$core->tpl->addValue('EventsEntryLatitude',array('tplEventHandler','EventsEntryLatitude'));
57$core->tpl->addValue('EventsEntryLongitude',array('tplEventHandler','EventsEntryLongitude'));
58$core->tpl->addValue('EventsEntryDuration',array('tplEventHandler','EventsEntryDuration'));
59$core->tpl->addValue('EventsEntryPeriod',array('tplEventHandler','EventsEntryPeriod'));
60$core->tpl->addValue('EventsEntryMap',array('tplEventHandler','EventsEntryMap'));
61
62# Events of a post
63$core->tpl->addBlock('EventsOfPost',array('tplEventHandler','EventsOfPost'));
64$core->tpl->addBlock('EventsOfPostHeader',array('tplEventHandler','EventsOfPostHeader'));
65$core->tpl->addBlock('EventsOfPostFooter',array('tplEventHandler','EventsOfPostFooter'));
66$core->tpl->addBlock('EventOfPostIf',array('tplEventHandler','EventOfPostIf'));
67$core->tpl->addValue('EventOfPostURL',array('tplEventHandler','EventOfPostURL'));
68$core->tpl->addValue('EventOfPostTitle',array('tplEventHandler','EventOfPostTitle'));
69$core->tpl->addValue('EventOfPostDate',array('tplEventHandler','EventOfPostDate'));
70$core->tpl->addValue('EventOfPostTime',array('tplEventHandler','EventOfPostTime'));
71$core->tpl->addValue('EventOfPostAuthorCommonName',array('tplEventHandler','EventOfPostAuthorCommonName'));
72$core->tpl->addValue('EventOfPostAuthorLink',array('tplEventHandler','EventOfPostAuthorLink'));
73$core->tpl->addValue('EventOfPostCategory',array('tplEventHandler','EventOfPostCategory'));
74$core->tpl->addValue('EventOfPostCategoryURL',array('tplEventHandler','EventOfPostCategoryURL'));
75$core->tpl->addValue('EventOfPostAddress',array('tplEventHandler','EventOfPostAddress'));
76$core->tpl->addValue('EventOfPostDuration',array('tplEventHandler','EventOfPostDuration'));
77$core->tpl->addValue('EventOfPostPeriod',array('tplEventHandler','EventOfPostPeriod'));
78
79# Posts of an event
80$core->tpl->addBlock('PostsOfEvent',array('tplEventHandler','PostsOfEvent'));
81$core->tpl->addBlock('PostsOfEventHeader',array('tplEventHandler','PostsOfEventHeader'));
82$core->tpl->addBlock('PostsOfEventFooter',array('tplEventHandler','PostsOfEventFooter'));
83$core->tpl->addBlock('PostOfEventIf',array('tplEventHandler','PostOfEventIf'));
84$core->tpl->addValue('PostOfEventURL',array('tplEventHandler','PostOfEventURL'));
85$core->tpl->addValue('PostOfEventTitle',array('tplEventHandler','PostOfEventTitle'));
86$core->tpl->addValue('PostOfEventDate',array('tplEventHandler','PostOfEventDate'));
87$core->tpl->addValue('PostOfEventTime',array('tplEventHandler','PostOfEventTime'));
88$core->tpl->addValue('PostOfEventAuthorCommonName',array('tplEventHandler','PostOfEventAuthorCommonName'));
89$core->tpl->addValue('PostOfEventAuthorLink',array('tplEventHandler','PostOfEventAuthorLink'));
90$core->tpl->addValue('PostOfEventCategory',array('tplEventHandler','PostOfEventCategory'));
91$core->tpl->addValue('PostOfEventCategoryURL',array('tplEventHandler','PostOfEventCategoryURL'));
92
93# Public behaviors
94class publicEventHandler
95{
96     # Add some css and js to page
97     public static function publicHeadContent($core)
98     {
99          if (!$core->blog->settings->eventHandler->active){return;}
100         
101          $public_map_zoom = abs((integer) $core->blog->settings->eventHandler->public_map_zoom);
102          if (!$public_map_zoom) $public_map_zoom = 9;
103         
104          echo 
105          "\n<!-- JS for eventHandler maps--> \n".
106          "<script type=\"text/javascript\" src=\"".
107               $core->blog->getQmarkURL().'pf=eventHandler/js/event-public-map.js">'.
108          "</script> \n".
109         
110          "\n<!-- JS for eventHandler calendar--> \n".
111          "<script type=\"text/javascript\" src=\"".
112               $core->blog->getQmarkURL().'pf=eventHandler/js/event-public-cal.js">'.
113          "</script> \n".
114          "<script type=\"text/javascript\"> \n".
115          "//<![CDATA[\n".
116          " \$(function(){if(!document.getElementById){return;} \n".
117          \$.fn.eventHandlerCalendar.defaults.service_url = '".
118          html::escapeJS($core->blog->url.$core->url->getBase('eventhandler_pubrest').'/')."'; \n".
119          \$.fn.eventHandlerCalendar.defaults.service_func = '".
120          html::escapeJS('eventHandlerCalendar')."'; \n".
121          \$.fn.eventHandlerCalendar.defaults.blog_uid = '".
122          html::escapeJS($core->blog->uid)."'; \n".
123          \$.fn.eventHandlerCalendar.defaults.msg_wait = '".
124          html::escapeJS(__('Please wait'))."'; \n".
125          \$('.calendar-array').eventHandlerCalendar(); \n".
126          " })\n".
127          "//]]>\n".
128          "</script>\n";
129         
130          $extra_css = $core->blog->settings->eventHandler->public_extra_css;
131          if ($extra_css) {
132               echo 
133               "\n<!-- user css for eventHandler --> \n".
134               '<style type="text/css">'."\n".
135               html::escapeHTML($extra_css)."\n".
136               "\n</style>\n";
137          }
138     }
139
140     # Before entry content
141     public static function publicEntryBeforeContent($core,$_ctx)
142     {
143          return self::publicEntryContent($core,$_ctx,'before');
144     }
145
146     # After entry content
147     public static function publicEntryAfterContent($core,$_ctx)
148     {
149          return self::publicEntryContent($core,$_ctx,'after');
150     }
151
152     # Add list of events / posts on entries
153     protected static function publicEntryContent($core,$_ctx,$place)
154     {
155          $s = $core->blog->settings->eventHandler;
156         
157          if (!$s->active || $s->public_posts_of_event_place == '') return;
158         
159          $default_url_type = array(
160               'eventhandler_list',
161               'eventhandler_single',
162               'eventhandler_preview'
163          );
164         
165          # List of posts related to a event
166          if (in_array($core->url->type,$default_url_type))
167          {
168               if ($s->public_posts_of_event_place != $place) return;
169               
170               echo $core->tpl->getData('eventhandler-postsofevent.html');
171          }
172          # List of events related to a post
173          else
174          {
175               if ($s->public_events_of_post_place != $place) return;
176               
177               echo $core->tpl->getData('eventhandler-eventsofpost.html');
178          }
179     }
180}
181
182# URL handler
183class urlEventHandler extends dcUrlHandlers
184{
185     
186     # Call service from public for ajax request
187     public static function eventService($args)
188     {
189          global $core;
190          $core->rest->addFunction('eventHandlerCalendar',
191               array('eventHandlerPublicRest','calendar'));
192          $core->rest->serve();
193          exit;
194     }
195     
196     # Single event page
197     public static function eventSingle($args)
198     {
199          global $core, $_ctx;
200         
201          if ($args == '' 
202           || !$_ctx->preview && !$core->blog->settings->eventHandler->active)
203          {
204               self::p404();
205               return;
206          }
207          else
208          {
209               $is_ical = self::isIcalDocument($args);
210               $is_hcal = self::isHcalDocument($args);
211               $is_gmap = self::isGmapDocument($args);
212               
213               $core->blog->withoutPassword(false);
214               
215               $params = new ArrayObject();
216               $params['post_type'] = 'eventhandler';
217               $params['post_url'] = $args;
218               
219               $_ctx->eventHandler = new eventHandler($core);
220               $_ctx->posts = $_ctx->eventHandler->getEvents($params);
221               
222               $_ctx->comment_preview = new ArrayObject();
223               $_ctx->comment_preview['content'] = '';
224               $_ctx->comment_preview['rawcontent'] = '';
225               $_ctx->comment_preview['name'] = '';
226               $_ctx->comment_preview['mail'] = '';
227               $_ctx->comment_preview['site'] = '';
228               $_ctx->comment_preview['preview'] = false;
229               $_ctx->comment_preview['remember'] = false;
230               
231               $core->blog->withoutPassword(true);
232               
233               
234               if ($_ctx->posts->isEmpty())
235               {
236                    # The specified page does not exist.
237                    self::p404();
238               }
239               else
240               {
241                    $post_id = $_ctx->posts->post_id;
242                    $post_password = $_ctx->posts->post_password;
243                   
244                    # Password protected entry
245                    if ($post_password != '' && !$_ctx->preview)
246                    {
247                         # Get passwords cookie
248                         if (isset($_COOKIE['dc_passwd'])) {
249                              $pwd_cookie = unserialize($_COOKIE['dc_passwd']);
250                         } else {
251                              $pwd_cookie = array();
252                         }
253                         
254                         # Check for match
255                         if ((!empty($_POST['password']) && $_POST['password'] == $post_password)
256                         || (isset($pwd_cookie[$post_id]) && $pwd_cookie[$post_id] == $post_password))
257                         {
258                              $pwd_cookie[$post_id] = $post_password;
259                              setcookie('dc_passwd',serialize($pwd_cookie),0,'/');
260                         }
261                         else
262                         {
263                              self::serveDocument('password-form.html','text/html',false);
264                              return;
265                         }
266                    }
267                   
268                    if ($is_ical)
269                    {
270                         self::serveIcalDocument($_ctx->posts,$args);
271                    }
272                    elseif ($is_hcal)
273                    {
274                         self::serveHcalDocument($_ctx->posts,$args);
275                    }
276                    elseif ($is_gmap)
277                    {
278                         self::serveGmapDocument($_ctx->posts,$args);
279                    }
280                    else
281                    {
282                         self::serveDocument('eventhandler-single.html');
283                    }
284               }
285          }
286          return;
287     }
288     
289     # Preview single event from admin side
290     public static function eventPreview($args)
291     {
292          global $core, $_ctx;
293         
294          if (!preg_match('#^(.+?)/([0-9a-z]{40})/(.+?)$#',$args,$m)) {
295               # The specified Preview URL is malformed.
296               self::p404();
297          }
298          else
299          {
300               $user_id = $m[1];
301               $user_key = $m[2];
302               $post_url = $m[3];
303               if (!$core->auth->checkUser($user_id,null,$user_key)) {
304                    # The user has no access to the entry.
305                    self::p404();
306               }
307               else
308               {
309                    $_ctx->preview = true;
310                    self::eventSingle($post_url);
311               }
312          }
313     }
314     
315     # Multiple events page
316     public static function eventList($args)
317     {
318          global $core, $_ctx;
319         
320          $n = self::getPageNumber($args);
321          $is_ical = self::isIcalDocument($args);
322          $is_hcal = self::isHcalDocument($args);
323          $is_gmap = self::isGmapDocument($args);
324         
325          $_ctx->event_params = self::getEventsParams($args);
326         
327          if ($n)
328          {
329               $GLOBALS['_page_number'] = $n;
330          }
331         
332          # If it is ical do all job here
333          if ($is_hcal || $is_ical || $is_gmap)
334          {
335               $params = array();
336               // force limit on gmap
337               if ($is_gmap)
338               {
339                    $params['limit'] = array(0,30);
340               }
341               else
342               {
343                    $pn = $n ? $n : 1;
344                    $nbppf = $core->blog->settings->system->nb_post_per_feed;
345                    $params['limit'] = array((($pn-1)*$nbppf),$nbppf);
346               }
347               if ($_ctx->exists("categories"))
348               {
349                    $params['cat_id'] = $_ctx->categories->cat_id;
350               }
351               $params = array_merge($params,$_ctx->event_params);
352               
353               $eventHandler = new eventHandler($core);
354               $rs = $eventHandler->getEvents($params);
355               
356               if ($is_ical)
357               {
358                    self::serveIcalDocument($rs,$args);
359               }
360               elseif ($is_hcal)
361               {
362                    self::serveHcalDocument($rs,$args);
363               }
364               elseif ($is_gmap)
365               {
366                    self::serveGmapDocument($rs,$args);
367               }
368          }
369          # Else serve normal document
370          else
371          {
372               self::serveDocument('eventhandler-list.html');
373          }
374          return;
375     }
376     
377     # Classic feed
378     public static function eventFeed($args)
379     {
380          $type = null;
381          $cat_url = false;
382          $params = array();
383          $subtitle = '';
384         
385          $mime = 'application/xml';
386         
387          global $core, $_ctx;
388         
389          if (preg_match('!^([a-z]{2}(-[a-z]{2})?)/(.*)$!',$args,$m))
390          {
391               $params['lang'] = $m[1];
392               $args = $m[3];
393               
394               $_ctx->langs = $core->blog->getLangs($params);
395               
396               if ($_ctx->langs->isEmpty())
397               {
398                    # The specified language does not exist.
399                    self::p404();
400                    return;
401               }
402               else
403               {
404                    $_ctx->cur_lang = $m[1];
405               }
406          }
407         
408          if (preg_match('#^rss2/xslt$#',$args,$m))
409          {
410               # RSS XSLT stylesheet
411               self::serveDocument('rss2.xsl','text/xml');
412               return;
413          }
414          elseif (preg_match('#^(?:category/(.+)/)?(atom|rss2)$#',$args,$m))
415          {
416               # All posts or comments feed
417               $type = $m[2];
418               if (!empty($m[1]))
419               {
420                    $cat_url = $m[1];
421               }
422          }
423          else
424          {
425               # The specified Feed URL is malformed.
426               self::p404();
427               return;
428          }
429         
430          if ($cat_url)
431          {
432               $params['cat_url'] = $cat_url;
433               $params['post_type'] = 'eventhandler';
434               $_ctx->categories = $core->blog->getCategories($params);
435               
436               if ($_ctx->categories->isEmpty())
437               {
438                    # The specified category does no exist.
439                    self::p404();
440                    return;
441               }
442               
443               $subtitle = ' - '.$_ctx->categories->cat_title;
444          }
445         
446          $tpl = 'eventhandler-'.$type.'.xml';
447         
448          if ($type == 'atom')
449          {
450               $mime = 'application/atom+xml';
451          }
452         
453          $_ctx->nb_entry_per_page = $core->blog->settings->system->nb_post_per_feed;
454          $_ctx->short_feed_items = $core->blog->settings->system->short_feed_items;
455          $_ctx->feed_subtitle = $subtitle;
456         
457          header('X-Robots-Tag: '.context::robotsPolicy($core->blog->settings->system->robots_policy,''));
458          self::serveDocument($tpl,$mime);
459          if (!$cat_url)
460          {
461               $core->blog->publishScheduledEntries();
462          }
463     }
464     
465     # Parse URI for multiple events page
466     public static function getEventsParams($args)
467     {
468          global $core, $_ctx;
469         
470          $params = array();
471          $params['post_type'] = 'eventhandler';
472         
473          # Know period
474          $default_period_list = array(
475               'all',
476               'ongoing',
477               'outgoing',
478               'scheduled',
479               'started',
480               'notfinished',
481               'finished'
482          );
483          # Know order
484          $default_order_list = array(
485               'title' => 'LOWER(post_title)',
486               'selected' => 'post_selected',
487               'author' => 'LOWER(user_id)',
488               'date' => 'post_dt',
489               'startdt' => 'event_startdt',
490               'enddt' =>'event_enddt'
491          );
492         
493          # Test URI
494          if (!preg_match('#^'.
495               '((/category/([^/]+))|)'.
496               '('.
497                '(/('.implode('|',$default_period_list).'))|'. // period
498                '(/(on|in|of)/([0-9]{4})(/([0-9]{1,2})|)(/([0-9]{1,2})|)(/([0-9]{4})(/([0-9]{1,2})|)(/([0-9]{1,2})|)|))|'. // interval
499               ')'. 
500               '(/('.implode('|',array_keys($default_order_list)).')(/(asc|desc)|)|)'. // order
501               '(/ical.ics|/hcal.html|/gmap|/|)$#i',$args,$m))
502          {
503               self::p404();
504               return;
505          }
506         
507          # Get category
508          if (!empty($m[3]))
509          {
510               $cat_params['cat_url'] = $m[3];
511               $cat_params['post_type'] = 'eventhandler';
512               $_ctx->categories = $core->blog->getCategories($cat_params);
513               
514               if ($_ctx->categories->isEmpty())
515               {
516                    # The specified category does no exist.
517                    self::p404();
518                    return;
519               }
520          }
521         
522          # Get period
523          if (!empty($m[6]))
524          {
525               $params['event_period'] = $m[6];
526          }
527          # Get interval
528          elseif (!empty($m[8]))
529          {
530               $params['event_interval'] = $m[8];
531               
532               # Make start date
533               if (!empty($m[13]))
534               {
535                    $start =  date('Y-m-d 00:00:00',mktime(0,0,0,$m[11],$m[13],$m[9]));
536                    $end =  date('Y-m-d 00:00:00',mktime(0,0,0,$m[11],($m[13]+1),$m[9]));
537               }
538               elseif (!empty($m[11]))
539               {
540                    $start = date('Y-m-d 00:00:00',mktime(0,0,0,$m[11],1,$m[9]));
541                    $end = date('Y-m-d 00:00:00',mktime(0,0,0,($m[11]+1),1,$m[9]));
542               }
543               elseif (!empty($m[9]))
544               {
545                    $start = date('Y-m-d 00:00:00',mktime(0,0,0,1,1,$m[9]));
546                    $end = date('Y-m-d 00:00:00',mktime(0,0,0,1,1,($m[9]+1)));
547               }
548               # Make end date
549               if (!empty($m[19]))
550               {
551                    $end =  date('Y-m-d 00:00:00',mktime(0,0,0,$m[17],$m[19],$m[15]));
552               }
553               elseif (!empty($m[17]))
554               {
555                    $end = date('Y-m-d 00:00:00',mktime(0,0,0,$m[17],1,$m[15]));
556               }
557               elseif (!empty($m[15]))
558               {
559                    $end = date('Y-m-d 00:00:00',mktime(0,0,0,1,1,$m[15]));
560               }
561               # Make interval
562               if ($m[8] == 'on')
563               {
564                    $params['event_period'] = 'ongoing';
565                    $params['event_startdt'] = $end;
566                    $params['event_enddt'] = $start;
567               }
568               elseif($m[8] == 'in')
569               {
570                    $params['event_period'] = 'ongoing';
571                    $params['event_startdt'] = $start;
572                    $params['event_enddt'] = $end;
573               }
574               else
575               {
576                    if (!empty($m[9]))
577                    {
578                         $params['event_start_year'] = $m[9];
579                    }
580                    if (!empty($m[11]))
581                    {
582                         $params['event_start_month'] = $m[11];
583                    }
584                    if (!empty($m[13]))
585                    {
586                         $params['event_start_day'] = $m[13];
587                    }
588               }
589          }
590          else
591          {
592               $params['event_period'] = 'scheduled'; // default
593          }
594          # Get order
595          $params['order'] = 'event_startdt ASC'; // default
596          if (!empty($m[21]))
597          {
598               $sortorder = 'ASC';
599               if (!empty($m[23]))
600               {
601                    $sortorder = strtoupper($m[23]);
602               }
603               $params['order'] = $default_order_list[$m[21]].' '.$sortorder;
604          }
605         
606          return $params;
607     }
608     
609     # Test if request url is a ical
610     protected static function isIcalDocument(&$args)
611     {
612          if (preg_match('#/ical\.ics$#',$args,$m))
613          {
614               $args = preg_replace('#/ical\.ics$#','',$args);
615               return true;
616          }
617          return false;
618     }
619     
620     # Test if request url is a hcal
621     protected static function isHcalDocument(&$args)
622     {
623          if (preg_match('#/hcal\.html$#',$args,$m))
624          {
625               $args = preg_replace('#/hcal\.html$#','',$args);
626               return true;
627          }
628          return false;
629     }
630     
631     # Test if request url is a gmap
632     protected static function isGmapDocument(&$args)
633     {
634          if (preg_match('#/gmap$#',$args,$m))
635          {
636               $args = preg_replace('#/gmap$#','',$args);
637               return true;
638          }
639          return false;
640     }
641     
642     # Serve special ical document
643     public static function serveIcalDocument($rs,$x_dc_folder='')
644     {
645          global $core;
646         
647          if ($rs->isEmpty())
648          {
649               self::p404();
650               return;
651          }
652         
653          $res =
654          "BEGIN:VCALENDAR\r\n".
655          "PRODID:-//eventHandler for Dotclear//eventHandler 1.0-alpha7//EN\r\n".
656          "VERSION:2.0\r\n".
657          "METHOD:PUBLISH\r\n".
658          "CALSCALE:GREGORIAN\r\n".
659          implode("\r\n ",str_split(trim("X-DC-BLOGNAME:".$core->blog->name),70))."\r\n";
660         
661          if ($x_dc_folder)
662          {
663               $res .= 
664               implode("\r\n ",str_split(trim("X-DC-FOLDER:".$x_dc_folder),70))."\r\n";
665          }
666         
667          while($rs->fetch())
668          {
669               # See lib.eventhandler.rs.extension.php
670               $res .= $rs->getIcalVEVENT();
671          }
672         
673          $res .= "END:VCALENDAR\r\n";
674         
675          header('Content-Type: text/calendar');
676          header('Content-Length: '.strlen($res));
677          header('Content-Disposition: attachment; filename="events.ics"');
678          echo $res;
679          exit;
680     }
681     
682     # Serve special hcal document
683     public static function serveHcalDocument($rs,$x_dc_folder='')
684     {
685          global $core;
686         
687          if ($rs->isEmpty())
688          {
689               self::p404();
690               return;
691          }
692         
693          $res = 
694          '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'."\n".
695          '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n".
696          '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.
697          $core->blog->settings->system->lang.'" lang="'.$core->blog->settings->system->lang.'">'."\n".
698          '<head>'."\n".
699          '<title>'.html::escapeHTML($core->blog->name).' - '.__('Events').'</title>'."\n".
700          '<style type="text/css" media="screen">'."\n".
701          '@import url('.$core->blog->getQmarkURL().
702          'pf=eventHandler/default-templates/event-hcalendar.css);'."\n".
703          '</style>'."\n".
704          '</head>'."\n".
705          '<body>'."\n".
706          '<div id="page">'."\n".
707          '<div id="top">'."\n".
708          '<h1><a href="'.$core->blog->url.'">'.html::escapeHTML($core->blog->name).
709          ' - '.__('Events').'</a></h1>'."\n";
710         
711          if ($x_dc_folder)
712          {
713               $res .= '<p>'.__('Directory:').' <a href="'.
714               $core->blog->url.$core->url->getBase('eventhandler_list').$x_dc_folder.'">'.
715               $x_dc_folder.'</a></p>'."\n";
716          }
717         
718          $res .=
719          '</div>'; 
720         
721          while($rs->fetch())
722          {
723               # See lib.eventhandler.rs.extension.php
724               $res .= 
725               '<div id="items">'."\n".
726               $rs->getHcalVEVENT().
727               '</div>'."\n";
728          }
729         
730          $res .= 
731          '<div id="footer">'."\n".
732          '<p>'.__('This page is powered by Dotclear and eventHandler').'</p>'."\n".
733          '</div>'."\n".
734          '</div>'."\n".
735          '</body></html>';
736         
737          header('Content-Type: text/html; charset=UTF-8');
738          header('Content-Length: '.strlen($res));
739          echo $res;
740          exit;
741     }
742     
743     # Serve special gmap document
744     public static function serveGmapDocument($rs,$x_dc_folder='')
745     {
746          global $core;
747         
748          $res = 
749          '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'."\n".
750          '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n".
751          '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.
752          $core->blog->settings->system->lang.'" lang="'.$core->blog->settings->system->lang.'">'."\n".
753          '<head>'."\n".
754          '<title>'.html::escapeHTML($core->blog->name).' - '.__('Events').'</title>'."\n".
755          '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />'."\n".
756          '<script type="text/javascript" src="'.$core->blog->settings->system->themes_url.
757          "/".$core->blog->settings->system->theme.'/../default/js/jquery.js"></script>'."\n".
758          '<script type="text/javascript" src="'.$core->blog->settings->system->themes_url.
759          "/".$core->blog->settings->system->theme.'/../default/js/jquery.cookie.js"></script>'."\n".
760          "<script type=\"text/javascript\" src=\"".$core->blog->getQmarkURL().
761          'pf=eventHandler/js/event-public-map.js"></script>'."\n".
762          '<style type="text/css">'.
763          'html { height: 100%; } body { height: 100%; margin: 0px; padding: 0px; } '.
764          '.event-gmap, .event-gmap-place { height: 100%; } h2 { margin: 2em;}</style>'."\n".
765          '</head>'.
766          '<body>';
767         
768          if ($rs->count()) {
769               $total_lat = $total_lng = 0;
770               $markers = '';
771               while($rs->fetch())
772               {
773                    $total_lat += (float) $rs->event_latitude;
774                    $total_lng += (float) $rs->event_longitude;
775                    $markers .= $rs->getGmapVEVENT();
776               }
777               $lat = round($total_lat / $rs->count(), 7);
778               $lng = round($total_lng / $rs->count(), 7);
779               
780               $res .= eventHandler::getGmapContent(
781                    '',
782                    '',
783                    $core->blog->settings->eventHandler->public_map_type,
784                    2,
785                    1,
786                    $lat,
787                    $lng,
788                    $markers
789               );
790          }
791          else {
792               $res .= '<h2>'.__("There's no event at this time.").'</h2>';
793          }
794         
795          $res .= 
796          '</body>'.
797          '</html>';
798         
799          header('Content-Type: text/html; charset=UTF-8');
800          header('Content-Length: '.strlen($res));
801          echo $res;
802          exit;
803     }
804}
805
806# Template values
807class tplEventHandler
808{
809     #
810     # Missing values
811     #
812     
813     public static function BlogTimezone($a)
814     {
815          return self::tplValue($a,'$core->blog->settings->system->blog_timezone');
816     }
817     
818     #
819     # Events page
820     #
821     
822     # URL of page of events list
823     public static function EventsURL($a)
824     {
825          return self::tplValue($a,'$core->blog->url.$core->url->getBase("eventhandler_list")');
826     }
827     
828     # Feed Url
829     public static function EventsFeedURL($a)
830     {
831          $type = !empty($a['type']) ? $a['type'] : 'atom';
832
833          if (!preg_match('#^(rss2|atom)$#',$type))
834          {
835               $type = 'atom';
836          }
837         
838          return self::tplValue($a,'$core->blog->url.$core->url->getBase("eventhandler_feed").($_ctx->exists("categories") ? "/category/".$_ctx->categories->cat_url : "")."/'.$type.'"');
839     }
840     
841     # Navigation menu
842     public static function EventsMenuPeriod($attr,$content)
843     {
844          $menus = !empty($attr['menus']) ? $attr['menus'] : '';
845          $separator = !empty($attr['separator']) ? $attr['separator'] : '';
846          $list = !empty($attr['list']) ? $attr['list'] : '';
847          $item = !empty($attr['item']) ? $attr['item'] : '';
848          $active_item = !empty($attr['active_item']) ? $attr['active_item'] : '';
849         
850          return "<?php echo tplEventHandler::EventsMenuPeriodHelper('".addslashes($menus)."','".addslashes($separator)."','".addslashes($list)."','".addslashes($item)."','".addslashes($active_item)."'); ?>";
851     }
852     
853     # Navigation menu helper
854     public static function EventsMenuPeriodHelper($menus,$separator,$list,$item,$active_item)
855     {
856          global $core, $_ctx;
857         
858          $default_menu = array(
859               'all' => __('All') ,
860               'ongoing' => __('Ongoing'),
861               'outgoing' => __('Outgoing'),
862               'scheduled' => __('Scheduled'),
863               'started' => __('Started'),
864               'notfinished' => __('Not finished'),
865               'finished' => __('Finished')
866          );
867          # Only requested menus
868          $menu = $default_menu;
869          if (!empty($menus))
870          {
871               $final_menu = array();
872               $menus = explode(',',$menus);
873               foreach($menus AS $k)
874               {
875                    if (isset($default_menu[$k]))
876                    {
877                         $final_menu[$k] = $default_menu[$k];
878                    }
879               }
880               if (!empty($final_menu))
881               {
882                    $menu = $final_menu;
883               }
884          }
885         
886          $separator = $separator ? html::decodeEntities($separator) : '';
887          $list = $list ? html::decodeEntities($list) : '<ul>%s</ul>';
888          $item = $item ? html::decodeEntities($item) : '<li><a href="%s">%s</a>%s</li>';
889          $active_item = $active_item ? html::decodeEntities($active_item) : '<li class="nav-active"><a href="%s">%s</a>%s</li>';
890          $url = $core->blog->url.$core->url->getBase("eventhandler_list").'/';
891          if ($_ctx->exists('categories'))
892          {
893               $url .= 'category/'.$_ctx->categories->cat_url.'/';
894          }
895         
896          $i = 1;
897          $res = '';
898          foreach($menu AS $id => $name)
899          {
900               $i++;
901               $sep = $separator && $i < count($menu)+1 ? $separator : '';
902               
903               if (isset($_ctx->event_params['event_period']) && $_ctx->event_params['event_period'] == $id)
904               {
905                    $res .= sprintf($active_item,$url.$id,$name,$sep);
906               }
907               else
908               {
909                    $res .= sprintf($item,$url.$id,$name,$sep);
910               }
911          }
912         
913          return '<div id="eventhandler-menu-period">'.sprintf($list,$res).'</div>';
914     }
915     
916     # Sort order menu
917     public static function EventsMenuSortOrder($attr)
918     {
919          $menus = !empty($attr['menus']) ? $attr['menus'] : '';
920          $separator = !empty($attr['separator']) ? $attr['separator'] : '';
921          $list = !empty($attr['list']) ? $attr['list'] : '';
922          $item = !empty($attr['item']) ? $attr['item'] : '';
923          $active_item = !empty($attr['active_item']) ? $attr['active_item'] : '';
924         
925          return "<?php echo tplEventHandler::EventsMenuSortOrdertHelper('".addslashes($menus)."','".addslashes($separator)."','".addslashes($list)."','".addslashes($item)."','".addslashes($active_item)."'); ?>";
926     }
927     
928     # Sort order menu helper
929     public static function EventsMenuSortOrdertHelper($menus,$separator,$list,$item,$active_item)
930     {
931          global $core, $_ctx;
932         
933          $default_sort_id = array(
934               'title' => 'LOWER(post_title)',
935               'selected' => 'post_selected',
936               'author' => 'LOWER(user_id)',
937               'date' => 'post_dt',
938               'startdt' => 'event_startdt',
939               'enddt' =>'event_enddt'
940          );
941          $default_sort_text = array(
942               'title' => __('Title'),
943               'selected' => __('Selected'),
944               'author' => __('Author'),
945               'date' => __('Published date'),
946               'startdt' => __('Start date'),
947               'enddt' => __('End date')
948          );
949         
950          # Only requested menus
951          $menu = $default_sort_id;
952          if (!empty($menus))
953          {
954               $final_menu = array();
955               $menus = explode(',',$menus);
956               foreach($menus AS $k)
957               {
958                    if (isset($default_sort_id[$k]))
959                    {
960                         $final_menu[$k] = $default_sort_id[$k];
961                    }
962               }
963               if (!empty($final_menu))
964               {
965                    $menu = $final_menu;
966               }
967          }
968         
969          $separator = $separator ? html::decodeEntities($separator) : '';
970          $list = $list ? 
971               html::decodeEntities($list) : 
972               '<ul>%s</ul>';
973          $item = $item ? 
974               html::decodeEntities($item) : 
975               '<li><a href="%s">%s</a>%s</li>';
976          $active_item = $active_item ? 
977               html::decodeEntities($active_item) : 
978               '<li class="nav-active"><a href="%s">%s</a>%s</li>';
979          $period = !empty($_ctx->event_params['event_period']) ? 
980               $_ctx->event_params['event_period'] : 
981               'all';
982          $url = $core->blog->url.$core->url->getBase("eventhandler_list").'/';
983          if ($_ctx->exists('categories')) {
984               $url .= 'category/'.$_ctx->categories->cat_url.'/';
985          }
986          $url .= $period;
987         
988          $sortstr = $sortby = $sortorder = null;
989          # Must quote array
990          $quoted_default_sort_id = array();
991          foreach($default_sort_id as $k => $v)
992          {
993               $quoted_default_sort_id[$k] = preg_quote($v);
994          }
995         
996          if (isset($_ctx->event_params['order']) && preg_match('/('.implode('|',$quoted_default_sort_id).')\s(ASC|DESC)/i',$_ctx->event_params['order'],$sortstr))
997          {
998               $sortby = in_array($sortstr[1],$default_sort_id) ? $sortstr[1]: '';
999               $sortorder = preg_match('#ASC#i',$sortstr[2]) ? 'asc' : 'desc';
1000          }
1001         
1002          $i = 1;
1003          $res = '';
1004          foreach($menu AS $id => $name)
1005          {
1006               $i++;
1007               $sep = $separator && $i < count($menu)+1 ? $separator : '';
1008               
1009               if ($sortby == $name)
1010               {
1011                    $ord = $sortorder == 'asc' ? 'desc' : 'asc';
1012                    $res .= sprintf($active_item,$url.'/'.$id.'/'.$ord,$default_sort_text[$id],$sep);
1013               }
1014               else
1015               {
1016                    $ord = $sortorder == 'desc' ? 'desc' : 'asc';
1017                    $res .= sprintf($item,$url.'/'.$id.'/'.$ord,$default_sort_text[$id],$sep);
1018               }
1019          }
1020         
1021          return '<div id="eventhandler-menu-sortorder">'.sprintf($list,$res).'</div>';
1022     }
1023     
1024     # Period info
1025     public static function EventsPeriod($attr)
1026     {
1027          if (!isset($attr['fulltext']))
1028          {
1029               $fulltext = '0';
1030          }
1031          elseif(empty($attr['fulltext']))
1032          {
1033               $fulltext = '1';
1034          }
1035          else
1036          {
1037               $fulltext = '2';
1038          }
1039         
1040          return "<?php echo tplEventHandler::EventsPeriodHelper('".$fulltext."'); ?>";
1041     }
1042     
1043     # Period helper
1044     public static function EventsPeriodHelper($fulltext)
1045     {
1046          global $_ctx;
1047         
1048          if ($fulltext == 2)
1049          {
1050               $text = array(
1051                    'all' => __('All events'),
1052                    'ongoing' => __('Current events'),
1053                    'outgoing' => __('Event not being'),
1054                    'scheduled' => __('Scheduled events'),
1055                    'started' => __('Started events'),
1056                    'notfinished' => __('Unfinished events'),
1057                    'finished' => __('Completed events')
1058               );
1059          }
1060          elseif ($fulltext == 1)
1061          {
1062               $text = array(
1063                    'all' => __('All'),
1064                    'ongoing' => __('Ongoing'),
1065                    'outgoing' => __('Outgoing'),
1066                    'scheduled' => __('Scheduled'),
1067                    'started' => __('Started'),
1068                    'notfinished' => __('Not finished'),
1069                    'finished' => __('Finished')
1070               );
1071          }
1072          else
1073          {
1074               $text = array(
1075                    'all' => 'all',
1076                    'ongoing' => 'ongoing',
1077                    'outgoing' => 'outgoing',
1078                    'scheduled' => 'scheduled',
1079                    'started' => 'started',
1080                    'notfinished' => 'notfinished',
1081                    'finished' => 'finished'
1082               );
1083          }
1084          return isset($_ctx->event_params['event_period']) && isset($text[$_ctx->event_params['event_period']]) ? $text[$_ctx->event_params['event_period']] : $text['all'];
1085     }
1086     
1087     # Interval info
1088     public static function EventsInterval($attr)
1089     {
1090          $format = !empty($attr['format']) ? addslashes($attr['format']) : __('%m %d %Y');
1091         
1092          return "<?php echo tplEventHandler::EventsIntervalHelper('".$format."'); ?>";
1093     }
1094     
1095     # Interval info helper
1096     public static function EventsIntervalHelper($format)
1097     {
1098          global $_ctx;
1099         
1100          if (!empty($_ctx->event_params['event_start_year']))
1101          {
1102               if (!empty($_ctx->event_params['event_start_day']))
1103               {
1104                    $dt = dt::str($format,mktime(0,0,0,$_ctx->event_params['event_start_month'],$_ctx->event_params['event_start_day'],$_ctx->event_params['event_start_year']));
1105                    return sprintf(__('For the day of %s'),$dt);
1106               }
1107               elseif (!empty($_ctx->event_params['event_start_month']))
1108               {
1109                    $dt = dt::str(__('%m %Y'),mktime(0,0,0,$_ctx->event_params['event_start_month'],1,$_ctx->event_params['event_start_year']));
1110                    return sprintf(__('For the month of %s'),$dt);
1111               }
1112               elseif (!empty($_ctx->event_params['event_start_year']))
1113               {
1114                    return sprintf(__('For the year of %s'),$_ctx->event_params['event_start_year']);
1115               }
1116          }
1117          else
1118          {
1119               $start = dt::dt2str($format,$_ctx->event_params['event_startdt']);
1120               $end = dt::dt2str($format,$_ctx->event_params['event_enddt']);
1121               
1122               if (strtotime($_ctx->event_params['event_startdt']) < strtotime($_ctx->event_params['event_enddt']))
1123               {
1124                    return sprintf(__('For the period between %s and %s'),$start,$end);
1125               }
1126               else
1127               {
1128                    return sprintf(__('For the period through %s and %s'),$end,$start);
1129               }
1130          }
1131     }
1132     
1133     # Conditions
1134     public static function EventsIf($attr,$content)
1135     {
1136          global $core;
1137         
1138          $if = array();
1139         
1140          $operator = isset($attr['operator']) ? $core->tpl->getOperator($attr['operator']) : '&&';
1141         
1142          if (isset($attr['has_interval']))
1143          {
1144               $sign = (boolean) $attr['has_interval'] ? '!' : '';
1145               $if[] = $sign.'empty($_ctx->event_params["event_interval"])';
1146          }
1147         
1148          if (isset($attr['has_category']))
1149          {
1150               $sign = (boolean) $attr['has_category'] ? '' : '!';
1151               $if[] = $sign.'$_ctx->exists("categories")';
1152          }
1153         
1154          if (isset($attr['has_period']))
1155          {
1156               if ($attr['has_period'])
1157               {
1158                    $if[] = '!empty($_ctx->event_params["event_period"]) && $_ctx->event_params["event_period"] != "all"';
1159               }
1160               else
1161               {
1162                    $if[] = 'empty($_ctx->event_params["event_period"]) || !empty($_ctx->event_params["event_period"]) && $_ctx->event_params["event_period"] == "all"';
1163               }
1164          }
1165         
1166          if (isset($attr['period']))
1167          {
1168               $if[] = 
1169               '(!empty($_ctx->event_params["event_period"]) && $_ctx->event_params["event_period"] == "'.addslashes($attr['period']).'" '.
1170               '|| empty($_ctx->event_params["event_period"]) && ("" == "'.addslashes($attr['period']).'" || "all" == "'.addslashes($attr['period']).'")))';
1171          }
1172         
1173          if (!empty($if))
1174          {
1175               return '<?php if('.implode(' '.$operator.' ',$if).') : ?>'.$content.'<?php endif; ?>';
1176          }
1177          else
1178          {
1179               return $content;
1180          }
1181     }
1182     
1183     #
1184     # Entries (on events page)
1185     #
1186     
1187     public static function EventsEntries($attr,$content)
1188     {
1189          global $core;
1190         
1191          $lastn = -1;
1192          if (isset($attr['lastn'])) {
1193               $lastn = abs((integer) $attr['lastn'])+0;
1194          }
1195         
1196          $p = 'if (!isset($_page_number)) { $_page_number = 1; }'."\n";
1197         
1198          if ($lastn != 0) {
1199               if ($lastn > 0) {
1200                    $p .= "\$params['limit'] = ".$lastn.";\n";
1201               } else {
1202                    $p .= "\$params['limit'] = \$_ctx->nb_entry_per_page;\n";
1203               }
1204               
1205               if (!isset($attr['ignore_pagination']) || $attr['ignore_pagination'] == "0") {
1206                    $p .= "\$params['limit'] = array(((\$_page_number-1)*\$params['limit']),\$params['limit']);\n";
1207               } else {
1208                    $p .= "\$params['limit'] = array(0, \$params['limit']);\n";
1209               }
1210          }
1211         
1212          if (isset($attr['author'])) {
1213               $p .= "\$params['user_id'] = '".addslashes($attr['author'])."';\n";
1214          }
1215         
1216          if (isset($attr['category'])) {
1217               $p .= "\$params['cat_url'] = '".addslashes($attr['category'])."';\n";
1218               $p .= "context::categoryPostParam(\$params);\n";
1219          }
1220         
1221          if (isset($attr['no_category']) && $attr['no_category']) {
1222               $p .= "@\$params['sql'] .= ' AND P.cat_id IS NULL ';\n";
1223               $p .= "unset(\$params['cat_url']);\n";
1224          }
1225         
1226          if (!empty($attr['type'])) {
1227               $p .= "\$params['post_type'] = preg_split('/\s*,\s*/','".addslashes($attr['type'])."',-1,PREG_SPLIT_NO_EMPTY);\n";
1228          }
1229         
1230          if (!empty($attr['url'])) {
1231               $p .= "\$params['post_url'] = '".addslashes($attr['url'])."';\n";
1232          }
1233         
1234          if (isset($attr['period'])) {
1235               $p .= "\$params['event_period'] = '".addslashes($attr['period'])."';\n";
1236          }
1237         
1238          if (empty($attr['no_context']))
1239          {
1240               $p .=
1241               'if ($_ctx->exists("users")) { '.
1242                    "\$params['user_id'] = \$_ctx->users->user_id; ".
1243               "}\n";
1244               
1245               $p .=
1246               'if ($_ctx->exists("categories")) { '.
1247                    "\$params['cat_id'] = \$_ctx->categories->cat_id; ".
1248               "}\n";
1249               
1250               $p .=
1251               'if ($_ctx->exists("archives")) { '.
1252                    "\$params['post_year'] = \$_ctx->archives->year(); ".
1253                    "\$params['post_month'] = \$_ctx->archives->month(); ";
1254               if (!isset($attr['lastn'])) {
1255                    $p .= "unset(\$params['limit']); ";
1256               }
1257               $p .=
1258               "}\n";
1259               
1260               $p .=
1261               'if ($_ctx->exists("langs")) { '.
1262                    "\$params['post_lang'] = \$_ctx->langs->post_lang; ".
1263               "}\n";
1264               
1265               $p .=
1266               'if (isset($_search)) { '.
1267                    "\$params['search'] = \$_search; ".
1268               "}\n";
1269               
1270               $p .=
1271               'if ($_ctx->exists("event_params")) { '.
1272                    "\$params = array_merge(\$params,\$_ctx->event_params); ".
1273               "}\n";
1274          }
1275         
1276          if (!empty($attr['order']) || !empty($attr['sortby'])) {
1277               $p .= 
1278               "\$params['order'] = '".$core->tpl->getSortByStr($attr,'eventhandler')."';\n";
1279          }
1280         
1281          if (isset($attr['no_content']) && $attr['no_content']) {
1282               $p .= "\$params['no_content'] = true;\n";
1283          }
1284         
1285          if (isset($attr['selected'])) {
1286               $p .= "\$params['post_selected'] = ".(integer) (boolean) $attr['selected'].";";
1287          }
1288         
1289          if (isset($attr['age'])) {
1290               $age = $core->tpl->getAge($attr);
1291               $p .= !empty($age) ? "@\$params['sql'] .= ' AND P.post_dt > \'".$age."\'';\n" : '';
1292          }
1293         
1294          return 
1295          "<?php\n".
1296          'if(!isset($eventHandler)) { $eventHandler = new eventHandler($core); } '."\n".
1297          '$params = array(); '."\n".
1298          $p.
1299          '$_ctx->post_params = $params; '."\n".
1300          '$_ctx->posts = $eventHandler->getEvents($params); unset($params); '."\n".
1301          "?>\n".
1302          '<?php while ($_ctx->posts->fetch()) : ?>'.$content.'<?php endwhile; '.
1303          '$_ctx->posts = null; $_ctx->post_params = null; ?>';
1304     }
1305     
1306     # Pagination
1307     public static function EventsPagination($attr,$content)
1308     {
1309          $p = 
1310          "<?php\n".
1311          'if(!isset($eventHandler)) { $eventHandler = new eventHandler($core); } '."\n".
1312          '$params = $_ctx->post_params; '."\n".
1313          '$_ctx->pagination = $eventHandler->getEvents($params,true); unset($params); '."\n".
1314          "?>\n";
1315         
1316          if (isset($attr['no_context']) && $attr['no_context']) {
1317               return $p.$content;
1318          }
1319       
1320          return
1321          $p.
1322          '<?php if ($_ctx->pagination->f(0) > $_ctx->posts->count()) : ?>'.
1323          $content.
1324          '<?php endif; ?>';
1325     }
1326     
1327     # Conditions
1328     public static function EventsEntryIf($attr,$content)
1329     {
1330          global $core;
1331         
1332          $if = array();
1333         
1334          $operator = isset($attr['operator']) ? $core->tpl->getOperator($attr['operator']) : '&&';
1335         
1336          if (isset($attr['has_category']))
1337          {
1338               $sign = (boolean) $attr['has_category'] ? '' : '!';
1339               $if[] = $sign.'$_ctx->posts->cat_id';
1340          }
1341         
1342          if (isset($attr['has_address']))
1343          {
1344               $sign = (boolean) $attr['has_address'] ? '!' : '=';
1345               $if[] = "'' ".$sign.'= $_ctx->posts->event_address';
1346          }
1347         
1348          if (isset($attr['has_geo']))
1349          {
1350               $sign = (boolean) $attr['has_geo'] ? '' : '!';
1351               $if[] = $sign.'("" != $_ctx->posts->event_latitude && "" != $_ctx->posts->event_longitude)';
1352          }
1353         
1354          if (isset($attr['period']))
1355          {
1356               $if[] = '$_ctx->posts->getPeriod() == "'.addslashes($attr['period']).'"';
1357          }
1358         
1359          if (isset($attr['sameday']))
1360          {
1361               $sign = (boolean) $attr['sameday'] ? '' : '!';
1362               $if[] = $sign."\$_ctx->posts->isOnSameDay()";
1363          }
1364         
1365          if (isset($attr['oneday']))
1366          {
1367               $sign = (boolean) $attr['oneday'] ? '' : '!';
1368               $if[] = $sign."\$_ctx->posts->isOnOneDay()";
1369          }
1370         
1371          if (!empty($attr['orderedby']))
1372          {
1373               if (substr($attr['orderedby'],0,1) == '!') {
1374                    $sign = '!';
1375                    $orderedby = substr($attr['orderedby'],1);
1376               }
1377               else {
1378                    $sign = '';
1379                    $orderedby = $attr['orderedby'];
1380               }
1381               
1382               $default_sort = array(
1383                    'date' => 'post_dt',
1384                    'startdt' => 'event_startdt',
1385                    'enddt' =>'event_enddt'
1386               );
1387               
1388               if (isset($default_sort[$orderedby])) {
1389                    $orderedby = $default_sort[$orderedby];
1390
1391                    $if[] = $sign."strstr(\$_ctx->post_params['order'],'".addslashes($orderedby)."')";
1392               }
1393          }
1394         
1395          if (!empty($if))
1396          {
1397               return '<?php if('.implode(' '.$operator.' ',$if).') : ?>'.$content.'<?php endif; ?>';
1398          }
1399          else
1400          {
1401               return $content;
1402          }
1403     }
1404     
1405     # First event date
1406     public static function EventsDateHeader($attr,$content)
1407     {
1408          $type = '';
1409          if (!empty($attr['creadt'])) { $type = 'creadt'; }
1410          if (!empty($attr['upddt'])) { $type = 'upddt'; }
1411          if (!empty($attr['enddt'])) { $type = 'enddt'; }
1412          if (!empty($attr['startdt'])) { $type = 'startdt'; }
1413         
1414          return
1415          "<?php ".
1416          'if ($_ctx->posts->firstEventOfDay("'.$type.'")) : ?>'.
1417          $content.
1418          "<?php endif; ?>";
1419     }
1420     
1421     # Last event date
1422     public static function EventsDateFooter($attr,$content)
1423     {
1424          $type = '';
1425          if (!empty($attr['creadt'])) { $type = 'creadt'; }
1426          if (!empty($attr['upddt'])) { $type = 'upddt'; }
1427          if (!empty($attr['enddt'])) { $type = 'enddt'; }
1428          if (!empty($attr['startdt'])) { $type = 'startdt'; }
1429
1430          return
1431          "<?php ".
1432          'if ($_ctx->posts->lastEventOfDay("'.$type.'")) : ?>'.
1433          $content.
1434          "<?php endif; ?>";
1435     }
1436     
1437     # Date of selected type
1438     public static function EventsEntryDate($a)
1439     {
1440          $format = !empty($a['format']) ? addslashes($a['format']) : '';
1441          $iso8601 = !empty($a['iso8601']);
1442          $rfc822 = !empty($a['rfc822']);
1443         
1444          $type = '';
1445          if (!empty($a['creadt'])) { $type = 'creadt'; }
1446          if (!empty($a['upddt'])) { $type = 'upddt'; }
1447          if (!empty($a['enddt'])) { $type = 'enddt'; }
1448          if (!empty($a['startdt'])) { $type = 'startdt'; }
1449         
1450          if ($rfc822) {
1451               return self::tplValue($a,"\$_ctx->posts->getEventRFC822Date('".$type."')");
1452          } elseif ($iso8601) {
1453               return self::tplValue($a,"\$_ctx->posts->getEventISO8601Date('".$type."')");
1454          } else {
1455               return self::tplValue($a,"\$_ctx->posts->getEventDate('".$format."','".$type."')");
1456          }
1457     }
1458     
1459     # Time of selected type
1460     public static function EventsEntryTime($a)
1461     {
1462          $format = !empty($a['format']) ? addslashes($a['format']) : '';
1463          $type = '';
1464          if (!empty($a['creadt'])) { $type = 'creadt'; }
1465          if (!empty($a['upddt'])) { $type = 'upddt'; }
1466          if (!empty($a['enddt'])) { $type = 'enddt'; }
1467          if (!empty($a['startdt'])) { $type = 'startdt'; }
1468       
1469          return self::tplValue($a,"\$_ctx->posts->getEventTime('".$format."','".$type."')");
1470     }
1471     
1472     # Category url
1473     public static function EventsEntryCategoryURL($a)
1474     {
1475          return self::tplValue($a,'$core->blog->url.$core->url->getBase("eventhandler_list")."/category/".html::sanitizeURL($_ctx->posts->cat_url)');
1476     }
1477     
1478     # Address
1479     public static function EventsEntryAddress($a)
1480     {
1481          $ics = !empty($a['ics']) ? '"LOCATION;CHARSET=UTF-8:".' : '';
1482         
1483          return self::tplValue($a,$ics.'$_ctx->posts->event_address');
1484     }
1485     
1486     # Latitude
1487     public static function EventsEntryLatitude($a)
1488     {
1489          return self::tplValue($a,'$_ctx->posts->event_latitude');
1490     }
1491     
1492     # Longitude
1493     public static function EventsEntryLongitude($a)
1494     {
1495          return self::tplValue($a,'$_ctx->posts->event_longitude');
1496     }
1497     
1498     # Duration
1499     public static function EventsEntryDuration($a)
1500     {
1501          $format = !empty($a['format']) ? addslashes($a['format']) : '';
1502         
1503          return self::tplValue($a,"eventHandler::getReadableDuration((strtotime(\$_ctx->posts->event_enddt) - strtotime(\$_ctx->posts->event_startdt)),'".$format."')");
1504     }
1505     
1506     # Period
1507     public static function EventsEntryPeriod($attr)
1508     {
1509          $scheduled = isset($attr['scheduled']) ? $attr['scheduled'] : 'scheduled';
1510          if (empty($attr['strict'])) $scheduled = __($scheduled);
1511         
1512          $ongoing = isset($attr['ongoing']) ? $attr['ongoing'] : 'ongoing';
1513          if (empty($attr['strict'])) $ongoing = __($ongoing);
1514         
1515          $finished = isset($attr['finished']) ? $attr['finished'] : 'finished';
1516          if (empty($attr['strict'])) $finished = __($finished);
1517         
1518          $f = $GLOBALS['core']->tpl->getFilters($attr);
1519         
1520          return
1521          "<?php \$time = time() + dt::getTimeOffset(\$_ctx->posts->post_tz)*2;\n".
1522          "if (\$_ctx->posts->getEventTS('startdt') > \$time) {\n".
1523          " echo ".sprintf($f,"'".$scheduled."'")."; }\n".
1524          "elseif (\$_ctx->posts->getEventTS('startdt') < \$time && \$_ctx->posts->getEventTS('enddt') > \$time) {\n".
1525          " echo ".sprintf($f,"'".$ongoing."'")."; }\n".
1526          "elseif (\$_ctx->posts->getEventTS('enddt') < \$time) {\n".
1527          " echo ".sprintf($f,"'".$finished."'")."; }\n".
1528          "unset(\$time); ?>\n";
1529     }
1530     
1531     # Map
1532     public static function EventsEntryMap($attr)
1533     {
1534          $map_zoom = !empty($attr['map_zoom']) ? abs((integer) $attr['map_zoom']) : '$core->blog->settings->eventHandler->public_map_zoom';
1535          $map_type = !empty($attr['map_type']) ? '"'.html::escapeHTML($attr['map_type']).'"' : '$core->blog->settings->eventHandler->public_map_type';
1536          $map_info = isset($attr['map_info']) && $attr['map_info'] == '0' ? '0' : '1';
1537         
1538          return '<?php echo eventHandler::getGmapContent("","",'.$map_type.','.$map_zoom.','.$map_info.',$_ctx->posts->event_latitude,$_ctx->posts->event_longitude,$_ctx->posts->getGmapVEVENT()); ?>';
1539     }
1540     
1541     #
1542     # Events of an entry (on posts context)
1543     #
1544     
1545     public static function EventsOfPost($attr,$content)
1546     {
1547          global $core;
1548         
1549          $p = '';
1550         
1551          $lastn = -1;
1552          if (isset($attr['lastn']))
1553          {
1554               $lastn = abs((integer) $attr['lastn'])+0;
1555               if ($lastn > 0)
1556               {
1557                    $p .= "\$params['limit'] = ".$lastn.";\n";
1558               }
1559          }
1560         
1561          if (isset($attr['event']))
1562          {
1563               $p .= "\$params['event_id'] = '".abs((integer) $attr['event'])."';\n";
1564          }
1565         
1566          if (isset($attr['author']))
1567          {
1568               $p .= "\$params['user_id'] = '".addslashes($attr['author'])."';\n";
1569          }
1570         
1571          if (isset($attr['category']))
1572          {
1573               $p .= "\$params['cat_url'] = '".addslashes($attr['category'])."';\n";
1574               $p .= "context::categoryPostParam(\$params);\n";
1575          }
1576         
1577          if (isset($attr['no_category']) && $attr['no_category'])
1578          {
1579               $p .= "@\$params['sql'] .= ' AND P.cat_id IS NULL ';\n";
1580               $p .= "unset(\$params['cat_url']);\n";
1581          }
1582         
1583          if (isset($attr['post']))
1584          {
1585               $p .= "\$params['post_id'] = '".abs((integer) $attr['post'])."';\n";
1586          }
1587         
1588          if (!empty($attr['type']))
1589          {
1590               $p .= "\$params['post_type'] = preg_split('/\s*,\s*/','".addslashes($attr['type'])."',-1,PREG_SPLIT_NO_EMPTY);\n";
1591          }
1592         
1593          $p .= "\$params['order'] = '".$core->tpl->getSortByStr($attr,'post')."';\n";
1594         
1595          if (isset($attr['no_content']) && $attr['no_content'])
1596          {
1597               $p .= "\$params['no_content'] = true;\n";
1598          }
1599         
1600          if (isset($attr['selected']))
1601          {
1602               $p .= "\$params['post_selected'] = ".(integer) (boolean) $attr['selected'].";";
1603          }
1604         
1605          if (isset($attr['age']))
1606          {
1607               $age = $core->tpl->getAge($attr);
1608               $p .= !empty($age) ? "@\$params['sql'] .= ' AND P.post_dt > \'".$age."\'';\n" : '';
1609          }
1610         
1611          return
1612          "<?php\n".
1613          'if(!isset($eventHandler)) { $eventHandler = new eventHandler($core); } '."\n".
1614          '$params = array(); '."\n".
1615          '$public_hidden_categories = @unserialize($core->blog->settings->eventHandler->public_hidden_categories); '.
1616          'if (is_array($public_hidden_categories)) { '.
1617          ' foreach($public_hidden_categories as $hidden_cat) { '.
1618          '  @$params[\'sql\'] .= " AND C.cat_id != \'".$core->con->escape($hidden_cat)."\' "; '.
1619          ' } '.
1620          "} \n".
1621          'if ($_ctx->exists("posts") && $_ctx->posts->post_id) { '.
1622          '$params["post_id"] = $_ctx->posts->post_id; '.
1623          "} \n".
1624          $p.
1625          'if (!empty($params["post_id"])) { '."\n".
1626          '$_ctx->eventsofpost_params = $params;'."\n".
1627          '$_ctx->eventsofpost = $eventHandler->getEventsByPost($params); unset($params); '."\n".
1628          'while ($_ctx->eventsofpost->fetch()) : ?>'.$content.'<?php endwhile; '.
1629          '} '."\n".
1630          '$_ctx->eventsofpost = null; $_ctx->eventsofpost_params = null; ?>';
1631     }
1632     
1633     public static function EventsOfPostHeader($attr,$content)
1634     {
1635          return
1636          "<?php if (\$_ctx->eventsofpost->isStart()) : ?>".
1637          $content.
1638          "<?php endif; ?>";
1639     }
1640     
1641     public static function EventsOfPostFooter($attr,$content)
1642     {
1643          return
1644          "<?php if (\$_ctx->eventsofpost->isEnd()) : ?>".
1645          $content.
1646          "<?php endif; ?>";
1647     }
1648     
1649     public static function EventOfPostIf($attr,$content)
1650     {
1651          global $core;
1652         
1653          $if = array();
1654         
1655          $operator = isset($attr['operator']) ? $core->tpl->getOperator($attr['operator']) : '&&';
1656         
1657          if (isset($attr['has_category']))
1658          {
1659               $sign = (boolean) $attr['has_category'] ? '' : '!';
1660               $if[] = $sign.'$_ctx->eventsofpost->cat_id';
1661          }
1662         
1663          if (isset($attr['has_address']))
1664          {
1665               $sign = (boolean) $attr['has_address'] ? '!' : '=';
1666               $if[] = "'' ".$sign.'= $_ctx->eventsofpost->event_address';
1667          }
1668         
1669          if (isset($attr['period']))
1670          {
1671               $if[] = '$_ctx->eventsofpost->getPeriod() == "'.addslashes($attr['period']).'"';
1672          }
1673         
1674          if (isset($attr['sameday']))
1675          {
1676               $sign = (boolean) $attr['sameday'] ? '' : '!';
1677               $if[] = $sign."\$_ctx->eventsofpost->isOnSameDay()";
1678          }
1679         
1680          if (isset($attr['oneday']))
1681          {
1682               $sign = (boolean) $attr['oneday'] ? '' : '!';
1683               $if[] = $sign."\$_ctx->eventsofpost->isOnOneDay()";
1684          }
1685         
1686          if (!empty($attr['orderedby']))
1687          {
1688               if (substr($attr['orderedby'],0,1) == '!') {
1689                    $sign = '!';
1690                    $orderedby = substr($attr['orderedby'],1);
1691               }
1692               else {
1693                    $sign = '';
1694                    $orderedby = $attr['orderedby'];
1695               }
1696               
1697               $default_sort = array(
1698                    'date' => 'post_dt',
1699                    'startdt' => 'event_startdt',
1700                    'enddt' =>'event_enddt'
1701               );
1702               
1703               if (isset($default_sort[$orderedby])) {
1704                    $orderedby = $default_sort[$orderedby];
1705
1706                    $if[] = $sign."strstr(\$_ctx->eventsofpost['order'],'".addslashes($orderedby)."')";
1707               }
1708          }
1709         
1710          if (!empty($if))
1711          {
1712               return '<?php if('.implode(' '.$operator.' ',$if).') : ?>'.$content.'<?php endif; ?>';
1713          }
1714          else
1715          {
1716               return $content;
1717          }
1718     }
1719     
1720     public static function EventOfPostTitle($a)
1721     {
1722          return self::tplValue($a,'$_ctx->eventsofpost->post_title');
1723     }
1724     
1725     public static function EventOfPostURL($a)
1726     {
1727          return self::tplValue($a,'$_ctx->eventsofpost->getURL()');
1728     }
1729     
1730     public static function EventOfPostDate($a)
1731     {
1732          $format = !empty($a['format']) ? addslashes($a['format']) : '';
1733          $iso8601 = !empty($a['iso8601']);
1734          $rfc822 = !empty($a['rfc822']);
1735         
1736          $type = '';
1737          if (!empty($a['creadt'])) { $type = 'creadt'; }
1738          if (!empty($a['upddt'])) { $type = 'upddt'; }
1739          if (!empty($a['enddt'])) { $type = 'enddt'; }
1740          if (!empty($a['startdt'])) { $type = 'startdt'; }
1741         
1742          if ($rfc822) {
1743               return self::tplValue($a,"\$_ctx->eventsofpost->getEventRFC822Date('".$type."')");
1744          } elseif ($iso8601) {
1745               return self::tplValue($a,"\$_ctx->eventsofpost->getEventISO8601Date('".$type."')");
1746          } else {
1747               return self::tplValue($a,"\$_ctx->eventsofpost->getEventDate('".$format."','".$type."')");
1748          }
1749     }
1750     
1751     public static function EventOfPostTime($a)
1752     {
1753          $format = !empty($a['format']) ? addslashes($a['format']) : '';
1754          $type = '';
1755          if (!empty($a['creadt'])) { $type = 'creadt'; }
1756          if (!empty($a['upddt'])) { $type = 'upddt'; }
1757          if (!empty($a['enddt'])) { $type = 'enddt'; }
1758          if (!empty($a['startdt'])) { $type = 'startdt'; }
1759       
1760          return self::tplValue($a,"\$_ctx->eventsofpost->getEventTime('".$format."','".$type."')");
1761     }
1762     
1763     public static function EventOfPostAuthorCommonName($a)
1764     {
1765          return self::tplValue($a,'$_ctx->eventsofpost->getAuthorCN()');
1766     }
1767     
1768     public static function EventOfPostAuthorLink($a)
1769     {
1770          return self::tplValue($a,'$_ctx->eventsofpost->getAuthorLink()');
1771     }
1772     
1773     public static function EventOfPostCategory($a)
1774     {
1775          return self::tplValue($a,'$_ctx->eventsofpost->cat_title');
1776     }
1777     
1778     public static function EventOfPostCategoryURL($a)
1779     {
1780          return self::tplValue($a,'$core->blog->url.$core->url->getBase("eventhandler_list")."/category/".html::sanitizeURL($_ctx->eventsofpost->cat_url)');
1781     }
1782     
1783     public static function EventOfPostAddress($a)
1784     {
1785          return self::tplValue($a,'$_ctx->eventsofpost->event_address');
1786     }
1787     
1788     public static function EventOfPostDuration($a)
1789     {
1790          $format = !empty($a['format']) ? addslashes($a['format']) : '';
1791         
1792          return self::tplValue($a,"eventHandler::getReadableDuration((strtotime(\$_ctx->eventsofpost->event_enddt) - strtotime(\$_ctx->eventsofpost->event_startdt)),'".$format."')");
1793     }
1794     
1795     public static function EventOfPostPeriod($attr)
1796     {
1797          $scheduled = isset($attr['scheduled']) ? $attr['scheduled'] : 'scheduled';
1798          if (empty($attr['strict'])) $scheduled = __($scheduled);
1799         
1800          $ongoing = isset($attr['ongoing']) ? $attr['ongoing'] : 'ongoing';
1801          if (empty($attr['strict'])) $ongoing = __($ongoing);
1802         
1803          $finished = isset($attr['finished']) ? $attr['finished'] : 'finished';
1804          if (empty($attr['strict'])) $finished = __($finished);
1805         
1806          $f = $GLOBALS['core']->tpl->getFilters($attr);
1807         
1808          return
1809          "<?php \$time = time() + dt::getTimeOffset(\$_ctx->eventsofpost->post_tz)*2;\n".
1810          "if (\$_ctx->eventsofpost->getEventTS('startdt') > \$time) {\n".
1811          " echo ".sprintf($f,"'".$scheduled."'")."; }\n".
1812          "elseif (\$_ctx->eventsofpost->getEventTS('startdt') < \$time && \$_ctx->eventsofpost->getEventTS('enddt') > \$time) {\n".
1813          " echo ".sprintf($f,"'".$ongoing."'")."; }\n".
1814          "elseif (\$_ctx->eventsofpost->getEventTS('enddt') < \$time) {\n".
1815          " echo ".sprintf($f,"'".$finished."'")."; }\n".
1816          "unset(\$time); ?>\n";
1817     }
1818     
1819     #
1820     # Entries of an event (on events context)
1821     #
1822     
1823     public static function PostsOfEvent($attr,$content)
1824     {
1825          global $core;
1826         
1827          $p = '';
1828         
1829          $lastn = -1;
1830          if (isset($attr['lastn']))
1831          {
1832               $lastn = abs((integer) $attr['lastn'])+0;
1833               if ($lastn > 0)
1834               {
1835                    $p .= "\$params['limit'] = ".$lastn.";\n";
1836               }
1837          }
1838         
1839          if (isset($attr['event']))
1840          {
1841               $p .= "\$params['event_id'] = '".abs((integer) $attr['event'])."';\n";
1842          }
1843         
1844          if (isset($attr['author']))
1845          {
1846               $p .= "\$params['user_id'] = '".addslashes($attr['author'])."';\n";
1847          }
1848         
1849          if (isset($attr['category']))
1850          {
1851               $p .= "\$params['cat_url'] = '".addslashes($attr['category'])."';\n";
1852               $p .= "context::categoryPostParam(\$params);\n";
1853          }
1854         
1855          if (isset($attr['no_category']) && $attr['no_category'])
1856          {
1857               $p .= "@\$params['sql'] .= ' AND P.cat_id IS NULL ';\n";
1858               $p .= "unset(\$params['cat_url']);\n";
1859          }
1860         
1861          if (!empty($attr['type']))
1862          {
1863               $p .= "\$params['post_type'] = preg_split('/\s*,\s*/','".addslashes($attr['type'])."',-1,PREG_SPLIT_NO_EMPTY);\n";
1864          }
1865         
1866          $p .= "\$params['order'] = '".$core->tpl->getSortByStr($attr,'post')."';\n";
1867         
1868          if (isset($attr['no_content']) && $attr['no_content'])
1869          {
1870               $p .= "\$params['no_content'] = true;\n";
1871          }
1872         
1873          if (isset($attr['selected']))
1874          {
1875               $p .= "\$params['post_selected'] = ".(integer) (boolean) $attr['selected'].";";
1876          }
1877         
1878          if (isset($attr['age']))
1879          {
1880               $age = $core->tpl->getAge($attr);
1881               $p .= !empty($age) ? "@\$params['sql'] .= ' AND P.post_dt > \'".$age."\'';\n" : '';
1882          }
1883         
1884          return
1885          "<?php\n".
1886          "\$postsofeventHandler = new eventHandler(\$core); \n".
1887          'if ($_ctx->exists("posts") && $_ctx->posts->post_id) { '.
1888          " \$params['event_id'] = \$_ctx->posts->post_id; ".
1889          "} \n".
1890          $p.
1891          '$_ctx->postsofevent_params = $params;'."\n".
1892          '$_ctx->postsofevent = $postsofeventHandler->getPostsByEvent($params); unset($params);'."\n".
1893          "?>\n".
1894          '<?php while ($_ctx->postsofevent->fetch()) : ?>'.$content.'<?php endwhile; '.
1895          '$_ctx->postsofevent = null; $_ctx->postsofevent_params = null; $postsofeventHandler = null; ?>';
1896         
1897          return $res;
1898     }
1899     
1900     public static function PostsOfEventHeader($attr,$content)
1901     {
1902          return
1903          "<?php if (\$_ctx->postsofevent->isStart()) : ?>".
1904          $content.
1905          "<?php endif; ?>";
1906     }
1907     
1908     public static function PostsOfEventFooter($attr,$content)
1909     {
1910          return
1911          "<?php if (\$_ctx->postsofevent->isEnd()) : ?>".
1912          $content.
1913          "<?php endif; ?>";
1914     }
1915     
1916     public static function PostOfEventIf($attr,$content)
1917     {
1918          global $core;
1919         
1920          $if = array();
1921         
1922          $operator = isset($attr['operator']) ? $core->tpl->getOperator($attr['operator']) : '&&';
1923       
1924          if (isset($attr['type']))
1925          {
1926               $type = trim($attr['type']);
1927               $type = !empty($type)?$type:'post';
1928               $if[] = '$_ctx->postsofevent->post_type == "'.addslashes($type).'"';
1929          }
1930         
1931          if (isset($attr['has_category']))
1932          {
1933               $sign = (boolean) $attr['has_category'] ? '' : '!';
1934               $if[] = $sign.'$_ctx->postsofevent->cat_id';
1935          }
1936         
1937          if (!empty($if))
1938          {
1939               return '<?php if('.implode(' '.$operator.' ',$if).') : ?>'.$content.'<?php endif; ?>';
1940          }
1941          else
1942          {
1943               return $content;
1944          }
1945     }
1946     
1947     public static function PostOfEventTitle($a)
1948     {
1949          return self::tplValue($a,'$_ctx->postsofevent->post_title');
1950     }
1951     
1952     public static function PostOfEventURL($a)
1953     {
1954          return self::tplValue($a,'$_ctx->postsofevent->getURL()');
1955     }
1956     
1957     public function PostOfEventDate($a)
1958     {
1959          $format = !empty($a['format']) ? addslashes($a['format']) : '';
1960          $iso8601 = !empty($a['iso8601']);
1961          $rfc822 = !empty($a['rfc822']);
1962          $type = (!empty($a['creadt']) ? 'creadt' : '');
1963          $type = (!empty($a['upddt']) ? 'upddt' : '');
1964         
1965          if ($rfc822)
1966          {
1967               return self::tplValue($a,"\$_ctx->postsofevent->getRFC822Date('".$type."')");
1968          }
1969          elseif ($iso8601)
1970          {
1971               return self::tplValue($a,"\$_ctx->postsofevent->getISO8601Date('".$type."')");
1972          }
1973          else
1974          {
1975               return self::tplValue($a,"\$_ctx->postsofevent->getDate('".$format."','".$type."')");
1976          }
1977     }
1978     
1979     public static function PostOfEventTime($a)
1980     {
1981          $format = !empty($a['format']) ? addslashes($a['format']) : '';
1982          $type = (!empty($a['creadt']) ? 'creadt' : '');
1983          $type = (!empty($a['upddt']) ? 'upddt' : '');
1984       
1985          return self::tplValue($a,"\$_ctx->postsofevent->getTime('".$format."','".$type."')");
1986     }
1987     
1988     public static function PostOfEventAuthorCommonName($a)
1989     {
1990          return self::tplValue($a,'$_ctx->postsofevent->getAuthorCN()');
1991     }
1992     
1993     public static function PostOfEventAuthorLink($a)
1994     {
1995          return self::tplValue($a,'$_ctx->postsofevent->getAuthorLink()');
1996     }
1997     
1998     public static function PostOfEventCategory($a)
1999     {
2000          return self::tplValue($a,'$_ctx->postsofevent->cat_title');
2001     }
2002     
2003     public static function PostOfEventCategoryURL($a)
2004     {
2005          return self::tplValue($a,'$_ctx->postsofevent->getCategoryURL()');
2006     }
2007     
2008     # Generic template value
2009     protected static function tplValue($a,$v)
2010     {
2011          return '<?php echo '.sprintf($GLOBALS['core']->tpl->getFilters($a),$v).'; ?>'; 
2012     }
2013}
2014?>
Note: See TracBrowser for help on using the repository browser.

Sites map