| 1 |
<?php |
| 2 |
/** |
| 3 |
* Settings View |
| 4 |
* |
| 5 |
* PHP Version 5.5 |
| 6 |
* |
| 7 |
* @category Admin |
| 8 |
* @author Benjamin J DeLong <[email protected]> |
| 9 |
*/ |
| 10 |
|
| 11 |
$title = $plugin_data['Name']; |
| 12 |
$description = __('A plugin for creating a Leaflet JS map with a shortcode. Boasts two free map tile services and three free geocoders.', 'leaflet-map'); |
| 13 |
$version = $plugin_data['Version']; |
| 14 |
?> |
| 15 |
<div class="wrap"> |
| 16 |
|
| 17 |
<h1><?php echo esc_html($title); ?> <small>version: <?php echo esc_html($version); ?></small></h1> |
| 18 |
|
| 19 |
<?php |
| 20 |
/** START FORM SUBMISSION */ |
| 21 |
|
| 22 |
// validate nonce! |
| 23 |
define('NONCE_NAME', 'leaflet-map-nonce'); |
| 24 |
define('NONCE_ACTION', 'leaflet-map-action'); |
| 25 |
|
| 26 |
function verify_nonce () { |
| 27 |
$verified = ( |
| 28 |
isset($_POST[NONCE_NAME]) && |
| 29 |
check_admin_referer(NONCE_ACTION, NONCE_NAME) |
| 30 |
); |
| 31 |
|
| 32 |
if (!$verified) { |
| 33 |
// side-effects can be fun? |
| 34 |
?> |
| 35 |
<div class="notice notice-error is-dismissible"> |
| 36 |
<p><?php esc_html_e('Sorry, your nonce did not verify', 'leaflet-map'); ?></p> |
| 37 |
</div> |
| 38 |
<?php |
| 39 |
} |
| 40 |
|
| 41 |
return $verified; |
| 42 |
} |
| 43 |
|
| 44 |
if (isset($_POST['submit']) && verify_nonce()) { |
| 45 |
/* copy and overwrite $post for checkboxes */ |
| 46 |
$form = $_POST; |
| 47 |
|
| 48 |
foreach ($settings->options as $name => $option) { |
| 49 |
if (!$option->type) continue; |
| 50 |
|
| 51 |
/* checkboxes don't get sent if not checked */ |
| 52 |
if ($option->type === 'checkbox') { |
| 53 |
$form[$name] = isset($_POST[ $name ]) ? 1 : 0; |
| 54 |
} |
| 55 |
|
| 56 |
$value = trim( stripslashes( $form[$name]) ); |
| 57 |
|
| 58 |
$settings->set($name, $value); |
| 59 |
} |
| 60 |
?> |
| 61 |
<div class="notice notice-success is-dismissible"> |
| 62 |
<p><?php esc_html_e('Options Updated!', 'leaflet-map'); ?></p> |
| 63 |
</div> |
| 64 |
<?php |
| 65 |
} elseif (isset($_POST['reset']) && verify_nonce()) { |
| 66 |
$settings->reset(); |
| 67 |
?> |
| 68 |
<div class="notice notice-success is-dismissible"> |
| 69 |
<p><?php esc_html_e('Options have been reset to default values!', 'leaflet-map'); ?></p> |
| 70 |
</div> |
| 71 |
<?php |
| 72 |
} elseif (isset($_POST['clear-geocoder-cache']) && verify_nonce()) { |
| 73 |
include_once LEAFLET_MAP__PLUGIN_DIR . 'class.geocoder.php'; |
| 74 |
Leaflet_Geocoder::remove_caches(); |
| 75 |
?> |
| 76 |
<div class="notice notice-success is-dismissible"> |
| 77 |
<p><?php esc_html_e('Location caches have been cleared!', 'leaflet-map'); ?></p> |
| 78 |
</div> |
| 79 |
<?php |
| 80 |
} |
| 81 |
/** END FORM SUBMISSION */ |
| 82 |
|
| 83 |
/** CHECK LEAFLET VERSION */ |
| 84 |
$db_js_url = $settings->get('js_url'); |
| 85 |
$unpkg_url = "https://unpkg.com/leaflet"; |
| 86 |
$is_unpkg_url = substr_compare($db_js_url, $unpkg_url, 0, strlen($unpkg_url)) === 0; |
| 87 |
|
| 88 |
if ($is_unpkg_url && $db_js_url !== $settings->options[ 'js_url' ]->default) { |
| 89 |
?> |
| 90 |
<div class="notice notice-info is-dismissible"> |
| 91 |
<p><?php |
| 92 |
esc_html_e('Info: your leaflet version may be out-of-sync with the latest default version: ', 'leaflet-map'); |
| 93 |
echo Leaflet_Map::$leaflet_version; |
| 94 |
?></p> |
| 95 |
</div> |
| 96 |
<?php |
| 97 |
} |
| 98 |
/** END LEAFLET VERSION */ |
| 99 |
?> |
| 100 |
|
| 101 |
<p><?php echo esc_html($description); ?></p> |
| 102 |
<?php |
| 103 |
/** FILTERS for helptext */ |
| 104 |
$allowed_helptext_tags = [ |
| 105 |
'a' => [ 'href' => [], 'title' => [], 'target' => [] ], |
| 106 |
'code' => [], |
| 107 |
'br' => [], |
| 108 |
'p' => [], |
| 109 |
'b' => [], |
| 110 |
]; |
| 111 |
?> |
| 112 |
|
| 113 |
<h3><?php esc_html_e('Found an issue?', 'leaflet-map') ?></h3> |
| 114 |
<p><?php esc_html_e('Post it to ', 'leaflet-map') ?><b><?php esc_html_e('WordPress Support', 'leaflet-map') ?></b>: <a href="https://wordpress.org/support/plugin/leaflet-map/" target="_blank">Leaflet Map (WordPress)</a></p> |
| 115 |
<p><?php esc_html_e('Add an issue on ', 'leaflet-map') ?><b>GitHub</b>: <a href="https://github.com/bozdoz/wp-plugin-leaflet-map/issues" target="_blank">Leaflet Map (GitHub)</a></p> |
| 116 |
|
| 117 |
<div class="wrap"> |
| 118 |
<div class="wrap"> |
| 119 |
<form method="post"> |
| 120 |
<?php wp_nonce_field(NONCE_ACTION, NONCE_NAME); ?> |
| 121 |
<div class="container"> |
| 122 |
<h2><?php esc_html_e('Settings', 'leaflet-map'); ?></h2> |
| 123 |
<hr> |
| 124 |
</div> |
| 125 |
<?php |
| 126 |
foreach ($settings->options as $name => $option) { |
| 127 |
if (!$option->type) continue; |
| 128 |
?> |
| 129 |
<div class="container"> |
| 130 |
<label> |
| 131 |
<span class="label"><?php echo esc_html($option->display_name); ?></span> |
| 132 |
<span class="input-group"> |
| 133 |
<?php |
| 134 |
$option->widget($name, $settings->get($name)); |
| 135 |
?> |
| 136 |
</span> |
| 137 |
</label> |
| 138 |
|
| 139 |
<?php |
| 140 |
if ($option->helptext) { |
| 141 |
?> |
| 142 |
<div class="helptext"> |
| 143 |
<p class="description"><?php |
| 144 |
echo wp_kses( $option->helptext, $allowed_helptext_tags ); |
| 145 |
?></p> |
| 146 |
</div> |
| 147 |
<?php |
| 148 |
} |
| 149 |
?> |
| 150 |
</div> |
| 151 |
<?php |
| 152 |
} |
| 153 |
?> |
| 154 |
<div class="submit"> |
| 155 |
<input type="submit" |
| 156 |
name="submit" |
| 157 |
id="submit" |
| 158 |
class="button button-primary" |
| 159 |
value="<?php esc_html_e('Save Changes', 'leaflet-map'); ?>"> |
| 160 |
<input type="submit" |
| 161 |
name="reset" |
| 162 |
id="reset" |
| 163 |
class="button button-secondary" |
| 164 |
value="<?php esc_html_e('Reset to Defaults', 'leaflet-map'); ?>"> |
| 165 |
<input type="submit" |
| 166 |
name="clear-geocoder-cache" |
| 167 |
id="clear-geocoder-cache" |
| 168 |
class="button button-secondary" |
| 169 |
value="<?php esc_html_e('Clear Geocoder Cache', 'leaflet-map'); ?>"> |
| 170 |
</div> |
| 171 |
|
| 172 |
</form> |
| 173 |
|
| 174 |
<div> |
| 175 |
<p><?php esc_html_e('Leaf icon provided by ', 'leaflet-map') ?><a href="https://fontawesome.com/" target="_blank">Font Awesome</a><?php esc_html_e( ', under their free license.', 'leaflet-map' ) ?></p> |
| 176 |
</div> |
| 177 |
|
| 178 |
</div> |
| 179 |
</div> |
| 180 |
|