3 * @file include/event.php
4 * @brief functions specific to event handling
7 require_once('include/bbcode.php');
8 require_once('include/map.php');
9 require_once('include/datetime.php');
11 function format_event_html($ev, $simple = false) {
13 if(! ((is_array($ev)) && count($ev)))
16 $bd_format = t('l F d, Y \@ g:i A') ; // Friday January 18, 2011 @ 8 AM
18 $event_start = (($ev['adjust']) ? day_translate(datetime_convert('UTC', date_default_timezone_get(),
19 $ev['start'] , $bd_format ))
20 : day_translate(datetime_convert('UTC', 'UTC',
21 $ev['start'] , $bd_format)));
23 $event_end = (($ev['adjust']) ? day_translate(datetime_convert('UTC', date_default_timezone_get(),
24 $ev['finish'] , $bd_format ))
25 : day_translate(datetime_convert('UTC', 'UTC',
26 $ev['finish'] , $bd_format )));
29 $o = "<h3>".bbcode($ev['summary'])."</h3>";
31 $o .= "<p>".bbcode($ev['desc'])."</p>";
33 $o .= "<h4>".t('Starts:')."</h4><p>".$event_start."</p>";
36 $o .= "<h4>".t('Finishes:')."</h4><p>".$event_end."</p>";
38 if(strlen($ev['location']))
39 $o .= "<h4>".t('Location:')."</h4><p>".$ev['location']."</p>";
44 $o = '<div class="vevent">' . "\r\n";
47 $o .= '<p class="summary event-summary">' . bbcode($ev['summary']) . '</p>' . "\r\n";
49 $o .= '<p class="description event-description">' . bbcode($ev['desc']) . '</p>' . "\r\n";
51 $o .= '<p class="event-start">' . t('Starts:') . ' <abbr class="dtstart" title="'
52 . datetime_convert('UTC','UTC',$ev['start'], (($ev['adjust']) ? ATOM_TIME : 'Y-m-d\TH:i:s' ))
54 . '</abbr></p>' . "\r\n";
57 $o .= '<p class="event-end" >' . t('Finishes:') . ' <abbr class="dtend" title="'
58 . datetime_convert('UTC','UTC',$ev['finish'], (($ev['adjust']) ? ATOM_TIME : 'Y-m-d\TH:i:s' ))
60 . '</abbr></p>' . "\r\n";
62 if(strlen($ev['location'])){
63 $o .= '<p class="event-location"> ' . t('Location:') . ' <span class="location">'
64 . bbcode($ev['location'])
65 . '</span></p>' . "\r\n";
67 if (strpos($ev['location'], "[map") !== False) {
68 $map = generate_named_map($ev['location']);
69 if ($map!==$ev['location']) $o.=$map;
74 $o .= '</div>' . "\r\n";
79 function parse_event($h) {
81 require_once('include/Scrape.php');
82 require_once('include/html2bbcode');
84 $h = '<html><body>' . $h . '</body></html>';
90 $dom = HTML5_Parser::parse($h);
91 } catch (DOMException $e) {
92 logger('parse_event: parse error: ' . $e);
98 $items = $dom->getElementsByTagName('*');
100 foreach($items as $item) {
101 if(attribute_contains($item->getAttribute('class'), 'vevent')) {
102 $level2 = $item->getElementsByTagName('*');
103 foreach($level2 as $x) {
104 if(attribute_contains($x->getAttribute('class'),'dtstart') && $x->getAttribute('title')) {
105 $ret['start'] = $x->getAttribute('title');
106 if(! strpos($ret['start'],'Z'))
107 $ret['adjust'] = true;
109 if(attribute_contains($x->getAttribute('class'),'dtend') && $x->getAttribute('title'))
110 $ret['finish'] = $x->getAttribute('title');
112 if(attribute_contains($x->getAttribute('class'),'description'))
113 $ret['desc'] = $x->textContent;
114 if(attribute_contains($x->getAttribute('class'),'location'))
115 $ret['location'] = $x->textContent;
122 if((x($ret,'desc')) && ((strpos($ret['desc'],'<') !== false) || (strpos($ret['desc'],'>') !== false))) {
123 $config = HTMLPurifier_Config::createDefault();
124 $config->set('Cache.DefinitionImpl', null);
125 $purifier = new HTMLPurifier($config);
126 $ret['desc'] = html2bbcode($purifier->purify($ret['desc']));
129 if((x($ret,'location')) && ((strpos($ret['location'],'<') !== false) || (strpos($ret['location'],'>') !== false))) {
130 $config = HTMLPurifier_Config::createDefault();
131 $config->set('Cache.DefinitionImpl', null);
132 $purifier = new HTMLPurifier($config);
133 $ret['location'] = html2bbcode($purifier->purify($ret['location']));
137 $ret['start'] = datetime_convert('UTC','UTC',$ret['start']);
139 $ret['finish'] = datetime_convert('UTC','UTC',$ret['finish']);
145 function format_event_bbcode($ev) {
150 $o .= '[event-summary]' . $ev['summary'] . '[/event-summary]';
153 $o .= '[event-description]' . $ev['desc'] . '[/event-description]';
156 $o .= '[event-start]' . $ev['start'] . '[/event-start]';
158 if(($ev['finish']) && (! $ev['nofinish']))
159 $o .= '[event-finish]' . $ev['finish'] . '[/event-finish]';
162 $o .= '[event-location]' . $ev['location'] . '[/event-location]';
165 $o .= '[event-adjust]' . $ev['adjust'] . '[/event-adjust]';
172 function bbtovcal($s) {
176 $o = format_event_html($ev);
181 function bbtoevent($s) {
186 if(preg_match("/\[event\-summary\](.*?)\[\/event\-summary\]/is",$s,$match))
187 $ev['summary'] = $match[1];
189 if(preg_match("/\[event\-description\](.*?)\[\/event\-description\]/is",$s,$match))
190 $ev['desc'] = $match[1];
192 if(preg_match("/\[event\-start\](.*?)\[\/event\-start\]/is",$s,$match))
193 $ev['start'] = $match[1];
195 if(preg_match("/\[event\-finish\](.*?)\[\/event\-finish\]/is",$s,$match))
196 $ev['finish'] = $match[1];
198 if(preg_match("/\[event\-location\](.*?)\[\/event\-location\]/is",$s,$match))
199 $ev['location'] = $match[1];
201 if(preg_match("/\[event\-adjust\](.*?)\[\/event\-adjust\]/is",$s,$match))
202 $ev['adjust'] = $match[1];
203 $ev['nofinish'] = (((x($ev, 'start') && $ev['start']) && (!x($ev, 'finish') || !$ev['finish'])) ? 1 : 0);
209 function sort_by_date($a) {
211 usort($a,'ev_compare');
216 function ev_compare($a,$b) {
218 $date_a = (($a['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$a['start']) : $a['start']);
219 $date_b = (($b['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$b['start']) : $b['start']);
221 if($date_a === $date_b)
222 return strcasecmp($a['desc'],$b['desc']);
224 return strcmp($date_a,$date_b);
227 function event_delete($event_id) {
231 q("DELETE FROM `event` WHERE `id` = %d", intval($event_id));
232 logger("Deleted event ".$event_id, LOGGER_DEBUG);
235 function event_store($arr) {
237 require_once('include/datetime.php');
238 require_once('include/items.php');
239 require_once('include/bbcode.php');
243 $arr['created'] = (($arr['created']) ? $arr['created'] : datetime_convert());
244 $arr['edited'] = (($arr['edited']) ? $arr['edited'] : datetime_convert());
245 $arr['type'] = (($arr['type']) ? $arr['type'] : 'event' );
246 $arr['cid'] = ((intval($arr['cid'])) ? intval($arr['cid']) : 0);
247 $arr['uri'] = (x($arr,'uri') ? $arr['uri'] : item_new_uri($a->get_hostname(),$arr['uid']));
248 $arr['private'] = ((x($arr,'private')) ? intval($arr['private']) : 0);
251 $c = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
256 $c = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
264 // Existing event being modified
268 // has the event actually changed?
270 $r = q("SELECT * FROM `event` WHERE `id` = %d AND `uid` = %d LIMIT 1",
274 if((! dbm::is_result($r)) || ($r[0]['edited'] === $arr['edited'])) {
276 // Nothing has changed. Grab the item id to return.
278 $r = q("SELECT * FROM `item` WHERE `event-id` = %d AND `uid` = %d LIMIT 1",
282 return((dbm::is_result($r)) ? $r[0]['id'] : 0);
285 // The event changed. Update it.
287 $r = q("UPDATE `event` SET
297 WHERE `id` = %d AND `uid` = %d",
299 dbesc($arr['edited']),
300 dbesc($arr['start']),
301 dbesc($arr['finish']),
302 dbesc($arr['summary']),
304 dbesc($arr['location']),
306 intval($arr['adjust']),
307 intval($arr['nofinish']),
311 $r = q("SELECT * FROM `item` WHERE `event-id` = %d AND `uid` = %d LIMIT 1",
315 if(dbm::is_result($r)) {
316 $object = '<object><type>' . xmlify(ACTIVITY_OBJ_EVENT) . '</type><title></title><id>' . xmlify($arr['uri']) . '</id>';
317 $object .= '<content>' . xmlify(format_event_bbcode($arr)) . '</content>';
318 $object .= '</object>' . "\n";
321 q("UPDATE `item` SET `body` = '%s', `object` = '%s', `edited` = '%s' WHERE `id` = %d AND `uid` = %d",
322 dbesc(format_event_bbcode($arr)),
324 dbesc($arr['edited']),
329 $item_id = $r[0]['id'];
333 call_hooks("event_updated", $arr['id']);
339 // New event. Store it.
341 $r = q("INSERT INTO `event` ( `uid`,`cid`,`uri`,`created`,`edited`,`start`,`finish`,`summary`, `desc`,`location`,`type`,
342 `adjust`,`nofinish`,`allow_cid`,`allow_gid`,`deny_cid`,`deny_gid`)
343 VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', '%s' ) ",
347 dbesc($arr['created']),
348 dbesc($arr['edited']),
349 dbesc($arr['start']),
350 dbesc($arr['finish']),
351 dbesc($arr['summary']),
353 dbesc($arr['location']),
355 intval($arr['adjust']),
356 intval($arr['nofinish']),
357 dbesc($arr['allow_cid']),
358 dbesc($arr['allow_gid']),
359 dbesc($arr['deny_cid']),
360 dbesc($arr['deny_gid'])
364 $r = q("SELECT * FROM `event` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
368 if(dbm::is_result($r))
373 $item_arr['uid'] = $arr['uid'];
374 $item_arr['contact-id'] = $arr['cid'];
375 $item_arr['uri'] = $arr['uri'];
376 $item_arr['parent-uri'] = $arr['uri'];
377 $item_arr['guid'] = $arr['guid'];
378 $item_arr['type'] = 'activity';
379 $item_arr['wall'] = (($arr['cid']) ? 0 : 1);
380 $item_arr['contact-id'] = $contact['id'];
381 $item_arr['owner-name'] = $contact['name'];
382 $item_arr['owner-link'] = $contact['url'];
383 $item_arr['owner-avatar'] = $contact['thumb'];
384 $item_arr['author-name'] = $contact['name'];
385 $item_arr['author-link'] = $contact['url'];
386 $item_arr['author-avatar'] = $contact['thumb'];
387 $item_arr['title'] = '';
388 $item_arr['allow_cid'] = $arr['allow_cid'];
389 $item_arr['allow_gid'] = $arr['allow_gid'];
390 $item_arr['deny_cid'] = $arr['deny_cid'];
391 $item_arr['deny_gid'] = $arr['deny_gid'];
392 $item_arr['private'] = $arr['private'];
393 $item_arr['last-child'] = 1;
394 $item_arr['visible'] = 1;
395 $item_arr['verb'] = ACTIVITY_POST;
396 $item_arr['object-type'] = ACTIVITY_OBJ_EVENT;
397 $item_arr['origin'] = ((intval($arr['cid']) == 0) ? 1 : 0);
398 $item_arr['body'] = format_event_bbcode($event);
401 $item_arr['object'] = '<object><type>' . xmlify(ACTIVITY_OBJ_EVENT) . '</type><title></title><id>' . xmlify($arr['uri']) . '</id>';
402 $item_arr['object'] .= '<content>' . xmlify(format_event_bbcode($event)) . '</content>';
403 $item_arr['object'] .= '</object>' . "\n";
405 $item_id = item_store($item_arr);
407 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
410 //if(dbm::is_result($r))
411 // $plink = $a->get_baseurl() . '/display/' . $r[0]['nickname'] . '/' . $item_id;
415 //q("UPDATE `item` SET `plink` = '%s', `event-id` = %d WHERE `uid` = %d AND `id` = %d",
417 // intval($event['id']),
418 // intval($arr['uid']),
421 q("UPDATE `item` SET `event-id` = %d WHERE `uid` = %d AND `id` = %d",
422 intval($event['id']),
428 call_hooks("event_created", $event['id']);
434 function get_event_strings() {
435 // First day of the week (0 = Sunday)
436 $firstDay = get_pconfig(local_user(),'system','first_day_of_week');
437 if ($firstDay === false) $firstDay=0;
440 "firstDay" => $firstDay,
448 "Sunday" => t("Sunday"),
449 "Monday" => t("Monday"),
450 "Tuesday" => t("Tuesday"),
451 "Wednesday" => t("Wednesday"),
452 "Thursday" => t("Thursday"),
453 "Friday" => t("Friday"),
454 "Saturday" => t("Saturday"),
467 "January" => t("January"),
468 "February" => t("February"),
469 "March" => t("March"),
470 "April" => t("April"),
474 "August" => t("August"),
475 "September" => t("September"),
476 "October" => t("October"),
477 "November" => t("November"),
478 "December" => t("December"),
479 "today" => t("today"),
480 "month" => t("month"),
483 "allday" => t("all-day"),
485 "noevent" => t("No events to display"),
487 "dtstart_label" => t("Starts:"),
488 "dtend_label" => t("Finishes:"),
489 "location_label" => t("Location:")
496 * @brief Get an event by its event ID
498 * @param type $owner_uid The User ID of the owner of the event
499 * @param type $event_params An assoziative array with
500 * int 'event_id' => The ID of the event in the event table
501 * @param type $sql_extra
502 * @return array Query result
504 function event_by_id($owner_uid = 0, $event_params, $sql_extra = '') {
505 // ownly allow events if there is a valid owner_id
509 // query for the event by event id
510 $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,
511 `item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event`
512 STRAIGHT_JOIN `item` ON `item`.`event-id` = `event`.`id` AND `item`.`uid` = `event`.`uid`
513 WHERE `event`.`uid` = %d AND `event`.`id` = %d $sql_extra",
515 intval($event_params["event_id"])
518 if(dbm::is_result($r))
524 * @brief Get all events in a specific timeframe
526 * @param int $owner_uid The User ID of the owner of the events
527 * @param array $event_params An assoziative array with
529 * string 'start' => Start time of the timeframe
530 * string 'finish' => Finish time of the timeframe
531 * string 'adjust_start' =>
532 * string 'adjust_start' =>
534 * @param string $sql_extra Additional sql conditions (e.g. permission request)
535 * @return array Query results
537 function events_by_date($owner_uid = 0, $event_params, $sql_extra = '') {
538 // ownly allow events if there is a valid owner_id
542 // query for the event by date
543 $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,
544 `item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event`
545 STRAIGHT_JOIN `item` ON `item`.`event-id` = `event`.`id` AND `item`.`uid` = `event`.`uid`
546 WHERE `event`.`uid` = %d AND event.ignore = %d
547 AND ((`adjust` = 0 AND (`finish` >= '%s' OR (nofinish AND start >= '%s')) AND `start` <= '%s')
548 OR (`adjust` = 1 AND (`finish` >= '%s' OR (nofinish AND start >= '%s')) AND `start` <= '%s'))
551 intval($event_params["ignored"]),
552 dbesc($event_params["start"]),
553 dbesc($event_params["start"]),
554 dbesc($event_params["finish"]),
555 dbesc($event_params["adjust_start"]),
556 dbesc($event_params["adjust_start"]),
557 dbesc($event_params["adjust_finish"])
560 if(dbm::is_result($r))
565 * @brief Convert an array query results in an arry which could be used by the events template
567 * @param array $arr Event query array
568 * @return array Event array for the template
570 function process_events ($arr) {
576 foreach($arr as $rr) {
578 $j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'j') : datetime_convert('UTC','UTC',$rr['start'],'j'));
579 $d = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], $fmt) : datetime_convert('UTC','UTC',$rr['start'],$fmt));
580 $d = day_translate($d);
582 $start = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'c') : datetime_convert('UTC','UTC',$rr['start'],'c'));
583 if ($rr['nofinish']){
586 $end = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['finish'], 'c') : datetime_convert('UTC','UTC',$rr['finish'],'c'));
590 $is_first = ($d !== $last_date);
593 $edit = ((! $rr['cid']) ? array($a->get_baseurl().'/events/event/'.$rr['id'],t('Edit event'),'','') : null);
594 $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8'));
596 list($title, $_trash) = explode("<br",bbcode($rr['desc']),2);
597 $title = strip_tags(html_entity_decode($title,ENT_QUOTES,'UTF-8'));
600 $html = format_event_html($rr);
601 $rr['desc'] = bbcode($rr['desc']);
602 $rr['location'] = bbcode($rr['location']);
612 'is_first'=>$is_first,
615 'plink' => array($rr['plink'],t('link to source'),'',''),
624 * @brief Format event to export format (ical/csv)
626 * @param array $events Query result for events
627 * @param string $format The output format (ical/csv)
628 * @param string $timezone The timezone of the user (not implemented yet)
630 * @return string Content according to selected export format
632 function event_format_export ($events, $format = 'ical', $timezone) {
633 if(! ((is_array($events)) && count($events)))
637 // format the exported data as a CSV file
639 header("Content-type: text/csv");
640 $o = '"Subject", "Start Date", "Start Time", "Description", "End Date", "End Time", "Location"' . PHP_EOL;
642 foreach ($events as $event) {
643 /// @todo the time / date entries don't include any information about the
644 // timezone the event is scheduled in :-/
645 $tmp1 = strtotime($event['start']);
646 $tmp2 = strtotime($event['finish']);
647 $time_format = "%H:%M:%S";
648 $date_format = "%Y-%m-%d";
649 $o .= '"'.$event['summary'].'", "'.strftime($date_format, $tmp1) .
650 '", "'.strftime($time_format, $tmp1).'", "'.$event['desc'] .
651 '", "'.strftime($date_format, $tmp2) .
652 '", "'.strftime($time_format, $tmp2) .
653 '", "'.$event['location'].'"' . PHP_EOL;
657 // format the exported data as a ics file
659 header("Content-type: text/ics");
660 $o = 'BEGIN:VCALENDAR'. PHP_EOL
661 . 'VERSION:2.0' . PHP_EOL
662 . 'PRODID:-//friendica calendar export//0.1//EN' . PHP_EOL;
663 /// @todo include timezone informations in cases were the time is not in UTC
664 // see http://tools.ietf.org/html/rfc2445#section-4.8.3
665 // . 'BEGIN:VTIMEZONE' . PHP_EOL
666 // . 'TZID:' . $timezone . PHP_EOL
667 // . 'END:VTIMEZONE' . PHP_EOL;
668 // TODO instead of PHP_EOL CRLF should be used for long entries
669 // but test your solution against http://icalvalid.cloudapp.net/
670 // also long lines SHOULD be split at 75 characters length
671 foreach ($events as $event) {
672 if ($event['adjust'] == 1) {
677 $o .= 'BEGIN:VEVENT' . PHP_EOL;
679 $tmp = strtotime($event['start']);
680 $dtformat = "%Y%m%dT%H%M%S".$UTC;
681 $o .= 'DTSTART:'.strftime($dtformat, $tmp).PHP_EOL;
683 if (!$event['nofinish']) {
684 $tmp = strtotime($event['finish']);
685 $dtformat = "%Y%m%dT%H%M%S".$UTC;
686 $o .= 'DTEND:'.strftime($dtformat, $tmp).PHP_EOL;
688 if ($event['summary'])
689 $tmp = $event['summary'];
690 $tmp = str_replace(PHP_EOL, PHP_EOL.' ',$tmp);
691 $tmp = addcslashes($tmp, ',;');
692 $o .= 'SUMMARY:' . $tmp . PHP_EOL;
694 $tmp = $event['desc'];
695 $tmp = str_replace(PHP_EOL, PHP_EOL.' ',$tmp);
696 $tmp = addcslashes($tmp, ',;');
697 $o .= 'DESCRIPTION:' . $tmp . PHP_EOL;
698 if ($event['location']) {
699 $tmp = $event['location'];
700 $tmp = str_replace(PHP_EOL, PHP_EOL.' ',$tmp);
701 $tmp = addcslashes($tmp, ',;');
702 $o .= 'LOCATION:' . $tmp . PHP_EOL;
705 $o .= 'END:VEVENT' . PHP_EOL;
709 $o .= 'END:VCALENDAR' . PHP_EOL;
717 * @brief Get all events for a user ID
719 * The query for events is done permission sensitive
720 * If the user is the owner of the calendar he/she
721 * will get all of his/her available events.
722 * If the user is only a visitor only the public events will
725 * @param int $uid The user ID
726 * @param int $sql_extra Additional sql conditions for permission
728 * @return array Query results
730 function events_by_uid($uid = 0, $sql_extra = '') {
734 // The permission condition if no condition was transmitted
736 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' ";
738 // does the user who requests happen to be the owner of the events
739 // requested? then show all of your events, otherwise only those that
740 // don't have limitations set in allow_cid and allow_gid
741 if (local_user() == $uid) {
742 $r = q("SELECT `start`, `finish`, `adjust`, `summary`, `desc`, `location`, `nofinish`
743 FROM `event` WHERE `uid`= %d AND `cid` = 0 ",
747 $r = q("SELECT `start`, `finish`, `adjust`, `summary`, `desc`, `location`, `nofinish`
748 FROM `event` WHERE `uid`= %d AND `cid` = 0 $sql_extra ",
753 if(dbm::is_result($r))
759 * @param int $uid The user ID
760 * @param string $format Output format (ical/csv)
761 * @return array With the results
762 * bool 'success' => True if the processing was successful
763 * string 'format' => The output format
764 * string 'extension' => The file extension of the output format
765 * string 'content' => The formatted output content
767 * @todo Respect authenticated users with events_by_uid()
769 function event_export($uid, $format = 'ical') {
773 // we are allowed to show events
774 // get the timezone the user is in
775 $r = q("SELECT `timezone` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid));
776 if (dbm::is_result($r))
777 $timezone = $r[0]['timezone'];
779 // get all events which are owned by a uid (respects permissions);
780 $events = events_by_uid($uid);
782 // we have the events that are available for the requestor
783 // now format the output according to the requested format
785 $res = event_format_export($events, $format, $timezone);
787 // If there are results the precess was successfull
791 // get the file extension for the format
806 'success' => $process,
808 'extension' => $file_ext,
816 * @brief Get the events widget
818 * @return string Formated html of the evens widget
820 function widget_events() {
823 $owner_uid = $a->data['user']['uid'];
824 // $a->data is only available if the profile page is visited. If the visited page is not part
825 // of the profile page it should be the personal /events page. So we can use $a->user
826 $user = ($a->data['user']['nickname'] ? $a->data['user']['nickname'] : $a->user['nickname']);
829 // The permission testing is a little bit tricky because we have to respect many cases
831 // It's not the private events page (we don't get the $owner_uid for /events)
832 if(! local_user() && ! $owner_uid)
835 // Cal logged in user (test permission at foreign profile page)
836 // If the $owner uid is available we know it is part of one of the profile pages (like /cal)
837 // So we have to test if if it's the own profile page of the logged in user
838 // or a foreign one. For foreign profile pages we need to check if the feature
839 // for exporting the cal is enabled (otherwise the widget would appear for logged in users
840 // on foreigen profile pages even if the widget is disabled)
841 if(intval($owner_uid) && local_user() !== $owner_uid && ! feature_enabled($owner_uid, "export_calendar"))
844 // If it's a kind of profile page (intval($owner_uid)) return if the user not logged in and
845 // export feature isn't enabled
846 if(intval($owner_uid) && ! local_user() && ! feature_enabled($owner_uid, "export_calendar"))
849 return replace_macros(get_markup_template("events_aside.tpl"), array(
850 '$etitle' => t("Export"),
851 '$export_ical' => t("Export calendar as ical"),
852 '$export_csv' => t("Export calendar as csv"),