BxBaseCmts.php 33 KB

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