Пример #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);
     }
 }
Пример #2
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";
 }
Пример #3
0
 public function initialize(array $options)
 {
     $this->logFile = static::DEFAULT_LOG_FILE;
     if (isset($options["file"]) && !empty($options["file"])) {
         $this->logFile = $options["file"];
     }
     $this->logFile = preg_replace("'[\\\\/]+'", "/", $this->logFile);
     if (substr($this->logFile, 0, 1) !== "/" && !preg_match("#^[a-z]:/#", $this->logFile)) {
         $this->logFile = Main\Application::getDocumentRoot() . "/" . $this->logFile;
     }
     $this->logFileHistory = $this->logFile . ".old";
     $this->maxLogSize = static::MAX_LOG_SIZE;
     if (isset($options["log_size"]) && $options["log_size"] > 0) {
         $this->maxLogSize = intval($options["log_size"]);
     }
     if (isset($options["level"]) && $options["level"] > 0) {
         $this->level = intval($options["level"]);
     }
 }
Пример #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];
 }
Пример #5
0
 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));
 }
Пример #6
0
 /**
  * Parses the passed content to find css, js and images. Returns the array of files.
  *
  * @param $content
  *
  * @return array
  */
 public function getFilesFromContent($content)
 {
     $files = array();
     $arFilesByType = array();
     $arExtensions = array("js", "css");
     $extension_regex = "(?:" . implode("|", $arExtensions) . ")";
     $regex = "/\n\t\t\t\t((?i:\n\t\t\t\t\thref=\n\t\t\t\t\t|src=\n\t\t\t\t\t|BX\\.loadCSS\\(\n\t\t\t\t\t|BX\\.loadScript\\(\n\t\t\t\t\t|jsUtils\\.loadJSFile\\(\n\t\t\t\t\t|background\\s*:\\s*url\\(\n\t\t\t\t))                                                   #attribute\n\t\t\t\t(\"|')                                               #open_quote\n\t\t\t\t([^?'\"]+\\.)                                        #href body\n\t\t\t\t(" . $extension_regex . ")                           #extentions\n\t\t\t\t(|\\?\\d+|\\?v=\\d+)                                 #params\n\t\t\t\t(\\2)                                                #close_quote\n\t\t\t/x";
     $match = array();
     preg_match_all($regex, $content, $match);
     $link = $match[3];
     $extension = $match[4];
     $params = $match[5];
     $linkCount = count($link);
     $fileData = array("FULL_FILE_LIST" => array(), "FILE_TIMESTAMPS" => array(), "CSS_FILE_IMAGES" => array());
     for ($i = 0; $i < $linkCount; $i++) {
         $fileData["FULL_FILE_LIST"][] = $files[] = $link[$i] . $extension[$i] . $params[$i];
         $fileData["FILE_TIMESTAMPS"][$link[$i] . $extension[$i]] = $params[$i];
         $arFilesByType[$extension[$i]][] = $link[$i] . $extension[$i];
     }
     $manifestCache = $this->readManifestCache($this->getCurrentManifestID());
     if (array_key_exists("css", $arFilesByType)) {
         $cssCount = count($arFilesByType["css"]);
         for ($j = 0; $j < $cssCount; $j++) {
             $cssFilePath = $arFilesByType["css"][$j];
             if ($manifestCache["FILE_DATA"]["FILE_TIMESTAMPS"][$cssFilePath] != $fileData["FILE_TIMESTAMPS"][$cssFilePath]) {
                 $fileContent = false;
                 $fileUrl = parse_url($cssFilePath);
                 $file = new \Freetrix\Main\IO\File(Application::getDocumentRoot() . $fileUrl['path']);
                 if ($file->isExists() && $file->isReadable()) {
                     $fileContent = $file->getContents();
                 } elseif ($fileUrl["scheme"]) {
                     $req = new \CHTTP();
                     $req->http_timeout = 20;
                     $fileContent = $req->Get($cssFilePath);
                 }
                 if ($fileContent != false) {
                     $regex = '#([;\\s:]*(?:url|@import)\\s*\\(\\s*)(\'|"|)(.+?)(\\2)\\s*\\)#si';
                     $cssFileRelative = new \Freetrix\Main\IO\File($cssFilePath);
                     $cssPath = $cssFileRelative->getDirectoryName();
                     preg_match_all($regex, $fileContent, $match);
                     $matchCount = count($match[3]);
                     for ($k = 0; $k < $matchCount; $k++) {
                         $file = self::replaceUrlCSS($match[3][$k], addslashes($cssPath));
                         if (!in_array($file, $files) && !strpos($file, ";base64")) {
                             $fileData["FULL_FILE_LIST"][] = $files[] = $file;
                             $fileData["CSS_FILE_IMAGES"][$cssFilePath][] = $file;
                         }
                     }
                 }
             } else {
                 $fileData["CSS_FILE_IMAGES"][$cssFilePath] = $manifestCache["FILE_DATA"]["CSS_FILE_IMAGES"][$cssFilePath];
                 if (is_array($manifestCache["FILE_DATA"]["CSS_FILE_IMAGES"][$cssFilePath])) {
                     $fileData["FULL_FILE_LIST"] = array_merge($fileData["FULL_FILE_LIST"], $manifestCache["FILE_DATA"]["CSS_FILE_IMAGES"][$cssFilePath]);
                 }
             }
         }
     }
     return $fileData;
 }
Пример #7
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"];
 }
Пример #8
0
 /**
  * Read messages from user defined lang file
  */
 private static function loadCustomMessages($lang)
 {
     $customMess = array();
     $documentRoot = Main\Application::getDocumentRoot();
     if (($fname = Main\Loader::getLocal("php_interface/user_lang/" . $lang . "/lang.php", $documentRoot)) !== false) {
         $mess = self::includeFile($fname);
         // typical call is Loc::loadMessages(__FILE__)
         // __FILE__ can differ from path used in the user file
         foreach ($mess as $key => $val) {
             $customMess[str_replace("\\", "/", realpath($documentRoot . $key))] = $val;
         }
     }
     return $customMess;
 }