[ Index ]
 

Code source de b2evolution 2.1.0-beta

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/blogs/inc/_core/ -> _param.funcs.php (sommaire)

This file implements parameter handling functions. This inlcudes: - sanity checking of inputs - removing PHP's stupid "magic" quotes - validating specific inputs (urls, regexps...) - memorizing params - regenerating urls with the memorized params - manually reconstructing urls

Author: cafelog (team)
Author: blueyed: Daniel HAHLER.
Author: fplanque: Francois PLANQUE.
Copyright: (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}
Version: $Id: _param.funcs.php,v 1.5 2007/11/01 19:52:46 fplanque Exp $
Poids: 1760 lignes (51 kb)
Inclus ou requis:0 fois
Référencé: 0 fois
Nécessite: 0 fichiers

Définit 45 fonctions

  param()
  param_arrayindex()
  param_action()
  param_cookie()
  param_string_not_empty()
  param_check_not_empty()
  param_check_number()
  param_integer_range()
  param_check_range()
  param_check_email()
  param_check_url()
  param_check_filename()
  param_check_isregexp()
  param_date()
  param_check_date()
  param_compact_date()
  param_time()
  param_extend_list()
  param_compile_cat_array()
  params_check_at_least_one()
  param_combo()
  param_child_select_value()
  param_check_phone()
  param_check_passwords()
  param_errors_detected()
  param_has_error()
  param_get_error_msg()
  param_error()
  param_error_multiple()
  param_add_message_to_Log()
  memorize_param()
  forget_param()
  param_ismemorized()
  set_param()
  get_param()
  get_memorized()
  regenerate_url()
  url_add_param()
  url_add_tail()
  validate_url()
  is_regexp()
  _trapError()
  remove_magic_quotes()
  remove_magic_quotes()
  remove_magic_quotes()

Fonctions
Fonctions qui ne font pas partie d'une Classe:

param( $var, $type = '', $default = '', $memorize = false, $override = false, $use_default = true, $strict_typing = 'allow_empty' )   X-Ref
Sets a parameter with values from the request or to provided default,
except if param is already set!

Also removes magic quotes if they are set automatically by PHP.
Also forces type.
Priority order: POST, GET, COOKIE, DEFAULT.

param: string Variable to set
param: string Force value type to one of:
param: mixed Default value or TRUE if user input required
param: boolean Do we need to memorize this to regenerate the URL for this page?
param: boolean Override if variable already set
param: boolean Force setting of variable to default if no param is sent and var wasn't set before
param: mixed true will refuse illegal values,
return: mixed Final value of Variable, or false if we don't force setting and did not set

param_arrayindex( $param_name, $default = '' )   X-Ref
Get the param from an array param's first index instead of the value.

E.g., for "param[value]" as a submit button you can get the value with
<code>Request::param_arrayindex( 'param' )</code>.

param: string Param name
param: mixed Default to use
return: string

param_action( $default = '', $memorize = false )   X-Ref
Get the action from params.

If we got no "action" param, we'll check for an "actionArray" param
( <input type="submit" name="actionArray[real_action]" ...> ).
And the real $action will be found in the first key...
When there are multiple submit buttons, this is smarter than checking the value which is a translated string.
When there is an image button, this allows to work around IE not sending the value (it only sends X & Y coords of the click).

param: mixed Default to use.
return: string

param_cookie($var, $type = '', $default = '', $memorize = false, $override = false, $use_default = true, $strict_typing = 'allow_empty')   X-Ref
Get a param from cookie.

{@internal This is just a wrapper around {@link param()} which unsets and
restores GET and POST. IMHO this is less hackish, at least performance
wise then using a $sources param for param()}}


param_string_not_empty( $var, $err_msg, $field_err_msg = NULL )   X-Ref

param: string param name
param: string error message
param: string|NULL error message for form field ($err_msg gets used if === NULL).
return: boolean true if OK

param_check_not_empty( $var, $err_msg, $field_err_msg = NULL )   X-Ref

param: string param name
param: string error message
param: string|NULL error message for form field ($err_msg gets used if === NULL).
return: boolean true if OK

param_check_number( $var, $err_msg, $required = false )   X-Ref
Checks if the param is a decimal number (no float, e.g. 3.14).

param: string param name
param: string error message
return: boolean true if OK

param_integer_range( $var, $min, $max, $err_msg, $required = true )   X-Ref
Gets a param and makes sure it's a decimal number (no float, e.g. 3.14) in a given range.

param: string param name
param: integer min value
param: integer max value
param: string error message (gets printf'ed with $min and $max)
return: boolean true if OK

param_check_range( $var, $min, $max, $err_msg, $required = true )   X-Ref
Checks if the param is a decimal number (no float, e.g. 3.14) in a given range.

param: string param name
param: integer min value
param: integer max value
param: string error message (gets printf'ed with $min and $max)
param: boolean Is the param required?
return: boolean true if OK

param_check_email( $var, $required = false )   X-Ref

param: string param name
return: boolean true if OK

param_check_url( $var, & $uri_scheme )   X-Ref

param: string param name
param: string error message
return: boolean true if OK

param_check_filename( $var, $err_msg )   X-Ref
Check if the value is a file name

param: string param name
param: string error message
return: boolean true if OK

param_check_isregexp( $var, $err_msg, $field_err_msg = NULL )   X-Ref
Check if the value of a param is a regular expression (syntax).

param: string param name
param: string error message
param: string|NULL error message for form field ($err_msg gets used if === NULL).
return: boolean true if OK

param_date( $var, $err_msg, $required, $default = '', $date_format = NULL )   X-Ref
Sets a date parameter by converting locale date (if valid) to ISO date.

If the date is not valid, it is set to the param unchanged (unconverted).

param: string param name
param: string error message
param: boolean Is a non-empty date required?
param: string Default (in the format of $date_format)
param: string|NULL date format (php format), defaults to {@link locale_datefmt()}

param_check_date( $var, $err_msg, $required = false, $date_format = NULL )   X-Ref
Check if param is an ISO date.

NOTE: for tokens like e.g. "D" (abbr. weekday), T_() gets used and it uses the current locale!

param: string param name
param: string error message
param: boolean Is a non-empty date required?
param: string date format (php format)
return: boolean|string false if not OK, ISO date if OK

param_compact_date( $var, $default = '', $memorize = false, $err_msg, $required = false )   X-Ref
Sets a date parameter with values from the request or to provided default,
And check we have a compact date (numbers only) ( used for URL filtering )

param: string Variable to set
param: mixed Default value or TRUE if user input required
param: boolean memorize ( see {@link param()} )
param: string error message
param: boolean 'required': Is non-empty date required? Default: true.
return: string the compact date value ( yyyymmdd )

param_time( $var, $default = '', $memorize = false, $override = false, $forceset = true )   X-Ref
Sets a time parameter with the value from the request of the var argument
or of the concat of the var argument_h: var argument_mn: var argument_s ,
except if param is already set!

param: string Variable to set
param: mixed Default value or TRUE if user input required
param: boolean Do we need to memorize this to regenerate the URL for this page?
param: boolean Override if variable already set
param: boolean Force setting of variable to default?
return: mixed Final value of Variable, or false if we don't force setting and did not set

param_extend_list( $var, $var_ext_array, $save_prefix = true )   X-Ref
Extend a LIST parameter with an ARRAY param.

Will be used for author/authorsel[], etc.
Note: cannot be used for catsel[], because catsel is NON-recursive.
param: string Variable to extend
param: string Name of array Variable to use as an extension
param: boolean Save non numeric prefix?  ( 1 char -- can be used as a modifier, e-g: - + * )

param_compile_cat_array( $restrict_to_blog = 0, $cat_default = NULL, $catsel_default = array()   X-Ref
Compiles the cat array from $cat (recursive + optional modifiers) and $catsel[] (non recursive)
and keeps those values available for future reference (category widget)


params_check_at_least_one( $vars, $err_msg, $field_err_msg = NULL )   X-Ref

param: array of param names
param: string error message
param: string|NULL error message for form field ($err_msg gets used if === NULL).
return: boolean true if OK

param_combo( $var, $default, $allow_none, $err_msg = '' )   X-Ref
Sets a combo parameter with values from the request,
=> the value of the select option and the input text value if new is selected
Display an error if the new value is selected that the input text has a value

param: string Variable to set
param: mixed Default value or TRUE if user input required
param: boolean true: allows to select new without entring a value in the input combo text
param: string error message
return: string position status ID or 'new' or '' if new is seleted but not input text value

param_child_select_value( $var )   X-Ref
set a parameter with the second part(X2) of the value from request ( X1-X2 )

param: string Variable to set

param_check_phone( $var, $required = false )   X-Ref

param: string param name
return: boolean true if OK

param_check_passwords( $var1, $var2, $required = false )   X-Ref

param: string param name
param: string param name
param: boolean Is a password required? (non-empty)
return: boolean true if OK

param_errors_detected()   X-Ref
Check if there have been validation errors

We play it safe here and check for all kind of errors, not just those from this particular class.

return: integer

param_has_error( $var )   X-Ref
Tell if there is an error on given field.


param_get_error_msg( $var )   X-Ref
Get error message for a param

return: string

param_error( $var, $err_msg, $field_err_msg = NULL )   X-Ref
Add an error for a variable, either to the Form's field and/or the global {@link $Messages} object.

param: string param name
param: string|NULL error message (by using NULL you can only add an error to the field, but not the $Message object)
param: string|NULL error message for form field ($err_msg gets used if === NULL).

param_error_multiple( $vars, $err_msg, $field_err_msg = NULL )   X-Ref
Add an error for multiple variables, either to the Form's field and/or the global {@link $Messages} object.

param: array of param names
param: string|NULL error message (by using NULL you can only add an error to the field, but not the $Message object)
param: string|NULL error message for form fields ($err_msg gets used if === NULL).

param_add_message_to_Log( $var, $err_msg, $log_category = 'error' )   X-Ref
This function is used by {@link param_error()} and {@link param_error_multiple()}.

If {@link $link_param_err_messages_to_field_IDs} is true, it will link those parts of the
error message that are not already links, to the html IDs of the fields with errors.

param: string param name
param: string error message

memorize_param( $var, $type, $default, $value = NULL )   X-Ref
Set a param (global) & Memorize it for automatic future use in regenerate_url()

param: string Variable to memorize
param: string Type of the variable
param: mixed Default value to compare to when regenerating url
param: mixed Value to set

forget_param( $var )   X-Ref
Forget a param so that is will not get included in subsequent {@link regenerate_url()} calls.

param: string Param name

param_ismemorized( $var )   X-Ref
Has the param already been memorized?


set_param( $var, $value )   X-Ref
Set the value of a param (by force! :P)

Same as setting a global, except you don't need a global declaration in your function.

get_param( $var )   X-Ref
Get the value of a param.

return: NULL|mixed The value of the param, if set. NULL otherwise.

get_memorized( $ignore = '' )   X-Ref
Construct an array of memorized params which are not in the ignore list

param: mixed string or array of ignore params

regenerate_url( $ignore = '', $set = '', $pagefileurl = '', $glue = '&amp;' )   X-Ref
Regenerate current URL from parameters
This may clean it up
But it is also useful when generating static pages: you cannot rely on $_REQUEST[]

param: mixed|string (delimited by commas) or array of params to ignore (can be regexps in /.../)
param: array|string Param(s) to set
param: mixed|string Alternative URL we want to point to if not the current URL (may be absolute if BASE tag gets used)
param: string Delimiter to use for multiple params (typically '&amp;' or '&')

url_add_param( $url, $param, $glue = '&amp;' )   X-Ref
Add param(s) at the end of an URL, using either "?" or "&amp;" depending on existing url

param: string existing url
param: string params to add
param: string delimiter to use for more params

url_add_tail( $url, $tail )   X-Ref
Add a tail (starting with "/") at the end of an URL before any params (starting with "?")

param: string existing url
param: string tail to add

validate_url( $url, & $allowed_uri_scheme, $absolute = false, $verbose = false )   X-Ref
Check the validity of a given URL

Checks allowed URI schemes and URL ban list.
URL can be empty.

Note: We have a problem when trying to "antispam" a keyword which is already blacklisted
If that keyword appears in the URL... then the next page has a bad referer! :/

{@internal This function gets tested in misc.funcs.simpletest.php.}}

param: string Url to validate
param: array Allowed URI schemes (see /conf/_formatting.php)
param: boolean Must the URL be absolute?
param: boolean Return verbose error message? (Should get only used in the backoffice)
return: mixed false (which means OK) or error message

is_regexp( $reg_exp, $includes_delim = false )   X-Ref
Checks if a given regular expression is valid.

It changes the error_handler and restores it.

author: plenque at hotmail dot com {@link http://php.net/manual/en/function.preg-match.php}
param: string the regular expression to test
param: boolean does the regular expression includes delimiters (and optionally modifiers)?
return: boolean

_trapError( $reset = 1 )   X-Ref
Meant to replace error handler temporarily.

return: integer number of errors

remove_magic_quotes( $mixed )   X-Ref


remove_magic_quotes( $mixed )   X-Ref
Remove quotes from input.
This handles magic_quotes_gpc and magic_quotes_sybase PHP settings/variants.

NOTE: you should not use it directly, but one of the param-functions!

param: mixed string or array (function is recursive)
return: mixed Value, with magic quotes removed

remove_magic_quotes( $mixed )   X-Ref




Généré le : Thu Nov 29 23:58:50 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics