Changeset 246


Ignore:
Timestamp:
06/24/2011 09:45:59 AM (11 months ago)
Author:
sque
Message:

Make google api key optional ( Closes #148 ) and improve api key selection algorithm

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/config-sample/config.php

    r236 r246  
    9292                        'default' => 'hybrid' 
    9393                        ), 
    94                 'api' => '2.128e', 
     94                'api' => '3.5', 
    9595                'keys' => array( // Domains must be as in $_SERVER['SERVER_NAME'] variable 
    9696                        // 'server.example.org/path' => 'example_key' 
  • trunk/globals/functions.php

    r245 r246  
    55 * Copyright (C) 2005 Nikolaos Nikalexis <winner@cube.gr> 
    66 * Copyright (C) 2009-2010 Vasilis Tsiligiannis <b_tsiligiannis@silverton.gr> 
     7 * Copyright (C) 2011 K. Paliouras <squarious@gmail.com> 
    78 *  
    89 * This program is free software; you can redistribute it and/or modify 
     
    324325function include_gmap($javascript) { 
    325326        global $main, $vars, $lang; 
    326         $dirname = dirname($_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']); 
    327         $gmap_key = '' ; 
    328         if (isset($vars['gmap']['keys'][$dirname])) { 
    329                 $gmap_key = $vars['gmap']['keys'][$dirname]; 
    330         } 
    331         if (isset($vars['gmap']['keys'][$dirname."/"]) && $gmap_key == '') { 
    332                 $gmap_key = $vars['gmap']['keys'][$dirname."/"]; 
    333         } 
    334         if (isset($vars['gmap']['keys']["http://".$dirname]) && $gmap_key == '') { 
    335                 $gmap_key = $vars['gmap']['keys']["http://".$dirname]; 
    336         } 
    337         if (isset($vars['gmap']['keys']["http://".$dirname."/"]) && $gmap_key == '') { 
    338                 $gmap_key = $vars['gmap']['keys']["http://".$dirname."/"]; 
    339         } 
    340         if ($gmap_key == '') return FALSE; 
    341          
    342         $main->html->head->add_script("text/javascript", htmlspecialchars("http://".$vars['gmap']['server']."/maps?file=api&v=".$vars['gmap']['api']."&key=".$gmap_key."&hl=".$lang["iso639"])); 
     327         
     328         
     329        $serve_host = strtolower($_SERVER['SERVER_NAME']); 
     330        $serve_path = $serve_host.$_SERVER['PHP_SELF']; 
     331        $gmap_key = false; 
     332         
     333        // Loop around all keys to find the most appropriate     
     334        foreach($vars['gmap']['keys'] as $key_path => $key) { 
     335                $key_path = strtolower($key_path); 
     336                 
     337                // remove prefixed http:// 
     338                if (substr($key_path, 0, 7) == 'http://') { 
     339                        $path = substr($key_path, 7); 
     340                } else if (substr($key_path, 0, 8) == 'https://') { 
     341                        $path = substr($key_path, 8); 
     342                } 
     343                 
     344                 
     345                // If host name is not the same then false 
     346                if (substr($key_path, 0, strlen($serve_host)) != $serve_host) 
     347                        continue; 
     348 
     349                // Compare if server_path includes $key_path  
     350                if (substr($serve_path, 0, strlen($key_path)) != $key_path) 
     351                        continue; 
     352                 
     353                $gmap_key = $key; 
     354        }        
     355        $main->html->head->add_script("text/javascript", 
     356                htmlspecialchars("http://{$vars['gmap']['server']}/maps?" . 
     357                        http_build_query(array( 
     358                                'file' => 'api', 
     359                                'v' => $vars['gmap']['api'], 
     360                                'key' => $gmap_key, 
     361                                'hl=' => $lang["iso639"]) 
     362                        ) 
     363                ) 
     364        ); 
    343365        $main->html->head->add_script("text/javascript", $javascript); 
    344366        $main->html->head->add_extra( 
  • trunk/includes/pages/gmap/gmap_fullmap.php

    r245 r246  
    2525        var $tpl; 
    2626         
    27         function gmap() { 
    28  
    29         } 
    30          
    3127        function output() { 
    3228                global $main, $vars; 
     
    3733 
    3834} 
    39  
    40 ?> 
  • trunk/includes/pages/gmap/gmap_js.php

    r169 r246  
    2424        var $tpl; 
    2525 
    26         function gmap_js() { 
    27                  
    28         } 
    29          
    3026        function output() { 
    3127                global $db, $lang, $vars; 
     
    8076} 
    8177 
    82 ?> 
  • trunk/includes/pages/gmap/gmap_pickup_js.php

    r169 r246  
    5757} 
    5858 
    59 ?> 
Note: See TracChangeset for help on using the changeset viewer.