Beispiel #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;
}
Beispiel #2
0
    jsonp_nocache_exit(array('status' => 'ok', 'count' => count($outpu_logos), 'items' => $outpu_logos));
}
if ($check_what === 'values') {
    list($db, $table, $field) = null_exit($req, 'db', 'table', 'field');
    $excepts = isset($req['except']) ? $req['except'] : array();
    $filters = isset($req['filters']) ? $req['filters'] : array();
    $table_root = table_root($db, $table);
    $res = array();
    foreach (glob("{$table_root}/*") as $file) {
        if (is_dir($file)) {
            continue;
        }
        if (!preg_match('~/(\\d+)\\.json$~', $file, $matches)) {
            continue;
        }
        $data_obj = merge_fields(object_read($file));
        if (empty($data_obj)) {
            continue;
        }
        $values = isset($data_obj[$field]) ? $data_obj[$field] : null;
        if (empty($values)) {
            continue;
        }
        if (count(array_intersect($excepts, $values))) {
            continue;
        }
        if (count($filters)) {
            $filter_source = '';
            array_walk_recursive($data_obj, 'walk_cb', $filter_source);
            $is_matched_all = true;
            foreach ($filters as $filter) {
Beispiel #3
0
function objects_read($db_name, $table_name, $with_id = false)
{
    $table_root = table_root($db_name, $table_name);
    $items = array();
    foreach (glob("{$table_root}/*.json") as $file) {
        if (is_dir($file)) {
            continue;
        }
        if (!preg_match('~/(\\d+)\\.json$~', $file, $matches)) {
            continue;
        }
        $item_id = $matches[1];
        $data_obj = object_read($file);
        if (empty($data_obj)) {
            continue;
        }
        $merge_items = merge_fields($data_obj);
        if (!$with_id) {
            unset($merge_items['ID']);
        }
        unset($merge_items['CREATE']);
        unset($merge_items['TIME']);
        $items[] = $merge_items;
    }
    return $items;
}