コード例 #1
0
ファイル: amr-ical-config.php プロジェクト: greg3560/plailly
function amr_ical_initialise()
{
    global $amr_options;
    global $amr_general;
    global $amr_components;
    global $amr_calprop;
    global $amr_colheading;
    global $amr_compprop;
    global $amr_groupings;
    global $amr_formats;
    global $amr_csize;
    global $amr_validrepeatablecomponents;
    global $amr_validrepeatableproperties;
    global $amr_wkst;
    global $amrdf;
    global $amrtf;
    global $amr_globaltz, $ical_timezone;
    // amr events uses ical_timezone
    global $utczobj;
    if (!defined('ICAL_EVENTS_DEBUG')) {
        if (isset($_GET["debug"]) and (is_user_logged_in() and current_user_can('administrator') or amr_is_trying_to_help())) {
            /* for debug and support - calendar data is public anyway, so no danger*/
            define('ICAL_EVENTS_DEBUG', true);
        } else {
            define('ICAL_EVENTS_DEBUG', false);
        }
    }
    if (ICAL_EVENTS_DEBUG) {
        echo '<h1>Debug mode</h1>';
        echo 'Other debug parameters that can be used together or separately to isolate problems: ';
        echo 'debugexc, rdebug, cdebug, tzdebug, debugall, debugq, memdebug, debugtime <br/>';
        if (!defined('AMR_ICAL_VERSION')) {
            define('AMR_ICAL_VERSION', '0');
        }
        echo '<br />key:' . AMR_ICAL_VERSION . '+' . AMR_ICAL_LIST_VERSION . '#' . PHP_VERSION . '-' . get_bloginfo('version') . '+' . get_option('blog_charset') . '+' . mb_internal_encoding();
        echo '@' . ini_get("memory_limit");
        echo ' time:' . ini_get('max_execution_time') . ' seconds';
    }
    $utczobj = timezone_open('UTC');
    /* set to empty string for concise code */
    if (!defined('AMR_NL')) {
        define('AMR_NL', "\n");
    }
    if (!defined('AMR_TB')) {
        define('AMR_TB', "\t");
    }
    define('AMR_EVENTS_CACHE_TTL', 60 * 20);
    //  20 mins
    define('ICAL_EVENTS_CACHE_TTL', 24 * 60 * 60);
    // 1 day
    define('AMR_MAX_REPEATS', 1000);
    /* if someone wants to repeat something very frequently from some time way in the past, then may need to increase this */
    $amr_ical_image_settings = get_option('amr-ical-images-to-use');
    if (empty($amr_ical_image_settings)) {
        $suffix = '_16';
    } else {
        $size = isset($amr_ical_image_settings['images_size']) ? $amr_ical_image_settings['images_size'] : '16';
        if (in_array($size, array('16', '32'))) {
            $suffix = '_' . $size;
        } else {
            $suffix = '_16';
        }
    }
    define('TIMEZONEIMAGE', 'timezone' . $suffix . '.png');
    define('MAPIMAGE', 'map' . $suffix . '.png');
    define('CALENDARIMAGE', 'calendar' . $suffix . '.png');
    define('CALENDARADDTOIMAGE', 'calendar_add' . $suffix . '.png');
    define('CALENDARADDSERIESIMAGE', 'calendar_link' . $suffix . '.png');
    define('ADDTOGOOGLEIMAGE', 'addtogoogle' . $suffix . '.png');
    define('REFRESHIMAGE', 'arrow_refresh' . $suffix . '.png');
    if (!defined('WP_PLUGIN_URL')) {
        define('WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins/');
    }
    if (!defined('WP_PLUGIN_DIR')) {
        define('WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins/');
    }
    $x = str_replace(basename(__FILE__), "", plugin_basename(__FILE__));
    $url = WP_PLUGIN_URL . '/amr-ical-events-list/';
    $dir = WP_PLUGIN_DIR . '/amr-ical-events-list/';
    define('ICALLISTPLUGINURL', $url);
    define('ICALLISTPLUGINDIR', $dir);
    define('ICALSTYLEURL', $url . 'css/icallist.css');
    define('ICALSTYLEFILE', $dir . 'css/icallist.css');
    define('ICAL_EDITSTYLEFILE', $dir . 'css/a-yours.css');
    define('ICALSTYLEPRINTURL', $url . 'css/icalprint.css');
    define('AMRICAL_ABSPATH', $url);
    define('IMAGES_LOCATION', AMRICAL_ABSPATH . 'images/');
    $uploads = wp_upload_dir();
    //define('ICAL_EVENTS_CACHE_LOCATION',path_join( ABSPATH, get_option('upload_path')));  /* do what wordpress does otherwise weird behaviour here - some folks already seem to have the abs path there. */
    define('ICAL_EVENTS_CACHE_LOCATION', $uploads['basedir']);
    define('ICAL_EVENTS_CSS_DIR', ICAL_EVENTS_CACHE_LOCATION . '/css/');
    /* where to store custom css so does not get overwritten */
    define('ICAL_EVENTS_CSS_URL', $uploads['baseurl'] . '/css/');
    /* where to store custom css so does not get overwritten */
    define('ICAL_EVENTS_CACHE_DEFAULT_EXTENSION', 'ics');
    $amr_wkst = ical_get_weekstart();
    $amr_validrepeatablecomponents = array('VEVENT', 'VTODO', 'VJOURNAL', 'VFREEBUSY', 'VTIMEZONE');
    $amr_validrepeatableproperties = array('ATTACH', 'ATTENDEE', 'CATEGORIES', 'COMMENT', 'CONTACT', 'DESCRIPTION', 'DAYLIGHT', 'EXDATE', 'EXRULE', 'FREEBUSY', 'RDATE', 'RSTATUS', 'RELATED', 'RESOURCES', 'RRULE', 'SUMMARY', 'STATUS', 'STANDARD', 'TZOFFSETTO', 'TZOFFSETFROM', 'URL', 'XPARAM', 'X-PROP');
    $amr_validrepeatableproperties = apply_filters('amr_valid_repeatable_properties', $amr_validrepeatableproperties);
    $dateformat = str_replace(' ', '\\&\\n\\b\\s\\p\\;', get_option('date_format'));
    $amr_formats = array('Time' => str_replace(' ', '\\&\\n\\b\\s\\p\\;', get_option('time_format')), 'Day' => 'D, ' . $dateformat, 'Month' => 'F,Y', 'Year' => 'Y', 'Week' => '\\W\\e\\e\\k W', 'DateTime' => $dateformat . ' ' . get_option('time_format'));
    /* used for admin field sizes */
    $amr_csize = array('Column' => '2', 'Order' => '2', 'Before' => '40', 'After' => '40', 'ColHeading' => '10');
    /* the default setup shows what the default display option is */
    $amr_admin_col_head = array('Column' => __('Column', 'amr-ical-events-list'), 'Order' => __('Order', 'amr-ical-events-list'), 'Before' => __('Before', 'amr-ical-events-list'), 'After' => __('After', 'amr-ical-events-list'));
}
コード例 #2
0
function amr_get_events_in_weeks_format($events, $weeks, $start)
{
    // should be using dummmyYMD?
    global $amr_globaltz;
    $wkst = ical_get_weekstart();
    // get the wp start of week
    if (isset($_GET['debugwks'])) {
        echo '<br />Separate ' . count($events) . ' events into weeks for ' . $weeks . ' weeks using wkst: ' . $wkst;
    }
    $weeksofevents = array();
    // prepare the months array so we show a calendar even if no events
    $dummydate = new Datetime();
    //if cloning dont need tz
    $dummydate = clone $start;
    $dummydate = amr_get_human_start_of_week($dummydate, $wkst);
    for ($i = 0; $i < $weeks; $i++) {
        $weekbeginning = $dummydate->format('Ymj');
        //numerical so do not need amr_date_format
        if (empty($firstweekbeginning)) {
            $firstweekbeginning = $weekbeginning;
        }
        if (isset($_GET['debugwks'])) {
            echo '<br />weekbeginning' . $weekbeginning;
        }
        $weeksofevents[$weekbeginning] = array();
        date_modify($dummydate, '+7 days');
    }
    // assign events to the box of their year and month
    if (!empty($events)) {
        foreach ($events as $event) {
            if (!empty($event['dummyYMD'])) {
                // ahh need the dummy date, not the Event Date
                date_date_set($dummydate, substr($event['dummyYMD'], 0, 4), substr($event['dummyYMD'], 4, 2), substr($event['dummyYMD'], 6, 2));
                if (isset($_GET['debugwks'])) {
                    echo '<br />date:' . $event['dummyYMD'];
                }
                $dummydate = amr_get_human_start_of_week($dummydate, $wkst);
                $weekbeginning = $dummydate->format('Ymj');
                if (isset($_GET['debugwks'])) {
                    echo '<br />start of week:' . $weekbeginning;
                }
                if (isset($weeksofevents[$weekbeginning])) {
                    $weeksofevents[$weekbeginning][] = $event;
                } else {
                    // the week beginning is not in our current set - might be a multi day that started the previous week or even earlier
                    if (isset($_GET['debugwks'])) {
                        echo '<br />No week begin of ' . $weekbeginning . ' for ? ' . $dummydate->format('c') . ' ' . $event['SUMMARY'];
                        //$weeksofevents[$weekbeginning][] = $event;  // assign our multi day to first week
                        //var_dump($event);
                    }
                }
            } else {
                if (isset($_GET['debugwks'])) {
                    echo '<br />event with no dummy date';
                    var_dump($event);
                }
            }
        }
    }
    if (isset($_GET['debugwks'])) {
        echo '<br />Have dates for:' . count($weeksofevents) . ' weeks';
        foreach ($weeksofevents as $i => $bunchevents) {
            echo '<br />' . $i . ' ' . count($bunchevents);
            foreach ($bunchevents as $i => $e) {
                echo '<br />&nbsp;&nbsp;' . $e['EventDate']->format('Ymd');
                //numerical so do not need amr_date_format
            }
        }
    }
    return $weeksofevents;
}