Show
Ignore:
Timestamp:
01/01/06 21:37:32 (6 years ago)
Author:
john
Message:

added a bunch of stuff for scaffolding

Location:
trunk/trax/vendor/trax/action_view
Files:
3 added
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/trax/vendor/trax/action_view/helpers.php

    r99 r106  
    3636            $html = array(); 
    3737            foreach($options as $key => $value) { 
    38                 $html[] = "$key=\"".htmlspecialchars($value, ENT_QUOTES)."\""; 
     38                $html[] = "$key=\"".@htmlspecialchars($value, ENT_QUOTES)."\""; 
    3939            } 
    4040            sort($html); 
     
    4444    } 
    4545 
    46     # Examples: 
    47     # tag("br") => <br /> 
    48     # tag("input", array("type" => "text")) => <input type="text" /> 
     46    # Example: tag("br"); 
     47    # Results: <br /> 
     48    # Example: tag("input", array("type" => "text")); 
     49    # <input type="text" /> 
    4950    function tag($name, $options = array(), $open = false) { 
    5051        $html = "<$name "; 
     
    5455    } 
    5556 
    56     # Examples: 
    57     # content_tag("p", "Hello world!") => <p>Hello world!</p> 
    58     # content_tag("div", content_tag("p", "Hello world!"), array("class" => "strong")) => 
    59     # <div class="strong"><p>Hello world!</p></div> 
     57    # Example: content_tag("p", "Hello world!"); 
     58    # Result: <p>Hello world!</p> 
     59    # Example: content_tag("div", content_tag("p", "Hello world!"), array("class" => "strong")) => 
     60    # Result:<div class="strong"><p>Hello world!</p></div> 
    6061    function content_tag($name, $content, $options = array()) { 
    6162        $html .= "<$name "; 
     
    6566    } 
    6667 
     68    # Returns the URL for the set of $options provided. 
     69    function url_for($options = array()) { 
     70        $url_base = null; 
     71        $url = array(); 
     72        if(is_string($options)) { 
     73            $url[] = $options; 
     74        } else { 
     75            if($_SERVER['SERVER_PORT'] == 443) { 
     76                $url_base = "https://".$_SERVER['HTTP_HOST']; 
     77            } else { 
     78                $url_base = "http://".$_SERVER['HTTP_HOST']; 
     79            } 
     80            if(array_key_exists(":controller", $options)) { 
     81                if($controller = $options[":controller"]) { 
     82                    if(stristr($this->controller_path, $controller)) { 
     83                        $url[] = $this->controller_path; 
     84                    } else { 
     85                        $url[] = $controller; 
     86                    } 
     87                } 
     88            } else { 
     89                $url[] = $this->controller_path; 
     90            } 
     91            if(array_key_exists(":action", $options)) { 
     92                if($action = $options[":action"]) { 
     93                    $url[] = $action; 
     94                } 
     95            } 
     96            if(array_key_exists(":id", $options)) { 
     97                if(is_object($options[":id"])) { 
     98                    if($id = $options[":id"]->id) { 
     99                        $url[] = $id; 
     100                    } 
     101                } else { 
     102                    if($id = $options[":id"]) { 
     103                        $url[] = $id; 
     104                    } 
     105                } 
     106            } 
     107        } 
     108        return $url_base . implode("/", $url); 
     109    } 
     110 
     111} 
     112 
     113function content_tag() { 
     114    $helper = new Helpers(); 
     115    $args = func_get_args(); 
     116    return call_user_func_array(array($helper, 'content_tag'), $args); 
    67117} 
    68118 
  • trunk/trax/vendor/trax/action_view/helpers/form_helper.php

    r102 r106  
    2626class FormHelper extends Helpers { 
    2727 
    28     function __construct($object_name, $field_name) { 
     28    function __construct($object_name, $attribute_name) { 
    2929        parent::__construct(); 
    3030        $this->object_name = $object_name; 
    31         $this->field_name = $field_name; 
     31        $this->attribute_name = $attribute_name; 
    3232        $this->default_field_options = $GLOBALS['DEFAULT_FIELD_OPTIONS'] ? $GLOBALS['DEFAULT_FIELD_OPTIONS'] : array("size" => 30); 
    3333        $this->default_radio_options = $GLOBALS['DEFAULT_RADIO_OPTIONS'] ? $GLOBALS['DEFAULT_RADIO_OPTIONS'] : array(); 
     
    3737 
    3838    function value() { 
    39         if(!$value = $_REQUEST[$this->object_name][$this->field_name]) { 
     39        if(!$value = $_REQUEST[$this->object_name][$this->attribute_name]) { 
    4040            $object = $this->object(); 
    41             if(is_object($object) && $this->field_name) { 
    42                 $value = $object->send($this->field_name); 
     41            if(is_object($object) && $this->attribute_name) { 
     42                $value = $object->send($this->attribute_name); 
    4343            } 
    4444        } 
    45         return $value;  
    46     } 
    47  
    48     function object() { 
    49         $object_name = $this->object_name; 
     45        return $value; 
     46    } 
     47 
     48    function object($object_name = null) { 
     49        $object_name = $object_name ? $object_name : $this->object_name; 
    5050        return $this->controller_object->$object_name; 
    5151    } 
    5252 
    5353    function tag_name() { 
    54         return "{$this->object_name}[{$this->field_name}]"; 
     54        return "{$this->object_name}[{$this->attribute_name}]"; 
    5555    } 
    5656 
    5757    function tag_name_with_index($index) { 
    58         return "{$this->object_name}[{$index}][{$this->field_name}]"; 
     58        return "{$this->object_name}[{$index}][{$this->attribute_name}]"; 
    5959    } 
    6060 
    6161    function tag_id() { 
    62         return "{$this->object_name}_{$this->field_name}"; 
     62        return "{$this->object_name}_{$this->attribute_name}"; 
    6363    } 
    6464 
    6565    function tag_id_with_index($index) { 
    66         return "{$this->object_name}_{$index}_{$this->field_name}"; 
     66        return "{$this->object_name}_{$index}_{$this->attribute_name}"; 
    6767    } 
    6868 
     
    106106        $pretty_tag_value = preg_replace('/\s/', "_", preg_replace('/\W/', "", strtolower($tag_value))); 
    107107        $options["id"] = $this->auto_index ? 
    108             "{$this->object_name}_{$this->auto_index}_{$this->field_name}_{$pretty_tag_value}" : 
    109             "{$this->object_name}_{$this->field_name}_{$pretty_tag_value}"; 
     108            "{$this->object_name}_{$this->auto_index}_{$this->attribute_name}_{$pretty_tag_value}" : 
     109            "{$this->object_name}_{$this->attribute_name}_{$pretty_tag_value}"; 
    110110        $options = $this->add_default_name_and_id($options); 
    111111        return $this->tag("input", $options); 
     
    242242#     <input type="radio" id="post_category" name="post[category] value="trax" checked="checked" /> 
    243243#     <input type="radio" id="post_category" name="post[category] value="java" /> 
    244 # 
    245244function radio_button($object, $field, $tag_value, $options = array()) { 
    246245    $form = new FormHelper($object, $field); 
  • trunk/trax/vendor/trax/action_view/helpers/url_helper.php

    r99 r106  
    6363    } 
    6464 
    65     # Returns the URL for the set of +options+ provided. 
    66     function url_for($options = array()) { 
    67         $url_base = null; 
    68         $url = array(); 
    69         if(is_string($options)) { 
    70             $url[] = $options; 
    71         } else { 
    72             if($_SERVER['SERVER_PORT'] == 443) { 
    73                 $url_base = "https://".$_SERVER['HTTP_HOST']; 
    74             } else { 
    75                 $url_base = "http://".$_SERVER['HTTP_HOST']; 
    76             } 
    77             if(array_key_exists(":controller", $options)) { 
    78                 if($controller = $options[":controller"]) { 
    79                     if(stristr($this->controller_path, $controller)) { 
    80                         $url[] = $this->controller_path; 
    81                     } else { 
    82                         $url[] = $controller; 
    83                     } 
    84                 } 
    85             } else { 
    86                 $url[] = $this->controller_path; 
    87             } 
    88             if(array_key_exists(":action", $options)) { 
    89                 if($action = $options[":action"]) { 
    90                     $url[] = $action; 
    91                 } 
    92             } 
    93             if(array_key_exists(":id", $options)) { 
    94                 if($id = $options[":id"]) { 
    95                     $url[] = $id; 
    96                 } 
    97             } 
    98         } 
    99         return $url_base . implode("/", $url); 
    100     } 
    101  
    10265    function convert_confirm_option_to_javascript($html_options) { 
    10366        if($html_options['confirm']) { 
     
    10669        } 
    10770        return $html_options; 
     71    } 
     72 
     73    function convert_boolean_attributes(&$html_options, $bool_attrs) { 
     74        foreach($bool_attrs as $x) { 
     75            if(in_array($x, $html_options)) { 
     76                $html_options[$x] = $x; 
     77                unset($html_options[$x]); 
     78            } 
     79        } 
     80        return $html_options; 
     81    } 
     82 
     83    function button_to($name, $options = array(), $html_options = null) { 
     84        $html_options = (!is_null($html_options) ? $html_options : array()); 
     85        $this->convert_boolean_attributes($html_options, array($disabled)); 
     86        $this->convert_confirm_option_to_javascript($html_options); 
     87        if (is_string($options)) { 
     88            $url = $options; 
     89            $name = (!is_null($name) ? $name : $options); 
     90        } else { 
     91            $url = url_for($options); 
     92            $name = (!is_null($name) ? $name : $this->url_for($options)); 
     93        } 
     94 
     95        $html_options = array_merge($html_options, array("type" => "submit", "value" => $name)); 
     96        return "<form method=\"post\" action=\"" .  htmlspecialchars($url) . "\" class=\"button-to\"><div>" . 
     97            $this->tag("input", $html_options) . "</div></form>"; 
     98    } 
     99 
     100    # This tag is deprecated. Combine the link_to and AssetTagHelper::image_tag yourself instead, like: 
     101    #   link_to(image_tag("rss", :size => "30x45", :border => 0), "http://www.example.com") 
     102    function link_image_to($src, $options = array(), $html_options = array(), $parameters_for_method_reference = array()) { 
     103        $image_options = array("src" => (ereg("/", $src) ? $src : "/images/$src")); 
     104        if (!ereg(".", $image_options["src"])) $image_options["src"] .= ".png"; 
     105 
     106        if (isset($html_options["alt"])) { 
     107            $image_options["alt"] = $html_options["alt"]; 
     108            unset($html_options["alt"]); 
     109        } else { 
     110            $image_options["alt"] = ucfirst(end(explode("/", $src))); 
     111        } 
     112 
     113        if (isset($html_options["size"])) { 
     114            $image_options["width"]  = current(explode("x", $html_options["size"])); 
     115            $image_options["height"] = end(explode("x", $html_options["size"])); 
     116            unset($html_options["size"]); 
     117        } 
     118 
     119        if (isset($html_options["border"])) { 
     120            $image_options["border"] = $html_options["border"]; 
     121            unset($html_options["border"]); 
     122        } 
     123 
     124        if (isset($html_options["align"])) { 
     125            $image_options["align"] = $html_options["align"]; 
     126            unset($html_options["align"]); 
     127        } 
     128 
     129        return $this->link_to($this->tag("img", $image_options), $options, $html_options, $parameters_for_method_reference); 
    108130    } 
    109131 
     
    118140} 
    119141 
     142function url_for($options = array()) { 
     143    $url_helper = new UrlHelper(); 
     144    return $url_helper->url_for($options); 
     145} 
    120146 
    121147?>