Merge pull request #43 from nhubbard2/master

Modularize all server-side components
This commit is contained in:
Michael Teeuw 2016-01-08 11:01:16 +01:00
commit 6b30d20de6
7 changed files with 57 additions and 50 deletions

View File

@ -1,45 +0,0 @@
<?php
// Set the url of the calendar feed.
$url = $_GET['url'];
/*****************************************/
// Run the helper function with the desired URL and echo the contents.
echo get_url($url);
// Define the helper function that retrieved the data and decodes the content.
function get_url($url)
{
//user agent is very necessary, otherwise some websites like google.com wont give zipped content
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-Language: en-US,en;q=0.8rn" .
"Accept-Encoding: gzip,deflate,sdchrn" .
"Accept-Charset:UTF-8,*;q=0.5rn" .
"User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:19.0) Gecko/20100101 Firefox/19.0 FirePHP/0.4rn",
"ignore_errors" => true //Fix problems getting data
),
//Fixes problems in ssl
"ssl" => array(
"verify_peer"=>false,
"verify_peer_name"=>false
)
);
$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;
}

5
controllers/calendar.php Normal file
View File

@ -0,0 +1,5 @@
<?php
include "functions/gzip.php";
$url = $_GET["url"];
echo get_url($url);
?>

View File

@ -0,0 +1,42 @@
<?php
/*
* @function get_url
* @purpose To fetch GZipped web content.
* @author Michael Teeuw
*/
function get_url($url) {
/*
* @array
* Prepare the options that we need for our GZip request.
*/
$opts = array(
"http" => array(
"method" => "GET",
"header" => "Accept-Language: en-US,en;q=0.8rn" . "Accept-Encoding: gzip,deflate,sdchrn" . "Accept-Charset:UTF-8,*;q=0.5rn" . "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:19.0) Gecko/20100101 Firefox/19.0 FirePHP/0.4rn",
"ignore_errors" => true
),
/*
* @array
* Put a Band-Aid over some SSL issues.
*/
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false
)
);
$context = stream_context_create($opts);
$content = file_get_contents($url, false, $context);
/*
* @note 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") {
/*
* @note Now, let's begin the actual purpose of this function:
*/
$content = gzinflate(substr($content, 10, -8));
}
}
return $content;
}
?>

7
controllers/hash.php Normal file
View File

@ -0,0 +1,7 @@
<?php
echo json_encode(
array(
"gitHash" => trim(`git rev-parse HEAD`)
)
);
?>

View File

@ -1,2 +0,0 @@
<?php
echo json_encode(array('gitHash'=>trim(`git rev-parse HEAD`)));

View File

@ -11,7 +11,7 @@ var calendar = {
calendar.updateData = function (callback) { calendar.updateData = function (callback) {
new ical_parser("calendar.php" + "?url="+encodeURIComponent(config.calendar.url), function(cal) { new ical_parser("controllers/calendar.php" + "?url="+encodeURIComponent(config.calendar.url), function(cal) {
var events = cal.getEvents(); var events = cal.getEvents();
this.eventList = []; this.eventList = [];

View File

@ -10,7 +10,7 @@ version.checkVersion = function () {
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: 'githash.php', url: 'controllers/hash.php',
success: function (data) { success: function (data) {
// The githash variable is located in index.php // The githash variable is located in index.php
if (data && data.gitHash !== gitHash) { if (data && data.gitHash !== gitHash) {