Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezhttptool.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezhttptool.php 8403 2001-11-14 10:27:34Z bf $
5 //
6 // Definition of eZTextTool class
7 //
8 // Created on: <23-Jan-2001 12:34:54 bf>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
31
38 class eZHTTPTool
39 {
43 function __construct()
44 {
45 $this->url_array =& explode( "/", $_SERVER['REQUEST_URI'] );
46 $this->url_array_length = count( $this->url_array );
47 }
48
55 static function getVar( $name, $onlyCheckPost=false )
56 {
57 if (is_array($name)) {
58 $ret = array();
59 foreach( $name as $v) {
60 $ret[] = eZHTTPTool::getVar($v,$onlyCheckPost);
61 }
62 return $ret;
63 }
64 if (isset($_POST[$name]))
65 {
66 return $_POST[$name];
67 }
68 if (!$onlyCheckPost && isset($_GET[$name]))
69 {
70 return $_GET[$name];
71 }
72 }
73
80 static function extractVar( $vars, $onlyCheckPost=false )
81 {
82 if (is_array($vars)) {
83 foreach( $vars as $v) {
84 $GLOBALS[$v] = eZHTTPTool::getVar($v,$onlyCheckPost);
85 }
86 }
87 }
88
96 static public function header( $string )
97 {
98 global $GlobalSiteIni;
99
100 $sid =& $_REQUEST["PHPSESSID"];
101
102 $cookie_vars = $_COOKIE;
103
104 // fix location if session is not by cookie
105 if ( !isset( $cookie_vars["PHPSESSID"] ) && isset( $sid ) )
106 {
107 $string = eZHTTPTool::removeVariable( $string, "PHPSESSID" );
108 $string = eZHTTPTool::addVariable( $string, "PHPSESSID", $sid );
109 }
110
111 // Redirect differently, when we are not using virtual hosts/mod_rewrite
112 if ( preg_match( "/^Location:[ ]*(\/.*)/", $string, $regs ) )
113 {
114 $string = "Location: " . $GlobalSiteIni->WWWDir . $GlobalSiteIni->Index . $regs[1];
115 }
116
117 header( $string );
118 }
119
124 static public function &addVariable( $url, $variable, $value )
125 {
126 $pos = strpos( $url, "?" );
127
128 if ( $pos )
129 {
130 $string = $url . "&" . $variable. "=" . $value;
131 }
132 else
133 {
134 $string = $url . "?" . $variable. "=" . $value;
135 }
136
137 return $string;
138 }
139
144 static public function &removeVariable( $url, $variable, $value = "" )
145 {
146 $pos = strpos( $url, "?" );
147
148 if ( $pos )
149 {
150 $start = substr( $url, 0, $pos );
151 $end = substr( $url, $pos );
152 if ( $value )
153 $end = preg_replace( "/&?$variable"."=".$value."/", "", $end );
154 else
155 $end = preg_replace( "/&?$variable"."=[^&]+/", "", $end );
156 if ( $end == "?" )
157 $end = "";
158 $url = $start . $end;
159 }
160
161 return $url;
162 }
163
171 static public function assignDate( $start, $prefix = "", $postfix = "" )
172 {
173 $url_array_length = $this->url_array_length;
174 $url_array =& $this->url_array;
175
176 $variableName = $prefix . "Year" . $postfix;
177 if( is_numeric( $url_array[ $start ] ) )
178 {
179 global $$variableName;
180 $$variableName = $url_array[ $start ];
181 $start++;
182 $year = true;
183 }
184
185 $variableName = $prefix . "Month" . $postfix;
186 if( is_numeric( $url_array[ $start ] ) && $year )
187 {
188 global $$variableName;
189 $$variableName = $url_array[ $start ];
190 $start++;
191 $month = true;
192 }
193
194 $variableName = $prefix . "Day" . $postfix;
195 if( is_numeric( $url_array[ $start ] ) && $month )
196 {
197 global $$variableName;
198 $$variableName = $url_array[ $start ];
199 $start++;
200 $day = true;
201 }
202
203 $variableName = $prefix . "Hour" . $postfix;
204 if( is_numeric( $url_array[ $start ] ) && $day && $url_array[ $start ] >= 0 && $url_array[ $start ] <= 23 )
205 {
206 global $$variableName;
207 $$variableName = $url_array[ $start ];
208 $start++;
209 $hour = true;
210 }
211
212 $variableName = $prefix . "Minute" . $postfix;
213 if( is_numeric( $url_array[ $start ] ) && $hour && $url_array[ $start ] >= 0 && $url_array[ $start ] <= 59 )
214 {
215 global $$variableName;
216 $$variableName = $url_array[ $start ];
217 $start++;
218 $minute = true;
219 }
220
221 $variableName = $prefix . "Second" . $postfix;
222 if( is_numeric( $url_array[ $start ] ) && $minute && $url_array[ $start ] >= 0 && $url_array[ $start ] <= 59 )
223 {
224 global $$variableName;
225 $$variableName = $url_array[ $start ];
226 $start++;
227 }
228
229 $end = $start;
230
231 return $end;
232 }
233
234
253 function assignValues( $position, $prefix = "", $postfix = "" )
254 {
255 $url_array_length = $this->url_array_length;
256 $url_array =& $this->url_array;
257
258 $i = $position;
259 $j = $i + 1;
260
261 for( $i; $j < $url_array_length; $i++, $j++ )
262 {
263 $arg = $url_array[$i];
264 $var = $url_array[$j];
265
266 if( is_string( $arg ) )
267 {
268 if( is_numeric( $var ) )
269 {
270 switch( $arg )
271 {
272 case "start":
273 case "begin":
274 case "from":
275 {
276 $i = $this->assignDate( $j, $prefix . ucfirst( $arg ) );
277 }
278 break;
279
280 case "end":
281 case "stop":
282 case "until":
283 {
284 $i = $this->assignDate( $j, $prefix . ucfirst( $arg ) );
285 }
286 break;
287
288 default:
289 {
290 $variableName = $prefix . ucfirst( $arg ) . $postfix;
291 global $$variableName;
292 $$variableName = $var;
293 }
294 break;
295 }
296 }
297 else
298 {
299 $variableName = $prefix . ucfirst( $arg ) . $postfix;
300 global $$variableName;
301 $$variableName = $var;
302 }
303 }
304 }
305 }
306
312 static public function setCookie( $variable, $value, $timeout=365 )
313 {
314 $exp= time() + ( $timeout * 86400 );
315 $exp=strftime("%a, %d-%b-%Y %H:%M:%S", $exp);
316 $exp="$exp GMT";
317 $host = $_SERVER["HTTP_HOST"];
318 header("Set-Cookie: $variable=$value;expires=$exp;path=/;domain=.$host");
319 }
320
325 static public function globaleZHTTPTool()
326 {
327 global $eZHTTPToolObject;
328
329 if ( !is_a( $eZHTTPToolObject, "eZHTTPTool" ) )
330 {
331 $eZHTTPToolObject = new eZHTTPTool();
332 }
333 return $eZHTTPToolObject;
334 }
335
339 var $url_array = array();
340
344 var $url_array_length = 0;
345 }
346
347 ?>
$i
$i
Definition: admin/adlist.php:91
$day
else $day
Definition: appointmentedit.php:665
$year
else $year
Definition: appointmentedit.php:655
$month
else $month
Definition: appointmentedit.php:660
eZHTTPTool
Definition: ezhttptool.php:39
eZHTTPTool\removeVariable
static & removeVariable( $url, $variable, $value="")
Definition: ezhttptool.php:144
eZHTTPTool\header
static header( $string)
Definition: ezhttptool.php:96
eZHTTPTool\getVar
static getVar( $name, $onlyCheckPost=false)
Definition: ezhttptool.php:55
eZHTTPTool\__construct
__construct()
Definition: ezhttptool.php:43
eZHTTPTool\setCookie
static setCookie( $variable, $value, $timeout=365)
Definition: ezhttptool.php:312
eZHTTPTool\assignValues
assignValues( $position, $prefix="", $postfix="")
Definition: ezhttptool.php:253
eZHTTPTool\$url_array
$url_array
Definition: ezhttptool.php:339
eZHTTPTool\extractVar
static extractVar( $vars, $onlyCheckPost=false)
Definition: ezhttptool.php:80
eZHTTPTool\globaleZHTTPTool
static globaleZHTTPTool()
Definition: ezhttptool.php:325
eZHTTPTool\$url_array_length
$url_array_length
Definition: ezhttptool.php:344
eZHTTPTool\assignDate
static assignDate( $start, $prefix="", $postfix="")
Definition: ezhttptool.php:171
eZHTTPTool\addVariable
static & addVariable( $url, $variable, $value)
Definition: ezhttptool.php:124
$name
$name
Definition: companytypelist.php:194
$minute
$minute
Definition: export_froogle.php:311
$hour
$hour
Definition: export_froogle.php:310
$GlobalSiteIni
$GlobalSiteIni
Definition: ezarticle/xmlrpc/xmlrpcserver.php:33
$j
$j
Definition: ezimagecatalogue/admin/imagelist.php:345
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$url
$url
Definition: messagereviewlist.php:153
$position
$position
Definition: quizscores.php:85
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.