4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5 * Copyright (C) 2002-2007 The Nucleus Group
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)
14 * @license http://nucleuscms.org/license.txt GNU General Public License
15 * @copyright Copyright (C) 2002-2007 The Nucleus Group
16 * @version $Id: vars4.0.6.php,v 1.6 2007-03-22 09:23:58 kimitake Exp $
17 * @version $NucleusJP: vars4.0.6.php,v 1.10 2007/02/04 06:28:46 kimitake Exp $
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
25 function getVar($name) {
26 global $HTTP_GET_VARS;
28 if (!isset($HTTP_GET_VARS[$name])) {
32 return undoMagic($HTTP_GET_VARS[$name]);
35 function postVar($name) {
36 global $HTTP_POST_VARS;
38 if (!isset($HTTP_POST_VARS[$name])) {
42 return undoMagic($HTTP_POST_VARS[$name]);
45 function cookieVar($name) {
46 global $HTTP_COOKIE_VARS;
48 if (!isset($HTTP_COOKIE_VARS[$name])) {
52 return undoMagic($HTTP_COOKIE_VARS[$name]);
55 // request: either POST or GET
56 function requestVar($name) {
57 return (postVar($name)) ? postVar($name) : getVar($name);
60 function serverVar($name) {
61 global $HTTP_SERVER_VARS;
63 if (!isset($HTTP_SERVER_VARS[$name])) {
67 return $HTTP_SERVER_VARS[$name];
70 // removes magic quotes if that option is enabled
71 function undoMagic($data) {
72 if (!get_magic_quotes_gpc())
74 if (ini_get('magic_quotes_sybase') != 1)
75 return stripslashes_array($data);
77 return undoSybaseQuotes_array($data);
80 function stripslashes_array($data) {
81 return is_array($data) ? array_map('stripslashes_array', $data) : stripslashes($data);
84 function undoSybaseQuotes_array($data) {
85 return is_array($data) ? array_map('undoSybaseQuotes', $data) : stripslashes($data);
88 function undoSybaseQuotes($data) {
89 return str_replace("''", "'", $data);
92 // integer array from request
93 function requestIntArray($name) {
94 global $HTTP_POST_VARS;
96 if (!isset($HTTP_POST_VARS[$name])) {
100 return $HTTP_POST_VARS[$name];
103 // array from request. Be sure to call undoMagic on the strings inside
104 function requestArray($name) {
105 global $HTTP_POST_VARS;
107 if (!isset($HTTP_POST_VARS[$name])) {
111 return $HTTP_POST_VARS[$name];
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')))
122 // a nextaction of 'showlogin' makes no sense
123 if (($key == 'nextaction') && ($value == 'showlogin'))
125 if (($key != 'login') && ($key != 'password'))
126 passVar($key, $value);
128 foreach ($HTTP_GET_VARS as $key => $value) {
129 if (($key == 'action') && ($value != requestVar('nextaction')))
131 // a nextaction of 'showlogin' makes no sense
132 if (($key == 'nextaction') && ($value == 'showlogin'))
134 if (($key != 'login') && ($key != 'password'))
135 passVar($key, $value);
139 function postFileInfo($name) {
140 global $HTTP_POST_FILES;
142 if (!isset($HTTP_POST_FILES[$name])) {
146 return $HTTP_POST_FILES[$name];
149 function setOldAction($value) {
150 global $HTTP_POST_VARS;
151 $HTTP_POST_VARS['oldaction'] = $value;