Exemplo n.º 1
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";
 }
Exemplo n.º 2
0
 private static function recursiveReindex($rootPath, $path, $arSites, $maxExecutionTime = 0, &$ns)
 {
     $pathAbs = IO\Path::combine($rootPath, $path);
     $dir = new IO\Directory($pathAbs);
     if (!$dir->isExists()) {
         return 0;
     }
     $siteId = "";
     foreach ($arSites as $site) {
         if (substr($pathAbs . "/", 0, strlen($site["path"] . "/")) == $site["path"] . "/") {
             $siteId = $site["site_id"];
             break;
         }
     }
     if (empty($siteId)) {
         return 0;
     }
     $arChildren = $dir->getChildren();
     foreach ($arChildren as $child) {
         if ($child->isDirectory()) {
             if ($child->isSystem()) {
                 continue;
             }
             //this is not first step and we had stopped here, so go on to reindex
             if ($maxExecutionTime <= 0 || strlen($ns["FLG"]) <= 0 || strlen($ns["FLG"]) > 0 && substr($ns["ID"] . "/", 0, strlen($child->getPath() . "/")) == $child->getPath() . "/") {
                 if (UrlRewriter::recursiveReindex($rootPath, substr($child->getPath(), strlen($rootPath)), $arSites, $maxExecutionTime, $ns) === false) {
                     return false;
                 }
             } else {
                 continue;
             }
         } else {
             //not the first step and we found last file from previos one
             if ($maxExecutionTime > 0 && strlen($ns["FLG"]) > 0 && $ns["ID"] == $child->getPath()) {
                 $ns["FLG"] = "";
             } elseif (empty($ns["FLG"])) {
                 $ID = UrlRewriter::reindexFile($siteId, $rootPath, substr($child->getPath(), strlen($rootPath)), $ns["max_file_size"]);
                 if ($ID) {
                     $ns["CNT"] = intval($ns["CNT"]) + 1;
                 }
             }
             if ($maxExecutionTime > 0 && getmicrotime() - START_EXEC_TIME > $maxExecutionTime) {
                 $ns["FLG"] = "Y";
                 $ns["ID"] = $child->getPath();
                 return false;
             }
         }
     }
     return true;
 }
Exemplo n.º 3
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);
	}
Exemplo n.º 4
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;
 }