BxBaseCmtsView.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  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. var $_sJsObjName;
  16. var $_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. * Get comments css file string
  27. *
  28. * @return string
  29. */
  30. public static function getExtraCss ()
  31. {
  32. BxDolTemplate::getInstance()->addCss(array('cmts.css'));
  33. }
  34. /**
  35. * Get comments js file string
  36. *
  37. * @return string
  38. */
  39. public static function getExtraJs ()
  40. {
  41. $oTemplate = BxDolTemplate::getInstance();
  42. $oTemplate->addJs(array('common_anim.js', 'jquery.form.js', 'BxDolCmts.js'));
  43. $oTemplate->addJsTranslation(array(
  44. '_Error occured',
  45. '_Are you sure?'
  46. ));
  47. }
  48. /**
  49. * Get initialization section of comments box
  50. *
  51. * @return string
  52. */
  53. function getScript()
  54. {
  55. $sToggleAdd = '';
  56. $ret = '';
  57. $ret .= $sToggleAdd . "
  58. <script type=\"text/javascript\">
  59. var " . $this->_sJsObjName . " = new BxDolCmts({
  60. sObjName: '" . $this->_sJsObjName . "',
  61. sRootUrl: '" . BX_DOL_URL_ROOT . "',
  62. sSystem: '" . $this->getSystemName() . "',
  63. sSystemTable: '" . $this->_aSystem['table_cmts'] . "',
  64. iAuthorId: '" . $this->_getAuthorId() . "',
  65. iObjId: '" . $this->getId () . "',
  66. sPostFormPosition: '" . $this->_aSystem['post_form_position'] . "',
  67. sBrowseType: '" . $this->_sBrowseType . "',
  68. sDisplayType: '" . $this->_sDisplayType . "'});\n";
  69. $ret .= "</script>";
  70. self::getExtraJs();
  71. self::getExtraCss();
  72. return $ret;
  73. }
  74. /**
  75. * get full comments block with initializations
  76. */
  77. function getCommentsBlock($iParentId = 0, $iVParentId = 0, $bInDesignbox = true) {
  78. $aBp = array('parent_id' => $iParentId, 'vparent_id' => $iVParentId);
  79. $sCmts = $this->getComments($aBp);
  80. $sCaption = _t('_cmt_block_comments_title', $this->_oQuery->getCommentsCount($this->_iId));
  81. $sContent = BxDolTemplate::getInstance()->parseHtmlByName('comments_block.html', array(
  82. 'system' => $this->_sSystem,
  83. 'list_anchor' => $this->getListAnchor(),
  84. 'id' => $this->getId(),
  85. 'bx_if:show_empty' => array(
  86. 'condition' => $sCmts == '',
  87. 'content' => array(
  88. 'style_prefix' => $this->_sStylePrefix
  89. )
  90. ),
  91. 'comments' => $sCmts,
  92. 'post_form_top' => $this->getFormBoxPost($aBp, array('type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_TOP)),
  93. 'post_form_bottom' => $this->getFormBoxPost($aBp, array('type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_BOTTOM)),
  94. 'script' => $this->getScript()
  95. ));
  96. return $bInDesignbox ? DesignBoxContent($sCaption, $sContent, BX_DB_PADDING_DEF, $this->_getControlsBox()) : $sContent;
  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['order'], $aBp['start'], $aBp['per_view']);
  109. if(empty($aCmts) || !is_array($aCmts))
  110. return '';
  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)
  121. {
  122. return BxDolTemplate::getInstance()->parseHtmlByName('comment_block.html', array(
  123. 'system' => $this->_sSystem,
  124. 'id' => $this->getId(),
  125. 'comment' => $this->getComment($iCmtId, array('type' => $this->_sBrowseType), array('type' => BX_CMT_DISPLAY_THREADED)),
  126. 'script' => $this->getScript()
  127. ));
  128. }
  129. /**
  130. * get one just posted comment
  131. *
  132. * @param int $iCmtId - comment id
  133. * @return string
  134. */
  135. function getComment($mixedCmt, $aBp = array(), $aDp = array())
  136. {
  137. $oTemplate = BxDolTemplate::getInstance();
  138. $iUserId = $this->_getAuthorId();
  139. $aCmt = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
  140. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
  141. $sClass = $sRet = '';
  142. if($aCmt['cmt_rated'] == -1 || $aCmt['cmt_rate'] < $this->_aSystem['viewing_threshold']) {
  143. $oTemplate->pareseHtmlByName('comment_hidden.html', array(
  144. 'js_object' => $this->_sJsObjName,
  145. 'id' => $aCmt['cmt_id'],
  146. 'title' => bx_process_output(_t('_hidden_comment', $sAuthorName)),
  147. 'bx_if:show_replies' => array(
  148. 'condition' => $aCmt['cmt_replies'] > 0,
  149. 'content' => array(
  150. 'replies' => _t('_Show N replies', $aCmt['cmt_replies'])
  151. )
  152. )
  153. ));
  154. $sClass = ' cmt-hidden';
  155. }
  156. if($aCmt['cmt_author_id'] == $iUserId)
  157. $sClass .= ' cmt-mine';
  158. $sActions = $this->_getActionsBox($aCmt, $aDp);
  159. $sText = $aCmt['cmt_text'];
  160. $sTextMore = '';
  161. $iMaxLength = (int)$this->_aSystem['chars_display_max'];
  162. if(strlen($sText) > $iMaxLength) {
  163. $iLength = strpos($sText, ' ', $iMaxLength);
  164. $sTextMore = trim(substr($sText, $iLength));
  165. $sText = trim(substr($sText, 0, $iLength));
  166. }
  167. $sText = $this->_prepareTextForOutput($sText);
  168. $sTextMore = $this->_prepareTextForOutput($sTextMore);
  169. $aTmplReplyTo = array();
  170. if((int)$aCmt['cmt_parent_id'] != 0) {
  171. $aParent = $this->getCommentRow($aCmt['cmt_parent_id']);
  172. list($sParAuthorName, $sParAuthorLink, $sParAuthorIcon) = $this->_getAuthorInfo($aParent['cmt_author_id']);
  173. $aTmplReplyTo = array(
  174. 'style_prefix' => $this->_sStylePrefix,
  175. 'par_cmt_link' => $this->getBaseUrl() . '#' . $this->_sSystem . $aCmt['cmt_parent_id'],
  176. 'par_cmt_author' => $sParAuthorName
  177. );
  178. }
  179. $aTmplImages = array();
  180. if($this->isAttachImageEnabled()) {
  181. $aImages = $this->_oQuery->getImages($this->_aSystem['system_id'], $aCmt['cmt_id']);
  182. if(!empty($aImages) && is_array($aImages)) {
  183. bx_import('BxDolImageTranscoder');
  184. $oTranscoder = BxDolImageTranscoder::getObjectInstance($this->_sTranscoderPreview);
  185. foreach($aImages as $aImage)
  186. $aTmplImages[] = array(
  187. 'style_prefix' => $this->_sStylePrefix,
  188. 'js_object' => $this->_sJsObjName,
  189. 'id' => $aImage['image_id'],
  190. 'image' => $oTranscoder->getImageUrl($aImage['image_id'])
  191. );
  192. }
  193. }
  194. $sReplies = '';
  195. if((int)$aCmt['cmt_replies'] > 0 && !empty($aDp) && $aDp['type'] == BX_CMT_DISPLAY_THREADED)
  196. $sReplies = $this->getComments(array('parent_id' => $aCmt['cmt_id'], 'vparent_id' => $aCmt['cmt_id'], 'type' => $aBp['type']), $aDp);
  197. $bAuthorIcon = !empty($sAuthorIcon);
  198. return $oTemplate->parseHtmlByName('comment.html', array(
  199. 'system' => $this->_sSystem,
  200. 'style_prefix' => $this->_sStylePrefix,
  201. 'js_object' => $this->_sJsObjName,
  202. 'id' => $aCmt['cmt_id'],
  203. 'class' => $sClass,
  204. 'bx_if:show_icon' => array(
  205. 'condition' => $bAuthorIcon,
  206. 'content' => array(
  207. 'author_icon' => $sAuthorIcon
  208. )
  209. ),
  210. 'bx_if:show_icon_empty' => array(
  211. 'condition' => !$bAuthorIcon,
  212. 'content' => array()
  213. ),
  214. 'bx_if:show_author_link' => array(
  215. 'condition' => !empty($sAuthorLink),
  216. 'content' => array(
  217. 'author_link' => $sAuthorLink,
  218. 'author_name' => $sAuthorName
  219. )
  220. ),
  221. 'bx_if:show_author_text' => array(
  222. 'condition' => empty($sAuthorLink),
  223. 'content' => array(
  224. 'author_name' => $sAuthorName
  225. )
  226. ),
  227. 'bx_if:show_reply_to' => array(
  228. 'condition' => !empty($aTmplReplyTo),
  229. 'content' => $aTmplReplyTo
  230. ),
  231. 'view_link' => bx_append_url_params($this->_sViewUrl, array(
  232. 'sys' => $this->_sSystem,
  233. 'id' => $this->_iId,
  234. 'cmt_id' => $aCmt['cmt_id']
  235. )),
  236. 'ago' => bx_time_js($aCmt['cmt_time']),
  237. 'bx_if:hide_rate_count' => array(
  238. 'condition' => (int)$aCmt['cmt_rate'] <= 0,
  239. 'content' => array()
  240. ),
  241. 'points' => _t(in_array($aCmt['cmt_rate'], array(-1, 0, 1)) ? '_N_point' : '_N_points', $aCmt['cmt_rate']),
  242. 'text' => $sText,
  243. 'bx_if:show_more' => array(
  244. 'condition' => !empty($sTextMore),
  245. 'content' => array(
  246. 'style_prefix' => $this->_sStylePrefix,
  247. 'js_object' => $this->_sJsObjName,
  248. 'text_more' => $sTextMore
  249. )
  250. ),
  251. 'bx_if:show_attached' => array(
  252. 'condition' => !empty($aTmplImages),
  253. 'content' => array(
  254. 'style_prefix' => $this->_sStylePrefix,
  255. 'bx_repeat:attached' => $aTmplImages
  256. )
  257. ),
  258. 'actions' => $sActions,
  259. 'replies' => $sReplies
  260. ));
  261. }
  262. function getFormBoxPost($aBp = array(), $aDp = array())
  263. {
  264. return $this->_getFormBox(BX_CMT_ACTION_POST, $aBp, $aDp);
  265. }
  266. function getFormBoxEdit($aBp = array(), $aDp = array())
  267. {
  268. return $this->_getFormBox(BX_CMT_ACTION_EDIT, $aBp, $aDp);
  269. }
  270. function getFormPost($iCmtParentId = 0)
  271. {
  272. return $this->_getFormPost($iCmtParentId);
  273. }
  274. function getFormEdit($aCmt)
  275. {
  276. return $this->_getFormEdit($aCmt);
  277. }
  278. function getPlusedBy($iCmtId)
  279. {
  280. $oTemplate = BxDolTemplate::getInstance();
  281. $aTmplUsers = array();
  282. $aUserIds = $this->_oQuery->getRatedBy($this->_aSystem['system_id'], $iCmtId);
  283. foreach($aUserIds as $iUserId) {
  284. list($sUserName, $sUserUrl, $sUserIcon, $sUserUnit) = $this->_getAuthorInfo($iUserId);
  285. $aTmplUsers[] = array(
  286. 'style_prefix' => $this->_sStylePrefix,
  287. 'user_unit' => $sUserUnit
  288. );
  289. }
  290. bx_import('BxTemplStudioFunctions');
  291. $sContent = BxTemplStudioFunctions::getInstance()->transBox($oTemplate->parseHtmlByName('comment_pb_list.html', array(
  292. 'style_prefix' => $this->_sStylePrefix,
  293. 'bx_repeat:list' => $aTmplUsers
  294. )));
  295. return $oTemplate->parseHtmlByName('comment_plused_by.html', array(
  296. 'style_prefix' => $this->_sStylePrefix,
  297. 'id' => $this->_sSystem . '-plused-by',
  298. 'content' => $sContent
  299. ));
  300. }
  301. function getImage($iImgId)
  302. {
  303. if(!$this->isAttachImageEnabled())
  304. return '';
  305. $oTemplate = BxDolTemplate::getInstance();
  306. bx_import('BxDolStorage');
  307. $oStorage = BxDolStorage::getObjectInstance($this->_sStorageObject);
  308. bx_import('BxTemplStudioFunctions');
  309. $sContent = BxTemplStudioFunctions::getInstance()->transBox($oTemplate->parseHtmlByName('bx_img.html', array(
  310. 'src' => $oStorage->getFileUrlById($iImgId),
  311. 'bx_repeat:attrs' => array(
  312. array('key' => 'alt', 'value' => bx_html_attribute(_t('_cmt_view_attached_image'))),
  313. array('key' => 'title', 'value' => bx_html_attribute(_t('_cmt_close_attached_image'))),
  314. array('key' => 'onclick', 'value' => $this->_sJsObjName . '.hideImage(this);')
  315. )
  316. )));
  317. return $oTemplate->parseHtmlByName('comment_image.html', array(
  318. 'style_prefix' => $this->_sStylePrefix,
  319. 'id' => $this->_sSystem . '-attached-image',
  320. 'content' => $sContent
  321. ));
  322. }
  323. /**
  324. * private functions
  325. */
  326. protected function _getControlsBox()
  327. {
  328. $oTemplate = BxDolTemplate::getInstance();
  329. $sDisplay = '';
  330. $bDisplay = (int)$this->_aSystem['is_display_switch'] == 1;
  331. if($bDisplay) {
  332. $aDisplayLinks = array(
  333. array('id' => $this->_sSystem . '-flat', 'name' => $this->_sSystem . '-flat', 'class' => '', 'title' => '_cmt_display_flat', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeDisplay(this, \'flat\');'),
  334. array('id' => $this->_sSystem . '-threaded', 'name' => $this->_sSystem . '-threaded', 'class' => '', 'title' => '_cmt_display_threaded', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeDisplay(this, \'threaded\');')
  335. );
  336. bx_import('BxTemplMenuInteractive');
  337. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-display', 'menu_items' => $aDisplayLinks));
  338. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sDisplayType);
  339. $sDisplay = $oMenu->getCode();
  340. }
  341. $sBrowse = '';
  342. $bBrowse = (int)$this->_aSystem['is_browse_switch'] == 1;
  343. if($bBrowse) {
  344. $aBrowseLinks = array(
  345. array('id' => $this->_sSystem . '-tail', 'name' => $this->_sSystem . '-tail', 'class' => '', 'title' => '_cmt_browse_tail', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'tail\');'),
  346. array('id' => $this->_sSystem . '-head', 'name' => $this->_sSystem . '-head', 'class' => '', 'title' => '_cmt_browse_head', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'head\');'),
  347. array('id' => $this->_sSystem . '-popular', 'name' => $this->_sSystem . '-popular', 'class' => '', 'title' => '_cmt_browse_popular', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'popular\');'),
  348. array('id' => $this->_sSystem . '-connection', 'name' => $this->_sSystem . '-connection', 'class' => '', 'title' => '_cmt_browse_connection', 'target' => '_self', 'onclick' => 'javascript:' . $this->_sJsObjName . '.cmtChangeBrowse(this, \'connection\');')
  349. );
  350. bx_import('BxTemplMenuInteractive');
  351. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sSystem . '-browse', 'menu_items' => $aBrowseLinks));
  352. $oMenu->setSelected('', $this->_sSystem . '-' . $this->_sBrowseType);
  353. $sBrowse = $oMenu->getCode();
  354. }
  355. return $oTemplate->parseHtmlByName('comments_controls.html', array(
  356. 'display_switcher' => $bDisplay ? $sDisplay : '',
  357. 'bx_if:is_divider' => array(
  358. 'condition' => $bDisplay && $bBrowse,
  359. 'content' => array(
  360. 'style_prefix' => $this->_sStylePrefix,
  361. )
  362. ),
  363. 'browse_switcher' => $bBrowse ? $sBrowse : '',
  364. ));
  365. }
  366. protected function _getActionsBox(&$aCmt, $aDp = array())
  367. {
  368. $oTemplate = BxDolTemplate::getInstance();
  369. $iUserId = $this->_getAuthorId();
  370. $isEditAllowedPermanently = ($aCmt['cmt_author_id'] == $iUserId && $this->isEditAllowed()) || $this->isEditAllowedAll();
  371. $isRemoveAllowedPermanently = ($aCmt['cmt_author_id'] == $iUserId && $this->isRemoveAllowed()) || $this->isRemoveAllowedAll();
  372. $sManagePopupId = $sManagePopupText = '';
  373. if($isEditAllowedPermanently || $isRemoveAllowedPermanently) {
  374. $aMenu = array(
  375. array('name' => 'cmt-edit', 'icon' => 'pencil', 'onclick' => $this->_sJsObjName . ".cmtEdit(this, " . $aCmt['cmt_id'] . ")", 'title' => _t('_Edit')),
  376. array('name' => 'cmt-delete', 'icon' => 'remove', 'onclick' => $this->_sJsObjName . ".cmtRemove(this, " . $aCmt['cmt_id'] . ")", 'title' => _t('_Delete')),
  377. );
  378. bx_import('BxTemplStudioMenu');
  379. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_vertical.html', 'menu_items' => $aMenu));
  380. bx_import('BxTemplStudioFunctions');
  381. $sManagePopupText = BxTemplStudioFunctions::getInstance()->transBox($oTemplate->parseHtmlByName('comment_manage.html', array(
  382. 'style_prefix' => $this->_sStylePrefix,
  383. 'content' => $oMenu->getCode()
  384. )));
  385. }
  386. $bRated = (int)$aCmt['cmt_rated'] > 0;
  387. return $oTemplate->parseHtmlByName('comment_actions.html', array(
  388. 'id' => $aCmt['cmt_id'],
  389. 'style_prefix' => $this->_sStylePrefix,
  390. 'view_link' => bx_append_url_params($this->_sViewUrl, array(
  391. 'sys' => $this->_sSystem,
  392. 'id' => $this->_iId,
  393. 'cmt_id' => $aCmt['cmt_id']
  394. )),
  395. 'points' => _t($aCmt['cmt_rate'] == 1 || $aCmt['cmt_rate'] == -1 ? '_N_point' : '_N_points', $aCmt['cmt_rate']),
  396. 'bx_if:show_reply' => array(
  397. 'condition' => $this->isPostReplyAllowed(),
  398. 'content' => array(
  399. 'js_object' => $this->_sJsObjName,
  400. 'style_prefix' => $this->_sStylePrefix,
  401. 'id' => $aCmt['cmt_id'],
  402. 'title_reply' => bx_html_attribute(_t(isset($aCmt['cmt_type']) && $aCmt['cmt_type'] == 'comment' ? '_Comment_to_this_comment' : '_Reply_to_this_comment'))
  403. )
  404. ),
  405. 'bx_if:show_rate' => array(
  406. 'condition' => $this->isRatable() && $this->isRateAllowed(),
  407. 'content' => array(
  408. 'js_object' => $this->_sJsObjName,
  409. 'style_prefix' => $this->_sStylePrefix,
  410. 'id' => $aCmt['cmt_id'],
  411. 'bx_if:hide_rate_plus' => array(
  412. 'condition' => $bRated,
  413. 'content' => array()
  414. ),
  415. 'bx_if:hide_rate_minus' => array(
  416. 'condition' => !$bRated,
  417. 'content' => array()
  418. )
  419. )
  420. ),
  421. 'bx_if:show_manage' => array(
  422. 'condition' => $isEditAllowedPermanently || $isRemoveAllowedPermanently,
  423. 'content' => array(
  424. 'js_object' => $this->_sJsObjName,
  425. 'style_prefix' => $this->_sStylePrefix,
  426. 'id' => $aCmt['cmt_id'],
  427. 'popup_id' => $this->_sSystem . '-manage' . $aCmt['cmt_id'],
  428. 'popup_text' => $sManagePopupText
  429. )
  430. )
  431. ));
  432. }
  433. protected function _getFormBox($sType, $aBp, $aDp)
  434. {
  435. $iCmtParentId = isset($aBp['parent_id']) ? (int)$aBp['parent_id'] : 0;
  436. $sPosition = isset($aDp['position']) ? $aDp['position'] : '';
  437. if(!$this->isPostReplyAllowed())
  438. return '';
  439. list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo();
  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. $bAuthorIcon = !empty($sAuthorIcon);
  446. return BxDolTemplate::getInstance()->parseHtmlByName('comment_reply_box.html', array(
  447. 'js_object' => $this->_sJsObjName,
  448. 'style_prefix' => $this->_sStylePrefix,
  449. 'bx_if:show_class' => array(
  450. 'condition' => !empty($sPosition),
  451. 'content' => array(
  452. 'class' => $this->_sStylePrefix . '-reply-' . $sPosition
  453. )
  454. ),
  455. 'bx_if:show_icon' => array(
  456. 'condition' => $bAuthorIcon,
  457. 'content' => array(
  458. 'author_icon' => $sAuthorIcon
  459. )
  460. ),
  461. 'bx_if:show_icon_empty' => array(
  462. 'condition' => !$bAuthorIcon,
  463. 'content' => array()
  464. ),
  465. 'bx_if:show_author_link' => array(
  466. 'condition' => !empty($sAuthorLink),
  467. 'content' => array(
  468. 'author_link' => $sAuthorLink,
  469. 'author_name' => $sAuthorName
  470. )
  471. ),
  472. 'bx_if:show_author_text' => array(
  473. 'condition' => empty($sAuthorLink),
  474. 'content' => array(
  475. 'author_name' => $sAuthorName
  476. )
  477. ),
  478. 'form' => $aForm['form'],
  479. 'form_id' => $aForm['form_id'],
  480. ));
  481. }
  482. protected function _getFormPost($iCmtParentId = 0)
  483. {
  484. $oForm = $this->_getFormObject(BX_CMT_ACTION_POST, $iCmtParentId);
  485. $oForm->aInputs['cmt_parent_id']['value'] = $iCmtParentId;
  486. $oForm->initChecker();
  487. if($oForm->isSubmittedAndValid()) {
  488. $iCmtAuthorId = $this->_getAuthorId();
  489. $iCmtParentId = $oForm->getCleanValue('cmt_parent_id');
  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. $iLevel = 0;
  496. $iCmtVisualParentId = 0;
  497. if((int)$iCmtParentId > 0) {
  498. $aParent = $this->getCommentRow($iCmtParentId);
  499. $iLevel = (int)$aParent['cmt_level'] + 1;
  500. $iCmtVisualParentId = $iLevel > $this->getMaxLevel() ? $aParent['cmt_vparent_id'] : $iCmtParentId;
  501. }
  502. $iCmtId = (int)$oForm->insert(array('cmt_vparent_id' => $iCmtVisualParentId, 'cmt_object_id' => $this->_iId, 'cmt_author_id' => $iCmtAuthorId, 'cmt_level' => $iLevel, 'cmt_time' => time()));
  503. if($iCmtId != 0) {
  504. if($this->isAttachImageEnabled()) {
  505. $aImages = $oForm->getCleanValue('cmt_image');
  506. if(!empty($aImages) && is_array($aImages)) {
  507. bx_import('BxDolStorage');
  508. $oStorage = BxDolStorage::getObjectInstance($this->_sStorageObject);
  509. foreach($aImages as $iImageId)
  510. if($this->_oQuery->saveImages($this->_aSystem['system_id'], $iCmtId, $iImageId))
  511. $oStorage->afterUploadCleanup($iImageId, $iCmtAuthorId);
  512. }
  513. }
  514. if($iCmtParentId)
  515. $this->_oQuery->updateRepliesCount($iCmtParentId, 1);
  516. $this->_triggerComment();
  517. $this->isPostReplyAllowed(true);
  518. bx_import('BxDolAlerts');
  519. $oZ = new BxDolAlerts($this->_sSystem, 'commentPost', $this->getId(), $iCmtAuthorId, array('comment_id' => $iCmtId, 'comment_author_id' => $iCmtAuthorId));
  520. $oZ->alert();
  521. return array('id' => $iCmtId, 'parent_id' => $iCmtParentId);
  522. }
  523. return array('msg' => _t('_cmt_err_cannot_perform_action'));
  524. }
  525. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  526. }
  527. protected function _getFormEdit($iCmtId)
  528. {
  529. $aCmt = $this->_oQuery->getCommentSimple ($this->getId(), $iCmtId);
  530. if(!$aCmt)
  531. return array('msg' => _t('_No such comment'));
  532. $iCmtAuthorId = $this->_getAuthorId();
  533. if(!$this->isEditAllowedAll() && ($aCmt['cmt_author_id'] != $iCmtAuthorId || !$this->isEditAllowed()))
  534. return array('msg' => $aCmt['cmt_author_id'] == $iCmtAuthorId && !$this->isEditAllowed() ? strip_tags($this->msgErrEditAllowed()) : _t('_Access denied'));
  535. $oForm = $this->_getFormObject(BX_CMT_ACTION_EDIT, $aCmt['cmt_id']);
  536. $oForm->initChecker($aCmt);
  537. if($oForm->isSubmittedAndValid()) {
  538. $sCmtText = $oForm->getCleanValue('cmt_text');
  539. if($this->_isSpam($sCmtText))
  540. return array('msg' => _t('_sys_spam_detected', BX_DOL_URL_ROOT . 'contact.php'));
  541. $sCmtText = $this->_prepareTextForSave ($sCmtText);
  542. $oForm->setSubmittedValue('cmt_text', $sCmtText, $oForm->aFormAttrs['method']);
  543. if($oForm->update($iCmtId)) {
  544. if ($aCmt['cmt_author_id'] == $iCmtAuthorId)
  545. $this->isEditAllowed(true);
  546. bx_import('BxDolAlerts');
  547. $oZ = new BxDolAlerts($this->_sSystem, 'commentUpdated', $this->getId(), $iCmtAuthorId, array('comment_id' => $aCmt['cmt_id'], 'comment_author_id' => $aCmt['cmt_author_id']));
  548. $oZ->alert();
  549. return array('id' => $iCmtId, 'text' => $sCmtText);
  550. }
  551. return array('msg' => _t('_cmt_err_cannot_perform_action'));
  552. }
  553. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  554. }
  555. protected function _getFormObject($sAction, $iId)
  556. {
  557. $sActionCap = ucfirst($sAction);
  558. $sDisplayName = '_sFormDisplay' . $sActionCap;
  559. bx_import('BxDolForm');
  560. $oForm = BxDolForm::getObjectInstance($this->_sFormObject, $this->$sDisplayName);
  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_cmts'];
  564. $oForm->aInputs['sys']['value'] = $this->_sSystem;
  565. $oForm->aInputs['id']['value'] = $this->_iId;
  566. $oForm->aInputs['action']['value'] = 'Submit' . $sActionCap . 'Form';
  567. if(!$this->isAttachImageEnabled())
  568. unset($oForm->aInputs['cmt_image']);
  569. if(isset($oForm->aInputs['cmt_image'])) {
  570. $aFormNested = array(
  571. 'params' =>array(
  572. 'nested_form_template' => 'comments_uploader_nfw.html'
  573. ),
  574. 'inputs' => array(),
  575. );
  576. bx_import('BxDolFormNested');
  577. $oFormNested = new BxDolFormNested('cmt_image', $aFormNested, 'cmt_submit');
  578. $oForm->aInputs['cmt_image']['storage_object'] = $this->_sStorageObject;
  579. $oForm->aInputs['cmt_image']['images_transcoder'] = $this->_sTranscoderPreview;
  580. $oForm->aInputs['cmt_image']['uploaders'] = $this->_aImageUploaders;
  581. $oForm->aInputs['cmt_image']['upload_buttons_titles'] = array('Simple' => 'camera');
  582. $oForm->aInputs['cmt_image']['multiple'] = true;
  583. $oForm->aInputs['cmt_image']['ghost_template'] = $oFormNested;
  584. }
  585. if(isset($oForm->aInputs['cmt_text'])) {
  586. $iCmtTextMin = (int)$this->_aSystem['chars_post_min'];
  587. $iCmtTextMax = (int)$this->_aSystem['chars_post_max'];
  588. $oForm->aInputs['cmt_text']['checker']['params'] = array($iCmtTextMin, $iCmtTextMax);
  589. $oForm->aInputs['cmt_text']['checker']['error'] = _t('_Please enter n1-n2 characters', $iCmtTextMin, $iCmtTextMax);
  590. }
  591. return $oForm;
  592. }
  593. protected function _getMoreLink($sCmts, $aBp = array(), $aDp = array())
  594. {
  595. $iStart = $iPerView = 0;
  596. switch($aBp['type']) {
  597. case BX_CMT_BROWSE_HEAD:
  598. case BX_CMT_BROWSE_POPULAR:
  599. case BX_CMT_BROWSE_CONNECTION:
  600. $iPerView = $aBp['per_view'];
  601. $iStart = $aBp['start'] + $iPerView;
  602. if($iStart >= $aBp['count'])
  603. return $sCmts;
  604. break;
  605. case BX_CMT_BROWSE_TAIL:
  606. $iPerView = $aBp['per_view'];
  607. $iStart = $aBp['start'] - $iPerView;
  608. if($iStart < 0) {
  609. $iPerView += $iStart;
  610. $iStart = 0;
  611. }
  612. if($iStart == 0 && $iPerView == 0)
  613. return $sCmts;
  614. break;
  615. }
  616. $bRoot = (int)$aBp['vparent_id'] <= 0;
  617. $sMore = BxDolTemplate::getInstance()->parseHtmlByName('comment_more.html', array(
  618. 'js_object' => $this->_sJsObjName,
  619. 'style_prefix' => $this->_sStylePrefix,
  620. 'bx_if:is_root' => array(
  621. 'condition' => $bRoot,
  622. 'content' => array()
  623. ),
  624. 'bx_if:is_button' => array(
  625. 'condition' => $bRoot,
  626. 'content' => array()
  627. ),
  628. 'parent_id' => $aBp['vparent_id'],
  629. 'start' => $iStart,
  630. 'per_view' => $iPerView,
  631. 'title' => _t('_load_more_' . ($aBp['vparent_id'] == 0 ? 'comments' : 'replies') . '_' . $aBp['type'])
  632. ));
  633. switch($aBp['type']) {
  634. case BX_CMT_BROWSE_HEAD:
  635. case BX_CMT_BROWSE_POPULAR:
  636. case BX_CMT_BROWSE_CONNECTION:
  637. $sCmts .= $sMore;
  638. break;
  639. case BX_CMT_BROWSE_TAIL:
  640. $sCmts = $sMore . $sCmts;
  641. break;
  642. }
  643. return $sCmts;
  644. }
  645. protected function _echoResultJson($a, $isAutoWrapForFormFileSubmit = false) {
  646. header('Content-type: text/html; charset=utf-8');
  647. require_once(BX_DIRECTORY_PATH_PLUGINS . 'Services_JSON.php');
  648. $oParser = new Services_JSON();
  649. $s = $oParser->encode($a);
  650. if ($isAutoWrapForFormFileSubmit && !empty($_FILES))
  651. $s = '<textarea>' . $s . '</textarea>'; // http://jquery.malsup.com/form/#file-upload
  652. echo $s;
  653. }
  654. }