PluginProbe
Interactive World Map / trunk
Interactive World Map vtrunk
trunk 3.2.0 3.4.4 3.4.8
interactive-world-map / mapslist.php

mapslist.php in Interactive World Map trunk, at mapslist.php

355 lines 13.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 $update = false;
4 $options = freeworld_html5map_plugin_get_options();
5 $goptions = freeworld_html5map_plugin_get_options(null, 'freeworldhtml5map_goptions');
6
7 if (isset($_REQUEST['action'])) {
8 switch ($_REQUEST['action']) {
9 case 'map_import':
10 check_admin_referer('new');
11 if (freeworld_html5map_plugin_import($errors))
12 freeworld_html5map_plugin_messages(array(__('Configuration successfully imported!', 'freeworld-html5-map')), null);
13 else
14 freeworld_html5map_plugin_messages(null, $errors);
15 break;
16 case 'new':
17 check_admin_referer('new');
18 $type = 1;
19 $name = sanitize_text_field($_REQUEST['name']);
20 $defaults = freeworld_html5map_plugin_map_defaults($name, $type);
21 if ($defaults) {
22 $options[] = $defaults;
23 $update = true;
24 }
25 break;
26 case 'delete':
27 freeworld_html5map_plugin_delete_action();
28 break;
29 }
30 }
31
32 if ($update) freeworld_html5map_plugin_save_options($options);
33
34 if (isset($_REQUEST['goptions']) && is_array($_REQUEST['goptions'])) {
35 check_admin_referer('roles');
36 $goptions = array(
37 "roles" => (array)array_map('sanitize_text_field', $_REQUEST['goptions']['roles']),
38 );
39
40 freeworld_html5map_plugin_save_options($goptions, null, 'freeworldhtml5map_goptions');
41 }
42
43 function freeworld_html5map_plugin_delete_action() {
44 $options = freeworld_html5map_plugin_get_options();
45 $map_id = isset($_REQUEST['map_id']) ? $_REQUEST['map_id'] : array();
46 if ( ! is_array($map_id))
47 $map_id = explode(',', $map_id);
48
49 if ( ! $map_id)
50 return;
51
52 foreach ($map_id as $id) {
53 if ( ! isset($options[$id])) {
54 echo '<script>document.location.href="?page=freeworld-html5-map-maps"</script>';
55 exit;
56 }
57 }
58 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
59 check_admin_referer('delete');
60 foreach ($map_id as $id) {
61 unset($options[$id]);
62 }
63 freeworld_html5map_plugin_save_options($options);
64 echo '<script>document.location.href="?page=freeworld-html5-map-maps"</script>';
65 exit;
66 } else {
67 $names = array();
68 foreach ($map_id as $id) {
69 $names[] = $options[$id]['name'];
70 }
71 ?>
72 <form method="post">
73 <?php wp_nonce_field('delete'); ?>
74 <input type="hidden" name="map_id" value="<?php echo implode(',', $map_id) ?>">
75 <h1><?php _e('Delete map', 'freeworld-html5-map') ?></h1>
76 <p><?php echo sprintf(_n('You are going to delete following map: <b>%s</b>.', 'You are going to delete following maps: <b>%s</b>.', count($names), 'freeworld-html5-map'), implode(', ', $names)) ?></p>
77 <p><?php _e('<b style="color: red">Attention!</b> All settings for the map will be deleted permanently!', 'freeworld-html5-map') ?></p>
78 <p><?php _e('Are you sure?', 'freeworld-html5-map') ?></p>
79 <br><br><br><br>
80 <a class="button button-primary" href="?page=freeworld-html5-map-maps"><?php _e('No, return back', 'freeworld-html5-map'); ?></a>&nbsp;&nbsp;&nbsp;&nbsp;<button class="button deletion"><?php _e('Yes, delete', 'freeworld-html5-map') ?></button>
81 </form>
82 <?php
83 exit;
84 }
85 }
86
87 class Map_List_Table extends WP_List_Table {
88
89 public function __construct($arr = array())
90 {
91 parent::__construct(array(
92 'singular' => 'id',
93 'plural' => 'id'
94 ));
95 }
96
97 public function prepare_items()
98 {
99 $columns = $this->get_columns();
100 $hidden = $this->get_hidden_columns();
101 $sortable = $this->get_sortable_columns();
102
103 $data = $this->table_data();
104 usort( $data, array( &$this, 'sort_data' ) );
105
106 $this->_column_headers = array($columns, $hidden, $sortable);
107 $this->items = $data;
108 }
109
110 public function get_columns()
111 {
112 $columns = array(
113 'checkbox' => '<input type="checkbox" class="maps_toggle" autocomplete="off" />',
114 'name' => __('Name', 'freeworld-html5-map'),
115 'shortcode' => __('ShortCode', 'freeworld-html5-map'),
116 'edit' => __('Edit', 'freeworld-html5-map'),
117 );
118
119 return $columns;
120 }
121
122 public function get_bulk_actions()
123 {
124 return array(
125 'delete' => __('Delete', 'freeworld-html5-map'),
126 /*'freeworld-html5-map-export' => __('Export', 'freeworld-html5-map')*/
127 );
128 }
129
130 public function get_hidden_columns()
131 {
132 return array();
133 }
134
135 public function get_sortable_columns()
136 {
137 return array(
138 'name' => array('name', false),
139 );
140 }
141
142 private function table_data()
143 {
144
145 $data = array();
146 $options = freeworld_html5map_plugin_get_options();
147
148 foreach ($options as $map_id => $map_data) {
149 $data[] = array(
150 'id' => $map_id,
151 'name' => $map_data['name'],
152 'shortcode' => '[freeworldhtml5map id="'.$map_id.'"]',
153 'edit' => '<div style="float: left"><a href="admin.php?page=freeworld-html5-map-options&map_id='.$map_id.'">'.__('General settings', 'freeworld-html5-map').'</a><br />
154 <a href="admin.php?page=freeworld-html5-map-states&map_id='.$map_id.'">'.__('Detailed settings', 'freeworld-html5-map').'</a><br />'.
155 '<a href="admin.php?page=freeworld-html5-map-tools&map_id='.$map_id.'">'.__('Tools', 'freeworld-html5-map').'</a><br />'.
156 '<a href="admin.php?page=freeworld-html5-map-view&map_id='.$map_id.'">'.__('Preview', 'freeworld-html5-map').'</a><br /><br /></div>
157 <div style="float: right; padding-right: 20px;">
158 <a href="admin.php?page=freeworld-html5-map-maps&action=delete&map_id='.$map_id.'" class="delete" style="color:#FF0000">'.__('Delete', 'freeworld-html5-map').'</a><br />
159 </div>
160 ',
161 );
162 }
163
164 return $data;
165 }
166
167 public function column_default( $item, $column_name )
168 {
169
170 switch( $column_name ) {
171 case 'checkbox':
172 echo '&nbsp;<input type="checkbox" name="map_id[]" value="'.$item['id'].'" class="map_checkbox" autocomplete="off" />';
173 break;
174 case 'name':
175 case 'shortcode':
176 case 'edit':
177 return $item[ $column_name ];
178 }
179 }
180
181 private function sort_data( $a, $b )
182 {
183 // Set defaults
184 $orderby = 'name';
185 $order = 'asc';
186
187 // If orderby is set, use this as the sort column
188 if(!empty($_GET['orderby']))
189 {
190 $orderby = $_GET['orderby'];
191 }
192
193 // If order is set use this as the order
194 if(!empty($_GET['order']))
195 {
196 $order = $_GET['order'];
197 }
198
199 $result = strcmp( $a[$orderby], $b[$orderby] );
200
201 if($order === 'asc')
202 {
203 return $result;
204 }
205
206 return -$result;
207 }
208
209 public function get_table_classes()
210 {
211 $list = parent::get_table_classes();
212 return $list;
213 }
214
215 }
216
217
218 $listtable = new Map_List_Table();
219 $listtable->prepare_items();
220
221 ?>
222
223 <style>
224 .column-shortcode {
225 min-width: 150px
226 }
227 .column-edit {
228 width: 220px;
229 }
230 </style>
231
232 <div class="wrap freeworld-html5-map full">
233 <div id="icon-users" class="icon32"></div>
234 <h2><?php echo __('Maps dashboard', 'freeworld-html5-map'); ?></h2>
235
236
237 <div class="left-block">
238 <form name="action_form" action="" method="POST" enctype="multipart/form-data" class="" style="margin-top: 20px">
239 <input type="hidden" name="action" value="new" />
240 <input type="hidden" name="maps" value="" />
241 <?php wp_nonce_field('new'); ?>
242
243 <fieldset>
244 <legend><?php echo __('Add new map', 'freeworld-html5-map'); ?></legend>
245 <span><?php echo __('New map name:', 'freeworld-html5-map'); ?></span>
246 <input type="text" name="name" value="<?php echo __('New map', 'freeworld-html5-map'); ?>" />
247 <input type="submit" class="button button-primary" value="<?php echo __('Add new map', 'freeworld-html5-map'); ?>" />
248 <div style="display: none">
249 <input type="file" name="import_file" />
250 </div>
251 </fieldset>
252 </form>
253
254 <form action="admin.php?page=freeworld-html5-map-maps">
255 <input type="hidden" name="page" value="freeworld-html5-map-maps">
256 <?php $listtable->display(); ?>
257 </form>
258
259 <form name="action_form2" action="" method="POST" enctype="multipart/form-data" class="" style="margin-top: 20px;">
260 <fieldset>
261 <legend><?php echo __('Export/import', 'freeworld-html5-map') ?></legend>
262 <p><?php echo __('To export please select a checkbox of one or more maps, and press Export button', 'freeworld-html5-map'); ?></p>
263 <input type="button" class="button button-secondary export" value="<?php echo __('Export', 'freeworld-html5-map'); ?>" />
264 <input type="button" class="button button-secondary import" value="<?php echo __('Import', 'freeworld-html5-map'); ?>" />
265 </fieldset>
266 </form>
267
268 <?php if (current_user_can('manage_options')) { ?>
269
270 <form name="action_form3" action="" method="POST">
271 <?php wp_nonce_field('roles'); ?>
272 <fieldset>
273 <legend><?php echo __('Access rights to plugin settings', 'freeworld-html5-map') ?></legend>
274 <p><?php echo __('This option enables access to plug-in settings for users with the "Editor" role.', 'freeworld-html5-map'); ?></p>
275
276 <ul>
277 <li>
278 <p>
279 <input type="hidden" name="goptions[roles][editor]" value="0" />
280 <input type="checkbox" name="goptions[roles][editor]" value="1" id="role_editor" <?php echo (isset($goptions['roles']['editor']) and intval($goptions['roles']['editor'])) ? "checked" : ""; ?>/>
281 <label for="role_editor"><?php echo __('Editor', 'freeworld-html5-map') ?></label>
282 </p>
283 </li>
284 </ul>
285
286 <input type="submit" class="button button-primary" value="<?php echo __('Save', 'freeworld-html5-map'); ?>" />
287 </fieldset>
288 </form>
289
290 <?php } ?>
291
292 </div>
293 <div class="qanner">
294 <a href="https://www.fla-shop.com/products/wp-plugins/world/countries/?utm_source=world-map-plugin&utm_medium=dashboard&utm_campaign=qanner" target="_blank"><img src="<?php echo freeworld_html5map_plugin_get_static_url("html5maps_img.png") . "?r=".time();?>" border="0" width="161" height="601"></a>
295 </div>
296
297 <div class="clear"></div>
298
299 </div>
300
301 <script type="text/javascript">
302 jQuery(document).ready(function() {
303
304 /*jQuery('a.delete').click(function() {
305 if (confirm('<?php echo __('Remove the map?\nAttention! All settings for the map will be deleted permanently!', 'freeworld-html5-map'); ?>')) {
306 return true;
307 } else {
308 return false;
309 }
310 });*/
311
312 jQuery('.maps_toggle').click(function() {
313 jQuery('.map_checkbox,.maps_toggle').not(jQuery(this)).each(function() {
314 jQuery(this).prop('checked', !(jQuery(this).is(':checked')));
315 });
316 });
317
318 jQuery('input.export').click(function() {
319 if (!jQuery('.map_checkbox:checked').length) {
320 alert('<?php _e('Select maps you want to export first!', 'freeworld-html5-map') ?>');
321 return false;
322 }
323 jQuery('input[name=action]').val('freeworld-html5-map-export');
324
325 var maps = '';
326 jQuery('.map_checkbox:checked').each(function() {
327 if (maps!='') maps+=',';
328 maps+=jQuery(this).val();
329 });
330
331 jQuery('input[name=maps]').val(maps);
332
333 jQuery('form[name=action_form]').submit();
334 return false;
335 });
336
337 jQuery('input.import').click(function() {
338 jQuery('input[name=import_file]').click();
339 return false;
340 });
341 jQuery('.button-primary').click(function() {
342 jQuery('input[name=action]').val('new');
343 });
344
345 jQuery('input[name=import_file]').change(function() {
346 jQuery('input[name=action]').val('map_import');
347 jQuery('form[name=action_form]').submit();
348 });
349 });
350 </script>
351
352 <?php
353
354 ?>
355