Changeset 2229

Show
Ignore:
Timestamp:
03/07/08 14:19:56 (6 months ago)
Author:
Shadowhand
Message:

Creating the IN_PRODUCTION flag, and access protection for module demo controllers.

Location:
trunk
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • trunk/index.php

    r2170 r2229  
    1010 * @license    http://kohanaphp.com/license.html 
    1111 */ 
     12 
     13/** 
     14 * Define the website environment status. When this flag is set to TRUE, some 
     15 * module demonstration controllers will result in 404 errors. For more information 
     16 * about this option, read the documentation about deploying Kohana. 
     17 * 
     18 * @see http://doc.kohanaphp.com/installation/deployment 
     19 */ 
     20define('IN_PRODUCTION', FALSE); 
    1221 
    1322/** 
  • trunk/modules/auth/controllers/auth.php

    r2159 r2229  
    22 
    33class Auth_Controller extends Controller { 
     4 
     5        // Do not allow to run in production 
     6        const ALLOW_PRODUCTION = FALSE; 
    47 
    58        public function __construct() 
  • trunk/modules/forge/controllers/forge_demo.php

    r2031 r2229  
    22 
    33class Forge_demo_Controller extends Controller { 
     4 
     5        // Do not allow to run in production 
     6        const ALLOW_PRODUCTION = FALSE; 
    47 
    58        public function index() 
  • trunk/modules/gmaps/controllers/google_map.php

    r2207 r2229  
    1111 */ 
    1212class Google_Map_Controller extends Controller { 
     13 
     14        // Do not allow to run in production 
     15        const ALLOW_PRODUCTION = FALSE; 
    1316 
    1417        public function index() 
     
    5457        } 
    5558 
     59        public function admin() 
     60        { 
     61                $valid = ! empty($_POST); 
     62 
     63                $_POST = Validation::factory($_POST) 
     64                        ->pre_filter('trim') 
     65                        ->add_rules('title', 'required', 'length[4,32]') 
     66                        ->add_rules('description', 'required', 'length[4,127]') 
     67                        ->add_rules('link', 'length[6,127]', 'valid::url') 
     68                        ->add_rules('address', 'required', 'length[4,127]') 
     69                        ->add_callbacks('address', array($this, '_admin_check_address')); 
     70 
     71                if ($_POST->validate()) 
     72                { 
     73                        // Create a new location 
     74                        $location = ORM::factory('location'); 
     75 
     76                        // 
     77                        foreach ($_POST->as_array() as $key => $val) 
     78                        { 
     79                                $location->$key = $val; 
     80                        } 
     81 
     82                        echo Kohana::debug($_POST->as_array()); 
     83                } 
     84 
     85                if ($errors = $_POST->errors()) 
     86                { 
     87                        foreach ($errors as $input => $rule) 
     88                        { 
     89                                // Add the errors 
     90                                $_POST->message($input, Kohana::lang("gmaps.form.$input")); 
     91                        } 
     92                } 
     93 
     94                View::factory('gmaps/admin')->render(TRUE); 
     95        } 
     96 
     97        public function _admin_check_address(Validation $array, $input) 
     98        { 
     99                if ($array[$input] == '') 
     100                        return; 
     101 
     102                // Fetch the lat and lon via Gmap 
     103                list ($lat, $lon) = Gmap::address_to_ll($array[$input]); 
     104 
     105                if ($lat === NULL OR $lon === NULL) 
     106                { 
     107                        // Add an error 
     108                        $array->add_error($input, 'address'); 
     109                } 
     110                else 
     111                { 
     112                        // Set the latitude and longitude 
     113                        $_POST['lat'] = $lat; 
     114                        $_POST['lon'] = $lon; 
     115                } 
     116        } 
     117 
    56118        public function jquery() 
    57119        { 
  • trunk/modules/kodoc/controllers/kodoc.php

    r2113 r2229  
    22 
    33class Kodoc_Controller extends Template_Controller { 
     4 
     5        // Do not allow to run in production 
     6        const ALLOW_PRODUCTION = FALSE; 
    47 
    58        public $template = 'kodoc/template'; 
  • trunk/modules/shoutbox/controllers/shoutbox.php

    r2044 r2229  
    22 
    33class Shoutbox_Controller extends Controller { 
     4 
     5        // Do not allow to run in production 
     6        const ALLOW_PRODUCTION = FALSE; 
    47 
    58        public function __construct() 
  • trunk/modules/user_guide/controllers/user_guide.php

    r1766 r2229  
    33 
    44class User_Guide_Controller extends Controller { 
     5 
     6        // Do not allow to run in production 
     7        const ALLOW_PRODUCTION = FALSE; 
    58 
    69        public function __construct() 
  • trunk/system/core/Kohana.php

    r2214 r2229  
    215215                        // Make sure the controller class exists 
    216216                        class_exists($controller, FALSE) or Event::run('system.404'); 
     217 
     218                        // Production enviroment protection, based on the IN_PRODUCTION flag 
     219                        (IN_PRODUCTION AND constant($controller.'::ALLOW_PRODUCTION') === FALSE) and Event::run('system.404'); 
    217220 
    218221                        // Run system.pre_controller 
  • trunk/system/libraries/Controller.php

    r2224 r2229  
    1212 */ 
    1313abstract class Controller_Core { 
     14 
     15        // Allow all controllers to run in production by default 
     16        const ALLOW_PRODUCTION = TRUE; 
    1417 
    1518        /**