BxBaseCmts.php 47 KB

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