Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding cached_programme.php, which can cache a url
need to specify the url in a config variable or something.
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
require_once 'Cache/Lite.php'; | ||
$options = array( | ||
'cacheDir' => sys_get_temp_dir().'/', | ||
'lifeTime' => 3600 | ||
); | ||
$Cache_Lite = new Cache_Lite($options); | ||
|
||
|
||
function getcached( $url ) | ||
{ | ||
global $Cache_Lite; | ||
$id = base64_encode($url); | ||
if ( ! ($data = $Cache_Lite->get($id)) ) { | ||
//shell_exec("echo 'cacheing {$url}' >> /tmp/pad.log"); | ||
$data = file_get_contents($url); | ||
$extra_head = <<<EOFSTR | ||
<head> | ||
<title>PADDAN</title> | ||
<link rel="stylesheet" href="http://hacknight.se/hacknight.css" content-type="text/css"> | ||
<link href="http://fonts.googleapis.com/css?family=Cabin+Sketch:bold" rel="stylesheet" type="text/css"> | ||
<link href="http://fonts.googleapis.com/css?family=Nunito" rel="stylesheet" type="text/css"> | ||
<link href="http://fonts.googleapis.com/css?family=Waiting+for+the+Sunrise" rel="stylesheet" type="text/css"> | ||
EOFSTR; | ||
if ( ! empty($data) ) { | ||
$data = str_replace('<head>', $extra_head, $data); | ||
$data = str_replace('<body>','<body><div id="wrapper"><div class="column" style="width:100%"><div class="inner">',$data); | ||
$data = str_replace('</body>','</div></div></div></body>',$data); | ||
} else { | ||
$data = 'unable to fetch url'; | ||
} | ||
$r = $Cache_Lite->save($data, $id); | ||
} | ||
return $data; | ||
} | ||
|
||
function on_get( $params = array() ) | ||
{ | ||
//@todo fix this as a config variable or something! | ||
$url = 'http://a.pad.url'; | ||
} | ||
|
||
$content = getcached($url); | ||
|
||
return $content; | ||
} | ||
|
||
echo on_get($_GET); |