/**
 * Override of the standard options_for_select, that allows the usage of the 'include_zero_custom' option
 * to insert a custom field returning the 0 value on top of the options
 *
 * @return String
 * @author Guglielmo Celata
 **/
function adv_options_for_select($options = array(), $selected = '', $html_options = array())
{
    $html_options = _parse_attributes($html_options);
    if (is_array($selected)) {
        $selected = array_map('strval', array_values($selected));
    }
    $html = '';
    if ($value = _get_option($html_options, 'include_zero_custom')) {
        $html .= content_tag('option', $value, array('value' => '0')) . "\n";
    } else {
        if ($value = _get_option($html_options, 'include_custom')) {
            $html .= content_tag('option', $value, array('value' => '')) . "\n";
        } else {
            if (_get_option($html_options, 'include_blank')) {
                $html .= content_tag('option', '', array('value' => '')) . "\n";
            }
        }
    }
    foreach ($options as $key => $value) {
        if (is_array($value)) {
            $html .= content_tag('optgroup', options_for_select($value, $selected, $html_options), array('label' => $key)) . "\n";
        } else {
            $option_options = array('value' => $key);
            if (is_array($selected) && in_array(strval($key), $selected, true) || strval($key) == strval($selected)) {
                $option_options['selected'] = 'selected';
            }
            $html .= content_tag('option', $value, $option_options) . "\n";
        }
    }
    return $html;
}
function object_enum_tag($object, $method, $options)
{
    $enumValues = _get_option($options, 'enumValues', array());
    $currentValue = _get_object_value($object, $method);
    $enumValues = array_combine($enumValues, $enumValues);
    return select_tag(_convert_method_to_name($method, $options), options_for_select($enumValues, $currentValue), $options);
}
function object_input_auto_complete_tag($object, $method, $options = array(), $default_value = null)
{
    $peer_table = _get_option($options, 'peer_table');
    $peer_field = _get_option($options, 'peer_field');
    $input_name = _convert_method_to_name($method, $options);
    echo input_auto_complete_tag("{$peer_table}_{$peer_field}_search", '', sfContext::getInstance()->getModuleName() . "/autocomplete?table={$peer_table}&field={$peer_field}", array('autocomplete' => 'off'), array('use_style' => true, 'after_update_element' => "function (inputField, selectedItem) { \$('" . get_id_from_name($input_name) . "').value = selectedItem.id; }", 'method' => 'get'));
    echo input_hidden_tag($input_name);
}
    /**
     * Returns the rich text editor as HTML.
     *
     * @return string Rich text editor HTML representation
     */
    public function toHTML()
    {
        $options = $this->options;
        // we need to know the id for things the rich text editor
        // in advance of building the tag
        $id = _get_option($options, 'id', $this->name);
        // use tinymce's gzipped js?
        $tinymce_file = _get_option($options, 'tinymce_gzip') ? '/tiny_mce_gzip.php' : '/tiny_mce.js';
        // tinymce installed?
        // $js_path = sfConfig::get('sf_rich_text_js_dir') ? '/'.sfConfig::get('sf_rich_text_js_dir').$tinymce_file : '/sf/tinymce/js'.$tinymce_file;
        $js_path = sfConfig::get('sf_rich_text_js_dir') ? '/' . sfConfig::get('sf_rich_text_js_dir') . $tinymce_file : '/sf/tinymce/js' . $tinymce_file;
        if (!is_readable(sfConfig::get('sf_web_dir') . $js_path)) {
            throw new sfConfigurationException('You must install TinyMCE to use this helper (see rich_text_js_dir settings).');
        }
        sfContext::getInstance()->getResponse()->addJavascript($js_path);
        use_helper('Javascript');
        $tinymce_options = '';
        $style_selector = '';
        // custom CSS file?
        if ($css_file = _get_option($options, 'css')) {
            $css_path = stylesheet_path($css_file);
            sfContext::getInstance()->getResponse()->addStylesheet($css_path);
            $css = file_get_contents(sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . $css_path);
            $styles = array();
            preg_match_all('#^/\\*\\s*user:\\s*(.+?)\\s*\\*/\\s*\\015?\\012\\s*\\.([^\\s]+)#Smi', $css, $matches, PREG_SET_ORDER);
            foreach ($matches as $match) {
                $styles[] = $match[1] . '=' . $match[2];
            }
            $tinymce_options .= '  content_css: "' . $css_path . '",' . "\n";
            $tinymce_options .= '  theme_advanced_styles: "' . implode(';', $styles) . '"' . "\n";
            $style_selector = 'styleselect,separator,';
        }
        $culture = sfContext::getInstance()->getUser()->getCulture();
        $tinymce_js = '
tinyMCE.init({
  mode: "exact",
  language: "' . strtolower(substr($culture, 0, 2)) . '",
  elements: "' . $id . '",
  plugins: "table,advimage,advlink,flash",
  theme: "advanced",
  theme_advanced_toolbar_location: "top",
  theme_advanced_toolbar_align: "left",
  theme_advanced_path_location: "bottom",
  theme_advanced_buttons1: "' . $style_selector . 'justifyleft,justifycenter,justifyright,justifyfull,separator,bold,italic,strikethrough,separator,sub,sup,separator,charmap",
  theme_advanced_buttons2: "bullist,numlist,separator,outdent,indent,separator,undo,redo,separator,link,unlink,image,flash,separator,cleanup,removeformat,separator,code",
  theme_advanced_buttons3: "tablecontrols",
  extended_valid_elements: "img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name]",
  relative_urls: false,
  debug: false
  ' . ($tinymce_options ? ',' . $tinymce_options : '') . '
  ' . (isset($options['tinymce_options']) ? ',' . $options['tinymce_options'] : '') . '
});';
        if (isset($options['tinymce_options'])) {
            unset($options['tinymce_options']);
        }
        return content_tag('script', javascript_cdata_section($tinymce_js), array('type' => 'text/javascript')) . content_tag('textarea', $this->content, array_merge(array('name' => $this->name, 'id' => get_id_from_name($id, null)), _convert_options($options)));
    }
Beispiel #5
0
/**
 * Returns a link with a gTip (tooltip) attached to it
 *
 * @param string $content content to show inside the a tag (tooltip controller)
 * @param string $content_tip     content to show inside the tooltip if not ajax (tooltip container)
 * @param array  $options   Options of the a link and tooltip
 * 
 * @author Gerald Estadieu <*****@*****.**>
 * @since  15 Apr 2007
 *
 */
function gtip($content, $content_tip = '', $options = array())
{
    _loadRessources();
    $html_options = _parse_attributes($options);
    $html_options['class'] = _get_option($options, 'class', '') . ' gtip';
    $tooltip = '';
    $href = _get_option($options, 'href', '');
    if (isset($options['id'])) {
        $tooltip = content_tag('div', $content_tip, array('id' => $options['id'], 'style' => 'display:none;'));
        unset($html_options['id']);
        $html_options['query_string'] = $options['query_string'] ? 'gtip=' . $options['id'] . '&' . $options['query_string'] : 'gtip=' . $options['id'];
    }
    return link_to($content, $href, $html_options) . $tooltip;
}
/**
 * Returns a <selectize> tag populated with all the languages in the world (or almost).
 *
 * The select_language_tag builds off the traditional select_tag function, and is conveniently populated with
 * all the languages in the world (sorted alphabetically). Each option in the list has a two or three character
 * language/culture code for its value and the language's name as its display title.  The country data is
 * retrieved via the sfCultureInfo class, which stores a wide variety of i18n and i10n settings for various
 * countries and cultures throughout the world. Here's an example of an <option> tag generated by the select_country_tag:
 *
 * <samp>
 *  <option value="en">English</option>
 * </samp>
 *
 * <b>Examples:</b>
 * <code>
 *  echo select_language_tag('language', 'de');
 * </code>
 *
 * @param  string $name     field name
 * @param  string $selected selected field values (two or three-character language/culture code)
 * @param  array  $options  additional HTML compliant <select> tag parameters
 *
 * @return string <selectize> tag populated with all the languages in the world.
 * @see select_tag, options_for_select, sfCultureInfo
 */
function object_multiselect_language_tag($name, $selected = null, $options = array())
{
    $c = new sfCultureInfo(sfContext::getInstance()->getUser()->getCulture());
    $languages = $c->getLanguages();
    if ($language_option = _get_option($options, 'languages')) {
        foreach ($languages as $key => $value) {
            if (!in_array($key, $language_option)) {
                unset($languages[$key]);
            }
        }
    }
    asort($languages);
    $option_tags = options_for_select($languages, $selected, $options);
    unset($options['include_blank'], $options['include_custom']);
    return select_tag($name, $option_tags, $options);
}
 /**
  * Returns the rich text editor as HTML.
  *
  * @return string Rich text editor HTML representation
  */
 public function toHTML()
 {
     $options = $this->options;
     // we need to know the id for things the rich text editor
     // in advance of building the tag
     $id = _get_option($options, 'id', $this->name);
     $php_file = sfConfig::get('sf_rich_text_fck_js_dir') . DIRECTORY_SEPARATOR . 'fckeditor.php';
     if (!is_readable(sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . $php_file)) {
         throw new sfConfigurationException('You must install FCKEditor to use this helper (see rich_text_fck_js_dir settings).');
     }
     // FCKEditor.php class is written with backward compatibility of PHP4.
     // This reportings are to turn off errors with public properties and already declared constructor
     $error_reporting = error_reporting(E_ALL);
     require_once sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . $php_file;
     // turn error reporting back to your settings
     error_reporting($error_reporting);
     $fckeditor = new FCKeditor($this->name);
     $fckeditor->BasePath = sfContext::getInstance()->getRequest()->getRelativeUrlRoot() . '/' . sfConfig::get('sf_rich_text_fck_js_dir') . '/';
     $fckeditor->Value = $this->content;
     if (isset($options['width'])) {
         $fckeditor->Width = $options['width'];
     } elseif (isset($options['cols'])) {
         $fckeditor->Width = (string) ((int) $options['cols'] * 10) . 'px';
     }
     if (isset($options['height'])) {
         $fckeditor->Height = $options['height'];
     } elseif (isset($options['rows'])) {
         $fckeditor->Height = (string) ((int) $options['rows'] * 10) . 'px';
     }
     if (isset($options['tool'])) {
         $fckeditor->ToolbarSet = $options['tool'];
     }
     if (isset($options['config'])) {
         $fckeditor->Config['CustomConfigurationsPath'] = javascript_path($options['config']);
     }
     $content = $fckeditor->CreateHtml();
     if (sfConfig::get('sf_compat_10')) {
         // fix for http://trac.symfony-project.com/ticket/732
         // fields need to be of type text to be picked up by fillin. they are hidden by inline css anyway:
         // <input type="hidden" id="name" name="name" style="display:none" value="&lt;p&gt;default&lt;/p&gt;">
         $content = str_replace('type="hidden"', 'type="text"', $content);
     }
     return $content;
 }
 /**
  * Returns the rich text editor as HTML.
  *
  * @return string Rich text editor HTML representation
  */
 public function toHTML()
 {
     $options = $this->options;
     // we need to know the id for things the rich text editor
     // in advance of building the tag
     $id = _get_option($options, 'id', $this->name);
     $php_file = sfConfig::get('sf_rich_text_fck_js_dir') . DIRECTORY_SEPARATOR . 'fckeditor.php';
     if (!is_readable(sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . $php_file)) {
         throw new sfConfigurationException('You must install FCKEditor to use this helper (see rich_text_fck_js_dir settings).');
     }
     // FCKEditor.php class is written with backward compatibility of PHP4.
     // This reportings are to turn off errors with public properties and already declared constructor
     $error_reporting = ini_get('error_reporting');
     error_reporting(E_ALL);
     require_once sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . $php_file;
     // turn error reporting back to your settings
     error_reporting($error_reporting);
     $fckeditor = new FCKeditor($this->name);
     $fckeditor->BasePath = sfContext::getInstance()->getRequest()->getRelativeUrlRoot() . '/' . sfConfig::get('sf_rich_text_fck_js_dir') . '/';
     $fckeditor->Value = $this->content;
     if (isset($options['width'])) {
         $fckeditor->Width = $options['width'];
     } elseif (isset($options['cols'])) {
         $fckeditor->Width = (string) ((int) $options['cols'] * 10) . 'px';
     }
     if (isset($options['height'])) {
         $fckeditor->Height = $options['height'];
     } elseif (isset($options['rows'])) {
         $fckeditor->Height = (string) ((int) $options['rows'] * 10) . 'px';
     }
     if (isset($options['tool'])) {
         $fckeditor->ToolbarSet = $options['tool'];
     }
     if (isset($options['config'])) {
         $fckeditor->Config['CustomConfigurationsPath'] = javascript_path($options['config']);
     }
     $content = $fckeditor->CreateHtml();
     return $content;
 }
function select_empresas2($name, $option_tags = null, $options = array())
{
    $options = _parse_attributes($options);
    if (!isset($options['control_name'])) {
        $options['control_name'] = 'empresa[id_empresa]';
    }
    if (!isset($options['control_name_tablas'])) {
        $options['control_name_tablas'] = 'tabla[id_tabla]';
    }
    $include_custom = _get_option($options, 'include_custom');
    $include_blank = _get_option($options, 'include_custom') ? 'true' : 'false';
    $param_include_custom = isset($include_custom) && $include_custom != '' ? " + '&include_custom=' + " . $include_custom . "" : null;
    $id_select_empresa = get_id_from_name($options['control_name']);
    $id_select_tablas = get_id_from_name($options['control_name_tablas']);
    $select = select_tag($name, $option_tags, array('control_name' => $options['control_name'], 'onChange' => "recargar_tablas();"));
    $html = $select;
    $html .= "\n";
    $js = "\n  function recargar_tablas()\n  {\n    var empresa = document.getElementById('" . $id_select_empresa . "').value;\n    " . remote_function(array('update' => $id_select_tablas, 'url' => 'empresas/update_select_tablas2', 'with' => "'id_empresa='+empresa + '&include_blank='+ " . $include_blank . "" . $param_include_custom . "")) . "\n  }";
    $html .= content_tag('script', $js, array('type' => 'text/javascript'));
    return $html;
}
function _convert_method_to_name($method, &$options)
{
    $name = _get_option($options, 'control_name');
    if (!$name) {
        if (is_array($method)) {
            $name = implode('-', $method[1]);
        } else {
            $name = sfInflector::underscore($method);
            $name = preg_replace('/^get_?/', '', $name);
        }
    }
    return $name;
}
Beispiel #11
0
/**
 * Returns a <textarea> tag, optionally wrapped with an inline rich-text JavaScript editor.
 *
 * The texarea_tag helper generates a standard HTML <textarea> tag and can be manipulated with
 * any number of standard HTML parameters via the <i>$options</i> array variable.  However, the 
 * textarea tag also has the unique capability of being transformed into a WYSIWYG rich-text editor
 * such as TinyMCE (http://tinymce.moxiecode.com) very easily with the use of some specific options:
 *
 * <b>Options:</b>
 *  - rich: A rich text editor class (for example sfRichTextEditorTinyMCE for TinyMCE).
 *
 * <b>Examples:</b>
 * <code>
 *  echo textarea_tag('notes');
 * </code>
 *
 * <code>
 *  echo textarea_tag('description', 'This is a description', array('rows' => 10, 'cols' => 50));
 * </code> 
 *
 * @param  string $name     field name
 * @param  string $content  populated field value
 * @param  array  $options  additional HTML compliant <textarea> tag parameters
 *
 * @return string <textarea> tag optionally wrapped with a rich-text WYSIWYG editor
 */
function textarea_tag($name, $content = null, $options = array())
{
    $options = _parse_attributes($options);
    if ($size = _get_option($options, 'size')) {
        list($options['cols'], $options['rows']) = explode('x', $size, 2);
    }
    // rich control?
    if ($rich = _get_option($options, 'rich', false)) {
        if (true === $rich) {
            $rich = sfConfig::get('sf_rich_text_editor_class', 'TinyMCE');
        }
        // switch for backward compatibility
        switch ($rich) {
            case 'tinymce':
                $rich = 'TinyMCE';
                break;
            case 'fck':
                $rich = 'FCK';
                break;
        }
        $editorClass = 'sfRichTextEditor' . $rich;
        if (!class_exists($editorClass)) {
            throw new sfConfigurationException(sprintf('The rich text editor "%s" does not exist.', $editorClass));
        }
        $sfEditor = new $editorClass();
        if (!in_array('sfRichTextEditor', class_parents($sfEditor))) {
            throw new sfConfigurationException(sprintf('The editor "%s" must extend sfRichTextEditor.', $editorClass));
        }
        $sfEditor->initialize($name, $content, $options);
        return $sfEditor->toHTML();
    }
    return content_tag('textarea', escape_once(is_object($content) ? $content->__toString() : $content), array_merge(array('name' => $name, 'id' => get_id_from_name(_get_option($options, 'id', $name), null)), _convert_options($options)));
}
Beispiel #12
0
function _get_propel_object_list($object, $method, $options)
{
    // get the lists of objects
    $through_class = _get_option($options, 'through_class');
    $objects = sfPropelManyToMany::getAllObjects($object, $through_class);
    $objects_associated = sfPropelManyToMany::getRelatedObjects($object, $through_class);
    $ids = array_map(create_function('$o', 'return $o->getPrimaryKey();'), $objects_associated);
    return array($objects, $objects_associated, $ids);
}
Beispiel #13
0
/**
 * two multiline select tags with associated and unassociated items
 *
 * @return string
 * @param object object
 * @param string method of object
 * @param array options
 * @param array html options of select tags
 **/
function double_list($object, $method, $options = array(), $html_options = array())
{
    $options = _parse_attributes($options);
    // get the lists of objects
    list($all_objects, $objects_associated, $associated_ids) = _get_object_list($object, $method, _get_option($options, 'through_class'), _get_option($options, 'peer_method'));
    // options
    $html_options['multiple'] = _get_option($html_options, 'multiple', true);
    $html_options['size'] = _get_option($html_options, 'size', 5);
    $html_options['class'] = 'double_list';
    $label_assoc = _get_option($options, 'associated_label', 'Zugeh�rige Gruppen');
    $label_all = _get_option($options, 'unassociated_label', 'Gruppenliste');
    $name1 = _get_option($options, 'associated', 'isSelected');
    $name2 = _get_option($options, 'unassociated', 'unSelected');
    $form = _get_option($options, 'form_id', 'editForm');
    // unassociated objects
    $objects_unassociated = array();
    foreach ($all_objects as $object) {
        if (!in_array($object->getPrimaryKey(), $associated_ids)) {
            $objects_unassociated[] = $object;
        }
    }
    // select tags
    $select1 = select_tag($name1, options_for_select(_get_options_from_objects($objects_associated), '', $options), $html_options);
    unset($html_options['class']);
    $select2 = select_tag($name2, options_for_select(_get_options_from_objects($objects_unassociated), '', $options), $html_options);
    // output skeloton
    $html = "\n<table><tr>\n\t<td class='first'><div class='first' style='padding-bottom:0px;padding-left:15px;'>{$label_assoc}</div>%s</td>\n\t<td class='first'><div class='first' style='padding-bottom:0px;padding-left:15px;'>&nbsp;</div>%s<br/>%s</td>\n\t<td class='first'><div class='first' style='padding-bottom:0px;padding-left:15px;'>{$label_all}</div>%s</td>\n</tr></table>\n";
    // include js library
    $response = sfContext::getInstance()->getResponse();
    $response->addJavascript('/js/double_list.js', 'last');
    return sprintf($html, $select1, link_to_function(image_tag('resultset_previous'), "double_list_move(\$('{$name2}'), \$('{$name1}'))"), link_to_function(image_tag('resultset_next'), "double_list_move(\$('{$name1}'), \$('{$name2}'))", 'style=display:block'), $select2, $form);
}
Beispiel #14
0
/**
 * Returns a variable number of <select> tags populated with date and time related select boxes.
 *
 * The select_datetime_tag is the culmination of both the select_date_tag and the select_time_tag.
 * By default, the <i>$value</i> parameter is set to the current date and time. To override this, simply pass a valid
 * date, time, datetime string or correctly formatted array (see example) to the <i>$value</i> parameter.
 * You can also set the <i>$value</i> parameter to null which will disable the <i>$value</i>, however this
 * will only be useful if you pass 'include_blank' or 'include_custom' to the <i>$options</i> parameter.
 * To include seconds to the result, use set the 'include_second' option in the <i>$options</i> parameter to true.
 * <b>Note:</b> The <i>$name</i> parameter will automatically converted to array names.
 * For example, a <i>$name</i> of "datetime" becomes:
 * <samp>
 *  <select name="datetime[month]">...</select>
 *  <select name="datetime[day]">...</select>
 *  <select name="datetime[year]">...</select>
 *  <select name="datetime[hour]">...</select>
 *  <select name="datetime[minute]">...</select>
 *  <select name="datetime[second]">...</select>
 * </samp>
 *
 * <b>Options:</b>
 * - include_blank     - Includes a blank <option> tag at the beginning of the string with an empty value.
 * - include_custom    - Includes an <option> tag with a custom display title at the beginning of the string with an empty value.
 * - include_second    - If set to true, includes the "seconds" select tag as part of the result.
 * - discard_month     - If set to true, will only return select tags for day and year.
 * - discard_day       - If set to true, will only return select tags for month and year.
 * - discard_year      - If set to true, will only return select tags for month and day.
 * - use_month_numbers - If set to true, will show the month's numerical value (1 - 12) instead of the months full name.
 * - use_short_month   - If set to true, will show the month's short name (i.e. Jan, Feb, Mar) instead of its full name.
 * - year_start        - If set, the range of years will begin at this four-digit date (i.e. 1979)
 * - year_end          - If set, the range of years will end at this four-digit date (i.e. 2025)
 * - second_step       - If set, the seconds will be incremented in blocks of X, where X = 'second_step'
 * - minute_step       - If set, the minutes will be incremented in blocks of X, where X = 'minute_step'
 * - 12hour_time       - If set to true, will return integers 1 through 12 instead of the default 0 through 23.
 * - date_seperator    - Includes a string of defined text between each generated select tag
 * - time_seperator    - Includes a string of defined text between each generated select tag
 * - ampm_seperator    - Includes a string of defined text between the minute/second select box and the AM/PM select box
 *
 * <b>Examples:</b>
 * <code>
 *  echo submit_datetime_tag('datetime');
 * </code>
 *
 * <code>
 *  echo select_datetime_tag('datetime', '1979-10-30');
 * </code>
 *
 * <code>
 *  $datetime = array('year' => '1979', 'month' => 10, 'day' => 30, 'hour' => '15', 'minute' => 46);
 *  echo select_datetime_tag('time', $datetime, array('use_short_month' => true, '12hour_time' => true));
 * </code>
 *
 * @param  string field name (automatically becomes an array of date and time parts)
 * @param  mixed  accepts a valid time string or properly formatted time array
 * @param  array  additional HTML compliant <select> tag parameters
 * @return string a variable number of <select> tags populated with date and time related select boxes
 * @see select date_tag, select_time_tag
 */
function select_datetime_tag($name, $value = null, $options = array(), $html_options = array())
{
    $options = _parse_attributes($options);
    $datetime_seperator = _get_option($options, 'datetime_seperator', '');
    $date = select_date_tag($name, $value, $options, $html_options);
    $time = select_time_tag($name, $value, $options, $html_options);
    return $date . $datetime_seperator . $time;
}
Beispiel #15
0
function _convert_include_custom_for_select($options, &$select_options)
{
    if (_get_option($options, 'include_blank')) {
        $select_options[''] = '';
    } else {
        if ($include_custom = _get_option($options, 'include_custom')) {
            $select_options[''] = $include_custom;
        }
    }
}
Beispiel #16
0
/**
 * Returns a <select> tag populated with all the timezones in the world.
 *
 * The select_timezone_tag builds off the traditional select_tag function, and is conveniently populated with 
 * all the timezones in the world (sorted alphabetically). Each option in the list has a unique timezone identifier 
 * for its value and the timezone's locale as its display title.  The timezone data is retrieved via the sfCultureInfo
 * class, which stores a wide variety of i18n and i10n settings for various countries and cultures throughout the world.
 * Here's an example of an <option> tag generated by the select_timezone_tag:
 *
 * <b>Options:</b>
 * - display - 
 *     identifer         - Display the PHP timezone identifier (e.g. America/Denver)
 *     timezone          - Display the full timezone name (e.g. Mountain Standard Time)
 *     timezone_abbr     - Display the timezone abbreviation (e.g. MST)
 *     timzone_dst       - Display the full timezone name with daylight savings time (e.g. Mountain Daylight Time)
 *     timezone_dst_abbr - Display the timezone abbreviation with daylight savings time (e.g. MDT)
 *     city              - Display the city/region that relates to the timezone (e.g. Denver)
 * 
 * <samp>
 *  <option value="America/Denver">America/Denver</option>
 * </samp>
 *
 * <b>Examples:</b>
 * <code>
 *  echo select_timezone_tag('timezone', 'America/Denver');
 * </code>
 *
 * @param  string $name      field name 
 * @param  string $selected  selected field value (timezone identifier)
 * @param  array  $options   additional HTML compliant <select> tag parameters
 *
 * @return string <select> tag populated with all the timezones in the world.
 * @see select_tag, options_for_select, sfCultureInfo
 */
function select_timezone_tag($name, $selected = null, $options = array())
{
    static $display_keys = array('identifier' => 0, 'timezone' => 1, 'timezone_abbr' => 2, 'timezone_dst' => 3, 'timezone_dst_abbr' => 4, 'city' => 5);
    $display = _get_option($options, 'display', 'identifier');
    $display_key = isset($display_keys[$display]) ? $display_keys[$display] : 0;
    $c = sfCultureInfo::getInstance(sfContext::getInstance()->getUser()->getCulture());
    $timezone_groups = $c->getTimeZones();
    $timezones = array();
    foreach ($timezone_groups as $tz_group) {
        $array_key = isset($tz_group[0]) ? $tz_group[0] : null;
        if (isset($tz_group[$display_key]) and !empty($tz_group[$display_key])) {
            $timezones[$array_key] = $tz_group[$display_key];
        }
    }
    if ($timezone_option = _get_option($options, 'timezones')) {
        $timezones = array_intersect_key($timezones, array_flip((array) $timezone_option));
    }
    // Remove duplicate values
    $timezones = array_unique($timezones);
    asort($timezones);
    $option_tags = options_for_select($timezones, $selected);
    return select_tag($name, $option_tags, $options);
}
Beispiel #17
0
function message_callback()
{
    $message = _get_option('message');
    printf('<input class="regular-text" type="text" name="repo_safety_net_options[message]" id="message" value="%s">', isset($message) ? esc_attr($message) : '');
}
Beispiel #18
0
/**
 * Returns an HTML <form> tag that points to a valid action, route or URL as defined by <i>$url_for_options</i>.
 *
 * By default, the form tag is generated in POST format, but can easily be configured along with any additional
 * HTML parameters via the optional <i>$options</i> parameter. If you are using file uploads, be sure to set the 
 * <i>multipart</i> option to true.
 *
 * Options:
 * - multipart - When set to true, enctype is set to "multipart/form-data".
 *
 * Examples:
 *    echo form_tag('@myroute');
 *    echo form_tag('/module/action', array('name' => 'myformname', 'multipart' => true));
 *
 * @param  string valid action, route or URL
 * @param  array optional HTML parameters for the <form> tag
 * @return string opening HTML <form> tag with options
 */
function form_tag($url_for_options = '', $options = array())
{
    $options = _parse_attributes($options);
    $html_options = $options;
    if (!isset($html_options['method'])) {
        $html_options['method'] = 'post';
    }
    if (_get_option($html_options, 'multipart')) {
        $html_options['enctype'] = 'multipart/form-data';
    }
    $html_options['action'] = url_for($url_for_options);
    return tag('form', $html_options, true);
}
 /**
  * Returns the rich text editor as HTML.
  *
  * @return string Rich text editor HTML representation
  */
 public function toHTML()
 {
     $options = $this->options;
     // we need to know the id for things the rich text editor
     // in advance of building the tag
     $id = _get_option($options, 'id', $this->name);
     // use tinymce's gzipped js?
     $tinymce_file = _get_option($options, 'tinymce_gzip') ? '/tiny_mce_gzip.php' : '/tiny_mce.js';
     // tinymce installed?
     $js_path = sfConfig::get('sf_rich_text_js_dir') ? '/' . sfConfig::get('sf_rich_text_js_dir') . $tinymce_file : '/sf/tinymce/js' . $tinymce_file;
     if (!is_readable(sfConfig::get('sf_web_dir') . $js_path)) {
         throw new sfConfigurationException('You must install TinyMCE to use this helper (see rich_text_js_dir settings).');
     }
     sfContext::getInstance()->getResponse()->addJavascript($js_path);
     use_helper('Javascript');
     $tinymce_options = '';
     $style_selector = '';
     // custom CSS file?
     if ($css_file = _get_option($options, 'css')) {
         $css_path = stylesheet_path($css_file);
         sfContext::getInstance()->getResponse()->addStylesheet($css_path);
         $css = file_get_contents(sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . $css_path);
         $styles = array();
         preg_match_all('#^/\\*\\s*user:\\s*(.+?)\\s*\\*/\\s*\\015?\\012\\s*\\.([^\\s]+)#Smi', $css, $matches, PREG_SET_ORDER);
         foreach ($matches as $match) {
             $styles[] = $match[1] . '=' . $match[2];
         }
         $tinymce_options .= '  content_css: "' . $css_path . '",' . "\n";
         $tinymce_options .= '  theme_advanced_styles: "' . implode(';', $styles) . '"' . "\n";
         $style_selector = 'styleselect,separator,';
     }
     $config = sfConfig::get('sf_config_dir_name');
     $path = sfConfigCache::getInstance()->checkConfig($config . DIRECTORY_SEPARATOR . 'tiny_mce.yml');
     $config = sfYaml::load($path);
     $culture = isset($config['culture']) ? $config['culture'] : sfContext::getInstance()->getUser()->getCulture();
     $mode = $config['options']['mode'];
     $plugins = implode(',', $config['options']['plugins']);
     $theme = $config['options']['theme'];
     $tbLocation = $config['options']['theme_settings']['theme_' . $theme . '_toolbar_location'];
     $tbAlign = $config['options']['theme_settings']['theme_' . $theme . '_toolbar_align'];
     $pathLocation = $config['options']['theme_settings']['theme_' . $theme . '_path_location'];
     $buttons = array();
     reset($config['options']['theme_settings']['buttons']);
     while (($key = key($config['options']['theme_settings']['buttons'])) !== null) {
         $current = current($config['options']['theme_settings']['buttons']);
         $buttons[] = $key . ': "' . implode(',', $current) . '"';
         next($config['options']['theme_settings']['buttons']);
     }
     $buttons = implode(",\n", $buttons);
     $extendedValidElements = array();
     reset($config['options']['theme_settings']['extended_valid_elements']);
     while (($key = key($config['options']['theme_settings']['extended_valid_elements'])) !== null) {
         $current = current($config['options']['theme_settings']['extended_valid_elements']);
         $extendedValidElements[] = $key . '[' . implode('|', $current) . ']';
         next($config['options']['theme_settings']['extended_valid_elements']);
     }
     $extendedValidElements = '"' . implode(",\n", $extendedValidElements) . '"';
     $relativeUrls = $config['options']['relative_urls'] ? 'true' : 'false';
     $debug = $config['options']['debug'] ? 'true' : 'false';
     $tinymce_js = 'tinyMCE.init({';
     // Mode
     $tinymce_js .= "mode: '{$mode}'";
     // Language
     $tinymce_js .= ', language: "' . strtolower(substr($culture, 0, 2)) . '"';
     // Elements
     $tinymce_js .= ', elements: "' . $id . '"';
     // Plugins
     if ($plugins) {
         $tinymce_js .= ', plugins: "' . $plugins . '"';
     }
     // Theme
     $tinymce_js .= ", theme: '{$theme}'";
     // Toolbar
     $tinymce_js .= ', theme_' . $theme . '_toolbar_location: "' . $tbLocation . '"';
     $tinymce_js .= ', theme_' . $theme . '_toolbar_align: "' . $tbAlign . '"';
     $tinymce_js .= ', theme_' . $theme . '_path_location: "' . $pathLocation . '"';
     // Buttons
     if ($buttons) {
         $tinymce_js .= ', ' . $buttons;
     }
     // Extended Valid Elements
     $tinymce_js .= ', extended_valid_elements: ' . $extendedValidElements;
     // Relative Urls
     $tinymce_js .= ', relative_urls: ' . $relativeUrls;
     // Debug
     $tinymce_js .= ', debug: ' . $debug;
     // Custom Options
     $tinymce_js .= $tinymce_options ? ',' . $tinymce_options : '';
     $tinymce_js .= isset($options['tinymce_options']) ? ',' . $options['tinymce_options'] : '';
     if (isset($config['options']['misc'])) {
         foreach ($config['options']['misc'] as $name => $value) {
             $tinymce_js .= ", {$name}: \"{$value}\"";
         }
     }
     if (isset($options['tinymce_options'])) {
         unset($options['tinymce_options']);
     }
     $tinymce_js .= '});';
     return content_tag('script', javascript_cdata_section($tinymce_js), array('type' => 'text/javascript')) . content_tag('textarea', $this->content, array_merge(array('name' => $this->name, 'id' => get_id_from_name($id, null)), _convert_options($options)));
 }
function _convert_method_to_name($method, &$options)
{
    $name = _get_option($options, 'control_name');
    if (!$name) {
        $name = sfInflector::underscore($method);
        $name = preg_replace('/^get_?/', '', $name);
    }
    return $name;
}
function my_input_date_tag($name, $value = null, $options = array(), $html_options = array())
{
    $options = _parse_attributes($options);
    $context = sfContext::getInstance();
    $culture = _get_option($options, 'culture', $context->getUser()->getCulture());
    // set it back for month tag
    $options['culture'] = $culture;
    $I18n_arr = _get_I18n_date_locales($culture);
    $date_seperator = _get_option($options, 'date_seperator', $I18n_arr['date_seperator']);
    $include_blank_month = array('include_blank' => _get_option($options, 'include_blank_month', false));
    $include_blank_day = array('include_blank' => _get_option($options, 'include_blank_day', false));
    $include_blank_year = array('include_blank' => _get_option($options, 'include_blank_year', false));
    $order = _get_option($options, 'order');
    $tags = array();
    if (is_array($order) && count($order) == 3) {
        foreach ($order as $v) {
            $tags[] = $v[0];
        }
    } else {
        $tags = $I18n_arr['date_order'];
    }
    $month_name = $name . '[month]';
    $m = select_month_tag($month_name, _parse_value_for_date($value, 'month', 'm'), $options + $include_blank_month, $html_options);
    $day_name = $name . '[day]';
    $d = select_day_tag($day_name, _parse_value_for_date($value, 'day', 'd'), $options + $include_blank_day, $html_options);
    $year_name = $name . '[year]';
    $y = select_year_tag($year_name, _parse_value_for_date($value, 'year', 'Y'), $options + $include_blank_year, $html_options);
    // we have $tags = array ('m','d','y')
    foreach ($tags as $k => $v) {
        // $tags['m|d|y'] = $m|$d|$y
        $tags[$k] = ${$v};
    }
    return implode($date_seperator, $tags);
}
Beispiel #22
0
/**
 * If the condition passed as first argument is true,
 * creates a <a> link tag of the given name using a routed URL
 * based on the module/action passed as argument and the routing configuration.
 * If the condition is false, the given name is returned between <span> tags
 *
 * <b>Options:</b>
 * - 'tag' - the HTML tag that must enclose the name if the condition is false, defaults to <span>
 * - 'absolute' - if set to true, the helper outputs an absolute URL
 * - 'query_string' - to append a query string (starting by ?) to the routed url
 * - 'anchor' - to append an anchor (starting by #) to the routed url
 * - 'confirm' - displays a javascript confirmation alert when the link is clicked
 * - 'popup' - if set to true, the link opens a new browser window
 * - 'post' - if set to true, the link submits a POST request instead of GET (caution: do not use inside a form)
 *
 * <b>Examples:</b>
 * <code>
 *  echo link_to_if($user->isAdministrator(), 'Delete this page', 'my_module/my_action');
 *    => <a href="/path/to/my/action">Delete this page</a>
 *  echo link_to_if(!$user->isAdministrator(), 'Delete this page', 'my_module/my_action');
 *    => <span>Delete this page</span>
 * </code>
 *
 * @param  bool   $condition     condition
 * @param  string $name          name of the link, i.e. string to appear between the <a> tags
 * @param  string $internal_uri  'module/action' or '@rule' of the action
 * @param  array  $options       additional HTML compliant <a> tag parameters
 * @return string XHTML compliant <a href> tag or name
 * @see    link_to
 */
function link_to_if($condition, $name = '', $internal_uri = '', $options = array())
{
    $html_options = _parse_attributes($options);
    if ($condition) {
        unset($html_options['tag']);
        return link_to($name, $internal_uri, $html_options);
    } else {
        unset($html_options['query_string']);
        unset($html_options['absolute_url']);
        unset($html_options['absolute']);
        $tag = _get_option($html_options, 'tag', 'span');
        return content_tag($tag, $name, $html_options);
    }
}
 /**
  * Iterates through and renders a collection of objects, each wrapped with
  * its own editable_content_tag.
  *
  * The advantage of using this method instead of manually iterating through
  * a collection and using editable_content_tag() is that this method adds
  * collection-specific functionality such as "Add new" and sortable.
  *
  * @param string $outer_tag The tag that should surround the whole collection (e.g. ul)
  * @param mixed $collection The Doctrine_Collection to iterate and render
  * @param array $options    An array of options to configure the outer tag
  * @param string $inner_tag The tag to render around each item (@see editable_content_tag)
  * @param mixed $fields     The field or fields to render and edit for each item (@see editable_content_tag)
  * @param array $inner_options Option on each internal editable_content_tag (@see editable_content_tag)
  *
  * @return string
  */
 public function getEditableContentList($outer_tag, Doctrine_Collection $collection, $attributes, $inner_tag, $fields, $inner_attributes)
 {
     // extract the option values, remove from the attributes array
     $options = array();
     foreach ($this->_validListOptions as $validOption) {
         if (isset($attributes[$validOption])) {
             $options[$validOption] = _get_option($attributes, $validOption);
         }
     }
     // pass the special with_delete option to the inner attributes
     $inner_attributes['with_delete'] = _get_option($options, 'with_delete');
     // start decking out the classes on the outer tag
     $classes = isset($attributes['class']) ? explode(' ', $attributes['class']) : array();
     if ($this->shouldShowEditor($collection)) {
         $classes[] = json_encode($options);
         $classes[] = $this->getOption('editable_list_class_name', 'io_editable_content_list');
     }
     if (count($classes)) {
         $attributes['class'] = implode(' ', $classes);
     }
     // create a new object of the given model
     $class = $collection->getTable()->getClassNameToReturn();
     $new = new $class();
     /*
      * Begin rendering the content - this is a refactor of the previous
      * _list.php partial
      */
     $content = '';
     foreach ($collection as $object) {
         $content .= $this->getEditableContentTag($inner_tag, $object, $fields, $inner_attributes);
     }
     // add the empty/new item so the js has something to build from
     if ($this->shouldShowEditor($collection)) {
         $empty_attributes = $inner_attributes;
         if (isset($empty_attributes['class'])) {
             $empty_attributes['class'] = $empty_attributes['class'] . ' io_new_tag';
         } else {
             $empty_attributes['class'] = 'io_new_tag';
         }
         $content .= $this->getEditableContentTag($inner_tag, $new, $fields, $empty_attributes);
     }
     // actually render the outer tag
     $content = content_tag($outer_tag, $content, $attributes);
     return $content;
 }
Beispiel #24
0
$t->is(tag('br', 'class=foo', false), '<br class="foo" />', 'tag() takes a string of options as its second parameters');
$t->is(tag('p', array('class' => 'foo', 'id' => 'bar'), true), '<p class="foo" id="bar">', 'tag() takes a boolean parameter as its third parameter');
//$t->is(tag('br', array('class' => '"foo"')), '<br class="&quot;foo&quot;" />');
// content_tag()
$t->diag('content_tag()');
$t->is(content_tag(''), '', 'content_tag() returns an empty string with empty input');
$t->is(content_tag('', ''), '', 'content_tag() returns an empty string with empty input');
$t->is(content_tag('p', 'Toto'), '<p>Toto</p>', 'content_tag() takes a content as its second parameter');
$t->is(content_tag('p', ''), '<p></p>', 'content_tag() takes a tag as its first parameter');
// cdata_section()
$t->diag('cdata_section()');
$t->is(cdata_section(''), '<![CDATA[]]>', 'cdata_section() returns a string wrapped into a CDATA section');
$t->is(cdata_section('foobar'), '<![CDATA[foobar]]>', 'cdata_section() returns a string wrapped into a CDATA section');
// escape_javascript()
$t->diag('escape_javascript()');
$t->is(escape_javascript("alert('foo');\nalert(\"bar\");"), 'alert(\\\'foo\\\');\\nalert(\\"bar\\");', 'escape_javascript() escapes JavaScript scripts');
// _get_option()
$t->diag('_get_option()');
$options = array('foo' => 'bar', 'bar' => 'foo');
$t->is(_get_option($options, 'foo'), 'bar', '_get_option() returns the value for the given key');
$t->ok(!isset($options['foo']), '_get_option() removes the key from the original array');
$t->is(_get_option($options, 'nofoo', 'nobar'), 'nobar', '_get_option() returns the default value if the key does not exist');
// escape_once()
$t->diag('escape_once()');
$t->is(escape_once('This a > text to "escape"'), 'This a &gt; text to &quot;escape&quot;', 'escape_once() escapes an HTML strings');
$t->is(escape_once(escape_once('This a > text to "escape"')), 'This a &gt; text to &quot;escape&quot;', 'escape_once() does not escape an already escaped string');
$t->is(escape_once('This a &gt; text to "escape"'), 'This a &gt; text to &quot;escape&quot;', 'escape_once() does not escape an already escaped string');
$t->is(escape_once("This a &gt; \"text\" to 'escape'"), "This a &gt; &quot;text&quot; to 'escape'", 'escape_once() does not escape simple quotes but escape double quotes');
// fix_double_escape()
$t->diag('fix_double_escape()');
$t->is(fix_double_escape(htmlspecialchars(htmlspecialchars('This a > text to "escape"'), ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8'), 'This a &gt; text to &quot;escape&quot;', 'fix_double_escape() fixes double escaped strings');
Beispiel #25
0
/**
 * If the condition passed as first argument is true,
 * creates a <a> link tag of the given name using a routed URL
 * based on the module/action passed as argument and the routing configuration.
 * If the condition is false, the given name is returned between <span> tags
 *
 * <b>Options:</b>
 * - 'tag' - the HTML tag that must enclose the name if the condition is false, defaults to <span>
 * - 'absolute' - if set to true, the helper outputs an absolute URL
 * - 'query_string' - to append a query string (starting by ?) to the routed url
 * - 'confirm' - displays a javascript confirmation alert when the link is clicked
 * - 'popup' - if set to true, the link opens a new browser window 
 * - 'post' - if set to true, the link submits a POST request instead of GET (caution: do not use inside a form)
 *
 * <b>Examples:</b>
 * <code>
 *  echo link_to_if($user->isAdministrator(), 'Delete this page', 'my_module/my_action');
 *    => <a href="/path/to/my/action">Delete this page</a>
 *  echo link_to_if(!$user->isAdministrator(), 'Delete this page', 'my_module/my_action'); 
 *    => <span>Delete this page</span>
 * </code>
 *
 * @param  bool condition
 * @param  string name of the link, i.e. string to appear between the <a> tags
 * @param  string 'module/action' or '@rule' of the action
 * @param  array additional HTML compliant <a> tag parameters
 * @return string XHTML compliant <a href> tag or name
 * @see    link_to
 */
function link_to_if($condition, $name = '', $internal_uri = '', $options = array())
{
    if ($condition) {
        return link_to($name, $internal_uri, $options);
    } else {
        $html_options = _parse_attributes($options);
        $tag = _get_option($html_options, 'tag', 'span');
        return content_tag($tag, $name, $html_options);
    }
}
Beispiel #26
0
/**
 * Returns an HTML <form> tag that points to a valid action, route or URL as defined by <i>$url_for_options</i>.
 *
 * By default, the form tag is generated in POST format, but can easily be configured along with any additional
 * HTML parameters via the optional <i>$options</i> parameter. If you are using file uploads, be sure to set the 
 * <i>multipart</i> option to true.
 *
 * <b>Options:</b>
 * - multipart - When set to true, enctype is set to "multipart/form-data".
 *
 * <b>Examples:</b>
 *   <code><?php echo form_tag('@myroute'); ?></code>
 *   <code><?php echo form_tag('/module/action', array('name' => 'myformname', 'multipart' => true)); ?></code>
 *
 * @param  string $url_for_options  valid action, route or URL
 * @param  array  $options          optional HTML parameters for the <form> tag
 *
 * @return string opening HTML <form> tag with options
 */
function form_tag($url_for_options = '', $options = array())
{
    $options = _parse_attributes($options);
    $html_options = $options;
    $html_options['method'] = isset($html_options['method']) ? strtolower($html_options['method']) : 'post';
    if (_get_option($html_options, 'multipart')) {
        $html_options['enctype'] = 'multipart/form-data';
    }
    $html_options['action'] = url_for($url_for_options);
    $html = '';
    if (!in_array($html_options['method'], array('get', 'post'))) {
        $html = tag('input', array('type' => 'hidden', 'name' => 'sf_method', 'value' => $html_options['method']));
        $html_options['method'] = 'post';
    }
    return tag('form', $html_options, true) . $html;
}
Beispiel #27
0
/**
 * If the condition passed as first argument is true,
 * creates a <a> link tag of the given name using a routed URL
 * based on the module/action passed as argument and the routing configuration.
 * If the condition is false, the given name is returned between <span> tags
 *
 * <b>Options:</b>
 * - 'tag' - the HTML tag that must enclose the name if the condition is false, defaults to <span>
 * - 'absolute' - if set to true, the helper outputs an absolute URL
 * - 'query_string' - to append a query string (starting by ?) to the routed url
 * - 'anchor' - to append an anchor (starting by #) to the routed url
 * - 'confirm' - displays a javascript confirmation alert when the link is clicked
 * - 'popup' - if set to true, the link opens a new browser window 
 * - 'post' - if set to true, the link submits a POST request instead of GET (caution: do not use inside a form)
 *
 * <b>Examples:</b>
 * <code>
 *  echo link_to_if($user->isAdministrator(), 'Delete this page', 'my_module/my_action');
 *    => <a href="/path/to/my/action">Delete this page</a>
 *  echo link_to_if(!$user->isAdministrator(), 'Delete this page', 'my_module/my_action'); 
 *    => <span>Delete this page</span>
 * </code>
 *
 * @param  bool   $condition     condition
 * @param  string $name          name of the link, i.e. string to appear between the <a> tags
 * @param  string $internal_uri  'module/action' or '@rule' of the action
 * @param  array  $options       additional HTML compliant <a> tag parameters
 *
 * @return string XHTML compliant <a href> tag or name
 *
 * @see    link_to
 */
function link_to_if()
{
    $arguments = func_get_args();
    if (empty($arguments[2]) || '@' == substr($arguments[2], 0, 1) || false !== strpos($arguments[2], '/')) {
        list($condition, $name, $params, $options) = array_pad($arguments, 4, null);
    } else {
        list($condition, $name, $routeName, $params, $options) = array_pad($arguments, 5, null);
        $params = array_merge(array('sf_route' => $routeName), is_object($params) ? array('sf_subject' => $params) : (array) $params);
    }
    $html_options = _parse_attributes($options);
    if ($condition) {
        unset($html_options['tag']);
        return link_to1($name, $params, $html_options);
    } else {
        unset($html_options['query_string']);
        unset($html_options['absolute_url']);
        unset($html_options['absolute']);
        $tag = _get_option($html_options, 'tag', 'span');
        return content_tag($tag, $name, $html_options);
    }
}
/**
 * Returns a <select> tag populated with all the timezones in the world.
 *
 * The select_timezone_tag builds off the traditional select_tag function, and is conveniently populated with 
 * all the timezones in the world (sorted alphabetically). Each option in the list has a unique timezone identifier 
 * for its value and the timezone's locale as its display title.  The timezone data is retrieved via the sfCultureInfo
 * class, which stores a wide variety of i18n and i10n settings for various countries and cultures throughout the world.
 * Here's an example of an <option> tag generated by the select_timezone_tag:
 *
 * <b>Options:</b>
 * - display - 
 *     identifer         - Display the PHP timezone identifier (e.g. America/Denver)
 *     timezone          - Display the full timezone name (e.g. Mountain Standard Time)
 *     timezone_abbr     - Display the timezone abbreviation (e.g. MST)
 *     timzone_dst       - Display the full timezone name with daylight savings time (e.g. Mountain Daylight Time)
 *     timezone_dst_abbr - Display the timezone abbreviation with daylight savings time (e.g. MDT)
 *     city              - Display the city/region that relates to the timezone (e.g. Denver)
 * 
 * <samp>
 *  <option value="America/Denver">America/Denver</option>
 * </samp>
 *
 * <b>Examples:</b>
 * <code>
 *  echo select_timezone_tag('timezone', 'America/Denver');
 * </code>
 *
 * @param  string field name 
 * @param  string selected field value (timezone identifier)
 * @param  array  additional HTML compliant <select> tag parameters
 * @return string <select> tag populated with all the timezones in the world.
 * @see select_tag, options_for_select, sfCultureInfo
 */
function select_timezone_tag($name, $selected = null, $options = array())
{
    if (!isset($options['display'])) {
        $options['display'] = 'identifier';
    }
    $c = new sfCultureInfo(sfContext::getInstance()->getUser()->getCulture());
    $timezone_groups = $c->getTimeZones();
    $display_key = 0;
    switch ($options['display']) {
        case "identifier":
            $display_key = 0;
            break;
        case "timezone":
            $display_key = 1;
            break;
        case "timezone_abbr":
            $display_key = 2;
            break;
        case "timezone_dst":
            $display_key = 3;
            break;
        case "timezone_dst_abbr":
            $display_key = 4;
            break;
        case "city":
            $display_key = 5;
            break;
        default:
            $display_key = 0;
            break;
    }
    unset($options['display']);
    $timezones = array();
    foreach ($timezone_groups as $tz_group_key => $tz_group) {
        $array_key = null;
        foreach ($tz_group as $tz_key => $tz) {
            if ($tz_key == 0) {
                $array_key = $tz;
            }
            if ($tz_key == $display_key and !empty($tz)) {
                $timezones[$array_key] = $tz;
            }
        }
    }
    if ($timezone_option = _get_option($options, 'timezones')) {
        $diff = array_diff_key($timezones, array_flip((array) $timezone_option));
        foreach ($diff as $key => $v) {
            unset($timezones[$key]);
        }
    }
    // Remove duplicate values
    $timezones = array_unique($timezones);
    asort($timezones);
    $option_tags = options_for_select($timezones, $selected);
    return select_tag($name, $option_tags, $options);
}
/**
 * This function is similar to option_for_select from symfony, except that it allows you
 * to specify a class for the options (which is class_prefix+value)
 */
function options_with_classes_for_select($options = array(), $selected = '', $html_options = array(), $class_prefix = '')
{
    $html_options = _parse_attributes($html_options);
    if (is_array($selected)) {
        $selected = array_map('strval', array_values($selected));
    }
    $html = '';
    if ($value = _get_option($html_options, 'include_custom')) {
        $html .= content_tag('option', $value, array('value' => '')) . "\n";
    } else {
        if (_get_option($html_options, 'include_blank')) {
            $html .= content_tag('option', '', array('value' => '')) . "\n";
        }
    }
    foreach ($options as $key => $value) {
        if (is_array($value)) {
            $html .= content_tag('optgroup', options_with_classes_for_select($value, $selected, $html_options), array('label' => $key), $class_prefix) . "\n";
        } else {
            $option_options = array('value' => $key);
            if (!empty($class_prefix)) {
                $tmp = explode('/', $key, 2);
                $suffix = $tmp[0];
                $option_options['class'] = $class_prefix . $suffix;
            }
            if (is_array($selected) && in_array(strval($key), $selected, true) || !is_array($selected) && strval($key) == strval($selected)) {
                $option_options['selected'] = 'selected';
            }
            $html .= content_tag('option', $value, $option_options) . "\n";
        }
    }
    return $html;
}