OSDN Git Service

dec0e21faf1c46a8dfbdf5f70d1dade2fbc2b757
[nucleus-jp/nucleus-jp-ancient.git] / nucleus / libs / vars4.1.0.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
14 // Remove $_COOKIE keys in $_REQUEST
15 // This is for maintaining the compatibility with PHP 4.0.6
16 // and also for avoiding bugs of plugins due to cookie keys
17 if (isset($_REQUEST) and isset($_COOKIE)) {
18         foreach($_COOKIE as $key=>$value) {
19                 if (isset($_REQUEST[$key])) unset($_REQUEST[$key]);
20         }
21 }
22
23 function getVar($name) {
24         if (!isset($_GET[$name])) {
25                 return;
26         }
27
28         return undoMagic($_GET[$name]);
29 }
30
31 function postVar($name) {
32         if (!isset($_POST[$name])) {
33                 return;
34         }
35
36         return undoMagic($_POST[$name]);
37 }
38
39 function cookieVar($name) {
40         if (!isset($_COOKIE[$name])) {
41                 return;
42         }
43
44         return undoMagic($_COOKIE[$name]);
45 }
46
47 function requestVar($name) {
48         if(array_key_exists($name,$_REQUEST))
49                 return undoMagic($_REQUEST[$name]);
50         elseif( array_key_exists($name,$_GET))
51                 return undoMagic($_GET[$name]);
52         elseif( array_key_exists($name,$_POST))
53                 return undoMagic($_POST[$name]);
54         else
55                 return;
56 }
57
58 function serverVar($name) {
59         if (!isset($_SERVER[$name])) {
60                 return false;
61         }
62
63         return $_SERVER[$name];
64 }
65
66 // removes magic quotes if that option is enabled
67 function undoMagic($data) {
68         if (!get_magic_quotes_gpc())
69                 return $data;
70         if (ini_get('magic_quotes_sybase') != 1)
71                 return stripslashes_array($data);
72         else
73                 return undoSybaseQuotes_array($data);
74 }
75
76 function stripslashes_array($data) {
77         return is_array($data) ? array_map('stripslashes_array', $data) : stripslashes($data);
78 }
79
80 function undoSybaseQuotes_array($data) {
81         return is_array($data) ? array_map('undoSybaseQuotes_array', $data) : str_replace("''", "'", $data);
82 }
83
84 function undoSybaseQuotes($data) {
85         return str_replace("''", "'", $data);
86 }
87
88 // integer array from request
89 function requestIntArray($name) {
90         if (!isset($_REQUEST[$name])) {
91                 return;
92         }
93
94         return $_REQUEST[$name];
95 }
96
97 // array from request. Be sure to call undoMagic on the strings inside
98 function requestArray($name) {
99         if (!isset($_REQUEST[$name])) {
100                 return;
101         }
102
103         return $_REQUEST[$name];
104 }
105
106 // add all the variables from the request as hidden input field
107 // @see globalfunctions.php#passVar
108 function passRequestVars() {
109         foreach ($_REQUEST as $key => $value) {
110                 if (($key == 'action') && ($value != requestVar('nextaction')))
111                         $key = 'nextaction';
112
113                 // a nextaction of 'showlogin' makes no sense
114                 if (($key == 'nextaction') && ($value == 'showlogin'))
115                         continue;
116
117                 if (($key != 'login') && ($key != 'password'))
118                         passVar($key, $value);
119         }
120 }
121
122 function postFileInfo($name) {
123         if (!isset($_FILES[$name])) {
124                 return;
125         }
126
127         return $_FILES[$name];
128 }
129
130 function setOldAction($value) {
131         $_POST['oldaction'] = $value;
132 }
133
134
135 ?>