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"; }
private function getDbConnConnectionParameters() { /* Old kernel code for compatibility */ global $DBType, $DBDebug, $DBDebugToFile, $DBHost, $DBName, $DBLogin, $DBPassword, $DBSQLServerType; require_once Main\Application::getDocumentRoot() . Main\Application::getPersonalRoot() . "/php_interface/dbconn.php"; $DBType = strtolower($DBType); if ($DBType == 'mysql') { $className = "\\Freetrix\\Main\\DB\\MysqlConnection"; } elseif ($DBType == 'mssql') { $className = "\\Freetrix\\Main\\DB\\MssqlConnection"; } else { $className = "\\Freetrix\\Main\\DB\\OracleConnection"; } return array('className' => $className, 'host' => $DBHost, 'database' => $DBName, 'login' => $DBLogin, 'password' => $DBPassword, 'options' => (!defined("DBPersistent") || DBPersistent ? Main\DB\Connection::PERSISTENT : 0) | (defined("DELAY_DB_CONNECT") && DELAY_DB_CONNECT === true ? Main\DB\Connection::DEFERRED : 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; }
public function initCache($TTL, $uniqueString, $initDir = false, $baseDir = "cache") { if ($initDir === false) { $request = Main\Context::getCurrent()->getRequest(); $initDir = $request->getRequestedPageDirectory(); } $personalRoot = Main\Application::getPersonalRoot(); $this->baseDir = $personalRoot . "/" . $baseDir . "/"; $this->initDir = $initDir; $this->filename = "/" . $this->getPath($uniqueString); $this->TTL = $TTL; $this->uniqueString = $uniqueString; $this->vars = false; if ($TTL <= 0) { return false; } if (static::shouldClearCache()) { return false; } $arAllVars = array("CONTENT" => "", "VARS" => ""); if (!$this->cacheEngine->read($arAllVars, $this->baseDir, $this->initDir, $this->filename, $this->TTL)) { return false; } if (static::$showCacheStat) { $read = 0; $path = ''; if ($this->cacheEngine instanceof ICacheEngineStat) { $read = $this->cacheEngine->getReadBytes(); $path = $this->cacheEngine->getCachePath(); } elseif ($this->cacheEngine instanceof \ICacheBackend) { /** @noinspection PhpUndefinedFieldInspection */ $read = $this->cacheEngine->read; /** @noinspection PhpUndefinedFieldInspection */ $path = $this->cacheEngine->path; } Diag\CacheTracker::addCacheStatBytes($read); Diag\CacheTracker::add($read, $path, $this->baseDir, $this->initDir, $this->filename, "R"); } $this->content = $arAllVars["CONTENT"]; $this->vars = $arAllVars["VARS"]; return true; }
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); }