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