Example #1
0
 /**
  * @param Uri $uri
  * @return array
  */
 protected static function getParserChain(Uri $uri)
 {
     $result = array();
     if (isset(static::$metadataParsersByHost[$uri->getHost()])) {
         $result[] = static::$metadataParsersByHost[$uri->getHost()];
     }
     $result = array_merge($result, static::$metadataParsers);
     return $result;
 }
Example #2
0
 /**
  * Returns true if document's site is allowed to be embedded.
  * @return bool
  */
 protected function isEmbeddingAllowed()
 {
     $result = false;
     $domainNameParts = explode('.', $this->uri->getHost());
     if (is_array($domainNameParts) && ($partsCount = count($domainNameParts)) >= 2) {
         $domainName = $domainNameParts[$partsCount - 2] . '.' . $domainNameParts[$partsCount - 1];
         $result = in_array($domainName, $this->hostsAllowedToEmbed);
     }
     return $result;
 }
Example #3
0
 /**
  * Checks file params
  * @param $file
  * @param $arFile
  * @return mixed|null|string
  */
 protected function checkFile($file, &$arFile)
 {
     $status = new Status("checked");
     if ($file["error"] > 0) {
         $status = new Error("BXU347.2", $file["error"]);
     } else {
         if (array_key_exists("tmp_url", $file)) {
             $url = new Uri($file["tmp_url"]);
             if ($url->getHost() == '' && ($tmp = \CFile::MakeFileArray($url->getPath())) && is_array($tmp)) {
                 $file = array_merge($tmp, $file);
             } else {
                 if ($url->getHost() != '' && $this->http->query("HEAD", $file["tmp_url"]) && $this->http->getStatus() == "200") {
                     $file = array_merge($file, array("size" => (int) $this->http->getHeaders()->get("content-length"), "type" => $this->http->getHeaders()->get("content-type")));
                 } else {
                     $status = new Error("BXU347.2");
                 }
             }
         } else {
             if (!is_uploaded_file($file['tmp_name']) || !file_exists($file['tmp_name'])) {
                 $status = new Error("BXU347.2");
             }
         }
     }
     if ($status instanceof Error) {
         //
     } elseif ($this->params["allowUpload"] == "I") {
         $error = \CFile::CheckFile($file, $this->params["uploadMaxFilesize"], "image/", \CFile::GetImageExtensions());
         if (!empty($error)) {
             $status = new Error("BXU347.3", $error);
         }
     } elseif ($this->params["allowUpload"] == "F") {
         $error = \CFile::CheckFile($file, $this->params["uploadMaxFilesize"], false, $this->params["allowUploadExt"]);
         if (!empty($error)) {
             $status = new Error("BXU347.3", $error);
         }
     } else {
         $error = \CFile::CheckFile($file, $this->params["uploadMaxFilesize"]);
         if (!empty($error)) {
             $status = new Error("BXU347.3", $error);
         }
     }
     if ($status instanceof Status) {
         $matches = array();
         $name = $file["~name"];
         if (preg_match("/^(.+?)\\.ch(\\d+)\\.(\\d+)\\.chs(\\d+)\$/", $file["~name"], $matches)) {
             $name = $matches[1];
         }
         $key = !empty($name) ? $name : 'default';
         $file["copy"] = $key;
         if (empty($matches)) {
             $arFile["files"][$key] = $file;
         } else {
             $fileAddInfo = array("chunks" => array(), "chunksInfo" => array("count" => $matches[4], "uploaded" => array(), "written" => array()));
             if (array_key_exists($key, $arFile["files"])) {
                 $fileAddInfo = $arFile["files"][$key];
             }
             $file["status"] = "inprogress";
             $file["number"] = $matches[2];
             $file["start"] = $matches[3];
             $fileAddInfo["chunks"][self::getChunkKey($fileAddInfo["chunksInfo"]["count"], $file["number"])] = $file;
             $arFile["files"][$key] = $fileAddInfo;
         }
     }
     return $status;
 }
Example #4
0
 protected function sendRequest($method, Uri $url, $postData = null)
 {
     $this->status = 0;
     $this->result = '';
     $this->responseHeaders->clear();
     $this->responseCookies->clear();
     if ($this->proxyHost != '') {
         $path = $url->getUrl();
         if ($this->proxyUser != '') {
             $this->setHeader("Proxy-Authorization", "Basic " . base64_encode($this->proxyUser . ":" . $this->proxyPassword));
         }
     } else {
         $path = $url->getPathQuery();
     }
     $request = $method . " " . $path . " HTTP/" . $this->version . "\r\n";
     $this->setHeader("Host", $url->getHost());
     $this->setHeader("Connection", "close", false);
     $this->setHeader("Accept", "*/*", false);
     $this->setHeader("Accept-Language", "en", false);
     if (($user = $url->getUser()) != '') {
         $this->setAuthorization($user, $url->getPass());
     }
     $cookies = $this->requestCookies->toString();
     if ($cookies != '') {
         $this->setHeader("Cookie", $cookies);
     }
     if ($this->compress) {
         $this->setHeader("Accept-Encoding", "gzip");
     }
     if (!is_resource($postData) && ($method == self::HTTP_POST || $method == self::HTTP_PUT)) {
         if ($method != self::HTTP_PUT && $this->requestHeaders->get("Content-Type") === null) {
             $contentType = "application/x-www-form-urlencoded";
             if ($this->requestCharset != '') {
                 $contentType .= "; charset=" . $this->requestCharset;
             }
             $this->setHeader("Content-Type", $contentType);
         }
         if ($this->requestHeaders->get("Content-Length") === null) {
             $this->setHeader("Content-Length", String::getBinaryLength($postData));
         }
     }
     $request .= $this->requestHeaders->toString();
     $request .= "\r\n";
     $this->send($request);
     if ($method == self::HTTP_POST || $method == self::HTTP_PUT) {
         if (is_resource($postData)) {
             //PUT data can be file resource
             while (!feof($postData)) {
                 $this->send(fread($postData, self::BUF_POST_LEN));
             }
         } else {
             $this->send($postData);
         }
     }
 }
Example #5
0
 /**
  * Returns the host from the server variable without a port number.
  * @return string
  */
 public function getHttpHost()
 {
     static $host = null;
     if ($host === null) {
         //scheme can be anything, it's used only for parsing
         $url = new Web\Uri("http://" . $this->server->getHttpHost());
         $host = $url->getHost();
         $host = trim($host, "\t\r\n .");
     }
     return $host;
 }
Example #6
0
 public function getHttpHost($raw = true)
 {
     if ($raw) {
         return $this->server->getHttpHost();
     }
     static $host = null;
     if ($host === null) {
         //scheme can be anything, it's used only for parsing
         $scheme = "http://";
         $host = $this->server->getHttpHost();
         $url = new Web\Uri($scheme . $host);
         $host = $url->getHost();
         $host = trim($host, "\t\r\n .");
     }
     return $host;
 }
Example #7
0
 /**
  * If provided url does not contain scheme part, tries to add it
  *
  * @param string $url URL to be fixed.
  * @return string Fixed URL.
  */
 protected static function normalizeUrl($url)
 {
     if (!preg_match('#^https?://#i', $url)) {
         $url = 'http://' . $url;
     }
     $parsedUrl = new Uri($url);
     $parsedUrl->setHost(strtolower($parsedUrl->getHost()));
     return $parsedUrl->getUri();
 }