function json_file($file_name) { do { list($database, $table) = get_selected_db(); $full_name = dbs_path() . "/{$database}/{$table}/{$file_name}"; if (!file_exists($full_name)) { break; } $json_res = file_get_contents($full_name); if (empty($json_res)) { break; } return json_decode($json_res, true); } while (false); return array(); }
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')); }