BxBaseCmts.php 44 KB

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