| 1 |
<?php |
| 2 |
/** |
| 3 |
* File admin.php |
| 4 |
* |
| 5 |
* @package Extensions for Leaflet Map |
| 6 |
*/ |
| 7 |
|
| 8 |
// Direktzugriff auf diese Datei verhindern. |
| 9 |
defined( 'ABSPATH' ) || die(); |
| 10 |
|
| 11 |
require __DIR__ . '/admin/deleting.php'; |
| 12 |
require __DIR__ . '/admin/elevation/main.php'; |
| 13 |
require __DIR__ . '/admin/marker/main.php'; |
| 14 |
require __DIR__ . '/admin/gesture.php'; |
| 15 |
require __DIR__ . '/admin/tiles/main.php'; |
| 16 |
require __DIR__ . '/admin/filemgr/main.php'; |
| 17 |
require __DIR__ . '/admin/hover/main.php'; |
| 18 |
require __DIR__ . '/admin/overviewmap/overview-map.php'; |
| 19 |
require __DIR__ . '/admin/overviewmap/featured-map.php'; |
| 20 |
require __DIR__ . '/admin/grouping/main.php'; |
| 21 |
require __DIR__ . '/admin/awesome.php'; |
| 22 |
require __DIR__ . '/admin/zoomhome.php'; |
| 23 |
|
| 24 |
/** |
| 25 |
* Add menu page for admin |
| 26 |
*/ |
| 27 |
function leafext_add_page() { |
| 28 |
// Add Submenu. |
| 29 |
$leafext_admin_page = add_submenu_page( |
| 30 |
'leaflet-map', |
| 31 |
esc_html__( 'Extensions for Leaflet Map Options', 'extensions-leaflet-map' ), |
| 32 |
esc_html__( 'Extensions for Leaflet Map', 'extensions-leaflet-map' ), |
| 33 |
'manage_options', |
| 34 |
LEAFEXT_PLUGIN_SETTINGS, |
| 35 |
'leafext_do_page' |
| 36 |
); |
| 37 |
} |
| 38 |
add_action( 'admin_menu', 'leafext_add_page', 80 ); |
| 39 |
|
| 40 |
/** |
| 41 |
* Draw the menu page itself. |
| 42 |
*/ |
| 43 |
function leafext_do_page() { |
| 44 |
$tab = filter_input( |
| 45 |
INPUT_GET, |
| 46 |
'tab', |
| 47 |
FILTER_CALLBACK, |
| 48 |
array( 'options' => 'esc_html' ) |
| 49 |
); |
| 50 |
$active_tab = $tab ? $tab : 'help'; |
| 51 |
|
| 52 |
echo '<div style="max-width: 1000px;">'; |
| 53 |
echo '<div class="wrap nothickbox">'; |
| 54 |
echo '<h2>' . esc_html__( 'Extensions for Leaflet Map - Help and Documentation', 'extensions-leaflet-map' ) . '</h2></div>' . "\n"; |
| 55 |
echo '</div>' . "\n"; |
| 56 |
|
| 57 |
if ( leafext_plugin_active( 'leaflet-map' ) ) { |
| 58 |
leafext_admin_tabs(); |
| 59 |
if ( strpos( $active_tab, 'elevation' ) !== false ) { |
| 60 |
leafext_admin_elevation( $active_tab ); |
| 61 |
} elseif ( strpos( $active_tab, 'filemgr' ) !== false ) { |
| 62 |
leafext_admin_filemgr( $active_tab ); |
| 63 |
} elseif ( strpos( $active_tab, 'marker' ) !== false ) { |
| 64 |
leafext_admin_marker( $active_tab ); |
| 65 |
} elseif ( strpos( $active_tab, 'tiles' ) !== false ) { |
| 66 |
leafext_admin_tiles( $active_tab ); |
| 67 |
} elseif ( strpos( $active_tab, 'hover' ) !== false ) { |
| 68 |
leafext_admin_hover( $active_tab ); |
| 69 |
} elseif ( $active_tab === 'gesture' ) { |
| 70 |
echo '<form method="post" action="options.php">'; |
| 71 |
settings_fields( 'leafext_settings_gesture' ); |
| 72 |
do_settings_sections( 'leafext_settings_gesture' ); |
| 73 |
if ( current_user_can( 'manage_options' ) ) { |
| 74 |
wp_nonce_field( 'leafext_gesture', 'leafext_gesture_nonce' ); |
| 75 |
submit_button(); |
| 76 |
} |
| 77 |
echo '</form>'; |
| 78 |
} elseif ( $active_tab === 'zoomhome' ) { |
| 79 |
leafext_help_awesome(); |
| 80 |
echo '<form method="post" action="options.php">'; |
| 81 |
settings_fields( 'leafext_settings_awesome' ); |
| 82 |
do_settings_sections( 'leafext_settings_awesome' ); |
| 83 |
if ( current_user_can( 'manage_options' ) ) { |
| 84 |
wp_nonce_field( 'leafext_awesome', 'leafext_awesome_nonce' ); |
| 85 |
submit_button(); |
| 86 |
} |
| 87 |
echo '</form>'; |
| 88 |
// |
| 89 |
leafext_zoomhome_help_head(); |
| 90 |
leafext_zoomhome_help_shortcode(); |
| 91 |
|
| 92 |
echo '<h2>' . esc_html__( 'Options', 'extensions-leaflet-map' ) . '</h2>'; |
| 93 |
echo '<form method="post" action="options.php">'; |
| 94 |
settings_fields( 'leafext_settings_zoomhome' ); |
| 95 |
do_settings_sections( 'leafext_settings_zoomhome' ); |
| 96 |
if ( current_user_can( 'manage_options' ) ) { |
| 97 |
wp_nonce_field( 'leafext_zoomhome', 'leafext_zoomhome_nonce' ); |
| 98 |
submit_button(); |
| 99 |
submit_button( __( 'Reset', 'extensions-leaflet-map' ), 'delete', 'delete', false ); |
| 100 |
} |
| 101 |
echo '</form>'; |
| 102 |
leafext_zoomhome_help_table(); |
| 103 |
} elseif ( $active_tab === 'help' ) { |
| 104 |
include __DIR__ . '/admin/help.php'; |
| 105 |
echo '<form method="post" action="options.php">'; |
| 106 |
settings_fields( 'leafext_settings_deleting' ); |
| 107 |
do_settings_sections( 'leafext_settings_deleting' ); |
| 108 |
if ( current_user_can( 'manage_options' ) ) { |
| 109 |
wp_nonce_field( 'leafext_deleting', 'leafext_deleting_nonce' ); |
| 110 |
submit_button(); |
| 111 |
} |
| 112 |
echo '</form>'; |
| 113 |
leafext_help_table( LEAFEXT_PLUGIN_SETTINGS ); |
| 114 |
} elseif ( $active_tab === 'fullscreen' ) { |
| 115 |
include __DIR__ . '/admin/fullscreen.php'; |
| 116 |
echo wp_kses_post( leafext_help_fullscreen() ); |
| 117 |
} elseif ( $active_tab === 'choropleth' ) { |
| 118 |
include __DIR__ . '/admin/choropleth.php'; |
| 119 |
echo wp_kses_post( leafext_choropleth_help() ); |
| 120 |
} elseif ( strpos( $active_tab, 'group' ) !== false ) { |
| 121 |
leafext_admin_grouping( $active_tab ); |
| 122 |
} elseif ( $active_tab === 'leafletsearch' ) { |
| 123 |
include __DIR__ . '/admin/leaflet-search.php'; |
| 124 |
leafext_leafletsearch_help(); |
| 125 |
} elseif ( $active_tab === 'overviewmap' ) { |
| 126 |
echo '<form method="post" action="options.php">'; |
| 127 |
settings_fields( 'leafext_settings_overviewmap' ); |
| 128 |
do_settings_sections( 'leafext_settings_overviewmap' ); |
| 129 |
if ( current_user_can( 'manage_options' ) ) { |
| 130 |
wp_nonce_field( 'leafext_overviewmap', 'leafext_overviewmap_nonce' ); |
| 131 |
submit_button(); |
| 132 |
} |
| 133 |
echo '</form>'; |
| 134 |
} elseif ( $active_tab === 'featuredmap' ) { |
| 135 |
leafext_featuredmap_admin(); |
| 136 |
} |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
function leafext_admin_tabs() { |
| 141 |
$tab = filter_input( |
| 142 |
INPUT_GET, |
| 143 |
'tab', |
| 144 |
FILTER_CALLBACK, |
| 145 |
array( 'options' => 'esc_html' ) |
| 146 |
); |
| 147 |
$active_tab = $tab ? $tab : 'help'; |
| 148 |
|
| 149 |
echo '<h3 class="nav-tab-wrapper">'; |
| 150 |
echo '<a href="' . esc_url( '?page=' . LEAFEXT_PLUGIN_SETTINGS . '&tab=help' ) . '" class="nav-tab'; |
| 151 |
echo $active_tab === 'help' ? ' nav-tab-active' : ''; |
| 152 |
echo '">' . esc_html__( 'Help', 'extensions-leaflet-map' ) . '</a>' . "\n"; |
| 153 |
if ( current_user_can( 'manage_options' ) ) { |
| 154 |
echo '<a href="' . esc_url( '?page=' . LEAFEXT_PLUGIN_SETTINGS . '&tab=filemgr' ) . '" class="nav-tab'; |
| 155 |
if ( strpos( $active_tab, 'filemgr' ) !== false ) { |
| 156 |
echo ' nav-tab-active'; |
| 157 |
} |
| 158 |
echo '">' . esc_html__( 'Manage Leaflet Map files', 'extensions-leaflet-map' ) . '</a>' . "\n"; |
| 159 |
} else { |
| 160 |
echo '<a href="' . esc_url( '?page=' . LEAFEXT_PLUGIN_SETTINGS . '&tab=filemgr-list' ) . '" class="nav-tab'; |
| 161 |
echo $active_tab === 'filemgr-list' ? ' nav-tab-active' : ''; |
| 162 |
echo '">' . esc_html__( 'Manage Leaflet Map files', 'extensions-leaflet-map' ) . '</a>' . "\n"; |
| 163 |
} |
| 164 |
echo '<a href="' . esc_url( '?page=' . LEAFEXT_PLUGIN_SETTINGS . '&tab=elevation' ) . '" class="nav-tab'; |
| 165 |
if ( strpos( $active_tab, 'elevation' ) !== false ) { |
| 166 |
echo ' nav-tab-active'; |
| 167 |
} |
| 168 |
echo '">' . esc_html__( 'Elevation Profiles', 'extensions-leaflet-map' ) . '</a>' . "\n"; |
| 169 |
|
| 170 |
$tabs = array( |
| 171 |
array( |
| 172 |
'tab' => 'markercluster', |
| 173 |
'title' => __( 'Markers and Icons', 'extensions-leaflet-map' ), |
| 174 |
'strpos' => 'marker', |
| 175 |
), |
| 176 |
array( |
| 177 |
'tab' => 'featuregroup', |
| 178 |
'title' => __( 'Grouping by options and features', 'extensions-leaflet-map' ), |
| 179 |
), |
| 180 |
array( |
| 181 |
'tab' => 'leafletsearch', |
| 182 |
'title' => __( 'Search markers/features', 'extensions-leaflet-map' ), |
| 183 |
), |
| 184 |
array( |
| 185 |
'tab' => 'tiles', |
| 186 |
'title' => __( 'Switching Tile Servers', 'extensions-leaflet-map' ), |
| 187 |
'strpos' => 'tiles', |
| 188 |
), |
| 189 |
array( |
| 190 |
'tab' => 'hover', |
| 191 |
'title' => __( 'Hovering and Tooltips', 'extensions-leaflet-map' ), |
| 192 |
'strpos' => 'hover', |
| 193 |
), |
| 194 |
array( |
| 195 |
'tab' => 'overviewmap', |
| 196 |
'title' => __( 'Overview Map', 'extensions-leaflet-map' ), |
| 197 |
), |
| 198 |
array( |
| 199 |
'tab' => 'featuredmap', |
| 200 |
'title' => __( 'Featured Map', 'extensions-leaflet-map' ), |
| 201 |
), |
| 202 |
array( |
| 203 |
'tab' => 'zoomhome', |
| 204 |
'title' => __( 'Reset the map', 'extensions-leaflet-map' ), |
| 205 |
), |
| 206 |
array( |
| 207 |
'tab' => 'fullscreen', |
| 208 |
'title' => __( 'Fullscreen', 'extensions-leaflet-map' ), |
| 209 |
), |
| 210 |
array( |
| 211 |
'tab' => 'gesture', |
| 212 |
'title' => __( 'Gesture Handling', 'extensions-leaflet-map' ), |
| 213 |
), |
| 214 |
array( |
| 215 |
'tab' => 'choropleth', |
| 216 |
'title' => 'Choropleth Map', |
| 217 |
), |
| 218 |
// array( |
| 219 |
// 'tab' => '', |
| 220 |
// 'title' => '', |
| 221 |
// ), |
| 222 |
); |
| 223 |
|
| 224 |
foreach ( $tabs as $tab ) { |
| 225 |
echo '<a href="' . esc_url( '?page=' . LEAFEXT_PLUGIN_SETTINGS . '&tab=' . $tab['tab'] ) . '" class="nav-tab'; |
| 226 |
$active = ( $active_tab === $tab['tab'] ) ? ' nav-tab-active' : ''; |
| 227 |
if ( isset( $tab['strpos'] ) ) { |
| 228 |
if ( strpos( $active_tab, $tab['strpos'] ) !== false ) { |
| 229 |
$active = ' nav-tab-active'; |
| 230 |
} |
| 231 |
} |
| 232 |
echo esc_attr( $active ); |
| 233 |
echo '">' . esc_html( $tab['title'] ) . '</a>' . "\n"; |
| 234 |
} |
| 235 |
echo '</h3>'; |
| 236 |
} |
| 237 |
|
| 238 |
function leafext_admin_style( $hook ) { |
| 239 |
if ( strpos( $hook, LEAFEXT_PLUGIN_SETTINGS ) === false ) { |
| 240 |
return; |
| 241 |
} |
| 242 |
wp_enqueue_style( |
| 243 |
'leafext_admin_css', |
| 244 |
plugins_url( 'css/leafext-admin' . LEAFEXT_MINI . '.css', LEAFEXT_PLUGIN_FILE ), |
| 245 |
array(), |
| 246 |
LEAFEXT_VERSION |
| 247 |
); |
| 248 |
} |
| 249 |
add_action( 'admin_enqueue_scripts', 'leafext_admin_style' ); |
| 250 |
|
| 251 |
function leafext_leaflet_map_needed() { |
| 252 |
if ( ! leafext_plugin_active( 'leaflet-map' ) ) { |
| 253 |
$uri = sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ?? '' ) ); |
| 254 |
if ( strpos( $uri, 'plugins.php' ) !== false || strpos( $uri, 'admin.php' ) !== false ) { |
| 255 |
$message = '<div class="error notice is-dismissible"><p>' . sprintf( |
| 256 |
/* translators: %s is a link. */ |
| 257 |
__( 'Please install and activate %1$sLeaflet Map%2$s before using %3$s.', 'extensions-leaflet-map' ), |
| 258 |
'<a href="https://wordpress.org/plugins/leaflet-map/">', |
| 259 |
'</a>', |
| 260 |
__( 'Extensions for Leaflet Map', 'extensions-leaflet-map' ) |
| 261 |
) . '</p></div>'; |
| 262 |
echo wp_kses_post( $message ); |
| 263 |
} |
| 264 |
} |
| 265 |
} |
| 266 |
add_action( 'admin_notices', 'leafext_leaflet_map_needed' ); |
| 267 |
|