mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 03:39:55 +00:00
Decoding using gzinflate.
This commit is contained in:
parent
ab16a3c2dd
commit
460cb40f56
47
calendar.php
47
calendar.php
@ -3,20 +3,37 @@
|
|||||||
// Set the url of the calendar feed.
|
// Set the url of the calendar feed.
|
||||||
$url = 'https://p01-calendarws.icloud.com/ca/subscribe/1/n6x7Farxpt7m9S8bHg1TGArSj7J6kanm_2KEoJPL5YIAk3y70FpRo4GyWwO-6QfHSY5mXtHcRGVxYZUf7U3HPDOTG5x0qYnno1Zr_VuKH2M';
|
$url = 'https://p01-calendarws.icloud.com/ca/subscribe/1/n6x7Farxpt7m9S8bHg1TGArSj7J6kanm_2KEoJPL5YIAk3y70FpRo4GyWwO-6QfHSY5mXtHcRGVxYZUf7U3HPDOTG5x0qYnno1Zr_VuKH2M';
|
||||||
|
|
||||||
// Initialize the curl request.
|
/*****************************************/
|
||||||
$ch = curl_init();
|
|
||||||
|
|
||||||
// Set the CURL url.
|
// Run the helper function with the desired URL and echo the contents.
|
||||||
curl_setopt ($ch, CURLOPT_URL, $url);
|
echo get_url($url);
|
||||||
|
|
||||||
// Make sure redirects are followed.
|
// Define the helper function that retrieved the data and decodes the content.
|
||||||
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
|
function get_url($url)
|
||||||
|
{
|
||||||
// Decode the response. Apple seems to use a encoded feed since the end of November 2014.
|
//user agent is very necessary, otherwise some websites like google.com wont give zipped content
|
||||||
curl_setopt ($ch, CURLOPT_ENCODING, true);
|
$opts = array(
|
||||||
|
'http'=>array(
|
||||||
// Execute the request and echo the response.
|
'method'=>"GET",
|
||||||
echo curl_exec($ch);
|
'header'=>"Accept-Language: en-US,en;q=0.8rn" .
|
||||||
|
"Accept-Encoding: gzip,deflate,sdchrn" .
|
||||||
// Close the CURL request.
|
"Accept-Charset:UTF-8,*;q=0.5rn" .
|
||||||
curl_close($ch);
|
"User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:19.0) Gecko/20100101 Firefox/19.0 FirePHP/0.4rn"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$context = stream_context_create($opts);
|
||||||
|
$content = file_get_contents($url ,false,$context);
|
||||||
|
|
||||||
|
//If http response header mentions that content is gzipped, then uncompress it
|
||||||
|
foreach($http_response_header as $c => $h)
|
||||||
|
{
|
||||||
|
if(stristr($h, 'content-encoding') and stristr($h, 'gzip'))
|
||||||
|
{
|
||||||
|
//Now lets uncompress the compressed data
|
||||||
|
$content = gzinflate( substr($content,10,-8) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user