BxBaseCmts.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  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 $_sJsObjName;
  15. protected $_sStylePrefix;
  16. function __construct( $sSystem, $iId, $iInit = true, $oTemplate = false)
  17. {
  18. parent::__construct($sSystem, $iId, $iInit, $oTemplate);
  19. if (empty($sSystem))
  20. return;
  21. $this->_sJsObjName = 'oCmts' . bx_gen_method_name($sSystem, array('_' , '-')) . $iId;
  22. $this->_sStylePrefix = isset($this->_aSystem['root_style_prefix']) ? $this->_aSystem['root_style_prefix'] : 'cmt';
  23. BxDolTemplate::getInstance()->addJsTranslation('_sys_txt_cmt_loading');
  24. }
  25. /**
  26. * Add comments CSS/JS
  27. */
  28. public function addCssJs ()
  29. {
  30. $this->_oTemplate->addCss(array('cmts.css'));
  31. $this->_oTemplate->addJs(array('jquery.anim.js', 'jquery.form.min.js', 'BxDolCmts.js'));
  32. $oForm = BxDolForm::getObjectInstance($this->_sFormObject, $this->_sFormDisplayPost);
  33. $oForm->addCssJs();
  34. }
  35. public function getJsObjectName()
  36. {
  37. return $this->_sJsObjName;
  38. }
  39. /**
  40. * Get initialization section of comments box
  41. *
  42. * @return string
  43. */
  44. public function getJsScript()
  45. {
  46. $aParams = array(
  47. 'sObjName' => $this->_sJsObjName,
  48. 'sRootUrl' => BX_DOL_URL_ROOT,
  49. 'sSystem' => $this->getSystemName(),
  50. 'iAuthorId' => $this->_getAuthorId(),
  51. 'iObjId' => $this->getId(),
  52. 'sBaseUrl' => $this->getBaseUrl(),
  53. 'sPostFormPosition' => $this->_aSystem['post_form_position'],
  54. 'sBrowseType' => $this->_sBrowseType,
  55. 'sDisplayType' => $this->_sDisplayType
  56. );
  57. $this->addCssJs();
  58. return BxDolTemplate::getInstance()->_wrapInTagJsCode("var " . $this->_sJsObjName . " = new BxDolCmts(" . json_encode($aParams) . ");");
  59. }
  60. /**
  61. * get full comments block with initializations
  62. */
  63. function getCommentsBlock($aBp = array(), $aDp = array())
  64. {
  65. $this->_getParams($aBp, $aDp);
  66. //add live update
  67. $this->actionResumeLiveUpdate();
  68. $sServiceCall = BxDolService::getSerializedService('system', 'get_live_updates_comments', array($this->_sSystem, $this->_iId, $this->_getAuthorId(), '{count}'), 'TemplCmtsServices');
  69. BxDolLiveUpdates::getInstance()->add($this->_sSystem . '_live_updates_cmts_' . $this->_iId, 1, $sServiceCall);
  70. //add live update
  71. $sCaption = _t($this->_aT['block_comments_title'], $this->getCommentsCountAll());
  72. $sContent = BxDolTemplate::getInstance()->parseHtmlByName('comments_block.html', array(
  73. 'system' => $this->_sSystem,
  74. 'list_anchor' => $this->getListAnchor(),
  75. 'id' => $this->getId(),
  76. 'comments' => $this->getComments($aBp, $aDp),
  77. 'post_form_top' => $this->getFormBoxPost($aBp, array_merge($aDp, array('type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_TOP))),
  78. 'post_form_bottom' => $this->getFormBoxPost($aBp, array_merge($aDp, array('type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_BOTTOM))),
  79. 'view_image_popup' => $this->_getViewImagePopup(),
  80. 'script' => $this->getJsScript()
  81. ));
  82. return $aDp['in_designbox'] ? DesignBoxContent($sCaption, $sContent, BX_DB_DEF, $this->_getControlsBox()) : array(
  83. 'title' => $sCaption,
  84. 'content' => $sContent,
  85. 'menu' => $this->_getControlsBox(),
  86. );
  87. }
  88. /**
  89. * get comments list for specified parent comment
  90. *
  91. * @param array $aBp - browse params array
  92. * @param array $aDp - display params array
  93. *
  94. */
  95. function getComments($aBp = array(), $aDp = array())
  96. {
  97. $this->_prepareParams($aBp, $aDp);
  98. $aCmts = $this->getCommentsArray($aBp['vparent_id'], $aBp['filter'], $aBp['order'], $aBp['start'], $aBp['per_view']);
  99. if(empty($aCmts) || !is_array($aCmts)) {
  100. if((int)$aBp['parent_id'] == 0 && !isLogged()) {
  101. $oPermalink = BxDolPermalinks::getInstance();
  102. return MsgBox(_t('_cmt_msg_login_required', $oPermalink->permalink('page.php?i=login'), $oPermalink->permalink('page.php?i=create-account')));
  103. }
  104. return isset($aDp['show_empty']) && $aDp['show_empty'] === true ? $this->_getEmpty() : '';
  105. }
  106. $sCmts = '';
  107. foreach($aCmts as $k => $aCmt)
  108. $sCmts .= $this->getComment($aCmt, $aBp, $aDp);
  109. $sCmts = $this->_getMoreLink($sCmts, $aBp, $aDp);
  110. return $sCmts;
  111. }
  112. /**
  113. * get comment view block with initializations
  114. */
  115. function getCommentBlock($iCmtId = 0, $aBp = array(), $aDp = array())
  116. {
  117. $mixedResult = BxDolService::call($this->_aSystem['module'], 'check_allowed_comments_view', array($this->getId(), $this->getSystemName()));
  118. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  119. return $mixedResult;
  120. $sComment = $this->getComment(
  121. $iCmtId,
  122. array_merge(array('type' => $this->_sBrowseType), $aBp),
  123. array_merge(array('type' => BX_CMT_DISPLAY_THREADED), $aDp)
  124. );
  125. if (!$sComment)
  126. return '';
  127. return BxDolTemplate::getInstance()->parseHtmlByName('comment_block.html', array(
  128. 'system' => $this->_sSystem,
  129. 'id' => $this->getId(),
  130. 'comment' => $sComment,
  131. 'view_image_popup' => $this->_getViewImagePopup(),
  132. 'script' => $this->getJsScript()
  133. ));
  134. }
  135. /**
  136. * get one just posted comment
  137. *
  138. * @param int $iCmtId - comment id
  139. * @return string
  140. */
  141. function getComment($mixedCmt, $aBp = array(), $aDp = array())
  142. {
  143. $iUserId = $this->_getAuthorId();
  144. $aCmt = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
  145. if (!$aCmt)
  146. return '';
  147. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  148. $sClass = $sClassCnt = '';
  149. if(isset($aCmt['vote_rate']) && (float)$aCmt['vote_rate'] < $this->_aSystem['viewing_threshold']) {
  150. $this->_oTemplate->pareseHtmlByName('comment_hidden.html', array(
  151. 'js_object' => $this->_sJsObjName,
  152. 'id' => $aCmt['cmt_id'],
  153. 'title' => bx_process_output(_t('_hidden_comment', $sAuthorName)),
  154. 'bx_if:show_replies' => array(
  155. 'condition' => $aCmt['cmt_replies'] > 0,
  156. 'content' => array(
  157. 'replies' => _t('_Show N replies', $aCmt['cmt_replies'])
  158. )
  159. )
  160. ));
  161. $sClass = ' ' . $this->_sStylePrefix . '-hidden';
  162. }
  163. if($aCmt['cmt_author_id'] == $iUserId)
  164. $sClass .= ' ' . $this->_sStylePrefix . '-mine';
  165. if(!empty($aDp['blink']) && in_array($aCmt['cmt_id'], $aDp['blink']))
  166. $sClass .= ' ' . $this->_sStylePrefix . '-blink';
  167. if(!empty($aDp['class_comment']))
  168. $sClass .= ' ' . $aDp['class_comment'];
  169. if(!empty($aDp['class_comment_content']))
  170. $sClassCnt .= ' ' . $aDp['class_comment_content'];
  171. $sActions = $this->_getActionsBox($aCmt, $aDp);
  172. $aTmplReplyTo = array();
  173. if((int)$aCmt['cmt_parent_id'] != 0) {
  174. $aParent = $this->getCommentRow($aCmt['cmt_parent_id']);
  175. list($sParAuthorName, $sParAuthorLink, $sParAuthorIcon) = $this->_getAuthorInfo($aParent['cmt_author_id']);
  176. $aTmplReplyTo = array(
  177. 'style_prefix' => $this->_sStylePrefix,
  178. 'par_cmt_link' => $this->getBaseUrl() . '#' . $this->_sSystem . $aCmt['cmt_parent_id'],
  179. 'par_cmt_title' => bx_html_attribute(_t('_in_reply_to', $sParAuthorName)),
  180. 'par_cmt_author' => $sParAuthorName
  181. );
  182. }
  183. $sAttachments = $this->_getAttachments($aCmt);
  184. $sReplies = '';
  185. if((int)$aCmt['cmt_replies'] > 0 && !empty($aDp) && $aDp['type'] == BX_CMT_DISPLAY_THREADED) {
  186. $aDp['show_empty'] = false;
  187. $sReplies = $this->getComments(array('parent_id' => $aCmt['cmt_id'], 'vparent_id' => $aCmt['cmt_id'], 'type' => $aBp['type']), $aDp);
  188. }
  189. $sAgo = bx_time_js($aCmt['cmt_time']);
  190. $bObjectTitle = !empty($this->_aSystem['trigger_field_title']);
  191. return $this->_oTemplate->parseHtmlByName('comment.html', array_merge(array(
  192. 'system' => $this->_sSystem,
  193. 'style_prefix' => $this->_sStylePrefix,
  194. 'js_object' => $this->_sJsObjName,
  195. 'id' => $aCmt['cmt_id'],
  196. 'class' => $sClass,
  197. 'class_cnt' => $sClassCnt,
  198. 'bx_if:show_reply_to' => array(
  199. 'condition' => !empty($aTmplReplyTo),
  200. 'content' => $aTmplReplyTo
  201. ),
  202. 'bx_if:show_ago_link' => array(
  203. 'condition' => $bObjectTitle,
  204. 'content' => array(
  205. 'style_prefix' => $this->_sStylePrefix,
  206. 'view_link' => $this->getViewUrl($aCmt['cmt_id']),
  207. 'ago' => $sAgo
  208. )
  209. ),
  210. 'bx_if:show_ago_text' => array(
  211. 'condition' => !$bObjectTitle,
  212. 'content' => array(
  213. 'ago' => $sAgo
  214. )
  215. ),
  216. 'bx_if:show_attached' => array(
  217. 'condition' => !empty($sAttachments),
  218. 'content' => array(
  219. 'style_prefix' => $this->_sStylePrefix,
  220. 'attached' => $sAttachments
  221. )
  222. ),
  223. 'actions' => $sActions,
  224. 'replies' => $sReplies
  225. ), $this->_getTmplVarsAuthor($aCmt), $this->_getTmplVarsText($aCmt)));
  226. }
  227. /**
  228. * get one comment for "Live Search"
  229. *
  230. * @param int $iCmtId - comment id
  231. * @return string
  232. */
  233. function getCommentLiveSearch($mixedCmt, $aParams = array())
  234. {
  235. $aCmt = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
  236. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  237. $bAuthorIcon = !empty($sAuthorIcon);
  238. $sViewLink = $this->getViewUrl($aCmt['cmt_id']);
  239. if(empty($sViewLink))
  240. $sViewLink = '#';
  241. return BxDolTemplate::getInstance()->parseHtmlByName('comment_live_search.html', array(
  242. 'bx_if:show_icon' => array(
  243. 'condition' => $bAuthorIcon,
  244. 'content' => array(
  245. 'author_icon' => $sAuthorIcon,
  246. 'view_link' => $sViewLink
  247. )
  248. ),
  249. 'bx_if:show_icon_empty' => array(
  250. 'condition' => !$bAuthorIcon,
  251. 'content' => array()
  252. ),
  253. 'view_link' => $sViewLink,
  254. 'text' => BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($aCmt['cmt_text']), $this->_sSnippetLenthLiveSearch),
  255. 'sample' => isset($aParams['txt_sample_single']) ? _t($aParams['txt_sample_single']) : ''
  256. ));
  257. }
  258. function getFormBoxPost($aBp = array(), $aDp = array())
  259. {
  260. if(!$this->isPostReplyAllowed())
  261. return '';
  262. return $this->_getFormBox(BX_CMT_ACTION_POST, $aBp, $aDp);
  263. }
  264. function getFormBoxEdit($aBp = array(), $aDp = array())
  265. {
  266. return $this->_getFormBox(BX_CMT_ACTION_EDIT, $aBp, $aDp);
  267. }
  268. function getFormPost($iCmtParentId = 0, $aDp = array())
  269. {
  270. return $this->_getFormPost($iCmtParentId, $aDp);
  271. }
  272. function getFormEdit($iCmtId, $aDp = array())
  273. {
  274. return $this->_getFormEdit($iCmtId, $aDp);
  275. }
  276. function getNotification($iCountOld = 0, $iCountNew = 0)
  277. {
  278. $iCount = (int)$iCountNew - (int)$iCountOld;
  279. $aComments = $this->_oQuery->getCommentsBy(array('type' => 'latest', 'object_id' => $this->_iId, 'author' => $this->_getAuthorId(), 'others' => 1, 'start' => '0', 'per_page' => $iCount));
  280. if(empty($aComments) || !is_array($aComments))
  281. return '';
  282. $sJsObject = $this->getJsObjectName();
  283. $oTemplate = BxDolTemplate::getInstance();
  284. $aComments = array_reverse($aComments);
  285. $iComments = count($aComments);
  286. $aTmplVarsNotifs = array();
  287. foreach($aComments as $iIndex => $aComment) {
  288. $iCommentId = $aComment['cmt_id'];
  289. $sShowOnClick = "javascript:" . $sJsObject . ".goTo(this, '" . $this->_sSystem . $iCommentId . "', '" . $iCommentId . "');";
  290. $sReplyOnClick = "javascript:" . $sJsObject . ".goToAndReply(this, '" . $this->_sSystem . $iCommentId . "', '" . $iCommentId . "');";
  291. $aTmplVarsNotifs[] = array(
  292. 'bx_if:show_as_hidden' => array(
  293. 'condition' => $iIndex < ($iComments - 1),
  294. 'content' => array(),
  295. ),
  296. 'item' => $oTemplate->parseHtmlByName('comments_notification.html', array_merge(array(
  297. 'style_prefix' => $this->_sStylePrefix,
  298. 'onclick_show' => $sShowOnClick,
  299. 'onclick_reply' => $sReplyOnClick,
  300. ), $this->_getTmplVarsAuthor($aComment), $this->_getTmplVarsText($aComment))),
  301. 'bx_if:show_previous' => array(
  302. 'condition' => $iIndex > 0,
  303. 'content' => array(
  304. 'onclick_previous' => $sJsObject . '.previousLiveUpdate(this)'
  305. )
  306. ),
  307. 'onclick_close' => $sJsObject . '.hideLiveUpdate(this)'
  308. );
  309. }
  310. return $oTemplate->parseHtmlByName('popup_chain.html', array(
  311. 'html_id' => $this->getNotificationId(),
  312. 'bx_repeat:items' => $aTmplVarsNotifs
  313. ));
  314. }
  315. /**
  316. * private functions
  317. */
  318. protected function _getControlsBox()
  319. {
  320. $sDisplay = '';
  321. $bDisplay = (int)$this->_aSystem['is_display_switch'] == 1;
  322. if($bDisplay) {
  323. $aDisplayLinks = array(
  324. array('id' => $this->_sSystem . '-flat', 'name' => $this->_sSystem . '-flat', 'class' => '', 'title' => '_cmt_display_flat', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeDisplay(this, \'flat\');'),
  325. array('id' => $this->_sSystem . '-threaded', 'name' => $this->_sSystem . '-threaded', 'class' => '', 'title' => '_cmt_display_threaded', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeDisplay(this, \'threaded\');')
  326. );
  327. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-display', 'menu_items' => $aDisplayLinks));
  328. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sDisplayType);
  329. $sDisplay = $oMenu->getCode();
  330. }
  331. $sBrowseType = '';
  332. $bBrowseType = (int)$this->_aSystem['is_browse_switch'] == 1;
  333. if($bBrowseType) {
  334. $aBrowseLinks = array(
  335. array('id' => $this->_sSystem . '-tail', 'name' => $this->_sSystem . '-tail', 'class' => '', 'title' => '_cmt_browse_tail', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'tail\');'),
  336. array('id' => $this->_sSystem . '-head', 'name' => $this->_sSystem . '-head', 'class' => '', 'title' => '_cmt_browse_head', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'head\');'),
  337. array('id' => $this->_sSystem . '-popular', 'name' => $this->_sSystem . '-popular', 'class' => '', 'title' => '_cmt_browse_popular', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'popular\');'),
  338. );
  339. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-browse', 'menu_items' => $aBrowseLinks));
  340. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sBrowseType);
  341. $sBrowseType = $oMenu->getCode();
  342. }
  343. $sBrowseFilter = '';
  344. $bBrowseFilter = (int)$this->_aSystem['is_browse_filter'] == 1;
  345. if($bBrowseFilter) {
  346. $aFilterLinks = array(
  347. array('id' => $this->_sSystem . '-all', 'name' => $this->_sSystem . '-all', 'class' => '', 'title' => '_cmt_browse_all', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'all\');'),
  348. array('id' => $this->_sSystem . '-friends', 'name' => $this->_sSystem . '-friends', 'class' => '', 'title' => '_cmt_browse_friends', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'friends\');'),
  349. array('id' => $this->_sSystem . '-subscriptions', 'name' => $this->_sSystem . '-subscriptions', 'class' => '', 'title' => '_cmt_browse_subscriptions', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeFilter(this, \'subscriptions\');')
  350. );
  351. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-filter', 'menu_items' => $aFilterLinks));
  352. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sBrowseFilter);
  353. $sBrowseFilter = $oMenu->getCode();
  354. }
  355. return $this->_oTemplate->parseHtmlByName('comments_controls.html', array(
  356. 'display_switcher' => $bDisplay ? $sDisplay : '',
  357. 'bx_if:is_divider_1' => array(
  358. 'condition' => $bDisplay && $bBrowseType,
  359. 'content' => array(
  360. 'style_prefix' => $this->_sStylePrefix,
  361. )
  362. ),
  363. 'browse_switcher' => $bBrowseType ? $sBrowseType : '',
  364. 'bx_if:is_divider_2' => array(
  365. 'condition' => $bBrowseType && $bBrowseFilter,
  366. 'content' => array(
  367. 'style_prefix' => $this->_sStylePrefix,
  368. )
  369. ),
  370. 'filter_switcher' => $bBrowseFilter ? $sBrowseFilter : '',
  371. ));
  372. }
  373. protected function _getActionsBox(&$aCmt, $aDp = array())
  374. {
  375. $bViewOnly = isset($aDp['view_only']) && $aDp['view_only'] === true;
  376. $bDynamicMode = isset($aDp['dynamic_mode']) && $aDp['dynamic_mode'] === true;
  377. $bMenuManage = false;
  378. $sMenuActions = $sMenuManage = '';
  379. if(!$bViewOnly) {
  380. //--- Actions Menu
  381. $oMenuActions = BxDolMenu::getObjectInstance($this->_sMenuObjActions);
  382. $oMenuActions->setCmtsData($this, $aCmt['cmt_id']);
  383. $oMenuActions->setDynamicMode($bDynamicMode);
  384. $sMenuActions = $oMenuActions->getCode();
  385. /*
  386. TODO: Remove before commit.
  387. $oVote = $this->getVoteObject($aCmt['cmt_id']);
  388. if($oVote !== false)
  389. $sMenuActions .= $oVote->getJsScript();
  390. */
  391. //--- Manage Menu
  392. $oMenuManage = BxDolMenu::getObjectInstance($this->_sMenuObjManage);
  393. $oMenuManage->setCmtsData($this, $aCmt['cmt_id']);
  394. $sMenuManage = $oMenuManage->getCode();
  395. $bMenuManage = !empty($sMenuManage);
  396. if($bMenuManage) {
  397. $sMenuManage = $this->_oTemplate->parseHtmlByName('comment_manage.html', array(
  398. 'style_prefix' => $this->_sStylePrefix,
  399. 'content' => $sMenuManage
  400. ));
  401. $sMenuManage = BxTemplFunctions::getInstance()->transBox($this->_sSystem . '-manage-' . $aCmt['cmt_id'], $sMenuManage, true);
  402. }
  403. }
  404. return $this->_oTemplate->parseHtmlByName('comment_actions.html', array(
  405. 'id' => $aCmt['cmt_id'],
  406. 'js_object' => $this->_sJsObjName,
  407. 'style_prefix' => $this->_sStylePrefix,
  408. 'menu_actions' => $sMenuActions,
  409. /*
  410. 'bx_if:hide_rate_count' => array(
  411. 'condition' => (int)$aCmt['cmt_rate'] <= 0,
  412. 'content' => array()
  413. ),
  414. 'points' => _t(in_array($aCmt['cmt_rate'], array(-1, 0, 1)) ? '_N_point' : '_N_points', $aCmt['cmt_rate']),
  415. */
  416. 'bx_if:show_menu_manage' => array(
  417. 'condition' => $bMenuManage,
  418. 'content' => array(
  419. 'js_object' => $this->_sJsObjName,
  420. 'style_prefix' => $this->_sStylePrefix,
  421. 'id' => $aCmt['cmt_id'],
  422. 'popup_text' => $sMenuManage
  423. )
  424. )
  425. ));
  426. }
  427. protected function _getFormBox($sType, $aBp, $aDp)
  428. {
  429. $iCmtParentId = isset($aBp['parent_id']) ? (int)$aBp['parent_id'] : 0;
  430. $sPosition = isset($aDp['position']) ? $aDp['position'] : '';
  431. $sPositionSystem = $this->_aSystem['post_form_position'];
  432. if(!empty($sPosition) && $sPositionSystem != $sPosition)
  433. return '';
  434. $sMethod = '_getForm' . ucfirst($sType);
  435. $aForm = $this->$sMethod($iCmtParentId, $aDp);
  436. return BxDolTemplate::getInstance()->parseHtmlByName('comment_reply_box.html', array(
  437. 'js_object' => $this->_sJsObjName,
  438. 'style_prefix' => $this->_sStylePrefix,
  439. 'bx_if:show_class' => array(
  440. 'condition' => !empty($sPosition),
  441. 'content' => array(
  442. 'class' => $this->_sStylePrefix . '-reply-' . $sPosition
  443. )
  444. ),
  445. 'form' => $aForm['form'],
  446. 'form_id' => $aForm['form_id'],
  447. ));
  448. }
  449. protected function _getFormPost($iCmtParentId = 0, $aDp = array())
  450. {
  451. $bDynamic = isset($aDp['dynamic_mode']) && (bool)$aDp['dynamic_mode'];
  452. $oForm = $this->_getForm(BX_CMT_ACTION_POST, $iCmtParentId);
  453. $oForm->aInputs['cmt_parent_id']['value'] = $iCmtParentId;
  454. $oForm->initChecker();
  455. if($oForm->isSubmittedAndValid()) {
  456. $iCmtAuthorId = $this->_getAuthorId();
  457. $iCmtParentId = $oForm->getCleanValue('cmt_parent_id');
  458. $sCmtText = $oForm->getCleanValue('cmt_text');
  459. $sCmtText = $this->_prepareTextForSave ($sCmtText);
  460. $oForm->setSubmittedValue('cmt_text', $sCmtText, $oForm->aFormAttrs['method']);
  461. $iLevel = 0;
  462. $iCmtVisualParentId = 0;
  463. if((int)$iCmtParentId > 0) {
  464. $aParent = $this->getCommentRow($iCmtParentId);
  465. $iLevel = (int)$aParent['cmt_level'] + 1;
  466. $iCmtVisualParentId = $iLevel > $this->getMaxLevel() ? $aParent['cmt_vparent_id'] : $iCmtParentId;
  467. }
  468. $iCmtId = (int)$oForm->insert(array('cmt_vparent_id' => $iCmtVisualParentId, 'cmt_object_id' => $this->_iId, 'cmt_author_id' => $iCmtAuthorId, 'cmt_level' => $iLevel, 'cmt_time' => time()));
  469. if($iCmtId != 0) {
  470. if($this->isAttachImageEnabled()) {
  471. $aImages = $oForm->getCleanValue('cmt_image');
  472. if(!empty($aImages) && is_array($aImages)) {
  473. $oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
  474. foreach($aImages as $iImageId)
  475. if($this->_oQuery->saveImages($this->_aSystem['system_id'], $iCmtId, $iImageId))
  476. $oStorage->afterUploadCleanup($iImageId, $iCmtAuthorId);
  477. }
  478. }
  479. if($iCmtParentId) {
  480. $this->_oQuery->updateRepliesCount($iCmtParentId, 1);
  481. $this->_sendNotificationEmail($iCmtId, $iCmtParentId);
  482. }
  483. $this->_triggerComment();
  484. $this->isPostReplyAllowed(true);
  485. if ($this->_sMetatagsObj) {
  486. $oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj);
  487. $oMetatags->keywordsAdd($this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId), $sCmtText);
  488. }
  489. $this->onPostAfter($iCmtId);
  490. return array('id' => $iCmtId, 'parent_id' => $iCmtParentId);
  491. }
  492. return array('msg' => _t('_cmt_err_cannot_perform_action'));
  493. }
  494. return array('form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id);
  495. }
  496. protected function _getFormEdit($iCmtId, $aDp = array())
  497. {
  498. $bDynamic = isset($aDp['dynamic_mode']) && (bool)$aDp['dynamic_mode'];
  499. $aCmt = $this->_oQuery->getCommentSimple ((int)$this->getId(), $iCmtId);
  500. if(!$aCmt)
  501. return array('msg' => _t('_No such comment'));
  502. $iCmtAuthorId = $this->_getAuthorId();
  503. if(!$this->isEditAllowed($aCmt))
  504. return array('msg' => $aCmt['cmt_author_id'] == $iCmtAuthorId ? strip_tags($this->msgErrEditAllowed()) : _t('_Access denied'));
  505. $oForm = $this->_getForm(BX_CMT_ACTION_EDIT, $aCmt['cmt_id']);
  506. $aCmt['cmt_text'] = $this->_prepareTextForEdit($aCmt['cmt_text']);
  507. $oForm->initChecker($aCmt);
  508. if($oForm->isSubmittedAndValid()) {
  509. $sCmtText = $oForm->getCleanValue('cmt_text');
  510. $sCmtText = $this->_prepareTextForSave ($sCmtText);
  511. $oForm->setSubmittedValue('cmt_text', $sCmtText, $oForm->aFormAttrs['method']);
  512. if($oForm->update($iCmtId)) {
  513. $this->isEditAllowed(true);
  514. if ($this->_sMetatagsObj) {
  515. $oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj);
  516. $oMetatags->keywordsAdd($this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId), $sCmtText);
  517. }
  518. $this->onEditAfter($iCmtId);
  519. return array('id' => $iCmtId, 'text' => $this->_prepareTextForOutput($sCmtText, $iCmtId));
  520. }
  521. return array('msg' => _t('_cmt_err_cannot_perform_action'));
  522. }
  523. return array('form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id);
  524. }
  525. protected function _getForm($sAction, $iId)
  526. {
  527. $oForm = $this->_getFormObject($sAction);
  528. $oForm->setId(sprintf($oForm->aFormAttrs['id'], $sAction, $this->_sSystem, $iId));
  529. $oForm->setName(sprintf($oForm->aFormAttrs['name'], $sAction, $this->_sSystem, $iId));
  530. $oForm->aParams['db']['table'] = $this->_aSystem['table'];
  531. $oForm->aInputs['sys']['value'] = $this->_sSystem;
  532. $oForm->aInputs['id']['value'] = $this->_iId;
  533. $oForm->aInputs['action']['value'] = 'Submit' . ucfirst($sAction) . 'Form';
  534. if(!$this->isAttachImageEnabled())
  535. unset($oForm->aInputs['cmt_image']);
  536. if(isset($oForm->aInputs['cmt_text'])) {
  537. $iCmtTextMin = (int)$this->_aSystem['chars_post_min'];
  538. $iCmtTextMax = (int)$this->_aSystem['chars_post_max'];
  539. $oForm->aInputs['cmt_text']['checker']['params'] = array($iCmtTextMin, $iCmtTextMax);
  540. $oForm->aInputs['cmt_text']['checker']['error'] = _t('_Please enter n1-n2 characters', $iCmtTextMin, $iCmtTextMax);
  541. }
  542. return $oForm;
  543. }
  544. protected function _getMoreLink($sCmts, $aBp = array(), $aDp = array())
  545. {
  546. $iStart = $iPerView = 0;
  547. switch($aBp['type']) {
  548. case BX_CMT_BROWSE_HEAD:
  549. case BX_CMT_BROWSE_POPULAR:
  550. case BX_CMT_BROWSE_CONNECTION:
  551. $iPerView = $aBp['per_view'];
  552. $iStart = $aBp['start'] + $iPerView;
  553. if($iStart >= $aBp['count'])
  554. return $sCmts;
  555. break;
  556. case BX_CMT_BROWSE_TAIL:
  557. $iPerView = $aBp['per_view'];
  558. $iStart = $aBp['start'] - $iPerView;
  559. if($iStart < 0) {
  560. $iPerView += $iStart;
  561. $iStart = 0;
  562. }
  563. if($iStart == 0 && $iPerView == 0)
  564. return $sCmts;
  565. break;
  566. }
  567. $bRoot = (int)$aBp['vparent_id'] <= 0;
  568. $sMore = BxDolTemplate::getInstance()->parseHtmlByName('comment_more.html', array(
  569. 'js_object' => $this->_sJsObjName,
  570. 'style_prefix' => $this->_sStylePrefix,
  571. 'bx_if:is_root' => array(
  572. 'condition' => $bRoot,
  573. 'content' => array()
  574. ),
  575. 'parent_id' => $aBp['vparent_id'],
  576. 'start' => $iStart,
  577. 'per_view' => $iPerView,
  578. 'title' => _t('_cmt_load_more_' . ($aBp['vparent_id'] == 0 ? 'comments' : 'replies') . '_' . $aBp['type'])
  579. ));
  580. switch($aBp['type']) {
  581. case BX_CMT_BROWSE_HEAD:
  582. case BX_CMT_BROWSE_POPULAR:
  583. case BX_CMT_BROWSE_CONNECTION:
  584. $sCmts .= $sMore;
  585. break;
  586. case BX_CMT_BROWSE_TAIL:
  587. $sCmts = $sMore . $sCmts;
  588. break;
  589. }
  590. return $sCmts;
  591. }
  592. protected function _getEmpty()
  593. {
  594. return BxDolTemplate::getInstance()->parseHtmlByName('comment_empty.html', array(
  595. 'style_prefix' => $this->_sStylePrefix
  596. ));
  597. }
  598. protected function _getViewImagePopup()
  599. {
  600. $sViewImagePopupId = 'cmts-box-' . $this->_sSystem . '-' . $this->getId() . '-view-image-popup' ;
  601. $sViewImagePopupContent = BxDolTemplate::getInstance()->parseHtmlByName('popup_image.html', array(
  602. 'image_url' => ''
  603. ));
  604. return BxTemplFunctions::getInstance()->transBox($sViewImagePopupId, $sViewImagePopupContent, true);
  605. }
  606. protected function _getAttachments($aCmt)
  607. {
  608. $aTmplImages = array();
  609. if(!$this->isAttachImageEnabled())
  610. return '';
  611. $aFiles = $this->_oQuery->getFiles($this->_aSystem['system_id'], $aCmt['cmt_id']);
  612. if(!empty($aFiles) && is_array($aFiles)) {
  613. $oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
  614. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->getTranscoderPreviewName());
  615. foreach($aFiles as $aFile) {
  616. $bImage = strncmp($aFile['mime_type'], 'image/', 6) === 0;
  617. $sPreview = '';
  618. if($oTranscoder && $bImage)
  619. $sPreview = $oTranscoder->getFileUrl($aFile['image_id']);
  620. if(!$sPreview)
  621. $sPreview = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($aFile['file_name']));
  622. $aTmplVarsFile = array(
  623. 'js_object' => $this->_sJsObjName,
  624. 'preview' => $sPreview,
  625. 'file' => $oStorage->getFileUrlById($aFile['image_id']),
  626. 'file_name' => $aFile['file_name'],
  627. 'file_icon' => $oStorage->getFontIconNameByFileName($aFile['file_name']),
  628. 'file_size' => _t_format_size($aFile['size']),
  629. );
  630. $aTmplImages[] = array(
  631. 'style_prefix' => $this->_sStylePrefix,
  632. 'bx_if:show_image' => array(
  633. 'condition' => $bImage,
  634. 'content' => $aTmplVarsFile
  635. ),
  636. 'bx_if:show_file' => array(
  637. 'condition' => !$bImage,
  638. 'content' => $aTmplVarsFile
  639. ),
  640. );
  641. }
  642. }
  643. return $this->_oTemplate->parseHtmlByName('comment_attachments.html', array(
  644. 'bx_repeat:attached' => $aTmplImages
  645. ));
  646. }
  647. protected function _getTmplVarsAuthor($aCmt)
  648. {
  649. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  650. $bAuthorIcon = !empty($sAuthorIcon);
  651. return array(
  652. 'bx_if:show_icon' => array(
  653. 'condition' => $bAuthorIcon,
  654. 'content' => array(
  655. 'author_icon' => $sAuthorIcon
  656. )
  657. ),
  658. 'bx_if:show_icon_empty' => array(
  659. 'condition' => !$bAuthorIcon,
  660. 'content' => array()
  661. ),
  662. 'bx_if:show_author_link' => array(
  663. 'condition' => !empty($sAuthorLink),
  664. 'content' => array(
  665. 'author_link' => $sAuthorLink,
  666. 'author_title' => bx_html_attribute($sAuthorName),
  667. 'author_name' => $sAuthorName
  668. )
  669. ),
  670. 'bx_if:show_author_text' => array(
  671. 'condition' => empty($sAuthorLink),
  672. 'content' => array(
  673. 'author_name' => $sAuthorName
  674. )
  675. ),
  676. );
  677. }
  678. protected function _getTmplVarsText($aCmt)
  679. {
  680. $sText = $aCmt['cmt_text'];
  681. $sTextMore = '';
  682. $iMaxLength = (int)$this->_aSystem['chars_display_max'];
  683. if(strlen($sText) > $iMaxLength) {
  684. $iLength = strpos($sText, ' ', $iMaxLength);
  685. $sTextMore = trim(substr($sText, $iLength));
  686. $sText = trim(substr($sText, 0, $iLength));
  687. }
  688. $sText = $this->_prepareTextForOutput($sText, $aCmt['cmt_id']);
  689. $sTextMore = $this->_prepareTextForOutput($sTextMore, $aCmt['cmt_id']);
  690. return array(
  691. 'text' => $sText,
  692. 'bx_if:show_more' => array(
  693. 'condition' => !empty($sTextMore),
  694. 'content' => array(
  695. 'style_prefix' => $this->_sStylePrefix,
  696. 'js_object' => $this->_sJsObjName,
  697. 'text_more' => $sTextMore
  698. )
  699. ),
  700. );
  701. }
  702. }
  703. /** @} */