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