BxTimelineMenuItemShare.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 Timeline Timeline
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * 'Item' menu.
  13. */
  14. class BxTimelineMenuItemShare extends BxTemplMenu
  15. {
  16. protected $_oModule;
  17. protected $_iEvent;
  18. protected $_aEvent;
  19. public function __construct($aObject, $oTemplate = false)
  20. {
  21. parent::__construct($aObject, $oTemplate);
  22. $this->_oModule = BxDolModule::getInstance('bx_timeline');
  23. if(bx_get('content_id') !== false)
  24. $this->setEventId((int)bx_get('content_id'));
  25. }
  26. public function setEventId($iEventId)
  27. {
  28. $this->_iEvent = $iEventId;
  29. $this->_aEvent = $this->_oModule->_oDb->getEvents(array('browse' => 'id', 'value' => $this->_iEvent));
  30. $sRepostOnclick = $sEtSend = '';
  31. if(!empty($this->_aEvent) && is_array($this->_aEvent)) {
  32. $sType = $this->_aEvent['type'];
  33. $sAction = $this->_aEvent['action'];
  34. $this->_aEvent['url'] = $this->_oModule->_oConfig->getItemViewUrl($this->_aEvent);
  35. if($this->_oModule->_oConfig->isSystem($sType, $sAction)) {
  36. $aResult = $this->_oModule->_oConfig->getSystemData($this->_aEvent);
  37. if(!empty($aResult['url']))
  38. $this->_aEvent['url'] = $aResult['url'];
  39. }
  40. //--- Repost item
  41. $iOwnerId = $this->_oModule->getUserId(); //--- in whose timeline the content will be reposted
  42. $iObjectId = $this->_oModule->_oConfig->isSystem($sType, $sAction) ? $this->_aEvent['object_id'] : $this->_aEvent['id'];
  43. $sRepostOnclick = $this->_oModule->serviceGetRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  44. //--- Send item
  45. $sAetSend = urlencode(base64_encode(serialize(array(
  46. 'name' => 'bx_timeline_send',
  47. 'params' => array(
  48. 'ViewLink' => $this->_aEvent['url']
  49. )
  50. ))));
  51. }
  52. $this->addMarkers(array(
  53. 'js_object_view' => $this->_oModule->_oConfig->getJsObject('view'),
  54. 'content_id' => $this->_iEvent,
  55. 'content_url' => $this->_aEvent['url'],
  56. 'js_onclick_repost' => $sRepostOnclick,
  57. 'et_send' => $sAetSend
  58. ));
  59. }
  60. public function getMenuItems ()
  61. {
  62. $aItems = parent::getMenuItems();
  63. $oSocial = BxDolMenu::getObjectInstance('sys_social_sharing');
  64. $oSocial->addMarkers(array(
  65. 'id' => $this->_iEvent,
  66. 'module' => $this->_oModule->_oConfig->getName(),
  67. 'url' => $this->_aEvent['url'],
  68. 'title' => $this->_aEvent['title'],
  69. ));
  70. return array_merge($aItems, $oSocial->getMenuItems());
  71. }
  72. /**
  73. * Check if menu items is visible.
  74. * @param $a menu item array
  75. * @return boolean
  76. */
  77. protected function _isVisible ($a)
  78. {
  79. if(!parent::_isVisible($a))
  80. return false;
  81. if(empty($this->_aEvent) || !is_array($this->_aEvent))
  82. return false;
  83. $sCheckFuncName = '';
  84. $aCheckFuncParams = array();
  85. switch ($a['name']) {
  86. case 'item-repost':
  87. $sCheckFuncName = 'isAllowedRepost';
  88. $aCheckFuncParams = array($this->_aEvent);
  89. break;
  90. case 'item-send':
  91. $sCheckFuncName = 'isAllowedSend';
  92. $aCheckFuncParams = array($this->_aEvent);
  93. break;
  94. }
  95. if(!$sCheckFuncName || !method_exists($this->_oModule, $sCheckFuncName))
  96. return true;
  97. return call_user_func_array(array($this->_oModule, $sCheckFuncName), $aCheckFuncParams) === true;
  98. }
  99. }
  100. /** @} */