Exemplo n.º 1
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.º 2
0
	public function addSite($domain, $dir = '/')
	{
		$domain = ToLower($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->query(
				$this->arServiceList[self::HOSTS_SERVICE],
				"POST",
				sprintf($str, Converter::getXmlConverter()->encode($domain))
			);

			if($queryResult->status == self::HTTP_STATUS_CREATED && strlen($queryResult->result) > 0)
			{
				return array($domain => true);
			}
			else
			{
				throw new Engine\YandexException($queryResult);
			}
		}
	}
Exemplo n.º 3
0
 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);
         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 = '/')
	{
		$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);
		}
	}