Exemplo n.º 1
0
function process_jsondb_url($req_url)
{
    //http://db.appgame.com/databases/db_name/table_name/12345678.json
    preg_match('#^((https?://[\\S]+)/databases/[\\S]+/[\\S]+/)[\\d]+\\.json$#i', $req_url, $matches);
    if ($matches == null) {
        return false;
    }
    $data_url = $matches[0];
    $schema_url = $matches[1] . 'schema.json';
    $http_prefix = $matches[2];
    $schema = object_read($schema_url);
    $data = object_read($data_url);
    if (empty($schema) || empty($data)) {
        return false;
    }
    list($ob_title, $ob_desc, $ob_image) = get_onebox_data($schema, $data);
    if (@$ob_image[0] === '/') {
        $ob_image = $http_prefix . $ob_image;
    }
    $res_obj = merge_fields($data);
    $utime = format_time(@$res_obj['TIME']);
    $ctime = @$res_obj['CREATE'];
    if (empty($ctime)) {
        $ctime = $utime;
    } else {
        $ctime = format_time($ctime);
    }
    $res = array();
    $res['onebox'] = 'jsondb';
    $res['provider_name'] = '任玩堂';
    $res['provider_url'] = 'http://www.appgame.com/';
    $res['favicon_url'] = 'http://www.appgame.com/favicon.ico';
    $res['ori_url'] = $data_url;
    $res['title'] = $ob_title;
    $res['image'] = $ob_image;
    $res['ID'] = intval($res_obj['ID']);
    $res['update_time'] = $utime;
    $res['create_time'] = $ctime;
    $res['description'] = strip_tags(trim($ob_desc));
    return $res;
}
Exemplo n.º 2
0
function onebox_object($schema, $data_file, $data = null)
{
    $data || ($data = object_read($data_file));
    $http_prefix = 'http://' . $_SERVER['HTTP_HOST'];
    list($ob_title, $ob_desc, $ob_image) = get_onebox_data($schema, $data);
    if (strlen($ob_image) > 1) {
        if ($ob_image[0] === '/') {
            $ob_image = $http_prefix . $ob_image;
        }
    }
    $res_obj = merge_fields($data);
    $ob_time = @$res_obj['TIME'];
    if ($ob_time) {
        $ob_time = format_time($ob_time);
    }
    $ob_ctime = @$res_obj['CREATE'];
    if ($ob_ctime) {
        $ob_ctime = format_time($ob_ctime);
    }
    $file_uri = substr($data_file, strlen($_SERVER['DOCUMENT_ROOT']));
    $file_uri = preg_replace('/\\/' . $_SERVER['HTTP_HOST'] . '/i', '', $file_uri);
    $file_uri = $http_prefix . $file_uri;
    $result = array();
    $result['title'] = $ob_title;
    $result['desc'] = strip_tags($ob_desc);
    $result['image'] = $ob_image;
    $result['url'] = $file_uri;
    $result['id'] = intval($res_obj['ID']);
    $result['time'] = $ob_time;
    $result['ctime'] = $ob_ctime;
    return $result;
}