All pastes #805213 Raw Edit

Stuff

public php v1 · immutable
·published 2007-12-04 04:07 UTC
rendered paste body
<?php/* This script is meant to be a flexible breadcrumbs script for the student intranet. * Breadcrumbs are nav, eg. Home - Faculties - English (etc.) * It basically reads the URL/path and makes it look pretty. * * This script can just be included using php include() in the ... hrm. * Ideally it should sit above the random images, in the randomimgs div but that's not open for editing. May need to fix that... * Perhaps it can also be in the page title? * Also, it's not sitting where it will eventually be sitting - perhaps createCrumbs can return a 2d array, * with folders matched to folder path hrmm. * Need to fix the way it handles non-existence of root folder - maybe throw an error. * Need to append the current file name to the end of it all in some way, perhaps? The filename isn't included in path. *//* * Reads the directory structure of where the page resides, * changes it to the desired 'root', * splits the folders into individual array items * and replaces the root folder name with "Home". * * @param root The name of the folder that the user will see as the "Homepage" of the site * @param homedispname What you want the user to see as as the "Homepage" link. Defaults to "Home". * @return folders An array of strings that can be used as individual breadcrumbs, or -1 if it didn't exist. */function getFoldernameArray($root="intranet-new", $homedispname="Home"){	try {	//everything before the folder with the name defined in user-given $root will be stripped out of the string	$path = getcwd(); 	echo "Full path: ".$path."<br />\n";	if (substr_count($path, $root) < 1) //check $root is actually part of the path of this current page	{		echo "The root folder doesn't exist in this path. FAIL!<br />\n";		return -1;	}	$path = substr($path, stripos($path, $root)); //strip out everything before the declared root	echo "Rooted path: ".$path."<br />\n";	$homedpath = substr_replace($path, $homedispname, 0, strlen($root)); //replace root folder name with 'Home'	echo "Homed path: ".$homedpath."<br />\n";	$folders = explode("/", $homedpath);	echo "Breadcrumbs: ".$folders."<br />\n";		if ($folders)	{		return $folders;	}	else	{		return $homedispname;	}	}	catch (Exception $e)	{		echo $e;	}}/** * This function returns an array of relative paths, for the anchors of the breadcrumbs. * @param root The first folder, root of the relative paths. * @return folderpaths An array of relative paths */function getFolderpathArray($root="intranet-new"){	$path = getcwd();	return $path;}?><html><head><title>Test!!</title></head><body><h2>Testing getFolderpathArray</h2><p>Without a root specified:<br /><?php echo getFolderpathArray(); ?></p><p>Specifying scripts folder as root:<br /><?php echo getFolderpathArray("scripts"); ?></p><h2>Testing getFoldernameArray</h2><p>Without a root specified: <br  /><?php echo getFoldernameArray(); ?></p><p>Specifying scripts folder as root only: <br /><?php echo getFoldernameArray("scripts"); ?></p><p>Specifying scripts folder as root and Script Home as homedispname: <br /><?php echo getFoldernameArray("scripts", "Script Home"); ?></p><p>Specifying Script Home as homedispname only: <br /><?php echo //getFoldernameArray(,"Script Home"); ?></p></body></html>