WordPress.org

Plugin Directory

Changeset 537712


Ignore:
Timestamp:
04/28/12 19:22:41 (2 years ago)
Author:
SteveAtty
Message:

Version 2 - Google Maps API V3

Location:
canalplan-ac
Files:
4 added
12 edited
6 copied

Legend:

Unmodified
Added
Removed
  • canalplan-ac/tags/1.0.1/canalplan.php

    r479046 r537712  
    55Plugin URI: http://blogs.canalplan.org.uk/canalplanac/canalplan-plug-in/ 
    66Description: Provides features to integrate your blog with <a href="http://www.canalplan.eu">Canalplan AC</a> - the Canal Route Planner. 
    7 Version: 1.0 
     7Version: 1.0.1 
    88Author: Steve Atty 
    99Author URI: http://blogs.canalplan.org.uk/steve/ 
     
    3131define ('CANALPLAN_GAZ_URL','http://www.canalplan.eu/gazetteer/'); 
    3232define ('CANALPLAN_MAX_POST_PROCESS',20); 
    33 define('CANALPLAN_CODE_RELEASE','0.9.1 r00'); 
     33define('CANALPLAN_CODE_RELEASE','1.0.1 r00'); 
    3434 
    3535global $table_prefix, $wp_version,$wpdb,$db_prefix; 
  • canalplan-ac/tags/1.0.1/readme.txt

    r479046 r537712  
    55Requires at least: 3.0 
    66Tested up to: 3.3 
    7 Stable tag: 1.0 
     7Stable tag: 1.0.1 
    88 
    99== Description == 
     
    5353== Changelog == 
    5454 
     55= Version 1.0.1 22/12/2011 = 
     56- Fixes some odd glitches to do with version numbering. 
     57 
    5558= Version 1.0 22/12/2011 = 
    5659- Checked for WP 3.3 compatability. 
  • canalplan-ac/tags/2.0/admin-pages/cp-admin-diagnostics.php

    r409641 r537712  
    4848        'WordPress' => $wp_version, 
    4949         'PHP' => $phpvers, 
     50         'PHP Memory Limit' => ini_get('memory_limit'), 
     51         'PHP Memory Usage (MB)' => memory_get_usage(true)/1024/1024, 
    5052        'MySQL' => $mysqlvers 
    5153        ); 
  • canalplan-ac/tags/2.0/admin-pages/cp-admin-general.php

    r409641 r537712  
    125125    foreach ($result as $entry) { 
    126126       $sql= "INSERT INTO ".CANALPLAN_CODES." (canalplan_id,place_name,size,lat,`long`,attributes,lat_lng_point) VALUES ('".$entry['id']."','".mysql_real_escape_string($entry['name'])."','".$entry['type']."','".$entry['latitude']."','".$entry['longitude']."','".$entry['attributes']."', GeomFromText('Point(".$entry['latitude']." ".$entry['longitude'].")')) ON DUPLICATE KEY UPDATE place_name='".mysql_real_escape_string($entry['name'])."', size='".$entry['type']."', lat='".$entry['latitude']."', `long`='".$entry['longitude']."', attributes='".$entry['attributes']."', lat_lng_point=GeomFromText('Point(".$entry['latitude']." ".$entry['longitude'].")'); "; 
     127    #var_dump($sql); 
     128#   echo "<br />"; 
    127129       $res = mysql_query($sql); 
    128130    } 
     
    258260 
    259261</div> 
    260 <?php  if (!defined('CANALPLAN_GMAP_KEY')) { ?> 
    261 <hr> 
    262 <h3><?php _e('Google Maps API Key') ?></h3> 
    263 <form action="" name="googleapi" id="googleapi" method="post"> 
    264  
    265 <?php 
    266 $r2 = mysql_query("SELECT pref_value FROM ".CANALPLAN_OPTIONS." where  blog_id=".$blog_id." and pref_code='apikey'"); 
    267 if (mysql_num_rows($r2)==0) { 
    268      $api=""; 
    269 } 
    270 else 
    271 { 
    272     $rw = mysql_fetch_array($r2,MYSQL_ASSOC); 
    273     $api=$rw['pref_value']; 
    274 }  
    275 echo '<input type="text" name="apikey" maxlength="100" size="100" value="'.$api.'">'; 
    276 ?> 
    277 <input type="hidden" name="googleapi" value="1"/> 
    278 <p class="submit"> <input type="submit"  value="Save API Key" /></p> 
    279 </form> 
    280  
    281 <p>You can obtain a Google Map API Key by <a href='http://code.google.com/apis/maps/signup.html'> Signing up for one at Google </a></p> 
    282  
    283 <?php 
    284 } 
    285 ?> 
     262 
    286263<hr> 
    287264 
  • canalplan-ac/tags/2.0/admin-pages/cp-admin-menu.php

    r409641 r537712  
    1818This plugin allows you to integrate your blog with <a href="http://www.canalplan.eu">Canalplan AC</a> 
    1919 
    20 <p><a href="admin.php?page=canalplan/admin-pages/cp-admin-general.php"> General Options </a> <br /> 
     20<p><a href="?page=canalplan/admin-pages/cp-admin-general.php"> General Options </a> <br /> 
    2121This sets up various general options for the Canalplan plugin such as the Canalplan API Key and GoogleMaps API Key</p> 
    22 <p><a href="admin.php?page=canalplan/admin-pages/cp-admin-home.php"> Home Mooring </a><br /> 
     22<p><a href="?page=canalplan/admin-pages/cp-admin-home.php"> Home Mooring </a><br /> 
    2323This allows you to set your home mooring location and give it a customised name </p> 
    24 <p><a href="admin.php?page=canalplan/admin-pages/cp-admin-fav.php"> Favourite Locations </a><br /> 
     24<p><a href="?page=canalplan/admin-pages/cp-admin-fav.php"> Favourite Locations </a><br /> 
    2525This allows you to set up some favourite locations and give them customised names.</p> 
    26 <p><a href="admin.php?page=canalplan/admin-pages/cp-import_route.php"> Import a route from CanalPlan AC </a><br /> 
     26<p><a href="?page=canalplan/admin-pages/cp-admin-google.php"> Google Map Options </a><br /> 
     27This allows you to set up the various options to do with how Google Maps are displayed.</p> 
     28<p><a href="?page=canalplan/admin-pages/cp-import_route.php"> Import a route from CanalPlan AC </a><br /> 
    2729This is the starting point for importing a route from Canalplan AC and creating a set of blog posts for the imported route</p> 
    28 <p><a href="admin.php?page=canalplan/admin-pages/cp-manage_route.php"> Manage Imported Routes </a><br /> 
     30<p><a href="?page=canalplan/admin-pages/cp-manage_route.php"> Manage Imported Routes </a><br /> 
    2931Once you've imported a route you might need to make adjustments to the daily totals - this page allows you to do that</p> 
    30 <p><a href="admin.php?page=canalplan/admin-pages/cp-admin-diagnostics.php"> Diagnostics / Version Information </a><br /> 
     32<p><a href="?page=canalplan/admin-pages/cp-admin-diagnostics.php"> Diagnostics / Version Information </a><br /> 
    3133Provides information and diagnostics - You'll need to refer to this page if you've got problems. 
    3234</p> 
    33 <p><a href="admin.php?page=canalplan/admin-pages/cp-admin-update.php"> Bulk Link Notifier </a><br /> 
     35<p><a href="?page=canalplan/admin-pages/cp-admin-update.php"> Bulk Link Notifier </a><br /> 
    3436During normal use the Canalplan AC website will learn about links from you blog back to it's gazetteer. However if you've just added a set of posts you might want to let Canalplan AC know about all the links. 
    3537</p> 
  • canalplan-ac/tags/2.0/canalplan.php

    r479046 r537712  
    11<?php 
    2  
    32/* 
    4 Plugin Name: CanalPlan AC Integration 
     3Plugin Name: CanalPlan Integration 
    54Plugin URI: http://blogs.canalplan.org.uk/canalplanac/canalplan-plug-in/ 
    65Description: Provides features to integrate your blog with <a href="http://www.canalplan.eu">Canalplan AC</a> - the Canal Route Planner. 
    7 Version: 1.0 
     6Version: 2.0 
    87Author: Steve Atty 
    98Author URI: http://blogs.canalplan.org.uk/steve/ 
     
    2625 * Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    2726*/ 
    28  
    2927@include("multisite.php"); 
    3028define ('CANALPLAN_URL','http://www.canalplan.eu/cgi-bin/'); 
    3129define ('CANALPLAN_GAZ_URL','http://www.canalplan.eu/gazetteer/'); 
    3230define ('CANALPLAN_MAX_POST_PROCESS',20); 
    33 define('CANALPLAN_CODE_RELEASE','0.9.1 r00'); 
     31define('CANALPLAN_CODE_RELEASE','2.0.0 r00'); 
    3432 
    3533global $table_prefix, $wp_version,$wpdb,$db_prefix; 
    3634# Determine the right table prefix to use 
    37 $cp_table_prefix=$table_prefix; 
     35$cp_table_prefix=$wpdb->base_prefix; 
    3836if (isset ($db_prefix) ) { $cp_table_prefix=$db_prefix;} 
    3937 
     
    5553                $numb = ~$numb; 
    5654        } 
    57  
    5855        return ascii_encode_helper($numb); 
    5956 
     
    7067        $string .= pack("C", $numb+63); 
    7168        return str_replace("\\","\\\\",$string); 
    72  
    7369} 
    7470 
     
    130126            $dist_text.= $wholemiles.$miletext.$furltext; 
    131127    } 
    132  
    133128    if ($locks ==1) {$dist_text.=" and 1 lock";} 
    134129    if ($locks >1) {$dist_text.=" and ".$locks." locks";} 
     
    136131} 
    137132 
    138 /* Use the admin_menu action to define the custom boxes */ 
    139 add_action('admin_menu', 'myplugin_add_custom_box'); 
    140  
    141 /* Use the save_post action to do something with the data entered */ 
    142 #add_action('save_post', 'myplugin_save_postdata'); 
    143  
    144 /* Adds a custom section to the "advanced" Post and Page edit screens */ 
    145 function myplugin_add_custom_box() { 
    146  
    147  
     133function canalplan_add_custom_box() { 
    148134    add_meta_box( 'myplugin_sectionid', __( 'CanalPlan Tags', 'myplugin_textdomain' ),  
    149135                'myplugin_inner_custom_box', 'post', 'advanced' ); 
     
    154140/* Prints the inner fields for the custom post/page section */ 
    155141function myplugin_inner_custom_box() { 
    156  
    157   // Use nonce for verification 
    158  
    159   echo '<input type="hidden" name="myplugin_noncename" id="myplugin_noncename" value="' .  
    160     wp_create_nonce( plugin_basename(__FILE__) ) . '" />'; 
    161  
    162   // The actual fields for data entry 
    163  
    164 global $wpdb,$blog_id; 
    165 #include("canalplan/canalplanfunct.js"); 
    166 echo '<script type="text/javascript"> var linktype=1; cplogid='.$blog_id.'</script>'; 
    167 echo '<script type="text/javascript" src="/wp-content/plugins/canalplan/canalplan/canalplanfunctions.js" DEFER></script>'; 
    168 echo '<script type="text/javascript" src="/wp-content/plugins/canalplan/canalplan/canalplan_actb.js"></script>'; 
    169 echo "Insert : "; 
    170 $blog_favourites = $wpdb->get_results("SELECT place_name FROM ".CANALPLAN_FAVOURITES." where blog_id=$blog_id order by place_order asc" ); 
    171 if (count($blog_favourites)>0 ){ 
    172 print '<select name="blogfav" onchange="CanalPlanID.value=blogfav.options[blogfav.selectedIndex].value">'; 
    173 print '<option value="" selected>Select Favourite</option>'; 
    174 foreach ($blog_favourites as $fav) { 
    175 print '<option value="'.$fav->place_name.'">'.$fav->place_name.'</option>'; 
    176         } 
    177 print "</select>"; 
    178  
    179 } 
    180 print ' <input type="text" ID="CanalPlanID" align="LEFT" size="50" maxlength="100"/> as'; 
    181 print '  <select name="tagtype" ID="tagtypeID"> <option value="CP" selected>Gazetteer Tag</option> <option value="CPGM">Google Map Tag</option> </select>'; 
    182 print ' <INPUT TYPE="button" name="CPsub" VALUE="Insert tag"  onclick="getCanalPlan(CanalPlanID.value);"/>'; 
    183 print '<script>canalplan_actb(document.getElementById("CanalPlanID"),new Array());</script>'; 
    184 } 
    185  
    186  
    187  
    188 class CanalPlanAutolinker { 
    189  
    190  
    191  
    192     function canal_init() { 
    193     //  add_action('admin_menu', array(__CLASS__, 'canal_add_options_page')); 
    194        add_filter('the_content', array(__CLASS__, 'canal_stats')); 
    195        add_filter('the_content', array(__CLASS__, 'canal_route_maps')); 
    196        add_filter('the_content', array(__CLASS__, 'canal_place_maps')); 
    197        add_filter('the_content', array(__CLASS__, 'canal_link_maps')); 
    198        add_filter('the_content', array(__CLASS__, 'canal_linkify')); 
    199 ; 
    200            global $dogooglemap; 
    201                 $dogooglemap=0; 
    202  
    203     } 
    204  
    205  
    206     function canal_add_options_page() { 
    207         add_options_page( 
    208             'CanalPlan Autolinker Options', 
    209             'CanalPlan Autolinker', 
    210             'manage_options', 
    211             'canalplan-autolinker-options', 
    212             array(__CLASS__, 'canal_options_page')); 
    213     } 
    214  
    215     function canal_route_maps($content,$mapblog_id=NULL,$post_id=NULL,$search=NULL) { 
    216         global $wpdb,$post,$blog_id; 
    217         // First we check the content for tags: 
    218         if (preg_match_all('/' . preg_quote('[[CPRM') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[0]; } 
    219         // If the array is empty then we've no maps so don't do anything! 
    220         if (count($places_array)==0) {return $content;} 
    221                 if (isset($mapblog_id)) {} else { $mapblog_id=$blog_id;} 
    222                 if (isset($post_id)) {} else {$post_id=$post->ID; 
    223                 if (isset($post->blog_id)) {$mapblog_id=$post->blog_id;}} 
    224          
     142    echo '<input type="hidden" name="myplugin_noncename" id="myplugin_noncename" value="' .  
     143        wp_create_nonce( plugin_basename(__FILE__) ) . '" />'; 
     144    global $wpdb,$blog_id; 
     145    echo '<script type="text/javascript"> var linktype=1; cplogid='.$blog_id.'</script>'; 
     146    echo '<script type="text/javascript" src="/wp-content/plugins/canalplan/canalplan/canalplanfunctions.js" DEFER></script>'; 
     147    echo '<script type="text/javascript" src="/wp-content/plugins/canalplan/canalplan/canalplan_actb.js"></script>'; 
     148    echo "Insert : "; 
     149    $blog_favourites = $wpdb->get_results("SELECT place_name FROM ".CANALPLAN_FAVOURITES." where blog_id=$blog_id order by place_order asc" ); 
     150    if (count($blog_favourites)>0 ){ 
     151        print '<select name="blogfav" onchange="CanalPlanID.value=blogfav.options[blogfav.selectedIndex].value">'; 
     152        print '<option value="" selected>Select Favourite</option>'; 
     153        foreach ($blog_favourites as $fav) { 
     154            print '<option value="'.$fav->place_name.'">'.$fav->place_name.'</option>'; 
     155        } 
     156        print "</select>"; 
     157    } 
     158    print ' <input type="text" ID="CanalPlanID" align="LEFT" size="50" maxlength="100"/> as'; 
     159    print '  <select name="tagtype" ID="tagtypeID"> <option value="CP" selected>Gazetteer Tag</option> <option value="CPGM">Google Map Tag</option> </select>'; 
     160    print ' <INPUT TYPE="button" name="CPsub" VALUE="Insert tag"  onclick="getCanalPlan(CanalPlanID.value);"/>'; 
     161    print '<script>canalplan_actb(document.getElementById("CanalPlanID"),new Array());</script>'; 
     162} 
     163 
     164 
     165function canal_init() { 
     166    add_filter('the_content',  'canal_stats'); 
     167    add_filter('the_content',  'canal_route_maps'); 
     168    add_filter('the_content',  'canal_place_maps'); 
     169    add_filter('the_content',  'canal_link_maps'); 
     170    add_filter('the_content',  'canal_linkify'); 
     171    global $dogooglemap; 
     172    $dogooglemap=0; 
     173} 
     174 
     175function canal_route_maps($content,$mapblog_id=NULL,$post_id=NULL,$search=NULL) { 
     176        global $wpdb,$post,$blog_id,$google_map_code,$dogooglemap; 
     177    // First we check the content for tags: 
     178    if (preg_match_all('/' . preg_quote('[[CPRM') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[0]; } 
     179    // If the array is empty then we've no maps so don't do anything! 
     180    if (count($places_array)==0) {return $content;} 
     181        if (isset($mapblog_id)) {} else { $mapblog_id=$blog_id;} 
     182        if (isset($post_id)) {} else {$post_id=$post->ID; 
     183        if (isset($post->blog_id)) {$mapblog_id=$post->blog_id;}} 
    225184    if ( get_query_var('feed') || $search=='Y' )  { 
    226                 $names = array(); 
    227                 $links = array(); 
    228                 foreach ($places_array as $place_code) { 
    229                 $words=split(":",$place_code); 
    230                         $names[] = $place_code; 
    231                         $links[] ="<b>[Google Route Map embedded here]</b>" ; 
    232                 } 
    233                 return str_replace($names,$links , $content); 
    234         } 
    235         // Get the Googlemap global and if its zero (i.e. first time called on the page) put out the googlemap key 
    236         global $dogooglemap; 
    237         $mapstuff="<br />"; 
    238         if ($dogooglemap==0){ 
    239  
    240         } 
    241         // Increment it 
    242         $dogooglemap=$dogooglemap+1; 
    243         // To allow multiple maps per page (for viewing posts by category) append the dogooglemap id to the end of the map div id 
    244         $mapstuff.= '<div id="map'.$dogooglemap.'" style="width: 500px; height: 600px"></div><script type="text/javascript">'; 
    245         $post_id=$post->ID; 
    246              $sql="select distance,`locks`,start_id,end_id from ".CANALPLAN_ROUTE_DAY." where blog_id=".$mapblog_id." and  post_id=".$post_id; 
    247          
     185        $names = array(); 
     186        $links = array(); 
     187        foreach ($places_array as $place_code) { 
     188        $words=split(":",$place_code); 
     189                $names[] = $place_code; 
     190                $links[] ="<b>[Google Route Map embedded here]</b>" ; 
     191        } 
     192        return str_replace($names,$links , $content); 
     193    } 
     194    $mapstuff="<br />"; 
     195    $dogooglemap=$dogooglemap+1; 
     196    $canalplan_options = get_option('canalplan_options'); 
     197    $post_id=$post->ID; 
     198    $sql="select distance,`locks`,start_id,end_id from ".CANALPLAN_ROUTE_DAY." where blog_id=".$mapblog_id." and  post_id=".$post_id; 
     199    $res = mysql_query($sql); 
     200    $row = mysql_fetch_array($res); 
     201    $sql="select totalroute from ".CANALPLAN_ROUTES." cpr, ".CANALPLAN_ROUTE_DAY." crd where cpr.route_id= crd.route_id and cpr.blog_id=crd.blog_id and crd.blog_id=".$mapblog_id." and  crd.post_id=".$post_id; 
     202    $res3 = mysql_query($sql); 
     203    $mid_point=round(mysql_num_rows($res3)/2,PHP_ROUND_HALF_UP); 
     204    $place_count=0; 
     205    $row3 = mysql_fetch_array($res3); 
     206    $places=split(",",$row3[totalroute]); 
     207    $dayroute=array_slice($places,$row[start_id], ($row[end_id] - $row[start_id])+1); 
     208    $pointstring = ""; 
     209    $zoomstring = ""; 
     210    $lat = 0; 
     211    $long = 0; 
     212    $lpoint=""; 
     213    $lpointb1=""; 
     214    $x=3; 
     215    $y=-1; 
     216    $lastid=end($dayroute); 
     217    $firstid=reset($dayroute); 
     218    $turnaround=""; 
     219    $maptype[S]="SATELLITE"; 
     220    $maptype[R]="ROADMAP"; 
     221    $maptype[T]="TERRAIN"; 
     222    $maptype[H]="HYBRID"; 
     223    $options['zoom']=$canalplan_options["canalplan_rm_zoom"]; 
     224    $options['type']=$canalplan_options["canalplan_rm_type"]; 
     225    $options['lat']=53.4; 
     226    $options['long']=-2.8; 
     227    $options['height']=$canalplan_options["canalplan_rm_height"]; 
     228    $options['width']=$canalplan_options["canalplan_rm_width"]; 
     229    $options['rgb']=$canalplan_options["canalplan_rm_r_hex"].$canalplan_options["canalplan_rm_g_hex"].$canalplan_options["canalplan_rm_b_hex"]; 
     230    $options['brush']=$canalplan_options["canalplan_rm_weight"]; 
     231    $words=substr($matches[1][0],1); 
     232    $opts=split(",",$words); 
     233    foreach ($opts as $opt) { 
     234         $opcode=split("=",$opt); 
     235         $options[$opcode[0]]=strtoupper($opcode[1]); 
     236    } 
     237    $mapstuff.= '<div id="map_canvas_'.$dogooglemap.'" style="width: '.$options['width'].'px; height: '.$options['height'].'px"></div>'; 
     238    foreach ($dayroute as $place) { 
     239        $sql2="set names 'utf8';"; 
     240        $zed = mysql_query($sql2); 
     241        $sql="select `lat`,`long`,`place_name` from ".CANALPLAN_CODES." where canalplan_id='".$place."'"; 
    248242        $res = mysql_query($sql); 
    249243        $row = mysql_fetch_array($res); 
    250         $sql="select totalroute from ".CANALPLAN_ROUTES." cpr, ".CANALPLAN_ROUTE_DAY."  crd where cpr.route_id= crd.route_id and cpr.blog_id=crd.blog_id and crd.blog_id=".$mapblog_id." and  crd.post_id=".$post_id; 
    251         $res3 = mysql_query($sql); 
    252         $row3 = mysql_fetch_array($res3); 
    253         $places=split(",",$row3[totalroute]); 
    254         $dayroute=array_slice($places,$row[start_id], ($row[end_id] - $row[start_id])+1); 
     244        if($place_count==$mid_point) { 
     245            $centre_lat=$row[lat]; 
     246            $centre_long=$row[long]; 
     247        }    
     248        $place_count=$place_count+1; 
     249        if ($place==$firstid){ 
     250            $firstname=$row[place_name]; 
     251            $first_lat=$row[lat]; 
     252            $first_long=$row[long]; 
     253        } 
     254        if ($place==$lastid){ 
     255            $lastname=$row[place_name]; 
     256            $last_lat=$row[lat]; 
     257            $last_long=$row[long]; 
     258        } 
     259        $points=$place.",".$row[lat].",".$row[long]; 
     260            $pointx = $row[lat]; 
     261            $pointy = $row[long];; 
     262            $nlat = floor($pointx * 1e5); 
     263            $nlong = floor($pointy * 1e5); 
     264            $pointstring .= ascii_encode($nlat - $lat) . ascii_encode($nlong -  $long); 
     265            $zoomstring .= 'B'; 
     266            $lat = $nlat; 
     267            $long = $nlong; 
     268            $cpoint=$row[place_name].",".$row[lat].",".$row[long]; 
     269            if ($cpoint==$lpointb1) { 
     270            $lpoints=split(",",$lpoint); 
     271            $turnaround.='var marker_turn'.$dogooglemap.'_'.$x.' = new google.maps.Marker({ position: new google.maps.LatLng('.$lpoints[1].','.$lpoints[2].'), map: map'.$dogooglemap.',   title: "Turn Round here  : '.$lpoints[0].'" });'; 
     272            $turnaround.='iconFile = "http://maps.google.com/mapfiles/ms/icons/blue-dot.png"; marker_turn'.$dogooglemap.'_'.$x.'.setIcon(iconFile) ; '; 
     273            $x=$x+1; 
     274        } 
     275        $lpointb1=$lpoint; 
     276        $y=$y+1; 
     277        $lpoint=$cpoint; 
     278    } 
     279 
     280    if ($firstid==$lastid) { 
     281        $markertext='var marker_start'.$dogooglemap.' = new google.maps.Marker({ position: new google.maps.LatLng('.$first_lat.','.$first_long.'), map: map'.$dogooglemap.',   title: "Start / Finish : '.$firstname.'"});'; 
     282        $markertext.='iconFile = "http://maps.google.com/mapfiles/ms/icons/yellow-dot.png"; marker_start'.$dogooglemap.'.setIcon(iconFile) ; '; 
     283    } 
     284    else 
     285    { 
     286        $markertext='var marker_start'.$dogooglemap.' = new google.maps.Marker({ position: new google.maps.LatLng('.$first_lat.','.$first_long.'), map: map'.$dogooglemap.',   title: "Start : '.$firstname.'" });'; 
     287        $markertext.='var marker_stop'.$dogooglemap.' = new google.maps.Marker({ position: new google.maps.LatLng('.$last_lat.','.$last_long.'), map: map'.$dogooglemap.',  title: "Stop : '.$lastname.'" });'; 
     288        $markertext.='iconFile = "http://maps.google.com/mapfiles/ms/icons/green-dot.png"; marker_start'.$dogooglemap.'.setIcon(iconFile) ; '; 
     289        $markertext.='iconFile = "http://maps.google.com/mapfiles/ms/icons/red-dot.png"; marker_stop'.$dogooglemap.'.setIcon(iconFile) ; ';  
     290    } 
     291    $google_map_code.= 'var map_'.$dogooglemap.'_opts = { zoom: '.$options['zoom'].',center: new google.maps.LatLng('.$centre_lat.','.$centre_long.'),'; 
     292        $google_map_code.='  scrollwheel: false, navigationControl: true, mapTypeControl: true, scaleControl: false, draggable: false,'; 
     293        $google_map_code.= ' mapTypeId: google.maps.MapTypeId.'.$maptype[$options['type']].' };'; 
     294        $google_map_code.= 'var map'.$dogooglemap.' = new google.maps.Map(document.getElementById("map_canvas_'.$dogooglemap.'"),map_'.$dogooglemap.'_opts);'; 
     295        $google_map_code.='  var polyOptions'.$dogooglemap.' = {strokeColor: "#'.$options['rgb'].'", strokeOpacity: 1.0,strokeWeight: '.$options['brush'].' }; '; 
     296    $i=1; 
     297    $google_map_code.=' var line'.$dogooglemap.'_'.$i.' = new google.maps.Polyline(polyOptions'.$dogooglemap.');'; 
     298    $google_map_code.=' line'.$dogooglemap.'_'.$i.'.setPath(google.maps.geometry.encoding.decodePath("'.$pointstring.'"));'; 
     299    $google_map_code.=' line'.$dogooglemap.'_'.$i.'.setMap(map'.$dogooglemap.');'; 
     300    $google_map_code.='var bounds'.$dogooglemap.' = new google.maps.LatLngBounds();'; 
     301    $google_map_code.='line'.$dogooglemap.'_'.$i.'.getPath().forEach(function(latLng) {bounds'.$dogooglemap.'.extend(latLng);});'; 
     302    $google_map_code.='map'.$dogooglemap.'.fitBounds(bounds'.$dogooglemap.');'; 
     303    $google_map_code.=$turnaround.$markertext; 
     304    $names = array(); 
     305    $links = array(); 
     306    foreach ($places_array as $place_code) { 
     307    $words=split(":",$place_code); 
     308        $names[] = $place_code; 
     309        $links[] =$mapstuff; 
     310    } 
     311    return str_replace($names,$links , $content); 
     312} 
     313 
     314function canal_link_maps($content) { 
     315     global $wpdb,$post,$dogooglemap,$google_map_code; 
     316    // First we check the content for tags: 
     317        if (preg_match_all('/' . preg_quote('[[CPGMW:') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[1]; } 
     318    // If the array is empty then we've no maps so don't do anything! 
     319    if (count($places_array)==0) {return $content;} 
     320    $canalplan_options = get_option('canalplan_options'); 
     321    if ( get_query_var('feed') || $search=='Y' )  { 
     322        $names = array(); 
     323        $links = array(); 
     324         foreach ($places_array as $place_code) { 
     325            $words=split("\|",$place_code); 
     326                $names[] = "[[CPGMW:" .$place_code . "]]"; 
     327                $links[] = "<b>[Embedded Google Map for ".trim($words[0])."]</b>"; 
     328            } 
     329        return str_replace($names,$links , $content); 
     330    } 
     331        $maptype[S]="SATELLITE"; 
     332        $maptype[R]="ROADMAP"; 
     333        $maptype[T]="TERRAIN"; 
     334        $maptype[H]="HYBRID"; 
     335    foreach ($places_array as $place_code) { 
     336    $options['zoom']=$canalplan_options["canalplan_rm_zoom"]; 
     337    $options['type']=$canalplan_options["canalplan_rm_type"]; 
     338    $options['lat']=53.4; 
     339    $options['long']=-2.8; 
     340    $options['height']=$canalplan_options["canalplan_rm_height"]; 
     341    $options['width']=$canalplan_options["canalplan_rm_width"]; 
     342    $options['rgb']=$canalplan_options["canalplan_rm_r_hex"].$canalplan_options["canalplan_rm_g_hex"].$canalplan_options["canalplan_rm_b_hex"]; 
     343    $options['brush']=$canalplan_options["canalplan_rm_weight"]; 
     344        $mapstuff="<br />"; 
     345        $words=split("\|",$place_code); 
     346        $opts=split(",",$words[2]); 
     347        foreach ($opts as $opt) { 
     348             $opcode=split("=",$opt); 
     349             $options[$opcode[0]]=strtoupper($opcode[1]); 
     350        } 
     351        $dogooglemap=$dogooglemap+1; 
     352        $mapstuff.= '<div id="map_canvas_'.$dogooglemap.'"  style="width: '.$options['width'].'px; height: '.$options['height'].'px"></div>'; 
     353        $post_id=$post->ID; 
     354        unset($missingpoly); 
     355        unset($plines); 
     356        unset($weights); 
     357        unset($polylines); 
     358        $missingpoly[]=$words[1]; 
     359        #$sql=" select lat,`long` from ".CANALPLAN_CODES.' where canalplan_id in (select place1 from '.CANALPLAN_LINK.' where waterway="'.$words[1].'") limit 1'; 
     360    $sql2=' select lat,`long` from '.CANALPLAN_CODES.' where canalplan_id in (select place1 from '.CANALPLAN_LINK.' where waterway in (select id from '.CANALPLAN_CANALS.' where parent="'.$words[1].'" or id="'.$words[1].'")) limit 1'; 
     361        $res = mysql_query($sql2); 
     362         $rw = mysql_fetch_row($res); 
     363        $centre_lat=$rw[0]; 
     364        $centre_long=$rw[1]; 
     365        while ( count($missingpoly)>0 ) { 
     366            reset($missingpoly); 
     367            $sql="select 1 from ".CANALPLAN_POLYLINES." where id='".current($missingpoly)."';"; 
     368            $res = mysql_query($sql); 
     369             $rw = mysql_fetch_row($res); 
     370            if ($rw[0]==1){$polylines[]=current($missingpoly);} 
     371            $sql="select id from ".CANALPLAN_CANALS." where parent='".current($missingpoly)."';"; 
     372            unset($missingpoly2); 
     373            $res = mysql_query($sql); 
     374            while( $rw = mysql_fetch_row($res)){ 
     375                $missingpoly[]=$rw[0]; 
     376            } 
     377    #Get the polyline. If there is one put it into the $polyline[]. 
     378    #Get a list of places where this id is the parent and put them into $missingpoly[] 
     379    #Remove the element from the array 
     380        $missingpoly=array_slice($missingpoly,1); 
     381        } 
     382        $markertext=""; 
     383        $i=1; 
     384            $google_map_code.= 'var map_'.$dogooglemap.'_opts = { zoom: '.$options['zoom'].',center: new google.maps.LatLng('.$centre_lat.','.$centre_long.'),'; 
     385            $google_map_code.='  scrollwheel: false, navigationControl: true, mapTypeControl: true, scaleControl: false, draggable: false,'; 
     386            $google_map_code.= ' mapTypeId: google.maps.MapTypeId.'.$maptype[$options['type']].' };'; 
     387            $google_map_code.= 'var map'.$dogooglemap.' = new google.maps.Map(document.getElementById("map_canvas_'.$dogooglemap.'"),map_'.$dogooglemap.'_opts);'; 
     388            $google_map_code.='  var polyOptions'.$dogooglemap.' = {strokeColor: "#'.$options['rgb'].'", strokeOpacity: 1.0, strokeWeight: '.$options['brush'].' }; '; 
     389        $i=1; 
     390        $google_map_code.='var bounds'.$dogooglemap.' = new google.maps.LatLngBounds();'; 
     391        foreach ($polylines as $polyline) { 
     392            $sql="select pline from ".CANALPLAN_POLYLINES." where id='".$polyline."';";; 
     393            $res = mysql_query($sql); 
     394             $rw = mysql_fetch_row($res);    
     395                $google_map_code.=' var line'.$dogooglemap.'_'.$i.' = new google.maps.Polyline(polyOptions'.$dogooglemap.');'; 
     396            $google_map_code.=' line'.$dogooglemap.'_'.$i.'.setPath(google.maps.geometry.encoding.decodePath("'.$rw[0].'"));'; 
     397            $google_map_code.=' line'.$dogooglemap.'_'.$i.'.setMap(map'.$dogooglemap.');'; 
     398            $google_map_code.='line'.$dogooglemap.'_'.$i.'.getPath().forEach(function(latLng) {bounds'.$dogooglemap.'.extend(latLng);});'; 
     399            $google_map_code.='map'.$dogooglemap.'.fitBounds(bounds'.$dogooglemap.');'; 
     400            $i=$i+1; 
     401        } 
     402            $names[] = "[[CPGMW:" .$place_code . "]]"; 
     403            $links[] = $mapstuff;    
     404        } 
     405    return str_ireplace($matches[0], $links, $content); 
     406} 
     407 
     408function canal_place_maps($content,$mapblog_id=NULL,$post_id=NULL) { 
     409    $gazstring=CANALPLAN_URL.'gazetteer.cgi?id='; 
     410    $canalplan_options = get_option('canalplan_options'); 
     411    #var_dump($canalplan_options); 
     412        if (preg_match_all('/' . preg_quote('[[CPGM:') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[1]; } 
     413        // If the array is empty then we've no links so don't do anything! 
     414    if (count($places_array)==0) {return $content;} 
     415    if (isset($mapblog_id)) {} else { $mapblog_id=$wpdb->blogid;} 
     416    if (isset($post_id)) {} else {$post_id=$post->ID; 
     417        if (isset($post->blog_id)) {$mapblog_id=$post->blog_id;}} 
     418        $names = array(); 
     419        $links = array(); 
     420        global $dogooglemap,$wpdb,$post,$google_map_code; 
     421        if ( get_query_var('feed')) { 
     422            foreach ($places_array as $place_code) { 
     423            $words=split("\|",$place_code); 
     424            $names[] = "[[CPGM:" .$place_code . "]]"; 
     425            $links[] = "<b>[Embedded Google Map for ".trim($words[0])."]</b>"; 
     426        } 
     427        return str_ireplace($names, $links, $content); 
     428        } 
     429        $maptype[S]="SATELLITE"; 
     430        $maptype[R]="ROADMAP"; 
     431        $maptype[T]="TERRAIN"; 
     432        $maptype[H]="HYBRID"; 
     433    foreach ($places_array as $place_code) { 
     434        $words=split("\|",$place_code); 
     435        $sql="select lat,`long` from ".CANALPLAN_CODES." where canalplan_id='".$words[1]."'"; 
     436        $res = mysql_query($sql); 
     437            $row = mysql_fetch_array($res); 
     438        $options['zoom']=$canalplan_options["canalplan_pm_zoom"]; 
     439        $options['type']=$canalplan_options["canalplan_pm_type"]; 
     440        $options['lat']=$row[lat]; 
     441        $options['long']=$row[long]; 
     442        $options['height']=$canalplan_options["canalplan_pm_height"]; 
     443        $options['width']=$canalplan_options["canalplan_pm_width"]; 
     444        $opts=split(",",$words[2]); 
     445        foreach ($opts as $opt) { 
     446             $opcode=split("=",$opt); 
     447             $options[$opcode[0]]=strtoupper($opcode[1]); 
     448        } 
     449            $mapstuff="<br />"; 
     450            $dogooglemap=$dogooglemap+1; 
     451        $mapstuff= '<div id="map_canvas_'.$dogooglemap.'" style="width: '.$options['width'].'px; height: '.$options['height'].'px"></div> '; 
     452        $names[] = "[[CPGM:" .$place_code . "]]"; 
     453        $links[] = $mapstuff; 
     454        $google_map_code.= 'var map_'.$dogooglemap.'_opts = { zoom: '.$options['zoom'].',center: new google.maps.LatLng('.$options['lat'].','.$options['long'].'),'; 
     455        $google_map_code.='  scrollwheel: false, navigationControl: true, mapTypeControl: true, scaleControl: false, draggable: false,'; 
     456        $google_map_code.= ' mapTypeId: google.maps.MapTypeId.'.$maptype[$options['type']].' };'; 
     457        $google_map_code.= 'var map'.$dogooglemap.' = new google.maps.Map(document.getElementById("map_canvas_'.$dogooglemap.'"),map_'.$dogooglemap.'_opts);'; 
     458        $google_map_code.= 'var marker'.$dogooglemap.' = new google.maps.Marker({ position: new google.maps.LatLng('.$options['lat'].','.$options['long'].'), map: map'.$dogooglemap.', title: "'.$words[0].'"  });  '; 
     459        } 
     460    return str_ireplace($matches[0], $links, $content); 
     461} 
     462 
     463function canal_stats($content,$mapblog_id=NULL,$post_id=NULL) { 
     464    global $blog_id,$wpdb,$post; 
     465    if (preg_match_all('/' . preg_quote('[[CPRS') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[0]; } 
     466    if (count($places_array)==0) {return $content;} 
     467    if (isset($mapblog_id)) {} else { $mapblog_id=$blog_id;} 
     468    if (isset($post_id)) {} else {$post_id=$post->ID; 
     469    if (isset($post->blog_id)) {$mapblog_id=$post->blog_id;}} 
     470    $sql="select distance,`locks`,start_id,end_id from ".CANALPLAN_ROUTE_DAY." where blog_id=".$mapblog_id." and  post_id=".$post_id; 
     471    $res = mysql_query($sql); 
     472    $row = mysql_fetch_array($res); 
     473    $sql="select totalroute,uom from ".CANALPLAN_ROUTES." cpr, ".CANALPLAN_ROUTE_DAY." crd where cpr.route_id= crd.route_id and cpr.blog_id=crd.blog_id and crd.blog_id=".$mapblog_id." and  crd.post_id=".$post_id; 
     474    $res3 = mysql_query($sql); 
     475    $row3 = mysql_fetch_array($res3); 
     476    $dformat=$row3[uom]; 
     477    $places=split(",",$row3[totalroute]); 
     478    $sql2="set names 'utf8';"; 
     479    $zed = mysql_query($sql2); 
     480    $sql="select place_name from ".CANALPLAN_FAVOURITES." where canalplan_id='".$places[$row[start_id]]."' and blog_id=".$mapblog_id." union select place_name from ".CANALPLAN_CODES." where canalplan_id='".$places[$row[start_id]]."' and canalplan_id not in (select canalplan_id from ".CANALPLAN_FAVOURITES." where canalplan_id='".$places[$row[start_id]]."' and blog_id=".$mapblog_id.")"; 
     481    $res2 = mysql_query($sql); 
     482    $row2 = mysql_fetch_array($res2); 
     483    $start_name=$row2[place_name]; 
     484    $sql="select place_name from ".CANALPLAN_FAVOURITES." where canalplan_id='".$places[$row[end_id]]."' and blog_id=".$mapblog_id." union select place_name from ".CANALPLAN_CODES." where canalplan_id='".$places[$row[end_id]]."' and canalplan_id not in (select canalplan_id from ".CANALPLAN_FAVOURITES." where canalplan_id='".$places[$row[end_id]]."' and blog_id=".$mapblog_id.")"; 
     485    $res2 = mysql_query($sql); 
     486    $row2 = mysql_fetch_array($res2); 
     487    $end_name=$row2[place_name]; 
     488    $names = array(); 
     489    $links = array(); 
     490    foreach ($places_array as $place_code) { 
     491    $words=split(":",$place_code); 
     492        $names[] = $place_code; 
     493        $links[] = "From [[CP:".$start_name."|".$places[$row[start_id]]."]] to [[CP:".$end_name."|".$places[$row[end_id]]."]], ".format_distance($row[distance],$row[locks],$dformat,2); 
     494    } 
     495    return str_ireplace($names, $links, $content); 
     496} 
     497 
     498function canal_linkify($content) { 
     499    global $post,$blog_id; 
     500    // First we check the content for tags: 
     501    if (preg_match_all('/' . preg_quote('[[CP') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[1]; } 
     502    // If the array is empty then we've no links so don't do anything! 
     503    #if (count($places_array)==0) {return $content;} 
     504    $names = array(); 
     505    $links = array(); 
     506    if (preg_match_all('/' . preg_quote('[[CP:') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) {  
     507        $places_array=$matches[1];  
     508        $gazstring=CANALPLAN_URL.'gazetteer.cgi?id='; 
     509        $x="SELECT pref_value FROM ".CANALPLAN_OPTIONS." where  blog_id=".$blog_id." and pref_code='canalkey'"; 
     510        $r2 = mysql_query("SELECT pref_value FROM ".CANALPLAN_OPTIONS." where  blog_id=".$blog_id." and pref_code='canalkey'"); 
     511        if (mysql_num_rows($r2)==0) { 
     512             $api=""; 
     513        } 
     514        else 
     515        { 
     516            $rw = mysql_fetch_array($r2,MYSQL_ASSOC); 
     517            $api=explode("|",$rw['pref_value']); 
     518            $blog_url=get_bloginfo('url'); 
     519            $date = date("Ymd",strtotime($post->post_date)); 
     520            $link=urlencode(str_replace($blog_url,"",get_permalink($post->ID))); 
     521            $title=urlencode($post->post_title); 
     522        }  
     523        foreach ($places_array as $place_code) { 
     524            $words=split("\|",$place_code); 
     525            $names[] = "[[CP:" .$place_code . "]]"; 
     526            if ($api[0]=="") { 
     527                $links[] = "<a href='".CANALPLAN_GAZ_URL.$words[1]."' target='gazetteer'  title='Link to ".trim($words[0])."'>".trim($words[0])."</a>"; 
     528            } 
     529             else  
     530            { 
     531                $links[] = "<a href='". CANALPLAN_GAZ_URL .$words[1]. "?blogkey=".$api[0]."&title=".$title."&blogid=".$api[1]."&date=".$date."&url=".$link."' target='gazetteer' title='Link to ".trim($words[0])."'>".trim($words[0])."</a>"; 
     532            } 
     533        } 
     534    } 
     535    if (preg_match_all('/' . preg_quote('[[CPW:') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) {  
     536        $places_array=$matches[1];  
     537        $gazstring=CANALPLAN_URL.'waterway.cgi?id='; 
     538        foreach ($places_array as $place_code) { 
     539        $words=split("\|",$place_code); 
     540            $names[] = "[[CPW:" .$place_code . "]]"; 
     541            $links[] = "<a href='".$gazstring.$words[1]."' target='gazetteer'  title='Link to ".trim($words[0])."'>".trim($words[0])."</a>"; 
     542        } 
     543    } 
     544    return str_ireplace($names, $links, $content); 
     545} 
     546 
     547function canal_options_page() { 
     548    global $wpdb; 
     549    if (!current_user_can('manage_options')) { 
     550        die('You don&#8217;t have sufficient permission to access this file.'); 
     551    } 
     552    if (isset($_POST['update'])) { 
     553        check_admin_referer('canalplan-autolinker-update-options'); 
     554        update_option('canalplan-autolinker-begin', $wpdb->escape($_POST['begin'])); 
     555        update_option('canalplan-autolinker-end', $wpdb->escape($_POST['end'])); 
     556        echo '<div id="message" class="updated fade"><p><strong>Options saved.</strong></p></div>'; 
     557    } 
     558} 
     559 
     560function blroute(){ 
     561    $routeid = $_REQUEST['routeid']; 
     562    $routeid = preg_replace('{/$}', '', $routeid); 
     563    if (!isset($routeid)){$routeid=0;} 
     564    if ($routeid<=0){$routeid=0;} 
     565    global $wpdb,$blog_id,$google_map_code,$dogooglemap; 
     566    $dogooglemap=1; 
     567    $blroute=""; 
     568    $canalplan_options = get_option('canalplan_options'); 
     569    #var_dump($canalplan_options); 
     570    if ($routeid==0){ 
     571        #$blroute .="<h2>Available Trip Reports</h2>"; 
     572        $sql2="set names 'utf8';"; 
     573        $zed = mysql_query($sql2); 
     574        if ($wpdb->blogid==1) { 
     575            $sql="select route_id,title,blog_id from ".CANALPLAN_ROUTES." where status=3"; 
     576        } 
     577        else 
     578        { 
     579            $sql="select route_id, title,description,blog_id from ".CANALPLAN_ROUTES." where status=3 and blog_id=$blog_id"; 
     580        } 
     581        if (!defined('CANALPLAN_ROUTE_SLUG')){ 
     582            $r2 = mysql_query("SELECT pref_value FROM ".CANALPLAN_OPTIONS." where blog_id=-1 and pref_code='routeslug'"); 
     583            if (mysql_num_rows($r2)==0) { 
     584                     $routeslug="UNDEFINED!"; 
     585            } 
     586            else 
     587            { 
     588                while($rw = mysql_fetch_array($r2)) 
     589                { 
     590                    $routeslug=$rw['pref_value']; 
     591                } 
     592            }  
     593        }  
     594        else { 
     595            $routeslug=CANALPLAN_ROUTE_SLUG; 
     596        } 
     597        $res = mysql_query($sql); 
     598        $blroute .="<ol>"; 
     599        while ($row = mysql_fetch_array($res)) { 
     600            if ($wpdb->blogid==1) {$blroute .='<li><a href='.get_blog_option($row[blog_id],"siteurl").'/'.$routeslug.'/'.$row[route_id].' target=\"_new\">'.$row[title].'</a> ( from '. get_blog_option($row[blog_id],'blogname').' )  </li>'; 
     601            } 
     602            else 
     603            { 
     604                $blroute .='<li><a href='.get_blog_option($row[blog_id],"siteurl").'/'.$routeslug.'/'.$row[route_id].' target=\"_new\">'.$row[title].'</a> ('.$row[description].')</li>'; 
     605            } 
     606        } 
     607        $blroute .="</ol><br><br>"; 
     608    } 
     609    else 
     610    { 
     611        $sql2="set names 'utf8';"; 
     612        $zed = mysql_query($sql2); 
     613        $sql="select description, totalroute from ".CANALPLAN_ROUTES." where route_id=".$routeid." and blog_id=".$wpdb->blogid; 
     614        $res = mysql_query($sql); 
     615        $mid_point=round(mysql_num_rows($res)/2,PHP_ROUND_HALF_UP); 
     616        $place_count=0; 
     617        $row = mysql_fetch_array($res); 
     618        $blroute .="<h2>".$row[description]."</h2><br/>"; 
     619        $blroute.='<div id="map_canvas_'.$dogooglemap.'"  style="width: '.$canalplan_options["canalplan_rm_width"].'px; height: '.$canalplan_options["canalplan_rm_height"].'px"></div>'; 
     620        #$blroute.='<div id="map_canvas_'.$dogooglemap.'" style="width: 500px; height: 600px"></div> '; 
    255621        $pointstring = ""; 
    256622        $zoomstring = ""; 
     
    261627        $x=3; 
    262628        $y=-1; 
    263         $lastid=end($dayroute); 
    264         $firstid=reset($dayroute); 
     629        $places=split(",",$row[totalroute]); 
     630        $lastid=end($places); 
     631        $firstid=reset($places); 
    265632        $turnaround=""; 
    266         foreach ($dayroute as $place) { 
    267 $sql2="set names 'utf8';"; 
    268 $zed = mysql_query($sql2); 
    269         $sql="select `lat`,`long`,`place_name` from ".CANALPLAN_CODES." where canalplan_id='".$place."'"; 
    270         $res = mysql_query($sql); 
    271         $row = mysql_fetch_array($res); 
    272         if ($place==$firstid){$firstname=$row[place_name];} 
    273         if ($place==$lastid){$lastname=$row[place_name];} 
    274         $points=$place.",".$row[lat].",".$row[long]; 
    275               $pointx = $row[lat]; 
    276                 $pointy = $row[long];; 
    277                 $nlat = floor($pointx * 1e5); 
    278                 $nlong = floor($pointy * 1e5); 
    279                 $pointstring .= ascii_encode($nlat - $lat) . ascii_encode($nlong - 
    280         $long); 
    281                 $zoomstring .= 'B'; 
    282                 $lat = $nlat; 
    283                 $long = $nlong; 
    284                 $cpoint=$row[place_name].",".$row[lat].",".$row[long]; 
    285                 if ($cpoint==$lpointb1) { 
    286             $lpoints=split(",",$lpoint); 
    287         $turnaround.='var marker'.$dogooglemap.$x.' = new GMarker(encodedPolyline.getVertex('.$y.'),{icon:icon2, draggable: false, title: "Turn Round here : '.$lpoints[0].'"});'; 
    288         $turnaround.='map'.$dogooglemap.'.addOverlay(marker'.$dogooglemap.$x.');'; 
    289          $x=$x+1; 
    290         } 
    291         $lpointb1=$lpoint; 
    292         $y=$y+1; 
    293         $lpoint=$cpoint; 
    294         } 
     633        $mapstuff='<div id="map_canvas_'.$dogooglemap.'"  style="width: '.$canalplan_options["canalplan_rm_width"].'px; height: '.$canalplan_options["canalplan_rm_height"].'px"></div>'; 
     634        foreach ($places as $place) { 
     635            $sql="select `lat`,`long`,`place_name` from ".CANALPLAN_CODES." where canalplan_id='".$place."'"; 
     636            $res = mysql_query($sql); 
     637            $row = mysql_fetch_array($res); 
     638            if ($place==$firstid){ 
     639                $firstname=$row[place_name]; 
     640                $first_lat=$row[lat]; 
     641                $first_long=$row[long]; 
     642            } 
     643            if ($place==$lastid){ 
     644                $lastname=$row[place_name]; 
     645                $last_lat=$row[lat]; 
     646                $last_long=$row[long]; 
     647            } 
     648            if($place_count==$mid_point) { 
     649                $centre_lat=$row[lat]; 
     650                $centre_long=$row[long]; 
     651            }    
     652            $place_count=$place_count+1; 
     653            $points=$place.",".$row[lat].",".$row[long]; 
     654                $pointx = $row[lat]; 
     655            $pointy = $row[long]; 
     656            $nlat = floor($pointx * 1e5); 
     657            $nlong = floor($pointy * 1e5); 
     658            $pointstring .= ascii_encode($nlat - $lat) . ascii_encode($nlong - $long); 
     659            $zoomstring .= 'B'; 
     660            $lat = $nlat; 
     661            $long = $nlong; 
     662            $cpoint=$row[place_name].",".$row[lat].",".$row[long]; 
     663            if ($cpoint==$lpointb1) { 
     664                $lpoints=split(",",$lpoint); 
     665                $turnaround.='var marker_turn'.$dogooglemap.'_'.$x.' = new google.maps.Marker({ position: new google.maps.LatLng('.$lpoints[1].','.$lpoints[2].'), map: map'.$dogooglemap.',   title: "Turn Round here  : '.$lpoints[0].'" });'; 
     666                $turnaround.='iconFile = "http://maps.google.com/mapfiles/ms/icons/blue-dot.png"; marker_turn'.$dogooglemap.'_'.$x.'.setIcon(iconFile) ; '; 
     667                $x=$x+1; 
     668            } 
     669            $lpointb1=$lpoint; 
     670            $y=$y+1; 
     671            $lpoint=$cpoint; 
     672            } 
    295673        if ($firstid==$lastid) { 
    296             $markertext='var marker'.$dogooglemap.'0 = new GMarker(encodedPolyline.getVertex(0), {icon:icon0, draggable: false, title: "Start/Finish : '.$firstname.'"});'; 
    297             $markertext.='map'.$dogooglemap.'.addOverlay(marker'.$dogooglemap.'0);'; 
     674            $markertext='var marker_start'.$dogooglemap.' = new google.maps.Marker({ position: new google.maps.LatLng('.$first_lat.','.$first_long.'), map: map'.$dogooglemap.',   title: "Start / Finish : '.$firstname.'"});'; 
     675            $markertext.='iconFile = "http://maps.google.com/mapfiles/ms/icons/yellow-dot.png"; marker_start'.$dogooglemap.'.setIcon(iconFile) ; '; 
    298676        } 
    299677        else 
    300678        { 
    301             $markertext='var marker'.$dogooglemap.'0 = new GMarker(encodedPolyline.getVertex(0), {icon:icon0, draggable: false, title: "Start : '.$firstname.'"});'; 
    302             $markertext.='var marker'.$dogooglemap.'1 = new GMarker(encodedPolyline.getVertex(encodedPolyline.getVertexCount()-1), {icon:icon1, draggable: false, title:"Finish : '.$lastname.'"});'; 
    303             $markertext.='map'.$dogooglemap.'.addOverlay(marker'.$dogooglemap.'0);'; 
    304             $markertext.='map'.$dogooglemap.'.addOverlay(marker'.$dogooglemap.'1);'; 
    305         } 
    306  
    307          $page2= ' if (GBrowserIsCompatible()) {            if(document.implementation.hasFeature( "http://www.w3.org/TR/SVG11/feature#SVG","1.1")){  _mSvgEnabled = true;  _mSvgForced  = true;}'; 
    308          $page2.= ' var map'.$dogooglemap.' = new GMap2(document.getElementById("map'.$dogooglemap.'")); map'.$dogooglemap.'.setCenter(new GLatLng(52.97035617,-2.508565798), 9); map'.$dogooglemap.'.addControl(new GSmallMapControl());   map'.$dogooglemap.'.addControl(new GMapTypeControl());  map'.$dogooglemap.'.setMapType(G_NORMAL_MAP); map'.$dogooglemap.'.setZoom(9);'; 
    309                  $page2.='var ads'.$dogooglemap.' = new GAdsManager(map'.$dogooglemap.',"pub-4296098225870941",{maxAdsOnMap : 10, style: "icon", channel: "5900391315" , minZoomLevel: 0}); ads'.$dogooglemap.'.enable();'; 
    310          $page2.= ' var baseIcon = new GIcon(); baseIcon.shadow = "/wp-content/plugins/canalplan/canalplan/markers/shadow.png"; baseIcon.iconSize = new GSize(12, 20);  baseIcon.shadowSize = new GSize(22, 20);    baseIcon.iconAnchor = new GPoint(6, 20);    baseIcon.infoWindowAnchor = new GPoint(9, 2);   baseIcon.infoShadowAnchor = new GPoint(18, 25);'; 
    311          $page2.= ' var icon0 = new GIcon(baseIcon); var icon1 = new GIcon(baseIcon);       var icon2 = new GIcon(baseIcon); '; 
    312          $page2.= ' icon0.image = "/wp-content/plugins/canalplan/canalplan/markers/small_green.png"; icon1.image = "/wp-content/plugins/canalplan/canalplan/markers/small_red.png"; icon2.image = "/wp-content/plugins/canalplan/canalplan/markers/small_yellow.png";'; 
    313        $page2.= ' var encodedPolyline = new GPolyline.fromEncoded({    color: "#0000FF",   weight: 2, opacity: 0.8, points: "'.$pointstring.'",    levels: "'.$zoomstring.'",zoomFactor: 32, numLevels: 4 });'; 
    314          $page2.= ' map'.$dogooglemap.'.addOverlay(encodedPolyline);    var bounds = new GLatLngBounds(); for (var i=0; i<encodedPolyline.getVertexCount()-1; i++) {  bounds.extend(encodedPolyline.getVertex(i));}'; 
    315          $page2.= '  var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat())/2; var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng())/2;    map'.$dogooglemap.'.setCenter(new GLatLng(clat,clng)); map'.$dogooglemap.'.setZoom(map'.$dogooglemap.'.getBoundsZoomLevel(bounds));}'; 
    316  
    317 $page2.=$turnaround.$markertext."</script> <br />"; 
    318  
    319  
    320         $names = array(); 
    321         $links = array(); 
    322         foreach ($places_array as $place_code) { 
    323         $words=split(":",$place_code); 
    324             $names[] = $place_code; 
    325             $links[] =$mapstuff.$page2 ; 
    326         } 
    327         return str_replace($names,$links , $content); 
    328     } 
    329  
    330 // Link Maps 
    331  
    332     function canal_link_maps($content) { 
    333         global $wpdb; 
    334         global $post; 
    335         // First we check the content for tags: 
    336                 if (preg_match_all('/' . preg_quote('[[CPGMW:') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[1]; } 
    337         // If the array is empty then we've no maps so don't do anything! 
    338         if (count($places_array)==0) {return $content;} 
    339          
    340     if ( get_query_var('feed') || $search=='Y' )  { 
    341                 $names = array(); 
    342                 $links = array(); 
    343                  foreach ($places_array as $place_code) { 
    344                 $words=split("\|",$place_code); 
    345                     $names[] = "[[CPGMW:" .$place_code . "]]"; 
    346                     $links[] = "<b>[Embedded Google Map for ".trim($words[0])."]</b>"; 
    347         } 
    348                 return str_replace($names,$links , $content); 
    349         } 
    350  
    351         // Get the Googlemap global and if its zero (i.e. first time called on the page) put out the googlemap key 
    352         global $dogooglemap; 
    353  
    354         $maptype[s]="G_SATELLITE_MAP"; 
    355         $maptype[n]="G_NORMAL_MAP"; 
    356         $maptype[h]="G_HYBRID_MAP"; 
    357         foreach ($places_array as $place_code) { 
    358         $mapstuff="<br />"; 
    359         $words=split("\|",$place_code); 
    360         if ($dogooglemap==0){ 
    361  
    362         } 
    363         // Increment it 
    364         $dogooglemap=$dogooglemap+1; 
    365         // To allow multiple maps per page (for viewing posts by category) append the dogooglemap id to the end of the map div id 
    366         $mapstuff.= '<div id="map'.$dogooglemap.'" style="width: 500px; height: 600px"></div><script type="text/javascript">'; 
    367         $post_id=$post->ID; 
    368  
    369 unset($missingpoly); 
    370 unset($plines); 
    371 unset($weights); 
    372 unset($polylines); 
    373 $missingpoly[]=$words[1]; 
    374 while ( count($missingpoly)>0 ) { 
    375         reset($missingpoly); 
    376 #print "<br>".count($missingpoly)." - "; 
    377 #var_dump($missingpoly); 
    378         $sql="select 1 from ".CANALPLAN_POLYLINES." where id='".current($missingpoly)."';"; 
    379         #print $sql."<br>"; 
    380         $res = mysql_query($sql); 
    381          $rw = mysql_fetch_row($res); 
    382        # print "!!".$rw[0]."H"; 
    383 if ($rw[0]==1){$polylines[]=current($missingpoly);} 
    384         $sql="select id from ".CANALPLAN_CANALS." where parent='".current($missingpoly)."';"; 
    385        # print $sql; 
    386         unset($missingpoly2); 
    387         $res = mysql_query($sql); 
    388         while( $rw = mysql_fetch_row($res)){ 
    389         #print $rw[0]." - "; 
    390         $missingpoly[]=$rw[0]; 
    391 } 
    392 #Get the polyline. If there is one put it into the $polyline[]. 
    393 #Get a list of places where this id is the parent and put them into $missingpoly[] 
    394 #Remove the element from the array 
    395 $missingpoly=array_slice($missingpoly,1); 
    396 #$missingpoly=array_merge($missingpoly,$missingpoly2); 
    397 } 
    398 $markertext=""; 
    399 #var_dump($polylines); 
    400 foreach ($polylines as $polyline) { 
    401         $sql="select pline,weights from ".CANALPLAN_POLYLINES." where id='".$polyline."';"; 
    402        # print $sql."<br>"; 
    403         $res = mysql_query($sql); 
    404          $rw = mysql_fetch_row($res); 
    405 $plines[]=$rw[0]; 
    406 $weights[]=$rw[1]; 
    407 } 
    408 #var_dump($plines); 
    409  
    410  
    411         $page2= ' if (GBrowserIsCompatible()) { if(document.implementation.hasFeature( "http://www.w3.org/TR/SVG11/feature#SVG","1.1")){  _mSvgEnabled = true;  _mSvgForced  = true;}'; 
    412         $page2.= ' var map'.$dogooglemap.' = new GMap2(document.getElementById("map'.$dogooglemap.'")); map'.$dogooglemap.'.setCenter(new GLatLng(52.97035617,-2.508565798), 9); map'.$dogooglemap.'.addControl(new GSmallMapControl());    map'.$dogooglemap.'.addControl(new GMapTypeControl());  map'.$dogooglemap.'.setMapType(G_NORMAL_MAP); map'.$dogooglemap.'.setZoom(9);'; 
    413                 $page2.='var globalbounds = new GLatLngBounds(); var ads'.$dogooglemap.' = new GAdsManager(map'.$dogooglemap.',"pub-4296098225870941",{maxAdsOnMap : 10, style: "icon", channel: "5900391315", minZoomLevel: 0}); ads'.$dogooglemap.'.enable();'; 
    414         $page2.= ' var baseIcon = new GIcon(); baseIcon.shadow = "/wp-content/plugins/canalplan/canalplan/markers/shadow.png";  baseIcon.iconSize = new GSize(12, 20);  baseIcon.shadowSize = new GSize(22, 20);    baseIcon.iconAnchor = new GPoint(6, 20);    baseIcon.infoWindowAnchor = new GPoint(9, 2);   baseIcon.infoShadowAnchor = new GPoint(18, 25);'; 
    415         $page2.= ' var icon0 = new GIcon(baseIcon); var icon1 = new GIcon(baseIcon);        var icon2 = new GIcon(baseIcon); '; 
    416         $page2.= ' icon0.image = "/wp-content/plugins/canalplan/canalplan/markers/small_green.png"; icon1.image = "/wp-content/plugins/canalplan/canalplan/markers/small_red.png"; icon2.image = "/wp-content/plugins/canalplan/canalplan/markers/small_yellow.png";'; 
    417 for ($i=0;$i<count($plines);$i++){ 
    418                 $page2.= ' var encodedPolyline = new GPolyline.fromEncoded({    color: "#0000ff",   weight: 3, opacity: 0.8, points: "'.$plines[$i].'",    levels: "'.$weights[$i].'",zoomFactor: 32, numLevels: 4 });'; 
    419         $page2.= ' map'.$dogooglemap.'.addOverlay(encodedPolyline); '; 
    420         $page2.=' var marker'.$dogooglemap.'0'.$i.'= new GMarker(encodedPolyline.getVertex(0), {icon:icon0, draggable: false});'; 
    421         $page2.=' var marker'.$dogooglemap.'1'.$i.' = new GMarker(encodedPolyline.getVertex(encodedPolyline.getVertexCount()-1), {icon:icon0, draggable: false});'; 
    422         $page2.=' map'.$dogooglemap.'.addOverlay(marker'.$dogooglemap.'0'.$i.');'; 
    423             $page2.=' map'.$dogooglemap.'.addOverlay(marker'.$dogooglemap.'1'.$i.');'; 
    424         $page2.= 'for (var i=0; i<encodedPolyline.getVertexCount()-1; i++) {  globalbounds.extend(encodedPolyline.getVertex(i));} '; 
    425 } 
    426  
    427                 $page2.='var clat = (globalbounds.getNorthEast().lat() + globalbounds.getSouthWest().lat())/2; var clng = (globalbounds.getNorthEast().lng() + globalbounds.getSouthWest().lng())/2;    map' .$dogooglemap.'.setCenter(new GLatLng(clat,clng)); map'.$dogooglemap.'.setZoom(map'.$dogooglemap.'.getBoundsZoomLevel(globalbounds));}'; 
    428  
    429  
    430 $page2.=$turnaround.$markertext."</script> <br />"; 
    431       $names[] = "[[CPGMW:" .$place_code . "]]"; 
    432       $links[] = $mapstuff.$page2; 
    433       } 
    434  
    435 return str_ireplace($matches[0], $links, $content); 
    436     } 
    437  
    438  
    439 function canal_place_maps($content,$mapblog_id=NULL,$post_id=NULL) { 
    440 $gazstring=CANALPLAN_URL.'gazetteer.cgi?id='; 
    441     // First we check the content for tags: 
    442     if (preg_match_all('/' . preg_quote('[[CPGM:') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[1]; } 
    443  
    444     // If the array is empty then we've no links so don't do anything! 
    445     if (count($places_array)==0) {return $content;} 
    446  
    447 if (isset($mapblog_id)) {} else { $mapblog_id=$wpdb->blogid;} 
    448 if (isset($post_id)) {} else {$post_id=$post->ID; 
    449                 if (isset($post->blog_id)) {$mapblog_id=$post->blog_id;}} 
    450     $names = array(); 
    451     $links = array(); 
    452     // Get the Googlemap global and if its zero (i.e. first time called on the page) put out the googlemap key 
    453     global $dogooglemap; 
    454     global $wpdb; 
    455     global $post; 
    456     #$mapblog_id=$wpdb->blogid; 
    457     #if (isset($post->blog_id)) {$mapblog_id=$post->blog_id;} 
    458     if ( get_query_var('feed')) { 
    459  
    460     foreach ($places_array as $place_code) { 
    461     $words=split("\|",$place_code); 
    462         $names[] = "[[CPGM:" .$place_code . "]]"; 
    463         $links[] = "<b>[Embedded Google Map for ".trim($words[0])."]</b>"; 
    464         } 
    465     return str_ireplace($names, $links, $content); 
    466     } 
    467     $maptype[s]="G_SATELLITE_MAP"; 
    468     $maptype[n]="G_NORMAL_MAP"; 
    469     $maptype[h]="G_HYBRID_MAP"; 
    470     foreach ($places_array as $place_code) { 
    471     $words=split("\|",$place_code); 
    472     $sql="select lat,`long` from ".CANALPLAN_CODES." where canalplan_id='".$words[1]."'"; 
    473      $res = mysql_query($sql); 
    474     $row = mysql_fetch_array($res); 
    475     // set defaults 
    476     $options[size]=300; 
    477     $options[zoom]=18; 
    478     $options[type]=s; 
    479     $options[lat]=$row[lat]; 
    480     $options[long]=$row[long]; 
    481 $opts=split(",",$words[2]); 
    482  foreach ($opts as $opt) { 
    483      $opcode=split("=",$opt); 
    484      $options[$opcode[0]]=$opcode[1]; 
    485  } 
    486     $mapstuff="<br />"; 
    487     if ($dogooglemap==0){ 
    488  
    489 $mapstuff.= <<< EOGS 
    490       <script> 
    491       var baseIcon = new GIcon(); 
    492       baseIcon.shadow = "/wp-content/plugins/canalplan/canalplan/markers/shadow.png"; 
    493       baseIcon.iconSize = new GSize(19, 33); 
    494       baseIcon.shadowSize = new GSize(36, 33); 
    495       baseIcon.iconAnchor = new GPoint(9, 33); 
    496       baseIcon.infoWindowAnchor = new GPoint(9, 2); 
    497       baseIcon.infoShadowAnchor = new GPoint(18, 25); 
    498       var icon0 = new GIcon(baseIcon); 
    499       icon0.iconSize = new GSize(12, 20); 
    500       icon0.shadowSize = new GSize(22, 20); 
    501       icon0.iconAnchor = new GPoint(6, 20); 
    502       icon0.image = "/wp-content/plugins/canalplan/canalplan/markers/small_green.png"; 
    503       </script> 
    504 EOGS; 
    505 #$mapstuff.=$mapstuff2; 
    506     } 
    507     // Increment it 
    508     $dogooglemap=$dogooglemap+1; 
    509     // To allow multiple maps per page/entry append the dogooglemap id to the end of the map div id 
    510  
    511     $mapstuff.= '<div id="map'.$dogooglemap.'" style="width: '.$options[size].'px; height: '.$options[size].'px"></div><script type="text/javascript" defer="defer"> '; 
    512     $mapstuff.='var point = new Array(); var map'.$dogooglemap.' = new GMap2(document.getElementById("map'.$dogooglemap.'"));'; 
    513     $mapstuff.='map'.$dogooglemap.'.addControl(new GSmallMapControl()); map'.$dogooglemap.'.addControl(new GMapTypeControl()); map'.$dogooglemap.'.setCenter(new GLatLng('.$options[lat].','.$options[long].'), '.$options[zoom].', '.$maptype[$options[type]].');'; 
    514 #$mapstuff.=' var adsManagerOptions = { maxAdsOnMap : 5, style: G_ADSMANAGER_STYLE_ICON", channel: "5900391315" };'; 
    515     $mapstuff.='var ads'.$dogooglemap.' = new GAdsManager(map'.$dogooglemap.',"pub-4296098225870941",{maxAdsOnMap : 10, style: G_ADSMANAGER_STYLE_ICON, channel: "5900391315", minZoomLevel: 0}); ads'.$dogooglemap.'.enable();'; 
    516    $mapstuff.='point['.$dogooglemap.'] = new GLatLng('.$options[lat].','.$options[long].'); var marker'.$dogooglemap.' = new GMarker(point['.$dogooglemap.'], {icon:icon0, title:"'.trim($words[0]).'"});'; 
    517    $mapstuff.='map'.$dogooglemap.'.addOverlay(marker'.$dogooglemap.');'; 
    518    $mapstuff.='GEvent.addListener(marker'.$dogooglemap.', "click", function(){marker'.$dogooglemap.'.openInfoWindowHtml("'.trim($words[0]).'"); });'; 
    519    $mapstuff.='map'.$dogooglemap.'.addOverlay(new Textbox(new GLatLng('.$options[lat].','.$options[long].'),"<b>'.trim($words[0]).'</b>"));'; 
    520     $mapstuff.='</script>'; 
    521       $names[] = "[[CPGM:" .$place_code . "]]"; 
    522       $links[] = $mapstuff; 
    523       } 
    524 return str_ireplace($matches[0], $links, $content); 
    525     } 
    526  
    527         function canal_stats($content,$mapblog_id=NULL,$post_id=NULL) { 
    528                 // First we check the content for tags: 
    529         global $blog_id,$wpdb,$post; 
    530                 if (preg_match_all('/' . preg_quote('[[CPRS') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[0]; } 
    531  
    532                 // If the array is empty then we've no links so don't do anything! 
    533                 if (count($places_array)==0) {return $content;} 
    534     if (isset($mapblog_id)) {} else { $mapblog_id=$blog_id;} 
    535     if (isset($post_id)) {} else {$post_id=$post->ID; 
    536                 if (isset($post->blog_id)) {$mapblog_id=$post->blog_id;}} 
    537       $sql="select distance,`locks`,start_id,end_id from ".CANALPLAN_ROUTE_DAY." where blog_id=".$mapblog_id." and  post_id=".$post_id; 
     679            $markertext='var marker_start'.$dogooglemap.' = new google.maps.Marker({ position: new google.maps.LatLng('.$first_lat.','.$first_long.'), map: map'.$dogooglemap.',   title: "Start : '.$firstname.'" });'; 
     680            $markertext.='var marker_stop'.$dogooglemap.' = new google.maps.Marker({ position: new google.maps.LatLng('.$last_lat.','.$last_long.'), map: map'.$dogooglemap.',  title: "Stop : '.$lastname.'" });'; 
     681            $markertext.='iconFile = "http://maps.google.com/mapfiles/ms/icons/green-dot.png"; marker_start'.$dogooglemap.'.setIcon(iconFile) ; '; 
     682            $markertext.='iconFile = "http://maps.google.com/mapfiles/ms/icons/red-dot.png"; marker_stop'.$dogooglemap.'.setIcon(iconFile) ; ';  
     683        } 
     684        #$blroute .=$pointstring; 
     685        $options['size']=200; 
     686        $options['zoom']=$canalplan_options["canalplan_rm_zoom"]; 
     687        $options['type']=$canalplan_options["canalplan_rm_type"]; 
     688        $options['lat']=53.4; 
     689        $options['long']=-2.8;   
     690        $options['rgb']=$canalplan_options["canalplan_rm_r_hex"].$canalplan_options["canalplan_rm_g_hex"].$canalplan_options["canalplan_rm_b_hex"]; 
     691        $maptype[S]="SATELLITE"; 
     692        $maptype[R]="ROADMAP"; 
     693        $maptype[T]="TERRAIN"; 
     694        $maptype[H]="HYBRID"; 
     695        $google_map_code.= 'var map_'.$dogooglemap.'_opts = { zoom: '.$options['zoom'].',center: new google.maps.LatLng('.$centre_lat.','.$centre_long.'),'; 
     696            $google_map_code.='  scrollwheel: false, navigationControl: true, mapTypeControl: true, scaleControl: false, draggable: false,'; 
     697            $google_map_code.= ' mapTypeId: google.maps.MapTypeId.'.$maptype[$options['type']].' };'; 
     698            $google_map_code.= 'var map'.$dogooglemap.' = new google.maps.Map(document.getElementById("map_canvas_'.$dogooglemap.'"),map_'.$dogooglemap.'_opts);'; 
     699            $google_map_code.='  var polyOptions'.$dogooglemap.' = {strokeColor: "#'.$options['rgb'].'", strokeOpacity: 1.0,strokeWeight: '.$canalplan_options["canalplan_rm_weight"].' }; '; 
     700        $i=1; 
     701        $google_map_code.=' var line'.$dogooglemap.'_'.$i.' = new google.maps.Polyline(polyOptions'.$dogooglemap.');'; 
     702        $google_map_code.=' line'.$dogooglemap.'_'.$i.'.setPath(google.maps.geometry.encoding.decodePath("'.$pointstring.'"));'; 
     703        $google_map_code.=' line'.$dogooglemap.'_'.$i.'.setMap(map'.$dogooglemap.');'; 
     704        $google_map_code.='var bounds'.$dogooglemap.' = new google.maps.LatLngBounds();'; 
     705        $google_map_code.='line'.$dogooglemap.'_'.$i.'.getPath().forEach(function(latLng) {bounds'.$dogooglemap.'.extend(latLng);});'; 
     706        $google_map_code.='map'.$dogooglemap.'.fitBounds(bounds'.$dogooglemap.');'; 
     707        $google_map_code.=$turnaround.$markertext; 
     708        $blroute .= $page; 
     709        $blroute .= $page2; 
     710        $blroute .= $page3; 
     711        $blroute .= "<p><h2>Blog Entries for this trip</h2>"; 
     712        $sql2="set names 'utf8';"; 
     713        $zed = mysql_query($sql2); 
     714        $sql="select id, post_title from ".$wpdb->posts." where id in (select post_id from ".CANALPLAN_ROUTE_DAY." where blog_id=".$wpdb->blogid." and  route_id=".$routeid." ) order by post_date"; 
    538715        $res = mysql_query($sql); 
    539         $row = mysql_fetch_array($res); 
    540         $sql="select totalroute,uom from ".CANALPLAN_ROUTES." cpr, ".CANALPLAN_ROUTE_DAY." crd where cpr.route_id= crd.route_id and cpr.blog_id=crd.blog_id and crd.blog_id=".$mapblog_id." and  crd.post_id=".$post_id; 
    541         $res3 = mysql_query($sql); 
    542         $row3 = mysql_fetch_array($res3); 
    543                 $dformat=$row3[uom]; 
    544         $places=split(",",$row3[totalroute]); 
    545         #print "!!!".$places[$row[start_id]-1]."££££".$places[$row[end_id]]; 
    546 #       $sql="select place_name from canalplan_codes where canalplan_id='".$places[$row[start_id]]."'"; 
    547 $sql2="set names 'utf8';"; 
    548 $zed = mysql_query($sql2); 
    549 $sql="select place_name from ".CANALPLAN_FAVOURITES." where canalplan_id='".$places[$row[start_id]]."' and blog_id=".$mapblog_id." union select place_name from ".CANALPLAN_CODES." where canalplan_id='".$places[$row[start_id]]."' and canalplan_id not in (select canalplan_id from ".CANALPLAN_FAVOURITES." where canalplan_id='".$places[$row[start_id]]."' and blog_id=".$mapblog_id.")"; 
    550 #print $sql; 
    551         $res2 = mysql_query($sql); 
    552         $row2 = mysql_fetch_array($res2); 
    553         $start_name=$row2[place_name]; 
    554 #       $sql="select place_name from canalplan_codes where canalplan_id='".$places[$row[end_id]]."'"; 
    555 $sql="select place_name from ".CANALPLAN_FAVOURITES." where canalplan_id='".$places[$row[end_id]]."' and blog_id=".$mapblog_id." union select place_name from ".CANALPLAN_CODES." where canalplan_id='".$places[$row[end_id]]."' and canalplan_id not in (select canalplan_id from ".CANALPLAN_FAVOURITES." where canalplan_id='".$places[$row[end_id]]."' and blog_id=".$mapblog_id.")"; 
    556  
    557         $res2 = mysql_query($sql); 
    558         $row2 = mysql_fetch_array($res2); 
    559         $end_name=$row2[place_name]; 
    560  
    561         $names = array(); 
    562         $links = array(); 
    563         foreach ($places_array as $place_code) { 
    564         $words=split(":",$place_code); 
    565             $names[] = $place_code; 
    566             $links[] = "From [[CP:".$start_name."|".$places[$row[start_id]]."]] to [[CP:".$end_name."|".$places[$row[end_id]]."]], ".format_distance($row[distance],$row[locks],$dformat,2); 
    567         } 
    568         return str_ireplace($names, $links, $content); 
    569     } 
    570  
    571  
    572  
    573     function canal_linkify($content) { 
    574         global $post,$blog_id; 
    575         // First we check the content for tags: 
    576         if (preg_match_all('/' . preg_quote('[[CP') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[1]; } 
    577         // If the array is empty then we've no links so don't do anything! 
    578         #if (count($places_array)==0) {return $content;} 
    579                 $names = array(); 
    580         $links = array(); 
    581                 if (preg_match_all('/' . preg_quote('[[CP:') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[1];  
    582                 $gazstring=CANALPLAN_URL.'gazetteer.cgi?id='; 
    583         $x="SELECT pref_value FROM ".CANALPLAN_OPTIONS." where  blog_id=".$blog_id." and pref_code='canalkey'"; 
    584     #   var_dump($x); 
    585         $r2 = mysql_query("SELECT pref_value FROM ".CANALPLAN_OPTIONS." where  blog_id=".$blog_id." and pref_code='canalkey'"); 
    586         if (mysql_num_rows($r2)==0) { 
    587              $api=""; 
    588         } 
    589         else 
    590         { 
    591             $rw = mysql_fetch_array($r2,MYSQL_ASSOC); 
    592         #   var_dump($rw); 
    593             $api=explode("|",$rw['pref_value']); 
    594             $blog_url=get_bloginfo('url'); 
    595             $date = date("Ymd",strtotime($post->post_date)); 
    596             $link=urlencode(str_replace($blog_url,"",get_permalink($post->ID))); 
    597             $title=urlencode($post->post_title); 
    598      
    599         }  
    600         foreach ($places_array as $place_code) { 
    601         $words=split("\|",$place_code); 
    602             $names[] = "[[CP:" .$place_code . "]]"; 
    603             if ($api[0]=="") { 
    604                 $links[] = "<a href='".CANALPLAN_GAZ_URL.$words[1]."' target='gazetteer'  title='Link to ".trim($words[0])."'>".trim($words[0])."</a>"; 
    605             } else  
    606             { 
    607                 $links[] = "<a href='". CANALPLAN_GAZ_URL .$words[1]. "?blogkey=".$api[0]."&title=".$title."&blogid=".$api[1]."&date=".$date."&url=".$link."' target='gazetteer' title='Link to ".trim($words[0])."'>".trim($words[0])."</a>"; 
    608             } 
    609         } 
    610                 } 
    611                 if (preg_match_all('/' . preg_quote('[[CPW:') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[1];  
    612                 $gazstring=CANALPLAN_URL.'waterway.cgi?id='; 
    613         foreach ($places_array as $place_code) { 
    614         $words=split("\|",$place_code); 
    615             $names[] = "[[CPW:" .$place_code . "]]"; 
    616             $links[] = "<a href='".$gazstring.$words[1]."' target='gazetteer'  title='Link to ".trim($words[0])."'>".trim($words[0])."</a>"; 
    617         }} 
    618         return str_ireplace($names, $links, $content); 
    619     } 
    620  
    621     function canal_options_page() { 
    622         global $wpdb; 
    623         if (!current_user_can('manage_options')) { 
    624             die('You don&#8217;t have sufficient permission to access this file.'); 
    625         } 
    626         if (isset($_POST['update'])) { 
    627             check_admin_referer('canalplan-autolinker-update-options'); 
    628             update_option('canalplan-autolinker-begin', $wpdb->escape($_POST['begin'])); 
    629             update_option('canalplan-autolinker-end', $wpdb->escape($_POST['end'])); 
    630             echo '<div id="message" class="updated fade"><p><strong>Options saved.</strong></p></div>'; 
    631         } 
    632 ?> 
    633  
    634 <?php 
    635     } 
    636 } 
    637  
    638  
     716        $blroute .="<ol>"; 
     717        while ($row = mysql_fetch_array($res)) { 
     718            $link = get_blog_permalink( $blog_id, $row[id] ) ; 
     719            $blroute .="<li><a href=\"$link\" target=\"_new\">$row[post_title]</a> </li>"; 
     720        } 
     721        $blroute .="</ol>"; 
     722    } 
     723    return $blroute ; 
     724} 
    639725 
    640726function wp_canalplan_admin_pages() { 
    641  
    642727    $base_dir=dirname(__FILE__).'/admin-pages/';  
    643728    $hook=add_menu_page('CanalPlan AC Overview', 'CanalPlan AC', 8,$base_dir.'cp-admin-menu.php'); 
     
    645730    add_submenu_page($base_dir.'cp-admin-menu.php', 'CanalPlan Options: Home Mooring', 'Home Mooring', 8, $base_dir.'cp-admin-home.php'); 
    646731    add_submenu_page($base_dir.'cp-admin-menu.php', 'CanalPlan Options: Favourites', 'Favourites', 8,  $base_dir.'cp-admin-fav.php'); 
     732    add_submenu_page($base_dir.'cp-admin-menu.php', 'CanalPlan Options: Google Maps', 'Google Maps', 8,  $base_dir.'cp-admin-google.php'); 
    647733    add_submenu_page($base_dir.'cp-admin-menu.php', 'CanalPlan Options: Import Route', 'Import Routes', 8,  $base_dir.'cp-import_route.php'); 
    648734    add_submenu_page($base_dir.'cp-admin-menu.php', 'CanalPlan Options: Manage Routes', 'Manage Routes', 8,  $base_dir.'cp-manage_route.php'); 
     
    651737} 
    652738 
    653  
    654739function canalplan_header($blah){ 
    655 global $blog_id,$wpdb; 
    656 if (!defined('CANALPLAN_GMAP_KEY')) { 
    657 $r2 = mysql_query("SELECT pref_value FROM ".CANALPLAN_OPTIONS." where blog_id=".$blog_id." and pref_code='apikey'"); 
    658 if (mysql_num_rows($r2)==0) { 
    659      $api=""; 
    660 } 
    661 else 
    662 { 
    663     $rw = mysql_fetch_array($r,MYSQL_ASSOC); 
    664     $api=$rw['pref_value']; 
    665 }  
    666 } else {$api=CANALPLAN_GMAP_KEY;} 
    667 echo '<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key='.$api.'" type="text/javascript"></script>'; 
    668 #echo '<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script>'; 
    669 echo '<meta name="verify-v1" content="gh8YjrQxNNQP2cet22ZdfXucI+py1YHC/6eczI1ljHc=" />'; 
    670 return $blah; 
     740    global $blog_id,$wpdb,$google_map_code; 
     741    $header = '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <script type="text/javascript" src="//maps.google.com/maps/api/js?libraries=geometry&amp;sensor=false"> </script> ';  
     742    echo $header; 
     743    $google_map_code='<script type="text/javascript">  function initialize() {  '; 
     744    return $blah; 
    671745} 
    672746 
    673747function canalplan_footer($blah) { 
     748    global $google_map_code; 
     749    $google_map_code.='  } </script> '; 
     750    echo $google_map_code; 
    674751    echo "\n<!-- Canalplan AC code revision : ".CANALPLAN_CODE_RELEASE." -->\n"; 
    675     echo "<p style='font-size:80%'>Canalplan Interlinking provided by <a href='http://wordpress.org/extend/plugins/canalplan-ac/'> Canalplan AC Plugin </a></p>"; 
     752    #echo "<p style='font-size:0%'>Canalplan Interlinking provided by <a href='http://wordpress.org/extend/plugins/canalplan-ac/'> Canalplan AC Plugin </a></p>"; 
     753    echo "<script type='text/javascript'> google.maps.event.addDomListener(window, 'load', initialize); </script> "; 
    676754    return $blah; 
    677 } 
    678  
    679 function blroute (){ 
    680  
    681 $routeid = $_REQUEST['routeid']; 
    682 $routeid = preg_replace('{/$}', '', $routeid); 
    683  
    684 if (!isset($routeid)){$routeid=0;} 
    685 if ($routeid<=0){$routeid=0;} 
    686 global $wpdb,$blog_id; 
    687  
    688  
    689 $blroute=""; 
    690 if ($routeid==0){ 
    691 #   $blroute .="<h2>Available Trip Reports</h2>"; 
    692 $sql2="set names 'utf8';"; 
    693 $zed = mysql_query($sql2); 
    694 if ($wpdb->blogid==1) { 
    695 $sql="select route_id,title,blog_id from ".CANALPLAN_ROUTES." where status=3"; 
    696 } 
    697 else 
    698 { 
    699 $sql="select route_id, title,description,blog_id from ".CANALPLAN_ROUTES." where status=3 and blog_id=$blog_id"; 
    700 } 
    701 if (!defined('CANALPLAN_ROUTE_SLUG')){ 
    702 $r2 = mysql_query("SELECT pref_value FROM ".CANALPLAN_OPTIONS." where blog_id=-1 and pref_code='routeslug'"); 
    703 if (mysql_num_rows($r2)==0) { 
    704      $routeslug="UNDEFINED!"; 
    705 } 
    706 else 
    707 { 
    708 while($rw = mysql_fetch_array($r2)) 
    709 { 
    710 $routeslug=$rw['pref_value']; 
    711 } 
    712 }  
    713 } else {$routeslug=CANALPLAN_ROUTE_SLUG;} 
    714 $res = mysql_query($sql); 
    715  
    716 $blroute .="<ol>"; 
    717 while ($row = mysql_fetch_array($res)) {; 
    718 if ($wpdb->blogid==1) {$blroute .='<li><a href='.get_blog_option($row[blog_id],"siteurl").'/'.$routeslug.'/'.$row[route_id].' target=\"_new\">'.$row[title].'</a> ( from '. get_blog_option($row[blog_id],'blogname').' )  </li>';} 
    719 else 
    720 { 
    721 $blroute .='<li><a href='.get_blog_option($row[blog_id],"siteurl").'/'.$routeslug.'/'.$row[route_id].' target=\"_new\">'.$row[title].'</a> ('.$row[description].')</li>';} 
    722 } 
    723 $blroute .="</ol><br><br>"; 
    724  
    725 } 
    726  
    727 else 
    728  
    729 { 
    730 $sql2="set names 'utf8';"; 
    731 $zed = mysql_query($sql2); 
    732 $sql="select description, totalroute from ".CANALPLAN_ROUTES." where route_id=".$routeid." and blog_id=".$wpdb->blogid; 
    733 $res = mysql_query($sql); 
    734 $row = mysql_fetch_array($res); 
    735 $blroute .="<h2>".$row[description]."</h2>"; 
    736 $pointstring = ""; 
    737 $zoomstring = ""; 
    738 $lat = 0; 
    739 $long = 0; 
    740 $lpoint=""; 
    741 $lpointb1=""; 
    742 $x=3; 
    743 $y=-1; 
    744 $places=split(",",$row[totalroute]); 
    745 $lastid=end($places); 
    746 $firstid=reset($places); 
    747 $turnaround=""; 
    748 foreach ($places as $place) { 
    749 $sql="select `lat`,`long`,`place_name` from ".CANALPLAN_CODES." where canalplan_id='".$place."'"; 
    750 $res = mysql_query($sql); 
    751 $row = mysql_fetch_array($res); 
    752 if ($place==$firstid){$firstname=$row[place_name];} 
    753 if ($place==$lastid){$lastname=$row[place_name];} 
    754 $points=$place.",".$row[lat].",".$row[long]; 
    755       $pointx = $row[lat]; 
    756         $pointy = $row[long]; 
    757 #   $blroute .="!".$pointx."!".$pointy."!<br>"; 
    758         $nlat = floor($pointx * 1e5); 
    759         $nlong = floor($pointy * 1e5); 
    760         $pointstring .= ascii_encode($nlat - $lat) . ascii_encode($nlong - 
    761 $long); 
    762         $zoomstring .= 'B'; 
    763         $lat = $nlat; 
    764         $long = $nlong; 
    765         $cpoint=$row[place_name].",".$row[lat].",".$row[long]; 
    766       # $blroute .="$$$$".$cpoint."!!!".$lpointb1."£££<br>"; 
    767         if ($cpoint==$lpointb1) { 
    768     $lpoints=split(",",$lpoint); 
    769 #   $blroute .="Turn round at ".$lpoints[0]; 
    770 $turnaround.='var marker'.$x.' = new GMarker(encodedPolyline.getVertex('.$y.'),{icon:icon2, draggable: false, title: "Turn Round here : '.$lpoints[0].'"});'; 
    771 $turnaround.='map.addOverlay(marker'.$x.');'; 
    772  $x=$x+1; 
    773 } 
    774 $lpointb1=$lpoint; 
    775 $y=$y+1; 
    776 $lpoint=$cpoint; 
    777 } 
    778 if ($firstid==$lastid) { 
    779     $markertext='var marker0 = new GMarker(encodedPolyline.getVertex(0), {icon:icon0, draggable: false, title: "Start/Finish : '.$firstname.'"});'; 
    780     $markertext.='map.addOverlay(marker0);'; 
    781 } 
    782 else 
    783 { 
    784     $markertext='var marker0 = new GMarker(encodedPolyline.getVertex(0), {icon:icon0, draggable: false, title: "Start : '.$firstname.'"});'; 
    785     $markertext.='var marker1 = new GMarker(encodedPolyline.getVertex(encodedPolyline.getVertexCount()-1), {icon:icon1, draggable: false, title:"Finish : '.$lastname.'"});'; 
    786     $markertext.='map.addOverlay(marker0);'; 
    787     $markertext.='map.addOverlay(marker1);'; 
    788 } 
    789 #$blroute .=$pointstring; 
    790  
    791  
    792 $page= <<< EOGS 
    793         <div id="map" style="width: 500px; height: 600px"></div> 
    794  
    795       <script type="text/javascript"> 
    796  
    797  
    798   if (GBrowserIsCompatible()) { 
    799     // Make sure that SVG is on. 
    800     if(document.implementation.hasFeature( 
    801         "http://www.w3.org/TR/SVG11/feature#SVG","1.1")){ 
    802       _mSvgEnabled = true; 
    803       _mSvgForced  = true; 
    804     } 
    805     // Set up the map. 
    806             var map = new GMap2(document.getElementById("map")); 
    807       map.setCenter(new GLatLng(52.97035617,-2.508565798), 9); 
    808         map.addControl(new GSmallMapControl()); 
    809         map.addControl(new GMapTypeControl()); 
    810         map.setMapType(G_NORMAL_MAP); 
    811         map.setZoom(9); 
    812 var publisher_id = 'pub-4296098225870941'; 
    813  
    814 var adsManagerOptions = { 
    815   maxAdsOnMap : 10, 
    816   style: 'icon', 
    817   // The channel field is optional - replace this field with a channel number  
    818   // for Google AdSense tracking 
    819   channel: '5900391315'   
    820 }; 
    821 adsManager = new GAdsManager(map, publisher_id, adsManagerOptions); 
    822 adsManager.enable(); 
    823 var baseIcon = new GIcon(); 
    824 baseIcon.shadow = "/wp-content/plugins/canalplan/canalplan/markers/shadow.png"; 
    825 baseIcon.iconSize = new GSize(12, 20); 
    826 baseIcon.shadowSize = new GSize(22, 20); 
    827 baseIcon.iconAnchor = new GPoint(6, 20); 
    828 baseIcon.infoWindowAnchor = new GPoint(9, 2); 
    829 baseIcon.infoShadowAnchor = new GPoint(18, 25); 
    830 var icon0 = new GIcon(baseIcon); 
    831 var icon1 = new GIcon(baseIcon); 
    832 var icon2 = new GIcon(baseIcon); 
    833 icon0.image = "/wp-content/plugins/canalplan/canalplan/markers/small_green.png"; 
    834 icon1.image = "/wp-content/plugins/canalplan/canalplan/markers/small_red.png"; 
    835 icon2.image = "/wp-content/plugins/canalplan/canalplan/markers/small_yellow.png"; 
    836 var encodedPolyline = new GPolyline.fromEncoded({ 
    837     color: "#0000FF", 
    838     weight: 3, 
    839 EOGS; 
    840 $page.='points: "'.$pointstring.'",    levels: "'.$zoomstring.'",'; 
    841 $page2= <<< BARF2 
    842     zoomFactor: 32, 
    843     numLevels: 4, opacity: 0.8 
    844 }); 
    845  
    846                 map.addOverlay(encodedPolyline); 
    847                 var bounds = new GLatLngBounds(); 
    848 for (var i=0; i<encodedPolyline.getVertexCount()-1; i++) { 
    849 //  alert(encodedPolyline.getVertex(i)); 
    850   bounds.extend(encodedPolyline.getVertex(i)); 
    851                     } 
    852 //alert(map.getBoundsZoomLevel(bounds)); 
    853                     var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat())/2; 
    854                     var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng())/2; 
    855                     map.setCenter(new GLatLng(clat,clng)); 
    856 map.setZoom(map.getBoundsZoomLevel(bounds)); 
    857 } 
    858 BARF2; 
    859  
    860 $page2.=$turnaround.$markertext; 
    861 $page3=<<< BARF3 
    862         </script> <br /> 
    863 BARF3; 
    864 $blroute .= $page; 
    865 $blroute .= $page2; 
    866 $blroute .= $page3; 
    867 $blroute .= "<h2>Blog Entries for this trip</h2>"; 
    868 $sql2="set names 'utf8';"; 
    869 $zed = mysql_query($sql2); 
    870  
    871 $sql="select id, post_title from ".$wpdb->posts." where id in (select post_id from ".CANALPLAN_ROUTE_DAY." where blog_id=".$wpdb->blogid." and  route_id=".$routeid." ) order by post_date"; 
    872 $res = mysql_query($sql); 
    873 $blroute .="<ol>"; 
    874  
    875 while ($row = mysql_fetch_array($res)) { 
    876 $link = get_blog_permalink( $blog_id, $row[id] ) ; 
    877 $blroute .="<li><a href=\"$link\" target=\"_new\">$row[post_title]</a> </li>"; 
    878 } 
    879 $blroute .="</ol>"; 
    880  
    881 } 
    882  
    883 return $blroute ; 
    884755} 
    885756 
     
    895766 
    896767function canal_activate() { 
    897 #add_option('canalplan-autolinker-begin', '['); 
    898     #add_option('canalplan-autolinker-end', ']'); 
    899768    global $wpdb, $table_prefix; 
    900769    wp_cache_flush(); 
     
    907776    $result = $wpdb->query( $sql ); 
    908777    if ($result === false) $errors[] = __('Failed to create ') . CANALPLAN_ALIASES ; 
    909  
    910778    $sql= 'CREATE TABLE IF NOT EXISTS '.CANALPLAN_CODES.' ( 
    911779      `canalplan_id` varchar(10) NOT NULL , 
     
    923791    $result = $wpdb->query( $sql ); 
    924792    if ($result === false) $errors[] = __('Failed to create ') . CANALPLAN_CODES ; 
    925  
    926  
    927793    $sql='CREATE TABLE IF NOT EXISTS '.CANALPLAN_FAVOURITES.' ( 
    928794      `blog_id` bigint(20) NOT NULL default 0, 
     
    935801    $result = $wpdb->query( $sql ); 
    936802    if ($result === false) $errors[] = __('Failed to create ') . CANALPLAN_FAVOURITES ; 
    937  
    938  
    939803    $sql='CREATE TABLE IF NOT EXISTS '.CANALPLAN_LINK.' ( 
    940804      `place1` varchar(4) NOT NULL , 
     
    948812    $result = $wpdb->query( $sql ); 
    949813    if ($result === false) $errors[] = __('Failed to create ') . CANALPLAN_LINK ; 
    950  
    951  
    952814    $sql='CREATE TABLE IF NOT EXISTS '.CANALPLAN_OPTIONS.' ( 
    953815      `blog_id` bigint(20) NOT NULL default 0, 
     
    958820    $result = $wpdb->query( $sql ); 
    959821    if ($result === false) $errors[] = __('Failed to create ') . CANALPLAN_OPTIONS ; 
    960  
    961  
    962822    $sql='CREATE TABLE IF NOT EXISTS '.CANALPLAN_ROUTES.' ( 
    963823          `route_id` bigint(10) NOT NULL default 0, 
     
    979839    $result = $wpdb->query( $sql ); 
    980840    if ($result === false) $errors[] = __('Failed to create ') . CANALPLAN_ROUTES ; 
    981  
    982  
    983841    $sql='CREATE TABLE IF NOT EXISTS '.CANALPLAN_CANALS.' ( 
    984842      `id` varchar(4) NOT NULL, 
     
    991849    $result = $wpdb->query( $sql ); 
    992850    if ($result === false) $errors[] = __('Failed to create ') . CANALPLAN_CANALS ; 
    993  
    994  
    995851    $sql='CREATE TABLE IF NOT EXISTS '.CANALPLAN_POLYLINES.' ( 
    996852      `id` varchar(5) NOT NULL, 
     
    1001857    $result = $wpdb->query( $sql ); 
    1002858    if ($result === false) $errors[] = __('Failed to create ') . CANALPLAN_POLYLINES ; 
    1003  
    1004859    $sql='CREATE TABLE IF NOT EXISTS '.CANALPLAN_ROUTE_DAY.' ( 
    1005860      `route_id` bigint(10) NOT NULL default 0, 
     
    1016871      KEY `post_blog_idx` (`blog_id`,`post_id`) 
    1017872    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;'; 
    1018  
    1019873    $result = $wpdb->query( $sql ); 
    1020874    if ($result === false) $errors[] = __('Failed to create ') . CANALPLAN_POLYLINES ; 
     
    1029883} 
    1030884 
    1031 add_action('activated_plugin','save_error'); 
     885function canalplan_option_init(){ 
     886    register_setting( 'canalplan_options', 'canalplan_options','canalplan_validate_options'); 
     887} 
     888 
     889function canalplan_validate_options($options) { 
     890    # Do they want to reset? If so we reset the options and let WordPress do the business for us! 
     891    if (isset( $_POST["RSD"] ))  { 
     892        $options["canalplan_pm_type"]='H'; 
     893        $options["canalplan_pm_zoom"]=14; 
     894        $options["canalplan_pm_height"]=200; 
     895        $options["canalplan_pm_width"]=200; 
     896        $options["canalplan_rm_type"]='H'; 
     897        $options["canalplan_rm_zoom"]=9; 
     898        $options["canalplan_rm_height"]=600; 
     899        $options["canalplan_rm_width"]=500; 
     900        $options["canalplan_rm_r_hex"]="00"; 
     901        $options["canalplan_rm_g_hex"]="00"; 
     902        $options["canalplan_rm_b_hex"]="ff"; 
     903        $options["canalplan_rm_weight"]=4; 
     904    } 
     905    return $options; 
     906} 
     907 
     908add_action('admin_init', 'canalplan_option_init' ); 
     909 
    1032910function save_error(){ 
    1033911    update_option('plugin_error',  ob_get_contents()); 
    1034912} 
    1035913 
     914add_action('activated_plugin','save_error'); 
    1036915add_filter('the_content','blogroute_insert'); 
    1037916add_action('wp_head', 'canalplan_header'); 
    1038917add_action('wp_footer', 'canalplan_footer'); 
    1039 add_action('init', array('CanalPlanAutolinker', 'canal_init')); 
     918add_action('admin_menu', 'canalplan_add_custom_box'); 
     919add_action('init', 'canal_init'); 
    1040920register_activation_hook(__FILE__, 'canal_activate'); 
    1041921add_action('admin_menu', 'wp_canalplan_admin_pages'); 
    1042  
    1043  
    1044  
    1045  
     922include("canalplan_widget.php"); 
    1046923 
    1047924?> 
  • canalplan-ac/tags/2.0/multisite.php.txt

    r408484 r537712  
    33#This allows administrators of Networked Blogs to set some installation wide configuration options. 
    44 
    5 # Google Maps API key - make sure you get one for your top level domain rather than for a specific subdomain 
    6 define ('CANALPLAN_GMAP_KEY','ABQIAAAAzDaUChkNH3lPjAjJapKq6RTvY22eKy7N0CiFH2Ct6wY8stwoVxR4QHlGjqnhLQYhV02RACCBlloxaA'); 
    75 
    86# This is the page slug that Canalplan AC will use to display the routes on. You should set this up on your base blog and ensure that all users create a page with the same name in their blogs. 
  • canalplan-ac/tags/2.0/readme.txt

    r479046 r537712  
    44Tags: crosspost, Canalplan 
    55Requires at least: 3.0 
    6 Tested up to: 3.3 
    7 Stable tag: 1.0 
     6Tested up to: 3.3.2 
     7Stable tag: 2.0 
    88 
    99== Description == 
    1010 
    11 This plugin allows you link your blog to the Canalplan AC website. You can import routes from the route planner and link your blog posts to the canalplan gazetteer. 
     11This plugin allows you link your self hosted Wordpress blog to the Canalplan AC website. You can import routes from the route planner and link your blog posts to the canalplan gazetteer. 
    1212 
    1313 
     
    1818The plugin also uses the fopen and file_get_contents calls. Please ensure that these functions are available and that they can access external sites. 
    1919 
    20 You have to have PHP V5 installed for this plugin to work as the code contains several PHP V5 specific features. As PHP V5 is a requirement for running Wordpress 3.2 you shouldn't have any problems but if you are on older version of Wordpress and still running PHP V4 then you need to talk to your hosting company and get PHP upgraded. 
     20You also need to ensure that your PHP installation has the PDOs for SQLite V3 installed as the plugin reads from an SQLite DB to populate its tables. 
     21 
    2122 
    2223== Installation == 
     
    26271. Upload the `canalplan` directory to the `/wp-content/plugins/` directory. 
    27281. Activate the plugin through the 'Plugins' menu in WordPress.  
    28 1. Navigate to `Options` &rarr; `Canalplan AC` and you can start to configure and customise the plugin.  
    29 1. If you are running in Mulitsite then some configuration can be done through the multisite.php file 
     291. Navigate to `Options` &rarr; `Canalplan AC` for configuration and follow the on-screen prompts. 
    3030 
    3131 
    3232== Features == 
    3333 
    34 - Imports data from the Canalplan AC website so you have an up to date list of all canalplan locations (currently stadning at 13601 places) 
     34- Imports data from the Canalplan AC website so you have an up to date list of all canalplan locations (currently standing at 17471 places) 
    3535- Easy linking to Canalplan AC Gazetteer entries 
    3636- Easy inclusion of Googlemaps related to Canalplan AC locations 
     
    4242- Works in "Classic" (Single blog) and Networked Blogs mode. Can be Network activated 
    4343- Common set of Tables for Networked Blogs mode - so 1 set of tables per Networked Blogs install, not per blog. 
    44 - Global configuration for Multisite can be done through a special multisite.php file. 
     44- Global configuration for Networked blog installs can be done through a special multisite.php file. 
    4545 
    4646 
     
    5252 
    5353== Changelog == 
     54 
     55= Version 2.0 28/04/2012 = 
     56- Checked for Wordpress 3.3.2 compatability 
     57- Removed Google Map API key code 
     58- Recoded Google Maps to use Version 3 of the Maps API 
     59- Added a Latitude Widget which links to Canalplan locations 
     60- Added a Maps options page 
     61- Recoded tag handling code to incorporate map customisation options. 
     62- Re-wrote the user guide. 
     63- Removed lots of commented out code left over from original development. 
     64 
    5465 
    5566= Version 1.0 22/12/2011 = 
  • canalplan-ac/trunk/admin-pages/cp-admin-diagnostics.php

    r409641 r537712  
    4848        'WordPress' => $wp_version, 
    4949         'PHP' => $phpvers, 
     50         'PHP Memory Limit' => ini_get('memory_limit'), 
     51         'PHP Memory Usage (MB)' => memory_get_usage(true)/1024/1024, 
    5052        'MySQL' => $mysqlvers 
    5153        ); 
  • canalplan-ac/trunk/admin-pages/cp-admin-general.php

    r409641 r537712  
    125125    foreach ($result as $entry) { 
    126126       $sql= "INSERT INTO ".CANALPLAN_CODES." (canalplan_id,place_name,size,lat,`long`,attributes,lat_lng_point) VALUES ('".$entry['id']."','".mysql_real_escape_string($entry['name'])."','".$entry['type']."','".$entry['latitude']."','".$entry['longitude']."','".$entry['attributes']."', GeomFromText('Point(".$entry['latitude']." ".$entry['longitude'].")')) ON DUPLICATE KEY UPDATE place_name='".mysql_real_escape_string($entry['name'])."', size='".$entry['type']."', lat='".$entry['latitude']."', `long`='".$entry['longitude']."', attributes='".$entry['attributes']."', lat_lng_point=GeomFromText('Point(".$entry['latitude']." ".$entry['longitude'].")'); "; 
     127    #var_dump($sql); 
     128#   echo "<br />"; 
    127129       $res = mysql_query($sql); 
    128130    } 
     
    258260 
    259261</div> 
    260 <?php  if (!defined('CANALPLAN_GMAP_KEY')) { ?> 
    261 <hr> 
    262 <h3><?php _e('Google Maps API Key') ?></h3> 
    263 <form action="" name="googleapi" id="googleapi" method="post"> 
    264  
    265 <?php 
    266 $r2 = mysql_query("SELECT pref_value FROM ".CANALPLAN_OPTIONS." where  blog_id=".$blog_id." and pref_code='apikey'"); 
    267 if (mysql_num_rows($r2)==0) { 
    268      $api=""; 
    269 } 
    270 else 
    271 { 
    272     $rw = mysql_fetch_array($r2,MYSQL_ASSOC); 
    273     $api=$rw['pref_value']; 
    274 }  
    275 echo '<input type="text" name="apikey" maxlength="100" size="100" value="'.$api.'">'; 
    276 ?> 
    277 <input type="hidden" name="googleapi" value="1"/> 
    278 <p class="submit"> <input type="submit"  value="Save API Key" /></p> 
    279 </form> 
    280  
    281 <p>You can obtain a Google Map API Key by <a href='http://code.google.com/apis/maps/signup.html'> Signing up for one at Google </a></p> 
    282  
    283 <?php 
    284 } 
    285 ?> 
     262 
    286263<hr> 
    287264 
  • canalplan-ac/trunk/admin-pages/cp-admin-menu.php

    r409641 r537712  
    1818This plugin allows you to integrate your blog with <a href="http://www.canalplan.eu">Canalplan AC</a> 
    1919 
    20 <p><a href="admin.php?page=canalplan/admin-pages/cp-admin-general.php"> General Options </a> <br /> 
     20<p><a href="?page=canalplan/admin-pages/cp-admin-general.php"> General Options </a> <br /> 
    2121This sets up various general options for the Canalplan plugin such as the Canalplan API Key and GoogleMaps API Key</p> 
    22 <p><a href="admin.php?page=canalplan/admin-pages/cp-admin-home.php"> Home Mooring </a><br /> 
     22<p><a href="?page=canalplan/admin-pages/cp-admin-home.php"> Home Mooring </a><br /> 
    2323This allows you to set your home mooring location and give it a customised name </p> 
    24 <p><a href="admin.php?page=canalplan/admin-pages/cp-admin-fav.php"> Favourite Locations </a><br /> 
     24<p><a href="?page=canalplan/admin-pages/cp-admin-fav.php"> Favourite Locations </a><br /> 
    2525This allows you to set up some favourite locations and give them customised names.</p> 
    26 <p><a href="admin.php?page=canalplan/admin-pages/cp-import_route.php"> Import a route from CanalPlan AC </a><br /> 
     26<p><a href="?page=canalplan/admin-pages/cp-admin-google.php"> Google Map Options </a><br /> 
     27This allows you to set up the various options to do with how Google Maps are displayed.</p> 
     28<p><a href="?page=canalplan/admin-pages/cp-import_route.php"> Import a route from CanalPlan AC </a><br /> 
    2729This is the starting point for importing a route from Canalplan AC and creating a set of blog posts for the imported route</p> 
    28 <p><a href="admin.php?page=canalplan/admin-pages/cp-manage_route.php"> Manage Imported Routes </a><br /> 
     30<p><a href="?page=canalplan/admin-pages/cp-manage_route.php"> Manage Imported Routes </a><br /> 
    2931Once you've imported a route you might need to make adjustments to the daily totals - this page allows you to do that</p> 
    30 <p><a href="admin.php?page=canalplan/admin-pages/cp-admin-diagnostics.php"> Diagnostics / Version Information </a><br /> 
     32<p><a href="?page=canalplan/admin-pages/cp-admin-diagnostics.php"> Diagnostics / Version Information </a><br /> 
    3133Provides information and diagnostics - You'll need to refer to this page if you've got problems. 
    3234</p> 
    33 <p><a href="admin.php?page=canalplan/admin-pages/cp-admin-update.php"> Bulk Link Notifier </a><br /> 
     35<p><a href="?page=canalplan/admin-pages/cp-admin-update.php"> Bulk Link Notifier </a><br /> 
    3436During normal use the Canalplan AC website will learn about links from you blog back to it's gazetteer. However if you've just added a set of posts you might want to let Canalplan AC know about all the links. 
    3537</p> 
  • canalplan-ac/trunk/canalplan.php

    r479046 r537712  
    11<?php 
    2  
    32/* 
    4 Plugin Name: CanalPlan AC Integration 
     3Plugin Name: CanalPlan Integration 
    54Plugin URI: http://blogs.canalplan.org.uk/canalplanac/canalplan-plug-in/ 
    65Description: Provides features to integrate your blog with <a href="http://www.canalplan.eu">Canalplan AC</a> - the Canal Route Planner. 
    7 Version: 1.0 
     6Version: 2.0 
    87Author: Steve Atty 
    98Author URI: http://blogs.canalplan.org.uk/steve/ 
     
    2625 * Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    2726*/ 
    28  
    2927@include("multisite.php"); 
    3028define ('CANALPLAN_URL','http://www.canalplan.eu/cgi-bin/'); 
    3129define ('CANALPLAN_GAZ_URL','http://www.canalplan.eu/gazetteer/'); 
    3230define ('CANALPLAN_MAX_POST_PROCESS',20); 
    33 define('CANALPLAN_CODE_RELEASE','0.9.1 r00'); 
     31define('CANALPLAN_CODE_RELEASE','2.0.0 r00'); 
    3432 
    3533global $table_prefix, $wp_version,$wpdb,$db_prefix; 
    3634# Determine the right table prefix to use 
    37 $cp_table_prefix=$table_prefix; 
     35$cp_table_prefix=$wpdb->base_prefix; 
    3836if (isset ($db_prefix) ) { $cp_table_prefix=$db_prefix;} 
    3937 
     
    5553                $numb = ~$numb; 
    5654        } 
    57  
    5855        return ascii_encode_helper($numb); 
    5956 
     
    7067        $string .= pack("C", $numb+63); 
    7168        return str_replace("\\","\\\\",$string); 
    72  
    7369} 
    7470 
     
    130126            $dist_text.= $wholemiles.$miletext.$furltext; 
    131127    } 
    132  
    133128    if ($locks ==1) {$dist_text.=" and 1 lock";} 
    134129    if ($locks >1) {$dist_text.=" and ".$locks." locks";} 
     
    136131} 
    137132 
    138 /* Use the admin_menu action to define the custom boxes */ 
    139 add_action('admin_menu', 'myplugin_add_custom_box'); 
    140  
    141 /* Use the save_post action to do something with the data entered */ 
    142 #add_action('save_post', 'myplugin_save_postdata'); 
    143  
    144 /* Adds a custom section to the "advanced" Post and Page edit screens */ 
    145 function myplugin_add_custom_box() { 
    146  
    147  
     133function canalplan_add_custom_box() { 
    148134    add_meta_box( 'myplugin_sectionid', __( 'CanalPlan Tags', 'myplugin_textdomain' ),  
    149135                'myplugin_inner_custom_box', 'post', 'advanced' ); 
     
    154140/* Prints the inner fields for the custom post/page section */ 
    155141function myplugin_inner_custom_box() { 
    156  
    157   // Use nonce for verification 
    158  
    159   echo '<input type="hidden" name="myplugin_noncename" id="myplugin_noncename" value="' .  
    160     wp_create_nonce( plugin_basename(__FILE__) ) . '" />'; 
    161  
    162   // The actual fields for data entry 
    163  
    164 global $wpdb,$blog_id; 
    165 #include("canalplan/canalplanfunct.js"); 
    166 echo '<script type="text/javascript"> var linktype=1; cplogid='.$blog_id.'</script>'; 
    167 echo '<script type="text/javascript" src="/wp-content/plugins/canalplan/canalplan/canalplanfunctions.js" DEFER></script>'; 
    168 echo '<script type="text/javascript" src="/wp-content/plugins/canalplan/canalplan/canalplan_actb.js"></script>'; 
    169 echo "Insert : "; 
    170 $blog_favourites = $wpdb->get_results("SELECT place_name FROM ".CANALPLAN_FAVOURITES." where blog_id=$blog_id order by place_order asc" ); 
    171 if (count($blog_favourites)>0 ){ 
    172 print '<select name="blogfav" onchange="CanalPlanID.value=blogfav.options[blogfav.selectedIndex].value">'; 
    173 print '<option value="" selected>Select Favourite</option>'; 
    174 foreach ($blog_favourites as $fav) { 
    175 print '<option value="'.$fav->place_name.'">'.$fav->place_name.'</option>'; 
    176         } 
    177 print "</select>"; 
    178  
    179 } 
    180 print ' <input type="text" ID="CanalPlanID" align="LEFT" size="50" maxlength="100"/> as'; 
    181 print '  <select name="tagtype" ID="tagtypeID"> <option value="CP" selected>Gazetteer Tag</option> <option value="CPGM">Google Map Tag</option> </select>'; 
    182 print ' <INPUT TYPE="button" name="CPsub" VALUE="Insert tag"  onclick="getCanalPlan(CanalPlanID.value);"/>'; 
    183 print '<script>canalplan_actb(document.getElementById("CanalPlanID"),new Array());</script>'; 
    184 } 
    185  
    186  
    187  
    188 class CanalPlanAutolinker { 
    189  
    190  
    191  
    192     function canal_init() { 
    193     //  add_action('admin_menu', array(__CLASS__, 'canal_add_options_page')); 
    194        add_filter('the_content', array(__CLASS__, 'canal_stats')); 
    195        add_filter('the_content', array(__CLASS__, 'canal_route_maps')); 
    196        add_filter('the_content', array(__CLASS__, 'canal_place_maps')); 
    197        add_filter('the_content', array(__CLASS__, 'canal_link_maps')); 
    198        add_filter('the_content', array(__CLASS__, 'canal_linkify')); 
    199 ; 
    200            global $dogooglemap; 
    201                 $dogooglemap=0; 
    202  
    203     } 
    204  
    205  
    206     function canal_add_options_page() { 
    207         add_options_page( 
    208             'CanalPlan Autolinker Options', 
    209             'CanalPlan Autolinker', 
    210             'manage_options', 
    211             'canalplan-autolinker-options', 
    212             array(__CLASS__, 'canal_options_page')); 
    213     } 
    214  
    215     function canal_route_maps($content,$mapblog_id=NULL,$post_id=NULL,$search=NULL) { 
    216         global $wpdb,$post,$blog_id; 
    217         // First we check the content for tags: 
    218         if (preg_match_all('/' . preg_quote('[[CPRM') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[0]; } 
    219         // If the array is empty then we've no maps so don't do anything! 
    220         if (count($places_array)==0) {return $content;} 
    221                 if (isset($mapblog_id)) {} else { $mapblog_id=$blog_id;} 
    222                 if (isset($post_id)) {} else {$post_id=$post->ID; 
    223                 if (isset($post->blog_id)) {$mapblog_id=$post->blog_id;}} 
    224          
     142    echo '<input type="hidden" name="myplugin_noncename" id="myplugin_noncename" value="' .  
     143        wp_create_nonce( plugin_basename(__FILE__) ) . '" />'; 
     144    global $wpdb,$blog_id; 
     145    echo '<script type="text/javascript"> var linktype=1; cplogid='.$blog_id.'</script>'; 
     146    echo '<script type="text/javascript" src="/wp-content/plugins/canalplan/canalplan/canalplanfunctions.js" DEFER></script>'; 
     147    echo '<script type="text/javascript" src="/wp-content/plugins/canalplan/canalplan/canalplan_actb.js"></script>'; 
     148    echo "Insert : "; 
     149    $blog_favourites = $wpdb->get_results("SELECT place_name FROM ".CANALPLAN_FAVOURITES." where blog_id=$blog_id order by place_order asc" ); 
     150    if (count($blog_favourites)>0 ){ 
     151        print '<select name="blogfav" onchange="CanalPlanID.value=blogfav.options[blogfav.selectedIndex].value">'; 
     152        print '<option value="" selected>Select Favourite</option>'; 
     153        foreach ($blog_favourites as $fav) { 
     154            print '<option value="'.$fav->place_name.'">'.$fav->place_name.'</option>'; 
     155        } 
     156        print "</select>"; 
     157    } 
     158    print ' <input type="text" ID="CanalPlanID" align="LEFT" size="50" maxlength="100"/> as'; 
     159    print '  <select name="tagtype" ID="tagtypeID"> <option value="CP" selected>Gazetteer Tag</option> <option value="CPGM">Google Map Tag</option> </select>'; 
     160    print ' <INPUT TYPE="button" name="CPsub" VALUE="Insert tag"  onclick="getCanalPlan(CanalPlanID.value);"/>'; 
     161    print '<script>canalplan_actb(document.getElementById("CanalPlanID"),new Array());</script>'; 
     162} 
     163 
     164 
     165function canal_init() { 
     166    add_filter('the_content',  'canal_stats'); 
     167    add_filter('the_content',  'canal_route_maps'); 
     168    add_filter('the_content',  'canal_place_maps'); 
     169    add_filter('the_content',  'canal_link_maps'); 
     170    add_filter('the_content',  'canal_linkify'); 
     171    global $dogooglemap; 
     172    $dogooglemap=0; 
     173} 
     174 
     175function canal_route_maps($content,$mapblog_id=NULL,$post_id=NULL,$search=NULL) { 
     176        global $wpdb,$post,$blog_id,$google_map_code,$dogooglemap; 
     177    // First we check the content for tags: 
     178    if (preg_match_all('/' . preg_quote('[[CPRM') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[0]; } 
     179    // If the array is empty then we've no maps so don't do anything! 
     180    if (count($places_array)==0) {return $content;} 
     181        if (isset($mapblog_id)) {} else { $mapblog_id=$blog_id;} 
     182        if (isset($post_id)) {} else {$post_id=$post->ID; 
     183        if (isset($post->blog_id)) {$mapblog_id=$post->blog_id;}} 
    225184    if ( get_query_var('feed') || $search=='Y' )  { 
    226                 $names = array(); 
    227                 $links = array(); 
    228                 foreach ($places_array as $place_code) { 
    229                 $words=split(":",$place_code); 
    230                         $names[] = $place_code; 
    231                         $links[] ="<b>[Google Route Map embedded here]</b>" ; 
    232                 } 
    233                 return str_replace($names,$links , $content); 
    234         } 
    235         // Get the Googlemap global and if its zero (i.e. first time called on the page) put out the googlemap key 
    236         global $dogooglemap; 
    237         $mapstuff="<br />"; 
    238         if ($dogooglemap==0){ 
    239  
    240         } 
    241         // Increment it 
    242         $dogooglemap=$dogooglemap+1; 
    243         // To allow multiple maps per page (for viewing posts by category) append the dogooglemap id to the end of the map div id 
    244         $mapstuff.= '<div id="map'.$dogooglemap.'" style="width: 500px; height: 600px"></div><script type="text/javascript">'; 
    245         $post_id=$post->ID; 
    246              $sql="select distance,`locks`,start_id,end_id from ".CANALPLAN_ROUTE_DAY." where blog_id=".$mapblog_id." and  post_id=".$post_id; 
    247          
     185        $names = array(); 
     186        $links = array(); 
     187        foreach ($places_array as $place_code) { 
     188        $words=split(":",$place_code); 
     189                $names[] = $place_code; 
     190                $links[] ="<b>[Google Route Map embedded here]</b>" ; 
     191        } 
     192        return str_replace($names,$links , $content); 
     193    } 
     194    $mapstuff="<br />"; 
     195    $dogooglemap=$dogooglemap+1; 
     196    $canalplan_options = get_option('canalplan_options'); 
     197    $post_id=$post->ID; 
     198    $sql="select distance,`locks`,start_id,end_id from ".CANALPLAN_ROUTE_DAY." where blog_id=".$mapblog_id." and  post_id=".$post_id; 
     199    $res = mysql_query($sql); 
     200    $row = mysql_fetch_array($res); 
     201    $sql="select totalroute from ".CANALPLAN_ROUTES." cpr, ".CANALPLAN_ROUTE_DAY." crd where cpr.route_id= crd.route_id and cpr.blog_id=crd.blog_id and crd.blog_id=".$mapblog_id." and  crd.post_id=".$post_id; 
     202    $res3 = mysql_query($sql); 
     203    $mid_point=round(mysql_num_rows($res3)/2,PHP_ROUND_HALF_UP); 
     204    $place_count=0; 
     205    $row3 = mysql_fetch_array($res3); 
     206    $places=split(",",$row3[totalroute]); 
     207    $dayroute=array_slice($places,$row[start_id], ($row[end_id] - $row[start_id])+1); 
     208    $pointstring = ""; 
     209    $zoomstring = ""; 
     210    $lat = 0; 
     211    $long = 0; 
     212    $lpoint=""; 
     213    $lpointb1=""; 
     214    $x=3; 
     215    $y=-1; 
     216    $lastid=end($dayroute); 
     217    $firstid=reset($dayroute); 
     218    $turnaround=""; 
     219    $maptype[S]="SATELLITE"; 
     220    $maptype[R]="ROADMAP"; 
     221    $maptype[T]="TERRAIN"; 
     222    $maptype[H]="HYBRID"; 
     223    $options['zoom']=$canalplan_options["canalplan_rm_zoom"]; 
     224    $options['type']=$canalplan_options["canalplan_rm_type"]; 
     225    $options['lat']=53.4; 
     226    $options['long']=-2.8; 
     227    $options['height']=$canalplan_options["canalplan_rm_height"]; 
     228    $options['width']=$canalplan_options["canalplan_rm_width"]; 
     229    $options['rgb']=$canalplan_options["canalplan_rm_r_hex"].$canalplan_options["canalplan_rm_g_hex"].$canalplan_options["canalplan_rm_b_hex"]; 
     230    $options['brush']=$canalplan_options["canalplan_rm_weight"]; 
     231    $words=substr($matches[1][0],1); 
     232    $opts=split(",",$words); 
     233    foreach ($opts as $opt) { 
     234         $opcode=split("=",$opt); 
     235         $options[$opcode[0]]=strtoupper($opcode[1]); 
     236    } 
     237    $mapstuff.= '<div id="map_canvas_'.$dogooglemap.'" style="width: '.$options['width'].'px; height: '.$options['height'].'px"></div>'; 
     238    foreach ($dayroute as $place) { 
     239        $sql2="set names 'utf8';"; 
     240        $zed = mysql_query($sql2); 
     241        $sql="select `lat`,`long`,`place_name` from ".CANALPLAN_CODES." where canalplan_id='".$place."'"; 
    248242        $res = mysql_query($sql); 
    249243        $row = mysql_fetch_array($res); 
    250         $sql="select totalroute from ".CANALPLAN_ROUTES." cpr, ".CANALPLAN_ROUTE_DAY."  crd where cpr.route_id= crd.route_id and cpr.blog_id=crd.blog_id and crd.blog_id=".$mapblog_id." and  crd.post_id=".$post_id; 
    251         $res3 = mysql_query($sql); 
    252         $row3 = mysql_fetch_array($res3); 
    253         $places=split(",",$row3[totalroute]); 
    254         $dayroute=array_slice($places,$row[start_id], ($row[end_id] - $row[start_id])+1); 
     244        if($place_count==$mid_point) { 
     245            $centre_lat=$row[lat]; 
     246            $centre_long=$row[long]; 
     247        }    
     248        $place_count=$place_count+1; 
     249        if ($place==$firstid){ 
     250            $firstname=$row[place_name]; 
     251            $first_lat=$row[lat]; 
     252            $first_long=$row[long]; 
     253        } 
     254        if ($place==$lastid){ 
     255            $lastname=$row[place_name]; 
     256            $last_lat=$row[lat]; 
     257            $last_long=$row[long]; 
     258        } 
     259        $points=$place.",".$row[lat].",".$row[long]; 
     260            $pointx = $row[lat]; 
     261            $pointy = $row[long];; 
     262            $nlat = floor($pointx * 1e5); 
     263            $nlong = floor($pointy * 1e5); 
     264            $pointstring .= ascii_encode($nlat - $lat) . ascii_encode($nlong -  $long); 
     265            $zoomstring .= 'B'; 
     266            $lat = $nlat; 
     267            $long = $nlong; 
     268            $cpoint=$row[place_name].",".$row[lat].",".$row[long]; 
     269            if ($cpoint==$lpointb1) { 
     270            $lpoints=split(",",$lpoint); 
     271            $turnaround.='var marker_turn'.$dogooglemap.'_'.$x.' = new google.maps.Marker({ position: new google.maps.LatLng('.$lpoints[1].','.$lpoints[2].'), map: map'.$dogooglemap.',   title: "Turn Round here  : '.$lpoints[0].'" });'; 
     272            $turnaround.='iconFile = "http://maps.google.com/mapfiles/ms/icons/blue-dot.png"; marker_turn'.$dogooglemap.'_'.$x.'.setIcon(iconFile) ; '; 
     273            $x=$x+1; 
     274        } 
     275        $lpointb1=$lpoint; 
     276        $y=$y+1; 
     277        $lpoint=$cpoint; 
     278    } 
     279 
     280    if ($firstid==$lastid) { 
     281        $markertext='var marker_start'.$dogooglemap.' = new google.maps.Marker({ position: new google.maps.LatLng('.$first_lat.','.$first_long.'), map: map'.$dogooglemap.',   title: "Start / Finish : '.$firstname.'"});'; 
     282        $markertext.='iconFile = "http://maps.google.com/mapfiles/ms/icons/yellow-dot.png"; marker_start'.$dogooglemap.'.setIcon(iconFile) ; '; 
     283    } 
     284    else 
     285    { 
     286        $markertext='var marker_start'.$dogooglemap.' = new google.maps.Marker({ position: new google.maps.LatLng('.$first_lat.','.$first_long.'), map: map'.$dogooglemap.',   title: "Start : '.$firstname.'" });'; 
     287        $markertext.='var marker_stop'.$dogooglemap.' = new google.maps.Marker({ position: new google.maps.LatLng('.$last_lat.','.$last_long.'), map: map'.$dogooglemap.',  title: "Stop : '.$lastname.'" });'; 
     288        $markertext.='iconFile = "http://maps.google.com/mapfiles/ms/icons/green-dot.png"; marker_start'.$dogooglemap.'.setIcon(iconFile) ; '; 
     289        $markertext.='iconFile = "http://maps.google.com/mapfiles/ms/icons/red-dot.png"; marker_stop'.$dogooglemap.'.setIcon(iconFile) ; ';  
     290    } 
     291    $google_map_code.= 'var map_'.$dogooglemap.'_opts = { zoom: '.$options['zoom'].',center: new google.maps.LatLng('.$centre_lat.','.$centre_long.'),'; 
     292        $google_map_code.='  scrollwheel: false, navigationControl: true, mapTypeControl: true, scaleControl: false, draggable: false,'; 
     293        $google_map_code.= ' mapTypeId: google.maps.MapTypeId.'.$maptype[$options['type']].' };'; 
     294        $google_map_code.= 'var map'.$dogooglemap.' = new google.maps.Map(document.getElementById("map_canvas_'.$dogooglemap.'"),map_'.$dogooglemap.'_opts);'; 
     295        $google_map_code.='  var polyOptions'.$dogooglemap.' = {strokeColor: "#'.$options['rgb'].'", strokeOpacity: 1.0,strokeWeight: '.$options['brush'].' }; '; 
     296    $i=1; 
     297    $google_map_code.=' var line'.$dogooglemap.'_'.$i.' = new google.maps.Polyline(polyOptions'.$dogooglemap.');'; 
     298    $google_map_code.=' line'.$dogooglemap.'_'.$i.'.setPath(google.maps.geometry.encoding.decodePath("'.$pointstring.'"));'; 
     299    $google_map_code.=' line'.$dogooglemap.'_'.$i.'.setMap(map'.$dogooglemap.');'; 
     300    $google_map_code.='var bounds'.$dogooglemap.' = new google.maps.LatLngBounds();'; 
     301    $google_map_code.='line'.$dogooglemap.'_'.$i.'.getPath().forEach(function(latLng) {bounds'.$dogooglemap.'.extend(latLng);});'; 
     302    $google_map_code.='map'.$dogooglemap.'.fitBounds(bounds'.$dogooglemap.');'; 
     303    $google_map_code.=$turnaround.$markertext; 
     304    $names = array(); 
     305    $links = array(); 
     306    foreach ($places_array as $place_code) { 
     307    $words=split(":",$place_code); 
     308        $names[] = $place_code; 
     309        $links[] =$mapstuff; 
     310    } 
     311    return str_replace($names,$links , $content); 
     312} 
     313 
     314function canal_link_maps($content) { 
     315     global $wpdb,$post,$dogooglemap,$google_map_code; 
     316    // First we check the content for tags: 
     317        if (preg_match_all('/' . preg_quote('[[CPGMW:') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[1]; } 
     318    // If the array is empty then we've no maps so don't do anything! 
     319    if (count($places_array)==0) {return $content;} 
     320    $canalplan_options = get_option('canalplan_options'); 
     321    if ( get_query_var('feed') || $search=='Y' )  { 
     322        $names = array(); 
     323        $links = array(); 
     324         foreach ($places_array as $place_code) { 
     325            $words=split("\|",$place_code); 
     326                $names[] = "[[CPGMW:" .$place_code . "]]"; 
     327                $links[] = "<b>[Embedded Google Map for ".trim($words[0])."]</b>"; 
     328            } 
     329        return str_replace($names,$links , $content); 
     330    } 
     331        $maptype[S]="SATELLITE"; 
     332        $maptype[R]="ROADMAP"; 
     333        $maptype[T]="TERRAIN"; 
     334        $maptype[H]="HYBRID"; 
     335    foreach ($places_array as $place_code) { 
     336    $options['zoom']=$canalplan_options["canalplan_rm_zoom"]; 
     337    $options['type']=$canalplan_options["canalplan_rm_type"]; 
     338    $options['lat']=53.4; 
     339    $options['long']=-2.8; 
     340    $options['height']=$canalplan_options["canalplan_rm_height"]; 
     341    $options['width']=$canalplan_options["canalplan_rm_width"]; 
     342    $options['rgb']=$canalplan_options["canalplan_rm_r_hex"].$canalplan_options["canalplan_rm_g_hex"].$canalplan_options["canalplan_rm_b_hex"]; 
     343    $options['brush']=$canalplan_options["canalplan_rm_weight"]; 
     344        $mapstuff="<br />"; 
     345        $words=split("\|",$place_code); 
     346        $opts=split(",",$words[2]); 
     347        foreach ($opts as $opt) { 
     348             $opcode=split("=",$opt); 
     349             $options[$opcode[0]]=strtoupper($opcode[1]); 
     350        } 
     351        $dogooglemap=$dogooglemap+1; 
     352        $mapstuff.= '<div id="map_canvas_'.$dogooglemap.'"  style="width: '.$options['width'].'px; height: '.$options['height'].'px"></div>'; 
     353        $post_id=$post->ID; 
     354        unset($missingpoly); 
     355        unset($plines); 
     356        unset($weights); 
     357        unset($polylines); 
     358        $missingpoly[]=$words[1]; 
     359        #$sql=" select lat,`long` from ".CANALPLAN_CODES.' where canalplan_id in (select place1 from '.CANALPLAN_LINK.' where waterway="'.$words[1].'") limit 1'; 
     360    $sql2=' select lat,`long` from '.CANALPLAN_CODES.' where canalplan_id in (select place1 from '.CANALPLAN_LINK.' where waterway in (select id from '.CANALPLAN_CANALS.' where parent="'.$words[1].'" or id="'.$words[1].'")) limit 1'; 
     361        $res = mysql_query($sql2); 
     362         $rw = mysql_fetch_row($res); 
     363        $centre_lat=$rw[0]; 
     364        $centre_long=$rw[1]; 
     365        while ( count($missingpoly)>0 ) { 
     366            reset($missingpoly); 
     367            $sql="select 1 from ".CANALPLAN_POLYLINES." where id='".current($missingpoly)."';"; 
     368            $res = mysql_query($sql); 
     369             $rw = mysql_fetch_row($res); 
     370            if ($rw[0]==1){$polylines[]=current($missingpoly);} 
     371            $sql="select id from ".CANALPLAN_CANALS." where parent='".current($missingpoly)."';"; 
     372            unset($missingpoly2); 
     373            $res = mysql_query($sql); 
     374            while( $rw = mysql_fetch_row($res)){ 
     375                $missingpoly[]=$rw[0]; 
     376            } 
     377    #Get the polyline. If there is one put it into the $polyline[]. 
     378    #Get a list of places where this id is the parent and put them into $missingpoly[] 
     379    #Remove the element from the array 
     380        $missingpoly=array_slice($missingpoly,1); 
     381        } 
     382        $markertext=""; 
     383        $i=1; 
     384            $google_map_code.= 'var map_'.$dogooglemap.'_opts = { zoom: '.$options['zoom'].',center: new google.maps.LatLng('.$centre_lat.','.$centre_long.'),'; 
     385            $google_map_code.='  scrollwheel: false, navigationControl: true, mapTypeControl: true, scaleControl: false, draggable: false,'; 
     386            $google_map_code.= ' mapTypeId: google.maps.MapTypeId.'.$maptype[$options['type']].' };'; 
     387            $google_map_code.= 'var map'.$dogooglemap.' = new google.maps.Map(document.getElementById("map_canvas_'.$dogooglemap.'"),map_'.$dogooglemap.'_opts);'; 
     388            $google_map_code.='  var polyOptions'.$dogooglemap.' = {strokeColor: "#'.$options['rgb'].'", strokeOpacity: 1.0, strokeWeight: '.$options['brush'].' }; '; 
     389        $i=1; 
     390        $google_map_code.='var bounds'.$dogooglemap.' = new google.maps.LatLngBounds();'; 
     391        foreach ($polylines as $polyline) { 
     392            $sql="select pline from ".CANALPLAN_POLYLINES." where id='".$polyline."';";; 
     393            $res = mysql_query($sql); 
     394             $rw = mysql_fetch_row($res);    
     395                $google_map_code.=' var line'.$dogooglemap.'_'.$i.' = new google.maps.Polyline(polyOptions'.$dogooglemap.');'; 
     396            $google_map_code.=' line'.$dogooglemap.'_'.$i.'.setPath(google.maps.geometry.encoding.decodePath("'.$rw[0].'"));'; 
     397            $google_map_code.=' line'.$dogooglemap.'_'.$i.'.setMap(map'.$dogooglemap.');'; 
     398            $google_map_code.='line'.$dogooglemap.'_'.$i.'.getPath().forEach(function(latLng) {bounds'.$dogooglemap.'.extend(latLng);});'; 
     399            $google_map_code.='map'.$dogooglemap.'.fitBounds(bounds'.$dogooglemap.');'; 
     400            $i=$i+1; 
     401        } 
     402            $names[] = "[[CPGMW:" .$place_code . "]]"; 
     403            $links[] = $mapstuff;    
     404        } 
     405    return str_ireplace($matches[0], $links, $content); 
     406} 
     407 
     408function canal_place_maps($content,$mapblog_id=NULL,$post_id=NULL) { 
     409    $gazstring=CANALPLAN_URL.'gazetteer.cgi?id='; 
     410    $canalplan_options = get_option('canalplan_options'); 
     411    #var_dump($canalplan_options); 
     412        if (preg_match_all('/' . preg_quote('[[CPGM:') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[1]; } 
     413        // If the array is empty then we've no links so don't do anything! 
     414    if (count($places_array)==0) {return $content;} 
     415    if (isset($mapblog_id)) {} else { $mapblog_id=$wpdb->blogid;} 
     416    if (isset($post_id)) {} else {$post_id=$post->ID; 
     417        if (isset($post->blog_id)) {$mapblog_id=$post->blog_id;}} 
     418        $names = array(); 
     419        $links = array(); 
     420        global $dogooglemap,$wpdb,$post,$google_map_code; 
     421        if ( get_query_var('feed')) { 
     422            foreach ($places_array as $place_code) { 
     423            $words=split("\|",$place_code); 
     424            $names[] = "[[CPGM:" .$place_code . "]]"; 
     425            $links[] = "<b>[Embedded Google Map for ".trim($words[0])."]</b>"; 
     426        } 
     427        return str_ireplace($names, $links, $content); 
     428        } 
     429        $maptype[S]="SATELLITE"; 
     430        $maptype[R]="ROADMAP"; 
     431        $maptype[T]="TERRAIN"; 
     432        $maptype[H]="HYBRID"; 
     433    foreach ($places_array as $place_code) { 
     434        $words=split("\|",$place_code); 
     435        $sql="select lat,`long` from ".CANALPLAN_CODES." where canalplan_id='".$words[1]."'"; 
     436        $res = mysql_query($sql); 
     437            $row = mysql_fetch_array($res); 
     438        $options['zoom']=$canalplan_options["canalplan_pm_zoom"]; 
     439        $options['type']=$canalplan_options["canalplan_pm_type"]; 
     440        $options['lat']=$row[lat]; 
     441        $options['long']=$row[long]; 
     442        $options['height']=$canalplan_options["canalplan_pm_height"]; 
     443        $options['width']=$canalplan_options["canalplan_pm_width"]; 
     444        $opts=split(",",$words[2]); 
     445        foreach ($opts as $opt) { 
     446             $opcode=split("=",$opt); 
     447             $options[$opcode[0]]=strtoupper($opcode[1]); 
     448        } 
     449            $mapstuff="<br />"; 
     450            $dogooglemap=$dogooglemap+1; 
     451        $mapstuff= '<div id="map_canvas_'.$dogooglemap.'" style="width: '.$options['width'].'px; height: '.$options['height'].'px"></div> '; 
     452        $names[] = "[[CPGM:" .$place_code . "]]"; 
     453        $links[] = $mapstuff; 
     454        $google_map_code.= 'var map_'.$dogooglemap.'_opts = { zoom: '.$options['zoom'].',center: new google.maps.LatLng('.$options['lat'].','.$options['long'].'),'; 
     455        $google_map_code.='  scrollwheel: false, navigationControl: true, mapTypeControl: true, scaleControl: false, draggable: false,'; 
     456        $google_map_code.= ' mapTypeId: google.maps.MapTypeId.'.$maptype[$options['type']].' };'; 
     457        $google_map_code.= 'var map'.$dogooglemap.' = new google.maps.Map(document.getElementById("map_canvas_'.$dogooglemap.'"),map_'.$dogooglemap.'_opts);'; 
     458        $google_map_code.= 'var marker'.$dogooglemap.' = new google.maps.Marker({ position: new google.maps.LatLng('.$options['lat'].','.$options['long'].'), map: map'.$dogooglemap.', title: "'.$words[0].'"  });  '; 
     459        } 
     460    return str_ireplace($matches[0], $links, $content); 
     461} 
     462 
     463function canal_stats($content,$mapblog_id=NULL,$post_id=NULL) { 
     464    global $blog_id,$wpdb,$post; 
     465    if (preg_match_all('/' . preg_quote('[[CPRS') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[0]; } 
     466    if (count($places_array)==0) {return $content;} 
     467    if (isset($mapblog_id)) {} else { $mapblog_id=$blog_id;} 
     468    if (isset($post_id)) {} else {$post_id=$post->ID; 
     469    if (isset($post->blog_id)) {$mapblog_id=$post->blog_id;}} 
     470    $sql="select distance,`locks`,start_id,end_id from ".CANALPLAN_ROUTE_DAY." where blog_id=".$mapblog_id." and  post_id=".$post_id; 
     471    $res = mysql_query($sql); 
     472    $row = mysql_fetch_array($res); 
     473    $sql="select totalroute,uom from ".CANALPLAN_ROUTES." cpr, ".CANALPLAN_ROUTE_DAY." crd where cpr.route_id= crd.route_id and cpr.blog_id=crd.blog_id and crd.blog_id=".$mapblog_id." and  crd.post_id=".$post_id; 
     474    $res3 = mysql_query($sql); 
     475    $row3 = mysql_fetch_array($res3); 
     476    $dformat=$row3[uom]; 
     477    $places=split(",",$row3[totalroute]); 
     478    $sql2="set names 'utf8';"; 
     479    $zed = mysql_query($sql2); 
     480    $sql="select place_name from ".CANALPLAN_FAVOURITES." where canalplan_id='".$places[$row[start_id]]."' and blog_id=".$mapblog_id." union select place_name from ".CANALPLAN_CODES." where canalplan_id='".$places[$row[start_id]]."' and canalplan_id not in (select canalplan_id from ".CANALPLAN_FAVOURITES." where canalplan_id='".$places[$row[start_id]]."' and blog_id=".$mapblog_id.")"; 
     481    $res2 = mysql_query($sql); 
     482    $row2 = mysql_fetch_array($res2); 
     483    $start_name=$row2[place_name]; 
     484    $sql="select place_name from ".CANALPLAN_FAVOURITES." where canalplan_id='".$places[$row[end_id]]."' and blog_id=".$mapblog_id." union select place_name from ".CANALPLAN_CODES." where canalplan_id='".$places[$row[end_id]]."' and canalplan_id not in (select canalplan_id from ".CANALPLAN_FAVOURITES." where canalplan_id='".$places[$row[end_id]]."' and blog_id=".$mapblog_id.")"; 
     485    $res2 = mysql_query($sql); 
     486    $row2 = mysql_fetch_array($res2); 
     487    $end_name=$row2[place_name]; 
     488    $names = array(); 
     489    $links = array(); 
     490    foreach ($places_array as $place_code) { 
     491    $words=split(":",$place_code); 
     492        $names[] = $place_code; 
     493        $links[] = "From [[CP:".$start_name."|".$places[$row[start_id]]."]] to [[CP:".$end_name."|".$places[$row[end_id]]."]], ".format_distance($row[distance],$row[locks],$dformat,2); 
     494    } 
     495    return str_ireplace($names, $links, $content); 
     496} 
     497 
     498function canal_linkify($content) { 
     499    global $post,$blog_id; 
     500    // First we check the content for tags: 
     501    if (preg_match_all('/' . preg_quote('[[CP') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[1]; } 
     502    // If the array is empty then we've no links so don't do anything! 
     503    #if (count($places_array)==0) {return $content;} 
     504    $names = array(); 
     505    $links = array(); 
     506    if (preg_match_all('/' . preg_quote('[[CP:') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) {  
     507        $places_array=$matches[1];  
     508        $gazstring=CANALPLAN_URL.'gazetteer.cgi?id='; 
     509        $x="SELECT pref_value FROM ".CANALPLAN_OPTIONS." where  blog_id=".$blog_id." and pref_code='canalkey'"; 
     510        $r2 = mysql_query("SELECT pref_value FROM ".CANALPLAN_OPTIONS." where  blog_id=".$blog_id." and pref_code='canalkey'"); 
     511        if (mysql_num_rows($r2)==0) { 
     512             $api=""; 
     513        } 
     514        else 
     515        { 
     516            $rw = mysql_fetch_array($r2,MYSQL_ASSOC); 
     517            $api=explode("|",$rw['pref_value']); 
     518            $blog_url=get_bloginfo('url'); 
     519            $date = date("Ymd",strtotime($post->post_date)); 
     520            $link=urlencode(str_replace($blog_url,"",get_permalink($post->ID))); 
     521            $title=urlencode($post->post_title); 
     522        }  
     523        foreach ($places_array as $place_code) { 
     524            $words=split("\|",$place_code); 
     525            $names[] = "[[CP:" .$place_code . "]]"; 
     526            if ($api[0]=="") { 
     527                $links[] = "<a href='".CANALPLAN_GAZ_URL.$words[1]."' target='gazetteer'  title='Link to ".trim($words[0])."'>".trim($words[0])."</a>"; 
     528            } 
     529             else  
     530            { 
     531                $links[] = "<a href='". CANALPLAN_GAZ_URL .$words[1]. "?blogkey=".$api[0]."&title=".$title."&blogid=".$api[1]."&date=".$date."&url=".$link."' target='gazetteer' title='Link to ".trim($words[0])."'>".trim($words[0])."</a>"; 
     532            } 
     533        } 
     534    } 
     535    if (preg_match_all('/' . preg_quote('[[CPW:') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) {  
     536        $places_array=$matches[1];  
     537        $gazstring=CANALPLAN_URL.'waterway.cgi?id='; 
     538        foreach ($places_array as $place_code) { 
     539        $words=split("\|",$place_code); 
     540            $names[] = "[[CPW:" .$place_code . "]]"; 
     541            $links[] = "<a href='".$gazstring.$words[1]."' target='gazetteer'  title='Link to ".trim($words[0])."'>".trim($words[0])."</a>"; 
     542        } 
     543    } 
     544    return str_ireplace($names, $links, $content); 
     545} 
     546 
     547function canal_options_page() { 
     548    global $wpdb; 
     549    if (!current_user_can('manage_options')) { 
     550        die('You don&#8217;t have sufficient permission to access this file.'); 
     551    } 
     552    if (isset($_POST['update'])) { 
     553        check_admin_referer('canalplan-autolinker-update-options'); 
     554        update_option('canalplan-autolinker-begin', $wpdb->escape($_POST['begin'])); 
     555        update_option('canalplan-autolinker-end', $wpdb->escape($_POST['end'])); 
     556        echo '<div id="message" class="updated fade"><p><strong>Options saved.</strong></p></div>'; 
     557    } 
     558} 
     559 
     560function blroute(){ 
     561    $routeid = $_REQUEST['routeid']; 
     562    $routeid = preg_replace('{/$}', '', $routeid); 
     563    if (!isset($routeid)){$routeid=0;} 
     564    if ($routeid<=0){$routeid=0;} 
     565    global $wpdb,$blog_id,$google_map_code,$dogooglemap; 
     566    $dogooglemap=1; 
     567    $blroute=""; 
     568    $canalplan_options = get_option('canalplan_options'); 
     569    #var_dump($canalplan_options); 
     570    if ($routeid==0){ 
     571        #$blroute .="<h2>Available Trip Reports</h2>"; 
     572        $sql2="set names 'utf8';"; 
     573        $zed = mysql_query($sql2); 
     574        if ($wpdb->blogid==1) { 
     575            $sql="select route_id,title,blog_id from ".CANALPLAN_ROUTES." where status=3"; 
     576        } 
     577        else 
     578        { 
     579            $sql="select route_id, title,description,blog_id from ".CANALPLAN_ROUTES." where status=3 and blog_id=$blog_id"; 
     580        } 
     581        if (!defined('CANALPLAN_ROUTE_SLUG')){ 
     582            $r2 = mysql_query("SELECT pref_value FROM ".CANALPLAN_OPTIONS." where blog_id=-1 and pref_code='routeslug'"); 
     583            if (mysql_num_rows($r2)==0) { 
     584                     $routeslug="UNDEFINED!"; 
     585            } 
     586            else 
     587            { 
     588                while($rw = mysql_fetch_array($r2)) 
     589                { 
     590                    $routeslug=$rw['pref_value']; 
     591                } 
     592            }  
     593        }  
     594        else { 
     595            $routeslug=CANALPLAN_ROUTE_SLUG; 
     596        } 
     597        $res = mysql_query($sql); 
     598        $blroute .="<ol>"; 
     599        while ($row = mysql_fetch_array($res)) { 
     600            if ($wpdb->blogid==1) {$blroute .='<li><a href='.get_blog_option($row[blog_id],"siteurl").'/'.$routeslug.'/'.$row[route_id].' target=\"_new\">'.$row[title].'</a> ( from '. get_blog_option($row[blog_id],'blogname').' )  </li>'; 
     601            } 
     602            else 
     603            { 
     604                $blroute .='<li><a href='.get_blog_option($row[blog_id],"siteurl").'/'.$routeslug.'/'.$row[route_id].' target=\"_new\">'.$row[title].'</a> ('.$row[description].')</li>'; 
     605            } 
     606        } 
     607        $blroute .="</ol><br><br>"; 
     608    } 
     609    else 
     610    { 
     611        $sql2="set names 'utf8';"; 
     612        $zed = mysql_query($sql2); 
     613        $sql="select description, totalroute from ".CANALPLAN_ROUTES." where route_id=".$routeid." and blog_id=".$wpdb->blogid; 
     614        $res = mysql_query($sql); 
     615        $mid_point=round(mysql_num_rows($res)/2,PHP_ROUND_HALF_UP); 
     616        $place_count=0; 
     617        $row = mysql_fetch_array($res); 
     618        $blroute .="<h2>".$row[description]."</h2><br/>"; 
     619        $blroute.='<div id="map_canvas_'.$dogooglemap.'"  style="width: '.$canalplan_options["canalplan_rm_width"].'px; height: '.$canalplan_options["canalplan_rm_height"].'px"></div>'; 
     620        #$blroute.='<div id="map_canvas_'.$dogooglemap.'" style="width: 500px; height: 600px"></div> '; 
    255621        $pointstring = ""; 
    256622        $zoomstring = ""; 
     
    261627        $x=3; 
    262628        $y=-1; 
    263         $lastid=end($dayroute); 
    264         $firstid=reset($dayroute); 
     629        $places=split(",",$row[totalroute]); 
     630        $lastid=end($places); 
     631        $firstid=reset($places); 
    265632        $turnaround=""; 
    266         foreach ($dayroute as $place) { 
    267 $sql2="set names 'utf8';"; 
    268 $zed = mysql_query($sql2); 
    269         $sql="select `lat`,`long`,`place_name` from ".CANALPLAN_CODES." where canalplan_id='".$place."'"; 
    270         $res = mysql_query($sql); 
    271         $row = mysql_fetch_array($res); 
    272         if ($place==$firstid){$firstname=$row[place_name];} 
    273         if ($place==$lastid){$lastname=$row[place_name];} 
    274         $points=$place.",".$row[lat].",".$row[long]; 
    275               $pointx = $row[lat]; 
    276                 $pointy = $row[long];; 
    277                 $nlat = floor($pointx * 1e5); 
    278                 $nlong = floor($pointy * 1e5); 
    279                 $pointstring .= ascii_encode($nlat - $lat) . ascii_encode($nlong - 
    280         $long); 
    281                 $zoomstring .= 'B'; 
    282                 $lat = $nlat; 
    283                 $long = $nlong; 
    284                 $cpoint=$row[place_name].",".$row[lat].",".$row[long]; 
    285                 if ($cpoint==$lpointb1) { 
    286             $lpoints=split(",",$lpoint); 
    287         $turnaround.='var marker'.$dogooglemap.$x.' = new GMarker(encodedPolyline.getVertex('.$y.'),{icon:icon2, draggable: false, title: "Turn Round here : '.$lpoints[0].'"});'; 
    288         $turnaround.='map'.$dogooglemap.'.addOverlay(marker'.$dogooglemap.$x.');'; 
    289          $x=$x+1; 
    290         } 
    291         $lpointb1=$lpoint; 
    292         $y=$y+1; 
    293         $lpoint=$cpoint; 
    294         } 
     633        $mapstuff='<div id="map_canvas_'.$dogooglemap.'"  style="width: '.$canalplan_options["canalplan_rm_width"].'px; height: '.$canalplan_options["canalplan_rm_height"].'px"></div>'; 
     634        foreach ($places as $place) { 
     635            $sql="select `lat`,`long`,`place_name` from ".CANALPLAN_CODES." where canalplan_id='".$place."'"; 
     636            $res = mysql_query($sql); 
     637            $row = mysql_fetch_array($res); 
     638            if ($place==$firstid){ 
     639                $firstname=$row[place_name]; 
     640                $first_lat=$row[lat]; 
     641                $first_long=$row[long]; 
     642            } 
     643            if ($place==$lastid){ 
     644                $lastname=$row[place_name]; 
     645                $last_lat=$row[lat]; 
     646                $last_long=$row[long]; 
     647            } 
     648            if($place_count==$mid_point) { 
     649                $centre_lat=$row[lat]; 
     650                $centre_long=$row[long]; 
     651            }    
     652            $place_count=$place_count+1; 
     653            $points=$place.",".$row[lat].",".$row[long]; 
     654                $pointx = $row[lat]; 
     655            $pointy = $row[long]; 
     656            $nlat = floor($pointx * 1e5); 
     657            $nlong = floor($pointy * 1e5); 
     658            $pointstring .= ascii_encode($nlat - $lat) . ascii_encode($nlong - $long); 
     659            $zoomstring .= 'B'; 
     660            $lat = $nlat; 
     661            $long = $nlong; 
     662            $cpoint=$row[place_name].",".$row[lat].",".$row[long]; 
     663            if ($cpoint==$lpointb1) { 
     664                $lpoints=split(",",$lpoint); 
     665                $turnaround.='var marker_turn'.$dogooglemap.'_'.$x.' = new google.maps.Marker({ position: new google.maps.LatLng('.$lpoints[1].','.$lpoints[2].'), map: map'.$dogooglemap.',   title: "Turn Round here  : '.$lpoints[0].'" });'; 
     666                $turnaround.='iconFile = "http://maps.google.com/mapfiles/ms/icons/blue-dot.png"; marker_turn'.$dogooglemap.'_'.$x.'.setIcon(iconFile) ; '; 
     667                $x=$x+1; 
     668            } 
     669            $lpointb1=$lpoint; 
     670            $y=$y+1; 
     671            $lpoint=$cpoint; 
     672            } 
    295673        if ($firstid==$lastid) { 
    296             $markertext='var marker'.$dogooglemap.'0 = new GMarker(encodedPolyline.getVertex(0), {icon:icon0, draggable: false, title: "Start/Finish : '.$firstname.'"});'; 
    297             $markertext.='map'.$dogooglemap.'.addOverlay(marker'.$dogooglemap.'0);'; 
     674            $markertext='var marker_start'.$dogooglemap.' = new google.maps.Marker({ position: new google.maps.LatLng('.$first_lat.','.$first_long.'), map: map'.$dogooglemap.',   title: "Start / Finish : '.$firstname.'"});'; 
     675            $markertext.='iconFile = "http://maps.google.com/mapfiles/ms/icons/yellow-dot.png"; marker_start'.$dogooglemap.'.setIcon(iconFile) ; '; 
    298676        } 
    299677        else 
    300678        { 
    301             $markertext='var marker'.$dogooglemap.'0 = new GMarker(encodedPolyline.getVertex(0), {icon:icon0, draggable: false, title: "Start : '.$firstname.'"});'; 
    302             $markertext.='var marker'.$dogooglemap.'1 = new GMarker(encodedPolyline.getVertex(encodedPolyline.getVertexCount()-1), {icon:icon1, draggable: false, title:"Finish : '.$lastname.'"});'; 
    303             $markertext.='map'.$dogooglemap.'.addOverlay(marker'.$dogooglemap.'0);'; 
    304             $markertext.='map'.$dogooglemap.'.addOverlay(marker'.$dogooglemap.'1);'; 
    305         } 
    306  
    307          $page2= ' if (GBrowserIsCompatible()) {            if(document.implementation.hasFeature( "http://www.w3.org/TR/SVG11/feature#SVG","1.1")){  _mSvgEnabled = true;  _mSvgForced  = true;}'; 
    308          $page2.= ' var map'.$dogooglemap.' = new GMap2(document.getElementById("map'.$dogooglemap.'")); map'.$dogooglemap.'.setCenter(new GLatLng(52.97035617,-2.508565798), 9); map'.$dogooglemap.'.addControl(new GSmallMapControl());   map'.$dogooglemap.'.addControl(new GMapTypeControl());  map'.$dogooglemap.'.setMapType(G_NORMAL_MAP); map'.$dogooglemap.'.setZoom(9);'; 
    309                  $page2.='var ads'.$dogooglemap.' = new GAdsManager(map'.$dogooglemap.',"pub-4296098225870941",{maxAdsOnMap : 10, style: "icon", channel: "5900391315" , minZoomLevel: 0}); ads'.$dogooglemap.'.enable();'; 
    310          $page2.= ' var baseIcon = new GIcon(); baseIcon.shadow = "/wp-content/plugins/canalplan/canalplan/markers/shadow.png"; baseIcon.iconSize = new GSize(12, 20);  baseIcon.shadowSize = new GSize(22, 20);    baseIcon.iconAnchor = new GPoint(6, 20);    baseIcon.infoWindowAnchor = new GPoint(9, 2);   baseIcon.infoShadowAnchor = new GPoint(18, 25);'; 
    311          $page2.= ' var icon0 = new GIcon(baseIcon); var icon1 = new GIcon(baseIcon);       var icon2 = new GIcon(baseIcon); '; 
    312          $page2.= ' icon0.image = "/wp-content/plugins/canalplan/canalplan/markers/small_green.png"; icon1.image = "/wp-content/plugins/canalplan/canalplan/markers/small_red.png"; icon2.image = "/wp-content/plugins/canalplan/canalplan/markers/small_yellow.png";'; 
    313        $page2.= ' var encodedPolyline = new GPolyline.fromEncoded({    color: "#0000FF",   weight: 2, opacity: 0.8, points: "'.$pointstring.'",    levels: "'.$zoomstring.'",zoomFactor: 32, numLevels: 4 });'; 
    314          $page2.= ' map'.$dogooglemap.'.addOverlay(encodedPolyline);    var bounds = new GLatLngBounds(); for (var i=0; i<encodedPolyline.getVertexCount()-1; i++) {  bounds.extend(encodedPolyline.getVertex(i));}'; 
    315          $page2.= '  var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat())/2; var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng())/2;    map'.$dogooglemap.'.setCenter(new GLatLng(clat,clng)); map'.$dogooglemap.'.setZoom(map'.$dogooglemap.'.getBoundsZoomLevel(bounds));}'; 
    316  
    317 $page2.=$turnaround.$markertext."</script> <br />"; 
    318  
    319  
    320         $names = array(); 
    321         $links = array(); 
    322         foreach ($places_array as $place_code) { 
    323         $words=split(":",$place_code); 
    324             $names[] = $place_code; 
    325             $links[] =$mapstuff.$page2 ; 
    326         } 
    327         return str_replace($names,$links , $content); 
    328     } 
    329  
    330 // Link Maps 
    331  
    332     function canal_link_maps($content) { 
    333         global $wpdb; 
    334         global $post; 
    335         // First we check the content for tags: 
    336                 if (preg_match_all('/' . preg_quote('[[CPGMW:') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[1]; } 
    337         // If the array is empty then we've no maps so don't do anything! 
    338         if (count($places_array)==0) {return $content;} 
    339          
    340     if ( get_query_var('feed') || $search=='Y' )  { 
    341                 $names = array(); 
    342                 $links = array(); 
    343                  foreach ($places_array as $place_code) { 
    344                 $words=split("\|",$place_code); 
    345                     $names[] = "[[CPGMW:" .$place_code . "]]"; 
    346                     $links[] = "<b>[Embedded Google Map for ".trim($words[0])."]</b>"; 
    347         } 
    348                 return str_replace($names,$links , $content); 
    349         } 
    350  
    351         // Get the Googlemap global and if its zero (i.e. first time called on the page) put out the googlemap key 
    352         global $dogooglemap; 
    353  
    354         $maptype[s]="G_SATELLITE_MAP"; 
    355         $maptype[n]="G_NORMAL_MAP"; 
    356         $maptype[h]="G_HYBRID_MAP"; 
    357         foreach ($places_array as $place_code) { 
    358         $mapstuff="<br />"; 
    359         $words=split("\|",$place_code); 
    360         if ($dogooglemap==0){ 
    361  
    362         } 
    363         // Increment it 
    364         $dogooglemap=$dogooglemap+1; 
    365         // To allow multiple maps per page (for viewing posts by category) append the dogooglemap id to the end of the map div id 
    366         $mapstuff.= '<div id="map'.$dogooglemap.'" style="width: 500px; height: 600px"></div><script type="text/javascript">'; 
    367         $post_id=$post->ID; 
    368  
    369 unset($missingpoly); 
    370 unset($plines); 
    371 unset($weights); 
    372 unset($polylines); 
    373 $missingpoly[]=$words[1]; 
    374 while ( count($missingpoly)>0 ) { 
    375         reset($missingpoly); 
    376 #print "<br>".count($missingpoly)." - "; 
    377 #var_dump($missingpoly); 
    378         $sql="select 1 from ".CANALPLAN_POLYLINES." where id='".current($missingpoly)."';"; 
    379         #print $sql."<br>"; 
    380         $res = mysql_query($sql); 
    381          $rw = mysql_fetch_row($res); 
    382        # print "!!".$rw[0]."H"; 
    383 if ($rw[0]==1){$polylines[]=current($missingpoly);} 
    384         $sql="select id from ".CANALPLAN_CANALS." where parent='".current($missingpoly)."';"; 
    385        # print $sql; 
    386         unset($missingpoly2); 
    387         $res = mysql_query($sql); 
    388         while( $rw = mysql_fetch_row($res)){ 
    389         #print $rw[0]." - "; 
    390         $missingpoly[]=$rw[0]; 
    391 } 
    392 #Get the polyline. If there is one put it into the $polyline[]. 
    393 #Get a list of places where this id is the parent and put them into $missingpoly[] 
    394 #Remove the element from the array 
    395 $missingpoly=array_slice($missingpoly,1); 
    396 #$missingpoly=array_merge($missingpoly,$missingpoly2); 
    397 } 
    398 $markertext=""; 
    399 #var_dump($polylines); 
    400 foreach ($polylines as $polyline) { 
    401         $sql="select pline,weights from ".CANALPLAN_POLYLINES." where id='".$polyline."';"; 
    402        # print $sql."<br>"; 
    403         $res = mysql_query($sql); 
    404          $rw = mysql_fetch_row($res); 
    405 $plines[]=$rw[0]; 
    406 $weights[]=$rw[1]; 
    407 } 
    408 #var_dump($plines); 
    409  
    410  
    411         $page2= ' if (GBrowserIsCompatible()) { if(document.implementation.hasFeature( "http://www.w3.org/TR/SVG11/feature#SVG","1.1")){  _mSvgEnabled = true;  _mSvgForced  = true;}'; 
    412         $page2.= ' var map'.$dogooglemap.' = new GMap2(document.getElementById("map'.$dogooglemap.'")); map'.$dogooglemap.'.setCenter(new GLatLng(52.97035617,-2.508565798), 9); map'.$dogooglemap.'.addControl(new GSmallMapControl());    map'.$dogooglemap.'.addControl(new GMapTypeControl());  map'.$dogooglemap.'.setMapType(G_NORMAL_MAP); map'.$dogooglemap.'.setZoom(9);'; 
    413                 $page2.='var globalbounds = new GLatLngBounds(); var ads'.$dogooglemap.' = new GAdsManager(map'.$dogooglemap.',"pub-4296098225870941",{maxAdsOnMap : 10, style: "icon", channel: "5900391315", minZoomLevel: 0}); ads'.$dogooglemap.'.enable();'; 
    414         $page2.= ' var baseIcon = new GIcon(); baseIcon.shadow = "/wp-content/plugins/canalplan/canalplan/markers/shadow.png";  baseIcon.iconSize = new GSize(12, 20);  baseIcon.shadowSize = new GSize(22, 20);    baseIcon.iconAnchor = new GPoint(6, 20);    baseIcon.infoWindowAnchor = new GPoint(9, 2);   baseIcon.infoShadowAnchor = new GPoint(18, 25);'; 
    415         $page2.= ' var icon0 = new GIcon(baseIcon); var icon1 = new GIcon(baseIcon);        var icon2 = new GIcon(baseIcon); '; 
    416         $page2.= ' icon0.image = "/wp-content/plugins/canalplan/canalplan/markers/small_green.png"; icon1.image = "/wp-content/plugins/canalplan/canalplan/markers/small_red.png"; icon2.image = "/wp-content/plugins/canalplan/canalplan/markers/small_yellow.png";'; 
    417 for ($i=0;$i<count($plines);$i++){ 
    418                 $page2.= ' var encodedPolyline = new GPolyline.fromEncoded({    color: "#0000ff",   weight: 3, opacity: 0.8, points: "'.$plines[$i].'",    levels: "'.$weights[$i].'",zoomFactor: 32, numLevels: 4 });'; 
    419         $page2.= ' map'.$dogooglemap.'.addOverlay(encodedPolyline); '; 
    420         $page2.=' var marker'.$dogooglemap.'0'.$i.'= new GMarker(encodedPolyline.getVertex(0), {icon:icon0, draggable: false});'; 
    421         $page2.=' var marker'.$dogooglemap.'1'.$i.' = new GMarker(encodedPolyline.getVertex(encodedPolyline.getVertexCount()-1), {icon:icon0, draggable: false});'; 
    422         $page2.=' map'.$dogooglemap.'.addOverlay(marker'.$dogooglemap.'0'.$i.');'; 
    423             $page2.=' map'.$dogooglemap.'.addOverlay(marker'.$dogooglemap.'1'.$i.');'; 
    424         $page2.= 'for (var i=0; i<encodedPolyline.getVertexCount()-1; i++) {  globalbounds.extend(encodedPolyline.getVertex(i));} '; 
    425 } 
    426  
    427                 $page2.='var clat = (globalbounds.getNorthEast().lat() + globalbounds.getSouthWest().lat())/2; var clng = (globalbounds.getNorthEast().lng() + globalbounds.getSouthWest().lng())/2;    map' .$dogooglemap.'.setCenter(new GLatLng(clat,clng)); map'.$dogooglemap.'.setZoom(map'.$dogooglemap.'.getBoundsZoomLevel(globalbounds));}'; 
    428  
    429  
    430 $page2.=$turnaround.$markertext."</script> <br />"; 
    431       $names[] = "[[CPGMW:" .$place_code . "]]"; 
    432       $links[] = $mapstuff.$page2; 
    433       } 
    434  
    435 return str_ireplace($matches[0], $links, $content); 
    436     } 
    437  
    438  
    439 function canal_place_maps($content,$mapblog_id=NULL,$post_id=NULL) { 
    440 $gazstring=CANALPLAN_URL.'gazetteer.cgi?id='; 
    441     // First we check the content for tags: 
    442     if (preg_match_all('/' . preg_quote('[[CPGM:') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[1]; } 
    443  
    444     // If the array is empty then we've no links so don't do anything! 
    445     if (count($places_array)==0) {return $content;} 
    446  
    447 if (isset($mapblog_id)) {} else { $mapblog_id=$wpdb->blogid;} 
    448 if (isset($post_id)) {} else {$post_id=$post->ID; 
    449                 if (isset($post->blog_id)) {$mapblog_id=$post->blog_id;}} 
    450     $names = array(); 
    451     $links = array(); 
    452     // Get the Googlemap global and if its zero (i.e. first time called on the page) put out the googlemap key 
    453     global $dogooglemap; 
    454     global $wpdb; 
    455     global $post; 
    456     #$mapblog_id=$wpdb->blogid; 
    457     #if (isset($post->blog_id)) {$mapblog_id=$post->blog_id;} 
    458     if ( get_query_var('feed')) { 
    459  
    460     foreach ($places_array as $place_code) { 
    461     $words=split("\|",$place_code); 
    462         $names[] = "[[CPGM:" .$place_code . "]]"; 
    463         $links[] = "<b>[Embedded Google Map for ".trim($words[0])."]</b>"; 
    464         } 
    465     return str_ireplace($names, $links, $content); 
    466     } 
    467     $maptype[s]="G_SATELLITE_MAP"; 
    468     $maptype[n]="G_NORMAL_MAP"; 
    469     $maptype[h]="G_HYBRID_MAP"; 
    470     foreach ($places_array as $place_code) { 
    471     $words=split("\|",$place_code); 
    472     $sql="select lat,`long` from ".CANALPLAN_CODES." where canalplan_id='".$words[1]."'"; 
    473      $res = mysql_query($sql); 
    474     $row = mysql_fetch_array($res); 
    475     // set defaults 
    476     $options[size]=300; 
    477     $options[zoom]=18; 
    478     $options[type]=s; 
    479     $options[lat]=$row[lat]; 
    480     $options[long]=$row[long]; 
    481 $opts=split(",",$words[2]); 
    482  foreach ($opts as $opt) { 
    483      $opcode=split("=",$opt); 
    484      $options[$opcode[0]]=$opcode[1]; 
    485  } 
    486     $mapstuff="<br />"; 
    487     if ($dogooglemap==0){ 
    488  
    489 $mapstuff.= <<< EOGS 
    490       <script> 
    491       var baseIcon = new GIcon(); 
    492       baseIcon.shadow = "/wp-content/plugins/canalplan/canalplan/markers/shadow.png"; 
    493       baseIcon.iconSize = new GSize(19, 33); 
    494       baseIcon.shadowSize = new GSize(36, 33); 
    495       baseIcon.iconAnchor = new GPoint(9, 33); 
    496       baseIcon.infoWindowAnchor = new GPoint(9, 2); 
    497       baseIcon.infoShadowAnchor = new GPoint(18, 25); 
    498       var icon0 = new GIcon(baseIcon); 
    499       icon0.iconSize = new GSize(12, 20); 
    500       icon0.shadowSize = new GSize(22, 20); 
    501       icon0.iconAnchor = new GPoint(6, 20); 
    502       icon0.image = "/wp-content/plugins/canalplan/canalplan/markers/small_green.png"; 
    503       </script> 
    504 EOGS; 
    505 #$mapstuff.=$mapstuff2; 
    506     } 
    507     // Increment it 
    508     $dogooglemap=$dogooglemap+1; 
    509     // To allow multiple maps per page/entry append the dogooglemap id to the end of the map div id 
    510  
    511     $mapstuff.= '<div id="map'.$dogooglemap.'" style="width: '.$options[size].'px; height: '.$options[size].'px"></div><script type="text/javascript" defer="defer"> '; 
    512     $mapstuff.='var point = new Array(); var map'.$dogooglemap.' = new GMap2(document.getElementById("map'.$dogooglemap.'"));'; 
    513     $mapstuff.='map'.$dogooglemap.'.addControl(new GSmallMapControl()); map'.$dogooglemap.'.addControl(new GMapTypeControl()); map'.$dogooglemap.'.setCenter(new GLatLng('.$options[lat].','.$options[long].'), '.$options[zoom].', '.$maptype[$options[type]].');'; 
    514 #$mapstuff.=' var adsManagerOptions = { maxAdsOnMap : 5, style: G_ADSMANAGER_STYLE_ICON", channel: "5900391315" };'; 
    515     $mapstuff.='var ads'.$dogooglemap.' = new GAdsManager(map'.$dogooglemap.',"pub-4296098225870941",{maxAdsOnMap : 10, style: G_ADSMANAGER_STYLE_ICON, channel: "5900391315", minZoomLevel: 0}); ads'.$dogooglemap.'.enable();'; 
    516    $mapstuff.='point['.$dogooglemap.'] = new GLatLng('.$options[lat].','.$options[long].'); var marker'.$dogooglemap.' = new GMarker(point['.$dogooglemap.'], {icon:icon0, title:"'.trim($words[0]).'"});'; 
    517    $mapstuff.='map'.$dogooglemap.'.addOverlay(marker'.$dogooglemap.');'; 
    518    $mapstuff.='GEvent.addListener(marker'.$dogooglemap.', "click", function(){marker'.$dogooglemap.'.openInfoWindowHtml("'.trim($words[0]).'"); });'; 
    519    $mapstuff.='map'.$dogooglemap.'.addOverlay(new Textbox(new GLatLng('.$options[lat].','.$options[long].'),"<b>'.trim($words[0]).'</b>"));'; 
    520     $mapstuff.='</script>'; 
    521       $names[] = "[[CPGM:" .$place_code . "]]"; 
    522       $links[] = $mapstuff; 
    523       } 
    524 return str_ireplace($matches[0], $links, $content); 
    525     } 
    526  
    527         function canal_stats($content,$mapblog_id=NULL,$post_id=NULL) { 
    528                 // First we check the content for tags: 
    529         global $blog_id,$wpdb,$post; 
    530                 if (preg_match_all('/' . preg_quote('[[CPRS') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[0]; } 
    531  
    532                 // If the array is empty then we've no links so don't do anything! 
    533                 if (count($places_array)==0) {return $content;} 
    534     if (isset($mapblog_id)) {} else { $mapblog_id=$blog_id;} 
    535     if (isset($post_id)) {} else {$post_id=$post->ID; 
    536                 if (isset($post->blog_id)) {$mapblog_id=$post->blog_id;}} 
    537       $sql="select distance,`locks`,start_id,end_id from ".CANALPLAN_ROUTE_DAY." where blog_id=".$mapblog_id." and  post_id=".$post_id; 
     679            $markertext='var marker_start'.$dogooglemap.' = new google.maps.Marker({ position: new google.maps.LatLng('.$first_lat.','.$first_long.'), map: map'.$dogooglemap.',   title: "Start : '.$firstname.'" });'; 
     680            $markertext.='var marker_stop'.$dogooglemap.' = new google.maps.Marker({ position: new google.maps.LatLng('.$last_lat.','.$last_long.'), map: map'.$dogooglemap.',  title: "Stop : '.$lastname.'" });'; 
     681            $markertext.='iconFile = "http://maps.google.com/mapfiles/ms/icons/green-dot.png"; marker_start'.$dogooglemap.'.setIcon(iconFile) ; '; 
     682            $markertext.='iconFile = "http://maps.google.com/mapfiles/ms/icons/red-dot.png"; marker_stop'.$dogooglemap.'.setIcon(iconFile) ; ';  
     683        } 
     684        #$blroute .=$pointstring; 
     685        $options['size']=200; 
     686        $options['zoom']=$canalplan_options["canalplan_rm_zoom"]; 
     687        $options['type']=$canalplan_options["canalplan_rm_type"]; 
     688        $options['lat']=53.4; 
     689        $options['long']=-2.8;   
     690        $options['rgb']=$canalplan_options["canalplan_rm_r_hex"].$canalplan_options["canalplan_rm_g_hex"].$canalplan_options["canalplan_rm_b_hex"]; 
     691        $maptype[S]="SATELLITE"; 
     692        $maptype[R]="ROADMAP"; 
     693        $maptype[T]="TERRAIN"; 
     694        $maptype[H]="HYBRID"; 
     695        $google_map_code.= 'var map_'.$dogooglemap.'_opts = { zoom: '.$options['zoom'].',center: new google.maps.LatLng('.$centre_lat.','.$centre_long.'),'; 
     696            $google_map_code.='  scrollwheel: false, navigationControl: true, mapTypeControl: true, scaleControl: false, draggable: false,'; 
     697            $google_map_code.= ' mapTypeId: google.maps.MapTypeId.'.$maptype[$options['type']].' };'; 
     698            $google_map_code.= 'var map'.$dogooglemap.' = new google.maps.Map(document.getElementById("map_canvas_'.$dogooglemap.'"),map_'.$dogooglemap.'_opts);'; 
     699            $google_map_code.='  var polyOptions'.$dogooglemap.' = {strokeColor: "#'.$options['rgb'].'", strokeOpacity: 1.0,strokeWeight: '.$canalplan_options["canalplan_rm_weight"].' }; '; 
     700        $i=1; 
     701        $google_map_code.=' var line'.$dogooglemap.'_'.$i.' = new google.maps.Polyline(polyOptions'.$dogooglemap.');'; 
     702        $google_map_code.=' line'.$dogooglemap.'_'.$i.'.setPath(google.maps.geometry.encoding.decodePath("'.$pointstring.'"));'; 
     703        $google_map_code.=' line'.$dogooglemap.'_'.$i.'.setMap(map'.$dogooglemap.');'; 
     704        $google_map_code.='var bounds'.$dogooglemap.' = new google.maps.LatLngBounds();'; 
     705        $google_map_code.='line'.$dogooglemap.'_'.$i.'.getPath().forEach(function(latLng) {bounds'.$dogooglemap.'.extend(latLng);});'; 
     706        $google_map_code.='map'.$dogooglemap.'.fitBounds(bounds'.$dogooglemap.');'; 
     707        $google_map_code.=$turnaround.$markertext; 
     708        $blroute .= $page; 
     709        $blroute .= $page2; 
     710        $blroute .= $page3; 
     711        $blroute .= "<p><h2>Blog Entries for this trip</h2>"; 
     712        $sql2="set names 'utf8';"; 
     713        $zed = mysql_query($sql2); 
     714        $sql="select id, post_title from ".$wpdb->posts." where id in (select post_id from ".CANALPLAN_ROUTE_DAY." where blog_id=".$wpdb->blogid." and  route_id=".$routeid." ) order by post_date"; 
    538715        $res = mysql_query($sql); 
    539         $row = mysql_fetch_array($res); 
    540         $sql="select totalroute,uom from ".CANALPLAN_ROUTES." cpr, ".CANALPLAN_ROUTE_DAY." crd where cpr.route_id= crd.route_id and cpr.blog_id=crd.blog_id and crd.blog_id=".$mapblog_id." and  crd.post_id=".$post_id; 
    541         $res3 = mysql_query($sql); 
    542         $row3 = mysql_fetch_array($res3); 
    543                 $dformat=$row3[uom]; 
    544         $places=split(",",$row3[totalroute]); 
    545         #print "!!!".$places[$row[start_id]-1]."££££".$places[$row[end_id]]; 
    546 #       $sql="select place_name from canalplan_codes where canalplan_id='".$places[$row[start_id]]."'"; 
    547 $sql2="set names 'utf8';"; 
    548 $zed = mysql_query($sql2); 
    549 $sql="select place_name from ".CANALPLAN_FAVOURITES." where canalplan_id='".$places[$row[start_id]]."' and blog_id=".$mapblog_id." union select place_name from ".CANALPLAN_CODES." where canalplan_id='".$places[$row[start_id]]."' and canalplan_id not in (select canalplan_id from ".CANALPLAN_FAVOURITES." where canalplan_id='".$places[$row[start_id]]."' and blog_id=".$mapblog_id.")"; 
    550 #print $sql; 
    551         $res2 = mysql_query($sql); 
    552         $row2 = mysql_fetch_array($res2); 
    553         $start_name=$row2[place_name]; 
    554 #       $sql="select place_name from canalplan_codes where canalplan_id='".$places[$row[end_id]]."'"; 
    555 $sql="select place_name from ".CANALPLAN_FAVOURITES." where canalplan_id='".$places[$row[end_id]]."' and blog_id=".$mapblog_id." union select place_name from ".CANALPLAN_CODES." where canalplan_id='".$places[$row[end_id]]."' and canalplan_id not in (select canalplan_id from ".CANALPLAN_FAVOURITES." where canalplan_id='".$places[$row[end_id]]."' and blog_id=".$mapblog_id.")"; 
    556  
    557         $res2 = mysql_query($sql); 
    558         $row2 = mysql_fetch_array($res2); 
    559         $end_name=$row2[place_name]; 
    560  
    561         $names = array(); 
    562         $links = array(); 
    563         foreach ($places_array as $place_code) { 
    564         $words=split(":",$place_code); 
    565             $names[] = $place_code; 
    566             $links[] = "From [[CP:".$start_name."|".$places[$row[start_id]]."]] to [[CP:".$end_name."|".$places[$row[end_id]]."]], ".format_distance($row[distance],$row[locks],$dformat,2); 
    567         } 
    568         return str_ireplace($names, $links, $content); 
    569     } 
    570  
    571  
    572  
    573     function canal_linkify($content) { 
    574         global $post,$blog_id; 
    575         // First we check the content for tags: 
    576         if (preg_match_all('/' . preg_quote('[[CP') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[1]; } 
    577         // If the array is empty then we've no links so don't do anything! 
    578         #if (count($places_array)==0) {return $content;} 
    579                 $names = array(); 
    580         $links = array(); 
    581                 if (preg_match_all('/' . preg_quote('[[CP:') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[1];  
    582                 $gazstring=CANALPLAN_URL.'gazetteer.cgi?id='; 
    583         $x="SELECT pref_value FROM ".CANALPLAN_OPTIONS." where  blog_id=".$blog_id." and pref_code='canalkey'"; 
    584     #   var_dump($x); 
    585         $r2 = mysql_query("SELECT pref_value FROM ".CANALPLAN_OPTIONS." where  blog_id=".$blog_id." and pref_code='canalkey'"); 
    586         if (mysql_num_rows($r2)==0) { 
    587              $api=""; 
    588         } 
    589         else 
    590         { 
    591             $rw = mysql_fetch_array($r2,MYSQL_ASSOC); 
    592         #   var_dump($rw); 
    593             $api=explode("|",$rw['pref_value']); 
    594             $blog_url=get_bloginfo('url'); 
    595             $date = date("Ymd",strtotime($post->post_date)); 
    596             $link=urlencode(str_replace($blog_url,"",get_permalink($post->ID))); 
    597             $title=urlencode($post->post_title); 
    598      
    599         }  
    600         foreach ($places_array as $place_code) { 
    601         $words=split("\|",$place_code); 
    602             $names[] = "[[CP:" .$place_code . "]]"; 
    603             if ($api[0]=="") { 
    604                 $links[] = "<a href='".CANALPLAN_GAZ_URL.$words[1]."' target='gazetteer'  title='Link to ".trim($words[0])."'>".trim($words[0])."</a>"; 
    605             } else  
    606             { 
    607                 $links[] = "<a href='". CANALPLAN_GAZ_URL .$words[1]. "?blogkey=".$api[0]."&title=".$title."&blogid=".$api[1]."&date=".$date."&url=".$link."' target='gazetteer' title='Link to ".trim($words[0])."'>".trim($words[0])."</a>"; 
    608             } 
    609         } 
    610                 } 
    611                 if (preg_match_all('/' . preg_quote('[[CPW:') . '(.*?)' . preg_quote(']]') .'/',$content,$matches)) { $places_array=$matches[1];  
    612                 $gazstring=CANALPLAN_URL.'waterway.cgi?id='; 
    613         foreach ($places_array as $place_code) { 
    614         $words=split("\|",$place_code); 
    615             $names[] = "[[CPW:" .$place_code . "]]"; 
    616             $links[] = "<a href='".$gazstring.$words[1]."' target='gazetteer'  title='Link to ".trim($words[0])."'>".trim($words[0])."</a>"; 
    617         }} 
    618         return str_ireplace($names, $links, $content); 
    619     } 
    620  
    621     function canal_options_page() { 
    622         global $wpdb; 
    623         if (!current_user_can('manage_options')) { 
    624             die('You don&#8217;t have sufficient permission to access this file.'); 
    625         } 
    626         if (isset($_POST['update'])) { 
    627             check_admin_referer('canalplan-autolinker-update-options'); 
    628             update_option('canalplan-autolinker-begin', $wpdb->escape($_POST['begin'])); 
    629             update_option('canalplan-autolinker-end', $wpdb->escape($_POST['end'])); 
    630             echo '<div id="message" class="updated fade"><p><strong>Options saved.</strong></p></div>'; 
    631         } 
    632 ?> 
    633  
    634 <?php 
    635     } 
    636 } 
    637  
    638  
     716        $blroute .="<ol>"; 
     717        while ($row = mysql_fetch_array($res)) { 
     718            $link = get_blog_permalink( $blog_id, $row[id] ) ; 
     719            $blroute .="<li><a href=\"$link\" target=\"_new\">$row[post_title]</a> </li>"; 
     720        } 
     721        $blroute .="</ol>"; 
     722    } 
     723    return $blroute ; 
     724} 
    639725 
    640726function wp_canalplan_admin_pages() { 
    641  
    642727    $base_dir=dirname(__FILE__).'/admin-pages/';  
    643728    $hook=add_menu_page('CanalPlan AC Overview', 'CanalPlan AC', 8,$base_dir.'cp-admin-menu.php'); 
     
    645730    add_submenu_page($base_dir.'cp-admin-menu.php', 'CanalPlan Options: Home Mooring', 'Home Mooring', 8, $base_dir.'cp-admin-home.php'); 
    646731    add_submenu_page($base_dir.'cp-admin-menu.php', 'CanalPlan Options: Favourites', 'Favourites', 8,  $base_dir.'cp-admin-fav.php'); 
     732    add_submenu_page($base_dir.'cp-admin-menu.php', 'CanalPlan Options: Google Maps', 'Google Maps', 8,  $base_dir.'cp-admin-google.php'); 
    647733    add_submenu_page($base_dir.'cp-admin-menu.php', 'CanalPlan Options: Import Route', 'Import Routes', 8,  $base_dir.'cp-import_route.php'); 
    648734    add_submenu_page($base_dir.'cp-admin-menu.php', 'CanalPlan Options: Manage Routes', 'Manage Routes', 8,  $base_dir.'cp-manage_route.php'); 
     
    651737} 
    652738 
    653  
    654739function canalplan_header($blah){ 
    655 global $blog_id,$wpdb; 
    656 if (!defined('CANALPLAN_GMAP_KEY')) { 
    657 $r2 = mysql_query("SELECT pref_value FROM ".CANALPLAN_OPTIONS." where blog_id=".$blog_id." and pref_code='apikey'"); 
    658 if (mysql_num_rows($r2)==0) { 
    659      $api=""; 
    660 } 
    661 else 
    662 { 
    663     $rw = mysql_fetch_array($r,MYSQL_ASSOC); 
    664     $api=$rw['pref_value']; 
    665 }  
    666 } else {$api=CANALPLAN_GMAP_KEY;} 
    667 echo '<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key='.$api.'" type="text/javascript"></script>'; 
    668 #echo '<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script>'; 
    669 echo '<meta name="verify-v1" content="gh8YjrQxNNQP2cet22ZdfXucI+py1YHC/6eczI1ljHc=" />'; 
    670 return $blah; 
     740    global $blog_id,$wpdb,$google_map_code; 
     741    $header = '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <script type="text/javascript" src="//maps.google.com/maps/api/js?libraries=geometry&amp;sensor=false"> </script> ';  
     742    echo $header; 
     743    $google_map_code='<script type="text/javascript">  function initialize() {  '; 
     744    return $blah; 
    671745} 
    672746 
    673747function canalplan_footer($blah) { 
     748    global $google_map_code; 
     749    $google_map_code.='  } </script> '; 
     750    echo $google_map_code; 
    674751    echo "\n<!-- Canalplan AC code revision : ".CANALPLAN_CODE_RELEASE." -->\n"; 
    675     echo "<p style='font-size:80%'>Canalplan Interlinking provided by <a href='http://wordpress.org/extend/plugins/canalplan-ac/'> Canalplan AC Plugin </a></p>"; 
     752    #echo "<p style='font-size:0%'>Canalplan Interlinking provided by <a href='http://wordpress.org/extend/plugins/canalplan-ac/'> Canalplan AC Plugin </a></p>"; 
     753    echo "<script type='text/javascript'> google.maps.event.addDomListener(window, 'load', initialize); </script> "; 
    676754    return $blah; 
    677 } 
    678  
    679 function blroute (){ 
    680  
    681 $routeid = $_REQUEST['routeid']; 
    682 $routeid = preg_replace('{/$}', '', $routeid); 
    683  
    684 if (!isset($routeid)){$routeid=0;} 
    685 if ($routeid<=0){$routeid=0;} 
    686 global $wpdb,$blog_id; 
    687  
    688  
    689 $blroute=""; 
    690 if ($routeid==0){ 
    691 #   $blroute .="<h2>Available Trip Reports</h2>"; 
    692 $sql2="set names 'utf8';"; 
    693 $zed = mysql_query($sql2); 
    694 if ($wpdb->blogid==1) { 
    695 $sql="select route_id,title,blog_id from ".CANALPLAN_ROUTES." where status=3"; 
    696 } 
    697 else 
    698 { 
    699 $sql="select route_id, title,description,blog_id from ".CANALPLAN_ROUTES." where status=3 and blog_id=$blog_id"; 
    700 } 
    701 if (!defined('CANALPLAN_ROUTE_SLUG')){ 
    702 $r2 = mysql_query("SELECT pref_value FROM ".CANALPLAN_OPTIONS." where blog_id=-1 and pref_code='routeslug'"); 
    703 if (mysql_num_rows($r2)==0) { 
    704      $routeslug="UNDEFINED!"; 
    705 } 
    706 else 
    707 { 
    708 while($rw = mysql_fetch_array($r2)) 
    709 { 
    710 $routeslug=$rw['pref_value']; 
    711 } 
    712 }  
    713 } else {$routeslug=CANALPLAN_ROUTE_SLUG;} 
    714 $res = mysql_query($sql); 
    715  
    716 $blroute .="<ol>"; 
    717 while ($row = mysql_fetch_array($res)) {; 
    718 if ($wpdb->blogid==1) {$blroute .='<li><a href='.get_blog_option($row[blog_id],"siteurl").'/'.$routeslug.'/'.$row[route_id].' target=\"_new\">'.$row[title].'</a> ( from '. get_blog_option($row[blog_id],'blogname').' )  </li>';} 
    719 else 
    720 { 
    721 $blroute .='<li><a href='.get_blog_option($row[blog_id],"siteurl").'/'.$routeslug.'/'.$row[route_id].' target=\"_new\">'.$row[title].'</a> ('.$row[description].')</li>';} 
    722 } 
    723 $blroute .="</ol><br><br>"; 
    724  
    725 } 
    726  
    727 else 
    728  
    729 { 
    730 $sql2="set names 'utf8';"; 
    731 $zed = mysql_query($sql2); 
    732 $sql="select description, totalroute from ".CANALPLAN_ROUTES." where route_id=".$routeid." and blog_id=".$wpdb->blogid; 
    733 $res = mysql_query($sql); 
    734 $row = mysql_fetch_array($res); 
    735 $blroute .="<h2>".$row[description]."</h2>"; 
    736 $pointstring = ""; 
    737 $zoomstring = ""; 
    738 $lat = 0; 
    739 $long = 0; 
    740 $lpoint=""; 
    741 $lpointb1=""; 
    742 $x=3; 
    743 $y=-1; 
    744 $places=split(",",$row[totalroute]); 
    745 $lastid=end($places); 
    746 $firstid=reset($places); 
    747 $turnaround=""; 
    748 foreach ($places as $place) { 
    749 $sql="select `lat`,`long`,`place_name` from ".CANALPLAN_CODES." where canalplan_id='".$place."'"; 
    750 $res = mysql_query($sql); 
    751 $row = mysql_fetch_array($res); 
    752 if ($place==$firstid){$firstname=$row[place_name];} 
    753 if ($place==$lastid){$lastname=$row[place_name];} 
    754 $points=$place.",".$row[lat].",".$row[long]; 
    755       $pointx = $row[lat]; 
    756         $pointy = $row[long]; 
    757 #   $blroute .="!".$pointx."!".$pointy."!<br>"; 
    758         $nlat = floor($pointx * 1e5); 
    759         $nlong = floor($pointy * 1e5); 
    760         $pointstring .= ascii_encode($nlat - $lat) . ascii_encode($nlong - 
    761 $long); 
    762         $zoomstring .= 'B'; 
    763         $lat = $nlat; 
    764         $long = $nlong; 
    765         $cpoint=$row[place_name].",".$row[lat].",".$row[long]; 
    766       # $blroute .="$$$$".$cpoint."!!!".$lpointb1."£££<br>"; 
    767         if ($cpoint==$lpointb1) { 
    768     $lpoints=split(",",$lpoint); 
    769 #   $blroute .="Turn round at ".$lpoints[0]; 
    770 $turnaround.='var marker'.$x.' = new GMarker(encodedPolyline.getVertex('.$y.'),{icon:icon2, draggable: false, title: "Turn Round here : '.$lpoints[0].'"});'; 
    771 $turnaround.='map.addOverlay(marker'.$x.');'; 
    772  $x=$x+1; 
    773 } 
    774 $lpointb1=$lpoint; 
    775 $y=$y+1; 
    776 $lpoint=$cpoint; 
    777 } 
    778 if ($firstid==$lastid) { 
    779     $markertext='var marker0 = new GMarker(encodedPolyline.getVertex(0), {icon:icon0, draggable: false, title: "Start/Finish : '.$firstname.'"});'; 
    780     $markertext.='map.addOverlay(marker0);'; 
    781 } 
    782 else 
    783 { 
    784     $markertext='var marker0 = new GMarker(encodedPolyline.getVertex(0), {icon:icon0, draggable: false, title: "Start : '.$firstname.'"});'; 
    785     $markertext.='var marker1 = new GMarker(encodedPolyline.getVertex(encodedPolyline.getVertexCount()-1), {icon:icon1, draggable: false, title:"Finish : '.$lastname.'"});'; 
    786     $markertext.='map.addOverlay(marker0);'; 
    787     $markertext.='map.addOverlay(marker1);'; 
    788 } 
    789 #$blroute .=$pointstring; 
    790  
    791  
    792 $page= <<< EOGS 
    793         <div id="map" style="width: 500px; height: 600px"></div> 
    794  
    795       <script type="text/javascript"> 
    796  
    797  
    798   if (GBrowserIsCompatible()) { 
    799     // Make sure that SVG is on. 
    800     if(document.implementation.hasFeature( 
    801         "http://www.w3.org/TR/SVG11/feature#SVG","1.1")){ 
    802       _mSvgEnabled = true; 
    803       _mSvgForced  = true; 
    804     } 
    805     // Set up the map. 
    806             var map = new GMap2(document.getElementById("map")); 
    807       map.setCenter(new GLatLng(52.97035617,-2.508565798), 9); 
    808         map.addControl(new GSmallMapControl()); 
    809         map.addControl(new GMapTypeControl()); 
    810         map.setMapType(G_NORMAL_MAP); 
    811         map.setZoom(9); 
    812 var publisher_id = 'pub-4296098225870941'; 
    813  
    814 var adsManagerOptions = { 
    815   maxAdsOnMap : 10, 
    816   style: 'icon', 
    817   // The channel field is optional - replace this field with a channel number  
    818   // for Google AdSense tracking 
    819   channel: '5900391315'   
    820 }; 
    821 adsManager = new GAdsManager(map, publisher_id, adsManagerOptions); 
    822 adsManager.enable(); 
    823 var baseIcon = new GIcon(); 
    824 baseIcon.shadow = "/wp-content/plugins/canalplan/canalplan/markers/shadow.png"; 
    825 baseIcon.iconSize = new GSize(12, 20); 
    826 baseIcon.shadowSize = new GSize(22, 20); 
    827 baseIcon.iconAnchor = new GPoint(6, 20); 
    828 baseIcon.infoWindowAnchor = new GPoint(9, 2); 
    829 baseIcon.infoShadowAnchor = new GPoint(18, 25); 
    830 var icon0 = new GIcon(baseIcon); 
    831 var icon1 = new GIcon(baseIcon); 
    832 var icon2 = new GIcon(baseIcon); 
    833 icon0.image = "/wp-content/plugins/canalplan/canalplan/markers/small_green.png"; 
    834 icon1.image = "/wp-content/plugins/canalplan/canalplan/markers/small_red.png"; 
    835 icon2.image = "/wp-content/plugins/canalplan/canalplan/markers/small_yellow.png"; 
    836 var encodedPolyline = new GPolyline.fromEncoded({ 
    837     color: "#0000FF", 
    838     weight: 3, 
    839 EOGS; 
    840 $page.='points: "'.$pointstring.'",    levels: "'.$zoomstring.'",'; 
    841 $page2= <<< BARF2 
    842     zoomFactor: 32, 
    843     numLevels: 4, opacity: 0.8 
    844 }); 
    845  
    846                 map.addOverlay(encodedPolyline); 
    847                 var bounds = new GLatLngBounds(); 
    848 for (var i=0; i<encodedPolyline.getVertexCount()-1; i++) { 
    849 //  alert(encodedPolyline.getVertex(i)); 
    850   bounds.extend(encodedPolyline.getVertex(i)); 
    851                     } 
    852 //alert(map.getBoundsZoomLevel(bounds)); 
    853                     var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat())/2; 
    854                     var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng())/2; 
    855                     map.setCenter(new GLatLng(clat,clng)); 
    856 map.setZoom(map.getBoundsZoomLevel(bounds)); 
    857 } 
    858 BARF2; 
    859  
    860 $page2.=$turnaround.$markertext; 
    861 $page3=<<< BARF3 
    862         </script> <br /> 
    863 BARF3; 
    864 $blroute .= $page; 
    865 $blroute .= $page2; 
    866 $blroute .= $page3; 
    867 $blroute .= "<h2>Blog Entries for this trip</h2>"; 
    868 $sql2="set names 'utf8';"; 
    869 $zed = mysql_query($sql2); 
    870  
    871 $sql="select id, post_title from ".$wpdb->posts." where id in (select post_id from ".CANALPLAN_ROUTE_DAY." where blog_id=".$wpdb->blogid." and  route_id=".$routeid." ) order by post_date"; 
    872 $res = mysql_query($sql); 
    873 $blroute .="<ol>"; 
    874  
    875 while ($row = mysql_fetch_array($res)) { 
    876 $link = get_blog_permalink( $blog_id, $row[id] ) ; 
    877 $blroute .="<li><a href=\"$link\" target=\"_new\">$row[post_title]</a> </li>"; 
    878 } 
    879 $blroute .="</ol>"; 
    880  
    881 } 
    882  
    883 return $blroute ; 
    884755} 
    885756 
     
    895766 
    896767function canal_activate() { 
    897 #add_option('canalplan-autolinker-begin', '['); 
    898     #add_option('canalplan-autolinker-end', ']'); 
    899768    global $wpdb, $table_prefix; 
    900769    wp_cache_flush(); 
     
    907776    $result = $wpdb->query( $sql ); 
    908777    if ($result === false) $errors[] = __('Failed to create ') . CANALPLAN_ALIASES ; 
    909  
    910778    $sql= 'CREATE TABLE IF NOT EXISTS '.CANALPLAN_CODES.' ( 
    911779      `canalplan_id` varchar(10) NOT NULL , 
     
    923791    $result = $wpdb->query( $sql ); 
    924792    if ($result === false) $errors[] = __('Failed to create ') . CANALPLAN_CODES ; 
    925  
    926  
    927793    $sql='CREATE TABLE IF NOT EXISTS '.CANALPLAN_FAVOURITES.' ( 
    928794      `blog_id` bigint(20) NOT NULL default 0, 
     
    935801    $result = $wpdb->query( $sql ); 
    936802    if ($result === false) $errors[] = __('Failed to create ') . CANALPLAN_FAVOURITES ; 
    937  
    938  
    939803    $sql='CREATE TABLE IF NOT EXISTS '.CANALPLAN_LINK.' ( 
    940804      `place1` varchar(4) NOT NULL , 
     
    948812    $result = $wpdb->query( $sql ); 
    949813    if ($result === false) $errors[] = __('Failed to create ') . CANALPLAN_LINK ; 
    950  
    951  
    952814    $sql='CREATE TABLE IF NOT EXISTS '.CANALPLAN_OPTIONS.' ( 
    953815      `blog_id` bigint(20) NOT NULL default 0, 
     
    958820    $result = $wpdb->query( $sql ); 
    959821    if ($result === false) $errors[] = __('Failed to create ') . CANALPLAN_OPTIONS ; 
    960  
    961  
    962822    $sql='CREATE TABLE IF NOT EXISTS '.CANALPLAN_ROUTES.' ( 
    963823          `route_id` bigint(10) NOT NULL default 0, 
     
    979839    $result = $wpdb->query( $sql ); 
    980840    if ($result === false) $errors[] = __('Failed to create ') . CANALPLAN_ROUTES ; 
    981  
    982  
    983841    $sql='CREATE TABLE IF NOT EXISTS '.CANALPLAN_CANALS.' ( 
    984842      `id` varchar(4) NOT NULL, 
     
    991849    $result = $wpdb->query( $sql ); 
    992850    if ($result === false) $errors[] = __('Failed to create ') . CANALPLAN_CANALS ; 
    993  
    994  
    995851    $sql='CREATE TABLE IF NOT EXISTS '.CANALPLAN_POLYLINES.' ( 
    996852      `id` varchar(5) NOT NULL, 
     
    1001857    $result = $wpdb->query( $sql ); 
    1002858    if ($result === false) $errors[] = __('Failed to create ') . CANALPLAN_POLYLINES ; 
    1003  
    1004859    $sql='CREATE TABLE IF NOT EXISTS '.CANALPLAN_ROUTE_DAY.' ( 
    1005860      `route_id` bigint(10) NOT NULL default 0, 
     
    1016871      KEY `post_blog_idx` (`blog_id`,`post_id`) 
    1017872    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;'; 
    1018  
    1019873    $result = $wpdb->query( $sql ); 
    1020874    if ($result === false) $errors[] = __('Failed to create ') . CANALPLAN_POLYLINES ; 
     
    1029883} 
    1030884 
    1031 add_action('activated_plugin','save_error'); 
     885function canalplan_option_init(){ 
     886    register_setting( 'canalplan_options', 'canalplan_options','canalplan_validate_options'); 
     887} 
     888 
     889function canalplan_validate_options($options) { 
     890    # Do they want to reset? If so we reset the options and let WordPress do the business for us! 
     891    if (isset( $_POST["RSD"] ))  { 
     892        $options["canalplan_pm_type"]='H'; 
     893        $options["canalplan_pm_zoom"]=14; 
     894        $options["canalplan_pm_height"]=200; 
     895        $options["canalplan_pm_width"]=200; 
     896        $options["canalplan_rm_type"]='H'; 
     897        $options["canalplan_rm_zoom"]=9; 
     898        $options["canalplan_rm_height"]=600; 
     899        $options["canalplan_rm_width"]=500; 
     900        $options["canalplan_rm_r_hex"]="00"; 
     901        $options["canalplan_rm_g_hex"]="00"; 
     902        $options["canalplan_rm_b_hex"]="ff"; 
     903        $options["canalplan_rm_weight"]=4; 
     904    } 
     905    return $options; 
     906} 
     907 
     908add_action('admin_init', 'canalplan_option_init' ); 
     909 
    1032910function save_error(){ 
    1033911    update_option('plugin_error',  ob_get_contents()); 
    1034912} 
    1035913 
     914add_action('activated_plugin','save_error'); 
    1036915add_filter('the_content','blogroute_insert'); 
    1037916add_action('wp_head', 'canalplan_header'); 
    1038917add_action('wp_footer', 'canalplan_footer'); 
    1039 add_action('init', array('CanalPlanAutolinker', 'canal_init')); 
     918add_action('admin_menu', 'canalplan_add_custom_box'); 
     919add_action('init', 'canal_init'); 
    1040920register_activation_hook(__FILE__, 'canal_activate'); 
    1041921add_action('admin_menu', 'wp_canalplan_admin_pages'); 
    1042  
    1043  
    1044  
    1045  
     922include("canalplan_widget.php"); 
    1046923 
    1047924?> 
  • canalplan-ac/trunk/multisite.php.txt

    r408484 r537712  
    33#This allows administrators of Networked Blogs to set some installation wide configuration options. 
    44 
    5 # Google Maps API key - make sure you get one for your top level domain rather than for a specific subdomain 
    6 define ('CANALPLAN_GMAP_KEY','ABQIAAAAzDaUChkNH3lPjAjJapKq6RTvY22eKy7N0CiFH2Ct6wY8stwoVxR4QHlGjqnhLQYhV02RACCBlloxaA'); 
    75 
    86# This is the page slug that Canalplan AC will use to display the routes on. You should set this up on your base blog and ensure that all users create a page with the same name in their blogs. 
  • canalplan-ac/trunk/readme.txt

    r479046 r537712  
    44Tags: crosspost, Canalplan 
    55Requires at least: 3.0 
    6 Tested up to: 3.3 
    7 Stable tag: 1.0 
     6Tested up to: 3.3.2 
     7Stable tag: 2.0 
    88 
    99== Description == 
    1010 
    11 This plugin allows you link your blog to the Canalplan AC website. You can import routes from the route planner and link your blog posts to the canalplan gazetteer. 
     11This plugin allows you link your self hosted Wordpress blog to the Canalplan AC website. You can import routes from the route planner and link your blog posts to the canalplan gazetteer. 
    1212 
    1313 
     
    1818The plugin also uses the fopen and file_get_contents calls. Please ensure that these functions are available and that they can access external sites. 
    1919 
    20 You have to have PHP V5 installed for this plugin to work as the code contains several PHP V5 specific features. As PHP V5 is a requirement for running Wordpress 3.2 you shouldn't have any problems but if you are on older version of Wordpress and still running PHP V4 then you need to talk to your hosting company and get PHP upgraded. 
     20You also need to ensure that your PHP installation has the PDOs for SQLite V3 installed as the plugin reads from an SQLite DB to populate its tables. 
     21 
    2122 
    2223== Installation == 
     
    26271. Upload the `canalplan` directory to the `/wp-content/plugins/` directory. 
    27281. Activate the plugin through the 'Plugins' menu in WordPress.  
    28 1. Navigate to `Options` &rarr; `Canalplan AC` and you can start to configure and customise the plugin.  
    29 1. If you are running in Mulitsite then some configuration can be done through the multisite.php file 
     291. Navigate to `Options` &rarr; `Canalplan AC` for configuration and follow the on-screen prompts. 
    3030 
    3131 
    3232== Features == 
    3333 
    34 - Imports data from the Canalplan AC website so you have an up to date list of all canalplan locations (currently stadning at 13601 places) 
     34- Imports data from the Canalplan AC website so you have an up to date list of all canalplan locations (currently standing at 17471 places) 
    3535- Easy linking to Canalplan AC Gazetteer entries 
    3636- Easy inclusion of Googlemaps related to Canalplan AC locations 
     
    4242- Works in "Classic" (Single blog) and Networked Blogs mode. Can be Network activated 
    4343- Common set of Tables for Networked Blogs mode - so 1 set of tables per Networked Blogs install, not per blog. 
    44 - Global configuration for Multisite can be done through a special multisite.php file. 
     44- Global configuration for Networked blog installs can be done through a special multisite.php file. 
    4545 
    4646 
     
    5252 
    5353== Changelog == 
     54 
     55= Version 2.0 28/04/2012 = 
     56- Checked for Wordpress 3.3.2 compatability 
     57- Removed Google Map API key code 
     58- Recoded Google Maps to use Version 3 of the Maps API 
     59- Added a Latitude Widget which links to Canalplan locations 
     60- Added a Maps options page 
     61- Recoded tag handling code to incorporate map customisation options. 
     62- Re-wrote the user guide. 
     63- Removed lots of commented out code left over from original development. 
     64 
    5465 
    5566= Version 1.0 22/12/2011 = 
Note: See TracChangeset for help on using the changeset viewer.