PHP Class Toolbox, glpi

Author: Anis BEREJEB Toolbox class
Afficher le fichier Open project: glpi-project/glpi Class Usage Examples

Méthodes publiques

Méthode 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 méthode

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

append_params() static public méthode

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 '')
Résultat string : Query string to append to a URL.

backtrace() static public méthode

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
Résultat string if $log is false

canUseImapPop() static public méthode

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

canUseLdap() static public méthode

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

checkMemoryLimit() static public méthode

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

checkNewVersionAvailable() static public méthode

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)
Résultat string explaining the result

checkSELinux() static public méthode

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
Résultat integer

checkValidReferer() static public méthode

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

cleanDecimal() static public méthode

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

cleanInteger() static public méthode

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

cleanNewLines() static public méthode

Clean new lines of a string
static public cleanNewLines ( $string ) : clean
$string string string to clean
Résultat clean string

clean_cross_side_scripting_deep() static public méthode

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

commonCheckForUseGLPI() static public méthode

Common Checks needed to use GLPI
static public commonCheckForUseGLPI ( ) : 2
Résultat 2

constructMailServerConfig() static public méthode

static public constructMailServerConfig ( $input )
$input

createSchema() static public méthode

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

decodeArrayFromInput() static public méthode

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

decodeFromUtf8() static public méthode

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")
Résultat converted string

decrypt() static public méthode

Decrypt a string
static public decrypt ( $string, $key ) : decrypted
$string string to decrypt
$key string key used to decrypt
Résultat decrypted string

deleteDir() static public méthode

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

encodeInUtf8() static public méthode

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")
Résultat utf8 string

encrypt() static public méthode

Encrypt a string
static public encrypt ( $string, $key ) : encrypted
$string string to encrypt
$key string key used to encrypt
Résultat encrypted string

filesizeDirectory() static public méthode

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

getDaysOfWeekArray() static public méthode

static public getDaysOfWeekArray ( )

getItemTypeFormURL() static public méthode

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 méthode

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 méthode

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 méthode

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

getMime() static public méthode

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)
Résultat string (if $type not given) else boolean

getMonthsOfYearArray() static public méthode

static public getMonthsOfYearArray ( )

getRandomString() static public méthode

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)
Résultat random string

getSize() static public méthode

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

getTimestampTimeUnits() static public méthode

Split timestamp in time units
static public getTimestampTimeUnits ( $time ) : string
$time integer: timestamp
Résultat string

getURLContent() static public méthode

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)
Résultat content of the page (or empty)

get_magic_quotes_gpc() static public méthode

Wrapper for get_magic_quotes_gpc - deprecated
Deprecation: in 0.90.1
static public get_magic_quotes_gpc ( ) : boolean
Résultat boolean

get_magic_quotes_runtime() static public méthode

Wrapper for get_magic_quotes_runtime - deprecated
Deprecation: in 0.90.1
static public get_magic_quotes_runtime ( ) : boolean
Résultat boolean

get_max_input_vars() static public méthode

Wrapper for max_input_vars
static public get_max_input_vars ( ) : integer
Résultat integer

inArrayCaseCompare() static public méthode

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
Résultat boolean : string founded ?

in_array_recursive() static public méthode

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

is_a() static public méthode

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
Résultat true if $object is an instance of $class_name

key_exists_deep() static public méthode

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

logDebug() static public méthode

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

logInFile() static public méthode

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 méthode

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
Résultat processed datas

manageRedirect() static public méthode

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

parseMailServerConnectString() static public méthode

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)
Résultat 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 méthode

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

removeHtmlSpecialChars() public static méthode

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

resizePicture() static public méthode

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)
Résultat boolean : true or false

return_bytes_from_ini_vars() static public méthode

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

sanitize() public static méthode

Sanitize received values
public static sanitize ( array $array ) : array
$array array
Résultat array

seems_utf8() static public méthode

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

sendFile() static public méthode

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
Résultat nothing

setDebugMode() static public méthode

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 méthode

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

showMailServerConfig() static public méthode

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

slugify() public static méthode

Slugify
public static slugify ( string $string ) : string
$string string String to slugify
Résultat string

str_pad() static public méthode

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)
Résultat string

stripslashes_deep() static public méthode

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

strlen() static public méthode

strlen function for utf8 string
static public strlen ( $str ) : length
$str string
Résultat length of the string

strpos() static public méthode

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)
Résultat substring

strtolower() static public méthode

strtolower function for utf8 string
static public strtolower ( $str ) : lower
$str string
Résultat lower case string

strtoupper() static public méthode

strtoupper function for utf8 string
static public strtoupper ( $str ) : upper
$str string
Résultat upper case string

substr() static public méthode

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)
Résultat substring

testWriteAccessToDirectory() static public méthode

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

ucfirst() static public méthode

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

unclean_cross_side_scripting_deep() static public méthode

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
Résultat unclean item

unclean_html_cross_side_scripting_deep() static public méthode

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
Résultat unclean item

userErrorHandlerDebug() static public méthode

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 méthode

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 méthode

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