Example #1
0
function delegate($action)
{
    //cleanCache();
    $ds = dataSetName($_GET);
    $data = loadFromCache($ds);
    if ($data) {
        echo $data;
        exit(0);
    }
    switch ($action) {
        //Twitter
        case 'topTweets':
            $data = topTweets();
            break;
            //Google Analytics
        //Google Analytics
        case 'chart':
            $data = getChart();
            break;
            //Events
        //Events
        case 'events':
            $data = getEvents();
            break;
            //Statistics
        //Statistics
        case 'stats':
            $data = getStatistics();
            break;
            //Social badge
        //Social badge
        case 'social':
            $data = generateSocialBadge();
            break;
    }
    if (!empty($data)) {
        $val = storeInCache($ds, output($data));
        if (!$val) {
        }
    }
    echo output($data);
    exit(0);
}
Example #2
0
<?php

$GLOBALS['cacheDir'] = dirname(__FILE__) . DIRECTORY_SEPARATOR . '.cache';
// 从浏览器转发过来的 proxy 请求,$_SERVER['REQUEST_URI'] 是原始的目标网址
$url = $_SERVER['REQUEST_URI'];
$req_headers = getAllHeaders();
list($resp_headers, $resp_body) = loadFromCache($url);
if (empty($resp_body)) {
    list($resp_headers, $resp_body) = doAgent(str_replace('-min.js', '.js', $url), $req_headers);
    if (empty($resp_body)) {
        list($resp_headers, $resp_body) = doAgent($url, $req_headers);
    }
    if (!empty($resp_body)) {
        saveToCache($url, $resp_headers, $resp_body);
    }
}
foreach ($resp_headers as $resp_header) {
    $tokens = explode(':', $resp_header);
    $whitelist = array('content-type', 'last-modified');
    if (in_array(strtolower($tokens[0]), $whitelist)) {
        header($resp_header);
    }
}
echo $resp_body;
function convUrlToFilename($url)
{
    $fnHead = $GLOBALS['cacheDir'] . DIRECTORY_SEPARATOR . md5($url);
    $fnBody = $fnHead . '.';
    preg_match('/^.*(\\.\\w{1,4}).*$/', $url, $matches);
    if (!empty($matches[1])) {
        $fnBody = $fnHead . $matches[1];
Example #3
0
// Deutsch = 'de' in templates - for WU it is 'DL'
if ($apiUrlpart[3] == 'DA') {
    $apiUrlpart[3] = 'DK';
}
// Danish  = 'da' in templates - for WU it is 'DK'
$apiUrlpart[5] = $userLocation;
$weatherApiUrl = '';
for ($i = 0; $i < count($apiUrlpart); $i++) {
    $weatherApiUrl .= $apiUrlpart[$i];
}
#----------------------------------------------------------------------------------------------
if (!wu_makeRequest()) {
    // load xml from url and process
    $errors = '<h3>load from WU failed, we try with twice as old cached data <h3>' . PHP_EOL;
    $cacheTime = $cacheTime * 2;
    $returnArray = loadFromCache($cacheFile);
    // load from cache returns data only when its data is valid
    if (!empty($returnArray)) {
        // if data is in cache and valid
        ws_message('<!-- module wuforecast3.php (' . __LINE__ . '): ' . $errors . ' -->');
        return $returnArray;
        //      return data to calling program
    }
    // eo valid data
    echo $errors . PHP_EOL;
    echo '<h3>  no data loaded </h3>' . PHP_EOL;
    // if something went wrong.
    echo '<h3>  program halted </h3>' . PHP_EOL;
    $returnArray = false;
    return;
}
Example #4
0
function APIcache($url, $params)
{
    $ds = APIdsName($url, $params);
    if (checkCache($ds)) {
        return loadFromCache($ds);
    }
    return null;
}