|
From: <mxb...@li...> - 2005-03-17 19:48:53
|
Update of /cvsroot/mxbb/core/includes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8498 Modified Files: mx_functions.php Log Message: Added a few comments to further document usage and inners of class mx_request_vars (defined in mx_functions.php, for now) Index: mx_functions.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/mx_functions.php,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** mx_functions.php 17 Mar 2005 12:45:35 -0000 1.30 --- mx_functions.php 17 Mar 2005 19:48:41 -0000 1.31 *************** *** 1123,1134 **** // Following flags are options for the $type parameter in method _read() // ! define('MX_TYPE_INT' , 1); ! define('MX_TYPE_FLOAT' , 2); ! define('MX_TYPE_NO_HTML' , 4); ! define('MX_TYPE_NO_TAGS' , 8); ! define('MX_TYPE_NO_STRIP' , 16); ! define('MX_TYPE_NO_SQL' , 32); ! define('MX_TYPE_POST_VARS' , 64); ! define('MX_TYPE_GET_VARS' , 128); // --- 1123,1145 ---- // Following flags are options for the $type parameter in method _read() // ! define('MX_TYPE_INT' , 1); // Be sure we get a request var of type INT. ! define('MX_TYPE_FLOAT' , 2); // Be sure we get a request var of type FLOAT. ! define('MX_TYPE_NO_HTML' , 4); // Be sure we get a request var of type STRING (htmlspecialchars). ! define('MX_TYPE_NO_TAGS' , 8); // Be sure we get a request var of type STRING (strip_tags + htmlspecialchars). ! define('MX_TYPE_NO_STRIP' , 16); // By default strings are slash stripped, this flag avoids this. ! define('MX_TYPE_NO_SQL' , 32); // Be sure we get a request var of type STRING, safe for SQL statements (single quotes escaped) ! define('MX_TYPE_POST_VARS' , 64); // Read a POST variable. ! define('MX_TYPE_GET_VARS' , 128); // Read a GET variable. ! ! // ! // Additional notes: ! // ! // More than one can specified by OR'ing the $type argument. Example: ! // For instance, we can use ( MX_TYPE_POST_VARS | MX_TYPE_GET_VARS ), see method request(). ! // or we can use ( MX_TYPE_NO_TAGS | MX_TYPE_NO_SQL ). ! // However, MX_TYPE_NO_HTML and MX_TYPE_NO_TAGS can't be specified at a time (defaults to MX_TYPE_NO_HTML). ! // Also, MX_TYPE_INT and MX_TYPE_FLOAT ignore flags MX_TYPE_NO_* ! // ! // *************** *** 1139,1152 **** // $mx_request_vars = new mx_request_vars(); // $mode = $mx_request_vars->post('mode', MX_TYPE_NO_TAGS, ''); ! // $page_id = $mx_request_vars->post('page', MX_TYPE_INT, 1); // class mx_request_vars { // ! // Properties // // ! // Contructor // //function mx_request_vars() --- 1150,1171 ---- // $mx_request_vars = new mx_request_vars(); // $mode = $mx_request_vars->post('mode', MX_TYPE_NO_TAGS, ''); ! // $page_id = $mx_request_vars->get('page', MX_TYPE_INT, 1); // class mx_request_vars { // ! // Implementation Conventions: ! // Properties and methods prefixed with underscore are intented to be private. ;-) // + // ------------------------------ + // Properties // ! ! // none in this class. ! ! ! // ------------------------------ ! // Constructor // //function mx_request_vars() *************** *** 1155,1160 **** //} // ! // Private Methods (convention: first char in name is underscore) // function _read($var, $type = 0, $dflt = '') --- 1174,1190 ---- //} + + // ------------------------------ + // Private Methods // ! ! // ! // Function: _read() ! // Description: Get the value of the specified request var (post or get) and force the result to be ! // of specified type. It might also transform the result (stripslashes, htmlspecialchars) for security ! // purposes. It all depends on the $type argument. ! // If the specified request var does not exist, then the default ($dflt) value is returned. ! // Note the $type argument behaves as a bit array where more than one option can be specified by OR'ing ! // the passed argument. This is tipical practice in languages like C, but it can also be done with PHP. // function _read($var, $type = 0, $dflt = '') *************** *** 1242,1248 **** } ! // // Public Methods // function post($var, $type = 0, $dflt = '') { --- 1272,1282 ---- } ! // ------------------------------ // Public Methods // + + // + // _read() wrappers to retrieve POST, GET or any REQUEST (both) variable. + // function post($var, $type = 0, $dflt = '') { *************** *** 1253,1259 **** --- 1287,1302 ---- return $this->_read($var, ($type | MX_TYPE_GET_VARS), $dflt); } + function request($var, $type = 0, $dflt = '') + { + return $this->_read($var, ($type | MX_TYPE_POST_VARS | MX_TYPE_GET_VARS), $dflt); + } + + // + // Boolean methods to check for existence of POST, GET or any REQUEST (both) variable. + // function is_post($var) { global $HTTP_POST_VARS; + // Note: _x and _y are used by (at least IE) to return the mouse position at onclick of INPUT TYPE="img" elements. return ( isset($HTTP_POST_VARS[$var]) || ( isset($HTTP_POST_VARS[$var.'_x']) && isset($HTTP_POST_VARS[$var.'_y']) ) ); } |