/** * 解开应用包 * @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; }
/** * @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]); } }
/** * 通过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; }