예제 #1
0
 public function finish()
 {
     foreach ($this->partList as $key => $partName) {
         $f = new File(Path::combine($this->getDirectoryName(), $partName));
         $f->rename(str_replace($this->getPrefix(), '', $f->getPath()));
         $this->partList[$key] = $f->getName();
     }
     if ($this->isCurrentPartNotEmpty()) {
         $this->addFooter();
         $this->rename(str_replace($this->getPrefix(), '', $this->getPath()));
     }
 }
예제 #2
0
 /**
  * Updates cache usage statistics.
  * Each of parameters is added to appropriate existing stats.
  *
  * @param int $hit
  * @param int $miss
  * @param int $quota
  * @param int $posts
  * @param float $files
  * @return void
  */
 public function writeStatistic($hit = 0, $miss = 0, $quota = 0, $posts = 0, $files = 0.0)
 {
     $fileValues = $this->readStatistic();
     if ($fileValues) {
         $newValues = array(intval($fileValues["HITS"]) + $hit, intval($fileValues["MISSES"]) + $miss, intval($fileValues["QUOTA"]) + $quota, intval($fileValues["POSTS"]) + $posts, $files === false ? 0 : doubleval($fileValues["FILE_SIZE"]) + doubleval($files));
         $this->statFile->putContents(implode(",", $newValues));
     }
 }
예제 #3
0
 function renderExceptionMessage(\Exception $exception, $debug = false)
 {
     if ($debug) {
         echo ExceptionHandlerFormatter::format($exception, true);
     } else {
         $p = Main\IO\Path::convertRelativeToAbsolute("/error.php");
         if (Main\IO\File::isFileExists($p)) {
             include $p;
         } else {
             $context = Main\Application::getInstance();
             if ($context) {
                 echo Main\Localization\Loc::getMessage("eho_render_exception_message");
             } else {
                 echo "A error occurred during execution of this script. You can turn on extended error reporting in .settings.php file.";
             }
         }
     }
 }
예제 #4
0
 private function reindexFile($siteId, $rootPath, $path, $maxFileSize = 0)
 {
     $pathAbs = IO\Path::combine($rootPath, $path);
     if (!UrlRewriter::checkPath($pathAbs)) {
         return 0;
     }
     $file = new IO\File($pathAbs);
     if ($maxFileSize > 0 && $file->getFileSize() > $maxFileSize * 1024) {
         return 0;
     }
     $fileSrc = $file->getContents();
     if (!$fileSrc || $fileSrc == "") {
         return 0;
     }
     $arComponents = \PHPParser::parseScript($fileSrc);
     for ($i = 0, $cnt = count($arComponents); $i < $cnt; $i++) {
         Component\ParametersTable::add(array('SITE_ID' => $siteId, 'COMPONENT_NAME' => $arComponents[$i]["DATA"]["COMPONENT_NAME"], 'TEMPLATE_NAME' => $arComponents[$i]["DATA"]["TEMPLATE_NAME"], 'REAL_PATH' => $path, 'SEF_MODE' => $arComponents[$i]["DATA"]["PARAMS"]["SEF_MODE"] == "Y" ? Component\ParametersTable::SEF_MODE : Component\ParametersTable::NOT_SEF_MODE, 'SEF_FOLDER' => $arComponents[$i]["DATA"]["PARAMS"]["SEF_MODE"] == "Y" ? $arComponents[$i]["DATA"]["PARAMS"]["SEF_FOLDER"] : null, 'START_CHAR' => $arComponents[$i]["START"], 'END_CHAR' => $arComponents[$i]["END"], 'PARAMETERS' => serialize($arComponents[$i]["DATA"]["PARAMS"])));
         if ($arComponents[$i]["DATA"]["PARAMS"]["SEF_MODE"] == "Y") {
             $arFields = array("CONDITION" => "#^" . $arComponents[$i]["DATA"]["PARAMS"]["SEF_FOLDER"] . "#", "RULE" => "", "ID" => $arComponents[$i]["DATA"]["COMPONENT_NAME"], "PATH" => $path, "SORT" => self::DEFAULT_SORT);
             UrlRewriter::add($siteId, $arFields);
         }
     }
     return true;
 }
예제 #5
0
 protected function sendToEventHandler(array $handler, Event $event)
 {
     try {
         $result = true;
         $event->addDebugInfo($handler);
         if (isset($handler["TO_MODULE_ID"]) && !empty($handler["TO_MODULE_ID"]) && $handler["TO_MODULE_ID"] != 'main') {
             $result = Loader::includeModule($handler["TO_MODULE_ID"]);
         } elseif (isset($handler["TO_PATH"]) && !empty($handler["TO_PATH"])) {
             $path = ltrim($handler["TO_PATH"], "/");
             if (($path = Loader::getLocal($path)) !== false) {
                 $result = (include_once $path);
             }
         } elseif (isset($handler["FULL_PATH"]) && !empty($handler["FULL_PATH"]) && IO\File::isFileExists($handler["FULL_PATH"])) {
             $result = (include_once $handler["FULL_PATH"]);
         }
         $event->addDebugInfo($result);
         if (isset($handler["TO_METHOD_ARG"]) && is_array($handler["TO_METHOD_ARG"]) && !empty($handler["TO_METHOD_ARG"])) {
             $args = $handler["TO_METHOD_ARG"];
         } else {
             $args = array();
         }
         if ($handler["VERSION"] > 1) {
             $args[] = $event;
         } else {
             $args = array_merge($args, array_values($event->getParameters()));
         }
         $callback = null;
         if (isset($handler["CALLBACK"])) {
             $callback = $handler["CALLBACK"];
         } elseif (!empty($handler["TO_CLASS"]) && !empty($handler["TO_METHOD"]) && class_exists($handler["TO_CLASS"])) {
             $callback = array($handler["TO_CLASS"], $handler["TO_METHOD"]);
         }
         if ($callback != null) {
             $result = call_user_func_array($callback, $args);
         }
         if ($result != null && !$result instanceof EventResult) {
             $result = new EventResult(EventResult::UNDEFINED, $result, $handler["TO_MODULE_ID"]);
         }
         $event->addDebugInfo($result);
         if ($result != null) {
             $event->addResult($result);
         }
     } catch (\Exception $ex) {
         if ($event->isDebugOn()) {
             $event->addException($ex);
         } else {
             throw $ex;
         }
     }
 }
예제 #6
0
function seoSitemapGetFilesData($PID, $arSitemap, $arCurrentDir, $sitemapFile)
{
	global $NS;

	$arDirList = array();

	if($arCurrentDir['ACTIVE'] == SitemapRuntimeTable::ACTIVE)
	{
		$list = \CSeoUtils::getDirStructure(
			$arSitemap['SETTINGS']['logical'] == 'Y',
			$arSitemap['SITE_ID'],
			$arCurrentDir['ITEM_PATH']
		);

		foreach($list as $dir)
		{
			$dirKey = "/".ltrim($dir['DATA']['ABS_PATH'], "/");

			if($dir['TYPE'] == 'F')
			{
				if(!isset($arSitemap['SETTINGS']['FILE'][$dirKey])
					|| $arSitemap['SETTINGS']['FILE'][$dirKey] == 'Y')
				{
					if(preg_match($arSitemap['SETTINGS']['FILE_MASK_REGEXP'], $dir['FILE']))
					{
						$f = new IO\File($dir['DATA']['PATH'], $arSitemap['SITE_ID']);
						$sitemapFile->addFileEntry($f);
						$NS['files_count']++;
					}
				}
			}
			else
			{
				if(!isset($arSitemap['SETTINGS']['DIR'][$dirKey])
					|| $arSitemap['SETTINGS']['DIR'][$dirKey] == 'Y')
				{
					$arDirList[] = $dirKey;
				}
			}
		}
	}
	else
	{
		$len = strlen($arCurrentDir['ITEM_PATH']);
		if(!empty($arSitemap['SETTINGS']['DIR']))
		{
			foreach($arSitemap['SETTINGS']['DIR'] as $dirKey => $checked)
			{
				if($checked == 'Y')
				{
					if(strncmp($arCurrentDir['ITEM_PATH'], $dirKey, $len) === 0)
					{
						$arDirList[] = $dirKey;
					}
				}
			}
		}

		if(!empty($arSitemap['SETTINGS']['FILE']))
		{
			foreach($arSitemap['SETTINGS']['FILE'] as $dirKey => $checked)
			{
				if($checked == 'Y')
				{
					if(strncmp($arCurrentDir['ITEM_PATH'], $dirKey, $len) === 0)
					{
						$fileName = IO\Path::combine(
							SiteTable::getDocumentRoot($arSitemap['SITE_ID']),
							$dirKey
						);

						if(!is_dir($fileName))
						{
							$f = new IO\File($fileName, $arSitemap['SITE_ID']);
							if($f->isExists()
								&& !$f->isSystem()
								&& preg_match($arSitemap['SETTINGS']['FILE_MASK_REGEXP'], $f->getName())
							)
							{
								$sitemapFile->addFileEntry($f);
								$NS['files_count']++;
							}
						}
					}
				}
			}
		}
	}

	if(count($arDirList) > 0)
	{
		foreach($arDirList as $dirKey)
		{
			$arRuntimeData = array(
				'PID' => $PID,
				'ITEM_PATH' => $dirKey,
				'PROCESSED' => SitemapRuntimeTable::UNPROCESSED,
				'ACTIVE' => SitemapRuntimeTable::ACTIVE,
				'ITEM_TYPE' => SitemapRuntimeTable::ITEM_TYPE_DIR,
			);
			SitemapRuntimeTable::add($arRuntimeData);
		}
	}

	SitemapRuntimeTable::update($arCurrentDir['ID'], array(
		'PROCESSED' => SitemapRuntimeTable::PROCESSED
	));
}
예제 #7
0
 public function __construct($siteId)
 {
     $this->siteId = $siteId;
     $this->documentRoot = SiteTable::getDocumentRoot($this->siteId);
     parent::__construct(IO\Path::combine($this->documentRoot, self::ROBOTS_FILE_NAME));
 }
예제 #8
0
 protected function getFileUrl(File $f)
 {
     static $arIndexNames;
     if (!is_array($arIndexNames)) {
         $arIndexNames = GetDirIndexArray();
     }
     if (substr($this->path, 0, strlen($this->documentRoot)) === $this->documentRoot) {
         $path = '/' . substr($f->getPath(), strlen($this->documentRoot));
     }
     $path = Path::convertLogicalToUri($path);
     $path = in_array($f->getName(), $arIndexNames) ? str_replace('/' . $f->getName(), '/', $path) : $path;
     return '/' . ltrim($path, '/');
 }
예제 #9
0
 /**
  * Downloads and saves a file.
  *
  * @param string $url URI to download
  * @param string $filePath Absolute file path
  * @return bool
  */
 public function download($url, $filePath)
 {
     $dir = IO\Path::getDirectory($filePath);
     IO\Directory::createDirectory($dir);
     $file = new IO\File($filePath);
     $handler = $file->open("w+");
     if ($handler !== false) {
         $this->setOutputStream($handler);
         $res = $this->query(self::HTTP_GET, $url);
         fclose($handler);
         return $res;
     }
     return false;
 }