Changeset 647

Show
Ignore:
Timestamp:
10/04/2007 01:57:26 PM (14 months ago)
Author:
Shadowhand
Message:

Overhauled User_Agent almost completely.

Spit shine on the rest of it.

Location:
trunk
Files:
15 modified

Legend:

Unmodified
Added
Removed
  • trunk/application/config/config.php

    r644 r647  
    11<?php defined('SYSPATH') or die('No direct script access.'); 
    2  
    32/* 
    43| ------------------------------------------------------------------------- 
     
    3231| Typically this will be your index.php file, unless you've renamed it to 
    3332| something else. If you are using mod_rewrite to remove the page set this 
    34 | variable so that it is blank. 
     33| variable to an empty string. 
    3534| 
    3635*/ 
    37 $config['index_page'] = 'index.php'; 
     36$config['index_page'] = ''; 
    3837 
     38/* 
     39| ----------------------------------------------------------------------------- 
     40| URL Suffix 
     41| ----------------------------------------------------------------------------- 
     42| 
     43| You can set an arbitrary filename extension to Kohana URLs. This extension is 
     44| completely freeform, but should start with a period. 
     45| 
     46*/ 
    3947$config['url_suffix'] = '.html'; 
    4048 
     49/* 
     50| ----------------------------------------------------------------------------- 
     51| Permitted URI Characters (EXPERT) 
     52| ----------------------------------------------------------------------------- 
     53| 
     54| This is the list of characters that Kohana will accept in the URI. Note that 
     55| the default will accept urlencoded (eg: %20) characters to pass through. ID 
     56| anchors (eg: #header_id) are always allowed. 
     57| 
     58*/ 
    4159$config['permitted_uri_chars'] = 'a-z 0-9~%.:_-'; 
    4260 
     61/* 
     62| ----------------------------------------------------------------------------- 
     63| Locale 
     64| ----------------------------------------------------------------------------- 
     65| 
     66| Kohana supports full international locale support. Changing this option to an 
     67| unavailable locale will break Kohana. 
     68| 
     69*/ 
    4370$config['locale'] = 'en'; 
    4471 
     72/* 
     73| ----------------------------------------------------------------------------- 
     74| Include Paths 
     75| ----------------------------------------------------------------------------- 
     76| 
     77| User Guide: http://kohanaphp.com/user_guide/en/general/configuration.html 
     78| 
     79*/ 
    4580$config['include_paths'] = array 
    4681( 
     
    4883); 
    4984 
     85/* 
     86| ----------------------------------------------------------------------------- 
     87| Enable Hooks (EXPERT!) 
     88| ----------------------------------------------------------------------------- 
     89| 
     90| User Guide: http://kohanaphp.com/user_guide/en/general/hooks.html 
     91| 
     92*/ 
    5093$config['enable_hooks'] = FALSE; 
    5194 
     95/* 
     96| ----------------------------------------------------------------------------- 
     97| Extension Prefix 
     98| ----------------------------------------------------------------------------- 
     99| 
     100| This prefix is used for the filename of your extended libraries, eg: 
     101| MY_Controller.php, MY_Database.php, MY_Validation.php 
     102| 
     103*/ 
    52104$config['extension_prefix'] = 'MY_'; 
    53105 
     106/* 
     107| ----------------------------------------------------------------------------- 
     108| Time Zone 
     109| ----------------------------------------------------------------------------- 
     110| 
     111| You can set any timezone supported by PHP here. A list of avaialable timezones 
     112| is located here: http://php.net/timezones 
     113| 
     114*/ 
    54115$config['timezone'] = ''; 
    55116 
     117/* 
     118| ----------------------------------------------------------------------------- 
     119| Auto-Load 
     120| ----------------------------------------------------------------------------- 
     121| 
     122| You can autoload libraries and models. This feature is not necessary due to 
     123| Kohana's internal auto-loading methods, but you can use it to save a small 
     124| amount of overhead. 
     125| 
     126| Set the class names in a comma separated list, eg: 
     127| 
     128|   'libraries' => 'Database, Validation', 
     129|   'models'    => 'Users, Pages' 
     130| 
     131*/ 
    56132$config['autoload'] = array 
    57133( 
  • trunk/application/config/cookie.php

    r644 r647  
    22/** 
    33 * Cookie Configuration 
     4 * ---------------------------------------------------------------------------- 
     5 * By default, cookie security is very relaxed. You are encouraged to set a 
     6 * domain and path to add some security to your cookies. 
     7 * 
     8 * User Guide: http://kohanaphp.com/user_guide/en/general/cookies.html 
    49 * 
    510 * @param  string  prefix   - Prefix to avoid collisions 
     
    914 * @param  boolean secure   - Only allow the cookie on HTTPS 
    1015 * @param  boolean httponly - Only allow cookie access through the HTTP protocol 
     16 * 
    1117 */ 
    12  
    13 // ---------------------------------------------------------------------------- 
    14  
    15 $config['prefix']   = ''; 
    16 $config['domain']   = ''; 
    17 $config['path']     = '/'; 
    18 $config['expire']   = 0; 
    19 $config['secure']   = FALSE; 
    20 $config['httponly'] = FALSE; 
     18$config = array 
     19( 
     20        'prefix'   => '', 
     21        'domain'   => '', 
     22        'path'     => '/', 
     23        'expire'   => 0, 
     24        'secure'   => FALSE, 
     25        'httponly' => FALSE 
     26); 
  • trunk/application/config/database.php

    r644 r647  
    11<?php defined('SYSPATH') or die('No direct script access.'); 
    2 /* 
    3 | Database Configuration 
    4 | ----------------------------------------------------------------------------- 
    5 | Database connection settings, defined by group name. If no group name is used 
    6 | when loading the database library, the group named "default" will be used. 
    7 | All of the variables listed below are explained in detail in the User Guide. 
    8 | 
    9 | User Guide: http://kohanaphp.com/user_guide/en/libraries/database.html 
    10 | 
    11 | Settings: 
    12 | - show_errors    Enable or disable database exceptions 
    13 | - persistent     Enable or disable a persistent connection 
    14 | - connection     DSN identifer: driver://user:password@server/database 
    15 | - character_set  Connection character set 
    16 | - table_prefix   Database table prefix 
    17 */ 
    18  
     2/** 
     3 * Database Configuration 
     4 * ----------------------------------------------------------------------------- 
     5 * Database connection settings, defined by group name. If no group name is used 
     6 * when loading the database library, the group named "default" will be used. 
     7 * All of the variables listed below are explained in detail in the User Guide. 
     8 * 
     9 * User Guide: http://kohanaphp.com/user_guide/en/libraries/database.html 
     10 * 
     11 * @param boolean show_errors   - Enable or disable database exceptions 
     12 * @param boolean persistent    - Enable or disable a persistent connection 
     13 * @param string  connection    - DSN identifier: driver://user:password@server/database 
     14 * @param string  character_set - Connection character set 
     15 * @param string  table_prefix  - Database table prefix 
     16 * @param boolean object        - Return objects (TRUE) or arrays (FALSE) 
     17 * 
     18 */ 
    1919$config['default'] = array 
    2020( 
  • trunk/application/config/encryption.php

    r644 r647  
    11<?php defined('SYSPATH') or die('No direct script access.'); 
     2/** 
     3 * Encryption Configuration 
     4 * ----------------------------------------------------------------------------- 
     5 * 
     6 * User Guide: http://kohanaphp.com/user_guide/en/libraries/encryption.html 
     7 * 
     8 * @param string  secret  - The encryption key, choose something good! 
     9 * 
     10 */ 
    211 
    3 $config['secret'] = 'K0H@NA+PHP'; 
     12$config = array 
     13( 
     14        'secret' => 'K0H@NA+PHP' 
     15); 
  • trunk/application/config/log.php

    r644 r647  
    11<?php defined('SYSPATH') or die('No direct script access.'); 
    2 /* 
    3 |-------------------------------------------------------------------------- 
    4 | Error Logging Threshold 
    5 |-------------------------------------------------------------------------- 
    6 | 
    7 | If you have enabled error logging, you can set an error threshold to  
    8 | determine what gets logged. Threshold options are: 
    9 | You can enable error logging by setting a threshold over zero. The 
    10 | threshold determines what gets logged. Threshold options are: 
    11 | 
    12 |       0 = Disables logging, Error logging TURNED OFF 
    13 |       1 = Error Messages (including PHP errors) 
    14 |       2 = Debug Messages 
    15 |       3 = Informational Messages 
    16 |       4 = All Messages 
    17 | 
    18 | For a live site you'll usually only enable Errors (1) to be logged otherwise 
    19 | your log files will fill up very fast. 
    20 | 
    21 */ 
    22 $config['threshold'] = 4; 
    23  
    24 /* 
    25 |-------------------------------------------------------------------------- 
    26 | Error Logging Directory Path 
    27 |-------------------------------------------------------------------------- 
    28 | 
    29 | Leave this BLANK unless you would like to set something other than the default 
    30 | application/logs/ folder.  Use a full server path with trailing slash. 
    31 | 
    32 */ 
    33 $config['directory'] = 'logs'; 
    34  
    35 /* 
    36 |-------------------------------------------------------------------------- 
    37 | Date Format for Logs 
    38 |-------------------------------------------------------------------------- 
    39 | 
    40 | Each item that is logged has an associated date. You can use PHP date 
    41 | codes to set your own date formatting 
    42 | 
    43 */ 
    44 $config['format'] = 'Y-m-d H:i:s'; 
     2/** 
     3 * Message Logging 
     4 * ---------------------------------------------------------------------------- 
     5 * If you have enabled message logging, you can set a threshold to determine 
     6 * what gets logged. Setting the threshold to 0 will disable logging completely. 
     7 * 
     8 *   0 = Disables logging completely 
     9 *   1 = Error Messages (including PHP errors) 
     10 *   2 = Debug Messages 
     11 *   3 = Informational Messages 
     12 *   4 = All Messages 
     13 * 
     14 * In production, you will want to disable "display_errors" in your index file, 
     15 * and set the threshold to enable only errors (1). 
     16 * 
     17 * @param integer threshold  - Message threshold 
     18 * @param string  directory  - Log file directory, relative to application/, or absolute 
     19 * @param string  format     - PHP date format for timestamps, see: http://php.net/date 
     20 * 
     21 */ 
     22$config = array 
     23( 
     24        'threshold' => 4, 
     25        'directory' => 'logs', 
     26        'format'    => 'Y-m-d H:i:s' 
     27); 
  • trunk/application/config/mimes.php

    r644 r647  
    11<?php defined('SYSPATH') or die('No direct access allowed.'); 
    2 /* 
    3 | ------------------------------------------------------------------- 
    4 | MIME TYPES 
    5 | ------------------------------------------------------------------- 
    6 | This file contains an array of mime types.  It is used by the 
    7 | Upload class to help identify allowed file types. 
    8 */ 
    9  
     2/** 
     3 * Mime Types 
     4 * ------------------------------------------------------------------- 
     5 * This file contains an array of mime types. Our list is generally 
     6 * more complete and robust than "mime.magic" 
     7 */ 
    108$config = array 
    119( 
  • trunk/application/config/pagination.php

    r644 r647  
    11<?php defined('SYSPATH') or die('No direct access allowed.'); 
    2  
    3 $config['style'] = 'classic'; 
    4  
    5 $config['items_per_page'] = 20; 
     2/** 
     3 * Pagination Configuration 
     4 * ----------------------------------------------------------------------------- 
     5 * 
     6 * User Guide: http://kohanaphp.com/user_guide/en/libraries/pagination.html 
     7 * 
     8 * @param string  style          Style name 
     9 * @param string  items_per_page Number of items in a page of results 
     10 * 
     11 */ 
     12$config = array 
     13( 
     14        'style'          => 'classic', 
     15        'items_per_page' => 20 
     16); 
  • trunk/application/config/routes.php

    r644 r647  
    11<?php defined('SYSPATH') or die('No direct access allowed.'); 
    2  
    3 $config['_default'] = 'user_guide'; 
     2/** 
     3 * Route Configuration 
     4 * ----------------------------------------------------------------------------- 
     5 * Routes can be defined as literal matches, regular expressions, and shortcuts. 
     6 * The "_default" route is reserved for a blank URI string, eg: home page. 
     7 * 
     8 * Supported shortcuts are: 
     9 * 
     10 *   :any - matches any non-blank string 
     11 *   :num - matches any number 
     12 * 
     13 * User Guide: http://kohanaphp.com/user_guide/en/libraries/database.html 
     14 * 
     15 */ 
     16$config = array 
     17( 
     18        '_default' => 'user_guide' 
     19); 
  • trunk/application/config/session.php

    r644 r647  
    22/** 
    33 * Session Configuration 
     4 * ---------------------------------------------------------------------------- 
     5 * 
     6 * User Guide: http://kohanaphp.com/user_guide/en/libraries/session.html 
    47 * 
    58 * @param  string  driver     - Session driver name 
    69 * @param  string  name       - Default session name 
    710 * @param  array   validate   - Session parameters to validate 
    8  * @param  mixed   encryption - Encryption key for sessions 
    9  * @param  int     expiration - Number of seconds that each session will last 
    10  * @param  int     regenerate - Number of page loads before the session is regenerated 
     11 * @param  mixed   encryption - Encryption key, set to FALSE to disable session encryption 
     12 * @param  integer expiration - Number of seconds that each session will last 
     13 * @param  integer regenerate - Number of page loads before the session is regenerated 
     14 * 
    1115 */ 
    12  
    13 // ---------------------------------------------------------------------------- 
    14  
    15 $config['driver']     = 'cookie'; 
    16 $config['name']       = 'kohana_session'; 
    17 $config['validate']   = array('user_agent'); 
    18 $config['encryption'] = FALSE; 
    19 $config['expiration'] = 7200; 
    20 $config['regenerate'] = 3; 
    21  
    22 // DEFAULT SETTINGS ----------------------------------------------------------- 
    23  
    24 /* 
    25 $config['driver']     = 'cookie'; 
    26 $config['name']       = 'kohana_session'; 
    27 $config['validate']   = array('user_agent'); 
    28 $config['encryption'] = FALSE; 
    29 $config['expiration'] = 7200; 
    30 $config['regenerate'] = 3; 
    31 */ 
     16$config = array 
     17( 
     18        'driver'     = 'cookie'; 
     19        'name'       = 'kohana_session'; 
     20        'validate'   = array('user_agent'); 
     21        'encryption' = FALSE; 
     22        'expiration' = 7200; 
     23        'regenerate' = 3; 
     24); 
  • trunk/application/config/upload.php

    r644 r647  
    11<?php defined('SYSPATH') or die('No direct access allowed.'); 
    2  
     2/** 
     3 * Session Configuration 
     4 * ---------------------------------------------------------------------------- 
     5 * 
     6 * User Guide: http://kohanaphp.com/user_guide/en/libraries/validation.html 
     7 * 
     8 * @param  string  upload_directory - Relative to your index file 
     9 * @param  string  remove_space     - Remove spaces from filenames 
     10 * 
     11 */ 
    312$config = array 
    413( 
    5         'upload_directory' => '@up', 
     14        'upload_directory' => '@upload', 
    615        'remove_spaces'    => TRUE 
    716); 
  • trunk/application/config/user_agents.php

    r644 r647  
    11<?php  if (!defined('SYSPATH')) exit('No direct script access allowed'); 
    2 /* 
    3 | ------------------------------------------------------------------- 
    4 | USER AGENT TYPES 
    5 | ------------------------------------------------------------------- 
    6 | This file contains four arrays of user agent data.  It is used by the 
    7 | User Agent Class to help identify browser, platform, robot, and 
    8 | mobile device data.  The array keys are used to identify the device 
    9 | and the array values are used to set the actual name of the item. 
    10 | 
    11 */ 
    12 $config['platforms'] = array 
     2/** 
     3 * User Agents 
     4 * ------------------------------------------------------------------- 
     5 * This file contains four arrays of user agent data.  It is used by the 
     6 * User Agent library to help identify browser, platform, robot, and 
     7 * mobile device data. The array keys are used to identify the device 
     8 * and the array values are used to set the actual name of the item. 
     9 */ 
     10$config['platform'] = array 
    1311( 
    1412        'windows nt 6.0' => 'Windows Longhorn', 
     
    4745// The order of this array should NOT be changed. Many browsers return 
    4846// multiple browser types so we want to identify the sub-type first. 
    49 $config['browsers'] = array 
     47$config['browser'] = array 
    5048( 
    5149        'Opera'             => 'Opera', 
     
    6058        'Netscape'          => 'Netscape', 
    6159        'OmniWeb'           => 'OmniWeb', 
     60        'Safari'            => 'Safari', 
    6261        'Mozilla'           => 'Mozilla', 
    63         'Safari'            => 'Safari', 
    6462        'Konqueror'         => 'Konqueror', 
    6563        'icab'              => 'iCab', 
    66         'Lynx'              => 'Lynx', 
    67         'Links'             => 'Links', 
     64        'lynx'              => 'Lynx', 
     65        'links'             => 'Links', 
    6866        'hotjava'           => 'HotJava', 
    6967        'amaya'             => 'Amaya', 
     
    7169); 
    7270 
    73 $config['mobiles'] = array 
     71$config['mobile'] = array 
    7472( 
    7573        'mobileexplorer' => 'Mobile Explorer', 
  • trunk/application/controllers/welcome.php

    r644 r647  
    55        function index() 
    66        { 
     7                $this->load->library('user_agent'); 
     8 
    79                foreach(get_class_methods(__CLASS__) as $method) 
    810                { 
     
    119121                echo "done in {execution_time} seconds"; 
    120122        } 
     123 
    121124        function user_agent_example() 
    122125        { 
    123126                $this->load->library('user_agent'); 
    124                 echo $this->user_agent; 
     127 
     128                foreach(array('agent', 'browser', 'version') as $key) 
     129                { 
     130                        print $key.': '.$this->user_agent->$key.'<br/>'."\n"; 
     131                } 
     132 
     133                print "<br/><br/>\n"; 
     134                print "done in {execution_time} seconds"; 
    125135        } 
     136 
    126137        function calendar_example() 
    127138        { 
     
    129140                echo $this->calendar->generate(); 
    130141        } 
     142 
    131143        function image_example() 
    132144        { 
  • trunk/index.php

    r644 r647  
    88| User Guide for more information. 
    99| ----------------------------------------------------------------------------- 
    10 | User Guide: http://kohanaphp.com/user_guide/kohana/installation.html 
     10| User Guide: http://kohanaphp.com/user_guide/en/kohana/installation.html 
     11| ----------------------------------------------------------------------------- 
     12| License:    http://kohanaphp.com/user_guide/en/license.html 
    1113| ----------------------------------------------------------------------------- 
    1214*/ 
    1315 
    14 // Set the error reporting level 
    15 @error_reporting(E_ALL); 
     16/** 
     17 * Set the error reporting level. E_ALL is a good default. 
     18 * NOTE: Kohana will always ignore E_NOTICE errors 
     19 */ 
     20error_reporting(E_ALL); 
    1621 
    17 // Enable or disable error reporting 
    18 @ini_set('display_errors', TRUE); 
     22/** 
     23 * Enable or disable error reporting. You should always disable this in production. 
     24 */ 
     25ini_set('display_errors', TRUE); 
    1926 
    20 // Kohana application directory 
     27/** 
     28 * Kohana application directory. This directory must contain a config/ directory. 
     29 */ 
    2130$kohana_application = 'application'; 
    2231 
    23 // Kohana system directory 
     32/** 
     33 * Kohana system directory. This directory must contain the core/ directory. 
     34 */ 
    2435$kohana_system = 'system'; 
     36 
     37/** 
     38 * If you have to rename all of the .php files distributed with Kohana to a 
     39 * different filename, you set the new extension here. Most people will never 
     40 * use this option. 
     41 */ 
     42define('EXT', '.php'); 
    2543 
    2644/* 
     
    2846| PLEASE DO NOT EDIT BELOW THIS LINE, unless you understand the repercussions! 
    2947| ----------------------------------------------------------------------------- 
    30 | User Guide: http://kohanaphp.com/user_guide/general/bootstrapping.html 
     48| User Guide: http://kohanaphp.com/user_guide/en/general/bootstrapping.html 
    3149| ----------------------------------------------------------------------------- 
    3250| $Id$ 
    3351*/ 
    34 // Absolute path names for include purposes 
    35 define('APPPATH', str_replace('\\', '/', realpath($kohana_application)).'/'); unset($kohana_application); 
    36 define('SYSPATH', str_replace('\\', '/', realpath($kohana_system)).'/'); unset($kohana_system); 
    37 // Information about the front controller 
    38 $docroot = str_replace('\\', '/', realpath(__FILE__)); 
    39 define('KOHANA',  pathinfo($docroot, PATHINFO_BASENAME)); 
    40 define('DOCROOT', pathinfo($docroot, PATHINFO_DIRNAME).'/'); 
    41 define('EXT', '.'.pathinfo($docroot, PATHINFO_EXTENSION)); 
    42 unset($docroot); 
    43 // Validate APPPATH 
     52$docroot = pathinfo(str_replace('\\', '/', realpath(__FILE__))); 
     53 
     54define('KOHANA',  $docroot['basename']); 
     55define('DOCROOT', $docroot['dirname'].'/'); 
     56 
     57define('APPPATH', str_replace('\\', '/', realpath($kohana_application)).'/'); 
     58define('SYSPATH', str_replace('\\', '/', realpath($kohana_system)).'/'); 
     59 
     60unset($docroot, $kohana_application, $kohana_system); 
     61 
    4462(is_dir(APPPATH) AND is_dir(APPPATH.'/config')) or die 
    4563( 
     
    4765        'Set a valid <code>$application_path</code> in <kbd>index.php</kbd> and refresh the page.' 
    4866); 
    49 // Validate SYSPATH 
     67 
    5068(is_dir(SYSPATH) AND file_exists(SYSPATH.'/core/'.'Bootstrap'.EXT)) or die 
    5169( 
     
    5371        'Set a valid <code>$kohana_system</code> in <kbd>index.php</kbd> and refresh the page.' 
    5472); 
    55 // Buckle those bootstraps! 
     73 
    5674require_once SYSPATH.'core/Bootstrap'.EXT; 
  • trunk/system/libraries/Session.php

    r644 r647  
    9292                $this->create(); 
    9393 
     94                // Close the session just before flushing the output buffer 
    9495                Event::add('system.pre_output', 'session_write_close'); 
    9596 
  • trunk/system/libraries/User_agent.php

    r644 r647  
    2828 * Identifies the platform, browser, robot, or mobile devise of the browsing agent 
    2929 * 
    30  * @package             Kohana 
    31  * @subpackage  Libraries 
    32  * @category    User Agent 
    33  * @author              Rick Ellis, Kohana Team 
    34  * @link                http://kohanaphp.com/user_guide/libraries/user_agent.html 
     30 * @package     Kohana 
     31 * @subpackage  Libraries 
     32 * @category    User Agent 
     33 * @author      Rick Ellis, Kohana Team 
     34 * @link        http://kohanaphp.com/user_guide/en/libraries/user_agent.html 
    3535 */ 
    3636class User_Agent_Core { 
    3737 
    38         private $agent          = NULL; 
     38        public static $agent = NULL; 
    3939 
    40         private $is_browser     = FALSE; 
    41         private $is_robot       = FALSE; 
    42         private $is_mobile      = FALSE; 
     40        protected static $referrer  = ''; 
     41        protected static $languages = array(); 
     42        protected static $charsets  = array(); 
    4343 
    44         private $languages      = array(); 
    45         private $charsets       = array(); 
    46  
    47         private $platforms      = array(); 
    48         private $browsers       = array(); 
    49         private $mobiles        = array(); 
    50         private $robots         = array(); 
    51  
    52         private $platform       = ''; 
    53         private $browser