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