BxBaseCmts.php 29 KB

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