1
0

BxBaseCmts.php 30 KB

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