BxBaseCmtsView.php 26 KB

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