Example #1
0
function amr_process_RRULE($p, $start, $astart, $aend, $limit)
{
    /* RRULE a parsed array.  If the specified event repeats between the given start and
     * end times, return one or more nonrepeating date strings in array
     */
    global $amr_wkst, $amr_timeperiod_conv;
    /* converts daily to day etc */
    /* now we should have if they are there: $p[freq], $p[interval, $until, $wkst, $ count, $byweekno etc */
    /* check  / set limits  NB don't forget the distinction between the two kinds of limits  */
    $tz = date_timezone_get($start);
    if (isset($_GET['rdebug'])) {
        echo '<br />&nbsp;start=' . $start->format('c') . ' <br />astart=' . $astart->format('c') . '<br /> parameter passed: ';
        if (is_array($p)) {
            foreach ($p as $k => $i) {
                echo $k . ' ';
                if (is_object($i)) {
                    echo $i->format('c');
                } else {
                    print_r($i);
                }
                echo '<br />';
            }
        } else {
            echo '<br />rule passed';
            var_dump($p);
        }
    }
    if (!isset($p['COUNT'])) {
        $count = AMR_MAX_REPEATS;
    } else {
        $count = $p['COUNT'];
    }
    if (isset($_GET['cdebug'])) {
        echo '<br />Limiting the repeats to ' . $count;
    }
    $until = amr_newDateTime();
    $original_until = amr_newDateTime();
    if (!isset($p['UNTIL'])) {
        $until = clone $aend;
        $original_until = clone $aend;
    } else {
        $until = clone $p['UNTIL'];
        $original_until = clone $p['UNTIL'];
        if ($until > $aend) {
            $until = clone $aend;
        }
    }
    // 2014 07 09
    $original_start = amr_newDateTime();
    $original_start = clone $start;
    $next_start = amr_newDateTime();
    $next_start = clone $start;
    if (amr_is_before($until, $astart)) {
        return false;
    }
    /* if it ends before our overall start, then skip */
    /* now prepare out "intervals array for date incrementing eg: p[monthly] = 2 etc... Actualy there should only be 1 */
    if (isset($p['FREQ'])) {
        /* so know yearly, daily or weekly etc  - setup increments eg 2 yearsly or what */
        if (!isset($p['INTERVAL'])) {
            $p['INTERVAL'] = 1;
        }
        switch ($p['FREQ']) {
            case 'WEEKLY':
                $int['day'] = $p['INTERVAL'] * 7;
                break;
            default:
                $inttype = $amr_timeperiod_conv[$p['FREQ']];
                $int[$inttype] = $p['INTERVAL'];
        }
        $freq = $p['FREQ'];
    }
    /*  use the freq increment to get close to our listing start time.  If we are within one freq of our listing start, we should be safe in calculating the odd rrules. */
    /* NOTE we can only do this if we do not have the count or a bysetpos !!!!   */
    //	if (empty($int)) var_dump($p);
    if (empty($p['COUNT']) and empty($p['BYSETPOS']) and !empty($int)) {
        $next_start = amr_get_a_closer_start($next_start, $astart, $int);
    }
    // 20110301 the nbydays, especially the negs, require that one initially consider a wider valid range so as not to unintentionally exclude a date before the expand/contract has beeen applied .  Ie we might iterate to 28th and exclude, but actually once one has applied the -2Mo or some such rule, the date would have contracted into the valid range.  So apply restrictions later.
    $until = amr_increment_datetime($until, $int);
    unset($p['UNTIL']);
    /* unset so we can use other params more cleanly, we have count saved etc */
    unset($p['COUNT']);
    unset($p['FREQ']);
    unset($p['INTERVAL']);
    if (!empty($p['WKST'])) {
        $wkst = $p['WKST'];
        unset($p['WKST']);
    } else {
        $wkst = $amr_wkst;
    }
    if (count($p) === 0) {
        $p = null;
    }
    /* If that was all we had, get rid of it anyway */
    if (isset($p['NBYDAY'])) {
        /* if we separated these in the parsing process, merge them here,    NOOO - will cause problems with the +1's and bool */
        if (isset($p['BYDAY'])) {
            $p['BYDAY'] = array_merge($p['NBYDAY'], $p['BYDAY']);
        } else {
            $p['BYDAY'] = $p['NBYDAY'];
        }
        unset($p['NBYDAY']);
    }
    while ($next_start <= $until) {
        /* don't check astart here - may miss some */
        $datearray[] = amr_get_date_parts($next_start);
        if (isset($_GET['rdebug'])) {
            echo '<hr>Checked start against extra until (1 extra iteration to allow for negativebydays) etc ' . $next_start->format('c') . ' ' . $until->format('c');
            echo '<br />date array = ';
            var_dump($datearray);
        }
        switch ($freq) {
            /* the 'bys' are now in an array $p .  NOTE THE sequence here is important */
            case 'SECONDLY':
                if (isset($p['month'])) {
                    $datearray = amr_limit($datearray, $p['month'], 'month');
                }
                /* BYWEEK NO not applicable here */
                if (isset($p['BYYEARDAY'])) {
                    $datearray = amr_limit_by_yearday($datearray, $p['BYYEARDAY'], $tz);
                }
                if (isset($p['day'])) {
                    $datearray = amr_limit($datearray, $p['day'], 'day');
                }
                if (isset($p['BYDAY'])) {
                    $datearray = amr_limit_by_day_of_week($datearray, $p['BYDAY'], $tz);
                }
                //				foreach ($p as $i => $by) amr_limit_dates_withby($dates);
                if (isset($p['hour'])) {
                    $datearray = amr_limit($datearray, $p['hour'], 'hour');
                }
                if (isset($p['minute'])) {
                    $datearray = amr_limit($datearray, $p['minute'], 'minute');
                }
                if (isset($p['second'])) {
                    $datearray = amr_limit($datearray, $p['second'], 'second');
                }
                break;
            case 'MINUTELY':
                if (isset($p['month'])) {
                    $datearray = amr_limit($datearray, $p['month'], 'month');
                }
                /* BYWEEK NO not applicable here */
                if (isset($p['BYYEARDAY'])) {
                    $datearray = amr_limit_by_yearday($datearray, $p['BYYEARDAY'], $tz);
                }
                if (isset($p['day'])) {
                    $datearray = amr_limit($datearray, $p['day'], 'day');
                }
                if (isset($p['BYDAY'])) {
                    $datearray = amr_limit_by_day_of_week($datearray, $p['BYDAY'], $tz);
                }
                if (isset($p['hour'])) {
                    $datearray = amr_limit($datearray, $p['hour'], 'hour');
                }
                if (isset($p['minute'])) {
                    $datearray = amr_limit($datearray, $p['minute'], 'minute');
                }
                if (isset($p['second'])) {
                    $datearray = amr_expand($datearray, $p['second'], 'second', $tz);
                }
                break;
            case 'HOURLY':
                if (isset($p['month'])) {
                    $datearray = amr_limit($datearray, $p['month'], 'month');
                }
                /* BYWEEK NO not applicable here */
                if (isset($p['BYYEARDAY'])) {
                    $datearray = amr_limit_by_yearday($datearray, $p['BYYEARDAY'], $tz);
                }
                if (isset($p['day'])) {
                    $datearray = amr_limit($datearray, $p['day'], 'day');
                }
                if (isset($p['BYDAY'])) {
                    $datearray = amr_limit_by_day_of_week($datearray, $p['BYDAY'], $tz);
                }
                if (isset($p['hour'])) {
                    $datearray = amr_limit($datearray, $p['hour'], 'hour', $tz);
                }
                if (isset($p['minute'])) {
                    $datearray = amr_expand($datearray, $p['minute'], 'minute', $tz);
                }
                if (isset($p['second'])) {
                    $datearray = amr_expand($datearray, $p['second'], 'second', $tz);
                }
                break;
            case 'DAILY':
                if (isset($p['month'])) {
                    $datearray = amr_limit($datearray, $p['month'], 'month');
                }
                /* BYWEEK NO and BYYEARDAY not applicable here */
                if (isset($p['day'])) {
                    $datearray = amr_limit($datearray, $p['day'], 'day');
                }
                if (isset($p['BYDAY'])) {
                    $datearray = amr_limit_by_day_of_week($datearray, $p['BYDAY'], $tz);
                }
                if (isset($p['hour'])) {
                    $datearray = amr_expand($datearray, $p['hour'], 'hour', $tz);
                }
                if (isset($p['minute'])) {
                    $datearray = amr_expand($datearray, $p['minute'], 'minute', $tz);
                }
                if (isset($p['second'])) {
                    $datearray = amr_expand($datearray, $p['second'], 'second', $tz);
                }
                break;
            case 'WEEKLY':
                if (isset($p['month'])) {
                    $datearray = amr_limit($datearray, $p['month'], 'month');
                }
                /* BYWEEK NO and BYYEARDAY and BYMONTH DAY not applicable here */
                if (isset($p['BYDAY'])) {
                    $datearray = amr_expand_by_day_of_week_for_weekly($datearray, $p, $tz, $wkst);
                }
                if (isset($p['hour'])) {
                    $datearray = amr_expand($datearray, $p['hour'], 'hour', $tz);
                }
                if (isset($p['minute'])) {
                    $datearray = amr_expand($datearray, $p['minute'], 'minute', $tz);
                }
                if (isset($p['second'])) {
                    $datearray = amr_expand($datearray, $p['second'], 'second', $tz);
                }
                break;
            case 'MONTHLY':
                if (isset($p['month'])) {
                    $datearray = amr_limit($datearray, $p['month'], 'month');
                }
                /* BYWEEK NO and BYYEARDAY not applicable here */
                if (isset($p['day'])) {
                    $datearray = amr_expand($datearray, $p['day'], 'day', $tz);
                }
                if (isset($p['BYDAY']) or isset($p['NBYDAY'])) {
                    /* as per note 1  on page 44 of http://www.rfc-archive.org/getrfc.php?rfc=5545 */
                    if (isset($p['day'])) {
                        /* BYDAY limits if BYMONTH DAY is present , else a special expand for monthly */
                        $datearray = amr_limit_by_day_of_week($datearray, $p, $tz);
                    } else {
                        $datearray = amr_special_expand_by_day_of_week_and_month_note1($datearray, $p, $tz);
                    }
                }
                if (isset($p['hour'])) {
                    $datearray = amr_expand($datearray, $p['hour'], 'hour', $tz);
                }
                if (isset($p['minute'])) {
                    $datearray = amr_expand($datearray, $p['minute'], 'minute', $tz);
                }
                if (isset($p['second'])) {
                    $datearray = amr_expand($datearray, $p['second'], 'second', $tz);
                }
                break;
            case 'YEARLY':
                if (isset($p['month'])) {
                    $datearray = amr_expand($datearray, $p['month'], 'month', $tz);
                }
                if (isset($p['BYWEEKNO'])) {
                    $datearray = amr_expand_by_weekno($datearray, $p['BYWEEKNO'], $tz);
                }
                if (isset($p['BYYEARDAY'])) {
                    $datearray = amr_expand_by_yearday($datearray, $p['BYYEARDAY'], $tz);
                }
                if (isset($p['day'])) {
                    $datearray = amr_expand($datearray, $p['day'], 'day', $tz);
                }
                if (isset($p['BYDAY'])) {
                    if (isset($p['day']) or isset($p['BYYEARDAY'])) {
                        /*Note 2:  BYDAY limits if BYMONTH DAY or BYYEARDAY  is present */
                        $datearray = amr_limit_by_day_of_week($datearray, $p['BYDAY'], $tz);
                    } else {
                        $datearray = amr_expand_by_day_of_week_for_year($datearray, $p, $tz);
                    }
                }
                //				if (isset($p['NBYDAY'])) {
                //					if (isset($p['day']) or isset($p['BYYEARDAY'])) /*Note 2:  BYDAY limits if BYMONTH DAY or BYYEARDAY  is present */
                //												$datearray = amr_limit_by_day_of_week ($datearray, $p['NBYDAY'],$tz);
                //					else 						$datearray = amr_expand_by_day_of_week_for_year ($datearray, $p,$tz);
                //				}
                if (isset($p['hour'])) {
                    $datearray = amr_expand($datearray, $p['hour'], 'hour', $tz);
                }
                if (isset($p['minute'])) {
                    $datearray = amr_expand($datearray, $p['minute'], 'minute', $tz);
                }
                if (isset($p['second'])) {
                    $datearray = amr_expand($datearray, $p['second'], 'second', $tz);
                }
                break;
        }
        $datearray = amr_sort_date_array($datearray);
        if (isset($_GET['rdebug'])) {
            echo '<br /> We have in date array: ';
            print_r($datearray);
        }
        // There will only be > 1 if there was an expanding BY:
        if (!empty($datearray) and !empty($p['BYSETPOS'])) {
            $datearray = amr_limit_by_setpos($datearray, $p['BYSETPOS']);
            if (isset($_GET['rdebug'])) {
                echo '<br />Selected after bysetpos:';
                print_r($p['BYSETPOS']);
                echo '</br>';
                print_date_array($datearray);
            }
            $datearray = amr_sort_date_array($datearray);
            /* sort again as the set position may have trashed it */
        }
        //		$num_events = count($datearray);
        //		if (isset ($_GET['cdebug'])) {echo '<br />We have '. $num_events.' events.  We want max:'.$count;	}
        //		if ($num_events > $count)  $datearray = array_slice($datearray,0, $count);
        //		if (isset ($_GET['cdebug'])) {echo '<br />Limit date array, now have :'.count($datearray);
        //			echo '<br>From  '.$astart->format('Y m d h:i').' until '.$until->format('Y m d h:i');
        //		}
        if (!empty($datearray)) {
            foreach ($datearray as $d) {
                /* create the date objects  */
                $possdate = amr_create_date_from_parts($d, $tz);
                if (is_object($possdate)) {
                    if (isset($_GET['rdebug'])) {
                        echo '<br>Possdate=' . $possdate->format('Y m d h:i:s');
                    }
                    //					if 	(($possdate <= $until) and ($possdate >= $astart)) {
                    $repeats[] = $possdate;
                    //						if (isset ($_GET['rdebug'])) echo ' - saved';
                }
            }
        }
        unset($datearray);
        /* now get next start */
        $next_start = amr_increment_datetime($next_start, $int);
        if (isset($_GET['rdebug'])) {
            echo '<hr>Next start data after incrementing = ' . $next_start->format('Y m d l h:i:s');
        }
    }
    /* end while*/
    //-----------------------------------------------------------------------
    if (isset($_GET['rdebug'])) {
        echo '<hr>Stop now..checked start against extra until <br>start=' . $next_start->format('c') . '<br>until=' . $until->format('c') . ' the extra until!';
        if ($next_start > $until) {
            echo '<br /><b>php says start > extra until </b>';
        }
    }
    if (!empty($repeats)) {
        $repeats = amr_limit_occurences($repeats, $count);
        foreach ($repeats as $i => $d) {
            /* check if it is within date limits  */
            if (isset($_GET['rdebug'])) {
                echo '<br>*** Check for this rrule - original until. ' . '<br />-------astart = ' . $astart->format('c') . '<br />original start = ' . $original_start->format('c') . '<br />instancedate = ' . $d->format('c') . '<br />originaluntil= ' . $original_until->format('c') . '<br />';
            }
            if (!($d <= $original_until and $d >= $original_start)) {
                //note these are rrule limits, not the overall limits
                unset($repeats[$i]);
                if (isset($_GET['rdebug'])) {
                    echo '<br>Event instance not within rrule limits - <b>removed</b> ' . $d->format('Y m d h:i') . '<br />';
                }
            } else {
                if (isset($_GET['rdebug'])) {
                    echo '<br>Event instance within rrule limits ' . $d->format('Y m d h:i') . '<br />';
                }
            }
        }
    }
    if (isset($_GET['rdebug'])) {
        if (empty($repeats)) {
            echo '<b>No repeats!</b><hr>';
        } else {
            echo '<b>' . count($repeats) . ' repeats before further processing, exclusions etc</b><hr>';
            foreach ($repeats as $i => $r) {
                echo '<br />' . $r->format('c');
            }
            echo '<hr/>Need use debugexc to check exclusion logic';
        }
    }
    if (empty($repeats)) {
        return null;
    }
    return $repeats;
}
Example #2
0
 function amr_list_events($events, $tid, $class, $show_views = true)
 {
     global $wp_locale, $locale, $amr_options, $amr_limits, $amr_listtype, $amr_liststyle, $amr_current_event, $amrW, $amrtotalevents, $amr_globaltz, $amr_groupings, $amr_event_columns, $change_view_allowed;
     if (ICAL_EVENTS_DEBUG) {
         echo '<br />Peak Memory So far :' . amr_memory_convert(memory_get_usage(true));
         echo '<br />Now Listing, and locale = ' . $locale . ' and list type = ' . $amr_listtype . '</h2>';
     }
     if (!defined('AMR_NL')) {
         define('AMR_NL', 'PHP_EOL');
     }
     /* we want to maybe be able to replace the table html for alternate styling - may need to  keep the li items though */
     $amrconstrainedevents = count($events);
     $html = '';
     if (in_array($amr_liststyle, array('smallcalendar', 'largecalendar', 'weekscalendar'))) {
         /* is it a calendar box we want - handle separately */
         $html = amr_events_as_calendar($amr_liststyle, $events, $tid, $class);
         return $html;
     }
     $columns = $amr_event_columns;
     // 20151018 add so we can use easily//prepare_order_and_sequence ($amr_options['listtypes'][$amr_listtype]['compprop']);
     if (!$columns) {
         return;
     } else {
         $no_cols = count($columns);
     }
     /* --- setup the html tags ---------------------------------------------- */
     $htm = amr_get_html_structure($amr_liststyle, $no_cols);
     /* -- show view options or not  ------------------------------------------*/
     if (isset($amr_limits['show_views']) and $amr_limits['show_views'] and $change_view_allowed) {
         $views = amrical_calendar_views();
     } else {
         $views = '';
     }
     /* -- show month year nav options or not  ----------------NOT IN USE - need to lift code out for reuse --------------------------*/
     $start = amr_newDateTime('now');
     if (!empty($amr_limits['start'])) {
         //$start = amr_newDateTime('now');
         //else
         $start = clone $amr_limits['start'];
     }
     $navigation = '';
     if (isset($amr_limits['show_month_nav']) and $amr_limits['show_month_nav']) {
         if (isset($amr_limits['months'])) {
             $months = $amr_limits['months'];
         } else {
             $months = 1;
         }
         //		$start    = new Datetime('now',$amr_globaltz);
         //		$start    = clone $amr_limits['start'];
         $navigation = amr_calendar_navigation($start, $months, 0, $amr_liststyle);
         // include month year dropdown	with links
         $navigation = '<div class="calendar_navigation">' . $navigation . '</div>';
     } else {
         if (isset($amr_limits['month_prev_next']) and $amr_limits['month_prev_next'] and function_exists('amr_do_month_prev_next_shortcode')) {
             $navigation .= amr_do_month_prev_next_shortcode();
         }
         if (isset($amr_limits['month_year_dropdown']) and $amr_limits['month_year_dropdown'] and function_exists('amr_month_year_navigation')) {
             $navigation .= amr_month_year_navigation($start);
         }
     }
     /* -- heading and footers code ------------------------------------------*/
     if (isset($amr_limits['headings'])) {
         $doheadings = $amr_limits['headings'];
     } else {
         $doheadings = true;
     }
     if (isset($amr_limits['pagination'])) {
         $dopagination = $amr_limits['pagination'];
     } else {
         $dopagination = true;
     }
     $headhtml = '';
     if ($doheadings) {
         $docolheading = false;
         if (ICAL_EVENTS_DEBUG) {
             echo '<br />Headings? ';
             var_dump($amr_options['listtypes'][$amr_listtype]['heading']);
         }
         foreach ($amr_options['listtypes'][$amr_listtype]['heading'] as $i => $h) {
             if (!empty($h)) {
                 $docolheading = true;
             }
         }
         if ($docolheading) {
             foreach ($columns as $i => $col) {
                 if (isset($amr_options['listtypes'][$amr_listtype]['heading'][$i])) {
                     $colhead = __($amr_options['listtypes'][$amr_listtype]['heading'][$i], 'amr-ical-events-list');
                 } else {
                     $colhead = '&nbsp;';
                 }
                 $headhtml .= amr_do_a_headercell_html($htm, $i, $colhead);
             }
             $html .= amr_do_column_header_html($htm, $i, $headhtml);
         }
     }
     /* ***** with thechange in list types, we have to rethink how we do the footers .... for tables we say the footers up front, but for others not. */
     $fhtml = '';
     if (isset($amr_options['ngiyabonga']) and $amr_options['ngiyabonga']) {
         $fhtml .= amr_ngiyabonga();
     } else {
         $fhtml .= '<!-- event calendar by anmari.com.  See it at icalevents.com -->';
     }
     if (isset($amr_limits['show_look_more']) and $amr_limits['show_look_more']) {
         $fhtml .= amr_show_look_more();
     }
     if (!empty($amr_limits) and $amrtotalevents > $amrconstrainedevents) {
         if ($dopagination and function_exists('amr_semi_paginate')) {
             $fhtml .= amr_semi_paginate();
         }
         if (function_exists('amr_ical_edit')) {
             $fhtml .= amr_add_new_event_link();
         }
     }
     $alt = false;
     /* -- body code ------------------------------------------*/
     /* ----------- check for groupings and compress these to requested groupings only */
     $groupings = amr_get_groupings_requested();
     $groupedevents = amr_assign_events_to_groupings($groupings, $events);
     // will just return if no grouping
     $html .= amr_list_events_in_groupings($htm, '', $columns, $groupedevents, $events);
     if (!empty($tid)) {
         $tid = ' id="' . $tid . '" ';
     }
     $html = (!empty($htm['box']) ? $htm['box'] . $tid . ' class="' . $class . '">' : '') . $html . $htm['boxc'] . $fhtml;
     $html = $views . AMR_NL . $navigation . AMR_NL . $html . AMR_NL;
     return $html;
 }
function amr_GET_set_start_for_nav()
{
    // gets or sets a date object to the begiinging of the curremt month, or the passed date
    if (isset($_GET['start'])) {
        $starttxt = intval($_GET['start']);
        $starttxt = substr($starttxt, 0, 4) . '-' . substr($starttxt, 4, 2) . '-' . substr($starttxt, 6, 2);
        $nstart = amr_newDateTime($starttxt);
    } else {
        $nstart = amr_newDateTime('');
        // must always set to first of month for dropdown to work
        $y = $nstart->format('Y');
        $m = $nstart->format('m');
        $nstart->setDate($y, $m, '01');
    }
    return $nstart;
}
Example #4
0
function amr_track_last_mod($date)
{
    global $amr_last_modified;
    $amr_globaltz;
    if (empty($amr_last_modified)) {
        $amr_last_modified = amr_newDateTime('0000-00-00 00:00:01');
    }
    if ($date->format('c') > $amr_last_modified->format('c')) {
        $amr_last_modified = clone $date;
    }
}
Example #5
0
function date_season($type = 'Meteorological', $D)
{
    /* Receives ($Dateobject and returns a string with the Meterological season by default*/
    /* Note that the limits must be defined on backwards order with a seemingly repeated entry at the end to catch all */
    if (!isset($D)) {
        $D = amr_newDateTime();
    }
    $Y = amr_format_date('Y', $D);
    $limits['Quarter'] = array('/12/31' => $Y . ' Q1', '/09/31' => $Y . ' Q4', '/06/30' => $Y . ' Q3', '/03/31' => $Y . ' Q2', '/01/00' => $Y . ' Q1');
    $limits['Meteorological'] = array('/12/01' => 'N. Winter, S. Summer', '/09/01' => 'N. Fall, S. Spring', '/06/01' => 'N. Summer, S. Winter', '/03/01' => 'N. Spring, S. Autumn', '/01/00' => 'N. Winter, S. Summer');
    $limits['Astronomical'] = array('/12/21' => 'N. Winter, S. Summer', '/09/23' => 'N. Fall, S. Spring', '/06/21' => 'N. Summer, S. Winter', '/03/21' => 'N. Spring, S. Autumn', '/01/00' => 'N. Winter, S. Summer');
    $limits['Traditional'] = array('/11/08' => 'N. Winter, S. Summer', '/08/06' => 'N. Fall, S. Spring', '/06/05' => 'N. Summer, S. Winter', '/02/05' => 'N. Spring, S. Autumn', '/01/00' => 'N. Winter, S. Summer');
    $limits['Zodiac'] = array('/12/22' => 'Capricorn', '/11/22' => 'Sagittarius', '/10/23' => 'Scorpio', '/09/23' => 'Libra', '/08/23' => 'Virgo', '/07/23' => 'Leo', '/06/21' => 'Cancer', '/05/21' => 'Gemini', '/04/20' => 'Taurus', '/03/21' => 'Aries', '/02/19' => 'Pisces', '/01/20' => 'Aquarius', '/01/00' => 'Capricon');
    /* get the current year */
    foreach ($limits[$type] as $key => $value) {
        /* add the current year to the limit */
        $limit = $key;
        $input = amr_format_date('/m/d', $D);
        /* if date is later than limit, then return the current value, else continue to check the next limit */
        if ($input > $limit) {
            return $value;
        }
    }
}
Example #6
0
function amr_events_as_calendar($liststyle, $events, $id, $class = '', $initial = true)
{
    /* startingpoint was wp calendar */
    global $amr_options, $amr_listtype, $amr_limits, $amrW;
    global $amr_globaltz;
    global $change_view_allowed;
    global $wpdb, $wp_locale;
    global $amr_calendar_url;
    global $amr_event_columns;
    //20151018
    $empty = '&nbsp;';
    $link = amr_get_day_link_stem();
    // get the daylink stem
    // ---  Note that if months set, then events will have started from beg of month */
    $months = 1;
    $weeks = 2;
    // as default
    if (isset($amr_limits['months'])) {
        $months = $amr_limits['months'];
        //may need later on if we are going to show multiple boxes on one page
        $weeks = 0;
    } else {
        if (isset($amr_limits['weeks'])) {
            $weeks = $amr_limits['weeks'];
            $months = 0;
        }
    }
    // testing
    //$weeks = 2;		// need weeks =2 else miss early ones
    // Let's figure out when we are
    $start = amr_newDateTime();
    $today_day = $start->format('j');
    $today_month = $start->format('m');
    $today_year = $start->format('Y');
    $start = clone $amr_limits['start'];
    $thismonth = $start->format('m');
    $thisyear = $start->format('Y');
    if (!($liststyle === 'weekscalendar')) {
        $start->setDate($thisyear, $thismonth, 1);
    } else {
        $start->setDate($thisyear, $thismonth, $start->format('j'));
    }
    // what was asked for  in url (in case using small calendar as a selector )
    if (!empty($_GET['start']) and is_numeric($_GET['start'])) {
        $selected_day = substr($_GET['start'], 6, 2);
        $selected_month = substr($_GET['start'], 4, 2);
        $selected_year = substr($_GET['start'], 0, 4);
    } else {
        $selected_day = $today_day;
        $selected_month = $today_month;
        $selected_year = $today_year;
    }
    $events = amr_check_for_multiday_events($events);
    // now have dummy multi day events added and field dummyYMD to use
    if (!($liststyle === 'weekscalendar')) {
        $bunchesofevents = amr_get_events_in_months_format($events, $months, $start);
    } else {
        $bunchesofevents = amr_get_events_in_weeks_format($events, $weeks, $start);
    }
    if ($liststyle === 'weekscalendar') {
        if (!empty($amr_options['listtypes'][$amr_listtype]['format']['Day'])) {
            $caption_format = $amr_options['listtypes'][$amr_listtype]['format']['Day'];
        } else {
            $caption_format = 'j M';
        }
    } else {
        if (!empty($amr_options['listtypes'][$amr_listtype]['format']['Month'])) {
            $caption_format = $amr_options['listtypes'][$amr_listtype]['format']['Month'];
        } else {
            $caption_format = 'F,Y';
        }
    }
    //	if ( isset($_GET['w']) ) $w = ''.intval($_GET['w']); /* what sthis for ?*/
    // week_begins = 0 stands for Sunday
    $week_begins = intval(get_option('start_of_week'));
    if ($liststyle == 'smallcalendar') {
        // for compatibility with wordpress default
        $class = ' widget_calendar ';
    }
    if (empty($class)) {
        $class = $liststyle;
    } else {
        $class = $class . ' ' . $liststyle . ' ';
    }
    if (!empty($amr_limits['show_views']) and $change_view_allowed) {
        $views = amrical_calendar_views();
    } else {
        $views = '';
    }
    $html = $views;
    $calendar_output = '';
    $multi_output = '';
    if (empty($amr_limits['show_month_nav'])) {
        $navigation = '';
        $tfoot = '';
    } else {
        $navigation = amr_calendar_navigation($start, $months, $weeks, $liststyle);
        // include month year dropdown	with links
        if ($liststyle == 'smallcalendar' and $months < 2) {
            $tfoot = '<tfoot><tr><td class="calendar_navigation" colspan="7">' . $navigation . '</td></tr></tfoot>';
        } else {
            $tfoot = '';
            $html .= '<div class="calendar_navigation">' . $navigation . '</div>';
        }
    }
    $columns = $amr_event_columns;
    // 20151018 add so we can use easily//prepare_order_and_sequence ($amr_options['listtypes'][$amr_listtype]['compprop']);
    //var_dump($columns);
    if (empty($columns)) {
        return;
    }
    // now do for each month or week-------------------------------------------------------------------------------------------------------
    if (isset($_GET['debugwks'])) {
        echo '<br />Bunches of events = ' . count($bunchesofevents) . '<br />';
    }
    foreach ($bunchesofevents as $ym => $bunchevents) {
        //also for weeks
        $thismonth = substr($ym, 4, 2);
        $thisyear = substr($ym, 0, 4);
        if (!($liststyle === 'weekscalendar')) {
            $start->setDate($thisyear, $thismonth, 1);
        } else {
            $start->setDate($thisyear, $thismonth, $start->format('j'));
        }
        if (ICAL_EVENTS_DEBUG) {
            echo '<br />' . $ym;
        }
        if (isset($_GET['debugwks'])) {
            echo '<br />weeks = ' . $weeks . ' ' . $start->format('c');
        }
        $dayheaders = '<tr class="dayheaders">' . amr_calendar_colheaders($liststyle, $start) . '</tr>';
        if ($liststyle === 'weekscalendar') {
            // then cannot use thead as can only have one thead per table- else is data
            $calendar_caption = apply_filters('amr_events_table_caption', amr_weeks_caption($start));
            if (!empty($calendar_caption)) {
                $calendar_caption = '<tr class="caption"><th colspan="7">' . $calendar_caption . '</th></tr>';
            }
            $calendar_output .= '<tbody>';
            $calendar_output .= $dayheaders;
        } else {
            $calendar_caption = apply_filters('amr_events_table_caption', amr_date_i18n($caption_format, $start));
            if (!empty($calendar_caption)) {
                $calendar_caption = '<caption>' . $calendar_caption . '</caption>';
            }
            $calendar_output .= '<table ' . $id . ' class="' . $class . '" >' . $calendar_caption;
            $calendar_output .= '<thead>' . $dayheaders . '</thead>' . $tfoot . '<tbody>';
        }
        // Get days with events
        $titles = array();
        $eventsfortheday = array();
        $dayswithevents = array();
        if (ICAL_EVENTS_DEBUG) {
            echo '<br />Bunch events count=' . count($bunchevents);
        }
        if (!empty($bunchevents)) {
            // NOTE SINGULAR month
            // get the titles and events for each day
            $bunchevents = amr_sort_by_two_cols('dummytime', 'MultiDay', $bunchevents);
            //20140805
            foreach ($bunchevents as $event) {
                // convert eventdate to display timezone now for day of month assignment, other dates will be
                // converted to display timezone at display time.
                if (empty($event['EventDate'])) {
                    continue;
                }
                // if no date, we cannot display anywhere
                if (isset($event['dummyYMD'])) {
                    //$month = $event['EventDate']->format('m');
                    //$month = substr($event['dummyYMD'],4,2); // quicker?
                    //if (isset($_GET['debugwks'])) {echo '<br />Do we need monts=thismonth check?'.$month.' '.$thismonth;}
                    //if ($month == $thismonth) {
                    // this allows to have agenda with more months and events cached
                    //$day = $event['dummyYMD']->format('j');
                    $day = ltrim(substr($event['dummyYMD'], 6, 2), '0');
                    // quicker?
                    $dayswithevents[] = $day;
                    // replace with listtype format
                    $title = '';
                    if (isset($event['SUMMARY'])) {
                        $title = $event['SUMMARY'];
                    }
                    if (is_array($title)) {
                        $title = implode($title);
                    }
                    $titles[$day][] = $title;
                    //
                    $eventsfortheday[$day][] = $event;
                    //	}
                }
            }
        }
        if (isset($dayswithevents)) {
            $dayswithevents = array_unique($dayswithevents);
        }
        if (!($liststyle === 'smallcalendar') or !function_exists('amr_events_customisable_small_calendar_daytitles')) {
            $daytitles = amr_prepare_day_titles($titles, $liststyle);
        }
        // for large hover?
        unset($titles);
        //-----------------------------------------------------------------------------------
        if (!empty($eventsfortheday)) {
            if (ICAL_EVENTS_DEBUG) {
                echo ' we have ' . count($eventsfortheday) . ' days of events';
            }
            foreach ($eventsfortheday as $day => $devents) {
                if (ICAL_EVENTS_DEBUG) {
                    echo '<br />Day =' . $day . ' with ' . count($devents) . ' events ';
                }
                $dayhtml[$day] = amr_list_one_days_events($devents, $columns);
                if (function_exists('amr_events_customisable_small_calendar_daytitles') and $liststyle === 'smallcalendar') {
                    $daytitles[$day] = amr_events_customisable_small_calendar_daytitles($devents, $columns);
                }
                //if (isset($_GET['debugwks']))  echo '<br />Day: '.$day.' '.$dayhtml[$day];
            }
        }
        unset($eventsfortheday);
        //		else echo 'EMPTY events forday';
        /* ------See how much we should pad in the beginning */
        $week = 1;
        $calendar_output .= "\n\t" . '<tr class="week week1">';
        //-----------------------------------------------------------------------------------
        if ($liststyle === 'weekscalendar') {
            //if (isset ($weeks)) {
            $day1 = $start->format('j');
            // set to start of week //The day of the month without leading zeros (1 to 31)
            //$daysinbunch = $day1+6;
            $daysinbunch = 7;
        } else {
            $pad = calendar_week_mod($start->format('w') - $week_begins);
            if (0 != $pad) {
                $calendar_output .= "\n\t\t" . '<td colspan="' . esc_attr($pad) . '" class="pad">' . $empty . '</td>';
            }
            $day1 = 1;
            $daysinbunch = $start->format('t');
            //The number of days in the given month
        }
        if (isset($_GET['debugwks'])) {
            echo '<br />Day 1= ' . $day1;
        }
        $newrow = false;
        $nextdate = new Datetime();
        //if cloning dont need tz
        $nextdate = clone $start;
        //			for ( $day = $day1; $day <= $daysinbunch; ++$day ) {
        for ($i = 1; $i <= $daysinbunch; $i += 1) {
            if (isset($_GET['debugwks'])) {
                echo '<br />i = ' . $i;
            }
            //				$calendar_output .= amr_handle_each_day ($thisyear, $thismonth, $day, $daytitles, $dayswithevents,$dayhtml);
            if (isset($newrow) && $newrow) {
                if ($week > 1) {
                    // then we need to end the previous row
                    $calendar_output .= AMR_NL . '</tr>';
                    $calendar_output .= AMR_NL . '<tr class="week week' . $week . '">' . AMR_NL;
                }
                //else echo 'new row but $week = '.$week;
            }
            $newrow = false;
            $lastinrow = '';
            // check if after this we need a new row eg if month calendar//
            //				if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) ) {
            if (6 == calendar_week_mod($nextdate->format('w') - $week_begins)) {
                $newrow = true;
                $lastinrow = ' endweek';
                $week = $week + 1;
                // helps to balance out the multi month view
            }
            /* wp code - can't we do better ? */
            //$datestring = $day.'-'.$thismonth.'-'.$thisyear; // must use hyphens for uk english dates, else it goes US
            //$dow = date('N',strtotime($datestring)); // does not like dates earlier than 1902
            $dow = $nextdate->format('N');
            $thisyear = $nextdate->format('Y');
            $thismonth = $nextdate->format('m');
            $day = $nextdate->format('j');
            $hasevents = '';
            if (!empty($amr_limits['day_links']) and $amr_limits['day_links'] and !empty($daytitles[$day])) {
                // then we have events for that day, so can link to it
                $hasevents = ' hasevents ';
                $daylink = '<a class="daylink" href="' . htmlentities(amr_get_day_link($thisyear, $thismonth, $day, $link)) . '" title="' . $daytitles[$day] . '">' . $day . '</a>';
            } else {
                $daylink = $day;
            }
            if ($day == $today_day && $thismonth == $today_month && $thisyear == $today_year) {
                $today = ' today ';
            } else {
                $today = '';
            }
            if ($day == $selected_day && $thismonth == $selected_month && $thisyear == $selected_year) {
                $selected = ' selected ';
            } else {
                $selected = '';
            }
            $calendar_output .= '<td class="day' . $dow . $today . $selected . $hasevents . $lastinrow . '">';
            if (!($liststyle === 'weekscalendar')) {
                $calendar_output .= '<div class="day">' . $daylink . '</div>';
            }
            if (!empty($dayswithevents) and in_array($day, $dayswithevents)) {
                // any posts today?
                if (isset($_GET['debugwks'])) {
                    echo '<br />Day=' . $day;
                }
                //				if (($liststyle == 'largecalendar')
                if (in_array($liststyle, array('largecalendar', 'weekscalendar')) and !empty($dayhtml[$day])) {
                    $calendar_output .= AMR_NL . $dayhtml[$day];
                }
            } else {
                $calendar_output .= $empty;
                //'&nbsp;';
            }
            $calendar_output .= '</td>';
            date_modify($nextdate, '+1 day');
        }
        // now check if we need to pad to the end of the week
        //			$pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
        $pad = 6 - calendar_week_mod($dow - $week_begins);
        if ($pad != 0 && $pad != 7) {
            $calendar_output .= "\n\t\t" . '<td class="pad" colspan="' . esc_attr($pad) . '">&nbsp;' . '</td>';
        } else {
            $week = $week - 1;
        }
        if ($months > 1 and $liststyle == 'smallcalendar') {
            // pad so that they will all line up nicely in the multiview
            for ($w = $week; $week <= 5; ++$week) {
                $calendar_output .= "\n\t" . '</tr><tr><td class="pad" colspan="7" >&nbsp;</td>' . "\n\t";
            }
        }
        if ($liststyle === 'weekscalendar') {
            $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t";
        } else {
            $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
        }
        $multi_output .= $calendar_output;
        $calendar_output = '';
        if (isset($weeks)) {
            date_modify($start, '+7 days');
        } else {
            date_modify($start, '+1 month');
        }
    }
    // for each bunch (eg month?)
    if ($liststyle === 'weekscalendar') {
        // if we are doing weekly, we want only one table so all will line up
        $multi_output = '<table ' . $id . ' class="' . $class . '" >' . $multi_output . '</table><!-- end weekly table -->';
    }
    $html .= $multi_output;
    return $html;
}
Example #7
0
function amr_convert_date_string_to_object($a)
{
    if (checkdate(substr($a, 4, 2), substr($a, 6, 2), substr($a, 0, 4))) {
        $e = amr_newDateTime($a);
    } else {
        _e('Invalid Event Date', 'amr-ical-events-list');
    }
    return $e;
}
Example #8
0
function amrical_formats($i)
{
    global $amr_options;
    ?>
<fieldset id="formats<?php 
    echo $i;
    ?>
" class="formats" >
	<h4 class="trigger"><a href="#" >
	<?php 
    _e(' Define date and time formats:', 'amr-ical-events-list');
    ?>
</a></h4>
	<div class="toggle_container"><p><em><?php 
    _e('Define the formats for the day (eg: Event date, End Date) and time (eg: Start time, End Time) fields. You can actually use any of these to display a full Date time string too. Use the Event date for event instances - the DTSTART field is the first startdate of a recurring event sequence.', 'amr-ical-events-list');
    ?>
</em></p><p><em><?php 
    _e('These are also used for the date related grouping headings (ie: will show the date in that format as a heading for that group of dates if relevant.)', 'amr-ical-events-list');
    ?>
 <?php 
    echo __('Use the standard PHP format strings: ', 'amr-ical-events-list') . '<a href="http://www.php.net/manual/en/function.date.php" target="new" title="' . __('Php manual - date datetime formats', 'amr-ical-events-list') . '" ' . '> ' . __('See php date function format strings', 'amr-ical-events-list') . '</a>' . __(' (will localise) ', 'amr-ical-events-list');
    ?>
</em></p><?php 
    if (!isset($amr_options['listtypes'][$i]['format'])) {
        echo 'No formats set';
    } else {
        $date = amr_newDateTime();
        echo '<ul>';
        foreach ($amr_options['listtypes'][$i]['format'] as $c => $v) {
            $l = str_replace(' ', '', $c) . $i;
            echo '<li><label for="' . $l . ' ">' . __($c, 'amr-ical-events-list') . '</label>';
            echo '<input type="text" size="12" id="' . $l . '" name="format[' . $i . '][' . $c . ']"';
            echo ' value="' . $v . '" /> ';
            echo amr_format_date($v, $date);
            //a* amr ***/
            echo '</li>';
        }
        echo '</ul>';
    }
    ?>
</div>
		</fieldset><?php 
    return;
}