protected function handle_request() { global $wp; $query = $wp->query_vars['query']; $access_token = self::haveAccess($wp->query_vars['access_token']); $plugin_data = get_plugin_data(plugin_dir_path(__FILE__) . '../watchtower.php'); $plugin_version = $plugin_data['Version']; switch (true) { case $query === 'test' && $access_token: $this->send_response(array('status' => '200 OK')); break; case $query === 'auto_update' && $access_token: wp_update_plugins(); $this->send_response(array('status' => '200 OK', 'client_version' => $plugin_version)); break; case $query === 'core' && $access_token: $this->send_response(array('status' => '200 OK', 'client_version' => $plugin_version, 'plugins' => WPCore_Model::getStat())); break; case $query === 'plugins' && $access_token: $this->send_response(array('status' => '200 OK', 'client_version' => $plugin_version, 'plugins' => Plugin_Model::getStat())); break; case $query === 'themes' && $access_token: $this->send_response(array('status' => '200 OK', 'client_version' => $plugin_version, 'plugins' => Theme_Model::getStat())); break; case $query === 'all' && $access_token: $this->send_response(array('status' => '200 OK', 'client_version' => $plugin_version, 'core' => WPCore_Model::getStat(), 'plugins' => Plugin_Model::getStat(), 'themes' => Theme_Model::getStat())); break; default: $this->send_response('Error', 'Invalid request or access token'); break; } }
emDirect("./plugin.php?plugin={$plugin}&setting=1"); } } else { emDirect("./plugin.php?plugin={$plugin}&error=1"); } } //安装插件 if ($action == 'install') { include View::getView('header'); require_once View::getView('plugin_install'); include View::getView('footer'); View::output(); } //删除插件 if ($action == 'del') { $Plugin_Model = new Plugin_Model(); $Plugin_Model->inactivePlugin($plugin); $pludir = preg_replace("/^([^\\/]+)\\/.*/", "\$1", $plugin); if (true === emDeleteFile('../content/plugins/' . $pludir)) { $CACHE->updateCache('options'); emDirect("./plugin.php?activate_del=1"); } else { emDirect("./plugin.php?error_a=1"); } } //上传zip插件 if ($action == 'upload_zip') { $zipfile = isset($_FILES['pluzip']) ? $_FILES['pluzip'] : ''; if ($zipfile['error'] == 4) { emDirect("./plugin.php?action=install&error_d=1"); }
/** * 替换SQL中的中文名,执行SQL,返回执行结果;返回结果为: * 正常:array('isError'=> false, 'data' =>'执行结果,二维数组'); * 出错:array('isError' => true, * 'errorMsg' => '出错信息', * 'data' => '解析后的执行SQL'); * * @param string $pCnName 项目中文名 * @param string $sql SQL * @return array 当出错时isError为true,data中执行结果; * 否则isError为false,data中为执行SQL, * data中为错误提示信息。 * */ public function execSQL($pCnName, $sql) { $result = $this->execCodeSection($pCnName, $sql); if (is_string($result)) { return array('isError' => true, 'errorMsg' => $result, 'data' => $sql); } $sql = $result['code']; $tName = $result['tCnName']; $dModel = $this->getDModel(); $model = new Plugin_Model($this->getDModel(), get_gvar($pCnName . $tName, $this->getTnameKey())); return $model->query($sql, true); }