- Symphony 2.2.5
-
› assets
11 -
› boot
9 -
› core
22 -
› email-gateways
3 -
› toolkit
67 -
› Unknown
33 - Delegates87
- Deprecated30
Versions
- 2.7.9
- 2.7.8
- 2.7.7
- 2.7.6
- 2.7.5
- 2.7.3
- 2.7.2
- 2.7.10
- 2.7.1
- 2.7.0
- 2.6.9
- 2.6.8
- 2.6.7
- 2.6.6
- 2.6.5
- 2.6.4
- 2.6.3
- 2.6.2
- 2.6.11
- 2.6.10
- 2.6.1
- 2.6.0
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4
- 2.3.6
- 2.3.5
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3
- 2.2.5
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2
Options
public class General
class.general.php #9General is a utility class that offers a number miscellaneous of functions that are used throughout Symphony.
Constants
static string CRLF = PHP_EOL
The end-of-line constant.
Deprecated
This will be removed in the next version of Symphony
Methods
static integer array_find_available_index(
$array, $seed)
Find the next available index in an array. Works best with numeric keys. The next available index is the minimum integer such that the array does not have a mapping for that index. Uses the increment operator on the index type of the input array, whatever that may do.
Parameters
Returns
the minimum empty index into the input array.
static array array_iunique(
$array)
Filter the input array for duplicates, treating each element in the array as a string and comparing them using a case insensitive comparison function.
Parameters
Returns
a new array containing only the unique elements of the input array.
static array array_map_recursive(
$function, $array)
Function recursively apply a function to an array's values. This will not touch the keys, just the values.
Returns
a new array with all the values passed through the given $function
static a array_remove_duplicates(
$array, $ignore_case)
Filter the duplicate values from an array into a new array, optionally ignoring the case of the values (assuming they are strings?). A new array is returned, the input array is left unchanged.
Parameters
Returns
new array containing only the unique elements of the input array.
static void array_to_xml(XMLElement $parent, $data, $validate)
Convert an array into an XML fragment and append it to an existing XML element. Any arrays contained as elements in the input array will also be recursively formatted and appended to the input XML fragment. The input XML element will be modified as a result of calling this.
Parameters
static XMLElement buildPaginationElement(
$total_entries, $total_pages, $entries_per_page, $current_page)
Construct an XML fragment that describes a pagination structure.
Parameters
Returns
the constructed XML fragment.
static void cleanArray(
$arr, $&$arr)
Strip any slashes from all array values.
Parameters
static integer countWords(
$string)
Count the number of words in a string. Words are delimited by "spaces". The characters included in the set of "spaces" are: ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '𠀯', ' ' Any html/xml tags are first removed by strip_tags() and any included html entities are decoded. The resulting string is then split by the above set of spaces and the resulting size of the resulting array returned.
Parameters
Returns
the number of words contained in the input string.
static string createFilename(
$string, $delim)
Given a string, this will clean it for use as a filename. Preserves multi-byte characters.
Parameters
Returns
Returns created filename
static string createHandle(
$string, $max_length, $delim, $uriencode, $additional_rule_set)
Given a string, this will clean it for use as a Symphony handle. Preserves multi-byte characters.
Parameters
Returns
Returns resultant handle
static boolean|XMLElement createXMLDateObject(
$timestamp, $element, $date_format, $time_format, $namespace)
Construct an XML fragment that reflects the structure of the input timestamp.
Parameters
Returns
false if there is no XMLElement class on the system, the constructed XML element otherwise.
static boolean deleteFile(
$file, $slient, $silent)
Delete a file at a given path, silently ignoring errors depending on the value of the input variable $silent.
Parameters
Returns
true if the file is successfully unlinked, if the unlink fails and silent is set to true then an exception is thrown. if the unlink fails and silent is set to false then this returns false.
static integer fileSort(
$f1, $f2)
Compare two file structure arrays based on their name. Names are
compared alphabetically. Should only be used in the context of a
sort function such as usort. For example:
usort($files, array('General', 'fileSort'));
Parameters
Returns
<1, 0, >1 if $f1
is less than, equal to or greater than $f2
.
static integer fileSortR(
$f1, $f2)
Compare two file structure arrays based on their name. Names are compared
alphabetically reversed. For example "z" is less than "a". Should only
be used in the context of a sort function such as usort. For example:
usort($files, array('General', 'fileSortR'));
Parameters
Returns
<1, 0, >1 if $f2
is less than, equal to or greater than $f1
.
static integer filemtimeSort(
$f1, $f2)
Compare two file structures based on their modification time. Should only
be used in the context of a sort function such as usort. For example:
usort($files, array('General', 'filemtimeSort'));
Parameters
Returns
<1, 0, >1 if $f1
is less than, equal to or greater than $f2
.
static void flattenArray(
$source, $output, $path, $&$source, $&$output)
Flatten the input array. Any elements of the input array that are
themselves arrays will be removed and the contents of the removed array
inserted in its place. The keys for the inserted values will be the
concatenation of the keys in the original arrays in which it was embedded.
The elements of the path are separated by periods (.). For example,
given the following nested array structure:
array(1 =>
array('key' => 'value'),
2 =>
array('key2' => 'value2', 'key3' => 'value3')
)
will flatten to:
array('1.key' => 'value', '2.key2' => 'value2', '2.key3' => 'value3')
Parameters
static string formatFilesize(
$file_size)
Format a number of bytes in human readable format. This will append MB as appropriate for values greater than 1,0241,024, KB for values between 1,024 and 1,0241,024-1 and bytes for values between 0 and 1,024.
Parameters
Returns
the formatted number.
static string generatePassword()
Create friendly passwords such as 4LargeWorms or 11HairyMonkeys. This uses the rand() function. Thus, if the random number generated is seeded appropriately, this function will return the same password consistently.
Returns
the generated password.
static array getExtension(
$file)
Extract the file extension from the input file path.
Parameters
Returns
an array with a single key 'extension' and a value of the extension of the input path.
static array getPostData()
Merge $_POST
with $_FILES
to produce a flat array of the contents
of both. If there is no mergefilepost_data function defined then
such a function is created. This is necessary to overcome PHP's ability
to handle forms. This overcomes PHP's convoluted $_FILES
structure
to make it simpler to access multi-part/formdata.
Returns
a flat array containing the flattened contents of both $_POST
and $_FILES
.
static string hash(
$input, $algorithm)
Uses SHA1 or MD5 to create a hash based on some input This function is currently very basic, but would allow future expansion. Salting the hash comes to mind.
Parameters
Returns
the hashed string
static boolean in_array_all(
$needles, $haystack)
Search an array for multiple values.
Parameters
Returns
true if any of the $needles
are in $haystack
, false otherwise.
static boolean in_array_multi(
$needle, $haystack)
Search a multi-dimensional array for a value.
Parameters
Returns
true if $needle
is found in $haystack
. true if $needle
== $haystack
. true if $needle
is found in any of the arrays contained within $haystack
. false otherwise.
static boolean in_iarray(
$needle, $haystack)
Test whether a value is in an array based on string comparison, ignoring the case of the values.
Parameters
Returns
true if the $needle
is in the $haystack
, false otherwise.
static string|boolean left(
$str, $num)
Extract the first $num
characters from a string.
Parameters
Returns
a string containing the last $num
characters of the input string, or false on failure.
static null|string limitWords(
$string, $maxChars, $appendHellip)
Truncate a string to a given length. Newlines are replaced with <br />
html elements and html tags are removed from the string. If the resulting
string contains only spaces then null is returned. If the resulting string
is less than the input length then it is returned. If the option to
truncate the string to a space character is provided then the string is
truncated to the character prior to the last space in the string. Words
(contiguous non-' ' characters) are then removed from the end of the string
until the length of resulting string is within the input bound. Initial
and trailing spaces are removed. Provided the user requested an
ellipsis suffix and the resulting string is shorter than the input string
then the ellipses are appended to the result which is then returned.
Parameters
Returns
if the resulting string contains only spaces then null is returned. otherwise a string that satisfies the input constraints.
static null|array listDirStructure(
$dir, $filter, $recurse, $strip_root, $exclude, $ignore_hidden)
Construct a multi-dimensional array that reflects the directory structure of a given path.
Parameters
Returns
return the array structure reflecting the input directory or null if the input directory is not actually a directory.
static null|array listStructure(
$dir, $filters, $sort, $strip_root, $exclude, $recurse, $ignore_hidden)
Construct a multi-dimensional array that reflects the directory structure of a given path grouped into directory and file keys matching any input constraints.
Parameters
Returns
return the array structure reflecting the input directory or null if the input directory is not actually a directory.
static array processFilePostData(
$filedata)
Transform a multi-dimensional array to a flat array. The input array
is expected to conform to the structure of the $_FILES
variable.
Parameters
Returns
the flattened array.
static boolean realiseDirectory(
$path, $mode)
Create all the directories as specified by the input path. If the current directory already exists, this function will return true.
Parameters
static string reverse_sanitize(
$str)
Revert any html entities to their character equivalents.
Parameters
Returns
the decoded version of the string
static string|boolean right(
$str, $num)
Extract the last $num
characters from a string.
Parameters
Returns
a string containing the last $num
characters of the input string, or false on failure.
static string sanitize(
$source)
Convert any special characters into their entity equivalents.
Parameters
Returns
the encoded version of the string.
static boolean sendEmail(
$to_email, $from_email, $from_name, $subject, $message, $additional_headers)
Allows you to send emails. It initializes the core email class.
Parameters
Returns
true on success
Deprecated
Since Symphony 2.2
static string|boolean substrmax(
$str, $val)
Extract the first $val
characters of the input string. If
$val
is larger than the length of the input string then
the original input string is returned
Parameters
Returns
the resulting string or false on failure.
static string|boolean substrmin(
$str, $val)
Extract the first $val
characters of the input string. If $val
is larger than the length of the input string then the original
input string is returned.
Parameters
Returns
the resulting string or false on failure.
static string tabsToSpaces(
$string, $spaces)
Replace the tabs with spaces in the input string.
Parameters
Returns
the resulting string.
static boolean uploadFile(
$dest_path, $dest_name, $tmp_name, $perm, $#dest_name)
Move a file from the source path to the destination path and name and set its permissions to the input permissions. This will ignore errors in the isuploadedfile(), moveuploadedfile() and chmod() functions.
Parameters
Returns
true if the file was moved and its permissions set as required. false otherwise.
static boolean validateString(
$string, $rule)
Validate a string against a set of regular expressions.
Parameters
Returns
false if any of the rules in $rule do not match any of the strings in $string
, return true otherwise.
static string validateURL(
$url)
Check that a string is a valid URL.
Parameters
Returns
a blank string or a valid URL
static boolean validateXML(
$data, $errors, $isFile, $xsltProcessor, $encoding, $&$errors)
Checks an xml document for well-formedness.
Parameters
Returns
true if there are no errors in validating the XML, false otherwise.
static boolean writeFile(
$file, $data, $perm, $mode)
Create a file at the input path with the (optional) input permissions with the input content. This function will ignore errors in opening, writing, closing and changing the permissions of the resulting file. If opening or writing the file fail then this will return false.
Parameters
Returns
true if the file is successfully opened, written to, closed and has the required permissions set. false, otherwise.