'', 'xhtml-trans' => '', 'xhtml-frame' => '', 'xhtml11' => '' ); var $_docTypesText = array( 'xhtml-strict' => 'XHTML 1.0 Strict', 'xhtml-trans' => 'XHTML 1.0 Transitional', 'xhtml-frame' => 'XHTML 1.0 Frameset', 'xhtml11' => 'XHTML 1.1' ); var $doctype = 'xhtml-trans'; /** * Singleton accessor */ function &getInstance () { static $instance; if (!is_object($instance)) $instance = new mosHtmlHelper(); return $instance; } function __docType($type=null) { static $obj; if (!is_object($obj)) $obj =& mosHtmlHelper::getInstance(); if (array_key_exists($type, $obj->_docTypes)) return $obj->_docTypes[$type]; return $obj->_docTypes[$obj->doctype]; } function renderDocType($type=null) { static $obj; if (!is_object($obj)) $obj =& mosHtmlHelper::getInstance(); echo $obj->__docType($type)."\n"; } function get($var) { static $obj; if (!is_object($obj)) $obj =& mosHtmlHelper::getInstance(); if(isset($obj->$var)) return $obj->$var; return null; } function set($property, $value) { static $obj; if (!is_object($obj)) $obj =& mosHtmlHelper::getInstance(); if($property{0} == '_') return; // dont set private properties if (isset($obj->$property)) $obj->$property = $value; } } // end class mosHtmlHelper /** * mosUriHelper class * * original copyright (c) 2003, binarycloud-dev * original license - LGPL (http://www.gnu.org/copyleft/lesser.html) * original author - jason hines, jason@greenhell.com * * Changelog: * 12-01-2007 Al Warren (alwarren) * - changed class name to mosUri * - removed includes * - removed references to authorizer class * - cleaned up comments */ /** * mosUriHelper is a single instance class used for altering and receiving the Uri * from different apps. By default, it looks to current Uri, and provides * methods for retrieving the various parts of the given Uri. * * Usage: * $Uri =& mosUriHelper::getInstance(); * $Uri->setUri('http://domain.com/path/to/script.php?param1=value1'); * $Uri->pushParam('foo','bar'); * $Uri->popParam('param1'); * print $Uri->getUri(); * * Outputs: http://domain.com/path/to/script.php?foo=bar * */ class mosUriHelper { /** * @var string Full uri */ var $uri; /** * @var string Protocol */ var $scheme; /** * @var string Username */ var $user; /** * @var string Password */ var $pass; /** * @var string Host */ var $host; /** * @var integer Port */ var $port; /** * @var string Path */ var $path; /** * @var array Query hash */ var $query; /** * @var string Anchor */ var $anchor; /** * Constructor set Uri on class instantiation. * * @param string * @access public */ function mosUriHelper() { $this->setUri(); } /** * Singleton accessor * * @access public */ function &getInstance() { static $instance; if(!isset($instance)) { $instance = new mosUriHelper(); } return $instance; } /** * Looks to _SERVER vars, and sets Uri property accordingly if Uri not passed. * * @access public */ function setUri($uri = null) { if ($uri == null) { $this->scheme = 'http' . (@$_SERVER['HTTPS'] == 'on' ? 's' : ''); $this->user = ''; $this->pass = ''; $this->host = !empty($host) ? $host : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost'); $this->port = !empty($port) ? $port : (isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80); $this->path = !empty($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : '/'; $this->query = isset($_SERVER['QUERY_STRING']) ? $this->_parseRawQuery($_SERVER['QUERY_STRING']) : null; $this->anchor = ''; } else { $_parts = parse_url($uri); $this->scheme = isset($_parts['scheme']) ? $_parts['scheme'] : 'http'; $this->user = isset($_parts['user']) ? $_parts['user'] : ''; $this->pass = isset($_parts['pass']) ? $_parts['pass'] : ''; $this->host = isset($_parts['host']) ? $_parts['host'] : ''; $this->port = isset($_parts['port']) ? $_parts['port'] : 80; $this->path = isset($_parts['path']) ? $_parts['path'] : ''; $this->query = isset($_parts['query']) ? $this->_parseRawQuery($_parts['query']) : array(); $this->anchor = isset($_parts['fragment']) ? $_parts['fragment'] : ''; } } /** * Returns full uri string * * @return string Full uri * @access public */ function toString() { $query = $this->getQuery(); $this->uri = $this->scheme . '://' . $this->user . (!empty($this->pass) ? ':' : '') . $this->pass . (!empty($this->user) ? '@' : '') . $this->host . ($this->port == '80' ? '' : ':' . $this->port) . $this->path . (!empty($query) ? '?' . $query : '') . (!empty($this->anchor) ? '#' . $this->anchor : ''); return $this->uri; } /** * Alias for toString() * * @access public */ function getUri() { return $this->toString(); } /** * Adds a query item * * @param string $name Name of item * @param string $value Value of item * @access public */ function pushParam($name, $value) { $this->query[$name] = is_array($value)? array_map('urlencode', $value): urlencode($value); } /** * Get a query item * * @param string $key Name of item * @return mixed * @access public */ function get($key, $default='') { if (isset($this->query[$key])) return $this->query[$key]; else return $default; } /** * Removes a query item * * @param string $name Name of item * @access public */ function popParam($name) { if (isset($this->query[$name])) { unset($this->query[$name]); } } /** * Sets the query to literally what you supply * * @param string $query The query data. Should be of the format foo=bar&x=y etc * @access public */ function setRawQuery($query) { $this->query = $this->_parseRawQuery($query); } /** * Returns flat query * * @return string Query * @access public */ function getQuery() { if (!empty($this->query)) { $query = array(); foreach ($this->query as $name => $value) { if (is_array($value)) { foreach ($value as $k => $v) { $query[] = $name . '=' . $v; } } elseif (!is_null($value)) { $query[] = $name . '=' . $value; } else { $query[] = $name; } } $query = implode('&', $query); } else { $query = ''; } return $query; } /** * Parses raw query and returns an array of it * * @param string $query The querystring to parse * @return array An array of the query data * @access private */ function _parseRawQuery($query) { $query = rawurldecode($query); // replace ampersand entities $query = str_replace('&', '&', $query); $parts = preg_split('/&/', $query, -1, PREG_SPLIT_NO_EMPTY); $return = array(); foreach ($parts as $part) { if (strpos($part, '=') !== false) { $value = rawurlencode(substr($part, strpos($part, '=') + 1)); $key = substr($part, 0, strpos($part, '=')); } else { $value = null; $key = $part; } if (substr($key, -2) == '[]') { $key = substr($key, 0, -2); if (@!is_array($return[$key])) { $return[$key] = array(); $return[$key][] = $value; } else { $return[$key][] = $value; } } elseif (!empty($return[$key])) { $return[$key] = (array) $return[$key]; $return[$key][] = $value; } else { $return[$key] = $value; } } return $return; } /** * Resolves //, ../ and ./ from a path and returns * the result. Eg: * * /foo/bar/../boo.php => /foo/boo.php * /foo/bar/../../boo.php => /boo.php * /foo/bar/.././/boo.php => /foo/boo.php * * This method can also be called statically. * * @param string $uri Uri path to resolve * @return string The result */ function resolvePath($path) { $path = explode('/', str_replace('//', '/', $path)); for ($i=0; $i 1 OR ($i == 1 AND $path[0] != '') ) ) { unset($path[$i]); unset($path[$i-1]); $path = array_values($path); $i -= 2; } elseif ($path[$i] == '..' AND $i == 1 AND $path[0] == '') { unset($path[$i]); $path = array_values($path); $i--; } else { continue; } } return implode('/', $path); } /** * Get scheme - returns the scheme * * @access public * @return string */ function getScheme() { return $this->scheme; } /** * Set scheme - sets the scheme (protocol) * * @param string scheme * @access public */ function setScheme($scheme) { $this->scheme = $scheme; } /** * Get username - returns the username, or null if no username was specified * * @access public * @return string */ function getUser() { return $this->user; } /** * Set username - sets the username * * @param string username * @access public */ function setUser($user) { $this->user = $user; } /** * Get password - returns the password * * @access public * @return string */ function getPass() { return $this->pass; } /** * Set password - sets the password * * @param string password * @access public */ function setPass($pass) { $this->pass = $pass; } /** * Get host - returns the hostname/ip, or null if no hostname/ip was specifi * * @access public * @return string */ function getHost() { return $this->host; } /** * Set host - sets the hostname/ip * * @param string hostname * @access public */ function setHost($host) { $this->host = $host; } /** * Get port - returns the port number, or null if no port was specified * * @access public * @return int */ function getPort() { return (isset($this->port)) ? $this->port : null; } /** * Set port - sets the port number * * @param int port number * @access public */ function setPort($port) { $this->port = $port; } /** * Gets the path string * * @access public * @return string */ function getPath() { return $this->path; } /** * Set path * * @param string fragment for page anchors * @access public */ function setPath($path) { $this->path = $path; } /** * Gets the archor string * * @access public * @return string */ function getAnchor() { return $this->anchor; } /** * Set anchor - sets everything after the "#" * * @param string fragment for page anchors * @access public */ function setAnchor($anchor) { $this->anchor = $anchor; } /** * Checks whether the current URI is using HTTPS * * @access public * @return boolean */ function checkSSL() { return $this->getScheme() == 'https' ? TRUE : FALSE; } } // end class mosUri ?>