Changeset 893

Show
Ignore:
Timestamp:
10/25/2007 08:53:51 PM (13 months ago)
Author:
Shadowhand
Message:

Small changes:

  • Comments updated in helpers
  • Small optimizations to helpers
  • Possible issue with index.php fixed (require vs require_once)
Location:
trunk
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/index.php

    r890 r893  
    8787); 
    8888 
    89 require_once SYSPATH.'core/Bootstrap'.EXT; 
     89require SYSPATH.'core/Bootstrap'.EXT; 
  • trunk/system/helpers/download.php

    r884 r893  
    11<?php defined('SYSPATH') or die('No direct script access.'); 
    2 /** 
    3  * Kohana: The swift, small, and secure PHP5 framework 
     2/* 
     3 * Class: download 
     4 *  Download helper class. 
    45 * 
    5  * @package    Kohana 
    6  * @author     Kohana Team 
    7  * @copyright  Copyright (c) 2007 Kohana Team 
    8  * @link       http://kohanaphp.com 
    9  * @license    http://kohanaphp.com/license.html 
    10  * @since      Version 2.0 
    11  * @filesource 
    12  * $Id$ 
    13  */ 
    14  
    15 /** 
    16  * Download Class 
    17  * 
    18  * @category    Helpers 
    19  * @author      Kohana Team 
    20  * @link        http://kohanaphp.com/user_guide/en/helpers/download.html 
     6 * Kohana Source Code: 
     7 *  author    - Kohana Team 
     8 *  copyright - (c) 2007 Kohana Team 
     9 *  license   - <http://kohanaphp.com/license.html> 
    2110 */ 
    2211class download { 
    2312 
    24         /** 
    25          * Force Download 
     13        /* 
     14         * Method: force 
     15         *  Force a download of a file to the user's browser. This function is 
     16         *  binary-safe and will work with any MIME type that Kohana is aware of. 
    2617         * 
    27          * Generates headers that force a download to happen 
    28          * 
    29          * @access  public 
    30          * @param   string  filename 
    31          * @param   mixed   the data to be downloaded 
    32          * @return  void 
     18         * Parameters: 
     19         *  filename - a file path or file name 
     20         *  data     - data to be sent if the filename does not exist 
    3321         */ 
    3422        public static function force($filename = '', $data = '') 
     
    113101        } 
    114102 
    115 } // End download class 
     103} // End download 
  • trunk/system/helpers/file.php

    r814 r893  
    11<?php defined('SYSPATH') or die('No direct script access.'); 
    2 /** 
    3  * Kohana: The swift, small, and secure PHP5 framework 
     2/* 
     3 * Class: file 
     4 *  File helper class. 
    45 * 
    5  * @package    Kohana 
    6  * @author     Kohana Team 
    7  * @copyright  Copyright (c) 2007 Kohana Team 
    8  * @link       http://kohanaphp.com 
    9  * @license    http://kohanaphp.com/license.html 
    10  * @since      Version 2.0 
    11  * @filesource 
    12  * $Id$ 
    13  */ 
    14  
    15 /** 
    16  * File Class 
    17  * 
    18  * @category    Helpers 
    19  * @author      Kohana Team 
    20  * @link        http://kohanaphp.com/user_guide/en/helpers/file.html 
     6 * Kohana Source Code: 
     7 *  author    - Kohana Team 
     8 *  copyright - (c) 2007 Kohana Team 
     9 *  license   - <http://kohanaphp.com/license.html> 
    2110 */ 
    2211class file { 
    2312 
     13        /* 
     14         * Method: split 
     15         *  Split a file into pieces matching a specific size. 
     16         * 
     17         * Parameters: 
     18         *  filename   - file to be split 
     19         *  output_dir - directory to output to, defaults to the same directory as the file 
     20         *  piece_size - size, in MB, for each chunk to be 
     21         * 
     22         * Returns: 
     23         *  The number of pieces that were created. 
     24         */ 
    2425        public static function split($filename, $output_dir = FALSE, $piece_size = 10) 
    2526        { 
     
    7172        } 
    7273 
     74        /* 
     75         * Method: join 
     76         *  Join a split file into a whole fike. 
     77         * 
     78         * Parameters: 
     79         *  filename  - split filename, without .000 extension 
     80         *  output    - output filename, if different then an the filename 
     81         * 
     82         * Returns: 
     83         *  The number of pieces that were joined. 
     84         */ 
    7385        public static function join($filename, $output = FALSE) 
    7486        { 
     
    109121        } 
    110122 
    111 } // End file class 
     123} // End file 
  • trunk/system/helpers/form.php

    r890 r893  
    11<?php defined('SYSPATH') or die('No direct script access.'); 
    2 /** 
    3  * Kohana: The swift, small, and secure PHP5 framework 
     2/* 
     3 * Class: form 
     4 *  Form helper class. 
    45 * 
    5  * @package    Kohana 
    6  * @author     Kohana Team 
    7  * @copyright  Copyright (c) 2007 Kohana Team 
    8  * @link       http://kohanaphp.com 
    9  * @license    http://kohanaphp.com/license.html 
    10  * @since      Version 2.0 
    11  * @filesource 
    12  * $Id$ 
    13  */ 
    14  
    15 /** 
    16  * Form Class 
    17  * 
    18  * @category    Helpers 
    19  * @author      Kohana Team 
    20  * @link        http://kohanaphp.com/user_guide/en/helpers/form.html 
     6 * Kohana Source Code: 
     7 *  author    - Kohana Team 
     8 *  copyright - (c) 2007 Kohana Team 
     9 *  license   - <http://kohanaphp.com/license.html> 
    2110 */ 
    2211class form { 
    2312 
    24         /** 
    25          * Form Declaration 
    26          * 
    27          * Creates the opening portion of the form. 
    28          * 
    29          * @access  public 
    30          * @param   string  the URI segments of the form destination 
    31          * @param   array   a key/value pair of attributes 
    32          * @param   array   a key/value pair hidden data 
    33          * @return  string 
     13        /* 
     14         * Method: open 
     15         *  Generates an opening HTML form tag. 
     16         * 
     17         * Parameters: 
     18         *  action - form action attribute 
     19         *  attr   - extra attributes 
     20         *  hidden - hidden fields to be created immediately after the form tag 
     21         * 
     22         * Returns: 
     23         *  An HTML form tag. 
    3424         */ 
    3525        public static function open($action = '', $attr = array(), $hidden = array()) 
     
    6656        } 
    6757 
     58        /* 
     59         * Method: open_multipart 
     60         *  Generates an opening HTML form tag that can be used for uploading files. 
     61         * 
     62         * Parameters: 
     63         *  action - form action attribute 
     64         *  attr   - extra attributes 
     65         *  hidden - hidden fields to be created immediately after the form tag 
     66         * 
     67         * Returns: 
     68         *  An HTML form tag. 
     69         */ 
     70        public static function open_multipart($action = '', $attr = array(), $hidden = array()) 
     71        { 
     72                // Set multi-part form type 
     73                $attr['enctype'] = 'multipart/form-data'; 
     74 
     75                return self::open($action, $attr, $hidden); 
     76        } 
     77 
     78        /** 
     79         * Hidden Input Field 
     80         * 
     81         * Generates hidden fields.  You can pass a simple key/value string or an associative 
     82         * array with multiple values. 
     83         * 
     84         * @access  public 
     85         * @param   mixed 
     86         * @param   string 
     87         * @return  string 
     88         */ 
     89        /* 
     90         * Method: open 
     91         *  Generates hidden form fields. 
     92         * 
     93         * Parameters: 
     94         *  data  - input name (string) or key/value pairs (array) 
     95         *  value - input value, if using an input name 
     96         * 
     97         * Returns: 
     98         *  One or more HTML hidden form input tags. 
     99         */ 
     100        public static function hidden($data, $value = '') 
     101        { 
     102                if ( ! is_array($data)) 
     103                { 
     104                        $data = array 
     105                        ( 
     106                                $data => $value 
     107                        ); 
     108                } 
     109 
     110                $input = ''; 
     111                foreach($data as $name => $value) 
     112                { 
     113                        $attr = array 
     114                        ( 
     115                                'type'  => 'hidden', 
     116                                'name'  => $name, 
     117                                'value' => $value 
     118                        ); 
     119 
     120                        $input .= self::input($attr)."\n"; 
     121                } 
     122 
     123                return $input; 
     124        } 
     125 
     126        /* 
     127         * Method: input 
     128         *  Creates an HTML form input tag. Defaults to a text type. 
     129         * 
     130         * Parameters: 
     131         *  data  - input name or an array of HTML attributes 
     132         *  value - input value, when using a name 
     133         *  extra - a string to be attached to the end of the attributes 
     134         * 
     135         * Returns: 
     136         *  An HTML form input tag. 
     137         */ 
     138        public static function input($data = '', $value = '', $extra = '') 
     139        { 
     140                if ( ! is_array($data)) 
     141                { 
     142                        $data = array('name' => $data); 
     143                } 
     144 
     145                // Type and value are required attributes 
     146                $data += array 
     147                ( 
     148                        'type'  => 'text', 
     149                        'value' => $value 
     150                ); 
     151 
     152                // Form elements should have the same id as name 
     153                if ( ! isset($data['id'])) 
     154                { 
     155                        $data['id'] = $data['name']; 
     156                } 
     157 
     158                // For safe form data 
     159                $data['value'] = html::specialchars($data['value']); 
     160 
     161                return '<input'.self::attributes($data).$extra.' />'; 
     162        } 
     163 
     164        /* 
     165         * Method: password 
     166         *  Creates a HTML form password input tag. 
     167         * 
     168         * Parameters: 
     169         *  data  - input name or an array of HTML attributes 
     170         *  value - input value, when using a name 
     171         *  extra - a string to be attached to the end of the attributes 
     172         * 
     173         * Returns: 
     174         *  An HTML form password input tag. 
     175         */ 
     176        public static function password($data = '', $value = '', $extra = '') 
     177        { 
     178                if ( ! is_array($data)) 
     179                { 
     180                        $data = array('name' => $data); 
     181                } 
     182 
     183                $data['type'] = 'password'; 
     184 
     185                return self::input($data, $value, $extra); 
     186        } 
     187 
     188        /* 
     189         * Method: input 
     190         *  Creates an HTML form upload input tag. 
     191         * 
     192         * Parameters: 
     193         *  data  - input name or an array of HTML attributes 
     194         *  value - input value, when using a name 
     195         *  extra - a string to be attached to the end of the attributes 
     196         * 
     197         * Returns: 
     198         *  An HTML form upload tag. 
     199         */ 
     200        public static function upload($data = '', $value = '', $extra = '') 
     201        { 
     202                if ( ! is_array($data)) 
     203                { 
     204                        $data = array('name' => $data); 
     205                } 
     206 
     207                $data['type'] = 'file'; 
     208 
     209                return self::input($data, $value, $extra); 
     210        } 
     211 
     212        /* 
     213         * Method: textarea 
     214         *  Creates an HTML form textarea tag. 
     215         * 
     216         * Parameters: 
     217         *  data  - textarea name or an array of HTML attributes 
     218         *  value - textarea value, when using a name 
     219         *  extra - a string to be attached to the end of the attributes 
     220         * 
     221         * Returns: 
     222         *  An HTML form textarea tag. 
     223         */ 
     224        public static function textarea($data = '', $value = '', $extra = '') 
     225        { 
     226                if ( ! is_array($data)) 
     227                { 
     228                        $data = array('name' => $data); 
     229                } 
     230 
     231                // Use the value from $data if possible, or use $value 
     232                $value = isset($data['value']) ? $data['value'] : $value; 
     233 
     234                // Value is not part of the attributes 
     235                unset($data['value']); 
     236 
     237                return '<textarea'.self::attributes($data).'>'.html::specialchars($value).'</textarea>'; 
     238        } 
     239 
     240        /* 
     241         * Method: dropdown 
     242         *  Creates an HTML form select tag, or "dropdown menu". 
     243         * 
     244         * Parameters: 
     245         *  data     - select name or an array of HTML attributes 
     246         *  options  - select options, when using a name 
     247         *  selected - option key that should be selected by default 
     248         *  extra    - a string to be attached to the end of the attributes 
     249         * 
     250         * Returns: 
     251         *  An HTML form select tag, with options. 
     252         */ 
     253        public static function dropdown($data = '', $options = array(), $selected = '', $extra = '') 
     254        { 
     255                if ( ! is_array($data)) 
     256                { 
     257                        $data = array('name' => $data); 
     258                } 
     259 
     260                $input = '<select '.self::attributes($data).$extra.'>'."\n"; 
     261                foreach ($options as $key => $val) 
     262                { 
     263                        $sel = ($selected == $key) ? ' selected="selected"' : ''; 
     264 
     265                        $input .= '<option value="'.$key.'"'.$sel.'>'.$val.'</option>'."\n"; 
     266                } 
     267                $input .= '</select>'; 
     268 
     269                return $input; 
     270        } 
     271 
     272        /* 
     273         * Method: checkbox 
     274         *  Creates an HTML form checkbox input tag. 
     275         * 
     276         * Parameters: 
     277         *  data    - input name or an array of HTML attributes 
     278         *  value   - input value, when using a name 
     279         *  checked - make the checkbox checked by default 
     280         *  extra   - a string to be attached to the end of the attributes 
     281         * 
     282         * Returns: 
     283         *  An HTML form checkbox tag. 
     284         */ 
     285        public static function checkbox($data = '', $value = '', $checked = FALSE, $extra = '') 
     286        { 
     287                if ( ! is_array($data)) 
     288                { 
     289                        $data = array('name' => $data); 
     290                } 
     291 
     292                $data['type'] = 'checkbox'; 
     293 
     294                if ($checked == TRUE OR (isset($data['checked']) AND $data['checked'] == TRUE)) 
     295                { 
     296                        $data['checked'] = 'checked'; 
     297                } 
     298                else 
     299                { 
     300                        unset($data['checked']); 
     301                } 
     302 
     303                return self::input($data, $value, $extra); 
     304        } 
     305 
     306        /* 
     307         * Method: radio 
     308         *  Creates an HTML form radio input tag. 
     309         * 
     310         * Parameters: 
     311         *  data    - input name or an array of HTML attributes 
     312         *  value   - input value, when using a name 
     313         *  checked - make the radio selected by default 
     314         *  extra   - a string to be attached to the end of the attributes 
     315         * 
     316         * Returns: 
     317         *  An HTML form radio tag. 
     318         */ 
     319        public static function radio($data = '', $value = '', $checked = FALSE, $extra = '') 
     320        { 
     321                if ( ! is_array($data)) 
     322                { 
     323                        $data = array('name' => $data); 
     324                } 
     325 
     326                $data['type'] = 'radio'; 
     327 
     328                if ($checked == TRUE OR (isset($data['checked']) AND $data['checked'] == TRUE)) 
     329                { 
     330                        $data['checked'] = 'checked'; 
     331                } 
     332                else 
     333                { 
     334                        unset($data['checked']); 
     335                } 
     336 
     337                return self::input($data, $value, $extra); 
     338        } 
     339 
     340        /* 
     341         * Method: submit 
     342         *  Creates an HTML form submit input tag. 
     343         * 
     344         * Parameters: 
     345         *  data    - input name or an array of HTML attributes 
     346         *  value   - input value, when using a name 
     347         *  extra   - a string to be attached to the end of the attributes 
     348         * 
     349         * Returns: 
     350         *  An HTML form submit tag. 
     351         */ 
     352        public static function submit($data = '', $value = '', $extra = '') 
     353        { 
     354                if ( ! is_array($data)) 
     355                { 
     356                        $data = array('name' => $data); 
     357                } 
     358 
     359                $data['type'] = 'submit'; 
     360 
     361                return self::input($data, $value, $extra); 
     362        } 
     363 
     364        /* 
     365         * Method: button 
     366         *  Creates an HTML form button input tag. 
     367         * 
     368         * Parameters: 
     369         *  data    - input name or an array of HTML attributes 
     370         *  value   - input value, when using a name 
     371         *  extra   - a string to be attached to the end of the attributes 
     372         * 
     373         * Returns: 
     374         *  An HTML form button tag. 
     375         */ 
     376        public static function button($data = '', $value = '', $extra = '') 
     377        { 
     378                if ( ! is_array($data)) 
     379                { 
     380                        $data = array('name' => $data); 
     381                } 
     382 
     383                $data += array 
     384                ( 
     385                        'type'  => 'button' 
     386                ); 
     387 
     388                if (isset($data['value'])) 
     389                { 
     390                        $value = $data['value']; 
     391                        unset($data['value']); 
     392                } 
     393 
     394                return '<button'.self::attributes($data).$extra.'>'.html::specialchars($value).'</button>'; 
     395        } 
     396 
     397        /* 
     398         * Method: close 
     399         *  Closes an open form tag. 
     400         * 
     401         * Parameters: 
     402         *  extra - string to be attached after the closing tag 
     403         * 
     404         * Returns: 
     405         *  A closing HTML form tag. 
     406         */ 
     407        public static function close($extra = '') 
     408        { 
     409                return '</form>'."\n".$extra; 
     410        } 
     411 
     412        /* 
     413         * Method: label 
     414         *  Creates an HTML form label tag. 
     415         * 
     416         * Parameters: 
     417         *  data  - label "for" name or an array of HTML attributes 
     418         *  text  - label text or HTML 
     419         *  extra - a string to be attached to the end of the attributes 
     420         * 
     421         * Returns: 
     422         *  An HTML form submit tag. 
     423         */ 
     424        public static function label($data = '', $text = '', $extra = '') 
     425        { 
     426                if ( ! is_array($data)) 
     427                { 
     428                        $data = array 
     429                        ( 
     430                                'for' => $data 
     431                        ); 
     432                } 
     433 
     434                return '<label'.self::attributes($data).$extra.'>'.$text.'</label>'; 
     435        } 
     436 
     437        /* 
     438         * Method: attributes 
     439         *  Sorts a key/value array of HTML attributes, putting form attributes first, 
     440         *  and returns an attribute string. 
     441         * 
     442         * Parameters: 
     443         *  attr - HTML attributes array 
     444         * 
     445         * Returns: 
     446         *  An HTML attribute string. 
     447         */ 
    68448        public static function attributes($attr) 
    69449        { 
     
    107487        } 
    108488 
    109         /** 
    110          * Form Declaration - Multipart type 
    111          * 
    112          * Creates the opening portion of the form, but with "multipart/form-data". 
    113          * 
    114          * @access  public 
    115          * @param   string  the URI segments of the form destination 
    116          * @param   array   a key/value pair of attributes 
    117          * @param   array   a key/value pair hidden data 
    118          * @return  string 
    119          */ 
    120         public static function open_multipart($action = '', $attr = array(), $hidden = array()) 
    121         { 
    122                 // Set multi-part form type 
    123                 $attr['enctype'] = 'multipart/form-data'; 
    124  
    125                 return self::open($action, $attr, $hidden); 
    126         } 
    127  
    128         /** 
    129          * Hidden Input Field 
    130          * 
    131          * Generates hidden fields.  You can pass a simple key/value string or an associative 
    132          * array with multiple values. 
    133          * 
    134          * @access  public 
    135          * @param   mixed 
    136          * @param   string 
    137          * @return  string 
    138          */ 
    139         public static function hidden($data, $value = '') 
    140         { 
    141                 if ( ! is_array($data)) 
    142                 { 
    143                         $data = array 
    144                         ( 
    145                                 $data => $value 
    146                         ); 
    147                 } 
    148  
    149                 $input = ''; 
    150                 foreach($data as $name => $value) 
    151                 { 
    152                         $attr = array 
    153                         ( 
    154                                 'type'  => 'hidden', 
    155                                 'name'  => $name, 
    156                                 'value' => $value 
    157                         ); 
    158  
    159                         $input .= self::input($attr)."\n"; 
    160                 } 
    161  
    162                 return $input; 
    163         } 
    164  
    165         /** 
    166          * Text Input Field 
    167          * 
    168          * @access  public 
    169          * @param   mixed 
    170          * @param   string 
    171          * @param   string 
    172          * @return  string 
    173          */ 
    174         public static function input($data = '', $value = '', $extra = '') 
    175         { 
    176                 if ( ! is_array($data)) 
    177                 { 
    178                         $data = array('name' => $data); 
    179                 } 
    180  
    181                 // Type and value are required attributes 
    182                 $data += array 
    183                 ( 
    184                         'type'  => 'text', 
    185                         'value' => $value 
    186                 ); 
    187  
    188                 // Form elements should have the same id as name 
    189                 if ( ! isset($data['id'])) 
    190                 { 
    191                         $data['id'] = $data['name']; 
    192                 } 
    193  
    194                 // For safe form data 
    195                 $data['value'] = html::specialchars($data['value']); 
    196  
    197                 return '<input'.self::attributes($data).$extra.' />'; 
    198         } 
    199  
    200         /** 
    201          * Password Field 
    202          * 
    203          * Identical to the input public static function but adds the "password" type 
    204          * 
    205          * @access  public 
    206          * @param   mixed 
    207          * @param   string 
    208          * @param   string 
    209          * @return  string 
    210          */ 
    211         public static function password($data = '', $value = '', $extra = '') 
    212         { 
    213                 if ( ! is_array($data)) 
    214                 { 
    215                         $data = array('name' => $