2018-12-08 09:44:28 +00:00
< ? php
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
if ( is_admin () ) {
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
add_action ( 'admin_menu' , 'wpgpxmaps_admin_menu' );
2019-01-03 11:11:14 +00:00
2018-12-08 09:44:28 +00:00
}
2019-01-03 11:11:14 +00:00
2018-12-08 09:44:28 +00:00
function wpgpxmaps_admin_menu () {
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
/*
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
All roles / capabilities :
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
https :// wordpress . org / support / article / roles - and - capabilities /
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
*/
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
if ( current_user_can ( 'manage_options' ) ) {
/* Only Administrators and Super Administrators */
add_options_page ( 'WP GPX Maps' , 'WP GPX Maps' , 'manage_options' , 'WP-GPX-Maps' , 'WP_GPX_Maps_html_page' );
2019-01-03 11:11:14 +00:00
2018-12-08 09:44:28 +00:00
}
2019-06-18 07:09:56 +00:00
elseif ( current_user_can ( 'publish_posts' ) ) {
/* Contributor Authors and */
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
$allow_users_upload = get_option ( 'wpgpxmaps_allow_users_view' ) === " true " ;
2018-12-08 09:44:28 +00:00
2019-06-18 07:09:56 +00:00
if ( $allow_users_upload == 1 )
{
add_menu_page ( 'WP GPX Maps' , 'WP GPX Maps' , 'publish_posts' , 'WP-GPX-Maps' , 'WP_GPX_Maps_html_page' );
}
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
}
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
}
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
function wpgpxmaps_ilc_admin_tabs ( $current ) {
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
if ( current_user_can ( 'manage_options' ) ) {
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
$tabs = array (
'tracks' => __ ( 'Tracks' , 'wp-gpx-maps' ),
'settings' => __ ( 'Settings' , 'wp-gpx-maps' ),
'help' => __ ( 'Help' , 'wp-gpx-maps' ),
);
} elseif ( current_user_can ( 'publish_posts' ) ) {
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
$tabs = array (
'tracks' => __ ( 'Tracks' , 'wp-gpx-maps' ),
'help' => __ ( 'Help' , 'wp-gpx-maps' ),
);
2018-12-08 09:44:28 +00:00
}
2019-06-18 07:09:56 +00:00
echo '<h2 class="nav-tab-wrapper">' ;
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
foreach ( $tabs as $tab => $name ) {
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
$class = ( $tab == $current ) ? ' nav-tab-active' : '' ;
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
echo " <a class='nav-tab $class ' href='?page=WP-GPX-Maps&tab= $tab '> $name </a> " ;
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
}
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
echo '</h2>' ;
2019-01-03 11:11:14 +00:00
2018-12-08 09:44:28 +00:00
}
2019-01-03 11:11:14 +00:00
2018-12-08 09:44:28 +00:00
function WP_GPX_Maps_html_page () {
2019-01-03 11:11:14 +00:00
2018-12-08 09:44:28 +00:00
$realGpxPath = gpxFolderPath ();
2019-01-03 11:11:14 +00:00
2018-12-08 09:44:28 +00:00
$cacheGpxPath = gpxCacheFolderPath ();
2019-01-03 11:11:14 +00:00
2018-12-08 09:44:28 +00:00
$relativeGpxPath = relativeGpxFolderPath ();
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
$relativeGpxPath = str_replace ( " \\ " , " / " , $relativeGpxPath );
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
$relativeGpxCachePath = relativeGpxCacheFolderPath ();
$relativeGpxCachePath = str_replace ( " \\ " , " / " , $relativeGpxCachePath );
2019-01-03 11:11:14 +00:00
2018-12-08 09:44:28 +00:00
$tab = $_GET [ 'tab' ];
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
if ( $tab == '' )
2019-01-03 11:11:14 +00:00
2018-12-08 09:44:28 +00:00
$tab = 'tracks' ;
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
?>
2019-01-03 11:11:14 +00:00
2018-12-08 09:44:28 +00:00
< div id = " icon-themes " class = " icon32 " >< br ></ div >
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
< h2 >< ? php _e ( 'Settings' , 'wp-gpx-maps' ); ?> </h2>
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
< ? php
2018-12-08 09:44:28 +00:00
2019-06-18 07:09:56 +00:00
if ( file_exists ( $realGpxPath ) && is_dir ( $realGpxPath ) ) {
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
/* Directory exist! */
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
} else {
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
if ( ! @ mkdir ( $realGpxPath , 0755 , true ) ) {
echo '<div class=" notice notice-error"><p>' ;
printf (
/* translators: Relative path of the GPX folder */
__ ( 'Can not create the folder %1s for GPX files. Please create the folder and make it writable! If not, you will must update the files manually!' , 'wp-gpx-maps' ),
'<span class="code"><strong>' . esc_html ( $relativeGpxPath ) . '</strong></span>'
);
echo '</p></div>' ;
2018-12-08 09:44:28 +00:00
}
}
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
if ( file_exists ( $cacheGpxPath ) && is_dir ( $cacheGpxPath ) ) {
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
/* Directory exist! */
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
} else {
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
if ( ! @ mkdir ( $cacheGpxPath , 0755 , true ) ) {
echo '<div class=" notice notice-error"><p>' ;
printf (
/* translators: Relative path of the GPX cache folder */
__ ( 'Can not create the cache folder %1s for the GPX files. Please create the folder and make it writable! If not, you will must update the files manually!' , 'wp-gpx-maps' ),
'<span class="code"><strong>' . esc_html ( $relativeGpxCachePath ) . '</strong></span>'
);
echo '</p></div>' ;
2018-12-08 09:44:28 +00:00
}
}
2019-06-18 07:09:56 +00:00
wpgpxmaps_ilc_admin_tabs ( $tab );
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
if ( $tab == 'tracks' ) {
2018-12-08 09:44:28 +00:00
include 'wp-gpx-maps_admin_tracks.php' ;
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
} elseif ( $tab == 'settings' ) {
2018-12-08 09:44:28 +00:00
include 'wp-gpx-maps_admin_settings.php' ;
2019-01-03 11:11:14 +00:00
2019-06-18 07:09:56 +00:00
} elseif ( $tab == 'help' ) {
include 'wp-gpx-maps_help.php' ;
2018-12-08 09:44:28 +00:00
}
}
2019-01-03 11:11:14 +00:00
?>