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