BxBaseCmts.php 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  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() : '';
  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. $aTmplVarsFormMin = array();
  622. if($bFormMin) {
  623. list($sAuthorName, $sAuthorLink, $sAuthorIcon, $sAuthorUnit) = $this->_getAuthorInfo($this->_getAuthorId());
  624. $oForm = new BxTemplFormView(array());
  625. $aInputPlaceholder = array(
  626. 'type' => 'text',
  627. 'name' => 'comment',
  628. 'caption' => '',
  629. 'attrs' => array(
  630. 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtShowForm(this)',
  631. 'placeholder' => _t('_cmt_txt_min_form_placeholder', $sAuthorName)
  632. ),
  633. 'value' => '',
  634. );
  635. $aTmplVarsFormMin = array(
  636. 'js_object' => $this->_sJsObjName,
  637. 'style_prefix' => $this->_sStylePrefix,
  638. 'author_unit' => $sAuthorUnit,
  639. 'placeholder' => $oForm->genRow($aInputPlaceholder)
  640. );
  641. }
  642. $sMethod = '_getForm' . ucfirst($sType);
  643. $aForm = $this->$sMethod($iCmtParentId, $aDp);
  644. return $this->_oTemplate->parseHtmlByName('comment_reply_box.html', array(
  645. 'js_object' => $this->_sJsObjName,
  646. 'style_prefix' => $this->_sStylePrefix,
  647. 'class' => $sClass,
  648. 'bx_if:show_form_min' => array(
  649. 'condition' => $bFormMin,
  650. 'content' => $aTmplVarsFormMin
  651. ),
  652. 'form' => $aForm['form'],
  653. 'form_id' => $aForm['form_id'],
  654. ));
  655. }
  656. protected function _getFormPost($iCmtParentId = 0, $aDp = array())
  657. {
  658. $bDynamic = isset($aDp['dynamic_mode']) && (bool)$aDp['dynamic_mode'];
  659. $oForm = $this->_getForm(BX_CMT_ACTION_POST, $iCmtParentId);
  660. $oForm->aInputs['cmt_parent_id']['value'] = $iCmtParentId;
  661. $oForm->initChecker();
  662. if($oForm->isSubmittedAndValid()) {
  663. $iCmtAuthorId = $this->_getAuthorId();
  664. $iCmtParentId = $oForm->getCleanValue('cmt_parent_id');
  665. $sCmtText = $oForm->getCleanValue('cmt_text');
  666. $iLevel = 0;
  667. $iCmtVisualParentId = 0;
  668. if((int)$iCmtParentId > 0) {
  669. $aParent = $this->getCommentRow($iCmtParentId);
  670. $iLevel = (int)$aParent['cmt_level'] + 1;
  671. $iCmtVisualParentId = $iLevel > $this->getMaxLevel() ? $aParent['cmt_vparent_id'] : $iCmtParentId;
  672. }
  673. $iCmtId = (int)$oForm->insert(array('cmt_vparent_id' => $iCmtVisualParentId, 'cmt_object_id' => $this->_iId, 'cmt_author_id' => $iCmtAuthorId, 'cmt_level' => $iLevel, 'cmt_time' => time()));
  674. if($iCmtId != 0) {
  675. if($this->isAttachImageEnabled()) {
  676. $aImages = $oForm->getCleanValue('cmt_image');
  677. if(!empty($aImages) && is_array($aImages)) {
  678. $oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
  679. foreach($aImages as $iImageId)
  680. if($this->_oQuery->saveImages($this->_aSystem['system_id'], $iCmtId, $iImageId))
  681. $oStorage->afterUploadCleanup($iImageId, $iCmtAuthorId);
  682. }
  683. }
  684. if($iCmtParentId) {
  685. $this->_oQuery->updateRepliesCount($iCmtParentId, 1);
  686. if(!BxDolModuleQuery::getInstance()->isEnabledByName('bx_notifications'))
  687. $this->_sendNotificationEmail($iCmtId, $iCmtParentId);
  688. }
  689. $this->_triggerComment();
  690. $this->isPostReplyAllowed(true);
  691. if ($this->_sMetatagsObj) {
  692. $oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj);
  693. $oMetatags->metaAdd($this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId), $sCmtText);
  694. }
  695. $this->onPostAfter($iCmtId);
  696. return array('id' => $iCmtId, 'parent_id' => $iCmtParentId);
  697. }
  698. return array('msg' => _t('_cmt_err_cannot_perform_action'));
  699. }
  700. return array('form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id);
  701. }
  702. protected function _getFormEdit($iCmtId, $aDp = array())
  703. {
  704. $bDynamic = isset($aDp['dynamic_mode']) && (bool)$aDp['dynamic_mode'];
  705. $aCmt = $this->_oQuery->getCommentSimple ((int)$this->getId(), $iCmtId);
  706. if(!$aCmt)
  707. return array('msg' => _t('_No such comment'));
  708. $iCmtAuthorId = $this->_getAuthorId();
  709. if(!$this->isEditAllowed($aCmt))
  710. return array('msg' => $aCmt['cmt_author_id'] == $iCmtAuthorId ? strip_tags($this->msgErrEditAllowed()) : _t('_Access denied'));
  711. $oForm = $this->_getForm(BX_CMT_ACTION_EDIT, $aCmt['cmt_id']);
  712. $oForm->initChecker($aCmt);
  713. if($oForm->isSubmittedAndValid()) {
  714. $sCmtText = $oForm->getCleanValue('cmt_text');
  715. if($oForm->update($iCmtId) !== false) {
  716. $this->isEditAllowed($aCmt, true);
  717. if ($this->_sMetatagsObj) {
  718. $oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj);
  719. $oMetatags->metaAdd($this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId), $sCmtText);
  720. }
  721. $this->onEditAfter($iCmtId);
  722. return array('id' => $iCmtId, 'text' => $this->_prepareTextForOutput($sCmtText, $iCmtId));
  723. }
  724. return array('msg' => _t('_cmt_err_cannot_perform_action'));
  725. }
  726. return array('form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id);
  727. }
  728. protected function _getForm($sAction, $iId)
  729. {
  730. $oForm = $this->_getFormObject($sAction);
  731. $oForm->setId(sprintf($oForm->getAttributeMask('id'), $sAction, $this->_sSystem, $iId));
  732. $oForm->setName(sprintf($oForm->getAttributeMask('name'), $sAction, $this->_sSystem, $iId));
  733. $oForm->aParams['db']['table'] = $this->_aSystem['table'];
  734. $oForm->aInputs['sys']['value'] = $this->_sSystem;
  735. $oForm->aInputs['id']['value'] = $this->_iId;
  736. $oForm->aInputs['action']['value'] = 'Submit' . ucfirst($sAction) . 'Form';
  737. if(!$this->isAttachImageEnabled())
  738. unset($oForm->aInputs['cmt_image']);
  739. if(isset($oForm->aInputs['cmt_text'])) {
  740. $oForm->aInputs['cmt_text']['html'] = $this->_aSystem['html'];
  741. $oForm->aInputs['cmt_text']['db']['pass'] = $this->isHtml() ? 'XssHtml' : 'XssMultiline';
  742. $iCmtTextMin = (int)$this->_aSystem['chars_post_min'];
  743. $iCmtTextMax = (int)$this->_aSystem['chars_post_max'];
  744. $oForm->aInputs['cmt_text']['checker']['params'] = array($iCmtTextMin, $iCmtTextMax);
  745. $oForm->aInputs['cmt_text']['checker']['error'] = _t('_Please enter n1-n2 characters', $iCmtTextMin, $iCmtTextMax);
  746. }
  747. return $oForm;
  748. }
  749. protected function _getMoreLink($sCmts, $aBp = array(), $aDp = array())
  750. {
  751. $iStart = $iPerView = 0;
  752. switch($aBp['type']) {
  753. case BX_CMT_BROWSE_HEAD:
  754. case BX_CMT_BROWSE_POPULAR:
  755. case BX_CMT_BROWSE_CONNECTION:
  756. $iPerView = $aBp['per_view'];
  757. $iStart = $aBp['start'] + $iPerView;
  758. if($iStart >= $aBp['count'])
  759. return $sCmts;
  760. break;
  761. case BX_CMT_BROWSE_TAIL:
  762. $iPerView = $aBp['per_view'];
  763. $iStart = $aBp['start'] - $iPerView;
  764. if($iStart < 0) {
  765. $iPerView += $iStart;
  766. $iStart = 0;
  767. }
  768. if($iStart == 0 && $iPerView == 0)
  769. return $sCmts;
  770. break;
  771. }
  772. $bRoot = (int)$aBp['vparent_id'] <= 0;
  773. $sMore = $this->_oTemplate->parseHtmlByName('comment_more.html', array(
  774. 'js_object' => $this->_sJsObjName,
  775. 'style_prefix' => $this->_sStylePrefix,
  776. 'bx_if:is_root' => array(
  777. 'condition' => $bRoot,
  778. 'content' => array()
  779. ),
  780. 'parent_id' => $aBp['vparent_id'],
  781. 'start' => $iStart,
  782. 'per_view' => $iPerView,
  783. 'title' => _t('_cmt_load_more_' . ($aBp['vparent_id'] == 0 ? 'comments' : 'replies') . '_' . $aBp['type'])
  784. ));
  785. switch($aBp['type']) {
  786. case BX_CMT_BROWSE_HEAD:
  787. case BX_CMT_BROWSE_POPULAR:
  788. case BX_CMT_BROWSE_CONNECTION:
  789. $sCmts .= $sMore;
  790. break;
  791. case BX_CMT_BROWSE_TAIL:
  792. $sCmts = $sMore . $sCmts;
  793. break;
  794. }
  795. return $sCmts;
  796. }
  797. protected function _getEmpty()
  798. {
  799. return $this->_oTemplate->parseHtmlByName('comment_empty.html', array(
  800. 'style_prefix' => $this->_sStylePrefix,
  801. 'content' => MsgBox(_t('_Empty'))
  802. ));
  803. }
  804. protected function _getViewImagePopup()
  805. {
  806. $sViewImagePopupId = 'cmts-box-' . $this->_sSystem . '-' . $this->getId() . '-view-image-popup' ;
  807. $sViewImagePopupContent = $this->_oTemplate->parseHtmlByName('popup_image.html', array(
  808. 'image_url' => ''
  809. ));
  810. return BxTemplFunctions::getInstance()->transBox($sViewImagePopupId, $sViewImagePopupContent, true);
  811. }
  812. protected function _getAttachments($aCmt)
  813. {
  814. $aTmplImages = array();
  815. if(!$this->isAttachImageEnabled())
  816. return '';
  817. $aFiles = $this->_oQuery->getFiles($this->_aSystem['system_id'], $aCmt['cmt_id']);
  818. if(!empty($aFiles) && is_array($aFiles)) {
  819. $oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
  820. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->getTranscoderPreviewName());
  821. foreach($aFiles as $aFile) {
  822. $bImage = $oTranscoder && $oTranscoder->isMimeTypeSupported($aFile['mime_type']);
  823. $sPreview = '';
  824. if($oTranscoder && $bImage)
  825. $sPreview = $oTranscoder->getFileUrl($aFile['image_id']);
  826. if(!$sPreview)
  827. $sPreview = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($aFile['file_name']));
  828. $aTmplVarsFile = array(
  829. 'js_object' => $this->_sJsObjName,
  830. 'preview' => $sPreview,
  831. 'file' => $oStorage->getFileUrlById($aFile['image_id']),
  832. 'file_name' => $aFile['file_name'],
  833. 'file_icon' => $oStorage->getFontIconNameByFileName($aFile['file_name']),
  834. 'file_size' => _t_format_size($aFile['size']),
  835. );
  836. $aTmplImages[] = array(
  837. 'style_prefix' => $this->_sStylePrefix,
  838. 'bx_if:show_image' => array(
  839. 'condition' => $bImage,
  840. 'content' => $aTmplVarsFile
  841. ),
  842. 'bx_if:show_file' => array(
  843. 'condition' => !$bImage,
  844. 'content' => $aTmplVarsFile
  845. ),
  846. );
  847. }
  848. }
  849. return $this->_oTemplate->parseHtmlByName('comment_attachments.html', array(
  850. 'bx_repeat:attached' => $aTmplImages
  851. ));
  852. }
  853. protected function _getTmplVarsAuthor($aCmt)
  854. {
  855. list($sAuthorName, $sAuthorLink, $sAuthorIcon, $sAuthorUnit) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  856. $bAuthorIcon = !empty($sAuthorIcon);
  857. return array(
  858. 'author_unit' => $sAuthorUnit,
  859. 'bx_if:show_icon' => array(
  860. 'condition' => $bAuthorIcon,
  861. 'content' => array(
  862. 'author_icon' => $sAuthorIcon
  863. )
  864. ),
  865. 'bx_if:show_icon_empty' => array(
  866. 'condition' => !$bAuthorIcon,
  867. 'content' => array()
  868. ),
  869. 'bx_if:show_author_link' => array(
  870. 'condition' => !empty($sAuthorLink),
  871. 'content' => array(
  872. 'author_link' => $sAuthorLink,
  873. 'author_title' => bx_html_attribute($sAuthorName),
  874. 'author_name' => $sAuthorName
  875. )
  876. ),
  877. 'bx_if:show_author_text' => array(
  878. 'condition' => empty($sAuthorLink),
  879. 'content' => array(
  880. 'author_name' => $sAuthorName
  881. )
  882. ),
  883. );
  884. }
  885. protected function _getTmplVarsText($aCmt)
  886. {
  887. $sText = $aCmt['cmt_text'];
  888. $sTextMore = '';
  889. if(!$this->isHtml()) {
  890. $iMaxLength = (int)$this->_aSystem['chars_display_max'];
  891. if(strlen($sText) > $iMaxLength) {
  892. $iLength = strpos($sText, ' ', $iMaxLength);
  893. $sTextMore = trim(substr($sText, $iLength));
  894. $sText = trim(substr($sText, 0, $iLength));
  895. }
  896. }
  897. $sText = $this->_prepareTextForOutput($sText, $aCmt['cmt_id']);
  898. $sTextMore = $this->_prepareTextForOutput($sTextMore, $aCmt['cmt_id']);
  899. return array(
  900. 'text' => $sText,
  901. 'bx_if:show_more' => array(
  902. 'condition' => !empty($sTextMore),
  903. 'content' => array(
  904. 'style_prefix' => $this->_sStylePrefix,
  905. 'js_object' => $this->_sJsObjName,
  906. 'text_more' => $sTextMore
  907. )
  908. ),
  909. );
  910. }
  911. }
  912. /** @} */