1
0

BxBaseMenuCreatePost.php 2.6 KB

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