Source for file options.php
Documentation is available at options.php
* Functions needed to display the options pages.
* @copyright 1999-2020 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: options.php 14845 2020-01-07 08:09:34Z pdontthink $
* SquirrelOption: An option for SquirrelMail.
* The original option configuration array
* The name of this setting
* The text that prefaces setting on the preferences page
* Whether or not the caption text is allowed to wrap
* The type of INPUT element
* See SMOPT_TYPE_* defines
* Indicates if a link should be shown to refresh part
* See SMOPT_REFRESH_* defines
* Specifies the size of certain input items
* See SMOPT_SIZE_* defines
* Text that follows a text input or
* select list input on the preferences page
* useful for indicating units, meanings of special values, etc.
* Indicates that the widget's "trailing text"
* should be displayed in a smaller sized font
* Indicates that the widget's "trailing text"
* contains HTML and should not thus be
* Text that overrides the "Yes" label for boolean
* Text that overrides the "No" label for boolean
* Some widgets support more than one layout type
* Indicates if the Add widget should be included
* Indicates if the Delete widget should be included
* associative array, treated the same as $possible_values
* (see its documentation below), but usually expected to
* have its first value contain a list of IMAP folders, an
* array itself in the format as passed back by
* sqimap_mailbox_list(). Used to display folder selector
* for possible values of an associative edit list option
* text displayed to the user
* Used with SMOPT_TYPE_COMMENT options
* additional javascript or other widget attributes added to the
* user input; must be an array where keys are attribute names
* ("onclick", etc) and values are the attribute values.
* script (usually Javascript) that will be placed after (outside of)
* The name of the Save Function for this option.
/* The various 'values' for this options. */
* default/preselected value for this option
* associative array, where each key is an actual input value
* and the corresponding value is what is displayed to the user
* for that list item in the drop-down list
* disables html sanitizing.
* WARNING - don't use it, if user input is possible in option
* or use own sanitizing functions. Currently only works for SMOPT_TYPE_STRLIST.
* Controls folder list limits in SMOPT_TYPE_FLDRLIST and
* SMOPT_TYPE_FLDRLIST_MULTI widgets as well as the optional
* embedded folder lists provided for inputting values for
* the SMOPT_TYPE_EDIT_LIST and SMOPT_TYPE_EDIT_LIST_ASSOCIATIVE
* See $flag argument in sqimap_mailbox_option_list() function.
* Constructor (PHP5 style, required in some future version of PHP)
* @param array $raw_option_array
* @param integer $refresh_level
* @param mixed $initial_value
* @param array $possible_values
* @param bool $htmlencoded
($raw_option_array, $name, $caption, $type, $refresh_level, $initial_value =
'', $possible_values =
'', $htmlencoded =
false) {
/* Set the basic stuff. */
//Check for a current value.
if (isset
($GLOBALS[$name])) {
$this->value =
$GLOBALS[$name];
// TODO: This code should be something more like the following, but who knows what would break if it was changed at this point
// } else if (initial_value !== '') {
} else if (!empty($initial_value)) {
$this->value =
$initial_value;
/* Check for a new value. */
/* Set the default save function. */
* Constructor (PHP4 style, kept for compatibility reasons)
* @param array $raw_option_array
* @param integer $refresh_level
* @param mixed $initial_value
* @param array $possible_values
* @param bool $htmlencoded
($raw_option_array, $name, $caption, $type, $refresh_level, $initial_value =
'', $possible_values =
'', $htmlencoded =
false) {
self::__construct($raw_option_array, $name, $caption, $type, $refresh_level, $initial_value, $possible_values, $htmlencoded);
/** Convenience function that identifies which types of
widgets are stored as (serialized) array values. */
* Set the value for this option.
* Set the new value for this option.
* @param mixed $new_value
* Set whether the caption is allowed to wrap for this option.
* @param boolean $caption_wrap
* Set the size for this option.
* Set the trailing_text for this option.
* @param string $trailing_text
* Set the trailing_text_small for this option.
* @param boolean $trailing_text_small
* Set the trailing_text_is_html for this option.
* @param boolean $trailing_text_is_html
* Set the yes_text for this option.
* @param string $yes_text
* Set the no_text for this option.
/* Set the "use add widget" value for this option. */
/* Set the "use delete widget" value for this option. */
/* Set the "poss value folders" value for this option.
See the associative edit list widget, which uses this
to offer folder list selection for the values */
* Set the layout type for this option.
* @param int $layout_type
* Set the comment for this option.
* Set the extra attributes for this option.
* @param array $aExtraAttribs
* Set the "post script" for this option.
* @param string $post_script
* Set the save function for this option.
* @param string $save_function
* Set the folder_filter for this option.
* @param string $folder_filter
* Creates fields on option pages according to option type
* This is the function that calls all other createWidget* functions.
* @return string The formated option field
// Use new value if available
$tempValue =
$this->value;
/* Get the widget for this option type. */
/* Add the "post script" for this option. */
// put correct value back if need be
$this->value =
$tempValue;
/* Now, return the created widget. */
* @return string html formated output
// return sq_htmlspecialchars($this->value);
// like COMMENT, allow HTML here
* @param boolean $password When TRUE, the text in the input
* widget will be obscured (OPTIONAL;
* @return string html formated option field
//TODO: might be better to have a separate template file for all widgets, because then the layout of the widget and the "trailing text" can be customized - they are still hard coded here (also, we have <small> tags here; don't want HTML here!)
* Create selection box or radio button group
* When $this->htmlencoded is TRUE, the keys and values in
* $this->possible_values are assumed to be display-safe.
* Note that when building radio buttons instead of a select
* widget, if the "size" attribute is SMOPT_SIZE_TINY, the
* radio buttons will be output one after another without
* linebreaks between them. Otherwise, each radio button
* goes on a line of its own.
* @param boolean $multiple_select When TRUE, the select widget
* will allow multiple selections
* (OPTIONAL; default is FALSE
* @param boolean $radio_buttons When TRUE, the widget will
* instead be built as a group
* $multiple_select will be
* forced to FALSE) (OPTIONAL;
* default is FALSE (select widget))
* @return string html formated selection box or radio buttons
//FIXME: Currently, $this->htmlencoded is ignored here -- was removed when changing to template-based output; a fix is available as part of proposed centralized sanitizing patch
// radio buttons instead of select widget?
// everything below applies to select widgets
//FIXME: not sure about these sizes... seems like we could add another on the "large" side...
* Create folder selection box
* @param boolean $multiple_select When TRUE, the select widget
* will allow multiple selections
* (OPTIONAL; default is FALSE
* @return string html formated selection box
//FIXME: not sure about these sizes... seems like we could add another on the "large" side...
// possible values might include a nested array of
// possible values (list of folders)
// list of folders (boxes array)
$option_list =
array_merge($option_list, array($value =>
$text));
$option_list =
array('ignore' =>
_("unavailable"));
* @return string html formated textarea field
default:
$rows =
5; $cols =
50;
* Creates field for integer
* Difference from createWidget_String is visible only when javascript is enabled
* @return string html formated option field
// add onChange javascript handler to a regular string widget
// which will strip out all non-numeric chars
$this->aExtraAttribs['onchange'] =
'origVal=this.value; newVal=\'\'; '
.
'for (i=0;i<origVal.length;i++) { if (origVal.charAt(i)>=\'0\' '
.
'&& origVal.charAt(i)<=\'9\') newVal += origVal.charAt(i); } '
* Creates field for floating number
* Difference from createWidget_String is visible only when javascript is enabled
* @return string html formated option field
// add onChange javascript handler to a regular string widget
// which will strip out all non-numeric (period also OK) chars
$this->aExtraAttribs['onchange'] =
'origVal=this.value; newVal=\'\'; '
.
'for (i=0;i<origVal.length;i++) { if ((origVal.charAt(i)>=\'0\' '
.
'&& origVal.charAt(i)<=\'9\') || origVal.charAt(i)==\'.\') '
.
'newVal += origVal.charAt(i); } this.value=newVal;';
* When creating Yes/No radio buttons, the "yes_text"
* and "no_text" option attributes are used to override
* the typical "Yes" and "No" text.
* @param boolean $checkbox When TRUE, the widget will be
* constructed as a checkbox,
* otherwise it will be a set of
* Yes/No radio buttons (OPTIONAL;
* default is TRUE (checkbox)).
* @return string html formated boolean widget
global $oTemplate, $nbsp;
//TODO: Why isn't trailing_text being sanitized with sm_encode_special_chars()??? If this is a bug, add that, then add the option to display unsanitized if $this->trailing_text_is_html is enabled
/* Build the yes choice. */
/* Build the no choice. */
/* Build the combined "boolean widget". */
* @return string html formated hidden input field
* Creates a (non-associative) edit list
* Note that multiple layout types are supported for this widget.
* $this->layout_type must be one of the SMOPT_EDIT_LIST_LAYOUT_*
* @return string html formated list of edit fields and
* their associated controls
//FIXME: $this->aExtraAttribs probably should only be used in one place
$oTemplate->assign('current_value', $this->value);
$oTemplate->assign('select_widget', addSelect('new_' .
$this->name, $this->possible_values, $this->value, FALSE, !checkForJavascript() ?
$this->aExtraAttribs :
array_merge(array('onchange' =>
'if (typeof(window.addinput_' .
$this->name .
') == \'undefined\') { var f = document.forms.length; var i = 0; var pos = -1; while( pos == -1 && i < f ) { var e = document.forms[i].elements.length; var j = 0; while( pos == -1 && j < e ) { if ( document.forms[i].elements[j].type == \'text\' && document.forms[i].elements[j].name == \'add_' .
$this->name .
'\' ) { pos = j; i=f-1; j=e-1; } j++; } i++; } if( pos >= 0 ) { window.addinput_' .
$this->name .
' = document.forms[i-1].elements[pos]; } } for (x = 0; x < this.length; x++) { if (this.options[x].selected) { window.addinput_' .
$this->name .
'.value = this.options[x].text; break; } }'), $this->aExtraAttribs), TRUE, $height));
// NOTE: i=f-1; j=e-1 is in lieu of break 2
$oTemplate->assign('name', $this->name);
return $oTemplate->fetch('edit_list_widget.tpl');
return $oTemplate->fetch('edit_list_widget_list_style.tpl');
* Creates an associative edit list
* Note that multiple layout types are supported for this widget.
* $this->layout_type must be one of the SMOPT_EDIT_LIST_LAYOUT_*
* @return string html formated list of edit fields and
* their associated controls
// ensure correct format of current value(s)
$oTemplate->assign('name', $this->name);
$oTemplate->assign('current_value', $this->value);
//FIXME: $this->aExtraAttribs probably should only be used in one place
$oTemplate->assign('select_height', $height);
return $oTemplate->fetch('edit_list_associative_widget.tpl');
return $oTemplate->fetch('edit_list_associative_widget_list_style.tpl');
* Creates a submit button
* @return string html formated submit button widget
// edit lists have a lot going on, so we'll always process them
} /* End of SquirrelOption class*/
* Saves the option value (this is the default save function
* unless overridden by the user)
* @param object $option object that holds option name and new_value
// Can't save the pref if we don't have the username
// if the widget is a selection list, make sure the new
// value is actually in the selection list and is not an
// all other widgets except TEXTAREAs should never be allowed to have newlines
// edit lists: first add new elements to list, then
// remove any selected ones (note that we must add
// before deleting because the javascript that populates
// the "add" textbox when selecting items in the list
&&
sqGetGlobalVar('add_' .
$option->name, $new_element, SQ_POST)) {
$new_element =
trim($new_element);
// delete selected elements if needed
&&
sqGetGlobalVar('delete_' .
$option->name, $ignore, SQ_POST))
// save full list (stored in "possible_values")
// associative edit lists are handled similar to
$retrieve_key =
sqGetGlobalVar('add_' .
$option->name .
'_key', $new_element_key, SQ_POST);
$retrieve_value =
sqGetGlobalVar('add_' .
$option->name .
'_value', $new_element_value, SQ_POST);
&&
($retrieve_key ||
$retrieve_value)) {
$new_element_key =
trim($new_element_key);
$new_element_value =
trim($new_element_value);
if (!empty($new_element_key) ||
!empty($new_element_value)) {
if (empty($new_element_key)) $new_element_key =
'0';
// delete selected elements if needed
&&
sqGetGlobalVar('delete_' .
$option->name, $ignore, SQ_POST)) {
// save full list (stored in "possible_values")
// Certain option types need to be serialized because
// Checkboxes, when unchecked, don't submit anything in
// the POST, so set to SMPREF_OFF if not found
// For integer fields, make sure we only have digits...
// We'll be nice and instead of just converting to an integer,
// we'll physically remove each non-digit in the string.
// if a checkbox or multi select is zeroed/cleared out, it
// needs to have an empty value pushed into its "new_value" slot
* save function that does not save
* Create hidden 'optpage' input field with value set by argument
* @param string $optpage identification of option page
* @return string html formated hidden input field
* Create hidden 'optmode' input field with value set by argument
* @return string html formated hidden input field
/* Build a simple array with which to start. */
/* Create option group for each option group name. */
foreach ($optgrps as $grpkey =>
$grpname) {
$result[$grpkey] =
array();
$result[$grpkey]['name'] =
$grpname;
$result[$grpkey]['options'] =
array();
/* Create a new SquirrelOption for each set of option values. */
foreach ($optvals as $grpkey =>
$grpopts) {
foreach ($grpopts as $optset) {
/* Create a new option with all values given. */
(isset
($optset['initial_value']) ?
$optset['initial_value'] :
''),
(isset
($optset['posvals']) ?
$optset['posvals'] :
''),
(isset
($optset['htmlencoded']) ?
$optset['htmlencoded'] :
false)
/* If provided, set if the caption is allowed to wrap for this option. */
if (isset
($optset['caption_wrap'])) {
/* If provided, set the size for this option. */
if (isset
($optset['size'])) {
$next_option->setSize($optset['size']);
/* If provided, set the trailing_text for this option. */
if (isset
($optset['trailing_text'])) {
/* If provided, set the trailing_text_small for this option. */
if (isset
($optset['trailing_text_small'])) {
/* If provided, set the trailing_text_is_html for this option. */
if (isset
($optset['trailing_text_is_html'])) {
/* If provided, set the yes_text for this option. */
if (isset
($optset['yes_text'])) {
/* If provided, set the no_text for this option. */
if (isset
($optset['no_text'])) {
/* If provided, set the poss_value_folders value for this option. */
if (isset
($optset['poss_value_folders'])) {
/* If provided, set the layout type for this option. */
if (isset
($optset['layout_type'])) {
/* If provided, set the use_add_widget value for this option. */
if (isset
($optset['use_add_widget'])) {
/* If provided, set the use_delete_widget value for this option. */
if (isset
($optset['use_delete_widget'])) {
/* If provided, set the comment for this option. */
if (isset
($optset['comment'])) {
/* If provided, set the save function for this option. */
if (isset
($optset['save'])) {
/* If provided, set the extra attributes for this option. */
if (isset
($optset['extra_attributes'])) {
/* If provided, set the "post script" for this option. */
if (isset
($optset['post_script'])) {
/* If provided, set the folder_filter for this option. */
if (isset
($optset['folder_filter'])) {
/* Add this option to the option array. */
$result[$grpkey]['options'][] =
$next_option;
/* Return our resulting array. */
Documentation generated on Mon, 13 Jan 2020 04:23:14 +0100 by phpDocumentor 1.4.3