BxBaseCmts.php 45 KB

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