Changeset 106 for trunk/trax/vendor/trax/action_view
- Timestamp:
- 01/01/06 21:37:32 (6 years ago)
- Location:
- trunk/trax/vendor/trax/action_view
- Files:
-
- 3 added
- 3 modified
-
helpers.php (modified) (4 diffs)
-
helpers/active_record_helper.php (added)
-
helpers/date_helper.php (added)
-
helpers/form_helper.php (modified) (4 diffs)
-
helpers/form_tag_helper.php (added)
-
helpers/url_helper.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/action_view/helpers.php
r99 r106 36 36 $html = array(); 37 37 foreach($options as $key => $value) { 38 $html[] = "$key=\"". htmlspecialchars($value, ENT_QUOTES)."\"";38 $html[] = "$key=\"".@htmlspecialchars($value, ENT_QUOTES)."\""; 39 39 } 40 40 sort($html); … … 44 44 } 45 45 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" /> 49 50 function tag($name, $options = array(), $open = false) { 50 51 $html = "<$name "; … … 54 55 } 55 56 56 # Example s: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> 60 61 function content_tag($name, $content, $options = array()) { 61 62 $html .= "<$name "; … … 65 66 } 66 67 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 113 function content_tag() { 114 $helper = new Helpers(); 115 $args = func_get_args(); 116 return call_user_func_array(array($helper, 'content_tag'), $args); 67 117 } 68 118 -
trunk/trax/vendor/trax/action_view/helpers/form_helper.php
r102 r106 26 26 class FormHelper extends Helpers { 27 27 28 function __construct($object_name, $ field_name) {28 function __construct($object_name, $attribute_name) { 29 29 parent::__construct(); 30 30 $this->object_name = $object_name; 31 $this-> field_name = $field_name;31 $this->attribute_name = $attribute_name; 32 32 $this->default_field_options = $GLOBALS['DEFAULT_FIELD_OPTIONS'] ? $GLOBALS['DEFAULT_FIELD_OPTIONS'] : array("size" => 30); 33 33 $this->default_radio_options = $GLOBALS['DEFAULT_RADIO_OPTIONS'] ? $GLOBALS['DEFAULT_RADIO_OPTIONS'] : array(); … … 37 37 38 38 function value() { 39 if(!$value = $_REQUEST[$this->object_name][$this-> field_name]) {39 if(!$value = $_REQUEST[$this->object_name][$this->attribute_name]) { 40 40 $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); 43 43 } 44 44 } 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; 50 50 return $this->controller_object->$object_name; 51 51 } 52 52 53 53 function tag_name() { 54 return "{$this->object_name}[{$this-> field_name}]";54 return "{$this->object_name}[{$this->attribute_name}]"; 55 55 } 56 56 57 57 function tag_name_with_index($index) { 58 return "{$this->object_name}[{$index}][{$this-> field_name}]";58 return "{$this->object_name}[{$index}][{$this->attribute_name}]"; 59 59 } 60 60 61 61 function tag_id() { 62 return "{$this->object_name}_{$this-> field_name}";62 return "{$this->object_name}_{$this->attribute_name}"; 63 63 } 64 64 65 65 function tag_id_with_index($index) { 66 return "{$this->object_name}_{$index}_{$this-> field_name}";66 return "{$this->object_name}_{$index}_{$this->attribute_name}"; 67 67 } 68 68 … … 106 106 $pretty_tag_value = preg_replace('/\s/', "_", preg_replace('/\W/', "", strtolower($tag_value))); 107 107 $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}"; 110 110 $options = $this->add_default_name_and_id($options); 111 111 return $this->tag("input", $options); … … 242 242 # <input type="radio" id="post_category" name="post[category] value="trax" checked="checked" /> 243 243 # <input type="radio" id="post_category" name="post[category] value="java" /> 244 #245 244 function radio_button($object, $field, $tag_value, $options = array()) { 246 245 $form = new FormHelper($object, $field); -
trunk/trax/vendor/trax/action_view/helpers/url_helper.php
r99 r106 63 63 } 64 64 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 102 65 function convert_confirm_option_to_javascript($html_options) { 103 66 if($html_options['confirm']) { … … 106 69 } 107 70 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); 108 130 } 109 131 … … 118 140 } 119 141 142 function url_for($options = array()) { 143 $url_helper = new UrlHelper(); 144 return $url_helper->url_for($options); 145 } 120 146 121 147 ?>
