1
0

BxBaseMenuCreatePost.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. /**
  10. * Menu representation.
  11. * @see BxDolMenu
  12. */
  13. class BxBaseMenuCreatePost extends BxTemplMenuCustom
  14. {
  15. protected $_bShowDivider;
  16. protected $_sJsObject;
  17. protected $_mixedContextId;
  18. public function __construct ($aObject, $oTemplate)
  19. {
  20. parent::__construct ($aObject);
  21. $this->_aObject['menu_id'] = 'sys-create-post-menu';
  22. $this->_bShowDivider = false;
  23. $this->_sJsObject = 'oBxDolCreatePost';
  24. $this->_mixedContextId = false;
  25. }
  26. public function setContextId($mixedContextId)
  27. {
  28. $this->_mixedContextId = $mixedContextId;
  29. }
  30. protected function getMenuItemsRaw ()
  31. {
  32. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'all_pairs_name_uri', 'active' => 1));
  33. $aResult = array();
  34. $aMenuItems = $this->_oQuery->getMenuItems();
  35. foreach($aMenuItems as $iKey => $aMenuItem) {
  36. if((int)$aMenuItem['active'] == 0)
  37. continue;
  38. $sModule = $aMenuItem['module'];
  39. if(!isset($aModules[$sModule]))
  40. continue;
  41. if($this->_mixedContextId !== false && ($aContextInfo = BxDolProfileQuery::getInstance()->getInfoById(abs($this->_mixedContextId)))) {
  42. if(BxDolRequest::serviceExists($sModule, 'act_as_profile'))
  43. continue;
  44. if(bx_srv($aContextInfo['type'], 'check_allowed_post_in_profile', [$aContextInfo['content_id'], $sModule]) !== CHECK_ACTION_RESULT_ALLOWED)
  45. continue;
  46. }
  47. $aResult[$iKey] = array_merge($aMenuItem, array(
  48. 'id' => $sModule,
  49. 'name' => $sModule,
  50. 'onclick' => "return " . $this->_sJsObject . ".getForm('" . $sModule . "', '" . $aModules[$sModule] . "', this)"
  51. ));
  52. }
  53. if(!empty($aResult) && is_array($aResult))
  54. $aResult['more-auto'] = array(
  55. 'module' => 'system',
  56. 'id' => 'more-auto',
  57. 'name' => 'more-auto',
  58. 'title' => '_sys_menu_item_title_va_more_auto_empty',
  59. 'href' => 'javascript:void(0)',
  60. 'icon' => 'ellipsis-v',
  61. 'active' => 1
  62. );
  63. return $aResult;
  64. }
  65. }
  66. /** @} */