2018-12-08 09:44:28 +00:00
< ? php
2019-06-18 07:09:56 +00:00
if ( is_admin () ) {
add_action ( 'admin_menu' , 'wpgpxmaps_admin_menu' );
2018-12-08 09:44:28 +00:00
}
2019-07-02 06:39:27 +00:00
/**
* Roles and capabilities
*
* Capabilities for each user role that are relevant to this plugin :
*
* Super Admin : can manage settings ; can publish , edit and delete all posts ; can upload and delete all GPX files
* Admin : can manage settings ; can publish , edit and delete all posts ; can upload and delete all GPX files
* Editor : can not manage settings ; can publish , edit and delete all posts ; can upload and delete all GPX files
* Author : can not manage settings ; can publish , edit and delete his own posts ; can upload and delete his own files
* Contributor : can not manage settings ; can edit and delete his own posts ; can not manage GPX files
* Subscriber : can not manage settings ; can not manage posts ; can not manage GPX files ( has read status everywhere )
*
* @ see https :// wordpress . org / support / article / roles - and - capabilities /
*/
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
if ( current_user_can ( 'manage_options' ) ) {
2019-07-02 06:39:27 +00:00
/* Access only for Super Administrators and Administrators */
2019-06-18 07:09:56 +00:00
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
2019-07-02 06:39:27 +00:00
} elseif ( current_user_can ( 'publish_posts' ) ) {
/* Access for Editors and Authors */
2019-01-03 11:11:14 +00:00
2019-07-02 06:39:27 +00:00
/* Contributor Authors and */
$allow_users_upload = get_option ( 'wpgpxmaps_allow_users_view' ) === 'true' ;
2018-12-08 09:44:28 +00:00
2019-07-02 06:39:27 +00:00
if ( $allow_users_upload == 1 ) {
2019-06-18 07:09:56 +00:00
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-07-02 06:39:27 +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-07-02 06:39:27 +00:00
/* Access for Super Administrators and Administrators */
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' ),
);
2019-01-03 11:11:14 +00:00
2019-07-02 06:39:27 +00:00
} elseif ( current_user_can ( 'publish_posts' ) ) {
/* Access for Editors and Authors */
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-07-02 06:39:27 +00:00
$class = ( $tab == $current ) ? ' nav-tab-active' : '' ;
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
echo '</h2>' ;
2018-12-08 09:44:28 +00:00
}
function WP_GPX_Maps_html_page () {
2019-01-03 11:11:14 +00:00
2019-07-02 06:39:27 +00:00
$realGpxPath = gpxFolderPath ();
$cacheGpxPath = gpxCacheFolderPath ();
$relativeGpxPath = relativeGpxFolderPath ();
$relativeGpxPath = str_replace ( '\\' , '/' , $relativeGpxPath );
2019-06-18 07:09:56 +00:00
$relativeGpxCachePath = relativeGpxCacheFolderPath ();
2019-07-02 06:39:27 +00:00
$relativeGpxCachePath = str_replace ( '\\' , '/' , $relativeGpxCachePath );
$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-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-07-02 06:39:27 +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
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 {
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-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 {
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
?>