Changeset 199 for trunk/trax/vendor/trax/action_view
- Timestamp:
- 05/04/06 19:52:43 (6 years ago)
- Location:
- trunk/trax/vendor/trax/action_view
- Files:
-
- 9 modified
-
helpers.php (modified) (1 prop)
-
helpers/active_record_helper.php (modified) (1 diff, 1 prop)
-
helpers/asset_tag_helper.php (modified) (13 diffs, 1 prop)
-
helpers/date_helper.php (modified) (7 diffs, 1 prop)
-
helpers/form_helper.php (modified) (1 prop)
-
helpers/form_options_helper.php (modified) (1 prop)
-
helpers/form_tag_helper.php (modified) (1 prop)
-
helpers/javascript_helper.php (modified) (1 prop)
-
helpers/url_helper.php (modified) (14 diffs, 1 prop)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/action_view/helpers.php
- Property svn:keywords set to Id
-
trunk/trax/vendor/trax/action_view/helpers/active_record_helper.php
- Property svn:keywords set to Id
r198 r199 204 204 * @todo Document this method 205 205 * @uses scaffolding 206 * @uses input_scaffolding() 206 207 */ 207 208 function default_input_block() { -
trunk/trax/vendor/trax/action_view/helpers/asset_tag_helper.php
- Property svn:keywords set to Id
r196 r199 30 30 31 31 /** 32 * @todo Document this class32 * Utility to help build HTML/XML link tags for public assets 33 33 */ 34 34 class AssetTagHelper extends Helpers { 35 35 36 36 /** 37 * @var string[] 38 */ 39 var $javascript_default_sources = null; 40 41 /** 37 42 * @todo Document this method 38 43 * 44 * @uses javascript_default_sources 39 45 */ 40 46 function __construct() { 41 47 parent::__construct(); 42 $this->javascript_default_sources = $GLOBALS['JAVASCRIPT_DEFAULT_SOURCES'] ? $GLOBALS['JAVASCRIPT_DEFAULT_SOURCES'] : array('prototype', 'effects', 'dragdrop', 'controls'); 43 } 44 45 /** 46 * @todo Document this method 47 * 48 $this->javascript_default_sources = 49 array_key_exists('JAVASCRIPT_DEFAULT_SOURCES',$GLOBALS) 50 ? $GLOBALS['JAVASCRIPT_DEFAULT_SOURCES'] 51 : array('prototype', 'effects', 'dragdrop', 'controls'); 52 } 53 54 /** 55 * Compute public path to an asset 56 * 57 * Build the public path, suitable for inclusion in a URL, to an 58 * asset. Arguments are the filename, directory and extension of 59 * the asset. 60 * @param string Filename of asset 61 * @param string Default directory name, if none in $source 62 * @param string Default file extension, if none in $source 63 * @return string Public path to the asset 64 * @uses controller_object 65 * @uses ActionController::asset_host 48 66 */ 49 67 private function compute_public_path($source, $dir, $ext) { 68 69 // Test whether source is a URL, ie. starts something:// 50 70 if(!preg_match('/^[-a-z]+:\/\//', $source)) { 71 72 // Source is not a URL. 73 // If path doesn't start with '/', prefix /$dir/ 51 74 if($source{0} != '/') { 52 75 $source = "/{$dir}/{$source}"; 53 76 } 77 78 // If no '.' in source file name, add '.ext' 54 79 if(!strstr($source, '.')) { 55 80 $source = "{$source}.{$ext}"; 56 81 } 82 83 // If TRAX_URL_PREFIX non-null, prefix it to path 57 84 if(!is_null(TRAX_URL_PREFIX)) { 58 85 $prefix = TRAX_URL_PREFIX; … … 60 87 $prefix = "/$prefix"; 61 88 } 62 $source = $prefix . ((substr($prefix, -1) == "/") ? substr($source, 1) : $source); 89 $source = $prefix . ((substr($prefix, -1) == "/") 90 ? substr($source, 1) : $source); 63 91 } 64 92 } 65 return $this->controller_object->asset_host . $source; 66 } 67 68 /** 69 * Returns path to a javascript asset. Example: 70 * 71 * javascript_path "xmlhr" # => /javascripts/xmlhr.js 93 94 // If controller defined and has asset_host value 95 // prefix that to path 96 // FIXME: won't this cause a problem if $source was http://...? 97 if ( isset($this->controller_object) 98 && isset($this->controller_object->asset_host) ) { 99 $source = $this->controller_object->asset_host . $source; 100 } 101 return $source; 102 } 103 104 /** 105 * Compute public path to a javascript asset 106 * 107 * Build the public path, suitable for inclusion in a URL, to a 108 * javascript asset. Argument is the filename of the asset. 109 * Default directory to 'javascripts', extension to '.js' 110 * @param string Filename of asset, in one of the formats 111 * accepted as the $filename argument of 112 * {@link compute_public_path()} 113 * @return string Public path to the javascript asset 114 * @uses compute_public_path() 72 115 */ 73 116 function javascript_path($source) { … … 76 119 77 120 /** 78 * Returns a script include tag per source given as argument. Examples:79 * 80 * javascript_include_tag("xmlhr") #=>121 * Return script include tag for one or more javascript assets 122 * 123 * javascript_include_tag("xmlhr"); => 81 124 * <script type="text/javascript" src="/javascripts/xmlhr.js"></script> 82 125 * 83 * javascript_include_tag("common.javascript", "/elsewhere/cools") #=>126 * javascript_include_tag("common.javascript", "/elsewhere/cools"); => 84 127 * <script type="text/javascript" src="/javascripts/common.javascript"></script> 85 128 * <script type="text/javascript" src="/elsewhere/cools.js"></script> 86 129 * 87 * javascript_include_tag("defaults") #=>130 * javascript_include_tag("defaults"); => 88 131 * <script type="text/javascript" src="/javascripts/prototype.js"></script> 89 132 * <script type="text/javascript" src="/javascripts/effects.js"></script> 90 133 * <script type="text/javascript" src="/javascripts/controls.js"></script> 91 134 * <script type="text/javascript" src="/javascripts/dragdrop.js"></script> 135 * @param mixed The arguments are zero or more strings, followed 136 * by an optional array containing options 137 * @return string 138 * @uses content_tag() 139 * @uses javascript_default_sources 140 * @uses javascript_path() 92 141 */ 93 142 function javascript_include_tag() { 94 143 if(func_num_args() > 0) { 95 144 $sources = func_get_args(); 96 $options = (is_array(end($sources)) ? array_pop($sources) : array()); 145 $options = (is_array(end($sources)) 146 ? array_pop($sources) : array()); 97 147 if(in_array('defaults', $sources)) { 98 148 if(is_array($this->javascript_default_sources)) { 99 $sources = array_merge($this->javascript_default_sources, $sources); 149 $sources = array_merge($this->javascript_default_sources, 150 $sources); 100 151 } 101 152 if(file_exists(TRAX_PUBLIC. "/javascripts/application.js")) { … … 108 159 foreach($sources as $source) { 109 160 $source = $this->javascript_path($source); 110 $contents[] = $this->content_tag("script", "", array_merge(array("type" => "text/javascript", "src" => $source), $options)); 161 $contents[] = $this->content_tag("script", "", 162 array_merge(array("type" => "text/javascript", 163 "src" => $source), $options)); 111 164 } 112 165 return implode("", $contents); … … 115 168 116 169 /** 117 * Returns path to a stylesheet asset. Example: 118 * 119 * stylesheet_path("style") # => /stylesheets/style.css 170 * Compute public path to a stylesheet asset 171 * 172 * Build the public path, suitable for inclusion in a URL, to a 173 * stylesheet asset. Argument is the filename of the asset. 174 * Default directory to 'stylesheets', extension to '.css' 175 * @param string Filename of asset, in one of the formats 176 * accepted as the $filename argument of 177 * {@link compute_public_path()} 178 * @return string Public path to the stylesheet asset 120 179 * @uses compute_public_path() 121 180 */ 122 181 function stylesheet_path($source) { 123 return $this->compute_public_path($source, 'stylesheets', 'css'); #should be stylesheets 124 } 125 126 /** 127 * Returns a css link tag per source given as argument. 128 * 129 * Examples: 130 * 131 * stylesheet_link_tag("style") # => 132 * <link href="/stylesheets/style.css" media="screen" rel="Stylesheet" type="text/css" /> 133 * 134 * stylesheet_link_tag("style", array("media" => "all")) # => 135 * <link href="/stylesheets/style.css" media="all" rel="Stylesheet" type="text/css" /> 136 * 137 * stylesheet_link_tag("random.styles", "/css/stylish") # => 138 * <link href="/stylesheets/random.styles" media="screen" rel="Stylesheet" type="text/css" /> 139 * <link href="/css/stylish.css" media="screen" rel="Stylesheet" type="text/css" /> 182 return $this->compute_public_path($source, 'stylesheets', 'css'); 183 } 184 185 /** 186 * Build link tags to one or more stylesheet assets 187 * 188 * @param mixed One or more assets, optionally followed by an 189 * array describing options to apply to the tags 190 * generated for these assets.<br> Each asset is a 191 * string in one of the formats accepted as value 192 * of the $source argument of 193 * {@link stylesheet_path()}.<br> The optional last 194 * argument is an array whose keys are names of 195 * attributes of the link tag and whose corresponding 196 * values are the values assigned to each 197 * attribute. If omitted, options default to: 198 * <ul> 199 * <li>"rel" => "Stylesheet"</li> 200 * <li>"type" => "text/css"</li> 201 * <li>"media" => "screen"</li> 202 * <li>"href" => <i>path-to-source</i></li> 203 * </ul> 204 * @return string A link tag for each asset in the argument list 140 205 * @uses stylesheet_path() 141 206 * @uses tag() … … 144 209 if(func_num_args() > 0) { 145 210 $sources = func_get_args(); 146 $options = (is_array(end($sources)) ? array_pop($sources) : array()); 211 $options = (is_array(end($sources)) 212 ? array_pop($sources) : array()); 147 213 $contents = array(); 148 214 foreach($sources as $source) { 149 215 $source = $this->stylesheet_path($source); 150 $contents[] = $this->tag("link", array_merge(array("rel" => "Stylesheet", "type" => "text/css", "media" => "screen", "href" => $source), $options)); 216 $contents[] = $this->tag("link", 217 array_merge(array("rel" => "Stylesheet", 218 "type" => "text/css", 219 "media" => "screen", 220 "href" => $source), $options)); 151 221 } 152 222 return implode("", $contents); … … 155 225 156 226 /** 157 * Returns path to an image asset. Example: 158 * 159 * The src can be supplied as a... 160 * * full path, like "/my_images/image.gif" 161 * * file name, like "rss.gif", that gets expanded to "/images/rss.gif" 162 * * file name without extension, like "logo", that gets expanded to "/images/logo.png" 163 * @uses compute_public_path 227 * Compute public path to a image asset 228 * 229 * Build the public path, suitable for inclusion in a URL, to a 230 * image asset. Argument is the filename of the asset. 231 * Default directory to 'images', extension to '.png' 232 * @param string Filename of asset, in one of the formats 233 * accepted as the $filename argument of 234 * {@link compute_public_path()} 235 * @return string Public path to the image asset 236 * @uses compute_public_path() 164 237 */ 165 238 function image_path($source) { 166 return $this->compute_public_path($source, 'images', 'png'); #should be images 167 } 168 169 /** 170 * Returns an image tag converting the $options instead html options on the tag, but with these special cases: 171 * 172 * * <tt>:alt</tt> - If no alt text is given, the file name part of the src is used (capitalized and without the extension) 173 * * <tt>:size</tt> - Supplied as "XxY", so "30x45" becomes width="30" and height="45" 174 * 175 * The src can be supplied as a... 176 * * full path, like "/my_images/image.gif" 177 * * file name, like "rss.gif", that gets expanded to "/images/rss.gif" 178 * * file name without extension, like "logo", that gets expanded to "/images/logo.png" 179 * @uses Inflector::capitalize() 239 return $this->compute_public_path($source, 'images', 'png'); 240 } 241 242 /** 243 * Build image tags to an image asset 244 * 245 * @param mixed An image asset optionally followed by an 246 * array describing options to apply to the tag 247 * generated for this asset.<br>The asset is a 248 * string in one of the formats accepted as value 249 * of the $source argument of 250 * {@link image_path()}.<br> The optional second 251 * argument is an array whose keys are names of 252 * attributes of the image tag and whose corresponding 253 * values are the values assigned to each 254 * attribute. The image size can be specified in 255 * two ways: by specifying option values "width" => 256 * <i>width</i> and "height" => <i>height</i>, or 257 * by specifying option "size" => "<i>width</i> 258 * x <i>height</i>". If omitted, options default to: 259 * <ul> 260 * <li>"alt" => <i>humanized filename</i></li> 261 * <li>"width" and "height" value computed from 262 * value of "size"</li> 263 * </ul> 264 * @return string A image tag for each asset in the argument list 180 265 * @uses image_path() 181 266 * @uses tag() … … 183 268 function image_tag($source, $options = array()) { 184 269 $options['src'] = $this->image_path($source); 185 $options['alt'] = $options['alt'] ? $options['alt'] : Inflector::capitalize(reset($file_array = explode('.', basename($options['src'])))); 186 270 $options['alt'] = array_key_exists('alt',$options) 271 ? $options['alt'] 272 : Inflector::capitalize(reset($file_array = 273 explode('.', basename($options['src'])))); 187 274 if(isset($options['size'])) { 188 275 $size = explode('x', $options["size"]); … … 191 278 unset($options['size']); 192 279 } 193 194 280 return $this->tag("img", $options); 195 281 } 196 282 197 283 /** 198 * Returns a link tag that browsers and news readers can use to auto-detect a RSS or ATOM feed for this page. The $type can 199 * either be <tt>:rss</tt> (default) or <tt>:atom</tt> and the $options follow the url_for() style of declaring a link target. 200 * 201 * Examples: 202 * auto_discovery_link_tag # => 203 * <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.curenthost.com/controller/action" /> 204 * auto_discovery_link_tag(:atom) # => 205 * <link rel="alternate" type="application/atom+xml" title="ATOM" href="http://www.curenthost.com/controller/action" /> 206 * auto_discovery_link_tag(:rss, {:action => "feed"}) # => 207 * <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.curenthost.com/controller/feed" /> 208 * auto_discovery_link_tag(:rss, {:action => "feed"}, {:title => "My RSS"}) # => 209 * <link rel="alternate" type="application/rss+xml" title="My RSS" href="http://www.curenthost.com/controller/feed" /> 210 * @uses tag() 211 */ 212 function auto_discovery_link_tag($type = 'rss', $options = array(), $tag_options = array()) { 284 * Returns a link tag that browsers and news readers can use to 285 * auto-detect a RSS or ATOM feed for this page. The $type can 286 * either be <tt>:rss</tt> (default) or <tt>:atom</tt> and the 287 * $options follow the url_for() style of declaring a link 288 * target. 289 * 290 * Examples: 291 * auto_discovery_link_tag => 292 * <link rel="alternate" type="application/rss+xml" title="RSS" 293 * href="http://www.curenthost.com/controller/action" /> 294 * auto_discovery_link_tag(:atom) => 295 * <link rel="alternate" type="application/atom+xml" 296 * title="ATOM" 297 * href="http://www.curenthost.com/controller/action" /> 298 * auto_discovery_link_tag(:rss, {:action => "feed"}) => 299 * <link rel="alternate" type="application/rss+xml" title="RSS" 300 * href="http://www.curenthost.com/controller/feed" /> 301 * auto_discovery_link_tag(:rss, {:action => "feed"}, {:title => 302 * "My RSS"}) => 303 * <link rel="alternate" type="application/rss+xml" title="My 304 * RSS" href="http://www.curenthost.com/controller/feed" /> 305 * @uses tag() 306 * @uses url_for() 307 */ 308 function auto_discovery_link_tag($type = 'rss', $options = array(), 309 $tag_options = array()) { 213 310 return $this->tag( 214 311 "link", array( 215 "rel" => ($tag_options['rel'] ? $tag_options['rel'] : "alternate"), 216 "type" => ($tag_options['type'] ? $tag_options['type'] : "application/{$type}+xml"), 217 "title" => ($tag_options['title'] ? $tag_options['title'] : strtoupper($type)), 218 "href" => url_for(array_merge($options, array('only_path' => false)))) 219 ); 312 "rel" => (array_key_exists('rel',$tag_options) 313 ? $tag_options['rel'] : "alternate"), 314 "type" => (array_key_exists('type',$tag_options) 315 ? $tag_options['type'] 316 : "application/{$type}+xml"), 317 "title" => (array_key_exists('title',$tag_options) 318 ? $tag_options['title'] 319 : strtoupper($type)), 320 "href" => url_for(array_merge($options, 321 array('only_path' => false)))) 322 ); 220 323 } 221 324 } 222 325 223 224 /** 225 * @todo Document this method 226 * Avialble functions for use in views 227 * auto_discovery_link_tag($type = 'rss', $options = array(), $tag_options = array()) 326 /** 327 * Make a new AssetTagHelper object and call its auto_discovery_link_tag() method 228 328 * @uses AssetTagHelper::auto_discovery_link_tag() 229 329 */ … … 231 331 $asset_helper = new AssetTagHelper(); 232 332 $args = func_get_args(); 233 return call_user_func_array(array($asset_helper, 'auto_discovery_link_tag'), $args);234 } 235 236 /** 237 * @todo Document this method 238 * image_tag($source, $options = array())333 return call_user_func_array(array($asset_helper, 334 'auto_discovery_link_tag'), $args); 335 } 336 337 /** 338 * Make a new AssetTagHelper object and call its image_tag() method 239 339 * @uses AssetTagHelper::image_tag() 240 340 */ … … 246 346 247 347 /** 248 * @todo Document this method 249 * stylesheet_link_tag($sources) 348 * Make a new AssetTagHelper object and call its stylesheet_link_tag() method 250 349 * @uses AssetTagHelper::stylesheet_link_tag() 251 350 */ … … 253 352 $asset_helper = new AssetTagHelper(); 254 353 $args = func_get_args(); 255 return call_user_func_array(array($asset_helper, 'stylesheet_link_tag'), $args);256 } 257 258 /** 259 * @todo Document this method 260 * javascript_include_tag($sources)354 return call_user_func_array(array($asset_helper, 355 'stylesheet_link_tag'), $args); 356 } 357 358 /** 359 * Make a new AssetTagHelper object and call its javascript_include_tag() method 261 360 * @uses AssetTagHelper::javascript_include_tag() 262 361 */ … … 264 363 $asset_helper = new AssetTagHelper(); 265 364 $args = func_get_args(); 266 return call_user_func_array(array($asset_helper, 'javascript_include_tag'), $args); 365 return call_user_func_array(array($asset_helper, 366 'javascript_include_tag'), $args); 267 367 } 268 368 -
trunk/trax/vendor/trax/action_view/helpers/date_helper.php
- Property svn:keywords set to Id
r198 r199 343 343 * @param mixed[] Output format options: 344 344 * <ul> 345 * <li><samp>'field_sep erator' => '</samp><i>somestring</i><samp>'</samp><br />345 * <li><samp>'field_separator' => '</samp><i>somestring</i><samp>'</samp><br /> 346 346 * String to insert between the month and year selectors. If 347 347 * none is specified, default value is <samp>' / '</samp></li> … … 372 372 $options['start_year'] = date("Y"); 373 373 $options['end_year'] = date("Y") + 7; 374 $options['field_sep erator'] = " / ";374 $options['field_separator'] = " / "; 375 375 376 376 // Find name and initial value of year field, … … 396 396 // Output month and year selectors in desired order 397 397 if($options['month_before_year']) { 398 $select_html = $month_select . $options['field_sep erator']398 $select_html = $month_select . $options['field_separator'] 399 399 . $year_select; 400 400 } else { 401 $select_html = $year_select . $options['field_sep erator']401 $select_html = $year_select . $options['field_separator'] 402 402 . $month_select; 403 403 } … … 1143 1143 * <li><samp>'discard_year' => true</samp> Don't show a year 1144 1144 * menu. If absent or false, year menu will be output.</li> 1145 * <li><samp>'field_sep erator' => '</samp><i>string</i><samp>'</samp>1145 * <li><samp>'field_separator' => '</samp><i>string</i><samp>'</samp> 1146 1146 * String to insert between the submenus in the output. If 1147 1147 * absent, one blank will be inserted.</li> … … 1171 1171 // . " attribute='$this->attribute_name'"); 1172 1172 // error_log("options=".var_export($options,true)); 1173 1174 // Handle historically misspelled options 1175 if (array_key_exists('field_seperator', $options)) { 1176 $options['field_separator'] = $options['field_seperator']; 1177 unset($options['field_seperator']); 1178 } 1173 1179 $defaults = array('discard_type' => true); 1174 1180 $options = array_merge($defaults, $options); … … 1241 1247 // (default blank) 1242 1248 if(count($date_select)) { 1243 $sep erator = array_key_exists('field_seperator',$options)1244 ? $options['field_sep erator'] : " ";1245 $date_select = implode($sep erator, $date_select);1249 $separator = array_key_exists('field_separator',$options) 1250 ? $options['field_separator'] : " "; 1251 $date_select = implode($separator, $date_select); 1246 1252 } 1247 1253 … … 1392 1398 $options['start_year'] = date("Y"); 1393 1399 $options['end_year'] = date("Y") + 7; 1394 $options['field_sep erator'] = " / ";1400 $options['field_separator'] = " / "; 1395 1401 return $this->to_date_select_tag($options); 1396 1402 } -
trunk/trax/vendor/trax/action_view/helpers/form_helper.php
- Property svn:keywords set to Id
-
trunk/trax/vendor/trax/action_view/helpers/form_options_helper.php
- Property svn:keywords set to Id
-
trunk/trax/vendor/trax/action_view/helpers/form_tag_helper.php
- Property svn:keywords set to Id
-
trunk/trax/vendor/trax/action_view/helpers/javascript_helper.php
- Property svn:keywords set to Id
-
trunk/trax/vendor/trax/action_view/helpers/url_helper.php
- Property svn:keywords set to Id
r196 r199 31 31 /** 32 32 * @todo Document this class 33 * @package PHPonTrax34 33 */ 35 34 class UrlHelper extends Helpers { 36 35 37 36 /** 38 * Creates a link tag of the given +name+ using an URL created by the set of +options+. 39 * It's also possible to pass a string instead of an options hash to 40 * get a link tag that just points without consideration. If null is passed as a name, the link itself will become the name. 41 * The $html_options have a special feature for creating javascript confirm alerts where if you pass ":confirm" => 'Are you sure?', 42 * the link will be guarded with a JS popup asking that question. If the user accepts, the link is processed, otherwise not. 37 * Creates a link tag of the given +name+ using an URL created by 38 * the set of +options+. 39 * It's also possible to pass a string instead of an options hash 40 * to get a link tag that just points without consideration. If 41 * null is passed as a name, the link itself will become the 42 * name. 43 * The $html_options have a special feature for creating 44 * javascript confirm alerts where if you pass ":confirm" => 'Are 45 * you sure?', 46 * the link will be guarded with a JS popup asking that 47 * question. If the user accepts, the link is processed, otherwise 48 * not. 43 49 * 44 50 * Example: 45 * link_to("Delete this page", array(":action" => "delete", ":id" => $page->id), array(":confirm" => "Are you sure?")) 51 * link_to("Delete this page", array(":action" => "delete", 52 * ":id" => $page->id), array(":confirm" => "Are you sure?")) 53 * @return string 54 * @uses content_tag() 55 * @uses convert_confirm_option_to_javascript() 56 * @uses url_for() 46 57 */ 47 58 function link_to($name, $options = array(), $html_options = array()) { 48 $html_options = $this->convert_confirm_option_to_javascript($html_options); 59 $html_options = 60 $this->convert_confirm_option_to_javascript($html_options); 49 61 if(is_string($options)) { 50 62 $href = array("href" => $options); … … 90 102 /** 91 103 * @todo Document this method 104 * @param mixed[] 105 * @param mixed[] 106 * @return mixed[] 92 107 */ 93 108 function convert_boolean_attributes(&$html_options, $bool_attrs) { … … 102 117 /** 103 118 * @todo Document this method 119 * @param string 120 * @param mixed[] 121 * @param mixed[] 122 * @return string 123 * @uses convert_boolean_attributes() 124 * @uses convert_confirm_option_to_javascript() 125 * @uses url_for() 104 126 */ 105 127 function button_to($name, $options = array(), $html_options = null) { … … 115 137 } 116 138 117 $html_options = array_merge($html_options, array("type" => "submit", "value" => $name)); 118 return "<form method=\"post\" action=\"" . htmlspecialchars($url) . "\" class=\"button-to\"><div>" . 119 $this->tag("input", $html_options) . "</div></form>"; 120 } 121 122 /** 123 * This tag is deprecated. Combine the link_to and AssetTagHelper::image_tag yourself instead, like: 124 * link_to(image_tag("rss", array("size" => "30x45"), array("border" => 0)), "http://www.example.com") 125 */ 126 function link_image_to($src, $options = array(), $html_options = array()) { 139 $html_options = array_merge($html_options, 140 array("type" => "submit", "value" => $name)); 141 return "<form method=\"post\" action=\"" . htmlspecialchars($url) 142 . "\" class=\"button-to\"><div>" 143 . $this->tag("input", $html_options) . "</div></form>"; 144 } 145 146 /** 147 * This tag is deprecated. Combine the link_to and 148 * AssetTagHelper::image_tag yourself instead, like: 149 * link_to(image_tag("rss", array("size" => "30x45"), 150 * array("border" => 0)), "http://www.example.com") 151 * @todo Document this method 152 */ 153 function link_image_to($src, $options = array(), 154 $html_options = array()) { 127 155 $image_options = array("src" => (ereg("/", $src) ? $src : "/images/$src")); 128 156 if (!ereg(".", $image_options["src"])) $image_options["src"] .= ".png"; … … 155 183 156 184 /** 157 * Return the URL for the set of $options provided. 185 * Generate URL based on current URL and optional arguments 186 * 187 * Output a URL with controller and optional action and id. 188 * The output URL has the same method, host and 189 * <samp>TRAX_URL_PREFIX</samp> as 190 * the current URL. Controller is either the current controller 191 * or a controller specified in $options. Action and ID are 192 * optionally specified in $options, or omitted. The 193 * <samp>':id'</samp> option will be ignored if the <samp>':action'</samp> 194 * option is omitted. 195 * @param mixed[] 196 * <ul> 197 * <li><b>string:</b><br /> 198 * The string value is returned immediately with no 199 * substitutions.</li> 200 * <li><b>array:</b> 201 * <ul> 202 * <li><samp>':controller'=></samp><i>controller value</i></li> 203 * <li><samp>':action'=></samp><i>action value</i></li> 204 * <li><samp>':id'=></samp><i>id value</i></li> 205 * </ul> 206 * </ul> 207 * @return string 208 * @uses controller_path 158 209 */ 159 210 function url_for($options = array()) { … … 162 213 $extra_params = array(); 163 214 if(is_string($options)) { 164 //$url[] = $options; 215 216 // Argument is a string, just return it 165 217 return $options; 218 166 219 } elseif(is_array($options)) { 220 221 // Argument is a (possibly empty) array 222 // Start forming URL with this host 167 223 $url_base = $_SERVER['HTTP_HOST']; 168 224 if(substr($url_base, -1) == "/") { 169 225 # remove the ending slash 170 $url_base = substr($url_base, 0, -1); 226 $url_base = substr($url_base, 0, -1); 171 227 } 172 228 229 // Method is same as was used by the current URL 173 230 if($_SERVER['SERVER_PORT'] == 443) { 174 231 $url_base = "https://".$url_base; … … 176 233 $url_base = "http://".$url_base; 177 234 } 235 // Insert value of TRAX_URL_PREFIX (must start with /) 178 236 if(!is_null(TRAX_URL_PREFIX)) { 179 $url_base .= "/".TRAX_URL_PREFIX;237 $url_base .= TRAX_URL_PREFIX; 180 238 } 181 239 240 // Get controller from $options or $controller_path 182 241 if(array_key_exists(":controller", $options)) { 183 242 if($controller = $options[":controller"]) { … … 192 251 $url[] = $controller; 193 252 } 194 253 254 // If controller found, get action from $options 195 255 if(count($url)) { 196 256 if(array_key_exists(":action", $options)) { … … 200 260 } 201 261 } 262 263 // If controller and action found, get id from $actions 202 264 if(count($url) > 1) { 203 265 if(array_key_exists(":id", $options)) { … … 226 288 $url_base .= "/"; 227 289 } 228 return $url_base . implode("/", $url) . (count($extra_params) ? "?".http_build_query($extra_params) : null); 290 return $url_base . implode("/", $url) 291 . (count($extra_params) 292 ? "?".http_build_query($extra_params) : null); 229 293 } 230 294 … … 232 296 233 297 /** 234 * Avialble functions for use in views235 * @ todo Document this function298 * Make a new UrlHelper object and call its link_to() method 299 * @uses UrlHelper::link_to() 236 300 */ 237 301 function link_to($name, $options = array(), $html_options = array()) { … … 240 304 } 241 305 306 /** 307 * Make a new UrlHelper object and call its link_image_to() method 308 * @uses UrlHelper::link_image_to() 309 */ 242 310 function link_image_to($src, $options = array(), $html_options = array()) { 243 311 $url_helper = new UrlHelper(); … … 245 313 } 246 314 315 /** 316 * Make a new UrlHelper object and call its button_to() method 317 * @uses UrlHelper::button_to() 318 */ 247 319 function button_to($name, $options = array(), $html_options = null) { 248 320 $url_helper = new UrlHelper(); … … 250 322 } 251 323 324 /** 325 * Make a new UrlHelper object and call its url_for() method 326 * @uses UrlHelper::url_for() 327 */ 252 328 function url_for($options = array()) { 253 329 $url_helper = new UrlHelper();
