]> git.mxchange.org Git - friendica.git/blob - include/nav.php
Merge pull request #3879 from zeroadam/Remove-Includes-#3873
[friendica.git] / include / nav.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Core\Config;
5 use Friendica\Core\System;
6
7 function nav(App $a) {
8
9         /*
10          *
11          * Build page header and site navigation bars
12          *
13          */
14
15         if (!(x($a->page,'nav')))
16                 $a->page['nav'] = '';
17
18         $a->page['htmlhead'] .= replace_macros(get_markup_template('nav_head.tpl'), array());
19
20         /*
21          * Placeholder div for popup panel
22          */
23
24         $a->page['nav'] .= '<div id="panel" style="display: none;"></div>' ;
25
26         $nav_info = nav_info($a);
27
28         /*
29          * Build the page
30          */
31
32         $tpl = get_markup_template('nav.tpl');
33
34         $a->page['nav'] .= replace_macros($tpl, array(
35                 '$baseurl' => System::baseUrl(),
36                 '$sitelocation' => $nav_info['sitelocation'],
37                 '$nav' => $nav_info['nav'],
38                 '$banner' => $nav_info['banner'],
39                 '$emptynotifications' => t('Nothing new here'),
40                 '$userinfo' => $nav_info['userinfo'],
41                 '$sel' =>  $a->nav_sel,
42                 '$apps' => $a->apps,
43                 '$clear_notifs' => t('Clear notifications'),
44                 '$search_hint' => t('@name, !forum, #tags, content')
45         ));
46
47         call_hooks('page_header', $a->page['nav']);
48 }
49
50 /**
51  * @brief Prepares a list of navigation links
52  *
53  * @param App $a
54  * @return array Navigation links
55  *      string 'sitelocation' => The webbie (username@site.com)
56  *      array 'nav' => Array of links used in the nav menu
57  *      string 'banner' => Formatted html link with banner image
58  *      array 'userinfo' => Array of user information (name, icon)
59  */
60 function nav_info(App $a)
61 {
62         $ssl_state = ((local_user()) ? true : false);
63
64         /*
65          * Our network is distributed, and as you visit friends some of the
66          * sites look exactly the same - it isn't always easy to know where you are.
67          * Display the current site location as a navigation aid.
68          */
69
70         $myident = ((is_array($a->user) && isset($a->user['nickname'])) ? $a->user['nickname'] . '@' : '');
71
72         $sitelocation = $myident . substr(System::baseUrl($ssl_state), strpos(System::baseUrl($ssl_state), '//') + 2 );
73
74         // nav links: array of array('href', 'text', 'extra css classes', 'title')
75         $nav = array();
76
77         // Display login or logout
78         $nav['usermenu'] = array();
79         $userinfo = null;
80
81         if (local_user()) {
82                 $nav['logout'] = array('logout', t('Logout'), '', t('End this session'));
83
84                 // user menu
85                 $nav['usermenu'][] = array('profile/' . $a->user['nickname'], t('Status'), '', t('Your posts and conversations'));
86                 $nav['usermenu'][] = array('profile/' . $a->user['nickname'] . '?tab=profile', t('Profile'), '', t('Your profile page'));
87                 $nav['usermenu'][] = array('photos/' . $a->user['nickname'], t('Photos'), '', t('Your photos'));
88                 $nav['usermenu'][] = array('videos/' . $a->user['nickname'], t('Videos'), '', t('Your videos'));
89                 $nav['usermenu'][] = array('events/', t('Events'), '', t('Your events'));
90                 $nav['usermenu'][] = array('notes/', t('Personal notes'), '', t('Your personal notes'));
91
92                 // user info
93                 $r = dba::select('contact', array('micro'), array('uid' => $a->user['uid'], 'self' => true), array('limit' => 1));
94                 $userinfo = array(
95                         'icon' => (dbm::is_result($r) ? $a->remove_baseurl($r['micro']) : 'images/person-48.jpg'),
96                         'name' => $a->user['username'],
97                 );
98         } else {
99                 $nav['login'] = array('login', t('Login'), ($a->module == 'login' ? 'selected' : ''), t('Sign in'));
100         }
101
102         // "Home" should also take you home from an authenticated remote profile connection
103         $homelink = get_my_url();
104         if (! $homelink) {
105                 $homelink = ((x($_SESSION,'visitor_home')) ? $_SESSION['visitor_home'] : '');
106         }
107
108         if (($a->module != 'home') && (! (local_user()))) {
109                 $nav['home'] = array($homelink, t('Home'), '', t('Home Page'));
110         }
111
112         if (($a->config['register_policy'] == REGISTER_OPEN) && (! local_user()) && (! remote_user())) {
113                 $nav['register'] = array('register', t('Register'), '', t('Create an account'));
114         }
115
116         $help_url = 'help';
117
118         if (!Config::get('system', 'hide_help')) {
119                 $nav['help'] = array($help_url, t('Help'), '', t('Help and documentation'));
120         }
121
122         if (count($a->apps) > 0) {
123                 $nav['apps'] = array('apps', t('Apps'), '', t('Addon applications, utilities, games'));
124         }
125
126         if (local_user() || !Config::get('system', 'local_search')) {
127                 $nav['search'] = array('search', t('Search'), '', t('Search site content'));
128
129                 $nav['searchoption'] = array(
130                                                 t('Full Text'),
131                                                 t('Tags'),
132                                                 t('Contacts'));
133
134                 if (Config::get('system', 'poco_local_search')) {
135                         $nav['searchoption'][] = t('Forums');
136                 }
137         }
138
139         $gdirpath = 'directory';
140
141         if (strlen(Config::get('system', 'singleuser'))) {
142                 $gdir = Config::get('system', 'directory');
143                 if (strlen($gdir)) {
144                         $gdirpath = zrl($gdir, true);
145                 }
146         } elseif (Config::get('system', 'community_page_style') == CP_USERS_ON_SERVER) {
147                 $nav['community'] = array('community', t('Community'), '', t('Conversations on this site'));
148         } elseif (Config::get('system', 'community_page_style') == CP_GLOBAL_COMMUNITY) {
149                 $nav['community'] = array('community', t('Community'), '', t('Conversations on the network'));
150         }
151
152         if (local_user()) {
153                 $nav['events'] = array('events', t('Events'), '', t('Events and Calendar'));
154         }
155
156         $nav['directory'] = array($gdirpath, t('Directory'), '', t('People directory'));
157
158         $nav['about'] = array('friendica', t('Information'), '', t('Information about this friendica instance'));
159
160         // The following nav links are only show to logged in users
161         if (local_user()) {
162                 $nav['network'] = array('network', t('Network'), '', t('Conversations from your friends'));
163                 $nav['net_reset'] = array('network/0?f=&order=comment&nets=all', t('Network Reset'), '', t('Load Network page with no filters'));
164
165                 $nav['home'] = array('profile/' . $a->user['nickname'], t('Home'), '', t('Your posts and conversations'));
166
167                 if (in_array($_SESSION['page_flags'], array(PAGE_NORMAL, PAGE_SOAPBOX, PAGE_FREELOVE, PAGE_PRVGROUP))) {
168                         // only show friend requests for normal pages. Other page types have automatic friendship.
169                         if (in_array($_SESSION['page_flags'], array(PAGE_NORMAL, PAGE_SOAPBOX, PAGE_PRVGROUP))) {
170                                 $nav['introductions'] = array('notifications/intros', t('Introductions'), '', t('Friend Requests'));
171                         }
172                         if (in_array($_SESSION['page_flags'], array(PAGE_NORMAL, PAGE_SOAPBOX, PAGE_FREELOVE))) {
173                                 $nav['notifications'] = array('notifications',  t('Notifications'), '', t('Notifications'));
174                                 $nav['notifications']['all'] = array('notifications/system', t('See all notifications'), '', '');
175                                 $nav['notifications']['mark'] = array('', t('Mark as seen'), '', t('Mark all system notifications seen'));
176                         }
177                 }
178
179                 $nav['messages'] = array('message', t('Messages'), '', t('Private mail'));
180                 $nav['messages']['inbox'] = array('message', t('Inbox'), '', t('Inbox'));
181                 $nav['messages']['outbox'] = array('message/sent', t('Outbox'), '', t('Outbox'));
182                 $nav['messages']['new'] = array('message/new', t('New Message'), '', t('New Message'));
183
184                 if (is_array($a->identities) && count($a->identities) > 1) {
185                         $nav['manage'] = array('manage', t('Manage'), '', t('Manage other pages'));
186                 }
187
188                 $nav['delegations'] = array('delegate', t('Delegations'), '', t('Delegate Page Management'));
189
190                 $nav['settings'] = array('settings', t('Settings'), '', t('Account settings'));
191
192                 if (feature_enabled(local_user(), 'multi_profiles')) {
193                         $nav['profiles'] = array('profiles', t('Profiles'), '', t('Manage/Edit Profiles'));
194                 }
195
196                 $nav['contacts'] = array('contacts', t('Contacts'), '', t('Manage/edit friends and contacts'));
197         }
198
199         // Show the link to the admin configuration page if user is admin
200         if (is_site_admin()) {
201                 $nav['admin'] = array('admin/', t('Admin'), '', t('Site setup and configuration'));
202         }
203
204         $nav['navigation'] = array('navigation/', t('Navigation'), '', t('Site map'));
205
206         // Provide a banner/logo/whatever
207         $banner = Config::get('system', 'banner');
208         if ($banner === false) {
209                 $banner = '<a href="https://friendi.ca"><img id="logo-img" src="images/friendica-32.png" alt="logo" /></a><span id="logo-text"><a href="https://friendi.ca">Friendica</a></span>';
210         }
211
212         call_hooks('nav_info', $nav);
213
214         return array(
215                 'sitelocation' => $sitelocation,
216                 'nav' => $nav,
217                 'banner' => $banner,
218                 'userinfo' => $userinfo,
219         );
220 }
221
222 /**
223  * Set a menu item in navbar as selected
224  *
225  */
226 function nav_set_selected($item){
227         $a = get_app();
228         $a->nav_sel = array(
229                 'community'     => null,
230                 'network'       => null,
231                 'home'          => null,
232                 'profiles'      => null,
233                 'introductions' => null,
234                 'notifications' => null,
235                 'messages'      => null,
236                 'directory'     => null,
237                 'settings'      => null,
238                 'contacts'      => null,
239                 'manage'        => null,
240                 'events'        => null,
241                 'register'      => null,
242         );
243         $a->nav_sel[$item] = 'selected';
244 }