BxBaseCmts.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  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. $sReactions = '';
  230. if(($oReaction = $this->getReactionObject($aCmt['cmt_unique_id'])) !== false)
  231. $sReactions = $oReaction->getCounter(array(
  232. 'show_counter' => true
  233. ));
  234. return $this->_oTemplate->parseHtmlByName('comment.html', array_merge(array(
  235. 'system' => $this->_sSystem,
  236. 'style_prefix' => $this->_sStylePrefix,
  237. 'js_object' => $this->_sJsObjName,
  238. 'id' => $aCmt['cmt_id'],
  239. 'anchor' => $this->getItemAnchor($aCmt['cmt_id']),
  240. 'class' => $sClass,
  241. 'class_cnt' => $sClassCnt,
  242. 'bx_if:show_reply_to' => array(
  243. 'condition' => !empty($aTmplReplyTo),
  244. 'content' => $aTmplReplyTo
  245. ),
  246. 'bx_if:meta' => array(
  247. 'condition' => !empty($aTmplVarsMeta),
  248. 'content' => $aTmplVarsMeta
  249. ),
  250. 'bx_if:show_attached' => array(
  251. 'condition' => !empty($sAttachments),
  252. 'content' => array(
  253. 'style_prefix' => $this->_sStylePrefix,
  254. 'attached' => $sAttachments
  255. )
  256. ),
  257. 'reactions' => $sReactions,
  258. 'actions' => $sActions,
  259. 'replies' => $sReplies,
  260. ), $this->_getTmplVarsAuthor($aCmt), $this->_getTmplVarsText($aCmt)));
  261. }
  262. function getCommentSearch($iCmtId, &$sAddon)
  263. {
  264. $aBp = array();
  265. $aDp = array(
  266. 'type' => BX_CMT_DISPLAY_FLAT,
  267. 'view_only' => true
  268. );
  269. if(empty($sAddon))
  270. $sAddon = $this->getJsScript($aBp, $aDp);
  271. return $this->_oTemplate->parseHtmlByName('comment_search.html', array(
  272. 'comment' => $this->getComment($iCmtId, $aBp, $aDp),
  273. 'view_image_popup' => $this->_getViewImagePopup(),
  274. ));
  275. }
  276. /**
  277. * get one comment for "Live Search"
  278. *
  279. * @param int $iCmtId - comment id
  280. * @return string
  281. */
  282. function getCommentLiveSearch($mixedCmt, $aParams = array())
  283. {
  284. $aCmt = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
  285. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  286. $bAuthorIcon = !empty($sAuthorIcon);
  287. $sViewLink = $this->getViewUrl($aCmt['cmt_id']);
  288. if(empty($sViewLink))
  289. $sViewLink = '#';
  290. return $this->_oTemplate->parseHtmlByName('comment_live_search.html', array(
  291. 'bx_if:show_icon' => array(
  292. 'condition' => $bAuthorIcon,
  293. 'content' => array(
  294. 'author_icon' => $sAuthorIcon,
  295. 'view_link' => $sViewLink
  296. )
  297. ),
  298. 'bx_if:show_icon_empty' => array(
  299. 'condition' => !$bAuthorIcon,
  300. 'content' => array()
  301. ),
  302. 'view_link' => $sViewLink,
  303. 'text' => BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($aCmt['cmt_text']), $this->_sSnippetLenthLiveSearch),
  304. 'sample' => isset($aParams['txt_sample_single']) ? _t($aParams['txt_sample_single']) : ''
  305. ));
  306. }
  307. function getFormBoxPost($aBp = array(), $aDp = array())
  308. {
  309. if(!$this->isPostReplyAllowed())
  310. return '';
  311. return $this->_getFormBox(BX_CMT_ACTION_POST, $aBp, $aDp);
  312. }
  313. function getFormBoxEdit($aBp = array(), $aDp = array())
  314. {
  315. return $this->_getFormBox(BX_CMT_ACTION_EDIT, $aBp, $aDp);
  316. }
  317. function getFormPost($iCmtParentId = 0, $aDp = array())
  318. {
  319. return $this->_getFormPost($iCmtParentId, $aDp);
  320. }
  321. function getFormEdit($iCmtId, $aDp = array())
  322. {
  323. return $this->_getFormEdit($iCmtId, $aDp);
  324. }
  325. function getLiveUpdate($iCountOld = 0, $iCountNew = 0)
  326. {
  327. $iCount = (int)$iCountNew - (int)$iCountOld;
  328. if($iCount < 0)
  329. return '';
  330. $aComments = $this->_oQuery->getCommentsBy(array('type' => 'latest', 'object_id' => $this->_iId, 'author' => $this->_getAuthorId(), 'others' => 1, 'start' => '0', 'per_page' => $iCount));
  331. if(empty($aComments) || !is_array($aComments))
  332. return '';
  333. $aComment = array_shift($aComments);
  334. if(empty($aComment) || !is_array($aComment))
  335. return '';
  336. $sJsObject = $this->getJsObjectName();
  337. return $this->_oTemplate->parseHtmlByName('comments_lu_button.html', array(
  338. 'style_prefix' => $this->_sStylePrefix,
  339. 'html_id' => $this->getNotificationId(),
  340. 'onclick_show' => "javascript:" . $sJsObject . ".goToBtn(this, '" . $this->getItemAnchor($aComment['cmt_id']) . "', '" . $aComment['cmt_id'] . "');",
  341. ));
  342. }
  343. function getLiveUpdates($iCountOld = 0, $iCountNew = 0)
  344. {
  345. $bShowAll = true;
  346. $bShowActions = false;
  347. $iCount = (int)$iCountNew - (int)$iCountOld;
  348. if($iCount < 0)
  349. return '';
  350. $aComments = $this->_oQuery->getCommentsBy(array('type' => 'latest', 'object_id' => $this->_iId, 'author' => $this->_getAuthorId(), 'others' => 1, 'start' => '0', 'per_page' => $iCount));
  351. if(empty($aComments) || !is_array($aComments))
  352. return '';
  353. $sJsObject = $this->getJsObjectName();
  354. $iUserId = $this->_getAuthorId();
  355. $bModerator = $this->isModerator();
  356. $aComments = array_reverse($aComments);
  357. $iComments = count($aComments);
  358. $aTmplVarsNotifs = array();
  359. foreach($aComments as $iIndex => $aComment) {
  360. $iCommentId = $aComment['cmt_id'];
  361. $sShowOnClick = "javascript:" . $sJsObject . ".goTo(this, '" . $this->getItemAnchor($iCommentId) . "', '" . $iCommentId . "');";
  362. $sReplyOnClick = "javascript:" . $sJsObject . ".goToAndReply(this, '" . $this->getItemAnchor($iCommentId) . "', '" . $iCommentId . "');";
  363. $iAuthorId = (int)$aComment['cmt_author_id'];
  364. if($iAuthorId < 0) {
  365. if(abs($iAuthorId) == $iUserId)
  366. continue;
  367. else if($bModerator)
  368. $iAuthorId *= -1;
  369. }
  370. $oAuthor = $this->_getAuthorObject($iAuthorId);
  371. $sAuthorName = $oAuthor->getDisplayName();
  372. $aTmplVarsNotifs[] = array(
  373. 'bx_if:show_as_hidden' => array(
  374. 'condition' => !$bShowAll && $iIndex < ($iComments - 1),
  375. 'content' => array(),
  376. ),
  377. 'item' => $this->_oTemplate->parseHtmlByName('comments_lu_notifications.html', array(
  378. 'style_prefix' => $this->_sStylePrefix,
  379. 'onclick_show' => $sShowOnClick,
  380. 'onclick_reply' => $sReplyOnClick,
  381. 'author_link' => $oAuthor->getUrl(),
  382. 'author_title' => bx_html_attribute($sAuthorName),
  383. 'author_name' => $sAuthorName,
  384. 'author_unit' => $oAuthor->getUnit(0, array('template' => 'unit_wo_info_links')),
  385. 'text' => _t('_cmt_txt_added_sample')
  386. )),
  387. 'bx_if:show_previous' => array(
  388. 'condition' => $bShowActions && $iIndex > 0,
  389. 'content' => array(
  390. 'onclick_previous' => $sJsObject . '.previousLiveUpdate(this)'
  391. )
  392. ),
  393. 'bx_if:show_close' => array(
  394. 'condition' => $bShowActions,
  395. 'content' => array(
  396. 'onclick_close' => $sJsObject . '.hideLiveUpdate(this)'
  397. )
  398. )
  399. );
  400. }
  401. return $this->_oTemplate->parseHtmlByName('popup_chain.html', array(
  402. 'html_id' => $this->getNotificationId(),
  403. 'bx_repeat:items' => $aTmplVarsNotifs
  404. ));
  405. }
  406. public function getElementBlock($aParams = array())
  407. {
  408. $aParams['usage'] = BX_CMT_USAGE_BLOCK;
  409. return $this->getElement($aParams);
  410. }
  411. public function getElementInline($aParams = array())
  412. {
  413. $aParams['usage'] = BX_CMT_USAGE_INLINE;
  414. return $this->getElement($aParams);
  415. }
  416. public function getElement($aParams = array())
  417. {
  418. $aParams = array_merge($this->_aElementDefaults, $aParams);
  419. $bShowDoCommentAsButtonSmall = isset($aParams['show_do_comment_as_button_small']) && $aParams['show_do_comment_as_button_small'] == true;
  420. $bShowDoCommentAsButton = !$bShowDoCommentAsButtonSmall && isset($aParams['show_do_comment_as_button']) && $aParams['show_do_comment_as_button'] == true;
  421. $bShowCounterEmpty = isset($aParams['show_counter_empty']) && $aParams['show_counter_empty'] == true;
  422. $iObjectId = $this->getId();
  423. $iAuthorId = $this->_getAuthorId();
  424. $iAuthorIp = $this->_getAuthorIp();
  425. $iCount = $this->getCommentsCountAll();
  426. $bCount = (int)$iCount != 0;
  427. $isAllowedComment = $this->isPostReplyAllowed();
  428. //--- Do Comment
  429. $bTmplVarsDoComment = $this->_isShowDoComment($aParams, $isAllowedComment, $bCount);
  430. $aTmplVarsDoComment = array();
  431. if($bTmplVarsDoComment) {
  432. $sClass = '';
  433. if($bShowDoCommentAsButton)
  434. $sClass = 'bx-btn';
  435. else if ($bShowDoCommentAsButtonSmall)
  436. $sClass = 'bx-btn bx-btn-small';
  437. if(!$isAllowedComment)
  438. $sClass .= $bShowDoCommentAsButton || $bShowDoCommentAsButtonSmall ? ' bx-btn-disabled' : 'bx-cmts-disabled';
  439. $aTmplVarsDoComment = array(
  440. 'style_prefix' => $this->_sStylePrefix,
  441. 'do_comment' => $this->_oTemplate->parseLink($this->getListUrl(), $this->_getLabelDo($aParams), array(
  442. 'class' => $this->_sStylePrefix . '-do-comment ' . $this->_sStylePrefix . '-dc ' . $sClass,
  443. 'title' => _t($this->_getTitleDo())
  444. )),
  445. );
  446. }
  447. //--- Counter
  448. $bTmplVarsCounter = $this->_isShowCounter($aParams, $isAllowedComment, $bCount);
  449. $aTmplVarsCounter = array();
  450. if($bTmplVarsCounter)
  451. $aTmplVarsCounter = array(
  452. 'style_prefix' => $this->_sStylePrefix,
  453. 'bx_if:show_hidden' => array(
  454. 'condition' => !$bShowCounterEmpty && !$bCount,
  455. 'content' => array()
  456. ),
  457. 'counter' => $this->getCounter($aParams)
  458. );
  459. if(!$bTmplVarsDoComment && !$bTmplVarsCounter)
  460. return '';
  461. $sTmplName = $this->{'_getTmplElement' . bx_gen_method_name(!empty($aParams['usage']) ? $aParams['usage'] : BX_DOL_SCORE_USAGE_DEFAULT)}();
  462. return $this->_oTemplate->parseHtmlByContent($sTmplName, array(
  463. 'style_prefix' => $this->_sStylePrefix,
  464. 'html_id' => $this->_aHtmlIds['main'],
  465. 'class' => $this->_sStylePrefix . ($bShowDoCommentAsButton ? '-button' : '') . ($bShowDoCommentAsButtonSmall ? '-button-small' : ''),
  466. 'count' => $iCount,
  467. 'bx_if:show_do_comment' => array(
  468. 'condition' => $bTmplVarsDoComment,
  469. 'content' => $aTmplVarsDoComment
  470. ),
  471. 'bx_if:show_counter' => array(
  472. 'condition' => $bTmplVarsCounter,
  473. 'content' => $aTmplVarsCounter
  474. ),
  475. 'script' => ''
  476. ));
  477. }
  478. public function getCounter($aParams = array())
  479. {
  480. $bShowEmpty = isset($aParams['show_counter_empty']) && $aParams['show_counter_empty'] == true;
  481. $bShowDoCommentAsButtonSmall = isset($aParams['show_do_comment_as_button_small']) && $aParams['show_do_comment_as_button_small'] == true;
  482. $bShowDoCommentAsButton = !$bShowDoCommentAsButtonSmall && isset($aParams['show_do_comment_as_button']) && $aParams['show_do_comment_as_button'] == true;
  483. $iCount = (int)$this->getCommentsCountAll();
  484. $sClass = $this->_sStylePrefix . '-counter';
  485. if($bShowDoCommentAsButtonSmall)
  486. $sClass .= ' bx-btn-small-height';
  487. if($bShowDoCommentAsButton)
  488. $sClass .= ' bx-btn-height';
  489. return $this->_oTemplate->parseHtmlByContent($this->_getTmplCounter(), array(
  490. 'id' => $this->_aHtmlIds['counter'],
  491. 'class' => $sClass,
  492. 'content' => $iCount != 0 || $bShowEmpty ? $this->_getLabelCounter($iCount) : ''
  493. ));
  494. }
  495. protected function _getLabelDo($aParams = array())
  496. {
  497. return $this->_oTemplate->parseHtmlByContent($this->_getTmplLabelDo(), array(
  498. 'bx_if:show_image' => array(
  499. 'condition' => isset($aParams['show_do_comment_image']) && $aParams['show_do_comment_image'] == true,
  500. 'content' => array(
  501. 'src' => $this->_getImageDo()
  502. )
  503. ),
  504. 'bx_if:show_icon' => array(
  505. 'condition' => isset($aParams['show_do_comment_icon']) && $aParams['show_do_comment_icon'] == true,
  506. 'content' => array(
  507. 'name' => $this->_getIconDo()
  508. )
  509. ),
  510. 'bx_if:show_text' => array(
  511. 'condition' => isset($aParams['show_do_comment_label']) && $aParams['show_do_comment_label'] == true,
  512. 'content' => array(
  513. 'text' => _t($this->_getTitleDo())
  514. )
  515. )
  516. ));
  517. }
  518. protected function _getLabelCounter($iCount)
  519. {
  520. return (int)$iCount != 0 ? _t('_cmt_txt_counter', $iCount) : _t('_cmt_txt_counter_empty');
  521. }
  522. protected function _getTmplElementBlock()
  523. {
  524. return self::$_sTmplContentElementBlock;
  525. }
  526. protected function _getTmplElementInline()
  527. {
  528. return self::$_sTmplContentElementInline;
  529. }
  530. protected function _getTmplLabelDo()
  531. {
  532. return self::$_sTmplContentDoCommentLabel;
  533. }
  534. protected function _getTmplCounter()
  535. {
  536. return self::$_sTmplContentCounter;
  537. }
  538. /**
  539. * private functions
  540. */
  541. protected function _getControlsBox()
  542. {
  543. $sDisplay = '';
  544. $bDisplay = (int)$this->_aSystem['is_display_switch'] == 1;
  545. if($bDisplay) {
  546. $aDisplayLinks = array(
  547. array('id' => $this->_sSystem . '-flat', 'name' => $this->_sSystem . '-flat', 'class' => '', 'title' => '_cmt_display_flat', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeDisplay(this, \'flat\');'),
  548. array('id' => $this->_sSystem . '-threaded', 'name' => $this->_sSystem . '-threaded', 'class' => '', 'title' => '_cmt_display_threaded', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeDisplay(this, \'threaded\');')
  549. );
  550. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-display', 'menu_items' => $aDisplayLinks));
  551. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sDisplayType);
  552. $sDisplay = $oMenu->getCode();
  553. }
  554. $sBrowseType = '';
  555. $bBrowseType = (int)$this->_aSystem['is_browse_switch'] == 1;
  556. if($bBrowseType) {
  557. $aBrowseLinks = array(
  558. array('id' => $this->_sSystem . '-tail', 'name' => $this->_sSystem . '-tail', 'class' => '', 'title' => '_cmt_browse_tail', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'tail\');'),
  559. array('id' => $this->_sSystem . '-head', 'name' => $this->_sSystem . '-head', 'class' => '', 'title' => '_cmt_browse_head', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'head\');'),
  560. array('id' => $this->_sSystem . '-popular', 'name' => $this->_sSystem . '-popular', 'class' => '', 'title' => '_cmt_browse_popular', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'popular\');'),
  561. );
  562. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-browse', 'menu_items' => $aBrowseLinks));
  563. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sBrowseType);
  564. $sBrowseType = $oMenu->getCode();
  565. }
  566. $sBrowseFilter = '';
  567. $bBrowseFilter = (int)$this->_aSystem['is_browse_filter'] == 1;
  568. if($bBrowseFilter) {
  569. $aFilterLinks = array(
  570. array('id' => $this->_sSystem . '-all', 'name' => $this->_sSystem . '-all', 'class' => '', 'title' => '_cmt_browse_all', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'all\');'),
  571. array('id' => $this->_sSystem . '-friends', 'name' => $this->_sSystem . '-friends', 'class' => '', 'title' => '_cmt_browse_friends', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'friends\');'),
  572. array('id' => $this->_sSystem . '-subscriptions', 'name' => $this->_sSystem . '-subscriptions', 'class' => '', 'title' => '_cmt_browse_subscriptions', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'subscriptions\');')
  573. );
  574. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-filter', 'menu_items' => $aFilterLinks));
  575. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sBrowseFilter);
  576. $sBrowseFilter = $oMenu->getCode();
  577. }
  578. return $this->_oTemplate->parseHtmlByName('comments_controls.html', array(
  579. 'display_switcher' => $bDisplay ? $sDisplay : '',
  580. 'bx_if:is_divider_1' => array(
  581. 'condition' => $bDisplay && $bBrowseType,
  582. 'content' => array(
  583. 'style_prefix' => $this->_sStylePrefix,
  584. )
  585. ),
  586. 'browse_switcher' => $bBrowseType ? $sBrowseType : '',
  587. 'bx_if:is_divider_2' => array(
  588. 'condition' => $bBrowseType && $bBrowseFilter,
  589. 'content' => array(
  590. 'style_prefix' => $this->_sStylePrefix,
  591. )
  592. ),
  593. 'filter_switcher' => $bBrowseFilter ? $sBrowseFilter : '',
  594. ));
  595. }
  596. protected function _getActionsBox(&$aCmt, $aDp = array())
  597. {
  598. $bViewOnly = isset($aDp['view_only']) && $aDp['view_only'] === true;
  599. $bDynamicMode = isset($aDp['dynamic_mode']) && $aDp['dynamic_mode'] === true;
  600. $sMenuActions = '';
  601. if(!$bViewOnly) {
  602. $oMenuActions = BxDolMenu::getObjectInstance($this->_sMenuObjActions);
  603. $oMenuActions->setCmtsData($this, $aCmt['cmt_id']);
  604. $oMenuActions->setDynamicMode($bDynamicMode);
  605. $sMenuActions = $oMenuActions->getCode();
  606. }
  607. return $this->_oTemplate->parseHtmlByName('comment_actions.html', array(
  608. 'id' => $aCmt['cmt_id'],
  609. 'js_object' => $this->_sJsObjName,
  610. 'style_prefix' => $this->_sStylePrefix,
  611. 'menu_actions' => $sMenuActions,
  612. ));
  613. }
  614. protected function _getFormBox($sType, $aBp, $aDp)
  615. {
  616. $iCmtParentId = isset($aBp['parent_id']) ? (int)$aBp['parent_id'] : 0;
  617. $sPosition = isset($aDp['position']) ? $aDp['position'] : '';
  618. $bFormMin = $iCmtParentId == 0 && isset($aDp['min_post_form']) ? $aDp['min_post_form'] : false;
  619. $sPositionSystem = $this->_aSystem['post_form_position'];
  620. if(!empty($sPosition) && $sPositionSystem != $sPosition)
  621. return '';
  622. $sClass = '';
  623. if(!empty($sPosition))
  624. $sClass .= ' ' . $this->_sStylePrefix . '-reply-' . $sPosition;
  625. if($bFormMin)
  626. $sClass .= ' ' . $this->_sStylePrefix . '-reply-min';
  627. if(!empty($aDp['class']))
  628. $sClass .= ' ' . $aDp['class'];
  629. $sClassBody = '';
  630. if(!empty($aDp['class_body']))
  631. $sClassBody .= ' ' . $aDp['class_body'];
  632. $aTmplVarsFormMin = array();
  633. if($bFormMin) {
  634. list($sAuthorName, $sAuthorLink, $sAuthorIcon, $sAuthorUnit) = $this->_getAuthorInfo($this->_getAuthorId());
  635. $oForm = new BxTemplFormView(array());
  636. $aInputPlaceholder = array(
  637. 'type' => 'text',
  638. 'name' => 'comment',
  639. 'caption' => '',
  640. 'attrs' => array(
  641. 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtShowForm(this)',
  642. 'placeholder' => _t('_cmt_txt_min_form_placeholder', $sAuthorName)
  643. ),
  644. 'value' => '',
  645. );
  646. $sClassBodyMin = '';
  647. if(!empty($aDp['class_body_min']))
  648. $sClassBodyMin .= ' ' . $aDp['class_body_min'];
  649. $aTmplVarsFormMin = array(
  650. 'js_object' => $this->_sJsObjName,
  651. 'class_body_min' => $sClassBodyMin,
  652. 'style_prefix' => $this->_sStylePrefix,
  653. 'author_unit' => $sAuthorUnit,
  654. 'placeholder' => $oForm->genRow($aInputPlaceholder)
  655. );
  656. }
  657. $sMethod = '_getForm' . ucfirst($sType);
  658. $aForm = $this->$sMethod($iCmtParentId, $aDp);
  659. return $this->_oTemplate->parseHtmlByName('comment_reply_box.html', array(
  660. 'js_object' => $this->_sJsObjName,
  661. 'style_prefix' => $this->_sStylePrefix,
  662. 'class' => $sClass,
  663. 'class_body' => $sClassBody,
  664. 'bx_if:show_form_min' => array(
  665. 'condition' => $bFormMin,
  666. 'content' => $aTmplVarsFormMin
  667. ),
  668. 'form' => $aForm['form'],
  669. 'form_id' => $aForm['form_id'],
  670. ));
  671. }
  672. protected function _getFormPost($iCmtParentId = 0, $aDp = array())
  673. {
  674. $bDynamic = isset($aDp['dynamic_mode']) && (bool)$aDp['dynamic_mode'];
  675. $oForm = $this->_getForm(BX_CMT_ACTION_POST, $iCmtParentId);
  676. $oForm->aInputs['cmt_parent_id']['value'] = $iCmtParentId;
  677. $oForm->initChecker();
  678. if($oForm->isSubmittedAndValid()) {
  679. $iCmtAuthorId = $this->_getAuthorId();
  680. $iCmtParentId = $oForm->getCleanValue('cmt_parent_id');
  681. $sCmtText = $oForm->getCleanValue('cmt_text');
  682. $iLevel = 0;
  683. $iCmtVisualParentId = 0;
  684. if((int)$iCmtParentId > 0) {
  685. $aParent = $this->getCommentRow($iCmtParentId);
  686. $iLevel = (int)$aParent['cmt_level'] + 1;
  687. $iCmtVisualParentId = $iLevel > $this->getMaxLevel() ? $aParent['cmt_vparent_id'] : $iCmtParentId;
  688. }
  689. $iCmtId = (int)$oForm->insert(array('cmt_vparent_id' => $iCmtVisualParentId, 'cmt_object_id' => $this->_iId, 'cmt_author_id' => $iCmtAuthorId, 'cmt_level' => $iLevel, 'cmt_time' => time()));
  690. if($iCmtId != 0) {
  691. if($this->isAttachImageEnabled()) {
  692. $aImages = $oForm->getCleanValue('cmt_image');
  693. if(!empty($aImages) && is_array($aImages)) {
  694. $oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
  695. foreach($aImages as $iImageId)
  696. if($this->_oQuery->saveImages($this->_aSystem['system_id'], $iCmtId, $iImageId))
  697. $oStorage->afterUploadCleanup($iImageId, $iCmtAuthorId);
  698. }
  699. }
  700. if($iCmtParentId) {
  701. $this->_oQuery->updateRepliesCount($iCmtParentId, 1);
  702. if(!BxDolModuleQuery::getInstance()->isEnabledByName('bx_notifications'))
  703. $this->_sendNotificationEmail($iCmtId, $iCmtParentId);
  704. }
  705. $this->_triggerComment();
  706. $this->isPostReplyAllowed(true);
  707. if ($this->_sMetatagsObj) {
  708. $oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj);
  709. $oMetatags->metaAdd($this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId), $sCmtText);
  710. }
  711. $this->onPostAfter($iCmtId);
  712. return array('id' => $iCmtId, 'parent_id' => $iCmtParentId);
  713. }
  714. return array('msg' => _t('_cmt_err_cannot_perform_action'));
  715. }
  716. return array('form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id);
  717. }
  718. protected function _getFormEdit($iCmtId, $aDp = array())
  719. {
  720. $bDynamic = isset($aDp['dynamic_mode']) && (bool)$aDp['dynamic_mode'];
  721. $aCmt = $this->_oQuery->getCommentSimple ((int)$this->getId(), $iCmtId);
  722. if(!$aCmt)
  723. return array('msg' => _t('_No such comment'));
  724. $iCmtAuthorId = $this->_getAuthorId();
  725. if(!$this->isEditAllowed($aCmt))
  726. return array('msg' => $aCmt['cmt_author_id'] == $iCmtAuthorId ? strip_tags($this->msgErrEditAllowed()) : _t('_Access denied'));
  727. $oForm = $this->_getForm(BX_CMT_ACTION_EDIT, $aCmt['cmt_id']);
  728. $oForm->initChecker($aCmt);
  729. if($oForm->isSubmittedAndValid()) {
  730. $sCmtText = $oForm->getCleanValue('cmt_text');
  731. if($oForm->update($iCmtId) !== false) {
  732. $this->isEditAllowed($aCmt, true);
  733. if ($this->_sMetatagsObj) {
  734. $oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj);
  735. $oMetatags->metaAdd($this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId), $sCmtText);
  736. }
  737. $this->onEditAfter($iCmtId);
  738. return array('id' => $iCmtId, 'text' => $this->_prepareTextForOutput($sCmtText, $iCmtId));
  739. }
  740. return array('msg' => _t('_cmt_err_cannot_perform_action'));
  741. }
  742. return array('form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id);
  743. }
  744. protected function _getForm($sAction, $iId)
  745. {
  746. $oForm = $this->_getFormObject($sAction);
  747. $oForm->setId(sprintf($oForm->getAttributeMask('id'), $sAction, $this->_sSystem, $iId));
  748. $oForm->setName(sprintf($oForm->getAttributeMask('name'), $sAction, $this->_sSystem, $iId));
  749. $oForm->aParams['db']['table'] = $this->_aSystem['table'];
  750. $oForm->aInputs['sys']['value'] = $this->_sSystem;
  751. $oForm->aInputs['id']['value'] = $this->_iId;
  752. $oForm->aInputs['action']['value'] = 'Submit' . ucfirst($sAction) . 'Form';
  753. if(!$this->isAttachImageEnabled())
  754. unset($oForm->aInputs['cmt_image']);
  755. if(isset($oForm->aInputs['cmt_text'])) {
  756. $oForm->aInputs['cmt_text']['html'] = $this->_aSystem['html'];
  757. $oForm->aInputs['cmt_text']['db']['pass'] = $this->isHtml() ? 'XssHtml' : 'XssMultiline';
  758. $iCmtTextMin = (int)$this->_aSystem['chars_post_min'];
  759. $iCmtTextMax = (int)$this->_aSystem['chars_post_max'];
  760. $oForm->aInputs['cmt_text']['checker']['params'] = array($iCmtTextMin, $iCmtTextMax);
  761. $oForm->aInputs['cmt_text']['checker']['error'] = _t('_Please enter n1-n2 characters', $iCmtTextMin, $iCmtTextMax);
  762. }
  763. return $oForm;
  764. }
  765. protected function _getMoreLink($sCmts, $aBp = array(), $aDp = array())
  766. {
  767. $iStart = $iPerView = 0;
  768. switch($aBp['type']) {
  769. case BX_CMT_BROWSE_HEAD:
  770. case BX_CMT_BROWSE_POPULAR:
  771. case BX_CMT_BROWSE_CONNECTION:
  772. $iPerView = $aBp['per_view'];
  773. $iStart = $aBp['start'] + $iPerView;
  774. if($iStart >= $aBp['count'])
  775. return $sCmts;
  776. break;
  777. case BX_CMT_BROWSE_TAIL:
  778. $iPerView = $aBp['per_view'];
  779. $iStart = $aBp['start'] - $iPerView;
  780. if($iStart < 0) {
  781. $iPerView += $iStart;
  782. $iStart = 0;
  783. }
  784. if($iStart == 0 && $iPerView == 0)
  785. return $sCmts;
  786. break;
  787. }
  788. $bRoot = (int)$aBp['vparent_id'] <= 0;
  789. $sMore = $this->_oTemplate->parseHtmlByName('comment_more.html', array(
  790. 'js_object' => $this->_sJsObjName,
  791. 'style_prefix' => $this->_sStylePrefix,
  792. 'bx_if:is_root' => array(
  793. 'condition' => $bRoot,
  794. 'content' => array()
  795. ),
  796. 'parent_id' => $aBp['vparent_id'],
  797. 'start' => $iStart,
  798. 'per_view' => $iPerView,
  799. 'title' => _t('_cmt_load_more_' . ($aBp['vparent_id'] == 0 ? 'comments' : 'replies') . '_' . $aBp['type'])
  800. ));
  801. switch($aBp['type']) {
  802. case BX_CMT_BROWSE_HEAD:
  803. case BX_CMT_BROWSE_POPULAR:
  804. case BX_CMT_BROWSE_CONNECTION:
  805. $sCmts .= $sMore;
  806. break;
  807. case BX_CMT_BROWSE_TAIL:
  808. $sCmts = $sMore . $sCmts;
  809. break;
  810. }
  811. return $sCmts;
  812. }
  813. protected function _getEmpty($aDp = array())
  814. {
  815. $sClass = '';
  816. if(!empty($aDp['class']))
  817. $sClass .= ' ' . $aDp['class'];
  818. return $this->_oTemplate->parseHtmlByName('comment_empty.html', array(
  819. 'style_prefix' => $this->_sStylePrefix,
  820. 'class' => $sClass,
  821. 'content' => MsgBox(_t('_Empty'))
  822. ));
  823. }
  824. protected function _getViewImagePopup()
  825. {
  826. $sViewImagePopupId = 'cmts-box-' . $this->_sSystem . '-' . $this->getId() . '-view-image-popup' ;
  827. $sViewImagePopupContent = $this->_oTemplate->parseHtmlByName('popup_image.html', array(
  828. 'image_url' => ''
  829. ));
  830. return BxTemplFunctions::getInstance()->transBox($sViewImagePopupId, $sViewImagePopupContent, true);
  831. }
  832. protected function _getAttachments($aCmt)
  833. {
  834. $aTmplImages = array();
  835. if(!$this->isAttachImageEnabled())
  836. return '';
  837. $aFiles = $this->_oQuery->getFiles($this->_aSystem['system_id'], $aCmt['cmt_id']);
  838. if(!empty($aFiles) && is_array($aFiles)) {
  839. $oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
  840. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->getTranscoderPreviewName());
  841. foreach($aFiles as $aFile) {
  842. $bImage = $oTranscoder && $oTranscoder->isMimeTypeSupported($aFile['mime_type']);
  843. $sPreview = '';
  844. if($oTranscoder && $bImage)
  845. $sPreview = $oTranscoder->getFileUrl($aFile['image_id']);
  846. if(!$sPreview)
  847. $sPreview = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($aFile['file_name']));
  848. $aTmplVarsFile = array(
  849. 'js_object' => $this->_sJsObjName,
  850. 'preview' => $sPreview,
  851. 'file' => $oStorage->getFileUrlById($aFile['image_id']),
  852. 'file_name' => $aFile['file_name'],
  853. 'file_icon' => $oStorage->getFontIconNameByFileName($aFile['file_name']),
  854. 'file_size' => _t_format_size($aFile['size']),
  855. );
  856. $aTmplImages[] = array(
  857. 'style_prefix' => $this->_sStylePrefix,
  858. 'bx_if:show_image' => array(
  859. 'condition' => $bImage,
  860. 'content' => $aTmplVarsFile
  861. ),
  862. 'bx_if:show_file' => array(
  863. 'condition' => !$bImage,
  864. 'content' => $aTmplVarsFile
  865. ),
  866. );
  867. }
  868. }
  869. return $this->_oTemplate->parseHtmlByName('comment_attachments.html', array(
  870. 'bx_repeat:attached' => $aTmplImages
  871. ));
  872. }
  873. protected function _getTmplVarsAuthor($aCmt)
  874. {
  875. list($sAuthorName, $sAuthorLink, $sAuthorIcon, $sAuthorUnit) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  876. $bAuthorIcon = !empty($sAuthorIcon);
  877. return array(
  878. 'author_unit' => $sAuthorUnit,
  879. 'bx_if:show_icon' => array(
  880. 'condition' => $bAuthorIcon,
  881. 'content' => array(
  882. 'author_icon' => $sAuthorIcon
  883. )
  884. ),
  885. 'bx_if:show_icon_empty' => array(
  886. 'condition' => !$bAuthorIcon,
  887. 'content' => array()
  888. ),
  889. 'bx_if:show_author_link' => array(
  890. 'condition' => !empty($sAuthorLink),
  891. 'content' => array(
  892. 'author_link' => $sAuthorLink,
  893. 'author_title' => bx_html_attribute($sAuthorName),
  894. 'author_name' => $sAuthorName
  895. )
  896. ),
  897. 'bx_if:show_author_text' => array(
  898. 'condition' => empty($sAuthorLink),
  899. 'content' => array(
  900. 'author_name' => $sAuthorName
  901. )
  902. ),
  903. );
  904. }
  905. protected function _getTmplVarsText($aCmt)
  906. {
  907. $sText = $aCmt['cmt_text'];
  908. $sTextMore = '';
  909. if(!$this->isHtml()) {
  910. $iMaxLength = (int)$this->_aSystem['chars_display_max'];
  911. if(strlen($sText) > $iMaxLength) {
  912. $iLength = strpos($sText, ' ', $iMaxLength);
  913. $sTextMore = trim(substr($sText, $iLength));
  914. $sText = trim(substr($sText, 0, $iLength));
  915. }
  916. }
  917. $sText = $this->_prepareTextForOutput($sText, $aCmt['cmt_id']);
  918. $sTextMore = $this->_prepareTextForOutput($sTextMore, $aCmt['cmt_id']);
  919. return array(
  920. 'text' => $sText,
  921. 'bx_if:show_more' => array(
  922. 'condition' => !empty($sTextMore),
  923. 'content' => array(
  924. 'style_prefix' => $this->_sStylePrefix,
  925. 'js_object' => $this->_sJsObjName,
  926. 'text_more' => $sTextMore
  927. )
  928. ),
  929. );
  930. }
  931. }
  932. /** @} */