Example #1
0
 function amr_format_value($content, $k, $event, $before = '', $after = '')
 {
     /* include the event so we can check for things like all day */
     /*  Format each Ical value for our presentation purposes
     	Note: Google does toss away the html when editing the text, but it is there if you add but don't edit.
     	what about all day?
     	*/
     global $amr_formats;
     /* amr check that this get set to the chosen list type */
     global $amr_options;
     global $amr_listtype;
     global $eventtaxonomies;
     //	echo '<br >'.$k;
     if (empty($content)) {
         return '';
     }
     if ($k == 'ORGANIZER') {
         // it is an array but a parsed one, not repeatable
         $htmlcontent = amr_format_organiser($content);
     } elseif ($k == 'ATTENDEE') {
         // it is an array but a parsed one, not repeatable
         $htmlcontent = amr_format_attendees($content);
     } elseif ($k == 'Attendee-counts') {
         // it is an array but we format the whole thing once
         $htmlcontent = amr_format_attendee_counts($content);
     } else {
         if (is_object($content)) {
             switch ($k) {
                 case 'EventDate':
                     $htmlcontent = '<abbr class="dtstart" title="' . amr_format_date('c', $content) . '">' . amr_format_date($amr_formats['Day'], $content) . '</abbr>';
                     break;
                 case 'EndDate':
                     $days = amr_event_is_multiday($event);
                     if ($days > 1) {
                         $htmlcontent = '<abbr class="dtend" title="' . amr_format_date('c', $content) . '">' . amr_format_date($amr_formats['Day'], $content) . '</abbr>';
                     } else {
                         $htmlcontent = '';
                     }
                     break;
                 case 'EndTime':
                 case 'StartTime':
                     if (isset($event['allday']) and $event['allday'] === 'allday') {
                         $htmlcontent = '';
                     } else {
                         $htmlcontent = amr_format_time($amr_formats['Time'], $content);
                     }
                     break;
                 case 'DTSTART':
                 case 'DTEND':
                 case 'UNTIL':
                     $htmlcontent = amr_format_date($amr_formats['Day'], $content);
                     if (empty($event['allday']) or !($event['allday'] == 'allday')) {
                         $htmlcontent .= ' ' . amr_format_time($amr_formats['Time'], $content);
                     }
                     break;
                 case 'X-WR-TIMEZONE':
                     /* amr  need to add code to reformat the timezone as per admin entry.  Also only show if timezone different ? */
                     $htmlcontent = amr_format_tz(timezone_name_get($content));
                     break;
                 case 'TZID':
                     /* amr  need to add code to reformat the timezone as per admin entry.  Also only show if timezone different ? */
                     $htmlcontent = amr_format_tz(timezone_name_get($content));
                     break;
                 case 'timezone':
                     /* amr  need to add code to reformat the timezone as per admin entry.  Also only show if timezone different ? */
                     $htmlcontent = amr_format_timezone($content);
                     break;
                 default:
                     /* should not be any */
                     $htmlcontent = amr_format_date($amr_formats['DateTime'], $content);
             }
         } elseif (is_array($content)) {
             if ($k === 'DURATION') {
                 $htmlcontent = amr_format_duration($content);
             } elseif ($k === 'RRULE' or $k === 'EXRULE') {
                 $htmlcontent = amr_format_rrule($content);
             } elseif ($k === 'RDATE' or $k === 'EXDATE') {
                 $htmlcontent = amr_prettyprint_r_ex_date($content);
             } elseif ($k === 'CATEGORIES') {
                 // umm - what if ics category
                 $htmlcontent = amr_format_taxonomies('category', $content);
             } elseif ($k === 'post_tag') {
                 $htmlcontent = amr_format_taxonomies('post_tag', $content);
             } elseif ($k == 'ATTACH') {
                 if (isset($content[0]['type'])) {
                     // then we are at the top level of the array, so can ask to handled repetaed values
                     return amr_format_repeatable_property($content, $k, $event, $before, $after);
                 } else {
                     $htmlcontent = amr_format_attach($content, $event);
                 }
             } else {
                 /* simple array don't think we need to list the items separately eg: multiple comments or descriptions - just line  */
                 if (!empty($eventtaxonomies) and in_array($k, $eventtaxonomies)) {
                     $htmlcontent = amr_format_taxonomies($k, $content);
                 } else {
                     return amr_format_repeatable_property($content, $k, $event, $before, $after);
                 }
             }
         } elseif (is_null($content) or $content === '') {
             $htmlcontent = '';
         } else {
             if (function_exists('amr_format_' . $k)) {
                 $htmlcontent = call_user_func('amr_format_' . $k, $content);
             } else {
                 switch ($k) {
                     case 'COMMENT':
                     case 'DESCRIPTION':
                         //var_dump($content);
                         $htmlcontent = html_entity_decode(amr_click_and_trim(nl2br2(amr_amp($content))));
                         break;
                     case 'SUMMARY':
                     case 'icsurl':
                     case 'addtogoogle':
                     case 'addevent':
                     case 'subscribeevent':
                     case 'subscribeseries':
                     case 'map':
                     case 'refresh':
                     case 'attending_event':
                         $htmlcontent = $content;
                         /* avoid hyperlink as we may have added url already */
                         break;
                     case 'URL':
                         /* assume valid URL, should not need to validate here, then format it as such */
                         $htmlcontent = amr_format_url($content);
                         break;
                     case 'LOCATION':
                         $htmlcontent = amr_click_and_trim(nl2br2(amr_amp($content)));
                         break;
                     case 'X-WR-TIMEZONE':
                         /* not parsed as object - since it is cal attribute, not property attribue */
                         $htmlcontent = amr_format_tz($content);
                         break;
                     case 'allday':
                         $htmlcontent = amr_format_allday($content);
                         break;
                     default:
                         /* Convert any newlines to html breaks */
                         if (!empty($eventtaxonomies) and in_array($k, $eventtaxonomies)) {
                             $htmlcontent = amr_format_taxonomies($k, $content);
                         } else {
                             $func = 'amr_format_' . str_replace('-', '_', $k);
                             if (function_exists($func)) {
                                 $htmlcontent = call_user_func($func, $content);
                             }
                             $htmlcontent = str_replace("\n", "<br />", $content);
                         }
                 }
             }
         }
     }
     if (empty($htmlcontent)) {
         return;
     }
     return $before . $htmlcontent . $after;
 }
Example #2
0
function amr_check_for_multiday_events(&$events)
{
    //for each event passed, chcek whiether it is a multi day, and if so add dummy days
    global $amr_globaltz;
    if (!empty($events)) {
        foreach ($events as $m => $event) {
            if (empty($event['EventDate'])) {
                if (ICAL_EVENTS_DEBUG) {
                    echo 'Unexpected empty event date for event ';
                    print_r($event, true);
                }
            } else {
                date_timezone_set($event['EventDate'], $amr_globaltz);
                // may do this earlier (after recurrence though), no harm in twice
                $days = amr_event_is_multiday($event);
                if (isset($_GET['debugmulti'])) {
                    echo '<br />Doing ' . $event['id'] . ' <b>multiday = ' . $days . ' </b>';
                }
                if ($days > 1) {
                    $day = 1;
                    if (empty($events[$m]['Classes'])) {
                        $events[$m]['Classes'] = '';
                    }
                    $events[$m]['Classes'] .= ' firstday ';
                    // already have first day
                    $events[$m]['dummyYMD'] = $event['EventDate']->format('Ymd');
                    //numerical so do not need amr_date_format
                    $events[$m]['MultiDay'] = $day;
                    //$tempdate = amr_newDateTime();  // create new obect so we do not update the same object
                    while ($day < $days) {
                        // must not be <= because we are plus one anyway - and original is first anyway
                        if (isset($_GET['debugmulti'])) {
                            echo '<br /> Do day = ' . $day;
                        }
                        $tempdate = new Datetime();
                        //if cloning dont need tz
                        $tempdate = clone $event['EventDate'];
                        // copy the current event date
                        date_modify($tempdate, '+' . $day . ' days');
                        // adjust days to currenmt midddle date if necessary
                        // must do like above in case we go over a month
                        $day = $day + 1;
                        $dummy[$m][$day] = $events[$m];
                        // copy event data over , but use dumy so we do not reprocess the additions
                        $dummy[$m][$day]['dummyYMD'] = $tempdate->format('Ymd');
                        // now set the date for this dummy event //numerical so do not need amr_date_format
                        $dummy[$m][$day]['MultiDay'] = $day;
                        // flag it as a multi day
                        // set the classes so we can style multi days
                        if (isset($_GET['debugmulti'])) {
                            echo ' dummyymd= ' . $dummy[$m][$day]['dummyYMD'];
                        }
                        if ($day >= $days) {
                            $dummy[$m][$day]['Classes'] .= ' lastday ';
                            $dummy[$m][$day]['Classes'] = str_replace('firstday', '', $dummy[$m][$day]['Classes']);
                        } else {
                            $dummy[$m][$day]['Classes'] = str_replace('firstday', '', $dummy[$m][$day]['Classes']);
                            $dummy[$m][$day]['Classes'] .= ' middleday ';
                        }
                    }
                } else {
                    $events[$m]['dummyYMD'] = $event['EventDate']->format('Ymd');
                    //numerical so do not need amr_date_format
                    $events[$m]['MultiDay'] = '0';
                    // to force non multidays to bottom
                }
                $events[$m]['dummytime'] = $event['EventDate']->format('His');
                //for sorting according to time
            }
        }
        //once we have processed all the events, THEN we can add the dummies in, so we do not reprocess them!
        if (!empty($dummy)) {
            foreach ($dummy as $m => $dummydays) {
                foreach ($dummydays as $k => $event) {
                    $events[] = $event;
                }
            }
        }
        //$events = amr_sort_by_three_cols ('dummyYMD', 'MultiDay', 'dummytime', $events);
        $events = amr_sort_by_two_cols('dummyYMD', 'MultiDay', $events);
        if (isset($_GET['debugmulti'])) {
            foreach ($events as $i => $e) {
                echo '<br />' . $e['id'] . ' ' . $e['EventDate']->format('Ymd') . ' ' . $e['dummyYMD'];
            }
        }
    }
    return $events;
}