All pastes #367105 Raw Edit

Stuff

public php v1 · immutable
#367105 ·published 2007-02-22 03:19 UTC
rendered paste body
<?php/** * RandomTales.net * A site where you can share, manage and edit your stories! * * @author		Dean Newman <webmaster@auscoder.com> * @copyright	Copyright 2007, Dean Newman *//** * URL Scheme Management Class * * @package		framework * @subpackage	crumbs * @copyright	Copyright 2007, Dean Newman * @author		Afterlife(69) <webmaster@auscoder.com> */final class crumbs{	const	MAX_BITS = 10;	public	$raw;	public	$crumbs;	public function __construct()	{		/**		 * Define as array to prevent errors		 */		$this->raw = array();				/**		 * If the REQUEST_URI is set and not empty		 */		if ( isset ( $_SERVER['REQUEST_URI'] ) && ! empty ( $_SERVER['REQUEST_URI'] ) )		{			/**			 * Slice off query strings			 */			$this->raw = $_SERVER['REQUEST_URI'] = str_replace(strstr($_SERVER['REQUEST_URI'], '?'), '', $_SERVER['REQUEST_URI']);			/**			 * Seperate the sections by forward slash			 */			$this->crumbs = explode('/', $this->raw, self::MAX_BITS);						/**			 * Remove the lower level directories and this file			 */			$index = array_search(basename(dirname($_SERVER['SCRIPT_NAME'])), $this->crumbs);			if ( array_search ($this->raw, $this->crumbs) )			{				/**				 * If the name of this file is found, remove it				 */				$index++;			}			$this->crumbs = array_slice($this->crumbs, ($index + 1));						/**			 * Remove empty values			 */			foreach ( $this->crumbs AS $key => $crumb )			{				if ( empty ( $crumb ) )				{					unset($this->crumbs[$key]);				}			}						/**			 * Sort the array by key			 */			ksort($this->crumbs);						/**			 * Decode the special chars of the entries			 */			$this->crumbs = array_map('urldecode', $this->crumbs);		}				/**		 * Return parsed url, or empty array.		 */		return $this->crumbs;	}		public function __destruct()	{			}		public function request($key, $default = null, $type = null, $maxlen = null, $walk = null)	{		$return = array_key_exists($key, $this->crumbs) ? $this->crumbs[$key] : $default;					if ( $type )		{			settype($return, $type);		}				if ( $walk )		{			$return = $walk($return);		}				if ( $maxlen )		{			$return = substr($return, 0, $maxlen);		}			return $return;	}		public static function get_external_url()	{		$http = ( isset($_SERVER['HTTPS']) ) ? 'https://' : 'http://';		$host = ( isset($_SERVER['HTTP_HOST']) ) ? $_SERVER['HTTP_HOST'] : false;		$path = ( isset($_SERVER['SCRIPT_NAME']) ) ? dirname($_SERVER['SCRIPT_NAME']) : false;			return ($http . $host . $path);	}}?>