Advertisement
baignoire

osm.php tweak by raf for custom post types and taxonomies

Oct 25th, 2013
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 48.77 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: OSM
  4. Plugin URI: http://wp-osm-plugin.HanBlog.net
  5. Description: Embeds maps in your blog and adds geo data to your posts. Find samples and a forum on the <a href="http://wp-osm-plugin.HanBlog.net">OSM plugin page</a>. Simply create the shortcode to add it in your post at [<a href="options-general.php?page=osm.php">Settings</a>]
  6. Version: 2.2
  7. Author: MiKa
  8. Author URI: http://www.HanBlog.net
  9. Minimum WordPress Version Required: 2.8
  10. */
  11.  
  12. /* (c) Copyright 2013 Michael Kang
  13.  
  14. This program is free software; you can redistribute it and/or modify
  15. it under the terms of the GNU General Public License as published by
  16. the Free Software Foundation; either version 2 of the License, or
  17. (at your option) any later version.
  18.  
  19. This program is distributed in the hope that it will be useful,
  20. but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. GNU General Public License for more details.
  23.  
  24. You should have received a copy of the GNU General Public License
  25. along with this program; if not, write to the Free Software
  26. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  27. */
  28. load_plugin_textdomain('OSM-plugin', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/');
  29.  
  30. define ("PLUGIN_VER", "V2.2");
  31.  
  32. // modify anything about the marker for tagged posts here
  33. // instead of the coding.
  34. define ("POST_MARKER_PNG", "marker_posts.png");
  35. define (POST_MARKER_PNG_HEIGHT, 2);
  36. define (POST_MARKER_PNG_WIDTH, 2);
  37.  
  38. define ("GCSTATS_MARKER_PNG", "geocache.png");
  39. define (GCSTATS_MARKER_PNG_HEIGHT, 25);
  40. define (GCSTATS_MARKER_PNG_WIDTH, 25);
  41.  
  42. define ("INDIV_MARKER", "marker_blue.png");
  43. define (INDIV_MARKER_PNG_HEIGHT, 25);
  44. define (INDIV_MARKER_PNG_WIDTH, 25);
  45.  
  46. // these defines are given by OpenStreetMap.org
  47. define ("URL_INDEX", "http://www.openstreetmap.org/index.html?");
  48. define ("URL_LAT","&mlat=");
  49. define ("URL_LON","&mlon=");
  50. define ("URL_ZOOM_01","&zoom=[");
  51. define ("URL_ZOOM_02","]");
  52. define (ZOOM_LEVEL_MAX,18); // standard is 17, only mapnik is 18
  53. define (ZOOM_LEVEL_MIN,1);
  54.  
  55. // other geo plugin defines
  56. // google-maps-geocoder
  57. define ("WPGMG_LAT", "lat");
  58. define ("WPGMG_LON", "lng");
  59.  
  60. // some general defines
  61. define (LAT_MIN,-90);
  62. define (LAT_MAX,90);
  63. define (LON_MIN,-180);
  64. define (LON_MAX,180);
  65.  
  66. // tracelevels
  67. define (DEBUG_OFF, 0);
  68. define (DEBUG_ERROR, 1);
  69. define (DEBUG_WARNING, 2);
  70. define (DEBUG_INFO, 3);
  71. define (HTML_COMMENT, 10);
  72.  
  73. // Load OSM library mode
  74. define (SERVER_EMBEDDED, 1);
  75. define (SERVER_WP_ENQUEUE, 2);
  76.  
  77.  
  78. if ( ! defined( 'WP_CONTENT_URL' ) )
  79. define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' );
  80. if ( ! defined( 'WP_CONTENT_DIR' ) )
  81. define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
  82. if ( ! defined( 'WP_PLUGIN_URL' ) )
  83. define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' );
  84. if ( ! defined( 'WP_PLUGIN_DIR' ) )
  85. define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
  86. define ("OSM_PLUGIN_URL", WP_PLUGIN_URL."/osm/");
  87. define ("OSM_PLUGIN_ICONS_URL", OSM_PLUGIN_URL."icons/");
  88. define ("URL_POST_MARKER", OSM_PLUGIN_URL.POST_MARKER_PNG);
  89. define ("OSM_PLUGIN_THEMES_URL", OSM_PLUGIN_URL."themes/");
  90. define( 'OSM_OPENLAYERS_THEMES_URL', WP_CONTENT_URL. '/uploads/osm/theme/' );
  91. define ("OSM_PLUGIN_JS_URL", OSM_PLUGIN_URL."js/");
  92.  
  93. global $wp_version;
  94. if (version_compare($wp_version,"2.5.1","<")){
  95. exit('[OSM plugin - ERROR]: At least Wordpress Version 2.5.1 is needed for this plugin!');
  96. }
  97.  
  98. // get the configuratin by
  99. // default or costumer settings
  100. if (@(!include('osm-config.php'))){
  101. include ('osm-config-sample.php');
  102. }
  103.  
  104. // do not edit this
  105. define ("Osm_TraceLevel", DEBUG_ERROR);
  106.  
  107.  
  108.  
  109. // If the function exists this file is called as upload_mimes.
  110. // We don't do anything then.
  111. if ( ! function_exists( 'fb_restrict_mime_types' ) ) {
  112. add_filter( 'upload_mimes', 'fb_restrict_mime_types' );
  113. /**
  114. * Retrun allowed mime types
  115. *
  116. * @see function get_allowed_mime_types in wp-includes/functions.php
  117. * @param array Array of mime types
  118. * @return array Array of mime types keyed by the file extension regex corresponding to those types.
  119. */
  120. function fb_restrict_mime_types( $mime_types ) {
  121. $mime_types['gpx'] = 'text/gpx';
  122. $mime_types['kml'] = 'text/kml';
  123. return $mime_types;
  124. }
  125. }
  126.  
  127.  
  128.  
  129. // If the function exists this file is called as post-upload-ui.
  130. // We don't do anything then.
  131. if ( ! function_exists( 'fb_restrict_mime_types_hint' ) ) {
  132. // add to wp
  133. add_action( 'post-upload-ui', 'fb_restrict_mime_types_hint' );
  134. /**
  135. * Get an Hint about the allowed mime types
  136. *
  137. * @return void
  138. */
  139. function fb_restrict_mime_types_hint() {
  140.  
  141. echo '<br />';
  142. _e( 'OSM plugin added: GPX / KML' );
  143. }
  144. }
  145.  
  146. //hook to create the meta box
  147. add_action( 'add_meta_boxes', 'osm_map_create' );
  148.  
  149. function osm_map_create() {
  150. //create a custom meta box
  151. $screens = array( 'post', 'page' );
  152. foreach ($screens as $screen) {
  153. add_meta_box( 'osm-sc-meta', 'WP OSM Plugin shortcode generator', 'osm_map_create_function', $screen, 'normal', 'high' );
  154. }
  155. }
  156.  
  157. function osm_map_create_function( $post ) {
  158. ?>
  159. <p>
  160. <b>Generate</b>:
  161. <select name="osm_mode">
  162. <option value="sc_gen">OSM shortcode</option>
  163. <option value="geotagging">geotag</option>
  164. </select><br>
  165. OSM shortcode options: <br>
  166. <b>OSM control theme</b>:
  167. <select name="osm_theme">
  168. <option value="none">none</option>
  169. <option value="blue">blue</option>
  170. <option value="dark">dark</option>
  171. <option value="orange">orange</option>
  172. </select>
  173. <b>OSM marker</b>:
  174. <select name="osm_marker">
  175. <option value="none">none</option>
  176. <option value="wpttemp-green.png">Waypoint Green</option>
  177. <option value="wpttemp-red.png">Waypoint Red</option>
  178. <option value="marker_blue.png">Marker Blue</option>
  179. <option value="wpttemp-yellow.png">Marker Yellow</option>
  180. <option value="car.png">Marker Car</option>
  181. <option value="bus.png">Marker Bus</option>
  182. <option value="bicycling.png">Marker Bicycling</option>
  183. <option value="airport.png">Marker Airport</option>
  184. <option value="motorbike.png">Marker Motorbike</option>
  185. <option value="hostel.png">Marker Hostel</option>
  186. <option value="guest_house.png">Marker Guesthouse</option>
  187. <option value="camping.png">Marker Camping</option>
  188. <option value="geocache.png">Geocache</option>
  189. <option value="styria_linux.png">Styria Tux</option>
  190. </select>
  191. </p>
  192.  
  193. <?php echo Osm::sc_showMap(array('msg_box'=>'metabox_sc_gen','lat'=>'50','long'=>'18.5','zoom'=>'3', 'type'=>'All', 'width'=>'450','height'=>'300', 'map_border'=>'thin solid grey', 'theme'=>'dark', 'control'=>'mouseposition,scaleline')); ?>
  194. <br>
  195. <h3><span style="color:green"> >> <?php _e('Copy the generated shortcode/customfield/argument: ','OSM-plugin') ?></span></h3>
  196. <div id="ShortCode_Div"><?php _e('If you click into the map this text is replaced','OSM-plugin') ?>
  197. </div><br>
  198. <?php
  199. }
  200.  
  201. include('osm-openlayers.php');
  202.  
  203. // let's be unique ...
  204. // with this namespace
  205. class Osm
  206. {
  207.  
  208. function Osm() {
  209. $this->localizionName = 'Osm';
  210. //$this->TraceLevel = DEBUG_INFO;
  211. $this->ErrorMsg = new WP_Error();
  212. $this->initErrorMsg();
  213.  
  214. // add the WP action
  215. add_action('wp_head', array(&$this, 'wp_head'));
  216. add_action('admin_menu', array(&$this, 'admin_menu'));
  217. add_action('wp_print_scripts',array(&$this, 'show_enqueue_script'));
  218.  
  219. // add the WP shortcode
  220. add_shortcode('osm_map',array(&$this, 'sc_showMap'));
  221. add_shortcode('osm_image',array(&$this, 'sc_showImage'));
  222. }
  223.  
  224. function initErrorMsg()
  225. {
  226. include('osm-error-msg.php');
  227. }
  228.  
  229. function traceErrorMsg($e = '')
  230. {
  231. if ($this == null){
  232. return $e;
  233. }
  234. $EMsg = $this->ErrorMsg->get_error_message($e);
  235. if ($EMsg == null){
  236. return $e;
  237. //return__("Unknown errormessage",$this->localizionName);
  238. }
  239. return $EMsg;
  240. }
  241.  
  242. function traceText($a_Level, $a_String)
  243. {
  244. $TracePrefix = array(
  245. DEBUG_ERROR =>'[OSM-Plugin-Error]:',
  246. DEBUG_WARNING=>'[OSM-Plugin-Warning]:',
  247. DEBUG_INFO=>'[OSM-Plugin-Info]:');
  248.  
  249. if ($a_Level == DEBUG_ERROR){
  250. echo '<div class="osm_error_msg"><p><strong style="color:red">'.$TracePrefix[$a_Level].Osm::traceErrorMsg($a_String).'</strong></p></div>';
  251. }
  252. else if ($a_Level <= Osm_TraceLevel){
  253. echo $TracePrefix[$a_Level].$a_String.'<br>';
  254. }
  255. else if ($a_Level == HTML_COMMENT){
  256. echo "<!-- ".$a_String." --> \n";
  257. }
  258. }
  259.  
  260. // add it to the Settings page
  261. function options_page_osm()
  262. {
  263. if(isset($_POST['Options'])){
  264.  
  265. // 0 = no error;
  266. // 1 = error occured
  267. $Option_Error = 0;
  268.  
  269. // get the zoomlevel for the external link
  270. // and inform the user if the level was out of range
  271. update_option('osm_custom_field',$_POST['osm_custom_field']);
  272.  
  273. if ($_POST['osm_zoom_level'] >= ZOOM_LEVEL_MIN && $_POST['osm_zoom_level'] <= ZOOM_LEVEL_MAX){
  274. update_option('osm_zoom_level',$_POST['osm_zoom_level']);
  275. }
  276. else {
  277. $Option_Error = 1;
  278. Osm::traceText(DEBUG_ERROR, "e_zoomlevel_range");
  279. }
  280. // Let the user know whether all was fine or not
  281. if ($Option_Error == 0){
  282. Osm::traceText(DEBUG_INFO, "i_options_updated");
  283. }
  284. else{
  285. Osm::traceText(DEBUG_ERROR, "e_options_not_updated");
  286. }
  287.  
  288. }
  289. else{
  290. add_option('osm_custom_field', 0);
  291. add_option('osm_zoom_level', 0);
  292. }
  293.  
  294. // name of the custom field to store Long and Lat
  295. // for the geodata of the post
  296. $osm_custom_field = get_option('osm_custom_field');
  297.  
  298. // zoomlevel for the link the OSM page
  299. $osm_zoom_level = get_option('osm_zoom_level');
  300.  
  301. include('osm-options.php');
  302. }
  303.  
  304. // put meta tags into the head section
  305. function wp_head($not_used)
  306. {
  307. global $wp_query;
  308. global $post;
  309.  
  310. $lat = '';
  311. $lon = '';
  312. $CustomField = get_option('osm_custom_field');
  313. if (($CustomField != false) && (get_post_meta($post->ID, $CustomField, true))){
  314. $PostLatLon = get_post_meta($post->ID, $CustomField, true);
  315. if (!empty($PostLatLon)) {
  316. list($lat, $lon) = explode(',', $PostLatLon);
  317. }
  318. }
  319.  
  320. if(is_single() && ($lat != '') && ($lon != '')){
  321. $title = convert_chars(strip_tags(get_bloginfo("name")))." - ".$wp_query->post->post_title;
  322. $this->traceText(HTML_COMMENT, 'OSM plugin '.PLUGIN_VER.': adding geo meta tags:');
  323. }
  324. else{
  325. $this->traceText(HTML_COMMENT, 'OSM plugin '.PLUGIN_VER.': did not add geo meta tags.');
  326. return;
  327. }
  328.  
  329. // let's store geo data with W3 standard
  330. echo "<meta name=\"ICBM\" content=\"{$lat}, {$lon}\" />\n";
  331. echo "<meta name=\"DC.title\" content=\"{$wp_query->post->post_title}\" />\n";
  332. echo "<meta name=\"geo.placename\" content=\"{$wp_query->post->post_title}\"/>\n";
  333. echo "<meta name=\"geo.position\" content=\"{$lat};{$lon}\" />\n";
  334. }
  335.  
  336.  
  337. function createMarkerList($a_import, $a_import_UserName, $a_Customfield, $a_import_osm_cat_incl_name, $a_import_osm_cat_excl_name, $a_post_type, $a_import_osm_custom_tax_incl_name, $a_custom_taxonomy)
  338. {
  339. $this->traceText(DEBUG_INFO, "createMarkerList(".$a_import.",".$a_import_UserName.",".$a_Customfield.")");
  340. global $post;
  341. $post_org = $post;
  342.  
  343. // make a dummymarker to you use icon.clone later
  344. if ($a_import == 'gcstats'){
  345. $this->traceText(DEBUG_INFO, "Requesting data from gcStats-plugin");
  346. include('osm-import.php');
  347. }
  348. else if ($a_import == 'ecf'){
  349. $this->traceText(DEBUG_INFO, "Requesting data from comments");
  350. include('osm-import.php');
  351. }
  352. else if ($a_import == 'osm' || $a_import == 'osm_l'){
  353. // let's see which posts are using our geo data ...
  354. $this->traceText(DEBUG_INFO, "check all posts for osm geo custom fields");
  355. $CustomFieldName = get_settings('osm_custom_field');
  356. $recentPosts = new WP_Query();
  357. $recentPosts->query('meta_key='.$CustomFieldName.'&post_status=publish'.'&showposts=-1'.'&post_type='.$a_post_type.'');
  358. // $recentPosts->query('meta_key='.$CustomFieldName.'&post_status=publish'.'&post_type=page');
  359. while ($recentPosts->have_posts()) : $recentPosts->the_post();
  360. list($temp_lat, $temp_lon) = explode(',', get_post_meta($post->ID, $CustomFieldName, true));
  361. // echo $post->ID.'Lat: '.$temp_lat.'Long '.$temp_lon.'<br>';
  362.  
  363. // check if a filter is set and geodata are set
  364. // if filter is set and set then pretend there are no geodata
  365. if (($a_import_osm_cat_incl_name != 'Osm_All' || $a_import_osm_cat_excl_name != 'Osm_None' || $a_import_osm_custom_tax_incl_name != 'Osm_All')&&($temp_lat != '' && $temp_lon != '')){
  366. $categories = wp_get_post_categories($post->ID);
  367. foreach( $categories as $catid ) {
  368. $cat = get_category($catid);
  369. if (($a_import_osm_cat_incl_name != 'Osm_All') && (strtolower($cat->name) != (strtolower($a_import_osm_cat_incl_name)))){
  370. $temp_lat = '';
  371. $temp_lon = '';
  372. }
  373. if (strtolower($cat->name) == (strtolower($a_import_osm_cat_excl_name))){
  374. $temp_lat = '';
  375. $temp_lon = '';
  376. }
  377. }
  378.  
  379.  
  380. if ($a_import_osm_custom_tax_incl_name != 'Osm_All')
  381. $mycustomcategories = get_the_terms( $post->ID, $a_import_osm_custom_tax_incl_name);
  382. foreach( $mycustomcategories as $term ) {
  383. $taxonomies[0] = $term->term_taxonomy_id;
  384. // Get rid of the other data stored in the object
  385. unset($term);
  386. }
  387. foreach( $taxonomies as $taxid ) {
  388. $termsObjects = wp_get_object_terms($post->ID, $a_custom_taxonomy);
  389. foreach ($termsObjects as $termsObject) {
  390. $currentCustomCat[] = $termsObject->name;
  391. }
  392. if (($a_import_osm_custom_tax_incl_name != 'Osm_All') && ! in_array($a_import_osm_custom_tax_incl_name, $currentCustomCat)) {
  393. $temp_lat = '';
  394. $temp_lon = '';
  395. }
  396. if (strtolower($currentCustomCat) == (strtolower($a_import_osm_cat_excl_name))){
  397. $temp_lat = '';
  398. $temp_lon = '';
  399. }
  400. }
  401.  
  402. }
  403.  
  404.  
  405. if ($temp_lat != '' && $temp_lon != '') {
  406. list($temp_lat, $temp_lon) = $this->checkLatLongRange('$marker_all_posts',$temp_lat, $temp_lon);
  407. if ($a_import == 'osm_l' ){
  408. $categories = wp_get_post_categories($post->ID);
  409.  
  410. // take the last one but ignore those without a specific category
  411. foreach( $categories as $catid ) {
  412. $cat = get_category($catid);
  413. if ((strtolower($cat->name) == 'uncategorized') || (strtolower($cat->name) == 'allgemein')){
  414. $Category_Txt = '';
  415. }
  416. else{
  417. $Category_Txt = $cat->name.': ';
  418. }
  419. }
  420. $Marker_Txt = '<a href="'.get_permalink($post->ID).'">'.$Category_Txt.get_the_title($post->ID).' </a>';
  421. $MarkerArray[] = array('lat'=> $temp_lat,'lon'=>$temp_lon,'popup_height'=>'100', 'popup_width'=>'150', 'marker'=>$Icon[name], 'text'=>$Marker_Txt);
  422. }
  423. else{ // plain osm without link to the post
  424. $Marker_Txt = ' ';
  425. $MarkerArray[] = array('lat'=> $temp_lat,'lon'=>$temp_lon,'popup_height'=>'100', 'popup_width'=>'150', 'marker'=>$Icon[name], 'text'=>$Marker_Txt);
  426. }
  427. }
  428. endwhile;
  429. }
  430. else if ($a_import == 'wpgmg'){
  431. // let's see which posts are using our geo data ...
  432. $this->traceText(DEBUG_INFO, "check all posts for wpgmg geo custom fields");
  433. $recentPosts = new WP_Query();
  434. $recentPosts->query('meta_key='.WPGMG_LAT.'&meta_key='.WPGMG_LON.'&showposts=-1');
  435. while ($recentPosts->have_posts()) : $recentPosts->the_post();
  436. include('osm-import.php');
  437. if ($temp_lat != '' && $temp_lon != '') {
  438. list($temp_lat, $temp_lon) = $this->checkLatLongRange('$marker_all_posts',$temp_lat, $temp_lon);
  439. $MarkerArray[] = array('lat'=> $temp_lat,'lon'=>$temp_lon,'marker'=>$Icon[name],'popup_height'=>'100', 'popup_width'=>'200');
  440. }
  441. endwhile;
  442. }
  443.  
  444. $post = $post_org;
  445. return $MarkerArray;
  446. }
  447.  
  448. // if you miss a colour, just add it
  449. function checkStyleColour($a_colour){
  450. if ($a_colour != 'red' && $a_colour != 'blue' && $a_colour != 'black' && $a_colour != 'green' && $a_colour != 'orange'){
  451. return "blue";
  452. }
  453. return $a_colour;
  454. }
  455.  
  456. // get the layer for the markers
  457. function getImportLayer($a_type, $a_UserName, $Icon, $a_osm_cat_incl_name, $a_osm_cat_excl_name, $a_line_color, $a_line_width, $a_line_opacity, $a_post_type, $a_import_osm_custom_tax_incl_name, $a_custom_taxonomy){
  458.  
  459. if ($a_type == 'osm_l'){
  460. $LayerName = 'TaggedPosts';
  461. if ($Icon[name] != 'NoName'){ // <= ToDo
  462. $PopUp = 'true';
  463. }
  464. else {
  465. $PopUp = 'false';
  466. }
  467.  
  468. }
  469.  
  470. // import data from tagged posts
  471. else if ($a_type == 'osm'){
  472. $LayerName = 'TaggedPosts';
  473. $PopUp = 'false';
  474. }
  475.  
  476. // import data from wpgmg
  477. else if ($a_type == 'wpgmg'){
  478. $LayerName = 'TaggedPosts';
  479. $PopUp = 'false';
  480. }
  481. // import data from gcstats
  482. else if ($a_type == 'gcstats'){
  483. $LayerName = 'GeoCaches';
  484. $PopUp = 'true';
  485. $Icon = Osm::getIconsize(GCSTATS_MARKER_PNG);
  486. $Icon[name] = GCSTATS_MARKER_PNG;
  487. }
  488. // import data from ecf
  489. else if ($a_type == 'ecf'){
  490. $LayerName = 'Comments';
  491. $PopUp = 'true';
  492. $Icon = Osm::getIconsize(INDIV_MARKER);
  493. $Icon[name] = INDIV_MARKER;
  494. }
  495. else{
  496. $this->traceText(DEBUG_ERROR, "e_import_unknwon");
  497. }
  498. $MarkerArray = $this->createMarkerList($a_type, $a_UserName,'Empty', $a_osm_cat_incl_name, $a_osm_cat_excl_name, $a_post_type, $a_import_osm_custom_tax_incl_name, $a_custom_taxonomy);
  499. if ($a_line_color != 'none'){
  500. $line_color = Osm::checkStyleColour($a_line_color);
  501. $txt = Osm_OpenLayers::addLines($MarkerArray, $line_color, $a_line_width);
  502. }
  503. $txt .= Osm_OpenLayers::addMarkerListLayer($LayerName, $Icon, $MarkerArray, $PopUp);
  504. return $txt;
  505. }
  506.  
  507. // check Lat and Long
  508. function getMapCenter($a_Lat, $a_Long, $a_import, $a_import_UserName){
  509. if ($a_import == 'wpgmg'){
  510. $a_Lat = OSM_getCoordinateLat($a_import);
  511. $a_Long = OSM_getCoordinateLong($a_import);
  512. }
  513. else if ($a_import == 'gcstats'){
  514. if (function_exists('gcStats__getInterfaceVersion')) {
  515. $Val = gcStats__getMinMaxLat($a_import_UserName);
  516. $a_Lat = ($Val[min] + $Val[max]) / 2;
  517. $Val = gcStats__getMinMaxLon($a_import_UserName);
  518. $a_Long = ($Val[min] + $Val[max]) / 2;
  519. }
  520. else{
  521. $this->traceText(DEBUG_WARNING, "getMapCenter() could not connect to gcStats plugin");
  522. $a_Lat = 0;$a_Long = 0;
  523. }
  524. }
  525. else if ($a_Lat == '' || $a_Long == ''){
  526. $a_Lat = OSM_getCoordinateLat('osm');
  527. $a_Long = OSM_getCoordinateLong('osm');
  528. }
  529. return array($a_Lat,$a_Long);
  530. }
  531.  
  532. // check Lat and Long
  533. function checkLatLongRange($a_CallingId, $a_Lat, $a_Long)
  534. {
  535. if ($a_Lat >= LAT_MIN && $a_Lat <= LAT_MAX && $a_Long >= LON_MIN && $a_Long <= LON_MAX &&
  536. preg_match('!^[^0-9]+$!', $a_Lat) != 1 && preg_match('!^[^0-9]+$!', $a_Long) != 1){
  537. return array($a_Lat,$a_Long);
  538. }
  539. else{
  540. $this->traceText(DEBUG_ERROR, "e_lat_lon_range");
  541. $this->traceText(DEBUG_INFO, "Error: ".$a_CallingId." Lat".$a_Lat." or Long".$a_Long);
  542. $a_Lat = 0;$a_Long = 0;
  543. }
  544. }
  545.  
  546. function isOsmIcon($a_IconName)
  547. {
  548.  
  549. if ($a_IconName == "airport.png" || $a_IconName == "bicycling.png" ||
  550. $a_IconName == "bus.png" || $a_IconName == "camping.png" ||
  551. $a_IconName == "car.png" || $a_IconName == "friends.png" ||
  552. $a_IconName == "geocache.png" || $a_IconName == "guest_house.png" ||
  553. $a_IconName == "home.png" || $a_IconName == "hostel.png" ||
  554. $a_IconName == "hotel.png"|| $a_IconName == "marker_blue.png" ||
  555. $a_IconName == "motorbike.png" || $a_IconName == "restaurant.png" ||
  556. $a_IconName == "services.png" || $a_IconName == "styria_linux.png" ||
  557. $a_IconName == "marker_posts.png" || $a_IconName == "restaurant.png" ||
  558. $a_IconName == "toilets.png" || $a_IconName == "wpttemp-yellow.png" ||
  559. $a_IconName == "wpttemp-green.png" || $a_IconName == "wpttemp-red.png"){
  560. return 1;
  561. }
  562. else {
  563. return 0;
  564. }
  565. }
  566.  
  567. function getIconsize($a_IconName)
  568. {
  569. $Icons = array(
  570. "airport.png" => array("height"=>32,"width"=>"31","offset_height"=>"-16","offset_width"=>"-16"),
  571. "bicycling.png" => array("height"=>19,"width"=>"32","offset_height"=>"-9","offset_width"=>"-16"),
  572. "bus.png" => array("height"=>32,"width"=>"26","offset_height"=>"-16","offset_width"=>"-13"),
  573. "camping.png" => array("height"=>32,"width"=>"32","offset_height"=>"-16","offset_width"=>"-16"),
  574. "car.png" => array("height"=>18,"width"=>"32","offset_height"=>"-16","offset_width"=>"-9"),
  575. "friends.png" => array("height"=>32,"width"=>"32","offset_height"=>"-16","offset_width"=>"-16"),
  576. "geocache.png" => array("height"=>25,"width"=>"25","offset_height"=>"-12","offset_width"=>"-12"),
  577. "guest_house.png" => array("height"=>32,"width"=>"32","offset_height"=>"-16","offset_width"=>"-16"),
  578. "home.png" => array("height"=>32,"width"=>"32","offset_height"=>"-16","offset_width"=>"-16"),
  579. "hostel.png" => array("height"=>24,"width"=>"24","offset_height"=>"-12","offset_width"=>"-12"),
  580. "hotel.png" => array("height"=>32,"width"=>"32","offset_height"=>"-16","offset_width"=>"-16"),
  581. "marker_blue.png" => array("height"=>24,"width"=>"24","offset_height"=>"-12","offset_width"=>"-12"),
  582. "motorbike.png" => array("height"=>23,"width"=>"32","offset_height"=>"-12","offset_width"=>"-16"),
  583. "restaurant.png" => array("height"=>24,"width"=>"24","offset_height"=>"-12","offset_width"=>"-12"),
  584. "services.png" => array("height"=>28,"width"=>"32","offset_height"=>"-14","offset_width"=>"-16"),
  585. "styria_linux.png" => array("height"=>50,"width"=>"36","offset_height"=>"-25","offset_width"=>"-18"),
  586. "marker_posts.png" => array("height"=>2,"width"=>"2","offset_height"=>"-1","offset_width"=>"-1"),
  587. "restaurant.png" => array("height"=>24,"width"=>"24","offset_height"=>"-12","offset_width"=>"-12"),
  588. "toilets.png" => array("height"=>32,"width"=>"32","offset_height"=>"-16","offset_width"=>"-16"),
  589. "wpttemp-yellow.png" => array("height"=>24,"width"=>"24","offset_height"=>"-24","offset_width"=>"0"),
  590. "wpttemp-green.png" => array("height"=>24,"width"=>"24","offset_height"=>"-24","offset_width"=>"0"),
  591. "wpttemp-red.png" => array("height"=>24,"width"=>"24","offset_height"=>"-24","offset_width"=>"0"),
  592. );
  593.  
  594. if ($Icons[$a_IconName][height] == ''){
  595. $Icon = array("height"=>24,"width"=>"24");
  596. $this->traceText(DEBUG_ERROR, "e_unknown_icon");
  597. $this->traceText(DEBUG_INFO, "Error: (marker_name: ".$a_IconName.")!");
  598. }
  599. else {
  600. $Icon = $Icons[$a_IconName];
  601. }
  602. return $Icon;
  603. }
  604.  
  605. function getGPXName($filepath){
  606. $file = basename($filepath, ".gpx"); // $file is set to "index"
  607. return $file;
  608. }
  609.  
  610. // execute the java script to display
  611. // the OpenStreetMap
  612. function sc_showMap($atts) {
  613. // let's get the shortcode arguments
  614. extract(shortcode_atts(array(
  615. // size of the map
  616. 'width' => '450', 'height' => '300',
  617. // address of the center in the map
  618. 'lat' => '', 'long' => '',
  619. // the zoomlevel of the map
  620. 'zoom' => '7',
  621. // Mapnik, CycleMap, ...
  622. 'type' => 'AllOsm',
  623. // track info
  624. 'gpx_file' => 'NoFile', // 'absolut address'
  625. 'gpx_file_proxy' => 'NoFile', // 'absolut address'
  626. 'gpx_colour'=> 'NoColour',
  627. 'gpx_file_list' => 'NoFileList',
  628. 'gpx_colour_list' => 'NoColourList',
  629. 'kml_file' => 'NoFile', // 'absolut address'
  630. 'kml_colour'=> 'NoColour',
  631. // are there markers in the map wished loaded from a file
  632. 'marker_file' => 'NoFile', // 'absolut address'
  633. 'marker_file_proxy' => 'NoFile', // 'absolut address'
  634. // are there markers in the map wished loaded from post tags
  635. 'marker_all_posts'=> 'n', // 'y' or 'Y'
  636. 'marker_name' => 'NoName',
  637. 'marker_height' => '0',
  638. 'marker_width' => '0',
  639. 'marker_focus' => '0',
  640. 'ov_map' => '-1', // zoomlevel of overviewmap
  641. 'import' => 'No',
  642. 'import_osm_cat_incl_name' => 'Osm_All',
  643. 'import_osm_cat_excl_name' => 'Osm_None',
  644. 'import_osm_line_color' => 'none',
  645. 'import_osm_line_width' => '4',
  646. 'import_osm_line_opacity' => '0.9',
  647. 'post_type' => 'post',
  648. 'custom_taxonomy' => 'none',
  649. 'import_osm_custom_tax_incl_name' => 'Osm_All',
  650. 'marker' => 'No',
  651. 'marker_routing' => 'No',
  652. 'msg_box' => 'No',
  653. 'custom_field' => 'No',
  654. 'control' => 'No',
  655. 'extmap_type' => 'No',
  656. 'extmap_name' => 'No',
  657. 'extmap_address' => 'No',
  658. 'extmap_init' => 'No',
  659. 'map_border' => 'none',
  660. 'z_index' => 'none',
  661. 'm_txt_01' => 'none',
  662. 'm_txt_02' => 'none',
  663. 'm_txt_03' => 'none',
  664. 'm_txt_04' => 'none',
  665. 'theme' => 'ol',
  666. 'disc_center_list' => '', // in decimal degrees
  667. 'disc_radius_list' => '', // in meters
  668. 'disc_center_opacity_list' => '0.5', // float 0->1
  669. 'disc_center_color_list' => 'red', // html name or #rvb or #rrvvbb
  670. 'disc_border_width_list' => '3', // integer
  671. 'disc_border_color_list' => 'blue', // html name or #rvb or #rrvvbb
  672. 'disc_border_opacity_list' => '0.5', // float 0->1
  673. 'disc_fill_color_list' => 'lightblue',// html name or #rvb or #rrvvbb
  674. 'disc_fill_opacity_list' => '0.5' // float 0->1
  675.  
  676. ), $atts));
  677.  
  678. if (($zoom < ZOOM_LEVEL_MIN || $zoom > ZOOM_LEVEL_MAX) && ($zoom != 'auto')){
  679. $this->traceText(DEBUG_ERROR, "e_zoomlevel_range");
  680. $this->traceText(DEBUG_INFO, "Error: (Zoomlevel: ".$zoom.")!");
  681. $zoom = 0;
  682. }
  683. if ($width < 1 || $height < 1){
  684. Osm::traceText(DEBUG_ERROR, "e_map_size");
  685. Osm::traceText(DEBUG_INFO, "Error: ($width: ".$width." $height: ".$height.")!");
  686. $width = 450; $height = 300;
  687. }
  688.  
  689. if ($marker_name == 'NoName'){
  690. $marker_name = POST_MARKER_PNG;
  691. }
  692.  
  693. if (Osm::isOsmIcon($marker_name) == 1){
  694. $Icon = Osm::getIconsize($marker_name);
  695. $Icon[name] = $marker_name;
  696. }
  697. else {
  698.  
  699. $Icon[height] = $marker_height;
  700. $Icon[width] = $marker_width;
  701. $Icon[name] = $marker_name;
  702. if ($marker_focus == 0){ // center is default
  703. $Icon[offset_height] = round(-$marker_height/2);
  704. $Icon[offset_width] = round(-$marker_width/2);
  705. }
  706. else if ($marker_focus == 1){ // left bottom
  707. $Icon[offset_height] = -$marker_height;
  708. $Icon[offset_width] = 0;
  709. }
  710. else if ($marker_focus == 2){ // left top
  711. $Icon[offset_height] = 0;
  712. $Icon[offset_width] = 0;
  713. }
  714. else if ($marker_focus == 3){ // right top
  715. $Icon[offset_height] = 0;
  716. $Icon[offset_width] = -$marker_width;
  717. }
  718. else if ($marker_focus == 4){ // right bottom
  719. $Icon[offset_height] = -$marker_height;
  720. $Icon[offset_width] = -$marker_width;
  721. }
  722. if ($Icon[height] == 0 || $Icon[width] == 0){
  723. Osm::traceText(DEBUG_ERROR, "e_marker_size"); //<= ToDo
  724. $Icon[height] = 24;
  725. $Icon[width] = 24;
  726. }
  727. }
  728.  
  729. list($import_type, $import_UserName) = explode(',', $import);
  730. if ($import_UserName == ''){
  731. $import_UserName = 'DummyName';
  732. }
  733. $import_type = strtolower($import_type);
  734. $array_control = explode( ',', $control);
  735.  
  736. list($lat, $long) = Osm::getMapCenter($lat, $long, $import_type, $import_UserName);
  737. if ($lat != 'auto' && $long != 'auto'){
  738. list($lat, $long) = Osm::checkLatLongRange('MapCenter',$lat, $long);
  739. }
  740. $gpx_colour = Osm::checkStyleColour($gpx_colour);
  741. $kml_colour = Osm::checkStyleColour($kml_colour);
  742. $type = Osm_OpenLayers::checkMapType($type);
  743. $ov_map = Osm_OpenLayers::checkOverviewMapZoomlevels($ov_map);
  744.  
  745. $array_control = Osm_OpenLayers::checkControlType($array_control);
  746.  
  747. // to manage several maps on the same page
  748. // create names with index
  749. static $MapCounter = 0;
  750. $MapCounter += 1;
  751. $MapName = 'map_'.$MapCounter;
  752. $GpxName = 'GPX_'.$MapCounter;
  753. $KmlName = 'KML_'.$MapCounter;
  754.  
  755. Osm::traceText(DEBUG_INFO, "MapCounter = ".$MapCounter);
  756.  
  757. // if we came up to here, let's load the map
  758. $output = '';
  759. $output .= '<link rel="stylesheet" type="text/css" href="'.OSM_PLUGIN_URL.'/css/osm_map.css" />';
  760. $output .= '<style type="text/css">';
  761. if ($z_index != 'none'){ // fix for NextGen-Gallery
  762. $output .= '.entry .olMapViewport img {z-index: '.$z_index.' !important;}';
  763. $output .= '.olControlNoSelect {z-index: '.$z_index.'+1.'.' !important;}';
  764. $output .= '.olControlAttribution {z-index: '.$z_index.'+1.'.' !important;}';
  765. }
  766. $output .= '.olTileImage { max-width: none !important; max-height: none !important; vertical-align: none;}';
  767. $output .= '.OSM_Map img { max-width: none !important; max-height: none !important; vertical-align: none;}';
  768.  
  769. $output .= '#'.$MapName.' {clear: both; padding: 0px; margin: 0px; border: 0px; width: 100%; height: 100%; margin-top:0px; margin-right:0px;margin-left:0px; margin-bottom:0px; left: 0px;}';
  770. $output .= '#'.$MapName.' img{clear: both; padding: 0px; margin: 0px; border: 0px; width: 100%; height: 100%; position: absolute; margin-top:0px; margin-right:0px;margin-left:0px; margin-bottom:0px;}';
  771. $output .= '</style>';
  772.  
  773. $output .= '<div id="'.$MapName.'" class="OSM_Map" style="width:'.$width.'px; height:'.$height.'px; overflow:hidden;padding:0px;border:'.$map_border.';">';
  774.  
  775.  
  776. if (Osm_LoadLibraryMode == SERVER_EMBEDDED){
  777. if (OL_LIBS_LOADED == 0) {
  778. $output .= '<script type="text/javascript" src="'.Osm_OL_LibraryLocation.'"></script>';
  779. define (OL_LIBS_LOADED, 1);
  780. }
  781.  
  782. if ($type == 'Mapnik' || $type == 'Osmarender' || $type == 'CycleMap' || $type == 'All' || $type == 'AllOsm' || $type == 'Ext'){
  783. if (OSM_LIBS_LOADED == 0) {
  784. $output .= '<script type="text/javascript" src="'.Osm_OSM_LibraryLocation.'"></script>';
  785. define (OSM_LIBS_LOADED, 1);
  786. }
  787. }
  788.  
  789. if ($type == 'OpenSeaMap'){
  790. if (OSM_LIBS_LOADED == 0) {
  791. $output .= '<script type="text/javascript" src="'.Osm_OSM_LibraryLocation.'"></script>';
  792. $output .= '<script type="text/javascript" src="'.Osm_harbours_LibraryLocation.'"></script>';
  793. $output .= '<script type="text/javascript" src="'.Osm_map_utils_LibraryLocation.'"></script>';
  794. $output .= '<script type="text/javascript" src="'.Osm_utilities_LibraryLocation.'"></script>';
  795. define (OSM_LIBS_LOADED, 1);
  796. }
  797. }
  798.  
  799. if ($type == 'GooglePhysical' || $type == 'GoogleStreet' || $type == 'GoogleHybrid' || $type == 'GoogleSatellite' || $type == 'All' || $type == 'AllGoogle' || $a_type == 'Ext' || $type == 'Google Physical' || $type == 'Google Street' || $type == 'Google Hybrid' || $type == 'Google Satellite'){
  800. if (GOOGLE_LIBS_LOADED == 0) {
  801. $output .= '<script type="text/javascript" src="'.Osm_GOOGLE_LibraryLocation.'"></script>';
  802. define (GOOGLE_LIBS_LOADED, 1);
  803. }
  804. }
  805. $output .= '<script type="text/javascript" src="'.OSM_PLUGIN_JS_URL.'osm-plugin-lib.js"></script>';
  806.  
  807. }
  808. elseif (Osm_LoadLibraryMode == SERVER_WP_ENQUEUE){
  809. // registered and loaded by WordPress
  810. }
  811. else{
  812. $this->traceText(DEBUG_ERROR, "e_library_config");
  813. }
  814.  
  815. $output .= '<script type="text/javascript">';
  816. $output .= '/* <![CDATA[ */';
  817. //$output .= 'jQuery(document).ready(';
  818. //$output .= 'function($) {';
  819. $output .= '(function($) {';
  820. $output .= Osm_OpenLayers::addOsmLayer($MapName, $type, $ov_map, $array_control, $extmap_type, $extmap_name, $extmap_address, $extmap_init, $theme);
  821.  
  822. // add a clickhandler if needed
  823. $msg_box = strtolower($msg_box);
  824. if ( $msg_box == 'sc_gen' || $msg_box == 'lat_long' || $msg_box == 'metabox_sc_gen'){
  825. $output .= Osm_OpenLayers::AddClickHandler($msg_box);
  826. }
  827. // set center and zoom of the map
  828. $output .= Osm_OpenLayers::setMapCenterAndZoom($lat, $long, $zoom);
  829.  
  830. // Add the Layer with GPX Track
  831. if ($gpx_file_proxy != 'NoFile'){
  832. $GpxName = basename($gpx_file_proxy, ".gpx");
  833. $output .= Osm_OpenLayers::addGmlLayer($GpxName, OSM_PLUGIN_URL."osm-proxy.php?url=".$gpx_file_proxy, $gpx_colour,'GPX');
  834. }
  835.  
  836. if ($gpx_file != 'NoFile'){
  837. $GpxName = basename($gpx_file, ".gpx");
  838. $output .= Osm_OpenLayers::addGmlLayer($GpxName, $gpx_file,$gpx_colour,'GPX');
  839. }
  840.  
  841. if ($gpx_file_list != 'NoFileList'){
  842. $GpxFileListArray = explode( ',', $gpx_file_list );
  843. $GpxColourListArray = explode( ',', $gpx_colour_list);
  844. $this->traceText(DEBUG_INFO, "(NumOfGpxFiles: ".sizeof($GpxFileListArray)." NumOfGpxColours: ".sizeof($GpxColourListArray).")!");
  845. if (sizeof($GpxFileListArray) == sizeof($GpxColourListArray)){
  846. for($x=0;$x<sizeof($GpxFileListArray);$x++){
  847. $GpxName = basename($GpxFileListArray[$x], ".gpx");
  848. $output .= Osm_OpenLayers::addGmlLayer($GpxName, $GpxFileListArray[$x],$GpxColourListArray[$x],'GPX');
  849. }
  850. }
  851. else {
  852. $this->traceText(DEBUG_ERROR, "e_gpx_list_error");
  853. }
  854. }
  855.  
  856. // Add the Layer with KML Track
  857. if ($kml_file != 'NoFile'){
  858. $output .= Osm_OpenLayers::addGmlLayer($KmlName, $kml_file,$kml_colour,'KML');
  859. }
  860.  
  861. // Add the marker here which we get from the file
  862. if ($marker_file_proxy != 'NoFile'){
  863. $MarkerName = basename($marker_file_proxy, ".txt");
  864. $output .= Osm_OpenLayers::addTextLayer($MarkerName, OSM_PLUGIN_URL."osm-proxy.php?url=".$marker_file_proxy);
  865. }
  866.  
  867. if ($marker_file != 'NoFile'){
  868. $MarkerName = basename($marker_file, ".txt");
  869. $output .= Osm_OpenLayers::addTextLayer($MarkerName, $marker_file);
  870. }
  871.  
  872. $marker_all_posts = strtolower($marker_all_posts);
  873. if ($marker_all_posts == 'y'){
  874. //$this->traceText(DEBUG_ERROR, "e_use_marker_all_posts");
  875. $import_type = 'osm';
  876. }
  877.  
  878. if ($import_type != 'no'){
  879. $output .= Osm::getImportLayer($import_type, $import_UserName, $Icon, $import_osm_cat_incl_name, $import_osm_cat_excl_name, $import_osm_line_color, $import_osm_line_width, $import_osm_line_opacity, $post_type, $import_osm_custom_tax_incl_name, $custom_taxonomy);
  880. }
  881.  
  882. //++
  883. if ($disc_center_list != ''){
  884. $centerListArray = explode( ',', $disc_center_list );
  885. $radiusListArray = explode( ',', $disc_radius_list );
  886. $centerOpacityListArray = explode( ',', $disc_center_opacity_list);
  887. $centerColorListArray = explode( ',', $disc_center_color_list );
  888. $borderWidthListArray = explode( ',', $disc_border_width_list );
  889. $borderColorListArray = explode( ',', $disc_border_color_list );
  890. $borderOpacityListArray = explode( ',', $disc_border_opacity_list);
  891. $fillColorListArray = explode( ',', $disc_fill_color_list );
  892. $fillOpacityListArray = explode( ',', $disc_fill_opacity_list);
  893. $this->traceText(DEBUG_INFO, "(NumOfdiscs: ".sizeof($centerListArray)." NumOfradius: ".sizeof($radiusListArray).")!");
  894.  
  895. if (sizeof($centerListArray) == sizeof($radiusListArray) && !empty($centerListArray) && !empty($radiusListArray) ) {
  896. $output .= Osm_OpenLayers::addDiscs($centerListArray,$radiusListArray,$centerOpacityListArray,$centerColorListArray, $borderWidthListArray,$borderColorListArray,$borderOpacityListArray,$fillColorListArray,$fillOpacityListArray);
  897. } else {
  898. $this->traceText(DEBUG_ERROR, "Discs parameters error");
  899. }
  900. }
  901. //--
  902.  
  903.  
  904. // just add single marker
  905. if ($marker != 'No'){
  906. global $post;
  907. $DoPopUp = 'true';
  908. list($temp_lat, $temp_lon, $temp_popup_custom_field) = explode(',', $marker);
  909. if ($temp_popup_custom_field == ''){
  910. $temp_popup_custom_field = 'osm_dummy';
  911. }
  912.  
  913. $temp_popup_custom_field = trim($temp_popup_custom_field);
  914. $temp_popup = get_post_meta($post->ID, $temp_popup_custom_field, true);
  915.  
  916. if ($m_txt_01 != 'none'){
  917. $temp_popup .= '<br>'.$m_txt_01;
  918. }
  919. if ($m_txt_02 != 'none'){
  920. $temp_popup .= '<br>'.$m_txt_02;
  921. }
  922. if ($m_txt_03 != 'none'){
  923. $temp_popup .= '<br>'.$m_txt_03;
  924. }
  925. if ($m_txt_04 != 'none'){
  926. $temp_popup .= '<br>'.$m_txt_04;
  927. }
  928.  
  929. $marker_routing = strtolower($marker_routing);
  930. if ($marker_routing != 'no') {
  931. $temp_popup .= '<br><div class="route"><a href="';
  932. if ($marker_routing == 'ors' || $marker_routing == 'openrouteservice') {
  933. $temp_popup .= 'http://openrouteservice.org/index.php?end=' . $temp_lon . ',' . $temp_lat . '&zoom=' . $zoom . '&pref=Fastest&lang=' . substr(get_locale(),0,2) . '&noMotorways=false&noTollways=false';
  934. }
  935. elseif ($marker_routing == 'cm' || $marker_routing == 'cloudmade') {
  936. $temp_popup .= 'http://maps.cloudmade.com/?lat=' . $temp_lat . '&lng=' . $temp_lon . '&zoom=' . $zoom . '&directions=' . $temp_lat . ',' . $temp_lon . '&travel=car&styleId=1&active_page=0&opened_tab=1';
  937. }
  938. elseif ($marker_routing == 'yn' || $marker_routing == 'yournavigation') {
  939. $temp_popup .= 'http://yournavigation.org/?tlat=' . $temp_lat . '&tlon=' . $temp_lon;
  940. }
  941. else {
  942. $temp_popup .= 'missing routing service!'.$marker_routing;
  943. Osm::traceText(DEBUG_ERROR, "e_missing_rs_error");
  944. }
  945. $temp_popup .= '">' . __("Route from your location to this place", "Osm") . '</a></div>';
  946. }
  947.  
  948. if (($temp_popup_custom_field == 'osm_dummy') && ($m_txt_01 == 'none') && ($marker_routing == 'no')){
  949. $DoPopUp = 'false';
  950. }
  951.  
  952. list($temp_lat, $temp_lon) = Osm::checkLatLongRange('Marker',$temp_lat, $temp_lon);
  953. $MarkerArray[] = array('lat'=> $temp_lat,'lon'=>$temp_lon,'text'=>$temp_popup,'popup_height'=>'150', 'popup_width'=>'150');
  954. $output .= Osm_OpenLayers::addMarkerListLayer('Marker', $Icon,$MarkerArray,$DoPopUp);
  955. }
  956.  
  957. // set center and zoom of the map
  958. $output .= Osm_OpenLayers::setMapCenterAndZoom($lat, $long, $zoom);
  959.  
  960. //$output .= '}';
  961. //$output .= ');';
  962. $output .= '})(jQuery)';
  963. $output .= '/* ]]> */';
  964. $output .= ' </script>';
  965. $output .= '</div>';
  966. return $output;
  967. }
  968.  
  969. // execute the java script to display
  970. // the zoomify
  971. function sc_showImage($atts) {
  972. // let's get the shortcode arguments
  973. extract(shortcode_atts(array(
  974. // size of the map
  975. 'width' => '450', 'height' => '300',
  976. // the zoomlevel of the map
  977. 'zoom' => '7',
  978. // track info
  979. 'control' => 'No',
  980. 'map_border' => 'none',
  981. 'z_index' => 'none',
  982. 'extmap_address' => 'No',
  983. 'theme' => 'ol'
  984. ), $atts));
  985.  
  986. if (($zoom < ZOOM_LEVEL_MIN || $zoom > ZOOM_LEVEL_MAX) && ($zoom != 'auto')){
  987. $this->traceText(DEBUG_ERROR, "e_zoomlevel_range");
  988. $this->traceText(DEBUG_INFO, "Error: (Zoomlevel: ".$zoom.")!");
  989. $zoom = 0;
  990. }
  991. if ($width < 1 || $height < 1){
  992. Osm::traceText(DEBUG_ERROR, "e_map_size");
  993. Osm::traceText(DEBUG_INFO, "Error: ($width: ".$width." $height: ".$height.")!");
  994. $width = 450; $height = 300;
  995. }
  996.  
  997.  
  998. $array_control = explode( ',', $control);
  999.  
  1000. $array_control = Osm_OpenLayers::checkControlType($array_control);
  1001.  
  1002. // to manage several maps on the same page
  1003. // create names with index
  1004. static $MapCounter = 0;
  1005. $MapCounter += 1;
  1006. $MapName = 'map_'.$MapCounter;
  1007.  
  1008. Osm::traceText(DEBUG_INFO, "MapCounter = ".$MapCounter);
  1009.  
  1010. // if we came up to here, let's load the image
  1011. $output = '';
  1012. $output .= '<link rel="stylesheet" type="text/css" href="'.OSM_PLUGIN_URL.'/css/osm_map.css" />';
  1013. $output .= '<style type="text/css">';
  1014. if ($z_index != 'none'){ // fix for NextGen-Gallery
  1015. $output .= '.entry .olMapViewport img {z-index: '.$z_index.' !important;}';
  1016. $output .= '.olControlNoSelect {z-index: '.$z_index.'+1.'.' !important;}';
  1017. $output .= '.olControlAttribution {z-index: '.$z_index.'+1.'.' !important;}';
  1018. }
  1019.  
  1020. $output .= '#'.$MapName.' {clear: both; padding: 0px; margin: 0px; border: 0px; width: 100%; height: 100%; margin-top:0px; margin-right:0px;margin-left:0px; margin-bottom:0px; left: 0px;}';
  1021. $output .= '#'.$MapName.' img{clear: both; padding: 0px; margin: 0px; border: 0px; width: 100%; height: 100%; position: absolute; margin-top:0px; margin-right:0px;margin-left:0px; margin-bottom:0px;}';
  1022. $output .= '</style>';
  1023.  
  1024. $output .= '<div id="'.$MapName.'" class="OSM_IMG" style="width:'.$width.'px; height:'.$height.'px; overflow:hidden;padding:0px;border:'.$map_border.';">';
  1025.  
  1026.  
  1027. if (Osm_LoadLibraryMode == SERVER_EMBEDDED){
  1028. if (OL_LIBS_LOADED == 0) {
  1029. $output .= '<script type="text/javascript" src="'.Osm_OL_LibraryLocation.'"></script>';
  1030. define (OL_LIBS_LOADED, 1);
  1031. }
  1032.  
  1033. if ($type == 'Mapnik' || $type == 'Osmarender' || $type == 'CycleMap' || $type == 'All' || $type == 'AllOsm' || $type == 'Ext'){
  1034. if (OSM_LIBS_LOADED == 0) {
  1035. $output .= '<script type="text/javascript" src="'.Osm_OSM_LibraryLocation.'"></script>';
  1036. define (OSM_LIBS_LOADED, 1);
  1037. }
  1038. }
  1039.  
  1040. if ($type == 'OpenSeaMap'){
  1041. if (OSM_LIBS_LOADED == 0) {
  1042. $output .= '<script type="text/javascript" src="'.Osm_OSM_LibraryLocation.'"></script>';
  1043. $output .= '<script type="text/javascript" src="'.Osm_harbours_LibraryLocation.'"></script>';
  1044. $output .= '<script type="text/javascript" src="'.Osm_map_utils_LibraryLocation.'"></script>';
  1045. $output .= '<script type="text/javascript" src="'.Osm_utilities_LibraryLocation.'"></script>';
  1046. define (OSM_LIBS_LOADED, 1);
  1047. }
  1048. }
  1049.  
  1050. if ($type == 'GooglePhysical' || $type == 'GoogleStreet' || $type == 'GoogleHybrid' || $type == 'GoogleSatellite' || $type == 'All' || $type == 'AllGoogle' || $a_type == 'Ext' || $type == 'Google Physical' || $type == 'Google Street' || $type == 'Google Hybrid' || $type == 'Google Satellite'){
  1051. if (GOOGLE_LIBS_LOADED == 0) {
  1052. $output .= '<script type="text/javascript" src="'.Osm_GOOGLE_LibraryLocation.'"></script>';
  1053. define (GOOGLE_LIBS_LOADED, 1);
  1054. }
  1055. }
  1056. $output .= '<script type="text/javascript" src="'.OSM_PLUGIN_JS_URL.'osm-plugin-lib.js"></script>';
  1057. }
  1058. elseif (Osm_LoadLibraryMode == SERVER_WP_ENQUEUE){
  1059. // registered and loaded by WordPress
  1060. }
  1061. else{
  1062. $this->traceText(DEBUG_ERROR, "e_library_config");
  1063. }
  1064.  
  1065. $extmap_init = 'new OpenLayers.Size('.width.', '.height.' )';
  1066.  
  1067. $output .= '<script type="text/javascript">';
  1068. $output .= '/* <![CDATA[ */';
  1069. //$output .= 'jQuery(document).ready(';
  1070. //$output .= 'function($) {';
  1071. $output .= '(function($) {';
  1072. $output .= Osm_OpenLayers::addOsmLayer("Zoomify", "ext", "0", "ext", "Zoomify", "Zoomify", $extmap_address, $extmap_init, $theme);
  1073.  
  1074. // set center and zoom of the map
  1075. //$output .= Osm_OpenLayers::setMapCenterAndZoom($lat, $long, $zoom);
  1076.  
  1077. //$output .= '}';
  1078. //$output .= ');';
  1079. $output .= '})(jQuery)';
  1080. $output .= '/* ]]> */';
  1081. $output .= ' </script>';
  1082. $output .= '</div>';
  1083. return $output;
  1084. }
  1085.  
  1086. // add OSM-config page to Settings
  1087. function admin_menu($not_used){
  1088. // place the info in the plugin settings page
  1089. add_options_page(__('OpenStreetMap Manager', 'Osm'), __('OSM', 'Osm'), 5, basename(__FILE__), array('Osm', 'options_page_osm'));
  1090. }
  1091.  
  1092.  
  1093.  
  1094. // ask WP to handle the loading of scripts
  1095. // if it is not admin area
  1096. function show_enqueue_script() {
  1097. wp_enqueue_script(array ('jquery'));
  1098.  
  1099. if (Osm_LoadLibraryMode == SERVER_EMBEDDED){
  1100. // it is loaded when the map is displayed
  1101. }
  1102. elseif (Osm_LoadLibraryMode == SERVER_WP_ENQUEUE){
  1103. //wp_enqueue_script('OlScript', 'http://www.openlayers.org/api/OpenLayers.js');
  1104. //wp_enqueue_script('OsnScript', 'http://www.openstreetmap.org/openlayers/OpenStreetMap.js');
  1105. wp_enqueue_script('OlScript',Osm_OL_LibraryLocation);
  1106. wp_enqueue_script('OsnScript',Osm_OSM_LibraryLocation);
  1107. wp_enqueue_script('OsnScript',Osm_GOOGLE_LibraryLocation);
  1108. wp_enqueue_script('OsnScript',OSM_PLUGIN_JS_URL.'osm-plugin-lib.js');
  1109. define (OSM_LIBS_LOADED, 1);
  1110. define (OL_LIBS_LOADED, 1);
  1111. define (GOOGLE_LIBS_LOADED, 1);
  1112. }
  1113. else{
  1114. // Errormsg is traced at another place
  1115. }
  1116. }
  1117. } // End class Osm
  1118.  
  1119. $pOsm = new Osm();
  1120.  
  1121. // This is meant to be the interface used
  1122. // in your WP-template
  1123.  
  1124. // returns Lat data of coordination
  1125. function OSM_getCoordinateLat($a_import)
  1126. {
  1127. global $post;
  1128.  
  1129. $a_import = strtolower($a_import);
  1130. if ($a_import == 'osm' || $a_import == 'osm_l'){
  1131. list($lat, $lon) = explode(',', get_post_meta($post->ID, get_settings('osm_custom_field'), true));
  1132. }
  1133. else if ($a_import == 'wpgmg'){
  1134. $lat = get_post_meta($post->ID, WPGMG_LAT, true);
  1135. }
  1136. else {
  1137. $this->traceText(DEBUG_ERROR, "e_php_getlat_missing_arg");
  1138. $lat = 0;
  1139. }
  1140. if ($lat != '') {
  1141. return trim($lat);
  1142. }
  1143. return '';
  1144. }
  1145.  
  1146. // returns Lon data
  1147. function OSM_getCoordinateLong($a_import)
  1148. {
  1149. global $post;
  1150.  
  1151. $a_import = strtolower($a_import);
  1152. if ($a_import == 'osm' || $a_import == 'osm_l'){
  1153. list($lat, $lon) = explode(',', get_post_meta($post->ID, get_settings('osm_custom_field'), true));
  1154. }
  1155. else if ($a_import == 'wpgmg'){
  1156. list($lon) = get_post_meta($post->ID,WPGMG_LON, true);
  1157. }
  1158. else {
  1159. $this->traceText(DEBUG_ERROR, "e_php_getlon_missing_arg");
  1160. $lon = 0;
  1161. }
  1162. if ($lon != '') {
  1163. return trim($lon);
  1164. }
  1165. return '';
  1166. }
  1167.  
  1168. function OSM_getOpenStreetMapUrl() {
  1169. $zoom_level = get_settings('osm_zoom_level');
  1170. $lat = $lat == ''? OSM_getCoordinateLat('osm') : $lat;
  1171. $lon = $lon == ''? OSM_getCoordinateLong('osm'): $lon;
  1172. return URL_INDEX.URL_LAT.$lat.URL_LON.$lon.URL_ZOOM_01.$zoom_level.URL_ZOOM_02;
  1173. }
  1174.  
  1175. function OSM_echoOpenStreetMapUrl(){
  1176. echo OSM_getOpenStreetMapUrl() ;
  1177. }
  1178. // functions to display a map in your theme
  1179. // by using the custom fields
  1180. // default values should be set only at sc_showMap()
  1181. function OSM_displayOpenStreetMap($a_widht, $a_hight, $a_zoom, $a_type){
  1182.  
  1183. $atts = array ('width' => $a_widht,
  1184. 'height' => $a_hight,
  1185. 'type' => $a_type,
  1186. 'zoom' => $a_zoom,
  1187. 'control' => 'off');
  1188.  
  1189. if ((OSM_getCoordinateLong("osm"))&&(OSM_getCoordinateLat("osm"))) {
  1190. echo OSM::sc_showMap($atts);
  1191. }
  1192. }
  1193.  
  1194. function OSM_displayOpenStreetMapExt($a_widht, $a_hight, $a_zoom, $a_type, $a_control, $a_marker_name, $a_marker_height, $a_marker_width, $a_marker_text, $a_ov_map, $a_marker_focus = 0, $a_routing = 'No'){
  1195.  
  1196. $atts = array ('width' => $a_widht,
  1197. 'height' => $a_hight,
  1198. 'type' => $a_type,
  1199. 'zoom' => $a_zoom,
  1200. 'ov_map' => $a_ov_map,
  1201. 'marker_name' => $a_marker_name,
  1202. 'marker_height' => $a_marker_height,
  1203. 'marker_width' => $a_marker_width,
  1204. 'marker' => OSM_getCoordinateLat("osm") . ',' . OSM_getCoordinateLong("osm") . ',' . $a_marker_text,
  1205. 'control' => $a_control,
  1206. 'marker_focus' => $a_marker_focus,
  1207. 'marker_routing' => $a_routing);
  1208.  
  1209. if ((OSM_getCoordinateLong("osm"))&&(OSM_getCoordinateLat("osm"))) {
  1210. echo OSM::sc_showMap($atts);
  1211. }
  1212. }
  1213. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement