Example #1
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);
	}
Example #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'];
             $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);
 }