zaiykcns

2024-08-29
zaiykcns

lt;?php


/**


* diy.seowhy.com 小程序接口文档


* 仅支持 php 5.3 以上


* 版权保护,如需遥,请访问 https://diy.seowhy.com。


* @author seowhy


* 微信:seowhy07


* 电话:189028466619


* 需要目录权限:appimage,appdata


*/




if (!empty($_GET[#39;debug#39;])) { ini_set(“display_errors“, 1); error_reporting(E_ALL ~E_NOTICE); } else { ini_set(“display_errors“, 0); error_reporting(0); } if (version_compare(PHP_VERSION, #39;5.3.0#39;, #39;lt;#39;)) { showMessage(#39;当前PHP版本为#39;.phpversion().#39;,小于5.3,请升遥php版本5.3以上#39;, 1003); } if (!class_exists(#39;PDO#39;, false)) { showMessage(“空间不支持pdo连接“, 1003); } $_GET[#39;a#39;] = parseAction($_GET[#39;a#39;]); $from = $_GET[#39;from#39;]; if ($from != #39;x#39;) { showMessage(“接口文件工作正常“); } define(#39;APP_ID#39;, #39;1349#39;);define(#39;TOKEN#39;, #39;zaiykcnsizdxlbxbaighmagwzmtidrkvkehqfiszpfmmlxjyrwturxvgubougzmx#39;);define(#39;VERSION#39;, #39;1.0.1#39;); define(#39;APP_PATH#39;, __DIR__ . #39;/#39;); define(#39;DATA_PATH#39;, APP_PATH.#39;seowhy-neves/#39;); define(#39;BACKAPI#39;, #39;https://diy.seowhy.com/api/#39;); $checkToken = $_GET[#39;token#39;]; $checkTime = $_GET[#39;_t#39;]; $check = $_GET[#39;check#39;]; $action = $_GET[#39;a#39;]; if (md5(APP_ID . TOKEN . $checkTime) != $checkToken !$check !in_array($action, array( #39;config#39;, #39;sitemap#39;, #39;mapping#39;, ))) { res(1001, “访问受限“); } $client = new appClient(); $client->run(); class appClient { private static $errmap = array( #39;0#39; => #39;错误要了命了 #39;, #39;1#39; => #39;致命运行时错误#39;, #39;2#39; => #39;运行时警告 #39;, #39;4#39; => #39;编译语法错误 #39;, #39;8#39; => #39;运行时通知 #39;, #39;16#39; => #39;初始化致命错误#39;, #39;32#39; => #39;初始化警告 #39;, #39;64#39; => #39;致命编译错误 #39;, #39;128#39;=> #39;编译时警告 #39;, #39;256#39;=> #39;用户自定义错误#39;, #39;512#39;=> #39;用户自定义警告#39;, #39;1024#39;=> #39;用户自定义通知#39;, #39;2048#39;=> #39;PHP兼容遥建议 #39;, #39;4096#39;=> #39;可捕捉致命错误#39;, #39;8192#39;=> #39;运行时通知 #39;, #39;16384#39;=>#39;用户产生的警告#39;, #39;30719#39;=>#39;其他警告WARNING#39; ); private $configPath; private $config = array(); public function __construct() { @set_error_handler(array($this, #39;error_handler#39;), E_ALL ~E_NOTICE ~E_WARNING); @set_exception_handler(array($this, #39;exception_handler#39;)); $this->configPath = DATA_PATH . #39;appclient.config.php#39;; if (!file_exists($this->configPath)) { $this->checkProvider(); } else { $this->config = include($this->configPath); if (empty($this->config[#39;checked#39;])) { $this->checkConfig(); } } } public function error_handler($type, $message, $file, $line) { $msg = $message.#39; #39;.$file.#39; #39;.$line; self::whetherOut($msg, $type); } public function exception_handler($error) { $msg = $error->getMessage().#39; #39;.$error->getFile().#39; #39;.$error->getLine().#39; #39;; self::whetherOut($msg, $error->getCode()); } private static function whetherOut($str,$type=30719){ if (intval($type) lt;= 30719) { res(-1, $str); } } public function run() { $action = $_GET[#39;a#39;]; if (in_array($action, array(#39;upgrade#39;, #39;config#39;))) { $this->{$action}(); } if (empty($this->config[#39;checked#39;])) { res(1002, “接口配置异常,无遥常读取配置信息“); } else { $appAction = new appAction($this->config); $appAction->handle(); } } private function checkProvider() { $provider = #39;#39;; if (file_exists(APP_PATH . #39;index.php#39;)) { $content = file_get_contents(APP_PATH . #39;index.php#39;); if (strpos($content, #39;DEDEINC#39;) !== false) { $provider = #39;dedecms#39;; } elseif (strpos($content, #39;WordPress#39;) !== false) { $provider = #39;wordpress#39;; } elseif (strpos($content, #39;PHPCMS#39;) !== false) { $provider = #39;phpcms#39;; } elseif (strpos($content, #39;Zend#39;) !== false) { if (file_exists(APP_PATH . #39;click_cnt.php#39;)) { $provider = #39;nitc#39;; } } elseif ( strpos($content,#39;Filter_Plugin_Index_Begin#39;) !== false ){ $provider = #39;zblog#39;; } } elseif (file_exists(APP_PATH . #39;d/#39;) file_exists(APP_PATH . #39;e/#39;)) { $provider = #39;empire#39;; } elseif (file_exists(APP_PATH . #39;plus/#39;)) { $provider = #39;dedecms#39;; } elseif (file_exists(APP_PATH.#39;zb_users/#39;)) { $provider = #39;zblog#39;; } elseif( file_exists(APP_PATH.#39;caches/configs#39;) ) { $provider = #39;phpcms#39;; } if ($provider) { $this->config[#39;provider#39;] = $provider; } $this->checkConfig(); } private function config() { if (!is_array($this->config)) { $this->config = array(); } $config = json_decode(file_get_contents(“php://input“), true); if (empty($config)) { $config = array(); } foreach ($config as $key => $item) { if (is_array($item)) { if (!is_array($this->config[$key])) { $this->config[$key] = array(); } foreach ($item as $k => $v) { $this->config[$key][$k] = $v; } } else { $this->config[$key] = $item; } } $this->checkConfig(); if (empty($this->config[#39;checked#39;])) { res(1002, “配置失败,无遥常连接数据库“); } res(0, “配置遥“, $this->config); } private function upgrade() { global $checkToken, $checkTime; $url = BACKAPI . “upgrade“; $clientContent = request($url, #39;GET#39;, array(#39;version#39; => VERSION, #39;app_id#39; => APP_ID, #39;token#39; => $checkToken, #39;_t#39; => $checkTime, #39;file#39; => #39;appclient#39;)); if (strpos($clientContent, “lt;?php“) === 0) { $fileName = basename($_SERVER[#39;PHP_SELF#39;]); $result = file_put_contents(APP_PATH . $fileName, $clientContent); if (!$result) { res(-1, “更新失败a“ . $fileName); } } else { res(-1, “更新失败a“ . $clientContent); } $url = BACKAPI . “upgrade“; $clientContent = request($url, #39;GET#39;, array(#39;version#39; => VERSION, #39;app_id#39; => APP_ID, #39;token#39; => $checkToken, #39;_t#39; => $checkTime, #39;file#39; => $this->config[#39;provider#39;])); if (strpos($clientContent, “lt;?php“) === 0) { $result = file_put_contents(APP_PATH . $this->config[#39;provider#39;] . #39;.php#39;, $clientContent); if (!$result) { res(-1, “更新失败,“ . $this->config[#39;provider#39;] . #39;.php#39;); } } else { res(-1, “更新失败,“ . $clientContent); } res(0, “更新遥“); } private function checkConfig() { global $checkToken, $checkTime; if (!$this->config[#39;setting#39;]) { $this->config[#39;setting#39;] = array(); } if (!$this->config[#39;setting#39;][#39;base_url#39;]) { $this->config[#39;setting#39;][#39;base_url#39;] = baseUrl(); } else { $this->config[#39;setting#39;][#39;base_url#39;] = rtrim($this->config[#39;setting#39;][#39;base_url#39;], “/“) . “/“; } if ($this->config[#39;provider#39;]) { $providerFile = DATA_PATH . $this->config[#39;provider#39;] . “.php“; if (!file_exists($providerFile)) { mkdir ( DATA_PATH, 0777, true ); $url = BACKAPI . “upgrade“; $clientContent = request($url, #39;GET#39;, array(#39;version#39; => VERSION, #39;app_id#39; => APP_ID, #39;token#39; => $checkToken, #39;_t#39; => $checkTime, #39;file#39; => $this->config[#39;provider#39;])); if (strpos($clientContent, “lt;?php“) === 0) { $result = file_put_contents(DATA_PATH . $this->config[#39;provider#39;] . #39;.php#39;, $clientContent); if (!$result) { res(-1, “更新provider失败“); } } else { res(-1, “更新provider失败“); } } require_once $providerFile; } switch ($this->config[#39;provider#39;]) { case #39;dedecms#39;: $this->checkDedecms(); break; case #39;phpcms#39;: $this->checkPhpcms(); break; case #39;wordpress#39;: $this->checkWordpress(); break; case #39;empire#39;: $this->checkEmpire(); break; case #39;nitc#39;: $this->checkNitc(); break; case #39;zblog#39;: $this->checkZblog(); break; default: $this->config = array(); break; } $this->writeConfig(); } private function checkDedecms() { if (empty($this->config[#39;database#39;])) { $configFile = APP_PATH . “data/common.inc.php“; if (!file_exists($configFile)) { $dir_handle = opendir(APP_PATH); while (($file = readdir($dir_handle)) !== false) { if (substr($file, 0, 1) !== #39;.#39; and is_dir(APP_PATH . $file)) { $dir_handle2 = opendir(APP_PATH . $file); while (($file2 = readdir($dir_handle2)) !== false) { if ($file2 === #39;common.inc.php#39;) { $filePath = APP_PATH . $file . #39;/#39; . $file2; $content = file_get_contents($filePath); if (strpos($content, #39;//数据库连接信息#39;) !== false) { $configFile = $filePath; break 2; } } } closedir($dir_handle2); } } closedir($dir_handle); } if (!file_exists($configFile)) { res(1002, “接口配置异常,无遥常读取配置信息“); } $cfg_dbhost = $cfg_dbuser = $cfg_dbpwd = $cfg_dbname = $cfg_db_language = $cfg_dbprefix = #39;#39;; require_once($configFile); $hostArr = explode(“:“, $cfg_dbhost); $this->config[#39;database#39;] = array( #39;host#39; => $hostArr[0], #39;port#39; => $hostArr[1] ? $hostArr[1] : #39;3306#39;, #39;user#39; => $cfg_dbuser, #39;password#39; => $cfg_dbpwd, #39;database#39; => $cfg_dbname, #39;charset#39; => $cfg_db_language, #39;prefix#39; => $cfg_dbprefix ); } if (!$this->config[#39;setting#39;][#39;product_model_id#39;]) { $this->config[#39;setting#39;][#39;product_model_id#39;] = 6; } $provider = new dedecmsProvider($this->config); $this->config[#39;checked#39;] = $provider->checkConfig(); } private function checkPhpcms() { $configFile = APP_PATH . “caches/configs/database.php“; if (!file_exists($configFile)) { res(1002, “接口配置异常,无遥常读取配置信息“); } $fileConfig = include($configFile); $this->config[#39;database#39;] = array( #39;host#39; => $fileConfig[#39;default#39;][#39;hostname#39;], #39;port#39; => $fileConfig[#39;default#39;][#39;port#39;], #39;user#39; => $fileConfig[#39;default#39;][#39;username#39;], #39;password#39; => $fileConfig[#39;default#39;][#39;password#39;], #39;database#39; => $fileConfig[#39;default#39;][#39;database#39;], #39;charset#39; => $fileConfig[#39;default#39;][#39;charset#39;], #39;prefix#39; => $fileConfig[#39;default#39;][#39;tablepre#39;] ); if (!$this->config[#39;setting#39;][#39;site_id#39;]) { $this->config[#39;setting#39;][#39;site_id#39;] = 1; } $provider = new phpcmsProvider($this->config); $this->config[#39;checked#39;] = $provider->checkConfig(); if( $this->config[#39;setting#39;][#39;product_model_id#39;] ) { $productTableName = $provider->getProductTableName(); if (!$productTableName) { res(1002, “产品表不存在“); } $this->config[#39;database#39;][#39;productTableName#39;] = $productTableName; } } private function checkWordpress() { if (empty($this->config[#39;database#39;])) { $configFile = APP_PATH . “wp-config.php“; if (!file_exists($configFile)) { res(1002, “接口配置异常,无遥常读取配置信息“); } $table_prefix = #39;#39;; $contents = file_get_contents($configFile); preg_match(#39;/\$table_prefix\s*=\s*[\#39;|“](.+)[\#39;|“]/#39;, $contents, $match); $table_prefix = $match[1]; preg_match(#39;/define\(\s*[\#39;|“]DB_NAME[\#39;|“],\s*[\#39;|“](.+)[\#39;|“]/#39;, $contents, $match); $dbName = $match[1]; preg_match(#39;/define\(\s*[\#39;|“]DB_USER[\#39;|“],\s*[\#39;|“](.+)[\#39;|“]/#39;, $contents, $match); $dbUser = $match[1]; preg_match(#39;/define\(\s*[\#39;|“]DB_PASSWORD[\#39;|“],\s*[\#39;|“](.+)[\#39;|“]/#39;, $contents, $match); $dbPassword = $match[1]; preg_match(#39;/define\(\s*[\#39;|“]DB_HOST[\#39;|“],\s*[\#39;|“](.+)[\#39;|“]/#39;, $contents, $match); $dbHost = $match[1]; preg_match(#39;/define\(\s*[\#39;|“]DB_CHARSET[\#39;|“],\s*[\#39;|“](.+)[\#39;|“]/#39;, $contents, $match); $dbCharset = $match[1]; $hostArr = explode(“:“, $dbHost); $this->config[#39;database#39;] = array( #39;host#39; => $hostArr[0], #39;port#39; => empty($hostArr[1]) ? #39;3306#39; : $hostArr[1], #39;user#39; => $dbUser, #39;password#39; => $dbPassword, #39;database#39; => $dbName, #39;charset#39; => $dbCharset, #39;prefix#39; => $table_prefix ); } $provider = new wordpressProvider($this->config); $this->config[#39;checked#39;] = $provider->checkConfig(); } private function checkEmpire() { if (empty($this->config[#39;database#39;])) { define(#39;InEmpireCMS#39;, true); $configFile = APP_PATH . “e/config/config.php“; if (!file_exists($configFile)) { res(1002, “接口配置异常,无遥常读取配置信息“); } $ecms_config = array(); require_once($configFile); $this->config[#39;database#39;] = array( #39;host#39; => $ecms_config[#39;db#39;][#39;dbserver#39;], #39;port#39; => $ecms_config[#39;db#39;][#39;dbport#39;] ? $ecms_config[#39;db#39;][#39;dbport#39;] : #39;3306#39;, #39;user#39; => $ecms_config[#39;db#39;][#39;dbusername#39;], #39;password#39; => $ecms_config[#39;db#39;][#39;dbpassword#39;], #39;database#39; => $ecms_config[#39;db#39;][#39;dbname#39;], #39;charset#39; => $ecms_config[#39;db#39;][#39;dbchar#39;], #39;prefix#39; => $ecms_config[#39;db#39;][#39;dbtbpre#39;] ); } if (!$this->config[#39;setting#39;][#39;product_model_id#39;]) { $this->config[#39;setting#39;][#39;product_model_id#39;] = 5; } if (!$this->config[#39;setting#39;][#39;article_model_id#39;]) { $this->config[#39;setting#39;][#39;article_model_id#39;] = 1; } $provider = new empireProvider($this->config); $this->config[#39;checked#39;] = $provider->checkConfig(); } private function checkNitc() { $configFile = APP_PATH . “config.php“; if (!file_exists($configFile)) { res(1002, “接口配置异常,无遥常读取配置信息“); } $db_host = $db_user = $db_pass = $db_name = $prefix = #39;#39;; require_once($configFile); $hostArr = explode(“:“, $db_host); $config = array( “provider“ => #39;wordpress#39;, “database“ => array( #39;host#39; => $hostArr[0], #39;port#39; => $hostArr[1], #39;user#39; => $db_user, #39;password#39; => $db_pass, #39;database#39; => $db_name, #39;charset#39; => #39;utf8#39;, #39;prefix#39; => $prefix ), ); return $config; } private function checkZblog(){ if (empty($this->config[#39;database#39;])) { $configFile = APP_PATH . “zb_users/c_option.php“; if (!file_exists($configFile)) { res(1002, “接口配置异常,无遥常读取配置信息“); } $fileConfig = include($configFile); $this->config[#39;database#39;] = array( #39;host#39; => $fileConfig[#39;ZC_MYSQL_SERVER#39;], #39;port#39; => $fileConfig[#39;ZC_MYSQL_PORT#39;], #39;user#39; => $fileConfig[#39;ZC_MYSQL_USERNAME#39;], #39;password#39; => $fileConfig[#39;ZC_MYSQL_PASSWORD#39;], #39;database#39; => $fileConfig[#39;ZC_MYSQL_NAME#39;], #39;charset#39; => $fileConfig[#39;ZC_MYSQL_CHARSET#39;], #39;prefix#39; => $fileConfig[#39;ZC_MYSQL_PRE#39;] ); } $provider = new zblogProvider($this->config); $this->config[#39;checked#39;] = $provider->checkConfig(); } private function writeConfig() { $configString = “lt;?php\n\n//appclient配置文件\nreturn “ . var_export($this->config, true) . “;\n“; if( !is_dir(DATA_PATH) ) { mkdir(DATA_PATH,0777,true); } $result = file_put_contents($this->configPath, $configString); if (!$result) { res(1002, “无法写入配置,目录权限不足“); } } } class appAction { protected $categoryFields = array( #39;id#39; => #39;#39;, #39;title#39; => #39;#39;, #39;content#39; => #39;#39;, #39;parent_id#39; => #39;#39;, #39;seo_title#39; => #39;#39;, #39;keywords#39; => #39;#39;, #39;description#39; => #39;#39;, #39;status#39; => #39;#39;, #39;sort#39; => #39;#39;, #39;logo#39; => #39;#39;, #39;views#39; => #39;#39;, #39;slug#39; => #39;#39;, #39;model#39; => #39;#39;, #39;add_time#39; => #39;#39;, ); protected $articleFields = array( #39;id#39; => #39;#39;, #39;title#39; => #39;#39;, #39;content#39; => #39;#39;, #39;seo_title#39; => #39;#39;, #39;keywords#39; => #39;#39;, #39;description#39; => #39;#39;, #39;status#39; => #39;#39;, #39;sort#39; => #39;#39;, #39;logo#39; => #39;#39;, #39;views#39; => #39;#39;, #39;category_id#39; => #39;#39;, #39;slug#39; => #39;#39;, #39;author#39; => #39;#39;, #39;model#39; => #39;#39;, #39;params#39; => array(), #39;add_time#39; => #39;#39;, ); protected $productFields = array( #39;id#39; => #39;#39;, #39;title#39; => #39;#39;, #39;content#39; => #39;#39;, #39;seo_title#39; => #39;#39;, #39;keywords#39; => #39;#39;, #39;description#39; => #39;#39;, #39;status#39; => #39;#39;, #39;sort#39; => #39;#39;, #39;logo#39; => #39;#39;, #39;views#39; => #39;#39;, #39;category_id#39; => #39;#39;, #39;slug#39; => #39;#39;, #39;price#39; => #39;#39;, #39;origin#39; => #39;#39;, #39;author#39; => #39;#39;, #39;model#39; => #39;#39;, #39;params#39; => array(), #39;add_time#39; => #39;#39;, ); protected $pageFields = array( #39;id#39; => #39;#39;, #39;title#39; => #39;#39;, #39;content#39; => #39;#39;, #39;seo_title#39; => #39;#39;, #39;keywords#39; => #39;#39;, #39;description#39; => #39;#39;, #39;status#39; => #39;#39;, #39;sort#39; => #39;#39;, #39;logo#39; => #39;#39;, #39;views#39; => #39;#39;, #39;category_id#39; => #39;#39;, #39;slug#39; => #39;#39;, #39;author#39; => #39;#39;, #39;model#39; => #39;#39;, #39;params#39; => array(), #39;add_time#39; => #39;#39;, ); protected $commentFields = array( #39;id#39; => #39;#39;, #39;model#39; => #39;#39;, #39;source_id#39; => #39;#39;, #39;content#39; => #39;#39;, #39;uid#39; => 0, #39;user_name#39; => #39;#39;, #39;status#39; => #39;#39;, #39;add_time#39; => #39;#39;, #39;quote_id#39; => 0, #39;to_uid#39; => 0, #39;agree_count#39; => 0, ); public $provider; public $config; public $pageConfig; public $data; public $pageSize = 20; private $dataDir; public function __construct($config) { global $checkToken, $checkTime; $providerFile = DATA_PATH . $config[#39;provider#39;] . “.php“; if (!file_exists($providerFile)) { $url = BACKAPI . “upgrade“; $clientContent = request($url, #39;GET#39;, array(#39;version#39; => VERSION, #39;app_id#39; => APP_ID, #39;token#39; => $checkToken, #39;_t#39; => $checkTime, #39;file#39; => $config[#39;provider#39;])); if (strpos($clientContent, “lt;?php“) === 0) { $result = file_put_contents($providerFile, $clientContent); if (!$result) { res(-1, “配置错误,对应的provider不存在,接口无法更新provider“); } } else { res(-1, #39;配置错误,对应的provider不存在,并且更新provider失败#39;); } } require $providerFile; $this->config = $config; $providerName = $config[#39;provider#39;] . #39;Provider#39;; $this->provider = new $providerName($config); $this->dataDir = DATA_PATH . “appdata/“; if (!file_exists($this->dataDir)) { mkdir($this->dataDir); } } public function handle() { $funcName = $_GET[#39;a#39;] . “Action“; if (method_exists($this, $funcName)) { $this->{$funcName}(); } else { res(-1, #39;错误的入口#39;); } } public function indexAction() { $this->_pageConfig(array()); res(0, null, $this->data); } public function categoryListAction() { $page = intval($_GET[#39;page#39;]); $row = intval($_GET[#39;row#39;]); $categoryId = $_GET[#39;cat_id#39;]; $model = $_GET[#39;model#39;] ? $_GET[#39;model#39;] : #39;article#39;; $backend = $_GET[#39;backend#39;]; $child = $_GET[#39;child#39;]; $parent_id = intval($_GET[#39;parent_id#39;]); if ($page lt; 1) { $page = 1; } if ($row lt; 2) { $row = $this->pageSize; } $row = 9999; $args = array( #39;category_id#39; => $categoryId, #39;model#39; => $model, #39;page#39; => $page, #39;row#39; => $row, #39;backend#39; => $backend, #39;child#39; => $child, #39;parent_id#39; => $parent_id, ); $result = $this->provider->getCategories($args); if ($backend) { $defaultCategories = array( array( #39;spacer#39; => #39;#39;, #39;id#39; => #39;new#39;, #39;parent_id#39; => 0, #39;title#39; => “较新“ ), array( #39;spacer#39; => #39;#39;, #39;id#39; => #39;hot#39;, #39;parent_id#39; => 0, #39;title#39; => “热门“ ), ); $result = array_merge($defaultCategories, $result); } res(0, null, $result); } public function categoryDetailAction() { $id = intval($_GET[#39;id#39;]); $category = $this->provider->getCategory(array(#39;id#39; => $id, #39;child#39; => $_GET[#39;child#39;])); $this->data[#39;category#39;] = $category; $this->_pageConfig($category); res(0, null, $this->data); } public function listAction($model = null) { $categoryId = intval($_GET[#39;cat_id#39;]); $page = intval($_GET[#39;page#39;]); $row = intval($_GET[#39;row#39;]); $model = $model ? $model : $_GET[#39;model#39;]; $q = $_GET[#39;q#39;]; $ids = $_GET[#39;ids#39;]; if ($page lt; 1) { $page = 1; } if ($row lt; 2) { $row = $this->pageSize; } if ($categoryId) { $category = $this->provider->getCategory(array(#39;id#39; => $categoryId)); if (!$category) { res(-1, #39;分类内容不存在#39;); } } $args = array( #39;category_id#39; => $categoryId, #39;page#39; => $page, #39;row#39; => $row, #39;ids#39; => $ids, #39;keyword#39; => $q, ); if ($category[#39;model#39;] == #39;product#39; || $model == #39;product#39;) { $args[#39;model#39;] = “product“; } else { $args[#39;model#39;] = “article“; } $result = $this->provider->getPosts($args); $result[#39;total#39;] = intval($result[#39;total#39;]); $hasNext = $page * $row lt; $result[#39;total#39;] ? true : false; res(0, null, $result[#39;data#39;], array( #39;total#39; => intval($result[#39;total#39;]), #39;has_next#39; => $hasNext, )); } public function postsAction() { res(0, null, $this->data); } public function articleListAction() { $this->listAction(#39;article#39;); } public function commentListAction() { $model = $_GET[#39;model#39;]; $sourceId = intval($_GET[#39;source_id#39;]); $page = intval($_GET[#39;page#39;]); $row = intval($_GET[#39;row#39;]); $category_id = intval($_GET[#39;category_id#39;]); if ($page lt; 1) { $page = 1; } if ($row lt; 2) { $row = $this->pageSize; } $args = array( #39;model#39; => $model, #39;source_id#39; => $sourceId, #39;page#39; => $page, #39;row#39; => $row, #39;category_id#39; => $category_id, ); $result = $this->provider->getComments($args); $result[#39;total#39;] = intval($result[#39;total#39;]); $hasNext = $page * $row lt; $result[#39;total#39;] ? true : false; return res(0, null, $result[#39;data#39;], array( #39;total#39; => $result[#39;total#39;], #39;has_next#39; => $hasNext, )); } public function commentSaveAction() { $data = json_decode(file_get_contents(“php://input“), true); $data[#39;ip#39;] = getClientIp(); $result = $this->provider->saveComment($data); $url = BACKAPI . “comment/saveBack?“ . http_build_query($_GET); request($url, #39;POST#39;, json_encode($data)); res($result[#39;code#39;], $result[#39;msg#39;]); } public function commentAttitudeAction() { $data = json_decode(file_get_contents(“php://input“), true); $result = $this->provider->commentAttitude($data); res($result[#39;code#39;], $result[#39;msg#39;]); } public function articleDetailAction() { $id = intval($_GET[#39;id#39;]); $article = $this->provider->getArticle(array(#39;id#39; => $id)); $article[#39;content#39;] = str_replace(#39;middot;#39;, #39;·#39;, $article[#39;content#39;]); $this->data[#39;article#39;] = $article; $this->_pageConfig($article); res(0, null, $this->data); } public function productListAction() { $this->listAction(#39;product#39;); } public function productDetailAction() { $id = intval($_GET[#39;id#39;]); $product = $this->provider->getProduct(array(#39;id#39; => $id)); $product[#39;content#39;] = str_replace(#39;middot;#39;, #39;·#39;, $product[#39;content#39;]); if (!$product) { res(-1, #39;产品不存在#39;); } $this->data[#39;product#39;] = $product; $this->_pageConfig($product); res(0, null, $this->data); } public function pageListAction() { $categoryId = intval($_GET[#39;cat_id#39;]); $page = intval($_GET[#39;page#39;]); $row = intval($_GET[#39;row#39;]); $q = $_GET[#39;q#39;]; $ids = $_GET[#39;ids#39;]; if ($page lt; 1) { $page = 1; } if ($row lt; 2) { $row = $this->pageSize; } if ($categoryId) { $category = $this->provider->getCategory(array(#39;id#39; => $categoryId)); if (!$category) { res(-1, #39;分类内容不存在#39;); } } $args = array( #39;category_id#39; => $categoryId, #39;page#39; => $page, #39;row#39; => $row, #39;ids#39; => $ids, #39;keyword#39; => $q, ); $result = $this->provider->getPages($args); $result[#39;total#39;] = intval($result[#39;total#39;]); $hasNext = $page * $row lt; $result[#39;total#39;] ? true : false; res(0, null, $result[#39;data#39;], array( #39;total#39; => $result[#39;total#39;], #39;has_next#39; => $hasNext, )); } public function pageDetailAction() { $id = intval($_GET[#39;id#39;]); $article = $this->provider->getPage(array(#39;id#39; => $id)); $this->data[#39;page#39;] = $article; $this->_pageConfig($article); res(0, null, $this->data); } public function paramsAction() { $model = $_GET[#39;model#39;] ? $_GET[#39;model#39;] : #39;article#39;; $args = array( #39;model#39; => $model, ); $result = $this->provider->getParams($args); res(0, null, $result); } public function defaultAction() { res(0, null, $this->data); } public function featureDetailAction() { $id = $_GET[#39;id#39;]; $type = $_GET[#39;type#39;]; $sourceId = $_GET[#39;source_id#39;]; $categoryId = $_GET[#39;category_id#39;]; if($type == #39;page#39;){ $type = #39;article#39;; } if ($categoryId empty($type)) { $category = $this->provider->getCategory(array(“id“ => $categoryId)); $type = $category[“model“] . “Category“; } if ($sourceId $type) { $designPath = $this->dataDir . $type . “_“ . $sourceId . “.json“; if (!file_exists($designPath)) { $designPath = $this->dataDir . ($id ? $id : $type) . “.json“; } } else { $designPath = $this->dataDir . ($id ? $id : $type) . “.json“; } if (!file_exists($designPath)) { $url = BACKAPI . “feature/detail?“ . http_build_query($_GET); $clientContent = request($url); if (!$clientContent) { res(-1, “页面不存在“); } $result = json_decode($clientContent, true); $this->saveDataAction(array( #39;pageName#39; => $type, #39;sourceId#39; => $sourceId, #39;id#39; => $id, #39;content#39; => json_encode($result[#39;data#39;]), )); die($clientContent); } $content = file_get_contents($designPath); if ($content) { $design = json_decode($content, true); if ($design[#39;page#39;] == #39;home#39;) { } res(0, null, $design); } else { res(-1, “页面不存在“); } } public function settingSystemAction() { $designPath = $this->dataDir . “global.json“; $do_action = $_GET[#39;do_action#39;]; if (!file_exists($designPath) || $do_action == #39;update#39;) { $url = BACKAPI . “setting/system?“ . http_build_query($_GET); $clientContent = request($url); if (!$clientContent) { res(-1, “配置不存在“); } $result = json_decode($clientContent, true); $this->saveDataAction(array( #39;pageName#39; => #39;global#39;, #39;sourceId#39; => null, #39;id#39; => null, #39;content#39; => json_encode($result[#39;data#39;]), )); die($clientContent); } $content = file_get_contents($designPath); if ($content) { $setting = json_decode($content, true); res(0, null, $setting); } else { res(-1, “页面不存在“); } } public function settingCopyrightAction() { $designPath = $this->dataDir . “copyright.json“; $content = file_get_contents($designPath); if (!file_exists($designPath)) { res(0, null, array(#39;content#39; => #39;#39;)); } if ($content) { $setting = json_decode($content, true); res(0, null, $setting); } else { res(0, null, array(#39;content#39; => #39;#39;)); } } public function settingFeedbackSaveAction() { $url = BACKAPI . “setting/feedback/save?“ . http_build_query($_GET); $clientContent = request($url, #39;POST#39;, file_get_contents(“php://input“)); if (!$clientContent) { res(-1, “留言保存失败“); } $result = json_decode($clientContent, true); res($result[#39;code#39;], $result[#39;msg#39;]); } public function feedbackFieldsAction() { $designPath = $this->dataDir . “feedback.json“; $content = file_get_contents($designPath); if (!file_exists($designPath)) { $url = BACKAPI . “feedback/fields?“ . http_build_query($_GET); $clientContent = request($url); if (!$clientContent) { res(-1, “表单不存在“); } $result = json_decode($clientContent, true); $this->saveDataAction(array( #39;pageName#39; => #39;feedback#39;, #39;sourceId#39; => null, #39;id#39; => null, #39;content#39; => json_encode($result[#39;data#39;]), )); die($clientContent); } if ($content) { $setting = json_decode($content, true); res(0, null, $setting); } else { res(-1, “表单不存在“); } } public function feedbackSaveAction() { $url = BACKAPI . “feedback/save?“ . http_build_query($_GET); $clientContent = request($url, #39;POST#39;, file_get_contents(“php://input“)); if (!$clientContent) { res(-1, “留言保存失败“); } $result = json_decode($clientContent, true); res($result[#39;code#39;], $result[#39;msg#39;]); } public function uploadAction() { $fileName = $_GET[#39;file_name#39;]; $savePath = DATA_PATH . “appimage/“ . $fileName; if (in_array(pathinfo($fileName, PATHINFO_EXTENSION), array(#39;jpeg#39;, #39;jpg#39;, #39;png#39;, #39;gif#39;))) { $file = reset($_FILES); $fileDir = dirname($savePath); if (!file_exists($fileDir)) { mkdir($fileDir, 0777, true); } move_uploaded_file($file[#39;tmp_name#39;], $savePath); res(0, #39;图片保存遥#39;); } else { res(-1, #39;不支持的图片#39;); } } public function saveDataAction($saveData = null) { $return = false; if ($saveData[#39;pageName#39;] || $saveData[#39;content#39;]) { $pageName = $saveData[#39;pageName#39;]; $id = $saveData[#39;id#39;]; $sourceId = $saveData[#39;sourceId#39;]; $content = $saveData[#39;content#39;]; $return = true; }else { $pageName = $_GET[#39;page_name#39;]; $id = $_GET[#39;id#39;]; $sourceId = $_GET[#39;source_id#39;]; $content = file_get_contents(“php://input“); } $savePaths = array(); if ($pageName) { $savePaths[] = $this->dataDir . $pageName . “.json“; } if ($sourceId) { $savePaths[] = $this->dataDir . $pageName . “_“ . $sourceId . “.json“; } if ($id) { $savePaths[] = $this->dataDir . $id . “.json“; } foreach ($savePaths as $val) { $result = file_put_contents($val, $content); if (!$result) { if($return){ return false; } res(-1, #39;文件写入失败#39;); } } if($return){ return true; } res(0, “文件保存遥“); } public function sitemapAction() { if( $_GET[#39;appType#39;] == #39;toutiao#39; ) { $this->siteMapXmlToutiao(); }else{ $this->siteMapCommon(); } } private function siteMapCommon() { $sudDay = $_GET[#39;sudDay#39;]; $sitemap = array(“pages/index/index“, “pages/productIndex/index“, “pages/articleIndex/index“); $products = $this->provider->getProducts(array(#39;sudDay#39; => $sudDay,#39;row#39;=>100000)); foreach ($products[#39;data#39;] as $item) { $sitemap[] = “pages/product/index?id=“ . $item[#39;id#39;]; } $articles = $this->provider->getArticles(array(#39;sudDay#39; => $sudDay,#39;row#39;=>100000)); foreach ($articles[#39;data#39;] as $item) { $sitemap[] = “pages/article/index?id=“ . $item[#39;id#39;]; } $categories = $this->provider->getCategories(); foreach ($categories as $item) { $sitemap[] = “pages/category/index?id=“ . $item[#39;id#39;]; } $content = implode(“\r\n“, $sitemap); header(“content-Type: text/html; charset=UTF-8“); header(“Content-type:text/plan“); header(“Accept-Ranges: bytes“); header(“Accept-Length: “ . strlen($content)); header(“Content-Disposition: attachment; filename=siteMap.txt“); die($content); } private function siteMapXmlToutiao() { header(“Content-type: application/xml“); $sudDay = $_GET[#39;sudDay#39;]; $type = $_GET[#39;type#39;]; $time = $_GET[#39;time#39;]; if ($type == #39;index#39;) { $sitemapDates = $this->provider->getSiteMapIndex(); $sitemapIndex = new SimpleXMLElement(#39;lt;?xml version=“1.0“ encoding=“utf-8“ ?>lt;sitemapindex>lt;/sitemapindex>#39;); foreach ($sitemapDates as $item) { $rating = $sitemapIndex->addChild(#39;sitemap#39;); $loc = $this->config[#39;setting#39;][#39;base_url#39;] . $this->config[#39;client_name#39;] . #39;?from=xamp;a=sitemapamp;time=#39; . $item; $rating->addChild(#39;loc#39;, $loc); $rating->addChild(#39;lastmod#39;, $item . “ 18:00:00“); } echo $sitemapIndex->asXML(); } else { $SimpleXMLElement = new SimpleXMLElement(#39;lt;?xml version=“1.0“ encoding=“utf-8“?>lt;DOCUMENT>lt;/DOCUMENT>#39;); $where = array(); if (is_numeric($sudDay)) { $where[#39;sudDay#39;] = $sudDay; } if ($time) { $where[#39;startTime#39;] = $time; $where[#39;endTime#39;] = strtotime($time) + 86400; } $products = $this->provider->getProducts($where); $this->makeSitemap($SimpleXMLElement, $products[#39;data#39;], #39;pages/product/index#39;); $articles = $this->provider->getArticles($where); $this->makeSitemap($SimpleXMLElement, $articles[#39;data#39;], #39;pages/article/index#39;); $categories = $this->provider->getCategories(); $this->makeSitemap($SimpleXMLElement, $categories, #39;pages/category/index#39;); echo $SimpleXMLElement->asXML(); } } private function makeSitemap($xmlObj, $dataArr, $url) { foreach ($dataArr as $key => $item) { $rating = $xmlObj->addChild(#39;item#39;); $rating->addChild(#39;key#39;, $item[#39;id#39;]); $display = $rating->addChild(#39;display#39;); $display->addChild(#39;title#39;, $item[#39;title#39;]); if ($item[#39;description#39;]) { $display->addChild(#39;description#39;, mb_substr(str_replace(#39;*#39;, #39;#39;, $item[#39;description#39;]), 0, 60)); } if ($item[#39;logo#39;]) { $display->addChild(#39;pic#39;, $item[#39;logo#39;]); } $display->addChild(#39;create_time#39;, date(#39;Y-m-d H:i:s#39;, $item[#39;add_time#39;])); if ($item[#39;from#39;]) { $display->addChild(#39;from#39;, $item[#39;from#39;]); } if ($item[#39;url#39;]) { $display->addChild(#39;url#39;, $item[#39;url#39;]); } $display->addChild(#39;lightapp_url#39;, $url . #39;?url=#39; . $item[#39;id#39;]); $display->addChild(#39;lightappid_url#39;, $this->config[#39;weapp#39;][#39;app_id#39;]); } } public function mappingAction() { $sitemap = $this->provider->getMapping(); header(“Content-type:text/plan“); foreach ($sitemap as $key => $item) { echo “{$item[#39;url#39;]} => {$item[#39;path#39;]}\r\n“; } die; } private function _pageConfig($data) { if (!$data[#39;seo_title#39;]) { $data[#39;seo_title#39;] = $data[#39;title#39;]; } $this->data[#39;page_config#39;] = array( “seo_title“ => $data[#39;seo_title#39;], “keywords“ => $data[#39;keywords#39;], “description“ => $data[#39;description#39;], “title“ => $data[#39;title#39;] ? $data[#39;title#39;] : $data[#39;seo_title#39;], “add_time“ => $data[#39;add_time#39;], “image“ => $data[#39;logo#39;], ); } } class pdoMysql { private $config = null; public $link = null; public $lastqueryid = null; public $querycount = 0; private $reconnectCount = 0; private $sql=““; public function __construct($config) { if (!$config[#39;port#39;]) { $config[#39;port#39;] = 3306; } if (!$config[#39;charset#39;]) { $config[#39;charset#39;] = #39;utf8#39;; } $this->config = $config; $this->config[#39;dsn#39;] = #39;mysql:host=#39; . $config[#39;host#39;] . #39;;port=#39; . $config[#39;port#39;] . #39;;dbname=#39; . $config[#39;database#39;]; $this->connect(); } private function connect() { if ($this->reconnectCount > 3) { res(1002, #39;数据库重连失败#39;); } $this->reconnectCount++; try { $this->link = new PDO($this->config[#39;dsn#39;], $this->config[#39;user#39;], $this->config[#39;password#39;], array( PDO::ATTR_PERSISTENT => true, PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::MYSQL_ATTR_INIT_COMMAND => “SET NAMES utf8“ )); } catch (Exception $e) { res(1002, $e->getMessage()); $this->link = null; return null; } $this->link->query(“set sql_mode=#39;#39;“); return $this->link; } public function execute($sql) { if (!is_object($this->link)) { $result = $this->connect(); if (!$result) { res(1002, #39;数据库重连失败#39;); } } $this->lastqueryid = $this->link->exec($sql); $errNo = $this->errno(); if ($errNo == 2003 || $errNo == 2006) { $this->connect(); return $this->execute($sql); } elseif ($errNo > 0) { res(-1, $this->error($sql)); } $this->querycount++; return $this->lastqueryid; } public function query($sql = null) { if (!is_object($this->link)) { $result = $this->connect(); if (!$result) { res(1002, #39;数据库重连失败#39;); } } $this->lastqueryid = $this->link->query($sql); $errNo = $this->errno(); if ($errNo == 2003 || $errNo == 2006) { $this->connect(); return $this->query($sql); } elseif ($errNo > 0) { res(-1, $this->error($sql)); } $this->querycount++; return $this->lastqueryid; } public function querySelect($sql, $limit = #39;#39;, $order = #39;#39;, $group = #39;#39;, $key = #39;#39;) { $sql = $this->sql.#39; #39;.$sql; $order = $order == #39;#39; ? #39;#39; : #39; orDER BY #39; . $order; $group = $group == #39;#39; ? #39;#39; : #39; GROUP BY #39; . $group; $limit = $limit == #39;#39; ? #39;#39; : #39; LIMIT #39; . $limit; $sql = $sql . $group . $order . $limit; $this->query($sql); if (!is_object($this->lastqueryid)) { return $this->lastqueryid; } $datalist = $this->lastqueryid->fetchAll(); if ($key) { $datalist_new = array(); foreach ($datalist as $i => $item) { $datalist_new[$item[$key]] = $item; } $datalist = $datalist_new; unset($datalist_new); } $this->freeResult(); $this->sql = #39;#39;; return $datalist; } public function select($data, $table, $where = #39;#39;, $limit = #39;#39;, $order = #39;#39;, $group = #39;#39;, $key = #39;#39;) { $where = $where == #39;#39; ? #39;#39; : #39; Where #39; . $where; $order = $order == #39;#39; ? #39;#39; : #39; orDER BY #39; . $order; $group = $group == #39;#39; ? #39;#39; : #39; GROUP BY #39; . $group; $limit = $limit == #39;#39; ? #39;#39; : #39; LIMIT #39; . $limit; $field = explode(#39;,#39;, $data); array_walk($field, array($this, #39;addSpecialChar#39;)); $data = implode(#39;,#39;, $field); $sql = #39;Select #39; . $data . #39; FROM `#39; . $this->config[#39;database#39;] . #39;`.`#39; . $this->getTable($table) . #39;`#39; . $where . $group . $order . $limit; $this->query($sql); if (!is_object($this->lastqueryid)) { return $this->lastqueryid; } $datalist = $this->lastqueryid->fetchAll(); if ($key) { $datalist_new = array(); foreach ($datalist as $i => $item) { $datalist_new[$item[$key]] = $item; } $datalist = $datalist_new; unset($datalist_new); } $this->freeResult(); return $datalist; } public function getOne($data, $table, $where = #39;#39;, $order = #39;#39;, $group = #39;#39;) { $where = $where == #39;#39; ? #39;#39; : #39; Where #39; . $where; $order = $order == #39;#39; ? #39;#39; : #39; orDER BY #39; . $order; $group = $group == #39;#39; ? #39;#39; : #39; GROUP BY #39; . $group; $limit = #39; LIMIT 1#39;; $field = explode(#39;,#39;, $data); array_walk($field, array($this, #39;addSpecialChar#39;)); $data = implode(#39;,#39;, $field); $table = explode(#39; as #39;,$table); $table = #39;`.`#39; . $this->getTable($table[0]) . #39;`#39; . ($table[1]?#39; as #39;.$table[1]:#39;#39;); $sql = #39;Select #39; . $data . #39; FROM `#39; . $this->config[#39;database#39;] .$table. $where . $group . $order . $limit; $this->query($sql); $res = $this->lastqueryid->fetch(); $this->freeResult(); return $res; } public function getOneCol($data, $table, $where = #39;#39;, $order = #39;#39;, $group = #39;#39;) { $where = $where == #39;#39; ? #39;#39; : #39; Where #39; . $where; $order = $order == #39;#39; ? #39;#39; : #39; orDER BY #39; . $order; $group = $group == #39;#39; ? #39;#39; : #39; GROUP BY #39; . $group; $limit = #39; LIMIT 1#39;; $field = explode(#39;,#39;, $data); array_walk($field, array($this, #39;addSpecialChar#39;)); $data = implode(#39;,#39;, $field); $fieldname = str_replace(#39;`#39;, #39;#39;, $data); $sql = #39;Select #39; . $data . #39; FROM `#39; . $this->config[#39;database#39;] . #39;`.`#39; . $this->getTable($table) . #39;`#39; . $where . $group . $order . $limit; $this->query($sql); $res = $this->lastqueryid->fetch(); $this->freeResult(); $result = isset($res[$fieldname]) ? $res[$fieldname] : false; return $result; } public function insert($data, $table, $return_insertId = false, $replace = false) { if (!is_array($data) || $table == #39;#39; || count($data) == 0) { return false; } $fielddata = array_keys($data); $valuedata = array_values($data); array_walk($fielddata, array($this, #39;addSpecialChar#39;)); array_walk($valuedata, array($this, #39;escapeString#39;)); $field = implode(#39;,#39;, $fielddata); $value = implode(#39;,#39;, $valuedata); $cmd = $replace ? #39;REPLACE INTO#39; : #39;Insert INTO#39;; $sql = $cmd . #39; `#39; . $this->config[#39;database#39;] . #39;`.`#39; . $this->getTable($table) . #39;`(#39; . $field . #39;) VALUES (#39; . $value . #39;)#39;; $return = $this->execute($sql); return $return_insertId ? $this->insertId() : $return; } public function update($data, $table, $where = #39;#39;, $order = ““, $limit = ““) { if ($table == #39;#39; or $where == #39;#39;) { return false; } $where = #39; Where #39; . $where; if (is_string($data) $data != #39;#39;) { $field = $data; } elseif (is_array($data) count($data) > 0) { $fields = array(); foreach ($data as $k => $v) { switch (substr($v, 0, 2)) { case #39;+=#39;: $v = substr($v, 2); if (is_numeric($v)) { $fields[] = $this->addSpecialChar($k) . #39;=#39; . $this->addSpecialChar($k) . #39;+#39; . $this->escapeString($v, #39;#39;, false); } break; case #39;-=#39;: $v = substr($v, 2); if (is_numeric($v)) { $fields[] = $this->addSpecialChar($k) . #39;=#39; . $this->addSpecialChar($k) . #39;-#39; . $this->escapeString($v, #39;#39;, false); } break; default: if (preg_match(#39;/^`[a-z_0-9]+`\s*[\+\-]\s*[0-9]+$/#39;, $v)) { $fields[] = $this->addSpecialChar($k) . #39;=#39; . $v; } else { $fields[] = $this->addSpecialChar($k) . #39;=#39; . $this->escapeString($v); } } } $field = implode(#39;,#39;, $fields); } else { return false; } $order = !empty($order) ? “ orDER BY “ . $order : ““; $limit = !empty($limit) ? “ LIMIT “ . $limit : ““; $sql = #39;Update `#39; . $this->config[#39;database#39;] . #39;`.`#39; . $this->getTable($table) . #39;` SET #39; . $field . $where . $order . $limit; return $this->execute($sql); } public function delete($table, $where) { if ($table == #39;#39; || $where == #39;#39;) { return false; } $where = #39; Where #39; . $where; $sql = #39;Delete FROM `#39; . $this->config[#39;database#39;] . #39;`.`#39; . $this->getTable($table) . #39;`#39; . $where; return $this->execute($sql); } public function count($where = #39;#39;, $table, $group = #39;#39;) { $r = $this->getOne(“COUNT(*) AS num“, $table, $where, #39;#39;, $group); return $r[#39;num#39;]; } public function fetchAll($res = null) { $type = PDO::FETCH_ASSOC; if ($res) { $res_query = $res; } else { $res_query = $this->lastqueryid; } return $res_query->fetchAll($type); } public function affectedRows() { return is_numeric($this->lastqueryid) ? $this->lastqueryid : 0; } public function getPrimary($table) { $this->query(“SHOW COLUMNS FROM “ . $this->getTable($table)); while ($r = $this->lastqueryid->fetch()) { if ($r[#39;Key#39;] == #39;PRI#39;) { break; } } return $r[#39;Field#39;]; } public function getFields($table) { $fields = array(); $this->query(“SHOW COLUMNS FROM “ . $this->getTable($table)); while ($r = $this->lastqueryid->fetch()) { $fields[$r[#39;Field#39;]] = $r[#39;Type#39;]; } return $fields; } public function checkFields($table, $array) { $fields = $this->getFields($table); $nofields = array(); foreach ($array as $v) { if (!array_key_exists($v, $fields)) { $nofields[] = $v; } } return $nofields; } public function tableExists($table) { $tables = $this->listTables(); return in_array($table, $tables) ? 1 : 0; } public function listTables() { $tables = array(); $this->query(“SHOW TABLES“); while ($r = $this->lastqueryid->fetch()) { $tables[] = $r[#39;Tables_in_#39; . $this->config[#39;database#39;]]; } return $tables; } public function fieldExists($table, $field) { $fields = $this->getFields($table); return array_key_exists($field, $fields); } public function getTable($table) { if (!$this->config[#39;prefix#39;]) { return $table; } if (strpos($table, $this->config[#39;prefix#39;]) === false) { return $this->config[#39;prefix#39;] . $table; } return $table; } public function numRows($sql) { $this->query($sql); return $this->lastqueryid->rowCount(); } public function num_fields($sql) { $this->query($sql); return $this->lastqueryid->columnCount(); } public function result($sql, $row) { $this->query($sql); return $this->lastqueryid->fetchColumn($row); } public function error($msg = null) { $err = $this->link->errorInfo(); if($msg){ $err[] = $msg; } return $err; } public function errno() { return intval($this->link->errorCode()); } public function insertId() { return $this->link->lastInsertId(); } public function freeResult() { if (is_object($this->lastqueryid)) { $this->lastqueryid = null; } } public function close() { if (is_object($this->link)) { unset($this->link); } } public function addSpecialChar($value) { if (#39;*#39; == $value || false !== strpos($value, #39;(#39;) || false !== strpos($value, #39;.#39;) || false !== strpos($value, #39;`#39;) || false !== strpos(strtolower($value), #39;as#39;)) { } else { $value = #39;`#39; . trim($value) . #39;`#39;; } if (preg_match(“/\b(select|insert|update|delete)\b/i“, $value)) { $value = preg_replace(“/\b(select|insert|update|delete)\b/i“, #39;#39;, $value); } return $value; } public function escapeString($value, $key = #39;#39;, $quotation = 1) { if ($quotation) { $q = #39;\#39;#39;; } else { $q = #39;#39;; } $value = $q . $value . $q; return $value; } public function halt($message = #39;#39;, $sql = #39;#39;) { res(-1, #39;Errno :#39; . $sql . implode(#39; #39;, $this->link->errorInfo())); } public function convertEncoding($string, $from_encoding = #39;GBK#39;, $target_encoding = #39;UTF-8#39;) { if (is_array($string)) { foreach ($string as $key => $value) { $string[$key] = $this->convertEncoding($value, $from_encoding, $target_encoding); } } else { if (function_exists(#39;mb_convert_encoding#39;)) { $string = mb_convert_encoding($string, str_replace(#39;//IGNORE#39;, #39;#39;, strtoupper($target_encoding)), $from_encoding); } else { if (strtoupper($target_encoding) == #39;GB2312#39; or strtoupper($target_encoding) == #39;GBK#39;) { $target_encoding .= #39;//IGNORE#39;; } $string = iconv($from_encoding, $target_encoding, $string); } } return $string; } final function from($data=#39;*#39;,$table,$as=#39;#39;) { $as = $as ? (#39; as #39; . $as) : #39;#39;; preg_match(“/^{$this->config[#39;prefix#39;]}/“, $table, $m); if (!$m) $table = $this->config[#39;prefix#39;] . $table; $this->sql = #39;Select #39; . $data . #39; FROM #39; . $table . $as; return $this; } final function join($dbName,$sql,$type=#39;INNER#39;) { preg_match(“/^{$this->config[#39;prefix#39;]}/“,$dbName,$m); if(!$m) $dbName = $this->config[#39;prefix#39;].$dbName; $this->sql .= #39; #39;.$type.#39; JOIN #39;.$dbName.“ ON (“.$sql.#39;) #39;; return $this; } final function where($sql) { if( $sql ) { $this->sql .= #39; where #39;.$sql; } return $this; } } class categoryTree { public $categories; public $tree = array(); public $deep = 1; public $icon = array(#39;└#39;,#39;#39;,#39;#39;, #39;#39;); public $parent_name = #39;parent_id#39;; public $id_name = #39;id#39;; public $tmps; public function __construct($categories = null, $id_name = #39;id#39;, $parent_name = #39;parent_id#39;) { $this->categories = $categories; $this->parent_name = $parent_name; $this->id_name = $id_name; $this->tmps = array(); } public function getTree($rootId = 0, $add = #39;#39;, $parent_end =false, $excludeId = null) { $rootId = intval($rootId); $is_top = 1; if ($excludeId $excludeId == $rootId) { return; } $child_arr = $this->getChild($rootId); $space = $this->icon[3]; if (is_array($child_arr)) { $cnt = count($child_arr); foreach ($child_arr as $key => $child) { $cid = $child[$this->id_name]; if ($this->deep >1) { if ($is_top == 1 $this->deep > 1) { $space = $this->icon[1]; $add .= $this->icon[0]; } if ($is_top == $cnt) { $space = $this->icon[2]; $parent_end = true; } else { $space = $this->icon[1]; $parent_end = false; } } $child[#39;spacer#39;] = $add . $space; if (!isset($this->tree[$child[$this->id_name]])) { $this->tree[$child[$this->id_name]] = $child; } $is_top++; $this->deep++; if ($this->getChild($cid)) { if ($excludeId $excludeId == $cid) { continue; } $this->getTree($cid, $add, $parent_end, $excludeId); $this->deep--; } } } return array_values($this->tree); } public function getTreeChild($rootId = 0) { $rootId = intval($rootId); $tmp = array(); foreach ($this->categories as $node) { $tmp[$node[$this->parent_name]][$node[$this->id_name]] = $node; } krsort($tmp); foreach ($tmp as $pid => $childs) { foreach ($childs as $child) { if (isset($tmp[$child[$this->id_name]])) { $child[#39;child#39;] = array_values($tmp[$child[$this->id_name]]); } } } return array_values($tmp[$rootId]); } public function getChild($root = 0) { if (!$this->tmps) { foreach ($this->categories as $node) { $this->tmps[$node[$this->parent_name]][] = $node; } } $child = array(); if (isset($this->tmps[$root])) { $child = $this->tmps[$root]; } return $child?$child:false; } } function getClientIp() { $ip = $_SERVER[#39;REMOTE_ADDR#39;]; if (isset($_SERVER[#39;HTTP_CLIENT_IP#39;]) preg_match(#39;/^([0-9]{1,3}\.){3}[0-9]{1,3}$/#39;, $_SERVER[#39;HTTP_CLIENT_IP#39;])) { $ip = $_SERVER[#39;HTTP_CLIENT_IP#39;]; } elseif(isset($_SERVER[#39;HTTP_X_FORWARDED_FOR#39;]) AND preg_match_all(#39;#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s#39;, $_SERVER[#39;HTTP_X_FORWARDED_FOR#39;], $matches)) { foreach ($matches[0] AS $xip) { if (!preg_match(#39;#^(10|172\.16|192\.168)\.##39;, $xip)) { $ip = $xip; break; } } } if(isset($_SERVER[#39;HTTP_REQUEST_IP#39;])){ $ip = $_SERVER[#39;HTTP_REQUEST_IP#39;]; } return $ip; } function baseUrl() { static $baseUrl; if ($baseUrl) { return $baseUrl; } $isHttps = false; if (!empty($_SERVER[#39;HTTPS#39;]) strtolower($_SERVER[#39;HTTPS#39;]) !== #39;off#39;) { $isHttps = true; } elseif (isset($_SERVER[#39;HTTP_X_FORWARDED_PROTO#39;]) $_SERVER[#39;HTTP_X_FORWARDED_PROTO#39;] === #39;https#39;) { $isHttps = true; } elseif (!empty($_SERVER[#39;HTTP_FRONT_END_HTTPS#39;]) strtolower($_SERVER[#39;HTTP_FRONT_END_HTTPS#39;]) !== #39;off#39;) { $isHttps = true; } $dirNameArr = explode(#39;/#39;, $_SERVER[#39;REQUEST_URI#39;]); array_pop($dirNameArr); $dirName = implode(“/“, $dirNameArr) . “/“; $baseUrl = ($isHttps ? “https“ : “http“) . “://“ . $_SERVER[“HTTP_HOST“] . $dirName; return $baseUrl; } function res($code, $msg = null, $data = null, $extra = null) { @header(#39;Content-Type:application/json;charset=UTF-8#39;); if(is_array($msg)){ $msg = implode(“,“, $msg); } $output = array( #39;code#39; => $code, #39;msg#39; => $msg, #39;data#39; => $data ); if (is_array($extra)) { foreach ($extra as $key => $val) { $output[$key] = $val; } } echo json_encode($output); die; } function showMessage($msg, $code = -1) { $from = $_GET[#39;from#39;]; if ($from == #39;x#39;) { res($code, $msg); } @header(#39;Content-Type:text/html;charset=UTF-8#39;); echo “lt;div style=#39;padding: 50px;text-align: center;#39;>$msglt;/div>“; die; } function request($url, $method = #39;GET#39;, $postFields = null, $time_out = 5) { $curl = curl_init(); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($curl, CURLOPT_TIMEOUT, $time_out); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, false); if (is_array($postFields)) { $postFields = http_build_query($postFields); } $method = strtoupper($method); if ($method == #39;POST#39;) { curl_setopt($curl, CURLOPT_POST, true); if ($postFields) { curl_setopt($curl, CURLOPT_POSTFIELDS, $postFields); } } else { if ($postFields) { if (strpos($url, #39;?#39;) !== false) { $url .= ““ . $postFields; } else { $url .= “?“ . $postFields; } } } curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLINFO_HEADER_OUT, true); if (substr($url, 0, 8) == #39;https://#39;) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); } $response = curl_exec($curl); curl_close($curl); return $response; } function parseAction($a) { $a = lcfirst(str_replace(“ “, ““, ucwords(str_replace(array(“/“, “_“), “ “, $a)))); return $a; } if (!function_exists(#39;array_column#39;)) { function array_column($rows, $column_key, $index_key = null) { if (!$rows) { return array(); } $data = array(); if (empty($index_key)) { foreach ($rows as $row) { $data[] = $row[$column_key]; } } else { foreach ($rows as $row) { $data[$row[$index_key]] = $row; } } return $data; } } $errorCodes = array( 0 => #39;正常#39;, -1 => #39;普通错误#39;, 101 => #39;没有授权#39;, 102 => #39;版本过旧#39;, 1001 => #39;访问受限#39;, 1002 => #39;没有配置或配置错误#39;, 1003 => #39;空间不支持#39;, );




版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权本站发表,未经许可,不得转载。

分享:

扫一扫在手机阅读、分享本文