1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
light_editor.php
См. документацию.
1<?
3class CLightHTMLEditor // LHE
4{
5 private $Id;
6 private $cssPath;
7 private $arJSPath;
8 private $bBBCode;
9 private $bRecreate;
10 private $mess;
11 private $messOld;
12 private $bAutorized;
13 private $bUseFileDialogs;
14 private $bUseMedialib;
15 private $bResizable;
16 private $bManualResize;
17 private $bAutoResize;
18 private $bInitByJS;
19 private $bSaveOnBlur;
20 private $content;
21 private $inputName;
22 private $inputId;
23 private $videoSettings;
24 private $jsObjName;
25 private $JSConfig;
26
27 function Init(&$arParams)
28 {
29 global $USER, $APPLICATION;
30 $basePath = '/bitrix/js/fileman/light_editor/';
31 $this->Id = (isset($arParams['id']) && $arParams['id'] <> '') ? $arParams['id'] : 'bxlhe'.mb_substr(uniqid(mt_rand(), true), 0, 4);
32 $this->Id = preg_replace("/[^a-zA-Z0-9_:\.]/is", "", $this->Id);
33
34 $this->cssPath = $basePath."light_editor.css";
35 $APPLICATION->SetAdditionalCSS($this->cssPath);
36
37 $this->arJSPath = array(
38 $basePath.'le_dialogs.js',
39 $basePath.'le_controls.js',
40 $basePath.'le_toolbarbuttons.js',
41 $basePath.'le_core.js'
42 );
43
44 $this->bBBCode = ($arParams['BBCode'] ?? null) === true;
45 $this->bRecreate = ($arParams['bRecreate'] ?? null) === true;
46 $arJS = Array();
47 $arCSS = Array();
48
49 foreach(GetModuleEvents("fileman", "OnBeforeLightEditorScriptsGet", true) as $arEvent)
50 {
51 $tmp = ExecuteModuleEventEx($arEvent, array($this->Id, $arParams));
52 if (!is_array($tmp))
53 continue;
54
55 if (is_array($tmp['JS']))
56 {
57 for($i = 0, $c = count($tmp['JS']); $i < $c; $i++)
58 {
59 if(file_exists($_SERVER['DOCUMENT_ROOT'].$tmp['JS'][$i]))
60 $this->arJSPath[] = $tmp['JS'][$i];
61 }
62 }
63 }
64
65 foreach($this->arJSPath as $path)
66 {
67 $APPLICATION->AddHeadScript($path);
68 }
69
70 //Messages
71 $langPath = $_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/fileman/lang/'.LANGUAGE_ID.'/classes/general/light_editor_js.php';
72 if(!file_exists($langPath))
73 $langPath = $_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/fileman/lang/en/classes/general/light_editor_js.php';
74 $this->mess = __IncludeLang($langPath, true, true);
75 $this->messOld = array();
76
77 if (!empty($this->mess))
78 {
79 $this->messOld = array('Image' => $this->mess['Image'], 'Video' => $this->mess['Video'],'ImageSizing' => $this->mess['ImageSizing']);
80
81 $jsMsg = "<script bxrunfirst>LHE_MESS = window.LHE_MESS = ".CUtil::PhpToJSObject($this->messOld)."; (window.BX||top.BX).message(".CUtil::PhpToJSObject($this->mess, false).");</script>";
82
83 $APPLICATION->AddLangJS($jsMsg);
84 }
85
86 $this->bAutorized = is_object($USER) && $USER->IsAuthorized();
87 $this->bUseFileDialogs = $arParams['bUseFileDialogs'] !== false && $this->bAutorized;
88 $this->bUseMedialib = ($arParams['bUseMedialib'] ?? null) !== false && COption::GetOptionString('fileman', "use_medialib", "Y") == "Y" && CMedialib::CanDoOperation('medialib_view_collection', 0);
89
90 $this->bResizable = ($arParams['bResizable'] ?? null) === true;
91 $this->bManualResize = $this->bResizable && ($arParams['bManualResize'] ?? null) !== false;
92 $this->bAutoResize = ($arParams['bAutoResize'] ?? null) !== false;
93 $this->bInitByJS = ($arParams['bInitByJS'] ?? null) === true;
94 $this->bSaveOnBlur = ($arParams['bSaveOnBlur'] ?? null) !== false;
95 $this->content = ($arParams['content'] ?? null);
96 $arParams['inputName'] ??= null;
97 $this->inputName = isset($arParams['inputName']) ? $arParams['inputName'] : 'lha_content';
98 $arParams['inputId'] ??= null;
99 $this->inputId = isset($arParams['inputId']) ? $arParams['inputId'] : 'lha_content_id';
100 $this->videoSettings = is_array($arParams['videoSettings'] ?? null) ? $arParams['videoSettings'] : array(
101 'maxWidth' => 640,
102 'maxHeight' => 480,
103 'WMode' => 'transparent',
104 'windowless' => true,
105 'bufferLength' => 20,
106 'skin' => '/bitrix/components/bitrix/player/mediaplayer/skins/bitrix.swf',
107 'logo' => ''
108 );
109
110 if (!is_array($arParams['arFonts'] ?? null) || count($arParams['arFonts']) <= 0)
111 $arParams['arFonts'] = array('Arial', 'Verdana', 'Times New Roman', 'Courier', 'Tahoma', 'Georgia', 'Optima', 'Impact', 'Geneva', 'Helvetica');
112
113 if (!is_array($arParams['arFontSizes'] ?? null) || count($arParams['arFontSizes']) <= 0)
114 $arParams['arFontSizes'] = array('1' => 'xx-small', '2' => 'x-small', '3' => 'small', '4' => 'medium', '5' => 'large', '6' => 'x-large', '7' => 'xx-large');
115
116 // Tables
117 //$this->arJSPath[] = $this->GetActualPath($basePath.'le_table.js');
118 $this->jsObjName = (isset($arParams['jsObjName']) && $arParams['jsObjName'] <> '') ? $arParams['jsObjName'] : 'LightHTMLEditor'.$this->Id;
119 $this->jsObjName = preg_replace("/[^a-zA-Z0-9_:\.]/is", "", $this->jsObjName);
120
121 if ($this->bResizable)
122 {
123 // Get height user settings
124 $userOpt = CUserOptions::GetOption(
125 'fileman',
126 'LHESize_'.$this->Id,
127 array('height' => $arParams['height'])
128 );
129 $arParams['height'] = intval($userOpt['height']) > 0 ? $userOpt['height'] : $arParams['height'];
130 }
131
132 $this->JSConfig = array(
133 'id' => $this->Id,
134 'content' => $this->content,
135 'bBBCode' => $this->bBBCode,
136 'bUseFileDialogs' => $this->bUseFileDialogs,
137 'bUseMedialib' => $this->bUseMedialib,
138 'arSmiles' => ($arParams['arSmiles'] ?? null),
139 'arFonts' => ($arParams['arFonts'] ?? null),
140 'arFontSizes' => ($arParams['arFontSizes'] ?? null),
141 'inputName' => $this->inputName,
142 'inputId' => $this->inputId,
143 'videoSettings' => $this->videoSettings,
144 'bSaveOnBlur' => $this->bSaveOnBlur,
145 'bResizable' => $this->bResizable,
146 'autoResizeSaveSize' => ($arParams['autoResizeSaveSize'] ?? null) !== false,
147 'bManualResize' => $this->bManualResize,
148 'bAutoResize' => $this->bAutoResize,
149 'bReplaceTabToNbsp' => true,
150 'bSetDefaultCodeView' => isset($arParams['bSetDefaultCodeView']) && $arParams['bSetDefaultCodeView'],
151 'bBBParseImageSize' => isset($arParams['bBBParseImageSize']) && $arParams['bBBParseImageSize'],
152 'smileCountInToolbar' => intval(($arParams['smileCountInToolbar'] ?? null)),
153 'bQuoteFromSelection' => isset($arParams['bQuoteFromSelection']) && $arParams['bQuoteFromSelection'],
154 'bConvertContentFromBBCodes' => isset($arParams['bConvertContentFromBBCodes']) && $arParams['bConvertContentFromBBCodes'],
155 'oneGif' => '/bitrix/images/1.gif',
156 'imagePath' => '/bitrix/images/fileman/light_htmledit/'
157 );
158
159 // Set editor from visual mode to textarea for mobile devices
160 if (!isset($this->JSConfig['bSetDefaultCodeView']) && CLightHTMLEditor::IsMobileDevice())
161 $this->JSConfig['bSetDefaultCodeView'] = true;
162
163 if (isset($arParams['width']) && intval($arParams['width']) > 0)
164 $this->JSConfig['width'] = $arParams['width'];
165 if (isset($arParams['height']) && intval($arParams['height']) > 0)
166 $this->JSConfig['height'] = $arParams['height'];
167 if (isset($arParams['toolbarConfig']))
168 $this->JSConfig['toolbarConfig'] = $arParams['toolbarConfig'];
169 if (isset($arParams['documentCSS']))
170 $this->JSConfig['documentCSS'] = $arParams['documentCSS'];
171 if (isset($arParams['fontFamily']))
172 $this->JSConfig['fontFamily'] = $arParams['fontFamily'];
173 if (isset($arParams['fontSize']))
174 $this->JSConfig['fontSize'] = $arParams['fontSize'];
175 if (isset($arParams['lineHeight']))
176 $this->JSConfig['lineHeight'] = $arParams['lineHeight'];
177 if (isset($arParams['bHandleOnPaste']))
178 $this->JSConfig['bHandleOnPaste'] = $arParams['bHandleOnPaste'];
179 if (isset($arParams['autoResizeOffset']))
180 $this->JSConfig['autoResizeOffset'] = $arParams['autoResizeOffset'];
181 if (isset($arParams['autoResizeMaxHeight']))
182 $this->JSConfig['autoResizeMaxHeight'] = $arParams['autoResizeMaxHeight'];
183 if (isset($arParams['controlButtonsHeight']))
184 $this->JSConfig['controlButtonsHeight'] = $arParams['controlButtonsHeight'];
185
186 if ($this->bBBCode)
187 {
188 $this->JSConfig['bParceBBImageSize'] = true;
189 }
190
191 if (isset($arParams['ctrlEnterHandler']))
192 $this->JSConfig['ctrlEnterHandler'] = $arParams['ctrlEnterHandler'];
193 }
194
196 {
197 return $path.'?'.@filemtime($_SERVER['DOCUMENT_ROOT'].$path);
198 }
199
200 function Show($arParams)
201 {
202 CUtil::InitJSCore(array('window', 'ajax'));
203 $this->Init($arParams);
204 $this->BuildSceleton();
205 $this->InitScripts();
206
207 if ($this->bUseFileDialogs)
208 $this->InitFileDialogs();
209
210 if ($this->bUseMedialib)
211 $this->InitMedialibDialogs();
212 }
213
214 function BuildSceleton()
215 {
216 $width = isset($this->JSConfig['width']) && intval($this->JSConfig['width']) > 0 ? $this->JSConfig['width'] : "100%";
217 $height = isset($this->JSConfig['height']) && intval($this->JSConfig['height']) > 0 ? $this->JSConfig['height'] : "100%";
218
219 $widthUnit = mb_strpos($width, "%") === false ? "px" : "%";
220 $heightUnit = mb_strpos($height, "%") === false ? "px" : "%";
221 $width = intval($width);
222 $height = intval($height);
223
224 $editorCellHeight = ($heightUnit == "px" && $height > 50 ? "height:".($height - 27 - ($this->bResizable ? 3 : 0))."px" : "");
225 ?>
226 <?/* <img src="/bitrix/images/1.gif" width="300" height="1" id="bxlhe_ww_<?=$this->Id?>" />*/?>
227<div class="bxlhe-frame" id="bxlhe_frame_<?=$this->Id?>" style="width:<?=$width.$widthUnit?>; height:<?=$height.$heightUnit?>;"><table class="bxlhe-frame-table" cellspacing="0" style="height:<?=$height.$heightUnit?>; width: 100%;">
228 <tr class="bxlhe-editor-toolbar-row"><td class="bxlhe-editor-buttons" style="height:27px;"><div class="lhe-stat-toolbar-cont lhe-stat-toolbar-cont-preload"></div></td></tr>
229 <tr><td class="bxlhe-editor-cell" style="<?=$editorCellHeight?>"></td></tr>
230 <?if ($this->bResizable):?>
231 <tr><td class="lhe-resize-row" style="height: 3px;"><img id="bxlhe_resize_<?=$this->Id?>" src="/bitrix/images/1.gif"/></td></tr>
232 <?endif;?>
233</table></div>
234 <?
235 }
236
237 function InitScripts()
238 {
239 ob_start();
240 foreach(GetModuleEvents("fileman", "OnIncludeLightEditorScript", true) as $arEvent)
241 ExecuteModuleEventEx($arEvent, array($this->Id));
242 $scripts = trim(ob_get_contents());
243 ob_end_clean();
244
245 $scripts = str_replace("<script>", "", $scripts);
246 $scripts = str_replace("</script>", "", $scripts);
247
248 $loadScript = "";
249 foreach ($this->arJSPath as $path)
250 {
251 if ($loadScript != "")
252 {
253 $loadScript .= ", ";
254 }
255 $loadScript .= "\"".$this->GetActualPath($path)."\"";
256 }
257 ?>
258 <script>
259 function LoadLHE_<?=$this->Id?>()
260 {
261 function _lheScriptloaded()
262 {
263 if (!window.JCLightHTMLEditor)
264 return setTimeout(_lheScriptloaded, 10);
265
266 <?if (!empty($scripts)):?>
267 // User's customization scripts here
268 try{<?= $scripts?>}
269 catch(e){alert('Errors in customization scripts! ' + e);}
270 <?endif;?>
271
272 if (
273 <?= ($this->bRecreate ? 'true' : 'false')?> ||
274 JCLightHTMLEditor.items['<?= $this->Id?>'] == undefined ||
275 !document.body.contains(JCLightHTMLEditor.items['<?= $this->Id?>'].pFrame)
276 )
277 {
278 top.<?=$this->jsObjName?> = window.<?=$this->jsObjName?> = new window.JCLightHTMLEditor(<?=CUtil::PhpToJSObject($this->JSConfig)?>);
279 BX.onCustomEvent(window, 'LHE_ConstructorInited', [window.<?=$this->jsObjName?>]);
280 }
281 }
282
283 if (!window.JCLightHTMLEditor)
284 {
285 BX.loadCSS("<?=$this->GetActualPath($this->cssPath)?>");
286 <?if (!empty($this->mess)):?>
287 LHE_MESS = window.LHE_MESS = "<?=CUtil::PhpToJSObject($this->messOld)?>"; (window.BX||top.BX).message(<?=CUtil::PhpToJSObject($this->mess, false)?>);
288 <?endif?>
289 BX.loadScript([<?=$loadScript?>], _lheScriptloaded);
290 }
291 else
292 {
293 _lheScriptloaded();
294 }
295 }
296
297 <?if(!$this->bInitByJS):?>
298 BX.ready(function(){LoadLHE_<?=$this->Id?>();});
299 <?endif;?>
300
301 </script><?
302 }
303
305 {
306 // Link
308 "event" => "LHED_Link_FDOpen",
309 "arResultDest" => Array("ELEMENT_ID" => "lhed_link_href"),
310 "arPath" => Array("SITE" => SITE_ID),
311 "select" => 'F',
312 "operation" => 'O',
313 "showUploadTab" => true,
314 "showAddToMenuTab" => false,
315 "fileFilter" => 'php, html',
316 "allowAllFiles" => true,
317 "SaveConfig" => true
318 ));
319
320 // Image
322 (
323 "event" => "LHED_Img_FDOpen",
324 "arResultDest" => Array("FUNCTION_NAME" => "LHED_Img_SetUrl"),
325 "arPath" => Array("SITE" => SITE_ID),
326 "select" => 'F',
327 "operation" => 'O',
328 "showUploadTab" => true,
329 "showAddToMenuTab" => false,
330 "fileFilter" => 'image',
331 "allowAllFiles" => true,
332 "SaveConfig" => true
333 ));
334
335 // video path
337 (
338 "event" => "LHED_VideoPath_FDOpen",
339 "arResultDest" => Array("FUNCTION_NAME" => "LHED_Video_SetPath"),
340 "arPath" => Array("SITE" => SITE_ID),
341 "select" => 'F',
342 "operation" => 'O',
343 "showUploadTab" => true,
344 "showAddToMenuTab" => false,
345 "fileFilter" => 'wmv,wma,flv,vp6,mp3,mp4,aac,jpg,jpeg,gif,png',
346 "allowAllFiles" => true,
347 "SaveConfig" => true
348 ));
349
350 // video preview
352 (
353 "event" => "LHED_VideoPreview_FDOpen",
354 "arResultDest" => Array("ELEMENT_ID" => "lhed_video_prev_path"),
355 "arPath" => Array("SITE" => SITE_ID),
356 "select" => 'F',
357 "operation" => 'O',
358 "showUploadTab" => true,
359 "showAddToMenuTab" => false,
360 "fileFilter" => 'image',
361 "allowAllFiles" => true,
362 "SaveConfig" => true
363 ));
364 }
365
367 {
368 CMedialib::ShowDialogScript(array(
369 "event" => "LHED_Img_MLOpen",
370 "arResultDest" => Array("FUNCTION_NAME" => "LHED_Img_SetUrl")
371 ));
372 CMedialib::ShowDialogScript(array(
373 "event" => "LHED_Video_MLOpen",
374 "arResultDest" => Array("FUNCTION_NAME" => "LHED_Video_SetPath")
375 ));
376 }
377
378 public static function IsMobileDevice()
379 {
380 return preg_match('/ipad|iphone|android|mobile|touch/i',$_SERVER['HTTP_USER_AGENT']);
381 }
382}
383?>
$arParams
Определения access_dialog.php:21
$path
Определения access_edit.php:21
$basePath
Определения include.php:41
global $APPLICATION
Определения include.php:80
static ShowScript($arConfig)
Определения file_dialog.php:9
Определения light_editor.php:4
InitMedialibDialogs()
Определения light_editor.php:366
static IsMobileDevice()
Определения light_editor.php:378
InitFileDialogs()
Определения light_editor.php:304
InitScripts()
Определения light_editor.php:237
Show($arParams)
Определения light_editor.php:200
Init(&$arParams)
Определения light_editor.php:27
GetActualPath($path)
Определения light_editor.php:195
BuildSceleton()
Определения light_editor.php:214
if(!is_array($prop["VALUES"])) $tmp
Определения component_props.php:203
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
bx_acc_lim_group_list limitGroupList[] multiple<?=$group[ 'ID']?> ID selected margin top
Определения file_new.php:657
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
global $USER
Определения csv_new_run.php:40
endif
Определения csv_new_setup.php:990
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
__IncludeLang($path, $bReturnArray=false, $bFileChecked=false)
Определения tools.php:3477
$i
Определения factura.php:643
font style
Определения invoice.php:442
</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."%"
Определения waybill.php:936
$width
Определения html.php:68
const SITE_ID
Определения sonet_set_content_view.php:12