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