BxBaseCmts.php 44 KB

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