4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5 * Copyright (C) 2002-2012 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)
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
17 function getVar($name) {
18 global $HTTP_GET_VARS;
20 if (!isset($HTTP_GET_VARS[$name])) {
24 return undoMagic($HTTP_GET_VARS[$name]);
27 function postVar($name) {
28 global $HTTP_POST_VARS;
30 if (!isset($HTTP_POST_VARS[$name])) {
34 return undoMagic($HTTP_POST_VARS[$name]);
37 function cookieVar($name) {
38 global $HTTP_COOKIE_VARS;
40 if (!isset($HTTP_COOKIE_VARS[$name])) {
44 return undoMagic($HTTP_COOKIE_VARS[$name]);
47 // request: either POST or GET
48 function requestVar($name) {
49 return (postVar($name)) ? postVar($name) : getVar($name);
52 function serverVar($name) {
53 global $HTTP_SERVER_VARS;
55 if (!isset($HTTP_SERVER_VARS[$name])) {
59 return $HTTP_SERVER_VARS[$name];
62 // removes magic quotes if that option is enabled
63 function undoMagic($data) {
64 if (!get_magic_quotes_gpc())
66 if (ini_get('magic_quotes_sybase') != 1)
67 return stripslashes_array($data);
69 return undoSybaseQuotes_array($data);
72 function stripslashes_array($data) {
73 return is_array($data) ? array_map('stripslashes_array', $data) : stripslashes($data);
76 function undoSybaseQuotes_array($data) {
77 return is_array($data) ? array_map('undoSybaseQuotes_array', $data) : str_replace("''", "'", $data);
80 function undoSybaseQuotes($data) {
81 return str_replace("''", "'", $data);
84 // integer array from request
85 function requestIntArray($name) {
86 global $HTTP_POST_VARS;
88 if (!isset($HTTP_POST_VARS[$name])) {
92 return $HTTP_POST_VARS[$name];
95 // array from request. Be sure to call undoMagic on the strings inside
96 function requestArray($name) {
97 global $HTTP_POST_VARS;
99 if (!isset($HTTP_POST_VARS[$name])) {
103 return $HTTP_POST_VARS[$name];
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')))
114 // a nextaction of 'showlogin' makes no sense
115 if (($key == 'nextaction') && ($value == 'showlogin'))
117 if (($key != 'login') && ($key != 'password'))
118 passVar($key, $value);
120 foreach ($HTTP_GET_VARS as $key => $value) {
121 if (($key == 'action') && ($value != requestVar('nextaction')))
123 // a nextaction of 'showlogin' makes no sense
124 if (($key == 'nextaction') && ($value == 'showlogin'))
126 if (($key != 'login') && ($key != 'password'))
127 passVar($key, $value);
131 function postFileInfo($name) {
132 global $HTTP_POST_FILES;
134 if (!isset($HTTP_POST_FILES[$name])) {
138 return $HTTP_POST_FILES[$name];
141 function setOldAction($value) {
142 global $HTTP_POST_VARS;
143 $HTTP_POST_VARS['oldaction'] = $value;