OSDN Git Service

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