The legendary "t3lib_div" class - Miscellaneous functions for general purpose.
Most of the functions does not relate specifically to TYPO3
However a section of functions requires certain TYPO3 features available
See comments in the source.
You are encouraged to use this library in your own scripts!
USE:
The class is intended to be used without creating an instance of it.
So: Don't instantiate - call functions with "t3lib_div::" prefixed the function name.
So use t3lib_div::[method-name] to refer to the functions, eg. 't3lib_div::milliseconds()'
Files: 1
Total filesizes: 113 Kbytes
Functions and classes: 109
The legendary "t3lib_div" class - Miscellaneous functions for general purpose.
Most of the functions does not relate specifically to TYPO3
However a section of functions requires certain TYPO3 features available
See comments in the source.
You are encouraged to use this library in your own scripts!
USE:
The class is intended to be used without creating an instance of it.
So: Don't instantiate - call functions with "t3lib_div::" prefixed the function name.
So use t3lib_div::[method-name] to refer to the functions, eg. 't3lib_div::milliseconds()'
@package: TYPO3
@subpackage: t3lib
@todo: Possible improvement: Should it rawurldecode the string first to check if any of these characters is encoded ?
The legendary "t3lib_div" class - Miscellaneous functions for general purpose.
Most of the functions does not relate specifically to TYPO3
However a section of functions requires certain TYPO3 features available
See comments in the source.
You are encouraged to use this library in your own scripts!
USE:
The class is intended to be used without creating an instance of it.
So: Don't instantiate - call functions with "t3lib_div::" prefixed the function name.
So use t3lib_div::[method-name] to refer to the functions, eg. 't3lib_div::milliseconds()'
Filesize: | 113 K |
Func/Classes: | 109 |
Tags: | @author Kasper Skaarhoj <kasper@typo3.com> @package TYPO3 @subpackage t3lib |
The legendary "t3lib_div" class - Miscellaneous functions for general purpose.
Most of the functions does not relate specifically to TYPO3
However a section of functions requires certain TYPO3 features available
See comments in the source.
You are encouraged to use this library in your own scripts!
USE:
The class is intended to be used without creating an instance of it.
So: Don't instantiate - call functions with "t3lib_div::" prefixed the function name.
So use t3lib_div::[method-name] to refer to the functions, eg. 't3lib_div::milliseconds()'
Returns: | [type] | ... |
@author Kasper Skaarhoj <kasper@typo3.com> | ||
@package TYPO3 | ||
@subpackage t3lib |
Returns the 'GLOBAL' value of incoming data from POST or GET, with priority to POST (that is equalent to 'GP' order)
Strips slashes from all output, both strings and arrays.
This function substitutes t3lib_div::GPvar()
To enhancement security in your scripts, please consider using
t3lib_div::_GET or t3lib_div::_POST if you already know by which method
your data is arriving to the scripts!
$var | string | GET/POST var to return |
Returns: | mixed | POST var named $var and if not set, the GET var of the same name. |
@see GPvar() |
Returns the global GET array (or value from) normalized to contain un-escaped values.
ALWAYS use this API function to acquire the GET variables!
$var='' | string | Optional pointer to value in GET array (basically name of GET var) |
Returns: | mixed | If $var is set it returns the value of $HTTP_GET_VARS[$var]. If $var is blank or zero, returns $HTTP_GET_VARS itself. In any case *slashes are stipped from the output!* |
@see _POST(), _GP(), _GETset() |
Returns the global POST array (or value from) normalized to contain un-escaped values.
ALWAYS use this API function to acquire the POST variables!
$var='' | string | Optional pointer to value in POST array (basically name of POST var) |
Returns: | mixed | If $var is set it returns the value of $HTTP_POST_VARS[$var]. If $var is blank or zero, returns $HTTP_POST_VARS itself. In any case *slashes are stipped from the output!* |
@see _GET(), _GP() |
Writes input value to $HTTP_GET_VARS / $_GET
$inputGet | array | Array to write to $HTTP_GET_VARS / $_GET. Values should NOT be escaped at input time (but will be escaped before writing according to TYPO3 standards). |
$key='' | string | Alternative key; If set, this will not set the WHOLE GET array, but only the key in it specified by this value! |
Returns: | void |
GET/POST variable
Returns the 'GLOBAL' value of incoming data from POST or GET, with priority to POST (that is equalent to 'GP' order)
Strips slashes of string-outputs, but not arrays UNLESS $strip is set.
If $strip is set all output will have escaped characters unescaped.
Usage: 686
$var | string | GET/POST var to return |
$strip=0 | boolean | If set, values are stripped of return values that are *arrays!* - string/integer values returned are always strip-slashed() |
Returns: | mixed | POST var named $var and if not set, the GET var of the same name. |
@depreciated Use t3lib_div::_GP instead (ALWAYS delivers a value with un-escaped values!) | ||
@see _GP() |
Sets global variables from HTTP_POST_VARS or HTTP_GET_VARS
Usage: 9
$list | string | List of GET/POST var keys to set globally |
$strip=0 | boolean | If set, values are passed through stripslashes() |
Returns: | void | |
@depreciated |
Returns the GET/POST global arrays merged with POST taking precedence.
Usage: 1
$var | string | Key (variable name) from GET or POST vars |
Returns: | array | Returns the GET vars merged recursively onto the POST vars. |
@depreciated |
Compressing a GIF file if not already LZW compressed
This function is a workaround for the fact that ImageMagick and/or GD
does not compress GIF-files to their minimun size (that is RLE or no
compression used)
The function takes a file-reference, $theFile, and saves it again through GD or ImageMagick in order to compress the file
GIF:
If $type is not set, the compression is done with ImageMagick (provided
that $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw'] is pointing to
the path of a lzw-enabled version of 'convert') else with GD (should be
RLE-enabled!)
If $type is set to either 'IM' or 'GD' the compression is done with ImageMagick and GD respectively
PNG:
No changes.
$theFile is expected to be a valid GIF-file!
The function returns a code for the operation.
Usage: 11
$theFile | string | Filepath |
$type | string | See description of function |
Returns: | string | Returns "GD" if GD was used, otherwise "IM" if ImageMagick was used. If nothing done at all, it returns empty string. |
@internal |
Converts a png file to gif
This converts a png file to gif IF the FLAG $GLOBALS['TYPO3_CONF_VARS']['FE']['png_to_gif'] is set true.
Usage: 5
$theFile | string | $theFile the filename with path |
Returns: | string | new filename |
@internal |
Returns filename of the png/gif version of the input file (which can be png or gif).
If input file type does not match the wanted output type a conversion is made and temp-filename returned.
Usage: 1
$theFile | string | Filepath of image file |
$output_png=0 | boolean | If set, then input file is converted to PNG, otherwise to GIF |
Returns: | string | If the new image file exists, it's filepath is returned |
@internal |
Truncate string
Returns a new string of max. $chars length.
If the string is longer, it will be truncated and appended with '...'.
Usage: 119
$string | string | $string string to truncate |
$chars | integer | $chars must be an integer of at least 4 |
$preStr='...' | string | String to append to the the output if it is truncated, default is '...' |
Returns: | string | new string |
@see fixed_lgd_pre() |
Truncate string
Returns a new string of max. $chars length.
If the string is longer, it will be truncated and prepended with '...'.
This works like fixed_lgd, but is truncated in the start of the string instead of the end
Usage: 19
$string | string | $string string to truncate |
$chars | integer | $chars must be an integer of at least 4 |
Returns: | string | new string |
@see fixed_lgd() |
Breaks up the text for emails
Usage: 1
$str | string | The string to break up |
$implChar="\n" | string | The string to implode the broken lines with (default/typically \n) |
$charWidth=76 | integer | The line length |
Returns: | string |
Breaks up a single line of text for emails
Usage: 3
$str | string | The string to break up |
$implChar="\n" | string | The string to implode the broken lines with (default/typically \n) |
$charWidth=76 | integer | The line length |
Returns: | string | |
@see breakTextForEmail() |
Match IP number with list of numbers with wildcard
Usage: 8
$baseIP | string | $baseIP is the current remote IP address for instance, typ. REMOTE_ADDR |
$list | string | $list is a comma-list of IP-addresses to match with. *-wildcard allowed instead of number, plus leaving out parts in the IP number is accepted as wildcard (eg. 192.168.*.* equals 192.168) |
Returns: | boolean | True if an IP-mask from $list matches $baseIP |
Check for item in list
Check if an item exists in a comma-separated list of items.
Usage: 166
$in_list | string | $in_list comma-separated list of items (string) |
$item | string | $item item to check for |
Returns: | boolean | true if $item is in $in_list |
Removes an item from a comma-separated list of items.
Usage: 1
$element | string | $element element to remove |
$list | string | $list comma-separated list of items (string) |
Returns: | string | new comma-separated list of items |
Forces the integer $theInt into the boundaries of $min and $max. If the $theInt is 'false' then the $zeroValue is applied.
Usage: 226
$theInt | integer | Input value |
$min | integer | Lower limit |
$max=2000000000 | integer | Higher limit |
$zeroValue=0 | integer | Default value if input is false. |
Returns: | integer | The input value forced into the boundaries of $min and $max |
Returns the $integer if greater than zero, otherwise returns zero.
Usage: 1
$theInt | integer | Integer string to process |
Returns: | integer |
Returns an integer from a three part version number, eg '4.12.3' -> 4012003
Usage: 2
$verNumberStr | string | Version number on format x.x.x |
Returns: | integer | Integer version of version number (where each part can count to 999) |
Makes a positive integer hash out of the first 7 chars from the md5 hash of the input
Usage: 0
$str | string | String to md5-hash |
Returns: | integer | Returns 28bit integer-hash |
Takes a comma-separated list and removes all duplicates
Usage: 16
$in_list | string | $in_list is a comma-separated list of values. |
Returns: | string | Returns the list without any duplicates of values, space around values are trimmed |
Splits a reference to a file in 5 parts
Usage: 43
$fileref | string | Filename/filepath to be analysed |
Returns: | array | Contains keys [path], [file], [filebody], [fileext], [realFileext] |
Returns the directory part of a path without trailing slash
If there is no dir-part, then an empty string is returned.
Behaviour:
'/dir1/dir2/script.php' => '/dir1/dir2'
'/dir1/' => '/dir1'
'dir1/script.php' => 'dir1'
'd/script.php' => 'd'
'/script.php' => ''
'' => ''
Usage: 5
$path | string | Directory name / path |
Returns: | string | Processed input value. See function description. |
Modifies a HTML Hex color by adding/subtracting $R,$G and $B integers
Usage: 37
$color | string | A hexadecimal color code, #xxxxxx |
$R | integer | Offset value 0-255 |
$G | integer | Offset value 0-255 |
$B | integer | Offset value 0-255 |
Returns: | string | A hexadecimal color code, #xxxxxx, modified according to input vars |
@see modifyHTMLColorAll() |
Modifies a HTML Hex color by adding/subtracting $all integer from all R/G/B channels
Usage: 4
$color | string | A hexadecimal color code, #xxxxxx |
$all | integer | Offset value 0-255 for all three channels. |
Returns: | string | A hexadecimal color code, #xxxxxx, modified according to input vars |
@see modifyHTMLColor() |
Removes comma (if present) in the end of string
Usage: 4
$string | string | String from which the comma in the end (if any) will be removed. |
Returns: | string |
strtoupper which converts danish (and other characters) characters as well
(Depreciated, use PHP function with locale settings instead or for HTML
output, wrap your content in <span
class="uppercase">...</span>)
Usage: 4
$string | string | String to process |
Returns: | string |
Change umlaut characters to plain ASCII with normally two character target
Only known characters will be converted, so don't expect a result for any character.
Works only for western europe single-byte charsets!
ä => ae, Ö => Oe
$str | string | String to convert. |
Returns: | string |
Returns the first 10 positions of the MD5-hash (changed from 6 to 10 recently)
Usage: 43
$input | string | Input string to be md5-hashed |
$len=10 | integer | The string-length of the output |
Returns: | string | Substring of the resulting md5-hash, being $len chars long (from beginning) |
Tests if the input is an integer.
Usage: 74
$var | mixed | Any input variable to test. |
Returns: | boolean | Returns true if string is an integer |
Returns true if the first part of $str matches the string $partStr
Usage: 58
$str | string | Full string to check |
$partStr | string | Reference string which must be found as the "first part" of the full string |
Returns: | boolean | True if $partStr was found to be equal to the first part of $str |
Formats the input integer $sizeInBytes as bytes/kilobytes/megabytes (-/K/M)
Usage: 54
$sizeInBytes | integer | Number of bytes to format. |
$labels='' | string | Labels for bytes, kilo, mega and giga separated by vertical bar (|) and possibly encapsulated in "". Eg: " | K| M| G" (which is the default value) |
Returns: | string | Formatted representation of the byte number, for output. |
Returns microtime input to milliseconds
Usage: 2
$microtime | string | Microtime |
Returns: | integer | Microtime input string converted to an integer (milliseconds) |
This splits a string by the chars in $operators (typical /+-*) and returns an array with them in
Usage: 2
$string | string | Input string, eg "123 + 456 / 789 - 4" |
$operators | string | Operators to split by, typically "/+-*" |
Returns: | array | Array with operators and operands separated. |
@see tslib_cObj::calc(), tslib_gifBuilder::calcOffset() |
Calculates the input by +,-,*,/,%,^ with priority to + and -
Usage: 1
$string | string | Input string, eg "123 + 456 / 789 - 4" |
Returns: | integer | Calculated value. Or error string. |
@see calcParenthesis() |
Calculates the input with parenthesis levels
Usage: 2
$string | string | Input string, eg "(123 + 456) / 789 - 4" |
Returns: | integer | Calculated value. Or error string. |
@see calcPriority(), tslib_cObj::stdWrap() |
Inverse version of htmlspecialchars()
Usage: 2
$value | string | Value where >, <, " and & should be converted to regular chars. |
Returns: | string | Converted result. |
Re-converts HTML entities if they have been converted by htmlspecialchars()
$str | string | String which contains eg. "&amp;" which should stay "&". Or "&#1234;" to "Ӓ". Or "&#x1b;" to "" |
Returns: | string | Converted result. |
This function is used to escape any ' -characters when transferring text to JavaScript!
Usage: 6
$string | string | String to escape |
$extended=0 | boolean | If set, also backslashes are escaped. |
$char="'" | string | The character to escape, default is ' (single-quote) |
Returns: | string | Processed input string |
Version of rawurlencode() where all spaces (%20) are re-converted to space-characters.
Usefull when passing text to JavaScript where you simply url-encode it
to get around problems with syntax-errors, linebreaks etc.
Usage: 8
$str | string | String to raw-url-encode with spaces preserved |
Returns: | string | Rawurlencoded result of input string, but with all %20 (space chars) converted to real spaces. |
rawurlencode which preserves "/" chars
Usefull when filepaths should keep the "/" chars, but have all other special chars encoded.
$str | string | Input string |
Returns: | string | Output string |
Checking syntax of input email address
Usage: 4
string | Input string to evaluate | |
Returns: | boolean | Returns true if the $email address (input string) is valid; Has a "@", domain name with at least one period and only allowed a-z characters. |
Formats a string for output between <textarea>-tags
All content outputted in a textarea form should be passed through this function
Not only is the content htmlspecialchar'ed on output but there is also
a single newline added in the top. The newline is necessary because
browsers will ignore the first newline after <textarea> if that
is the first character. Therefore better set it!
Usage: 30
$content | string | Input string to be formatted. |
Returns: | string | Formatted for <textarea>-tags |
Check if an item exists in an array
Please note that the order of parameters is reverse compared to the php4-function in_array()!!!
Usage: 3
$in_array | array | $in_array one-dimensional array of items |
$item | string | $item item to check for |
Returns: | boolean | true if $item is in the one-dimensional array $in_array |
@internal |
Explodes a $string delimited by $delim and passes each item in the array through intval().
Corresponds to explode(), but with conversion to integers for all values.
Usage: 86
$delim | string | Delimiter string to explode with |
$string | string | The string to explode |
Returns: | array | Exploded values, all converted to integers |
Reverse explode which explodes the string counting from behind.
Thus t3lib_div::revExplode(':','my:words:here',2) will return array('my:words','here')
Usage: 6
$delim | string | Delimiter string to explode with |
$string | string | The string to explode |
$count=0 | integer | Number of array entries |
Returns: | array | Exploded values |
Explodes a string and trims all values for whitespace in the ends.
If $onlyNonEmptyValues is set, then all blank ('') values are removed.
Usage: 239
$delim | string | Delimiter string to explode with |
$string | string | The string to explode |
$onlyNonEmptyValues=0 | boolean | If set, all empty values (='') will NOT be set in output |
Returns: | array | Exploded values |
Takes a one-dimensional array and returns an array where the values are unique
The keys in the array are substituted with some md5-hashes
If the value is trim(empty), the value is ignored.
Values are trimmed
(Depreciated, use PHP function array_unique instead)
Usage: 2
$valueArray | array | Array of values to make unique |
Returns: | array | |
@depreciated |
Removes the value $cmpValue from the $array if found there. Returns the modified array
Usage: 2
$array | array | Array containing the values |
$cmpValue | string | Value to search for and if found remove array entry where found. |
Returns: | array | Output array with entries removed if search string is found |
Implodes a multidim-array into GET-parameters (eg. ¶m[key][key2]=value2¶m[key][key3]=value3)
Usage: 24
$name | string | Name prefix for entries. Set to blank if you wish none. |
$theArray | array | The (multidim) array to implode |
$str='' | boolean | If set, all values that are blank (='') will NOT be imploded |
$skipBlank=0 | boolean | If set, parameters which were blank strings would be removed. |
$rawurlencodeParamName=0 | boolean | If set, the param name itselt (for example "param[key][key2]") would be rawurlencoded as well. |
Returns: | string | Imploded result, fx. ¶m[key][key2]=value2¶m[key][key3]=value3 |
Returns an array with selected keys from incoming data.
(Better read source code if you want to find out...)
Usage: 3
$varList | string | List of variable/key names |
$getArray | array | Array from where to get values based on the keys in $varList |
$GPvarAlt=1 | boolean | If set, then t3lib_div::_GP() is used to fetch the value if not found (isset) in the $getArray |
Returns: | array | Output array with selected variables. |
AddSlash array
This function traverses a multidimentional array and adds slashes to the values.
NOTE that the input array is and argument by reference.!!
Twin-function to stripSlashesOnArray
Usage: 6
&$theArray | array | Multidimensional input array, (REFERENCE!) |
Returns: | array |
StripSlash array
This function traverses a multidimentional array and strips slashes to the values.
NOTE that the input array is and argument by reference.!!
Twin-function to addSlashesOnArray
Usage: 7
&$theArray | array | Multidimensional input array, (REFERENCE!) |
Returns: | array |
Either slashes ($cmd=add) or strips ($cmd=strip) array $arr depending on $cmd
Usage: 6
$arr | array | Multidimensional input array |
$cmd | string | "add" or "strip", depending on usage you wish. |
Returns: | array |
Merges
two arrays recursively, overruling similar the values in the first
array ($arr0) with the values of the second array ($arr1)
In case of identical keys, ie. keeping the values of the second.
Usage: 26
$arr0 | array | First array |
$arr1 | array | Second array, overruling the first array |
$notAddKeys=0 | boolean | If set, keys that are NOT found in $arr0 (first array) will not be set. Thus only existing value can/will be overruled from second array. |
Returns: | array | Resulting array where $arr1 values has overruled $arr0 values |
An array_merge function where the keys are NOT renumbered as they happen to be with the real php-array_merge function
Usage: 27
$arr1 | array | First array |
$arr2 | array | Second array |
Returns: | array | Merged result. |
Takes a row and returns a CSV string of the values with $delim (default is ,) and $quote (default is ") as separator chars.
Usage: 5
$row | array | Input array of values |
$delim=',' | string | Delimited, default is comman |
$quote='"' | string | Quote-character to wrap around the values. |
Returns: | string | A single line of CSV |
$tag is either a whole tag (eg '<TAG OPTION ATTRIB=VALUE>') or the parameterlist (ex ' OPTION ATTRIB=VALUE>')
Returns an array with all attributes as keys. Attributes are only lowercase a-z
If a attribute is empty (I call it 'an option'), then the value for the key is empty. You can check if it existed with isset()
Usage: 9
$tag | string | HTML-tag string (or attributes only) |
Returns: | array | Array with the attribute values. |
Returns
an array with the 'components' from an attribute list from an HTML tag.
The result is normally analyzed by get_tag_attributes
Removes tag-name if found
Usage: 1
$tag | string | HTML-tag string (or attributes only) |
Returns: | array | Array with the attribute values. |
@internal |
Implodes attributes in the array $arr for an attribute list in eg. and HTML tag (with quotes)
Usage: 10
$arr | array | Array with attribute key/value pairs, eg. "bgcolor"=>"red", "border"=>0 |
$xhtmlSafe=FALSE | boolean | If set the resulting attribute list will have a) all attributes in lowercase (and duplicates weeded out, first entry taking precedence) and b) all values htmlspecialchar()'ed. It is recommended to use this switch! |
$dontOmitBlankAttribs=FALSE | boolean | If true, don't check if values are blank. Default is to omit attributes with blank values. |
Returns: | string | Imploded attributes, eg. 'bgcolor="red" border="0"' |
Wraps JavaScript code XHTML ready with <script>-tags
Automatic re-identing of the JS code is done by using the first line as ident reference.
This is nice for identing JS code with PHP code on the same level.
$string | string | JavaScript code |
$linebreak=TRUE | boolean | Wrap script element in linebreaks? Default is TRUE. |
Returns: | string | The wrapped JS code, ready to put into a XHTML page |
@author Ingmar Schlecht <ingmars@web.de> | ||
@author René Fritz <r.fritz@colorcube.de> |
Parses XML input into a PHP array with associative keys
$string | string | XML data input |
$depth=999 | integer | Number of element levels to resolve the XML into an array. Any further structure will be set as XML. |
Returns: | mixed | The array with the parsed structure unless the XML parser returns with an error in which case the error message string is returned. |
@author bisqwit at iki dot fi dot not dot for dot ads dot invalid / http://dk.php.net/xml_parse_into_struct + kasper@typo3.com |
Converts a PHP array into an XML string.
The XML output is optimized for readability since associative keys are used as tagnames.
This also means that only alphanumeric characters are allowed in the
tag names AND only keys NOT starting with numbers (so watch your usage
of keys!). However there are options you can set to avoid this problem.
Numeric keys are stored with the default tagname "numIndex" but can be overridden to other formats)
The function handles input values from the PHP array in a binary-safe
way; All characters below 32 (except 9,10,13) will trigger the content
to be converted to a base64-string
The PHP variable type of the data is IS preserved as long as the types
are strings, arrays, integers and booleans. Strings are the default
type unless the "type" attribute is set.
The output XML has been tested with the PHP XML-parser and parses OK under all tested circumstances.
However using MSIE to read the XML output didn't always go well: One
reason could be that the character encoding is not observed in the PHP
data. The other reason may be if the tag-names are invalid in the eyes
of MSIE. Also using the namespace feature will make MSIE break parsing.
There might be more reasons...
$array | array | The input PHP array with any kind of data; text, binary, integers. Not objects though. |
$NSprefix='' | string | tag-prefix, eg. a namespace prefix like "T3:" |
$level=0 | integer | Current recursion level. Don't change, stay at zero! |
$docTag='phparray' | string | Alternative document tag. Default is "phparray". |
$spaceInd=0 | integer | If set, the number of spaces corresponding to this number is used for indenting, otherwise a single chr(9) (TAB) is used |
$options=array() | array | Options for the compilation. Key "useNindex" => 0/1 (boolean: whether to use "n0, n1, n2" for num. indexes); Key "useIndexTagForNum" => "[tag for numerical indexes]"; Key "useIndexTagForAssoc" => "[tag for associative indexes"; Key "parentTagMap" => array('parentTag' => 'thisLevelTag') |
$parentTagName='' | string | Parent tag name. Don't touch. |
Returns: | string | An XML string made from the input content in the array. |
@see xml2array() |
Converts an XML string to a PHP array.
This is the reverse function of array2xml()
$string | string | XML content to convert into an array |
$NSprefix='' | string | The tag-prefix resolve, eg. a namespace like "T3:" |
Returns: | mixed | If the parsing had errors, a string with the error message is returned. Otherwise an array with the content. |
@see array2xml() |
This implodes an array of XML parts (made with xml_parse_into_struct()) into XML again.
$vals | array | A array of XML parts, see xml2tree |
Returns: | string | Re-compiled XML data. |
Extract the encoding scheme as found in the first line of an XML document (typically)
$xmlData | string | XML data |
Returns: | string | Encoding scheme (lowercase), if found. |
Reads the file or url $url and returns the content
If you are having trouble with proxys when reading URLs you can
configure your way out of that with settings like
$TYPO3_CONF_VARS['SYS']['curlUse'] etc.
Usage: 79
$url | string | Filepath/URL to read |
Returns: | string | The content from the resource given as input. |
Writes $content to the file $file
Usage: 31
$file | string | Filepath to write to |
$content | string | Content to write |
Returns: | boolean | True if the file was successfully opened and written to. |
Returns an array with the names of folders in a specific path
Will return 'error' (string) if there were an error with reading directory content.
Usage: 13
$path | string | Path to list directories from |
Returns: | array | Returns an array with the directory entries as values. If no path, the return value is nothing. |
Returns an array with the names of files in a specific path
Usage: 17
$path | string | $path: Is the path to the file |
$extensionList='' | string | $extensionList is the comma list of extensions to read only (blank = all) |
$prependPath=0 | boolean | If set, then the path is prepended the filenames. Otherwise only the filenames are returned in the array |
$order='' | string | $order is sorting: 1= sort alphabetically, 'mtime' = sort by modification time. |
Returns: | array | Array of the files found |
Recursively gather all files and folders of a path.
$fileArr | array | $fileArr: Empty input array (will have files added to it) |
$path | string | $path: The path to read recursively from (absolute) |
$extList='' | string | $extList: Comma list of file extensions: Only files with extensions in this list (if applicable) will be selected. |
$regDirs=0 | boolean | $regDirs: If set, directories are also included in output. |
$recursivityLevels=99 | integer | $recursivityLevels: The number of levels to dig down... |
Returns: | array | An array with the found files/directories. |
Removes the absolute part of all files/folders in fileArr
$fileArr | array | $fileArr: The file array to remove the prefix from |
$prefixToRemove | string | $prefixToRemove: The prefix path to remove (if found as first part of string!) |
Returns: | array | The input $fileArr processed. |
Fixes a path for windows-backslashes and reduces double-slashes to single slashes
Usage: 2
$theFile | string | File path to process |
Returns: | string |
Resolves "../" sections in the input path string
$pathStr | string | File path in which "/../" is resolved |
Returns: | string |
Prefixes a URL used with 'header-location' with 'http://...' depending on whether it has it already.
- If already having a scheme, nothing is prepended
- If having REQUEST_URI slash '/', then prefixing 'http://[host]' (relative to host)
- Otherwise prefixed with TYPO3_REQUEST_DIR (relative to current dir / TYPO3_REQUEST_DIR)
Usage: 31
$path | string | URL / path to prepend full URL addressing to. |
Returns: | string |
Returns a string with a list of ascii-values for the first $characters characters in $string
Usage: 5
$string | string | String to show ASCII value for |
$characters=100 | integer | Number of characters to show |
Returns: | string | The string with ASCII values in separated by a space char. |
@internal |
Returns HTML-code, which is a visual representation of a multidimensional array
use t3lib_div::print_array() in order to print an array
Returns false if $array_in is not an array
Usage: 27
$array_in | array | Array to view |
Returns: | string | HTML output |
Prints an array
Usage: 28
$array_in | array | Array to print visually (in a table). |
Returns: | void | |
@internal | ||
@see view_array() |
Makes debug output
Prints $var in bold between two vertical lines
If not $var the word 'debug' is printed
If $var is an array, the array is printed by t3lib_div::print_array()
Usage: 8
$var="" | mixed | Variable to print |
$brOrHeader=0 | mixed | If the parameter is a string it will be used as header. Otherwise number of break tags to apply after (positive integer) or before (negative integer) the output. |
Returns: | void |
Returns the HOST+DIR-PATH of the current script (The URL, but without 'http://' and without script-filename)
Usage: 1
Returns: | string |
Returns the link-url to the current script.
In $getParams you can set associative keys corresponding to the
get-vars you wish to add to the url. If you set them empty, they will
remove existing get-vars from the current url.
REMEMBER to always htmlspecialchar() content in href-properties to
ampersands get converted to entities (XHTML requirement and XSS
precaution)
Usage: 54
$getParams=array() | array | Array of GET parameters to include |
Returns: | string |
Takes
a full URL, $url, possibly with a querystring and overlays the
$getParams arrays values onto the quirystring, packs it all together
and returns the URL again.
So basically it adds the parameters in $getParams to an existing URL, $url
Usage: 2
$url | string | URL string |
$getParams=array() | array | Array of key/value pairs for get parameters to add/overrule with. Can be multidimensional. |
Returns: | string | Output URL with added getParams. |
Abstraction
method which returns System Environment Variables regardless of server
OS, CGI/MODULE version etc. Basically this is SERVER variables for most
of them.
This should be used instead of getEnv() and HTTP_SERVER_VARS/ENV_VARS to get reliable values for all situations.
Usage: 226
$getEnvName | string | Name of the "environment variable"/"server variable" you wish to use. Valid values are SCRIPT_NAME, SCRIPT_FILENAME, REQUEST_URI, PATH_INFO, REMOTE_ADDR, REMOTE_HOST, HTTP_REFERER, HTTP_HOST, HTTP_USER_AGENT, HTTP_ACCEPT_LANGUAGE, QUERY_STRING, TYPO3_DOCUMENT_ROOT, TYPO3_HOST_ONLY, TYPO3_HOST_ONLY, TYPO3_REQUEST_HOST, TYPO3_REQUEST_URL, TYPO3_REQUEST_SCRIPT, TYPO3_REQUEST_DIR, TYPO3_SITE_URL, _ARRAY |
Returns: | string | Value based on the input key, independent of server/os environment. |
milliseconds
microtime recalculated to t3lib_div::milliseconds(1/1000 sec)
Usage: 39
Returns: | integer |
Client Browser Information
Usage: 4
$useragent='' | string | Alternative User Agent string (if empty, t3lib_div::getIndpEnv('HTTP_USER_AGENT') is used) |
Returns: | array | Parsed information about the HTTP_USER_AGENT in categories BROWSER, VERSION, SYSTEM and FORMSTYLE |
Returns the absolute filename of $filename.
Decodes the prefix EXT: for TYPO3 Extensions.
Usage: 9
$filename | string | The input filename/filepath to evaluate |
$onlyRelative=1 | boolean | If $onlyRelative is set (which it is by default), then only return values relative to the current PATH_site is accepted. |
$relToTYPO3_mainDir=0 | boolean | If $relToTYPO3_mainDir is set, then relative paths are relative to PATH_typo3 constant - otherwise (default) they are relative to PATH_site |
Returns: | string | Returns the absolute filename of $filename IF valid, otherwise blank string. |
Returns true if no '//', '..' or '\' is in the $theFile
This should make sure that the path is not pointing 'backwards' and further doesn't contain double/back slashes.
So it's compatible with the UNIX style path strings valid for TYPO3 internally.
Usage: 8
$theFile | string | Filepath to evaluate |
Returns: | boolean | True, if no '//', '..' or '\' is in the $theFile |
@todo Possible improvement: Should it rawurldecode the string first to check if any of these characters is encoded ? |
Checks if the $path is absolute or relative (detecting either '/' or 'x:/' as first part of string) and returns true if so.
Usage: 9
$path | string | Filepath to evaluate |
Returns: | boolean |
Returns true if the path is absolute, without backpath '..' and within the PATH_site OR within the lockRootPath
Usage: 1
$path | string | Filepath to evaluate |
Returns: | boolean |
Verifies the input filename againts the 'fileDenyPattern'. Returns true if OK.
Usage: 2
$filename | string | Filepath to evaluate |
Returns: | boolean |
Moves $source file to $destination if uploaded, otherwise try to make a copy
Usage: 3
$source | string | Source file, absolute path |
$destination | string | Destination file, absolute path |
Returns: | boolean | Returns true if the file was moved. |
@coauthor Dennis Petersen <fessor@software.dk> | ||
@see upload_to_tempfile() |
Will
move an uploaded file (normally in "/tmp/xxxxx") to a temporary
filename in PATH_site."typo3temp/" from where TYPO3 can use it under
safe_mode.
Use this function to move uploaded files to where you can work on them.
REMEMBER to use t3lib_div::unlink_tempfile() afterwards - otherwise
temp-files will build up! They are NOT automatically deleted in
PATH_site."typo3temp/"!
$uploadedFileName | string | The temporary uploaded filename, eg. $GLOBALS['HTTP_POST_FILES']['[upload field name here]']['tmp_name'] |
Returns: | string | If a new file was successfully created, return its filename, otherwise blank string. |
@see unlink_tempfile(), upload_copy_move() |
Deletes (unlink) a temporary filename in 'PATH_site."typo3temp/"' given as input.
The function will check that the file exists, is in
PATH_site."typo3temp/" and does not contain back-spaces ("../") so it
should be pretty safe.
Use this after upload_to_tempfile() or tempnam() from this class!
$uploadedTempFileName | string | Filepath for a file in PATH_site."typo3temp/". Must be absolute. |
Returns: | boolean | Returns true if the file was unlink()'ed |
@see upload_to_tempfile(), tempnam() |
Create temporary filename (Create file with unique file name)
This function should be used for getting temporary filenames - will make your applications safe for open_basedir = on
REMEMBER to delete the temporary files after use! This is done by t3lib_div::unlink_tempfile()
$filePrefix | string | Prefix to temp file (which will have no extension btw) |
Returns: | string | result from PHP function tempnam() with PATH_site.'typo3temp/' set for temp path. |
@see unlink_tempfile() |
standard authentication code - can't remember what it's used for.
Usage: 2
$uid_or_record | mixed | Uid (integer) or record (array) |
$fields='' | string | List of fields from the record if that is given. |
Returns: | string | MD5 hash of 8 chars. |
@internal |
Loads the $TCA (Table Configuration Array) for the $table
Requirements:
1) must be configured table (the ctrl-section configured),
2) columns must not be an array (which it is always if whole table loaded), and
3) there is a value for dynamicConfigFile (filename in typo3conf)
Usage: 92
$table | string | Table name for which to load the full TCA array part into the global $TCA |
Returns: | void |
Looks
for a sheet-definition in the input data structure array. If found it
will return the data structure for the sheet given as $sheet (if found).
If the sheet definition is in an external file that file is parsed and the data structure inside of that is returned.
$dataStructArray | array | Input data structure, possibly with a sheet-definition and references to external data source files. |
$sheet='sDEF' | string | The sheet to return, preferably. |
Returns: | array | An array with two num. keys: key0: The data structure is returned in this key (array) UNLESS an error happend in which case an error string is returned (string). key1: The used sheet key value! |
Resolves ALL sheet definitions in dataStructArray
If no sheet is found, then the default "sDEF" will be created with the dataStructure inside.
$dataStructArray | array | Input data structure, possibly with a sheet-definition and references to external data source files. |
Returns: | array | Output data structure with all sheets resolved as arrays. |
Calls a userdefined function/method in class
Such a function/method should look like this: "function proc(&$params, &$ref) {...}"
Usage: 3
$funcName | string | Method reference, [class]->[method] or [function]. You can prefix this reference with "[file-reference]:" and t3lib_div::getFileAbsFileName() will then be used to resolve the filename and subsequently include it by "require_once()" which means you don't have to worry about including the class file either! Example: "EXT:realurl/class.tx_realurl.php:tx_realurl->>encodeSpURL". Finally; for method references the normal operator "->" creates a new instance each time; if you use "->>" instead you will reuse the previous instance of the object identified by the full reference string (meaning; if you call another method in the same class another object is created for that). |
&$params | mixed | Parameters to be pass along (typically an array) (REFERENCE!) |
&$ref | mixed | Reference to be passed along (typically "$this" - being a reference to the calling object) (REFERENCE!) |
$checkPrefix='user_' | string | Required prefix of class or function name |
$silent=0 | boolean | If set, not debug() error message is shown if class/function is not present. |
Returns: | mixed | Content from method/function call |
Find the best service and check if it works.
Returns object of the service class.
$serviceType | string | Type of service (service key). |
$serviceSubType='' | string | Sub type like file extensions or similar. Defined by the service. |
$excludeServiceKeys='' | string | List of service keys which should be exluded in the search for a service. |
Returns: | object | The service object or an array with error info's. |
@author René Fritz <r.fritz@colorcube.de> |
Return classname for new instance
Takes the class-extensions API of TYPO3 into account
Usage: 18
$className | string | Base Class name to evaluate |
Returns: | string | Final class name to instantiate with "new [classname]" |
Simple substitute for the PHP function mail().
The fifth parameter, $enc, will allow you to specify 'base64' encryption for the output (set $enc=base64)
Further the output has the charset set to ISO-8859-1 by default.
Usage: 4
string | Email address to send to. (see PHP function mail()) | |
$subject | string | Subject line, non-encoded. (see PHP function mail()) |
$message | string | Message content, non-encoded. (see PHP function mail()) |
$headers='' | string | Headers, separated by chr(10) |
$enc='' | string | Encoding type: "base64", "quoted-printable", "8bit". If blank, no encoding will be used, no encoding headers set. |
$charset='ISO-8859-1' | string | Charset used in encoding-headers (only if $enc is set to a valid value which produces such a header) |
$dontEncodeSubject=0 | boolean | If set, the content of $subject will not be encoded. |
Returns: | void |
Implementation of quoted-printable encode.
This functions is buggy. It seems that in the part where the lines are
breaked every 76th character, that it fails if the break happens right
in a quoted_printable encode character!
(Originally taken from class.t3lib_htmlmail.php - which may be updated if this function should ever be improved!
See RFC 1521, section 5.1 Quoted-Printable Content-Transfer-Encoding
Usage: 2
$string | string | Content to encode |
$maxlen=76 | integer | Length of the lines, default is 76 |
Returns: | string | The QP encoded string |
Takes
a clear-text message body for a plain text email, finds all 'http://'
links and if they are longer than 76 chars they are converted to a
shorter URL with a hash parameter. The real parameter is stored in the
database and the hash-parameter/URL will be redirected to the real
parameter when the link is clicked.
This function is about preserving long links in messages.
Usage: 3
$message | string | Message content |
$urlmode='76' | string | URL mode; "76" or "all" |
$index_script_url='' | string | URL of index script (see makeRedirectUrl()) |
Returns: | string | Processed message content |
@see makeRedirectUrl() |
Subfunction for substUrlsInPlainText() above.
Usage: 2
$inUrl | string | Input URL |
$l=0 | integer | URL string length limit |
$index_script_url='' | string | URL of "index script" - the prefix of the "?RDCT=..." parameter. If not supplyed it will default to t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR') |
Returns: | string | Processed URL |
@internal |
Function to compensate for FreeType2 96 dpi
Usage: 16
$font_size | integer | Fontsize for freetype function call |
Returns: | integer | Compensated fontsize based on $GLOBALS['TYPO3_CONF_VARS']['GFX']['TTFdpi'] |
Developer
log; This should be implemented around the source code, both frontend
and backend, logging everything from the flow through an application,
messages, results from comparisons to fatal errors.
The result is meant to make sense to developers during development or debugging of a site.
The idea is that this function is only a wrapper for external
extensions which can set a hook which will be allowed to handle the
logging of the information to any format they might wish and with any
kind of filter they would like.
If you want to implement the devLog in your applications, simply add lines like:
if (TYPO3_DLOG) t3lib_div::devLog('[write message in english here]', 'extension key');
$msg | string | Message (in english). |
$extKey | string | Extension key (from which extension you are calling the log) |
$severity=0 | integer | Severity: 0 is info, 1 is notice, 2 is warning, 3 is fatal error, -1 is "OK" message |
$dataVar=FALSE | array | Additional data you want to pass to the logger. |
Returns: | void |