BxTimelineMenuItem.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Persons Persons
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxTemplMenu');
  12. /**
  13. * 'Item' menu.
  14. */
  15. class BxTimelineMenuItem extends BxTemplMenu {
  16. protected $_aEvent;
  17. protected $_oModule;
  18. public function __construct($aObject, $oTemplate = false) {
  19. parent::__construct($aObject, $oTemplate);
  20. $this->_oModule = BxDolModule::getInstance('bx_timeline');
  21. $this->addMarkers(array(
  22. 'js_object_view' => $this->_oModule->_oConfig->getJsObject('view'),
  23. ));
  24. }
  25. public function setEvent($aEvent)
  26. {
  27. if(empty($aEvent) || !is_array($aEvent))
  28. return;
  29. $this->_aEvent = $aEvent;
  30. $sCommentsSystem = '';
  31. $iCommentsCount = 0;
  32. if(isset($aEvent['comments']) && is_array($aEvent['comments']) && isset($aEvent['comments']['system'])) {
  33. $sCommentsSystem = $aEvent['comments']['system'];
  34. $iCommentsCount = (int)$aEvent['comments']['count'];
  35. }
  36. $sCommonPrefix = $this->_oModule->_oConfig->getPrefix('common_post');
  37. $iOwnerId = $this->_oModule->getUserId(); //--- in whose timeline the content will be shared
  38. $sType = $aEvent['type'];
  39. $sAction = $aEvent['action'];
  40. if($this->_oModule->_oConfig->isSystem($sType, $sAction))
  41. $iObjectId = $aEvent['object_id'];
  42. else {
  43. $iObjectId = $aEvent['id'];
  44. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_SHARE) {
  45. $sType = $aEvent['content']['type'];
  46. $sAction = $aEvent['content']['action'];
  47. $iObjectId = $aEvent['content']['object_id'];
  48. }
  49. }
  50. $this->addMarkers(array(
  51. //--- For Share Button
  52. 'share_onclick' => $this->_oModule->serviceGetShareOnclick($iOwnerId, $sType, $sAction, $iObjectId),
  53. //--- For Share Button
  54. 'counter_shares' => (int)$aEvent['shares'] > 0 ? ' (' . $aEvent['shares'] . ')' : '',
  55. 'counter_comments' => $iCommentsCount > 0 ? ' (' . $iCommentsCount . ')' : '',
  56. 'content_id' => $aEvent['id'],
  57. 'comments_system' => $sCommentsSystem
  58. ));
  59. }
  60. /**
  61. * Check if menu items is visible.
  62. * @param $a menu item array
  63. * @return boolean
  64. */
  65. protected function _isVisible ($a) {
  66. if(!parent::_isVisible($a))
  67. return false;
  68. $sCheckFuncName = '';
  69. $aCheckFuncParams = array();
  70. switch ($a['name']) {
  71. case 'item-delete':
  72. $sCheckFuncName = 'isAllowedDelete';
  73. if(!empty($this->_aEvent))
  74. $aCheckFuncParams = array($this->_aEvent);
  75. break;
  76. case 'item-comment':
  77. $sCheckFuncName = 'isAllowedComment';
  78. if(!empty($this->_aEvent))
  79. $aCheckFuncParams = array($this->_aEvent);
  80. break;
  81. case 'item-vote':
  82. $sCheckFuncName = 'isAllowedVote';
  83. if(!empty($this->_aEvent))
  84. $aCheckFuncParams = array($this->_aEvent);
  85. break;
  86. case 'item-share':
  87. $sCheckFuncName = 'isAllowedShare';
  88. if(!empty($this->_aEvent))
  89. $aCheckFuncParams = array($this->_aEvent);
  90. break;
  91. }
  92. if(!$sCheckFuncName || !method_exists($this->_oModule, $sCheckFuncName))
  93. return true;
  94. return call_user_func_array(array($this->_oModule, $sCheckFuncName), $aCheckFuncParams);
  95. }
  96. }
  97. /** @} */