BxBaseCmtsPageView.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. class BxBaseCmtsPageView extends BxTemplPage
  10. {
  11. protected $_oCmts;
  12. protected $_iCmtId;
  13. public function __construct($aObject, $oTemplate)
  14. {
  15. parent::__construct($aObject, $oTemplate);
  16. $sSystem = bx_get('sys');
  17. $sSystem = $sSystem !== false ? $sSystem = bx_process_input($sSystem) : '';
  18. $iObjectId = bx_get('id');
  19. $iObjectId = $iObjectId !== false ? bx_process_input($iObjectId, BX_DATA_INT) : 0;
  20. $iCommentId = bx_get('cmt_id');
  21. $this->_iCmtId = $iCommentId !== false ? bx_process_input($iCommentId, BX_DATA_INT) : 0;
  22. if(!$sSystem || !$iObjectId)
  23. return;
  24. $this->_oCmts = BxDolCmts::getObjectInstance($sSystem, $iObjectId, true);
  25. if(!$this->_oCmts)
  26. return;
  27. $sObjectTitle = bx_process_output(strip_tags($this->_oCmts->getObjectTitle($iObjectId)));
  28. $sObjectUrl = $this->_oCmts->getBaseUrl();
  29. $this->addMarkers([
  30. 'system' => $sSystem,
  31. 'object_id' => $iObjectId,
  32. 'object_title' => $sObjectTitle,
  33. 'object_url' => $sObjectUrl,
  34. 'comment_id' => $iCommentId,
  35. 'comment_snippet' => $this->_oCmts->getViewSnippet($iCommentId)
  36. ]);
  37. }
  38. protected function _isAvailablePage ($a)
  39. {
  40. if(!$this->_iCmtId)
  41. return false;
  42. $aCmt = $this->_oCmts->getCommentSimple($this->_iCmtId);
  43. if(empty($aCmt) || !is_array($aCmt))
  44. return false;
  45. return parent::_isAvailablePage($a);
  46. }
  47. public function getCode()
  48. {
  49. if (!$this->_isAvailablePage($this->_aObject)) {
  50. $this->_oTemplate->displayPageNotFound();
  51. exit;
  52. }
  53. if($this->_oCmts)
  54. BxDolTemplate::getInstance()->setPageUrl($this->_oCmts->getViewUrl($this->_iCmtId));
  55. return parent::getCode();
  56. }
  57. }
  58. /** @} */