Show
Ignore:
Timestamp:
03/07/2008 02:19:56 PM (9 months ago)
Author:
Shadowhand
Message:

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

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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        {