Exemplo n.º 1
0
 public function appendEntry($entry)
 {
     if ($this->isSplitNeeded()) {
         $this->split();
         $this->appendEntry($entry);
     } else {
         if (!$this->partChanged) {
             $this->addHeader();
         }
         $fd = $this->open('r+');
         fseek($fd, $this->getSize() - strlen(self::FILE_FOOTER));
         fwrite($fd, sprintf(self::ENTRY_TPL, Converter::getXmlConverter()->encode($entry['XML_LOC']), Converter::getXmlConverter()->encode($entry['XML_LASTMOD']), Converter::getXmlConverter()->encode($entry['XML_PRIORITY'])) . self::FILE_FOOTER);
         fclose($fd);
     }
 }
Exemplo n.º 2
0
 public function appendIndexEntry($file)
 {
     if ($this->isExists()) {
         $fileUrlEnc = Converter::getXmlConverter()->encode($this->settings['PROTOCOL'] . '://' . \CBXPunycode::toASCII($this->settings['DOMAIN'], $e = null) . $this->getFileUrl($file));
         $contents = $this->getContents();
         $reg = "/" . sprintf(preg_quote(self::ENTRY_TPL, "/"), preg_quote($fileUrlEnc, "/"), "[^<]*") . "/";
         $newEntry = sprintf(self::ENTRY_TPL, $fileUrlEnc, date(c, $file->getModificationTime($file)));
         $count = 0;
         $contents = preg_replace($reg, $newEntry, $contents, 1, $count);
         if ($count <= 0) {
             $contents = substr($contents, 0, -strlen(self::FILE_FOOTER)) . $newEntry . self::FILE_FOOTER;
         }
         $this->putContents($contents);
     } else {
         $this->createIndex(array($file));
     }
 }
Exemplo n.º 3
0
	/**
	 * Searches and removes entry to the existing and finished sitemap file
	 *
	 * Entry array keys
	 * XML_LOC - loc field value
	 * XML_LASTMOD - lastmod field value
	 *
	 * @param string $url Entry URL.
	 *
	 * @return void
	 */
	public function removeEntry($url)
	{
		$url = $this->settings['PROTOCOL'].'://'.\CBXPunycode::toASCII($this->settings['DOMAIN'], $e = null).$url;
		$pattern = sprintf(self::ENTRY_TPL_SEARCH, $url);

		while($this->isExists())
		{
			$c = $this->getContents();
			$p = strpos($c, $pattern);
			unset($c);

			if($p !== false)
			{
				$fd = $this->open('r+');

				fseek($fd, intval($p));
				fwrite($fd, str_repeat(" ", strlen(sprintf(
					self::ENTRY_TPL,
					Converter::getXmlConverter()->encode($url),
					Converter::getXmlConverter()->encode(date('c'))
				))));
				fclose($fd);
				break;
			}

			if(!$this->isSplitNeeded())
			{
				break;
			}
			else
			{
				$this->part++;

				$fileName = $this->partFile;
				$fileName = substr($fileName, 0, -strlen(self::FILE_EXT)).self::FILE_PART_SUFFIX.$this->part.substr($fileName, -strlen(self::FILE_EXT));

				$this->reInit($fileName);
			}
		}
	}
Exemplo n.º 4
0
    public function addSite($domain, $dir = '/')
    {
        $domain = ToLower($domain);
        $queryDomain = Context::getCurrent()->getRequest()->isHttps() ? 'https://' . $domain : $domain;
        if (!isset($this->arServiceList[self::HOSTS_SERVICE])) {
            $this->getServiceDocument();
        }
        if (isset($this->arServiceList[self::HOSTS_SERVICE])) {
            $str = <<<EOT
<host><name>%s</name></host>
EOT;
            $queryResult = $this->queryOld($this->arServiceList[self::HOSTS_SERVICE], "POST", sprintf($str, Converter::getXmlConverter()->encode($queryDomain)));
            if ($queryResult->status == self::HTTP_STATUS_CREATED && strlen($queryResult->result) > 0) {
                return array($domain => true);
            } else {
                throw new Engine\YandexException($queryResult);
            }
        }
    }
Exemplo n.º 5
0
    public function addSite($domain, $dir = '/')
    {
        $str = <<<EOT
<atom:entry xmlns:atom='http://www.w3.org/2005/Atom'><atom:content src="%s" /></atom:entry>
EOT;
        $queryResult = $this->queryXml(self::SCOPE_BASE . self::SCOPE_FEED_SITES, "POST", sprintf($str, Converter::getXmlConverter()->encode(self::SCOPE_DOMAIN_PROTOCOL . $domain . $dir)));
        if ($queryResult->status == self::HTTP_STATUS_CREATED && strlen($queryResult->result) > 0) {
            return $this->processResult($queryResult->result);
        } else {
            throw new \Exception('Query error! ' . $queryResult->status . ': ' . $queryResult->result);
        }
    }
Exemplo n.º 6
0
    public function verifySite($domain, $dir)
    {
        $str = <<<EOT
<atom:entry xmlns:atom='http://www.w3.org/2005/Atom' xmlns:wt="http://schemas.google.com/webmasters/tools/2007"><atom:id>%s</atom:id><wt:verification-method type="htmlpage" in-use="true"/></atom:entry>
EOT;
        $queryResult = $this->query($this->getSiteId($domain, $dir), "PUT", sprintf($str, Converter::getXmlConverter()->encode(self::SCOPE_DOMAIN_PROTOCOL . $domain . $dir)));
        if ($queryResult->status == self::HTTP_STATUS_OK && strlen($queryResult->result) > 0) {
            return $this->processResult($queryResult->result);
        } else {
            throw new \Exception('Query error! ' . $queryResult->status . ': ' . $queryResult->result);
        }
    }