]> git.mxchange.org Git - friendica-addons.git/blobdiff - cal/cal.php
Additional work for PR 3778
[friendica-addons.git] / cal / cal.php
index fb5ae482c6118f0e6bf5d11071c01c04afc03060..5c2f102191c51afb1bc6cff2a8c6dc756fe9e8f2 100644 (file)
@@ -5,6 +5,7 @@
  * Version: 0.1
  * Author: Tobias Diekershoff <https://f.diekershoff.de/profile/tobias>
  * License: MIT
+ * Status: Unsupported
  * ******************************************************************/
 
 
@@ -22,8 +23,8 @@ function cal_module()
 {
 }
 /*  pathes
- *  /cal/$user/export/$
- *  currently supported format is ical (iCalendar
+ *  /cal/$user/export/$format
+ *  currently supported formats are ical (iCalendar) and CSV
  */
 function cal_content()
 {
@@ -62,9 +63,9 @@ function cal_content()
        //  requested? then show all of your events, otherwise only those that 
        //  don't have limitations set in allow_cid and allow_gid
        if (local_user() == $uid) {
-           $r = q("SELECT `start`, `finish`, `adjust`, `summary`, `desc`, `location` FROM `event` WHERE `uid`=".$uid.";");
+           $r = q("SELECT `start`, `finish`, `adjust`, `summary`, `desc`, `location` FROM `event` WHERE `uid`=".$uid." and `cid`=0;");
        } else {
-           $r = q("SELECT `start`, `finish`, `adjust`, `summary`, `desc`, `location` FROM `event` WHERE `allow_cid`='' and `allow_gid`='' and `uid`='".$uid."';");
+           $r = q("SELECT `start`, `finish`, `adjust`, `summary`, `desc`, `location` FROM `event` WHERE `allow_cid`='' and `allow_gid`='' and `uid`='".$uid."' and `cid`='0';");
        }
        //  we have the events that are available for the requestor
        //  now format the output according to the requested format
@@ -80,7 +81,7 @@ function cal_content()
 
 function cal_format_output ($r, $f, $tz)
 {
-    $res = t('This calendar format is not supported');;
+    $res = t('This calendar format is not supported');
     switch ($f)
     {
        //  format the exported data as a CSV file
@@ -88,10 +89,12 @@ function cal_format_output ($r, $f, $tz)
            header("Content-type: text/csv");
            $o = '"Subject", "Start Date", "Start Time", "Description", "End Date", "End Time", "Location"' . PHP_EOL;
            foreach ($r as $rr) {
+//  TODO the time / date entries don't include any information about the 
+//  timezone the event is scheduled in :-/
                $tmp1 = strtotime($rr['start']);
                $tmp2 = strtotime($rr['finish']);
                $time_format = "%H:%M:%S";
-               $date_format = "%d.%m.%Y";
+               $date_format = "%Y-%m-%d";
                $o .= '"'.$rr['summary'].'", "'.strftime($date_format, $tmp1) .
                    '", "'.strftime($time_format, $tmp1).'", "'.$rr['desc'] .
                    '", "'.strftime($date_format, $tmp2) .
@@ -103,14 +106,17 @@ function cal_format_output ($r, $f, $tz)
 
        case "ical":
            header("Content-type: text/ics");
-           $res = '';
            $o = 'BEGIN:VCALENDAR'. PHP_EOL
-               . 'PRODID:-//friendica calendar export//0.1//EN' . PHP_EOL
-               . 'VERSION:2.0' . PHP_EOL;
+               . 'VERSION:2.0' . PHP_EOL
+               . 'PRODID:-//friendica calendar export//0.1//EN' . PHP_EOL;
 //  TODO include timezone informations in cases were the time is not in UTC
+//  see http://tools.ietf.org/html/rfc2445#section-4.8.3
 //             . 'BEGIN:VTIMEZONE' . PHP_EOL
 //             . 'TZID:' . $tz . PHP_EOL
 //             . 'END:VTIMEZONE' . PHP_EOL;
+//  TODO instead of PHP_EOL CRLF should be used for long entries
+//       but test your solution against http://icalvalid.cloudapp.net/
+//       also long lines SHOULD be split at 75 characters length
            foreach ($r as $rr) {
                if ($rr['adjust'] == 1) {
                    $UTC = 'Z';
@@ -131,14 +137,17 @@ function cal_format_output ($r, $f, $tz)
                if ($rr['summary'])
                    $tmp = $rr['summary'];
                    $tmp = str_replace(PHP_EOL, PHP_EOL.' ',$tmp);
+                   $tmp = addcslashes($tmp, ',;');
                    $o .= 'SUMMARY:' . $tmp . PHP_EOL;
                if ($rr['desc'])
                    $tmp = $rr['desc'];
                    $tmp = str_replace(PHP_EOL, PHP_EOL.' ',$tmp);
+                   $tmp = addcslashes($tmp, ',;');
                    $o .= 'DESCRIPTION:' . $tmp . PHP_EOL;
                if ($rr['location']) {
                    $tmp = $rr['location'];
                    $tmp = str_replace(PHP_EOL, PHP_EOL.' ',$tmp);
+                   $tmp = addcslashes($tmp, ',;');
                    $o .= 'LOCATION:' . $tmp . PHP_EOL;
                }
                $o .= 'END:VEVENT' . PHP_EOL;
@@ -167,17 +176,25 @@ function cal_addon_settings ( &$a, &$s  )
 
     $enabled = get_pconfig(local_user(), 'cal', 'enable');
     $checked = (($enabled) ? ' checked="checked" ' : '');
-    $url = $a->get_baseurl().'/cal/'.$a->user['nickname'].'/export/ical';
+    $url = $a->get_baseurl().'/cal/'.$a->user['nickname'].'/export/<em>format</em>';
 
+    $s .= '<span id="settings_cal_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_cal_expanded\'); openClose(\'settings_cal_inflated\');">';
     $s .= '<h3>'.t('Export Events').'</h3>';
-    $s .= '<p>'.t('If this is enabled, you public events will be available at').' <strong>'.$url.'</strong></p>';
-    $s .= '<div id="cal-enable-wrapper">';
+    $s .= '</span>';
+    $s .= '<div id="settings_cal_expanded" class="settings-block" style="display: none;">';
+    $s .= '<span class="fakelink" onclick="openClose(\'settings_cal_expanded\'); openClose(\'settings_cal_inflated\');">';
+    $s .= '<h3>'.t('Export Events').'</h3>';
+    $s .= '</span>';
+
+    $s .= '<div id="cal-wrapper">';
+    $s .= '<p>'.t('If this is enabled, your public events will be available at').' <strong>'.$url.'</strong></p>';
+    $s .= '<p>'.t('Currently supported formats are ical and csv.').'</p>';
     $s .= '<label id="cal-enable-label" for="cal-checkbox">'. t('Enable calendar export') .'</label>';
     $s .= '<input id="cal-checkbox" type="checkbox" name="cal-enable" value="1" ' . $checked . '/>';
-    $s .= '</div><div class="clear"></div>';
-    $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="cal-submit" class="settings-submit" value="' . t('Submit') . '" /></div>'; 
-    $s .= '</div><div class="clear"></div>';
-
+    $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="cal-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div>'; 
+    $s .= '<div class="clear"></div>';
+    $s .= '</div>';
+    $s .= '</div>';
 }
 
 ?>