BxBaseCmtsView.php 28 KB

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