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