Beispiel #1
0
 public function getRequestedPageDirectory()
 {
     if ($this->requestedFileDirectory != null) {
         return $this->requestedFileDirectory;
     }
     $requestedFile = $this->getRequestedPage();
     return $this->requestedFileDirectory = IO\Path::getDirectory($requestedFile);
 }
Beispiel #2
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()));
     }
 }
Beispiel #3
0
 public static function getCurrentTemplateId($siteId)
 {
     $cacheFlags = Config\Configuration::getValue("cache_flags");
     $ttl = isset($cacheFlags["site_template"]) ? $cacheFlags["site_template"] : 0;
     $connection = Application::getConnection();
     $sqlHelper = $connection->getSqlHelper();
     $field = $connection->getType() === "mysql" ? "`CONDITION`" : "CONDITION";
     $path2templates = IO\Path::combine(Application::getDocumentRoot(), Application::getPersonalRoot(), "templates");
     if ($ttl === false) {
         $sql = "\n\t\t\t\tSELECT " . $field . ", TEMPLATE\n\t\t\t\tFROM b_site_template\n\t\t\t\tWHERE SITE_ID = '" . $sqlHelper->forSql($siteId) . "'\n\t\t\t\tORDER BY IF(LENGTH(" . $field . ") > 0, 1, 2), SORT\n\t\t\t\t";
         $recordset = $connection->query($sql);
         while ($record = $recordset->fetch()) {
             $condition = trim($record["CONDITION"]);
             if ($condition != '' && !@eval("return " . $condition . ";")) {
                 continue;
             }
             if (IO\Directory::isDirectoryExists($path2templates . "/" . $record["TEMPLATE"])) {
                 return $record["TEMPLATE"];
             }
         }
     } else {
         $managedCache = Application::getInstance()->getManagedCache();
         if ($managedCache->read($ttl, "b_site_template")) {
             $arSiteTemplateBySite = $managedCache->get("b_site_template");
         } else {
             $arSiteTemplateBySite = array();
             $sql = "\n\t\t\t\t\tSELECT " . $field . ", TEMPLATE, SITE_ID\n\t\t\t\t\tFROM b_site_template\n\t\t\t\t\tWHERE SITE_ID = '" . $sqlHelper->forSql($siteId) . "'\n\t\t\t\t\tORDER BY SITE_ID, IF(LENGTH(" . $field . ") > 0, 1, 2), SORT\n\t\t\t\t\t";
             $recordset = $connection->query($sql);
             while ($record = $recordset->fetch()) {
                 $arSiteTemplateBySite[$record['SITE_ID']][] = $record;
             }
             $managedCache->set("b_site_template", $arSiteTemplateBySite);
         }
         if (is_array($arSiteTemplateBySite[$siteId])) {
             foreach ($arSiteTemplateBySite[$siteId] as $record) {
                 $condition = trim($record["CONDITION"]);
                 if ($condition != '' && !@eval("return " . $condition . ";")) {
                     continue;
                 }
                 if (IO\Directory::isDirectoryExists($path2templates . "/" . $record["TEMPLATE"])) {
                     return $record["TEMPLATE"];
                 }
             }
         }
     }
     return ".default";
 }
 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.";
             }
         }
     }
 }
Beispiel #5
0
 public static function getDocumentRoot($siteId = null)
 {
     if ($siteId === null) {
         $context = Application::getInstance()->getContext();
         $siteId = $context->getSite();
     }
     if (!isset(self::$documentRootCache[$siteId])) {
         $ar = SiteTable::getRow(array("filter" => array("LID" => $siteId)));
         if ($ar && ($docRoot = $ar["DOC_ROOT"]) && strlen($docRoot) > 0) {
             if (!IO\Path::isAbsolute($docRoot)) {
                 $docRoot = IO\Path::combine(Application::getDocumentRoot(), $docRoot);
             }
             self::$documentRootCache[$siteId] = $docRoot;
         } else {
             self::$documentRootCache[$siteId] = Application::getDocumentRoot();
         }
     }
     return self::$documentRootCache[$siteId];
 }
Beispiel #6
0
 private static function checkPath($path)
 {
     static $searchMasksCache = false;
     if (is_array($searchMasksCache)) {
         $arExc = $searchMasksCache["exc"];
         $arInc = $searchMasksCache["inc"];
     } else {
         $arExc = array();
         $arInc = array();
         $inc = Config\Option::get("main", "urlrewrite_include_mask", "*.php");
         $inc = str_replace("'", "\\'", str_replace("*", ".*?", str_replace("?", ".", str_replace(".", "\\.", str_replace("\\", "/", $inc)))));
         $arIncTmp = explode(";", $inc);
         foreach ($arIncTmp as $preg_mask) {
             if (strlen(trim($preg_mask)) > 0) {
                 $arInc[] = "'^" . trim($preg_mask) . "\$'";
             }
         }
         $exc = Config\Option::get("main", "urlrewrite_exclude_mask", "/freetrix/*;");
         $exc = str_replace("'", "\\'", str_replace("*", ".*?", str_replace("?", ".", str_replace(".", "\\.", str_replace("\\", "/", $exc)))));
         $arExcTmp = explode(";", $exc);
         foreach ($arExcTmp as $preg_mask) {
             if (strlen(trim($preg_mask)) > 0) {
                 $arExc[] = "'^" . trim($preg_mask) . "\$'";
             }
         }
         $searchMasksCache = array("exc" => $arExc, "inc" => $arInc);
     }
     $file = IO\Path::getName($path);
     if (substr($file, 0, 1) === ".") {
         return 0;
     }
     foreach ($arExc as $preg_mask) {
         if (preg_match($preg_mask, $path)) {
             return false;
         }
     }
     foreach ($arInc as $preg_mask) {
         if (preg_match($preg_mask, $path)) {
             return true;
         }
     }
     return false;
 }
Beispiel #7
0
 /**
  * Reads the configuration.
  *
  * @return array
  */
 public function includeConfiguration()
 {
     if (!isset($this->options)) {
         $arHTMLPagesOptions = array();
         $configurationPath = Main\IO\Path::convertRelativeToAbsolute(Main\Application::getPersonalRoot() . "/html_pages/.config.php");
         if (file_exists($configurationPath)) {
             include $configurationPath;
         }
         $this->options = $arHTMLPagesOptions;
     }
     return $this->options;
 }
Beispiel #8
0
				case 'site_verify':
					$res = array('error' => 'Unknown domain');

					if(is_array($arDomain))
					{
						$siteInfo = $engine->getSiteInfo($arDomain['DOMAIN'], $arDomain['SITE_DIR']);
						if($siteInfo[$arDomain['DOMAIN']]['verified'] == 'false')
						{
							$filename = $siteInfo[$arDomain['DOMAIN']]['verification-method']['file-name'];

							// paranoia?
							$filename = preg_replace("/^(.*?)\..*$/", "\\1.html", $filename);

							$path = Path::combine((
								strlen($arDomain['SITE_DOC_ROOT']) > 0
									? $arDomain['SITE_DOC_ROOT']
									: $_SERVER['DOCUMENT_ROOT']
								), $arDomain['SITE_DIR'], $filename);

							$obFile = new \Freetrix\Main\IO\File($path);
							$obFile->putContents($siteInfo[$arDomain['DOMAIN']]['verification-method']['file-content']);

							$res = $engine->verifySite($arDomain['DOMAIN'], $arDomain['SITE_DIR']);

							$obFile->delete();

							$res = $engine->getFeeds();

							$res['_domain'] = $arDomain['DOMAIN'];
						}
						elseif($siteInfo[$arDomain['DOMAIN']]['verified'] == 'true')
Beispiel #9
0
 private static function loadLazy($code, $language)
 {
     if ($code == '') {
         return;
     }
     $trace = Main\Diag\Helper::getBackTrace(4, DEBUG_BACKTRACE_IGNORE_ARGS);
     $currentFile = null;
     for ($i = 3; $i >= 1; $i--) {
         if (stripos($trace[$i]["function"], "GetMessage") === 0) {
             $currentFile = Path::normalize($trace[$i]["file"]);
             break;
         }
     }
     if ($currentFile !== null && isset(self::$lazyLoadFiles[$currentFile])) {
         //in most cases we know the file containing the "code" - load it directly
         self::loadLanguageFile($currentFile, $language);
         unset(self::$lazyLoadFiles[$currentFile]);
     }
     if (!isset(self::$messages[$language][$code])) {
         //we still don't know which file contains the "code" - go through the files in the reverse order
         $unset = array();
         if (($file = end(self::$lazyLoadFiles)) !== false) {
             do {
                 self::loadLanguageFile($file, $language);
                 $unset[] = $file;
                 if (isset(self::$messages[$language][$code])) {
                     if (defined("FX_MESS_LOG") && $currentFile !== null) {
                         file_put_contents(FX_MESS_LOG, 'CTranslateUtils::CopyMessage("' . $code . '", "' . $file . '", "' . $currentFile . '");' . "\n", FILE_APPEND);
                     }
                     break;
                 }
             } while (($file = prev(self::$lazyLoadFiles)) !== false);
         }
         foreach ($unset as $file) {
             unset(self::$lazyLoadFiles[$file]);
         }
     }
 }
Beispiel #10
0
function seo_getDir($bLogical, $site_id, $dir, $depth, $checked, $arChecked = array())
{
	if(!is_array($arChecked))
		$arChecked = array();

	$arDirs = \CSeoUtils::getDirStructure($bLogical, $site_id, $dir);
	if(count($arDirs) > 0)
	{
		foreach ($arDirs as $arDir)
		{
			$d = Main\IO\Path::combine($dir,$arDir['FILE']);

			$bChecked = $arChecked[$d] === 'Y' || $checked && $arChecked[$d] !== 'N';

			$d = Converter::getHtmlConverter()->encode($d);
			$r = RandString(8);

			$varName = $arDir['TYPE'] == 'D' ? 'DIR' : 'FILE';
?>
<div class="sitemap-dir-item">
<?
			if($arDir['TYPE']=='D'):
?>
	<span onclick="loadDir(<?php 
echo $bLogical ? 'true' : 'false';
?>
, this, '<?php 
echo CUtil::JSEscape($d);
?>
', '<?php 
echo $r;
?>
', '<?php 
echo $depth + 1;
?>
', BX('DIR_<?php 
echo $d;
?>
').checked)" class="sitemap-tree-icon"></span><?
			endif;
?><span class="sitemap-dir-item-text">
		<input type="hidden" name="<?php 
echo $varName;
?>
[<?php 
echo $d;
?>
]" value="N" />
		<input type="checkbox" name="<?php 
echo $varName;
?>
[<?php 
echo $d;
?>
]" id="DIR_<?php 
echo $d;
?>
"<?php 
echo $bChecked ? ' checked="checked"' : '';
?>
 value="Y" onclick="checkAll('<?php 
echo $r;
?>
', this.checked);" />
		<label for="DIR_<?php 
echo $d;
?>
"><?php 
echo Converter::getHtmlConverter()->encode($arDir['NAME'] . ($bLogical ? ' (' . $arDir['FILE'] . ')' : ''));
?>
</label>
	</span>
	<div id="subdirs_<?php 
echo $r;
?>
" class="sitemap-dir-item-children"></div>
</div>
<?
		}
	}
	else
	{
		echo $space.Loc::getMessage('SEO_SITEMAP_NO_DIRS_FOUND');
	}
}
Beispiel #11
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
	));
}
Beispiel #12
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, '/');
 }
Beispiel #13
0
	public static function OnChangeFile($path, $site)
	{
		$pagesDir = new IO\Directory(IO\Path::convertRelativeToAbsolute(Application::getPersonalRoot()."/html_pages"));
		if (!$pagesDir->isExists())
		{
			return;
		}

		$bytes = 0.0;
		$domainDirs = $pagesDir->getChildren();
		$cachedFile = \Freetrix\Main\Data\StaticHtmlCache::convertUriToPath($path);
		foreach ($domainDirs as $domainDir)
		{
			if ($domainDir->isDirectory())
			{
				$bytes += self::deleteRecursive("/".$domainDir->getName().$cachedFile);
			}
		}

		self::updateQuota(-$bytes);
	}
Beispiel #14
0
 protected function convertToPath($path)
 {
     $p = strpos($path, "?");
     if ($p !== false) {
         $path = substr($path, 0, $p);
     }
     if (substr($path, -1, 1) === "/") {
         $path .= "index.php";
     }
     $path = IO\Path::normalize($path);
     return $path;
 }
Beispiel #15
0
 public function rename($newPath)
 {
     $newPathNormalized = Path::normalize($newPath);
     $success = true;
     if ($this->isExists()) {
         $success = rename($this->getPhysicalPath(), Path::convertLogicalToPhysical($newPathNormalized));
     }
     if ($success) {
         $this->originalPath = $newPath;
         $this->path = $newPathNormalized;
         $this->pathPhysical = null;
     }
     return $success;
 }
Beispiel #16
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));
 }
Beispiel #17
0
 /**
  * Search connection parameters (type, host, db, login and password) by connection name
  *
  * @param string $name Connection name
  * @return array('type' => string, 'host' => string, 'db_name' => string, 'login' => string, 'password' => string, "init_command" => string, "options" => string)|null
  * @throws \Freetrix\Main\ArgumentTypeException
  * @throws \Freetrix\Main\ArgumentNullException
  */
 private function searchConnectionParametersByName($name)
 {
     if (!is_string($name)) {
         throw new \Freetrix\Main\ArgumentTypeException("name", "string");
     }
     if ($name === "") {
         throw new \Freetrix\Main\ArgumentNullException("name");
     }
     if ($name === self::DEFAULT_CONNECTION) {
         $v = \Freetrix\Main\Config\Configuration::getValue(self::DEFAULT_CONNECTION_CONFIGURATION);
         if ($v != null) {
             return $v;
         }
         $DBType = "";
         $DBHost = "";
         $DBName = "";
         $DBLogin = "";
         $DBPassword = "";
         include \Freetrix\Main\IO\Path::convertRelativeToAbsolute("/freetrix/php_interface/dbconn.php");
         return array("type" => $DBType, "host" => $DBHost, "db_name" => $DBName, "login" => $DBLogin, "password" => $DBPassword);
     }
     /* TODO: реализовать */
     return null;
 }
Beispiel #18
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;
 }