Example #1
0
 private static function getCurrentLang()
 {
     $context = Context::getCurrent();
     if ($context !== null) {
         return $context->getLanguage();
     }
     return 'en';
 }
Example #2
0
 public static function checkObsoleteManifest()
 {
     $server = \Freetrix\Main\Context::getCurrent()->getServer();
     $appCacheUrl = $server->get("HTTP_FX_APPCACHE_URL");
     $appCacheParams = $server->get("HTTP_FX_APPCACHE_PARAMS");
     if ($appCacheUrl) {
         $params = json_decode($appCacheParams, true);
         if (!is_array($params)) {
             $params = array();
         }
         \Freetrix\Main\Data\AppCacheManifest::clear($appCacheUrl, $params);
     }
 }
Example #3
0
 /**
  * Returns request method
  *
  * @return string
  */
 public function getRequestMethod()
 {
     return Main\Context::getCurrent()->getServer()->getRequestMethod();
 }
Example #4
0
require_once dirname(__FILE__) . "/../include/prolog_admin_before.php";
require_once $_SERVER["DOCUMENT_ROOT"] . FX_ROOT . "/modules/main/prolog.php";
define("HELP_FILE", "settings/culture_admin.php");
if (!$USER->CanDoOperation('edit_other_settings') && !$USER->CanDoOperation('view_other_settings')) {
    $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
}
$isAdmin = $USER->CanDoOperation('edit_other_settings');
use Freetrix\Main;
use Freetrix\Main\Localization\CultureTable;
use Freetrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__);
$tableID = "tbl_culture";
$sorting = new CAdminSorting($tableID, "name", "asc");
$adminList = new CAdminList($tableID, $sorting);
/** @var $request Main\HttpRequest */
$request = Main\Context::getCurrent()->getRequest();
if ($adminList->EditAction() && $isAdmin) {
    foreach ($request["FIELDS"] as $ID => $arFields) {
        if (!$adminList->IsUpdated($ID)) {
            continue;
        }
        $result = CultureTable::update($ID, $arFields);
        if (!$result->isSuccess()) {
            $adminList->AddUpdateError("(ID=" . $ID . ") " . implode("<br>", $result->getErrorMessages()), $ID);
        }
    }
}
if (($arID = $adminList->GroupAction()) && $isAdmin) {
    if ($request['action_target'] == 'selected') {
        $arID = array();
        $data = CultureTable::getList();
Example #5
0
 protected static function getFormat(Context\Culture $culture = null)
 {
     static $defaultCulture = null;
     if ($culture === null) {
         if ($defaultCulture === null) {
             $context = Context::getCurrent();
             $defaultCulture = $context->getCulture();
         }
         $culture = $defaultCulture;
     }
     $format = static::getCultureFormat($culture);
     return static::convertFormatToPhp($format);
 }
Example #6
0
 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;
 }
Example #7
0
	public static function OnEpilog()
	{
		global $USER;

		$arOptions = CHTMLPagesCache::GetOptions();
		if ($arOptions["COMPOSITE"] === "Y")
		{
			if (Main\Data\Cache::shouldClearCache())
			{
				$server = Main\Context::getCurrent()->getServer();

				$queryString = DeleteParam(array("clear_cache", "clear_cache_session"));
				$uri = new Freetrix\Main\Web\Uri($server->getRequestUri());
				$refinedUri = $queryString != "" ? $uri->getPath()."?".$queryString : $uri->getPath();

				$cachedFile = Main\Data\StaticHtmlCache::convertUriToPath($refinedUri, $server->getHttpHost());
				$bytes = self::deleteRecursive($cachedFile);
				self::updateQuota(-$bytes);
			}
			return;
		}

		$bAutorized = is_object($USER) && $USER->IsAuthorized();
		if(!$bAutorized && defined("HTML_PAGES_FILE"))
		{
			@setcookie(session_name(), "", time()-360000, "/");
		}

		$bExcludeByFile = $_SERVER["SCRIPT_NAME"] == "/freetrix/admin/get_start_menu.php";

		$posts = 0;
		$bytes = 0.0;
		$all_clean = false;

		//Check if modifyng action happend
		if(($_SERVER["REQUEST_METHOD"] === "POST") || ($bAutorized && check_freetrix_sessid() && !$bExcludeByFile))
		{
			//if it was admin post
			if(strncmp($_SERVER["REQUEST_URI"], "/freetrix/", 8) === 0)
			{
				//Then will clean all the cache
				$bytes = CHTMLPagesCache::deleteRecursive("/");
				$all_clean = true;
			}
			//check if it was SEF post
			elseif(array_key_exists("SEF_APPLICATION_CUR_PAGE_URL", $_REQUEST) && file_exists($_SERVER['DOCUMENT_ROOT']."/urlrewrite.php"))
			{
				$arUrlRewrite = array();
				include($_SERVER['DOCUMENT_ROOT']."/urlrewrite.php");
				foreach($arUrlRewrite as $val)
				{
					if(preg_match($val["CONDITION"], $_SERVER["REQUEST_URI"]) > 0)
					{
						if (strlen($val["RULE"]) > 0)
							$url = preg_replace($val["CONDITION"], (StrLen($val["PATH"]) > 0 ? $val["PATH"]."?" : "").$val["RULE"], $_SERVER["REQUEST_URI"]);
						else
							$url = $val["PATH"];

						$pos=strpos($url, "?");
						if($pos !== false)
						{
							$url = substr($url, 0, $pos);
						}
						$url = substr($url, 0, strrpos($url, "/")+1);
						$bytes = CHTMLPagesCache::deleteRecursive($url);
						break;
					}
				}
			}
			//public page post
			else
			{
				$folder = substr($_SERVER["REQUEST_URI"], 0, strrpos($_SERVER["REQUEST_URI"], "/"));
				$bytes = CHTMLPagesCache::deleteRecursive($folder);
			}
			$posts++;
		}

		if($bytes > 0.0 && class_exists("cdiskquota"))
		{
			CDiskQuota::updateDiskQuota("file", $bytes, "delete");
		}

		if($posts || $bytes)
		{
			CHTMLPagesCache::writeStatistic(
				0, //hit
				0, //miss
				0, //quota
				$posts, //posts
				($all_clean? false: -$bytes) //files
			);
		}
	}
Example #8
0
	private function getPost($key = "", $checkPost = true)
	{
		static $request = false;
		if ($key === true || $key === false)
		{
			$checkPost = $key;
			$key = "";
		}

		$checkPost = ($checkPost === true ? "postAndGet" : "onlyGet");
		if ($request === false)
		{
			$req = \Freetrix\Main\Context::getCurrent()->getRequest();
			$request = array(
				"onlyGet" => $req->getQueryList()->toArray(),
				"postAndGet" => array_merge($req->getQueryList()->toArray(), $req->getPostList()->toArray())
			);
		}
		$post = $request[$checkPost];
		if ($key == "")
			return array_key_exists(self::INFO_NAME, $post) ? $post[self::INFO_NAME] : false;
		else if (array_key_exists(self::INFO_NAME, $post) && array_key_exists($key, $post[self::INFO_NAME]))
			return $post[self::INFO_NAME][$key];
		return false;
	}
Example #9
0
 public static function isAjaxRequest()
 {
     if (self::$isAjaxRequest == null) {
         $actionType = \Freetrix\Main\Context::getCurrent()->getServer()->get("HTTP_FX_ACTION_TYPE");
         self::$isAjaxRequest = $actionType == "get_dynamic" || defined("actionType") && constant("actionType") == "get_dynamic";
     }
     return self::$isAjaxRequest;
 }