function replacer($str)
{
    $str = CFileMan::SecurePathVar($str);
    $str = preg_replace("/[^a-zA-Z0-9_\\.-\\+]/is", "_", $str);
    return $str;
}
Exemple #2
0
	public static function RequestAction($action = '')
	{
		global $USER, $APPLICATION;
		$result = array();

		switch($action)
		{
			case "load_site_template":
				if (!$USER->CanDoOperation('fileman_view_file_structure'))
					break;
				$siteTemplate = $_REQUEST['site_template'];
				$siteId = isset($_REQUEST['site_id']) ? $_REQUEST['site_id'] : SITE_ID;
				$result = self::GetSiteTemplateParams($siteTemplate, $siteId);
				break;
			case "load_components_list":
				if (!$USER->CanDoOperation('fileman_view_file_structure'))
					break;
				$siteTemplate = $_REQUEST['site_template'];
				$result = self::GetComponents($siteTemplate, true);
				break;

			case "video_oembed":
				$result = self::GetVideoOembed($_REQUEST['video_source']);
				break;

			// Snippets actions
			case "load_snippets_list":
				if (!$USER->CanDoOperation('fileman_view_file_structure'))
					break;
				$template = $_REQUEST['site_template'];
				$result = array(
					'result' => true,
					'snippets' => array($template => self::GetSnippets($template, $_REQUEST['clear_cache'] == 'Y'))
				);
				break;
			case "edit_snippet":
				if (!$USER->CanDoOperation('fileman_view_file_structure'))
					break;
				CUtil::JSPostUnEscape();
				$template = $_REQUEST['site_template'];

				// Update
				if ($_REQUEST['current_path'])
				{
					$result = CSnippets::Update(array(
						'template' => $template,
						'path' => $_REQUEST['path'],
						'code' => $_REQUEST['code'],
						'title' => $_REQUEST['name'],
						'current_path' => $_REQUEST['current_path'],
						'description' => $_REQUEST['description']
					));
				}
				// Add new
				else
				{
					$result = CSnippets::Add(array(
						'template' => $template,
						'path' => $_REQUEST['path'],
						'code' => $_REQUEST['code'],
						'title' => $_REQUEST['name'],
						'description' => $_REQUEST['description']
					));
				}

				if ($result && $result['result'])
				{
					$result['snippets'] = array($template => self::GetSnippets($template));
				}

				break;
			case "remove_snippet":
				if (!$USER->CanDoOperation('fileman_view_file_structure'))
					break;
				CUtil::JSPostUnEscape();
				$template = $_REQUEST['site_template'];

				$res = CSnippets::Remove(array(
					'template' => $template,
					'path' => $_REQUEST['path']
				));

				if ($res)
				{
					$result = array(
						'result' => true,
						'snippets' => array($template => self::GetSnippets($template))
					);
				}
				else
				{
					$result = array('result' => false);
				}

				break;
			case "snippet_add_category":
				if (!$USER->CanDoOperation('fileman_view_file_structure'))
					break;
				CUtil::JSPostUnEscape();
				$template = $_REQUEST['site_template'];
				$res = CSnippets::CreateCategory(array(
					'template' => $template,
					'name' => $_REQUEST['category_name'],
					'parent' => $_REQUEST['category_parent']
				));

				if ($res)
				{
					$result = array(
						'result' => true,
						'snippets' => array($template => self::GetSnippets($template))
					);
				}
				else
				{
					$result = array('result' => false);
				}
				break;
			case "snippet_remove_category":
				if (!$USER->CanDoOperation('fileman_view_file_structure'))
					break;
				CUtil::JSPostUnEscape();
				$template = $_REQUEST['site_template'];
				$res = CSnippets::RemoveCategory(array(
					'template' => $template,
					'path' => $_REQUEST['category_path']
				));

				if ($res)
				{
					$result = array(
						'result' => true,
						'snippets' => array($template => self::GetSnippets($template))
					);
				}
				else
				{
					$result = array('result' => false);
				}
				break;
			case "snippet_rename_category":
				if (!$USER->CanDoOperation('fileman_view_file_structure'))
					break;
				CUtil::JSPostUnEscape();
				$template = $_REQUEST['site_template'];
				$res = CSnippets::RenameCategory(array(
					'template' => $template,
					'path' => $_REQUEST['category_path'],
					'new_name' => $_REQUEST['category_new_name']
				));

				if ($res)
				{
					$result = array(
						'result' => true,
						'snippets' => array($template => self::GetSnippets($template))
					);
				}
				else
				{
					$result = array('result' => false);
				}
				break;
			// END *** Snippets actions

			// spellcheck
			case "spellcheck_words":
			case "spellcheck_add_word":
				CUtil::JSPostUnEscape();
				$spellChecker = new CSpellchecker(array(
					"lang" => $_REQUEST['lang'],
					"skip_length" => 2,
					"use_pspell" => $_REQUEST['use_pspell'] !== "N",
					"use_custom_spell" => $_REQUEST['use_custom_spell'] !== "N",
					"mode" => PSPELL_FAST
				));

				if ($action == "spellcheck_words")
				{
					$words = (isset($_REQUEST['words']) && is_array($_REQUEST['words'])) ? $_REQUEST['words'] : array();
					$result = array(
						'words' => $spellChecker->checkWords($words)
					);
				}
				else // Add word
				{
					$word = CFileMan::SecurePathVar($_REQUEST['word']);
					$spellChecker->addWord($word);
				}
				break;
			// END *** spellcheck
		}

		self::ShowResponse(intVal($_REQUEST['reqId']), $result);
	}
 public static function NormalizePath($path)
 {
     $path = CFileMan::SecurePathVar(Rel2Abs("/", $path));
     $path = rtrim($path, '/');
     return $path;
 }
Exemple #4
0
    function PreviewFlash($Params)
    {
        if (CModule::IncludeModule("fileman")) {
            global $APPLICATION, $USER;
            if (CModule::IncludeModule("compression")) {
                CCompress::Disable2048Spaces();
            }
            $path = $Params['path'];
            $path = CFileMan::SecurePathVar($path);
            $path = Rel2Abs("/", $path);
            $arPath = array($Params['site'], $path);
            if (!$USER->CanDoFileOperation('fm_view_file', $arPath)) {
                $path = '';
            }
            if ($path == "") {
                return;
            }
            $APPLICATION->RestartBuffer();
            ?>
<HTML>
<HEAD></HEAD>
<BODY id="__flash" style="margin:0px; border-width: 0px;">
<embed id="__flash_preview" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="__flash_preview" quality="high" width="<?php 
            echo $Params['width'];
            ?>
" height="<?php 
            echo $Params['height'];
            ?>
" src="<?php 
            echo htmlspecialcharsex($path);
            ?>
" />
</BODY>
</HTML>
<?php 
            die;
        }
    }
Exemple #5
0
	public static function GetGroups($Params)
	{
		$template = CFileMan::SecurePathVar($Params['template']);
		$arSnGroups = Array();
		CSnippets::InspectDir($arSnGroups, "", $template);
		CSnippets::DisplayJSGroups($template, $arSnGroups);
	}
Exemple #6
0
 public static function RequestAction($action = '')
 {
     global $USER, $APPLICATION;
     $result = array();
     switch ($action) {
         case "load_site_template":
             if (!$USER->CanDoOperation('fileman_view_file_structure')) {
                 break;
             }
             $siteTemplate = $_REQUEST['site_template'];
             $siteId = isset($_REQUEST['site_id']) ? $_REQUEST['site_id'] : SITE_ID;
             $result = self::GetSiteTemplateParams($siteTemplate, $siteId);
             break;
         case "load_components_list":
             if (!$USER->CanDoOperation('fileman_view_file_structure')) {
                 break;
             }
             $siteTemplate = $_REQUEST['site_template'];
             $componentFilter = isset($_REQUEST['componentFilter']) ? $_REQUEST['componentFilter'] : false;
             $result = self::GetComponents($siteTemplate, true, $componentFilter);
             break;
         case "video_oembed":
             $result = self::GetVideoOembed($_REQUEST['video_source']);
             break;
             // Snippets actions
         // Snippets actions
         case "load_snippets_list":
             if (!$USER->CanDoOperation('fileman_view_file_structure')) {
                 break;
             }
             $template = $_REQUEST['site_template'];
             $result = array('result' => true, 'snippets' => array($template => self::GetSnippets($template, $_REQUEST['clear_cache'] == 'Y')));
             break;
         case "edit_snippet":
             if (!$USER->CanDoOperation('fileman_view_file_structure')) {
                 break;
             }
             CUtil::JSPostUnEscape();
             $template = $_REQUEST['site_template'];
             // Update
             if ($_REQUEST['current_path']) {
                 $result = CSnippets::Update(array('template' => $template, 'path' => $_REQUEST['path'], 'code' => $_REQUEST['code'], 'title' => $_REQUEST['name'], 'current_path' => $_REQUEST['current_path'], 'description' => $_REQUEST['description']));
             } else {
                 $result = CSnippets::Add(array('template' => $template, 'path' => $_REQUEST['path'], 'code' => $_REQUEST['code'], 'title' => $_REQUEST['name'], 'description' => $_REQUEST['description']));
             }
             if ($result && $result['result']) {
                 $result['snippets'] = array($template => self::GetSnippets($template));
             }
             break;
         case "remove_snippet":
             if (!$USER->CanDoOperation('fileman_view_file_structure')) {
                 break;
             }
             CUtil::JSPostUnEscape();
             $template = $_REQUEST['site_template'];
             $res = CSnippets::Remove(array('template' => $template, 'path' => $_REQUEST['path']));
             if ($res) {
                 $result = array('result' => true, 'snippets' => array($template => self::GetSnippets($template)));
             } else {
                 $result = array('result' => false);
             }
             break;
         case "snippet_add_category":
             if (!$USER->CanDoOperation('fileman_view_file_structure')) {
                 break;
             }
             CUtil::JSPostUnEscape();
             $template = $_REQUEST['site_template'];
             $res = CSnippets::CreateCategory(array('template' => $template, 'name' => $_REQUEST['category_name'], 'parent' => $_REQUEST['category_parent']));
             if ($res) {
                 $result = array('result' => true, 'snippets' => array($template => self::GetSnippets($template)));
             } else {
                 $result = array('result' => false);
             }
             break;
         case "snippet_remove_category":
             if (!$USER->CanDoOperation('fileman_view_file_structure')) {
                 break;
             }
             CUtil::JSPostUnEscape();
             $template = $_REQUEST['site_template'];
             $res = CSnippets::RemoveCategory(array('template' => $template, 'path' => $_REQUEST['category_path']));
             if ($res) {
                 $result = array('result' => true, 'snippets' => array($template => self::GetSnippets($template)));
             } else {
                 $result = array('result' => false);
             }
             break;
         case "snippet_rename_category":
             if (!$USER->CanDoOperation('fileman_view_file_structure')) {
                 break;
             }
             CUtil::JSPostUnEscape();
             $template = $_REQUEST['site_template'];
             $res = CSnippets::RenameCategory(array('template' => $template, 'path' => $_REQUEST['category_path'], 'new_name' => $_REQUEST['category_new_name']));
             if ($res) {
                 $result = array('result' => true, 'snippets' => array($template => self::GetSnippets($template)));
             } else {
                 $result = array('result' => false);
             }
             break;
             // END *** Snippets actions
             // spellcheck
         // END *** Snippets actions
         // spellcheck
         case "spellcheck_words":
         case "spellcheck_add_word":
             CUtil::JSPostUnEscape();
             $spellChecker = new CSpellchecker(array("lang" => $_REQUEST['lang'], "skip_length" => 2, "use_pspell" => $_REQUEST['use_pspell'] !== "N", "use_custom_spell" => $_REQUEST['use_custom_spell'] !== "N", "mode" => PSPELL_FAST));
             if ($action == "spellcheck_words") {
                 $words = isset($_REQUEST['words']) && is_array($_REQUEST['words']) ? $_REQUEST['words'] : array();
                 $result = array('words' => $spellChecker->checkWords($words));
             } else {
                 $word = CFileMan::SecurePathVar($_REQUEST['word']);
                 $spellChecker->addWord($word);
             }
             break;
             // END *** spellcheck
         // END *** spellcheck
         case "load_file_dialogs":
             $editorId = $_REQUEST['editor_id'];
             $editorId = preg_replace("/[^a-zA-Z0-9_-]/is", "_", $editorId);
             CAdminFileDialog::ShowScript(array("event" => "BxOpenFileBrowserWindFile" . $editorId, "arResultDest" => array("FUNCTION_NAME" => "OnFileDialogSelect" . $editorId), "arPath" => array("SITE" => SITE_ID), "select" => 'F', "operation" => 'O', "showUploadTab" => true, "showAddToMenuTab" => false, "fileFilter" => 'image', "allowAllFiles" => true, "SaveConfig" => true));
             CMedialib::ShowBrowseButton(array('value' => '...', 'event' => "BxOpenFileBrowserWindFile" . $editorId, 'button_id' => "bx-open-file-link-medialib-but-" . $editorId, 'id' => "bx_open_file_link_medialib_button_" . $editorId, 'MedialibConfig' => array("event" => "BxOpenFileBrowserFileMl" . $editorId, "arResultDest" => array("FUNCTION_NAME" => "OnFileDialogSelect" . $editorId)), 'useMLDefault' => false));
             CMedialib::ShowBrowseButton(array('value' => '...', 'event' => "BxOpenFileBrowserWindFile" . $editorId, 'button_id' => "bx-open-file-medialib-but-" . $editorId, 'id' => "bx_open_file_medialib_button_" . $editorId, 'MedialibConfig' => array("event" => "BxOpenFileBrowserImgFileMl" . $editorId, "arResultDest" => array("FUNCTION_NAME" => "OnFileDialogImgSelect" . $editorId), "types" => array('image'))));
             $result = array('result' => true);
             break;
     }
     self::ShowResponse(intVal($_REQUEST['reqId']), $result);
 }
Exemple #7
0
	public static function GetGroupList($Params)
	{
		$template = CFileMan::SecurePathVar($Params['template']);

		$arGroups = false;
		$CACHE_SNIPPETS = Array();

		if ($Params['bClearCache'])
			CSnippets::ClearCache();


		if (!$arGroups || !is_array($arGroups))
		{
			$arGroups = Array();
			CSnippets::InspectDir($arGroups, "", $template);
			$CACHE_SNIPPETS[$template] = $arGroups;
		}
		return $arGroups;
	}
Exemple #8
0
 public static function GetGroupList($Params)
 {
     global $CACHE_MANAGER;
     $template = CFileMan::SecurePathVar($Params['template']);
     $arGroups = false;
     $CACHE_SNIPPETS = array();
     if ($Params['bClearCache']) {
         CSnippets::ClearCache();
     }
     $ttl = 30 * 24 * 60 * 60;
     // 30 days
     if ($CACHE_MANAGER->Read($ttl, "fileman_snippet_group")) {
         $CACHE_SNIPPETS = $CACHE_MANAGER->Get("fileman_snippet_group");
         if (isset($CACHE_SNIPPETS[$template])) {
             $arGroups = $CACHE_SNIPPETS[$template];
         }
     }
     if (!$arGroups || !is_array($arGroups)) {
         $arGroups = array();
         CSnippets::InspectDir($arGroups, "", $template);
         $CACHE_SNIPPETS[$template] = $arGroups;
         $CACHE_MANAGER->Set("fileman_snippet_group", $CACHE_SNIPPETS);
     }
     return $arGroups;
 }
Exemple #9
0
 public static function RemoveCategory($params)
 {
     $res = false;
     if (is_array($params) && isset($params['path'])) {
         $path = CFileMan::SecurePathVar($params['path']);
         $template = isset($params['template']) && $params['template'] !== '' ? CFileMan::SecurePathVar($params['template']) : '.default';
         $basePath = $_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/templates/" . $template . "/snippets";
         $categoryPath = $basePath . '/' . $path;
         $io = CBXVirtualIo::GetInstance();
         if ($io->DirectoryExists($categoryPath)) {
             $res = $io->Delete($categoryPath);
         }
         CSnippets::ClearCache();
     }
     return $res;
 }