3 * FusionForge navigation
5 * Copyright 2009 - 2010, Olaf Lenz
7 * This file is part of FusionForge.
9 * FusionForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
14 * FusionForge is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with FusionForge; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 require_once $gfwww.'search/include/SearchManager.class.php';
28 * This class provides all the navigational elements to be used by the themes,
29 * like the site menu, the project menus, and the user links.
30 * Some of the methods return HTML code, some return abstract data
31 * structures, and some methods give you the choice. The HTML code
32 * always tries to be as generic as possible so that it can easily be
35 class Navigation extends Error {
37 * Associative array of data for the project menus.
39 * @var array $project_menu_data.
41 var $project_menu_data;
44 function Navigation() {
49 /** Get the HTML code of the title of the page. If the array
50 * $params contains a value for the key 'title', this title
51 * is appended to the title generated here. If $asHTML is
52 * set to false, it will return only the title in plain
54 function getTitle($params, $asHTML = true) {
57 if (!$params['title']) {
58 return forge_get_config('forge_name');
60 return forge_get_config('forge_name') . ': ' . $params['title'];
63 // return HTML code otherwise
64 return '<title>' . $this->getTitle($params, false) . '</title>';
68 /** Get the HTML code for the favicon links of the site (to be
69 * put into the <head>. If $asHTML is false, it will return
70 * the URL of the favicon.
72 * @todo: Make favicon configurable
74 function getFavIcon($asHTML=true) {
76 return util_make_url('/images/icon.png');
78 return '<link rel="icon" type="image/png" href="'
79 . $this->getFavIcon(false) .'" />'
80 . '<link rel="shortcut icon" type="image/png" href="'
81 . $this->getFavIcon(false) .'" />';
85 /** Get the HTML code for the RSS feeds of the site (to be put
86 * into the <head>. If $asHTML is false, it will return an
87 * array with the following structure: $result['titles']:
88 * list of titles of the feeds; $result['urls'] list of urls
90 function getRSS($asHTML=true) {
93 $res['titles'] = array();
94 $res['urls'] = array();
96 $res['titles'][] = forge_get_config ('forge_name').' - Project News Highlights RSS';
97 $res['urls'][] = util_make_url('/export/rss_sfnews.php');
99 $res['titles'][] = forge_get_config ('forge_name').' - Project News Highlights RSS 2.0';
100 $res['urls'][] = util_make_url('/export/rss20_news.php');
102 $res['titles'][] = forge_get_config ('forge_name').' - New Projects RSS';
103 $res['urls'][] = util_make_url('/export/rss_sfprojects.php');
105 if (isset($GLOBALS['group_id'])) {
106 $res['titles'][] = forge_get_config ('forge_name') . ' - New Activity RSS';
107 $res['urls'][] = util_make_url('/export/rss20_activity.php?group_id='.$GLOBALS['group_id']);
111 $feeds = $this->getRSS(false);
112 for ($j = 0; $j < count($feeds['urls']); $j++) {
114 <link rel="alternate" title="' . $feeds['titles'][$j]
115 . '" href="' . $feeds['urls'][$j]
116 . '" type="application/rss+xml"/>';
121 /** Get the searchBox HTML code. */
122 function getSearchBox() {
123 global $words,$forum_id,$group_id,$group_project_id,$atid,$exact,$type_of_search;
126 if (get_magic_quotes_gpc()) {
127 $defaultWords = stripslashes($words);
129 $defaultWords = $words;
132 $defaultWords = htmlspecialchars($defaultWords);
134 // if there is no search currently, set the default
135 if (!isset($type_of_search) ) {
139 $res .= '<form id="searchBox" action="'.util_make_uri('/search/').'" method="get">
142 SEARCH__PARAMETER_GROUP_ID => $group_id,
143 SEARCH__PARAMETER_ARTIFACT_ID => $atid,
144 SEARCH__PARAMETER_FORUM_ID => $forum_id,
145 SEARCH__PARAMETER_GROUP_PROJECT_ID => $group_project_id
148 $searchManager =& getSearchManager();
149 $searchManager->setParametersValues($parameters);
150 $searchEngines =& $searchManager->getAvailableSearchEngines();
152 $res .= '<label for="searchBox-words">
153 <select name="type_of_search">';
154 for($i = 0, $max = count($searchEngines); $i < $max; $i++) {
155 $searchEngine =& $searchEngines[$i];
156 $res .= '<option value="' . $searchEngine->getType() . '"'
157 . ( $type_of_search == $searchEngine->getType() ? ' selected="selected"' : '' )
158 . '>' . $searchEngine->getLabel($parameters) . '</option>' . "\n";
160 $res .= '</select></label>';
162 $parameters = $searchManager->getParameters();
163 foreach($parameters AS $name => $value) {
164 $res .= '<input type="hidden" value="'.$value.'" name="'.$name.'" />' . "\n";
166 $res .= '<input type="text" size="12" id="searchBox-words" name="words" value="'
167 . $defaultWords . '" />' . "\n";
168 $res .= '<input type="submit" name="Search" value="'._('Search').'" />' . "\n";
170 if (isset($group_id) && $group_id) {
171 $res .= util_make_link('/search/advanced_search.php?group_id=' .
172 $group_id, _('Advanced search'));
180 /** Get an array of the user links (Login/Logout/My
181 Account/Register) with the following structure:
182 $result['titles']: list of the titles. $result['urls']: list
185 function getUserLinks() {
187 if (session_loggedin()) {
188 $u =& user_get_object(user_getid());
189 $res['titles'][] = sprintf("%s (%s)", _('Log Out'), $u->getRealName());
190 $res['urls'][] = util_make_uri('/account/logout.php');
192 $res['titles'][] = _('My Account');
193 $res['urls'][] = util_make_uri('/account/');
195 $url = '/account/login.php';
196 if(getStringFromServer('REQUEST_METHOD') != 'POST') {
197 $url .= '?return_to=';
198 $url .= urlencode(getStringFromServer('REQUEST_URI'));
200 $res['titles'][] = _('Log In');
201 $res['urls'][] = util_make_url($url);
203 if (!forge_get_config ('user_registration_restricted')) {
204 $res['titles'][] = _('New Account');
205 $res['urls'][] = util_make_url('/account/register.php');
211 /** Get an array of the menu of the site with the following
212 * structure: $result['titles']: list of titles of the
213 * links. $result['urls']: list of urls. $result['selected']:
214 * number of the selected menu entry.
216 function getSiteMenu() {
217 $request_uri = getStringFromServer('REQUEST_URI');
220 $menu['titles'] = array();
221 $menu['urls'] = array();
225 $menu['titles'][] = _('Home');
226 $menu['urls'][] = util_make_uri('/');
229 $menu['titles'][] = _('My Page');
230 $menu['urls'][] = util_make_uri('/my/');
231 if (strstr($request_uri, util_make_uri('/my/'))
232 || strstr($request_uri, util_make_uri('/account/'))
233 || strstr($request_uri, util_make_uri('/register/'))
234 || strstr($request_uri, util_make_uri('/themes/'))
237 $selected=count($menu['urls'])-1;
240 if (forge_get_config('use_trove') || forge_get_config('use_project_tags') || forge_get_config('use_project_full_list')) {
241 $menu['titles'][] = _('Projects');
242 $menu['urls'][] = util_make_uri('/softwaremap/') ;
243 if (strstr($request_uri, util_make_uri('/softwaremap/'))) {
244 $selected=count($menu['urls'])-1;
248 if (forge_get_config('use_snippet')) {
249 $menu['titles'][] = _('Code Snippets');
250 $menu['urls'][] = util_make_uri('/snippet/') ;
251 if (strstr($request_uri, util_make_uri('/snippet/'))) {
252 $selected=count($menu['urls'])-1;
256 if (forge_get_config('use_people')) {
257 $menu['titles'][] = _('Project Openings');
258 $menu['urls'][] = util_make_uri('/people/') ;
259 if (strstr($request_uri, util_make_uri('/people/'))) {
260 $selected=count($menu['urls'])-1;
265 $before = count($menu['urls']);
266 $plugin_urls = array();
267 $hookParams['DIRS'] = &$menu['urls'];
268 $hookParams['TITLES'] = &$menu['titles'];
269 plugin_hook ("outermenu", $hookParams);
271 // try to find selected entry
272 for ($j = $before; $j < count($plugin_urls); $j++) {
273 $url = $menu['urls'][$j];
274 if (strstr($request_uri, parse_url ($url, PHP_URL_PATH))) {
280 // Admin and Reporting
281 if (forge_check_global_perm ('forge_admin')) {
282 $user_is_super = true;
283 $menu['titles'][] = _('Site Admin');
284 $menu['urls'][] = util_make_url('/admin/') ;
285 if (strstr($request_uri, util_make_uri('/admin/'))) {
286 $selected=count($menu['urls'])-1;
289 if (forge_check_global_perm ('forge_stats', 'read')) {
290 $menu['titles'][] = _('Reporting');
291 $menu['urls'][] = util_make_uri('/reporting/') ;
292 if (strstr($request_uri, util_make_uri('/reporting/'))) {
293 $selected=count($menu['urls'])-1;
298 if (isset($GLOBALS['group_id'])) {
299 // get group info using the common result set
300 $project =& group_get_object($GLOBALS['group_id']);
301 if ($project && is_object($project)) {
302 if ($project->isError()) {
303 } elseif (!$project->isProject()) {
305 $menu['titles'][] = $project->getPublicName();
306 if (isset ($GLOBALS['sys_noforcetype']) && $GLOBALS['sys_noforcetype']) {
307 $menu['urls'][]=util_make_uri('/project/?group_id') .$project->getId();
309 $menu['urls'][]=util_make_uri('/projects/') .$project->getUnixName().'/';
311 $selected=count($menu['urls'])-1;
316 $menu['selected'] = $selected;
321 /** Get a reference to an array of the projects menu for the
322 * project with the id $group_id with the following
323 * structure: $result['starturl']: URL of the
324 * projects starting page; $result['name']: public name of
325 * the project; $result['titles']: list of titles of the menu
326 * entries; $result['urls']: list of urls of the menu
327 * entries; $result['adminurls']: list of urls to the admin
328 * pages of the menu entries. If the user has no admin
329 * permissions, the correpsonding adminurl is
330 * false. $result['selected']: number of the menu entry that
331 * is currently selected.
333 function getProjectMenu($group_id, $toptab="") {
334 // rebuild menu if it has never been built before, or
335 // if the toptab was set differently
336 if (!isset($this->project_menu_data[$group_id])
338 || ($toptab != $this->project_menu_data[$group_id]['last_toptab'])) {
339 // get the group and permission objects
340 $group = group_get_object($group_id);
341 if (!$group || !is_object($group)) {
344 if ($group->isError()) {
345 //wasn't found or some other problem
348 if (!$group->isProject()) {
354 $menu =& $this->project_menu_data[$group_id];
355 $menu['titles'] = array();
356 $menu['urls'] = array();
357 $menu['adminurls'] = array();
359 $menu['name'] = $group->getPublicName();
362 $menu['titles'][] = _('Summary');
363 if (isset ($GLOBALS['sys_noforcetype']) && $GLOBALS['sys_noforcetype']) {
364 $url = util_make_uri('/project/?group_id=' . $group_id);
366 $url = util_make_uri('/projects/' . $group->getUnixName() .'/');
368 $menu['urls'][] = $url;
369 $menu['adminurls'][] = false;
370 if ($toptab == "home") {
371 $selected = (count($menu['urls'])-1);
374 // setting these allows to change the initial project page
375 $menu['starturl'] = $url;
378 if (forge_check_perm ('project_admin', $group_id)) {
379 $menu['titles'][] = _('Admin');
380 $menu['urls'][] = util_make_uri('/project/admin/?group_id=' . $group_id);
381 $menu['adminurls'][] = false;
382 if ($toptab == "admin") {
383 $selected = (count($menu['urls'])-1);
388 // check for use_home_tab?
389 $TABS_DIRS[]='http://'. $this->getHomePage();
390 $TABS_TITLES[]=_('Home Page');
393 // Project Activity tab
394 $menu['titles'][] = _('Activity');
395 $menu['urls'][] = util_make_uri('/activity/?group_id=' . $group_id);
396 $menu['adminurls'][] = false;
397 if ($toptab == "activity") {
398 $selected = (count($menu['urls'])-1);
402 if ($group->usesForum()) {
403 $menu['titles'][] = _('Forums');
404 $menu['urls'][] = util_make_uri('/forum/?group_id=' . $group_id);
405 if (forge_check_perm ('forum_admin', $group_id)) {
406 $menu['adminurls'][] = util_make_url('/forum/admin/?group_id='.$group_id);
408 $menu['adminurls'][] = false;
410 if ($toptab == "forums") {
411 $selected = (count($menu['urls'])-1);
416 if ($group->usesTracker()) {
417 $menu['titles'][] = _('Tracker');
418 $menu['urls'][] = util_make_uri('/tracker/?group_id=' . $group_id);
419 if (forge_check_perm ('tracker_admin', $group_id)) {
420 $menu['adminurls'][] = util_make_url('/tracker/admin/?group_id='.$group_id);
422 $menu['adminurls'][] = false;
424 if ($toptab == "tracker" ||
426 $toptab == "support" ||
427 $toptab == "patch") {
428 $selected = (count($menu['urls'])-1);
433 if ($group->usesMail()) {
434 $menu['titles'][] = _('Lists');
435 $menu['urls'][] = util_make_uri('/mail/?group_id=' . $group_id);
436 if (forge_check_perm ('project_admin', $group_id)) {
437 $menu['adminurls'][] = util_make_url('/mail/admin/?group_id='.$group_id);
439 $menu['adminurls'][] = false;
441 if ($toptab == "mail") {
442 $selected = (count($menu['urls'])-1);
446 // Project/Task Manager
447 if ($group->usesPm()) {
448 $menu['titles'][] = _('Tasks');
449 $menu['urls'][] = util_make_uri('/pm/?group_id=' . $group_id);
450 if (forge_check_perm ('pm_admin', $group_id)) {
451 $menu['adminurls'][] = util_make_uri('/pm/admin/?group_id='.$group_id);
453 $menu['adminurls'][] = false;
455 if ($toptab == "pm") {
456 $selected = (count($menu['urls'])-1);
461 if ($group->usesDocman()) {
462 $menu['titles'][] = _('Docs');
463 $menu['urls'][] = util_make_uri('/docman/?group_id=' . $group_id);
464 if (forge_check_perm ('docman', $group_id, 'approve')) {
465 $menu['adminurls'][] = util_make_uri('/docman/?group_id='.$group_id.'&view=admin');
467 $menu['adminurls'][] = false;
469 if ($toptab == "docman") {
470 $selected = (count($menu['urls'])-1);
475 if ($group->usesSurvey()) {
476 $menu['titles'][] = _('Surveys');
477 $menu['urls'][] = util_make_uri('/survey/?group_id=' . $group_id);
478 if (forge_check_perm ('project_admin', $group_id)) {
479 $menu['adminurls'][] = util_make_uri('/survey/admin/?group_id='.$group_id);
481 $menu['adminurls'][] = false;
483 if ($toptab == "surveys") {
484 $selected = (count($menu['urls'])-1);
489 if ($group->usesNews()) {
490 $menu['titles'][] = _('News');
491 $menu['urls'][] = util_make_uri('/news/?group_id=' . $group_id);
492 if (forge_check_perm ('project_admin', $group_id)) {
493 $menu['adminurls'][] = util_make_uri('/news/admin/?group_id='.$group_id);
495 $menu['adminurls'][] = false;
497 if ($toptab == "news") {
498 $selected = (count($menu['urls'])-1);
503 if ($group->usesSCM()) {
504 $menu['titles'][] = _('SCM');
505 $menu['urls'][] = util_make_uri('/scm/?group_id=' . $group_id);
507 if (forge_check_perm ('project_admin', $group_id)) {
508 $menu['adminurls'][] = util_make_uri('/scm/admin/?group_id='.$group_id);
510 $menu['adminurls'][] = false;
512 if ($toptab == "scm") {
513 $selected = (count($menu['urls'])-1);
517 // groupmenu_after_scm hook
518 $hookParams = array();
519 $hookParams['group_id'] = $group_id ;
520 $hookParams['DIRS'] =& $menu['urls'];
521 $hookParams['TITLES'] =& $menu['titles'];
522 $hookParams['toptab'] =& $toptab;
523 $hookParams['selected'] =& $selected;
524 plugin_hook ("groupmenu_scm", $hookParams) ;
527 for ($i = 0; $i < count($menu['urls']) - count($menu['adminurls']); $i++) {
528 $menu['adminurls'][] = false;
532 if ($group->usesFRS()) {
533 $menu['titles'][] = _('Files');
534 $menu['urls'][] = util_make_uri('/frs/?group_id=' . $group_id);
535 if (forge_check_perm ('frs', $group_id, 'write')) {
536 $menu['adminurls'][] = util_make_uri('/frs/admin/?group_id='.$group_id);
538 $menu['adminurls'][] = false;
540 if ($toptab == "frs") {
541 $selected = (count($menu['urls'])-1);
546 $hookParams = array();
547 $hookParams['group'] = $group_id ;
548 $hookParams['DIRS'] =& $menu['urls'];
549 $hookParams['TITLES'] =& $menu['titles'];
550 $hookParams['toptab'] =& $toptab;
551 $hookParams['selected'] =& $selected;
552 plugin_hook ("groupmenu", $hookParams) ;
555 for ($i = 0; $i < count($menu['urls']) - count($menu['adminurls']); $i++) {
556 $menu['adminurls'][] = false;
559 // store selected menu item (if any)
560 $menu['selected'] = $selected;
562 $menu['last_toptab'] = $toptab;
565 return $this->project_menu_data[$group_id] ;
569 * Create the HTML code for the banner "Powered By
570 * FusionForge". If $asHTML is set to false, it will return an
571 * array with the following structure: $result['url']: URL for
572 * the link on the banner; $result['image']: URL of the banner
573 * image; $result['title']: HTML code that outputs the banner;
574 * $result['html']: HTML code that creates the banner and the link.
576 function getPoweredBy($asHTML=true) {
577 $res['url'] = 'http://fusionforge.org/';
578 $res['image'] = util_make_uri('/images/pow-fusionforge.png');
579 $res['title'] = '<img src="'
581 . '" alt="Powered By FusionForge" border="0" />';
582 $res['html'] = util_make_link($res['url'], $res['title'], array(), true);
590 /** Create the HTML code for the "Show Source" link if
591 * forge_get_config('show_source') is set, otherwise "". If $asHTML is set
592 * to false, it returns NULL when forge_get_config('show_source') is not
593 * set, otherwise an array with the following structure:
594 * $result['url']: URL of the link to the source code viewer;
595 * $result['title']: Title of the link.
597 function getShowSource($asHTML=true) {
598 if (forge_get_config('show_source')) {
599 $res['url'] = util_make_url('/source.php?file='.getStringFromServer('SCRIPT_NAME'));
600 $res['title'] = _('Show source');
602 return ($asHTML ? "" : NULL);
607 return util_make_link($res['url'], $res['title'],
608 array('class' => 'showsource'),
616 // c-file-style: "bsd"