Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Roy2014-04-16 20:23:19 +0000
committerDenis Roy2014-04-16 20:23:19 +0000
commit5eae66c20bfcbe25e2ca951cbefb323eebdea441 (patch)
tree0fdb531a2a606f06c569f55448b2fe91b6530b8a
parentfc86702d0a91f8db489d7285baadc7bc544bdec7 (diff)
downloadeclipse.org-common-5eae66c20bfcbe25e2ca951cbefb323eebdea441.tar.gz
eclipse.org-common-5eae66c20bfcbe25e2ca951cbefb323eebdea441.tar.xz
eclipse.org-common-5eae66c20bfcbe25e2ca951cbefb323eebdea441.zip
Bug 216820 - [navigation] Please add breadcrumb like navigation on
eclipse.org Signed-off-by: Denis Roy <denis.roy@eclipse.org>
-rw-r--r--system/breadcrumb.php139
1 files changed, 139 insertions, 0 deletions
diff --git a/system/breadcrumb.php b/system/breadcrumb.php
new file mode 100644
index 00000000..cb6037f5
--- /dev/null
+++ b/system/breadcrumb.php
@@ -0,0 +1,139 @@
+<?php
+/*******************************************************************************
+ * Copyright (c) 2014 Eclipse Foundation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Denis Roy (Eclipse Foundation)- initial API and implementation
+ *******************************************************************************/
+require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/menuitem.class.php");
+
+class Breadcrumb extends Menu {
+
+ private $CrumbList = array();
+
+ # static list of first-level URIs with corresponding display-friendly names
+ # everything outside of this is considered to be in project space
+ private $FirstLevel = array(
+ "committers" => "Committers",
+ "downloads" => "Downloads",
+ "membership" => "Membership",
+ "newsgroups" => "Forums",
+ "org" => "About Us",
+ "projects" => "Projects",
+ "users" => "Users"
+ );
+
+ function getCrumbList() {
+ return $this->CrumbList;
+ }
+
+ function setCrumbList($_List) {
+ $this->CrumbList = $_List;
+ }
+
+ # Main constructor
+ function Breadcrumb() {
+
+ $www_prefix = "";
+
+ global $App;
+
+ if(!isset($App)) {
+ $App = new App();
+ }
+ $www_prefix = $App->getWWWPrefix();
+
+
+ # Default: Home
+ $this->addCrumb("Home", $www_prefix . "/", "_self");
+
+ if(isset($_SERVER['REQUEST_URI'])) {
+ http://www.eclipse.org/newsgroups/test.php
+ # Array ( [0] => [1] => newsgroups [2] => test.php )
+ $items = explode("/", $_SERVER['REQUEST_URI']);
+
+
+ # Examine Item 1 (first level URL)
+ if(isset($this->FirstLevel[$items[1]])) {
+ $this->addCrumb($this->FirstLevel[$items[1]], $www_prefix . "/" . $items[1], "_self");
+ }
+ else {
+ # Not pre-defined Foundation page, must be a project page
+ # /xtext/file.php => Home > Projects > xtext > $pageTitle
+ $this->addCrumb("Project", $www_prefix . "/projects/", "_self");
+ $this->addCrumb($items[1], $www_prefix . "/" . $items[1], "_self");
+ }
+
+ # Add current page
+ # AT this point, $pageTitle should be set as we are running in header()
+ global $pageTitle;
+ if(isset($pageTitle)) {
+ $title = $pageTitle;
+
+ # consider truncating $pageTitle if it's too long
+ if(strlen($title) > 35) {
+ $title = substr($title, 0, 35) . "...";
+ }
+
+ $this->addCrumb($pageTitle, NULL, NULL);
+ }
+ else {
+ # Add final generic crumb
+ $this->addCrumb("Document", NULL, NULL);
+ }
+ }
+ }
+
+ function addCrumb($_Text, $_URL, $_Target) {
+ # Menu Items must be added at position 1
+ $Crumb = new Link($_Text, $_URL, $_Target, 0);
+
+ # Add incoming menuitem
+ $this->CrumbList[count($this->CrumbList)] = $Crumb;
+ }
+
+ function getCrumbCount() {
+ return count($this->CrumbList);
+ }
+
+ function getCrumbAt($_Pos) {
+ if($_Pos < $this->getCrumbCount()) {
+ return $this->CrumbList[$_Pos];
+ }
+ }
+
+ /**
+ * Insert breadcrumb at a specific position
+ * @param unknown $_Pos Position to insert at
+ * @param unknown $_Text Link text
+ * @param unknown $_URL Link URL
+ * @param unknown $_Target Link target
+ *
+ */
+ function insertCrumbAt($_Pos, $_Text, $_URL, $_Target) {
+ if($_Pos < $this->getCrumbCount() && $_Pos > 0) { # Don't allow inserting before Home
+ $Crumb = new Link($_Text, $_URL, $_Target, 0);
+ $tempList = array($Crumb);
+ $result = array_merge(array_slice($this->CrumbList, 0, $_Pos, true), $tempList, array_slice($this->CrumbList, $_Pos, $this->getCrumbCount(), true));
+ $this->CrumbList = $result;
+ }
+ else {
+ $this->addCrumb($_Text, $_URL, $_Target);
+ }
+ }
+
+ function showBreadcrumbs() {
+ # for debugging purposes only
+ echo "Breadcrumbs: ";
+ foreach ($this->CrumbList as $Crumb) {
+ # $Crumb is a Link object
+ echo "<a href='" . $Crumb->getURL() . "'>" . $Crumb->getText() . "</a>";
+ echo " | " ;
+ }
+ }
+}
+?> \ No newline at end of file

Back to the top