Header Footer Code Manager - Version 1.0.3

Version Description

2017-06-09 * Compatible with WordPress 4.8

Download this release

Release Info

Developer 99robots
Plugin Icon 128x128 Header Footer Code Manager
Version 1.0.3
Comparing to
See all releases

Code changes from version 1.0.2 to 1.0.3

99robots-header-footer-code-manager.php CHANGED
@@ -1,355 +1,362 @@
1
- <?php
2
-
3
- /*
4
- Plugin Name: Header Footer Code Manager
5
- Plugin URI: https://99robots.com/products
6
- Description: Header Footer Code Manager by 99 Robots is a quick and simple way for you to add tracking code snippets, conversion pixels, or other scripts required by third party services for analytics, tracking, marketing, or chat functions. For detailed documentation, please visit the plugin's <a href="https://99robots.com/"> official page</a>.
7
- Version: 1.0.2
8
- Author: 99robots
9
- Author URI: https://99robots.com/
10
- Disclaimer: Use at your own risk. No warranty expressed or implied is provided.
11
- Text Domain: 99robots-header-footer-code-manager
12
- Domain Path: /languages
13
- */
14
-
15
- global $hfcm_db_version;
16
- $hfcm_db_version = '1.0';
17
-
18
- // function to create the DB / Options / Defaults
19
- function hfcm_options_install() {
20
-
21
- global $wpdb;
22
- global $hfcm_db_version;
23
-
24
- $table_name = $wpdb->prefix . 'hfcm_scripts';
25
- $charset_collate = $wpdb->get_charset_collate();
26
- $sql =
27
- "CREATE TABLE IF NOT EXISTS $table_name(
28
- `script_id` int(10) NOT NULL AUTO_INCREMENT,
29
- `name` varchar(100) DEFAULT NULL,
30
- `snippet` text,
31
- `device_type` enum('mobile','desktop', 'both') DEFAULT 'both',
32
- `location` varchar(100) NOT NULL,
33
- `display_on` enum('All','s_pages', 's_posts','s_categories','s_custom_posts','s_tags','latest_posts','manual') NOT NULL DEFAULT 'All',
34
- `lp_count` int(10) DEFAULT NULL,
35
- `s_pages` varchar(300) DEFAULT NULL,
36
- `s_posts` varchar(1000) DEFAULT NULL,
37
- `s_custom_posts` varchar(300) DEFAULT NULL,
38
- `s_categories` varchar(300) DEFAULT NULL,
39
- `s_tags` varchar(300) DEFAULT NULL,
40
- `status` enum('active','inactive') NOT NULL DEFAULT 'active',
41
- `created_by` varchar(300) DEFAULT NULL,
42
- `last_modified_by` varchar(300) DEFAULT NULL,
43
- `created` datetime DEFAULT NULL,
44
- `last_revision_date` datetime DEFAULT NULL,
45
- PRIMARY KEY (`script_id`)
46
- ) $charset_collate; ";
47
-
48
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
49
- dbDelta( $sql );
50
-
51
- add_option( 'hfcm_db_version', $hfcm_db_version );
52
- }
53
-
54
- // run the install scripts upon plugin activation
55
- register_activation_hook( __FILE__, 'hfcm_options_install' );
56
-
57
- /*
58
- * register with hook 'admin_print_styles'
59
- */
60
- add_action( 'admin_enqueue_scripts', 'hfcm_enqueue_assets' );
61
-
62
- /*
63
- * Enqueue style-file, if it exists.
64
- */
65
-
66
- function hfcm_enqueue_assets( $hook ) {
67
- $allowed_pages = array(
68
- 'toplevel_page_hfcm-list',
69
- 'header-footer-code-manager_page_hfcm-create',
70
- 'admin_page_hfcm-update',
71
- );
72
-
73
- if ( in_array( $hook, $allowed_pages ) ) {
74
- // Plugin's CSS
75
- wp_register_style( 'hfcm_assets', plugins_url( 'css/style-admin.css', __FILE__ ) );
76
- wp_enqueue_style( 'hfcm_assets' );
77
- }
78
-
79
- // Remove hfcm-list from $allowed_pages
80
- array_shift( $allowed_pages );
81
-
82
- if ( in_array( $hook, $allowed_pages ) ) {
83
- // selectize.js plugin CSS and JS files
84
- wp_register_style( 'selectize-css', plugins_url( 'css/selectize.bootstrap3.css', __FILE__ ) );
85
- wp_enqueue_style( 'selectize-css' );
86
-
87
- wp_register_script( 'selectize-js', plugins_url( 'js/selectize.min.js', __FILE__ ), array('jquery') );
88
- wp_enqueue_script( 'selectize-js' );
89
- }
90
- }
91
-
92
- add_action( 'admin_menu', 'hfcm_modifymenu' );
93
-
94
- /*
95
- * This function loads plugins translation files
96
- */
97
-
98
- function hfcm_load_translation_files() {
99
- load_plugin_textdomain( '99robots-header-footer-code-manager', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
100
- }
101
-
102
- // Add action to load plugin files
103
- add_action( 'plugins_loaded', 'hfcm_load_translation_files' );
104
-
105
- // function to create menu page, and submenu pages.
106
- function hfcm_modifymenu() {
107
-
108
- //this is the main item for the menu
109
- add_menu_page( __( 'Header Footer Code Manager', '99robots-header-footer-code-manager' ), //page title
110
- __( 'Header Footer Code Manager', '99robots-header-footer-code-manager' ), //menu title
111
- 'manage_options', //capabilities
112
- 'hfcm-list', //menu slug
113
- 'hfcm_list', //function
114
- plugins_url( 'images/', __FILE__ ) . '99robots.png' );
115
- //this is a submenu
116
- add_submenu_page( 'hfcm-list', //parent slug
117
- __( 'All Snippets', '99robots-header-footer-code-manager' ), //page title
118
- __( 'All Snippets', '99robots-header-footer-code-manager' ), //menu title
119
- 'manage_options', //capability
120
- 'hfcm-list', //menu slug
121
- 'hfcm_list' ); //function
122
- //this is a submenu
123
- add_submenu_page( 'hfcm-list', //parent slug
124
- __( 'Add New Snippet', '99robots-header-footer-code-manager' ), //page title
125
- __( 'Add New', '99robots-header-footer-code-manager' ), //menu title
126
- 'manage_options', //capability
127
- 'hfcm-create', //menu slug
128
- 'hfcm_create' ); //function
129
- //this submenu is HIDDEN, however, we need to add it anyways
130
- add_submenu_page( null, //parent slug
131
- __( 'Update Script', '99robots-header-footer-code-manager' ), //page title
132
- __( 'Update', '99robots-header-footer-code-manager' ), //menu title
133
- 'manage_options', //capability
134
- 'hfcm-update', //menu slug
135
- 'hfcm_update' ); //function
136
- //this submenu is HIDDEN, however, we need to add it anyways
137
- add_submenu_page( null, //parent slug
138
- __( 'Request Handler Script', '99robots-header-footer-code-manager' ), //page title
139
- __( 'Request Handler', '99robots-header-footer-code-manager' ), //menu title
140
- 'manage_options', //capability
141
- 'hfcm-request-handler', //menu slug
142
- 'hfcm_request_handler' ); //function
143
- }
144
-
145
- // Files containing submenu functions
146
- require_once( plugin_dir_path( __FILE__ ) . 'includes/hfcm-list.php' );
147
- require_once( plugin_dir_path( __FILE__ ) . 'includes/hfcm-create.php' );
148
- require_once( plugin_dir_path( __FILE__ ) . 'includes/hfcm-update.php' );
149
- require_once( plugin_dir_path( __FILE__ ) . 'includes/hfcm-request-handler.php' );
150
-
151
- // Function to render the snippet
152
- function hfcm_render_snippet( $scriptdata ) {
153
- $output = "<!-- HFCM by 99 Robots - Snippet # {$scriptdata->script_id}: {$scriptdata->name} -->\n{$scriptdata->snippet}\n<!-- /end HFCM by 99 Robots -->\n";
154
-
155
- return $output;
156
- }
157
-
158
- // Function to implement shortcode
159
- function hfcm_shortcode( $atts ) {
160
- global $wpdb;
161
- $table_name = $wpdb->prefix . 'hfcm_scripts';
162
- if ( !empty( $atts['id'] ) ) {
163
- $id = (int) $atts['id'];
164
- $hide_device = wp_is_mobile() ? 'desktop' : 'mobile';
165
- $script = $wpdb->get_results( $wpdb->prepare( "SELECT * from $table_name where status='active' AND device_type!='$hide_device' AND script_id=%s", $id ) );
166
- if ( !empty( $script ) ) {
167
- return hfcm_render_snippet( $script[0] );
168
- }
169
- }
170
- }
171
-
172
- // Function to json_decode array and check if empty
173
- function hfcm_not_empty( $scriptdata, $prop_name ) {
174
- $data = json_decode( $scriptdata->{$prop_name} );
175
- if ( empty( $data ) ) {
176
- return false;
177
- }
178
- return true;
179
- }
180
-
181
- add_shortcode( 'hfcm', 'hfcm_shortcode' );
182
-
183
- // Function to decide which snippets to show - triggered by hooks
184
- function hfcm_add_snippets( $location = '', $content = '' ) {
185
- global $wpdb;
186
-
187
- $beforecontent = '';
188
- $aftercontent = '';
189
-
190
- if ( $location && in_array( $location, array( 'header', 'footer' ) ) ) {
191
- $display_location = "location='$location'";
192
- } else {
193
- $display_location = "location NOT IN ( 'header', 'footer' )";
194
- }
195
-
196
- $table_name = $wpdb->prefix . "hfcm_scripts";
197
- $hide_device = wp_is_mobile() ? 'desktop' : 'mobile';
198
- $script = $wpdb->get_results( "SELECT * from $table_name where $display_location AND status='active' AND device_type!='$hide_device'" );
199
-
200
- if ( !empty( $script ) ) {
201
- foreach ( $script as $key => $scriptdata ) {
202
- $out = '';
203
- switch ( $scriptdata->display_on ) {
204
- case 'All':
205
- $out = hfcm_render_snippet( $scriptdata );
206
- break;
207
- case 'latest_posts':
208
- if ( is_single() ) {
209
- $args = array(
210
- 'public' => true,
211
- '_builtin' => false
212
- );
213
- $output = 'names'; // names or objects, note names is the default
214
- $operator = 'and'; // 'and' or 'or'
215
- $c_posttypes = get_post_types( $args, $output, $operator );
216
- $posttypes = array(
217
- "post"
218
- );
219
- foreach ( $c_posttypes as $cpkey => $cpdata ) {
220
- $posttypes[] = $cpdata;
221
- }
222
- if ( !empty( $scriptdata->lp_count ) ) {
223
- $latestposts = wp_get_recent_posts( array(
224
- "numberposts" => $scriptdata->lp_count,
225
- "post_type" => $posttypes
226
- ) );
227
- } else {
228
- $latestposts = wp_get_recent_posts( array(
229
- "post_type" => $posttypes
230
- ) );
231
- }
232
-
233
- $islatest = false;
234
- foreach ( $latestposts as $key => $lpostdata ) {
235
- if ( get_the_ID() == $lpostdata['ID'] ) {
236
- $islatest = true;
237
- }
238
- }
239
- if ( $islatest ) {
240
- $out = hfcm_render_snippet( $scriptdata );
241
- }
242
- }
243
- break;
244
- case 's_categories':
245
- if ( hfcm_not_empty( $scriptdata, 's_categories' ) && in_category( json_decode( $scriptdata->s_categories ) ) ) {
246
- $out = hfcm_render_snippet( $scriptdata );
247
- }
248
- break;
249
- case 's_custom_posts':
250
- if ( hfcm_not_empty( $scriptdata, 's_custom_posts' ) && is_singular( json_decode( $scriptdata->s_custom_posts ) ) ) {
251
- $out = hfcm_render_snippet( $scriptdata );
252
- }
253
- break;
254
- case 's_posts':
255
- if ( hfcm_not_empty( $scriptdata, 's_posts' ) && is_single( json_decode( $scriptdata->s_posts ) ) ) {
256
- $out = hfcm_render_snippet( $scriptdata );
257
- }
258
- break;
259
- case 's_pages':
260
- if ( hfcm_not_empty( $scriptdata, 's_pages' ) && is_page( json_decode( $scriptdata->s_pages ) ) ) {
261
- $out = hfcm_render_snippet( $scriptdata );
262
- }
263
- break;
264
- case 's_tags':
265
- if ( hfcm_not_empty( $scriptdata, 's_tags' ) && has_tag( json_decode( $scriptdata->s_tags ) ) ) {
266
- $out = hfcm_render_snippet( $scriptdata );
267
- }
268
- }
269
-
270
- switch ( $scriptdata->location ) {
271
- case 'before_content':
272
- $beforecontent .= $out;
273
- break;
274
- case 'after_content':
275
- $aftercontent .= $out;
276
- break;
277
- default:
278
- echo $out;
279
- }
280
- }
281
- }
282
- // Return results after the loop finishes
283
- return $beforecontent . $content . $aftercontent;
284
- }
285
-
286
- add_action( 'wp_head', 'hfcm_header_scripts' );
287
-
288
- // Function to add snippets in the header
289
- function hfcm_header_scripts() {
290
- hfcm_add_snippets( 'header' );
291
- }
292
-
293
- add_action( 'wp_footer', 'hfcm_footer_scripts' );
294
-
295
- // Function to add snippets in the footer
296
- function hfcm_footer_scripts() {
297
- hfcm_add_snippets( 'footer' );
298
- }
299
-
300
- add_action( 'the_content', 'hfcm_content_scripts' );
301
-
302
- // Function to add snippets before/after the content
303
- function hfcm_content_scripts( $content ) {
304
- return hfcm_add_snippets( false, $content );
305
- }
306
-
307
- // Load redirection Javascript code
308
- function hfcm_redirect( $url = '' ) {
309
- // Register the script
310
- wp_register_script( 'hfcm_redirection', plugins_url( 'js/location.js', __FILE__ ) );
311
-
312
- // Localize the script with new data
313
- $translation_array = array(
314
- 'url' => $url
315
- );
316
- wp_localize_script( 'hfcm_redirection', 'hfcm_location', $translation_array );
317
-
318
- // Enqueued script with localized data.
319
- wp_enqueue_script( 'hfcm_redirection' );
320
- }
321
-
322
- // Handle AJAX requests
323
- add_action( 'wp_ajax_hfcm-request', 'hfcm_request_handler' );
324
-
325
- // Function to sanitize POST data
326
- function hfcm_sanitize_text( $key, $sanitize = true ) {
327
- if ( !empty( $_POST['data'][$key] ) ) {
328
- $out = stripslashes_deep( $_POST['data'][$key] );
329
- if ($sanitize) {
330
- $out = sanitize_text_field( $out );
331
- }
332
- return $out;
333
- }
334
- return '';
335
- }
336
-
337
- // Function to sanitize strings within POST data arrays
338
- function hfcm_sanitize_array( $key, $type = 'integer' ) {
339
- if ( !empty( $_POST['data'][$key] ) ) {
340
- $arr = $_POST['data'][$key];
341
- if ( !is_array( $arr ) ) {
342
- return array();
343
- }
344
- if ( 'integer' === $type ) {
345
- return array_map( 'absint', $arr );
346
- } else { // strings
347
- $new_array = array();
348
- foreach ($arr as $val) {
349
- $new_array[] = sanitize_text_field( $val );
350
- }
351
- }
352
- return $new_array;
353
- }
354
- return array();
355
- }
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: Header Footer Code Manager
4
+ * Plugin URI: https://99robots.com/products
5
+ * Description: Header Footer Code Manager by 99 Robots is a quick and simple way for you to add tracking code snippets, conversion pixels, or other scripts required by third party services for analytics, tracking, marketing, or chat functions. For detailed documentation, please visit the plugin's <a href="https://99robots.com/"> official page</a>.
6
+ * Version: 1.0.3
7
+ * Author: 99robots
8
+ * Author URI: https://99robots.com/
9
+ * Disclaimer: Use at your own risk. No warranty expressed or implied is provided.
10
+ * Text Domain: 99robots-header-footer-code-manager
11
+ * Domain Path: /languages
12
+ */
13
+
14
+ // If this file is called directly, abort.
15
+ if ( ! defined( 'WPINC' ) ) {
16
+ die;
17
+ }
18
+
19
+ global $hfcm_db_version;
20
+ $hfcm_db_version = '1.0';
21
+
22
+ // function to create the DB / Options / Defaults
23
+ function hfcm_options_install() {
24
+
25
+ global $wpdb;
26
+ global $hfcm_db_version;
27
+
28
+ $table_name = $wpdb->prefix . 'hfcm_scripts';
29
+ $charset_collate = $wpdb->get_charset_collate();
30
+ $sql =
31
+ "CREATE TABLE IF NOT EXISTS $table_name(
32
+ `script_id` int(10) NOT NULL AUTO_INCREMENT,
33
+ `name` varchar(100) DEFAULT NULL,
34
+ `snippet` text,
35
+ `device_type` enum('mobile','desktop', 'both') DEFAULT 'both',
36
+ `location` varchar(100) NOT NULL,
37
+ `display_on` enum('All','s_pages', 's_posts','s_categories','s_custom_posts','s_tags','latest_posts','manual') NOT NULL DEFAULT 'All',
38
+ `lp_count` int(10) DEFAULT NULL,
39
+ `s_pages` varchar(300) DEFAULT NULL,
40
+ `s_posts` varchar(1000) DEFAULT NULL,
41
+ `s_custom_posts` varchar(300) DEFAULT NULL,
42
+ `s_categories` varchar(300) DEFAULT NULL,
43
+ `s_tags` varchar(300) DEFAULT NULL,
44
+ `status` enum('active','inactive') NOT NULL DEFAULT 'active',
45
+ `created_by` varchar(300) DEFAULT NULL,
46
+ `last_modified_by` varchar(300) DEFAULT NULL,
47
+ `created` datetime DEFAULT NULL,
48
+ `last_revision_date` datetime DEFAULT NULL,
49
+ PRIMARY KEY (`script_id`)
50
+ ) $charset_collate; ";
51
+
52
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
53
+ dbDelta( $sql );
54
+
55
+ add_option( 'hfcm_db_version', $hfcm_db_version );
56
+ }
57
+ register_activation_hook( __FILE__, 'hfcm_options_install' );
58
+
59
+ /*
60
+ * Enqueue style-file, if it exists.
61
+ */
62
+ function hfcm_enqueue_assets( $hook ) {
63
+
64
+ $allowed_pages = array(
65
+ 'toplevel_page_hfcm-list',
66
+ 'header-footer-code-manager_page_hfcm-create',
67
+ 'admin_page_hfcm-update',
68
+ );
69
+
70
+ if ( in_array( $hook, $allowed_pages ) ) {
71
+ // Plugin's CSS
72
+ wp_register_style( 'hfcm_assets', plugins_url( 'css/style-admin.css', __FILE__ ) );
73
+ wp_enqueue_style( 'hfcm_assets' );
74
+ }
75
+
76
+ // Remove hfcm-list from $allowed_pages
77
+ array_shift( $allowed_pages );
78
+
79
+ if ( in_array( $hook, $allowed_pages ) ) {
80
+ // selectize.js plugin CSS and JS files
81
+ wp_register_style( 'selectize-css', plugins_url( 'css/selectize.bootstrap3.css', __FILE__ ) );
82
+ wp_enqueue_style( 'selectize-css' );
83
+
84
+ wp_register_script( 'selectize-js', plugins_url( 'js/selectize.min.js', __FILE__ ), array( 'jquery' ) );
85
+ wp_enqueue_script( 'selectize-js' );
86
+ }
87
+ }
88
+ add_action( 'admin_enqueue_scripts', 'hfcm_enqueue_assets' );
89
+
90
+ /*
91
+ * This function loads plugins translation files
92
+ */
93
+ function hfcm_load_translation_files() {
94
+ load_plugin_textdomain( '99robots-header-footer-code-manager', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
95
+ }
96
+ add_action( 'plugins_loaded', 'hfcm_load_translation_files' );
97
+
98
+ // function to create menu page, and submenu pages.
99
+ function hfcm_modifymenu() {
100
+
101
+ // This is the main item for the menu
102
+ add_menu_page(
103
+ __( 'Header Footer Code Manager', '99robots-header-footer-code-manager' ),
104
+ __( 'HFCM', '99robots-header-footer-code-manager' ),
105
+ 'manage_options',
106
+ 'hfcm-list',
107
+ 'hfcm_list',
108
+ plugins_url( 'images/', __FILE__ ) . '99robots.png'
109
+ );
110
+
111
+ // This is a submenu
112
+ add_submenu_page(
113
+ 'hfcm-list',
114
+ __( 'All Snippets', '99robots-header-footer-code-manager' ),
115
+ __( 'All Snippets', '99robots-header-footer-code-manager' ),
116
+ 'manage_options',
117
+ 'hfcm-list',
118
+ 'hfcm_list'
119
+ );
120
+
121
+ // This is a submenu
122
+ add_submenu_page(
123
+ 'hfcm-list',
124
+ __( 'Add New Snippet', '99robots-header-footer-code-manager' ),
125
+ __( 'Add New', '99robots-header-footer-code-manager' ),
126
+ 'manage_options',
127
+ 'hfcm-create',
128
+ 'hfcm_create'
129
+ );
130
+
131
+ // This submenu is HIDDEN, however, we need to add it anyways
132
+ add_submenu_page(
133
+ null,
134
+ __( 'Update Script', '99robots-header-footer-code-manager' ),
135
+ __( 'Update', '99robots-header-footer-code-manager' ),
136
+ 'manage_options',
137
+ 'hfcm-update',
138
+ 'hfcm_update'
139
+ );
140
+
141
+ // This submenu is HIDDEN, however, we need to add it anyways
142
+ add_submenu_page(
143
+ null,
144
+ __( 'Request Handler Script', '99robots-header-footer-code-manager' ),
145
+ __( 'Request Handler', '99robots-header-footer-code-manager' ),
146
+ 'manage_options',
147
+ 'hfcm-request-handler',
148
+ 'hfcm_request_handler'
149
+ );
150
+ }
151
+ add_action( 'admin_menu', 'hfcm_modifymenu' );
152
+
153
+ // Files containing submenu functions
154
+ require_once( plugin_dir_path( __FILE__ ) . 'includes/hfcm-list.php' );
155
+ require_once( plugin_dir_path( __FILE__ ) . 'includes/hfcm-create.php' );
156
+ require_once( plugin_dir_path( __FILE__ ) . 'includes/hfcm-update.php' );
157
+ require_once( plugin_dir_path( __FILE__ ) . 'includes/hfcm-request-handler.php' );
158
+
159
+ // Function to render the snippet
160
+ function hfcm_render_snippet( $scriptdata ) {
161
+ $output = "<!-- HFCM by 99 Robots - Snippet # {$scriptdata->script_id}: {$scriptdata->name} -->\n{$scriptdata->snippet}\n<!-- /end HFCM by 99 Robots -->\n";
162
+
163
+ return $output;
164
+ }
165
+
166
+ // Function to implement shortcode
167
+ function hfcm_shortcode( $atts ) {
168
+ global $wpdb;
169
+ $table_name = $wpdb->prefix . 'hfcm_scripts';
170
+ if ( ! empty( $atts['id'] ) ) {
171
+ $id = (int) $atts['id'];
172
+ $hide_device = wp_is_mobile() ? 'desktop' : 'mobile';
173
+ $script = $wpdb->get_results( $wpdb->prepare( "SELECT * from $table_name where status='active' AND device_type!='$hide_device' AND script_id=%s", $id ) );
174
+ if ( ! empty( $script ) ) {
175
+ return hfcm_render_snippet( $script[0] );
176
+ }
177
+ }
178
+ }
179
+ add_shortcode( 'hfcm', 'hfcm_shortcode' );
180
+
181
+ // Function to json_decode array and check if empty
182
+ function hfcm_not_empty( $scriptdata, $prop_name ) {
183
+ $data = json_decode( $scriptdata->{$prop_name} );
184
+ if ( empty( $data ) ) {
185
+ return false;
186
+ }
187
+ return true;
188
+ }
189
+
190
+ // Function to decide which snippets to show - triggered by hooks
191
+ function hfcm_add_snippets( $location = '', $content = '' ) {
192
+ global $wpdb;
193
+
194
+ $beforecontent = '';
195
+ $aftercontent = '';
196
+
197
+ if ( $location && in_array( $location, array( 'header', 'footer' ) ) ) {
198
+ $display_location = "location='$location'";
199
+ } else {
200
+ $display_location = "location NOT IN ( 'header', 'footer' )";
201
+ }
202
+
203
+ $table_name = $wpdb->prefix . 'hfcm_scripts';
204
+ $hide_device = wp_is_mobile() ? 'desktop' : 'mobile';
205
+ $script = $wpdb->get_results( "SELECT * from $table_name where $display_location AND status='active' AND device_type!='$hide_device'" );
206
+
207
+ if ( ! empty( $script ) ) {
208
+ foreach ( $script as $key => $scriptdata ) {
209
+ $out = '';
210
+ switch ( $scriptdata->display_on ) {
211
+ case 'All':
212
+ $out = hfcm_render_snippet( $scriptdata );
213
+ break;
214
+ case 'latest_posts':
215
+ if ( is_single() ) {
216
+ $args = array(
217
+ 'public' => true,
218
+ '_builtin' => false,
219
+ );
220
+ $output = 'names'; // names or objects, note names is the default
221
+ $operator = 'and'; // 'and' or 'or'
222
+ $c_posttypes = get_post_types( $args, $output, $operator );
223
+ $posttypes = array( 'post' );
224
+ foreach ( $c_posttypes as $cpkey => $cpdata ) {
225
+ $posttypes[] = $cpdata;
226
+ }
227
+ if ( ! empty( $scriptdata->lp_count ) ) {
228
+ $latestposts = wp_get_recent_posts( array(
229
+ 'numberposts' => $scriptdata->lp_count,
230
+ 'post_type' => $posttypes,
231
+ ) );
232
+ } else {
233
+ $latestposts = wp_get_recent_posts( array( 'post_type' => $posttypes ) );
234
+ }
235
+
236
+ $islatest = false;
237
+ foreach ( $latestposts as $key => $lpostdata ) {
238
+ if ( get_the_ID() == $lpostdata['ID'] ) {
239
+ $islatest = true;
240
+ }
241
+ }
242
+
243
+ if ( $islatest ) {
244
+ $out = hfcm_render_snippet( $scriptdata );
245
+ }
246
+ }
247
+ break;
248
+ case 's_categories':
249
+ if ( hfcm_not_empty( $scriptdata, 's_categories' ) && in_category( json_decode( $scriptdata->s_categories ) ) ) {
250
+ $out = hfcm_render_snippet( $scriptdata );
251
+ }
252
+ break;
253
+ case 's_custom_posts':
254
+ if ( hfcm_not_empty( $scriptdata, 's_custom_posts' ) && is_singular( json_decode( $scriptdata->s_custom_posts ) ) ) {
255
+ $out = hfcm_render_snippet( $scriptdata );
256
+ }
257
+ break;
258
+ case 's_posts':
259
+ if ( hfcm_not_empty( $scriptdata, 's_posts' ) && is_single( json_decode( $scriptdata->s_posts ) ) ) {
260
+ $out = hfcm_render_snippet( $scriptdata );
261
+ }
262
+ break;
263
+ case 's_pages':
264
+ if ( hfcm_not_empty( $scriptdata, 's_pages' ) && is_page( json_decode( $scriptdata->s_pages ) ) ) {
265
+ $out = hfcm_render_snippet( $scriptdata );
266
+ }
267
+ break;
268
+ case 's_tags':
269
+ if ( hfcm_not_empty( $scriptdata, 's_tags' ) && has_tag( json_decode( $scriptdata->s_tags ) ) ) {
270
+ $out = hfcm_render_snippet( $scriptdata );
271
+ }
272
+ }
273
+
274
+ switch ( $scriptdata->location ) {
275
+ case 'before_content':
276
+ $beforecontent .= $out;
277
+ break;
278
+ case 'after_content':
279
+ $aftercontent .= $out;
280
+ break;
281
+ default:
282
+ echo $out;
283
+ }
284
+ }
285
+ }
286
+ // Return results after the loop finishes
287
+ return $beforecontent . $content . $aftercontent;
288
+ }
289
+
290
+ // Function to add snippets in the header
291
+ function hfcm_header_scripts() {
292
+ hfcm_add_snippets( 'header' );
293
+ }
294
+ add_action( 'wp_head', 'hfcm_header_scripts' );
295
+
296
+ // Function to add snippets in the footer
297
+ function hfcm_footer_scripts() {
298
+ hfcm_add_snippets( 'footer' );
299
+ }
300
+ add_action( 'wp_footer', 'hfcm_footer_scripts' );
301
+
302
+
303
+ // Function to add snippets before/after the content
304
+ function hfcm_content_scripts( $content ) {
305
+ return hfcm_add_snippets( false, $content );
306
+ }
307
+ add_action( 'the_content', 'hfcm_content_scripts' );
308
+
309
+ // Load redirection Javascript code
310
+ function hfcm_redirect( $url = '' ) {
311
+ // Register the script
312
+ wp_register_script( 'hfcm_redirection', plugins_url( 'js/location.js', __FILE__ ) );
313
+
314
+ // Localize the script with new data
315
+ $translation_array = array( 'url' => $url );
316
+ wp_localize_script( 'hfcm_redirection', 'hfcm_location', $translation_array );
317
+
318
+ // Enqueued script with localized data.
319
+ wp_enqueue_script( 'hfcm_redirection' );
320
+ }
321
+
322
+ // Handle AJAX requests
323
+ add_action( 'wp_ajax_hfcm-request', 'hfcm_request_handler' );
324
+
325
+ // Function to sanitize POST data
326
+ function hfcm_sanitize_text( $key, $sanitize = true ) {
327
+
328
+ if ( ! empty( $_POST['data'][ $key ] ) ) {
329
+ $out = stripslashes_deep( $_POST['data'][ $key ] );
330
+ if ( $sanitize ) {
331
+ $out = sanitize_text_field( $out );
332
+ }
333
+ return $out;
334
+ }
335
+
336
+ return '';
337
+ }
338
+
339
+ // Function to sanitize strings within POST data arrays
340
+ function hfcm_sanitize_array( $key, $type = 'integer' ) {
341
+ if ( ! empty( $_POST['data'][ $key ] ) ) {
342
+
343
+ $arr = $_POST['data'][ $key ];
344
+
345
+ if ( ! is_array( $arr ) ) {
346
+ return array();
347
+ }
348
+
349
+ if ( 'integer' === $type ) {
350
+ return array_map( 'absint', $arr );
351
+ } else { // strings
352
+ $new_array = array();
353
+ foreach ( $arr as $val ) {
354
+ $new_array[] = sanitize_text_field( $val );
355
+ }
356
+ }
357
+
358
+ return $new_array;
359
+ }
360
+
361
+ return array();
362
+ }
css/selectize.bootstrap3.css CHANGED
@@ -1,401 +1,401 @@
1
- /**
2
- * selectize.bootstrap3.css (v0.12.1) - Bootstrap 3 Theme
3
- * Copyright (c) 2013–2015 Brian Reavis & contributors
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6
- * file except in compliance with the License. You may obtain a copy of the License at:
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software distributed under
10
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
- * ANY KIND, either express or implied. See the License for the specific language
12
- * governing permissions and limitations under the License.
13
- *
14
- * @author Brian Reavis <brian@thirdroute.com>
15
- */
16
- .selectize-control.plugin-drag_drop.multi > .selectize-input > div.ui-sortable-placeholder {
17
- visibility: visible !important;
18
- background: #f2f2f2 !important;
19
- background: rgba(0, 0, 0, 0.06) !important;
20
- border: 0 none !important;
21
- -webkit-box-shadow: inset 0 0 12px 4px #ffffff;
22
- box-shadow: inset 0 0 12px 4px #ffffff;
23
- }
24
- .selectize-control.plugin-drag_drop .ui-sortable-placeholder::after {
25
- content: '!';
26
- visibility: hidden;
27
- }
28
- .selectize-control.plugin-drag_drop .ui-sortable-helper {
29
- -webkit-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
30
- box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
31
- }
32
- .selectize-dropdown-header {
33
- position: relative;
34
- padding: 3px 12px;
35
- border-bottom: 1px solid #d0d0d0;
36
- background: #f8f8f8;
37
- -webkit-border-radius: 4px 4px 0 0;
38
- -moz-border-radius: 4px 4px 0 0;
39
- border-radius: 4px 4px 0 0;
40
- }
41
- .selectize-dropdown-header-close {
42
- position: absolute;
43
- right: 12px;
44
- top: 50%;
45
- color: #333333;
46
- opacity: 0.4;
47
- margin-top: -12px;
48
- line-height: 20px;
49
- font-size: 20px !important;
50
- }
51
- .selectize-dropdown-header-close:hover {
52
- color: #000000;
53
- }
54
- .selectize-dropdown.plugin-optgroup_columns .optgroup {
55
- border-right: 1px solid #f2f2f2;
56
- border-top: 0 none;
57
- float: left;
58
- -webkit-box-sizing: border-box;
59
- -moz-box-sizing: border-box;
60
- box-sizing: border-box;
61
- }
62
- .selectize-dropdown.plugin-optgroup_columns .optgroup:last-child {
63
- border-right: 0 none;
64
- }
65
- .selectize-dropdown.plugin-optgroup_columns .optgroup:before {
66
- display: none;
67
- }
68
- .selectize-dropdown.plugin-optgroup_columns .optgroup-header {
69
- border-top: 0 none;
70
- }
71
- .selectize-control.plugin-remove_button [data-value] {
72
- position: relative;
73
- padding-right: 24px !important;
74
- }
75
- .selectize-control.plugin-remove_button [data-value] .remove {
76
- z-index: 1;
77
- /* fixes ie bug (see #392) */
78
- position: absolute;
79
- top: 0;
80
- right: 0;
81
- bottom: 0;
82
- width: 17px;
83
- text-align: center;
84
- font-weight: bold;
85
- font-size: 12px;
86
- color: inherit;
87
- text-decoration: none;
88
- vertical-align: middle;
89
- display: inline-block;
90
- padding: 1px 0 0 0;
91
- border-left: 1px solid rgba(0, 0, 0, 0);
92
- -webkit-border-radius: 0 2px 2px 0;
93
- -moz-border-radius: 0 2px 2px 0;
94
- border-radius: 0 2px 2px 0;
95
- -webkit-box-sizing: border-box;
96
- -moz-box-sizing: border-box;
97
- box-sizing: border-box;
98
- }
99
- .selectize-control.plugin-remove_button [data-value] .remove:hover {
100
- background: rgba(0, 0, 0, 0.05);
101
- }
102
- .selectize-control.plugin-remove_button [data-value].active .remove {
103
- border-left-color: rgba(0, 0, 0, 0);
104
- }
105
- .selectize-control.plugin-remove_button .disabled [data-value] .remove:hover {
106
- background: none;
107
- }
108
- .selectize-control.plugin-remove_button .disabled [data-value] .remove {
109
- border-left-color: rgba(77, 77, 77, 0);
110
- }
111
- .selectize-control {
112
- position: relative;
113
- }
114
- .selectize-dropdown,
115
- .selectize-input,
116
- .selectize-input input {
117
- color: #333333;
118
- font-family: inherit;
119
- font-size: inherit;
120
- line-height: 20px;
121
- -webkit-font-smoothing: inherit;
122
- }
123
- .selectize-input,
124
- .selectize-control.single .selectize-input.input-active {
125
- background: #ffffff;
126
- cursor: text;
127
- display: inline-block;
128
- }
129
- .selectize-input {
130
- border: 1px solid #cccccc;
131
- padding: 6px 12px;
132
- display: inline-block;
133
- width: 100%;
134
- overflow: hidden;
135
- position: relative;
136
- z-index: 1;
137
- -webkit-box-sizing: border-box;
138
- -moz-box-sizing: border-box;
139
- box-sizing: border-box;
140
- -webkit-box-shadow: none;
141
- box-shadow: none;
142
- -webkit-border-radius: 4px;
143
- -moz-border-radius: 4px;
144
- border-radius: 4px;
145
- }
146
- .selectize-control.multi .selectize-input.has-items {
147
- padding: 5px 12px 2px;
148
- }
149
- .selectize-input.full {
150
- background-color: #ffffff;
151
- }
152
- .selectize-input.disabled,
153
- .selectize-input.disabled * {
154
- cursor: default !important;
155
- }
156
- .selectize-input.focus {
157
- -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
158
- box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
159
- }
160
- .selectize-input.dropdown-active {
161
- -webkit-border-radius: 4px 4px 0 0;
162
- -moz-border-radius: 4px 4px 0 0;
163
- border-radius: 4px 4px 0 0;
164
- }
165
- .selectize-input > * {
166
- vertical-align: baseline;
167
- display: -moz-inline-stack;
168
- display: inline-block;
169
- zoom: 1;
170
- *display: inline;
171
- }
172
- .selectize-control.multi .selectize-input > div {
173
- cursor: pointer;
174
- margin: 0 3px 3px 0;
175
- padding: 1px 3px;
176
- background: #efefef;
177
- color: #333333;
178
- border: 0 solid rgba(0, 0, 0, 0);
179
- }
180
- .selectize-control.multi .selectize-input > div.active {
181
- background: #428bca;
182
- color: #ffffff;
183
- border: 0 solid rgba(0, 0, 0, 0);
184
- }
185
- .selectize-control.multi .selectize-input.disabled > div,
186
- .selectize-control.multi .selectize-input.disabled > div.active {
187
- color: #808080;
188
- background: #ffffff;
189
- border: 0 solid rgba(77, 77, 77, 0);
190
- }
191
- .selectize-input > input {
192
- display: inline-block !important;
193
- padding: 0 !important;
194
- min-height: 0 !important;
195
- max-height: none !important;
196
- max-width: 100% !important;
197
- margin: 0 !important;
198
- text-indent: 0 !important;
199
- border: 0 none !important;
200
- background: none !important;
201
- line-height: inherit !important;
202
- -webkit-user-select: auto !important;
203
- -webkit-box-shadow: none !important;
204
- box-shadow: none !important;
205
- }
206
- .selectize-input > input::-ms-clear {
207
- display: none;
208
- }
209
- .selectize-input > input:focus {
210
- outline: none !important;
211
- }
212
- .selectize-input::after {
213
- content: ' ';
214
- display: block;
215
- clear: left;
216
- }
217
- .selectize-input.dropdown-active::before {
218
- content: ' ';
219
- display: block;
220
- position: absolute;
221
- background: #ffffff;
222
- height: 1px;
223
- bottom: 0;
224
- left: 0;
225
- right: 0;
226
- }
227
- .selectize-dropdown {
228
- position: absolute;
229
- z-index: 10;
230
- border: 1px solid #d0d0d0;
231
- background: #ffffff;
232
- margin: -1px 0 0 0;
233
- border-top: 0 none;
234
- -webkit-box-sizing: border-box;
235
- -moz-box-sizing: border-box;
236
- box-sizing: border-box;
237
- -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
238
- box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
239
- -webkit-border-radius: 0 0 4px 4px;
240
- -moz-border-radius: 0 0 4px 4px;
241
- border-radius: 0 0 4px 4px;
242
- }
243
- .selectize-dropdown [data-selectable] {
244
- cursor: pointer;
245
- overflow: hidden;
246
- }
247
- .selectize-dropdown [data-selectable] .highlight {
248
- background: rgba(255, 237, 40, 0.4);
249
- -webkit-border-radius: 1px;
250
- -moz-border-radius: 1px;
251
- border-radius: 1px;
252
- }
253
- .selectize-dropdown [data-selectable],
254
- .selectize-dropdown .optgroup-header {
255
- padding: 3px 12px;
256
- }
257
- .selectize-dropdown .optgroup:first-child .optgroup-header {
258
- border-top: 0 none;
259
- }
260
- .selectize-dropdown .optgroup-header {
261
- color: #777777;
262
- background: #ffffff;
263
- cursor: default;
264
- }
265
- .selectize-dropdown .active {
266
- background-color: #f5f5f5;
267
- color: #262626;
268
- }
269
- .selectize-dropdown .active.create {
270
- color: #262626;
271
- }
272
- .selectize-dropdown .create {
273
- color: rgba(51, 51, 51, 0.5);
274
- }
275
- .selectize-dropdown-content {
276
- overflow-y: auto;
277
- overflow-x: hidden;
278
- max-height: 200px;
279
- }
280
- .selectize-control.single .selectize-input,
281
- .selectize-control.single .selectize-input input {
282
- cursor: pointer;
283
- }
284
- .selectize-control.single .selectize-input.input-active,
285
- .selectize-control.single .selectize-input.input-active input {
286
- cursor: text;
287
- }
288
- .selectize-control.single .selectize-input:after {
289
- content: ' ';
290
- display: block;
291
- position: absolute;
292
- top: 50%;
293
- right: 17px;
294
- margin-top: -3px;
295
- width: 0;
296
- height: 0;
297
- border-style: solid;
298
- border-width: 5px 5px 0 5px;
299
- border-color: #333333 transparent transparent transparent;
300
- }
301
- .selectize-control.single .selectize-input.dropdown-active:after {
302
- margin-top: -4px;
303
- border-width: 0 5px 5px 5px;
304
- border-color: transparent transparent #333333 transparent;
305
- }
306
- .selectize-control.rtl.single .selectize-input:after {
307
- left: 17px;
308
- right: auto;
309
- }
310
- .selectize-control.rtl .selectize-input > input {
311
- margin: 0 4px 0 -2px !important;
312
- }
313
- .selectize-control .selectize-input.disabled {
314
- opacity: 0.5;
315
- background-color: #ffffff;
316
- }
317
- .selectize-dropdown,
318
- .selectize-dropdown.form-control {
319
- height: auto;
320
- padding: 0;
321
- margin: 2px 0 0 0;
322
- z-index: 1000;
323
- background: #ffffff;
324
- border: 1px solid #cccccc;
325
- border: 1px solid rgba(0, 0, 0, 0.15);
326
- -webkit-border-radius: 4px;
327
- -moz-border-radius: 4px;
328
- border-radius: 4px;
329
- -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
330
- box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
331
- }
332
- .selectize-dropdown .optgroup-header {
333
- font-size: 12px;
334
- line-height: 1.42857143;
335
- }
336
- .selectize-dropdown .optgroup:first-child:before {
337
- display: none;
338
- }
339
- .selectize-dropdown .optgroup:before {
340
- content: ' ';
341
- display: block;
342
- height: 1px;
343
- margin: 9px 0;
344
- overflow: hidden;
345
- background-color: #e5e5e5;
346
- margin-left: -12px;
347
- margin-right: -12px;
348
- }
349
- .selectize-dropdown-content {
350
- padding: 5px 0;
351
- }
352
- .selectize-dropdown-header {
353
- padding: 6px 12px;
354
- }
355
- .selectize-input {
356
- min-height: 34px;
357
- }
358
- .selectize-input.dropdown-active {
359
- -webkit-border-radius: 4px;
360
- -moz-border-radius: 4px;
361
- border-radius: 4px;
362
- }
363
- .selectize-input.dropdown-active::before {
364
- display: none;
365
- }
366
- .selectize-input.focus {
367
- border-color: #66afe9;
368
- outline: 0;
369
- -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6);
370
- box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6);
371
- }
372
- .has-error .selectize-input {
373
- border-color: #a94442;
374
- -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
375
- box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
376
- }
377
- .has-error .selectize-input:focus {
378
- border-color: #843534;
379
- -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #ce8483;
380
- box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #ce8483;
381
- }
382
- .selectize-control.multi .selectize-input.has-items {
383
- padding-left: 9px;
384
- padding-right: 9px;
385
- }
386
- .selectize-control.multi .selectize-input > div {
387
- -webkit-border-radius: 3px;
388
- -moz-border-radius: 3px;
389
- border-radius: 3px;
390
- }
391
- .form-control.selectize-control {
392
- padding: 0;
393
- height: auto;
394
- border: none;
395
- background: none;
396
- -webkit-box-shadow: none;
397
- box-shadow: none;
398
- -webkit-border-radius: 0;
399
- -moz-border-radius: 0;
400
- border-radius: 0;
401
- }
1
+ /**
2
+ * selectize.bootstrap3.css (v0.12.1) - Bootstrap 3 Theme
3
+ * Copyright (c) 2013–2015 Brian Reavis & contributors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6
+ * file except in compliance with the License. You may obtain a copy of the License at:
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ * ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ *
14
+ * @author Brian Reavis <brian@thirdroute.com>
15
+ */
16
+ .selectize-control.plugin-drag_drop.multi > .selectize-input > div.ui-sortable-placeholder {
17
+ visibility: visible !important;
18
+ background: #f2f2f2 !important;
19
+ background: rgba(0, 0, 0, 0.06) !important;
20
+ border: 0 none !important;
21
+ -webkit-box-shadow: inset 0 0 12px 4px #ffffff;
22
+ box-shadow: inset 0 0 12px 4px #ffffff;
23
+ }
24
+ .selectize-control.plugin-drag_drop .ui-sortable-placeholder::after {
25
+ content: '!';
26
+ visibility: hidden;
27
+ }
28
+ .selectize-control.plugin-drag_drop .ui-sortable-helper {
29
+ -webkit-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
30
+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
31
+ }
32
+ .selectize-dropdown-header {
33
+ position: relative;
34
+ padding: 3px 12px;
35
+ border-bottom: 1px solid #d0d0d0;
36
+ background: #f8f8f8;
37
+ -webkit-border-radius: 4px 4px 0 0;
38
+ -moz-border-radius: 4px 4px 0 0;
39
+ border-radius: 4px 4px 0 0;
40
+ }
41
+ .selectize-dropdown-header-close {
42
+ position: absolute;
43
+ right: 12px;
44
+ top: 50%;
45
+ color: #333333;
46
+ opacity: 0.4;
47
+ margin-top: -12px;
48
+ line-height: 20px;
49
+ font-size: 20px !important;
50
+ }
51
+ .selectize-dropdown-header-close:hover {
52
+ color: #000000;
53
+ }
54
+ .selectize-dropdown.plugin-optgroup_columns .optgroup {
55
+ border-right: 1px solid #f2f2f2;
56
+ border-top: 0 none;
57
+ float: left;
58
+ -webkit-box-sizing: border-box;
59
+ -moz-box-sizing: border-box;
60
+ box-sizing: border-box;
61
+ }
62
+ .selectize-dropdown.plugin-optgroup_columns .optgroup:last-child {
63
+ border-right: 0 none;
64
+ }
65
+ .selectize-dropdown.plugin-optgroup_columns .optgroup:before {
66
+ display: none;
67
+ }
68
+ .selectize-dropdown.plugin-optgroup_columns .optgroup-header {
69
+ border-top: 0 none;
70
+ }
71
+ .selectize-control.plugin-remove_button [data-value] {
72
+ position: relative;
73
+ padding-right: 24px !important;
74
+ }
75
+ .selectize-control.plugin-remove_button [data-value] .remove {
76
+ z-index: 1;
77
+ /* fixes ie bug (see #392) */
78
+ position: absolute;
79
+ top: 0;
80
+ right: 0;
81
+ bottom: 0;
82
+ width: 17px;
83
+ text-align: center;
84
+ font-weight: bold;
85
+ font-size: 12px;
86
+ color: inherit;
87
+ text-decoration: none;
88
+ vertical-align: middle;
89
+ display: inline-block;
90
+ padding: 1px 0 0 0;
91
+ border-left: 1px solid rgba(0, 0, 0, 0);
92
+ -webkit-border-radius: 0 2px 2px 0;
93
+ -moz-border-radius: 0 2px 2px 0;
94
+ border-radius: 0 2px 2px 0;
95
+ -webkit-box-sizing: border-box;
96
+ -moz-box-sizing: border-box;
97
+ box-sizing: border-box;
98
+ }
99
+ .selectize-control.plugin-remove_button [data-value] .remove:hover {
100
+ background: rgba(0, 0, 0, 0.05);
101
+ }
102
+ .selectize-control.plugin-remove_button [data-value].active .remove {
103
+ border-left-color: rgba(0, 0, 0, 0);
104
+ }
105
+ .selectize-control.plugin-remove_button .disabled [data-value] .remove:hover {
106
+ background: none;
107
+ }
108
+ .selectize-control.plugin-remove_button .disabled [data-value] .remove {
109
+ border-left-color: rgba(77, 77, 77, 0);
110
+ }
111
+ .selectize-control {
112
+ position: relative;
113
+ }
114
+ .selectize-dropdown,
115
+ .selectize-input,
116
+ .selectize-input input {
117
+ color: #333333;
118
+ font-family: inherit;
119
+ font-size: inherit;
120
+ line-height: 20px;
121
+ -webkit-font-smoothing: inherit;
122
+ }
123
+ .selectize-input,
124
+ .selectize-control.single .selectize-input.input-active {
125
+ background: #ffffff;
126
+ cursor: text;
127
+ display: inline-block;
128
+ }
129
+ .selectize-input {
130
+ border: 1px solid #cccccc;
131
+ padding: 6px 12px;
132
+ display: inline-block;
133
+ width: 100%;
134
+ overflow: hidden;
135
+ position: relative;
136
+ z-index: 1;
137
+ -webkit-box-sizing: border-box;
138
+ -moz-box-sizing: border-box;
139
+ box-sizing: border-box;
140
+ -webkit-box-shadow: none;
141
+ box-shadow: none;
142
+ -webkit-border-radius: 4px;
143
+ -moz-border-radius: 4px;
144
+ border-radius: 4px;
145
+ }
146
+ .selectize-control.multi .selectize-input.has-items {
147
+ padding: 5px 12px 2px;
148
+ }
149
+ .selectize-input.full {
150
+ background-color: #ffffff;
151
+ }
152
+ .selectize-input.disabled,
153
+ .selectize-input.disabled * {
154
+ cursor: default !important;
155
+ }
156
+ .selectize-input.focus {
157
+ -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
158
+ box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
159
+ }
160
+ .selectize-input.dropdown-active {
161
+ -webkit-border-radius: 4px 4px 0 0;
162
+ -moz-border-radius: 4px 4px 0 0;
163
+ border-radius: 4px 4px 0 0;
164
+ }
165
+ .selectize-input > * {
166
+ vertical-align: baseline;
167
+ display: -moz-inline-stack;
168
+ display: inline-block;
169
+ zoom: 1;
170
+ *display: inline;
171
+ }
172
+ .selectize-control.multi .selectize-input > div {
173
+ cursor: pointer;
174
+ margin: 0 3px 3px 0;
175
+ padding: 1px 3px;
176
+ background: #efefef;
177
+ color: #333333;
178
+ border: 0 solid rgba(0, 0, 0, 0);
179
+ }
180
+ .selectize-control.multi .selectize-input > div.active {
181
+ background: #428bca;
182
+ color: #ffffff;
183
+ border: 0 solid rgba(0, 0, 0, 0);
184
+ }
185
+ .selectize-control.multi .selectize-input.disabled > div,
186
+ .selectize-control.multi .selectize-input.disabled > div.active {
187
+ color: #808080;
188
+ background: #ffffff;
189
+ border: 0 solid rgba(77, 77, 77, 0);
190
+ }
191
+ .selectize-input > input {
192
+ display: inline-block !important;
193
+ padding: 0 !important;
194
+ min-height: 0 !important;
195
+ max-height: none !important;
196
+ max-width: 100% !important;
197
+ margin: 0 !important;
198
+ text-indent: 0 !important;
199
+ border: 0 none !important;
200
+ background: none !important;
201
+ line-height: inherit !important;
202
+ -webkit-user-select: auto !important;
203
+ -webkit-box-shadow: none !important;
204
+ box-shadow: none !important;
205
+ }
206
+ .selectize-input > input::-ms-clear {
207
+ display: none;
208
+ }
209
+ .selectize-input > input:focus {
210
+ outline: none !important;
211
+ }
212
+ .selectize-input::after {
213
+ content: ' ';
214
+ display: block;
215
+ clear: left;
216
+ }
217
+ .selectize-input.dropdown-active::before {
218
+ content: ' ';
219
+ display: block;
220
+ position: absolute;
221
+ background: #ffffff;
222
+ height: 1px;
223
+ bottom: 0;
224
+ left: 0;
225
+ right: 0;
226
+ }
227
+ .selectize-dropdown {
228
+ position: absolute;
229
+ z-index: 10;
230
+ border: 1px solid #d0d0d0;
231
+ background: #ffffff;
232
+ margin: -1px 0 0 0;
233
+ border-top: 0 none;
234
+ -webkit-box-sizing: border-box;
235
+ -moz-box-sizing: border-box;
236
+ box-sizing: border-box;
237
+ -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
238
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
239
+ -webkit-border-radius: 0 0 4px 4px;
240
+ -moz-border-radius: 0 0 4px 4px;
241
+ border-radius: 0 0 4px 4px;
242
+ }
243
+ .selectize-dropdown [data-selectable] {
244
+ cursor: pointer;
245
+ overflow: hidden;
246
+ }
247
+ .selectize-dropdown [data-selectable] .highlight {
248
+ background: rgba(255, 237, 40, 0.4);
249
+ -webkit-border-radius: 1px;
250
+ -moz-border-radius: 1px;
251
+ border-radius: 1px;
252
+ }
253
+ .selectize-dropdown [data-selectable],
254
+ .selectize-dropdown .optgroup-header {
255
+ padding: 3px 12px;
256
+ }
257
+ .selectize-dropdown .optgroup:first-child .optgroup-header {
258
+ border-top: 0 none;
259
+ }
260
+ .selectize-dropdown .optgroup-header {
261
+ color: #777777;
262
+ background: #ffffff;
263
+ cursor: default;
264
+ }
265
+ .selectize-dropdown .active {
266
+ background-color: #f5f5f5;
267
+ color: #262626;
268
+ }
269
+ .selectize-dropdown .active.create {
270
+ color: #262626;
271
+ }
272
+ .selectize-dropdown .create {
273
+ color: rgba(51, 51, 51, 0.5);
274
+ }
275
+ .selectize-dropdown-content {
276
+ overflow-y: auto;
277
+ overflow-x: hidden;
278
+ max-height: 200px;
279
+ }
280
+ .selectize-control.single .selectize-input,
281
+ .selectize-control.single .selectize-input input {
282
+ cursor: pointer;
283
+ }
284
+ .selectize-control.single .selectize-input.input-active,
285
+ .selectize-control.single .selectize-input.input-active input {
286
+ cursor: text;
287
+ }
288
+ .selectize-control.single .selectize-input:after {
289
+ content: ' ';
290
+ display: block;
291
+ position: absolute;
292
+ top: 50%;
293
+ right: 17px;
294
+ margin-top: -3px;
295
+ width: 0;
296
+ height: 0;
297
+ border-style: solid;
298
+ border-width: 5px 5px 0 5px;
299
+ border-color: #333333 transparent transparent transparent;
300
+ }
301
+ .selectize-control.single .selectize-input.dropdown-active:after {
302
+ margin-top: -4px;
303
+ border-width: 0 5px 5px 5px;
304
+ border-color: transparent transparent #333333 transparent;
305
+ }
306
+ .selectize-control.rtl.single .selectize-input:after {
307
+ left: 17px;
308
+ right: auto;
309
+ }
310
+ .selectize-control.rtl .selectize-input > input {
311
+ margin: 0 4px 0 -2px !important;
312
+ }
313
+ .selectize-control .selectize-input.disabled {
314
+ opacity: 0.5;
315
+ background-color: #ffffff;
316
+ }
317
+ .selectize-dropdown,
318
+ .selectize-dropdown.form-control {
319
+ height: auto;
320
+ padding: 0;
321
+ margin: 2px 0 0 0;
322
+ z-index: 1000;
323
+ background: #ffffff;
324
+ border: 1px solid #cccccc;
325
+ border: 1px solid rgba(0, 0, 0, 0.15);
326
+ -webkit-border-radius: 4px;
327
+ -moz-border-radius: 4px;
328
+ border-radius: 4px;
329
+ -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
330
+ box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
331
+ }
332
+ .selectize-dropdown .optgroup-header {
333
+ font-size: 12px;
334
+ line-height: 1.42857143;
335
+ }
336
+ .selectize-dropdown .optgroup:first-child:before {
337
+ display: none;
338
+ }
339
+ .selectize-dropdown .optgroup:before {
340
+ content: ' ';
341
+ display: block;
342
+ height: 1px;
343
+ margin: 9px 0;
344
+ overflow: hidden;
345
+ background-color: #e5e5e5;
346
+ margin-left: -12px;
347
+ margin-right: -12px;
348
+ }
349
+ .selectize-dropdown-content {
350
+ padding: 5px 0;
351
+ }
352
+ .selectize-dropdown-header {
353
+ padding: 6px 12px;
354
+ }
355
+ .selectize-input {
356
+ min-height: 34px;
357
+ }
358
+ .selectize-input.dropdown-active {
359
+ -webkit-border-radius: 4px;
360
+ -moz-border-radius: 4px;
361
+ border-radius: 4px;
362
+ }
363
+ .selectize-input.dropdown-active::before {
364
+ display: none;
365
+ }
366
+ .selectize-input.focus {
367
+ border-color: #66afe9;
368
+ outline: 0;
369
+ -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6);
370
+ box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6);
371
+ }
372
+ .has-error .selectize-input {
373
+ border-color: #a94442;
374
+ -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
375
+ box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
376
+ }
377
+ .has-error .selectize-input:focus {
378
+ border-color: #843534;
379
+ -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #ce8483;
380
+ box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #ce8483;
381
+ }
382
+ .selectize-control.multi .selectize-input.has-items {
383
+ padding-left: 9px;
384
+ padding-right: 9px;
385
+ }
386
+ .selectize-control.multi .selectize-input > div {
387
+ -webkit-border-radius: 3px;
388
+ -moz-border-radius: 3px;
389
+ border-radius: 3px;
390
+ }
391
+ .form-control.selectize-control {
392
+ padding: 0;
393
+ height: auto;
394
+ border: none;
395
+ background: none;
396
+ -webkit-box-shadow: none;
397
+ box-shadow: none;
398
+ -webkit-border-radius: 0;
399
+ -moz-border-radius: 0;
400
+ border-radius: 0;
401
+ }
includes/hfcm-add-edit.php CHANGED
@@ -1,326 +1,305 @@
1
- <?php
2
-
3
- // Register the script
4
- wp_register_script( 'hfcm_showboxes', plugins_url('js/showboxes.js', dirname( __FILE__ ) ), array( 'jquery' ) );
5
-
6
- // prepare ID (for AJAX)
7
- if ( !isset($id) ) {
8
- $id = -1;
9
- }
10
-
11
- // Localize the script with new data
12
- $translation_array = array(
13
- 'header' => __( 'Header', '99robots-header-footer-code-manager' ),
14
- 'before_content' => __( 'Before Content', '99robots-header-footer-code-manager' ),
15
- 'after_content' => __( 'After Content', '99robots-header-footer-code-manager' ),
16
- 'footer' => __( 'Footer', '99robots-header-footer-code-manager' ),
17
- 'id' => $id,
18
- 'security' => wp_create_nonce( 'hfcm-get-posts' )
19
- );
20
- wp_localize_script( 'hfcm_showboxes', 'hfcm_localize', $translation_array );
21
-
22
- // Enqueued script with localized data.
23
- wp_enqueue_script( 'hfcm_showboxes' );
24
-
25
- ?>
26
-
27
- <div class="wrap">
28
- <h1><?php _e( ( $update ? 'Edit Snippet' : 'Add New Snippet' ), '99robots-header-footer-code-manager'); ?>
29
- <?php if( $update ) :?><a href="<?php echo admin_url('admin.php?page=hfcm-create'); ?>" class="page-title-action"><?php _e('Add New Snippet', '99robots-header-footer-code-manager'); ?></a><?php endif; ?>
30
- </h1>
31
- <?php
32
- if ( !empty( $_GET['message'] ) ) :
33
- if ( $_GET['message'] == 1 ) :
34
- ?>
35
- <div class="updated">
36
- <p><?php _e('Script updated', '99robots-header-footer-code-manager'); ?></p>
37
- </div>
38
- <a href="<?php echo admin_url('admin.php?page=hfcm-list') ?>">&laquo; <?php _e('Back to list', '99robots-header-footer-code-manager'); ?></a>
39
- <?php
40
- elseif ( $_GET['message'] == 6 ) :
41
- ?>
42
- <div class="updated">
43
- <p><?php _e('Script Added Successfully', '99robots-header-footer-code-manager'); ?></p>
44
- </div>
45
- <a href="<?php echo admin_url('admin.php?page=hfcm-list') ?>">&laquo; <?php _e('Back to list', '99robots-header-footer-code-manager'); ?></a>
46
- <?php
47
- endif;
48
- endif;
49
-
50
- if( $update ) :
51
- ?>
52
- <form method="post" action="<?php echo admin_url('admin.php?page=hfcm-request-handler&id=' . $id); ?>">
53
- <?php
54
- wp_nonce_field('update-snippet_' . $id);
55
- else :
56
- ?>
57
- <form method="post" action="<?php echo admin_url('admin.php?page=hfcm-request-handler'); ?>">
58
- <?php
59
- wp_nonce_field('create-snippet');
60
- endif;
61
- ?>
62
- <table class="wp-list-table widefat fixed hfcm-form-width form-table">
63
- <tr>
64
- <th class="hfcm-th-width"><?php _e('Snippet Name', '99robots-header-footer-code-manager'); ?></th>
65
- <td><input type="text" name="data[name]" value="<?php echo $name; ?>" class="hfcm-field-width" /></td>
66
- </tr>
67
- <?php $darray = array('All' => 'Site Wide', 's_posts' => 'Specific Posts', 's_pages' => 'Specific Pages', 's_categories' => 'Specific Categories', 's_custom_posts' => 'Specific Custom Post Types', 's_tags' => 'Specific Tags', 'latest_posts' => 'Latest Posts', 'manual' => 'Shortcode Only'); ?>
68
- <tr>
69
- <th class="hfcm-th-width"><?php _e('Site Display', '99robots-header-footer-code-manager'); ?></th>
70
- <td>
71
- <select name="data[display_on]" onchange="hfcm_showotherboxes(this.value);">
72
- <?php
73
- foreach ($darray as $dkey => $statusv) {
74
- if ($display_on === $dkey) {
75
- echo "<option value='$dkey' selected='selected'>" . __($statusv, '99robots-header-footer-code-manager') . '</option>';
76
- } else {
77
- echo "<option value='$dkey'>" . __($statusv, '99robots-header-footer-code-manager') . '</option>';
78
- }
79
- }
80
- ?>
81
- </select>
82
- </td>
83
- </tr>
84
- <?php
85
- $pages = get_pages();
86
- if ('s_pages' === $display_on) {
87
- $spagesstyle = '';
88
- } else {
89
- $spagesstyle = 'display:none;';
90
- }
91
- ?>
92
- <tr id="s_pages" style="<?php echo $spagesstyle; ?>">
93
- <th class="hfcm-th-width"><?php _e('Page List', '99robots-header-footer-code-manager'); ?></th>
94
- <td>
95
- <select name="data[s_pages][]" multiple>
96
- <?php
97
- foreach ($pages as $pdata) {
98
- if (in_array($pdata->ID, $s_pages)) {
99
- echo "<option value='{$pdata->ID}' selected>{$pdata->post_title}</option>";
100
- } else {
101
- echo "<option value='{$pdata->ID}'>{$pdata->post_title}</option>";
102
- }
103
- }
104
- ?>
105
- </select>
106
- </td>
107
- </tr>
108
- <?php
109
- if ('s_posts' === $display_on) {
110
- $spostsstyle = '';
111
- } else {
112
- $spostsstyle = 'display:none;';
113
- }
114
- ?>
115
- <tr id="s_posts" style="<?php echo $spostsstyle; ?>">
116
- <th class="hfcm-th-width"><?php _e('Post List', '99robots-header-footer-code-manager'); ?></th>
117
- <td>
118
- <select class="nnr-wraptext" name="data[s_posts][]" multiple>
119
- <option disabled>...</option>
120
- </select>
121
- </td>
122
- </tr>
123
- <?php
124
- $args = array(
125
- 'hide_empty' => 0
126
- );
127
- $categories = get_categories($args);
128
- if ('s_categories' === $display_on) {
129
- $scategoriesstyle = '';
130
- } else {
131
- $scategoriesstyle = 'display:none;';
132
- }
133
- $tags = get_tags($args);
134
- if ('s_tags' === $display_on) {
135
- $stagsstyle = '';
136
- } else {
137
- $stagsstyle = 'display:none;';
138
- }
139
- if ('s_custom_posts' === $display_on) {
140
- $cpostssstyle = '';
141
- } else {
142
- $cpostssstyle = 'display:none;';
143
- }
144
- if ('latest_posts' === $display_on) {
145
- $lpcountstyle = '';
146
- } else {
147
- $lpcountstyle = 'display:none;';
148
- }
149
- if ('manual' === $display_on) {
150
- $locationstyle = 'display:none;';
151
- } else {
152
- $locationstyle = '';
153
- }
154
-
155
- // Get all names of Custom Post Types
156
- $args = array(
157
- 'public' => true,
158
- '_builtin' => false,
159
- );
160
-
161
- $output = 'names'; // names or objects, note names is the default
162
- $operator = 'and'; // 'and' or 'or'
163
-
164
- $c_posttypes = get_post_types($args, $output, $operator);
165
- $posttypes = array('post');
166
- foreach ($c_posttypes as $cpdata) {
167
- $posttypes[] = $cpdata;
168
- }
169
- ?>
170
- <tr id="s_categories" style="<?php echo $scategoriesstyle; ?>">
171
- <th class="hfcm-th-width"><?php _e('Category List', '99robots-header-footer-code-manager'); ?></th>
172
- <td>
173
- <select name="data[s_categories][]" multiple>
174
- <?php
175
- foreach ($categories as $cdata) {
176
- if (in_array($cdata->term_id, $s_categories)) {
177
- echo "<option value='{$cdata->term_id}' selected>{$cdata->name}</option>";
178
- } else {
179
- echo "<option value='{$cdata->term_id}'>{$cdata->name}</option>";
180
- }
181
- }
182
- ?>
183
- </select>
184
- </td>
185
- </tr>
186
- <tr id="s_tags" style="<?php echo $stagsstyle; ?>">
187
- <th class="hfcm-th-width"><?php _e('Tags List', '99robots-header-footer-code-manager'); ?></th>
188
- <td>
189
- <select name="data[s_tags][]" multiple>
190
- <?php
191
- foreach ($tags as $tdata) {
192
- if (in_array($tdata->term_id, $s_tags)) {
193
- echo "<option value='{$tdata->term_id}' selected>{$tdata->name}</option>";
194
- } else {
195
- echo "<option value='{$tdata->term_id}'>{$tdata->name}</option>";
196
- }
197
- }
198
- ?>
199
- </select>
200
- </td>
201
- </tr>
202
- <tr id="c_posttype" style="<?php echo $cpostssstyle; ?>">
203
- <th class="hfcm-th-width"><?php _e('Custom Post Types', '99robots-header-footer-code-manager'); ?></th>
204
- <td>
205
- <select name="data[s_custom_posts][]" multiple>
206
- <?php
207
- foreach ($c_posttypes as $cpkey => $cpdata) {
208
- if (in_array($cpkey, $s_custom_posts)) {
209
- echo "<option value='$cpkey' selected>$cpdata</option>";
210
- } else {
211
- echo "<option value='$cpkey'>$cpdata</option>";
212
- }
213
- }
214
- ?>
215
- </select>
216
- </td>
217
- </tr>
218
- <tr id="lp_count" style="<?php echo $lpcountstyle; ?>">
219
- <th class="hfcm-th-width"><?php _e('Post Count', '99robots-header-footer-code-manager'); ?></th>
220
- <td>
221
- <select name="data[lp_count]">
222
- <?php
223
- for ($i = 1; $i <= 20; $i++) {
224
- if ($i == $lp_count) {
225
- echo "<option value='{$i}' selected>{$i}</option>";
226
- } else {
227
- echo "<option value='{$i}'>{$i}</option>";
228
- }
229
- }
230
- ?>
231
- </select>
232
- </td>
233
- </tr>
234
- <?php
235
- if ( in_array( $display_on, array( 's_posts', 's_pages', 's_categories', 's_custom_posts', 's_tags', 'latest_posts' ) ) ) {
236
- $larray = array('header' => 'Header', 'before_content' => 'Before Content', 'after_content' => 'After Content', 'footer' => 'Footer');
237
- } else {
238
- $larray = array('header' => 'Header', 'footer' => 'Footer');
239
- }
240
- ?>
241
- <tr id="locationtr" style="<?php echo $locationstyle; ?>">
242
- <th class="hfcm-th-width"><?php _e('Location', '99robots-header-footer-code-manager'); ?></th>
243
- <td>
244
- <select name="data[location]" id="data_location">
245
- <?php
246
- foreach ($larray as $lkey => $statusv) {
247
- if ($location === $lkey) {
248
- echo "<option value='" . $lkey . "' selected='selected'>" . __($statusv, '99robots-header-footer-code-manager') . '</option>';
249
- } else {
250
- echo "<option value='" . $lkey . "'>" . __($statusv, '99robots-header-footer-code-manager') . '</option>';
251
- }
252
- }
253
- ?>
254
- </select>
255
- </td>
256
- </tr>
257
- <?php $devicetypearray = array('both' => 'Show on All Devices', 'desktop' => 'Only Desktop', 'mobile' => 'Only Mobile Devices'); ?>
258
- <?php $statusarray = array('active' => 'Active', 'inactive' => 'Inactive'); ?>
259
- <tr>
260
- <th class="hfcm-th-width"><?php _e('Device Display', '99robots-header-footer-code-manager'); ?></th>
261
- <td>
262
- <select name="data[device_type]">
263
- <?php
264
- foreach ($devicetypearray as $smkey => $typev) {
265
- if ($device_type === $smkey) {
266
- echo "<option value='" . $smkey . "' selected='selected'>" . __($typev, '99robots-header-footer-code-manager') . '</option>';
267
- } else {
268
- echo "<option value='" . $smkey . "'>" . __($typev, '99robots-header-footer-code-manager') . '</option>';
269
- }
270
- }
271
- ?>
272
- </select>
273
- </td>
274
- </tr>
275
- <tr>
276
- <th class="hfcm-th-width"><?php _e('Status', '99robots-header-footer-code-manager'); ?></th>
277
- <td>
278
- <select name="data[status]">
279
- <?php
280
- foreach ($statusarray as $skey => $statusv) {
281
- if ($status === $skey) {
282
- echo "<option value='" . $skey . "' selected='selected'>" . __($statusv, '99robots-header-footer-code-manager') . '</option>';
283
- } else {
284
- echo "<option value='" . $skey . "'>" . __($statusv, '99robots-header-footer-code-manager') . '</option>';
285
- }
286
- }
287
- ?>
288
- </select>
289
- </td>
290
- </tr>
291
- <?php if ( $update ) : ?>
292
- <tr>
293
- <th class="hfcm-th-width"><?php _e('Shortcode', '99robots-header-footer-code-manager'); ?></th>
294
- <td>
295
- <p>[hfcm id="<?php echo $id; ?>"]</p>
296
- </td>
297
- </tr>
298
- <tr>
299
- <th class="hfcm-th-width"><?php _e('Changelog', '99robots-header-footer-code-manager'); ?></th>
300
- <td>
301
- <p>
302
- <?php _e('Snippet created by', '99robots-header-footer-code-manager'); ?> <b><?php echo $createdby; ?></b> <?php echo __('on', '99robots-header-footer-code-manager') . ' ' . date_i18n(get_option('date_format'), strtotime($createdon)) . ' ' . __('at', '99robots-header-footer-code-manager') . ' ' . date_i18n(get_option('time_format'), strtotime($createdon)); ?>
303
- <br/>
304
- <?php if (!empty($lastmodifiedby)) : ?>
305
- <?php _e('Last edited by', '99robots-header-footer-code-manager'); ?> <b><?php echo $lastmodifiedby; ?></b> <?php echo __('on', '99robots-header-footer-code-manager') . ' ' . date_i18n(get_option('date_format'), strtotime($lastrevisiondate)) . ' ' . __('at', '99robots-header-footer-code-manager') . ' ' . date_i18n(get_option('time_format'), strtotime($lastrevisiondate)); ?>
306
- <?php endif; ?>
307
- </p>
308
- </td>
309
- </tr>
310
- <?php endif; ?>
311
- </table>
312
- <div class="wrap">
313
- <h1><?php _e('Snippet', '99robots-header-footer-code-manager'); ?> / <?php _e('Code', '99robots-header-footer-code-manager'); ?></h1>
314
- <div class="wrap">
315
- <textarea name="data[snippet]" aria-describedby="newcontent-description" id="newcontent" name="newcontent" rows="10"><?php echo $snippet; ?></textarea>
316
- <div class="wp-core-ui">
317
- <input type="submit"
318
- name="<?php echo $update ? 'update' : 'insert'; ?>"
319
- value="<?php _e( ( $update ? 'Update' : 'Save' ), '99robots-header-footer-code-manager'); ?>"
320
- class="button button-primary button-large nnr-btnsave"
321
- />
322
- </div>
323
- </div>
324
- </div>
325
- </form>
326
- </div>
1
+ <?php
2
+
3
+ // Register the script
4
+ wp_register_script( 'hfcm_showboxes', plugins_url( 'js/showboxes.js', dirname( __FILE__ ) ), array( 'jquery' ) );
5
+
6
+ // prepare ID (for AJAX)
7
+ if ( ! isset( $id ) ) {
8
+ $id = -1;
9
+ }
10
+
11
+ // Localize the script with new data
12
+ $translation_array = array(
13
+ 'header' => __( 'Header', '99robots-header-footer-code-manager' ),
14
+ 'before_content' => __( 'Before Content', '99robots-header-footer-code-manager' ),
15
+ 'after_content' => __( 'After Content', '99robots-header-footer-code-manager' ),
16
+ 'footer' => __( 'Footer', '99robots-header-footer-code-manager' ),
17
+ 'id' => $id,
18
+ 'security' => wp_create_nonce( 'hfcm-get-posts' ),
19
+ );
20
+ wp_localize_script( 'hfcm_showboxes', 'hfcm_localize', $translation_array );
21
+
22
+ // Enqueued script with localized data.
23
+ wp_enqueue_script( 'hfcm_showboxes' );
24
+ ?>
25
+
26
+ <div class="wrap">
27
+ <h1>
28
+ <?php echo $update ? esc_html__( 'Edit Snippet', '99robots-header-footer-code-manager' ) : esc_html__( 'Add New Snippet', '99robots-header-footer-code-manager' ) ?>
29
+ <?php if ( $update ) : ?>
30
+ <a href="<?php echo admin_url( 'admin.php?page=hfcm-create' ) ?>" class="page-title-action">
31
+ <?php esc_html_e( 'Add New Snippet', '99robots-header-footer-code-manager' ) ?>
32
+ </a>
33
+ <?php endif; ?>
34
+ </h1>
35
+ <?php
36
+ if ( ! empty( $_GET['message'] ) ) :
37
+ if ( 1 === $_GET['message'] ) :
38
+ ?>
39
+ <div class="updated">
40
+ <p><?php esc_html_e( 'Script updated', '99robots-header-footer-code-manager' ); ?></p>
41
+ </div>
42
+ <a href="<?php echo admin_url( 'admin.php?page=hfcm-list' ) ?>">&laquo; <?php esc_html_e( 'Back to list', '99robots-header-footer-code-manager' ); ?></a>
43
+ <?php elseif ( 6 === $_GET['message'] ) : ?>
44
+ <div class="updated">
45
+ <p><?php esc_html_e( 'Script Added Successfully', '99robots-header-footer-code-manager' ); ?></p>
46
+ </div>
47
+ <a href="<?php echo admin_url( 'admin.php?page=hfcm-list' ) ?>">&laquo; <?php esc_html_e( 'Back to list', '99robots-header-footer-code-manager' ); ?></a>
48
+ <?php
49
+ endif;
50
+ endif;
51
+
52
+ if ( $update ) : ?>
53
+ <form method="post" action="<?php echo admin_url( 'admin.php?page=hfcm-request-handler&id=' . $id ) ?>">
54
+ <?php
55
+ wp_nonce_field( 'update-snippet_' . $id );
56
+ else :
57
+ ?>
58
+ <form method="post" action="<?php echo admin_url( 'admin.php?page=hfcm-request-handler' ) ?>">
59
+ <?php
60
+ wp_nonce_field( 'create-snippet' );
61
+ endif;
62
+ ?>
63
+ <table class="wp-list-table widefat fixed hfcm-form-width form-table">
64
+ <tr>
65
+ <th class="hfcm-th-width"><?php esc_html_e( 'Snippet Name', '99robots-header-footer-code-manager' ); ?></th>
66
+ <td><input type="text" name="data[name]" value="<?php echo $name; ?>" class="hfcm-field-width" /></td>
67
+ </tr>
68
+ <?php
69
+ $darray = array(
70
+ 'All' => esc_html__( 'Site Wide', '99robots-header-footer-code-manager' ),
71
+ 's_posts' => esc_html__( 'Specific Posts', '99robots-header-footer-code-manager' ),
72
+ 's_pages' => esc_html__( 'Specific Pages', '99robots-header-footer-code-manager' ),
73
+ 's_categories' => esc_html__( 'Specific Categories', '99robots-header-footer-code-manager' ),
74
+ 's_custom_posts' => esc_html__( 'Specific Custom Post Types', '99robots-header-footer-code-manager' ),
75
+ 's_tags' => esc_html__( 'Specific Tags', '99robots-header-footer-code-manager' ),
76
+ 'latest_posts' => esc_html__( 'Latest Posts', '99robots-header-footer-code-manager' ),
77
+ 'manual' => esc_html__( 'Shortcode Only', '99robots-header-footer-code-manager' ),
78
+ ); ?>
79
+ <tr>
80
+ <th class="hfcm-th-width"><?php esc_html_e( 'Site Display', '99robots-header-footer-code-manager' ); ?></th>
81
+ <td>
82
+ <select name="data[display_on]" onchange="hfcm_showotherboxes(this.value);">
83
+ <?php
84
+ foreach ( $darray as $dkey => $statusv ) {
85
+ if ( $display_on === $dkey ) {
86
+ printf( '<option value="%1$s" selected="selected">%2$s</option>', $dkey, $statusv );
87
+ } else {
88
+ printf( '<option value="%1$s">%2$s</option>', $dkey, $statusv );
89
+ }
90
+ }
91
+ ?>
92
+ </select>
93
+ </td>
94
+ </tr>
95
+ <?php
96
+ $pages = get_pages();
97
+ $spagesstyle = ( 's_pages' === $display_on ) ? '' : 'display:none;';
98
+ ?>
99
+ <tr id="s_pages" style="<?php echo $spagesstyle; ?>">
100
+ <th class="hfcm-th-width"><?php esc_html_e( 'Page List', '99robots-header-footer-code-manager' ); ?></th>
101
+ <td>
102
+ <select name="data[s_pages][]" multiple>
103
+ <?php
104
+ foreach ( $pages as $pdata ) {
105
+ if ( in_array( $pdata->ID, $s_pages ) ) {
106
+ printf( '<option value="%1$s" selected="selected">%2$s</option>', $pdata->ID, $pdata->post_title );
107
+ } else {
108
+ printf( '<option value="%1$s">%2$s</option>', $pdata->ID, $pdata->post_title );
109
+ }
110
+ }
111
+ ?>
112
+ </select>
113
+ </td>
114
+ </tr>
115
+ <?php $spostsstyle = 's_posts' === $display_on ? '' : 'display:none;'; ?>
116
+ <tr id="s_posts" style="<?php echo $spostsstyle; ?>">
117
+ <th class="hfcm-th-width"><?php esc_html_e( 'Post List', '99robots-header-footer-code-manager' ); ?></th>
118
+ <td>
119
+ <select class="nnr-wraptext" name="data[s_posts][]" multiple>
120
+ <option disabled>...</option>
121
+ </select>
122
+ </td>
123
+ </tr>
124
+ <?php
125
+ $args = array( 'hide_empty' => 0 );
126
+ $categories = get_categories( $args );
127
+ $tags = get_tags( $args );
128
+
129
+ $scategoriesstyle = 's_categories' === $display_on ? '' : 'display:none;';
130
+ $stagsstyle = 's_tags' === $display_on ? '' : 'display:none;';
131
+ $cpostssstyle = 's_custom_posts' === $display_on ? '' : 'display:none;';
132
+ $lpcountstyle = 'latest_posts' === $display_on ? '' : 'display:none;';
133
+ $locationstyle = 'manual' === $display_on ? 'display:none;' : '';
134
+
135
+ // Get all names of Custom Post Types
136
+ $args = array(
137
+ 'public' => true,
138
+ '_builtin' => false,
139
+ );
140
+
141
+ $output = 'names';
142
+ $operator = 'and';
143
+
144
+ $c_posttypes = get_post_types( $args, $output, $operator );
145
+ $posttypes = array( 'post' );
146
+ foreach ( $c_posttypes as $cpdata ) {
147
+ $posttypes[] = $cpdata;
148
+ }
149
+ ?>
150
+ <tr id="s_categories" style="<?php echo $scategoriesstyle; ?>">
151
+ <th class="hfcm-th-width"><?php esc_html_e( 'Category List', '99robots-header-footer-code-manager' ); ?></th>
152
+ <td>
153
+ <select name="data[s_categories][]" multiple>
154
+ <?php
155
+ foreach ( $categories as $cdata ) {
156
+ if ( in_array( $cdata->term_id, $s_categories ) ) {
157
+ echo "<option value='{$cdata->term_id}' selected>{$cdata->name}</option>";
158
+ } else {
159
+ echo "<option value='{$cdata->term_id}'>{$cdata->name}</option>";
160
+ }
161
+ }
162
+ ?>
163
+ </select>
164
+ </td>
165
+ </tr>
166
+ <tr id="s_tags" style="<?php echo $stagsstyle; ?>">
167
+ <th class="hfcm-th-width"><?php esc_html_e( 'Tags List', '99robots-header-footer-code-manager' ); ?></th>
168
+ <td>
169
+ <select name="data[s_tags][]" multiple>
170
+ <?php
171
+ foreach ( $tags as $tdata ) {
172
+ if ( in_array( $tdata->term_id, $s_tags ) ) {
173
+ echo "<option value='{$tdata->term_id}' selected>{$tdata->name}</option>";
174
+ } else {
175
+ echo "<option value='{$tdata->term_id}'>{$tdata->name}</option>";
176
+ }
177
+ }
178
+ ?>
179
+ </select>
180
+ </td>
181
+ </tr>
182
+ <tr id="c_posttype" style="<?php echo $cpostssstyle; ?>">
183
+ <th class="hfcm-th-width"><?php esc_html_e( 'Custom Post Types', '99robots-header-footer-code-manager' ); ?></th>
184
+ <td>
185
+ <select name="data[s_custom_posts][]" multiple>
186
+ <?php
187
+ foreach ( $c_posttypes as $cpkey => $cpdata ) {
188
+ if ( in_array( $cpkey, $s_custom_posts ) ) {
189
+ echo "<option value='$cpkey' selected>$cpdata</option>";
190
+ } else {
191
+ echo "<option value='$cpkey'>$cpdata</option>";
192
+ }
193
+ }
194
+ ?>
195
+ </select>
196
+ </td>
197
+ </tr>
198
+ <tr id="lp_count" style="<?php echo $lpcountstyle; ?>">
199
+ <th class="hfcm-th-width"><?php esc_html_e( 'Post Count', '99robots-header-footer-code-manager' ); ?></th>
200
+ <td>
201
+ <select name="data[lp_count]">
202
+ <?php
203
+ for ( $i = 1; $i <= 20; $i++ ) {
204
+ if ( $i === $lp_count ) {
205
+ echo "<option value='{$i}' selected>{$i}</option>";
206
+ } else {
207
+ echo "<option value='{$i}'>{$i}</option>";
208
+ }
209
+ }
210
+ ?>
211
+ </select>
212
+ </td>
213
+ </tr>
214
+ <?php
215
+ if ( in_array( $display_on, array( 's_posts', 's_pages', 's_categories', 's_custom_posts', 's_tags', 'latest_posts' ) ) ) {
216
+ $larray = array( 'header' => 'Header', 'before_content' => 'Before Content', 'after_content' => 'After Content', 'footer' => 'Footer' );
217
+ } else {
218
+ $larray = array( 'header' => 'Header', 'footer' => 'Footer' );
219
+ }
220
+ ?>
221
+ <tr id="locationtr" style="<?php echo $locationstyle; ?>">
222
+ <th class="hfcm-th-width"><?php esc_html_e( 'Location', '99robots-header-footer-code-manager' ); ?></th>
223
+ <td>
224
+ <select name="data[location]" id="data_location">
225
+ <?php
226
+ foreach ( $larray as $lkey => $statusv ) {
227
+ if ( $location === $lkey ) {
228
+ echo "<option value='" . $lkey . "' selected='selected'>" . $statusv . '</option>';
229
+ } else {
230
+ echo "<option value='" . $lkey . "'>" . $statusv . '</option>';
231
+ }
232
+ }
233
+ ?>
234
+ </select>
235
+ </td>
236
+ </tr>
237
+ <?php $devicetypearray = array( 'both' => 'Show on All Devices', 'desktop' => 'Only Desktop', 'mobile' => 'Only Mobile Devices' ) ?>
238
+ <?php $statusarray = array( 'active' => 'Active', 'inactive' => 'Inactive' ) ?>
239
+ <tr>
240
+ <th class="hfcm-th-width"><?php esc_html_e( 'Device Display', '99robots-header-footer-code-manager' ); ?></th>
241
+ <td>
242
+ <select name="data[device_type]">
243
+ <?php
244
+ foreach ( $devicetypearray as $smkey => $typev ) {
245
+ if ( $device_type === $smkey ) {
246
+ echo "<option value='" . $smkey . "' selected='selected'>" . $typev . '</option>';
247
+ } else {
248
+ echo "<option value='" . $smkey . "'>" . $typev . '</option>';
249
+ }
250
+ }
251
+ ?>
252
+ </select>
253
+ </td>
254
+ </tr>
255
+ <tr>
256
+ <th class="hfcm-th-width"><?php esc_html_e( 'Status', '99robots-header-footer-code-manager' ); ?></th>
257
+ <td>
258
+ <select name="data[status]">
259
+ <?php
260
+ foreach ( $statusarray as $skey => $statusv ) {
261
+ if ( $status === $skey ) {
262
+ echo "<option value='" . $skey . "' selected='selected'>" . $statusv . '</option>';
263
+ } else {
264
+ echo "<option value='" . $skey . "'>" . $statusv . '</option>';
265
+ }
266
+ }
267
+ ?>
268
+ </select>
269
+ </td>
270
+ </tr>
271
+ <?php if ( $update ) : ?>
272
+ <tr>
273
+ <th class="hfcm-th-width"><?php esc_html_e( 'Shortcode', '99robots-header-footer-code-manager' ); ?></th>
274
+ <td>
275
+ <p>[hfcm id="<?php echo $id; ?>"]</p>
276
+ </td>
277
+ </tr>
278
+ <tr>
279
+ <th class="hfcm-th-width"><?php esc_html_e( 'Changelog', '99robots-header-footer-code-manager' ); ?></th>
280
+ <td>
281
+ <p>
282
+ <?php esc_html_e( 'Snippet created by', '99robots-header-footer-code-manager' ); ?> <b><?php echo $createdby; ?></b> <?php echo __( 'on', '99robots-header-footer-code-manager' ) . ' ' . date_i18n( get_option( 'date_format' ), strtotime( $createdon ) ) . ' ' . __( 'at', '99robots-header-footer-code-manager' ) . ' ' . date_i18n( get_option( 'time_format' ), strtotime( $createdon ) ) ?>
283
+ <br/>
284
+ <?php if ( ! empty( $lastmodifiedby ) ) : ?>
285
+ <?php esc_html_e( 'Last edited by', '99robots-header-footer-code-manager' ); ?> <b><?php echo $lastmodifiedby; ?></b> <?php echo __( 'on', '99robots-header-footer-code-manager' ) . ' ' . date_i18n( get_option( 'date_format' ), strtotime( $lastrevisiondate ) ) . ' ' . __( 'at', '99robots-header-footer-code-manager' ) . ' ' . date_i18n( get_option( 'time_format' ), strtotime( $lastrevisiondate ) ) ?>
286
+ <?php endif; ?>
287
+ </p>
288
+ </td>
289
+ </tr>
290
+ <?php endif; ?>
291
+ </table>
292
+ <div class="wrap">
293
+ <h1><?php esc_html_e( 'Snippet', '99robots-header-footer-code-manager' ); ?> / <?php esc_html_e( 'Code', '99robots-header-footer-code-manager' ) ?></h1>
294
+ <div class="wrap">
295
+ <textarea name="data[snippet]" aria-describedby="newcontent-description" id="newcontent" name="newcontent" rows="10"><?php echo $snippet; ?></textarea>
296
+ <div class="wp-core-ui">
297
+ <input type="submit"
298
+ name="<?php echo $update ? 'update' : 'insert'; ?>"
299
+ value="<?php echo $update ? esc_html__( 'Update', '99robots-header-footer-code-manager' ) : esc_html__( 'Save', '99robots-header-footer-code-manager' ) ?>"
300
+ class="button button-primary button-large nnr-btnsave" >
301
+ </div>
302
+ </div>
303
+ </div>
304
+ </form>
305
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/hfcm-create.php CHANGED
@@ -1,28 +1,27 @@
1
- <?php
2
-
3
- // function for submenu "Add snippet" page
4
- function hfcm_create() {
5
-
6
- // check user capabilities
7
- current_user_can('administrator');
8
-
9
- // prepare variables for includes/hfcm-add-edit.php
10
- $name = '';
11
- $snippet = '';
12
- $device_type = '';
13
- $location = '';
14
- $display_on = '';
15
- $status = '';
16
- $lp_count = 5; // Default value
17
- $s_pages = array();
18
- $s_posts = array();
19
- $s_custom_posts = array();
20
- $s_categories = array();
21
- $s_tags = array();
22
-
23
- // Notify hfcm-add-edit.php NOT to make changes for update
24
- $update = false;
25
-
26
- require_once( plugin_dir_path( __FILE__ ) . 'hfcm-add-edit.php' );
27
-
28
- }
1
+ <?php
2
+
3
+ // function for submenu "Add snippet" page
4
+ function hfcm_create() {
5
+
6
+ // check user capabilities
7
+ current_user_can( 'administrator' );
8
+
9
+ // prepare variables for includes/hfcm-add-edit.php
10
+ $name = '';
11
+ $snippet = '';
12
+ $device_type = '';
13
+ $location = '';
14
+ $display_on = '';
15
+ $status = '';
16
+ $lp_count = 5; // Default value
17
+ $s_pages = array();
18
+ $s_posts = array();
19
+ $s_custom_posts = array();
20
+ $s_categories = array();
21
+ $s_tags = array();
22
+
23
+ // Notify hfcm-add-edit.php NOT to make changes for update
24
+ $update = false;
25
+
26
+ require_once( plugin_dir_path( __FILE__ ) . 'hfcm-add-edit.php' );
27
+ }
 
includes/hfcm-list.php CHANGED
@@ -1,435 +1,469 @@
1
- <?php
2
- if (!class_exists('WP_List_Table')) {
3
- require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
4
- }
5
-
6
- class hfcm_Snippets_List extends WP_List_Table {
7
-
8
- /** Class constructor */
9
- public function __construct() {
10
-
11
- parent::__construct(
12
- array(
13
- 'singular' => __('Snippet', '99robots-header-footer-code-manager'), //singular name of the listed records
14
- 'plural' => __('Snippets', '99robots-header-footer-code-manager'), //plural name of the listed records
15
- 'ajax' => false //does this table support ajax?
16
- )
17
- );
18
- }
19
-
20
- /**
21
- * Retrieve snippets data from the database
22
- *
23
- * @param int $per_page
24
- * @param int $page_number
25
- *
26
- * @return mixed
27
- */
28
- public static function get_snippets($per_page = 5, $page_number = 1, $customvar = 'all') {
29
-
30
- global $wpdb;
31
- $table_name = "{$wpdb->prefix}hfcm_scripts";
32
- $sql = "SELECT * FROM $table_name";
33
- if ( in_array( $customvar, array( 'inactive', 'active' ) ) ) {
34
- $sql .= " where status = '$customvar'";
35
- }
36
- if (!empty($_REQUEST['orderby'])) {
37
- $sql .= ' ORDER BY ' . esc_sql($_REQUEST['orderby']);
38
- $sql .=!empty($_REQUEST['order']) ? ' ' . esc_sql($_REQUEST['order']) : ' ASC';
39
- }
40
-
41
- $sql .= " LIMIT $per_page";
42
- $sql .= ' OFFSET ' . ( $page_number - 1 ) * $per_page;
43
-
44
-
45
- $result = $wpdb->get_results($sql, 'ARRAY_A');
46
- return $result;
47
- }
48
-
49
- /**
50
- * Delete a snipppet record.
51
- *
52
- * @param int $id snippet ID
53
- */
54
- public static function delete_snippet($id) {
55
- global $wpdb;
56
- $table_name = "{$wpdb->prefix}hfcm_scripts";
57
-
58
- $wpdb->delete(
59
- $table_name, array( 'script_id' => $id ), array( '%d' )
60
- );
61
- }
62
-
63
- /**
64
- * Activate a snipppet record.
65
- *
66
- * @param int $id snippet ID
67
- */
68
- public static function activate_snippet($id) {
69
- global $wpdb;
70
- $table_name = "{$wpdb->prefix}hfcm_scripts";
71
-
72
- $wpdb->update(
73
- $table_name, array(
74
- 'status' => 'active',
75
- ), array( 'script_id' => $id ), array( '%s' ), array( '%d' )
76
- );
77
- }
78
-
79
- /**
80
- * Deactivate a snipppet record.
81
- *
82
- * @param int $id snippet ID
83
- */
84
- public static function deactivate_snippet($id) {
85
- global $wpdb;
86
- $table_name = "{$wpdb->prefix}hfcm_scripts";
87
-
88
- $wpdb->update(
89
- $table_name, array(
90
- 'status' => 'inactive',
91
- ), array( 'script_id' => $id ), array( '%s' ), array( '%d' )
92
- );
93
- }
94
-
95
- /**
96
- * Returns the count of records in the database.
97
- *
98
- * @return null|string
99
- */
100
- public static function record_count($customvar = 'all') {
101
- global $wpdb;
102
- $table_name = "{$wpdb->prefix}hfcm_scripts";
103
- $sql = "SELECT COUNT(*) FROM $table_name";
104
- if ( in_array( $customvar, array( 'inactive', 'active' ) ) ) {
105
- $sql .= " where status = '$customvar'";
106
- }
107
-
108
- return $wpdb->get_var($sql);
109
- }
110
-
111
- /** Text displayed when no snippet data is available */
112
- public function no_items() {
113
- _e('No Snippets avaliable.', '99robots-header-footer-code-manager');
114
- }
115
-
116
- /**
117
- * Render a column when no column specific method exist.
118
- *
119
- * @param array $item
120
- * @param string $column_name
121
- *
122
- * @return mixed
123
- */
124
- public function column_default( $item, $column_name ) {
125
- switch ($column_name) {
126
- case 'name':
127
- return esc_html($item[$column_name]);
128
- case 'display_on':
129
- $darray = array('All' => 'Site Wide', 's_posts' => 'Specific Posts', 's_pages' => 'Specific Pages', 's_categories' => 'Specific Categories', 's_custom_posts' => 'Specific Custom Post Types', 's_tags' => 'Specific Tags', 'latest_posts' => 'Latest Posts', 'manual' => 'Shortcode Only');
130
- if ( 's_posts' === $item[$column_name] ) {
131
- $s_posts = json_decode( $item['s_posts'] );
132
-
133
- $empty = 1;
134
-
135
- foreach ($s_posts as $ID) {
136
- if ( 'publish' === get_post_status($ID) ) {
137
- $empty = 0;
138
- break;
139
- }
140
- }
141
- if ($empty)
142
- return '<span class="hfcm-red">' . __('No post selected', '99robots-header-footer-code-manager') . '</span>';
143
- }
144
- return __(esc_html($darray[$item[$column_name]]), '99robots-header-footer-code-manager');
145
- case 'location':
146
- if (!$item[$column_name]) {
147
- return __('N/A', '99robots-header-footer-code-manager');
148
- }
149
-
150
- $larray = array('header' => 'Header', 'before_content' => 'Before Content', 'after_content' => 'After Content', 'footer' => 'Footer');
151
- return __(esc_html($larray[$item[$column_name]]), '99robots-header-footer-code-manager');
152
- case 'device_type':
153
- if ( 'both' === $item[$column_name] ) {
154
- return __('Show on All Devices', '99robots-header-footer-code-manager');
155
- } elseif ( 'mobile' === $item[$column_name] ) {
156
- return __('Only Mobile Devices', '99robots-header-footer-code-manager');
157
- } elseif ( 'desktop' === $item[$column_name] ) {
158
- return __('Only Desktop', '99robots-header-footer-code-manager');
159
- } else {
160
- return esc_html($item[$column_name]);
161
- }
162
- case 'status':
163
- if ( 'inactive' === $item[$column_name] ) {
164
- return '<div class="nnr-switch">
165
- <label for="nnr-round-toggle' . $item['script_id'] . '">OFF</label>
166
- <input id="nnr-round-toggle' . $item['script_id'] . '" class="round-toggle round-toggle-round-flat" type="checkbox" data-id="' . $item['script_id'] . '" />
167
- <label for="nnr-round-toggle' . $item['script_id'] . '"></label>
168
- <label for="nnr-round-toggle' . $item['script_id'] . '">ON</label>
169
- </div>
170
- ';
171
- } elseif ( 'active' === $item[$column_name] ) {
172
- return '<div class="nnr-switch">
173
- <label for="nnr-round-toggle' . $item['script_id'] . '">OFF</label>
174
- <input id="nnr-round-toggle' . $item['script_id'] . '" class="round-toggle round-toggle-round-flat" type="checkbox" data-id="' . $item['script_id'] . '" checked="checked" />
175
- <label for="nnr-round-toggle' . $item['script_id'] . '"></label>
176
- <label for="nnr-round-toggle' . $item['script_id'] . '">ON</label>
177
- </div>
178
- ';
179
- } else {
180
- return esc_html($item[$column_name]);
181
- }
182
- case 'script_id':
183
- return esc_html($item[$column_name]);
184
- case 'shortcode':
185
- return '[hfcm id="' . $item['script_id'] . '"]';
186
- default:
187
- return print_r($item, true); //Show the whole array for troubleshooting purposes
188
- }
189
- }
190
-
191
- /**
192
- * Render the bulk edit checkbox
193
- *
194
- * @param array $item
195
- *
196
- * @return string
197
- */
198
- function column_cb($item) {
199
- return sprintf(
200
- '<input type="checkbox" name="snippets[]" value="%s" />', $item['script_id']
201
- );
202
- }
203
-
204
- /**
205
- * Method for name column
206
- *
207
- * @param array $item an array of DB data
208
- *
209
- * @return string
210
- */
211
- function column_name($item) {
212
-
213
- $delete_nonce = wp_create_nonce('hfcm_delete_snippet');
214
- $edit_nonce = wp_create_nonce('hfcm_edit_snippet');
215
-
216
- $title = '<strong>' . $item['name'] . '</strong>';
217
-
218
- $actions = array(
219
- 'edit' => sprintf('<a href="?page=%s&action=%s&id=%s&_wpnonce=%s">' . __('Edit', '99robots-header-footer-code-manager') . '</a>', esc_attr("hfcm-update"), 'edit', absint($item['script_id']), $edit_nonce),
220
- 'delete' => sprintf('<a href="?page=%s&action=%s&snippet=%s&_wpnonce=%s">' . __('Delete', '99robots-header-footer-code-manager') . '</a>', esc_attr($_REQUEST['page']), 'delete', absint($item['script_id']), $delete_nonce)
221
- );
222
-
223
- return $title . $this->row_actions($actions);
224
- }
225
-
226
- /**
227
- * Associative array of columns
228
- *
229
- * @return array
230
- */
231
- function get_columns() {
232
- $columns = array(
233
- 'cb' => '<input type="checkbox" />',
234
- 'script_id' => __('ID', '99robots-header-footer-code-manager'),
235
- 'status' => __('Status', '99robots-header-footer-code-manager'),
236
- 'name' => __('Snippet Name', '99robots-header-footer-code-manager'),
237
- 'display_on' => __('Display On', '99robots-header-footer-code-manager'),
238
- 'location' => __('Location', '99robots-header-footer-code-manager'),
239
- 'device_type' => __('Devices', '99robots-header-footer-code-manager'),
240
- 'shortcode' => __('Shortcode', '99robots-header-footer-code-manager')
241
- );
242
-
243
- return $columns;
244
- }
245
-
246
- /**
247
- * Columns to make sortable.
248
- *
249
- * @return array
250
- */
251
- public function get_sortable_columns() {
252
- $sortable_columns = array(
253
- 'name' => array('name', true),
254
- 'script_id' => array('script_id', false)
255
- );
256
-
257
- return $sortable_columns;
258
- }
259
-
260
- /**
261
- * Returns an associative array containing the bulk action
262
- *
263
- * @return array
264
- */
265
- public function get_bulk_actions() {
266
- $actions = array(
267
- 'bulk-activate' => __('Activate', '99robots-header-footer-code-manager'),
268
- 'bulk-deactivate' => __('Deactivate', '99robots-header-footer-code-manager'),
269
- 'bulk-delete' => __('Remove', '99robots-header-footer-code-manager'),
270
- );
271
-
272
- return $actions;
273
- }
274
-
275
- /**
276
- * Handles data query and filter, sorting, and pagination.
277
- */
278
- public function prepare_items() {
279
-
280
- $columns = $this->get_columns();
281
- $hidden = array();
282
- $sortable = $this->get_sortable_columns();
283
-
284
- //Retrieve $customvar for use in query to get items.
285
- $customvar = ( isset($_REQUEST['customvar']) ? $_REQUEST['customvar'] : 'all');
286
- $this->_column_headers = array($columns, $hidden, $sortable);
287
-
288
- /** Process bulk action */
289
- $this->process_bulk_action();
290
- $this->views();
291
- $per_page = $this->get_items_per_page('snippets_per_page', 5);
292
- $current_page = $this->get_pagenum();
293
- $total_items = self::record_count();
294
-
295
- $this->set_pagination_args(array(
296
- 'total_items' => $total_items, //WE have to calculate the total number of items
297
- 'per_page' => $per_page //WE have to determine how many items to show on a page
298
- ));
299
-
300
- $this->items = self::get_snippets($per_page, $current_page, $customvar);
301
- }
302
-
303
- public function get_views() {
304
- $views = array();
305
- $current = (!empty($_REQUEST['customvar']) ? $_REQUEST['customvar'] : 'all');
306
-
307
- //All link
308
- $class = ( 'all' === $current ? ' class="current"' : '');
309
- $all_url = remove_query_arg('customvar');
310
- $views['all'] = "<a href='{$all_url }' {$class} >" . __('All', '99robots-header-footer-code-manager') . ' (' . $this->record_count() . ')</a>';
311
-
312
- //Foo link
313
- $foo_url = add_query_arg('customvar', 'active');
314
- $class = ( 'active' === $current ? ' class="current"' : '');
315
- $views['active'] = "<a href='{$foo_url}' {$class} >" . __('Active', '99robots-header-footer-code-manager') . ' (' . $this->record_count('active') . ')</a>';
316
-
317
- //Bar link
318
- $bar_url = add_query_arg('customvar', 'inactive');
319
- $class = ( 'inactive' === $current ? ' class="current"' : '');
320
- $views['inactive'] = "<a href='{$bar_url}' {$class} >" . __('Inactive', '99robots-header-footer-code-manager') . ' (' . $this->record_count('inactive') . ')</a>';
321
-
322
- return $views;
323
- }
324
-
325
- public function process_bulk_action() {
326
-
327
- //Detect when a bulk action is being triggered...
328
- if ( 'delete' === $this->current_action() ) {
329
-
330
- // In our file that handles the request, verify the nonce.
331
- $nonce = esc_attr($_REQUEST['_wpnonce']);
332
-
333
- if ( !wp_verify_nonce($nonce, 'hfcm_delete_snippet') ) {
334
- die('Go get a life script kiddies');
335
- } else {
336
- self::delete_snippet( absint( $_GET['snippet'] ) );
337
-
338
- hfcm_redirect( admin_url('admin.php?page=hfcm-list') );
339
- return;
340
- }
341
- }
342
-
343
- // If the delete bulk action is triggered
344
- if ( ( isset($_POST['action']) && 'bulk-delete' === $_POST['action'] )
345
- || ( isset($_POST['action2']) && 'bulk-delete' === $_POST['action2'] )
346
- ) {
347
-
348
- $delete_ids = esc_sql($_POST['snippets']);
349
-
350
- // loop over the array of record IDs and delete them
351
- foreach ($delete_ids as $id) {
352
- self::delete_snippet($id);
353
- }
354
-
355
- hfcm_redirect( admin_url('admin.php?page=hfcm-list') );
356
- return;
357
- } elseif (( isset($_POST['action']) && 'bulk-activate' === $_POST['action'] )
358
- || ( isset($_POST['action2']) && 'bulk-activate' === $_POST['action2'] )
359
- ) {
360
-
361
- $activate_ids = esc_sql($_POST['snippets']);
362
-
363
- // loop over the array of record IDs and activate them
364
- foreach ($activate_ids as $id) {
365
- self::activate_snippet($id);
366
- }
367
-
368
- hfcm_redirect( admin_url('admin.php?page=hfcm-list') );
369
- return;
370
- } elseif (( isset($_POST['action']) && 'bulk-deactivate' === $_POST['action'] )
371
- || ( isset($_POST['action2']) && 'bulk-deactivate' === $_POST['action2'] )
372
- ) {
373
-
374
- $delete_ids = esc_sql($_POST['snippets']);
375
-
376
- // loop over the array of record IDs and deactivate them
377
- foreach ($delete_ids as $id) {
378
- self::deactivate_snippet($id);
379
- }
380
-
381
- hfcm_redirect( admin_url('admin.php?page=hfcm-list') );
382
- return;
383
- }
384
- }
385
-
386
- }
387
-
388
- /** Generate list of all snippets */
389
- function hfcm_list() {
390
-
391
- global $wpdb;
392
- $table_name = $wpdb->prefix . 'hfcm_scripts';
393
- $activeclass = '';
394
- $inactiveclass = '';
395
- $allclass = 'current';
396
- $snippetObj = new hfcm_Snippets_List();
397
-
398
- if (!empty($_GET['script_status']) && in_array($_GET['script_status'], array('active', 'inactive'))) {
399
- $allclass = '';
400
- if ('active' === $_GET['script_status'] ) {
401
- $activeclass = 'current';
402
- }
403
- if ('inactive' === $_GET['script_status'] ) {
404
- $inactiveclass = 'current';
405
- }
406
- }
407
- ?>
408
- <div class="wrap">
409
- <h1><?php _e('Snippets', '99robots-header-footer-code-manager'); ?>
410
- <a href="<?php echo admin_url('admin.php?page=hfcm-create'); ?>" class="page-title-action"><?php _e('Add New Snippet', '99robots-header-footer-code-manager'); ?></a>
411
- </h1>
412
-
413
- <form method="post">
414
- <?php
415
- $snippetObj->prepare_items();
416
- $snippetObj->display();
417
- ?>
418
- </form>
419
-
420
- </div>
421
- <?php
422
-
423
- // Register the script
424
- wp_register_script( 'hfcm_toggle', plugins_url( '../js/toggle.js', __FILE__ ) );
425
-
426
- // Localize the script with new data
427
- $translation_array = array(
428
- 'url' => admin_url('admin.php'),
429
- 'security' => wp_create_nonce( 'hfcm-toggle-snippet' )
430
- );
431
- wp_localize_script( 'hfcm_toggle', 'hfcm_ajax', $translation_array );
432
-
433
- // Enqueued script with localized data.
434
- wp_enqueue_script( 'hfcm_toggle' );
435
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! class_exists( 'WP_List_Table' ) ) {
3
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
4
+ }
5
+
6
+ class Hfcm_Snippets_List extends WP_List_Table {
7
+
8
+ /** Class constructor */
9
+ public function __construct() {
10
+
11
+ parent::__construct(
12
+ array(
13
+ 'singular' => esc_html__( 'Snippet', '99robots-header-footer-code-manager' ),
14
+ 'plural' => esc_html__( 'Snippets', '99robots-header-footer-code-manager' ),
15
+ 'ajax' => false,
16
+ )
17
+ );
18
+ }
19
+
20
+ /**
21
+ * Retrieve snippets data from the database
22
+ *
23
+ * @param int $per_page
24
+ * @param int $page_number
25
+ *
26
+ * @return mixed
27
+ */
28
+ public static function get_snippets( $per_page = 5, $page_number = 1, $customvar = 'all' ) {
29
+
30
+ global $wpdb;
31
+ $table_name = "{$wpdb->prefix}hfcm_scripts";
32
+ $sql = "SELECT * FROM $table_name";
33
+
34
+ if ( in_array( $customvar, array( 'inactive', 'active' ) ) ) {
35
+ $sql .= " where status = '$customvar'";
36
+ }
37
+
38
+ if ( ! empty( $_REQUEST['orderby'] ) ) {
39
+ $sql .= ' ORDER BY ' . esc_sql( $_REQUEST['orderby'] );
40
+ $sql .= ! empty( $_REQUEST['order'] ) ? ' ' . esc_sql( $_REQUEST['order'] ) : ' ASC';
41
+ }
42
+
43
+ $sql .= " LIMIT $per_page";
44
+ $sql .= ' OFFSET ' . ( $page_number - 1 ) * $per_page;
45
+
46
+ $result = $wpdb->get_results( $sql, 'ARRAY_A' );
47
+ return $result;
48
+ }
49
+
50
+ /**
51
+ * Delete a snipppet record.
52
+ *
53
+ * @param int $id snippet ID
54
+ */
55
+ public static function delete_snippet( $id ) {
56
+
57
+ global $wpdb;
58
+ $table_name = "{$wpdb->prefix}hfcm_scripts";
59
+
60
+ $wpdb->delete(
61
+ $table_name, array( 'script_id' => $id ), array( '%d' )
62
+ );
63
+ }
64
+
65
+ /**
66
+ * Activate a snipppet record.
67
+ *
68
+ * @param int $id snippet ID
69
+ */
70
+ public static function activate_snippet( $id ) {
71
+
72
+ global $wpdb;
73
+ $table_name = "{$wpdb->prefix}hfcm_scripts";
74
+
75
+ $wpdb->update(
76
+ $table_name, array(
77
+ 'status' => 'active',
78
+ ), array( 'script_id' => $id ), array( '%s' ), array( '%d' )
79
+ );
80
+ }
81
+
82
+ /**
83
+ * Deactivate a snipppet record.
84
+ *
85
+ * @param int $id snippet ID
86
+ */
87
+ public static function deactivate_snippet( $id ) {
88
+
89
+ global $wpdb;
90
+ $table_name = "{$wpdb->prefix}hfcm_scripts";
91
+
92
+ $wpdb->update(
93
+ $table_name, array(
94
+ 'status' => 'inactive',
95
+ ), array( 'script_id' => $id ), array( '%s' ), array( '%d' )
96
+ );
97
+ }
98
+
99
+ /**
100
+ * Returns the count of records in the database.
101
+ *
102
+ * @return null|string
103
+ */
104
+ public static function record_count( $customvar = 'all' ) {
105
+
106
+ global $wpdb;
107
+ $table_name = "{$wpdb->prefix}hfcm_scripts";
108
+ $sql = "SELECT COUNT(*) FROM $table_name";
109
+
110
+ if ( in_array( $customvar, array( 'inactive', 'active' ) ) ) {
111
+ $sql .= " where status = '$customvar'";
112
+ }
113
+
114
+ return $wpdb->get_var( $sql );
115
+ }
116
+
117
+ /** Text displayed when no snippet data is available */
118
+ public function no_items() {
119
+ esc_html_e( 'No Snippets avaliable.', '99robots-header-footer-code-manager' );
120
+ }
121
+
122
+ /**
123
+ * Render a column when no column specific method exist.
124
+ *
125
+ * @param array $item
126
+ * @param string $column_name
127
+ *
128
+ * @return mixed
129
+ */
130
+ public function column_default( $item, $column_name ) {
131
+
132
+ switch ( $column_name ) {
133
+ case 'name':
134
+ return esc_html( $item[ $column_name ] );
135
+
136
+ case 'display_on':
137
+ $darray = array(
138
+ 'All' => esc_html__( 'Site Wide', '99robots-header-footer-code-manager' ),
139
+ 's_posts' => esc_html__( 'Specific Posts', '99robots-header-footer-code-manager' ),
140
+ 's_pages' => esc_html__( 'Specific Pages', '99robots-header-footer-code-manager' ),
141
+ 's_categories' => esc_html__( 'Specific Categories', '99robots-header-footer-code-manager' ),
142
+ 's_custom_posts' => esc_html__( 'Specific Custom Post Types', '99robots-header-footer-code-manager' ),
143
+ 's_tags' => esc_html__( 'Specific Tags', '99robots-header-footer-code-manager' ),
144
+ 'latest_posts' => esc_html__( 'Latest Posts', '99robots-header-footer-code-manager' ),
145
+ 'manual' => esc_html__( 'Shortcode Only', '99robots-header-footer-code-manager' ),
146
+ );
147
+
148
+ if ( 's_posts' === $item[ $column_name ] ) {
149
+
150
+ $empty = 1;
151
+ $s_posts = json_decode( $item['s_posts'] );
152
+
153
+ foreach ( $s_posts as $id ) {
154
+ if ( 'publish' === get_post_status( $id ) ) {
155
+ $empty = 0;
156
+ break;
157
+ }
158
+ }
159
+ if ( $empty ) {
160
+ return '<span class="hfcm-red">' . esc_html__( 'No post selected', '99robots-header-footer-code-manager' ) . '</span>';
161
+ }
162
+ }
163
+
164
+ return esc_html( $darray[ $item[ $column_name ] ] );
165
+
166
+ case 'location':
167
+
168
+ if ( ! $item[ $column_name ] ) {
169
+ return esc_html__( 'N/A', '99robots-header-footer-code-manager' );
170
+ }
171
+
172
+ $larray = array(
173
+ 'header' => esc_html__( 'Header', '99robots-header-footer-code-manager' ),
174
+ 'before_content' => esc_html__( 'Before Content', '99robots-header-footer-code-manager' ),
175
+ 'after_content' => esc_html__( 'After Content', '99robots-header-footer-code-manager' ),
176
+ 'footer' => esc_html__( 'Footer', '99robots-header-footer-code-manager' ),
177
+ );
178
+ return esc_html( $larray[ $item[ $column_name ] ] );
179
+
180
+ case 'device_type':
181
+
182
+ if ( 'both' === $item[ $column_name ] ) {
183
+ return esc_html__( 'Show on All Devices', '99robots-header-footer-code-manager' );
184
+ } elseif ( 'mobile' === $item[ $column_name ] ) {
185
+ return esc_html__( 'Only Mobile Devices', '99robots-header-footer-code-manager' );
186
+ } elseif ( 'desktop' === $item[ $column_name ] ) {
187
+ return esc_html__( 'Only Desktop', '99robots-header-footer-code-manager' );
188
+ } else {
189
+ return esc_html( $item[ $column_name ] );
190
+ }
191
+
192
+ case 'status':
193
+
194
+ if ( 'inactive' === $item[ $column_name ] ) {
195
+ return '<div class="nnr-switch">
196
+ <label for="nnr-round-toggle' . $item['script_id'] . '">OFF</label>
197
+ <input id="nnr-round-toggle' . $item['script_id'] . '" class="round-toggle round-toggle-round-flat" type="checkbox" data-id="' . $item['script_id'] . '" />
198
+ <label for="nnr-round-toggle' . $item['script_id'] . '"></label>
199
+ <label for="nnr-round-toggle' . $item['script_id'] . '">ON</label>
200
+ </div>
201
+ ';
202
+ } elseif ( 'active' === $item[ $column_name ] ) {
203
+ return '<div class="nnr-switch">
204
+ <label for="nnr-round-toggle' . $item['script_id'] . '">OFF</label>
205
+ <input id="nnr-round-toggle' . $item['script_id'] . '" class="round-toggle round-toggle-round-flat" type="checkbox" data-id="' . $item['script_id'] . '" checked="checked" />
206
+ <label for="nnr-round-toggle' . $item['script_id'] . '"></label>
207
+ <label for="nnr-round-toggle' . $item['script_id'] . '">ON</label>
208
+ </div>
209
+ ';
210
+ } else {
211
+ return esc_html( $item[ $column_name ] );
212
+ }
213
+
214
+ case 'script_id':
215
+ return esc_html( $item[ $column_name ] );
216
+
217
+ case 'shortcode':
218
+ return '[hfcm id="' . $item['script_id'] . '"]';
219
+
220
+ default:
221
+ return print_r( $item, true ); // Show the whole array for troubleshooting purposes
222
+ }
223
+ }
224
+
225
+ /**
226
+ * Render the bulk edit checkbox
227
+ *
228
+ * @param array $item
229
+ *
230
+ * @return string
231
+ */
232
+ function column_cb( $item ) {
233
+ return sprintf(
234
+ '<input type="checkbox" name="snippets[]" value="%s" />', $item['script_id']
235
+ );
236
+ }
237
+
238
+ /**
239
+ * Method for name column
240
+ *
241
+ * @param array $item an array of DB data
242
+ *
243
+ * @return string
244
+ */
245
+ function column_name( $item ) {
246
+
247
+ $delete_nonce = wp_create_nonce( 'hfcm_delete_snippet' );
248
+ $edit_nonce = wp_create_nonce( 'hfcm_edit_snippet' );
249
+
250
+ $title = '<strong>' . $item['name'] . '</strong>';
251
+
252
+ $actions = array(
253
+ 'edit' => sprintf( '<a href="?page=%s&action=%s&id=%s&_wpnonce=%s">' . esc_html__( 'Edit', '99robots-header-footer-code-manager' ) . '</a>', esc_attr( 'hfcm-update' ), 'edit', absint( $item['script_id'] ), $edit_nonce ),
254
+ 'delete' => sprintf( '<a href="?page=%s&action=%s&snippet=%s&_wpnonce=%s">' . esc_html__( 'Delete', '99robots-header-footer-code-manager' ) . '</a>', esc_attr( $_REQUEST['page'] ), 'delete', absint( $item['script_id'] ), $delete_nonce ),
255
+ );
256
+
257
+ return $title . $this->row_actions( $actions );
258
+ }
259
+
260
+ /**
261
+ * Associative array of columns
262
+ *
263
+ * @return array
264
+ */
265
+ function get_columns() {
266
+ $columns = array(
267
+ 'cb' => '<input type="checkbox" />',
268
+ 'script_id' => esc_html__( 'ID', '99robots-header-footer-code-manager' ),
269
+ 'status' => esc_html__( 'Status', '99robots-header-footer-code-manager' ),
270
+ 'name' => esc_html__( 'Snippet Name', '99robots-header-footer-code-manager' ),
271
+ 'display_on' => esc_html__( 'Display On', '99robots-header-footer-code-manager' ),
272
+ 'location' => esc_html__( 'Location', '99robots-header-footer-code-manager' ),
273
+ 'device_type' => esc_html__( 'Devices', '99robots-header-footer-code-manager' ),
274
+ 'shortcode' => esc_html__( 'Shortcode', '99robots-header-footer-code-manager' ),
275
+ );
276
+
277
+ return $columns;
278
+ }
279
+
280
+ /**
281
+ * Columns to make sortable.
282
+ *
283
+ * @return array
284
+ */
285
+ public function get_sortable_columns() {
286
+
287
+ return array(
288
+ 'name' => array( 'name', true ),
289
+ 'script_id' => array( 'script_id', false ),
290
+ );
291
+ }
292
+
293
+ /**
294
+ * Returns an associative array containing the bulk action
295
+ *
296
+ * @return array
297
+ */
298
+ public function get_bulk_actions() {
299
+
300
+ return array(
301
+ 'bulk-activate' => esc_html__( 'Activate', '99robots-header-footer-code-manager' ),
302
+ 'bulk-deactivate' => esc_html__( 'Deactivate', '99robots-header-footer-code-manager' ),
303
+ 'bulk-delete' => esc_html__( 'Remove', '99robots-header-footer-code-manager' ),
304
+ );
305
+ }
306
+
307
+ /**
308
+ * Handles data query and filter, sorting, and pagination.
309
+ */
310
+ public function prepare_items() {
311
+
312
+ $columns = $this->get_columns();
313
+ $hidden = array();
314
+ $sortable = $this->get_sortable_columns();
315
+
316
+ //Retrieve $customvar for use in query to get items.
317
+ $customvar = ( isset( $_REQUEST['customvar'] ) ? $_REQUEST['customvar'] : 'all');
318
+ $this->_column_headers = array( $columns, $hidden, $sortable );
319
+
320
+ /** Process bulk action */
321
+ $this->process_bulk_action();
322
+ $this->views();
323
+ $per_page = $this->get_items_per_page( 'snippets_per_page', 5 );
324
+ $current_page = $this->get_pagenum();
325
+ $total_items = self::record_count();
326
+
327
+ $this->set_pagination_args(array(
328
+ 'total_items' => $total_items,
329
+ 'per_page' => $per_page,
330
+ ));
331
+
332
+ $this->items = self::get_snippets( $per_page, $current_page, $customvar );
333
+ }
334
+
335
+ public function get_views() {
336
+ $views = array();
337
+ $current = ( ! empty( $_REQUEST['customvar'] ) ? $_REQUEST['customvar'] : 'all');
338
+
339
+ //All link
340
+ $class = 'all' === $current ? ' class="current"' : '';
341
+ $all_url = remove_query_arg( 'customvar' );
342
+ $views['all'] = "<a href='{$all_url }' {$class} >" . esc_html__( 'All', '99robots-header-footer-code-manager' ) . ' (' . $this->record_count() . ')</a>';
343
+
344
+ //Foo link
345
+ $foo_url = add_query_arg( 'customvar', 'active' );
346
+ $class = ( 'active' === $current ? ' class="current"' : '');
347
+ $views['active'] = "<a href='{$foo_url}' {$class} >" . esc_html__( 'Active', '99robots-header-footer-code-manager' ) . ' (' . $this->record_count( 'active' ) . ')</a>';
348
+
349
+ //Bar link
350
+ $bar_url = add_query_arg( 'customvar', 'inactive' );
351
+ $class = ( 'inactive' === $current ? ' class="current"' : '');
352
+ $views['inactive'] = "<a href='{$bar_url}' {$class} >" . esc_html__( 'Inactive', '99robots-header-footer-code-manager' ) . ' (' . $this->record_count( 'inactive' ) . ')</a>';
353
+
354
+ return $views;
355
+ }
356
+
357
+ public function process_bulk_action() {
358
+
359
+ //Detect when a bulk action is being triggered...
360
+ if ( 'delete' === $this->current_action() ) {
361
+
362
+ // In our file that handles the request, verify the nonce.
363
+ $nonce = esc_attr( $_REQUEST['_wpnonce'] );
364
+
365
+ if ( ! wp_verify_nonce( $nonce, 'hfcm_delete_snippet' ) ) {
366
+ die( 'Go get a life script kiddies' );
367
+ } else {
368
+ self::delete_snippet( absint( $_GET['snippet'] ) );
369
+
370
+ hfcm_redirect( admin_url( 'admin.php?page=hfcm-list' ) );
371
+ return;
372
+ }
373
+ }
374
+
375
+ // If the delete bulk action is triggered
376
+ if (
377
+ ( isset( $_POST['action'] ) && 'bulk-delete' === $_POST['action'] ) ||
378
+ ( isset( $_POST['action2'] ) && 'bulk-delete' === $_POST['action2'] )
379
+ ) {
380
+ $delete_ids = esc_sql( $_POST['snippets'] );
381
+
382
+ // loop over the array of record IDs and delete them
383
+ foreach ( $delete_ids as $id ) {
384
+ self::delete_snippet( $id );
385
+ }
386
+
387
+ hfcm_redirect( admin_url( 'admin.php?page=hfcm-list' ) );
388
+ return;
389
+ } elseif (
390
+ ( isset( $_POST['action'] ) && 'bulk-activate' === $_POST['action'] ) ||
391
+ ( isset( $_POST['action2'] ) && 'bulk-activate' === $_POST['action2'] )
392
+ ) {
393
+
394
+ $activate_ids = esc_sql( $_POST['snippets'] );
395
+
396
+ // loop over the array of record IDs and activate them
397
+ foreach ( $activate_ids as $id ) {
398
+ self::activate_snippet( $id );
399
+ }
400
+
401
+ hfcm_redirect( admin_url( 'admin.php?page=hfcm-list' ) );
402
+ return;
403
+ } elseif (
404
+ ( isset( $_POST['action'] ) && 'bulk-deactivate' === $_POST['action'] ) ||
405
+ ( isset( $_POST['action2'] ) && 'bulk-deactivate' === $_POST['action2'] )
406
+ ) {
407
+
408
+ $delete_ids = esc_sql( $_POST['snippets'] );
409
+
410
+ // loop over the array of record IDs and deactivate them
411
+ foreach ( $delete_ids as $id ) {
412
+ self::deactivate_snippet( $id );
413
+ }
414
+
415
+ hfcm_redirect( admin_url( 'admin.php?page=hfcm-list' ) );
416
+
417
+ return;
418
+ }
419
+ }
420
+ }
421
+
422
+ /** Generate list of all snippets */
423
+ function hfcm_list() {
424
+
425
+ global $wpdb;
426
+ $table_name = $wpdb->prefix . 'hfcm_scripts';
427
+ $activeclass = '';
428
+ $inactiveclass = '';
429
+ $allclass = 'current';
430
+ $snippet_obj = new Hfcm_Snippets_List();
431
+
432
+ if ( ! empty( $_GET['script_status'] ) && in_array( $_GET['script_status'], array( 'active', 'inactive' ) ) ) {
433
+ $allclass = '';
434
+ if ( 'active' === $_GET['script_status'] ) {
435
+ $activeclass = 'current';
436
+ }
437
+ if ( 'inactive' === $_GET['script_status'] ) {
438
+ $inactiveclass = 'current';
439
+ }
440
+ }
441
+ ?>
442
+ <div class="wrap">
443
+ <h1><?php esc_html_e( 'Snippets', '99robots-header-footer-code-manager' ) ?>
444
+ <a href="<?php echo admin_url( 'admin.php?page=hfcm-create' ) ?>" class="page-title-action"><?php esc_html_e( 'Add New Snippet', '99robots-header-footer-code-manager' ) ?></a>
445
+ </h1>
446
+
447
+ <form method="post">
448
+ <?php
449
+ $snippet_obj->prepare_items();
450
+ $snippet_obj->display();
451
+ ?>
452
+ </form>
453
+
454
+ </div>
455
+ <?php
456
+
457
+ // Register the script
458
+ wp_register_script( 'hfcm_toggle', plugins_url( '../js/toggle.js', __FILE__ ) );
459
+
460
+ // Localize the script with new data
461
+ $translation_array = array(
462
+ 'url' => admin_url( 'admin.php' ),
463
+ 'security' => wp_create_nonce( 'hfcm-toggle-snippet' ),
464
+ );
465
+ wp_localize_script( 'hfcm_toggle', 'hfcm_ajax', $translation_array );
466
+
467
+ // Enqueued script with localized data.
468
+ wp_enqueue_script( 'hfcm_toggle' );
469
+ }
includes/hfcm-request-handler.php CHANGED
@@ -1,212 +1,217 @@
1
- <?php
2
-
3
- function hfcm_request_handler() {
4
-
5
- // Check user capabilities
6
- current_user_can( 'administrator' );
7
-
8
- if ( isset( $_POST['insert'] ) ) {
9
- // Check nonce
10
- check_admin_referer( 'create-snippet' );
11
- } else {
12
- if ( !isset( $_REQUEST['id'] ) ) {
13
- die('Missing ID parameter.');
14
- }
15
- $id = (int) $_REQUEST['id'];
16
- }
17
- if ( isset( $_POST['update'] ) ) {
18
- // Check nonce
19
- check_admin_referer( 'update-snippet_' . $id );
20
- }
21
-
22
- // Handle AJAX on/off toggle for snippets
23
- if ( isset( $_REQUEST['toggle'] ) && !empty( $_REQUEST['togvalue'] ) ) {
24
-
25
- // Check nonce
26
- check_ajax_referer( 'hfcm-toggle-snippet', 'security' );
27
-
28
- if ( 'on' === $_REQUEST['togvalue'] ) {
29
- $status = 'active';
30
- } else {
31
- $status = 'inactive';
32
- }
33
-
34
- // Global vars
35
- global $wpdb;
36
- $table_name = $wpdb->prefix . 'hfcm_scripts';
37
-
38
- $wpdb->update(
39
- $table_name, //table
40
- array( 'status' => $status ), //data
41
- array( 'script_id' => $id ), //where
42
- array( '%s', '%s', '%s', '%s', '%s', '%s' ), //data format
43
- array( '%s' ) //where format
44
- );
45
-
46
- // Create / update snippet
47
- } elseif ( isset( $_POST['insert'] ) || isset( $_POST['update'] ) ) {
48
-
49
- // Sanitize fields
50
- $name = hfcm_sanitize_text( 'name' );
51
- $snippet = hfcm_sanitize_text( 'snippet', false );
52
- $device_type = hfcm_sanitize_text( 'device_type' );
53
- $display_on = hfcm_sanitize_text( 'display_on' );
54
- $location = hfcm_sanitize_text( 'location' );
55
- $lp_count = hfcm_sanitize_text( 'lp_count' );
56
- $status = hfcm_sanitize_text( 'status' );
57
- $s_pages = hfcm_sanitize_array( 's_pages' );
58
- $s_posts = hfcm_sanitize_array( 's_posts' );
59
- $s_custom_posts = hfcm_sanitize_array( 's_custom_posts', 'string' );
60
- $s_categories = hfcm_sanitize_array( 's_categories' );
61
- $s_tags = hfcm_sanitize_array( 's_tags' );
62
-
63
- if ( 'manual' === $display_on ) {
64
- $location = '';
65
- }
66
- $lp_count = max( 1, (int) $lp_count );
67
-
68
- // Global vars
69
- global $wpdb;
70
- global $current_user;
71
- $table_name = $wpdb->prefix . 'hfcm_scripts';
72
-
73
- // Update snippet
74
- if ( isset( $id ) ) {
75
-
76
- $wpdb->update( $table_name, //table
77
- array( // data
78
- 'name' => $name,
79
- 'snippet' => $snippet,
80
- 'device_type' => $device_type,
81
- 'location' => $location,
82
- 'display_on' => $display_on,
83
- 'status' => $status,
84
- 'lp_count' => $lp_count,
85
- 's_pages' => wp_json_encode( $s_pages ),
86
- 's_posts' => wp_json_encode( $s_posts ),
87
- 's_custom_posts' => wp_json_encode( $s_custom_posts ),
88
- 's_categories' => wp_json_encode( $s_categories ),
89
- 's_tags' => wp_json_encode( $s_tags ),
90
- 'last_revision_date' => current_time( 'Y-m-d H:i:s' ),
91
- 'last_modified_by' => sanitize_text_field( $current_user->display_name )
92
- ),
93
- array( // where
94
- 'script_id' => $id
95
- ),
96
- array( // data format
97
- '%s',
98
- '%s',
99
- '%s',
100
- '%s',
101
- '%s',
102
- '%s'
103
- ),
104
- array( // where format
105
- '%s'
106
- )
107
- );
108
- hfcm_redirect( admin_url( 'admin.php?page=hfcm-update&message=1&id=' . $id ) );
109
- } else {
110
- // Create new snippet
111
- $wpdb->insert( $table_name, //table
112
- array(
113
- 'name' => $name,
114
- 'snippet' => $snippet,
115
- 'device_type' => $device_type,
116
- 'location' => $location,
117
- 'display_on' => $display_on,
118
- 'status' => $status,
119
- 'lp_count' => $lp_count,
120
- 's_pages' => wp_json_encode( $s_pages ),
121
- 's_posts' => wp_json_encode( $s_posts ),
122
- 's_custom_posts' => wp_json_encode( $s_custom_posts ),
123
- 's_categories' => wp_json_encode( $s_categories ),
124
- 's_tags' => wp_json_encode( $s_tags ),
125
- 'created' => current_time( 'Y-m-d H:i:s' ),
126
- 'created_by' => sanitize_text_field( $current_user->display_name )
127
- ), array(
128
- '%s',
129
- '%s',
130
- '%s',
131
- '%s',
132
- '%s',
133
- '%s',
134
- '%d',
135
- '%s',
136
- '%s',
137
- '%s',
138
- '%s',
139
- '%s',
140
- '%s',
141
- '%s'
142
- )
143
- );
144
- $lastid = $wpdb->insert_id;
145
- hfcm_redirect( admin_url( 'admin.php?page=hfcm-update&message=6&id=' . $lastid ) );
146
-
147
-
148
- }
149
- // JSON return posts for AJAX
150
- } elseif ( isset( $_POST['get_posts'] ) ) {
151
-
152
- // Check nonce
153
- check_ajax_referer( 'hfcm-get-posts', 'security' );
154
-
155
- // Global vars
156
- global $wpdb;
157
- $table_name = $wpdb->prefix . 'hfcm_scripts';
158
-
159
- // Get all selected posts
160
- if ( -1 === $id ) {
161
- $s_posts = array();
162
- } else {
163
-
164
- // Select value to update
165
- $script = $wpdb->get_results( $wpdb->prepare( "SELECT s_posts from $table_name where script_id=%s", $id ) );
166
- foreach ($script as $s) {
167
- $s_posts = json_decode( $s->s_posts );
168
- if ( !is_array( $s_posts ) ) {
169
- $s_posts = array();
170
- }
171
- }
172
-
173
- }
174
-
175
- // Get all posts
176
- $args = array(
177
- 'public' => true,
178
- '_builtin' => false,
179
- );
180
-
181
- $output = 'names'; // names or objects, note names is the default
182
- $operator = 'and'; // 'and' or 'or'
183
-
184
- $c_posttypes = get_post_types($args, $output, $operator);
185
- $posttypes = array('post');
186
- foreach ($c_posttypes as $cpdata) {
187
- $posttypes[] = $cpdata;
188
- }
189
- $posts = get_posts(array('post_type' => $posttypes, 'posts_per_page' => -1, 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC'));
190
-
191
- $json_output = array(
192
- 'selected' => array(),
193
- 'posts' => array()
194
- );
195
-
196
- foreach ($posts as $pdata) {
197
-
198
- if ( in_array( $pdata->ID, $s_posts ) ) {
199
- $json_output['selected'][] = $pdata->ID;
200
- }
201
- $json_output['posts'][] = array(
202
- 'text' => sanitize_text_field( $pdata->post_title ),
203
- 'value' => $pdata->ID,
204
- );
205
-
206
- }
207
-
208
- echo wp_json_encode( $json_output );
209
- wp_die();
210
-
211
- }
212
- }
 
 
 
 
 
1
+ <?php
2
+
3
+ function hfcm_request_handler() {
4
+
5
+ // Check user capabilities
6
+ current_user_can( 'administrator' );
7
+
8
+ if ( isset( $_POST['insert'] ) ) {
9
+ // Check nonce
10
+ check_admin_referer( 'create-snippet' );
11
+ } else {
12
+ if ( ! isset( $_REQUEST['id'] ) ) {
13
+ die( 'Missing ID parameter.' );
14
+ }
15
+ $id = (int) $_REQUEST['id'];
16
+ }
17
+ if ( isset( $_POST['update'] ) ) {
18
+ // Check nonce
19
+ check_admin_referer( 'update-snippet_' . $id );
20
+ }
21
+
22
+ // Handle AJAX on/off toggle for snippets
23
+ if ( isset( $_REQUEST['toggle'] ) && ! empty( $_REQUEST['togvalue'] ) ) {
24
+
25
+ // Check nonce
26
+ check_ajax_referer( 'hfcm-toggle-snippet', 'security' );
27
+
28
+ if ( 'on' === $_REQUEST['togvalue'] ) {
29
+ $status = 'active';
30
+ } else {
31
+ $status = 'inactive';
32
+ }
33
+
34
+ // Global vars
35
+ global $wpdb;
36
+ $table_name = $wpdb->prefix . 'hfcm_scripts';
37
+
38
+ $wpdb->update(
39
+ $table_name, //table
40
+ array( 'status' => $status ), //data
41
+ array( 'script_id' => $id ), //where
42
+ array( '%s', '%s', '%s', '%s', '%s', '%s' ), //data format
43
+ array( '%s' ) //where format
44
+ );
45
+
46
+ } elseif ( isset( $_POST['insert'] ) || isset( $_POST['update'] ) ) {
47
+
48
+ // Create / update snippet
49
+
50
+ // Sanitize fields
51
+ $name = hfcm_sanitize_text( 'name' );
52
+ $snippet = hfcm_sanitize_text( 'snippet', false );
53
+ $device_type = hfcm_sanitize_text( 'device_type' );
54
+ $display_on = hfcm_sanitize_text( 'display_on' );
55
+ $location = hfcm_sanitize_text( 'location' );
56
+ $lp_count = hfcm_sanitize_text( 'lp_count' );
57
+ $status = hfcm_sanitize_text( 'status' );
58
+ $s_pages = hfcm_sanitize_array( 's_pages' );
59
+ $s_posts = hfcm_sanitize_array( 's_posts' );
60
+ $s_custom_posts = hfcm_sanitize_array( 's_custom_posts', 'string' );
61
+ $s_categories = hfcm_sanitize_array( 's_categories' );
62
+ $s_tags = hfcm_sanitize_array( 's_tags' );
63
+
64
+ if ( 'manual' === $display_on ) {
65
+ $location = '';
66
+ }
67
+ $lp_count = max( 1, (int) $lp_count );
68
+
69
+ // Global vars
70
+ global $wpdb;
71
+ global $current_user;
72
+ $table_name = $wpdb->prefix . 'hfcm_scripts';
73
+
74
+ // Update snippet
75
+ if ( isset( $id ) ) {
76
+
77
+ $wpdb->update( $table_name, //table
78
+ // Data
79
+ array(
80
+ 'name' => $name,
81
+ 'snippet' => $snippet,
82
+ 'device_type' => $device_type,
83
+ 'location' => $location,
84
+ 'display_on' => $display_on,
85
+ 'status' => $status,
86
+ 'lp_count' => $lp_count,
87
+ 's_pages' => wp_json_encode( $s_pages ),
88
+ 's_posts' => wp_json_encode( $s_posts ),
89
+ 's_custom_posts' => wp_json_encode( $s_custom_posts ),
90
+ 's_categories' => wp_json_encode( $s_categories ),
91
+ 's_tags' => wp_json_encode( $s_tags ),
92
+ 'last_revision_date' => current_time( 'Y-m-d H:i:s' ),
93
+ 'last_modified_by' => sanitize_text_field( $current_user->display_name ),
94
+ ),
95
+ // Where
96
+ array( 'script_id' => $id ),
97
+ // Data format
98
+ array(
99
+ '%s',
100
+ '%s',
101
+ '%s',
102
+ '%s',
103
+ '%s',
104
+ '%s',
105
+ ),
106
+ // Where format
107
+ array( '%s' )
108
+ );
109
+ hfcm_redirect( admin_url( 'admin.php?page=hfcm-update&message=1&id=' . $id ) );
110
+ } else {
111
+
112
+ // Create new snippet
113
+ $wpdb->insert( $table_name, //table
114
+ array(
115
+ 'name' => $name,
116
+ 'snippet' => $snippet,
117
+ 'device_type' => $device_type,
118
+ 'location' => $location,
119
+ 'display_on' => $display_on,
120
+ 'status' => $status,
121
+ 'lp_count' => $lp_count,
122
+ 's_pages' => wp_json_encode( $s_pages ),
123
+ 's_posts' => wp_json_encode( $s_posts ),
124
+ 's_custom_posts' => wp_json_encode( $s_custom_posts ),
125
+ 's_categories' => wp_json_encode( $s_categories ),
126
+ 's_tags' => wp_json_encode( $s_tags ),
127
+ 'created' => current_time( 'Y-m-d H:i:s' ),
128
+ 'created_by' => sanitize_text_field( $current_user->display_name ),
129
+ ), array(
130
+ '%s',
131
+ '%s',
132
+ '%s',
133
+ '%s',
134
+ '%s',
135
+ '%s',
136
+ '%d',
137
+ '%s',
138
+ '%s',
139
+ '%s',
140
+ '%s',
141
+ '%s',
142
+ '%s',
143
+ '%s',
144
+ )
145
+ );
146
+ $lastid = $wpdb->insert_id;
147
+ hfcm_redirect( admin_url( 'admin.php?page=hfcm-update&message=6&id=' . $lastid ) );
148
+ }
149
+ } elseif ( isset( $_POST['get_posts'] ) ) {
150
+
151
+ // JSON return posts for AJAX
152
+
153
+ // Check nonce
154
+ check_ajax_referer( 'hfcm-get-posts', 'security' );
155
+
156
+ // Global vars
157
+ global $wpdb;
158
+ $table_name = $wpdb->prefix . 'hfcm_scripts';
159
+
160
+ // Get all selected posts
161
+ if ( -1 === $id ) {
162
+ $s_posts = array();
163
+ } else {
164
+
165
+ // Select value to update
166
+ $script = $wpdb->get_results( $wpdb->prepare( "SELECT s_posts from $table_name where script_id=%s", $id ) );
167
+ foreach ( $script as $s ) {
168
+ $s_posts = json_decode( $s->s_posts );
169
+ if ( ! is_array( $s_posts ) ) {
170
+ $s_posts = array();
171
+ }
172
+ }
173
+ }
174
+
175
+ // Get all posts
176
+ $args = array(
177
+ 'public' => true,
178
+ '_builtin' => false,
179
+ );
180
+
181
+ $output = 'names'; // names or objects, note names is the default
182
+ $operator = 'and'; // 'and' or 'or'
183
+
184
+ $c_posttypes = get_post_types( $args, $output, $operator );
185
+ $posttypes = array( 'post' );
186
+ foreach ( $c_posttypes as $cpdata ) {
187
+ $posttypes[] = $cpdata;
188
+ }
189
+ $posts = get_posts( array(
190
+ 'post_type' => $posttypes,
191
+ 'posts_per_page' => -1,
192
+ 'numberposts' => -1,
193
+ 'orderby' => 'title',
194
+ 'order' => 'ASC',
195
+ ) );
196
+
197
+ $json_output = array(
198
+ 'selected' => array(),
199
+ 'posts' => array(),
200
+ );
201
+
202
+ foreach ( $posts as $pdata ) {
203
+
204
+ if ( in_array( $pdata->ID, $s_posts ) ) {
205
+ $json_output['selected'][] = $pdata->ID;
206
+ }
207
+
208
+ $json_output['posts'][] = array(
209
+ 'text' => sanitize_text_field( $pdata->post_title ),
210
+ 'value' => $pdata->ID,
211
+ );
212
+ }
213
+
214
+ echo wp_json_encode( $json_output );
215
+ wp_die();
216
+ }
217
+ }
includes/hfcm-update.php CHANGED
@@ -1,69 +1,74 @@
1
- <?php
2
-
3
- // function for submenu "Update snippet" page
4
- function hfcm_update() {
5
-
6
- add_action( 'wp_enqueue_scripts', 'hfcm_selectize_enqueue' );
7
-
8
- // check user capabilities
9
- current_user_can('administrator');
10
-
11
- if ( !isset( $_GET['id'] ) ) {
12
- die( 'Missing ID parameter.' );
13
- }
14
- $id = $_GET['id'];
15
-
16
- global $wpdb;
17
- $table_name = $wpdb->prefix . 'hfcm_scripts';
18
-
19
- //selecting value to update
20
- $script = $wpdb->get_results( $wpdb->prepare( "SELECT * from $table_name where script_id=%s", $id ) );
21
- foreach ($script as $s) {
22
- $name = $s->name;
23
- $snippet = $s->snippet;
24
- $device_type = $s->device_type;
25
- $location = $s->location;
26
- $display_on = $s->display_on;
27
- $status = $s->status;
28
- $lp_count = $s->lp_count;
29
- $s_pages = json_decode( $s->s_pages );
30
- if ( !is_array( $s_pages ) ) {
31
- $s_pages = array();
32
- }
33
- $s_posts = json_decode( $s->s_posts );
34
- if ( !is_array( $s_posts ) ) {
35
- $s_posts = array();
36
- }
37
- $s_custom_posts = json_decode( $s->s_custom_posts );
38
- if ( !is_array( $s_custom_posts ) ) {
39
- $s_custom_posts = array();
40
- }
41
- $s_categories = json_decode( $s->s_categories );
42
- if ( !is_array( $s_categories ) ) {
43
- $s_categories = array();
44
- }
45
- $s_tags = json_decode( $s->s_tags );
46
- if ( !is_array( $s_tags ) ) {
47
- $s_tags = array();
48
- }
49
- $createdby = esc_html( $s->created_by );
50
- $lastmodifiedby = esc_html( $s->last_modified_by );
51
- $createdon = esc_html( $s->created );
52
- $lastrevisiondate = esc_html( $s->last_revision_date );
53
- }
54
-
55
- // escape for html output
56
- $name = esc_textarea( $name );
57
- $snippet = esc_textarea( $snippet );
58
- $device_type = esc_html( $device_type );
59
- $location = esc_html( $location );
60
- $display_on = esc_html( $display_on );
61
- $status = esc_html( $status );
62
- $lp_count = esc_html( $lp_count );
63
-
64
- // Notify hfcm-add-edit.php to make necesary changes for update
65
- $update = true;
66
-
67
- require_once( plugin_dir_path( __FILE__ ) . 'hfcm-add-edit.php' );
68
-
69
- }
 
 
 
 
 
1
+ <?php
2
+
3
+ // Function for submenu "Update snippet" page
4
+ function hfcm_update() {
5
+
6
+ add_action( 'wp_enqueue_scripts', 'hfcm_selectize_enqueue' );
7
+
8
+ // check user capabilities
9
+ current_user_can( 'administrator' );
10
+
11
+ if ( ! isset( $_GET['id'] ) ) {
12
+ die( 'Missing ID parameter.' );
13
+ }
14
+ $id = $_GET['id'];
15
+
16
+ global $wpdb;
17
+ $table_name = $wpdb->prefix . 'hfcm_scripts';
18
+
19
+ //selecting value to update
20
+ $script = $wpdb->get_results( $wpdb->prepare( "SELECT * from $table_name where script_id=%s", $id ) );
21
+ foreach ( $script as $s ) {
22
+ $name = $s->name;
23
+ $snippet = $s->snippet;
24
+ $device_type = $s->device_type;
25
+ $location = $s->location;
26
+ $display_on = $s->display_on;
27
+ $status = $s->status;
28
+ $lp_count = $s->lp_count;
29
+ $s_pages = json_decode( $s->s_pages );
30
+
31
+ if ( ! is_array( $s_pages ) ) {
32
+ $s_pages = array();
33
+ }
34
+
35
+ $s_posts = json_decode( $s->s_posts );
36
+ if ( ! is_array( $s_posts ) ) {
37
+ $s_posts = array();
38
+ }
39
+
40
+ $s_custom_posts = json_decode( $s->s_custom_posts );
41
+ if ( ! is_array( $s_custom_posts ) ) {
42
+ $s_custom_posts = array();
43
+ }
44
+
45
+ $s_categories = json_decode( $s->s_categories );
46
+ if ( ! is_array( $s_categories ) ) {
47
+ $s_categories = array();
48
+ }
49
+
50
+ $s_tags = json_decode( $s->s_tags );
51
+ if ( ! is_array( $s_tags ) ) {
52
+ $s_tags = array();
53
+ }
54
+
55
+ $createdby = esc_html( $s->created_by );
56
+ $lastmodifiedby = esc_html( $s->last_modified_by );
57
+ $createdon = esc_html( $s->created );
58
+ $lastrevisiondate = esc_html( $s->last_revision_date );
59
+ }
60
+
61
+ // escape for html output
62
+ $name = esc_textarea( $name );
63
+ $snippet = esc_textarea( $snippet );
64
+ $device_type = esc_html( $device_type );
65
+ $location = esc_html( $location );
66
+ $display_on = esc_html( $display_on );
67
+ $status = esc_html( $status );
68
+ $lp_count = esc_html( $lp_count );
69
+
70
+ // Notify hfcm-add-edit.php to make necesary changes for update
71
+ $update = true;
72
+
73
+ require_once( plugin_dir_path( __FILE__ ) . 'hfcm-add-edit.php' );
74
+ }
js/selectize.min.js CHANGED
@@ -1,3 +1,3 @@
1
- /*! selectize.js - v0.12.1 | https://github.com/brianreavis/selectize.js | Apache License (v2) */
2
- !function(a,b){"function"==typeof define&&define.amd?define("sifter",b):"object"==typeof exports?module.exports=b():a.Sifter=b()}(this,function(){var a=function(a,b){this.items=a,this.settings=b||{diacritics:!0}};a.prototype.tokenize=function(a){if(a=d(String(a||"").toLowerCase()),!a||!a.length)return[];var b,c,f,h,i=[],j=a.split(/ +/);for(b=0,c=j.length;c>b;b++){if(f=e(j[b]),this.settings.diacritics)for(h in g)g.hasOwnProperty(h)&&(f=f.replace(new RegExp(h,"g"),g[h]));i.push({string:j[b],regex:new RegExp(f,"i")})}return i},a.prototype.iterator=function(a,b){var c;c=f(a)?Array.prototype.forEach||function(a){for(var b=0,c=this.length;c>b;b++)a(this[b],b,this)}:function(a){for(var b in this)this.hasOwnProperty(b)&&a(this[b],b,this)},c.apply(a,[b])},a.prototype.getScoreFunction=function(a,b){var c,d,e,f;c=this,a=c.prepareSearch(a,b),e=a.tokens,d=a.options.fields,f=e.length;var g=function(a,b){var c,d;return a?(a=String(a||""),d=a.search(b.regex),-1===d?0:(c=b.string.length/a.length,0===d&&(c+=.5),c)):0},h=function(){var a=d.length;return a?1===a?function(a,b){return g(b[d[0]],a)}:function(b,c){for(var e=0,f=0;a>e;e++)f+=g(c[d[e]],b);return f/a}:function(){return 0}}();return f?1===f?function(a){return h(e[0],a)}:"and"===a.options.conjunction?function(a){for(var b,c=0,d=0;f>c;c++){if(b=h(e[c],a),0>=b)return 0;d+=b}return d/f}:function(a){for(var b=0,c=0;f>b;b++)c+=h(e[b],a);return c/f}:function(){return 0}},a.prototype.getSortFunction=function(a,c){var d,e,f,g,h,i,j,k,l,m,n;if(f=this,a=f.prepareSearch(a,c),n=!a.query&&c.sort_empty||c.sort,l=function(a,b){return"$score"===a?b.score:f.items[b.id][a]},h=[],n)for(d=0,e=n.length;e>d;d++)(a.query||"$score"!==n[d].field)&&h.push(n[d]);if(a.query){for(m=!0,d=0,e=h.length;e>d;d++)if("$score"===h[d].field){m=!1;break}m&&h.unshift({field:"$score",direction:"desc"})}else for(d=0,e=h.length;e>d;d++)if("$score"===h[d].field){h.splice(d,1);break}for(k=[],d=0,e=h.length;e>d;d++)k.push("desc"===h[d].direction?-1:1);return i=h.length,i?1===i?(g=h[0].field,j=k[0],function(a,c){return j*b(l(g,a),l(g,c))}):function(a,c){var d,e,f;for(d=0;i>d;d++)if(f=h[d].field,e=k[d]*b(l(f,a),l(f,c)))return e;return 0}:null},a.prototype.prepareSearch=function(a,b){if("object"==typeof a)return a;b=c({},b);var d=b.fields,e=b.sort,g=b.sort_empty;return d&&!f(d)&&(b.fields=[d]),e&&!f(e)&&(b.sort=[e]),g&&!f(g)&&(b.sort_empty=[g]),{options:b,query:String(a||"").toLowerCase(),tokens:this.tokenize(a),total:0,items:[]}},a.prototype.search=function(a,b){var c,d,e,f,g=this;return d=this.prepareSearch(a,b),b=d.options,a=d.query,f=b.score||g.getScoreFunction(d),a.length?g.iterator(g.items,function(a,e){c=f(a),(b.filter===!1||c>0)&&d.items.push({score:c,id:e})}):g.iterator(g.items,function(a,b){d.items.push({score:1,id:b})}),e=g.getSortFunction(d,b),e&&d.items.sort(e),d.total=d.items.length,"number"==typeof b.limit&&(d.items=d.items.slice(0,b.limit)),d};var b=function(a,b){return"number"==typeof a&&"number"==typeof b?a>b?1:b>a?-1:0:(a=h(String(a||"")),b=h(String(b||"")),a>b?1:b>a?-1:0)},c=function(a){var b,c,d,e;for(b=1,c=arguments.length;c>b;b++)if(e=arguments[b])for(d in e)e.hasOwnProperty(d)&&(a[d]=e[d]);return a},d=function(a){return(a+"").replace(/^\s+|\s+$|/g,"")},e=function(a){return(a+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")},f=Array.isArray||$&&$.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)},g={a:"[aÀÁÂÃÄÅàáâãäåĀāąĄ]",c:"[cÇçćĆčČ]",d:"[dđĐďĎ]",e:"[eÈÉÊËèéêëěĚĒēęĘ]",i:"[iÌÍÎÏìíîïĪī]",l:"[lłŁ]",n:"[nÑñňŇńŃ]",o:"[oÒÓÔÕÕÖØòóôõöøŌō]",r:"[rřŘ]",s:"[sŠšśŚ]",t:"[tťŤ]",u:"[uÙÚÛÜùúûüůŮŪū]",y:"[yŸÿýÝ]",z:"[zŽžżŻźŹ]"},h=function(){var a,b,c,d,e="",f={};for(c in g)if(g.hasOwnProperty(c))for(d=g[c].substring(2,g[c].length-1),e+=d,a=0,b=d.length;b>a;a++)f[d.charAt(a)]=c;var h=new RegExp("["+e+"]","g");return function(a){return a.replace(h,function(a){return f[a]}).toLowerCase()}}();return a}),function(a,b){"function"==typeof define&&define.amd?define("microplugin",b):"object"==typeof exports?module.exports=b():a.MicroPlugin=b()}(this,function(){var a={};a.mixin=function(a){a.plugins={},a.prototype.initializePlugins=function(a){var c,d,e,f=this,g=[];if(f.plugins={names:[],settings:{},requested:{},loaded:{}},b.isArray(a))for(c=0,d=a.length;d>c;c++)"string"==typeof a[c]?g.push(a[c]):(f.plugins.settings[a[c].name]=a[c].options,g.push(a[c].name));else if(a)for(e in a)a.hasOwnProperty(e)&&(f.plugins.settings[e]=a[e],g.push(e));for(;g.length;)f.require(g.shift())},a.prototype.loadPlugin=function(b){var c=this,d=c.plugins,e=a.plugins[b];if(!a.plugins.hasOwnProperty(b))throw new Error('Unable to find "'+b+'" plugin');d.requested[b]=!0,d.loaded[b]=e.fn.apply(c,[c.plugins.settings[b]||{}]),d.names.push(b)},a.prototype.require=function(a){var b=this,c=b.plugins;if(!b.plugins.loaded.hasOwnProperty(a)){if(c.requested[a])throw new Error('Plugin has circular dependency ("'+a+'")');b.loadPlugin(a)}return c.loaded[a]},a.define=function(b,c){a.plugins[b]={name:b,fn:c}}};var b={isArray:Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)}};return a}),function(a,b){"function"==typeof define&&define.amd?define("selectize",["jquery","sifter","microplugin"],b):"object"==typeof exports?module.exports=b(require("jquery"),require("sifter"),require("microplugin")):a.Selectize=b(a.jQuery,a.Sifter,a.MicroPlugin)}(this,function(a,b,c){"use strict";var d=function(a,b){if("string"!=typeof b||b.length){var c="string"==typeof b?new RegExp(b,"i"):b,d=function(a){var b=0;if(3===a.nodeType){var e=a.data.search(c);if(e>=0&&a.data.length>0){var f=a.data.match(c),g=document.createElement("span");g.className="highlight";var h=a.splitText(e),i=(h.splitText(f[0].length),h.cloneNode(!0));g.appendChild(i),h.parentNode.replaceChild(g,h),b=1}}else if(1===a.nodeType&&a.childNodes&&!/(script|style)/i.test(a.tagName))for(var j=0;j<a.childNodes.length;++j)j+=d(a.childNodes[j]);return b};return a.each(function(){d(this)})}},e=function(){};e.prototype={on:function(a,b){this._events=this._events||{},this._events[a]=this._events[a]||[],this._events[a].push(b)},off:function(a,b){var c=arguments.length;return 0===c?delete this._events:1===c?delete this._events[a]:(this._events=this._events||{},void(a in this._events!=!1&&this._events[a].splice(this._events[a].indexOf(b),1)))},trigger:function(a){if(this._events=this._events||{},a in this._events!=!1)for(var b=0;b<this._events[a].length;b++)this._events[a][b].apply(this,Array.prototype.slice.call(arguments,1))}},e.mixin=function(a){for(var b=["on","off","trigger"],c=0;c<b.length;c++)a.prototype[b[c]]=e.prototype[b[c]]};var f=/Mac/.test(navigator.userAgent),g=65,h=13,i=27,j=37,k=38,l=80,m=39,n=40,o=78,p=8,q=46,r=16,s=f?91:17,t=f?18:17,u=9,v=1,w=2,x=!/android/i.test(window.navigator.userAgent)&&!!document.createElement("form").validity,y=function(a){return"undefined"!=typeof a},z=function(a){return"undefined"==typeof a||null===a?null:"boolean"==typeof a?a?"1":"0":a+""},A=function(a){return(a+"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},B=function(a){return(a+"").replace(/\$/g,"$$$$")},C={};C.before=function(a,b,c){var d=a[b];a[b]=function(){return c.apply(a,arguments),d.apply(a,arguments)}},C.after=function(a,b,c){var d=a[b];a[b]=function(){var b=d.apply(a,arguments);return c.apply(a,arguments),b}};var D=function(a){var b=!1;return function(){b||(b=!0,a.apply(this,arguments))}},E=function(a,b){var c;return function(){var d=this,e=arguments;window.clearTimeout(c),c=window.setTimeout(function(){a.apply(d,e)},b)}},F=function(a,b,c){var d,e=a.trigger,f={};a.trigger=function(){var c=arguments[0];return-1===b.indexOf(c)?e.apply(a,arguments):void(f[c]=arguments)},c.apply(a,[]),a.trigger=e;for(d in f)f.hasOwnProperty(d)&&e.apply(a,f[d])},G=function(a,b,c,d){a.on(b,c,function(b){for(var c=b.target;c&&c.parentNode!==a[0];)c=c.parentNode;return b.currentTarget=c,d.apply(this,[b])})},H=function(a){var b={};if("selectionStart"in a)b.start=a.selectionStart,b.length=a.selectionEnd-b.start;else if(document.selection){a.focus();var c=document.selection.createRange(),d=document.selection.createRange().text.length;c.moveStart("character",-a.value.length),b.start=c.text.length-d,b.length=d}return b},I=function(a,b,c){var d,e,f={};if(c)for(d=0,e=c.length;e>d;d++)f[c[d]]=a.css(c[d]);else f=a.css();b.css(f)},J=function(b,c){if(!b)return 0;var d=a("<test>").css({position:"absolute",top:-99999,left:-99999,width:"auto",padding:0,whiteSpace:"pre"}).text(b).appendTo("body");I(c,d,["letterSpacing","fontSize","fontFamily","fontWeight","textTransform"]);var e=d.width();return d.remove(),e},K=function(a){var b=null,c=function(c,d){var e,f,g,h,i,j,k,l;c=c||window.event||{},d=d||{},c.metaKey||c.altKey||(d.force||a.data("grow")!==!1)&&(e=a.val(),c.type&&"keydown"===c.type.toLowerCase()&&(f=c.keyCode,g=f>=97&&122>=f||f>=65&&90>=f||f>=48&&57>=f||32===f,f===q||f===p?(l=H(a[0]),l.length?e=e.substring(0,l.start)+e.substring(l.start+l.length):f===p&&l.start?e=e.substring(0,l.start-1)+e.substring(l.start+1):f===q&&"undefined"!=typeof l.start&&(e=e.substring(0,l.start)+e.substring(l.start+1))):g&&(j=c.shiftKey,k=String.fromCharCode(c.keyCode),k=j?k.toUpperCase():k.toLowerCase(),e+=k)),h=a.attr("placeholder"),!e&&h&&(e=h),i=J(e,a)+4,i!==b&&(b=i,a.width(i),a.triggerHandler("resize")))};a.on("keydown keyup update blur",c),c()},L=function(c,d){var e,f,g,h,i=this;h=c[0],h.selectize=i;var j=window.getComputedStyle&&window.getComputedStyle(h,null);if(g=j?j.getPropertyValue("direction"):h.currentStyle&&h.currentStyle.direction,g=g||c.parents("[dir]:first").attr("dir")||"",a.extend(i,{order:0,settings:d,$input:c,tabIndex:c.attr("tabindex")||"",tagType:"select"===h.tagName.toLowerCase()?v:w,rtl:/rtl/i.test(g),eventNS:".selectize"+ ++L.count,highlightedValue:null,isOpen:!1,isDisabled:!1,isRequired:c.is("[required]"),isInvalid:!1,isLocked:!1,isFocused:!1,isInputHidden:!1,isSetup:!1,isShiftDown:!1,isCmdDown:!1,isCtrlDown:!1,ignoreFocus:!1,ignoreBlur:!1,ignoreHover:!1,hasOptions:!1,currentResults:null,lastValue:"",caretPos:0,loading:0,loadedSearches:{},$activeOption:null,$activeItems:[],optgroups:{},options:{},userOptions:{},items:[],renderCache:{},onSearchChange:null===d.loadThrottle?i.onSearchChange:E(i.onSearchChange,d.loadThrottle)}),i.sifter=new b(this.options,{diacritics:d.diacritics}),i.settings.options){for(e=0,f=i.settings.options.length;f>e;e++)i.registerOption(i.settings.options[e]);delete i.settings.options}if(i.settings.optgroups){for(e=0,f=i.settings.optgroups.length;f>e;e++)i.registerOptionGroup(i.settings.optgroups[e]);delete i.settings.optgroups}i.settings.mode=i.settings.mode||(1===i.settings.maxItems?"single":"multi"),"boolean"!=typeof i.settings.hideSelected&&(i.settings.hideSelected="multi"===i.settings.mode),i.initializePlugins(i.settings.plugins),i.setupCallbacks(),i.setupTemplates(),i.setup()};return e.mixin(L),c.mixin(L),a.extend(L.prototype,{setup:function(){var b,c,d,e,g,h,i,j,k,l=this,m=l.settings,n=l.eventNS,o=a(window),p=a(document),q=l.$input;if(i=l.settings.mode,j=q.attr("class")||"",b=a("<div>").addClass(m.wrapperClass).addClass(j).addClass(i),c=a("<div>").addClass(m.inputClass).addClass("items").appendTo(b),d=a('<input type="text" autocomplete="off" />').appendTo(c).attr("tabindex",q.is(":disabled")?"-1":l.tabIndex),h=a(m.dropdownParent||b),e=a("<div>").addClass(m.dropdownClass).addClass(i).hide().appendTo(h),g=a("<div>").addClass(m.dropdownContentClass).appendTo(e),l.settings.copyClassesToDropdown&&e.addClass(j),b.css({width:q[0].style.width}),l.plugins.names.length&&(k="plugin-"+l.plugins.names.join(" plugin-"),b.addClass(k),e.addClass(k)),(null===m.maxItems||m.maxItems>1)&&l.tagType===v&&q.attr("multiple","multiple"),l.settings.placeholder&&d.attr("placeholder",m.placeholder),!l.settings.splitOn&&l.settings.delimiter){var u=l.settings.delimiter.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&");l.settings.splitOn=new RegExp("\\s*"+u+"+\\s*")}q.attr("autocorrect")&&d.attr("autocorrect",q.attr("autocorrect")),q.attr("autocapitalize")&&d.attr("autocapitalize",q.attr("autocapitalize")),l.$wrapper=b,l.$control=c,l.$control_input=d,l.$dropdown=e,l.$dropdown_content=g,e.on("mouseenter","[data-selectable]",function(){return l.onOptionHover.apply(l,arguments)}),e.on("mousedown click","[data-selectable]",function(){return l.onOptionSelect.apply(l,arguments)}),G(c,"mousedown","*:not(input)",function(){return l.onItemSelect.apply(l,arguments)}),K(d),c.on({mousedown:function(){return l.onMouseDown.apply(l,arguments)},click:function(){return l.onClick.apply(l,arguments)}}),d.on({mousedown:function(a){a.stopPropagation()},keydown:function(){return l.onKeyDown.apply(l,arguments)},keyup:function(){return l.onKeyUp.apply(l,arguments)},keypress:function(){return l.onKeyPress.apply(l,arguments)},resize:function(){l.positionDropdown.apply(l,[])},blur:function(){return l.onBlur.apply(l,arguments)},focus:function(){return l.ignoreBlur=!1,l.onFocus.apply(l,arguments)},paste:function(){return l.onPaste.apply(l,arguments)}}),p.on("keydown"+n,function(a){l.isCmdDown=a[f?"metaKey":"ctrlKey"],l.isCtrlDown=a[f?"altKey":"ctrlKey"],l.isShiftDown=a.shiftKey}),p.on("keyup"+n,function(a){a.keyCode===t&&(l.isCtrlDown=!1),a.keyCode===r&&(l.isShiftDown=!1),a.keyCode===s&&(l.isCmdDown=!1)}),p.on("mousedown"+n,function(a){if(l.isFocused){if(a.target===l.$dropdown[0]||a.target.parentNode===l.$dropdown[0])return!1;l.$control.has(a.target).length||a.target===l.$control[0]||l.blur(a.target)}}),o.on(["scroll"+n,"resize"+n].join(" "),function(){l.isOpen&&l.positionDropdown.apply(l,arguments)}),o.on("mousemove"+n,function(){l.ignoreHover=!1}),this.revertSettings={$children:q.children().detach(),tabindex:q.attr("tabindex")},q.attr("tabindex",-1).hide().after(l.$wrapper),a.isArray(m.items)&&(l.setValue(m.items),delete m.items),x&&q.on("invalid"+n,function(a){a.preventDefault(),l.isInvalid=!0,l.refreshState()}),l.updateOriginalInput(),l.refreshItems(),l.refreshState(),l.updatePlaceholder(),l.isSetup=!0,q.is(":disabled")&&l.disable(),l.on("change",this.onChange),q.data("selectize",l),q.addClass("selectized"),l.trigger("initialize"),m.preload===!0&&l.onSearchChange("")},setupTemplates:function(){var b=this,c=b.settings.labelField,d=b.settings.optgroupLabelField,e={optgroup:function(a){return'<div class="optgroup">'+a.html+"</div>"},optgroup_header:function(a,b){return'<div class="optgroup-header">'+b(a[d])+"</div>"},option:function(a,b){return'<div class="option">'+b(a[c])+"</div>"},item:function(a,b){return'<div class="item">'+b(a[c])+"</div>"},option_create:function(a,b){return'<div class="create">Add <strong>'+b(a.input)+"</strong>&hellip;</div>"}};b.settings.render=a.extend({},e,b.settings.render)},setupCallbacks:function(){var a,b,c={initialize:"onInitialize",change:"onChange",item_add:"onItemAdd",item_remove:"onItemRemove",clear:"onClear",option_add:"onOptionAdd",option_remove:"onOptionRemove",option_clear:"onOptionClear",optgroup_add:"onOptionGroupAdd",optgroup_remove:"onOptionGroupRemove",optgroup_clear:"onOptionGroupClear",dropdown_open:"onDropdownOpen",dropdown_close:"onDropdownClose",type:"onType",load:"onLoad",focus:"onFocus",blur:"onBlur"};for(a in c)c.hasOwnProperty(a)&&(b=this.settings[c[a]],b&&this.on(a,b))},onClick:function(a){var b=this;b.isFocused||(b.focus(),a.preventDefault())},onMouseDown:function(b){{var c=this,d=b.isDefaultPrevented();a(b.target)}if(c.isFocused){if(b.target!==c.$control_input[0])return"single"===c.settings.mode?c.isOpen?c.close():c.open():d||c.setActiveItem(null),!1}else d||window.setTimeout(function(){c.focus()},0)},onChange:function(){this.$input.trigger("change")},onPaste:function(b){var c=this;c.isFull()||c.isInputHidden||c.isLocked?b.preventDefault():c.settings.splitOn&&setTimeout(function(){for(var b=a.trim(c.$control_input.val()||"").split(c.settings.splitOn),d=0,e=b.length;e>d;d++)c.createItem(b[d])},0)},onKeyPress:function(a){if(this.isLocked)return a&&a.preventDefault();var b=String.fromCharCode(a.keyCode||a.which);return this.settings.create&&"multi"===this.settings.mode&&b===this.settings.delimiter?(this.createItem(),a.preventDefault(),!1):void 0},onKeyDown:function(a){var b=(a.target===this.$control_input[0],this);if(b.isLocked)return void(a.keyCode!==u&&a.preventDefault());switch(a.keyCode){case g:if(b.isCmdDown)return void b.selectAll();break;case i:return void(b.isOpen&&(a.preventDefault(),a.stopPropagation(),b.close()));case o:if(!a.ctrlKey||a.altKey)break;case n:if(!b.isOpen&&b.hasOptions)b.open();else if(b.$activeOption){b.ignoreHover=!0;var c=b.getAdjacentOption(b.$activeOption,1);c.length&&b.setActiveOption(c,!0,!0)}return void a.preventDefault();case l:if(!a.ctrlKey||a.altKey)break;case k:if(b.$activeOption){b.ignoreHover=!0;var d=b.getAdjacentOption(b.$activeOption,-1);d.length&&b.setActiveOption(d,!0,!0)}return void a.preventDefault();case h:return void(b.isOpen&&b.$activeOption&&(b.onOptionSelect({currentTarget:b.$activeOption}),a.preventDefault()));case j:return void b.advanceSelection(-1,a);case m:return void b.advanceSelection(1,a);case u:return b.settings.selectOnTab&&b.isOpen&&b.$activeOption&&(b.onOptionSelect({currentTarget:b.$activeOption}),b.isFull()||a.preventDefault()),void(b.settings.create&&b.createItem()&&a.preventDefault());case p:case q:return void b.deleteSelection(a)}return!b.isFull()&&!b.isInputHidden||(f?a.metaKey:a.ctrlKey)?void 0:void a.preventDefault()},onKeyUp:function(a){var b=this;if(b.isLocked)return a&&a.preventDefault();var c=b.$control_input.val()||"";b.lastValue!==c&&(b.lastValue=c,b.onSearchChange(c),b.refreshOptions(),b.trigger("type",c))},onSearchChange:function(a){var b=this,c=b.settings.load;c&&(b.loadedSearches.hasOwnProperty(a)||(b.loadedSearches[a]=!0,b.load(function(d){c.apply(b,[a,d])})))},onFocus:function(a){var b=this,c=b.isFocused;return b.isDisabled?(b.blur(),a&&a.preventDefault(),!1):void(b.ignoreFocus||(b.isFocused=!0,"focus"===b.settings.preload&&b.onSearchChange(""),c||b.trigger("focus"),b.$activeItems.length||(b.showInput(),b.setActiveItem(null),b.refreshOptions(!!b.settings.openOnFocus)),b.refreshState()))},onBlur:function(a,b){var c=this;if(c.isFocused&&(c.isFocused=!1,!c.ignoreFocus)){if(!c.ignoreBlur&&document.activeElement===c.$dropdown_content[0])return c.ignoreBlur=!0,void c.onFocus(a);var d=function(){c.close(),c.setTextboxValue(""),c.setActiveItem(null),c.setActiveOption(null),c.setCaret(c.items.length),c.refreshState(),(b||document.body).focus(),c.ignoreFocus=!1,c.trigger("blur")};c.ignoreFocus=!0,c.settings.create&&c.settings.createOnBlur?c.createItem(null,!1,d):d()}},onOptionHover:function(a){this.ignoreHover||this.setActiveOption(a.currentTarget,!1)},onOptionSelect:function(b){var c,d,e=this;b.preventDefault&&(b.preventDefault(),b.stopPropagation()),d=a(b.currentTarget),d.hasClass("create")?e.createItem(null,function(){e.settings.closeAfterSelect&&e.close()}):(c=d.attr("data-value"),"undefined"!=typeof c&&(e.lastQuery=null,e.setTextboxValue(""),e.addItem(c),e.settings.closeAfterSelect?e.close():!e.settings.hideSelected&&b.type&&/mouse/.test(b.type)&&e.setActiveOption(e.getOption(c))))},onItemSelect:function(a){var b=this;b.isLocked||"multi"===b.settings.mode&&(a.preventDefault(),b.setActiveItem(a.currentTarget,a))},load:function(a){var b=this,c=b.$wrapper.addClass(b.settings.loadingClass);b.loading++,a.apply(b,[function(a){b.loading=Math.max(b.loading-1,0),a&&a.length&&(b.addOption(a),b.refreshOptions(b.isFocused&&!b.isInputHidden)),b.loading||c.removeClass(b.settings.loadingClass),b.trigger("load",a)}])},setTextboxValue:function(a){var b=this.$control_input,c=b.val()!==a;c&&(b.val(a).triggerHandler("update"),this.lastValue=a)},getValue:function(){return this.tagType===v&&this.$input.attr("multiple")?this.items:this.items.join(this.settings.delimiter)},setValue:function(a,b){var c=b?[]:["change"];F(this,c,function(){this.clear(b),this.addItems(a,b)})},setActiveItem:function(b,c){var d,e,f,g,h,i,j,k,l=this;if("single"!==l.settings.mode){if(b=a(b),!b.length)return a(l.$activeItems).removeClass("active"),l.$activeItems=[],void(l.isFocused&&l.showInput());if(d=c&&c.type.toLowerCase(),"mousedown"===d&&l.isShiftDown&&l.$activeItems.length){for(k=l.$control.children(".active:last"),g=Array.prototype.indexOf.apply(l.$control[0].childNodes,[k[0]]),h=Array.prototype.indexOf.apply(l.$control[0].childNodes,[b[0]]),g>h&&(j=g,g=h,h=j),e=g;h>=e;e++)i=l.$control[0].childNodes[e],-1===l.$activeItems.indexOf(i)&&(a(i).addClass("active"),l.$activeItems.push(i));c.preventDefault()}else"mousedown"===d&&l.isCtrlDown||"keydown"===d&&this.isShiftDown?b.hasClass("active")?(f=l.$activeItems.indexOf(b[0]),l.$activeItems.splice(f,1),b.removeClass("active")):l.$activeItems.push(b.addClass("active")[0]):(a(l.$activeItems).removeClass("active"),l.$activeItems=[b.addClass("active")[0]]);l.hideInput(),this.isFocused||l.focus()}},setActiveOption:function(b,c,d){var e,f,g,h,i,j=this;j.$activeOption&&j.$activeOption.removeClass("active"),j.$activeOption=null,b=a(b),b.length&&(j.$activeOption=b.addClass("active"),(c||!y(c))&&(e=j.$dropdown_content.height(),f=j.$activeOption.outerHeight(!0),c=j.$dropdown_content.scrollTop()||0,g=j.$activeOption.offset().top-j.$dropdown_content.offset().top+c,h=g,i=g-e+f,g+f>e+c?j.$dropdown_content.stop().animate({scrollTop:i},d?j.settings.scrollDuration:0):c>g&&j.$dropdown_content.stop().animate({scrollTop:h},d?j.settings.scrollDuration:0)))},selectAll:function(){var a=this;"single"!==a.settings.mode&&(a.$activeItems=Array.prototype.slice.apply(a.$control.children(":not(input)").addClass("active")),a.$activeItems.length&&(a.hideInput(),a.close()),a.focus())},hideInput:function(){var a=this;a.setTextboxValue(""),a.$control_input.css({opacity:0,position:"absolute",left:a.rtl?1e4:-1e4}),a.isInputHidden=!0},showInput:function(){this.$control_input.css({opacity:1,position:"relative",left:0}),this.isInputHidden=!1},focus:function(){var a=this;a.isDisabled||(a.ignoreFocus=!0,a.$control_input[0].focus(),window.setTimeout(function(){a.ignoreFocus=!1,a.onFocus()},0))},blur:function(a){this.$control_input[0].blur(),this.onBlur(null,a)},getScoreFunction:function(a){return this.sifter.getScoreFunction(a,this.getSearchOptions())},getSearchOptions:function(){var a=this.settings,b=a.sortField;return"string"==typeof b&&(b=[{field:b}]),{fields:a.searchField,conjunction:a.searchConjunction,sort:b}},search:function(b){var c,d,e,f=this,g=f.settings,h=this.getSearchOptions();if(g.score&&(e=f.settings.score.apply(this,[b]),"function"!=typeof e))throw new Error('Selectize "score" setting must be a function that returns a function');if(b!==f.lastQuery?(f.lastQuery=b,d=f.sifter.search(b,a.extend(h,{score:e})),f.currentResults=d):d=a.extend(!0,{},f.currentResults),g.hideSelected)for(c=d.items.length-1;c>=0;c--)-1!==f.items.indexOf(z(d.items[c].id))&&d.items.splice(c,1);return d},refreshOptions:function(b){var c,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s;"undefined"==typeof b&&(b=!0);var t=this,u=a.trim(t.$control_input.val()),v=t.search(u),w=t.$dropdown_content,x=t.$activeOption&&z(t.$activeOption.attr("data-value"));for(g=v.items.length,"number"==typeof t.settings.maxOptions&&(g=Math.min(g,t.settings.maxOptions)),h={},i=[],c=0;g>c;c++)for(j=t.options[v.items[c].id],k=t.render("option",j),l=j[t.settings.optgroupField]||"",m=a.isArray(l)?l:[l],e=0,f=m&&m.length;f>e;e++)l=m[e],t.optgroups.hasOwnProperty(l)||(l=""),h.hasOwnProperty(l)||(h[l]=[],i.push(l)),h[l].push(k);for(this.settings.lockOptgroupOrder&&i.sort(function(a,b){var c=t.optgroups[a].$order||0,d=t.optgroups[b].$order||0;return c-d}),n=[],c=0,g=i.length;g>c;c++)l=i[c],t.optgroups.hasOwnProperty(l)&&h[l].length?(o=t.render("optgroup_header",t.optgroups[l])||"",o+=h[l].join(""),n.push(t.render("optgroup",a.extend({},t.optgroups[l],{html:o})))):n.push(h[l].join(""));if(w.html(n.join("")),t.settings.highlight&&v.query.length&&v.tokens.length)for(c=0,g=v.tokens.length;g>c;c++)d(w,v.tokens[c].regex);if(!t.settings.hideSelected)for(c=0,g=t.items.length;g>c;c++)t.getOption(t.items[c]).addClass("selected");p=t.canCreate(u),p&&(w.prepend(t.render("option_create",{input:u})),s=a(w[0].childNodes[0])),t.hasOptions=v.items.length>0||p,t.hasOptions?(v.items.length>0?(r=x&&t.getOption(x),r&&r.length?q=r:"single"===t.settings.mode&&t.items.length&&(q=t.getOption(t.items[0])),q&&q.length||(q=s&&!t.settings.addPrecedence?t.getAdjacentOption(s,1):w.find("[data-selectable]:first"))):q=s,t.setActiveOption(q),b&&!t.isOpen&&t.open()):(t.setActiveOption(null),b&&t.isOpen&&t.close())},addOption:function(b){var c,d,e,f=this;if(a.isArray(b))for(c=0,d=b.length;d>c;c++)f.addOption(b[c]);else(e=f.registerOption(b))&&(f.userOptions[e]=!0,f.lastQuery=null,f.trigger("option_add",e,b))},registerOption:function(a){var b=z(a[this.settings.valueField]);return!b||this.options.hasOwnProperty(b)?!1:(a.$order=a.$order||++this.order,this.options[b]=a,b)},registerOptionGroup:function(a){var b=z(a[this.settings.optgroupValueField]);return b?(a.$order=a.$order||++this.order,this.optgroups[b]=a,b):!1},addOptionGroup:function(a,b){b[this.settings.optgroupValueField]=a,(a=this.registerOptionGroup(b))&&this.trigger("optgroup_add",a,b)},removeOptionGroup:function(a){this.optgroups.hasOwnProperty(a)&&(delete this.optgroups[a],this.renderCache={},this.trigger("optgroup_remove",a))},clearOptionGroups:function(){this.optgroups={},this.renderCache={},this.trigger("optgroup_clear")},updateOption:function(b,c){var d,e,f,g,h,i,j,k=this;if(b=z(b),f=z(c[k.settings.valueField]),null!==b&&k.options.hasOwnProperty(b)){if("string"!=typeof f)throw new Error("Value must be set in option data");j=k.options[b].$order,f!==b&&(delete k.options[b],g=k.items.indexOf(b),-1!==g&&k.items.splice(g,1,f)),c.$order=c.$order||j,k.options[f]=c,h=k.renderCache.item,i=k.renderCache.option,h&&(delete h[b],delete h[f]),i&&(delete i[b],delete i[f]),-1!==k.items.indexOf(f)&&(d=k.getItem(b),e=a(k.render("item",c)),d.hasClass("active")&&e.addClass("active"),d.replaceWith(e)),k.lastQuery=null,k.isOpen&&k.refreshOptions(!1)}},removeOption:function(a,b){var c=this;a=z(a);var d=c.renderCache.item,e=c.renderCache.option;d&&delete d[a],e&&delete e[a],delete c.userOptions[a],delete c.options[a],c.lastQuery=null,c.trigger("option_remove",a),c.removeItem(a,b)},clearOptions:function(){var a=this;a.loadedSearches={},a.userOptions={},a.renderCache={},a.options=a.sifter.items={},a.lastQuery=null,a.trigger("option_clear"),a.clear()},getOption:function(a){return this.getElementWithValue(a,this.$dropdown_content.find("[data-selectable]"))},getAdjacentOption:function(b,c){var d=this.$dropdown.find("[data-selectable]"),e=d.index(b)+c;return e>=0&&e<d.length?d.eq(e):a()},getElementWithValue:function(b,c){if(b=z(b),"undefined"!=typeof b&&null!==b)for(var d=0,e=c.length;e>d;d++)if(c[d].getAttribute("data-value")===b)return a(c[d]);return a()},getItem:function(a){return this.getElementWithValue(a,this.$control.children())},addItems:function(b,c){for(var d=a.isArray(b)?b:[b],e=0,f=d.length;f>e;e++)this.isPending=f-1>e,this.addItem(d[e],c)},addItem:function(b,c){var d=c?[]:["change"];F(this,d,function(){var d,e,f,g,h,i=this,j=i.settings.mode;return b=z(b),-1!==i.items.indexOf(b)?void("single"===j&&i.close()):void(i.options.hasOwnProperty(b)&&("single"===j&&i.clear(c),"multi"===j&&i.isFull()||(d=a(i.render("item",i.options[b])),h=i.isFull(),i.items.splice(i.caretPos,0,b),i.insertAtCaret(d),(!i.isPending||!h&&i.isFull())&&i.refreshState(),i.isSetup&&(f=i.$dropdown_content.find("[data-selectable]"),i.isPending||(e=i.getOption(b),g=i.getAdjacentOption(e,1).attr("data-value"),i.refreshOptions(i.isFocused&&"single"!==j),g&&i.setActiveOption(i.getOption(g))),!f.length||i.isFull()?i.close():i.positionDropdown(),i.updatePlaceholder(),i.trigger("item_add",b,d),i.updateOriginalInput({silent:c})))))})},removeItem:function(a,b){var c,d,e,f=this;c="object"==typeof a?a:f.getItem(a),a=z(c.attr("data-value")),d=f.items.indexOf(a),-1!==d&&(c.remove(),c.hasClass("active")&&(e=f.$activeItems.indexOf(c[0]),f.$activeItems.splice(e,1)),f.items.splice(d,1),f.lastQuery=null,!f.settings.persist&&f.userOptions.hasOwnProperty(a)&&f.removeOption(a,b),d<f.caretPos&&f.setCaret(f.caretPos-1),f.refreshState(),f.updatePlaceholder(),f.updateOriginalInput({silent:b}),f.positionDropdown(),f.trigger("item_remove",a,c))},createItem:function(b,c){var d=this,e=d.caretPos;b=b||a.trim(d.$control_input.val()||"");var f=arguments[arguments.length-1];if("function"!=typeof f&&(f=function(){}),"boolean"!=typeof c&&(c=!0),!d.canCreate(b))return f(),!1;d.lock();var g="function"==typeof d.settings.create?this.settings.create:function(a){var b={};return b[d.settings.labelField]=a,b[d.settings.valueField]=a,b},h=D(function(a){if(d.unlock(),!a||"object"!=typeof a)return f();var b=z(a[d.settings.valueField]);return"string"!=typeof b?f():(d.setTextboxValue(""),d.addOption(a),d.setCaret(e),d.addItem(b),d.refreshOptions(c&&"single"!==d.settings.mode),void f(a))}),i=g.apply(this,[b,h]);return"undefined"!=typeof i&&h(i),!0},refreshItems:function(){this.lastQuery=null,this.isSetup&&this.addItem(this.items),this.refreshState(),this.updateOriginalInput()},refreshState:function(){var a,b=this;b.isRequired&&(b.items.length&&(b.isInvalid=!1),b.$control_input.prop("required",a)),b.refreshClasses()},refreshClasses:function(){var b=this,c=b.isFull(),d=b.isLocked;b.$wrapper.toggleClass("rtl",b.rtl),b.$control.toggleClass("focus",b.isFocused).toggleClass("disabled",b.isDisabled).toggleClass("required",b.isRequired).toggleClass("invalid",b.isInvalid).toggleClass("locked",d).toggleClass("full",c).toggleClass("not-full",!c).toggleClass("input-active",b.isFocused&&!b.isInputHidden).toggleClass("dropdown-active",b.isOpen).toggleClass("has-options",!a.isEmptyObject(b.options)).toggleClass("has-items",b.items.length>0),b.$control_input.data("grow",!c&&!d)},isFull:function(){return null!==this.settings.maxItems&&this.items.length>=this.settings.maxItems},updateOriginalInput:function(a){var b,c,d,e,f=this;if(a=a||{},f.tagType===v){for(d=[],b=0,c=f.items.length;c>b;b++)e=f.options[f.items[b]][f.settings.labelField]||"",d.push('<option value="'+A(f.items[b])+'" selected="selected">'+A(e)+"</option>");d.length||this.$input.attr("multiple")||d.push('<option value="" selected="selected"></option>'),f.$input.html(d.join(""))}else f.$input.val(f.getValue()),f.$input.attr("value",f.$input.val());f.isSetup&&(a.silent||f.trigger("change",f.$input.val()))},updatePlaceholder:function(){if(this.settings.placeholder){var a=this.$control_input;this.items.length?a.removeAttr("placeholder"):a.attr("placeholder",this.settings.placeholder),a.triggerHandler("update",{force:!0})}},open:function(){var a=this;a.isLocked||a.isOpen||"multi"===a.settings.mode&&a.isFull()||(a.focus(),a.isOpen=!0,a.refreshState(),a.$dropdown.css({visibility:"hidden",display:"block"}),a.positionDropdown(),a.$dropdown.css({visibility:"visible"}),a.trigger("dropdown_open",a.$dropdown))},close:function(){var a=this,b=a.isOpen;"single"===a.settings.mode&&a.items.length&&a.hideInput(),a.isOpen=!1,a.$dropdown.hide(),a.setActiveOption(null),a.refreshState(),b&&a.trigger("dropdown_close",a.$dropdown)},positionDropdown:function(){var a=this.$control,b="body"===this.settings.dropdownParent?a.offset():a.position();b.top+=a.outerHeight(!0),this.$dropdown.css({width:a.outerWidth(),top:b.top,left:b.left})},clear:function(a){var b=this;b.items.length&&(b.$control.children(":not(input)").remove(),b.items=[],b.lastQuery=null,b.setCaret(0),b.setActiveItem(null),b.updatePlaceholder(),b.updateOriginalInput({silent:a}),b.refreshState(),b.showInput(),b.trigger("clear"))},insertAtCaret:function(b){var c=Math.min(this.caretPos,this.items.length);0===c?this.$control.prepend(b):a(this.$control[0].childNodes[c]).before(b),this.setCaret(c+1)},deleteSelection:function(b){var c,d,e,f,g,h,i,j,k,l=this;if(e=b&&b.keyCode===p?-1:1,f=H(l.$control_input[0]),l.$activeOption&&!l.settings.hideSelected&&(i=l.getAdjacentOption(l.$activeOption,-1).attr("data-value")),g=[],l.$activeItems.length){for(k=l.$control.children(".active:"+(e>0?"last":"first")),h=l.$control.children(":not(input)").index(k),e>0&&h++,c=0,d=l.$activeItems.length;d>c;c++)g.push(a(l.$activeItems[c]).attr("data-value"));
3
  b&&(b.preventDefault(),b.stopPropagation())}else(l.isFocused||"single"===l.settings.mode)&&l.items.length&&(0>e&&0===f.start&&0===f.length?g.push(l.items[l.caretPos-1]):e>0&&f.start===l.$control_input.val().length&&g.push(l.items[l.caretPos]));if(!g.length||"function"==typeof l.settings.onDelete&&l.settings.onDelete.apply(l,[g])===!1)return!1;for("undefined"!=typeof h&&l.setCaret(h);g.length;)l.removeItem(g.pop());return l.showInput(),l.positionDropdown(),l.refreshOptions(!0),i&&(j=l.getOption(i),j.length&&l.setActiveOption(j)),!0},advanceSelection:function(a,b){var c,d,e,f,g,h,i=this;0!==a&&(i.rtl&&(a*=-1),c=a>0?"last":"first",d=H(i.$control_input[0]),i.isFocused&&!i.isInputHidden?(f=i.$control_input.val().length,g=0>a?0===d.start&&0===d.length:d.start===f,g&&!f&&i.advanceCaret(a,b)):(h=i.$control.children(".active:"+c),h.length&&(e=i.$control.children(":not(input)").index(h),i.setActiveItem(null),i.setCaret(a>0?e+1:e))))},advanceCaret:function(a,b){var c,d,e=this;0!==a&&(c=a>0?"next":"prev",e.isShiftDown?(d=e.$control_input[c](),d.length&&(e.hideInput(),e.setActiveItem(d),b&&b.preventDefault())):e.setCaret(e.caretPos+a))},setCaret:function(b){var c=this;if(b="single"===c.settings.mode?c.items.length:Math.max(0,Math.min(c.items.length,b)),!c.isPending){var d,e,f,g;for(f=c.$control.children(":not(input)"),d=0,e=f.length;e>d;d++)g=a(f[d]).detach(),b>d?c.$control_input.before(g):c.$control.append(g)}c.caretPos=b},lock:function(){this.close(),this.isLocked=!0,this.refreshState()},unlock:function(){this.isLocked=!1,this.refreshState()},disable:function(){var a=this;a.$input.prop("disabled",!0),a.$control_input.prop("disabled",!0).prop("tabindex",-1),a.isDisabled=!0,a.lock()},enable:function(){var a=this;a.$input.prop("disabled",!1),a.$control_input.prop("disabled",!1).prop("tabindex",a.tabIndex),a.isDisabled=!1,a.unlock()},destroy:function(){var b=this,c=b.eventNS,d=b.revertSettings;b.trigger("destroy"),b.off(),b.$wrapper.remove(),b.$dropdown.remove(),b.$input.html("").append(d.$children).removeAttr("tabindex").removeClass("selectized").attr({tabindex:d.tabindex}).show(),b.$control_input.removeData("grow"),b.$input.removeData("selectize"),a(window).off(c),a(document).off(c),a(document.body).off(c),delete b.$input[0].selectize},render:function(a,b){var c,d,e="",f=!1,g=this,h=/^[\t \r\n]*<([a-z][a-z0-9\-_]*(?:\:[a-z][a-z0-9\-_]*)?)/i;return("option"===a||"item"===a)&&(c=z(b[g.settings.valueField]),f=!!c),f&&(y(g.renderCache[a])||(g.renderCache[a]={}),g.renderCache[a].hasOwnProperty(c))?g.renderCache[a][c]:(e=g.settings.render[a].apply(this,[b,A]),("option"===a||"option_create"===a)&&(e=e.replace(h,"<$1 data-selectable")),"optgroup"===a&&(d=b[g.settings.optgroupValueField]||"",e=e.replace(h,'<$1 data-group="'+B(A(d))+'"')),("option"===a||"item"===a)&&(e=e.replace(h,'<$1 data-value="'+B(A(c||""))+'"')),f&&(g.renderCache[a][c]=e),e)},clearCache:function(a){var b=this;"undefined"==typeof a?b.renderCache={}:delete b.renderCache[a]},canCreate:function(a){var b=this;if(!b.settings.create)return!1;var c=b.settings.createFilter;return!(!a.length||"function"==typeof c&&!c.apply(b,[a])||"string"==typeof c&&!new RegExp(c).test(a)||c instanceof RegExp&&!c.test(a))}}),L.count=0,L.defaults={options:[],optgroups:[],plugins:[],delimiter:",",splitOn:null,persist:!0,diacritics:!0,create:!1,createOnBlur:!1,createFilter:null,highlight:!0,openOnFocus:!0,maxOptions:1e3,maxItems:null,hideSelected:null,addPrecedence:!1,selectOnTab:!1,preload:!1,allowEmptyOption:!1,closeAfterSelect:!1,scrollDuration:60,loadThrottle:300,loadingClass:"loading",dataAttr:"data-data",optgroupField:"optgroup",valueField:"value",labelField:"text",optgroupLabelField:"label",optgroupValueField:"value",lockOptgroupOrder:!1,sortField:"$order",searchField:["text"],searchConjunction:"and",mode:null,wrapperClass:"selectize-control",inputClass:"selectize-input",dropdownClass:"selectize-dropdown",dropdownContentClass:"selectize-dropdown-content",dropdownParent:null,copyClassesToDropdown:!0,render:{}},a.fn.selectize=function(b){var c=a.fn.selectize.defaults,d=a.extend({},c,b),e=d.dataAttr,f=d.labelField,g=d.valueField,h=d.optgroupField,i=d.optgroupLabelField,j=d.optgroupValueField,k=function(b,c){var h,i,j,k,l=b.attr(e);if(l)for(c.options=JSON.parse(l),h=0,i=c.options.length;i>h;h++)c.items.push(c.options[h][g]);else{var m=a.trim(b.val()||"");if(!d.allowEmptyOption&&!m.length)return;for(j=m.split(d.delimiter),h=0,i=j.length;i>h;h++)k={},k[f]=j[h],k[g]=j[h],c.options.push(k);c.items=j}},l=function(b,c){var k,l,m,n,o=c.options,p={},q=function(a){var b=e&&a.attr(e);return"string"==typeof b&&b.length?JSON.parse(b):null},r=function(b,e){b=a(b);var i=z(b.attr("value"));if(i||d.allowEmptyOption)if(p.hasOwnProperty(i)){if(e){var j=p[i][h];j?a.isArray(j)?j.push(e):p[i][h]=[j,e]:p[i][h]=e}}else{var k=q(b)||{};k[f]=k[f]||b.text(),k[g]=k[g]||i,k[h]=k[h]||e,p[i]=k,o.push(k),b.is(":selected")&&c.items.push(i)}},s=function(b){var d,e,f,g,h;for(b=a(b),f=b.attr("label"),f&&(g=q(b)||{},g[i]=f,g[j]=f,c.optgroups.push(g)),h=a("option",b),d=0,e=h.length;e>d;d++)r(h[d],f)};for(c.maxItems=b.attr("multiple")?null:1,n=b.children(),k=0,l=n.length;l>k;k++)m=n[k].tagName.toLowerCase(),"optgroup"===m?s(n[k]):"option"===m&&r(n[k])};return this.each(function(){if(!this.selectize){var e,f=a(this),g=this.tagName.toLowerCase(),h=f.attr("placeholder")||f.attr("data-placeholder");h||d.allowEmptyOption||(h=f.children('option[value=""]').text());var i={placeholder:h,options:[],optgroups:[],items:[]};"select"===g?l(f,i):k(f,i),e=new L(f,a.extend(!0,{},c,i,b))}})},a.fn.selectize.defaults=L.defaults,a.fn.selectize.support={validity:x},L.define("drag_drop",function(){if(!a.fn.sortable)throw new Error('The "drag_drop" plugin requires jQuery UI "sortable".');if("multi"===this.settings.mode){var b=this;b.lock=function(){var a=b.lock;return function(){var c=b.$control.data("sortable");return c&&c.disable(),a.apply(b,arguments)}}(),b.unlock=function(){var a=b.unlock;return function(){var c=b.$control.data("sortable");return c&&c.enable(),a.apply(b,arguments)}}(),b.setup=function(){var c=b.setup;return function(){c.apply(this,arguments);var d=b.$control.sortable({items:"[data-value]",forcePlaceholderSize:!0,disabled:b.isLocked,start:function(a,b){b.placeholder.css("width",b.helper.css("width")),d.css({overflow:"visible"})},stop:function(){d.css({overflow:"hidden"});var c=b.$activeItems?b.$activeItems.slice():null,e=[];d.children("[data-value]").each(function(){e.push(a(this).attr("data-value"))}),b.setValue(e),b.setActiveItem(c)}})}}()}}),L.define("dropdown_header",function(b){var c=this;b=a.extend({title:"Untitled",headerClass:"selectize-dropdown-header",titleRowClass:"selectize-dropdown-header-title",labelClass:"selectize-dropdown-header-label",closeClass:"selectize-dropdown-header-close",html:function(a){return'<div class="'+a.headerClass+'"><div class="'+a.titleRowClass+'"><span class="'+a.labelClass+'">'+a.title+'</span><a href="javascript:void(0)" class="'+a.closeClass+'">&times;</a></div></div>'}},b),c.setup=function(){var d=c.setup;return function(){d.apply(c,arguments),c.$dropdown_header=a(b.html(b)),c.$dropdown.prepend(c.$dropdown_header)}}()}),L.define("optgroup_columns",function(b){var c=this;b=a.extend({equalizeWidth:!0,equalizeHeight:!0},b),this.getAdjacentOption=function(b,c){var d=b.closest("[data-group]").find("[data-selectable]"),e=d.index(b)+c;return e>=0&&e<d.length?d.eq(e):a()},this.onKeyDown=function(){var a=c.onKeyDown;return function(b){var d,e,f,g;return!this.isOpen||b.keyCode!==j&&b.keyCode!==m?a.apply(this,arguments):(c.ignoreHover=!0,g=this.$activeOption.closest("[data-group]"),d=g.find("[data-selectable]").index(this.$activeOption),g=b.keyCode===j?g.prev("[data-group]"):g.next("[data-group]"),f=g.find("[data-selectable]"),e=f.eq(Math.min(f.length-1,d)),void(e.length&&this.setActiveOption(e)))}}();var d=function(){var a,b=d.width,c=document;return"undefined"==typeof b&&(a=c.createElement("div"),a.innerHTML='<div style="width:50px;height:50px;position:absolute;left:-50px;top:-50px;overflow:auto;"><div style="width:1px;height:100px;"></div></div>',a=a.firstChild,c.body.appendChild(a),b=d.width=a.offsetWidth-a.clientWidth,c.body.removeChild(a)),b},e=function(){var e,f,g,h,i,j,k;if(k=a("[data-group]",c.$dropdown_content),f=k.length,f&&c.$dropdown_content.width()){if(b.equalizeHeight){for(g=0,e=0;f>e;e++)g=Math.max(g,k.eq(e).height());k.css({height:g})}b.equalizeWidth&&(j=c.$dropdown_content.innerWidth()-d(),h=Math.round(j/f),k.css({width:h}),f>1&&(i=j-h*(f-1),k.eq(f-1).css({width:i})))}};(b.equalizeHeight||b.equalizeWidth)&&(C.after(this,"positionDropdown",e),C.after(this,"refreshOptions",e))}),L.define("remove_button",function(b){if("single"!==this.settings.mode){b=a.extend({label:"&times;",title:"Remove",className:"remove",append:!0},b);var c=this,d='<a href="javascript:void(0)" class="'+b.className+'" tabindex="-1" title="'+A(b.title)+'">'+b.label+"</a>",e=function(a,b){var c=a.search(/(<\/[^>]+>\s*)$/);return a.substring(0,c)+b+a.substring(c)};this.setup=function(){var f=c.setup;return function(){if(b.append){var g=c.settings.render.item;c.settings.render.item=function(){return e(g.apply(this,arguments),d)}}f.apply(this,arguments),this.$control.on("click","."+b.className,function(b){if(b.preventDefault(),!c.isLocked){var d=a(b.currentTarget).parent();c.setActiveItem(d),c.deleteSelection()&&c.setCaret(c.items.length)}})}}()}}),L.define("restore_on_backspace",function(a){var b=this;a.text=a.text||function(a){return a[this.settings.labelField]},this.onKeyDown=function(){var c=b.onKeyDown;return function(b){var d,e;return b.keyCode===p&&""===this.$control_input.val()&&!this.$activeItems.length&&(d=this.caretPos-1,d>=0&&d<this.items.length)?(e=this.options[this.items[d]],this.deleteSelection(b)&&(this.setTextboxValue(a.text.apply(this,[e])),this.refreshOptions(!0)),void b.preventDefault()):c.apply(this,arguments)}}()}),L});
1
+ /*! selectize.js - v0.12.1 | https://github.com/brianreavis/selectize.js | Apache License (v2) */
2
+ !function(a,b){"function"==typeof define&&define.amd?define("sifter",b):"object"==typeof exports?module.exports=b():a.Sifter=b()}(this,function(){var a=function(a,b){this.items=a,this.settings=b||{diacritics:!0}};a.prototype.tokenize=function(a){if(a=d(String(a||"").toLowerCase()),!a||!a.length)return[];var b,c,f,h,i=[],j=a.split(/ +/);for(b=0,c=j.length;c>b;b++){if(f=e(j[b]),this.settings.diacritics)for(h in g)g.hasOwnProperty(h)&&(f=f.replace(new RegExp(h,"g"),g[h]));i.push({string:j[b],regex:new RegExp(f,"i")})}return i},a.prototype.iterator=function(a,b){var c;c=f(a)?Array.prototype.forEach||function(a){for(var b=0,c=this.length;c>b;b++)a(this[b],b,this)}:function(a){for(var b in this)this.hasOwnProperty(b)&&a(this[b],b,this)},c.apply(a,[b])},a.prototype.getScoreFunction=function(a,b){var c,d,e,f;c=this,a=c.prepareSearch(a,b),e=a.tokens,d=a.options.fields,f=e.length;var g=function(a,b){var c,d;return a?(a=String(a||""),d=a.search(b.regex),-1===d?0:(c=b.string.length/a.length,0===d&&(c+=.5),c)):0},h=function(){var a=d.length;return a?1===a?function(a,b){return g(b[d[0]],a)}:function(b,c){for(var e=0,f=0;a>e;e++)f+=g(c[d[e]],b);return f/a}:function(){return 0}}();return f?1===f?function(a){return h(e[0],a)}:"and"===a.options.conjunction?function(a){for(var b,c=0,d=0;f>c;c++){if(b=h(e[c],a),0>=b)return 0;d+=b}return d/f}:function(a){for(var b=0,c=0;f>b;b++)c+=h(e[b],a);return c/f}:function(){return 0}},a.prototype.getSortFunction=function(a,c){var d,e,f,g,h,i,j,k,l,m,n;if(f=this,a=f.prepareSearch(a,c),n=!a.query&&c.sort_empty||c.sort,l=function(a,b){return"$score"===a?b.score:f.items[b.id][a]},h=[],n)for(d=0,e=n.length;e>d;d++)(a.query||"$score"!==n[d].field)&&h.push(n[d]);if(a.query){for(m=!0,d=0,e=h.length;e>d;d++)if("$score"===h[d].field){m=!1;break}m&&h.unshift({field:"$score",direction:"desc"})}else for(d=0,e=h.length;e>d;d++)if("$score"===h[d].field){h.splice(d,1);break}for(k=[],d=0,e=h.length;e>d;d++)k.push("desc"===h[d].direction?-1:1);return i=h.length,i?1===i?(g=h[0].field,j=k[0],function(a,c){return j*b(l(g,a),l(g,c))}):function(a,c){var d,e,f;for(d=0;i>d;d++)if(f=h[d].field,e=k[d]*b(l(f,a),l(f,c)))return e;return 0}:null},a.prototype.prepareSearch=function(a,b){if("object"==typeof a)return a;b=c({},b);var d=b.fields,e=b.sort,g=b.sort_empty;return d&&!f(d)&&(b.fields=[d]),e&&!f(e)&&(b.sort=[e]),g&&!f(g)&&(b.sort_empty=[g]),{options:b,query:String(a||"").toLowerCase(),tokens:this.tokenize(a),total:0,items:[]}},a.prototype.search=function(a,b){var c,d,e,f,g=this;return d=this.prepareSearch(a,b),b=d.options,a=d.query,f=b.score||g.getScoreFunction(d),a.length?g.iterator(g.items,function(a,e){c=f(a),(b.filter===!1||c>0)&&d.items.push({score:c,id:e})}):g.iterator(g.items,function(a,b){d.items.push({score:1,id:b})}),e=g.getSortFunction(d,b),e&&d.items.sort(e),d.total=d.items.length,"number"==typeof b.limit&&(d.items=d.items.slice(0,b.limit)),d};var b=function(a,b){return"number"==typeof a&&"number"==typeof b?a>b?1:b>a?-1:0:(a=h(String(a||"")),b=h(String(b||"")),a>b?1:b>a?-1:0)},c=function(a){var b,c,d,e;for(b=1,c=arguments.length;c>b;b++)if(e=arguments[b])for(d in e)e.hasOwnProperty(d)&&(a[d]=e[d]);return a},d=function(a){return(a+"").replace(/^\s+|\s+$|/g,"")},e=function(a){return(a+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")},f=Array.isArray||$&&$.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)},g={a:"[aÀÁÂÃÄÅàáâãäåĀāąĄ]",c:"[cÇçćĆčČ]",d:"[dđĐďĎ]",e:"[eÈÉÊËèéêëěĚĒēęĘ]",i:"[iÌÍÎÏìíîïĪī]",l:"[lłŁ]",n:"[nÑñňŇńŃ]",o:"[oÒÓÔÕÕÖØòóôõöøŌō]",r:"[rřŘ]",s:"[sŠšśŚ]",t:"[tťŤ]",u:"[uÙÚÛÜùúûüůŮŪū]",y:"[yŸÿýÝ]",z:"[zŽžżŻźŹ]"},h=function(){var a,b,c,d,e="",f={};for(c in g)if(g.hasOwnProperty(c))for(d=g[c].substring(2,g[c].length-1),e+=d,a=0,b=d.length;b>a;a++)f[d.charAt(a)]=c;var h=new RegExp("["+e+"]","g");return function(a){return a.replace(h,function(a){return f[a]}).toLowerCase()}}();return a}),function(a,b){"function"==typeof define&&define.amd?define("microplugin",b):"object"==typeof exports?module.exports=b():a.MicroPlugin=b()}(this,function(){var a={};a.mixin=function(a){a.plugins={},a.prototype.initializePlugins=function(a){var c,d,e,f=this,g=[];if(f.plugins={names:[],settings:{},requested:{},loaded:{}},b.isArray(a))for(c=0,d=a.length;d>c;c++)"string"==typeof a[c]?g.push(a[c]):(f.plugins.settings[a[c].name]=a[c].options,g.push(a[c].name));else if(a)for(e in a)a.hasOwnProperty(e)&&(f.plugins.settings[e]=a[e],g.push(e));for(;g.length;)f.require(g.shift())},a.prototype.loadPlugin=function(b){var c=this,d=c.plugins,e=a.plugins[b];if(!a.plugins.hasOwnProperty(b))throw new Error('Unable to find "'+b+'" plugin');d.requested[b]=!0,d.loaded[b]=e.fn.apply(c,[c.plugins.settings[b]||{}]),d.names.push(b)},a.prototype.require=function(a){var b=this,c=b.plugins;if(!b.plugins.loaded.hasOwnProperty(a)){if(c.requested[a])throw new Error('Plugin has circular dependency ("'+a+'")');b.loadPlugin(a)}return c.loaded[a]},a.define=function(b,c){a.plugins[b]={name:b,fn:c}}};var b={isArray:Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)}};return a}),function(a,b){"function"==typeof define&&define.amd?define("selectize",["jquery","sifter","microplugin"],b):"object"==typeof exports?module.exports=b(require("jquery"),require("sifter"),require("microplugin")):a.Selectize=b(a.jQuery,a.Sifter,a.MicroPlugin)}(this,function(a,b,c){"use strict";var d=function(a,b){if("string"!=typeof b||b.length){var c="string"==typeof b?new RegExp(b,"i"):b,d=function(a){var b=0;if(3===a.nodeType){var e=a.data.search(c);if(e>=0&&a.data.length>0){var f=a.data.match(c),g=document.createElement("span");g.className="highlight";var h=a.splitText(e),i=(h.splitText(f[0].length),h.cloneNode(!0));g.appendChild(i),h.parentNode.replaceChild(g,h),b=1}}else if(1===a.nodeType&&a.childNodes&&!/(script|style)/i.test(a.tagName))for(var j=0;j<a.childNodes.length;++j)j+=d(a.childNodes[j]);return b};return a.each(function(){d(this)})}},e=function(){};e.prototype={on:function(a,b){this._events=this._events||{},this._events[a]=this._events[a]||[],this._events[a].push(b)},off:function(a,b){var c=arguments.length;return 0===c?delete this._events:1===c?delete this._events[a]:(this._events=this._events||{},void(a in this._events!=!1&&this._events[a].splice(this._events[a].indexOf(b),1)))},trigger:function(a){if(this._events=this._events||{},a in this._events!=!1)for(var b=0;b<this._events[a].length;b++)this._events[a][b].apply(this,Array.prototype.slice.call(arguments,1))}},e.mixin=function(a){for(var b=["on","off","trigger"],c=0;c<b.length;c++)a.prototype[b[c]]=e.prototype[b[c]]};var f=/Mac/.test(navigator.userAgent),g=65,h=13,i=27,j=37,k=38,l=80,m=39,n=40,o=78,p=8,q=46,r=16,s=f?91:17,t=f?18:17,u=9,v=1,w=2,x=!/android/i.test(window.navigator.userAgent)&&!!document.createElement("form").validity,y=function(a){return"undefined"!=typeof a},z=function(a){return"undefined"==typeof a||null===a?null:"boolean"==typeof a?a?"1":"0":a+""},A=function(a){return(a+"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},B=function(a){return(a+"").replace(/\$/g,"$$$$")},C={};C.before=function(a,b,c){var d=a[b];a[b]=function(){return c.apply(a,arguments),d.apply(a,arguments)}},C.after=function(a,b,c){var d=a[b];a[b]=function(){var b=d.apply(a,arguments);return c.apply(a,arguments),b}};var D=function(a){var b=!1;return function(){b||(b=!0,a.apply(this,arguments))}},E=function(a,b){var c;return function(){var d=this,e=arguments;window.clearTimeout(c),c=window.setTimeout(function(){a.apply(d,e)},b)}},F=function(a,b,c){var d,e=a.trigger,f={};a.trigger=function(){var c=arguments[0];return-1===b.indexOf(c)?e.apply(a,arguments):void(f[c]=arguments)},c.apply(a,[]),a.trigger=e;for(d in f)f.hasOwnProperty(d)&&e.apply(a,f[d])},G=function(a,b,c,d){a.on(b,c,function(b){for(var c=b.target;c&&c.parentNode!==a[0];)c=c.parentNode;return b.currentTarget=c,d.apply(this,[b])})},H=function(a){var b={};if("selectionStart"in a)b.start=a.selectionStart,b.length=a.selectionEnd-b.start;else if(document.selection){a.focus();var c=document.selection.createRange(),d=document.selection.createRange().text.length;c.moveStart("character",-a.value.length),b.start=c.text.length-d,b.length=d}return b},I=function(a,b,c){var d,e,f={};if(c)for(d=0,e=c.length;e>d;d++)f[c[d]]=a.css(c[d]);else f=a.css();b.css(f)},J=function(b,c){if(!b)return 0;var d=a("<test>").css({position:"absolute",top:-99999,left:-99999,width:"auto",padding:0,whiteSpace:"pre"}).text(b).appendTo("body");I(c,d,["letterSpacing","fontSize","fontFamily","fontWeight","textTransform"]);var e=d.width();return d.remove(),e},K=function(a){var b=null,c=function(c,d){var e,f,g,h,i,j,k,l;c=c||window.event||{},d=d||{},c.metaKey||c.altKey||(d.force||a.data("grow")!==!1)&&(e=a.val(),c.type&&"keydown"===c.type.toLowerCase()&&(f=c.keyCode,g=f>=97&&122>=f||f>=65&&90>=f||f>=48&&57>=f||32===f,f===q||f===p?(l=H(a[0]),l.length?e=e.substring(0,l.start)+e.substring(l.start+l.length):f===p&&l.start?e=e.substring(0,l.start-1)+e.substring(l.start+1):f===q&&"undefined"!=typeof l.start&&(e=e.substring(0,l.start)+e.substring(l.start+1))):g&&(j=c.shiftKey,k=String.fromCharCode(c.keyCode),k=j?k.toUpperCase():k.toLowerCase(),e+=k)),h=a.attr("placeholder"),!e&&h&&(e=h),i=J(e,a)+4,i!==b&&(b=i,a.width(i),a.triggerHandler("resize")))};a.on("keydown keyup update blur",c),c()},L=function(c,d){var e,f,g,h,i=this;h=c[0],h.selectize=i;var j=window.getComputedStyle&&window.getComputedStyle(h,null);if(g=j?j.getPropertyValue("direction"):h.currentStyle&&h.currentStyle.direction,g=g||c.parents("[dir]:first").attr("dir")||"",a.extend(i,{order:0,settings:d,$input:c,tabIndex:c.attr("tabindex")||"",tagType:"select"===h.tagName.toLowerCase()?v:w,rtl:/rtl/i.test(g),eventNS:".selectize"+ ++L.count,highlightedValue:null,isOpen:!1,isDisabled:!1,isRequired:c.is("[required]"),isInvalid:!1,isLocked:!1,isFocused:!1,isInputHidden:!1,isSetup:!1,isShiftDown:!1,isCmdDown:!1,isCtrlDown:!1,ignoreFocus:!1,ignoreBlur:!1,ignoreHover:!1,hasOptions:!1,currentResults:null,lastValue:"",caretPos:0,loading:0,loadedSearches:{},$activeOption:null,$activeItems:[],optgroups:{},options:{},userOptions:{},items:[],renderCache:{},onSearchChange:null===d.loadThrottle?i.onSearchChange:E(i.onSearchChange,d.loadThrottle)}),i.sifter=new b(this.options,{diacritics:d.diacritics}),i.settings.options){for(e=0,f=i.settings.options.length;f>e;e++)i.registerOption(i.settings.options[e]);delete i.settings.options}if(i.settings.optgroups){for(e=0,f=i.settings.optgroups.length;f>e;e++)i.registerOptionGroup(i.settings.optgroups[e]);delete i.settings.optgroups}i.settings.mode=i.settings.mode||(1===i.settings.maxItems?"single":"multi"),"boolean"!=typeof i.settings.hideSelected&&(i.settings.hideSelected="multi"===i.settings.mode),i.initializePlugins(i.settings.plugins),i.setupCallbacks(),i.setupTemplates(),i.setup()};return e.mixin(L),c.mixin(L),a.extend(L.prototype,{setup:function(){var b,c,d,e,g,h,i,j,k,l=this,m=l.settings,n=l.eventNS,o=a(window),p=a(document),q=l.$input;if(i=l.settings.mode,j=q.attr("class")||"",b=a("<div>").addClass(m.wrapperClass).addClass(j).addClass(i),c=a("<div>").addClass(m.inputClass).addClass("items").appendTo(b),d=a('<input type="text" autocomplete="off" />').appendTo(c).attr("tabindex",q.is(":disabled")?"-1":l.tabIndex),h=a(m.dropdownParent||b),e=a("<div>").addClass(m.dropdownClass).addClass(i).hide().appendTo(h),g=a("<div>").addClass(m.dropdownContentClass).appendTo(e),l.settings.copyClassesToDropdown&&e.addClass(j),b.css({width:q[0].style.width}),l.plugins.names.length&&(k="plugin-"+l.plugins.names.join(" plugin-"),b.addClass(k),e.addClass(k)),(null===m.maxItems||m.maxItems>1)&&l.tagType===v&&q.attr("multiple","multiple"),l.settings.placeholder&&d.attr("placeholder",m.placeholder),!l.settings.splitOn&&l.settings.delimiter){var u=l.settings.delimiter.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&");l.settings.splitOn=new RegExp("\\s*"+u+"+\\s*")}q.attr("autocorrect")&&d.attr("autocorrect",q.attr("autocorrect")),q.attr("autocapitalize")&&d.attr("autocapitalize",q.attr("autocapitalize")),l.$wrapper=b,l.$control=c,l.$control_input=d,l.$dropdown=e,l.$dropdown_content=g,e.on("mouseenter","[data-selectable]",function(){return l.onOptionHover.apply(l,arguments)}),e.on("mousedown click","[data-selectable]",function(){return l.onOptionSelect.apply(l,arguments)}),G(c,"mousedown","*:not(input)",function(){return l.onItemSelect.apply(l,arguments)}),K(d),c.on({mousedown:function(){return l.onMouseDown.apply(l,arguments)},click:function(){return l.onClick.apply(l,arguments)}}),d.on({mousedown:function(a){a.stopPropagation()},keydown:function(){return l.onKeyDown.apply(l,arguments)},keyup:function(){return l.onKeyUp.apply(l,arguments)},keypress:function(){return l.onKeyPress.apply(l,arguments)},resize:function(){l.positionDropdown.apply(l,[])},blur:function(){return l.onBlur.apply(l,arguments)},focus:function(){return l.ignoreBlur=!1,l.onFocus.apply(l,arguments)},paste:function(){return l.onPaste.apply(l,arguments)}}),p.on("keydown"+n,function(a){l.isCmdDown=a[f?"metaKey":"ctrlKey"],l.isCtrlDown=a[f?"altKey":"ctrlKey"],l.isShiftDown=a.shiftKey}),p.on("keyup"+n,function(a){a.keyCode===t&&(l.isCtrlDown=!1),a.keyCode===r&&(l.isShiftDown=!1),a.keyCode===s&&(l.isCmdDown=!1)}),p.on("mousedown"+n,function(a){if(l.isFocused){if(a.target===l.$dropdown[0]||a.target.parentNode===l.$dropdown[0])return!1;l.$control.has(a.target).length||a.target===l.$control[0]||l.blur(a.target)}}),o.on(["scroll"+n,"resize"+n].join(" "),function(){l.isOpen&&l.positionDropdown.apply(l,arguments)}),o.on("mousemove"+n,function(){l.ignoreHover=!1}),this.revertSettings={$children:q.children().detach(),tabindex:q.attr("tabindex")},q.attr("tabindex",-1).hide().after(l.$wrapper),a.isArray(m.items)&&(l.setValue(m.items),delete m.items),x&&q.on("invalid"+n,function(a){a.preventDefault(),l.isInvalid=!0,l.refreshState()}),l.updateOriginalInput(),l.refreshItems(),l.refreshState(),l.updatePlaceholder(),l.isSetup=!0,q.is(":disabled")&&l.disable(),l.on("change",this.onChange),q.data("selectize",l),q.addClass("selectized"),l.trigger("initialize"),m.preload===!0&&l.onSearchChange("")},setupTemplates:function(){var b=this,c=b.settings.labelField,d=b.settings.optgroupLabelField,e={optgroup:function(a){return'<div class="optgroup">'+a.html+"</div>"},optgroup_header:function(a,b){return'<div class="optgroup-header">'+b(a[d])+"</div>"},option:function(a,b){return'<div class="option">'+b(a[c])+"</div>"},item:function(a,b){return'<div class="item">'+b(a[c])+"</div>"},option_create:function(a,b){return'<div class="create">Add <strong>'+b(a.input)+"</strong>&hellip;</div>"}};b.settings.render=a.extend({},e,b.settings.render)},setupCallbacks:function(){var a,b,c={initialize:"onInitialize",change:"onChange",item_add:"onItemAdd",item_remove:"onItemRemove",clear:"onClear",option_add:"onOptionAdd",option_remove:"onOptionRemove",option_clear:"onOptionClear",optgroup_add:"onOptionGroupAdd",optgroup_remove:"onOptionGroupRemove",optgroup_clear:"onOptionGroupClear",dropdown_open:"onDropdownOpen",dropdown_close:"onDropdownClose",type:"onType",load:"onLoad",focus:"onFocus",blur:"onBlur"};for(a in c)c.hasOwnProperty(a)&&(b=this.settings[c[a]],b&&this.on(a,b))},onClick:function(a){var b=this;b.isFocused||(b.focus(),a.preventDefault())},onMouseDown:function(b){{var c=this,d=b.isDefaultPrevented();a(b.target)}if(c.isFocused){if(b.target!==c.$control_input[0])return"single"===c.settings.mode?c.isOpen?c.close():c.open():d||c.setActiveItem(null),!1}else d||window.setTimeout(function(){c.focus()},0)},onChange:function(){this.$input.trigger("change")},onPaste:function(b){var c=this;c.isFull()||c.isInputHidden||c.isLocked?b.preventDefault():c.settings.splitOn&&setTimeout(function(){for(var b=a.trim(c.$control_input.val()||"").split(c.settings.splitOn),d=0,e=b.length;e>d;d++)c.createItem(b[d])},0)},onKeyPress:function(a){if(this.isLocked)return a&&a.preventDefault();var b=String.fromCharCode(a.keyCode||a.which);return this.settings.create&&"multi"===this.settings.mode&&b===this.settings.delimiter?(this.createItem(),a.preventDefault(),!1):void 0},onKeyDown:function(a){var b=(a.target===this.$control_input[0],this);if(b.isLocked)return void(a.keyCode!==u&&a.preventDefault());switch(a.keyCode){case g:if(b.isCmdDown)return void b.selectAll();break;case i:return void(b.isOpen&&(a.preventDefault(),a.stopPropagation(),b.close()));case o:if(!a.ctrlKey||a.altKey)break;case n:if(!b.isOpen&&b.hasOptions)b.open();else if(b.$activeOption){b.ignoreHover=!0;var c=b.getAdjacentOption(b.$activeOption,1);c.length&&b.setActiveOption(c,!0,!0)}return void a.preventDefault();case l:if(!a.ctrlKey||a.altKey)break;case k:if(b.$activeOption){b.ignoreHover=!0;var d=b.getAdjacentOption(b.$activeOption,-1);d.length&&b.setActiveOption(d,!0,!0)}return void a.preventDefault();case h:return void(b.isOpen&&b.$activeOption&&(b.onOptionSelect({currentTarget:b.$activeOption}),a.preventDefault()));case j:return void b.advanceSelection(-1,a);case m:return void b.advanceSelection(1,a);case u:return b.settings.selectOnTab&&b.isOpen&&b.$activeOption&&(b.onOptionSelect({currentTarget:b.$activeOption}),b.isFull()||a.preventDefault()),void(b.settings.create&&b.createItem()&&a.preventDefault());case p:case q:return void b.deleteSelection(a)}return!b.isFull()&&!b.isInputHidden||(f?a.metaKey:a.ctrlKey)?void 0:void a.preventDefault()},onKeyUp:function(a){var b=this;if(b.isLocked)return a&&a.preventDefault();var c=b.$control_input.val()||"";b.lastValue!==c&&(b.lastValue=c,b.onSearchChange(c),b.refreshOptions(),b.trigger("type",c))},onSearchChange:function(a){var b=this,c=b.settings.load;c&&(b.loadedSearches.hasOwnProperty(a)||(b.loadedSearches[a]=!0,b.load(function(d){c.apply(b,[a,d])})))},onFocus:function(a){var b=this,c=b.isFocused;return b.isDisabled?(b.blur(),a&&a.preventDefault(),!1):void(b.ignoreFocus||(b.isFocused=!0,"focus"===b.settings.preload&&b.onSearchChange(""),c||b.trigger("focus"),b.$activeItems.length||(b.showInput(),b.setActiveItem(null),b.refreshOptions(!!b.settings.openOnFocus)),b.refreshState()))},onBlur:function(a,b){var c=this;if(c.isFocused&&(c.isFocused=!1,!c.ignoreFocus)){if(!c.ignoreBlur&&document.activeElement===c.$dropdown_content[0])return c.ignoreBlur=!0,void c.onFocus(a);var d=function(){c.close(),c.setTextboxValue(""),c.setActiveItem(null),c.setActiveOption(null),c.setCaret(c.items.length),c.refreshState(),(b||document.body).focus(),c.ignoreFocus=!1,c.trigger("blur")};c.ignoreFocus=!0,c.settings.create&&c.settings.createOnBlur?c.createItem(null,!1,d):d()}},onOptionHover:function(a){this.ignoreHover||this.setActiveOption(a.currentTarget,!1)},onOptionSelect:function(b){var c,d,e=this;b.preventDefault&&(b.preventDefault(),b.stopPropagation()),d=a(b.currentTarget),d.hasClass("create")?e.createItem(null,function(){e.settings.closeAfterSelect&&e.close()}):(c=d.attr("data-value"),"undefined"!=typeof c&&(e.lastQuery=null,e.setTextboxValue(""),e.addItem(c),e.settings.closeAfterSelect?e.close():!e.settings.hideSelected&&b.type&&/mouse/.test(b.type)&&e.setActiveOption(e.getOption(c))))},onItemSelect:function(a){var b=this;b.isLocked||"multi"===b.settings.mode&&(a.preventDefault(),b.setActiveItem(a.currentTarget,a))},load:function(a){var b=this,c=b.$wrapper.addClass(b.settings.loadingClass);b.loading++,a.apply(b,[function(a){b.loading=Math.max(b.loading-1,0),a&&a.length&&(b.addOption(a),b.refreshOptions(b.isFocused&&!b.isInputHidden)),b.loading||c.removeClass(b.settings.loadingClass),b.trigger("load",a)}])},setTextboxValue:function(a){var b=this.$control_input,c=b.val()!==a;c&&(b.val(a).triggerHandler("update"),this.lastValue=a)},getValue:function(){return this.tagType===v&&this.$input.attr("multiple")?this.items:this.items.join(this.settings.delimiter)},setValue:function(a,b){var c=b?[]:["change"];F(this,c,function(){this.clear(b),this.addItems(a,b)})},setActiveItem:function(b,c){var d,e,f,g,h,i,j,k,l=this;if("single"!==l.settings.mode){if(b=a(b),!b.length)return a(l.$activeItems).removeClass("active"),l.$activeItems=[],void(l.isFocused&&l.showInput());if(d=c&&c.type.toLowerCase(),"mousedown"===d&&l.isShiftDown&&l.$activeItems.length){for(k=l.$control.children(".active:last"),g=Array.prototype.indexOf.apply(l.$control[0].childNodes,[k[0]]),h=Array.prototype.indexOf.apply(l.$control[0].childNodes,[b[0]]),g>h&&(j=g,g=h,h=j),e=g;h>=e;e++)i=l.$control[0].childNodes[e],-1===l.$activeItems.indexOf(i)&&(a(i).addClass("active"),l.$activeItems.push(i));c.preventDefault()}else"mousedown"===d&&l.isCtrlDown||"keydown"===d&&this.isShiftDown?b.hasClass("active")?(f=l.$activeItems.indexOf(b[0]),l.$activeItems.splice(f,1),b.removeClass("active")):l.$activeItems.push(b.addClass("active")[0]):(a(l.$activeItems).removeClass("active"),l.$activeItems=[b.addClass("active")[0]]);l.hideInput(),this.isFocused||l.focus()}},setActiveOption:function(b,c,d){var e,f,g,h,i,j=this;j.$activeOption&&j.$activeOption.removeClass("active"),j.$activeOption=null,b=a(b),b.length&&(j.$activeOption=b.addClass("active"),(c||!y(c))&&(e=j.$dropdown_content.height(),f=j.$activeOption.outerHeight(!0),c=j.$dropdown_content.scrollTop()||0,g=j.$activeOption.offset().top-j.$dropdown_content.offset().top+c,h=g,i=g-e+f,g+f>e+c?j.$dropdown_content.stop().animate({scrollTop:i},d?j.settings.scrollDuration:0):c>g&&j.$dropdown_content.stop().animate({scrollTop:h},d?j.settings.scrollDuration:0)))},selectAll:function(){var a=this;"single"!==a.settings.mode&&(a.$activeItems=Array.prototype.slice.apply(a.$control.children(":not(input)").addClass("active")),a.$activeItems.length&&(a.hideInput(),a.close()),a.focus())},hideInput:function(){var a=this;a.setTextboxValue(""),a.$control_input.css({opacity:0,position:"absolute",left:a.rtl?1e4:-1e4}),a.isInputHidden=!0},showInput:function(){this.$control_input.css({opacity:1,position:"relative",left:0}),this.isInputHidden=!1},focus:function(){var a=this;a.isDisabled||(a.ignoreFocus=!0,a.$control_input[0].focus(),window.setTimeout(function(){a.ignoreFocus=!1,a.onFocus()},0))},blur:function(a){this.$control_input[0].blur(),this.onBlur(null,a)},getScoreFunction:function(a){return this.sifter.getScoreFunction(a,this.getSearchOptions())},getSearchOptions:function(){var a=this.settings,b=a.sortField;return"string"==typeof b&&(b=[{field:b}]),{fields:a.searchField,conjunction:a.searchConjunction,sort:b}},search:function(b){var c,d,e,f=this,g=f.settings,h=this.getSearchOptions();if(g.score&&(e=f.settings.score.apply(this,[b]),"function"!=typeof e))throw new Error('Selectize "score" setting must be a function that returns a function');if(b!==f.lastQuery?(f.lastQuery=b,d=f.sifter.search(b,a.extend(h,{score:e})),f.currentResults=d):d=a.extend(!0,{},f.currentResults),g.hideSelected)for(c=d.items.length-1;c>=0;c--)-1!==f.items.indexOf(z(d.items[c].id))&&d.items.splice(c,1);return d},refreshOptions:function(b){var c,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s;"undefined"==typeof b&&(b=!0);var t=this,u=a.trim(t.$control_input.val()),v=t.search(u),w=t.$dropdown_content,x=t.$activeOption&&z(t.$activeOption.attr("data-value"));for(g=v.items.length,"number"==typeof t.settings.maxOptions&&(g=Math.min(g,t.settings.maxOptions)),h={},i=[],c=0;g>c;c++)for(j=t.options[v.items[c].id],k=t.render("option",j),l=j[t.settings.optgroupField]||"",m=a.isArray(l)?l:[l],e=0,f=m&&m.length;f>e;e++)l=m[e],t.optgroups.hasOwnProperty(l)||(l=""),h.hasOwnProperty(l)||(h[l]=[],i.push(l)),h[l].push(k);for(this.settings.lockOptgroupOrder&&i.sort(function(a,b){var c=t.optgroups[a].$order||0,d=t.optgroups[b].$order||0;return c-d}),n=[],c=0,g=i.length;g>c;c++)l=i[c],t.optgroups.hasOwnProperty(l)&&h[l].length?(o=t.render("optgroup_header",t.optgroups[l])||"",o+=h[l].join(""),n.push(t.render("optgroup",a.extend({},t.optgroups[l],{html:o})))):n.push(h[l].join(""));if(w.html(n.join("")),t.settings.highlight&&v.query.length&&v.tokens.length)for(c=0,g=v.tokens.length;g>c;c++)d(w,v.tokens[c].regex);if(!t.settings.hideSelected)for(c=0,g=t.items.length;g>c;c++)t.getOption(t.items[c]).addClass("selected");p=t.canCreate(u),p&&(w.prepend(t.render("option_create",{input:u})),s=a(w[0].childNodes[0])),t.hasOptions=v.items.length>0||p,t.hasOptions?(v.items.length>0?(r=x&&t.getOption(x),r&&r.length?q=r:"single"===t.settings.mode&&t.items.length&&(q=t.getOption(t.items[0])),q&&q.length||(q=s&&!t.settings.addPrecedence?t.getAdjacentOption(s,1):w.find("[data-selectable]:first"))):q=s,t.setActiveOption(q),b&&!t.isOpen&&t.open()):(t.setActiveOption(null),b&&t.isOpen&&t.close())},addOption:function(b){var c,d,e,f=this;if(a.isArray(b))for(c=0,d=b.length;d>c;c++)f.addOption(b[c]);else(e=f.registerOption(b))&&(f.userOptions[e]=!0,f.lastQuery=null,f.trigger("option_add",e,b))},registerOption:function(a){var b=z(a[this.settings.valueField]);return!b||this.options.hasOwnProperty(b)?!1:(a.$order=a.$order||++this.order,this.options[b]=a,b)},registerOptionGroup:function(a){var b=z(a[this.settings.optgroupValueField]);return b?(a.$order=a.$order||++this.order,this.optgroups[b]=a,b):!1},addOptionGroup:function(a,b){b[this.settings.optgroupValueField]=a,(a=this.registerOptionGroup(b))&&this.trigger("optgroup_add",a,b)},removeOptionGroup:function(a){this.optgroups.hasOwnProperty(a)&&(delete this.optgroups[a],this.renderCache={},this.trigger("optgroup_remove",a))},clearOptionGroups:function(){this.optgroups={},this.renderCache={},this.trigger("optgroup_clear")},updateOption:function(b,c){var d,e,f,g,h,i,j,k=this;if(b=z(b),f=z(c[k.settings.valueField]),null!==b&&k.options.hasOwnProperty(b)){if("string"!=typeof f)throw new Error("Value must be set in option data");j=k.options[b].$order,f!==b&&(delete k.options[b],g=k.items.indexOf(b),-1!==g&&k.items.splice(g,1,f)),c.$order=c.$order||j,k.options[f]=c,h=k.renderCache.item,i=k.renderCache.option,h&&(delete h[b],delete h[f]),i&&(delete i[b],delete i[f]),-1!==k.items.indexOf(f)&&(d=k.getItem(b),e=a(k.render("item",c)),d.hasClass("active")&&e.addClass("active"),d.replaceWith(e)),k.lastQuery=null,k.isOpen&&k.refreshOptions(!1)}},removeOption:function(a,b){var c=this;a=z(a);var d=c.renderCache.item,e=c.renderCache.option;d&&delete d[a],e&&delete e[a],delete c.userOptions[a],delete c.options[a],c.lastQuery=null,c.trigger("option_remove",a),c.removeItem(a,b)},clearOptions:function(){var a=this;a.loadedSearches={},a.userOptions={},a.renderCache={},a.options=a.sifter.items={},a.lastQuery=null,a.trigger("option_clear"),a.clear()},getOption:function(a){return this.getElementWithValue(a,this.$dropdown_content.find("[data-selectable]"))},getAdjacentOption:function(b,c){var d=this.$dropdown.find("[data-selectable]"),e=d.index(b)+c;return e>=0&&e<d.length?d.eq(e):a()},getElementWithValue:function(b,c){if(b=z(b),"undefined"!=typeof b&&null!==b)for(var d=0,e=c.length;e>d;d++)if(c[d].getAttribute("data-value")===b)return a(c[d]);return a()},getItem:function(a){return this.getElementWithValue(a,this.$control.children())},addItems:function(b,c){for(var d=a.isArray(b)?b:[b],e=0,f=d.length;f>e;e++)this.isPending=f-1>e,this.addItem(d[e],c)},addItem:function(b,c){var d=c?[]:["change"];F(this,d,function(){var d,e,f,g,h,i=this,j=i.settings.mode;return b=z(b),-1!==i.items.indexOf(b)?void("single"===j&&i.close()):void(i.options.hasOwnProperty(b)&&("single"===j&&i.clear(c),"multi"===j&&i.isFull()||(d=a(i.render("item",i.options[b])),h=i.isFull(),i.items.splice(i.caretPos,0,b),i.insertAtCaret(d),(!i.isPending||!h&&i.isFull())&&i.refreshState(),i.isSetup&&(f=i.$dropdown_content.find("[data-selectable]"),i.isPending||(e=i.getOption(b),g=i.getAdjacentOption(e,1).attr("data-value"),i.refreshOptions(i.isFocused&&"single"!==j),g&&i.setActiveOption(i.getOption(g))),!f.length||i.isFull()?i.close():i.positionDropdown(),i.updatePlaceholder(),i.trigger("item_add",b,d),i.updateOriginalInput({silent:c})))))})},removeItem:function(a,b){var c,d,e,f=this;c="object"==typeof a?a:f.getItem(a),a=z(c.attr("data-value")),d=f.items.indexOf(a),-1!==d&&(c.remove(),c.hasClass("active")&&(e=f.$activeItems.indexOf(c[0]),f.$activeItems.splice(e,1)),f.items.splice(d,1),f.lastQuery=null,!f.settings.persist&&f.userOptions.hasOwnProperty(a)&&f.removeOption(a,b),d<f.caretPos&&f.setCaret(f.caretPos-1),f.refreshState(),f.updatePlaceholder(),f.updateOriginalInput({silent:b}),f.positionDropdown(),f.trigger("item_remove",a,c))},createItem:function(b,c){var d=this,e=d.caretPos;b=b||a.trim(d.$control_input.val()||"");var f=arguments[arguments.length-1];if("function"!=typeof f&&(f=function(){}),"boolean"!=typeof c&&(c=!0),!d.canCreate(b))return f(),!1;d.lock();var g="function"==typeof d.settings.create?this.settings.create:function(a){var b={};return b[d.settings.labelField]=a,b[d.settings.valueField]=a,b},h=D(function(a){if(d.unlock(),!a||"object"!=typeof a)return f();var b=z(a[d.settings.valueField]);return"string"!=typeof b?f():(d.setTextboxValue(""),d.addOption(a),d.setCaret(e),d.addItem(b),d.refreshOptions(c&&"single"!==d.settings.mode),void f(a))}),i=g.apply(this,[b,h]);return"undefined"!=typeof i&&h(i),!0},refreshItems:function(){this.lastQuery=null,this.isSetup&&this.addItem(this.items),this.refreshState(),this.updateOriginalInput()},refreshState:function(){var a,b=this;b.isRequired&&(b.items.length&&(b.isInvalid=!1),b.$control_input.prop("required",a)),b.refreshClasses()},refreshClasses:function(){var b=this,c=b.isFull(),d=b.isLocked;b.$wrapper.toggleClass("rtl",b.rtl),b.$control.toggleClass("focus",b.isFocused).toggleClass("disabled",b.isDisabled).toggleClass("required",b.isRequired).toggleClass("invalid",b.isInvalid).toggleClass("locked",d).toggleClass("full",c).toggleClass("not-full",!c).toggleClass("input-active",b.isFocused&&!b.isInputHidden).toggleClass("dropdown-active",b.isOpen).toggleClass("has-options",!a.isEmptyObject(b.options)).toggleClass("has-items",b.items.length>0),b.$control_input.data("grow",!c&&!d)},isFull:function(){return null!==this.settings.maxItems&&this.items.length>=this.settings.maxItems},updateOriginalInput:function(a){var b,c,d,e,f=this;if(a=a||{},f.tagType===v){for(d=[],b=0,c=f.items.length;c>b;b++)e=f.options[f.items[b]][f.settings.labelField]||"",d.push('<option value="'+A(f.items[b])+'" selected="selected">'+A(e)+"</option>");d.length||this.$input.attr("multiple")||d.push('<option value="" selected="selected"></option>'),f.$input.html(d.join(""))}else f.$input.val(f.getValue()),f.$input.attr("value",f.$input.val());f.isSetup&&(a.silent||f.trigger("change",f.$input.val()))},updatePlaceholder:function(){if(this.settings.placeholder){var a=this.$control_input;this.items.length?a.removeAttr("placeholder"):a.attr("placeholder",this.settings.placeholder),a.triggerHandler("update",{force:!0})}},open:function(){var a=this;a.isLocked||a.isOpen||"multi"===a.settings.mode&&a.isFull()||(a.focus(),a.isOpen=!0,a.refreshState(),a.$dropdown.css({visibility:"hidden",display:"block"}),a.positionDropdown(),a.$dropdown.css({visibility:"visible"}),a.trigger("dropdown_open",a.$dropdown))},close:function(){var a=this,b=a.isOpen;"single"===a.settings.mode&&a.items.length&&a.hideInput(),a.isOpen=!1,a.$dropdown.hide(),a.setActiveOption(null),a.refreshState(),b&&a.trigger("dropdown_close",a.$dropdown)},positionDropdown:function(){var a=this.$control,b="body"===this.settings.dropdownParent?a.offset():a.position();b.top+=a.outerHeight(!0),this.$dropdown.css({width:a.outerWidth(),top:b.top,left:b.left})},clear:function(a){var b=this;b.items.length&&(b.$control.children(":not(input)").remove(),b.items=[],b.lastQuery=null,b.setCaret(0),b.setActiveItem(null),b.updatePlaceholder(),b.updateOriginalInput({silent:a}),b.refreshState(),b.showInput(),b.trigger("clear"))},insertAtCaret:function(b){var c=Math.min(this.caretPos,this.items.length);0===c?this.$control.prepend(b):a(this.$control[0].childNodes[c]).before(b),this.setCaret(c+1)},deleteSelection:function(b){var c,d,e,f,g,h,i,j,k,l=this;if(e=b&&b.keyCode===p?-1:1,f=H(l.$control_input[0]),l.$activeOption&&!l.settings.hideSelected&&(i=l.getAdjacentOption(l.$activeOption,-1).attr("data-value")),g=[],l.$activeItems.length){for(k=l.$control.children(".active:"+(e>0?"last":"first")),h=l.$control.children(":not(input)").index(k),e>0&&h++,c=0,d=l.$activeItems.length;d>c;c++)g.push(a(l.$activeItems[c]).attr("data-value"));
3
  b&&(b.preventDefault(),b.stopPropagation())}else(l.isFocused||"single"===l.settings.mode)&&l.items.length&&(0>e&&0===f.start&&0===f.length?g.push(l.items[l.caretPos-1]):e>0&&f.start===l.$control_input.val().length&&g.push(l.items[l.caretPos]));if(!g.length||"function"==typeof l.settings.onDelete&&l.settings.onDelete.apply(l,[g])===!1)return!1;for("undefined"!=typeof h&&l.setCaret(h);g.length;)l.removeItem(g.pop());return l.showInput(),l.positionDropdown(),l.refreshOptions(!0),i&&(j=l.getOption(i),j.length&&l.setActiveOption(j)),!0},advanceSelection:function(a,b){var c,d,e,f,g,h,i=this;0!==a&&(i.rtl&&(a*=-1),c=a>0?"last":"first",d=H(i.$control_input[0]),i.isFocused&&!i.isInputHidden?(f=i.$control_input.val().length,g=0>a?0===d.start&&0===d.length:d.start===f,g&&!f&&i.advanceCaret(a,b)):(h=i.$control.children(".active:"+c),h.length&&(e=i.$control.children(":not(input)").index(h),i.setActiveItem(null),i.setCaret(a>0?e+1:e))))},advanceCaret:function(a,b){var c,d,e=this;0!==a&&(c=a>0?"next":"prev",e.isShiftDown?(d=e.$control_input[c](),d.length&&(e.hideInput(),e.setActiveItem(d),b&&b.preventDefault())):e.setCaret(e.caretPos+a))},setCaret:function(b){var c=this;if(b="single"===c.settings.mode?c.items.length:Math.max(0,Math.min(c.items.length,b)),!c.isPending){var d,e,f,g;for(f=c.$control.children(":not(input)"),d=0,e=f.length;e>d;d++)g=a(f[d]).detach(),b>d?c.$control_input.before(g):c.$control.append(g)}c.caretPos=b},lock:function(){this.close(),this.isLocked=!0,this.refreshState()},unlock:function(){this.isLocked=!1,this.refreshState()},disable:function(){var a=this;a.$input.prop("disabled",!0),a.$control_input.prop("disabled",!0).prop("tabindex",-1),a.isDisabled=!0,a.lock()},enable:function(){var a=this;a.$input.prop("disabled",!1),a.$control_input.prop("disabled",!1).prop("tabindex",a.tabIndex),a.isDisabled=!1,a.unlock()},destroy:function(){var b=this,c=b.eventNS,d=b.revertSettings;b.trigger("destroy"),b.off(),b.$wrapper.remove(),b.$dropdown.remove(),b.$input.html("").append(d.$children).removeAttr("tabindex").removeClass("selectized").attr({tabindex:d.tabindex}).show(),b.$control_input.removeData("grow"),b.$input.removeData("selectize"),a(window).off(c),a(document).off(c),a(document.body).off(c),delete b.$input[0].selectize},render:function(a,b){var c,d,e="",f=!1,g=this,h=/^[\t \r\n]*<([a-z][a-z0-9\-_]*(?:\:[a-z][a-z0-9\-_]*)?)/i;return("option"===a||"item"===a)&&(c=z(b[g.settings.valueField]),f=!!c),f&&(y(g.renderCache[a])||(g.renderCache[a]={}),g.renderCache[a].hasOwnProperty(c))?g.renderCache[a][c]:(e=g.settings.render[a].apply(this,[b,A]),("option"===a||"option_create"===a)&&(e=e.replace(h,"<$1 data-selectable")),"optgroup"===a&&(d=b[g.settings.optgroupValueField]||"",e=e.replace(h,'<$1 data-group="'+B(A(d))+'"')),("option"===a||"item"===a)&&(e=e.replace(h,'<$1 data-value="'+B(A(c||""))+'"')),f&&(g.renderCache[a][c]=e),e)},clearCache:function(a){var b=this;"undefined"==typeof a?b.renderCache={}:delete b.renderCache[a]},canCreate:function(a){var b=this;if(!b.settings.create)return!1;var c=b.settings.createFilter;return!(!a.length||"function"==typeof c&&!c.apply(b,[a])||"string"==typeof c&&!new RegExp(c).test(a)||c instanceof RegExp&&!c.test(a))}}),L.count=0,L.defaults={options:[],optgroups:[],plugins:[],delimiter:",",splitOn:null,persist:!0,diacritics:!0,create:!1,createOnBlur:!1,createFilter:null,highlight:!0,openOnFocus:!0,maxOptions:1e3,maxItems:null,hideSelected:null,addPrecedence:!1,selectOnTab:!1,preload:!1,allowEmptyOption:!1,closeAfterSelect:!1,scrollDuration:60,loadThrottle:300,loadingClass:"loading",dataAttr:"data-data",optgroupField:"optgroup",valueField:"value",labelField:"text",optgroupLabelField:"label",optgroupValueField:"value",lockOptgroupOrder:!1,sortField:"$order",searchField:["text"],searchConjunction:"and",mode:null,wrapperClass:"selectize-control",inputClass:"selectize-input",dropdownClass:"selectize-dropdown",dropdownContentClass:"selectize-dropdown-content",dropdownParent:null,copyClassesToDropdown:!0,render:{}},a.fn.selectize=function(b){var c=a.fn.selectize.defaults,d=a.extend({},c,b),e=d.dataAttr,f=d.labelField,g=d.valueField,h=d.optgroupField,i=d.optgroupLabelField,j=d.optgroupValueField,k=function(b,c){var h,i,j,k,l=b.attr(e);if(l)for(c.options=JSON.parse(l),h=0,i=c.options.length;i>h;h++)c.items.push(c.options[h][g]);else{var m=a.trim(b.val()||"");if(!d.allowEmptyOption&&!m.length)return;for(j=m.split(d.delimiter),h=0,i=j.length;i>h;h++)k={},k[f]=j[h],k[g]=j[h],c.options.push(k);c.items=j}},l=function(b,c){var k,l,m,n,o=c.options,p={},q=function(a){var b=e&&a.attr(e);return"string"==typeof b&&b.length?JSON.parse(b):null},r=function(b,e){b=a(b);var i=z(b.attr("value"));if(i||d.allowEmptyOption)if(p.hasOwnProperty(i)){if(e){var j=p[i][h];j?a.isArray(j)?j.push(e):p[i][h]=[j,e]:p[i][h]=e}}else{var k=q(b)||{};k[f]=k[f]||b.text(),k[g]=k[g]||i,k[h]=k[h]||e,p[i]=k,o.push(k),b.is(":selected")&&c.items.push(i)}},s=function(b){var d,e,f,g,h;for(b=a(b),f=b.attr("label"),f&&(g=q(b)||{},g[i]=f,g[j]=f,c.optgroups.push(g)),h=a("option",b),d=0,e=h.length;e>d;d++)r(h[d],f)};for(c.maxItems=b.attr("multiple")?null:1,n=b.children(),k=0,l=n.length;l>k;k++)m=n[k].tagName.toLowerCase(),"optgroup"===m?s(n[k]):"option"===m&&r(n[k])};return this.each(function(){if(!this.selectize){var e,f=a(this),g=this.tagName.toLowerCase(),h=f.attr("placeholder")||f.attr("data-placeholder");h||d.allowEmptyOption||(h=f.children('option[value=""]').text());var i={placeholder:h,options:[],optgroups:[],items:[]};"select"===g?l(f,i):k(f,i),e=new L(f,a.extend(!0,{},c,i,b))}})},a.fn.selectize.defaults=L.defaults,a.fn.selectize.support={validity:x},L.define("drag_drop",function(){if(!a.fn.sortable)throw new Error('The "drag_drop" plugin requires jQuery UI "sortable".');if("multi"===this.settings.mode){var b=this;b.lock=function(){var a=b.lock;return function(){var c=b.$control.data("sortable");return c&&c.disable(),a.apply(b,arguments)}}(),b.unlock=function(){var a=b.unlock;return function(){var c=b.$control.data("sortable");return c&&c.enable(),a.apply(b,arguments)}}(),b.setup=function(){var c=b.setup;return function(){c.apply(this,arguments);var d=b.$control.sortable({items:"[data-value]",forcePlaceholderSize:!0,disabled:b.isLocked,start:function(a,b){b.placeholder.css("width",b.helper.css("width")),d.css({overflow:"visible"})},stop:function(){d.css({overflow:"hidden"});var c=b.$activeItems?b.$activeItems.slice():null,e=[];d.children("[data-value]").each(function(){e.push(a(this).attr("data-value"))}),b.setValue(e),b.setActiveItem(c)}})}}()}}),L.define("dropdown_header",function(b){var c=this;b=a.extend({title:"Untitled",headerClass:"selectize-dropdown-header",titleRowClass:"selectize-dropdown-header-title",labelClass:"selectize-dropdown-header-label",closeClass:"selectize-dropdown-header-close",html:function(a){return'<div class="'+a.headerClass+'"><div class="'+a.titleRowClass+'"><span class="'+a.labelClass+'">'+a.title+'</span><a href="javascript:void(0)" class="'+a.closeClass+'">&times;</a></div></div>'}},b),c.setup=function(){var d=c.setup;return function(){d.apply(c,arguments),c.$dropdown_header=a(b.html(b)),c.$dropdown.prepend(c.$dropdown_header)}}()}),L.define("optgroup_columns",function(b){var c=this;b=a.extend({equalizeWidth:!0,equalizeHeight:!0},b),this.getAdjacentOption=function(b,c){var d=b.closest("[data-group]").find("[data-selectable]"),e=d.index(b)+c;return e>=0&&e<d.length?d.eq(e):a()},this.onKeyDown=function(){var a=c.onKeyDown;return function(b){var d,e,f,g;return!this.isOpen||b.keyCode!==j&&b.keyCode!==m?a.apply(this,arguments):(c.ignoreHover=!0,g=this.$activeOption.closest("[data-group]"),d=g.find("[data-selectable]").index(this.$activeOption),g=b.keyCode===j?g.prev("[data-group]"):g.next("[data-group]"),f=g.find("[data-selectable]"),e=f.eq(Math.min(f.length-1,d)),void(e.length&&this.setActiveOption(e)))}}();var d=function(){var a,b=d.width,c=document;return"undefined"==typeof b&&(a=c.createElement("div"),a.innerHTML='<div style="width:50px;height:50px;position:absolute;left:-50px;top:-50px;overflow:auto;"><div style="width:1px;height:100px;"></div></div>',a=a.firstChild,c.body.appendChild(a),b=d.width=a.offsetWidth-a.clientWidth,c.body.removeChild(a)),b},e=function(){var e,f,g,h,i,j,k;if(k=a("[data-group]",c.$dropdown_content),f=k.length,f&&c.$dropdown_content.width()){if(b.equalizeHeight){for(g=0,e=0;f>e;e++)g=Math.max(g,k.eq(e).height());k.css({height:g})}b.equalizeWidth&&(j=c.$dropdown_content.innerWidth()-d(),h=Math.round(j/f),k.css({width:h}),f>1&&(i=j-h*(f-1),k.eq(f-1).css({width:i})))}};(b.equalizeHeight||b.equalizeWidth)&&(C.after(this,"positionDropdown",e),C.after(this,"refreshOptions",e))}),L.define("remove_button",function(b){if("single"!==this.settings.mode){b=a.extend({label:"&times;",title:"Remove",className:"remove",append:!0},b);var c=this,d='<a href="javascript:void(0)" class="'+b.className+'" tabindex="-1" title="'+A(b.title)+'">'+b.label+"</a>",e=function(a,b){var c=a.search(/(<\/[^>]+>\s*)$/);return a.substring(0,c)+b+a.substring(c)};this.setup=function(){var f=c.setup;return function(){if(b.append){var g=c.settings.render.item;c.settings.render.item=function(){return e(g.apply(this,arguments),d)}}f.apply(this,arguments),this.$control.on("click","."+b.className,function(b){if(b.preventDefault(),!c.isLocked){var d=a(b.currentTarget).parent();c.setActiveItem(d),c.deleteSelection()&&c.setCaret(c.items.length)}})}}()}}),L.define("restore_on_backspace",function(a){var b=this;a.text=a.text||function(a){return a[this.settings.labelField]},this.onKeyDown=function(){var c=b.onKeyDown;return function(b){var d,e;return b.keyCode===p&&""===this.$control_input.val()&&!this.$activeItems.length&&(d=this.caretPos-1,d>=0&&d<this.items.length)?(e=this.options[this.items[d]],this.deleteSelection(b)&&(this.setTextboxValue(a.text.apply(this,[e])),this.refreshOptions(!0)),void b.preventDefault()):c.apply(this,arguments)}}()}),L});
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: 99robots, charliepatel
3
  Tags: header, footer, code manager, snippet, functions.php, tracking, google analytics, adsense, verification, pixel
4
  Requires at least: 4.0
5
- Tested up to: 4.6.1
6
- Stable tag: 1.0.2
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Donate link: https://99robots.com
@@ -11,7 +11,7 @@ Donate link: https://99robots.com
11
  Easily add tracking code snippets, conversion pixels, or other scripts required by third party services for analytics, marketing, or chat features.
12
 
13
  == Description ==
14
- Header Footer Code Manager by 99 Robots is a easy interface to add snippets to the header or footer or above or below the content of your page.
15
 
16
  = BENEFITS =
17
  * Never have to worry about inadvertently breaking your site by adding code
@@ -26,7 +26,7 @@ Header Footer Code Manager by 99 Robots is a easy interface to add snippets to t
26
  * Supports custom post types
27
  * Supports ability to load only on a specific post or page, or latest posts
28
  * Control where exactly on the page the script is loaded - head, footer, before content, or after content
29
- * Script can load only on desktops or mobile. Enable or disable one or the other.
30
  * Use shortcodes to manually place the code anywhere
31
  * Label every snippet for easy reference
32
  * Plugin logs which user added and last edited the snippet, and when
@@ -57,7 +57,7 @@ Header Footer Code Manager by 99 Robots is a easy interface to add snippets to t
57
  * Google Adsense
58
  * Google Tag Manager
59
  * Clicky Web Analytics or other analytics tracking scripts
60
- * Chat modules such as Olark, Drip, or
61
  * Pinterest site verification
62
  * Facebook Pixels, Facebook Scripts, Facebook og:image Tag
63
  * Google Conversion Pixels
@@ -88,7 +88,7 @@ http://www.99robots.com/docs/header-footer-code-manager
88
  == Frequently Asked Questions ==
89
 
90
  = Q. I have a question =
91
- A. Since this is a free plugin, please ask all questions on the support forum here on WordPress.org. We will try to respond to every question within 48 hours.
92
 
93
  = Q. How can I request a feature or encourage future development? =
94
  A. Free plugins rely on user feedback. Therefore, the best thing you can do for us is to leave a review to encourage others to try the plugin. The more users, the more likely newer features will be added. That's a very small thing to ask for in exchange for a FREE plugin.
@@ -98,6 +98,9 @@ A. If your script is not supported, just let us know and we'll look into it imme
98
 
99
  == Changelog ==
100
 
 
 
 
101
  = 1.0.2 = 2016-9-22
102
  * FIXED: Updated code triggering a fatal error for sites with older PHP versions.
103
 
@@ -105,4 +108,4 @@ A. If your script is not supported, just let us know and we'll look into it imme
105
  * FIXED: Updated code triggering a fatal error for sites with older PHP versions; now compatible.
106
 
107
  = 1.0.0 = 2016-7-20
108
- * Initial release - HFCM is born! :)
2
  Contributors: 99robots, charliepatel
3
  Tags: header, footer, code manager, snippet, functions.php, tracking, google analytics, adsense, verification, pixel
4
  Requires at least: 4.0
5
+ Tested up to: 4.8.0
6
+ Stable tag: 1.0.3
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Donate link: https://99robots.com
11
  Easily add tracking code snippets, conversion pixels, or other scripts required by third party services for analytics, marketing, or chat features.
12
 
13
  == Description ==
14
+ Header Footer Code Manager by 99 Robots is a easy interface to add snippets to the header or footer or above or below the content of your page.
15
 
16
  = BENEFITS =
17
  * Never have to worry about inadvertently breaking your site by adding code
26
  * Supports custom post types
27
  * Supports ability to load only on a specific post or page, or latest posts
28
  * Control where exactly on the page the script is loaded - head, footer, before content, or after content
29
+ * Script can load only on desktops or mobile. Enable or disable one or the other.
30
  * Use shortcodes to manually place the code anywhere
31
  * Label every snippet for easy reference
32
  * Plugin logs which user added and last edited the snippet, and when
57
  * Google Adsense
58
  * Google Tag Manager
59
  * Clicky Web Analytics or other analytics tracking scripts
60
+ * Chat modules such as Olark, Drip, or
61
  * Pinterest site verification
62
  * Facebook Pixels, Facebook Scripts, Facebook og:image Tag
63
  * Google Conversion Pixels
88
  == Frequently Asked Questions ==
89
 
90
  = Q. I have a question =
91
+ A. Since this is a free plugin, please ask all questions on the support forum here on WordPress.org. We will try to respond to every question within 48 hours.
92
 
93
  = Q. How can I request a feature or encourage future development? =
94
  A. Free plugins rely on user feedback. Therefore, the best thing you can do for us is to leave a review to encourage others to try the plugin. The more users, the more likely newer features will be added. That's a very small thing to ask for in exchange for a FREE plugin.
98
 
99
  == Changelog ==
100
 
101
+ = 1.0.3 = 2017-06-09
102
+ * Compatible with WordPress 4.8
103
+
104
  = 1.0.2 = 2016-9-22
105
  * FIXED: Updated code triggering a fatal error for sites with older PHP versions.
106
 
108
  * FIXED: Updated code triggering a fatal error for sites with older PHP versions; now compatible.
109
 
110
  = 1.0.0 = 2016-7-20
111
+ * Initial release - HFCM is born! :)
uninstall.php CHANGED
@@ -1,18 +1,17 @@
1
- <?php
2
- // If uninstall is not called from WordPress, exit
3
- if (!defined('WP_UNINSTALL_PLUGIN')) {
4
- exit();
5
- }
6
-
7
- $option_name = 'hfcm_db_version';
8
-
9
- delete_option($option_name);
10
-
11
- // For site options in Multisite
12
- delete_site_option($option_name);
13
-
14
- // Drop a custom db table
15
- global $wpdb;
16
- $table_name = $wpdb->prefix . "hfcm_scripts";
17
-
18
- $wpdb->query("DROP TABLE IF EXISTS $table_name");
1
+ <?php
2
+ // If uninstall is not called from WordPress, exit
3
+ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
4
+ exit;
5
+ }
6
+
7
+ $option_name = 'hfcm_db_version';
8
+ delete_option( $option_name );
9
+
10
+ // For site options in Multisite
11
+ delete_site_option( $option_name );
12
+
13
+ // Drop a custom db table
14
+ global $wpdb;
15
+ $table_name = $wpdb->prefix . 'hfcm_scripts';
16
+
17
+ $wpdb->query( "DROP TABLE IF EXISTS $table_name" );