Esempio 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;
}
Esempio n. 2
0
function combobox_to_checkbox_exit($req)
{
    $db_name = @$req['db_name'];
    $table_name = @$req['table_name'];
    $field = @$req['field'];
    $seperator = @$req['seperator'];
    if (all_empty(array($db_name, $table_name, $field, $seperator))) {
        jsonp_nocache_exit(array('status' => 'error', 'error' => 'command parameter error.'));
    }
    $data_path = table_root($db_name, $table_name);
    $schema = object_read("{$data_path}/schema.json");
    $fields = $schema['fields'];
    $group_name = null;
    $field_type = null;
    foreach ($fields as $group => $items) {
        foreach ($items as $name => $value) {
            if ($name === $field) {
                $group_name = $group;
                $field_type = $value;
                break 2;
            }
        }
    }
    if (all_empty(array($group_name, $field_type))) {
        jsonp_nocache_exit(array('status' => 'error', 'error' => 'command parameter field name error.'));
    }
    if ($field_type !== 'jqxComboBox') {
        jsonp_nocache_exit(array('status' => 'error', 'error' => 'the target field not a combobox.'));
    }
    $schema['fields'][$group_name][$field] = 'jqxCheckBox';
    object_save("{$data_path}/schema.json", $schema);
    foreach (glob("{$data_path}/*.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;
        }
        $combo_str = @$data_obj[$group_name][$field];
        if (empty($combo_str)) {
            continue;
        }
        $check_arr = explode($seperator, $combo_str);
        $data_obj[$group_name][$field] = $check_arr;
        object_save($file, $data_obj);
    }
    $counter = refresh_listview($db_name, $table_name);
    jsonp_nocache_exit(array('status' => 'ok', 'counter' => $counter));
}
Esempio n. 3
0
<?php

require_once '../../admin/functions.php';
define('AUTO_FIELD_LIST', 'auto-field-list');
define('AUTO_FIELD_CAPVIEW', 'auto-field-capview');
$req = get_param();
$db_name = @$req['db_name'];
$db_name || ($db_name = 'default');
$table_name = @$req['table_name'];
$table_name || ($table_name = 'default');
$list_caption = @$req['caption'];
$list_item = @$req['caption'];
$map_key = mapper_key(@$req['mapper']);
if (!api_valid($db_name, $table_name, @$req['apikey'])) {
    jsonp_nocache_exit(array('status' => 'error', 'error' => 'api key error'));
}
if (empty($map_key)) {
    jsonp_nocache_exit(array('status' => 'error', 'error' => 'not mapper in parameter'));
}
$table_root = table_root($db_name, $table_name);
$schema = object_read("{$table_root}/schema.json");
$mapper = object_read("{$table_root}/mapper.json");
Esempio n. 4
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) {
Esempio n. 5
0
        jsonp_nocache_exit(array('status' => 'error', 'error' => 'not mapper in parameter'));
    }
    $is_new_data = true;
    do {
        if (empty($mapper)) {
            break;
        }
        $map_val = @$mapper[$map_key];
        if (empty($map_val)) {
            break;
        }
        $map_file = "{$table_root}/{$map_val}.json";
        if (!file_exists($map_file)) {
            break;
        }
        $ori_data = object_read($map_file);
        if (empty($ori_data)) {
            break;
        }
        if (!set_data_id($data, $map_val)) {
            jsonp_nocache_exit(array('status' => 'error', 'error' => 'no id field'));
        }
        $is_new_data = false;
    } while (false);
    if ($is_new_data) {
        $output = create_new_data($db_name, $table_name, $data);
    } else {
        $output = update_current_data($db_name, $table_name, $data);
    }
    jsonp_nocache_exit($output);
}
Esempio n. 6
0
function wh_event($db, $table, $event, $data = null)
{
    $table_root = table_root($db, $table);
    $db_schema = object_read(dirname($table_root) . '/schema.json');
    $db_hooks = @$db_schema['caption']['hooks'];
    !empty($db_hooks) or $db_hooks = array();
    $table_schema = object_read("{$table_root}/schema.json");
    $table_hooks = @$table_schema['caption']['hooks'];
    !empty($table_hooks) or $table_hooks = array();
    $hooks = array_values(array_merge($db_hooks, $table_hooks));
    if (empty($hooks)) {
        return false;
    }
    if (empty($data)) {
        $data = array();
    }
    if (!is_array($data)) {
        $data = array($data);
    }
    $wh_data = array();
    $wh_data['domain'] = db_domain();
    $wh_data['db'] = $db;
    $wh_data['table'] = $table;
    $wh_data['items'] = $data;
    $wh_data['event'] = $event;
    $wh_data['hooks'] = $hooks;
    queue_in('webhook', array($wh_data));
    if (function_exists('wh_checkpoint')) {
        wh_checkpoint();
    }
    return true;
}
Esempio n. 7
0
            $onebox_url_routes[] = [$group_name, $field_name];
        }
    }
}
$counter_changed = 0;
$counter_constant = 0;
$counter_all = 0;
foreach (glob("{$table_path}/*.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;
    }
    $counter_file_changed = 0;
    $counter_all++;
    echo '<h2>' . $file . '</h2>';
    foreach ($onebox_url_routes as $route) {
        $oneboxs = @$data_obj[$route[0]][$route[1]];
        if (empty($oneboxs)) {
            continue;
        }
        $new_oneboxs = array();
        foreach ($oneboxs as $onebox) {
            $url = $onebox['url'];
            if (empty($url)) {
Esempio n. 8
0
function get_listview_column($db_name, $table_name, $field_name)
{
    $table_root = table_root($db_name, $table_name);
    $schema = object_read("{$table_root}/schema.json");
    $listview_data = object_read("{$table_root}/listview.json");
    $id_index = array_search($field_name, $schema['listview']);
    $rep_list = array();
    foreach ($listview_data as $subitem) {
        $id_cmp = $subitem[$id_index];
        if (empty($id_cmp)) {
            continue;
        }
        if (is_array($id_cmp)) {
            foreach ($id_cmp as $item) {
                if (!in_array($item, $rep_list)) {
                    $rep_list[] = $item;
                }
            }
        } else {
            if (!in_array($id_cmp, $rep_list)) {
                $rep_list[] = $id_cmp;
            }
        }
    }
    return $rep_list;
}
Esempio n. 9
0
<?php

require_once '../../admin/functions.php';
$req = get_param();
$db_name = @$req['db_name'];
$table_name = @$req['table_name'];
$db_name || ($db_name = 'default');
$table_name || ($table_name = 'default');
$map_key = @$req['name'];
$direct = @$req['direct'];
list($map_val, $data_file, $data_url) = mapper_value_exit($db_name, $table_name, $map_key);
if ($direct === 'true') {
    jsonp_nocache_exit(object_read($data_file));
}
if ($direct === 'false') {
    jsonp_nocache_exit(array('status' => 'ok', 'ID' => $map_val, 'data_file' => $data_url));
}
header("Location: {$data_url}");
Esempio n. 10
0
    $page_size = $setting['page_size'];
    $list_file = CONFIG_PATH . '/' . $setting['list'];
    $list_data = async_read($list_file);
    $total = count($list_data);
    $max_pages = $total / $page_size + 1;
    $req_page = max($req_page, 1);
    $req_page = min($req_page, $max_pages);
    if ($order !== 'desc') {
        $list_data = array_reverse($list_data);
        $order = 'asc';
    }
    $res_list = array_slice($list_data, ($req_page - 1) * $page_size, $page_size);
    $results = array();
    $md5_src = '';
    foreach ($res_list as $uni_name) {
        $results[] = object_read(UPLOAD_PATH . "/{$uni_name}.json");
        $md5_src .= $uni_name;
    }
    jsonp_nocache_exit(array('status' => 'ok', 'total' => $total, 'order' => $order, 'page' => $req_page, 'pages' => $max_pages, 'count' => count($results), 'digest' => md5($md5_src), 'results' => $results));
}
if ($cmd !== 'write') {
    jsonp_nocache_exit(array('status' => 'error', 'error' => 'not valid cmd'));
}
//接下来是处理上传文件
$origin_dir = UPLOAD_PATH . "/ori";
$preview_dir = UPLOAD_PATH . "/prev";
$thumbnail_dir = UPLOAD_PATH . "/thumb";
$uploaed_tmpname = @$_FILES["fileToUpload"]["tmp_name"];
$uploaed_name = @$_FILES["fileToUpload"]["name"];
$upload_size = @$_FILES["fileToUpload"]["size"];
$upload_type = pathinfo($uploaed_name, PATHINFO_EXTENSION);
Esempio n. 11
0
function edit_table_exit($req)
{
    $filename = dbs_path() . "/{$req['db_name']}";
    if (!file_exists($filename)) {
        jsonp_nocache_exit(array('status' => 'error', 'error' => 'The request database not found.', 'ori_cmd' => $req));
    }
    $old_name = "{$filename}/{$req['ori_name']}";
    if (!file_exists($old_name)) {
        jsonp_nocache_exit(array('status' => 'error', 'error' => 'The request table not found.', 'ori_cmd' => $req));
    }
    $filename = "{$filename}/{$req['name']}";
    if ($req['ori_name'] !== $req['name']) {
        rename($old_name, $filename);
    }
    touch($filename);
    $filename = "{$filename}/schema.json";
    $schema = object_read($filename);
    $caption = array();
    $caption['title'] = @$req['title'];
    $caption['content'] = @$req['content'];
    $caption['image'] = @$req['image'];
    $caption['key'] = @$req['key'];
    $caption['hooks'] = isset($req['hooks']) ? array_values($req['hooks']) : array();
    $schema['caption'] = $caption;
    object_save($filename, $schema);
    jsonp_nocache_exit(array('status' => 'ok'));
}