예제 #1
0
function remote_filemtime($url, $recurse = 0)
{
    // We hate infinite loops!
    if (++$recurse > 5) {
        return 0;
    }
    // Caching the remote mtime is a Really Good Idea.
    static $remote_files = array();
    if (isset($remote_files[$url])) {
        return $remote_files[$url];
    }
    $uri = parse_url($url);
    $uri['proto'] = isset($uri['proto']) && $uri['proto'] == 'https' ? 'ssl://' : '';
    $uri['port'] = isset($uri['port']) ? $uri['port'] : 80;
    $uri['path'] = isset($uri['path']) ? $uri['path'] : '/';
    $uri['query'] = isset($uri['query']) ? '?' . $uri['query'] : '';
    $path = $uri['path'] . $uri['query'];
    $auth = isset($uri['user']) || isset($uri['pass']) ? 'Authentication: Basic ' . base64_encode(@$uri['user'] . ':' . @$uri['pass']) . "\r\n" : '';
    $handle = @fsockopen($uri['proto'] . $uri['host'], $uri['port']);
    if (!$handle) {
        $remote_files[$url] = 0;
        return 0;
    }
    fputs($handle, "HEAD {$path} HTTP/1.1\r\nHost: {$uri['host']}\r\n{$auth}Connection: close\r\n\r\n");
    $headers = array();
    while (!feof($handle)) {
        $line = trim(fgets($handle, 1024));
        if (empty($line)) {
            break;
        }
        $headers[] = $line;
    }
    fclose($handle);
    $result = 0;
    array_shift($headers);
    foreach ($headers as $header) {
        list($key, $value) = explode(':', $header, 2);
        $value = trim($value);
        switch (strtolower(trim($key))) {
            case 'location':
                // Redirect
                $result = remote_filemtime(resolve_path($url, $value), $recurse);
                break;
            case 'last-modified':
                // Got it!
                $result = strtotime($value);
                break;
        }
        if ($result) {
            break;
        }
    }
    $remote_files[$url] = $result;
    return $result;
}
예제 #2
0
if ($parse_file) {
    $overlap_array = array();
    $uid_counter = 0;
}
$calnumber = 1;
foreach ($cal_filelist as $cal_key => $filename) {
    // Find the real name of the calendar.
    $actual_calname = getCalendarName($filename);
    if ($parse_file) {
        // Let's see if we're doing a webcal
        if (substr($filename, 0, 7) == 'http://' || substr($filename, 0, 8) == 'https://' || substr($filename, 0, 9) == 'webcal://') {
            $cal_webcalPrefix = str_replace(array('http://', 'https://'), 'webcal://', $filename);
            $cal_httpPrefix = str_replace(array('webcal://', 'https://'), 'http://', $filename);
            $cal_httpsPrefix = str_replace(array('http://', 'webcal://'), 'https://', $filename);
            $master_array['-4'][$calnumber]['webcal'] = 'yes';
            $actual_mtime = remote_filemtime($cal_httpPrefix);
            /*
             * We want to copy the remote calendar to a local temporary file,
             * because the current parser will read it twice:
             * - Once to get the timezone information
             * - And again to collect the remaining data
             * See: http://phpicalendar.net/forums/viewtopic.php?f=45&t=4140#p14451
             */
            $filename = tempnam(sys_get_temp_dir(), 'ICS');
            if (copy($cal_httpPrefix, $filename) === FALSE) {
                exit(error($lang['l_copy_error'], $cal_httpPrefix));
            }
        } else {
            $actual_mtime = filemtime($filename);
        }
        include BASE . 'functions/parse/parse_tzs.php';