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