OSDN Git Service

merged 3.3 beta1
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / vars4.0.6.php
1 <?php
2
3 /*
4  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5  * Copyright (C) 2002-2006 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-2006 The Nucleus Group
16  * @version $Id: vars4.0.6.php,v 1.7 2006-07-12 07:11:47 kimitake Exp $
17  * $NucleusJP: vars4.0.6.php,v 1.6 2005/08/13 07:33:02 kimitake Exp $
18  */
19
20 /**
21   * The purpose of the functions below is to avoid declaring HTTP_ vars to be global
22   * everywhere, plus to offer support for php versions before 4.1.0, that do not
23   * have the _GET etc vars
24   */
25 function getVar($name) {
26         global $HTTP_GET_VARS;
27
28         if (!isset($HTTP_GET_VARS[$name])) {
29                 return;
30         }
31
32         return undoMagic($HTTP_GET_VARS[$name]);
33 }
34
35 function postVar($name) {
36         global $HTTP_POST_VARS;
37
38         if (!isset($HTTP_POST_VARS[$name])) {
39                 return;
40         }
41
42         return undoMagic($HTTP_POST_VARS[$name]);
43 }
44
45 function cookieVar($name) {
46         global $HTTP_COOKIE_VARS;
47
48         if (!isset($HTTP_COOKIE_VARS[$name])) {
49                 return;
50         }
51
52         return undoMagic($HTTP_COOKIE_VARS[$name]);
53 }
54
55 // request: either POST or GET
56 function requestVar($name) {
57         return (postVar($name)) ? postVar($name) : getVar($name);
58 }
59
60 function serverVar($name) {
61         global $HTTP_SERVER_VARS;
62
63         if (!isset($HTTP_SERVER_VARS[$name])) {
64                 return;
65         }
66
67         return $HTTP_SERVER_VARS[$name];
68 }
69
70 // removes magic quotes if that option is enabled
71 function undoMagic($data) {
72         if (!get_magic_quotes_gpc())
73                 return $data;
74         if (ini_get('magic_quotes_sybase') != 1)
75                 return stripslashes_array($data);
76         else
77                 return undoSybaseQuotes_array($data);
78 }
79
80 function stripslashes_array($data) {
81         return is_array($data) ? array_map('stripslashes', $data) : stripslashes($data);
82 }
83
84 function undoSybaseQuotes_array($data) {
85         return is_array($data) ? array_map('undoSybaseQuotes', $data) : stripslashes($data);
86 }
87
88 function undoSybaseQuotes($data) {
89         return str_replace("''", "'", $data);
90 }
91
92 // integer array from request
93 function requestIntArray($name) {
94         global $HTTP_POST_VARS;
95
96         if (!isset($HTTP_POST_VARS[$name])) {
97                 return;
98         }
99
100         return $HTTP_POST_VARS[$name];
101 }
102
103 // array from request. Be sure to call undoMagic on the strings inside
104 function requestArray($name) {
105         global $HTTP_POST_VARS;
106
107         if (!isset($HTTP_POST_VARS[$name])) {
108                 return;
109         }
110
111         return $HTTP_POST_VARS[$name];
112 }
113
114
115 // add all the variables from the request as hidden input field
116 // @see globalfunctions.php#passVar
117 function passRequestVars() {
118         global $HTTP_POST_VARS, $HTTP_GET_VARS;
119         foreach ($HTTP_POST_VARS as $key => $value) {
120                 if (($key == 'action') && ($value != requestVar('nextaction')))
121                         $key = 'nextaction';
122                 // a nextaction of 'showlogin' makes no sense
123                 if (($key == 'nextaction') && ($value == 'showlogin'))
124                         continue;
125                 if (($key != 'login') && ($key != 'password'))
126                         passVar($key, $value);
127         }
128         foreach ($HTTP_GET_VARS as $key => $value) {
129                 if (($key == 'action') && ($value != requestVar('nextaction')))
130                         $key = 'nextaction';
131                 // a nextaction of 'showlogin' makes no sense
132                 if (($key == 'nextaction') && ($value == 'showlogin'))
133                         continue;
134                 if (($key != 'login') && ($key != 'password'))
135                         passVar($key, $value);
136         }
137 }
138
139 function postFileInfo($name) {
140         global $HTTP_POST_FILES;
141
142         if (!isset($HTTP_POST_FILES[$name])) {
143                 return;
144         }
145
146         return $HTTP_POST_FILES[$name];
147 }
148
149 function setOldAction($value) {
150         global $HTTP_POST_VARS;
151         $HTTP_POST_VARS['oldaction'] = $value;
152 }
153
154 ?>