Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 216820 | Differences between
and this patch

Collapse All | Expand All

(-)system/breadcrumb.class.php (+139 lines)
Added Link Here
1
<?php
2
/*******************************************************************************
3
 * Copyright (c) 2014 Eclipse Foundation and others.
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Denis Roy (Eclipse Foundation)- initial API and implementation
11
 *******************************************************************************/
12
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/menuitem.class.php");
13
14
class Breadcrumb extends Menu {
15
	
16
	private $CrumbList = array();
17
	
18
	# static list of first-level URIs with corresponding display-friendly names
19
	# everything outside of this is considered to be in project space 
20
	private $FirstLevel = array(
21
			"committers"	=> "Committers",
22
			"downloads"		=> "Downloads",
23
			"membership"	=> "Membership",
24
			"newsgroups"	=> "Forums",
25
			"org" 			=> "About Us",
26
			"projects"		=> "Projects",
27
			"users"			=> "Users"
28
	);
29
30
	function getCrumbList() {
31
		return $this->CrumbList;
32
	}
33
	
34
	function setCrumbList($_List) {
35
		$this->CrumbList = $_List;
36
	}
37
	
38
	# Main constructor
39
	function Breadcrumb() {
40
41
		$www_prefix = "";
42
		
43
		global $App;
44
45
		if(!isset($App)) {
46
			$App = new App();
47
		}
48
		$www_prefix = $App->getWWWPrefix();
49
50
51
		# Default: Home
52
		$this->addCrumb("Home", $www_prefix . "/", "_self");
53
		
54
		if(isset($_SERVER['REQUEST_URI'])) {
55
			http://www.eclipse.org/newsgroups/test.php
56
			# Array ( [0] => [1] => newsgroups [2] => test.php )
57
			$items = explode("/", $_SERVER['REQUEST_URI']);
58
			
59
			
60
			# Examine Item 1 (first level URL)
61
			if(isset($this->FirstLevel[$items[1]])) {
62
				$this->addCrumb($this->FirstLevel[$items[1]], $www_prefix . "/" . $items[1], "_self");
63
			}
64
			else {
65
				# Not pre-defined Foundation page, must be a project page
66
				# /xtext/file.php => Home > Projects > xtext > $pageTitle
67
				$this->addCrumb("Project", $www_prefix . "/projects/", "_self");
68
				$this->addCrumb($items[1], $www_prefix . "/" . $items[1], "_self");
69
			}
70
			
71
			# Add current page
72
			# AT this point, $pageTitle should be set as we are running in header()
73
			global $pageTitle;
74
			if(isset($pageTitle)) {
75
				$title = $pageTitle;
76
				
77
				# consider truncating $pageTitle if it's too long
78
				if(strlen($title) > 35) {
79
					$title = substr($title, 0, 35) . "...";
80
				} 
81
				
82
				$this->addCrumb($pageTitle, NULL, NULL);
83
			}
84
			else {
85
				# Add final generic crumb
86
				$this->addCrumb("Document", NULL, NULL);
87
			}
88
		}
89
	}
90
	
91
	function addCrumb($_Text, $_URL, $_Target) {
92
		# Menu Items must be added at position 1
93
		$Crumb = new Link($_Text, $_URL, $_Target, 0);
94
			
95
		# Add incoming menuitem
96
		$this->CrumbList[count($this->CrumbList)] = $Crumb;
97
	}
98
99
	function getCrumbCount() {
100
		return count($this->CrumbList);
101
	}
102
	
103
	function getCrumbAt($_Pos) {
104
		if($_Pos < $this->getCrumbCount()) {
105
			return $this->CrumbList[$_Pos];
106
		}
107
	}
108
	
109
	/**
110
	 * Insert breadcrumb at a specific position
111
	 * @param unknown $_Pos Position to insert at
112
	 * @param unknown $_Text Link text
113
	 * @param unknown $_URL Link URL
114
	 * @param unknown $_Target Link target
115
	 * 
116
	 */
117
	function insertCrumbAt($_Pos, $_Text, $_URL, $_Target) {
118
		if($_Pos < $this->getCrumbCount() && $_Pos > 0) {  # Don't allow inserting before Home
119
			$Crumb = new Link($_Text, $_URL, $_Target, 0);
120
			$tempList = array($Crumb);
121
			$result = array_merge(array_slice($this->CrumbList, 0, $_Pos, true), $tempList, array_slice($this->CrumbList, $_Pos, $this->getCrumbCount(), true));
122
			$this->CrumbList = $result;
123
		}
124
		else {
125
			$this->addCrumb($_Text, $_URL, $_Target);
126
		}
127
	}
128
129
	function showBreadcrumbs() {
130
		# for debugging purposes only
131
		echo "Breadcrumbs: ";
132
		foreach ($this->CrumbList as $Crumb) {
133
			# $Crumb is a Link object
134
			echo "<a href='" . $Crumb->getURL() . "'>" . $Crumb->getText() . "</a>";
135
			echo " | " ; 
136
		}
137
	}
138
}
139
?>

Return to bug 216820