BxBaseCmts.php 46 KB

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