OSDN Git Service

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