public function get_file() { $url = in($_POST['file']); $ext = explode('.', $url); $ext = end($ext); if (function_exists('zip_open')) { $url = substr($url, 0, -strlen($ext)) . $ext; } else { $url = substr($url, 0, -strlen($ext)) . 'gz'; } $file = @Http::doGet($url, 60); if (empty($file)) { if (function_exists('zip_open')) { $this->msg('采用正常模式获取更新文件失败,请稍后再试!', 0); } else { $this->msg('采用备用模式获取更新文件失败,请稍后再试!', 0); } } $cache_dir = __ROOTDIR__ . '/data/cache/'; if (!is_dir($cache_dir)) { @mkdir($cache_dir, 0777, true); } if (!@file_put_contents($cache_dir . $this->config['ver_date'] . '.' . $ext, $file)) { $this->msg('/data/cache/"目录下文件保存失败,请确认此目录存在或有读写权限!'); exit; } $this->msg('/data/cache/' . $this->config['ver_date'] . '.' . $ext, 1); }
public function __construct() { parent::__construct(); $this->mobile = in($_POST['mobile']); $this->mobile_code = in($_POST['mobile_code']); $this->sms_code = in($_POST['sms_code']); }
/** * User command for betting on the coin toss game in the casino * * @param bet int The amount of money to bet on the coin toss game * @return Array * * @note * If the player bets within ~1% of the maximum bet, they will receive a reward item */ public function bet() { $player = new Player(self_char_id()); $bet = intval(in('bet')); $negative = $bet < 0; set_setting('bet', max(0, $bet)); $pageParts = ['reminder-max-bet']; if ($negative) { $pageParts = ['result-cheat']; $player->vo->health = subtractHealth($player->id(), 99); } else { if ($bet > $player->vo->gold) { $pageParts = ['result-no-gold']; } else { if ($bet > 0 && $bet <= self::MAX_BET) { if (rand(0, 1) === 1) { $pageParts = ['result-win']; $player->vo->gold = add_gold($player->id(), $bet); if ($bet >= round(self::MAX_BET * 0.99)) { // within about 1% of the max bet & you win, you get a reward item. add_item($player->id(), self::REWARD, 1); } } else { $player->vo->gold = subtract_gold($player->id(), $bet); $pageParts = ['result-lose']; } } } } // End of not cheating check. return $this->render(['pageParts' => $pageParts, 'player' => $player, 'bet' => get_setting('bet')]); }
public function content($dir = null, $page = null) { if (is_numeric($dir)) { $aid = intval($dir); } else { $dir = in($dir); } if (!empty($aid)) { $_GET['aid'] = $aid; $_GET['page'] = intval($page); module('content')->index(); return; } if (!empty($dir)) { $lang = model('lang')->langid(); $content = $this->model->field('A.aid,A.urltitle,B.lang')->table('content', 'A')->add_table('category', 'B', 'A.cid=B.cid')->where('A.urltitle="' . $dir . '" AND B.lang=' . $lang)->find(); if (empty($content)) { $this->error404(); return; } else { $_GET['aid'] = $content['aid']; $_GET['page'] = intval($page); module('content')->index(); return; } } $this->error404(); return; }
/** * Take in a url parameter of work and try to convert it to gold */ public function requestWork() { // Initialize variables to pass to the template. $work_multiplier = self::WORK_MULTIPLIER; $worked = positive_int(in('worked')); // No negative work. $earned_gold = null; $not_enough_energy = null; $recommended_to_work = $worked; $is_logged_in = is_logged_in(); $char_id = self_char_id(); $char = new Player($char_id); $turns = $char->turns(); $gold = $char->gold(); if ($worked > $turns) { $not_enough_energy = true; } else { $earned_gold = $worked * $work_multiplier; // calc amount worked $char->set_gold($gold + $earned_gold); $char->set_turns($turns - $worked); $char->save(); } $gold_display = number_format($char->gold()); $parts = ['recommended_to_work' => $recommended_to_work, 'work_multiplier' => $work_multiplier, 'is_logged_in' => $is_logged_in, 'gold_display' => $gold_display, 'worked' => $worked, 'earned_gold' => number_format($earned_gold), 'not_enough_energy' => $not_enough_energy]; return $this->render($parts); }
/** * Action to request class change form AND execute class change * * @todo split form request and execute into separate funcs * @return ViewSpec */ public function changeClass() { if (is_logged_in()) { $player = new Player(self_char_id()); $classes = $this->classesInfo(); $requestedIdentity = in('requested_identity'); $currentClass = $player->identity; $showMonks = false; $parts = []; if (isset($classes[$requestedIdentity])) { $error = $this->classChangeReqs($player, self::CLASS_CHANGE_COST); if ($currentClass != $requestedIdentity && !$error) { $error = $this->changePlayerClass($player, $requestedIdentity); } $currentClass = $player->identity; if (!$error) { $parts['pageParts'] = ['success-class-change']; $showMonks = true; } else { $parts['error'] = $error; } } else { $parts['pageParts'] = ['form-class-change']; } unset($classes[$currentClass]); $parts['classOptions'] = $classes; return $this->render($parts, $player, $showMonks); } else { return $this->accessDenied(); } }
public function testInputWithinEnvironment() { $id = in('id'); $this->assertEquals(7, $id); $default_result = in('doesnotexist', 5); $this->assertEquals(5, $default_result); }
public function process() { if (!$this->response instanceof ActionResponse) { return; } $products = $this->response->get('products'); $ids = array(); foreach ($products as $key => $product) { $ids[$product['ID']] = !empty($product['parentID']) ? $product['parentID'] : $product['ID']; } if (!$ids) { return; } $f = select(in(f('ProductImage.productID'), array_values($ids)), new LikeCond(f('ProductImage.title'), '%Virtual Mirror%')); $hasMirror = array(); foreach (ActiveRecordModel::getRecordSetArray('ProductImage', $f) as $mirror) { $hasMirror[$mirror['productID']] = true; } foreach ($ids as $realID => $parentID) { if (!empty($hasMirror[$parentID])) { $hasMirror[$realID] = true; } } foreach ($products as $key => $product) { if ($hasMirror[$product['ID']]) { $products[$key]['hasMirror'] = true; } } $this->response->set('hasMirror', $hasMirror); $this->response->set('products', $products); }
/** * User command for betting on the coin toss game in the casino * * @param bet int The amount of money to bet on the coin toss game * @return Array * * @note * If the player bets within ~1% of the maximum bet, they will receive a * reward item */ public function bet() { $player = Player::find(self_char_id()); $bet = intval(in('bet')); $pageParts = ['reminder-max-bet']; if ($bet < 0) { $pageParts = ['result-cheat']; $player->harm(self::CHEAT_DMG); } else { if ($bet > $player->gold) { $pageParts = ['result-no-gold']; } else { if ($bet > 0 && $bet <= self::MAX_BET) { if (rand(0, 1) === 1) { $pageParts = ['result-win']; $player->set_gold($player->gold + $bet); if ($bet >= round(self::MAX_BET * 0.99)) { // within about 1% of the max bet & you win, you get a reward item. add_item($player->id(), self::REWARD, 1); } } else { $player->set_gold($player->gold - $bet); $pageParts = ['result-lose']; } } } } $player->save(); return $this->render(['pageParts' => $pageParts, 'player' => $player]); }
function chia($tu1, $mau1, $tu2, $mau2) { // xu ly chia $tu3 = $tu1 * $mau2; $mau3 = $mau1 * $tu2; in($tu1, $mau1, $tu2, $mau2, $tu3, $mau3); }
function in($t, $arrays = true, $keyEncode = '') { if (is_array($t)) { if ($arrays) { $b = array(); foreach ($t as $i) { $n = array(); foreach ($i as $k => $v) { $n[chgName($k)] = $v; } $n['_' . chgName($keyEncode)] = in($i[$keyEncode]); array_push($b, $n); } return $b; } else { $n = array(); foreach ($t as $k => $v) { $n[chgName($k)] = $v; } $n['_' . chgName($keyEncode)] = in($t[$keyEncode]); return $n; } } else { $encode = base64_encode(time()); return base64_encode(str_pad(strlen($encode), 3, '0', STR_PAD_LEFT) . $encode . base64_encode($t)); } }
public function index() { $type = $_GET['type']; if (!empty($type)) { $url_type = '-type-' . $type; if ($type == 'no') { $where = 'type is Null'; } else { $where = 'type="' . $type . '"'; } } $ext = intval($_GET['ext']); if (!empty($ext)) { $ext1 = '"jpg","gif","jpeg","bmp","png"'; $ext2 = '"flv","wmv","wma","mp3","jpeg","mp4","3gp","avi","swf","mkv"'; $ext3 = '"doc","xsl","wps","docx","xslx","ppt","pptx"'; $ext4 = '"zip","rar","7z"'; $ext5 = $ext1 . ',' . $ext2 . ',' . $ext3 . ',' . $ext4; $url_ext = '-ext-' . $ext; switch ($ext) { case 1: $where = 'ext in(' . $ext1 . ')'; break; case 2: $where = 'ext in(' . $ext2 . ')'; break; case 3: $where = 'ext in(' . $ext3 . ')'; break; case 4: $where = 'ext in(' . $ext4 . ')'; break; case 5: $where = 'ext not in(' . $ext5 . ')'; break; } } $search = in(urldecode($_GET['search'])); if (!empty($search)) { $where = ' title like "%' . $search . '%"'; $url_search = '-search-' . $search; } //分页处理 //分页信息 $url = __URL__ . '/index/page-{page}' . $url_type . $url_ext . $url_search; //分页基准网址 $listRows = 50; $page = new Page(); $cur_page = $page->getCurPage($url); $limit_start = ($cur_page - 1) * $listRows; $limit = $limit_start . ',' . $listRows; //内容列表 $this->list = model('upload')->file_list($where, $limit); //统计总内容数量 $count = model('upload')->count($where); $this->assign('page', $this->page($url, $count, $listRows)); $this->module_list = model('upload')->module_list(); $this->show(); }
/** * Take an enemy off a pc's list. */ public function deleteEnemy() { $remove_enemy = in('remove_enemy', null, 'toInt'); if (is_numeric($remove_enemy) && $remove_enemy != 0) { $this->removeEnemyFromPlayer(self_char_id(), $remove_enemy); } return new RedirectResponse('enemies.php'); }
function check_for_debug() { $dbg = in('debug'); if ($dbg == 'on') { $_COOKIE['debug'] == true; } elseif ($dbg == 'off') { $_COOKIE['debug'] == false; } }
/** * Display that list of public quests! */ public function index() { $quest_id = in('quest_id'); $quest_accepted = in('quest_accepted'); $quests = format_quests(get_quests()); $title = 'Quests'; $tpl = 'quests.tpl'; $parts = ['quests' => $quests]; return ['template' => $tpl, 'title' => $title, 'parts' => $parts, 'options' => null]; }
protected function postProcessData() { $addresses = array(); foreach ($this->data as $key => $shipment) { $id = !empty($shipment['shippingAddressID']) ? $shipment['shippingAddressID'] : $shipment['CustomerOrder']['shippingAddressID']; $addresses[$id] = $key; } foreach (ActiveRecordModel::getRecordSetArray('UserAddress', select(in('UserAddress.ID', array_keys($addresses)))) as $address) { $this->data[$addresses[$address['ID']]]['ShippingAddress'] = $address; } }
public function getLocale() { $languages = $this->agent->languages(); if (!$languages) { return null; } $locales = array_values(array_filter($languages, function ($l) { return strlen($l) == 2; })); return in($locales, 0); }
/** * Get the slugs and parameters values. */ private function parse_slugs($give = false, $self_use = false) { $url_part = $_SERVER['REQUEST_URI']; $path = parse_url($url_part, PHP_URL_PATH); $slugs = explode('/', trim($path, '/')); $selfTarget = whichever(in('selfTarget'), $self_use); $link_back = whichever(in('link_back'), $selfTarget ? 'inventory' : null); $item_in = $slugs[2]; $in_target = isset($slugs[3]) ? $slugs[3] : null; return ['link_back' => $link_back, 'item_in' => $item_in, 'in_target' => $in_target, 'selfTarget' => $selfTarget, 'give' => $give]; }
public function process() { $this->application->getRouter()->removeAutoAppendVariable('currency'); if (!$this->response instanceof ActionResponse) { return; } $products = $this->response->get('products'); $parents = $variations = array(); foreach ($products as $key => $product) { if ($product['parentID']) { $parents[$product['parentID']] = true; $variations[$key] = $product; } } if (!$parents) { return; } $loadedParents = array(); foreach (ActiveRecordModel::getRecordSetArray('Product', select(in(f('Product.ID'), array_keys($parents))), array('Manufacturer', 'DefaultImage' => 'ProductImage', 'Category')) as $parent) { $loadedParents[$parent['ID']] = $parent; } ProductSpecification::loadSpecificationForRecordSetArray($loadedParents); ProductPrice::loadPricesForRecordSetArray($loadedParents); foreach ($products as $key => $product) { if ($product['parentID']) { $parent = $loadedParents[$product['parentID']]; foreach ($parent as $field => $value) { if (empty($product[$field])) { $product[$field] = $parent[$field]; } } foreach (array('price_USD', 'price_CAD', 'formattedPrice', 'formattedListPrice') as $field) { if (isset($parent[$field])) { $product[$field] = $parent[$field]; } } ///var_dump($parent);exit; $products[$key] = $product; } } ProductSet::loadVariationsForProductArray($variations); foreach ($variations as $key => $variation) { $vars = array(); foreach ($variation['variationTypes'] as $type) { $vars[] = $type['name_lang']; } if ($vars) { $products[$key]['name_lang'] .= ' (' . implode(' / ', $vars) . ')'; } } $this->response->set('products', $products); }
/** * 安装处理 */ public function importing() { $data = in($_POST); $configDb = $data['DB']; if (strpos($configDb['DB_HOST'], ':') !== false) { $db_host = explode(':', $configDb['DB_HOST']); $configDb['DB_HOST'] = $db_host[0]; $configDb['DB_PORT'] = $db_host[1]; } else { $configDb['DB_PORT'] = '3306'; } $link = @mysql_connect($configDb['DB_HOST'] . ':' . $configDb['DB_PORT'], $configDb['DB_USER'], $configDb['DB_PWD']); if (!$link) { $this->msg('数据库连接失败,请检查连接信息是否正确!', false); } $mysqlInfo = @mysql_get_server_info($link); if ($mysqlInfo < '5.0') { $this->msg('MySql版本低于5.0,无法继续安装!', false); } $status = @mysql_select_db($configDb['DB_NAME'], $link); if (!$status) { $this->msg('数据库' . $configDb['DB_NAME'] . '不存在,请检查数据库!', false); } if ($data['agree'] != 1) { $this->msg('请认真阅读并同意安装协议!', false); } //设置表前缀 $dbPrefix = $configDb['DB_PREFIX'] ? $configDb['DB_PREFIX'] : ''; $dbData = ROOT_PATH . 'data/install.sql'; $sqlData = Install::mysql($dbData, 'ecs_', $dbPrefix); //更新安装sql文件 try { #todo #############################################因为ECShop的order_info表没有表前缀, 所以去掉$dbPrefix #$if (!model('Install')->get_column($configDb, $dbPrefix . 'order_info', 'mobile_pay')) { if (!model('Install')->get_column($configDb, 'order_info', 'mobile_pay')) { $sqlData[] = "ALTER TABLE `" . $dbPrefix . "order_info` ADD COLUMN `mobile_order` int(1) UNSIGNED NOT NULL DEFAULT 0,ADD COLUMN `mobile_pay` int(1) UNSIGNED NOT NULL DEFAULT 0 AFTER `discount`;"; } } catch (Exception $e) { return $e->getMessage(); } $sqlData[] = "UPDATE `" . $dbPrefix . "touch_shop_config` SET `value` = '" . str_replace('/mobile', '', __URL__) . "' where `code`='shop_url';"; if (!model('Install')->runSql($configDb, $sqlData)) { $this->msg('数据导入失败,请检查后手动删除数据库重新安装!', false); } model('Install')->filter_column($configDb, 'touch_shop_config'); //配置shop_config $this->set_config($configDb); $this->msg('安装成功!', true); }
/** * Display standard login page. */ public function index() { $logged_out = in('logged_out'); // Logout page redirected to this one, so display the message. $login_error_message = in('error'); // Error to display after unsuccessful login and redirection. $stored_username = isset($_COOKIE['username']) ? $_COOKIE['username'] : null; $referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; $is_logged_in = is_logged_in(); if ($is_logged_in) { return new RedirectResponse(WEB_ROOT); } $parts = ['is_logged_in' => $is_logged_in, 'login_error_message' => $login_error_message, 'logged_out' => $logged_out, 'referrer' => $referrer, 'stored_username' => $stored_username]; return $this->render('Login', $parts); }
/** * 数据过滤函数 * @param string|array $data 待过滤的字符串或字符串数组 * @param boolean $force 为true时忽略get_magic_quotes_gpc * @return mixed */ function in($data, $force = false) { if (is_string($data)) { $data = trim(htmlspecialchars($data)); // 防止被挂马,跨站攻击 if (($force == true) || (!get_magic_quotes_gpc())) { $data = addslashes($data); // 防止sql注入 } return $data; } else if (is_array($data)) { foreach ($data as $key => $value) { $data[$key] = in($value, $force); } return $data; } else { return $data; } }
public function info() { $tag = urldecode($_GET['tag']); if (!is_utf8($tag)) { $tag = auto_charset($tag, 'gbk', 'utf-8'); } $tag = msubstr(in($tag), 0, 20); //查找tag信息 if (!empty($tag)) { $info = model('tags')->tag_info($tag); } else { $this->error404(); } if (empty($info)) { $this->error404(); } //更新点击计数 model('tags')->views_content($info['id'], $info['click']); /*hook*/ $this->plus_hook('tags', 'index', $info); /*hook end*/ //分页处理 $url = __INDEX__ . '/tags-' . $tag . '/pages-{page}.html'; $listrows = $this->config['TPL_TAGS_PAGE']; if (empty($listrows)) { $listrows = 20; } $limit = $this->pagelimit($url, $listrows); $nav = array(0 => array('name' => 'TAG', 'url' => __INDEX__ . '/tags/index'), 1 => array('name' => $tag, 'url' => __INDEX__ . '/tags-' . $tag . '/')); //MEDIA信息 $this->common = model('pageinfo')->media($info['name'] . ' - TAGS', $tag); //内容列表 $loop = model('tags')->tag_list($info['id'], $limit); //统计总内容数量 $count = model('tags')->tag_count($info['id']); //分页处理 $this->page = $this->page($url, $count, $listrows); //获取上一页代码 $this->prepage = $this->page($url, $count, $listrows, '', 1); //获取下一页代码 $this->nextpage = $this->page($url, $count, $listrows, '', 2); $this->assign('loop', $loop); $this->assign('nav', $nav); $this->assign('info', $info); $this->display($this->config['TPL_TAGS']); }
/** * Pull & display the chats and a chat send if logged in **/ public function index() { // Initialize variables to pass to the template. $field_size = self::FIELD_SIZE; $target = $_SERVER['PHP_SELF']; $all_chats_count = $this->getChatCount(); $view_all = in('view_all'); $error = in('error'); $chatlength = in('chatlength', self::DEFAULT_LIMIT, 'toInt'); $chatlength = min(3000, max(30, $chatlength)); // Min 30, max 3000 // Output section. $chats = $this->getChats($view_all ? null : $chatlength); // Limit by chatlength unless a request to view all came in. $more_chats_to_see = rco($chats) < $all_chats_count ? true : null; $parts = ['field_size' => $field_size, 'target' => $target, 'chats' => $chats, 'error' => $error, 'more_chats_to_see' => $more_chats_to_see]; return $this->render($parts); }
/** * Command for current user to purchase a quantity of a specific item * * @param quantity int The quantity of the item to purchase * @param item string The identity of the item to purchase * @return Array */ public function buy() { $in_quantity = in('quantity'); $in_item = in('item'); $gold = get_gold($this->sessionData['char_id']); $current_item_cost = 0; $no_funny_business = false; // Pull the item info from the database $item_costs = $this->itemForSaleCosts(); $item = getItemByID(item_id_from_display_name($in_item)); $quantity = whichever(positive_int($in_quantity), 1); $item_text = null; if ($item instanceof Item) { $item_text = $quantity > 1 ? $item->getPluralName() : $item->getName(); $purchaseOrder = new PurchaseOrder(); // Determine the quantity from input or as a fallback, default of 1. $purchaseOrder->quantity = $quantity; $purchaseOrder->item = $item; $potential_cost = isset($item_costs[$purchaseOrder->item->identity()]['item_cost']) ? $item_costs[$purchaseOrder->item->identity()]['item_cost'] : null; $current_item_cost = first_value($potential_cost, 0); $current_item_cost = $current_item_cost * $purchaseOrder->quantity; if (!$this->sessionData['char_id'] || !$purchaseOrder->item || $purchaseOrder->quantity < 1) { $no_funny_business = true; } else { if ($gold >= $current_item_cost) { // Has enough gold. try { add_item($this->sessionData['char_id'], $purchaseOrder->item->identity(), $purchaseOrder->quantity); subtract_gold($this->sessionData['char_id'], $current_item_cost); } catch (\Exception $e) { $invalid_item = $e->getMessage(); error_log('Invalid Item attempted :' . $invalid_item); $no_funny_business = true; } } } } else { $no_funny_business = true; } $parts = array('current_item_cost' => $current_item_cost, 'quantity' => $quantity, 'item_text' => $item_text, 'no_funny_business' => $no_funny_business, 'view_part' => 'buy'); return $this->render($parts); }
public function edit($data) { $dir = __ROOTDIR__ . '/lang/' . in($data['lang']); $info = $this->info($data['id']); if (!is_dir($dir)) { if (!@mkdir($dir, 0777)) { return false; } @copy_dir(__ROOTDIR__ . '/lang/zh', $dir); } else { if (!@copy_dir(__ROOTDIR__ . '/lang/' . $info['lang'], $dir)) { return false; } } if (is_dir($dir)) { @del_dir(__ROOTDIR__ . '/lang/' . $info['lang']); } $condition['id'] = intval($data['id']); return $this->model->table('lang')->data($data)->where($condition)->update(); }
public function index() { $where_url = ''; $order = 'A.id desc'; $sequence = intval($_GET['sequence']); if ($sequence == 1) { $where_url .= 'sequence-1-'; $order = ' A.click desc '; } if ($sequence == 2) { $where_url .= 'sequence-2-'; $order = ' A.click asc '; } if (isset($_GET['cid'])) { $cid = intval($_GET['cid']); if ($cid) { $where_url .= 'cid-' . $cid . '-'; $where = ' AND A.cid=' . $cid; } else { $where_url .= 'cid-0-'; $where = ' AND (A.cid=0 OR A.cid is null)'; } } $search = in(urldecode($_GET['search'])); if (!empty($search)) { $where_url .= 'cid-' . urlencode($search) . '-'; $where = ' AND A.name like "%' . $search . '%"'; } //分页信息 $url = __URL__ . '/index/' . $where_url . 'page-{page}.html'; //分页基准网址 $listRows = 50; $limit = $this->pagelimit($url, $listRows); //内容列表 $this->list = model('tags')->tag_list($where, $limit, $order); //统计总内容数量 $count = model('tags')->count($where); $this->assign('page', $this->page($url, $count, $listRows)); $this->category_list = model('tags')->tag_category(); $this->show(); }
/** * Determine if value A is contained in value B. * * Usage example: * {$values = [a, b, c]} * {if a|in:$values} # true * {if x|in:$values} # false * ... * {$value = "Hello World"} * {if "Hello"|in:$value} # true * {if "Goodbye"|in:$value} # false */ function in($val_a, $val_b = null) { if (is_scalar($val_a)) { if (is_array($val_b)) { return in_array($val_a, $val_b); } else { if ($val_a && is_scalar($val_b)) { return strpos($val_b, $val_a) !== false; } } } else { if (is_array($val_a)) { foreach ($val_a as $k => $v) { if (!in($v, $val_b)) { return false; } return true; } } } return; }
public function upInfo() { $state = $this->in_get('state', None, 2, 'True'); $wx_data = base64_decode($state); $con['p_id'] = $this->in_cookie('pId', None, 1, 'True'); // 获取用户订单信息 $wx_data_arr = explode('@@', $wx_data); $room = in($wx_data_arr[0]); $phone = in($wx_data_arr[1]); $msg = Check::rule(array(check::mobile($phone), '手机电话号码格式不对')); if ($msg != 1) { $this->alert('您的手机号码不正确'); } $data['addr'] = $room; $data['phone'] = $phone; $res = $this->model->table($this->config['info_person'])->data($data)->where($con)->update(); if ($res) { $this->alert('个人信息更新成功', __ROOT__ . '/person'); } else { $this->alert('服务器暂时出了点小差'); } }
/** * Determine which function to call to get the json for. **/ function nw_json($type, $dirty_jsoncallback) { $jsoncallback = $dirty_jsoncallback; $jsoncallback = !preg_match('/[^a-z_0-9]/i', $dirty_jsoncallback) ? $dirty_jsoncallback : null; // Reject if non alphanumeric and _ chars if (!$jsoncallback) { header('Content-Type: application/json; charset=utf8'); return json_encode(false); } $res = false; // Whitelist of valid callbacks. $valid_type_map = array('player' => 'json_player', 'latest_event' => 'json_latest_event', 'chats' => 'json_chats', 'latest_message' => 'json_latest_message', 'index' => 'json_index', 'latest_chat_id' => 'json_latest_chat_id', 'inventory' => 'json_inventory', 'new_chats' => 'json_new_chats', 'send_chat' => 'json_send_chat', 'char_search' => 'json_char_search'); $res = null; $data = in('data'); if (isset($valid_type_map[$type])) { if ($type == 'send_chat') { $res = $jsoncallback . '(' . json_send_chat(in('msg')) . ')'; } else { if ($type == 'new_chats') { $chat_since = in('since', null); $chat_limit = in('chat_limit', 100); $res = $jsoncallback . '(' . json_new_chats($chat_since, $chat_limit) . ')'; } elseif ($type == 'chats') { $chat_limit = in('chat_limit', 20); $res = $jsoncallback . '(' . json_chats($chat_limit) . ')'; } elseif ($type == 'char_search') { $res = $jsoncallback . '(' . json_char_search(in('term'), in('limit')) . ')'; } elseif (!empty($data)) { // If data param is present, pass data to the function $res = $jsoncallback . '(' . $valid_type_map[$type]($data) . ')'; } else { // No data present, just call the function with no arguments. $res = $jsoncallback . '(' . $valid_type_map[$type]() . ')'; } } } return $res; }