예제 #1
0
 static function get_text($key)
 {
     $annotation = Annotation::from_db($key);
     if ($annotation) {
         return $annotation->text;
     }
     return '';
 }
예제 #2
0
 function time_annotation($key)
 {
     $key .= "-{$this->id}";
     $log = Annotation::from_db($key);
     if ($log) {
         return $log->time;
     } else {
         return 0;
     }
 }
예제 #3
0
파일: story.php 프로젝트: manelio/woolr
function print_external_anaylsis($link)
{
    $data = Annotation::from_db("analysis_{$link->id}");
    if ($data) {
        $objects = json_decode($data->text);
        Haanga::Load('link_external_analysis.html', compact('objects'));
    }
}
예제 #4
0
header('Content-Type: application/json; charset=utf-8');
$service = clean_input_string($_GET['s']);
switch ($service) {
    case 'tweet':
        $id = $_GET['id'];
        if (!ctype_digit($id)) {
            syslog(LOG_INFO, "Missing id {$id}");
            exit;
        }
        $url = "https://api.twitter.com/1/statuses/oembed.json?id={$id}&align=center&maxwidth=550";
        break;
    default:
        die;
}
$key = "json_cache_{$service}-{$id}";
$cache = Annotation::from_db($key);
if ($cache) {
    echo $cache->text;
    exit(0);
}
// Get the url if not cached
$cache = new Annotation($key);
$res = get_url($url);
if (!$res || !$res['content'] || $res['http_code'] != 200) {
    $cache->time = time() + 3600;
    // if it failed, cache for one hour
    $cache->text = '{}';
    // Return empty object
} else {
    $cache->time = time() + 86400 * 7;
    // 7 days in cache