Ejemplo n.º 1
0
function amr_deduceTZID($icstzid)
{
    // we have something that php didn't like, so we will try work something out
    // Not great, really should use the filter function rather
    global $amr_globaltz, $globaltzstring;
    //			$strip = array ('(',' ');
    //			$icstzid = str_replace($strip,'',$icstzid);
    $gmtend = stripos($icstzid, ')');
    /* do we have a brackedt GMT ? */
    //if (isset ($_REQUEST['tzdebug'])) {echo '<br/>Check for a bracketed gmt? = '.$gmtend.' in string '.$icstzid ; }
    if (!empty($gmtend)) {
        $icstzid = str_replace(')', '/', $icstzid);
        $icstzcities = explode('/', $icstzid);
        /* could be commas, could be slashes */
        if (isset($_REQUEST['tzdebug'])) {
            echo '<br/>strip the gmt out ';
            print_r($icstzcities);
        }
        $gmt = stripos($icstzid, 'GMT');
        /* do we have a brackedt GMT ? */
        if (!empty($gmt)) {
            unset($icstzcities[0]);
        }
        /* don't want the GMT - potentially misleading */
    } else {
        /* Maybe we have a list of cities and maybe we do not */
        $icstzcities = array();
        $temp = explode(',', $icstzid);
        /* could be commas, could be slashes */
        foreach ($temp as $temp2) {
            $temp3 = explode('/', $temp2);
            $icstzcities = array_merge($icstzcities, $temp3);
        }
    }
    foreach ($icstzcities as $i => $icscity) {
        $icstzcities[$i] = trim($icscity, ' ');
    }
    //if (isset ($_REQUEST['tzdebug'])) { echo '<br />Do we have a City? <br />';print_r($icstzcities);}
    $globalcontcity = explode('/', $globaltzstring);
    if (isset($globalcontcity[1])) {
        $globalcity = $globalcontcity[1];
    } else {
        $globalcity = $globalcontcity[0];
    }
    //			if (isset ($_REQUEST['tzdebug'])) {	echo '<hr> text = '.$text.'<br/>icstzid = '.$icstzid.' and wp tz = '.$globalcity.' <br >'; print_r($icstzcities);		}
    if (in_array($globalcity, $icstzcities)) {
        /* if one of the cities in the tzid matches ours, again we can use the matched one */
        $tzname = $globaltzstring;
    } else {
        $alltzcities = amr_get_timezone_cities();
        if (isset($alltzcities[$icstzid])) {
            /* then it is a normal php timezone we know about, so we can proceed */
            $tzname = $icstzid;
        } else {
            foreach ($icstzcities as $i => $c) {
                if (isset($alltzcities[$c])) {
                    /* try each of the cities if we have mutiple */
                    $tzname = $alltzcities[$c];
                    break;
                }
            }
            if (isset($_REQUEST['tzdebug'])) {
                echo '<br/>No match to known cities';
            }
        }
    }
    /* */
    if (!isset($tzname)) {
        /* see if we do it with GMT after all ? */
        if (isset($icstzcities[0])) {
            $tryoffset = str_replace('GMT', '', $icstzcities[0]);
            if (empty($tryoffset) or is_int($tryoffset)) {
                $tzname = amr_getTimeZone($tryoffset);
                if (isset($_REQUEST['tzdebug'])) {
                    echo '<br/>Try see if offset:' . $tryoffset . ' gave ' . $tzname;
                }
            } else {
                $tzname = amr_unknown_timezone($icstzid, $globaltzstring);
            }
        } else {
            $tzname = amr_unknown_timezone($icstzid, $globaltzstring);
        }
    }
    if (isset($_REQUEST['tzdebug'])) {
        echo '<br /><b>Timezone must be: </b> ' . $tzname . '<br />';
    }
    $tz = amr_try_timezone($tzname);
    if (!$tz) {
        $tz = $amr_globaltz;
    }
    return $tz;
}
Ejemplo n.º 2
0
function amr_set_defaults_for_datetime()
{
    global $amr_globaltz;
    global $ical_timezone;
    if ($a_tz = get_option('timezone_string') and !empty($a_tz)) {
        $amr_globaltz = timezone_open($a_tz);
        //date_default_timezone_set($a_tz);
        if (isset($_GET['tzdebug'])) {
            echo '<br />Tz string:' . $a_tz;
        }
    } else {
        if ($gmt_offset = get_option('gmt_offset') and !is_null($gmt_offset) and is_numeric($gmt_offset)) {
            $a_tz = amr_getTimeZone($gmt_offset);
            $amr_globaltz = timezone_open($a_tz);
            //date_default_timezone_set($a_tz);
            if (isset($_GET['tzdebug'])) {
                echo '<h2>Found gmt offset in wordpress options:' . $gmt_offset . '</h2>';
            }
        } else {
            if (isset($_GET['tzdebug'])) {
                echo '<h2>Using php default for timezone</h2>';
            }
            $amr_globaltz = timezone_open(date_default_timezone_get());
            // this will give UTC as wordpress  ALWAYS uses UTC
        }
    }
    if (empty($amr_globaltz)) {
        echo '<br />Error getting and setting global timezone either from wp or the default php  ';
    }
    $ical_timezone = $amr_globaltz;
    // usedin amr-events aand to save the global tz if it changes do to event timezone use
}