Example #1
1
 /**
  * Function ends the caching block of the component execution.
  *
  * <p>Note: automaticly called by includeComponentTemplate.</p>
  * @return void
  *
  */
 public final function endResultCache()
 {
     global $NavNum, $CACHE_MANAGER;
     if (!$this->__bInited) {
         return null;
     }
     if (!$this->__cache) {
         return null;
     }
     $arCache = array("arResult" => $this->arResult);
     if ($this->__template) {
         $arCache["templateCachedData"] =& $this->__template->getCachedData();
         if ($this->__component_epilog) {
             $arCache["templateCachedData"]["component_epilog"] = $this->__component_epilog;
         }
     } else {
         $arCache["templateCachedData"] = array();
     }
     if ($this->__NavNum !== false && $this->__NavNum !== $NavNum) {
         $arCache["templateCachedData"]["__NavNum"] = $NavNum - $this->__NavNum;
     }
     if (!empty($this->__children_css)) {
         $arCache["templateCachedData"]["__children_css"] = $this->__children_css;
         if ($this->__parent) {
             foreach ($this->__children_css as $cssPath) {
                 $this->__parent->addChildCSS($cssPath);
             }
         }
     }
     if (!empty($this->__children_js)) {
         $arCache["templateCachedData"]["__children_js"] = $this->__children_js;
         if ($this->__parent) {
             foreach ($this->__children_js as $jsPath) {
                 $this->__parent->addChildJS($jsPath);
             }
         }
     }
     if (!empty($this->__children_epilogs)) {
         $arCache["templateCachedData"]["__children_epilogs"] = $this->__children_epilogs;
         if ($this->__parent) {
             foreach ($this->__children_epilogs as $epilogFile) {
                 $this->__parent->addChildEpilog($epilogFile);
             }
         }
     }
     if (!empty($this->__view)) {
         $arCache["templateCachedData"]["__view"] = $this->__view;
     }
     if (!empty($this->__editButtons)) {
         $arCache["templateCachedData"]["__editButtons"] = $this->__editButtons;
     }
     $cacheWasStarted = $this->__cache->isStarted();
     $this->__cache->endDataCache($arCache);
     if (defined("BX_COMP_MANAGED_CACHE") && $cacheWasStarted) {
         $CACHE_MANAGER->endTagCache();
     }
     $this->__cache = null;
 }
Example #2
0
 /**
  * По Битрикс-имени шаблона возвращает путь к его файлу
  *
  * @param string $name
  * @return string
  * @throws \Twig_Error_Loader
  */
 private function getComponentTemplatePath($name)
 {
     list($namespace, $component, $template, $file) = explode(':', $name);
     if (strlen($template) === 0) {
         $template = '';
     }
     if (strlen($file) === 0) {
         $file = '';
     }
     $componentName = "{$namespace}:{$component}";
     $component = new \CBitrixComponent();
     $component->InitComponent($componentName, $template);
     $component->__templatePage = $file;
     $obTemplate = new \CBitrixComponentTemplate();
     $obTemplate->Init($component);
     $templatePath = $_SERVER['DOCUMENT_ROOT'] . $obTemplate->GetFile();
     if (!file_exists($templatePath)) {
         throw new \Twig_Error_Loader("Не удалось найти шаблон '{$name}'");
     }
     return $templatePath;
 }
Example #3
0
	/**
	* Function starts the caching block of the component execution.
	*
	* @param int $cacheTime
	* @param mixed $additionalCacheID
	* @param string $cachePath
	* @return string
	*
	*/
	final public function startResultCache($cacheTime = false, $additionalCacheID = false, $cachePath = false)
	{
		global $APPLICATION, $CACHE_MANAGER;
		if (!$this->__bInited)
			return null;

		if ($this->arParams["CACHE_TYPE"] == "N" || ($this->arParams["CACHE_TYPE"] == "A" && COption::getOptionString("main", "component_cache_on", "Y") == "N"))
			return True;

		if ($cacheTime === false)
			$cacheTime = intval($this->arParams["CACHE_TIME"]);

		$this->__cacheID = $this->getCacheID($additionalCacheID);
		$this->__cachePath = $cachePath;
		if ($this->__cachePath === false)
			$this->__cachePath = $CACHE_MANAGER->getCompCachePath($this->__relativePath);

		$this->__cache = new CPHPCache;
		if ($this->__cache->startDataCache($cacheTime, $this->__cacheID, $this->__cachePath))
		{
			$this->__NavNum = $GLOBALS["NavNum"];
			if (defined("BX_COMP_MANAGED_CACHE"))
				$CACHE_MANAGER->startTagCache($this->__cachePath);

			return true;
		}
		else
		{
			$arCache = $this->__cache->GetVars();
			$this->arResult = $arCache["arResult"];
			if (array_key_exists("templateCachedData", $arCache))
			{
				$templateCachedData = & $arCache["templateCachedData"];
				CBitrixComponentTemplate::applyCachedData($templateCachedData);
				if ($templateCachedData["__editButtons"])
				{
					foreach ($templateCachedData["__editButtons"] as $button)
					{
						if ($button[0] == 'AddEditAction')
							$this->addEditAction($button[1], $button[2], $button[3], $button[4]);
						else
							$this->addDeleteAction($button[1], $button[2], $button[3], $button[4]);
					}
				}

				if ($templateCachedData["__view"])
					foreach ($templateCachedData["__view"] as $view_id => $target)
						foreach ($target as $view_content)
							$GLOBALS["APPLICATION"]->addViewContent($view_id, $view_content[0], $view_content[1]);

				if (array_key_exists("__NavNum", $templateCachedData))
					$GLOBALS["NavNum"]+= $templateCachedData["__NavNum"];

				if (array_key_exists("__children_css", $templateCachedData))
				{
					foreach ($templateCachedData["__children_css"] as $css_url)
						$APPLICATION->setAdditionalCSS($css_url);
				}

				if (array_key_exists("__children_epilogs", $templateCachedData))
				{
					foreach ($templateCachedData["__children_epilogs"] as $component_epilog)
						$this->includeComponentEpilog($component_epilog);
				}

				if (array_key_exists("component_epilog", $templateCachedData))
				{
					$this->includeComponentEpilog($templateCachedData["component_epilog"]);
				}
			}
			return false;
		}
	}
Example #4
0
$cache = new CPHPCache();
$cache_id = "blog_last_messages_" . serialize($arParams) . "_" . serialize($UserGroupID) . "_" . $USER->IsAdmin();
if (($tzOffset = CTimeZone::GetOffset()) != 0) {
    $cache_id .= "_" . $tzOffset;
}
if ($arParams["USE_SOCNET"] == "Y") {
    $cache_id .= "_" . $user_id;
}
$cache_path = "/" . SITE_ID . "/blog/last_messages/";
$arResult = array();
if ($arParams["CACHE_TIME"] > 0 && $cache->InitCache($arParams["CACHE_TIME"], $cache_id, $cache_path)) {
    $Vars = $cache->GetVars();
    foreach ($Vars["arResult"] as $k => $v) {
        $arResult[$k] = $v;
    }
    CBitrixComponentTemplate::ApplyCachedData($Vars["templateCachedData"]);
    $cache->Output();
} else {
    if ($arParams["CACHE_TIME"] > 0) {
        $cache->StartDataCache($arParams["CACHE_TIME"], $cache_id, $cache_path);
    }
    $arFilter = array("<=DATE_PUBLISH" => ConvertTimeStamp(time() + $tzOffset, "FULL", false), "PUBLISH_STATUS" => BLOG_PUBLISH_STATUS_PUBLISH, ">PERMS" => BLOG_PERMS_DENY, "BLOG_ACTIVE" => "Y", "BLOG_GROUP_SITE_ID" => SITE_ID);
    if (strlen($arParams["BLOG_URL"]) > 0) {
        $arFilter["BLOG_URL"] = $arParams["BLOG_URL"];
    }
    if (!empty($arParams["GROUP_ID"])) {
        $arFilter["BLOG_GROUP_ID"] = $arParams["GROUP_ID"];
    }
    if ($USER->IsAdmin()) {
        unset($arFilter[">PERMS"]);
    }
Example #5
0
 /**
  * Example:
  * <code>
  * <div id="<?=$item->area($this)?>"></div>
  * </code>
  * @param CBitrixComponentTemplate $component
  * @param bool $edit
  * @param bool $delete
  * @return string
  */
 function area($component, $edit = true, $delete = true)
 {
     if ($edit) {
         $component->AddEditAction($this->id(), $this->get('EDIT_LINK'), CIBlock::GetArrayByID($this->iblock(), "ELEMENT_EDIT"));
     }
     if ($delete) {
         $component->AddDeleteAction($this->id(), $this->get('DELETE_LINK'), CIBlock::GetArrayByID($this->iblock(), "ELEMENT_DELETE"), array("CONFIRM" => GetMessage('CT_BNL_ELEMENT_DELETE_CONFIRM')));
     }
     return $component->GetEditAreaId($this->id());
 }
Example #6
0
 }
 if (isset($arTemplateParameters) && is_array($arTemplateParameters)) {
     $arParameters = $arParameters + $arTemplateParameters;
 }
 $arTemplatesList = CComponentUtil::GetTemplatesList($_GET["component_name"], $_GET["template_id"]);
 for ($i = 0, $cnt = count($arTemplatesList); $i < $cnt; $i++) {
     if ($arComponent["DATA"]["TEMPLATE_NAME"] != "" && $arTemplatesList[$i]["NAME"] == $arComponent["DATA"]["TEMPLATE_NAME"] || $arComponent["DATA"]["TEMPLATE_NAME"] == "" && $arTemplatesList[$i]["NAME"] == ".default") {
         $templateSiteTemplate = $arTemplatesList[$i]["TEMPLATE"];
         break;
     }
 }
 /* save parameters to file */
 if ($_SERVER["REQUEST_METHOD"] == "POST" && $_REQUEST["action"] == "save" && $arComponent !== false && $arComponentDescription !== false && check_bitrix_sessid()) {
     //check template name
     $sTemplateName = trim($_POST["TEMPLATE_NAME"]);
     if ($sTemplateName == '' || !CBitrixComponentTemplate::CheckName($sTemplateName)) {
         $sTemplateName = '.default';
     }
     if ($_POST["SITE_TEMPLATE"] != $_GET["template_id"] && $_POST["SITE_TEMPLATE"] != ".default") {
         $_POST["USE_TEMPLATE"] = "N";
     }
     if (CComponentUtil::CopyTemplate($arComponent["DATA"]["COMPONENT_NAME"], $arComponent["DATA"]["TEMPLATE_NAME"], strlen($templateSiteTemplate) > 0 ? $templateSiteTemplate : false, $_POST["SITE_TEMPLATE"], $sTemplateName, false)) {
         if ($_POST["USE_TEMPLATE"] == "Y") {
             $code = ($arComponent["DATA"]["VARIABLE"] ? $arComponent["DATA"]["VARIABLE"] . "=" : "") . "\$APPLICATION->IncludeComponent(\"" . $arComponent["DATA"]["COMPONENT_NAME"] . "\", " . "\"" . $sTemplateName . "\", " . "Array(\n\t" . PHPParser::ReturnPHPStr2($arComponent["DATA"]["PARAMS"], $arParameters) . "\n\t)" . ",\n\t" . (strlen($arComponent["DATA"]["PARENT_COMP"]) > 0 ? $arComponent["DATA"]["PARENT_COMP"] : "false") . (!empty($arComponent["DATA"]["FUNCTION_PARAMS"]) ? ",\n\t" . "array(\n\t" . PHPParser::ReturnPHPStr2($arComponent["DATA"]["FUNCTION_PARAMS"]) . "\n\t)" : "") . "\n);";
             $filesrc_for_save = substr($filesrc, 0, $arComponent["START"]) . $code . substr($filesrc, $arComponent["END"]);
             if (!$APPLICATION->SaveFileContent($abs_path, $filesrc_for_save)) {
                 $strWarning .= GetMessage("comp_prop_err_save") . "<br>";
             }
         }
         if ($strWarning == "") {
             $strJSText = 'window.location = window.location.href;';
Example #7
0
 /**
  * Добавляет кнопку удаление элемента инфоблока
  * @param \CBitrixComponent $template
  * @param IblockElement $element
  */
 public static function addButtonDeleteIblockSection(\CBitrixComponentTemplate &$template, IblockSection $element, $title = "Удалить")
 {
     $template->AddDeleteAction($element->ID, Iblock::getSectionDeleteUrl($element), $title, ["CONFIRM" => "Вы уверены что хотите удалить запись?"]);
 }