BxTimelineMenuItemShare.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. $iContentId = 0;
  24. if(bx_get('content_id') !== false)
  25. $iContentId = bx_process_input(bx_get('content_id'), BX_DATA_INT);
  26. $aBrowseParams = array('name' => '', 'view' => '', 'type' => '');
  27. foreach($aBrowseParams as $sKey => $sValue)
  28. if(bx_get($sKey) !== false)
  29. $aBrowseParams[$sKey] = bx_process_input(bx_get($sKey));
  30. $this->setEventById($iContentId, $aBrowseParams);
  31. }
  32. public function setEventById($iEventId, $aBrowseParams = array())
  33. {
  34. $this->_iEvent = $iEventId;
  35. $this->_aEvent = $this->_oModule->_oDb->getEvents(array('browse' => 'id', 'value' => $this->_iEvent));
  36. $this->_setBrowseParams($aBrowseParams);
  37. $sRepostOnclick = $sEtSend = '';
  38. if(!empty($this->_aEvent) && is_array($this->_aEvent)) {
  39. $sType = $this->_aEvent['type'];
  40. $sAction = $this->_aEvent['action'];
  41. $this->_aEvent['url'] = $this->_oModule->_oConfig->getItemViewUrl($this->_aEvent);
  42. if($this->_oModule->_oConfig->isSystem($sType, $sAction)) {
  43. $aResult = $this->_oModule->_oConfig->getSystemData($this->_aEvent);
  44. if(!empty($aResult['url']))
  45. $this->_aEvent['url'] = $aResult['url'];
  46. }
  47. //--- Repost and 'Repost To' items
  48. $iOwnerId = $this->_oModule->getUserId(); //--- in whose timeline the content will be reposted
  49. $iObjectId = $this->_oModule->_oConfig->isSystem($sType, $sAction) ? $this->_aEvent['object_id'] : $this->_aEvent['id'];
  50. $sRepostOnclick = $this->_oModule->serviceGetRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  51. $sRepostToOnclick = $this->_oModule->serviceGetRepostToJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  52. //--- Send item
  53. $sAetSend = urlencode(base64_encode(serialize(array(
  54. 'name' => 'bx_timeline_send',
  55. 'params' => array(
  56. 'ViewLink' => $this->_aEvent['url']
  57. )
  58. ))));
  59. }
  60. $this->addMarkers(array(
  61. 'content_id' => $this->_iEvent,
  62. 'content_url' => $this->_aEvent['url'],
  63. 'repost_onclick' => $sRepostOnclick,
  64. 'repost_to_onclick' => $sRepostToOnclick,
  65. 'et_send' => $sAetSend
  66. ));
  67. }
  68. public function getMenuItems ()
  69. {
  70. $aItems = parent::getMenuItems();
  71. $aMarkers = array(
  72. 'id' => $this->_iEvent,
  73. 'module' => $this->_oModule->_oConfig->getName(),
  74. 'url' => $this->_aEvent['url'],
  75. 'title' => $this->_aEvent['title'],
  76. 'img_url' => '',
  77. 'img_url_encoded' => ''
  78. );
  79. $aEventData = $this->_oModule->_oTemplate->getDataCached($this->_aEvent);
  80. if(!empty($aEventData['content']['images']) && is_array($aEventData['content']['images'])) {
  81. $aImage = array_shift($aEventData['content']['images']);
  82. $sImgUrl = isset($aImage['src_medium']) ? $aImage['src_medium'] : $aImage['src'];;
  83. if(!empty($sImgUrl))
  84. $aMarkers = array_merge($aMarkers, array(
  85. 'img_url' => $sImgUrl,
  86. 'img_url_encoded' => rawurlencode($sImgUrl),
  87. ));
  88. }
  89. $oSocial = BxDolMenu::getObjectInstance('sys_social_sharing');
  90. $oSocial->addMarkers($aMarkers);
  91. return array_merge($aItems, $oSocial->getMenuItems());
  92. }
  93. protected function _setBrowseParams($aBrowseParams = array())
  94. {
  95. $aMarkers = array();
  96. foreach($aBrowseParams as $sKey => $mixedValue)
  97. if(!is_array($aMarkers))
  98. $aMarkers[$sKey] = $mixedValue;
  99. $this->addMarkers($aMarkers);
  100. $this->addMarkers(array(
  101. 'js_object_view' => $this->_oModule->_oConfig->getJsObjectView($aBrowseParams)
  102. ));
  103. }
  104. /**
  105. * Check if menu items is visible.
  106. * @param $a menu item array
  107. * @return boolean
  108. */
  109. protected function _isVisible ($a)
  110. {
  111. if(!parent::_isVisible($a))
  112. return false;
  113. if(empty($this->_aEvent) || !is_array($this->_aEvent))
  114. return false;
  115. $sCheckFuncName = '';
  116. $aCheckFuncParams = array();
  117. switch ($a['name']) {
  118. case 'item-repost':
  119. $sCheckFuncName = 'isAllowedRepost';
  120. $aCheckFuncParams = array($this->_aEvent);
  121. break;
  122. case 'item-send':
  123. $sCheckFuncName = 'isAllowedSend';
  124. $aCheckFuncParams = array($this->_aEvent);
  125. break;
  126. }
  127. if(!$sCheckFuncName || !method_exists($this->_oModule, $sCheckFuncName))
  128. return true;
  129. return call_user_func_array(array($this->_oModule, $sCheckFuncName), $aCheckFuncParams) === true;
  130. }
  131. }
  132. /** @} */