| Version 4 (modified by thomasb, 5 years ago) (diff) |
|---|
Common PHP functions
The include file program/include/main.inc provides some commonly used functions which are listed below.
get_input_value($fname, $source, $allow_html=FALSE, $charset=NULL)
Read a specific GET/POST value and convert it for (safe) internal use. Performs stripslashes() and charset conversion if necessary. Use one of the following constants to specify $source: RCUBE_INPUT_GET, RCUBE_INPUT_POST, RCUBE_INPUT_GPC
strip_quotes($str)
Removes quotes from a given string. Use this together with get_input_value() when passing a GET/POST parameter to the HTML or JavaScript output.
rcube_charset_convert($str, $from, $to=NULL)
This function converts a string from one charset to another. This is mostly used for converting mail contents into the internally used UTF-8 charset. It invokes mbstring or iconv function if available. The third parameter defaults to the internal chars which is UTF-8.
Q($str, $mode='strict', $newlines=TRUE)
HTML encodes a string similar to htmlentities(). This should be used wherever a variable is written to the HTML output. $mode accepts the following values: 'strict' (encode all entities), 'show' (leave <>"&), 'remove' (executes strip_tags()).
JQ($str)
Quotes a string for JavaScript output. This will replace new lines and other chars.
$OUTPUT->send([template])
Delivers response content to the client. This will automatically decide whether it's an AJAX call or a regular request and then send the commands and contents accordingly. The specified JS code (usually added with $OUTPUT->command()) will be evaled and executed on the client.
console($msg)
Used for debug output. Depending on the debug_level it will dump the given value to the HTML page or write it to logs/console.
write_log($name, $line)
Append a line to a logfile ($name) in the logs directory. The current date will be added automatically to the line.
rcube_label($attrib)
Get a localized text. $attrib can be the label/message name or an array with the following keys: 'name', 'vars' (hash array of variables to replace in text), 'uppercase' (boolean), 'lowercase' (boolean).
Global objects and vars
$RCMAIL
The main application object holding instances of all the 'global' objects like config, database and imap connections. It's and instance of the rcmail class and can be obtained by calling rcmail::get_instance()
$IMAP (deprecated, use $RCMAIL->imap instead)
This is a global instance of the rcube_imap class. It is created and initialized by Roundcube's startup function.
$OUTPUT (deprecated, use $RCMAIL->output instead)
A global instance of the rcube_template class. Use it to collect all kind of response data to be sent to the client after processing the script.
$DB (deprecated, use $RCMAIL->get_dbh() instead)
Use this global instance of the rcube_db class for all database communication. It is initialized by Roundcube's startup function.
$CONFIG (deprecated, use $RCMAIL->config instead)
Global array containing all config parameters. It is loaded from the local config files and extended by the user specific settings.
