\Horde_Util

The Horde_Util:: class provides generally useful methods.

Copyright 1999-2017 Horde LLC (http://www.horde.org/)

See the enclosed file LICENSE for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.

Summary

Methods
Properties
Constants
nonInputVar()
formInput()
pformInput()
dispelMagicQuotes()
getFormData()
getGet()
getPost()
getTempFile()
getTempFileWithExtension()
createTempDir()
realPath()
deleteAtShutdown()
shutdown()
extensionExists()
loadExtension()
getPathInfo()
$patterns
No constants found
_secureDelete()
$_magicquotes
$_shutdowndata
$_shutdownreg
$_cache
N/A
No private methods found
No private properties found
N/A

Properties

$_magicquotes

$_magicquotes : boolean

Are magic quotes in use?

Type

boolean

$_shutdowndata

$_shutdowndata : array

Data used to determine shutdown deletion.

Type

array

$_shutdownreg

$_shutdownreg : boolean

Has the shutdown method been registered?

Type

boolean

$_cache

$_cache : array

Cache for extensionExists().

Type

array

Methods

nonInputVar()

nonInputVar(string  $varname, mixed  $default = null) : mixed

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.

Parameters

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.

Returns

mixed —

$default if the var is in user input or not present, the variable value otherwise.

formInput()

formInput(boolean  $append_session) : string

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

Parameters

boolean $append_session

0 = only if needed, 1 = always.

Returns

string —

The hidden form input, if needed/requested.

pformInput()

pformInput(boolean  $append_session) 

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

Parameters

boolean $append_session

0 = only if needed, 1 = always.

dispelMagicQuotes()

dispelMagicQuotes(mixed  $var) : mixed

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

Parameters

mixed $var

The string, or an array of strings, to un-quote.

Returns

mixed —

$var, minus any magic quotes.

getFormData()

getFormData(string  $var, string  $default = null) : string

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.

Parameters

string $var

The name of the form variable to look for.

string $default

The value to return if the variable is not there.

Returns

string —

The cleaned form variable, or $default.

getGet()

getGet(string  $var, string  $default = null) : string

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

Parameters

string $var

The name of the form variable to look for.

string $default

The value to return if the variable is not there.

Returns

string —

The cleaned form variable, or $default.

getPost()

getPost(string  $var, string  $default = null) : string

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

Parameters

string $var

The name of the form variable to look for.

string $default

The value to return if the variable is not there.

Returns

string —

The cleaned form variable, or $default.

getTempFile()

getTempFile(string  $prefix = '', boolean  $delete = true, string  $dir = '', boolean  $secure = false) : string

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

Parameters

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 the file, should we securely delete the file by overwriting it with random data?

Returns

string —

Returns the full path-name to the temporary file. Returns false if a temp file could not be created.

getTempFileWithExtension()

getTempFileWithExtension(string  $extension = '.tmp', string  $prefix = '', boolean  $delete = true, string  $dir = '', boolean  $secure = false) : string

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

Parameters

string $extension

The file extension to use.

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 by overwriting it with random data?

Returns

string —

Returns the full path-name to the temporary file. Returns false if a temporary file could not be created.

createTempDir()

createTempDir(boolean  $delete = true, string  $temp_dir = null) : string

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

Parameters

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.

Returns

string —

The pathname to the new temporary directory. Returns false if directory not created.

realPath()

realPath(string  $path) : string

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).

Parameters

string $path

A file path.

Returns

string —

The canonicalized file path.

deleteAtShutdown()

deleteAtShutdown(string  $filename, boolean  $register = true, boolean  $secure = false) 

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 Horde_Util::_deleteAtShutdown()).

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

The second parameter allows the unregistering of previously registered elements.

Parameters

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?

shutdown()

shutdown() 

Deletes registered files at request shutdown.

This function should never be called manually; it is registered as a shutdown function by Horde_Util::deleteAtShutdown() and called automatically at the end of the request.

Contains code from gpg_functions.php. Copyright 2002-2003 Braverock Ventures

extensionExists()

extensionExists(string  $ext) : boolean

Caches the result of extension_loaded() calls.

Parameters

string $ext

The extension name.

Returns

boolean —

Is the extension loaded?

loadExtension()

loadExtension(string  $ext) : boolean

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

Parameters

string $ext

The extension to load.

Returns

boolean —

True if the extension is now loaded, false if not. True can mean that the extension was already loaded, OR was loaded dynamically.

getPathInfo()

getPathInfo() : string

Utility function to obtain PATH_INFO information.

Returns

string —

The PATH_INFO string.

_secureDelete()

_secureDelete(string  $file) 

Securely delete the file by overwriting the data with a random string.

Parameters

string $file

Filename.