14 $CACHE_SNIPPETS = Array();
16 if ($Params[
'bClearCache'])
19 $ttl = 30 * 24 * 60 * 60;
27 if (!$arSNIPPETS || !is_array($arSNIPPETS))
29 $arSNIPPETS = Array();
30 $arTemplateKeys = Array();
40 if ($Params[
'returnArray'] ??
null)
46 ?><script>window.arSnippets = <?= CUtil::PhpToJSObject($arSNIPPETS)?>; </script><?
55 if (
count($arSNIPPETS) > 0)
71 $d =
$io->GetDirectory($bpPath);
72 $arChildren = $d->GetChildren();
73 foreach ($arChildren as $child)
75 $file = $child->GetName();
76 if($file ==
".htaccess" || $file ==
".content.php" || ($level == 0 && $file ==
"images"))
79 $filePath = $child->GetPathWithName();
80 if($child->IsDirectory())
82 $new_path =
"".$path.($path ==
"" ?
"" :
"/").$file;
88 $ext = $child->GetExtension();
94 if (mb_strpos(
$name,
".snp") ===
false)
99 if (!
$io->FileExists($bpPath.
"/".
$name))
101 $io->Rename($filePath, $bpPath.
"/".
$name);
105 for (
$n = 1;
$n < 256;
$n++)
107 $name_ = str_replace(
".snp",
"(".
$n.
").snp",
$name);
108 if (!
$io->FileExists($bpPath.
"/".$name_))
111 $io->Rename($filePath, $bpPath.
"/".
$name);
119 $arSNIPPETS[
$key] = Array(
131 $arKeys[
$key] = Array(
145 if (file_exists(
$basePath.
"/.content.php"))
148 $arK = array_keys($SNIPPETS);
152 $pos = mb_strrpos(
$name,
".");
153 $f_name = ($pos !== FALSE)? mb_substr(
$name, 0, $pos) :
$name;
154 if (
$ar[$f_name.
".snp"])
156 $ar[$f_name.
".snp"][
'title'] = stripslashes($SNIPPETS[
$name][
'title']);
157 $ar[$f_name.
".snp"][
'description'] = stripslashes($SNIPPETS[
$name][
'description'] ??
'');
167 $GLOBALS[
'APPLICATION']->SaveFileContent(
$path.
"/.htaccess",
"Allow from All");
183 public static function Edit($Params)
187 $title = $Params[
'title'];
191 $site = $Params[
'site'];
192 $code = $Params[
'code'];
194 $templatePath = mb_substr(
$basePath, 0, -9);
197 if (!file_exists($templatePath))
199 ?><script>alert(
'Error: Incorrect template Id: <?= CUtil::JSEscape($template)?>');</script><?
212 ?><script>window.__bx_res_sn_filename =
"<?= CUtil::JSEscape($name);?>";</script><?
225 if (file_exists(
$basePath.
"/.content.php"))
235 $contentSrc =
'<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?>'.chr(10);
236 $contentSrc .=
'<?'.chr(10).
'$SNIPPETS = Array();'.chr(10);
237 foreach ($SNIPPETS as
$k=>$_arSn)
240 $contentSrc .=
'$SNIPPETS[\''.CUtil::addslashes(
$k).
'\'] = Array(
"title"=>\
''.Cutil::addslashes($_arSn[
'title'] ??
null).
'\',
"description"=>\
''.Cutil::addslashes($_arSn[
'description'] ??
null).
'\');
'.chr(10);
244 $APPLICATION->SaveFileContent($basePath."/.content.php", $contentSrc);
247 CSnippets::ClearCache();
249 // 3. Handle thumbnail
250 if ($thumb !== false)
252 if (mb_substr($thumb, 0, 1) == '/
')
253 $thumb = mb_substr($thumb, 1);
255 $pos = mb_strrpos($name, ".");
259 //delete existent thumbnail
260 $f_name = mb_substr($name, 0, $pos);
261 $img_path1 = BX_PERSONAL_ROOT.'/templates/
'.$template.'/snippets/images/
'.$path.($path == '' ? '' : '/
').$f_name;
262 $DOC_ROOT = CSite::GetSiteDocRoot($site);
263 $arExt = array("gif", "jpg", "jpeg", "png", "bmp");
264 for ($i = 0, $c = count($arExt); $i < $c; $i++)
266 $p_ = $img_path1.".".$arExt[$i];
267 if(file_exists($DOC_ROOT.$p_))
268 CFileman::DeleteFile(Array($site, $p_));
271 if (empty($thumb) || mb_strrpos($thumb, '.
') === FALSE)
275 $path_from_1 = $DOC_ROOT."/".$thumb;
276 $path_from = '/
'.$thumb;
278 if (file_exists($path_from_1))
280 $pos = mb_strrpos($thumb, ".");
281 $f_ext = ($pos !== FALSE)? mb_strtolower(mb_substr($thumb, $pos + 1)) : '';
283 if (in_array($f_ext, $arExt))
285 $path_to = $img_path1.'.
'.$f_ext;
286 $strWarning_tmp = CFileMan::CopyEx(Array($site, $path_from), Array($site, $path_to));
292 public static function Delete($Params)
296 $io = CBXVirtualIo::GetInstance();
297 if($io->DirectoryExists($_SERVER["DOCUMENT_ROOT"]."/local/templates/".$Params['template
']."/snippets"))
299 $snPath = "/local/templates/".$Params['template']."/snippets";
303 $snPath = BX_PERSONAL_ROOT."/templates/".$Params['template']."/snippets";
306 $basePath = $_SERVER["DOCUMENT_ROOT"].$snPath;
307 $path = CFileMan::SecurePathVar($Params["path"]);
308 $key = $Params["path"].($Params["path"] == '' ? '' : '/
').CFileMan::SecurePathVar($Params["name"]);
310 //Delete snippet file
311 CFileman::DeleteFile(Array($Params["site"], $snPath.'/
'.$key));
314 if ($Params["thumb"] != '')
316 CFileman::DeleteFile(Array($Params["site"], $snPath.'/images/
'.$path.($path == '' ? '' : '/
').CFileMan::SecurePathVar($Params["thumb"])));
319 if (file_exists($basePath."/.content.php"))
321 @include($basePath."/.content.php");
322 $contentSrc = '<?
if(!defined(
"B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==
true)
die();?>
'.chr(10);
323 $contentSrc .= '<?
'.chr(10).'$SNIPPETS = Array();
'.chr(10);
324 foreach ($SNIPPETS as $k=>$_arSn)
326 if ($k != $key && CSnippets::CheckFile(array('site
' => $Params["site"], 'template' => $Params['template'], 'path' => $k)))
327 $contentSrc .= '$SNIPPETS[\
''.CUtil::JSEscape(
$k).
'\'] = Array(
"title"=>\
''.CUtil::JSEscape($_arSn[
'title']).
'\',
"description"=>\
''.CUtil::JSEscape($_arSn[
'description']).
'\');
'.chr(10);
330 $APPLICATION->SaveFileContent($basePath."/.content.php", $contentSrc);
333 CSnippets::ClearCache();
336window.operation_success = true;
341 public static function CheckFile($params)
343 $basePath = self::GetBasePath($params['template']);
344 return file_exists(CFileMan::SecurePathVar($basePath.'/
'.$params['path']));
347 public static function GetGroups($Params)
349 $template = CFileMan::SecurePathVar($Params['template']);
350 $arSnGroups = Array();
351 CSnippets::InspectDir($arSnGroups, "", $template);
352 CSnippets::DisplayJSGroups($template, $arSnGroups);
355 public static function GetGroupList($Params)
357 global $CACHE_MANAGER;
358 $template = CFileMan::SecurePathVar($Params['template']);
361 $CACHE_SNIPPETS = Array();
363 if ($Params['bClearCache
'])
364 CSnippets::ClearCache();
366 $ttl = 30 * 24 * 60 * 60; // 30 days
367 if($CACHE_MANAGER->Read($ttl, "fileman_snippet_group"))
369 $CACHE_SNIPPETS = $CACHE_MANAGER->Get("fileman_snippet_group");
370 if (isset($CACHE_SNIPPETS[$template]))
371 $arGroups = $CACHE_SNIPPETS[$template];
374 if (!$arGroups || !is_array($arGroups))
377 CSnippets::InspectDir($arGroups, "", $template);
378 $CACHE_SNIPPETS[$template] = $arGroups;
379 $CACHE_MANAGER->Set("fileman_snippet_group", $CACHE_SNIPPETS);
384 public static function SaveGroupList($Params)
389 public static function InspectDir(&$arSnGroups, $path, $template, $level = 0, $parent = '')
391 $io = CBXVirtualIo::GetInstance();
392 $basePath = self::GetBasePath($template);
393 if(!$io->DirectoryExists($basePath))
396 $bpPath = $basePath.($path == "" ? "" : "/").$path;
400 $d = $io->GetDirectory($bpPath);
401 $arChildren = $d->GetChildren();
402 foreach ($arChildren as $child)
404 $file = $child->GetName();
405 if($file == ".htaccess" || $file == ".content.php" || ($level == 0 && $file == "images") || !$child->IsDirectory())
408 $filePath = $child->GetPathWithName();
409 $arSnGroups[] = Array
414 'default_name
' => CSnippets::GetDefaultFileName($filePath)
417 $new_path = "".$path.($path == "" ? "" : "/").$file;
418 CSnippets::InspectDir($arSnGroups, $new_path, $template, $level + 1, $parent);
422 public static function GetDefaultFileName($path)
424 $io = CBXVirtualIo::GetInstance();
425 for ($i = 1; $i <= 9999; $i++)
427 $name = 'snippet
'.str_pad($i, 4, "0", STR_PAD_LEFT);
428 if (!$io->FileExists($path.'/
'.$name.'.snp
'))
434 public static function DisplayJSGroups($template, $ar = array())
436 $template = CUtil::JSEscape(htmlspecialcharsex($template));
437 $basePath = self::GetBasePath($template);
439 window.arSnGroups['<?=
$template?>
'] = {};
442 for($i=0,$len = count($ar); $i < $len; $i++)
444 $key = CUtil::JSEscape($ar[$i]['path'].($ar[$i]['path'] != '' ? '/
' : '').$ar[$i]['name
']);
448 name: '<?=CUtil::JSEscape(
$ar[
$i][
'name'])?>
',
449 path: '<?=CUtil::JSEscape(
$ar[
$i][
'path'])?>
',
450 level: '<?=CUtil::JSEscape(
$ar[
$i][
'level'])?>
',
451 default_name: '<?=CUtil::JSEscape(
$ar[
$i][
'default_name'])?>
'
464 public static function Add($params = array())
466 $params['
new'] = true;
467 return self::Update($params);
476 public static function Update($params = array())
480 $title = $params['
title'];
481 $description = $params['description
'];
482 $currentPath = $params['new'] ? '' : CFileMan::SecurePathVar($params['current_path
']);
483 $path = CFileMan::SecurePathVar($params['path']);
484 $template = CFileMan::SecurePathVar($params['template']);
485 $code = $params['code
'];
486 $basePath = self::GetBasePath($template);
487 $snippetPath = $basePath.($path == '' ? '' : '/
'.$path);
489 $io = CBXVirtualIo::GetInstance();
490 if(!$io->DirectoryExists($basePath))
492 $io->CreateDirectory($basePath);
497 $fileName = CSnippets::GetDefaultFileName($snippetPath).'.snp
';
501 $currentPath = $basePath.'/
'.$currentPath;
502 $oldSnippetPath = $io->ExtractPathFromPath($currentPath);
504 if ($snippetPath !== $oldSnippetPath && $io->FileExists($currentPath))
506 $io->Delete($currentPath);
507 $fileName = CSnippets::GetDefaultFileName($snippetPath).'.snp
';
511 $fileName = $io->ExtractNameFromPath($currentPath);
514 $key = ($path === '' ? '' : $path.'/
').$fileName;
516 if (!$io->ValidatePathString('/
'.$fileName) ||
517 IsFileUnsafe($snippetPath.'/
'.$fileName) ||
518 HasScriptExtension($snippetPath.'/
'.$fileName))
523 // 1. Save new snippet with new content
526 $APPLICATION->SaveFileContent($snippetPath.'/
'.$fileName, $code);
529 // 2. Rewrite title & description in .content.php
530 if ($title || $description)
533 if ($io->FileExists($basePath."/.content.php"))
534 @include($basePath."/.content.php");
537 $SNIPPETS[$key]['title'] = $title;
539 $SNIPPETS[$key]['description
'] = $description;
541 $contentSrc = '<?
if(!defined(
"B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==
true)
die();?>
'.chr(10);
542 $contentSrc .= '<?
'.chr(10).'$SNIPPETS = Array();
'.chr(10);
543 foreach ($SNIPPETS as $k => $snip)
545 if($io->FileExists(CFileMan::SecurePathVar($basePath.'/
'.$k)))
547 $contentSrc .= '$SNIPPETS[\
''.CUtil::addslashes(
$k).
'\'] = Array(
';
549 if (isset($snip['title']) && $snip['title'] !== '')
551 $contentSrc .= '\
'title\' => \''.Cutil::addslashes($snip[
'title']).
'\'';
552 if (isset($snip[
'description']) && $snip[
'description'] !==
'')
555 if (isset($snip[
'description']) && $snip[
'description'] !==
'')
557 $contentSrc .=
'\'description\
' => \''.Cutil::addslashes($snip[
'description']).
'\'';
559 $contentSrc .=
');'.chr(10);
586 $snippetPath =
$basePath.($path ==
'' ?
'' :
'/'.$path);
589 if (!
$io->ValidatePathString(
'/'.$path) ||
597 if(
$io->FileExists($snippetPath))
599 $res =
$io->Delete($snippetPath);
606 $contentSrc =
'<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?>'.chr(10);
607 $contentSrc .=
'<?'.chr(10).
'$SNIPPETS = Array();'.chr(10);
608 foreach ($SNIPPETS as
$k => $snip)
612 $contentSrc .=
'$SNIPPETS[\''.CUtil::addslashes(
$k).
'\'] = Array(
';
614 if (isset($snip['title']) && $snip['title'] !== '')
616 $contentSrc .= '\
'title\' => \''.Cutil::addslashes($snip[
'title']).
'\'';
617 if (isset($snip[
'description']) && $snip[
'description'] !==
'')
620 if (isset($snip[
'description']) && $snip[
'description'] !==
'')
622 $contentSrc .=
'\'description\
' => \''.Cutil::addslashes($snip[
'description']).
'\'';
624 $contentSrc .=
');'.chr(10);
643 $templatePath = mb_substr(
$basePath, 0, -9);
646 if(
$io->DirectoryExists($templatePath))
655 if (!
$io->DirectoryExists($categoryPath))
657 $res =
$io->CreateDirectory($categoryPath);
677 $newCategoryPath =
$io->ExtractPathFromPath($categoryPath).
'/'.
$params[
'new_name'];
678 if(
$io->DirectoryExists($categoryPath) && !
$io->DirectoryExists($newCategoryPath))
680 $res =
$io->Rename($categoryPath, $newCategoryPath);
687 $newPath = ltrim(
$io->ExtractPathFromPath(
$path).
'/'.
$params[
'new_name'],
'/');
688 $processedNewPath = CUtil::addslashes($newPath);
689 $contentSrc = preg_replace(
"/\\\$SNIPPETS\\['".
$path.
"\\//",
'$SNIPPETS[\''.$processedNewPath.
'/', $contentSrc);
709 if(
$io->DirectoryExists($categoryPath))
711 $res =
$io->Delete($categoryPath);
719 private static function GetBasePath(
$template)
static SecurePathVar($str)
static Remove($params=array())
static UpdateContentInfo(&$ar, &$arKeys, $template)
static ReadDir(&$arSNIPPETS, &$arKeys, $path, $template, $level=0, $parent="")
static GetDefaultFileName($path)
static RemoveCategory($params)
static WriteHtaccess($path)
static RenameCategory($params)
static HandleForTemplate($template, &$arSNIPPETS, &$arTemplateKeys)
static CheckFile($params)
static CreateCategory($params=array())
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
$_SERVER["DOCUMENT_ROOT"]
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
HasScriptExtension($check_name)
<? endif;?> window document title
if(empty($signedUserToken)) $key
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
$GLOBALS['_____370096793']