class-shortcode-generator.php
15.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<?php
/**
* Shortcode Generator class
*
* @author Tijmen Smit
* @since 2.2.10
*/
if ( !defined( 'ABSPATH' ) ) exit;
if ( !class_exists( 'WPSL_Shortcode_Generator' ) ) {
/**
* Handle the generation of the WPSL shortcode through the media button
*
* @since 2.2.10
*/
class WPSL_Shortcode_Generator {
/**
* Constructor
*/
public function __construct() {
add_action( 'media_buttons', array( $this, 'add_wpsl_media_button' ) );
add_action( 'admin_init', array( $this, 'show_thickbox_iframe_content' ) );
}
/**
* Add the WPSL media button to the media button row
*
* @since 2.2.10
* @return void
*/
public function add_wpsl_media_button() {
global $pagenow, $typenow;
/* Make sure we're on a post/page or edit screen in the admin area */
if ( in_array( $pagenow, array( 'post.php', 'page.php', 'post-new.php', 'post-edit.php' ) ) && $typenow != 'wpsl_stores' ) {
$changelog_link = self_admin_url( '?wpsl_media_action=store_locator&KeepThis=true&TB_iframe=true&width=783&height=800' );
echo '<a href="' . esc_url( $changelog_link ) . '" class="thickbox button wpsl-thickbox" name="' . __( 'WP Store Locator' ,'wpsl' ) . '">' . __( 'Insert Store Locator', 'wpsl' ) . '</a>';
}
}
/**
* Show the shortcode thickbox content
*
* @since 2.2.10
* @return void
*/
function show_thickbox_iframe_content() {
global $wpsl_settings, $wpsl_admin;
if ( empty( $_REQUEST['wpsl_media_action'] ) ) {
return;
}
if ( !current_user_can( 'edit_pages' ) ) {
wp_die( __( 'You do not have permission to perform this action', 'wpsl' ), __( 'Error', 'wpsl' ), array( 'response' => 403 ) );
}
$min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
// Make sure the required JS / CSS files are loaded in the Thickbox iframe
wp_print_scripts( 'jquery-ui-core' );
wp_print_scripts( 'jquery-ui-tabs' );
wp_print_scripts( 'media-upload' );
?>
<script type="text/javascript" src="<?php echo plugins_url( '/js/wpsl-shortcode-generator' . $min . '.js?ver='. WPSL_VERSION_NUM .'', __FILE__ ); ?>"></script>
<?php
wp_print_styles('buttons' );
wp_print_styles('forms' );
?>
<link rel="stylesheet" type="text/css" href="<?php echo plugins_url( '/css/style' . $min . '.css?ver='. WPSL_VERSION_NUM .'', __FILE__ ); ?>" media="all" />
<style>
body {
color: #444;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 13px;
margin: 0;
}
#wpsl-media-tabs .ui-tabs-nav {
padding-left: 15px;
background: #fff !important;
border-bottom: 1px solid #dfdfdf;
border-collapse: collapse;
padding-top: .2em;
}
#wpsl-media-tabs .ui-tabs-nav::after {
clear: both;
content: "";
display: table;
border-collapse: collapse;
}
#wpsl-media-tabs .ui-tabs-nav li {
list-style: none;
float: left;
position: relative;
top: 0;
margin: 1px .2em 0 0;
padding: 0;
white-space: nowrap;
border-bottom-width: 0;
}
#wpsl-media-tabs .ui-tabs-anchor {
float: left;
padding: .5em 1em;
text-decoration: none;
font-size: 14.3px;
}
#wpsl-media-tabs .ui-tabs-active a {
color: #212121;
cursor: text;
}
#wpsl-media-tabs .ui-tabs .ui-tabs-anchor {
float: left;
padding: .5em 1em;
text-decoration: none;
}
#wpsl-media-tabs.ui-widget-content {
border: none;
padding: 10px 0 0 0;
}
#wpsl-media-tabs .ui-tabs-anchor {
outline: none;
}
#wpsl-shortcode-config tr > td {
width: 25%;
}
#wpsl-markers-tab .wpsl-marker-list {
display: block;
overflow: hidden;
padding: 0;
list-style-type: none;
}
#wpsl-markers-tab .wpsl-marker-list li input {
padding: 0;
margin: 0;
}
#wpsl-shortcode-config .form-table,
#wpsl-shortcode-config .form-table td,
#wpsl-shortcode-config .form-table th,
#wpsl-shortcode-config .form-table td p {
font-size: 13px;
}
#wpsl-shortcode-config .ui-tabs .ui-tabs-nav {
padding-left: 15px;
border-radius: 0;
margin: 0;
}
.wpsl-shortcode-markers {
padding: 0 10px;
margin-top: 27px;
font-size: 13px;
}
#wpsl-insert-shortcode {
margin-left: 19px;
}
#wpsl-shortcode-config .ui-state-default {
border: 1px solid #d3d3d3;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
background: none;
}
#wpsl-shortcode-config .ui-state-default a {
color: #909090;
}
#wpsl-shortcode-config .ui-state-default.ui-tabs-active a {
color: #212121;
}
#wpsl-shortcode-config .ui-state-hover {
border-bottom: none;
}
#wpsl-shortcode-config .ui-state-hover a {
color: #72777c;
}
#wpsl-media-tabs .ui-state-active {
border: 1px solid #aaa;
border-bottom: 1px solid #fff;
padding-bottom: 0;
}
#wpsl-shortcode-config li.ui-tabs-active.ui-state-hover,
#wpsl-shortcode-config li.ui-tabs-active {
border-bottom: 1px solid #fff;
padding-bottom: 0;
}
#wpsl-media-tabs li.ui-tabs-active {
margin-bottom: -1px;
}
#wpsl-general-tab,
#wpsl-markers-tab {
border: 0;
padding: 1em 1.4em;
background: none;
}
@media ( max-width: 782px ) {
#wpsl-shortcode-config tr > td {
width: 100%;
}
}
</style>
<div id="wpsl-shortcode-config" class="wp-core-ui">
<div id="wpsl-media-tabs">
<ul>
<li><a href="#wpsl-general-tab"><?php _e( 'General Options', 'wpsl' ); ?></a></li>
<li><a href="#wpsl-markers-tab"><?php _e('Markers', 'wpsl' ); ?></a></li>
</ul>
<div id="wpsl-general-tab">
<table class="form-table wpsl-shortcode-config">
<tbody>
<tr>
<td><label for="wpsl-store-template"><?php _e('Select the used template', 'wpsl' ); ?></label></td>
<td><?php echo $wpsl_admin->settings_page->show_template_options(); ?></td>
</tr>
<tr>
<td><label for="wpsl-start-location"><?php _e( 'Start point', 'wpsl' ); ?></label><span class="wpsl-info"><span class="wpsl-info-text wpsl-hide"><?php echo sprintf( __( 'If nothing it set, then the start point from the %ssettings%s page is used.', '' ), '<a href=' . admin_url( 'edit.php?post_type=wpsl_stores&page=wpsl_settings#wpsl-map-settings' ) . '>', '</a>' ); ?></span></span></p></td>
<td><input type="text" placeholder="Optional" value="" id="wpsl-start-location"></td>
</tr>
<tr>
<td>
<label for="wpsl-auto-locate"><?php _e( 'Attempt to auto-locate the user', 'wpsl' ); ?><span class="wpsl-info"><span class="wpsl-info-text wpsl-hide"><?php echo sprintf( __( 'Most modern browsers %srequire%s a HTTPS connection before the Geolocation feature works.', 'wpsl_csv' ), '<a href="https://wpstorelocator.co/document/html-5-geolocation-not-working/">', '</a>' ); ?></span></span></label>
</td>
<td><input type="checkbox" value="" <?php checked( $wpsl_settings['auto_locate'], true ); ?> name="wpsl_map[auto_locate]" id="wpsl-auto-locate"></td>
</tr>
<?php
$terms = get_terms( 'wpsl_store_category', 'hide_empty=1' );
if ( $terms ) {
?>
<tr>
<td><label for="wpsl-cat-filter-types"><?php _e( 'Category filter type', 'wpsl' ); ?></label></p></td>
<td>
<select id="wpsl-cat-filter-types" autocomplete="off">
<option value="" selected="selected"><?php _e( 'None', 'wpsl' ); ?></option>
<option value="dropdown"><?php _e( 'Dropdown', 'wpsl' ); ?></option>
<option value="checkboxes"><?php _e( 'Checkboxes', 'wpsl' ); ?></option>
</select>
</td>
</tr>
<tr class="wpsl-cat-restriction">
<td style="vertical-align:top;"><label for="wpsl-cat-restriction"><?php _e('Automatically restrict the returned results to one or more categories?', 'wpsl' ); ?></label></td>
<td>
<?php
$cat_restricton = '<select id="wpsl-cat-restriction" multiple="multiple" autocomplete="off">';
foreach ( $terms as $term ) {
$cat_restricton .= '<option value="' . esc_attr( $term->slug ) . '">' . esc_html( $term->name ) . '</option>';
}
$cat_restricton .= '</select>';
echo $cat_restricton;
?>
</td>
</tr>
<tr class="wpsl-cat-selection wpsl-hide">
<td style="vertical-align:top;"><label for="wpsl-cat-selection"><?php _e('Set a selected category?', 'wpsl' ); ?></label></td>
<td>
<?php
$cat_selection = '<select id="wpsl-cat-selection" autocomplete="off">';
$cat_selection .= '<option value="" selected="selected">' . __( 'Select category', 'wpsl' ) . '</option>';
foreach ( $terms as $term ) {
$cat_selection .= '<option value="' . esc_attr( $term->slug ) . '">' . esc_html( $term->name ) . '</option>';
}
$cat_selection .= '</select>';
echo $cat_selection;
?>
</td>
</tr>
<?php
}
?>
<tr class="wpsl-checkbox-options wpsl-hide">
<td><label for="wpsl-checkbox-columns"><?php _e('Checkbox columns', 'wpsl' ); ?></label></td>
<td>
<?php
echo '<select id="wpsl-checkbox-columns">';
$i = 1;
while ( $i <= 4 ) {
$selected = ( $i == 3 ) ? "selected='selected'" : ''; // 3 is the default
echo '<option value="' . $i . '" ' . $selected . '>' . $i . '</option>';
$i++;
}
echo '</select>';
?>
</td>
</tr>
<tr class="wpsl-checkbox-selection wpsl-hide">
<td><label for="wpsl-checkbox-columns"><?php _e('Set selected checkboxes', 'wpsl' ); ?></label></td>
<td>
<?php
$checkbox_selection = '<select id="wpsl-checkbox-selection" multiple="multiple" autocomplete="off">';
foreach ( $terms as $term ) {
$checkbox_selection .= '<option value="' . esc_attr( $term->slug ) . '">' . esc_html( $term->name ) . '</option>';
}
$checkbox_selection .= '</select>';
echo $checkbox_selection;
?>
</td>
</tr>
<tr>
<td><label for="wpsl-map-type"><?php _e( 'Map type', 'wpsl' ); ?>:</label></td>
<td><?php echo $wpsl_admin->settings_page->create_dropdown( 'map_types' ); ?></td>
</tr>
</tbody>
</table>
</div>
<div id="wpsl-markers-tab">
<div class="wpsl-shortcode-markers">
<?php echo $wpsl_admin->settings_page->show_marker_options(); ?>
</div>
</div>
</div>
<p class="submit">
<input type="button" id="wpsl-insert-shortcode" class="button-primary" value="<?php echo _e( 'Insert Store Locator', 'wpsl' ); ?>" onclick="WPSL_InsertShortcode();" />
</p>
</div>
<?php
exit();
}
}
new WPSL_Shortcode_Generator();
}