Exemplo n.º 1
0
 function _tag_options($options)
 {
     $formated_options = array();
     foreach ($options as $key=>$value){
         if(empty($value) && !is_string($value)){
             continue;
         }
         if(!is_numeric($key) && !is_array($value) && !is_object($value)){
             $formated_options[$key] =  $key.'="'.TagHelper::escape_once($value).'"';
         }
     }
     ksort($formated_options);
     return empty($formated_options) ? '' : ' '.join(' ',$formated_options);
 }
Exemplo n.º 2
0
    /**
    * Generates a form containing a sole button that submits to the
    * URL given by _$options_.  Use this method instead of +link_to+
    * for actions that do not have the safe HTTP GET semantics
    * implied by using a hypertext link.
    *
    * The parameters are the same as for +link_to+.  Any _html_options_
    * that you pass will be applied to the inner +input+ element.
    * In particular, pass
    * 
    *   'disabled' => true/false
    *
    * as part of _html_options_ to control whether the button is
    * disabled.  The generated form element is given the class
    * 'button-to', to which you can attach CSS styles for display
    * purposes.
    *
    * Example 1:
    *
    *   // inside of controller for "feeds"
    *   $url_helper->button_to('Edit', array('action' => 'edit', 'id' => 3));
    *
    * Generates the following HTML (sans formatting):
    *
    *   <form method="post" action="/feeds/edit/3" class="button-to">
    *     <div><input type="submit" value="Edit"  /></div>
    *   </form>
    *
    * Example 2:
    *
    *   $url_helper->button_to('Destroy', array('action' => 'destroy', 'id' => 3 , 'confirm' => 'Are you sure?'));
    *
    * Generates the following HTML (sans formatting):
    *
    *   <form method="post" action="/feeds/destroy/3" class="button-to">
    *     <div><input onclick="return confirm('Are you sure?');" value="Destroy" type="submit" /></div>
    *   </form>
    *
    * Note: This method generates HTML code that represents a form.
    * Forms are "block" content, which means that you should not try to
    * insert them into your HTML where only inline content is expected.
    * For example, you can legally insert a form inside of a <div> or
    * <td> element or in between <p> elements, but not in the middle of
    * a run of text, nor can you place a form within another form.
    * (Bottom line: Always validate your HTML before going public.)
    */
    function button_to($name, $options = array(), $html_options = array())
    {
        $html_options = $this->_convert_boolean_attributes($html_options, 'disabled');

        if(!empty($html_options['confirm'])){
            $html_options['onclick'] = 'return '.$this->_confirm_javascript_function($html_options['confirm']).';';
            unset($html_options['confirm']);
        }

        $url = is_string($options) ? $options : $this->url_for($options);

        $name = !empty($name) ? $name : (is_string($options) ?  $options : TagHelper::escape_once($this->url_for($options)));

        $html_options = array_merge($html_options,array('type'=>'submit','value'=>$name));
        return '<form method="post" action="'.$url.'" class="button-to"><div>'.
        TagHelper::tag('input', $html_options) . '</div></form>';
    }
Exemplo n.º 3
0
 function to_text_area_tag($options = array())
 {
     $options = array_merge($this->default_text_area_options, $options);
     $this->add_default_name_and_id($options);
     return TagHelper::content_tag('textarea', TagHelper::escape_once($this->value_before_type_cast()), $options);
 }
Exemplo n.º 4
0
 public function test_for_not_double_escaping_entities()
 {
     $this->assertEqual(TagHelper::escape_once("1 > 2 &amp; 3"), "1 &gt; 2 &amp; 3");
 }
Exemplo n.º 5
0
 /**
  * Generate a list of <option> tags from an array, using the array keys as
  * the value attributes, and the corresponding array values as the labels.
  *
  * If arrays are nested, an <optgroup> tag will be generated using the array
  * key as its label, and containing <option> tags for each element of the
  * nested array.
  *
  * @param array $choices Set of $value=>$label choices
  * @param mixed $selected Single value or array of values that indicate keys of
  *                        options to mark as selected.
  * @return string Set of <option> tags
  */
 public static function options_for_select($choices, $selected = null)
 {
     $selected_reversed = array_flip(array_map('strval', array_values((array) $selected)));
     $option_tags = '';
     foreach ($choices as $key => $value) {
         if (is_array($value)) {
             $option_tags .= TagHelper::content_tag('optgroup', self::options_for_select($value, $selected), array('label' => $key)) . "\n";
         } else {
             $html_attributes = array('value' => $key);
             if (isset($selected_reversed[strval($key)])) {
                 $html_attributes['selected'] = 'selected';
             }
             $option_tags .= TagHelper::content_tag('option', TagHelper::escape_once($value), $html_attributes) . "\n";
         }
     }
     return $option_tags;
 }