public static function GetInstance() { if (!isset(self::$_zbe)) { self::$_zbe = new ZBlogException(); } return self::$_zbe; }
function __construct() { global $option, $lang, $blogpath, $bloghost, $cookiespath, $usersdir, $table, $datainfo; global $blogversion, $blogtitle, $blogname, $blogsubname, $blogtheme, $blogstyle; ZBlogException::SetErrorHook(); //基本配置加载到$zbp内 $this->version =& $blogversion; $this->option =& $option; $this->lang =& $lang; $this->path =& $blogpath; $this->host =& $bloghost; $this->cookiespath =& $cookiespath; $this->usersdir =& $usersdir; $this->table =& $table; $this->datainfo =& $datainfo; if (trim($this->option['ZC_BLOG_CLSID']) == '') { $this->option['ZC_BLOG_CLSID'] = GetGuid(); } $this->guid =& $this->option['ZC_BLOG_CLSID']; $this->title =& $blogtitle; $this->name =& $blogname; $this->subname =& $blogsubname; $this->theme =& $blogtheme; $this->style =& $blogstyle; $this->managecount = $this->option['ZC_MANAGE_COUNT']; $this->pagebarcount = $this->option['ZC_PAGEBAR_COUNT']; $this->searchcount = $this->option['ZC_SEARCH_COUNT']; $this->displaycount = $this->option['ZC_DISPLAY_COUNT']; $this->commentdisplaycount = $this->option['ZC_COMMENTS_DISPLAY_COUNT']; $this->cache = new Metas(); }
/** * @param string $varBody * @return mixed|void */ public function send($varBody = '') { $data = $varBody; if (is_array($data)) { $data = http_build_query($data); } if ($this->option['method'] == 'POST') { if ($data == '') { $data = $this->__buildPostData(); //http_build_query($this->postdata); } $this->option['content'] = $data; if (!isset($this->httpheader['Content-Type'])) { if ($this->__isBinary) { $this->httpheader['Content-Type'] = 'Content-Type: multipart/form-data; boundary=' . $this->__boundary; } else { $this->httpheader['Content-Type'] = 'Content-Type: application/x-www-form-urlencoded'; } } $this->httpheader['Content-Length'] = 'Content-Length: ' . strlen($data); } $this->httpheader[] = 'Host: ' . $this->parsed_url['host']; //$this->httpheader[] = 'Referer: ' . 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $this->httpheader[] = 'Connection: close'; if (!isset($this->httpheader['Accept'])) { if (isset($_SERVER['HTTP_ACCEPT'])) { $this->httpheader['Accept'] = 'Accept:' . $_SERVER['HTTP_ACCEPT']; } } if (!isset($this->httpheader['Accept-Language'])) { if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $this->httpheader['Accept-Language'] = 'Accept-Language: ' . $_SERVER['HTTP_ACCEPT_LANGUAGE']; } } if ($this->isgzip == true) { $this->httpheader['Accept-Encoding'] = 'Accept-Encoding: gzip'; } $this->option['header'] = implode("\r\n", $this->httpheader); ZBlogException::SuspendErrorHook(); $socket = fsockopen(($this->scheme == 'https' ? 'ssl://' : '') . $this->parsed_url['host'], $this->port, $this->errno, $this->errstr, $this->timeout); ZBlogException::SuspendErrorHook(); if (!$socket) { return; } $url = $this->option['method'] . ' ' . ($this->parsed_url['path'] == '' ? '/' : $this->parsed_url['path']); if (isset($this->parsed_url["query"])) { $url .= "?" . $this->parsed_url["query"]; } fwrite($socket, $url . ' HTTP/1.0' . "\r\n"); fwrite($socket, $this->option['header'] . "\r\n"); fwrite($socket, "\r\n"); if (isset($this->option['content'])) { fwrite($socket, $this->option['content'] . "\r\n"); fwrite($socket, "\r\n"); } while (!feof($socket)) { $this->responseText .= fgets($socket, 128); } $this->responseHeader = substr($this->responseText, 0, strpos($this->responseText, "\r\n\r\n")); $this->responseText = substr($this->responseText, strpos($this->responseText, "\r\n\r\n") + 4); $this->responseHeader = explode("\r\n", $this->responseHeader); $i = $this->maxredirs; if ($this->maxredirs > 0) { if (strstr($this->responseHeader[0], ' 301 ') || strstr($this->responseHeader[0], ' 302 ') || strstr($this->responseHeader[0], ' 303 ') || strstr($this->responseHeader[0], ' 307 ')) { fclose($socket); $url = $this->getResponseHeader('Location'); $this->canreinit = false; $this->open('Get', $url); $this->setMaxRedirs($i - 1); $this->canreinit = true; return $this->send(); } } if ($this->getResponseHeader('Transfer-Encoding') == 'chunked') { if (!function_exists('http_chunked_decode')) { $this->responseText = $this->http_chunked_decode($this->responseText); } else { $this->responseText = http_chunked_decode($this->responseText); } } if ($this->getResponseHeader('Content-Encoding') == 'gzip') { if (!function_exists('gzdecode')) { $this->responseText = $this->gzdecode($this->responseText); } else { $this->responseText = gzdecode($this->responseText); } } if (isset($this->responseHeader[0])) { $this->statusText = $this->responseHeader[0]; $a = explode(' ', $this->statusText); if (isset($a[0])) { $this->responseVersion = $a[0]; } if (isset($a[1])) { $this->status = $a[1]; } unset($this->responseHeader[0]); } fclose($socket); }
/** * @param string $varBody */ public function send($varBody = '') { $data = $varBody; if (is_array($data)) { $data = http_build_query($data); } if ($this->option['method'] == 'POST') { if ($data == '') { $data = $this->__buildPostData(); //http_build_query($this->postdata); } $this->option['content'] = $data; if (!isset($this->httpheader['Content-Type'])) { if ($this->__isBinary) { $this->httpheader['Content-Type'] = 'Content-Type: multipart/form-data; boundary=' . $this->__boundary; } else { $this->httpheader['Content-Type'] = 'Content-Type: application/x-www-form-urlencoded'; } } $this->httpheader['Content-Length'] = 'Content-Length: ' . strlen($data); } $this->option['header'] = implode("\r\n", $this->httpheader); //$this->httpheader[] = 'Referer: ' . 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; if ($this->maxredirs > 0) { $this->option['follow_location'] = 1; $this->option['max_redirects'] = $this->maxredirs; } else { $this->option['follow_location'] = 0; $this->option['max_redirects'] = 0; } ZBlogException::SuspendErrorHook(); $http_response_header = null; $this->responseText = file_get_contents(($this->isgzip == true ? 'compress.zlib://' : '') . $this->url, false, stream_context_create(array('http' => $this->option))); $this->responseHeader = $http_response_header; ZBlogException::ResumeErrorHook(); if (isset($this->responseHeader[0])) { $this->statusText = $this->responseHeader[0]; $a = explode(' ', $this->statusText); if (isset($a[0])) { $this->responseVersion = $a[0]; } if (isset($a[1])) { $this->status = $a[1]; } unset($this->responseHeader[0]); } }
/** * 解开应用包 * @param $xml * @return bool */ public static function UnPack($xml) { global $zbp; $xml = simplexml_load_string($xml); if (!$xml) { return false; } if ($xml['version'] != 'php') { return false; } $type = $xml['type']; $id = $xml->id; $dir = $zbp->path . 'zb_users/' . $type . '/'; ZBlogException::SuspendErrorHook(); if (!file_exists($dir . $id . '/')) { @mkdir($dir . $id . '/', 0755, true); } foreach ($xml->folder as $folder) { $f = $dir . $folder->path; if (!file_exists($f)) { @mkdir($f, 0755, true); } } foreach ($xml->file as $file) { $s = base64_decode($file->stream); $f = $dir . $file->path; @file_put_contents($f, $s); if (function_exists('chmod')) { @chmod($f, 0755); } } ZBlogException::ResumeErrorHook(); return true; }
/** * 通过URL获取远程页面内容 * @param string $url URL地址 * @return string 返回页面文本内容,默认为null */ function GetHttpContent($url) { if (class_exists('Network')) { $ajax = Network::Create(); if (!$ajax) { return null; } $ajax->open('GET', $url); $ajax->enableGzip(); $ajax->setTimeOuts(60, 60, 0, 0); $ajax->send(); if ($ajax->status == 200) { return $ajax->responseText; } else { return null; } } $r = null; if (function_exists("curl_init") && function_exists('curl_exec')) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); if (ini_get("safe_mode") == false && ini_get("open_basedir") == false) { curl_setopt($ch, CURLOPT_MAXREDIRS, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); } if (extension_loaded('zlib')) { curl_setopt($ch, CURLOPT_ENCODING, 'gzip'); } $r = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($code == 200) { return $r; } } elseif (ini_get("allow_url_fopen")) { ZBlogException::SuspendErrorHook(); $http_response_header = null; $r = file_get_contents((extension_loaded('zlib') ? 'compress.zlib://' : '') . $url); if (is_array($http_response_header) && in_array('HTTP/1.1 200 OK', $http_response_header)) { if ($r !== false) { return $r; } } ZBlogException::ResumeErrorHook(); } return null; }
public static function EnableFull() { self::$isfull = true; }
public static function EnableWarning() { self::$iswarning = true; }
/** * 显示错误信息 * @api Filter_Plugin_Zbp_ShowError * @param $idortext * @param null $file * @param null $line * @return mixed * @throws Exception */ public function ShowError($idortext, $file = null, $line = null) { if ((int) $idortext == 2) { Http404(); } ZBlogException::$error_id = (int) $idortext; ZBlogException::$error_file = $file; ZBlogException::$error_line = $line; if (is_numeric($idortext)) { $idortext = $this->lang['error'][$idortext]; } foreach ($GLOBALS['hooks']['Filter_Plugin_Zbp_ShowError'] as $fpname => &$fpsignal) { $fpsignal = PLUGIN_EXITSIGNAL_NONE; $fpreturn = $fpname($idortext, $file, $line); if ($fpsignal == PLUGIN_EXITSIGNAL_RETURN) { return $fpreturn; } } throw new Exception($idortext); }
/** * register_shutdown_function * @return true */ function api_shutdown_error_handler() { if ($error = error_get_last()) { //ob_clean(); $zbe = ZBlogException::GetInstance(); $zbe->ParseShutdown($error); //Http500(); api_format_exception($zbe); } }
public function Display() { #强制撤除所有错误监控 if ($GLOBALS['option']['ZC_DEBUG_MODE'] == false) { ZBlogException::ClearErrorHook(); } #入口处将tags里的变量提升全局!!! foreach ($this->tags as $key => &$value) { ${$key} =& $value; } include $this->path . $this->templatename . '.php'; }