Created
January 20, 2016 18:10
-
-
Save seyfro/5cd1b9367d403e0584fd to your computer and use it in GitHub Desktop.
XML Sitemap plugin integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('sm_buildmap',array(&$this, 'lmm_add_kml_to_sitemap')); | |
function lmm_add_kml_to_sitemap(){ | |
if(class_exists('GoogleSitemapGenerator')) { | |
global $wpdb; | |
$table_name_markers = $wpdb->prefix.'leafletmapsmarker_markers'; | |
$table_name_layers = $wpdb->prefix.'leafletmapsmarker_layers'; | |
$lmm_options = get_option( 'leafletmapsmarker_options' ); | |
$sitemap = GoogleSitemapGenerator::GetInstance(); | |
//info: add markers | |
if ( ($lmm_options[ 'xml_sitemaps_include' ] == 'both') || ($lmm_options[ 'xml_sitemaps_include' ] == 'markers') ) { | |
$sql_markers = 'SELECT m.id as mid, m.createdon as mcreatedon, m.updatedon as mupdatedon FROM `'.$table_name_markers.'` AS m'; | |
//info: exclude specific markers | |
if ($lmm_options[ 'xml_sitemaps_exclude_markers' ] != NULL ) { | |
if (preg_match('/^\d(?:,\d)*$/', str_replace(', ', ',', trim($lmm_options[ 'xml_sitemaps_exclude_markers' ]))) == TRUE) { | |
$sql_markers .= ' WHERE m.id NOT IN (' . str_replace(', ', ',', trim($lmm_options[ 'xml_sitemaps_exclude_markers' ])) . ')'; | |
} | |
} | |
$markers = $wpdb->get_results($sql_markers, ARRAY_A); | |
foreach ($markers as $marker) { | |
if ( ($marker['mupdatedon'] == NULL) || ($marker['mupdatedon'] == '0000-00-00 00:00:00') ){ | |
$date_kml = strtotime($marker['mcreatedon']); | |
} else { | |
$date_kml = strtotime($marker['mupdatedon']); | |
} | |
$sitemap->AddUrl(LEAFLET_PLUGIN_URL . 'leaflet-kml.php?marker=' . $marker['mid'], $date_kml, $lmm_options['xml_sitemaps_change_frequency_markers'], $lmm_options['xml_sitemaps_priority_markers']); | |
} | |
} | |
//info: add layers | |
if ( ($lmm_options[ 'xml_sitemaps_include' ] == 'both') || ($lmm_options[ 'xml_sitemaps_include' ] == 'layers') ) { | |
$sql_layers = 'SELECT l.id as lid, l.createdon as lcreatedon, l.updatedon as lupdatedon FROM `'.$table_name_layers.'` AS l WHERE l.id != 0'; | |
//info: exclude specific layers | |
if ($lmm_options[ 'xml_sitemaps_exclude_layers' ] != NULL ) { | |
if (preg_match('/^\d(?:,\d)*$/', str_replace(', ', ',', trim($lmm_options[ 'xml_sitemaps_exclude_layers' ]))) == TRUE) { | |
$sql_layers .= ' AND l.id NOT IN (' . str_replace(', ', ',', trim($lmm_options[ 'xml_sitemaps_exclude_layers' ])) . ')'; | |
} | |
} | |
$layers = $wpdb->get_results($sql_layers, ARRAY_A); | |
foreach ($layers as $layer) { | |
if ( ($layer['lupdatedon'] == NULL) || ($layer['lupdatedon'] == '0000-00-00 00:00:00') ){ | |
$date_kml = strtotime($layer['lcreatedon']); | |
} else { | |
$date_kml = strtotime($layer['lupdatedon']); | |
} | |
$sitemap->AddUrl(LEAFLET_PLUGIN_URL . 'leaflet-kml.php?layer=' . $layer['lid'], $date_kml, $lmm_options['xml_sitemaps_change_frequency_layers'], $lmm_options['xml_sitemaps_priority_layers']); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment