display_page();
}
function lmm_list_layers()
{
global $wpdb;
$lmm_options = get_option( 'leafletmapsmarker_options' );
$columnsort = isset($_GET['orderby']) ? mysql_real_escape_string($_GET['orderby']) : 'id';
$columnsortorder = isset($_GET['order']) ? mysql_real_escape_string($_GET['order']) : 'asc';
$table_name_layers = $wpdb->prefix.'leafletmapsmarker_layers';
$table_name_markers = $wpdb->prefix.'leafletmapsmarker_markers';
$layerlist = $wpdb->get_results('SELECT * FROM '.$table_name_layers.' WHERE id>0 order by '.$columnsort.' '.$columnsortorder.'', ARRAY_A);
$lcount = intval($wpdb->get_var('SELECT COUNT(*)-1 FROM '.$table_name_layers));
include('leaflet-list-layers.php');
}
function lmm_list_markers()
{
global $wpdb;
$lmm_options = get_option( 'leafletmapsmarker_options' );
$table_name_markers = $wpdb->prefix.'leafletmapsmarker_markers';
$table_name_layers = $wpdb->prefix.'leafletmapsmarker_layers';
$radius = 1;
$pagenum = isset($_POST['paged']) ? intval($_POST['paged']) : (isset($_GET['paged']) ? intval($_GET['paged']) : 1);
$columnsort = isset($_GET['orderby']) ? mysql_real_escape_string($_GET['orderby']) : 'id';
$columnsortorder = isset($_GET['order']) ? mysql_real_escape_string($_GET['order']) : 'asc';
$start = ($pagenum - 1) * intval($lmm_options[ 'markers_per_page' ]);
$action = isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : '');
$searchtext = isset($_POST['searchtext']) ? $_POST['searchtext'] : (isset($_GET['searchtext']) ? mysql_real_escape_string($_GET['searchtext']) : '');
if ($action == 'search') {
$markersearchnonce = isset($_POST['_wpnonce']) ? $_POST['_wpnonce'] : '';
if (! wp_verify_nonce($markersearchnonce, 'markersearch-nonce') ) die('
'.__('Security check failed - please call this function from the according Leaflet Maps Marker admin page!','lmm').'');
$mcount = intval($wpdb->get_var('SELECT COUNT(*) FROM '.$table_name_markers.' WHERE markername like \'%'.$searchtext.'%'.'\' OR popuptext like \'%'.$searchtext.'%'.'\''));
$marklist = $wpdb->get_results('SELECT m.id,CONCAT(m.lat,\',\',m.lon) AS coords,m.basemap,m.icon,m.popuptext,m.layer,m.zoom,m.openpopup as openpopup,m.lat,m.lon,m.mapwidth,m.mapheight,m.mapwidthunit,m.markername,m.panel,m.createdby,m.createdon,m.updatedby,m.updatedon,m.controlbox,m.overlays_custom,m.overlays_custom2,m.overlays_custom3,m.overlays_custom4,m.wms,m.wms2,m.wms3,m.wms4,m.wms5,m.wms6,m.wms7,m.wms8,m.wms9,m.wms10,l.name AS layername,l.id as layerid FROM '.$table_name_markers.' AS m LEFT OUTER JOIN '.$table_name_layers.' AS l ON m.layer=l.id WHERE m.markername like \'%'.$searchtext.'%'.'\' OR m.popuptext like \'%'.$searchtext.'%'.'\' order by '.$columnsort.' '.$columnsortorder.' LIMIT '.intval($lmm_options[ 'markers_per_page' ]).' OFFSET '.$start, ARRAY_A);
}
else
{
$mcount = intval($wpdb->get_var('SELECT COUNT(*) FROM '.$table_name_markers));
$marklist = $wpdb->get_results('SELECT m.id,CONCAT(m.lat,\',\',m.lon) AS coords,m.basemap,m.icon,m.popuptext,m.layer,m.zoom,m.openpopup as openpopup,m.lat,m.lon,m.mapwidth,m.mapheight,m.mapwidthunit,m.markername,m.panel,m.createdby,m.createdon,m.updatedby,m.updatedon,m.controlbox,m.overlays_custom,m.overlays_custom2,m.overlays_custom3,m.overlays_custom4,m.wms,m.wms2,m.wms3,m.wms4,m.wms5,m.wms6,m.wms7,m.wms8,m.wms9,m.wms10,l.name AS layername,l.id as layerid FROM '.$table_name_markers.' AS m LEFT OUTER JOIN '.$table_name_layers.' AS l ON m.layer=l.id order by '.$columnsort.' '.$columnsortorder.' LIMIT '.intval($lmm_options[ 'markers_per_page' ]).' OFFSET '.$start, ARRAY_A);
}
if ($start > $mcount or $start < 0)
$start = 0;
include('leaflet-list-markers.php');
}
function lmm_layer()
{
global $wpdb;
$lmm_options = get_option( 'leafletmapsmarker_options' );
$table_name_markers = $wpdb->prefix.'leafletmapsmarker_markers';
$table_name_layers = $wpdb->prefix.'leafletmapsmarker_layers';
include('leaflet-layer.php');
}
function lmm_marker()
{
global $wpdb;
$lmm_options = get_option( 'leafletmapsmarker_options' );
$table_name_markers = $wpdb->prefix.'leafletmapsmarker_markers';
$table_name_layers = $wpdb->prefix.'leafletmapsmarker_layers';
include('leaflet-marker.php');
}
function lmm_showmap($atts) {
global $wpdb;
$lmm_options = get_option( 'leafletmapsmarker_options' );
$uid = substr(md5(''.rand()), 0, 8);
extract(shortcode_atts(array(
'lat' => '', 'lon' => '',
'mlat' => '', 'mlon' => '',
'basemap' => $lmm_options[ 'defaults_marker_shortcode_basemap'],
'mpopuptext' => '',
'micon' => '',
'zoom' => intval($lmm_options[ 'defaults_marker_shortcode_zoom' ]),
'openpopup' => '',
'geojson' => '',
'geojsonurl' => '',
'layer' => '',
'marker' => '',
'markername' => '',
'panel' => '0',
'mapwidth' => intval($lmm_options[ 'defaults_marker_shortcode_mapwidth' ]),
'mapwidthunit' => $lmm_options[ 'defaults_marker_shortcode_mapwidthunit' ],
'mapheight' => intval($lmm_options[ 'defaults_marker_shortcode_mapheight' ]),
'mapname' => 'mapsmarker_'.$uid
), $atts));
$pname = 'pa'.$uid;
//info: prepare layers
if (!empty($layer)) {
$table_name_layers = $wpdb->prefix.'leafletmapsmarker_layers';
$row = $wpdb->get_row('SELECT id,name,basemap,mapwidth,mapheight,mapwidthunit,panel,layerzoom,layerviewlat,layerviewlon,controlbox,overlays_custom,overlays_custom2,overlays_custom3,overlays_custom4,wms,wms2,wms3,wms4,wms5,wms6,wms7,wms8,wms9,wms10 FROM '.$table_name_layers.' WHERE id='.$layer, ARRAY_A);
$id = $row['id'];
$basemap = $row['basemap'];
$lat = $row['layerviewlat'];
$lon = $row['layerviewlon'];
$zoom = $row['layerzoom'];
$mapwidth = $row['mapwidth'];
$mapheight = $row['mapheight'];
$mapwidthunit = $row['mapwidthunit'];
$panel = $row['panel'];
$paneltext = ($row['name'] == NULL) ? ' ' : $row['name'];
$controlbox = $row['controlbox'];
$overlays_custom = $row['overlays_custom'];
$overlays_custom2 = $row['overlays_custom2'];
$overlays_custom3 = $row['overlays_custom3'];
$overlays_custom4 = $row['overlays_custom4'];
$wms = $row['wms'];
$wms2 = $row['wms2'];
$wms3 = $row['wms3'];
$wms4 = $row['wms4'];
$wms5 = $row['wms5'];
$wms6 = $row['wms6'];
$wms7 = $row['wms7'];
$wms8 = $row['wms8'];
$wms9 = $row['wms9'];
$wms10 = $row['wms10'];
}
//info: prepare markers
if (!empty($marker)) {
$table_name_markers = $wpdb->prefix.'leafletmapsmarker_markers';
$row = $wpdb->get_row('SELECT id,markername,basemap,layer,lat,lon,icon,popuptext,zoom,openpopup,mapwidth,mapwidthunit,mapheight,panel,controlbox,overlays_custom,overlays_custom2,overlays_custom3,overlays_custom4,wms,wms2,wms3,wms4,wms5,wms6,wms7,wms8,wms9,wms10 FROM '.$table_name_markers.' WHERE id='.$marker, ARRAY_A);
if(!empty($row)) {
$id = $row['id'];
$basemap = $row['basemap'];
$lon = $row['lon'];
$lat = $row['lat'];
$coords = $lat.', '.$lon;
$icon = $row['icon'];
$popuptext = $row['popuptext'];
$zoom = $row['zoom'];
$openpopup = ($row['openpopup'] == 1) ? '.openPopup()' : '';
$mopenpopup = $openpopup;
$layer = $row['layer'];
$mlat = $lat;
$mlon = $lon;
$mpopuptext = $popuptext;
$micon = $icon;
$mapwidth = $row['mapwidth'];
$mapwidthunit = $row['mapwidthunit'];
$mapheight = $row['mapheight'];
$panel = $row['panel'];
$paneltext = ($row['markername'] == NULL) ? ' ' : $row['markername'];
$controlbox = $row['controlbox'];
$overlays_custom = $row['overlays_custom'];
$overlays_custom2 = $row['overlays_custom2'];
$overlays_custom3 = $row['overlays_custom3'];
$overlays_custom4 = $row['overlays_custom4'];
$wms = $row['wms'];
$wms2 = $row['wms2'];
$wms3 = $row['wms3'];
$wms4 = $row['wms4'];
$wms5 = $row['wms5'];
$wms6 = $row['wms6'];
$wms7 = $row['wms7'];
$wms8 = $row['wms8'];
$wms9 = $row['wms9'];
$wms10 = $row['wms10'];
}
}
//info: prepare markers only added by shortcode and not defined in backend
if (empty($layer) and empty($marker)) {
$lat = $mlat;
$lon = $mlon;
$controlbox = $lmm_options[ 'defaults_marker_shortcode_controlbox' ];
$overlays_custom = isset($lmm_options[ 'defaults_marker_shortcode_overlays_custom_active' ]) == TRUE && ($lmm_options[ 'defaults_marker_shortcode_overlays_custom_active' ] == 1 ) ? '1' : '0';
$overlays_custom2 = isset($lmm_options[ 'defaults_marker_shortcode_overlays_custom2_active' ]) == TRUE && ($lmm_options[ 'defaults_marker_shortcode_overlays_custom2_active' ] == 1 ) ? '1' : '0';
$overlays_custom3 = isset($lmm_options[ 'defaults_marker_shortcode_overlays_custom3_active' ]) == TRUE && ($lmm_options[ 'defaults_marker_shortcode_overlays_custom3_active' ] == 1 ) ? '1' : '0';
$overlays_custom4 = isset($lmm_options[ 'defaults_marker_shortcode_overlays_custom4_active' ]) == TRUE && ($lmm_options[ 'defaults_marker_shortcode_overlays_custom4_active' ] == 1 ) ? '1' : '0';
$wms = isset($lmm_options[ 'defaults_marker_shortcode_wms_active' ]) == TRUE && ($lmm_options[ 'defaults_marker_shortcode_wms_active' ] == 1 ) ? '1' : '0';
$wms2 = isset($lmm_options[ 'defaults_marker_shortcode_wms2_active' ]) == TRUE && ($lmm_options[ 'defaults_marker_shortcode_wms2_active' ] == 1 ) ? '1' : '0';
$wms3 = isset($lmm_options[ 'defaults_marker_shortcode_wms3_active' ]) == TRUE && ($lmm_options[ 'defaults_marker_shortcode_wms3_active' ] == 1 ) ? '1' : '0';
$wms4 = isset($lmm_options[ 'defaults_marker_shortcode_wms4_active' ]) == TRUE && ($lmm_options[ 'defaults_marker_shortcode_wms4_active' ] == 1 ) ? '1' : '0';
$wms5 = isset($lmm_options[ 'defaults_marker_shortcode_wms5_active' ]) == TRUE && ($lmm_options[ 'defaults_marker_shortcode_wms5_active' ] == 1 ) ? '1' : '0';
$wms6 = isset($lmm_options[ 'defaults_marker_shortcode_wms6_active' ]) == TRUE && ($lmm_options[ 'defaults_marker_shortcode_wms6_active' ] == 1 ) ? '1' : '0';
$wms7 = isset($lmm_options[ 'defaults_marker_shortcode_wms7_active' ]) == TRUE && ($lmm_options[ 'defaults_marker_shortcode_wms7_active' ] == 1 ) ? '1' : '0';
$wms8 = isset($lmm_options[ 'defaults_marker_shortcode_wms8_active' ]) == TRUE && ($lmm_options[ 'defaults_marker_shortcode_wms8_active' ] == 1 ) ? '1' : '0';
$wms9 = isset($lmm_options[ 'defaults_marker_shortcode_wms9_active' ]) == TRUE && ($lmm_options[ 'defaults_marker_shortcode_wms9_active' ] == 1 ) ? '1' : '0';
$wms10 = isset($lmm_options[ 'defaults_marker_shortcode_wms10_active' ]) == TRUE && ($lmm_options[ 'defaults_marker_shortcode_wms10_active' ] == 1 ) ? '1' : '0';
}
//info: check if layer/marker ID exists
if ($lat == NULL) {
$error_layer_not_exists = sprintf( esc_attr__('Error: a layer with the ID %1$s does not exist!','lmm'), $layer);
$error_marker_not_exists = sprintf( esc_attr__('Error: a marker with the ID %1$s does not exist!','lmm'), $marker);
if (empty($layer)) {
echo $error_marker_not_exists . '
';
}
if (empty($marker)) {
echo $error_layer_not_exists . '
';
}
echo '
';
} else {
//info: starting output on frontend
$lmm_out = '';
//info: panel for layer/marker name and API URLs
if ($panel == 1) {
if ($mapwidthunit == 'px') {
$lmm_out .= '
' . __('More information on support','lmm') . ': http://www.mapsmarker.com/support
'; if ( version_compare( $wp_version, '3.3', '<' ) ) { global $current_screen; add_contextual_help( $current_screen, $helptext ); } else if ( version_compare( $wp_version, '3.3', '>=' ) ) { $screen = get_current_screen(); $screen->add_help_tab( array( 'id' => 'lmm_help_tab', 'title' => __('Help & Support','lmm'), 'content' => $helptext )); } } function lmm_admin_jquery_ui() { wp_enqueue_script( array ( 'jquery', 'jquery-ui-tabs' ) ); } function lmm_frontend_enqueue_scripts() { wp_enqueue_script( array ( 'jquery' ) ); wp_enqueue_script( 'leafletmapsmarker', LEAFLET_PLUGIN_URL.'/leaflet-dist/leaflet.js', array(), NULL); wp_localize_script ( 'leafletmapsmarker', 'leafletmapsmarker_L10n', array( 'lmm_zoom_in' => __( 'Zoom in', 'lmm' ), 'lmm_zoom_out' => __( 'Zoom out', 'lmm' ) ) ); } function lmm_admin_enqueue_scripts_flattr() { wp_enqueue_script( 'leafletmapsmarker-flattr', LEAFLET_PLUGIN_URL.'/js/flattr.js', array(), NULL); } function lmm_admin_enqueue_scripts() { wp_enqueue_script( array ( 'jquery' ) ); wp_enqueue_script( 'leafletmapsmarker', LEAFLET_PLUGIN_URL.'/leaflet-dist/leaflet.js', array(), NULL); wp_localize_script ( 'leafletmapsmarker', 'leafletmapsmarker_L10n', array( 'lmm_zoom_in' => __( 'Zoom in', 'lmm' ), 'lmm_zoom_out' => __( 'Zoom out', 'lmm' ) ) ); } function lmm_frontend_enqueue_stylesheets() { global $wp_styles; wp_register_style('leafletmapsmarker', LEAFLET_PLUGIN_URL . '/leaflet-dist/leaflet.css', array(), NULL); wp_enqueue_style('leafletmapsmarker'); wp_register_style('leafletmapsmarker-ie-only', LEAFLET_PLUGIN_URL . '/leaflet-dist/leaflet.ie.css', array(), NULL); wp_enqueue_style('leafletmapsmarker-ie-only'); $wp_styles->add_data('leafletmapsmarker-ie-only', 'conditional', 'lt IE 9'); } function lmm_admin_enqueue_stylesheets() { global $wp_styles; wp_register_style( 'leafletmapsmarker', LEAFLET_PLUGIN_URL . '/leaflet-dist/leaflet.css', array(), NULL ); wp_enqueue_style( 'leafletmapsmarker' ); wp_register_style( 'leafletmapsmarker-admin', LEAFLET_PLUGIN_URL . '/css/leafletmapsmarker-admin.css', array(), NULL ); wp_enqueue_style('leafletmapsmarker-admin' ); wp_register_style('leafletmapsmarker-ie-only', LEAFLET_PLUGIN_URL . '/leaflet-dist/leaflet.ie.css', array(), NULL); wp_enqueue_style('leafletmapsmarker-ie-only'); $wp_styles->add_data('leafletmapsmarker-ie-only', 'conditional', 'lt IE 8'); } function lmm_install_and_updates() { global $wpdb; //info: 2 options not managed by Settings API (class-leaflet-options.php) add_option('leafletmapsmarker_version', 'init'); add_option('leafletmapsmarker_redirect', 'true'); //redirect to plugin settings page after first activation only if (get_option('leafletmapsmarker_version') == 'init') { //info: copy map icons to wp-content/uploads WP_Filesystem(); $target = ABSPATH . 'wp-content/uploads/leaflet-maps-marker-icons'; if (!is_dir($target)) //info: check for multisite installations { wp_mkdir_p( $target ); $source = WP_PLUGIN_DIR . '/' . end(explode('/', dirname(__FILE__))) . '/img/mapicons'; copy_dir($source, $target, $skip_list = array() ); $zipfile = ABSPATH . 'wp-content/uploads/leaflet-maps-marker-icons/mapicons.zip'; unzip_file( $zipfile, $target ); } //info: create tables for markers & layers $table_name_markers = $wpdb->prefix.'leafletmapsmarker_markers'; $table_name_layers = $wpdb->prefix.'leafletmapsmarker_layers'; $sql_create_marker_table = "CREATE TABLE IF NOT EXISTS `" . $table_name_markers . "` ( `id` int(6) unsigned NOT NULL auto_increment, `markername` varchar(255) CHARACTER SET utf8 NOT NULL, `basemap` varchar(20) NOT NULL, `layer` int(6) unsigned NOT NULL, `lat` decimal(9,6) NOT NULL, `lon` decimal(9,6) NOT NULL, `icon` varchar(255) CHARACTER SET utf8 NOT NULL, `popuptext` text CHARACTER SET utf8 NOT NULL, `zoom` int(2) NOT NULL, `openpopup` tinyint(1) NOT NULL, `mapwidth` int(4) NOT NULL, `mapwidthunit` varchar(2) NOT NULL, `mapheight` int(4) NOT NULL, `panel` tinyint(1) NOT NULL, `createdby` varchar(30) CHARACTER SET utf8 NOT NULL, `createdon` datetime NOT NULL, `updatedby` varchar(30) CHARACTER SET utf8 NOT NULL, `updatedon` datetime NOT NULL, `controlbox` int(1) NOT NULL, `overlays_custom` int(1) NOT NULL, `overlays_custom2` int(1) NOT NULL, `overlays_custom3` int(1) NOT NULL, `overlays_custom4` int(1) NOT NULL, `wms` int(1) NOT NULL, `wms2` int(1) NOT NULL, `wms3` int(1) NOT NULL, `wms4` int(1) NOT NULL, `wms5` int(1) NOT NULL, `wms6` int(1) NOT NULL, `wms7` int(1) NOT NULL, `wms8` int(1) NOT NULL, `wms9` int(1) NOT NULL, `wms10` int(1) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;"; $wpdb->query($sql_create_marker_table); $sql_create_layer_table = "CREATE TABLE IF NOT EXISTS `".$table_name_layers."` ( `id` int(6) unsigned NOT NULL auto_increment, `name` varchar(255) CHARACTER SET utf8 NOT NULL, `basemap` varchar(20) NOT NULL, `layerzoom` int(2) NOT NULL, `mapwidth` int(4) NOT NULL, `mapwidthunit` varchar(2) NOT NULL, `mapheight` int(4) NOT NULL, `panel` tinyint(1) NOT NULL, `layerviewlat` decimal(9,6) NOT NULL, `layerviewlon` decimal(9,6) NOT NULL, `createdby` varchar(30) CHARACTER SET utf8 NOT NULL, `createdon` datetime NOT NULL, `updatedby` varchar(30) CHARACTER SET utf8 NOT NULL, `updatedon` datetime NOT NULL, `controlbox` int(1) NOT NULL, `overlays_custom` int(1) NOT NULL, `overlays_custom2` int(1) NOT NULL, `overlays_custom3` int(1) NOT NULL, `overlays_custom4` int(1) NOT NULL, `wms` int(1) NOT NULL, `wms2` int(1) NOT NULL, `wms3` int(1) NOT NULL, `wms4` int(1) NOT NULL, `wms5` int(1) NOT NULL, `wms6` int(1) NOT NULL, `wms7` int(1) NOT NULL, `wms8` int(1) NOT NULL, `wms9` int(1) NOT NULL, `wms10` int(1) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;"; $wpdb->query($sql_create_layer_table); //info: insert layer row 0 for markers without assigned layer $sql = "SET SESSION sql_mode=NO_AUTO_VALUE_ON_ZERO;"; $wpdb->query($sql); $sql2 = "INSERT INTO `".$table_name_layers."` ( `id`, `name`, `basemap`, `layerzoom`, `mapwidth`, `mapwidthunit`, `mapheight`, `layerviewlat`, `layerviewlon` ) VALUES (0, 'markers not assigned to a layer', 'osm_mapnik', '11', '640', 'px', '480', '', '');"; $wpdb->query($sql2); $sql3 = "SET SESSION sql_mode='';"; $wpdb->query($sql3); update_option('leafletmapsmarker_version', '1.0'); //info: redirect to settings page only on first plugin activation, otherwise redirect is also done on bulk plugin activations if (get_option('leafletmapsmarker_redirect') == 'true') { update_option('leafletmapsmarker_redirect', 'false'); wp_redirect(WP_ADMIN_URL.'admin.php?page=leafletmapsmarker_settings&display=install_note'); } } /* prepared for plugin update 1.1 if (get_option('leafletmapsmarker_version') == '1.0' ) { //mandatory if new options in class-leaflet-options.php were added $save_defaults_for_new_options = new Leafletmapsmarker_options(); $save_defaults_for_new_options->save_defaults_for_new_options(); //optional: add code for sql ddl updates //mandatory: update_option('leafletmapsmarker_version', '1.1'); //mandatory: move code for redirect-on-first-activation-check to here } */ }//info: end install_and_updates() function lmm_plugin_meta_links() { define( 'FB_BASENAME', plugin_basename( __FILE__ ) ); define( 'FB_BASEFOLDER', plugin_basename( dirname( __FILE__ ) ) ); define( 'FB_FILENAME', str_replace( FB_BASEFOLDER.'/', '', plugin_basename(__FILE__) ) ); function leafletmapsmarker_filter_plugin_meta($links, $file) { if ( $file == FB_BASENAME ) { array_unshift( $links, ''.__('Markers','lmm').'', ''.__('Layers','lmm').'' , ''.__('Settings','lmm').'' ); } return $links; } add_filter( 'plugin_action_links', 'leafletmapsmarker_filter_plugin_meta', 10, 2 ); } //info: end plugin_meta_links() } //info: end class $run_leafletmapsmarker = new Leafletmapsmarker(); unset($run_leafletmapsmarker); ?>