Beispiel #1
0
 public function __construct($path, $siteId = null)
 {
     if (empty($path)) {
         throw new InvalidPathException($path);
     }
     $this->originalPath = $path;
     $this->path = Path::normalize($path);
     if ($siteId === null) {
         $this->documentRoot = Main\Application::getDocumentRoot();
     } else {
         $this->documentRoot = Main\SiteTable::getDocumentRoot($siteId);
     }
     if (empty($this->path)) {
         throw new InvalidPathException($path);
     }
 }
Beispiel #2
0
 public function __construct($fileName, $arSettings)
 {
     $this->settings = array('SITE_ID' => $arSettings['SITE_ID'], 'PROTOCOL' => $arSettings['PROTOCOL'] == 'https' ? 'https' : 'http', 'DOMAIN' => $arSettings['DOMAIN']);
     $arSite = SiteTable::getRow(array("filter" => array("LID" => $this->settings['SITE_ID'])));
     $this->siteRoot = Path::combine(SiteTable::getDocumentRoot($this->settings['SITE_ID']), $arSite['DIR']);
     if (substr($fileName, -strlen(self::FILE_EXT)) != self::FILE_EXT) {
         $fileName .= self::FILE_EXT;
     }
     if ($this->partFile == '') {
         $this->partFile = $fileName;
     }
     $this->pathPhysical = null;
     // hack for object reconstuct during file splitting
     parent::__construct($this->siteRoot . '/' . $fileName, $this->settings['SITE_ID']);
     $this->partChanged = $this->isExists();
 }
Beispiel #3
0
 public static function delete($id)
 {
     //We know for sure that languages and sites can refer to the culture.
     //Other entities should place CultureOnBeforeDelete event handler.
     $result = new Entity\DeleteResult();
     $res = LanguageTable::getList(array('filter' => array('=CULTURE_ID' => $id)));
     while ($language = $res->fetch()) {
         $result->addError(new Entity\EntityError(Loc::getMessage("culture_err_del_lang", array("#LID#" => $language["LID"]))));
     }
     $res = \Freetrix\Main\SiteTable::getList(array('filter' => array('=CULTURE_ID' => $id)));
     while ($site = $res->fetch()) {
         $result->addError(new Entity\EntityError(Loc::getMessage("culture_err_del_site", array("#LID#" => $site["LID"]))));
     }
     if (!$result->isSuccess()) {
         return $result;
     }
     return parent::delete($id);
 }
Beispiel #4
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 #5
0
 protected function initializeSite()
 {
     $request = $this->getRequest();
     $currentDirectory = $request->getRequestedPageDirectory();
     $currentDomain = $request->getHttpHost(false);
     $site = SiteTable::getByDomainAndPath($currentDomain, $currentDirectory);
     if ($site === false) {
         $siteList = SiteTable::getList(array('filter' => array('ACTIVE' => 'Y'), 'order' => array('DEF' => 'DESC', 'SORT' => 'ASC'), 'select' => array('*', 'ID' => 'LID')));
         $site = $siteList->fetch();
     }
     if ($site === false) {
         throw new SystemException("Site not found");
     }
     $culture = Context\Culture::wakeUp($site["CULTURE_ID"]);
     if ($culture === null) {
         $culture = new Context\Culture();
     }
     $this->site = new Context\Site($site);
     $this->site->setCulture($culture);
     $this->setContextCulture($culture, $this->site->getLanguage());
 }
Beispiel #6
0
 public static function reindexAll($maxExecutionTime = 0, $ns = array())
 {
     @set_time_limit(0);
     if (!is_array($ns)) {
         $ns = array();
     }
     if ($maxExecutionTime <= 0) {
         $nsOld = $ns;
         $ns = array("CLEAR" => "N", "ID" => "", "FLG" => "", "SESS_ID" => md5(uniqid("")), "max_execution_time" => $nsOld["max_execution_time"], "stepped" => $nsOld["stepped"], "max_file_size" => $nsOld["max_file_size"]);
         if ($nsOld["SITE_ID"] != "") {
             $ns["SITE_ID"] = $nsOld["SITE_ID"];
         }
     }
     $ns["CNT"] = intval($ns["CNT"]);
     $arSites = array();
     $filterRootPath = "";
     $db = SiteTable::getList(array("select" => array("LID", "DOC_ROOT", "DIR"), "filter" => array("ACTIVE" => "Y")));
     while ($ar = $db->fetch()) {
         if (empty($ar["DOC_ROOT"])) {
             $ar["DOC_ROOT"] = Application::getDocumentRoot();
         }
         $arSites[] = array("site_id" => $ar["LID"], "root" => $ar["DOC_ROOT"], "path" => IO\Path::combine($ar["DOC_ROOT"], $ar["DIR"]));
         if ($ns["SITE_ID"] != "" && $ns["SITE_ID"] == $ar["LID"]) {
             $filterRootPath = $ar["DOC_ROOT"];
         }
     }
     if ($ns["SITE_ID"] != "" && !empty($filterRootPath)) {
         $arSitesTmp = array();
         $arKeys = array_keys($arSites);
         foreach ($arKeys as $key) {
             if ($arSites[$key]["root"] == $filterRootPath) {
                 $arSitesTmp[] = $arSites[$key];
             }
         }
         $arSites = $arSitesTmp;
     }
     uasort($arSites, function ($a, $b) {
         $la = strlen($a["path"]);
         $lb = strlen($b["path"]);
         if ($la == $lb) {
             if ($a["site_id"] == $b["site_id"]) {
                 return 0;
             } else {
                 return $a["site_id"] > $b["site_id"] ? -1 : 1;
             }
         }
         return $la > $lb ? -1 : 1;
     });
     if ($ns["CLEAR"] != "Y") {
         $arAlreadyDeleted = array();
         foreach ($arSites as $site) {
             Component\ParametersTable::deleteBySiteId($site["site_id"]);
             if (!in_array($site["root"], $arAlreadyDeleted)) {
                 UrlRewriter::delete($site["site_id"], array("!ID" => ""));
                 $arAlreadyDeleted[] = $site["root"];
             }
         }
     }
     $ns["CLEAR"] = "Y";
     clearstatcache();
     $arAlreadyParsed = array();
     foreach ($arSites as $site) {
         if (in_array($site["root"], $arAlreadyParsed)) {
             continue;
         }
         $arAlreadyParsed[] = $site["root"];
         if ($maxExecutionTime > 0 && !empty($ns["FLG"]) && substr($ns["ID"] . "/", 0, strlen($site["root"] . "/")) != $site["root"] . "/") {
             continue;
         }
         UrlRewriter::recursiveReindex($site["root"], "/", $arSites, $maxExecutionTime, $ns);
         if ($maxExecutionTime > 0 && !empty($ns["FLG"])) {
             return $ns;
         }
     }
     return $ns["CNT"];
 }
Beispiel #7
0
 public static function convertSiteRelativeToAbsolute($relativePath, $site = null)
 {
     if (!is_string($relativePath) || $relativePath == "") {
         $site = SITE_ID;
     }
     $basePath = Main\SiteTable::getDocumentRoot($site);
     return self::combine($basePath, $relativePath);
 }
Beispiel #8
0
 /**
  * Function clears entire component cache.
  *
  * <p>Note: parameters must exactly match to startResultCache call.</p>
  * @param string $componentName
  * @param string $siteId
  * @return void
  *
  */
 public static final function clearComponentCache($componentName, $siteId = "")
 {
     /** @global CCacheManager $CACHE_MANAGER */
     global $CACHE_MANAGER;
     $componentRelativePath = CComponentEngine::MakeComponentPath($componentName);
     if ($componentRelativePath != "") {
         $obCache = new CPHPCache();
         $obCache->CleanDir($componentRelativePath, "cache");
         BXClearCache(true, $componentRelativePath);
         if ($siteId == "") {
             $rsSite = \Freetrix\Main\SiteTable::getList(array('order' => array('SORT' => 'ASC')));
             while ($site = $rsSite->fetch()) {
                 $componentCachePath = "/" . $site["LID"] . $componentRelativePath;
                 $obCache = new CPHPCache();
                 $obCache->CleanDir($componentCachePath, "cache");
                 BXClearCache(true, $componentCachePath);
             }
         } else {
             $componentCachePath = "/" . $siteId . $componentRelativePath;
             $obCache = new CPHPCache();
             $obCache->CleanDir($componentCachePath, "cache");
             BXClearCache(true, $componentCachePath);
         }
         if (defined("FX_COMP_MANAGED_CACHE")) {
             $CACHE_MANAGER->ClearByTag($componentName);
         }
     }
 }
Beispiel #9
0
		while($arRes = $dbRes->fetch())
		{
			if (!is_array($arSitemap['SETTINGS'][$arRes["ENTITY_TYPE"].'_AUTO']))
				$arSitemap['SETTINGS'][$arRes["ENTITY_TYPE"].'_AUTO'] = array();
			$arSitemap['SETTINGS'][$arRes["ENTITY_TYPE"].'_AUTO'][$arRes['ENTITY_ID']] = 'Y';
		}
		if (empty($arSitemap['SETTINGS']['FILENAME_FORUM']))
			$arSitemap['SETTINGS']['FILENAME_FORUM'] = "sitemap_forum_#FORUM_ID#.xml";

		$SITE_ID = $arSitemap['SITE_ID'];
	}
}

if(strlen($SITE_ID) > 0)
{
	$dbSite = Main\SiteTable::getByPrimary($SITE_ID);
	$arSite = $dbSite->fetch();
	if(!is_array($arSite))
	{
		$SITE_ID = '';
	}
	else
	{
		$arSite['DOMAINS'] = array();

		$robotsFile = new RobotsFile($SITE_ID);
		if($robotsFile->isExists())
		{
			$arHostsList = $robotsFile->getRules('Host');
			foreach ($arHostsList as $rule)
			{
Beispiel #10
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 #11
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 #12
0
$arSites = array();

$dbSites = Freetrix\Main\SiteTable::getList(
	array(
		'order' => array('DEF' => 'DESC', 'NAME' => 'ASC'),
		'select' => array('LID', 'NAME', 'DEF', 'DIR', 'DOC_ROOT', 'SERVER_NAME')
	)
);


while($arRes = $dbSites->fetch(Converter::getHtmlConverter()))
{
	if($arRes['DOC_ROOT'] == '')
	{
		$arRes['DOC_ROOT'] = Converter::getHtmlConverter()->encode(
			Main\SiteTable::getDocumentRoot($arRes['LID'])
		);
	}

	if($arRes['DEF'] == 'Y')
	{
		$arDefaultSite = $arRes;
	}

	$arSites[$arRes['LID']] = $arRes;
}

$arCurrentSite = isset($arSites[$siteId]) ? $arSites[$siteId] : $arDefaultSite;
$siteId = $arCurrentSite['LID'];

$arRobotsConfig = array(
Beispiel #13
0
 protected static function actionAdd($name, $arFields)
 {
     if ($name == 'ADDELEMENT') {
         if (!self::checkElement($arFields)) {
             return;
         }
         // we don't have the GLOBAL_ACTIVE flag in $arFields so we should check it manually
         if (is_array($arFields['IBLOCK_SECTION']) && count($arFields['IBLOCK_SECTION']) > 0) {
             $arNewSections = array();
             $arFilter = array('ID' => $arFields['IBLOCK_SECTION'], 'IBLOCK_ID' => $arFields['IBLOCK_ID'], 'GLOBAL_ACTIVE' => 'Y');
             $dbRes = \CIBlockSection::getList(array(), $arFilter, false, array('ID'));
             while ($ar = $dbRes->fetch()) {
                 $arNewSections[] = $ar['ID'];
             }
             if (count($arNewSections) <= 0) {
                 // element is added to inactive sections
                 return;
             }
             $arFields['IBLOCK_SECTION'] = $arNewSections;
         }
     } elseif ($name == 'ADDSECTION') {
         $dbRes = \CIBlockSection::getList(array(), array('ID' => $arFields['ID'], 'GLOBAL_ACTIVE' => 'Y'), false, array('ID'));
         if (!$dbRes->fetch()) {
             // section is added to inactive branch
             return;
         }
     }
     $arSitemaps = SitemapIblockTable::getByIblock($arFields, $name == 'ADDSECTION' ? SitemapIblockTable::TYPE_SECTION : SitemapIblockTable::TYPE_ELEMENT);
     $arFields['TIMESTAMP_X'] = ConvertTimeStamp(false, "FULL");
     if (isset($arFields['IBLOCK_SECTION']) && is_array($arFields['IBLOCK_SECTION']) && count($arFields['IBLOCK_SECTION']) > 0) {
         $arFields['IBLOCK_SECTION_ID'] = min($arFields['IBLOCK_SECTION']);
     }
     if (count($arSitemaps) > 0) {
         $arSiteDirs = array();
         $dbSite = SiteTable::getList(array('select' => array('LID', 'DIR')));
         while ($arSite = $dbSite->fetch()) {
             $arSiteDirs[$arSite['LID']] = $arSite['DIR'];
         }
         foreach ($arSitemaps as $arSitemap) {
             $arFields['LANG_DIR'] = $arSiteDirs[$arSitemap['SITE_ID']];
             $rule = array('url' => $name == 'ADDSECTION' ? \CIBlock::replaceDetailUrl($arSitemaps[0]['SECTION_PAGE_URL'], $arFields, false, "S") : \CIBlock::replaceDetailUrl($arSitemaps[0]['DETAIL_PAGE_URL'], $arFields, false, "E"), 'lastmod' => MakeTimeStamp($arFields['TIMESTAMP_X']));
             $fileName = str_replace(array('#IBLOCK_ID#', '#IBLOCK_CODE#', '#IBLOCK_XML_ID#'), array($arFields['IBLOCK_ID'], $arSitemap['IBLOCK_CODE'], $arSitemap['IBLOCK_XML_ID']), $arSitemap['SITEMAP_FILE_IBLOCK']);
             $sitemapFile = new SitemapFile($fileName, $arSitemap);
             $sitemapFile->appendIblockEntry($rule['url'], $rule['lastmod']);
             $sitemapIndex = new SitemapIndex($arSitemap['SITEMAP_FILE'], $arSitemap);
             $sitemapIndex->appendIndexEntry($sitemapFile);
             if ($arSitemap['ROBOTS'] == 'Y') {
                 $robotsFile = new RobotsFile($arSitemap['SITE_ID']);
                 $robotsFile->addRule(array(RobotsFile::SITEMAP_RULE, $sitemapIndex->getUrl()));
             }
         }
     }
 }