PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/bitrix/components/bitrix/blog.post.edit/templates/micro/lhe.php

https://gitlab.com/Rad1calDreamer/honey
PHP | 418 lines | 369 code | 34 blank | 15 comment | 69 complexity | 6215087bcca71fe0d105511eea0cbe0f MD5 | raw file
  1. <?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?>
  2. <?
  3. if(CModule::IncludeModule("fileman"))
  4. {
  5. ?>
  6. <script>
  7. BX.message({'BLOG_POST_AUTOSAVE':'<?=GetMessage("BLOG_POST_AUTOSAVE")?>'});
  8. var arImages = Array();
  9. var arImagesId = Array();
  10. <?
  11. $i = 0;
  12. foreach($arResult["Images"] as $aImg)
  13. {
  14. ?>
  15. arImages['<?=$i?>'] = '<?=CUtil::JSEscape($aImg["PARAMS"]["SRC"])?>';
  16. arImagesId['<?=$i?>'] = '<?=$aImg["ID"]?>';
  17. <?
  18. $i++;
  19. }
  20. ?>
  21. </script>
  22. <?
  23. function CustomizeLightEditorForBlog()
  24. {
  25. ?>
  26. <script>
  27. LHEButtons['BlogImage'] ={
  28. id : 'Image', // Standart image icon from editor-s CSS
  29. name : BX.message.Image,
  30. handler: function(pBut)
  31. {
  32. pBut.pLEditor.OpenDialog({id : 'BlogImage', obj: false});
  33. },
  34. OnBeforeCreate: function(pLEditor, pBut)
  35. {
  36. // Disable in non BBCode mode in html
  37. pBut.disableOnCodeView = !pLEditor.bBBCode || pLEditor.arConfig.bConvertContentFromBBCodes;
  38. return pBut;
  39. },
  40. parser: {
  41. name: 'blogimage',
  42. obj: {
  43. Parse: function(sName, sContent, pLEditor)
  44. {
  45. var i, cnt = arImages.length, j;
  46. if (!pLEditor.arBlogImages)
  47. pLEditor.arBlogImages = {};
  48. for(i = 0; i < cnt; i++)
  49. {
  50. if (!pLEditor.arBlogImages[arImagesId[i]])
  51. {
  52. pLEditor.arBlogImages[arImagesId[i]] = {
  53. src : arImages[i],
  54. pTitle: ''
  55. };
  56. }
  57. }
  58. sContent = sContent.replace(/\[IMG ID=(\d+)(?:\s*?WIDTH=(\d+)\s*?HEIGHT=(\d+))?\]/ig, function(str, id, width, height)
  59. {
  60. if (!pLEditor.arBlogImages[id])
  61. return str;
  62. width = parseInt(width);
  63. height = parseInt(height);
  64. var
  65. strSize = "",
  66. imageSrc = pLEditor.arBlogImages[id].src,
  67. imageTitle = "";
  68. if (width && height && pLEditor.bBBParseImageSize)
  69. strSize = " width=\"" + width + "\" height=\"" + height + "\"";
  70. return '<img id="' + pLEditor.SetBxTag(false, {tag: "blogimage", params: {value : id}}) + '" src="' + imageSrc + '" title="' + imageTitle + '" ' + strSize +'>';
  71. });
  72. return sContent;
  73. },
  74. UnParse: function(bxTag, pNode, pLEditor)
  75. {
  76. if (bxTag.tag == 'blogimage')
  77. {
  78. var
  79. width = parseInt(pNode.arAttributes['width']),
  80. height = parseInt(pNode.arAttributes['height']),
  81. strSize = "";
  82. if (width && height && pLEditor.bBBParseImageSize)
  83. strSize = ' WIDTH=' + width + ' HEIGHT=' + height;
  84. return '[IMG ID=' + bxTag.params.value + strSize + ']';
  85. }
  86. return "";
  87. }
  88. }
  89. }
  90. };
  91. // Rename image button and change Icon
  92. LHEButtons['Image'].id = 'ImageLink';
  93. LHEButtons['Image'].src = '/bitrix/components/bitrix/blog/templates/.default/images/bbcode/font_image_upload.gif';
  94. LHEButtons['Image'].name = '<?=GetMessage("BLOG_P_IMAGE_LINK")?>';
  95. LHEButtons['BlogInputVideo'] = {
  96. id : 'BlogInputVideo',
  97. src : '/bitrix/components/bitrix/blog/templates/.default/images/bbcode/icon_video.gif',
  98. name : '<?=GetMessage("FPF_VIDEO")?>',
  99. handler: function(pBut)
  100. {
  101. pBut.pLEditor.OpenDialog({id : 'BlogVideo', obj: false});
  102. },
  103. OnBeforeCreate: function(pLEditor, pBut)
  104. {
  105. // Disable in non BBCode mode in html
  106. pBut.disableOnCodeView = !pLEditor.bBBCode || pLEditor.arConfig.bConvertContentFromBBCodes;
  107. return pBut;
  108. },
  109. parser: {
  110. name: 'blogvideo',
  111. obj: {
  112. Parse: function(sName, sContent, pLEditor)
  113. {
  114. sContent = sContent.replace(/\[VIDEO\s*?width=(\d+)\s*?height=(\d+)\s*\]((?:\s|\S)*?)\[\/VIDEO\]/ig, function(str, w, h, src)
  115. {
  116. var
  117. w = parseInt(w) || 400,
  118. h = parseInt(h) || 300,
  119. src = BX.util.trim(src);
  120. return '<img id="' + pLEditor.SetBxTag(false, {tag: "blogvideo", params: {value : src}}) + '" src="/bitrix/images/1.gif" class="bxed-video" width=' + w + ' height=' + h + ' title="' + BX.message.Video + ": " + src + '" />';
  121. });
  122. return sContent;
  123. },
  124. UnParse: function(bxTag, pNode, pLEditor)
  125. {
  126. if (bxTag.tag == 'blogvideo')
  127. {
  128. return "[VIDEO WIDTH=" + pNode.arAttributes["width"] + " HEIGHT=" + pNode.arAttributes["height"] + "]" + bxTag.params.value + "[/VIDEO]";
  129. }
  130. return "";
  131. }
  132. }
  133. }
  134. };
  135. window.LHEDailogs['BlogImage'] = function(pObj)
  136. {
  137. var str =
  138. '<span class="errortext" id="lhed_blog_image_error" style="display:none;"></span>' +
  139. '<table width="100%"><tr>' +
  140. '<td class="lhe-dialog-label lhe-label-imp"><?= GetMessage('BLOG_IMAGE')?>:</td>' +
  141. '<td class="lhe-dialog-param">' +
  142. '<form id="' + pObj.pLEditor.id + 'img_upload_form" action="<?=CUtil::JSEscape(POST_FORM_ACTION_URI)?>" method="post" enctype="multipart/form-data" style="margin: 0!important; padding: 0!important;">' +
  143. '<?=bitrix_sessid_post()?>' +
  144. '<input type="file" size="30" name="BLOG_UPLOAD_FILE" id="bx_lhed_blog_img_input" />' +
  145. '<input type="hidden" value="Y" name="blog_upload_image"/>' +
  146. '<input type="hidden" value="Y" name="do_upload"/>' +
  147. '</form>'+
  148. '</td>' +
  149. '</tr><tr id="' + pObj.pLEditor.id + 'lhed_blog_notice">' +
  150. '<td colSpan="2" style="padding: 0 0 20px 25px !important; font-size: 11px!important;"><?= GetMessage('BPC_IMAGE_SIZE_NOTICE', Array('#SIZE#' => DoubleVal(COption::GetOptionString("blog", "image_max_size", 1000000)/1000000)))?></td>' +
  151. '</tr></table>';
  152. return {
  153. title: "<?= GetMessage('BLOG_P_IMAGE_UPLOAD')?>",
  154. innerHTML : str,
  155. width: 500,
  156. OnLoad: function()
  157. {
  158. pObj.pForm = false;
  159. pObj.pInput = false;
  160. pObj.pInput = BX('bx_lhed_blog_img_input');
  161. pObj.pForm = BX(pObj.pLEditor.id + 'img_upload_form');
  162. pObj.pLEditor.focus(pObj.pInput);
  163. window.obLHEDialog.adjustSizeEx();
  164. },
  165. OnSave: function()
  166. {
  167. if (pObj.pInput && pObj.pForm && pObj.pInput.value != "")
  168. {
  169. BX.showWait('bx_lhed_blog_img_input');
  170. BX('lhed_blog_image_error').style.display = 'none';
  171. BX('lhed_blog_image_error').innerHTML = '';
  172. BX.ajax.submit(pObj.pForm, function(){
  173. BX.closeWait();
  174. if (window.bxBlogImageId)
  175. {
  176. window.InsertBlogImage(window.bxBlogImageId, window.bxBlogImageIdWidth);
  177. window.obLHEDialog.Close();
  178. window.bxBlogImageId = false;
  179. }
  180. else if(window.bxBlogImageError)
  181. {
  182. BX('lhed_blog_image_error').innerHTML = window.bxBlogImageError;
  183. BX('lhed_blog_image_error').style.display = 'block';
  184. window.obLHEDialog.adjustSizeEx();
  185. }
  186. });
  187. return false;
  188. }
  189. }
  190. };
  191. };
  192. window.InsertBlogImage = function(imageId, width)
  193. {
  194. pLEditor = window.oBlogLHE;
  195. var strSize = '';
  196. if (!pLEditor.arBlogImages[imageId])
  197. {
  198. if(width > 0)
  199. {
  200. if(pLEditor.arConfig.width && pLEditor.arConfig.width.indexOf('%') <= 0)
  201. widthC = parseInt(pLEditor.arConfig.width)*0.8;
  202. else
  203. widthC = 400;
  204. if(width > widthC)
  205. strSize = ' width="80%"';
  206. }
  207. var imgId = window.arImagesId[imageId-1];
  208. var src = window.arImages[imageId-1];
  209. imageId = imgId;
  210. pLEditor.arBlogImages[imageId] = {
  211. src : src,
  212. pTitle: ''
  213. };
  214. }
  215. if (pLEditor.sEditorMode == 'code' && pLEditor.bBBCode) // BB Codes
  216. pLEditor.WrapWith("", "", "[IMG ID=" + imageId + "]");
  217. else if(pLEditor.sEditorMode == 'html') // WYSIWYG
  218. {
  219. pLEditor.InsertHTML('<img id="' + pLEditor.SetBxTag(false, {tag: "blogImage", params: {value : imageId}}) + '" src="' + pLEditor.arBlogImages[imageId].src + '" title="' + (pLEditor.arBlogImages[imageId].pTitle.value || "") + '"' + strSize + '>');
  220. setTimeout('pLEditor.AutoResize();', 500);
  221. }
  222. }
  223. //
  224. window.LHEDailogs['BlogVideo'] = function(pObj)
  225. {
  226. var str = '<table width="100%"><tr>' +
  227. '<td class="lhe-dialog-label lhe-label-imp"><label for="' + pObj.pLEditor.id + 'lhed_blog_video_path"><b><?= GetMessage('BPC_VIDEO_P')?>:</b></label></td>' +
  228. '<td class="lhe-dialog-param">' +
  229. '<input id="' + pObj.pLEditor.id + 'lhed_blog_video_path" value="" size="30"/>' +
  230. '</td>' +
  231. '</tr><tr>' +
  232. '<td></td>' +
  233. '<td style="padding: 0!important; font-size: 11px!important;"><?= GetMessage('BPC_VIDEO_PATH_EXAMPLE')?></td>' +
  234. '</tr><tr>' +
  235. '<td class="lhe-dialog-label lhe-label-imp"><label for="' + pObj.pLEditor.id + 'lhed_blog_video_width">' + BX.message.ImageSizing + ':</label></td>' +
  236. '<td class="lhe-dialog-param">' +
  237. '<input id="' + pObj.pLEditor.id + 'lhed_blog_video_width" value="" size="4"/>' +
  238. ' x ' +
  239. '<input id="' + pObj.pLEditor.id + 'lhed_blog_video_height" value="" size="4" />' +
  240. '</td>' +
  241. '</tr></table>';
  242. return {
  243. title: "<?= GetMessage('FPF_VIDEO')?>",
  244. innerHTML : str,
  245. width: 480,
  246. OnLoad: function()
  247. {
  248. pObj.pPath = BX(pObj.pLEditor.id + "lhed_blog_video_path");
  249. pObj.pWidth = BX(pObj.pLEditor.id + "lhed_blog_video_width");
  250. pObj.pHeight = BX(pObj.pLEditor.id + "lhed_blog_video_height");
  251. pObj.pLEditor.focus(pObj.pPath);
  252. },
  253. OnSave: function()
  254. {
  255. pLEditor = window.oBlogLHE;
  256. var
  257. src = BX.util.trim(pObj.pPath.value),
  258. w = parseInt(pObj.pWidth.value) || 400,
  259. h = parseInt(pObj.pHeight.value) || 300;
  260. if (src == "")
  261. return;
  262. if (pLEditor.sEditorMode == 'code' && pLEditor.bBBCode) // BB Codes
  263. {
  264. pLEditor.WrapWith("", "", "[VIDEO WIDTH=" + w + " HEIGHT=" + h + "]" + src + "[/VIDEO]");
  265. }
  266. else if(pLEditor.sEditorMode == 'html') // WYSIWYG
  267. {
  268. pLEditor.InsertHTML('<img id="' + pLEditor.SetBxTag(false, {tag: "blogvideo", params: {value : src}}) + '" src="/bitrix/images/1.gif" class="bxed-video" width=' + w + ' height=' + h + ' title="' + BX.message.Video + ": " + src + '" />');
  269. setTimeout('pLEditor.AutoResize();', 500);
  270. }
  271. }
  272. };
  273. };
  274. // Submit form by ctrl+enter
  275. window.blogCtrlEnterHandler = function(e)
  276. {
  277. oBlogLHE.SaveContent();
  278. if (document.forms.REPLIER)
  279. document.forms.REPLIER.submit();
  280. };
  281. document.forms.REPLIER.onsubmit = function()
  282. {
  283. oBlogLHE.SaveContent();
  284. BX('add-microblog').disabled = true;
  285. };
  286. </script>
  287. <?
  288. }
  289. AddEventHandler("fileman", "OnIncludeLightEditorScript", "CustomizeLightEditorForBlog");
  290. $arSmiles = array();
  291. if(!empty($arResult["Smiles"]))
  292. {
  293. foreach($arResult["Smiles"] as $arSmile)
  294. {
  295. $arSmiles[] = array(
  296. 'name' => $arSmile["~LANG_NAME"],
  297. 'path' => "/bitrix/images/blog/smile/".$arSmile["IMAGE"],
  298. 'code' => str_replace("\\\\","\\",$arSmile["TYPE"])
  299. );
  300. }
  301. }
  302. ?>
  303. <div id="edit-post-text">
  304. <?
  305. $bbCode = true;
  306. if($arResult["allow_html"] == "Y" && (($arResult["PostToShow"]["DETAIL_TEXT_TYPE"] == "html" && $_REQUEST["load_editor"] != "N") || $_REQUEST["load_editor"] == "Y"))
  307. $bbCode = false;
  308. // Detect necessity of first convertion content from BB-code to HTML in editor.
  309. $bConvertContentFromBBCodes = !$bbCode && $_REQUEST["load_editor"] == "Y" &&
  310. !isset($_REQUEST['preview']) && !isset($_REQUEST['save']) && !isset($_REQUEST['apply']) && !isset($_REQUEST['draft']);
  311. $LHE = new CLightHTMLEditor;
  312. $LHE->Show(array(
  313. 'id' => 'LHEBlogId',
  314. 'width' => '100%',
  315. //'height' => $arParams['EDITOR_DEFAULT_HEIGHT'],
  316. 'height' => '120px',
  317. 'inputId' => 'POST_MESSAGE_HTML',
  318. 'inputName' => 'POST_MESSAGE',
  319. 'content' => $arResult["PostToShow"]["~DETAIL_TEXT"],
  320. 'bUseFileDialogs' => false,
  321. 'bUseMedialib' => false,
  322. 'toolbarConfig' => array(
  323. 'BlogImage',
  324. 'CreateLink',
  325. (($arResult["allowVideo"] == "Y") ? 'BlogInputVideo' : ''),
  326. //'SmileList',
  327. ),
  328. 'jsObjName' => 'oBlogLHE',
  329. 'arSmiles' => $arSmiles,
  330. 'smileCountInToolbar' => 1,
  331. 'bSaveOnBlur' => false,
  332. 'BBCode' => $bbCode,
  333. 'bConvertContentFromBBCodes' => $bConvertContentFromBBCodes,
  334. 'bQuoteFromSelection' => true, // Make quote from any text in the page
  335. 'bResizable' => true,
  336. 'bAutoResize' => true,
  337. 'autoResizeOffset' => 40,
  338. 'autoResizeMaxHeight' => 300,
  339. 'controlButtonsHeight' => 0,
  340. 'autoResizeSaveSize' => false,
  341. 'ctrlEnterHandler' => 'blogCtrlEnterHandler', // Ctrl+Enter handler name in global namespace
  342. 'bSetDefaultCodeView' => false, // Set first view to CODE or to WYSIWYG
  343. 'bBBParseImageSize' => true // [IMG ID=XXX WEIGHT=5 HEIGHT=6], [IMGWEIGHT=5 HEIGHT=6]/image.gif[/IMG]
  344. ));
  345. ?></div><?
  346. }
  347. ?>
  348. <script>
  349. var bShow = false;
  350. function blogCheckLength()
  351. {
  352. if(window.oBlogLHE)
  353. {
  354. if(!bShow)
  355. {
  356. var el = BX.findChild(BX("bxlhe_frame_LHEBlogId"), {className: "lhe-stat-toolbar-cont"}, true);
  357. elTr = BX.findParent(BX.findParent(el));
  358. elTr.style.display = "none";
  359. BX("blog-post-micro-lhe-but").appendChild(el);
  360. if(BX("slog-mb-hide"))
  361. BX("blog-post-micro-lhe-hide").innerHTML = BX("slog-mb-hide").innerHTML;
  362. <?
  363. /*
  364. if(COption::GetOptionString("blog", "use_autosave", "Y") == "Y")
  365. {
  366. ?>BlogPostAutoSaveIcon();<?
  367. }
  368. */
  369. ?>
  370. document.getElementById("blog-post-edit-micro-form").style.display = "block";
  371. bShow = true;
  372. }
  373. window.oBlogLHE.SetContent('<?=CUtil::JSEscape($arResult["PostToShow"]["~DETAIL_TEXT"])?>');
  374. window.oBlogLHE.CreateFrame(); // We need to recreate editable frame after reappending editor container
  375. window.oBlogLHE.SetEditorContent(window.oBlogLHE.content);
  376. window.oBlogLHE.SetFocus();
  377. //window.oBlogLHE.AutoResize();
  378. }
  379. else
  380. setTimeout("blogCheckLength()", 1000);
  381. }
  382. setTimeout("blogCheckLength()", 1000);
  383. BX.addCustomEvent('onSocNetLogMoveBody', function() {blogCheckLength();});
  384. </script>