BxBaseCmts.php 29 KB

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