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