PageRenderTime 49ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/blog/general/functions.php

https://gitlab.com/alexprowars/bitrix
PHP | 735 lines | 653 code | 72 blank | 10 comment | 108 complexity | 29256aa4debe1b0bd0525167a02151bf MD5 | raw file
  1. <?php
  2. IncludeModuleLangFile(__FILE__);
  3. class blogTextParser extends CTextParser
  4. {
  5. public $bPublic = false;
  6. public $pathToUserEntityId = false;
  7. public $pathToUserEntityType = false;
  8. public $smilesGallery = 0;
  9. public $maxStringLen = 100;
  10. private $arImages = array();
  11. public $showedImages = array();
  12. // max sizes for show image in popup
  13. const IMAGE_MAX_SHOWING_WIDTH = 1000;
  14. const IMAGE_MAX_SHOWING_HEIGHT = 1000;
  15. public function __construct($strLang = False, $pathToSmile = false, $arParams = array())
  16. {
  17. parent::__construct();
  18. global $CACHE_MANAGER;
  19. if ($strLang===False)
  20. $strLang = LANGUAGE_ID;
  21. $this->imageWidth = \Bitrix\Blog\Util::getImageMaxWidth();
  22. $this->imageHeight = \Bitrix\Blog\Util::getImageMaxHeight();
  23. $this->showedImages = array();
  24. $this->ajaxPage = $GLOBALS["APPLICATION"]->GetCurPageParam("", array("bxajaxid", "logout"));
  25. $this->blogImageSizeEvents = GetModuleEvents("blog", "BlogImageSize", true);
  26. $this->arUserfields = array();
  27. $this->bPublic = (is_array($arParams) && $arParams["bPublic"]);
  28. $this->smilesGallery = \COption::GetOptionInt("blog", "smile_gallery_id", 0);
  29. }
  30. public function convert($text, $bPreview = True, $arImages = array(), $allow = array("HTML" => "N", "ANCHOR" => "Y", "BIU" => "Y", "IMG" => "Y", "QUOTE" => "Y", "CODE" => "Y", "FONT" => "Y", "LIST" => "Y", "SMILES" => "Y", "NL2BR" => "N", "VIDEO" => "Y", "TABLE" => "Y", "CUT_ANCHOR" => "N", "SHORT_ANCHOR" => "N"), $arParams = Array())
  31. {
  32. if(!is_array($arParams) && $arParams <> '')
  33. $type = $arParams;
  34. elseif(is_array($arParams))
  35. $type = $arParams["type"];
  36. if(intval($arParams["imageWidth"]) > 0)
  37. $this->imageWidth = intval($arParams["imageWidth"]);
  38. if(intval($arParams["imageHeight"]) > 0)
  39. $this->imageHeight = intval($arParams["imageHeight"]);
  40. if($arParams["pathToUser"] <> '')
  41. $this->pathToUser = $arParams["pathToUser"];
  42. if(!empty($arParams["pathToUserEntityType"]) && $arParams["pathToUserEntityType"] <> '')
  43. $this->pathToUserEntityType = $arParams["pathToUserEntityType"];
  44. if(intval($arParams["pathToUserEntityId"]) > 0)
  45. $this->pathToUserEntityId = intval($arParams["pathToUserEntityId"]);
  46. $this->parser_nofollow = COption::GetOptionString("blog", "parser_nofollow", "N");
  47. $this->type = ($type == "rss" ? "rss" : "html");
  48. $this->isSonetLog = $arParams["isSonetLog"];
  49. $this->allow = array(
  50. "HTML" => ($allow["HTML"] == "Y" ? "Y" : "N"),
  51. "NL2BR" => ($allow["NL2BR"] == "Y" ? "Y" : "N"),
  52. "CODE" => ($allow["CODE"] == "N" ? "N" : "Y"),
  53. "VIDEO" => ($allow["VIDEO"] == "N" ? "N" : "Y"),
  54. "ANCHOR" => ($allow["ANCHOR"] == "N" ? "N" : "Y"),
  55. "BIU" => ($allow["BIU"] == "N" ? "N" : "Y"),
  56. "IMG" => ($allow["IMG"] == "N" ? "N" : "Y"),
  57. "QUOTE" => ($allow["QUOTE"] == "N" ? "N" : "Y"),
  58. "FONT" => ($allow["FONT"] == "N" ? "N" : "Y"),
  59. "LIST" => ($allow["LIST"] == "N" ? "N" : "Y"),
  60. "SMILES" => ($allow["SMILES"] == "N" ? "N" : "Y"),
  61. "TABLE" => ($allow["TABLE"] == "N" ? "N" : "Y"),
  62. "ALIGN" => ($allow["ALIGN"] == "N" ? "N" : "Y"),
  63. "CUT_ANCHOR" => ($allow["CUT_ANCHOR"] == "Y" ? "Y" : "N"),
  64. "SHORT_ANCHOR" => ($allow["SHORT_ANCHOR"] == "Y" ? "Y" : "N"),
  65. "USER" => ($allow["USER"] == "N" ? "N" : "Y"),
  66. "USER_LINK" => ($allow["USER_LINK"] == "N" ? "N" : "Y"),
  67. "TAG" => ($allow["TAG"] == "N" ? "N" : "Y"),
  68. 'SPOILER' => ($allow['SPOILER'] === 'N' ? 'N' : 'Y'),
  69. "USERFIELDS" => (is_array($allow["USERFIELDS"]) ? $allow["USERFIELDS"] : array())
  70. );
  71. if (!empty($this->arUserfields))
  72. $this->allow["USERFIELDS"] = array_merge($this->allow["USERFIELDS"], $this->arUserfields);
  73. $this->arImages = $arImages;
  74. $this->bPreview = $bPreview;
  75. static $firstCall = true;
  76. if ($firstCall)
  77. {
  78. $firstCall = false;
  79. AddEventHandler("main", "TextParserBefore", Array("blogTextParser", "ParserCut"));
  80. AddEventHandler("main", "TextParserBefore", Array("blogTextParser", "ParserBlogImageBefore"));
  81. AddEventHandler("main", "TextParserAfterTags", Array("blogTextParser", "ParserBlogImage"));
  82. AddEventHandler("main", "TextParserAfterTags", Array("blogTextParser", "ParserTag"));
  83. AddEventHandler("main", "TextParserAfter", Array("blogTextParser", "ParserCutAfter"));
  84. AddEventHandler("main", "TextParserVideoConvert", Array("blogTextParser", "blogConvertVideo"));
  85. }
  86. $text = $this->convertText($text);
  87. return trim($text);
  88. }
  89. public static function ParserCut(&$text, &$obj)
  90. {
  91. if ($obj->bPreview)
  92. {
  93. $text = preg_replace("#^(.*?)<cut[\s]*(/>|>).*?$#is", "\\1", $text);
  94. $text = preg_replace("#^(.*?)\[cut[\s]*(/\]|\]).*?$#is", "\\1", $text);
  95. }
  96. else
  97. {
  98. $text = preg_replace("#<cut[\s]*(/>|>)#is", "[cut]", $text);
  99. }
  100. }
  101. public static function ParserCutAfter(&$text, &$obj)
  102. {
  103. if (!$obj->bPreview)
  104. {
  105. $text = preg_replace("#\[cut[\s]*(/\]|\])#is", "<a name=\"cut\"></a>", $text);
  106. }
  107. }
  108. public static function ParserBlogImageBefore(&$text, &$obj = null)
  109. {
  110. $text = preg_replace("/\[img([^\]]*)id\s*=\s*([0-9]+)([^\]]*)\]/is".BX_UTF_PCRE_MODIFIER, "[imag id=\\1 \\2 \\3]", $text);
  111. }
  112. public static function ParserBlogImage(&$text, &$obj)
  113. {
  114. if(is_callable(array($obj, 'convert_blog_image')))
  115. {
  116. $text = preg_replace_callback(
  117. "/\[imag([^\]]*)id\s*=\s*([0-9]+)([^\]]*)\]/is".BX_UTF_PCRE_MODIFIER,
  118. array($obj, "convertBlogImage"),
  119. $text
  120. );
  121. }
  122. }
  123. private function convertBlogImage($matches)
  124. {
  125. return $this->convert_blog_image($matches[1], $matches[2], $matches[3]);
  126. }
  127. private function convertBlogImageMail($matches)
  128. {
  129. return $this->convert_blog_image('', $matches[2], '', 'mail');
  130. }
  131. public static function ParserTag(&$text, &$obj)
  132. {
  133. if($obj->allow["TAG"] != "N" && is_callable(array($obj, 'convert_blog_tag')))
  134. {
  135. $text = preg_replace_callback(
  136. "/\[tag(?:[^\]])*\](.+?)\[\/tag\]/is".BX_UTF_PCRE_MODIFIER,
  137. array($obj, "convertBlogTag"),
  138. $text
  139. );
  140. }
  141. }
  142. private function convertBlogTag($matches)
  143. {
  144. return $this->convert_blog_tag($matches[1]);
  145. }
  146. private function convert_blog_tag($name = "")
  147. {
  148. if($name == '')
  149. return;
  150. return "TAG [".$name."]";
  151. }
  152. function convert4im($text, $arImages = [])
  153. {
  154. $text = preg_replace(
  155. [
  156. "/\[(\/?)(code|quote)([^\]]*)\]/is" . BX_UTF_PCRE_MODIFIER,
  157. "/\\[url\\s*=\\s*(\\S+?)\\s*\\](.*?)\\[\\/url\\]/is" . BX_UTF_PCRE_MODIFIER,
  158. "/\\[(table)(.*?)\\]/is" . BX_UTF_PCRE_MODIFIER,
  159. "/\\[\\/table(.*?)\\]/is" . BX_UTF_PCRE_MODIFIER
  160. ],
  161. [
  162. '',
  163. "\\2",
  164. "\n",
  165. "\n",
  166. ],
  167. $text
  168. );
  169. return $this->convert4mail($text, $arImages);
  170. }
  171. public function convert4mail($text, $arImages = Array())
  172. {
  173. $text = parent::convert4mail($text);
  174. $this->arImages = $arImages;
  175. $text = preg_replace_callback(
  176. "/\[img([^\]]*)id\s*=\s*([0-9]+)([^\]]*)\]/is".BX_UTF_PCRE_MODIFIER,
  177. array($this, "convertBlogImageMail"),
  178. $text
  179. );
  180. return $text;
  181. }
  182. private function convert_blog_image($p1 = "", $imageId = "", $p2 = "", $type = "html")
  183. {
  184. $imageId = intval($imageId);
  185. if($imageId <= 0)
  186. return;
  187. $res = "";
  188. if(intval($this->arImages[$imageId]) > 0)
  189. {
  190. $this->showedImages[] = $imageId;
  191. if($f = CBlogImage::GetByID($imageId))
  192. {
  193. if(COption::GetOptionString("blog", "use_image_perm", "N") == "N")
  194. {
  195. if($db_img_arr = CFile::GetFileArray($this->arImages[$imageId]))
  196. {
  197. if(mb_substr($db_img_arr["SRC"], 0, 1) == "/")
  198. $strImage = $this->serverName.$db_img_arr["SRC"];
  199. else
  200. $strImage = $db_img_arr["SRC"];
  201. $strPar = "";
  202. preg_match("/width\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p1, $width);
  203. preg_match("/height\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p1, $height);
  204. $width = intval($width[1]);
  205. $height = intval($height[1]);
  206. if($width <= 0)
  207. {
  208. preg_match("/width\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p2, $width);
  209. $width = intval($width[1]);
  210. }
  211. if($height <= 0)
  212. {
  213. preg_match("/height\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p2, $height);
  214. $height = intval($height[1]);
  215. }
  216. if(intval($width) <= 0)
  217. $width = $db_img_arr["WIDTH"];
  218. if(intval($height) <= 0)
  219. $height= $db_img_arr["HEIGHT"];
  220. if($width > $this->imageWidth || $height > $this->imageHeight)
  221. {
  222. $arFileTmp = CFile::ResizeImageGet(
  223. $db_img_arr,
  224. array("width" => $this->imageWidth, "height" => $this->imageHeight),
  225. BX_RESIZE_IMAGE_PROPORTIONAL,
  226. true
  227. );
  228. if(mb_substr($arFileTmp["src"], 0, 1) == "/")
  229. $strImage = $this->serverName.$arFileTmp["src"];
  230. else
  231. $strImage = $arFileTmp["src"];
  232. $width = $arFileTmp["width"];
  233. $height = $arFileTmp["height"];
  234. }
  235. $sourceImage = $this->serverName."/bitrix/components/bitrix/blog/show_file.php?fid=".$imageId;
  236. // if original size bigger than limits - need resize
  237. if($db_img_arr["WIDTH"] > blogTextParser::IMAGE_MAX_SHOWING_WIDTH)
  238. $sourceImage .= "&width=".blogTextParser::IMAGE_MAX_SHOWING_WIDTH;
  239. if($db_img_arr["HEIGHT"] > blogTextParser::IMAGE_MAX_SHOWING_HEIGHT)
  240. $sourceImage .= "&height=".blogTextParser::IMAGE_MAX_SHOWING_HEIGHT;
  241. $strPar = 'style=" width:'.$width.'px; height:'.$height.'px;"';
  242. $strImage = preg_replace("'(?<!:)/+'s", "/", $strImage);
  243. $sourceImage = preg_replace("'(?<!:)/+'s", "/", $sourceImage);
  244. if($this->authorName <> '')
  245. $strPar .= " data-bx-title=\"".$this->authorName."\"";
  246. if ($this->isSonetLog)
  247. {
  248. $strImage = preg_replace("'(?<!:)/+'s", "/", $strImage);
  249. $res = '[IMG]'.$strImage.'[/IMG]';
  250. }
  251. else
  252. {
  253. if($type == "mail")
  254. $res = htmlspecialcharsbx($f["TITLE"])." (IMAGE: ".$strImage." )";
  255. else
  256. $res = '<img src="'.$strImage.'" title="" alt="'.htmlspecialcharsbx($f["TITLE"]).'" border="0"'.$strPar.' data-bx-image="'.$sourceImage.'" />';
  257. }
  258. }
  259. }
  260. else
  261. {
  262. preg_match("/width\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p1, $width);
  263. preg_match("/height\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p1, $height);
  264. $width = intval($width[1]);
  265. $height = intval($height[1]);
  266. if($width <= 0)
  267. {
  268. preg_match("/width\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p2, $width);
  269. $width = intval($width[1]);
  270. }
  271. if($height <= 0)
  272. {
  273. preg_match("/height\=([0-9]+)/is".BX_UTF_PCRE_MODIFIER, $p2, $height);
  274. $height = intval($height[1]);
  275. }
  276. if(intval($width) <= 0)
  277. $width = $this->imageWidth;
  278. if(intval($height) <= 0)
  279. $height = $this->imageHeight;
  280. if($width > $this->imageWidth)
  281. $width = $this->imageWidth;
  282. if($height > $this->imageHeight)
  283. $height = $this->imageHeight;
  284. $db_img_arr = CFile::GetFileArray($this->arImages[$imageId]);
  285. $strImage = $this->serverName."/bitrix/components/bitrix/blog/show_file.php?fid=".$imageId."&width=".$width."&height=".$height;
  286. $sourceImage = $this->serverName."/bitrix/components/bitrix/blog/show_file.php?fid=".$imageId;
  287. // if original size bigger than limits - need resize
  288. if($db_img_arr["WIDTH"] > blogTextParser::IMAGE_MAX_SHOWING_WIDTH)
  289. $sourceImage .= "&width=".blogTextParser::IMAGE_MAX_SHOWING_WIDTH;
  290. if($db_img_arr["HEIGHT"] > blogTextParser::IMAGE_MAX_SHOWING_HEIGHT)
  291. $sourceImage .= "&height=".blogTextParser::IMAGE_MAX_SHOWING_HEIGHT;
  292. CFile::ScaleImage($db_img_arr["WIDTH"], $db_img_arr["HEIGHT"], Array("width" => $width, "height" => $height), BX_RESIZE_IMAGE_PROPORTIONAL, $bNeedCreatePicture, $arSourceSize, $arDestinationSize);
  293. if ($this->isSonetLog)
  294. {
  295. $strImage = preg_replace("'(?<!:)/+'s", "/", $strImage);
  296. $res = '[IMG]'.$strImage.'[/IMG]';
  297. }
  298. else
  299. {
  300. if($type == "mail")
  301. $res = htmlspecialcharsbx($f["TITLE"])." (IMAGE: ".$strImage." )";
  302. else
  303. {
  304. $strPar = ' width="'.$arDestinationSize["width"].'" height="'.$arDestinationSize["height"].'"';
  305. if($this->authorName <> '')
  306. $strPar .= " data-bx-title=\"".$this->authorName."\"";
  307. $res = '<img src="'.$strImage.'" title="" alt="'.htmlspecialcharsbx($f["TITLE"]).'" border="0" data-bx-image="'.$sourceImage.'"'.$strPar.' />';
  308. if(!empty($this->blogImageSizeEvents))
  309. {
  310. foreach($this->blogImageSizeEvents as $arEvent)
  311. ExecuteModuleEventEx($arEvent, Array(&$res, $strImage, $db_img_arr, $f, $arDestinationSize));
  312. }
  313. }
  314. }
  315. }
  316. return $res;
  317. }
  318. }
  319. return $res;
  320. }
  321. public function convert_to_rss($text, $arImages = Array(), $arAllow = array("HTML" => "N", "ANCHOR" => "Y", "BIU" => "Y", "IMG" => "Y", "QUOTE" => "Y", "CODE" => "Y", "FONT" => "Y", "LIST" => "Y", "SMILES" => "Y", "NL2BR" => "N", "VIDEO" => "Y", "TABLE" => "Y", "CUT_ANCHOR" => "N"), $bPreview = true, $arParams = Array())
  322. {
  323. $arParams["type"] = "rss";
  324. $text = $this->convert($text, $bPreview, $arImages, $arAllow, $arParams);
  325. return trim($text);
  326. }
  327. function convert_open_tag($marker = "quote")
  328. {
  329. $marker = (mb_strtolower($marker) == "code" ? "code" : "quote");
  330. $this->{$marker."_open"}++;
  331. if ($this->type == "rss")
  332. return "\n====".$marker."====\n";
  333. return "<div class='blog-post-".$marker."' title=\"".GetMessage("BLOG_".ToUpper($marker))."\"><table class='blog".$marker."'><tr><td>";
  334. }
  335. public static function blogConvertVideo(&$arParams)
  336. {
  337. $video = "";
  338. $bEvents = false;
  339. foreach(GetModuleEvents("blog", "videoConvert", true) as $arEvent)
  340. {
  341. $video = ExecuteModuleEventEx($arEvent, Array(&$arParams));
  342. $bEvents = true;
  343. }
  344. if(!$bEvents)
  345. {
  346. ob_start();
  347. $GLOBALS["APPLICATION"]->IncludeComponent(
  348. "bitrix:player", "",
  349. Array(
  350. "PLAYER_TYPE" => "auto",
  351. "USE_PLAYLIST" => "N",
  352. "PATH" => $arParams["PATH"],
  353. "WIDTH" => $arParams["WIDTH"],
  354. "HEIGHT" => $arParams["HEIGHT"],
  355. "PREVIEW" => $arParams["PREVIEW"],
  356. "LOGO" => "",
  357. "FULLSCREEN" => "Y",
  358. "SKIN_PATH" => "/bitrix/components/bitrix/player/mediaplayer/skins",
  359. "SKIN" => "bitrix.swf",
  360. "CONTROLBAR" => "bottom",
  361. "WMODE" => "transparent",
  362. "HIDE_MENU" => "N",
  363. "SHOW_CONTROLS" => "Y",
  364. "SHOW_STOP" => "N",
  365. "SHOW_DIGITS" => "Y",
  366. "CONTROLS_BGCOLOR" => "FFFFFF",
  367. "CONTROLS_COLOR" => "000000",
  368. "CONTROLS_OVER_COLOR" => "000000",
  369. "SCREEN_COLOR" => "000000",
  370. "AUTOSTART" => "N",
  371. "REPEAT" => "N",
  372. "VOLUME" => "90",
  373. "DISPLAY_CLICK" => "play",
  374. "MUTE" => "N",
  375. "HIGH_QUALITY" => "Y",
  376. "ADVANCED_MODE_SETTINGS" => "N",
  377. "BUFFER_LENGTH" => "10",
  378. "DOWNLOAD_LINK" => "",
  379. "DOWNLOAD_LINK_TARGET" => "_self"),
  380. null,
  381. array(
  382. "HIDE_ICONS" => "Y"
  383. )
  384. );
  385. $video = ob_get_contents();
  386. ob_end_clean();
  387. }
  388. return $video;
  389. }
  390. public static function killAllTags($text)
  391. {
  392. if (method_exists("CTextParser", "clearAllTags"))
  393. return CTextParser::clearAllTags($text);
  394. $text = strip_tags($text);
  395. $text = preg_replace(
  396. array(
  397. "/\<(\/)(quote|code)([^\>]*)\>/is".BX_UTF_PCRE_MODIFIER,
  398. "/\[(\/)(code|quote|video|td|tr|th|table|tbody|thead|file|document|disk)([^\]]*)\]/is".BX_UTF_PCRE_MODIFIER,
  399. "/\[(\/?)(\*)([^\]]*)\]/is".BX_UTF_PCRE_MODIFIER,
  400. ),
  401. " ",
  402. $text);
  403. $text = preg_replace(
  404. array(
  405. "/\<(\/?)(quote|code|font|color|video)([^\>]*)\>/is".BX_UTF_PCRE_MODIFIER,
  406. "/\[(\/?)(b|u|i|s|list|code|quote|font|color|url|img|video|td|tr|th|tbody|thead|table|file|document|disk|user|left|right|center|justify)([^\]]*)\]/is".BX_UTF_PCRE_MODIFIER
  407. ),
  408. "",
  409. $text);
  410. return $text;
  411. }
  412. function render_user($fields)
  413. {
  414. $classAdditional = (!empty($fields['CLASS_ADDITIONAL']) ? $fields['CLASS_ADDITIONAL'] : '');
  415. $pathToUser = (!empty($fields['PATH_TO_USER']) ? $fields['PATH_TO_USER'] : '');
  416. $userId = (!empty($fields['USER_ID']) ? $fields['USER_ID'] : '');
  417. $userName = (!empty($fields['USER_NAME']) ? $fields['USER_NAME'] : '');
  418. $anchorId = RandString(8);
  419. return (
  420. $this->allow["USER_LINK"] == "N"
  421. ? $userName
  422. : '<a class="blog-p-user-name' . $classAdditional . '" id="bp_'.$anchorId.'" href="'.CComponentEngine::MakePathFromTemplate($pathToUser, array("user_id" => $userId)).'" bx-tooltip-user-id="'.(!$this->bMobile ? $userId : '').'">'.$userName.'</a>'
  423. );
  424. }
  425. private static function getEditorDefaultFeatures()
  426. {
  427. return array("Bold","Italic","Underline","SmileList","RemoveFormat","Quote","Code"/*,"Source"*/);
  428. }
  429. private static function getEditorExtendFeatures()
  430. {
  431. return array(
  432. "EDITOR_USE_FONT" => array("FontList", "FontSizeList","ForeColor"),
  433. "EDITOR_USE_LINK" => array("CreateLink"),
  434. "EDITOR_USE_IMAGE" => array("UploadImage","Image"),
  435. "EDITOR_USE_FORMAT" => array("Strike","Table","Justify","InsertOrderedList","InsertUnorderedList"),
  436. "EDITOR_USE_VIDEO" => array("InputVideo")
  437. );
  438. }
  439. public static function GetEditorToolbar($params, $arResult = null)
  440. {
  441. if(isset($params["blog"]))
  442. {
  443. $blog = $params["blog"];
  444. }
  445. else
  446. {
  447. $blog = array();
  448. $params = array("EDITOR_FULL" => "Y");
  449. }
  450. $editorFull = isset($params["EDITOR_FULL"]) && $params["EDITOR_FULL"] == "Y";
  451. $defaultFeatures = self::getEditorDefaultFeatures();
  452. $extendFeatures = self::getEditorExtendFeatures();
  453. // if set FULL flag - use ALL features. If other - use features by blog settings
  454. $result = $defaultFeatures;
  455. if($editorFull)
  456. {
  457. foreach($extendFeatures as $key => $feature)
  458. $result = array_merge($result, $feature);
  459. }
  460. else
  461. {
  462. foreach($extendFeatures as $key => $feature)
  463. {
  464. // use feature name as key to can remove then later
  465. if(isset($blog[$key]) && $blog[$key] == "Y")
  466. foreach($feature as $f)
  467. $result[$f] = $f;
  468. }
  469. }
  470. // UNSET not allowed by component settings features
  471. if(is_array($arResult) && !$arResult["allowVideo"])
  472. foreach($extendFeatures["EDITOR_USE_VIDEO"] as $f)
  473. unset($result[$f]);
  474. if(is_array($arResult) && $arResult["NoCommentUrl"])
  475. foreach($extendFeatures["EDITOR_USE_LINK"] as $f)
  476. unset($result[$f]);
  477. if (LANGUAGE_ID == 'ru')
  478. $result[] = 'Translit';
  479. return $result;
  480. }
  481. public static function getEditorButtons($blog, $arResult)
  482. {
  483. $result = array();
  484. // IMAGES or FILES
  485. if(
  486. is_array($arResult["COMMENT_PROPERTIES"]["DATA"])
  487. && (
  488. array_key_exists("UF_BLOG_COMMENT_FILE", $arResult["COMMENT_PROPERTIES"]["DATA"])
  489. || array_key_exists("UF_BLOG_COMMENT_DOC", $arResult["COMMENT_PROPERTIES"]["DATA"])
  490. )
  491. && array_key_exists('EDITOR_USE_IMAGE', $blog) && $blog["EDITOR_USE_IMAGE"] === "Y"
  492. )
  493. {
  494. $result[] = "UploadFile";
  495. }
  496. // VIDEO
  497. if($arResult["allowVideo"] && (isset($blog["EDITOR_USE_VIDEO"]) && $blog["EDITOR_USE_VIDEO"] === "Y"))
  498. {
  499. $result[] = "InputVideo";
  500. }
  501. // LINK
  502. if(!$arResult["NoCommentUrl"] && (isset($blog["EDITOR_USE_LINK"]) && $blog["EDITOR_USE_LINK"] === "Y"))
  503. {
  504. $result[] = 'CreateLink';
  505. }
  506. // OTHER for all
  507. $result[] = "Quote";
  508. $result[] = "BlogTag";
  509. return $result;
  510. }
  511. }
  512. class CBlogTools
  513. {
  514. public static function htmlspecialcharsExArray($array)
  515. {
  516. $res = Array();
  517. if(!empty($array) && is_array($array))
  518. {
  519. foreach($array as $k => $v)
  520. {
  521. if(is_array($v))
  522. {
  523. foreach($v as $k1 => $v1)
  524. {
  525. $res[$k1] = htmlspecialcharsex($v1);
  526. $res['~'.$k1] = $v1;
  527. }
  528. }
  529. else
  530. {
  531. if (preg_match("/[;&<>\"]/", $v))
  532. $res[$k] = htmlspecialcharsex($v);
  533. else
  534. $res[$k] = $v;
  535. $res['~'.$k] = $v;
  536. }
  537. }
  538. }
  539. return $res;
  540. }
  541. public static function ResizeImage($aFile, $sizeX, $sizeY)
  542. {
  543. $arFile = CFile::ResizeImageGet($aFile, array("width"=>$sizeX, "height"=>$sizeY));
  544. if(is_array($arFile))
  545. return $arFile["src"];
  546. else
  547. return false;
  548. }
  549. public static function GetDateTimeFormat()
  550. {
  551. $timestamp = mktime(7,30,45,2,22,2007);
  552. return array(
  553. "d-m-Y H:i:s" => date("d-m-Y H:i:s", $timestamp),//"22-02-2007 7:30",
  554. "m-d-Y H:i:s" => date("m-d-Y H:i:s", $timestamp),//"02-22-2007 7:30",
  555. "Y-m-d H:i:s" => date("Y-m-d H:i:s", $timestamp),//"2007-02-22 7:30",
  556. "d.m.Y H:i:s" => date("d.m.Y H:i:s", $timestamp),//"22.02.2007 7:30",
  557. "m.d.Y H:i:s" => date("m.d.Y H:i:s", $timestamp),//"02.22.2007 7:30",
  558. "j M Y H:i:s" => date("j M Y H:i:s", $timestamp),//"22 Feb 2007 7:30",
  559. "M j, Y H:i:s" => date("M j, Y H:i:s", $timestamp),//"Feb 22, 2007 7:30",
  560. "j F Y H:i:s" => date("j F Y H:i:s", $timestamp),//"22 February 2007 7:30",
  561. "F j, Y H:i:s" => date("F j, Y H:i:s", $timestamp),//"February 22, 2007",
  562. "d.m.y g:i A" => date("d.m.y g:i A", $timestamp),//"22.02.07 1:30 PM",
  563. "d.m.y G:i" => date("d.m.y G:i", $timestamp),//"22.02.07 7:30",
  564. "d.m.Y H:i:s" => date("d.m.Y H:i:s", $timestamp),//"22.02.2007 07:30",
  565. );
  566. }
  567. public static function DeleteDoubleBR($text)
  568. {
  569. if(mb_strpos($text, "<br />\r<br />") !== false)
  570. {
  571. $text = str_replace("<br />\r<br />", "<br />", $text);
  572. return CBlogTools::DeleteDoubleBR($text);
  573. }
  574. if(mb_strpos($text, "<br /><br />") !== false)
  575. {
  576. $text = str_replace("<br /><br />", "<br />", $text);
  577. return CBlogTools::DeleteDoubleBR($text);
  578. }
  579. if(mb_strpos($text, "<br />") == 0 && mb_strpos($text, "<br />") !== false)
  580. {
  581. $text = mb_substr($text, 6);
  582. }
  583. return $text;
  584. }
  585. public static function blogUFfileEdit($arResult, $arParams)
  586. {
  587. $result = false;
  588. if (mb_strpos($arParams['arUserField']['FIELD_NAME'], CBlogPost::UF_NAME) === 0 || mb_strpos($arParams['arUserField']['FIELD_NAME'], 'UF_BLOG_COMMENT_DOC') === 0)
  589. {
  590. $componentParams = array(
  591. 'INPUT_NAME' => $arParams["arUserField"]["FIELD_NAME"],
  592. 'INPUT_NAME_UNSAVED' => 'FILE_NEW_TMP',
  593. 'INPUT_VALUE' => $arResult["VALUE"],
  594. 'MAX_FILE_SIZE' => intval($arParams['arUserField']['SETTINGS']['MAX_ALLOWED_SIZE']),
  595. 'MULTIPLE' => $arParams['arUserField']['MULTIPLE'],
  596. 'MODULE_ID' => 'uf',
  597. 'ALLOW_UPLOAD' => 'A',
  598. );
  599. $GLOBALS["APPLICATION"]->IncludeComponent('bitrix:main.file.input', 'drag_n_drop', $componentParams, false, Array("HIDE_ICONS" => "Y"));
  600. $result = true;
  601. }
  602. return $result;
  603. }
  604. public static function blogUFfileShow($arResult, $arParams)
  605. {
  606. $result = false;
  607. if ($arParams['arUserField']['FIELD_NAME'] == CBlogPost::UF_NAME || mb_strpos($arParams['arUserField']['FIELD_NAME'], 'UF_BLOG_COMMENT_DOC') === 0)
  608. {
  609. if (sizeof($arResult['VALUE']) > 0)
  610. {
  611. ?>
  612. <div class="feed-com-files">
  613. <div class="feed-com-files-title"><?=GetMessage('BLOG_FILES')?></div>
  614. <div class="feed-com-files-cont">
  615. <?
  616. }
  617. foreach ($arResult['VALUE'] as $fileID)
  618. {
  619. $arFile = CFile::GetFileArray($fileID);
  620. if($arFile)
  621. {
  622. $name = $arFile['ORIGINAL_NAME'];
  623. $ext = '';
  624. $dotpos = mb_strrpos($name, ".");
  625. if (($dotpos !== false) && ($dotpos + 1 < mb_strlen($name)))
  626. $ext = mb_substr($name, $dotpos + 1);
  627. if (mb_strlen($ext) < 3 || mb_strlen($ext) > 5)
  628. $ext = '';
  629. $arFile['EXTENSION'] = $ext;
  630. $arFile['LINK'] = "/bitrix/components/bitrix/blog/show_file.php?bp_fid=".$fileID;
  631. $arFile["FILE_SIZE"] = CFile::FormatSize($arFile["FILE_SIZE"]);
  632. ?>
  633. <div id="wdif-doc-<?=$arFile['ID']?>" class="feed-com-file-wrap">
  634. <div class="feed-con-file-name-wrap">
  635. <div class="feed-con-file-icon feed-file-icon-<?=htmlspecialcharsbx($arFile['EXTENSION'])?>"></div>
  636. <a target="_blank" href="<?=htmlspecialcharsbx($arFile['LINK'])?>" class="feed-com-file-name"><?=htmlspecialcharsbx($arFile['ORIGINAL_NAME'])?></a>
  637. <span class="feed-con-file-size">(<?=$arFile['FILE_SIZE']?>)</span>
  638. </div>
  639. </div>
  640. <?
  641. }
  642. }
  643. if (sizeof($arResult['VALUE']) > 0)
  644. {
  645. ?>
  646. </div>
  647. </div>
  648. <?
  649. }
  650. $result = true;
  651. }
  652. return $result;
  653. }
  654. }