BxBaseCmts.php 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * @see BxDolCmts
  11. */
  12. class BxBaseCmts extends BxDolCmts
  13. {
  14. protected static $_sTmplContentElementBlock;
  15. protected static $_sTmplContentElementInline;
  16. protected static $_sTmplContentDoCommentLabel;
  17. protected static $_sTmplContentCounter;
  18. protected $_sJsObjName;
  19. protected $_sStylePrefix;
  20. protected $_aHtmlIds;
  21. protected $_aElementDefaults;
  22. function __construct( $sSystem, $iId, $iInit = true, $oTemplate = false)
  23. {
  24. parent::__construct($sSystem, $iId, $iInit, $oTemplate);
  25. if (empty($sSystem))
  26. return;
  27. $this->_sJsObjName = 'oCmts' . bx_gen_method_name($sSystem, array('_' , '-')) . $iId;
  28. $this->_sStylePrefix = isset($this->_aSystem['root_style_prefix']) ? $this->_aSystem['root_style_prefix'] : 'cmt';
  29. $sHtmlId = str_replace(array('_' , ' '), array('-', '-'), $sSystem) . '-' . $iId;
  30. $this->_aHtmlIds = array(
  31. 'main' => 'bx-cmt-' . $sHtmlId,
  32. 'counter' => 'bx-cmt-counter-' . $sHtmlId
  33. );
  34. $this->_aElementDefaults = array(
  35. 'show_do_comment_as_button' => false,
  36. 'show_do_comment_as_button_small' => false,
  37. 'show_do_comment_image' => false,
  38. 'show_do_comment_icon' => true,
  39. 'show_do_comment_label' => false,
  40. 'show_counter' => true,
  41. 'show_counter_empty' => false
  42. );
  43. if(empty(self::$_sTmplContentElementBlock))
  44. self::$_sTmplContentElementBlock = $this->_oTemplate->getHtml('comment_element_block.html');
  45. if(empty(self::$_sTmplContentElementInline))
  46. self::$_sTmplContentElementInline = $this->_oTemplate->getHtml('comment_element_inline.html');
  47. if(empty(self::$_sTmplContentDoCommentLabel))
  48. self::$_sTmplContentDoCommentLabel = $this->_oTemplate->getHtml('comment_do_comment_label.html');
  49. if(empty(self::$_sTmplContentCounter))
  50. self::$_sTmplContentCounter = $this->_oTemplate->getHtml('comment_counter.html');
  51. $this->_oTemplate->addJsTranslation('_sys_txt_cmt_loading');
  52. }
  53. /**
  54. * Add comments CSS/JS
  55. */
  56. public function addCssJs ()
  57. {
  58. $oForm = BxDolForm::getObjectInstance($this->_sFormObject, $this->_sFormDisplayPost);
  59. $oForm->addCssJs();
  60. }
  61. public function getJsObjectName()
  62. {
  63. return $this->_sJsObjName;
  64. }
  65. /**
  66. * Get initialization section of comments box
  67. *
  68. * @return string
  69. */
  70. public function getJsScript($aBp = array(), $aDp = array())
  71. {
  72. $bMinPostForm = isset($aDp['min_post_form']) ? $aDp['min_post_form'] : $this->_bMinPostForm;
  73. $aParams = array(
  74. 'sObjName' => $this->_sJsObjName,
  75. 'sRootUrl' => BX_DOL_URL_ROOT,
  76. 'sSystem' => $this->getSystemName(),
  77. 'iAuthorId' => $this->_getAuthorId(),
  78. 'iObjId' => $this->getId(),
  79. 'sBaseUrl' => $this->getBaseUrl(),
  80. 'sPostFormPosition' => $this->_aSystem['post_form_position'],
  81. 'sBrowseType' => $this->_sBrowseType,
  82. 'sDisplayType' => $this->_sDisplayType,
  83. 'iMinPostForm' => $bMinPostForm ? 1 : 0,
  84. );
  85. $this->addCssJs();
  86. return $this->_oTemplate->_wrapInTagJsCode("if(window['" . $this->_sJsObjName . "'] == undefined) var " . $this->_sJsObjName . " = new BxDolCmts(" . json_encode($aParams) . "); " . $this->_sJsObjName . ".cmtInit();");
  87. }
  88. /**
  89. * get full comments block with initializations
  90. */
  91. function getCommentsBlock($aBp = array(), $aDp = array())
  92. {
  93. $mixedResult = $this->isViewAllowed();
  94. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  95. return $mixedResult;
  96. $this->_getParams($aBp, $aDp);
  97. //add live update
  98. $this->actionResumeLiveUpdate();
  99. $sServiceCall = BxDolService::getSerializedService('system', 'get_live_update', array($this->_sSystem, $this->_iId, $this->_getAuthorId(), '{count}'), 'TemplCmtsServices');
  100. BxDolLiveUpdates::getInstance()->add($this->_sSystem . '_live_updates_cmts_' . $this->_iId, 1, $sServiceCall);
  101. //add live update
  102. $sCaption = _t($this->_aT['block_comments_title'], $this->getCommentsCountAll());
  103. $sContent = $this->_oTemplate->parseHtmlByName('comments_block.html', array(
  104. 'system' => $this->_sSystem,
  105. 'list_anchor' => $this->getListAnchor(),
  106. 'id' => $this->getId(),
  107. 'comments' => $this->getComments($aBp, $aDp),
  108. 'post_form_top' => $this->getFormBoxPost($aBp, array_merge($aDp, array('type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_TOP))),
  109. 'post_form_bottom' => $this->getFormBoxPost($aBp, array_merge($aDp, array('type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_BOTTOM))),
  110. 'view_image_popup' => $this->_getViewImagePopup(),
  111. 'script' => $this->getJsScript($aBp, $aDp)
  112. ));
  113. return $aDp['in_designbox'] ? DesignBoxContent($sCaption, $sContent, BX_DB_DEF, $this->_getControlsBox()) : array(
  114. 'title' => $sCaption,
  115. 'content' => $sContent,
  116. 'menu' => $this->_getControlsBox(),
  117. );
  118. }
  119. /**
  120. * get comments list for specified parent comment
  121. *
  122. * @param array $aBp - browse params array
  123. * @param array $aDp - display params array
  124. *
  125. */
  126. function getComments($aBp = array(), $aDp = array())
  127. {
  128. $this->_prepareParams($aBp, $aDp);
  129. $aCmts = $this->getCommentsArray($aBp['vparent_id'], $aBp['filter'], $aBp['order'], $aBp['start'], $aBp['per_view']);
  130. if(empty($aCmts) || !is_array($aCmts)) {
  131. if((int)$aBp['parent_id'] == 0 && !isLogged()) {
  132. $oPermalink = BxDolPermalinks::getInstance();
  133. return MsgBox(_t('_cmt_msg_login_required', $oPermalink->permalink('page.php?i=login'), $oPermalink->permalink('page.php?i=create-account')));
  134. }
  135. return isset($aDp['show_empty']) && $aDp['show_empty'] === true ? $this->_getEmpty($aDp) : '';
  136. }
  137. $sCmts = '';
  138. foreach($aCmts as $k => $aCmt)
  139. $sCmts .= $this->getComment($aCmt, $aBp, $aDp);
  140. $sCmts = $this->_getMoreLink($sCmts, $aBp, $aDp);
  141. return $sCmts;
  142. }
  143. /**
  144. * get comment view block with initializations
  145. */
  146. function getCommentBlock($iCmtId = 0, $aBp = array(), $aDp = array())
  147. {
  148. $mixedResult = $this->isViewAllowed();
  149. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  150. return $mixedResult;
  151. $aBp = array_merge(array('type' => $this->_sBrowseType), $aBp);
  152. $aDp = array_merge(array('type' => BX_CMT_DISPLAY_THREADED), $aDp);
  153. $sComment = $this->getComment($iCmtId, $aBp, $aDp);
  154. if (!$sComment)
  155. return '';
  156. return $this->_oTemplate->parseHtmlByName('comment_block.html', array(
  157. 'system' => $this->_sSystem,
  158. 'id' => $this->getId(),
  159. 'comment' => $sComment,
  160. 'view_image_popup' => $this->_getViewImagePopup(),
  161. 'script' => $this->getJsScript($aBp, $aDp)
  162. ));
  163. }
  164. /**
  165. * get one just posted comment
  166. *
  167. * @param int $iCmtId - comment id
  168. * @return string
  169. */
  170. function getComment($mixedCmt, $aBp = array(), $aDp = array())
  171. {
  172. $iUserId = $this->_getAuthorId();
  173. $aCmt = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
  174. if (!$aCmt)
  175. return '';
  176. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  177. $sClass = $sClassCnt = '';
  178. if(isset($aCmt['vote_rate']) && (float)$aCmt['vote_rate'] < $this->_aSystem['viewing_threshold']) {
  179. $this->_oTemplate->pareseHtmlByName('comment_hidden.html', array(
  180. 'js_object' => $this->_sJsObjName,
  181. 'id' => $aCmt['cmt_id'],
  182. 'title' => bx_process_output(_t('_hidden_comment', $sAuthorName)),
  183. 'bx_if:show_replies' => array(
  184. 'condition' => $aCmt['cmt_replies'] > 0,
  185. 'content' => array(
  186. 'replies' => _t('_Show N replies', $aCmt['cmt_replies'])
  187. )
  188. )
  189. ));
  190. $sClass = ' ' . $this->_sStylePrefix . '-hidden';
  191. }
  192. if($aCmt['cmt_author_id'] == $iUserId)
  193. $sClass .= ' ' . $this->_sStylePrefix . '-mine';
  194. if(!empty($aDp['blink']) && in_array($aCmt['cmt_id'], $aDp['blink']))
  195. $sClass .= ' ' . $this->_sStylePrefix . '-blink';
  196. if(!empty($aDp['class_comment']))
  197. $sClass .= ' ' . $aDp['class_comment'];
  198. if(!empty($aDp['class_comment_content']))
  199. $sClassCnt .= ' ' . $aDp['class_comment_content'];
  200. $sActions = $this->_getActionsBox($aCmt, $aDp);
  201. $aTmplReplyTo = array();
  202. if((int)$aCmt['cmt_parent_id'] != 0) {
  203. $aParent = $this->getCommentRow($aCmt['cmt_parent_id']);
  204. list($sParAuthorName, $sParAuthorLink, $sParAuthorIcon) = $this->_getAuthorInfo($aParent['cmt_author_id']);
  205. $aTmplReplyTo = array(
  206. 'style_prefix' => $this->_sStylePrefix,
  207. 'par_cmt_link' => $this->getItemUrl($aCmt['cmt_parent_id']),
  208. 'par_cmt_title' => bx_html_attribute(_t('_in_reply_to', $sParAuthorName)),
  209. 'par_cmt_author' => $sParAuthorName
  210. );
  211. }
  212. $sAttachments = $this->_getAttachments($aCmt);
  213. $sReplies = '';
  214. if((int)$aCmt['cmt_replies'] > 0 && !empty($aDp) && $aDp['type'] == BX_CMT_DISPLAY_THREADED) {
  215. $aDp['show_empty'] = false;
  216. $sReplies = $this->getComments(array('parent_id' => $aCmt['cmt_id'], 'vparent_id' => $aCmt['cmt_id'], 'type' => $aBp['type']), $aDp);
  217. }
  218. $aTmplVarsMeta = array();
  219. if(!empty($this->_sMenuObjMeta)) {
  220. $oMenuMeta = BxDolMenu::getObjectInstance($this->_sMenuObjMeta, $this->_oTemplate);
  221. if($oMenuMeta) {
  222. $oMenuMeta->setCmtsData($this, $aCmt['cmt_id']);
  223. $aTmplVarsMeta = array(
  224. 'style_prefix' => $this->_sStylePrefix,
  225. 'meta' => $oMenuMeta->getCode()
  226. );
  227. }
  228. }
  229. return $this->_oTemplate->parseHtmlByName('comment.html', array_merge(array(
  230. 'system' => $this->_sSystem,
  231. 'style_prefix' => $this->_sStylePrefix,
  232. 'js_object' => $this->_sJsObjName,
  233. 'id' => $aCmt['cmt_id'],
  234. 'anchor' => $this->getItemAnchor($aCmt['cmt_id']),
  235. 'class' => $sClass,
  236. 'class_cnt' => $sClassCnt,
  237. 'bx_if:show_reply_to' => array(
  238. 'condition' => !empty($aTmplReplyTo),
  239. 'content' => $aTmplReplyTo
  240. ),
  241. 'bx_if:meta' => array(
  242. 'condition' => !empty($aTmplVarsMeta),
  243. 'content' => $aTmplVarsMeta
  244. ),
  245. 'bx_if:show_attached' => array(
  246. 'condition' => !empty($sAttachments),
  247. 'content' => array(
  248. 'style_prefix' => $this->_sStylePrefix,
  249. 'attached' => $sAttachments
  250. )
  251. ),
  252. 'actions' => $sActions,
  253. 'replies' => $sReplies
  254. ), $this->_getTmplVarsAuthor($aCmt), $this->_getTmplVarsText($aCmt)));
  255. }
  256. function getCommentSearch($iCmtId, &$sAddon)
  257. {
  258. $aBp = array();
  259. $aDp = array(
  260. 'type' => BX_CMT_DISPLAY_FLAT,
  261. 'view_only' => true
  262. );
  263. if(empty($sAddon))
  264. $sAddon = $this->getJsScript($aBp, $aDp);
  265. return $this->_oTemplate->parseHtmlByName('comment_search.html', array(
  266. 'comment' => $this->getComment($iCmtId, $aBp, $aDp),
  267. 'view_image_popup' => $this->_getViewImagePopup(),
  268. ));
  269. }
  270. /**
  271. * get one comment for "Live Search"
  272. *
  273. * @param int $iCmtId - comment id
  274. * @return string
  275. */
  276. function getCommentLiveSearch($mixedCmt, $aParams = array())
  277. {
  278. $aCmt = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
  279. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  280. $bAuthorIcon = !empty($sAuthorIcon);
  281. $sViewLink = $this->getViewUrl($aCmt['cmt_id']);
  282. if(empty($sViewLink))
  283. $sViewLink = '#';
  284. return $this->_oTemplate->parseHtmlByName('comment_live_search.html', array(
  285. 'bx_if:show_icon' => array(
  286. 'condition' => $bAuthorIcon,
  287. 'content' => array(
  288. 'author_icon' => $sAuthorIcon,
  289. 'view_link' => $sViewLink
  290. )
  291. ),
  292. 'bx_if:show_icon_empty' => array(
  293. 'condition' => !$bAuthorIcon,
  294. 'content' => array()
  295. ),
  296. 'view_link' => $sViewLink,
  297. 'text' => BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($aCmt['cmt_text']), $this->_sSnippetLenthLiveSearch),
  298. 'sample' => isset($aParams['txt_sample_single']) ? _t($aParams['txt_sample_single']) : ''
  299. ));
  300. }
  301. function getFormBoxPost($aBp = array(), $aDp = array())
  302. {
  303. if(!$this->isPostReplyAllowed())
  304. return '';
  305. return $this->_getFormBox(BX_CMT_ACTION_POST, $aBp, $aDp);
  306. }
  307. function getFormBoxEdit($aBp = array(), $aDp = array())
  308. {
  309. return $this->_getFormBox(BX_CMT_ACTION_EDIT, $aBp, $aDp);
  310. }
  311. function getFormPost($iCmtParentId = 0, $aDp = array())
  312. {
  313. return $this->_getFormPost($iCmtParentId, $aDp);
  314. }
  315. function getFormEdit($iCmtId, $aDp = array())
  316. {
  317. return $this->_getFormEdit($iCmtId, $aDp);
  318. }
  319. function getLiveUpdate($iCountOld = 0, $iCountNew = 0)
  320. {
  321. $iCount = (int)$iCountNew - (int)$iCountOld;
  322. if($iCount < 0)
  323. return '';
  324. $aComments = $this->_oQuery->getCommentsBy(array('type' => 'latest', 'object_id' => $this->_iId, 'author' => $this->_getAuthorId(), 'others' => 1, 'start' => '0', 'per_page' => $iCount));
  325. if(empty($aComments) || !is_array($aComments))
  326. return '';
  327. $aComment = array_shift($aComments);
  328. if(empty($aComment) || !is_array($aComment))
  329. return '';
  330. $sJsObject = $this->getJsObjectName();
  331. return $this->_oTemplate->parseHtmlByName('comments_lu_button.html', array(
  332. 'style_prefix' => $this->_sStylePrefix,
  333. 'html_id' => $this->getNotificationId(),
  334. 'onclick_show' => "javascript:" . $sJsObject . ".goToBtn(this, '" . $this->getItemAnchor($aComment['cmt_id']) . "', '" . $aComment['cmt_id'] . "');",
  335. ));
  336. }
  337. function getLiveUpdates($iCountOld = 0, $iCountNew = 0)
  338. {
  339. $bShowAll = true;
  340. $bShowActions = false;
  341. $iCount = (int)$iCountNew - (int)$iCountOld;
  342. if($iCount < 0)
  343. return '';
  344. $aComments = $this->_oQuery->getCommentsBy(array('type' => 'latest', 'object_id' => $this->_iId, 'author' => $this->_getAuthorId(), 'others' => 1, 'start' => '0', 'per_page' => $iCount));
  345. if(empty($aComments) || !is_array($aComments))
  346. return '';
  347. $sJsObject = $this->getJsObjectName();
  348. $iUserId = $this->_getAuthorId();
  349. $bModerator = $this->isModerator();
  350. $aComments = array_reverse($aComments);
  351. $iComments = count($aComments);
  352. $aTmplVarsNotifs = array();
  353. foreach($aComments as $iIndex => $aComment) {
  354. $iCommentId = $aComment['cmt_id'];
  355. $sShowOnClick = "javascript:" . $sJsObject . ".goTo(this, '" . $this->getItemAnchor($iCommentId) . "', '" . $iCommentId . "');";
  356. $sReplyOnClick = "javascript:" . $sJsObject . ".goToAndReply(this, '" . $this->getItemAnchor($iCommentId) . "', '" . $iCommentId . "');";
  357. $iAuthorId = (int)$aComment['cmt_author_id'];
  358. if($iAuthorId < 0) {
  359. if(abs($iAuthorId) == $iUserId)
  360. continue;
  361. else if($bModerator)
  362. $iAuthorId *= -1;
  363. }
  364. $oAuthor = $this->_getAuthorObject($iAuthorId);
  365. $sAuthorName = $oAuthor->getDisplayName();
  366. $aTmplVarsNotifs[] = array(
  367. 'bx_if:show_as_hidden' => array(
  368. 'condition' => !$bShowAll && $iIndex < ($iComments - 1),
  369. 'content' => array(),
  370. ),
  371. 'item' => $this->_oTemplate->parseHtmlByName('comments_lu_notifications.html', array(
  372. 'style_prefix' => $this->_sStylePrefix,
  373. 'onclick_show' => $sShowOnClick,
  374. 'onclick_reply' => $sReplyOnClick,
  375. 'author_link' => $oAuthor->getUrl(),
  376. 'author_title' => bx_html_attribute($sAuthorName),
  377. 'author_name' => $sAuthorName,
  378. 'author_unit' => $oAuthor->getUnit(0, array('template' => 'unit_wo_info_links')),
  379. 'text' => _t('_cmt_txt_added_sample')
  380. )),
  381. 'bx_if:show_previous' => array(
  382. 'condition' => $bShowActions && $iIndex > 0,
  383. 'content' => array(
  384. 'onclick_previous' => $sJsObject . '.previousLiveUpdate(this)'
  385. )
  386. ),
  387. 'bx_if:show_close' => array(
  388. 'condition' => $bShowActions,
  389. 'content' => array(
  390. 'onclick_close' => $sJsObject . '.hideLiveUpdate(this)'
  391. )
  392. )
  393. );
  394. }
  395. return $this->_oTemplate->parseHtmlByName('popup_chain.html', array(
  396. 'html_id' => $this->getNotificationId(),
  397. 'bx_repeat:items' => $aTmplVarsNotifs
  398. ));
  399. }
  400. public function getElementBlock($aParams = array())
  401. {
  402. $aParams['usage'] = BX_CMT_USAGE_BLOCK;
  403. return $this->getElement($aParams);
  404. }
  405. public function getElementInline($aParams = array())
  406. {
  407. $aParams['usage'] = BX_CMT_USAGE_INLINE;
  408. return $this->getElement($aParams);
  409. }
  410. public function getElement($aParams = array())
  411. {
  412. $aParams = array_merge($this->_aElementDefaults, $aParams);
  413. $bShowDoCommentAsButtonSmall = isset($aParams['show_do_comment_as_button_small']) && $aParams['show_do_comment_as_button_small'] == true;
  414. $bShowDoCommentAsButton = !$bShowDoCommentAsButtonSmall && isset($aParams['show_do_comment_as_button']) && $aParams['show_do_comment_as_button'] == true;
  415. $bShowCounterEmpty = isset($aParams['show_counter_empty']) && $aParams['show_counter_empty'] == true;
  416. $iObjectId = $this->getId();
  417. $iAuthorId = $this->_getAuthorId();
  418. $iAuthorIp = $this->_getAuthorIp();
  419. $iCount = $this->getCommentsCountAll();
  420. $bCount = (int)$iCount != 0;
  421. $isAllowedComment = $this->isPostReplyAllowed();
  422. //--- Do Comment
  423. $bTmplVarsDoComment = $this->_isShowDoComment($aParams, $isAllowedComment, $bCount);
  424. $aTmplVarsDoComment = array();
  425. if($bTmplVarsDoComment) {
  426. $sClass = '';
  427. if($bShowDoCommentAsButton)
  428. $sClass = 'bx-btn';
  429. else if ($bShowDoCommentAsButtonSmall)
  430. $sClass = 'bx-btn bx-btn-small';
  431. if(!$isAllowedComment)
  432. $sClass .= $bShowDoCommentAsButton || $bShowDoCommentAsButtonSmall ? ' bx-btn-disabled' : 'bx-cmts-disabled';
  433. $aTmplVarsDoComment = array(
  434. 'style_prefix' => $this->_sStylePrefix,
  435. 'do_comment' => $this->_oTemplate->parseLink($this->getListUrl(), $this->_getLabelDo($aParams), array(
  436. 'class' => $this->_sStylePrefix . '-do-comment ' . $this->_sStylePrefix . '-dc ' . $sClass,
  437. 'title' => _t($this->_getTitleDo())
  438. )),
  439. );
  440. }
  441. //--- Counter
  442. $bTmplVarsCounter = $this->_isShowCounter($aParams, $isAllowedComment, $bCount);
  443. $aTmplVarsCounter = array();
  444. if($bTmplVarsCounter)
  445. $aTmplVarsCounter = array(
  446. 'style_prefix' => $this->_sStylePrefix,
  447. 'bx_if:show_hidden' => array(
  448. 'condition' => !$bShowCounterEmpty && !$bCount,
  449. 'content' => array()
  450. ),
  451. 'counter' => $this->getCounter($aParams)
  452. );
  453. if(!$bTmplVarsDoComment && !$bTmplVarsCounter)
  454. return '';
  455. $sTmplName = $this->{'_getTmplElement' . bx_gen_method_name(!empty($aParams['usage']) ? $aParams['usage'] : BX_DOL_SCORE_USAGE_DEFAULT)}();
  456. return $this->_oTemplate->parseHtmlByContent($sTmplName, array(
  457. 'style_prefix' => $this->_sStylePrefix,
  458. 'html_id' => $this->_aHtmlIds['main'],
  459. 'class' => $this->_sStylePrefix . ($bShowDoCommentAsButton ? '-button' : '') . ($bShowDoCommentAsButtonSmall ? '-button-small' : ''),
  460. 'count' => $iCount,
  461. 'bx_if:show_do_comment' => array(
  462. 'condition' => $bTmplVarsDoComment,
  463. 'content' => $aTmplVarsDoComment
  464. ),
  465. 'bx_if:show_counter' => array(
  466. 'condition' => $bTmplVarsCounter,
  467. 'content' => $aTmplVarsCounter
  468. ),
  469. 'script' => ''
  470. ));
  471. }
  472. public function getCounter($aParams = array())
  473. {
  474. $bShowEmpty = isset($aParams['show_counter_empty']) && $aParams['show_counter_empty'] == true;
  475. $bShowDoCommentAsButtonSmall = isset($aParams['show_do_comment_as_button_small']) && $aParams['show_do_comment_as_button_small'] == true;
  476. $bShowDoCommentAsButton = !$bShowDoCommentAsButtonSmall && isset($aParams['show_do_comment_as_button']) && $aParams['show_do_comment_as_button'] == true;
  477. $iCount = (int)$this->getCommentsCountAll();
  478. $sClass = $this->_sStylePrefix . '-counter';
  479. if($bShowDoCommentAsButtonSmall)
  480. $sClass .= ' bx-btn-small-height';
  481. if($bShowDoCommentAsButton)
  482. $sClass .= ' bx-btn-height';
  483. return $this->_oTemplate->parseHtmlByContent($this->_getTmplCounter(), array(
  484. 'id' => $this->_aHtmlIds['counter'],
  485. 'class' => $sClass,
  486. 'content' => $iCount != 0 || $bShowEmpty ? $this->_getLabelCounter($iCount) : ''
  487. ));
  488. }
  489. protected function _getLabelDo($aParams = array())
  490. {
  491. return $this->_oTemplate->parseHtmlByContent($this->_getTmplLabelDo(), array(
  492. 'bx_if:show_image' => array(
  493. 'condition' => isset($aParams['show_do_comment_image']) && $aParams['show_do_comment_image'] == true,
  494. 'content' => array(
  495. 'src' => $this->_getImageDo()
  496. )
  497. ),
  498. 'bx_if:show_icon' => array(
  499. 'condition' => isset($aParams['show_do_comment_icon']) && $aParams['show_do_comment_icon'] == true,
  500. 'content' => array(
  501. 'name' => $this->_getIconDo()
  502. )
  503. ),
  504. 'bx_if:show_text' => array(
  505. 'condition' => isset($aParams['show_do_comment_label']) && $aParams['show_do_comment_label'] == true,
  506. 'content' => array(
  507. 'text' => _t($this->_getTitleDo())
  508. )
  509. )
  510. ));
  511. }
  512. protected function _getLabelCounter($iCount)
  513. {
  514. return (int)$iCount != 0 ? _t('_cmt_txt_counter', $iCount) : _t('_cmt_txt_counter_empty');
  515. }
  516. protected function _getTmplElementBlock()
  517. {
  518. return self::$_sTmplContentElementBlock;
  519. }
  520. protected function _getTmplElementInline()
  521. {
  522. return self::$_sTmplContentElementInline;
  523. }
  524. protected function _getTmplLabelDo()
  525. {
  526. return self::$_sTmplContentDoCommentLabel;
  527. }
  528. protected function _getTmplCounter()
  529. {
  530. return self::$_sTmplContentCounter;
  531. }
  532. /**
  533. * private functions
  534. */
  535. protected function _getControlsBox()
  536. {
  537. $sDisplay = '';
  538. $bDisplay = (int)$this->_aSystem['is_display_switch'] == 1;
  539. if($bDisplay) {
  540. $aDisplayLinks = array(
  541. array('id' => $this->_sSystem . '-flat', 'name' => $this->_sSystem . '-flat', 'class' => '', 'title' => '_cmt_display_flat', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeDisplay(this, \'flat\');'),
  542. array('id' => $this->_sSystem . '-threaded', 'name' => $this->_sSystem . '-threaded', 'class' => '', 'title' => '_cmt_display_threaded', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeDisplay(this, \'threaded\');')
  543. );
  544. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-display', 'menu_items' => $aDisplayLinks));
  545. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sDisplayType);
  546. $sDisplay = $oMenu->getCode();
  547. }
  548. $sBrowseType = '';
  549. $bBrowseType = (int)$this->_aSystem['is_browse_switch'] == 1;
  550. if($bBrowseType) {
  551. $aBrowseLinks = array(
  552. array('id' => $this->_sSystem . '-tail', 'name' => $this->_sSystem . '-tail', 'class' => '', 'title' => '_cmt_browse_tail', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'tail\');'),
  553. array('id' => $this->_sSystem . '-head', 'name' => $this->_sSystem . '-head', 'class' => '', 'title' => '_cmt_browse_head', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'head\');'),
  554. array('id' => $this->_sSystem . '-popular', 'name' => $this->_sSystem . '-popular', 'class' => '', 'title' => '_cmt_browse_popular', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'popular\');'),
  555. );
  556. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-browse', 'menu_items' => $aBrowseLinks));
  557. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sBrowseType);
  558. $sBrowseType = $oMenu->getCode();
  559. }
  560. $sBrowseFilter = '';
  561. $bBrowseFilter = (int)$this->_aSystem['is_browse_filter'] == 1;
  562. if($bBrowseFilter) {
  563. $aFilterLinks = array(
  564. array('id' => $this->_sSystem . '-all', 'name' => $this->_sSystem . '-all', 'class' => '', 'title' => '_cmt_browse_all', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'all\');'),
  565. array('id' => $this->_sSystem . '-friends', 'name' => $this->_sSystem . '-friends', 'class' => '', 'title' => '_cmt_browse_friends', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'friends\');'),
  566. array('id' => $this->_sSystem . '-subscriptions', 'name' => $this->_sSystem . '-subscriptions', 'class' => '', 'title' => '_cmt_browse_subscriptions', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'subscriptions\');')
  567. );
  568. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-filter', 'menu_items' => $aFilterLinks));
  569. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sBrowseFilter);
  570. $sBrowseFilter = $oMenu->getCode();
  571. }
  572. return $this->_oTemplate->parseHtmlByName('comments_controls.html', array(
  573. 'display_switcher' => $bDisplay ? $sDisplay : '',
  574. 'bx_if:is_divider_1' => array(
  575. 'condition' => $bDisplay && $bBrowseType,
  576. 'content' => array(
  577. 'style_prefix' => $this->_sStylePrefix,
  578. )
  579. ),
  580. 'browse_switcher' => $bBrowseType ? $sBrowseType : '',
  581. 'bx_if:is_divider_2' => array(
  582. 'condition' => $bBrowseType && $bBrowseFilter,
  583. 'content' => array(
  584. 'style_prefix' => $this->_sStylePrefix,
  585. )
  586. ),
  587. 'filter_switcher' => $bBrowseFilter ? $sBrowseFilter : '',
  588. ));
  589. }
  590. protected function _getActionsBox(&$aCmt, $aDp = array())
  591. {
  592. $bViewOnly = isset($aDp['view_only']) && $aDp['view_only'] === true;
  593. $bDynamicMode = isset($aDp['dynamic_mode']) && $aDp['dynamic_mode'] === true;
  594. $sMenuActions = '';
  595. if(!$bViewOnly) {
  596. $oMenuActions = BxDolMenu::getObjectInstance($this->_sMenuObjActions);
  597. $oMenuActions->setCmtsData($this, $aCmt['cmt_id']);
  598. $oMenuActions->setDynamicMode($bDynamicMode);
  599. $sMenuActions = $oMenuActions->getCode();
  600. }
  601. return $this->_oTemplate->parseHtmlByName('comment_actions.html', array(
  602. 'id' => $aCmt['cmt_id'],
  603. 'js_object' => $this->_sJsObjName,
  604. 'style_prefix' => $this->_sStylePrefix,
  605. 'menu_actions' => $sMenuActions,
  606. ));
  607. }
  608. protected function _getFormBox($sType, $aBp, $aDp)
  609. {
  610. $iCmtParentId = isset($aBp['parent_id']) ? (int)$aBp['parent_id'] : 0;
  611. $sPosition = isset($aDp['position']) ? $aDp['position'] : '';
  612. $bFormMin = $iCmtParentId == 0 && isset($aDp['min_post_form']) ? $aDp['min_post_form'] : false;
  613. $sPositionSystem = $this->_aSystem['post_form_position'];
  614. if(!empty($sPosition) && $sPositionSystem != $sPosition)
  615. return '';
  616. $sClass = '';
  617. if(!empty($sPosition))
  618. $sClass .= ' ' . $this->_sStylePrefix . '-reply-' . $sPosition;
  619. if($bFormMin)
  620. $sClass .= ' ' . $this->_sStylePrefix . '-reply-min';
  621. if(!empty($aDp['class']))
  622. $sClass .= ' ' . $aDp['class'];
  623. $sClassBody = '';
  624. if(!empty($aDp['class_body']))
  625. $sClassBody .= ' ' . $aDp['class_body'];
  626. $aTmplVarsFormMin = array();
  627. if($bFormMin) {
  628. list($sAuthorName, $sAuthorLink, $sAuthorIcon, $sAuthorUnit) = $this->_getAuthorInfo($this->_getAuthorId());
  629. $oForm = new BxTemplFormView(array());
  630. $aInputPlaceholder = array(
  631. 'type' => 'text',
  632. 'name' => 'comment',
  633. 'caption' => '',
  634. 'attrs' => array(
  635. 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtShowForm(this)',
  636. 'placeholder' => _t('_cmt_txt_min_form_placeholder', $sAuthorName)
  637. ),
  638. 'value' => '',
  639. );
  640. $sClassBodyMin = '';
  641. if(!empty($aDp['class_body_min']))
  642. $sClassBodyMin .= ' ' . $aDp['class_body_min'];
  643. $aTmplVarsFormMin = array(
  644. 'js_object' => $this->_sJsObjName,
  645. 'class_body_min' => $sClassBodyMin,
  646. 'style_prefix' => $this->_sStylePrefix,
  647. 'author_unit' => $sAuthorUnit,
  648. 'placeholder' => $oForm->genRow($aInputPlaceholder)
  649. );
  650. }
  651. $sMethod = '_getForm' . ucfirst($sType);
  652. $aForm = $this->$sMethod($iCmtParentId, $aDp);
  653. return $this->_oTemplate->parseHtmlByName('comment_reply_box.html', array(
  654. 'js_object' => $this->_sJsObjName,
  655. 'style_prefix' => $this->_sStylePrefix,
  656. 'class' => $sClass,
  657. 'class_body' => $sClassBody,
  658. 'bx_if:show_form_min' => array(
  659. 'condition' => $bFormMin,
  660. 'content' => $aTmplVarsFormMin
  661. ),
  662. 'form' => $aForm['form'],
  663. 'form_id' => $aForm['form_id'],
  664. ));
  665. }
  666. protected function _getFormPost($iCmtParentId = 0, $aDp = array())
  667. {
  668. $bDynamic = isset($aDp['dynamic_mode']) && (bool)$aDp['dynamic_mode'];
  669. $oForm = $this->_getForm(BX_CMT_ACTION_POST, $iCmtParentId);
  670. $oForm->aInputs['cmt_parent_id']['value'] = $iCmtParentId;
  671. $oForm->initChecker();
  672. if($oForm->isSubmittedAndValid()) {
  673. $iCmtAuthorId = $this->_getAuthorId();
  674. $iCmtParentId = $oForm->getCleanValue('cmt_parent_id');
  675. $sCmtText = $oForm->getCleanValue('cmt_text');
  676. $iLevel = 0;
  677. $iCmtVisualParentId = 0;
  678. if((int)$iCmtParentId > 0) {
  679. $aParent = $this->getCommentRow($iCmtParentId);
  680. $iLevel = (int)$aParent['cmt_level'] + 1;
  681. $iCmtVisualParentId = $iLevel > $this->getMaxLevel() ? $aParent['cmt_vparent_id'] : $iCmtParentId;
  682. }
  683. $iCmtId = (int)$oForm->insert(array('cmt_vparent_id' => $iCmtVisualParentId, 'cmt_object_id' => $this->_iId, 'cmt_author_id' => $iCmtAuthorId, 'cmt_level' => $iLevel, 'cmt_time' => time()));
  684. if($iCmtId != 0) {
  685. if($this->isAttachImageEnabled()) {
  686. $aImages = $oForm->getCleanValue('cmt_image');
  687. if(!empty($aImages) && is_array($aImages)) {
  688. $oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
  689. foreach($aImages as $iImageId)
  690. if($this->_oQuery->saveImages($this->_aSystem['system_id'], $iCmtId, $iImageId))
  691. $oStorage->afterUploadCleanup($iImageId, $iCmtAuthorId);
  692. }
  693. }
  694. if($iCmtParentId) {
  695. $this->_oQuery->updateRepliesCount($iCmtParentId, 1);
  696. if(!BxDolModuleQuery::getInstance()->isEnabledByName('bx_notifications'))
  697. $this->_sendNotificationEmail($iCmtId, $iCmtParentId);
  698. }
  699. $this->_triggerComment();
  700. $this->isPostReplyAllowed(true);
  701. if ($this->_sMetatagsObj) {
  702. $oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj);
  703. $oMetatags->metaAdd($this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId), $sCmtText);
  704. }
  705. $this->onPostAfter($iCmtId);
  706. return array('id' => $iCmtId, 'parent_id' => $iCmtParentId);
  707. }
  708. return array('msg' => _t('_cmt_err_cannot_perform_action'));
  709. }
  710. return array('form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id);
  711. }
  712. protected function _getFormEdit($iCmtId, $aDp = array())
  713. {
  714. $bDynamic = isset($aDp['dynamic_mode']) && (bool)$aDp['dynamic_mode'];
  715. $aCmt = $this->_oQuery->getCommentSimple ((int)$this->getId(), $iCmtId);
  716. if(!$aCmt)
  717. return array('msg' => _t('_No such comment'));
  718. $iCmtAuthorId = $this->_getAuthorId();
  719. if(!$this->isEditAllowed($aCmt))
  720. return array('msg' => $aCmt['cmt_author_id'] == $iCmtAuthorId ? strip_tags($this->msgErrEditAllowed()) : _t('_Access denied'));
  721. $oForm = $this->_getForm(BX_CMT_ACTION_EDIT, $aCmt['cmt_id']);
  722. $oForm->initChecker($aCmt);
  723. if($oForm->isSubmittedAndValid()) {
  724. $sCmtText = $oForm->getCleanValue('cmt_text');
  725. if($oForm->update($iCmtId) !== false) {
  726. $this->isEditAllowed($aCmt, true);
  727. if ($this->_sMetatagsObj) {
  728. $oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj);
  729. $oMetatags->metaAdd($this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId), $sCmtText);
  730. }
  731. $this->onEditAfter($iCmtId);
  732. return array('id' => $iCmtId, 'text' => $this->_prepareTextForOutput($sCmtText, $iCmtId));
  733. }
  734. return array('msg' => _t('_cmt_err_cannot_perform_action'));
  735. }
  736. return array('form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id);
  737. }
  738. protected function _getForm($sAction, $iId)
  739. {
  740. $oForm = $this->_getFormObject($sAction);
  741. $oForm->setId(sprintf($oForm->getAttributeMask('id'), $sAction, $this->_sSystem, $iId));
  742. $oForm->setName(sprintf($oForm->getAttributeMask('name'), $sAction, $this->_sSystem, $iId));
  743. $oForm->aParams['db']['table'] = $this->_aSystem['table'];
  744. $oForm->aInputs['sys']['value'] = $this->_sSystem;
  745. $oForm->aInputs['id']['value'] = $this->_iId;
  746. $oForm->aInputs['action']['value'] = 'Submit' . ucfirst($sAction) . 'Form';
  747. if(!$this->isAttachImageEnabled())
  748. unset($oForm->aInputs['cmt_image']);
  749. if(isset($oForm->aInputs['cmt_text'])) {
  750. $oForm->aInputs['cmt_text']['html'] = $this->_aSystem['html'];
  751. $oForm->aInputs['cmt_text']['db']['pass'] = $this->isHtml() ? 'XssHtml' : 'XssMultiline';
  752. $iCmtTextMin = (int)$this->_aSystem['chars_post_min'];
  753. $iCmtTextMax = (int)$this->_aSystem['chars_post_max'];
  754. $oForm->aInputs['cmt_text']['checker']['params'] = array($iCmtTextMin, $iCmtTextMax);
  755. $oForm->aInputs['cmt_text']['checker']['error'] = _t('_Please enter n1-n2 characters', $iCmtTextMin, $iCmtTextMax);
  756. }
  757. return $oForm;
  758. }
  759. protected function _getMoreLink($sCmts, $aBp = array(), $aDp = array())
  760. {
  761. $iStart = $iPerView = 0;
  762. switch($aBp['type']) {
  763. case BX_CMT_BROWSE_HEAD:
  764. case BX_CMT_BROWSE_POPULAR:
  765. case BX_CMT_BROWSE_CONNECTION:
  766. $iPerView = $aBp['per_view'];
  767. $iStart = $aBp['start'] + $iPerView;
  768. if($iStart >= $aBp['count'])
  769. return $sCmts;
  770. break;
  771. case BX_CMT_BROWSE_TAIL:
  772. $iPerView = $aBp['per_view'];
  773. $iStart = $aBp['start'] - $iPerView;
  774. if($iStart < 0) {
  775. $iPerView += $iStart;
  776. $iStart = 0;
  777. }
  778. if($iStart == 0 && $iPerView == 0)
  779. return $sCmts;
  780. break;
  781. }
  782. $bRoot = (int)$aBp['vparent_id'] <= 0;
  783. $sMore = $this->_oTemplate->parseHtmlByName('comment_more.html', array(
  784. 'js_object' => $this->_sJsObjName,
  785. 'style_prefix' => $this->_sStylePrefix,
  786. 'bx_if:is_root' => array(
  787. 'condition' => $bRoot,
  788. 'content' => array()
  789. ),
  790. 'parent_id' => $aBp['vparent_id'],
  791. 'start' => $iStart,
  792. 'per_view' => $iPerView,
  793. 'title' => _t('_cmt_load_more_' . ($aBp['vparent_id'] == 0 ? 'comments' : 'replies') . '_' . $aBp['type'])
  794. ));
  795. switch($aBp['type']) {
  796. case BX_CMT_BROWSE_HEAD:
  797. case BX_CMT_BROWSE_POPULAR:
  798. case BX_CMT_BROWSE_CONNECTION:
  799. $sCmts .= $sMore;
  800. break;
  801. case BX_CMT_BROWSE_TAIL:
  802. $sCmts = $sMore . $sCmts;
  803. break;
  804. }
  805. return $sCmts;
  806. }
  807. protected function _getEmpty($aDp = array())
  808. {
  809. $sClass = '';
  810. if(!empty($aDp['class']))
  811. $sClass .= ' ' . $aDp['class'];
  812. return $this->_oTemplate->parseHtmlByName('comment_empty.html', array(
  813. 'style_prefix' => $this->_sStylePrefix,
  814. 'class' => $sClass,
  815. 'content' => MsgBox(_t('_Empty'))
  816. ));
  817. }
  818. protected function _getViewImagePopup()
  819. {
  820. $sViewImagePopupId = 'cmts-box-' . $this->_sSystem . '-' . $this->getId() . '-view-image-popup' ;
  821. $sViewImagePopupContent = $this->_oTemplate->parseHtmlByName('popup_image.html', array(
  822. 'image_url' => ''
  823. ));
  824. return BxTemplFunctions::getInstance()->transBox($sViewImagePopupId, $sViewImagePopupContent, true);
  825. }
  826. protected function _getAttachments($aCmt)
  827. {
  828. $aTmplImages = array();
  829. if(!$this->isAttachImageEnabled())
  830. return '';
  831. $aFiles = $this->_oQuery->getFiles($this->_aSystem['system_id'], $aCmt['cmt_id']);
  832. if(!empty($aFiles) && is_array($aFiles)) {
  833. $oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
  834. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->getTranscoderPreviewName());
  835. foreach($aFiles as $aFile) {
  836. $bImage = $oTranscoder && $oTranscoder->isMimeTypeSupported($aFile['mime_type']);
  837. $sPreview = '';
  838. if($oTranscoder && $bImage)
  839. $sPreview = $oTranscoder->getFileUrl($aFile['image_id']);
  840. if(!$sPreview)
  841. $sPreview = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($aFile['file_name']));
  842. $aTmplVarsFile = array(
  843. 'js_object' => $this->_sJsObjName,
  844. 'preview' => $sPreview,
  845. 'file' => $oStorage->getFileUrlById($aFile['image_id']),
  846. 'file_name' => $aFile['file_name'],
  847. 'file_icon' => $oStorage->getFontIconNameByFileName($aFile['file_name']),
  848. 'file_size' => _t_format_size($aFile['size']),
  849. );
  850. $aTmplImages[] = array(
  851. 'style_prefix' => $this->_sStylePrefix,
  852. 'bx_if:show_image' => array(
  853. 'condition' => $bImage,
  854. 'content' => $aTmplVarsFile
  855. ),
  856. 'bx_if:show_file' => array(
  857. 'condition' => !$bImage,
  858. 'content' => $aTmplVarsFile
  859. ),
  860. );
  861. }
  862. }
  863. return $this->_oTemplate->parseHtmlByName('comment_attachments.html', array(
  864. 'bx_repeat:attached' => $aTmplImages
  865. ));
  866. }
  867. protected function _getTmplVarsAuthor($aCmt)
  868. {
  869. list($sAuthorName, $sAuthorLink, $sAuthorIcon, $sAuthorUnit) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  870. $bAuthorIcon = !empty($sAuthorIcon);
  871. return array(
  872. 'author_unit' => $sAuthorUnit,
  873. 'bx_if:show_icon' => array(
  874. 'condition' => $bAuthorIcon,
  875. 'content' => array(
  876. 'author_icon' => $sAuthorIcon
  877. )
  878. ),
  879. 'bx_if:show_icon_empty' => array(
  880. 'condition' => !$bAuthorIcon,
  881. 'content' => array()
  882. ),
  883. 'bx_if:show_author_link' => array(
  884. 'condition' => !empty($sAuthorLink),
  885. 'content' => array(
  886. 'author_link' => $sAuthorLink,
  887. 'author_title' => bx_html_attribute($sAuthorName),
  888. 'author_name' => $sAuthorName
  889. )
  890. ),
  891. 'bx_if:show_author_text' => array(
  892. 'condition' => empty($sAuthorLink),
  893. 'content' => array(
  894. 'author_name' => $sAuthorName
  895. )
  896. ),
  897. );
  898. }
  899. protected function _getTmplVarsText($aCmt)
  900. {
  901. $sText = $aCmt['cmt_text'];
  902. $sTextMore = '';
  903. if(!$this->isHtml()) {
  904. $iMaxLength = (int)$this->_aSystem['chars_display_max'];
  905. if(strlen($sText) > $iMaxLength) {
  906. $iLength = strpos($sText, ' ', $iMaxLength);
  907. $sTextMore = trim(substr($sText, $iLength));
  908. $sText = trim(substr($sText, 0, $iLength));
  909. }
  910. }
  911. $sText = $this->_prepareTextForOutput($sText, $aCmt['cmt_id']);
  912. $sTextMore = $this->_prepareTextForOutput($sTextMore, $aCmt['cmt_id']);
  913. return array(
  914. 'text' => $sText,
  915. 'bx_if:show_more' => array(
  916. 'condition' => !empty($sTextMore),
  917. 'content' => array(
  918. 'style_prefix' => $this->_sStylePrefix,
  919. 'js_object' => $this->_sJsObjName,
  920. 'text_more' => $sTextMore
  921. )
  922. ),
  923. );
  924. }
  925. }
  926. /** @} */