PHP Class Toolbox, glpi

Author: Anis BEREJEB Toolbox class
Datei anzeigen Open project: glpi-project/glpi Class Usage Examples

Public Methods

Method Description
addslashes_deep ( $value ) : addslashes Add slash for variable & array
append_params ( $array, $separator = '&', $parent = '' ) : string Converts an array of parameters into a query string to be appended to a URL.
backtrace ( $log = 'php-errors', $hide = '', array $skip = [] ) : string Generate a Backtrace
canUseImapPop ( ) : boolean Determine if Imap/Pop is usable checking extension existence
canUseLdap ( ) : boolean Determine if Ldap is usable checking ldap extension existence
checkMemoryLimit ( ) Check is current memory_limit is enough for GLPI
checkNewVersionAvailable ( $auto = true, $messageafterredirect = false ) : string Check if new version is available
checkSELinux ( $fordebug = false ) : integer Check SELinux configuration
checkValidReferer ( ) : nothing Check valid referer accessing GLPI
cleanDecimal ( $decimal ) : clean Clean decimal value (strip all chars not - and spaces )
cleanInteger ( $integer ) : clean Clean integer value (strip all chars not - and spaces )
cleanNewLines ( $string ) : clean Clean new lines of a string
clean_cross_side_scripting_deep ( $value ) : clean Prevent from XSS Clean code
commonCheckForUseGLPI ( ) : 2 Common Checks needed to use GLPI
constructMailServerConfig ( $input )
createSchema ( $lang = 'en_GB' ) : nothing Create the GLPI default schema
decodeArrayFromInput ( $value ) : string Decode array passed on an input form
decodeFromUtf8 ( $string, $to_charset = "ISO-8859-1" ) : converted Decode string from UTF-8 to specified charset
decrypt ( $string, $key ) : decrypted Decrypt a string
deleteDir ( $dir ) Delete a directory and file contains in it
encodeInUtf8 ( $string, $from_charset = "ISO-8859-1" ) : utf8 Encode string to UTF-8
encrypt ( $string, $key ) : encrypted Encrypt a string
filesizeDirectory ( $path ) : size Get the filesize of a complete directory (from php.net)
getDaysOfWeekArray ( )
getItemTypeFormURL ( $itemtype, $full = true ) Get form URL for itemtype
getItemTypeSearchURL ( $itemtype, $full = true ) Get search URL for itemtype
getItemTypeTabsURL ( $itemtype, $full = true ) Get ajax tabs url for itemtype
getMemoryLimit ( $ininame = 'memory_limit' ) : memory Compute PHP memory_limit
getMime ( $file, $type = false ) : string Retrieve the mime type of a file
getMonthsOfYearArray ( )
getRandomString ( integer $length, boolean $high = false ) : random Get a random string
getSize ( $size ) : formatted Format a size passing a size in octet
getTimestampTimeUnits ( $time ) : string Split timestamp in time units
getURLContent ( $url, &$msgerr = NULL, $rec ) : content Get a web page. Use proxy if configured
get_magic_quotes_gpc ( ) : boolean Wrapper for get_magic_quotes_gpc - deprecated
get_magic_quotes_runtime ( ) : boolean Wrapper for get_magic_quotes_runtime - deprecated
get_max_input_vars ( ) : integer Wrapper for max_input_vars
inArrayCaseCompare ( $string, $datas = [] ) : boolean Do a in_array search comparing string using strcasecmp
in_array_recursive ( mixed $needle, array $haystack, $strict = false ) : boolean Summary of in_array_recursive
is_a ( $object, $class_name ) : true Check if the given object is of the type $class_name. Can be identical or a subclass.
key_exists_deep ( $need, $tab )
logDebug ( ) Log in 'php-errors' all args
logInFile ( $name, $text, $force = false ) Log a message in log file
manageBeginAndEndPlanDates ( &$data ) : processed Manage planning posted datas (must have begin + duration or end) Compute end if duration is set
manageRedirect ( $where ) Manage login redirection
parseMailServerConnectString ( $value, $forceport = false ) : array Parse imap open connect string
prepareArrayForInput ( array $value ) : string Prepare array passed on an input form
removeHtmlSpecialChars ( string $string ) : string Remove accentued characters and return lower case string
resizePicture ( $source_path, $dest_path, $new_width = 71, $new_height = 71, $img_y, $img_x, $img_width, $img_height, $max_size = 500 ) : boolean Resize a picture to the new size
return_bytes_from_ini_vars ( $val ) Convert a value in byte, kbyte, megabyte etc.
sanitize ( array $array ) : array Sanitize received values
seems_utf8 ( $str ) : boolean Is a string seems to be UTF-8 one ?
sendFile ( $file, $filename, $mime = null ) : nothing Send a file (not a document) to the navigator See Document->send();
setDebugMode ( $mode = NULL, $debug_sql = NULL, $debug_vars = NULL, $log_in_files = NULL ) Switch error mode for GLPI
shortcut ( $str, $shortcut ) : string to underline shortcut letter
showMailServerConfig ( $value ) : String Display a mail server configuration form
slugify ( string $string ) : string Slugify
str_pad ( $input, $pad_length, $pad_string = " ", $pad_type = STR_PAD_RIGHT ) : string Replace str_pad() who bug with utf8
stripslashes_deep ( $value ) : stripslashes Strip slash for variable & array
strlen ( $str ) : length strlen function for utf8 string
strpos ( $str, $tofound, $offset ) : substring substr function for utf8 string
strtolower ( $str ) : lower strtolower function for utf8 string
strtoupper ( $str ) : upper strtoupper function for utf8 string
substr ( $str, $start, $length ) : substring substr function for utf8 string
testWriteAccessToDirectory ( $dir ) : 2 Check Write Access to a directory
ucfirst ( $str ) : string Convert first caracter in upper
unclean_cross_side_scripting_deep ( $value ) : unclean Invert fonction from clean_cross_side_scripting_deep
unclean_html_cross_side_scripting_deep ( $value ) : unclean Invert fonction from clean_cross_side_scripting_deep to display HTML striping XSS code
userErrorHandlerDebug ( $errno, $errmsg, $filename, $linenum, $vars ) Specific error handler in Debug mode
userErrorHandlerNormal ( $errno, $errmsg, $filename, $linenum, $vars ) Specific error handler in Normal mode
writeConfig ( $name, $content ) : boolean Save a configuration file

Method Details

addslashes_deep() static public method

Add slash for variable & array
static public addslashes_deep ( $value ) : addslashes
$value array or string: value to add slashes (array or string)
return addslashes value

append_params() static public method

Converts an array of parameters into a query string to be appended to a URL.
static public append_params ( $array, $separator = '&', $parent = '' ) : string
$array array parameters to append to the query string.
$separator separator may be defined as & to display purpose (default '&')
$parent This should be left blank (it is used internally by the function). (default '')
return string : Query string to append to a URL.

backtrace() static public method

Generate a Backtrace
static public backtrace ( $log = 'php-errors', $hide = '', array $skip = [] ) : string
$log String log file name (default php-errors) if false, return the strung
$hide String call to hide (but display script/line) (default '')
$skip array Array of call to not display at all
return string if $log is false

canUseImapPop() static public method

Determine if Imap/Pop is usable checking extension existence
static public canUseImapPop ( ) : boolean
return boolean

canUseLdap() static public method

Determine if Ldap is usable checking ldap extension existence
static public canUseLdap ( ) : boolean
return boolean

checkMemoryLimit() static public method

Check is current memory_limit is enough for GLPI
static public checkMemoryLimit ( )

checkNewVersionAvailable() static public method

Check if new version is available
static public checkNewVersionAvailable ( $auto = true, $messageafterredirect = false ) : string
$auto boolean: check done autically ? (if not display result) (true by default)
$messageafterredirect boolean: use message after redirect instead of display (false by default)
return string explaining the result

checkSELinux() static public method

Check SELinux configuration
static public checkSELinux ( $fordebug = false ) : integer
$fordebug Boolean true is displayed in system information @return integer 0: OK, 1:Warning, 2:Error
return integer

checkValidReferer() static public method

Check valid referer accessing GLPI
static public checkValidReferer ( ) : nothing
return nothing : display error if not permit

cleanDecimal() static public method

Clean decimal value (strip all chars not - and spaces )
static public cleanDecimal ( $decimal ) : clean
$decimal string float string
return clean integer

cleanInteger() static public method

Clean integer value (strip all chars not - and spaces )
static public cleanInteger ( $integer ) : clean
$integer string integer string
return clean integer

cleanNewLines() static public method

Clean new lines of a string
static public cleanNewLines ( $string ) : clean
$string string string to clean
return clean string

clean_cross_side_scripting_deep() static public method

Prevent from XSS Clean code
static public clean_cross_side_scripting_deep ( $value ) : clean
$value array or string: item to prevent (array or string)
return clean item

commonCheckForUseGLPI() static public method

Common Checks needed to use GLPI
static public commonCheckForUseGLPI ( ) : 2
return 2

constructMailServerConfig() static public method

static public constructMailServerConfig ( $input )
$input

createSchema() static public method

Create the GLPI default schema
Since: 9.1
static public createSchema ( $lang = 'en_GB' ) : nothing
$lang
return nothing

decodeArrayFromInput() static public method

Decode array passed on an input form
static public decodeArrayFromInput ( $value ) : string
$value string encoded value
return string decoded array

decodeFromUtf8() static public method

Decode string from UTF-8 to specified charset
static public decodeFromUtf8 ( $string, $to_charset = "ISO-8859-1" ) : converted
$string string string to convert
$to_charset string destination charset (default "ISO-8859-1")
return converted string

decrypt() static public method

Decrypt a string
static public decrypt ( $string, $key ) : decrypted
$string string to decrypt
$key string key used to decrypt
return decrypted string

deleteDir() static public method

Delete a directory and file contains in it
static public deleteDir ( $dir )
$dir string: directory to delete

encodeInUtf8() static public method

Encode string to UTF-8
static public encodeInUtf8 ( $string, $from_charset = "ISO-8859-1" ) : utf8
$string string string to convert
$from_charset string original charset (if 'auto' try to autodetect) (default "ISO-8859-1")
return utf8 string

encrypt() static public method

Encrypt a string
static public encrypt ( $string, $key ) : encrypted
$string string to encrypt
$key string key used to encrypt
return encrypted string

filesizeDirectory() static public method

Get the filesize of a complete directory (from php.net)
static public filesizeDirectory ( $path ) : size
$path string: directory or file to get size
return size of the $path

getDaysOfWeekArray() static public method

static public getDaysOfWeekArray ( )

getItemTypeFormURL() static public method

Get form URL for itemtype
static public getItemTypeFormURL ( $itemtype, $full = true )
$itemtype string item type
$full path or relative one (true by default) return string itemtype Form URL

getItemTypeSearchURL() static public method

Get search URL for itemtype
static public getItemTypeSearchURL ( $itemtype, $full = true )
$itemtype string item type
$full path or relative one (true by default) return string itemtype search URL

getItemTypeTabsURL() static public method

Get ajax tabs url for itemtype
static public getItemTypeTabsURL ( $itemtype, $full = true )
$itemtype string item type
$full path or relative one (true by default) return string itemtype tabs URL

getMemoryLimit() static public method

Compute PHP memory_limit
static public getMemoryLimit ( $ininame = 'memory_limit' ) : memory
$ininame String name of the ini ooption to retrieve (since 9.1)
return memory limit

getMime() static public method

Retrieve the mime type of a file
static public getMime ( $file, $type = false ) : string
$file string path of the file
$type string check if $file is the correct type (false by default)
return string (if $type not given) else boolean

getMonthsOfYearArray() static public method

static public getMonthsOfYearArray ( )

getRandomString() static public method

Get a random string
static public getRandomString ( integer $length, boolean $high = false ) : random
$length integer of the random string
$high boolean strength of the random source (since 9.2)
return random string

getSize() static public method

Format a size passing a size in octet
static public getSize ( $size ) : formatted
$size integer: Size in octet
return formatted size

getTimestampTimeUnits() static public method

Split timestamp in time units
static public getTimestampTimeUnits ( $time ) : string
$time integer: timestamp
return string

getURLContent() static public method

Get a web page. Use proxy if configured
static public getURLContent ( $url, &$msgerr = NULL, $rec ) : content
$url string to retrieve
$msgerr string set if problem encountered (default NULL)
$rec integer internal use only Must be 0 (default 0)
return content of the page (or empty)

get_magic_quotes_gpc() static public method

Wrapper for get_magic_quotes_gpc - deprecated
Deprecation: in 0.90.1
static public get_magic_quotes_gpc ( ) : boolean
return boolean

get_magic_quotes_runtime() static public method

Wrapper for get_magic_quotes_runtime - deprecated
Deprecation: in 0.90.1
static public get_magic_quotes_runtime ( ) : boolean
return boolean

get_max_input_vars() static public method

Wrapper for max_input_vars
static public get_max_input_vars ( ) : integer
return integer

inArrayCaseCompare() static public method

Do a in_array search comparing string using strcasecmp
static public inArrayCaseCompare ( $string, $datas = [] ) : boolean
$string string to search
$datas array to search to search
return boolean : string founded ?

in_array_recursive() static public method

Summary of in_array_recursive
static public in_array_recursive ( mixed $needle, array $haystack, $strict = false ) : boolean
$needle mixed
$haystack array
return boolean

is_a() static public method

This method emulates PHP 5.3.9: is_a with allow_string == true
static public is_a ( $object, $class_name ) : true
$object can be an object or a string contining the class name
$class_name the name of the class to compare
return true if $object is an instance of $class_name

key_exists_deep() static public method

static public key_exists_deep ( $need, $tab )
$need
$tab

logDebug() static public method

Log in 'php-errors' all args
static public logDebug ( )

logInFile() static public method

Log a message in log file
static public logInFile ( $name, $text, $force = false )
$name string name of the log file
$text string text to log
$force boolean force log in file not seeing use_log_in_files config (false by default)

manageBeginAndEndPlanDates() static public method

Manage planning posted datas (must have begin + duration or end) Compute end if duration is set
static public manageBeginAndEndPlanDates ( &$data ) : processed
$data array data to process
return processed datas

manageRedirect() static public method

Manage login redirection
static public manageRedirect ( $where )
$where string: where to redirect ?

parseMailServerConnectString() static public method

Parse imap open connect string
static public parseMailServerConnectString ( $value, $forceport = false ) : array
$value string: connect string
$forceport boolean: force compute port if not set (false by default)
return array of parsed arguments (address, port, mailbox, type, ssl, tls, validate-cert norsh, secure and debug) : options are empty if not set and options have boolean values if set

prepareArrayForInput() static public method

Prepare array passed on an input form
static public prepareArrayForInput ( array $value ) : string
$value array array passed array
return string encoded array

removeHtmlSpecialChars() public static method

Remove accentued characters and return lower case string
public static removeHtmlSpecialChars ( string $string ) : string
$string string String to handle
return string

resizePicture() static public method

Resize a picture to the new size
static public resizePicture ( $source_path, $dest_path, $new_width = 71, $new_height = 71, $img_y, $img_x, $img_width, $img_height, $max_size = 500 ) : boolean
$source_path string path of the picture to be resized
$dest_path string path of the new resized picture
$new_width string new width after resized (default 71)
$new_height string new height after resized (default 71)
$img_y string y axis of picture (default 0)
$img_x string x axis of picture (default 0)
$img_width string width of picture (default 0)
$img_height string height of picture (default 0)
$max_size integer max size of the picture (default 500, is set to 0 no resize)
return boolean : true or false

return_bytes_from_ini_vars() static public method

..
static public return_bytes_from_ini_vars ( $val )
$val string: config value (like 10k, 5M)

sanitize() public static method

Sanitize received values
public static sanitize ( array $array ) : array
$array array
return array

seems_utf8() static public method

Is a string seems to be UTF-8 one ?
static public seems_utf8 ( $str ) : boolean
$str string string to analyze
return boolean

sendFile() static public method

Send a file (not a document) to the navigator See Document->send();
static public sendFile ( $file, $filename, $mime = null ) : nothing
$file string: storage filename
$filename string: file title
$mime string: file mime type
return nothing

setDebugMode() static public method

Switch error mode for GLPI
static public setDebugMode ( $mode = NULL, $debug_sql = NULL, $debug_vars = NULL, $log_in_files = NULL )
$mode Integer from Session::*_MODE (default NULL)
$debug_sql Boolean (default NULL)
$debug_vars Boolean (default NULL)
$log_in_files Boolean (default NULL)

shortcut() static public method

to underline shortcut letter
static public shortcut ( $str, $shortcut ) : string
$str string from dico
$shortcut letter of shortcut
return string

showMailServerConfig() static public method

Display a mail server configuration form
static public showMailServerConfig ( $value ) : String
$value String host connect string ex {localhost:993/imap/ssl}INBOX
return String type of the server (imap/pop)

slugify() public static method

Slugify
public static slugify ( string $string ) : string
$string string String to slugify
return string

str_pad() static public method

Replace str_pad() who bug with utf8
static public str_pad ( $input, $pad_length, $pad_string = " ", $pad_type = STR_PAD_RIGHT ) : string
$input string input string
$pad_length integer padding length
$pad_string string padding string (default '')
$pad_type integer padding type (default STR_PAD_RIGHT)
return string

stripslashes_deep() static public method

Strip slash for variable & array
static public stripslashes_deep ( $value ) : stripslashes
$value array or string: item to stripslashes (array or string)
return stripslashes item

strlen() static public method

strlen function for utf8 string
static public strlen ( $str ) : length
$str string
return length of the string

strpos() static public method

substr function for utf8 string
static public strpos ( $str, $tofound, $offset ) : substring
$str string string
$tofound string string to found
$offset integer The search offset. If it is not specified, 0 is used. (default 0)
return substring

strtolower() static public method

strtolower function for utf8 string
static public strtolower ( $str ) : lower
$str string
return lower case string

strtoupper() static public method

strtoupper function for utf8 string
static public strtoupper ( $str ) : upper
$str string
return upper case string

substr() static public method

substr function for utf8 string
static public substr ( $str, $start, $length ) : substring
$str string
$start integer start of the result substring
$length integer The maximum length of the returned string if > 0 (default -1)
return substring

testWriteAccessToDirectory() static public method

Check Write Access to a directory
static public testWriteAccessToDirectory ( $dir ) : 2
$dir string: directory to check
return 2

ucfirst() static public method

Convert first caracter in upper
static public ucfirst ( $str ) : string
$str string to change
return string changed

unclean_cross_side_scripting_deep() static public method

Invert fonction from clean_cross_side_scripting_deep
See also: clean_cross_side_scripting_deep
static public unclean_cross_side_scripting_deep ( $value ) : unclean
$value array or string item to unclean from clean_cross_side_scripting_deep
return unclean item

unclean_html_cross_side_scripting_deep() static public method

Invert fonction from clean_cross_side_scripting_deep to display HTML striping XSS code
See also: clean_cross_side_scripting_deep
static public unclean_html_cross_side_scripting_deep ( $value ) : unclean
$value array or string: item to unclean from clean_cross_side_scripting_deep
return unclean item

userErrorHandlerDebug() static public method

Specific error handler in Debug mode
static public userErrorHandlerDebug ( $errno, $errmsg, $filename, $linenum, $vars )
$errno integer level of the error raised.
$errmsg string error message.
$filename string filename that the error was raised in.
$linenum integer line number the error was raised at.
$vars array that points to the active symbol table at the point the error occurred.

userErrorHandlerNormal() static public method

Specific error handler in Normal mode
static public userErrorHandlerNormal ( $errno, $errmsg, $filename, $linenum, $vars )
$errno integer level of the error raised.
$errmsg string error message.
$filename string filename that the error was raised in.
$linenum integer line number the error was raised at.
$vars array that points to the active symbol table at the point the error occurred.

writeConfig() static public method

Save a configuration file
static public writeConfig ( $name, $content ) : boolean
$name string config file name
$content string config file content
return boolean