PHP Classes

File: CGI.php

Recommend this page to a friend!
  Classes of John Luxford   CGI.php   CGI.php   Download  
File: CGI.php
Role: ???
Content type: text/plain
Description: The base CGI class file
Class: CGI.php
Author: By
Last change:
Date: 22 years ago
Size: 5,124 bytes
 

Contents

Class file image Download
<?php // // +----------------------------------------------------------------------+ // | Sitellite - Content Management System | // +----------------------------------------------------------------------+ // | Copyright (c) 2001 Simian Systems | // +----------------------------------------------------------------------+ // | This software is released under the Simian Open Software License. | // | Please see the accompanying file OPENLICENSE for licensing details! | // | | // | You should have received a copy of the Simian Open Software License | // | along with this program; if not, write to Simian Systems, | // | 101-314 Broadway, Winnipeg, MB, R3C 0S7, CANADA. The Simian | // | Public License is also available at the following web site | // | address: <http://www.simian.ca/license.php> | // +----------------------------------------------------------------------+ // | Authors: John Luxford <lux@simian.ca> | // +----------------------------------------------------------------------+ // // CGI is a class that is used to give GET and POST auto-generated // variables their own distinct namespace, so as not to conflict with // other auto-generated variables, such as Cookie data. // /*! <package name="CGI"> <class name="CGI" access="public" date="2001-05-29 11:05:37" version="1.0"> <author name="John Luxford" email="lux@simian.ca" url="http://www.simian.ca/" /> <summary>CGI is a class that is used to give GET and POST auto-generated variables their own distinct namespace, so as not to conflict with other auto-generated variables, such as Cookie data. The CGI class gets its data from the $HTTP_POST_VARS and $HTTP_GET_VARS hashes.</summary> <example>$cgi = new CGI; // if a variable called 'query' was passed to this script, it can // be accessed this way: echo $cgi->query; // or you can use the 'param' property to retrieve all of the names // of the variables passed to this script: foreach ($cgi->param as $p) { echo $cgi->{$p}; }</example> !*/ class CGI { /*! <property name="param" access="public" type="array"> <summary>Contains a list of the names of all the variables passed to the current script through either the GET or POST methods.</summary> </property> !*/ var $param = array (); /*! <method name="CGI" access="public"> <summary>Constructor method.</summary> </method> !*/ function CGI () { global $HTTP_GET_VARS, $HTTP_POST_VARS; if ($HTTP_GET_VARS) { while (list ($k, $v) = each ($HTTP_GET_VARS)) { $this->{$k} = $v; array_push ($this->param, $k); } } if ($HTTP_POST_VARS) { while (list ($k, $v) = each ($HTTP_POST_VARS)) { $this->{$k} = $v; array_push ($this->param, $k); } } } /*! <method name="parseUri" access="public"> <summary>Takes the global $REQUEST_URI variable and parses it as if each subdirectory listing is a key/value pair, separated by periods (.), and adds these pairs as properties of this object, and the keys to the param array. Any subdirectories that do not contain a period are returned as extras.</summary> <returns type="array" /> </method> !*/ function parseUri () { global $REQUEST_URI; $extra_vars = array (); // directories that didn't separate with a . $path_split = split ("/", $REQUEST_URI); array_shift ($path_split); // lose the www... part of the URI array_shift ($path_split); // lose the filename part of the URI foreach ($path_split as $one) { if (ereg (".\..", $one)) { list ($key, $val) = split ("\.", $one); $this->{$key} = $val; array_push ($this->param, $key); } else { array_push ($extra_vars, $one); } } return $extra_vars; } /*! <method name="translateUri" access="public"> <summary>Takes an ordinary URI with GET parameters in it, and returns a URI compatible with the parseUri method. The optional lose parameter is a comma-separated list of key/value pairs in the URI to lose, but not from the parameter list (the stuff that follows the ?), but from the first part of the URI.</summary> <param name="uri" type="string" /> <param name="lose" type="string" /> <returns type="string" /> </method> !*/ function translateUri ($uri = "", $lose = "") { list ($start, $params) = split ("\?", $uri); $vars = array (); $lose_these = split (", ?", $lose); // compile array of key.value pairs foreach (split ("&", $params) as $p) { if (! empty ($p)) { array_push ($vars, ereg_replace ("=", ".", $p)); } } // lose specified already translated parts of the URI foreach ($lose_these as $p) { $start = ereg_replace ('/' . $p . '(\.?[^/]*)/', "/", $start); $start = ereg_replace ('/' . $p . '(\.?[^/]*)/?$', "", $start); } return $start . '/' . join ('/', $vars); } } /*! </class> </package> !*/ ?>