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 $GLOBALS['sys_name'];
60 return $GLOBALS['sys_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'][] = $GLOBALS['sys_name'].' - Project News Highlights RSS';
97 $res['urls'][] = util_make_url('/export/rss_sfnews.php');
99 $res['titles'][] = $GLOBALS['sys_name'].' - Project News Highlights RSS 2.0';
100 $res['urls'][] = util_make_url('/export/rss20_news.php');
102 $res['titles'][] = $GLOBALS['sys_name'].' - New Projects RSS';
103 $res['urls'][] = util_make_url('/export/rss_sfprojects.php');
105 if (isset($GLOBALS['group_id'])) {
106 $res['titles'][] = $GLOBALS['sys_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_url ('/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'));
181 /** Get an array of the user links (Login/Logout/My
182 Account/Register) with the following structure:
183 $result['titles']: list of the titles. $result['urls']: list
186 function getUserLinks() {
188 if (session_loggedin()) {
189 $u =& user_get_object(user_getid());
190 $res['titles'][] = sprintf("%s (%s)", _('Log Out'), $u->getRealName());
191 $res['urls'][] = util_make_url ('/account/logout.php');
193 $res['titles'][] = _('My Account');
194 $res['urls'][] = util_make_url ('/account/');
196 $url = '/account/login.php';
197 if(getStringFromServer('REQUEST_METHOD') != 'POST') {
198 $url .= '?return_to=';
199 $url .= urlencode(getStringFromServer('REQUEST_URI'));
201 $res['titles'][] = _('Log In');
202 $res['urls'][] = util_make_url($url);
204 if (!$GLOBALS['sys_user_reg_restricted']) {
205 $res['titles'][] = _('New Account');
206 $res['urls'][] = util_make_url('/account/register.php');
212 /** Get an array of the menu of the site with the following
213 * structure: $result['titles']: list of titles of the
214 * links. $result['urls']: list of urls. $result['selected']:
215 * number of the selected menu entry.
217 function getSiteMenu() {
218 global $sys_use_trove,$sys_use_snippet,$sys_use_people,$sys_use_project_tags, $sys_use_project_full_list;
220 $request_uri = getStringFromServer('REQUEST_URI');
223 $menu['titles'] = array();
224 $menu['urls'] = array();
228 $menu['titles'][] = _('Home');
229 $menu['urls'][] = util_make_url ('/');
232 $menu['titles'][] = _('My Page');
233 $menu['urls'][] = util_make_url ('/my/');
234 if (strstr($request_uri, util_make_uri('/my/'))
235 || strstr($request_uri, util_make_uri('/account/'))
236 || strstr($request_uri, util_make_uri('/register/'))
237 || strstr($request_uri, util_make_uri('/themes/'))
240 $selected=count($menu['urls'])-1;
243 if ($sys_use_trove || $sys_use_project_tags || $sys_use_project_full_list) {
244 $menu['titles'][] = _('Projects');
245 $menu['urls'][] = util_make_url ('/softwaremap/') ;
246 if (strstr($request_uri, util_make_uri('/softwaremap/'))) {
247 $selected=count($menu['urls'])-1;
251 if ($sys_use_snippet) {
252 $menu['titles'][] = _('Code Snippets');
253 $menu['urls'][] = util_make_url ('/snippet/') ;
254 if (strstr($request_uri, util_make_uri('/snippet/'))) {
255 $selected=count($menu['urls'])-1;
259 if ($sys_use_people) {
260 $menu['titles'][] = _('Project Openings');
261 $menu['urls'][] = util_make_url ('/people/') ;
262 if (strstr($request_uri, util_make_uri('/people/'))) {
263 $selected=count($menu['urls'])-1;
268 $before = count($menu['urls']);
269 $plugin_urls = array();
270 $hookParams['DIRS'] = &$menu['urls'];
271 $hookParams['TITLES'] = &$menu['titles'];
272 plugin_hook ("outermenu", $hookParams) ;
274 // try to find selected entry
275 for ($j = $before; $j < count($plugin_urls); $j++) {
276 $url = $menu['urls'][$j];
277 if (strstr($request_uri, parse_url ($url, PHP_URL_PATH))) {
283 // Admin and Reporting
284 $user_is_super=false;
285 if (session_loggedin()) {
286 $projectmaster =& group_get_object(GROUP_IS_MASTER);
287 $projectstats =& group_get_object(GROUP_IS_STATS);
288 $permmaster =& $projectmaster->getPermission( session_get_user() );
289 $permstats =& $projectstats->getPermission( session_get_user() );
291 if ($permmaster->isAdmin()) {
292 $user_is_super = true;
293 $menu['titles'][] = _('Admin');
294 $menu['urls'][] = util_make_url('/admin/') ;
295 if (strstr($request_uri, util_make_uri('/admin/'))) {
296 $selected=count($menu['urls'])-1;
299 if ($permstats->isMember()) {
300 $menu['titles'][] = _('Reporting');
301 $menu['urls'][] = util_make_url ('/reporting/') ;
302 if (strstr($request_uri, util_make_uri('/reporting/'))) {
303 $selected=count($menu['urls'])-1;
309 if (isset($GLOBALS['group_id'])) {
310 // get group info using the common result set
311 $project =& group_get_object($GLOBALS['group_id']);
312 if ($project && is_object($project)) {
313 if ($project->isError()) {
314 } elseif (!$project->isProject()) {
316 $menu['titles'][] = $project->getPublicName();
317 if (isset ($GLOBALS['sys_noforcetype']) && $GLOBALS['sys_noforcetype']) {
318 $menu['urls'][]=util_make_url ('/project/?group_id') .$project->getId();
320 $menu['urls'][]=util_make_url ('/projects/') .$project->getUnixName().'/';
322 $selected=count($menu['urls'])-1;
328 $menu['selected'] = $selected;
334 /** Get a reference to an array of the projects menu for the
335 * project with the id $group_id with the following
336 * structure: $result['starturl']: URL of the
337 * projects starting page; $result['name']: public name of
338 * the project; $result['titles']: list of titles of the menu
339 * entries; $result['urls']: list of urls of the menu
340 * entries; $result['adminurls']: list of urls to the admin
341 * pages of the menu entries. If the user has no admin
342 * permissions, the correpsonding adminurl is
343 * false. $result['selected']: number of the menu entry that
344 * is currently selected.
346 function &getProjectMenu ($group_id, $toptab="") {
347 // rebuild menu if it has never been built before, or
348 // if the toptab was set differently
349 if (!isset($this->project_menu_data[$group_id])
351 || ($toptab != $this->project_menu_data[$group_id]['last_toptab']))
353 // get the group and permission objects
354 $group =& group_get_object($group_id);
355 if (!$group || !is_object($group)) {
358 if ($group->isError()) {
359 //wasn't found or some other problem
362 if (!$group->isProject()) {
366 $perm =& $group->getPermission( session_get_user() );
370 $menu =& $this->project_menu_data[$group_id];
371 $menu['titles'] = array();
372 $menu['urls'] = array();
373 $menu['adminurls'] = array();
375 $menu['name'] = $group->getPublicName();
378 $menu['titles'][] = _('Summary');
379 if (isset ($GLOBALS['sys_noforcetype']) && $GLOBALS['sys_noforcetype']) {
380 $url = util_make_url ('/project/?group_id=' . $group_id);
382 $url = util_make_url ('/projects/' . $group->getUnixName() .'/');
384 $menu['urls'][] = $url;
385 $menu['adminurls'][] = false;
386 if ($toptab == "home") {
387 $selected = (count($menu['urls'])-1);
390 // setting these allows to change the initial project page
391 $menu['starturl'] = $url;
394 if ($perm->isAdmin()) {
395 $menu['titles'][] = _('Admin');
396 $menu['urls'][] = util_make_url ('/project/admin/?group_id=' . $group_id);
397 $menu['adminurls'][] = false;
398 if ($toptab == "admin") {
399 $selected = (count($menu['urls'])-1);
404 // check for use_home_tab?
405 $TABS_DIRS[]='http://'. $this->getHomePage();
406 $TABS_TITLES[]=_('Home Page');
409 // Project Activity tab
410 $menu['titles'][] = _('Activity');
411 $menu['urls'][] = util_make_url ('/activity/?group_id=' . $group_id);
412 $menu['adminurls'][] = false;
413 if ($toptab == "activity") {
414 $selected = (count($menu['urls'])-1);
418 if ($group->usesForum()) {
419 $menu['titles'][] = _('Forums');
420 $menu['urls'][] = util_make_url ('/forum/?group_id=' . $group_id);
421 if ($perm->isAdmin() || $perm->isForumAdmin()) {
422 $menu['adminurls'][] = util_make_url('/forum/admin/?group_id='.$group_id);
424 $menu['adminurls'][] = false;
426 if ($toptab == "forums") {
427 $selected = (count($menu['urls'])-1);
432 if ($group->usesTracker()) {
433 $menu['titles'][] = _('Tracker');
434 $menu['urls'][] = util_make_url ('/tracker/?group_id=' . $group_id);
435 if ($perm->isAdmin() || $perm->isArtifactAdmin()) {
436 $menu['adminurls'][] = util_make_url('/tracker/admin/?group_id='.$group_id);
438 $menu['adminurls'][] = false;
440 if ($toptab == "tracker" ||
442 $toptab == "support" ||
443 $toptab == "patch") {
444 $selected = (count($menu['urls'])-1);
450 if ($group->usesMail()) {
451 $menu['titles'][] = _('Lists');
452 $menu['urls'][] = util_make_url ('/mail/?group_id=' . $group_id);
453 if ($perm->isAdmin()) {
454 $menu['adminurls'][] = util_make_url('/mail/admin/?group_id='.$group_id);
456 $menu['adminurls'][] = false;
458 if ($toptab == "mail") {
459 $selected = (count($menu['urls'])-1);
464 // Project/Task Manager
465 if ($group->usesPm()) {
466 $menu['titles'][] = _('Tasks');
467 $menu['urls'][] = util_make_url ('/pm/?group_id=' . $group_id);
468 if ($perm->isAdmin() || $perm->isPMAdmin()) {
469 $menu['adminurls'][] = util_make_url ('/pm/admin/?group_id='.$group_id);
471 $menu['adminurls'][] = false;
473 if ($toptab == "pm") {
474 $selected = (count($menu['urls'])-1);
480 if ($group->usesDocman()) {
481 $menu['titles'][] = _('Docs');
482 $menu['urls'][] = util_make_url ('/docman/?group_id=' . $group_id);
483 if ($perm->isAdmin() || $perm->isDocEditor()) {
484 $menu['adminurls'][] = util_make_url ('/docman/admin/?group_id='.$group_id);
486 $menu['adminurls'][] = false;
488 if ($toptab == "docman") {
489 $selected = (count($menu['urls'])-1);
495 if ($group->usesSurvey()) {
496 $menu['titles'][] = _('Surveys');
497 $menu['urls'][] = util_make_url ('/survey/?group_id=' . $group_id);
498 if ($perm->isAdmin()) {
499 $menu['adminurls'][] = util_make_url ('/survey/admin/?group_id='.$group_id);
501 $menu['adminurls'][] = false;
503 if ($toptab == "surveys") {
504 $selected = (count($menu['urls'])-1);
509 if ($group->usesNews()) {
510 $menu['titles'][] = _('News');
511 $menu['urls'][] = util_make_url ('/news/?group_id=' . $group_id);
512 if ($perm->isAdmin()) {
513 $menu['adminurls'][] = util_make_url ('/news/admin/?group_id='.$group_id);
515 $menu['adminurls'][] = false;
517 if ($toptab == "news") {
518 $selected = (count($menu['urls'])-1);
523 if ($group->usesSCM()) {
524 $menu['titles'][] = _('SCM');
525 $menu['urls'][] = util_make_url ('/scm/?group_id=' . $group_id);
527 if ($perm->isAdmin()) {
528 $menu['adminurls'][] = util_make_url ('/scm/admin/?group_id='.$group_id);
530 $menu['adminurls'][] = false;
532 if ($toptab == "scm") {
533 $selected = (count($menu['urls'])-1);
537 // groupmenu_after_scm hook
538 $hookParams = array();
539 $hookParams['group_id'] = $group_id ;
540 $hookParams['DIRS'] =& $menu['urls'];
541 $hookParams['TITLES'] =& $menu['titles'];
542 $hookParams['toptab'] =& $toptab;
543 $hookParams['selected'] =& $selected;
545 plugin_hook ("groupmenu_scm", $hookParams) ;
548 for ($i = 0; $i < count($menu['urls']) - count($menu['adminurls']); $i++) {
549 $menu['adminurls'][] = false;
553 if ($group->usesFRS()) {
554 $menu['titles'][] = _('Files');
555 $menu['urls'][] = util_make_url ('/frs/?group_id=' . $group_id);
556 if ($perm->isAdmin() || $perm->isReleaseTechnician()) {
557 $menu['adminurls'][] = util_make_url ('/frs/admin/?group_id='.$group_id);
559 $menu['adminurls'][] = false;
561 if ($toptab == "frs") {
562 $selected = (count($menu['urls'])-1);
567 $hookParams = array();
568 $hookParams['group'] = $group_id ;
569 $hookParams['DIRS'] =& $menu['urls'];
570 $hookParams['TITLES'] =& $menu['titles'];
571 $hookParams['toptab'] =& $toptab;
572 $hookParams['selected'] =& $selected;
574 plugin_hook ("groupmenu", $hookParams) ;
578 $i < count($menu['urls']) - count($menu['adminurls']);
581 $menu['adminurls'][] = false;
584 // store selected menu item (if any)
585 $menu['selected'] = $selected;
587 $menu['last_toptab'] = $toptab;
590 return $this->project_menu_data[$group_id] ;
594 * Create the HTML code for the banner "Powered By
595 * FusionForge". If $asHTML is set to false, it will return an
596 * array with the following structure: $result['url']: URL for
597 * the link on the banner; $result['image']: URL of the banner
598 * image; $result['title']: HTML code that outputs the banner;
599 * $result['html']: HTML code that creates the banner and the link.
601 function getPoweredBy($asHTML=true) {
602 $res['url'] = 'http://fusionforge.org/';
603 $res['image'] = util_make_url ('/images/pow-fusionforge.png');
604 $res['title'] = '<img src="'
606 . '" alt="Powered By FusionForge" border="0" />';
607 $res['html'] = util_make_link($res['url'], $res['title'], array(), true);
615 /** Create the HTML code for the "Show Source" link if
616 * $sys_show_source is set, otherwise "". If $asHTML is set
617 * to false, it returns NULL when $sys_show_source is not
618 * set, otherwise an array with the following structure:
619 * $result['url']: URL of the link to the source code viewer;
620 * $result['title']: Title of the link.
622 function getShowSource($asHTML=true) {
623 global $sys_show_source;
624 if ($sys_show_source) {
625 $res['url'] = util_make_url('/source.php?file='.getStringFromServer('SCRIPT_NAME'));
626 $res['title'] = _('Show source');
628 return ($asHTML ? "" : NULL);
633 return util_make_link($res['url'], $res['title'],
634 array('class' => 'showsource'),
642 // c-file-style: "bsd"