Class Util

Description

The Util:: class provides generally useful methods of different kinds.

$Horde: framework/Util/Util.php,v 1.384.6.37 2009/07/21 18:17:23 slusarz Exp $

Copyright 1999-2009 The Horde Project (http://www.horde.org/)

See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.

Located in /Util/Util.php (line 28)


	
			
Method Summary
 string addParameter (string $url, mixed $parameter, [string $value = null], [boolean $encode = true])
 void assertDriverConfig (array $params, array $fields, string $name, [array $info = array()])
 string bufferOutput (string $function, mixed $arg1, mixed $arg2, mixed $arg..., mixed $argN)
 object The &cloneObject (object &$obj)
 void closeWindowJS ([string $code = ''])
 string createTempDir ([boolean $delete = true], [string $temp_dir = null])
 string date2strftime (string $format)
 void deleteAtShutdown ([string $filename = false], [boolean $register = true], [boolean $secure = false])
 string dispelMagicQuotes (string &$var)
 string formInput ([boolean $append_session = 0])
 string getFormData (string $var, [string $default = null])
 string getGet (string $var, [string $default = null])
 string getPathInfo ()
 string getPost (string $var, [string $default = null])
 string getTempDir ()
 string getTempFile ([string $prefix = ''], [boolean $delete = true], [string $dir = ''], [boolean $secure = false])
 string hmac (string $data, string $key, [boolean $raw_output = false])
 boolean loadExtension (string $ext)
 string nocacheUrl (string $url, [boolean $encode = true])
 mixed nonInputVar (string $varname, [mixed $default = null])
 void pformInput ([boolean $append_session = 0])
 string realPath (string $path)
 string removeParameter (string $url, mixed $remove)
 string strftime2date (string $format)
 string uriB64Decode (string $string)
 string uriB64Encode (string $string)
Methods
addParameter (line 161)

Adds a name=value pair to the end of an URL, taking care of whether there are existing parameters and whether to use ?, & or & as the glue. All data will be urlencoded.

  • return: The modified URL.
string addParameter (string $url, mixed $parameter, [string $value = null], [boolean $encode = true])
  • string $url: The URL to modify
  • mixed $parameter: Either the name=value pair to add (DEPRECATED) -or- the name value -or- an array of name/value pairs.
  • string $value: If specified, the value part ($parameter is then assumed to just be the parameter name).
  • boolean $encode: Encode the argument separator?
assertDriverConfig (line 784)

Checks if all necessary parameters for a driver's configuration are set and returns a PEAR_Error if something is missing.

void assertDriverConfig (array $params, array $fields, string $name, [array $info = array()])
  • array $params: The configuration array with all parameters.
  • array $fields: An array with mandatory parameter names for this driver.
  • string $name: The clear text name of the driver. If not specified, the application name will be used.
  • array $info: A hash containing detailed information about the driver. Will be passed as the userInfo to the PEAR_Error.
bufferOutput (line 73)

Buffers the output from a function call, like readfile() or highlight_string(), that prints the output directly, so that instead it can be returned as a string and used.

  • return: The output of the function.
string bufferOutput (string $function, mixed $arg1, mixed $arg2, mixed $arg..., mixed $argN)
  • string $function: The function to run.
  • mixed $arg1: First argument to $function().
  • mixed $arg2: Second argument to $function().
  • mixed $arg...: ...
  • mixed $argN: Nth argument to $function().
cloneObject (line 37)

Returns an object's clone.

  • return: cloned object.
object The &cloneObject (object &$obj)
  • object &$obj: The object to clone.
closeWindowJS (line 699)

Outputs javascript code to close the current window.

void closeWindowJS ([string $code = ''])
  • string $code: Any additional javascript code to run before closing the window.
createTempDir (line 505)

Creates a temporary directory in the system's temporary directory.

  • return: The pathname to the new temporary directory. Returns false if directory not created.
string createTempDir ([boolean $delete = true], [string $temp_dir = null])
  • boolean $delete: Delete the temporary directory at the end of the request?
  • string $temp_dir: Use this temporary directory as the directory where the temporary directory will be created.
date2strftime (line 815)

Returns a format string to be used by strftime().

  • return: A format string as similar as possible to $format.
string date2strftime (string $format)
  • string $format: A format string as used by date().
deleteAtShutdown (line 601)

Removes given elements at request shutdown.

If called with a filename will delete that file at request shutdown; if called with a directory will remove that directory and all files in that directory at request shutdown.

If called with no arguments, return all elements to be deleted (this should only be done by Util::_deleteAtShutdown).

The first time it is called, it initializes the array and registers Util::_deleteAtShutdown() as a shutdown function - no need to do so manually.

The second parameter allows the unregistering of previously registered elements.

void deleteAtShutdown ([string $filename = false], [boolean $register = true], [boolean $secure = false])
  • string $filename: The filename to be deleted at the end of the request.
  • boolean $register: If true, then register the element for deletion, otherwise, unregister it.
  • boolean $secure: If deleting file, should we securely delete the file?
dispelMagicQuotes (line 351)

If magic_quotes_gpc is in use, run stripslashes() on $var.

  • return: minus any magic quotes.
string dispelMagicQuotes (string &$var)
  • string &$var: The string to un-quote, if necessary.
formInput (line 324)

Returns a hidden form input containing the session name and id.

  • return: The hidden form input, if needed/requested.
string formInput ([boolean $append_session = 0])
  • boolean $append_session:
    1. = only if needed, 1 = always.
getFormData (line 382)

Gets a form variable from GET or POST data, stripped of magic quotes if necessary. If the variable is somehow set in both the GET data and the POST data, the value from the POST data will be returned and the GET value will be ignored.

  • return: The cleaned form variable, or $default.
string getFormData (string $var, [string $default = null])
  • string $var: The name of the form variable to look for.
  • string $default: The value to return if the variable is not there.
getGet (line 398)

Gets a form variable from GET data, stripped of magic quotes if necessary. This function will NOT return a POST variable.

  • return: The cleaned form variable, or $default.
string getGet (string $var, [string $default = null])
  • string $var: The name of the form variable to look for.
  • string $default: The value to return if the variable is not there.
getPathInfo (line 858)

Utility function to obtain PATH_INFO information.

  • return: The PATH_INFO string.
  • since: Horde 3.2
string getPathInfo ()
getPost (line 415)

Gets a form variable from POST data, stripped of magic quotes if necessary. This function will NOT return a GET variable.

  • return: The cleaned form variable, or $default.
string getPost (string $var, [string $default = null])
  • string $var: The name of the form variable to look for.
  • string $default: The value to return if the variable is not there.
getTempDir (line 428)

Determines the location of the system temporary directory.

  • return: A directory name which can be used for temp files. Returns false if one could not be found.
string getTempDir ()
getTempFile (line 469)

Creates a temporary filename for the lifetime of the script, and (optionally) register it to be deleted at request shutdown.

  • return: Returns the full path-name to the temporary file. Returns false if a temp file could not be created.
string getTempFile ([string $prefix = ''], [boolean $delete = true], [string $dir = ''], [boolean $secure = false])
  • string $prefix: Prefix to make the temporary name more recognizable.
  • boolean $delete: Delete the file at the end of the request?
  • string $dir: Directory to create the temporary file in.
  • boolean $secure: If deleting file, should we securely delete the file?
hmac (line 888)

Calculate an HMAC for a given $data and secret $key using SHA-1.

  • return: | binary HMAC
  • since: Horde 3.3
string hmac (string $data, string $key, [boolean $raw_output = false])
  • string $data: Data to sign
  • string $key: Secret key
  • boolean $raw_output: Return binary data? Default to hex.
loadExtension (line 735)

Tries to load a PHP extension, behaving correctly for all operating systems.

  • return: True if the extension is now loaded, false if not. True can mean that the extension was already loaded, OR was loaded dynamically.
boolean loadExtension (string $ext)
  • string $ext: The extension to load.
nocacheUrl (line 298)

Returns a url with the 'nocache' parameter added, if the browser is buggy and caches old URLs.

  • return: The requested URI.
string nocacheUrl (string $url, [boolean $encode = true])
  • string $url: The URL to modify.
  • boolean $encode: Encode the argument separator? (since Horde 3.2)
nonInputVar (line 134)

Checks to see if a value has been set by the script and not by GET, POST, or cookie input. The value being checked MUST be in the global scope.

  • return: if the var is in user input or not present, the variable value otherwise.
  • since: Horde 3.1
mixed nonInputVar (string $varname, [mixed $default = null])
  • string $varname: The variable name to check.
  • mixed $default: Default value if the variable isn't present or was specified by the user. Defaults to null.
pformInput (line 339)

Prints a hidden form input containing the session name and id.

void pformInput ([boolean $append_session = 0])
  • boolean $append_session:
    1. = only if needed, 1 = always.
realPath (line 545)

Returns the canonical path of the string. Like PHP's built-in realpath() except the directory need not exist on the local server.

Algorithim loosely based on code from the Perl File::Spec::Unix module (version 1.5).

  • return: The canonicalized file path.
  • since: Horde 3.0.5
string realPath (string $path)
  • string $path: A file path.
removeParameter (line 229)

Removes name=value pairs from a URL.

  • return: The modified URL.
string removeParameter (string $url, mixed $remove)
  • string $url: The URL to modify.
  • mixed $remove: Either a single parameter to remove or an array of parameters to remove.
strftime2date (line 843)

Returns a format string to be used by date().

  • return: A format string as similar as possible to $format.
string strftime2date (string $format)
  • string $format: A format string as used by strftime().
uriB64Decode (line 936)

Decode URL-safe base64 data, dealing with missing =

  • return: Decoded data.
  • since: Horde 3.3
string uriB64Decode (string $string)
  • string $string: Encoded data
uriB64Encode (line 920)

URL-safe base64 encoding, with trimmed =

  • return: URL-safe, base64 encoded data.
  • since: Horde 3.3
string uriB64Encode (string $string)
  • string $string: String to encode.

Documentation generated on Sun, 30 Jan 2011 05:23:04 +0000 by phpDocumentor 1.4.3