Location: PHPKode > scripts > Simple navigation > simple-navigation/navigation.class.php
<?php //: $RCSfile: navigation.class.php,v $ {
//: $Revision: 1.0 $
//: $Date: 2004/05/14 14:11:25 $
//: $Author: Feighen $
//:-

/** class::navigation
	@author Feighen Oosterbroek
	@author hide@address.com
	@var $html string html output from class
	@example 
	$links = array();
	$links[] = array("link"=>"index.php?method=showHome", "text"=>"Home", "title"=>"Click to view home page");
	...
	$links[] = array("link"=>"admin.php?method=panel", "text"=>"Administration", "title"=>"Click to view administration panel");
	$nav = new navigation();
	$nav->drawNavigation($links);
	$nav->printHtml();
*/
class navigation {
	#: Variables
	protected static $html;
	//: Public Functions {
		#: Class Constructor
		public function __construct() {
			return true;
		}
		public function navigation() {
			return self::__construct();
		}
		#: Class Functions
		Public function drawNavigation($urls) {
			self::$html = (string)"";
			self::$html .= self::styleSheet();			# css
			self::$html .= self::javaScript();			# javascript
			self::$html .= "<ul class='nav'>\n";
			$urls = self::setArray($urls);
			foreach ($urls as $key=>$val) {
				$pattern = "/.*(".preg_replace(array(0=>"/\?/", 1=>"/\./"), array(0=>"\\?", 1=>"\\."), FUNC).").*/";
				
				self::$html .= "<li class='".(preg_match($pattern, $val["link"]) ? "current" : "norm")."' onmouseover='overObj(this);' onmouseout='offObj(this);'>";
				self::$html .= "<a href='".$val["link"]."' title='".$val["title"]."'>".ucwords(preg_replace("/_/", " ", $val["text"]))."</a>\n";
				self::$html .= "</li>\n";
			}
			self::$html .= "</ul>\n";
		}
		
		public function returnHtml() {
			return self::$html;
		}
		
		public function printHtml() {
			print(self::$html);
		}
	// }
	//: Private Functions {
		/** styleSheet()
			@author Feighen Oosterbroek
			@author hide@address.com
			@notes change this to how you would prefer your menu to look
		*/
		private function styleSheet() {
			$html = (string)"<style type='text/css' media='screen'>
			.nav {
				margin: 0 0;
				padding: 0 0;
				float: right;
				margin-right: 30px;
			}
			.nav li {
				list-style-type: none;
				display: inline;
				padding-right: 20px;
			}
			.norm,
			.norm a,
			.norm a:active,
			.norm a:visited {
				color: ".COLOURS_NORMAL_PAGE.";
				text-decoration: none;
			}
			.current,
			.current a,
			.current a:active,
			.current a:visited {
				font-weight: bold;
				font-size: 1.1em;
				color: ".COLOURS_CURRENT_PAGE.";
				text-decoration: none;
			}
			</style>\n";
			
			return $html;
		}
		
		private function javaScript() {
			$html = (string)"<script type='text/javascript'>
			function overObj(obj) {
				var child = obj.firstChild;
				child.style.color = '".COLOURS_HILIGHT."';
			}
			
			function offObj(obj) {
				var col;
				var child = obj.firstChild;
				
				switch (obj.className) {
					case 'current':
					col = '".COLOURS_CURRENT_PAGE."';	
					break;
					case 'norm':
					col = '".COLOURS_NORMAL_PAGE."';
					break;
				}
				
				child.style.color = col;
			}
			</script>\n";
			
			return $html;
		}
		
		private function setArray($array) {
			return is_array($array) ? $array : array();
		}
	// }
}

// }
?>
Return current item: Simple navigation