]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/Nav.php
Move $apps out of App
[friendica.git] / src / Content / Nav.php
index 4f6f4ae0b905adc3832da6e8abf56db386922ff3..8289825eade47587a67017f7bcee64be49542134 100644 (file)
@@ -15,50 +15,102 @@ use Friendica\Model\Contact;
 use Friendica\Model\Profile;
 
 require_once 'boot.php';
-require_once 'dba.php';
 require_once 'include/text.php';
 
 class Nav
 {
+       private static $selected = [
+               'global'    => null,
+               'community' => null,
+               'network'   => null,
+               'home'      => null,
+               'profiles'  => null,
+               'introductions' => null,
+               'notifications' => null,
+               'messages'  => null,
+               'directory' => null,
+               'settings'  => null,
+               'contacts'  => null,
+               'manage'    => null,
+               'events'    => null,
+               'register'  => null
+       ];
+
+       /**
+        * An array of HTML links provided by addons providing a module via the app_menu hook
+        *
+        * @var array
+        */
+       private static $app_menu = null;
+
+       /**
+        * Set a menu item in navbar as selected
+        */
+       public static function setSelected($item)
+       {
+               self::$selected[$item] = 'selected';
+       }
+
        /**
         * Build page header and site navigation bars
         */
        public static function build(App $a)
        {
-               if (!(x($a->page, 'nav'))) {
-                       $a->page['nav'] = '';
-               }
-
-               $a->page['htmlhead'] .= replace_macros(get_markup_template('nav_head.tpl'), []);
-
-               /*
-                * Placeholder div for popup panel
-                */
-
-               $a->page['nav'] .= '<div id="panel" style="display: none;"></div>' ;
+               // Placeholder div for popup panel
+               $nav = '<div id="panel" style="display: none;"></div>' ;
 
                $nav_info = self::getInfo($a);
 
-               /*
-                * Build the page
-                */
-
                $tpl = get_markup_template('nav.tpl');
 
-               $a->page['nav'] .= replace_macros($tpl, [
-                       '$baseurl' => System::baseUrl(),
+               $nav .= replace_macros($tpl, [
+                       '$baseurl'      => System::baseUrl(),
                        '$sitelocation' => $nav_info['sitelocation'],
-                       '$nav' => $nav_info['nav'],
-                       '$banner' => $nav_info['banner'],
+                       '$nav'          => $nav_info['nav'],
+                       '$banner'       => $nav_info['banner'],
                        '$emptynotifications' => L10n::t('Nothing new here'),
-                       '$userinfo' => $nav_info['userinfo'],
-                       '$sel' =>  $a->nav_sel,
-                       '$apps' => $a->apps,
+                       '$userinfo'     => $nav_info['userinfo'],
+                       '$sel'          => self::$selected,
+                       '$apps'         => self::getAppMenu(),
                        '$clear_notifs' => L10n::t('Clear notifications'),
-                       '$search_hint' => L10n::t('@name, !forum, #tags, content')
+                       '$search_hint'  => L10n::t('@name, !forum, #tags, content')
                ]);
 
-               Addon::callHooks('page_header', $a->page['nav']);
+               Addon::callHooks('page_header', $nav);
+
+               return $nav;
+       }
+
+       /**
+        * Returns the addon app menu
+        *
+        * @return array
+        */
+       public static function getAppMenu()
+       {
+               if (is_null(self::$app_menu)) {
+                       self::populateAppMenu();
+               }
+
+               return self::$app_menu;
+       }
+
+       /**
+        * Fills the apps static variable with apps that require a menu
+        */
+       private static function populateAppMenu()
+       {
+               self::$app_menu = [];
+
+               //Don't populate apps_menu if apps are private
+               $privateapps = Config::get('config', 'private_addons', false);
+               if (local_user() || !$privateapps) {
+                       $arr = ['app_menu' => self::$app_menu];
+
+                       Addon::callHooks('app_menu', $arr);
+
+                       self::$app_menu = $arr['app_menu'];
+               }
        }
 
        /**
@@ -134,7 +186,7 @@ class Nav
                        $nav['help'] = [$help_url, L10n::t('Help'), '', L10n::t('Help and documentation')];
                }
 
-               if (count($a->apps) > 0) {
+               if (count(self::getAppMenu()) > 0) {
                        $nav['apps'] = ['apps', L10n::t('Apps'), '', L10n::t('Addon applications, utilities, games')];
                }
 
@@ -235,29 +287,4 @@ class Nav
                        'userinfo' => $userinfo,
                ];
        }
-
-       /**
-        * Set a menu item in navbar as selected
-        */
-       public static function setSelected($item)
-       {
-               $a = get_app();
-               $a->nav_sel = [
-                       'global'        => null,
-                       'community'     => null,
-                       'network'       => null,
-                       'home'          => null,
-                       'profiles'      => null,
-                       'introductions' => null,
-                       'notifications' => null,
-                       'messages'      => null,
-                       'directory'     => null,
-                       'settings'      => null,
-                       'contacts'      => null,
-                       'manage'        => null,
-                       'events'        => null,
-                       'register'      => null
-               ];
-               $a->nav_sel[$item] = 'selected';
-       }
 }