Location: PHPKode > projects > SkullPuppy > Project/library/SP/HTTP.php
<?php

class SP_HTTP {
	static private $_baseUrl;

	static public function location($uri) {
		header("location:$uri");
		exit;
	}

	static public function post($url, $data) {
		$ctx = stream_context_create(
			array('http' => array('method' => 'POST', 'content' => $data))
			);
		return @file_get_contents($url, flase, $ctx);
	}

	static public function url($params, $route=null) {
		if($params instanceof SP_Controller) {
			$c = $params;
			$params = array();
			$params['module'] = substr($c->module,8,-1);
			$params['controller'] = $c->controller;
			$params['action'] = $c->action;
		} else {
			if(gettype($params)=='object') return false;
			$params = (array) $params;
		}
		$route = (string) $route;
		unset($module);
		$router = SP_Router::getInstance();
		$url_mode = $route ? 'routed' : SP_Registry::getKey('url_mode');
		$url = '';
		switch($url_mode) {
		case 'clean':
			$url = '/';
			if($params['module']) {
				$url .= "{$params['module']}/";
				unset($params['module']);
			}
			if($params['controller']) {
				$url .= $params['controller']."/";
				unset($params['controller']);
			}
			if($params['action']) {
				$url .= $params['action']."/";
				unset($params['action']);
			}
			foreach($params as $key => $val) {
				$url .= "$key/";
				if($val !== null) $url .= "$val/";
			}
			break;
		case 'routed':
			$url = '/';
			$route = $router->getRoute($route);
			foreach($route->getDefinition() as $seg) {
				if(substr($seg,0,1)==':') {
					$url .= $params[substr($seg,1)].'/';
				} else {
					$url .= "$seg/";
				}
			}
			unset($params['module']);
			unset($params['controller']);
			unset($params['action']);
			if($route->hasWild()) {
				foreach($params as $key => $val) {
					$url .= "$key/";
					if($val !== null) $url .= "$val/";
				}
			}
			break;
		default:
			if($params['module']) {
				$url .= $params['module'].'/';
				unset($params['module']);
			}
			$url .= '?';
			$url .= $params['controller'];
			unset($params['controller']);
			if($params['action']) {
				$url .= "&".$params['action'];
				unset($params['action']);
			}
			foreach($params as $key => $val) {
				$url .= "&$key=$val";
			}
		}
		return $url;
	}

	static public function getFullUrl() {
		return self::getBaseUrl().$_SERVER['REQUEST_URI'];
	}

	static public function getBaseUrl() {
		$url = self::$_baseUrl;
		if(!$url) {
			$url = isset($_SERVER['HTTPS']) ? 's' : '';
			$url = "http$url://".$_SERVER['SERVER_NAME'];
			self::setBaseUrl($url);
		}
		return $url;
	}

	static public function setBaseUrl($url) {
		self::$_baseUrl = $url;
		$a =1;
	}
}

?>
Return current item: SkullPuppy