• Модуль: fileman
  • Путь к файлу: ~/bitrix/modules/fileman/classes/general/html_editor.php
  • Класс: CHTMLEditor
  • Вызов: CHTMLEditor::RequestAction
static function RequestAction($action = '')
{
	global $USER;
	$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
		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
		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;

		case "uploadfile":
			$uploader = new CFileUploader(
				array("events" => array(
					"onFileIsUploaded" => function ($hash, &$file, &$package, &$upload, &$error)
					{
						$error = CFile::CheckFile($file["files"]["default"], 0, "image/", CFile::GetImageExtensions());
						$io = CBXVirtualIo::GetInstance();
						$fileName = $file["name"];

						if(empty($error) && $io->ValidateFilenameString($fileName) && $io->ValidatePathString(self::GetUploadPath().$fileName))
						{
							if (COption::GetOptionString('fileman', "use_medialib", "Y") != "N" &&
								CMedialib::CanDoOperation('medialib_view_collection', 0, false, true))
							{
								$image = CMedialib::AutosaveImage($file["files"]["default"]);
								if ($image && $image['PATH'])
								{
									$file["uploadedPath"] = $image['PATH'];
									return true;
								}
								else
								{
									return false;
								}
							}
							else
							{
								$newPath = self::GetUploadPath().$fileName;
								if($io->FileExists($_SERVER["DOCUMENT_ROOT"].$newPath))
								{
									$ext = GetFileExtension($fileName);
									$name = GetFileNameWithoutExtension($fileName);
									$iter = 1;
									while(true && $iter < 1000)
									{
										$newPath = self::GetUploadPath().$name.'('.$iter.').'.$ext;
										if(!$io->FileExists($_SERVER["DOCUMENT_ROOT"].$newPath))
										{
											break;
										}
										$iter++;
									}
								}
								CopyDirFiles($file["files"]["default"]["tmp_name"], $_SERVER["DOCUMENT_ROOT"].$newPath);
								$file["uploadedPath"] = $newPath;
								return true;
							}
						}
					}
				)),
				"get"
			);
			$uploader->checkPost();
			$result = array('result' => true);
			break;
	}

	self::ShowResponse(intval($_REQUEST['reqId']), $result);
}