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