示例#1
0
	public static function DisplayJSGroups($template, $ar = array())
	{
		$template = CUtil::JSEscape(htmlspecialcharsex($template));
		?><script>
		window.arSnGroups['<?php 
echo $template;
?>
'] = {};
		window.rootDefaultName['<?php 
echo $template;
?>
'] = '<?php 
echo CSnippets::GetDefaultFileName($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/templates/" . $template . "/snippets");
?>
';
		<?
		for($i=0,$len = count($ar); $i < $len; $i++)
		{
			$key = CUtil::JSEscape($ar[$i]['path'].($ar[$i]['path'] != '' ? '/' : '').$ar[$i]['name']);
		?>
window.arSnGroups['<?php 
echo $template;
?>
']['<?php 
echo $key;
?>
'] =
{
	name: '<?php 
echo CUtil::JSEscape($ar[$i]['name']);
?>
',
	path: '<?php 
echo CUtil::JSEscape($ar[$i]['path']);
?>
',
	level: '<?php 
echo CUtil::JSEscape($ar[$i]['level']);
?>
',
	default_name: '<?php 
echo CUtil::JSEscape($ar[$i]['default_name']);
?>
'
};
		<?
		}
		?></script><?
	}
示例#2
0
	public static function GetSnippets($templateId, $bClearCache = false)
	{
		return array(
			'items' => CSnippets::LoadList(
					array(
						'template' => $templateId,
						'bClearCache' => $bClearCache,
						'returnArray' => true
					)
				),
			'groups' => CSnippets::GetGroupList(
					array(
						'template' => $templateId,
						'bClearCache' => $bClearCache
					)
				),
			'rootDefaultFilename' => CSnippets::GetDefaultFileName($_SERVER["DOCUMENT_ROOT"].BX_PERSONAL_ROOT."/templates/".$templateId."/snippets")
		);
	}
示例#3
0
 /**
  * Updates existent snippet
  *
  * @param array - list of params
  * @return bool or object - result
  */
 public static function Update($params = array())
 {
     global $APPLICATION;
     $res = false;
     $title = $params['title'];
     $description = $params['description'];
     $currentPath = $params['new'] ? '' : CFileMan::SecurePathVar($params['current_path']);
     $path = CFileMan::SecurePathVar($params['path']);
     $template = CFileMan::SecurePathVar($params['template']);
     $code = $params['code'];
     $contPath = $_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/templates/" . $template . "/snippets";
     $snippetPath = $contPath . ($path == '' ? '' : '/' . $path);
     $io = CBXVirtualIo::GetInstance();
     if (!$io->DirectoryExists($contPath)) {
         $io->CreateDirectory($contPath);
     }
     if ($params['new']) {
         $fileName = CSnippets::GetDefaultFileName($snippetPath) . '.snp';
     } else {
         $currentPath = $contPath . '/' . $currentPath;
         $oldSnippetPath = $io->ExtractPathFromPath($currentPath);
         if ($snippetPath !== $oldSnippetPath && $io->FileExists($currentPath)) {
             $io->Delete($currentPath);
             $fileName = CSnippets::GetDefaultFileName($snippetPath) . '.snp';
         } else {
             $fileName = $io->ExtractNameFromPath($currentPath);
         }
     }
     $key = ($path === '' ? '' : $path . '/') . $fileName;
     if (!$io->ValidatePathString($snippetPath . '/' . $fileName) || IsFileUnsafe($snippetPath . '/' . $fileName) || HasScriptExtension($snippetPath . '/' . $fileName)) {
         return false;
     }
     // 1. Save new snippet with new content
     if ($code) {
         $APPLICATION->SaveFileContent($snippetPath . '/' . $fileName, $code);
     }
     // 2. Rewrite title & description in .content.php
     if ($title || $description) {
         $SNIPPETS = array();
         if ($io->FileExists($contPath . "/.content.php")) {
             @(include $contPath . "/.content.php");
         }
         if ($title) {
             $SNIPPETS[$key]['title'] = $title;
         }
         if ($description) {
             $SNIPPETS[$key]['description'] = $description;
         }
         $contentSrc = '<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?>' . chr(10);
         $contentSrc .= '<?' . chr(10) . '$SNIPPETS = Array();' . chr(10);
         foreach ($SNIPPETS as $k => $snip) {
             if ($io->FileExists(CFileMan::SecurePathVar($contPath . '/' . $k))) {
                 $contentSrc .= '$SNIPPETS[\'' . CUtil::addslashes($k) . '\'] = Array(';
                 if (isset($snip['title']) && $snip['title'] !== '') {
                     $contentSrc .= '\'title\' => \'' . Cutil::addslashes($snip['title']) . '\'';
                     if (isset($snip['description']) && $snip['description'] !== '') {
                         $contentSrc .= ', ';
                     }
                 }
                 if (isset($snip['description']) && $snip['description'] !== '') {
                     $contentSrc .= '\'description\' => \'' . Cutil::addslashes($snip['description']) . '\'';
                 }
                 $contentSrc .= ');' . chr(10);
             }
         }
         $contentSrc .= '?>';
         $APPLICATION->SaveFileContent($contPath . "/.content.php", $contentSrc);
     }
     $res = array('result' => true);
     CSnippets::ClearCache();
     return $res;
 }