OSDN Git Service

Merge branch 'skinnable-master'
[nucleus-jp/nucleus-next.git] / nucleus / libs / vars4.1.0.php
1 <?php
2
3 /*
4  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5  * Copyright (C) 2002-2009 The Nucleus Group
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * (see nucleus/documentation/index.html#license for more info)
12  */
13 /**
14  * @license http://nucleuscms.org/license.txt GNU General Public License
15  * @copyright Copyright (C) 2002-2009 The Nucleus Group
16  * @version $Id: vars4.1.0.php 1544 2011-06-25 22:32:50Z kaigreve $
17  */
18
19 /**
20  * Return the value of $_GET for the variable $name
21  * 
22  * If the variable is set the function returns the value,
23  * if it is not set it returns null (which is equal to false).
24  * 
25  * @param unknown_type $name
26  */
27 function getVar($name) {
28         if (!isset($_GET[$name])) {
29                 return;
30         }
31
32         return undoMagic($_GET[$name]);
33 }
34
35 /**
36  * Return the value of $_POST for the variable $name
37  * 
38  * If the variable is set the function returns the value,
39  * if it is not set it returns null (which is equal to false).
40  * 
41  * @param unknown_type $name
42  */
43 function postVar($name) {
44         if (!isset($_POST[$name])) {
45                 return;
46         }
47
48         return undoMagic($_POST[$name]);
49 }
50
51 /**
52  * Return the value of $_COOKIE for the variable $name
53  * 
54  * If the variable is set the function returns the value,
55  * if it is not set it returns null (which is equal to false).
56  * 
57  * @param unknown_type $name
58  */
59 function cookieVar($name) {
60         if (!isset($_COOKIE[$name])) {
61                 return;
62         }
63
64         return undoMagic($_COOKIE[$name]);
65 }
66
67 /**
68  * Return the request var for the variable $name
69  * 
70  * If the variable is set the function returns the value,
71  * if it is not set it returns null (which is equal to false).
72  * Trys to resolve also $_GET and $_POST
73  * 
74  * @param unknown_type $name
75  */
76 function requestVar($name) {
77         if(array_key_exists($name,$_REQUEST))
78                 return undoMagic($_REQUEST[$name]);
79         elseif( array_key_exists($name,$_GET))
80                 return undoMagic($_GET[$name]);
81         elseif( array_key_exists($name,$_POST))
82                 return undoMagic($_POST[$name]);
83         else
84                 return;
85 }
86
87 /**
88  * Return the value of $_SERVER for the variable $name
89  * 
90  * If the variable is set the function returns the value,
91  * if it is not set it returns null (which is equal to false)
92  * 
93  * @param unknown_type $name
94  */
95 function serverVar($name) {
96         if (!isset($_SERVER[$name])) {
97                 return false;
98         }
99
100         return $_SERVER[$name];
101 }
102
103 /**
104  * Removes magic quotes if that option is enabled
105  * 
106  * @param $data
107  */
108 function undoMagic($data) {
109         if (!get_magic_quotes_gpc())
110                 return $data;
111         if (ini_get('magic_quotes_sybase') != 1)
112                 return stripslashes_array($data);
113         else
114                 return undoSybaseQuotes_array($data);
115 }
116
117 /**
118  * Strip slashes from a variable or an array
119  * 
120  * @param $data
121  */
122 function stripslashes_array($data) {
123         return is_array($data) ? array_map('stripslashes_array', $data) : stripslashes($data);
124 }
125
126 /**
127  * Undo Sybase Quotes from an array
128  * 
129  * @param $data
130  */
131 function undoSybaseQuotes_array($data) {
132         return is_array($data) ? array_map('undoSybaseQuotes', $data) : stripslashes($data);
133 }
134
135 /**
136  * Undo Sybase Quotes from a variable
137  * 
138  * @param $data
139  */
140 function undoSybaseQuotes($data) {
141         return str_replace("''", "'", $data);
142 }
143
144 /**
145  * Integer array from request
146  * 
147  * @param unknown_type $name
148  */
149 function requestIntArray($name) {
150         if (!isset($_REQUEST[$name])) {
151                 return;
152         }
153
154         return $_REQUEST[$name];
155 }
156
157 /**
158  * Array from request. Be sure to call undoMagic on the strings inside.
159  * 
160  * @param $name
161  */
162 function requestArray($name) {
163         if (!isset($_REQUEST[$name])) {
164                 return;
165         }
166
167         return $_REQUEST[$name];
168 }
169
170 /**
171  *  add all the variables from the request as hidden input field
172  *  @see globalfunctions.php#passVar
173  * 
174  */
175 function passRequestVars() {
176         foreach ($_REQUEST as $key => $value) {
177                 if (($key == 'action') && ($value != requestVar('nextaction')))
178                         $key = 'nextaction';
179
180                 // a nextaction of 'showlogin' makes no sense
181                 if (($key == 'nextaction') && ($value == 'showlogin'))
182                         continue;
183
184                 if (($key != 'login') && ($key != 'password'))
185                         passVar($key, $value);
186         }
187 }
188
189 /**
190  * Return the value of $_FILES for the variable $name
191  * 
192  * If the variable is set the function returns the value,
193  * if it is not set it returns null (which is equal to false)
194  * 
195  * @param $name
196  */
197 function postFileInfo($name) {
198         if (!isset($_FILES[$name])) {
199                 return;
200         }
201
202         return $_FILES[$name];
203 }
204
205 /**
206  * Sets the $_POST variable oldaction to the given value
207  * 
208  * @param $value
209  */
210 function setOldAction($value) {
211         $_POST['oldaction'] = $value;
212 }
213
214 ?>