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