Header Footer Code Manager - Version 1.1.11

Version Description

2021-08-10 * FIXED: Warnings - Undefined Variables * FIXED: Selectize issue of not able to select first option from the dropdown * ADDED: Snippet types * ADDED: Code Editor in place of textarea * ADDED: Import/Export Snippets * UPDATED: Compatibility with WordPress 5.8

Download this release

Release Info

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

Code changes from version 1.1.10 to 1.1.11

99robots-header-footer-code-manager.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Header Footer Code Manager
4
  * Plugin URI: https://draftpress.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://draftpress.com/"> official page</a>.
6
- * Version: 1.1.10
7
  * Author: 99robots
8
  * Author URI: https://draftpress.com/
9
  * Disclaimer: Use at your own risk. No warranty expressed or implied is provided.
@@ -18,28 +18,59 @@ if (!defined('WPINC')) {
18
  die;
19
  }
20
 
21
- global $hfcm_db_version;
22
- $hfcm_db_version = '1.1';
 
 
 
 
 
 
 
 
 
 
23
 
24
- /*
25
- * function to create the DB / Options / Defaults
26
- */
27
- function hfcm_options_install()
28
- {
29
- $hfcm_now = strtotime("now");
30
- add_option('hfcm_activation_date', $hfcm_now);
31
- update_option('hfcm_activation_date', $hfcm_now);
32
-
33
- global $wpdb;
34
- global $hfcm_db_version;
35
-
36
- $table_name = $wpdb->prefix . 'hfcm_scripts';
37
- $charset_collate = $wpdb->get_charset_collate();
38
- $sql =
39
- "CREATE TABLE IF NOT EXISTS $table_name(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  `script_id` int(10) NOT NULL AUTO_INCREMENT,
41
  `name` varchar(100) DEFAULT NULL,
42
  `snippet` text,
 
43
  `device_type` enum('mobile','desktop', 'both') DEFAULT 'both',
44
  `location` varchar(100) NOT NULL,
45
  `display_on` enum('All','s_pages', 's_posts','s_categories','s_custom_posts','s_tags','latest_posts','manual') NOT NULL DEFAULT 'All',
@@ -59,495 +90,1015 @@ function hfcm_options_install()
59
  PRIMARY KEY (`script_id`)
60
  ) $charset_collate; ";
61
 
62
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
63
- dbDelta($sql);
64
- add_option('hfcm_db_version', $hfcm_db_version);
65
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
- register_activation_hook(__FILE__, 'hfcm_options_install');
68
-
69
- function hfcm_db_update_check()
70
- {
71
- global $hfcm_db_version;
72
- global $wpdb;
73
-
74
- $table_name = $wpdb->prefix . 'hfcm_scripts';
75
- if (get_site_option('hfcm_db_version') != $hfcm_db_version) {
76
- $wpdb->show_errors();
77
-
78
- // Check for Exclude Pages
79
- $column_name = 'ex_pages';
80
- if (!empty($wpdb->dbname)) {
81
- $checkcolumn = $wpdb->get_results($wpdb->prepare(
82
- "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = %s ",
83
- $wpdb->dbname,
84
- $table_name,
85
- $column_name
86
- ));
87
- if (empty($checkcolumn)) {
88
- $altersql = "ALTER TABLE `$table_name` ADD `ex_pages` varchar(300) DEFAULT 0 AFTER `s_pages`";
89
- $wpdb->query($altersql);
90
  }
91
 
92
- //Check for Exclude Posts
93
- $column_name1 = 'ex_posts';
94
- $checkcolumn2 = $wpdb->get_results($wpdb->prepare(
95
- "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = %s ",
96
- $wpdb->dbname,
97
- $table_name,
98
- $column_name1
99
- ));
100
- if (empty($checkcolumn2)) {
101
- $altersql = "ALTER TABLE `$table_name` ADD `ex_posts` varchar(300) DEFAULT 0 AFTER `s_posts`";
102
- $wpdb->query($altersql);
 
103
  }
104
  }
105
- hfcm_options_install();
106
- }
107
- update_option('hfcm_db_version', $hfcm_db_version);
108
- }
109
 
110
- add_action('plugins_loaded', 'hfcm_db_update_check');
 
 
111
 
112
- /*
113
- * Enqueue style-file, if it exists.
114
- */
115
- function hfcm_enqueue_assets($hook)
116
- {
117
- $allowed_pages = array(
118
- 'toplevel_page_hfcm-list',
119
- 'hfcm_page_hfcm-create',
120
- 'admin_page_hfcm-update',
121
- );
122
-
123
- wp_register_style('hfcm_general_admin_assets', plugins_url('css/style-general-admin.css', __FILE__));
124
- wp_enqueue_style('hfcm_general_admin_assets');
125
-
126
- if (in_array($hook, $allowed_pages)) {
127
- // Plugin's CSS
128
- wp_register_style('hfcm_assets', plugins_url('css/style-admin.css', __FILE__));
129
- wp_enqueue_style('hfcm_assets');
130
- }
131
 
132
- // Remove hfcm-list from $allowed_pages
133
- array_shift($allowed_pages);
134
 
135
- if (in_array($hook, $allowed_pages)) {
136
- // selectize.js plugin CSS and JS files
137
- wp_register_style('selectize-css', plugins_url('css/selectize.bootstrap3.css', __FILE__));
138
- wp_enqueue_style('selectize-css');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
 
140
- wp_register_script('selectize-js', plugins_url('js/selectize.min.js', __FILE__), array('jquery'));
141
- wp_enqueue_script('selectize-js');
142
- }
143
- }
 
 
 
 
 
 
 
144
 
145
- add_action('admin_enqueue_scripts', 'hfcm_enqueue_assets');
 
 
 
 
 
 
146
 
147
- /*
148
- * This function loads plugins translation files
149
- */
150
- function hfcm_load_translation_files()
151
- {
152
- load_plugin_textdomain('99robots-header-footer-code-manager', false, dirname(plugin_basename(__FILE__)) . '/languages');
153
- }
154
 
155
- add_action('plugins_loaded', 'hfcm_load_translation_files');
156
 
157
- /*
158
- * function to create menu page, and submenu pages.
159
- */
160
- function hfcm_modifymenu()
161
- {
162
-
163
- // This is the main item for the menu
164
- add_menu_page(
165
- __('Header Footer Code Manager', '99robots-header-footer-code-manager'),
166
- __('HFCM', '99robots-header-footer-code-manager'),
167
- 'manage_options',
168
- 'hfcm-list',
169
- 'hfcm_list',
170
- plugins_url('images/', __FILE__) . '99robots.png'
171
- );
172
-
173
- // This is a submenu
174
- add_submenu_page(
175
- 'hfcm-list',
176
- __('All Snippets', '99robots-header-footer-code-manager'),
177
- __('All Snippets', '99robots-header-footer-code-manager'),
178
- 'manage_options',
179
- 'hfcm-list',
180
- 'hfcm_list'
181
- );
182
-
183
- // This is a submenu
184
- add_submenu_page(
185
- 'hfcm-list',
186
- __('Add New Snippet', '99robots-header-footer-code-manager'),
187
- __('Add New', '99robots-header-footer-code-manager'),
188
- 'manage_options',
189
- 'hfcm-create',
190
- 'hfcm_create'
191
- );
192
-
193
- // This submenu is HIDDEN, however, we need to add it anyways
194
- add_submenu_page(
195
- null,
196
- __('Update Script', '99robots-header-footer-code-manager'),
197
- __('Update', '99robots-header-footer-code-manager'),
198
- 'manage_options',
199
- 'hfcm-update',
200
- 'hfcm_update'
201
- );
202
-
203
- // This submenu is HIDDEN, however, we need to add it anyways
204
- add_submenu_page(
205
- null,
206
- __('Request Handler Script', '99robots-header-footer-code-manager'),
207
- __('Request Handler', '99robots-header-footer-code-manager'),
208
- 'manage_options',
209
- 'hfcm-request-handler',
210
- 'hfcm_request_handler'
211
- );
212
- }
213
 
214
- add_action('admin_menu', 'hfcm_modifymenu');
215
-
216
- // Adding A settings link for the plugin on the Settings Page
217
- add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'hfcm_add_plugin_page_settings_link');
218
- function hfcm_add_plugin_page_settings_link($links)
219
- {
220
- $links = array_merge(
221
- array('<a href="' . admin_url('admin.php?page=hfcm-list') . '">' . __('Settings') . '</a>'),
222
- $links
223
- );
224
- return $links;
225
- }
 
 
 
226
 
227
- /*
228
- * Check Installation Date
229
- */
230
- function hfcm_check_installation_date()
231
- {
232
- $install_date = get_option('hfcm_activation_date');
233
- $past_date = strtotime('-7 days');
234
 
235
- if ($past_date >= $install_date) {
236
- add_action('admin_notices', 'hfcm_review_push_notice');
237
- }
238
- }
239
 
240
- add_action('admin_init', 'hfcm_check_installation_date');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
 
242
- /*
243
- * Create the Admin Notice
244
- */
245
- function hfcm_review_push_notice()
246
- {
247
- $allowed_pages_notices = array(
248
- 'toplevel_page_hfcm-list',
249
- 'hfcm_page_hfcm-create',
250
- 'admin_page_hfcm-update',
251
- );
252
- $screen = get_current_screen()->id;
253
-
254
- $user_id = get_current_user_id();
255
- // Check if current user has already dismissed it
256
- $install_date = get_option('hfcm_activation_date');
257
- if (!get_user_meta($user_id, 'hfcm_plugin_notice_dismissed') && in_array($screen, $allowed_pages_notices)) {
258
- ?>
259
- <div id="hfcm-message" class="notice notice-success">
260
- <a class="hfcm-dismiss-alert notice-dismiss" href="?hfcm-admin-notice-dismissed">Dismiss</a>
261
- <p><?php _e('Hey there! You’ve been using the <strong>Header Footer Code Manager</strong> plugin for a while now. If you like the plugin, please support our awesome development and support team by leaving a <a class="hfcm-review-stars" href="https://wordpress.org/support/plugin/header-footer-code-manager/reviews/"><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span></a> rating. <a href="https://wordpress.org/support/plugin/header-footer-code-manager/reviews/">Rate it!</a> It’ll mean the world to us and keep this plugin free and constantly updated. <a href="https://wordpress.org/support/plugin/header-footer-code-manager/reviews/">Leave A Review</a>', '99robots-header-footer-code-manager'); ?>
262
- </p>
263
- </div>
264
- <?php
265
- }
266
- }
267
 
268
- /*
269
- * Check if current user has already dismissed it
270
- */
271
- function hfcm_plugin_notice_dismissed()
272
- {
273
- $user_id = get_current_user_id();
274
- // Checking if user clicked on the Dismiss button
275
- if (isset($_GET['hfcm-admin-notice-dismissed'])) {
276
- add_user_meta($user_id, 'hfcm_plugin_notice_dismissed', 'true', true);
277
- // Redirect to original page the user was on
278
- $current_url = wp_get_referer();
279
- wp_redirect($current_url);
280
- exit;
281
- }
282
- }
283
 
284
- add_action('admin_init', 'hfcm_plugin_notice_dismissed');
 
 
 
 
 
285
 
286
- /*****/
 
287
 
288
- // Files containing submenu functions
289
- require_once(plugin_dir_path(__FILE__) . 'includes/hfcm-list.php');
290
- require_once(plugin_dir_path(__FILE__) . 'includes/hfcm-create.php');
291
- require_once(plugin_dir_path(__FILE__) . 'includes/hfcm-update.php');
292
- require_once(plugin_dir_path(__FILE__) . 'includes/hfcm-request-handler.php');
293
 
294
- /*
295
- * Function to render the snippet
296
- */
297
- function hfcm_render_snippet($scriptdata)
298
- {
299
- $output = "<!-- HFCM by 99 Robots - Snippet # {$scriptdata->script_id}: {$scriptdata->name} -->\n{$scriptdata->snippet}\n<!-- /end HFCM by 99 Robots -->\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
 
301
- return $output;
302
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
303
 
304
- /*
305
- * Function to implement shortcode
306
- */
307
- function hfcm_shortcode($atts)
308
- {
309
- global $wpdb;
310
- $table_name = $wpdb->prefix . 'hfcm_scripts';
311
- if (!empty($atts['id'])) {
312
- $id = (int)$atts['id'];
313
- $hide_device = wp_is_mobile() ? 'desktop' : 'mobile';
314
- $script = $wpdb->get_results($wpdb->prepare("SELECT * from $table_name where status='active' AND device_type!='$hide_device' AND script_id=%s", $id));
315
- if (!empty($script)) {
316
- return hfcm_render_snippet($script[0]);
317
  }
318
- }
319
- }
320
 
321
- add_shortcode('hfcm', 'hfcm_shortcode');
 
 
 
 
 
 
322
 
323
- /*
324
- * Function to json_decode array and check if empty
325
- */
326
- function hfcm_not_empty($scriptdata, $prop_name)
327
- {
328
- $data = json_decode($scriptdata->{$prop_name});
329
- if (empty($data)) {
330
- return false;
331
- }
332
- return true;
333
- }
334
 
335
- /*
336
- * Function to decide which snippets to show - triggered by hooks
337
- */
338
- function hfcm_add_snippets($location = '', $content = '')
339
- {
340
- global $wpdb;
 
341
 
342
- $beforecontent = '';
343
- $aftercontent = '';
 
344
 
345
- if ($location && in_array($location, array('header', 'footer'))) {
346
- $display_location = "location='$location'";
347
- } else {
348
- $display_location = "location NOT IN ( 'header', 'footer' )";
349
- }
350
 
351
- $table_name = $wpdb->prefix . 'hfcm_scripts';
352
- $hide_device = wp_is_mobile() ? 'desktop' : 'mobile';
353
- $script = $wpdb->get_results("SELECT * from $table_name where $display_location AND status='active' AND device_type!='$hide_device'");
 
 
 
 
 
 
 
 
 
354
 
355
- if (!empty($script)) {
356
- foreach ($script as $key => $scriptdata) {
357
- $out = '';
358
- switch ($scriptdata->display_on) {
359
- case 'All':
360
 
361
- if ((hfcm_not_empty($scriptdata, 'ex_pages') && is_page(json_decode($scriptdata->ex_pages))) || (hfcm_not_empty($scriptdata, 'ex_posts') && is_single(json_decode($scriptdata->ex_posts)))) {
362
- $out = '';
363
- } else {
364
- $out = hfcm_render_snippet($scriptdata);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
365
  }
366
- break;
367
- case 'latest_posts':
368
- if (is_single()) {
369
- $args = array(
370
- 'public' => true,
371
- '_builtin' => false,
372
- );
373
- $output = 'names'; // names or objects, note names is the default
374
- $operator = 'and'; // 'and' or 'or'
375
- $c_posttypes = get_post_types($args, $output, $operator);
376
- $posttypes = array('post');
377
- foreach ($c_posttypes as $cpkey => $cpdata) {
378
- $posttypes[] = $cpdata;
379
- }
380
- if (!empty($scriptdata->lp_count)) {
381
- $latestposts = wp_get_recent_posts(array(
382
- 'numberposts' => $scriptdata->lp_count,
383
- 'post_type' => $posttypes,
384
- ));
385
- } else {
386
- $latestposts = wp_get_recent_posts(array('post_type' => $posttypes));
387
- }
388
 
389
- $islatest = false;
390
- foreach ($latestposts as $key => $lpostdata) {
391
- if (get_the_ID() == $lpostdata['ID']) {
392
- $islatest = true;
393
- }
394
- }
395
 
396
- if ($islatest) {
397
- $out = hfcm_render_snippet($scriptdata);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
398
  }
399
  }
400
- break;
401
- case 's_categories':
402
- if (hfcm_not_empty($scriptdata, 's_categories') && in_category(json_decode($scriptdata->s_categories))) {
403
- if (is_category(json_decode($scriptdata->s_categories))) {
404
- $out = hfcm_render_snippet($scriptdata);
405
- }
406
- if (!is_archive() && !is_home()) {
407
- $out = hfcm_render_snippet($scriptdata);
408
  }
409
  }
410
- break;
411
- case 's_custom_posts':
412
- if (hfcm_not_empty($scriptdata, 's_custom_posts') && is_singular(json_decode($scriptdata->s_custom_posts))) {
413
- $out = hfcm_render_snippet($scriptdata);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
414
  }
415
- break;
416
- case 's_posts':
417
- if (hfcm_not_empty($scriptdata, 's_posts') && is_single(json_decode($scriptdata->s_posts))) {
418
- $out = hfcm_render_snippet($scriptdata);
419
- }
420
- break;
421
- case 's_pages':
422
- if (hfcm_not_empty($scriptdata, 's_pages')) {
423
- // Gets the page ID of the blog page
424
- $blog_page = get_option('page_for_posts');
425
- // Checks if the blog page is present in the array of selected pages
426
- if (in_array($blog_page, json_decode($scriptdata->s_pages))) {
427
- if (is_page(json_decode($scriptdata->s_pages)) || (!is_front_page() && is_home())) {
428
- $out = hfcm_render_snippet($scriptdata);
429
- }
430
- } elseif (is_page(json_decode($scriptdata->s_pages))) {
431
- $out = hfcm_render_snippet($scriptdata);
432
- }
433
- }
434
- break;
435
- case 's_tags':
436
- if (hfcm_not_empty($scriptdata, 's_tags') && has_tag(json_decode($scriptdata->s_tags))) {
437
- if (is_tag(json_decode($scriptdata->s_tags))) {
438
- $out = hfcm_render_snippet($scriptdata);
439
- }
440
- if (!is_archive() && !is_home()) {
441
- $out = hfcm_render_snippet($scriptdata);
442
- }
443
  }
444
- }
445
 
446
- switch ($scriptdata->location) {
447
- case 'before_content':
448
- $beforecontent .= $out;
449
- break;
450
- case 'after_content':
451
- $aftercontent .= $out;
452
- break;
453
- default:
454
- echo $out;
455
  }
456
  }
457
- }
458
- // Return results after the loop finishes
459
- return $beforecontent . $content . $aftercontent;
460
- }
461
 
462
- /*
463
- * Function to add snippets in the header
464
- */
465
- function hfcm_header_scripts()
466
- {
467
- hfcm_add_snippets('header');
468
- }
469
 
470
- add_action('wp_head', 'hfcm_header_scripts');
471
-
472
- /*
473
- * Function to add snippets in the footer
474
- */
475
- function hfcm_footer_scripts()
476
- {
477
- hfcm_add_snippets('footer');
478
- }
479
-
480
- add_action('wp_footer', 'hfcm_footer_scripts');
481
 
 
 
482
 
483
- /*
484
- * Function to add snippets before/after the content
485
- */
486
- function hfcm_content_scripts($content)
487
- {
488
- return hfcm_add_snippets(false, $content);
489
- }
490
-
491
- add_action('the_content', 'hfcm_content_scripts');
492
-
493
- /*
494
- * Load redirection Javascript code
495
- */
496
- function hfcm_redirect($url = '')
497
- {
498
- // Register the script
499
- wp_register_script('hfcm_redirection', plugins_url('js/location.js', __FILE__));
500
-
501
- // Localize the script with new data
502
- $translation_array = array('url' => $url);
503
- wp_localize_script('hfcm_redirection', 'hfcm_location', $translation_array);
504
-
505
- // Enqueued script with localized data.
506
- wp_enqueue_script('hfcm_redirection');
507
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
508
 
509
- // Handle AJAX requests
510
- add_action('wp_ajax_hfcm-request', 'hfcm_request_handler');
 
 
 
 
 
 
 
 
 
 
 
 
 
511
 
512
- /*
513
- * Function to sanitize POST data
514
- */
515
- function hfcm_sanitize_text($key, $sanitize = true)
516
- {
517
- if (!empty($_POST['data'][$key])) {
518
- $out = stripslashes_deep($_POST['data'][$key]);
519
- if ($sanitize) {
520
- $out = sanitize_text_field($out);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
521
  }
522
- return $out;
523
- }
524
 
525
- return '';
526
- }
 
 
 
 
 
527
 
528
- /*
529
- * Function to sanitize strings within POST data arrays
530
- */
531
- function hfcm_sanitize_array($key, $type = 'integer')
532
- {
533
- if (!empty($_POST['data'][$key])) {
534
- $arr = $_POST['data'][$key];
535
 
536
- if (!is_array($arr)) {
537
- return array();
538
  }
539
 
540
- if ('integer' === $type) {
541
- return array_map('absint', $arr);
542
- } else { // strings
543
- $new_array = array();
544
- foreach ($arr as $val) {
545
- $new_array[] = sanitize_text_field($val);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
546
  }
547
  }
548
 
549
- return $new_array;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
550
  }
551
 
552
- return array();
553
- }
3
  * Plugin Name: Header Footer Code Manager
4
  * Plugin URI: https://draftpress.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://draftpress.com/"> official page</a>.
6
+ * Version: 1.1.11
7
  * Author: 99robots
8
  * Author URI: https://draftpress.com/
9
  * Disclaimer: Use at your own risk. No warranty expressed or implied is provided.
18
  die;
19
  }
20
 
21
+ register_activation_hook(__FILE__, array('NNR_HFCM', 'hfcm_options_install'));
22
+ add_action('plugins_loaded', array('NNR_HFCM', 'hfcm_db_update_check'));
23
+ add_action('admin_enqueue_scripts', array('NNR_HFCM', 'hfcm_enqueue_assets'));
24
+ add_action('plugins_loaded', array('NNR_HFCM', 'hfcm_load_translation_files'));
25
+ add_action('admin_menu', array('NNR_HFCM', 'hfcm_modifymenu'));
26
+ add_filter('plugin_action_links_' . plugin_basename(__FILE__), array('NNR_HFCM', 'hfcm_add_plugin_page_settings_link'));
27
+ add_action('admin_init', array('NNR_HFCM', 'hfcm_init'));
28
+ add_shortcode('hfcm', array('NNR_HFCM', 'hfcm_shortcode'));
29
+ add_action('wp_head', array('NNR_HFCM', 'hfcm_header_scripts'));
30
+ add_action('wp_footer', array('NNR_HFCM', 'hfcm_footer_scripts'));
31
+ add_action('the_content', array('NNR_HFCM', 'hfcm_content_scripts'));
32
+ add_action('wp_ajax_hfcm-request', array('NNR_HFCM', 'hfcm_request_handler'));
33
 
34
+ // Files containing submenu functions
35
+ require_once(plugin_dir_path(__FILE__) . 'includes/hfcm-list.php');
36
+
37
+ if (!class_exists('NNR_HFCM')) :
38
+
39
+ class NNR_HFCM
40
+ {
41
+ public static $nnr_hfcm_db_version = "1.2";
42
+ public static $nnr_hfcm_table = "hfcm_scripts";
43
+
44
+
45
+ /*
46
+ * hfcm init function
47
+ */
48
+ public static function hfcm_init() {
49
+ self::hfcm_check_installation_date();
50
+ self::hfcm_plugin_notice_dismissed();
51
+ self::hfcm_import_snippets();
52
+ self::hfcm_export_snippets();
53
+ }
54
+
55
+ /*
56
+ * function to create the DB / Options / Defaults
57
+ */
58
+ public static function hfcm_options_install()
59
+ {
60
+ $hfcm_now = strtotime("now");
61
+ add_option('hfcm_activation_date', $hfcm_now);
62
+ update_option('hfcm_activation_date', $hfcm_now);
63
+
64
+ global $wpdb;
65
+
66
+ $table_name = $wpdb->prefix . self::$nnr_hfcm_table;
67
+ $charset_collate = $wpdb->get_charset_collate();
68
+ $sql =
69
+ "CREATE TABLE IF NOT EXISTS $table_name(
70
  `script_id` int(10) NOT NULL AUTO_INCREMENT,
71
  `name` varchar(100) DEFAULT NULL,
72
  `snippet` text,
73
+ `snippet_type` enum('html', 'js', 'css') DEFAULT 'html',
74
  `device_type` enum('mobile','desktop', 'both') DEFAULT 'both',
75
  `location` varchar(100) NOT NULL,
76
  `display_on` enum('All','s_pages', 's_posts','s_categories','s_custom_posts','s_tags','latest_posts','manual') NOT NULL DEFAULT 'All',
90
  PRIMARY KEY (`script_id`)
91
  ) $charset_collate; ";
92
 
93
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
94
+ dbDelta($sql);
95
+ add_option('hfcm_db_version', self::$nnr_hfcm_db_version);
96
+ }
97
+
98
+
99
+ /*
100
+ * function to check if plugin is being updated
101
+ */
102
+ public static function hfcm_db_update_check()
103
+ {
104
+ global $wpdb;
105
+
106
+ $table_name = $wpdb->prefix . self::$nnr_hfcm_table;
107
+ if (get_site_option('hfcm_db_version') != self::$nnr_hfcm_db_version) {
108
+ $wpdb->show_errors();
109
+
110
+ if (!empty($wpdb->dbname)) {
111
+ // Check for Exclude Pages
112
+ $nnr_column_ex_pages = 'ex_pages';
113
+ $nnr_check_column_ex_pages = $wpdb->get_results($wpdb->prepare(
114
+ "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = %s ",
115
+ $wpdb->dbname,
116
+ $table_name,
117
+ $nnr_column_ex_pages
118
+ ));
119
+ if (empty($nnr_check_column_ex_pages)) {
120
+ $nnr_alter_sql = "ALTER TABLE `$table_name` ADD `ex_pages` varchar(300) DEFAULT 0 AFTER `s_pages`";
121
+ $wpdb->query($nnr_alter_sql);
122
+ }
123
+
124
+ // Check for Exclude Posts
125
+ $nnr_column_ex_posts = 'ex_posts';
126
+ $nnr_check_column_ex_posts = $wpdb->get_results($wpdb->prepare(
127
+ "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = %s ",
128
+ $wpdb->dbname,
129
+ $table_name,
130
+ $nnr_column_ex_posts
131
+ ));
132
+ if (empty($nnr_check_column_ex_posts)) {
133
+ $nnr_alter_sql = "ALTER TABLE `$table_name` ADD `ex_posts` varchar(300) DEFAULT 0 AFTER `s_posts`";
134
+ $wpdb->query($nnr_alter_sql);
135
+ }
136
+
137
+ // Check for Snippet Type
138
+ $nnr_column_snippet_type = 'snippet_type';
139
+ $nnr_check_column_snippet_type = $wpdb->get_results($wpdb->prepare(
140
+ "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = %s ",
141
+ $wpdb->dbname,
142
+ $table_name,
143
+ $nnr_column_snippet_type
144
+ ));
145
+ if (empty($nnr_check_column_snippet_type)) {
146
+ $nnr_alter_sql = "ALTER TABLE `$table_name` ADD `snippet_type` enum('html', 'js', 'css') DEFAULT 'html' AFTER `snippet`";
147
+ $wpdb->query($nnr_alter_sql);
148
+ }
149
+ }
150
+ self::hfcm_options_install();
151
+ }
152
+ update_option('hfcm_db_version', self::$nnr_hfcm_db_version);
153
+ }
154
 
155
+
156
+ /*
157
+ * Enqueue style-file, if it exists.
158
+ */
159
+ public static function hfcm_enqueue_assets($hook)
160
+ {
161
+ $allowed_pages = array(
162
+ 'toplevel_page_hfcm-list',
163
+ 'hfcm_page_hfcm-create',
164
+ 'admin_page_hfcm-update',
165
+ );
166
+
167
+ wp_register_style('hfcm_general_admin_assets', plugins_url('css/style-general-admin.css', __FILE__));
168
+ wp_enqueue_style('hfcm_general_admin_assets');
169
+
170
+ if (in_array($hook, $allowed_pages)) {
171
+ // Plugin's CSS
172
+ wp_register_style('hfcm_assets', plugins_url('css/style-admin.css', __FILE__));
173
+ wp_enqueue_style('hfcm_assets');
 
 
 
 
174
  }
175
 
176
+ // Remove hfcm-list from $allowed_pages
177
+ array_shift($allowed_pages);
178
+
179
+ if (in_array($hook, $allowed_pages)) {
180
+ // selectize.js plugin CSS and JS files
181
+ wp_register_style('selectize-css', plugins_url('css/selectize.bootstrap3.css', __FILE__));
182
+ wp_enqueue_style('selectize-css');
183
+
184
+ wp_register_script('selectize-js', plugins_url('js/selectize.min.js', __FILE__), array('jquery'));
185
+ wp_enqueue_script('selectize-js');
186
+
187
+ wp_enqueue_code_editor(array('type' => 'text/html'));
188
  }
189
  }
 
 
 
 
190
 
191
+ /*
192
+ * This function loads plugins translation files
193
+ */
194
 
195
+ public static function hfcm_load_translation_files()
196
+ {
197
+ load_plugin_textdomain('99robots-header-footer-code-manager', false, dirname(plugin_basename(__FILE__)) . '/languages');
198
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
 
 
 
200
 
201
+ /*
202
+ * function to create menu page, and submenu pages.
203
+ */
204
+ public static function hfcm_modifymenu()
205
+ {
206
+
207
+ // This is the main item for the menu
208
+ add_menu_page(
209
+ __('Header Footer Code Manager', '99robots-header-footer-code-manager'),
210
+ __('HFCM', '99robots-header-footer-code-manager'),
211
+ 'manage_options',
212
+ 'hfcm-list',
213
+ array('NNR_HFCM', 'hfcm_list'),
214
+ plugins_url('images/', __FILE__) . '99robots.png'
215
+ );
216
+
217
+ // This is a submenu
218
+ add_submenu_page(
219
+ 'hfcm-list',
220
+ __('All Snippets', '99robots-header-footer-code-manager'),
221
+ __('All Snippets', '99robots-header-footer-code-manager'),
222
+ 'manage_options',
223
+ 'hfcm-list',
224
+ array('NNR_HFCM', 'hfcm_list')
225
+ );
226
+
227
+ // This is a submenu
228
+ add_submenu_page(
229
+ 'hfcm-list',
230
+ __('Add New Snippet', '99robots-header-footer-code-manager'),
231
+ __('Add New', '99robots-header-footer-code-manager'),
232
+ 'manage_options',
233
+ 'hfcm-create',
234
+ array('NNR_HFCM', 'hfcm_create')
235
+ );
236
+
237
+ // This is a submenu
238
+ add_submenu_page(
239
+ 'hfcm-list',
240
+ __('Tools', '99robots-header-footer-code-manager'),
241
+ __('Tools', '99robots-header-footer-code-manager'),
242
+ 'manage_options',
243
+ 'hfcm-tools',
244
+ array('NNR_HFCM', 'hfcm_tools')
245
+ );
246
+
247
+ // This submenu is HIDDEN, however, we need to add it anyways
248
+ add_submenu_page(
249
+ null,
250
+ __('Update Script', '99robots-header-footer-code-manager'),
251
+ __('Update', '99robots-header-footer-code-manager'),
252
+ 'manage_options',
253
+ 'hfcm-update',
254
+ array('NNR_HFCM', 'hfcm_update')
255
+ );
256
+
257
+ // This submenu is HIDDEN, however, we need to add it anyways
258
+ add_submenu_page(
259
+ null,
260
+ __('Request Handler Script', '99robots-header-footer-code-manager'),
261
+ __('Request Handler', '99robots-header-footer-code-manager'),
262
+ 'manage_options',
263
+ 'hfcm-request-handler',
264
+ array('NNR_HFCM', 'hfcm_request_handler')
265
+ );
266
+ }
267
 
268
+ /*
269
+ * function to add a settings link for the plugin on the Settings Page
270
+ */
271
+ public static function hfcm_add_plugin_page_settings_link($links)
272
+ {
273
+ $links = array_merge(
274
+ array('<a href="' . admin_url('admin.php?page=hfcm-list') . '">' . __('Settings') . '</a>'),
275
+ $links
276
+ );
277
+ return $links;
278
+ }
279
 
280
+ /*
281
+ * function to check the plugins installation date
282
+ */
283
+ public static function hfcm_check_installation_date()
284
+ {
285
+ $install_date = get_option('hfcm_activation_date');
286
+ $past_date = strtotime('-7 days');
287
 
288
+ if ($past_date >= $install_date) {
289
+ add_action('admin_notices', array('NNR_HFCM', 'hfcm_review_push_notice'));
290
+ }
291
+ }
 
 
 
292
 
 
293
 
294
+ /*
295
+ * function to create the Admin Notice
296
+ */
297
+ public static function hfcm_review_push_notice()
298
+ {
299
+ $allowed_pages_notices = array(
300
+ 'toplevel_page_hfcm-list',
301
+ 'hfcm_page_hfcm-create',
302
+ 'admin_page_hfcm-update',
303
+ );
304
+ $screen = get_current_screen()->id;
305
+
306
+ $user_id = get_current_user_id();
307
+ // Check if current user has already dismissed it
308
+ $install_date = get_option('hfcm_activation_date');
309
+ if (!get_user_meta($user_id, 'hfcm_plugin_notice_dismissed') && in_array($screen, $allowed_pages_notices)) {
310
+ ?>
311
+ <div id="hfcm-message" class="notice notice-success">
312
+ <a class="hfcm-dismiss-alert notice-dismiss" href="?hfcm-admin-notice-dismissed">Dismiss</a>
313
+ <p><?php _e('Hey there! You’ve been using the <strong>Header Footer Code Manager</strong> plugin for a while now. If you like the plugin, please support our awesome development and support team by leaving a <a class="hfcm-review-stars" href="https://wordpress.org/support/plugin/header-footer-code-manager/reviews/"><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span></a> rating. <a href="https://wordpress.org/support/plugin/header-footer-code-manager/reviews/">Rate it!</a> It’ll mean the world to us and keep this plugin free and constantly updated. <a href="https://wordpress.org/support/plugin/header-footer-code-manager/reviews/">Leave A Review</a>', '99robots-header-footer-code-manager'); ?>
314
+ </p>
315
+ </div>
316
+ <?php
317
+ }
318
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
319
 
320
+ /*
321
+ * function to check if current user has already dismissed it
322
+ */
323
+ public static function hfcm_plugin_notice_dismissed()
324
+ {
325
+ $user_id = get_current_user_id();
326
+ // Checking if user clicked on the Dismiss button
327
+ if (isset($_GET['hfcm-admin-notice-dismissed'])) {
328
+ add_user_meta($user_id, 'hfcm_plugin_notice_dismissed', 'true', true);
329
+ // Redirect to original page the user was on
330
+ $current_url = wp_get_referer();
331
+ wp_redirect($current_url);
332
+ exit;
333
+ }
334
+ }
335
 
336
+ /*
337
+ * function to render the snippet
338
+ */
339
+ public static function hfcm_render_snippet($scriptdata)
340
+ {
341
+ $output = "<!-- HFCM by 99 Robots - Snippet # {$scriptdata->script_id}: {$scriptdata->name} -->\n{$scriptdata->snippet}\n<!-- /end HFCM by 99 Robots -->\n";
 
342
 
343
+ return $output;
344
+ }
 
 
345
 
346
+ /*
347
+ * function to implement shortcode
348
+ */
349
+ public static function hfcm_shortcode($atts)
350
+ {
351
+ global $wpdb;
352
+ $table_name = $wpdb->prefix . self::$nnr_hfcm_table;
353
+ if (!empty($atts['id'])) {
354
+ $id = (int)$atts['id'];
355
+ $hide_device = wp_is_mobile() ? 'desktop' : 'mobile';
356
+ $script = $wpdb->get_results($wpdb->prepare("SELECT * from $table_name where status='active' AND device_type!='$hide_device' AND script_id=%s", $id));
357
+ if (!empty($script)) {
358
+ return self::hfcm_render_snippet($script[0]);
359
+ }
360
+ }
361
+ }
362
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
363
 
364
+ /*
365
+ * Function to json_decode array and check if empty
366
+ */
367
+ public static function hfcm_not_empty($scriptdata, $prop_name)
368
+ {
369
+ $data = json_decode($scriptdata->{$prop_name});
370
+ if (empty($data)) {
371
+ return false;
372
+ }
373
+ return true;
374
+ }
 
 
 
 
375
 
376
+ /*
377
+ * function to decide which snippets to show - triggered by hooks
378
+ */
379
+ public static function hfcm_add_snippets($location = '', $content = '')
380
+ {
381
+ global $wpdb;
382
 
383
+ $beforecontent = '';
384
+ $aftercontent = '';
385
 
386
+ if ($location && in_array($location, array('header', 'footer'))) {
387
+ $display_location = "location='$location'";
388
+ } else {
389
+ $display_location = "location NOT IN ( 'header', 'footer' )";
390
+ }
391
 
392
+ $table_name = $wpdb->prefix . self::$nnr_hfcm_table;
393
+ $hide_device = wp_is_mobile() ? 'desktop' : 'mobile';
394
+ $script = $wpdb->get_results("SELECT * from $table_name where $display_location AND status='active' AND device_type!='$hide_device'");
395
+
396
+ if (!empty($script)) {
397
+ foreach ($script as $key => $scriptdata) {
398
+ $out = '';
399
+ switch ($scriptdata->display_on) {
400
+ case 'All':
401
+
402
+ $is_not_empty_ex_pages = self::hfcm_not_empty($scriptdata, 'ex_pages');
403
+ $is_not_empty_ex_posts = self::hfcm_not_empty($scriptdata, 'ex_posts');
404
+ if (($is_not_empty_ex_pages && is_page(json_decode($scriptdata->ex_pages))) || ($is_not_empty_ex_posts && is_single(json_decode($scriptdata->ex_posts)))) {
405
+ $out = '';
406
+ } else {
407
+ $out = self::hfcm_render_snippet($scriptdata);
408
+ }
409
+ break;
410
+ case 'latest_posts':
411
+ if (is_single()) {
412
+ if (!empty($scriptdata->lp_count)) {
413
+ $nnr_hfcm_latest_posts = wp_get_recent_posts(
414
+ array(
415
+ 'numberposts' => $scriptdata->lp_count,
416
+ )
417
+ );
418
+ } else {
419
+ $nnr_hfcm_latest_posts = wp_get_recent_posts(
420
+ array(
421
+ 'numberposts' => 5
422
+ )
423
+ );
424
+ }
425
+
426
+ foreach ($nnr_hfcm_latest_posts as $key => $lpostdata) {
427
+ if (get_the_ID() == $lpostdata['ID']) {
428
+ $out = self::hfcm_render_snippet($scriptdata);
429
+ }
430
+ }
431
+ }
432
+ break;
433
+ case 's_categories':
434
+ $is_not_empty_s_categories = self::hfcm_not_empty($scriptdata, 's_categories');
435
+ if ($is_not_empty_s_categories && in_category(json_decode($scriptdata->s_categories))) {
436
+ if (is_category(json_decode($scriptdata->s_categories))) {
437
+ $out = self::hfcm_render_snippet($scriptdata);
438
+ }
439
+ if (!is_archive() && !is_home()) {
440
+ $out = self::hfcm_render_snippet($scriptdata);
441
+ }
442
+ }
443
+ break;
444
+ case 's_custom_posts':
445
+ $is_not_empty_s_custom_posts = self::hfcm_not_empty($scriptdata, 's_custom_posts');
446
+ if ($is_not_empty_s_custom_posts && is_singular(json_decode($scriptdata->s_custom_posts))) {
447
+ $out = self::hfcm_render_snippet($scriptdata);
448
+ }
449
+ break;
450
+ case 's_posts':
451
+ $is_not_empty_s_posts = self::hfcm_not_empty($scriptdata, 's_posts');
452
+ if ($is_not_empty_s_posts && is_single(json_decode($scriptdata->s_posts))) {
453
+ $out = self::hfcm_render_snippet($scriptdata);
454
+ }
455
+ break;
456
+ case 's_pages':
457
+ $is_not_empty_s_pages = self::hfcm_not_empty($scriptdata, 's_pages');
458
+ if ($is_not_empty_s_pages) {
459
+ // Gets the page ID of the blog page
460
+ $blog_page = get_option('page_for_posts');
461
+ // Checks if the blog page is present in the array of selected pages
462
+ if (in_array($blog_page, json_decode($scriptdata->s_pages))) {
463
+ if (is_page(json_decode($scriptdata->s_pages)) || (!is_front_page() && is_home())) {
464
+ $out = self::hfcm_render_snippet($scriptdata);
465
+ }
466
+ } elseif (is_page(json_decode($scriptdata->s_pages))) {
467
+ $out = self::hfcm_render_snippet($scriptdata);
468
+ }
469
+ }
470
+ break;
471
+ case 's_tags':
472
+ $is_not_empty_s_tags = self::hfcm_not_empty($scriptdata, 's_tags');
473
+ if ($is_not_empty_s_tags && has_tag(json_decode($scriptdata->s_tags))) {
474
+ if (is_tag(json_decode($scriptdata->s_tags))) {
475
+ $out = self::hfcm_render_snippet($scriptdata);
476
+ }
477
+ if (!is_archive() && !is_home()) {
478
+ $out = self::hfcm_render_snippet($scriptdata);
479
+ }
480
+ }
481
+ }
482
 
483
+ switch ($scriptdata->location) {
484
+ case 'before_content':
485
+ $beforecontent .= $out;
486
+ break;
487
+ case 'after_content':
488
+ $aftercontent .= $out;
489
+ break;
490
+ default:
491
+ echo $out;
492
+ }
493
+ }
494
+ }
495
+ // Return results after the loop finishes
496
+ return $beforecontent . $content . $aftercontent;
497
+ }
498
 
499
+ /*
500
+ * function to add snippets in the header
501
+ */
502
+ public static function hfcm_header_scripts()
503
+ {
504
+ self::hfcm_add_snippets('header');
 
 
 
 
 
 
 
505
  }
 
 
506
 
507
+ /*
508
+ * function to add snippets in the footer
509
+ */
510
+ public static function hfcm_footer_scripts()
511
+ {
512
+ self::hfcm_add_snippets('footer');
513
+ }
514
 
515
+ /*
516
+ * function to add snippets before/after the content
517
+ */
518
+ public static function hfcm_content_scripts($content)
519
+ {
520
+ return self::hfcm_add_snippets(false, $content);
521
+ }
 
 
 
 
522
 
523
+ /*
524
+ * load redirection Javascript code
525
+ */
526
+ public static function hfcm_redirect($url = '')
527
+ {
528
+ // Register the script
529
+ wp_register_script('hfcm_redirection', plugins_url('js/location.js', __FILE__));
530
 
531
+ // Localize the script with new data
532
+ $translation_array = array('url' => $url);
533
+ wp_localize_script('hfcm_redirection', 'hfcm_location', $translation_array);
534
 
535
+ // Enqueued script with localized data.
536
+ wp_enqueue_script('hfcm_redirection');
537
+ }
 
 
538
 
539
+ /*
540
+ * function to sanitize POST data
541
+ */
542
+ public static function hfcm_sanitize_text($key, $sanitize = true)
543
+ {
544
+ if (!empty($_POST['data'][$key])) {
545
+ $out = stripslashes_deep($_POST['data'][$key]);
546
+ if ($sanitize) {
547
+ $out = sanitize_text_field($out);
548
+ }
549
+ return $out;
550
+ }
551
 
552
+ return '';
553
+ }
 
 
 
554
 
555
+ /*
556
+ * function to sanitize strings within POST data arrays
557
+ */
558
+ public static function hfcm_sanitize_array($key, $type = 'integer')
559
+ {
560
+ if (!empty($_POST['data'][$key])) {
561
+ $arr = $_POST['data'][$key];
562
+
563
+ if (!is_array($arr)) {
564
+ return array();
565
+ }
566
+
567
+ if ('integer' === $type) {
568
+ return array_map('absint', $arr);
569
+ } else { // strings
570
+ $new_array = array();
571
+ foreach ($arr as $val) {
572
+ $new_array[] = sanitize_text_field($val);
573
  }
574
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
575
 
576
+ return $new_array;
577
+ }
 
 
 
 
578
 
579
+ return array();
580
+ }
581
+
582
+ /*
583
+ * function for submenu "Add snippet" page
584
+ */
585
+ public static function hfcm_create()
586
+ {
587
+
588
+ // check user capabilities
589
+ current_user_can('administrator');
590
+
591
+ // prepare variables for includes/hfcm-add-edit.php
592
+ $name = '';
593
+ $snippet = '';
594
+ $nnr_snippet_type = 'html';
595
+ $device_type = '';
596
+ $location = '';
597
+ $display_on = '';
598
+ $status = '';
599
+ $lp_count = 5; // Default value
600
+ $s_pages = array();
601
+ $ex_pages = array();
602
+ $s_posts = array();
603
+ $ex_posts = array();
604
+ $s_custom_posts = array();
605
+ $s_categories = array();
606
+ $s_tags = array();
607
+
608
+ // Notify hfcm-add-edit.php NOT to make changes for update
609
+ $update = false;
610
+
611
+ require_once(plugin_dir_path(__FILE__) . 'includes/hfcm-add-edit.php');
612
+ }
613
+
614
+ /*
615
+ * function to handle add/update requests
616
+ */
617
+ public static function hfcm_request_handler()
618
+ {
619
+
620
+ // Check user capabilities
621
+ current_user_can('administrator');
622
+
623
+ if (isset($_POST['insert'])) {
624
+ // Check nonce
625
+ check_admin_referer('create-snippet');
626
+ } else {
627
+ if (!isset($_REQUEST['id'])) {
628
+ die('Missing ID parameter.');
629
+ }
630
+ $id = (int)$_REQUEST['id'];
631
+ }
632
+ if (isset($_POST['update'])) {
633
+ // Check nonce
634
+ check_admin_referer('update-snippet_' . $id);
635
+ }
636
+
637
+ // Handle AJAX on/off toggle for snippets
638
+ if (isset($_REQUEST['toggle']) && !empty($_REQUEST['togvalue'])) {
639
+
640
+ // Check nonce
641
+ check_ajax_referer('hfcm-toggle-snippet', 'security');
642
+
643
+ if ('on' === $_REQUEST['togvalue']) {
644
+ $status = 'active';
645
+ } else {
646
+ $status = 'inactive';
647
+ }
648
+
649
+ // Global vars
650
+ global $wpdb;
651
+ $table_name = $wpdb->prefix . self::$nnr_hfcm_table;
652
+
653
+ $wpdb->update(
654
+ $table_name, //table
655
+ array('status' => $status), //data
656
+ array('script_id' => $id), //where
657
+ array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s'), //data format
658
+ array('%s') //where format
659
+ );
660
+
661
+ } elseif (isset($_POST['insert']) || isset($_POST['update'])) {
662
+
663
+ // Create / update snippet
664
+
665
+ // Sanitize fields
666
+ $name = self::hfcm_sanitize_text('name');
667
+ $snippet = self::hfcm_sanitize_text('snippet', false);
668
+ $nnr_snippet_type = self::hfcm_sanitize_text('snippet_type', false);
669
+ $device_type = self::hfcm_sanitize_text('device_type');
670
+ $display_on = self::hfcm_sanitize_text('display_on');
671
+ $location = self::hfcm_sanitize_text('location');
672
+ $lp_count = self::hfcm_sanitize_text('lp_count');
673
+ $status = self::hfcm_sanitize_text('status');
674
+ $s_pages = self::hfcm_sanitize_array('s_pages');
675
+ $ex_pages = self::hfcm_sanitize_array('ex_pages');
676
+ $s_posts = self::hfcm_sanitize_array('s_posts');
677
+ $ex_posts = self::hfcm_sanitize_array('ex_posts');
678
+ $s_custom_posts = self::hfcm_sanitize_array('s_custom_posts', 'string');
679
+ $s_categories = self::hfcm_sanitize_array('s_categories');
680
+ $s_tags = self::hfcm_sanitize_array('s_tags');
681
+
682
+ if ('manual' === $display_on) {
683
+ $location = '';
684
+ }
685
+ $lp_count = max(1, (int)$lp_count);
686
+
687
+ // Global vars
688
+ global $wpdb;
689
+ global $current_user;
690
+ $table_name = $wpdb->prefix . self::$nnr_hfcm_table;
691
+
692
+ // Update snippet
693
+ if (isset($id)) {
694
+
695
+ $wpdb->update($table_name, //table
696
+ // Data
697
+ array(
698
+ 'name' => $name,
699
+ 'snippet' => $snippet,
700
+ 'snippet_type' => $nnr_snippet_type,
701
+ 'device_type' => $device_type,
702
+ 'location' => $location,
703
+ 'display_on' => $display_on,
704
+ 'status' => $status,
705
+ 'lp_count' => $lp_count,
706
+ 's_pages' => wp_json_encode($s_pages),
707
+ 'ex_pages' => wp_json_encode($ex_pages),
708
+ 's_posts' => wp_json_encode($s_posts),
709
+ 'ex_posts' => wp_json_encode($ex_posts),
710
+ 's_custom_posts' => wp_json_encode($s_custom_posts),
711
+ 's_categories' => wp_json_encode($s_categories),
712
+ 's_tags' => wp_json_encode($s_tags),
713
+ 'last_revision_date' => current_time('Y-m-d H:i:s'),
714
+ 'last_modified_by' => sanitize_text_field($current_user->display_name),
715
+ ),
716
+ // Where
717
+ array('script_id' => $id),
718
+ // Data format
719
+ array(
720
+ '%s',
721
+ '%s',
722
+ '%s',
723
+ '%s',
724
+ '%s',
725
+ '%s',
726
+ '%s',
727
+ '%s',
728
+ '%s',
729
+ ),
730
+ // Where format
731
+ array('%s')
732
+ );
733
+ self::hfcm_redirect(admin_url('admin.php?page=hfcm-update&message=1&id=' . $id));
734
+ } else {
735
+
736
+ // Create new snippet
737
+ $wpdb->insert($table_name, //table
738
+ array(
739
+ 'name' => $name,
740
+ 'snippet' => $snippet,
741
+ 'snippet_type' => $nnr_snippet_type,
742
+ 'device_type' => $device_type,
743
+ 'location' => $location,
744
+ 'display_on' => $display_on,
745
+ 'status' => $status,
746
+ 'lp_count' => $lp_count,
747
+ 's_pages' => wp_json_encode($s_pages),
748
+ 'ex_pages' => wp_json_encode($ex_pages),
749
+ 's_posts' => wp_json_encode($s_posts),
750
+ 'ex_posts' => wp_json_encode($ex_posts),
751
+ 's_custom_posts' => wp_json_encode($s_custom_posts),
752
+ 's_categories' => wp_json_encode($s_categories),
753
+ 's_tags' => wp_json_encode($s_tags),
754
+ 'created' => current_time('Y-m-d H:i:s'),
755
+ 'created_by' => sanitize_text_field($current_user->display_name),
756
+ ), array(
757
+ '%s',
758
+ '%s',
759
+ '%s',
760
+ '%s',
761
+ '%s',
762
+ '%s',
763
+ '%s',
764
+ '%d',
765
+ '%s',
766
+ '%s',
767
+ '%s',
768
+ '%s',
769
+ '%s',
770
+ '%s',
771
+ '%s',
772
+ '%s',
773
+ '%s',
774
+ )
775
+ );
776
+ $lastid = $wpdb->insert_id;
777
+ self::hfcm_redirect(admin_url('admin.php?page=hfcm-update&message=6&id=' . $lastid));
778
+ }
779
+ } elseif (isset($_POST['get_posts'])) {
780
+
781
+ // JSON return posts for AJAX
782
+
783
+ // Check nonce
784
+ check_ajax_referer('hfcm-get-posts', 'security');
785
+
786
+ // Global vars
787
+ global $wpdb;
788
+ $table_name = $wpdb->prefix . self::$nnr_hfcm_table;
789
+
790
+ // Get all selected posts
791
+ if (-1 === $id) {
792
+ $s_posts = array();
793
+ $ex_posts = array();
794
+ } else {
795
+
796
+ // Select value to update
797
+ $script = $wpdb->get_results($wpdb->prepare("SELECT s_posts from $table_name where script_id=%s", $id));
798
+ foreach ($script as $s) {
799
+ $s_posts = json_decode($s->s_posts);
800
+ if (!is_array($s_posts)) {
801
+ $s_posts = array();
802
  }
803
  }
804
+
805
+ $script_ex = $wpdb->get_results($wpdb->prepare("SELECT ex_posts from $table_name where script_id=%s", $id));
806
+ foreach ($script_ex as $s) {
807
+ $ex_posts = json_decode($s->ex_posts);
808
+ if (!is_array($ex_posts)) {
809
+ $ex_posts = array();
 
 
810
  }
811
  }
812
+ }
813
+
814
+ // Get all posts
815
+ $args = array(
816
+ 'public' => true,
817
+ '_builtin' => false,
818
+ );
819
+
820
+ $output = 'names'; // names or objects, note names is the default
821
+ $operator = 'and'; // 'and' or 'or'
822
+
823
+ $c_posttypes = get_post_types($args, $output, $operator);
824
+ $posttypes = array('post');
825
+ foreach ($c_posttypes as $cpdata) {
826
+ $posttypes[] = $cpdata;
827
+ }
828
+ $posts = get_posts(array(
829
+ 'post_type' => $posttypes,
830
+ 'posts_per_page' => -1,
831
+ 'numberposts' => -1,
832
+ 'orderby' => 'title',
833
+ 'order' => 'ASC',
834
+ ));
835
+
836
+ $json_output = array(
837
+ 'selected' => array(),
838
+ 'posts' => array(),
839
+ 'excluded' => array(),
840
+ );
841
+
842
+ foreach ($posts as $pdata) {
843
+
844
+ if (in_array($pdata->ID, $ex_posts)) {
845
+ $json_output['excluded'][] = $pdata->ID;
846
  }
847
+
848
+ if (in_array($pdata->ID, $s_posts)) {
849
+ $json_output['selected'][] = $pdata->ID;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
850
  }
 
851
 
852
+ $json_output['posts'][] = array(
853
+ 'text' => sanitize_text_field($pdata->post_title),
854
+ 'value' => $pdata->ID,
855
+ );
856
+ }
857
+
858
+ echo wp_json_encode($json_output);
859
+ wp_die();
 
860
  }
861
  }
 
 
 
 
862
 
863
+ /*
864
+ * function for submenu "Update snippet" page
865
+ */
866
+ public static function hfcm_update()
867
+ {
 
 
868
 
869
+ add_action('wp_enqueue_scripts', 'hfcm_selectize_enqueue');
 
 
 
 
 
 
 
 
 
 
870
 
871
+ // check user capabilities
872
+ current_user_can('administrator');
873
 
874
+ if (empty($_GET['id'])) {
875
+ die('Missing ID parameter.');
876
+ }
877
+ $id = (int)$_GET['id'];
878
+
879
+ global $wpdb;
880
+ $table_name = $wpdb->prefix . self::$nnr_hfcm_table;
881
+
882
+ //selecting value to update
883
+ $nnr_hfcm_snippets = $wpdb->get_results($wpdb->prepare("SELECT * from $table_name where script_id=%s", $id));
884
+ foreach ($nnr_hfcm_snippets as $s) {
885
+ $name = $s->name;
886
+ $snippet = $s->snippet;
887
+ $nnr_snippet_type = $s->snippet_type;
888
+ $device_type = $s->device_type;
889
+ $location = $s->location;
890
+ $display_on = $s->display_on;
891
+ $status = $s->status;
892
+ $lp_count = $s->lp_count;
893
+ if (empty($lp_count)) {
894
+ $lp_count = 5;
895
+ }
896
+ $s_pages = json_decode($s->s_pages);
897
+ $ex_pages = json_decode($s->ex_pages);
898
+ $ex_posts = json_decode($s->ex_posts);
899
+
900
+ if (!is_array($s_pages)) {
901
+ $s_pages = array();
902
+ }
903
+
904
+ if (!is_array($ex_pages)) {
905
+ $ex_pages = array();
906
+ }
907
+
908
+ $s_posts = json_decode($s->s_posts);
909
+ if (!is_array($s_posts)) {
910
+ $s_posts = array();
911
+ }
912
+
913
+ $ex_posts = json_decode($s->ex_posts);
914
+ if (!is_array($ex_posts)) {
915
+ $ex_posts = array();
916
+ }
917
+
918
+ $s_custom_posts = json_decode($s->s_custom_posts);
919
+ if (!is_array($s_custom_posts)) {
920
+ $s_custom_posts = array();
921
+ }
922
+
923
+ $s_categories = json_decode($s->s_categories);
924
+ if (!is_array($s_categories)) {
925
+ $s_categories = array();
926
+ }
927
+
928
+ $s_tags = json_decode($s->s_tags);
929
+ if (!is_array($s_tags)) {
930
+ $s_tags = array();
931
+ }
932
+
933
+ $createdby = esc_html($s->created_by);
934
+ $lastmodifiedby = esc_html($s->last_modified_by);
935
+ $createdon = esc_html($s->created);
936
+ $lastrevisiondate = esc_html($s->last_revision_date);
937
+ }
938
 
939
+ // escape for html output
940
+ $name = esc_textarea($name);
941
+ $snippet = esc_textarea($snippet);
942
+ $nnr_snippet_type = esc_textarea($nnr_snippet_type);
943
+ $device_type = esc_html($device_type);
944
+ $location = esc_html($location);
945
+ $display_on = esc_html($display_on);
946
+ $status = esc_html($status);
947
+ $lp_count = esc_html($lp_count);
948
+ $i = esc_html($lp_count);
949
+ // Notify hfcm-add-edit.php to make necesary changes for update
950
+ $update = true;
951
+
952
+ require_once(plugin_dir_path(__FILE__) . 'includes/hfcm-add-edit.php');
953
+ }
954
 
955
+ /*
956
+ * function to get list of all snippets
957
+ */
958
+ public static function hfcm_list()
959
+ {
960
+
961
+ global $wpdb;
962
+ $table_name = $wpdb->prefix . self::$nnr_hfcm_table;
963
+ $activeclass = '';
964
+ $inactiveclass = '';
965
+ $allclass = 'current';
966
+ $snippet_obj = new Hfcm_Snippets_List();
967
+
968
+ if (!empty($_GET['import'])) {
969
+ if ($_GET['import'] == 2) {
970
+ $message = "Header Footer Code Manager has successfully imported all snippets and set them as INACTIVE. Please review each snippet individually and ACTIVATE those that are needed for this site. Snippet types that are only available in the PRO version are skipped";
971
+ } else {
972
+ $message = "Header Footer Code Manager has successfully imported all snippets and set them as INACTIVE. Please review each snippet individually and ACTIVATE those that are needed for this site.";
973
+ }
974
+ ?>
975
+ <div id="hfcm-message" class="notice notice-success is-dismissible">
976
+ <p>
977
+ <?php _e($message, '99robots-header-footer-code-manager'); ?>
978
+ </p>
979
+ </div>
980
+ <?php
981
+ }
982
+ if (!empty($_GET['script_status']) && in_array($_GET['script_status'], array('active', 'inactive'))) {
983
+ $allclass = '';
984
+ if ('active' === $_GET['script_status']) {
985
+ $activeclass = 'current';
986
+ }
987
+ if ('inactive' === $_GET['script_status']) {
988
+ $inactiveclass = 'current';
989
+ }
990
+ }
991
+ ?>
992
+ <div class="wrap">
993
+ <h1><?php esc_html_e('Snippets', '99robots-header-footer-code-manager') ?>
994
+ <a href="<?php echo admin_url('admin.php?page=hfcm-create') ?>"
995
+ class="page-title-action"><?php esc_html_e('Add New Snippet', '99robots-header-footer-code-manager') ?></a>
996
+ </h1>
997
+
998
+ <form method="post">
999
+ <?php
1000
+ $snippet_obj->prepare_items();
1001
+ $snippet_obj->display();
1002
+ ?>
1003
+ </form>
1004
+
1005
+ </div>
1006
+ <?php
1007
+
1008
+ // Register the script
1009
+ wp_register_script('hfcm_toggle', plugins_url('js/toggle.js', __FILE__));
1010
+
1011
+ // Localize the script with new data
1012
+ $translation_array = array(
1013
+ 'url' => admin_url('admin.php'),
1014
+ 'security' => wp_create_nonce('hfcm-toggle-snippet'),
1015
+ );
1016
+ wp_localize_script('hfcm_toggle', 'hfcm_ajax', $translation_array);
1017
+
1018
+ // Enqueued script with localized data.
1019
+ wp_enqueue_script('hfcm_toggle');
1020
  }
 
 
1021
 
1022
+ /*
1023
+ * function to get load tools page
1024
+ */
1025
+ public static function hfcm_tools()
1026
+ {
1027
+ global $wpdb;
1028
+ $nnr_hfcm_table_name = $wpdb->prefix . self::$nnr_hfcm_table;
1029
 
1030
+ $nnr_hfcm_snippets = $wpdb->get_results("SELECT * from $nnr_hfcm_table_name");
 
 
 
 
 
 
1031
 
1032
+ require_once(plugin_dir_path(__FILE__) . 'includes/hfcm-tools.php');
 
1033
  }
1034
 
1035
+ /*
1036
+ * function to export snippets
1037
+ */
1038
+ public static function hfcm_export_snippets()
1039
+ {
1040
+ global $wpdb;
1041
+ $nnr_hfcm_table_name = $wpdb->prefix . self::$nnr_hfcm_table;
1042
+
1043
+ if (!empty($_POST['nnr_hfcm_snippets']) && !empty($_POST['action']) && ($_POST['action'] == "download") && check_admin_referer('hfcm-nonce')) {
1044
+ $nnr_hfcm_snippets_comma_separated = "";
1045
+ foreach ($_POST['nnr_hfcm_snippets'] as $nnr_hfcm_key => $nnr_hfcm_snippet) {
1046
+ $nnr_hfcm_snippet = str_replace("snippet_", "", sanitize_text_field($nnr_hfcm_snippet));
1047
+ if (empty($nnr_hfcm_snippets_comma_separated)) {
1048
+ $nnr_hfcm_snippets_comma_separated .= $nnr_hfcm_snippet;
1049
+ } else {
1050
+ $nnr_hfcm_snippets_comma_separated .= "," . $nnr_hfcm_snippet;
1051
+ }
1052
+ }
1053
+ if (!empty($nnr_hfcm_snippets_comma_separated)) {
1054
+ $nnr_hfcm_snippets = $wpdb->get_results("SELECT * from $nnr_hfcm_table_name where script_id IN (" . $nnr_hfcm_snippets_comma_separated . ")");
1055
+
1056
+ if (!empty($nnr_hfcm_snippets)) {
1057
+ $nnr_hfcm_export_snippets = array();
1058
+ foreach ($nnr_hfcm_snippets as $nnr_hfcm_snippet_key => $nnr_hfcm_snippet_item) {
1059
+ unset($nnr_hfcm_snippet_item->script_id);
1060
+ $nnr_hfcm_export_snippets[$nnr_hfcm_snippet_key] = $nnr_hfcm_snippet_item;
1061
+ }
1062
+ $file_name = 'hfcm-export-' . date('Y-m-d') . '.json';
1063
+ header("Content-Description: File Transfer");
1064
+ header("Content-Disposition: attachment; filename={$file_name}");
1065
+ header("Content-Type: application/json; charset=utf-8");
1066
+ echo json_encode($nnr_hfcm_export_snippets, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
1067
+ }
1068
+ }
1069
+ die;
1070
  }
1071
  }
1072
 
1073
+ /*
1074
+ * function to import snippets
1075
+ */
1076
+ public static function hfcm_import_snippets()
1077
+ {
1078
+ if (!empty($_FILES['nnr_hfcm_import_file']['tmp_name']) && check_admin_referer('hfcm-nonce')) {
1079
+ global $wpdb;
1080
+ $nnr_hfcm_table_name = $wpdb->prefix . self::$nnr_hfcm_table;
1081
+
1082
+ $nnr_hfcm_snippets_json = file_get_contents($_FILES['nnr_hfcm_import_file']['tmp_name']);
1083
+ $nnr_hfcm_snippets = json_decode($nnr_hfcm_snippets_json);
1084
+
1085
+ $nnr_non_script_snippets = 1;
1086
+ foreach ($nnr_hfcm_snippets as $nnr_hfcm_key => $nnr_hfcm_snippet) {
1087
+ $nnr_hfcm_snippet = (array)$nnr_hfcm_snippet;
1088
+ if (!empty($nnr_hfcm_snippet['snippet_type']) && !in_array($nnr_hfcm_snippet['snippet_type'], array("html", "css", "js"))) {
1089
+ $nnr_non_script_snippets = 2;
1090
+ continue;
1091
+ }
1092
+ if (!empty($nnr_hfcm_snippet['display_to'])) {
1093
+ unset($nnr_hfcm_snippet['display_to']);
1094
+ }
1095
+ $nnr_hfcm_snippet['status'] = 'inactive';
1096
+ $wpdb->insert($nnr_hfcm_table_name, $nnr_hfcm_snippet);
1097
+ }
1098
+
1099
+ self::hfcm_redirect(admin_url('admin.php?page=hfcm-list&import=' . $nnr_non_script_snippets));
1100
+ }
1101
+ }
1102
  }
1103
 
1104
+ endif;
 
css/style-admin.css CHANGED
@@ -14,7 +14,7 @@
14
  .selectize-control {
15
  width: 400px;
16
  }
17
- #newcontent {
18
  width: 75%;
19
  }
20
  .nnr-btnsave {
@@ -76,6 +76,9 @@ input.round-toggle-round-flat:checked + label:after {
76
  .nnr-switch label:hover {
77
  color: #40B000;
78
  }
 
 
 
79
  input.round-toggle-round-flat:checked + label {
80
  color: #4aaeee;
81
  background: #4aaeee;
@@ -93,7 +96,7 @@ input.round-toggle-round-flat:checked + label:hover {
93
  .hfcm-form-width select {
94
  min-width: auto;
95
  }
96
- #newcontent {
97
  width: 103%;
98
  width: calc(100% + 24px);
99
  }
14
  .selectize-control {
15
  width: 400px;
16
  }
17
+ #nnr_newcontent {
18
  width: 75%;
19
  }
20
  .nnr-btnsave {
76
  .nnr-switch label:hover {
77
  color: #40B000;
78
  }
79
+ .nnr-switch label:first-child:hover {
80
+ color: #ff2525;
81
+ }
82
  input.round-toggle-round-flat:checked + label {
83
  color: #4aaeee;
84
  background: #4aaeee;
96
  .hfcm-form-width select {
97
  min-width: auto;
98
  }
99
+ #nnr_newcontent {
100
  width: 103%;
101
  width: calc(100% + 24px);
102
  }
css/style-general-admin.css CHANGED
@@ -26,3 +26,65 @@
26
  #hfcm-message{
27
  position: relative;
28
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  #hfcm-message{
27
  position: relative;
28
  }
29
+ .hfcm-meta-box-wrap.hfcm-grid .postbox {
30
+ float: left;
31
+ clear: left;
32
+ width: 50%;
33
+ margin: 0 0 16px;
34
+ }
35
+ .hfcm-meta-box-wrap.hfcm-grid .postbox:nth-child(even) {
36
+ float: right;
37
+ clear: right;
38
+ margin-right: -8px;
39
+ }
40
+ .hfcm-meta-box-wrap.hfcm-grid {
41
+ margin-left: 8px;
42
+ margin-right: 8px;
43
+ }
44
+ .hfcm-meta-box-wrap .postbox {
45
+ -webkit-box-sizing: border-box;
46
+ -moz-box-sizing: border-box;
47
+ box-sizing: border-box;
48
+ }
49
+ .hfcm-meta-box-wrap .postbox .hndle {
50
+ font-size: 14px;
51
+ padding: 8px 12px;
52
+ margin: 0;
53
+ line-height: 1.4;
54
+ position: relative;
55
+ z-index: 1;
56
+ cursor: default;
57
+ }
58
+ .hfcm-meta-box-wrap.hfcm-grid .postbox:nth-child(odd) {
59
+ margin-left: -8px;
60
+ }
61
+ .hfcm-meta-box-wrap.hfcm-grid .hfcm-notice {
62
+ margin: 5px 0 15px;
63
+ background: #fff;
64
+ border: 1px solid #c3c4c7;
65
+ border-left-width: 4px;
66
+ box-shadow: 0 1px 1px rgb(0 0 0 / 4%);
67
+ padding: 1px 12px;
68
+ border-left-color: #dba617;
69
+ }
70
+ .hfcm-meta-box-wrap.hfcm-grid .hfcm-fields {
71
+ border: #ebebeb solid 1px;
72
+ background: #fafafa;
73
+ border-radius: 3px;
74
+ }
75
+ .hfcm-meta-box-wrap.hfcm-grid .hfcm-fields>.hfcm-field {
76
+ position: relative;
77
+ margin: 0;
78
+ padding: 15px 12px;
79
+ border-top: #EEEEEE solid 1px;
80
+ }
81
+ .hfcm-meta-box-wrap.hfcm-grid .hfcm-checkbox-list {
82
+ column-width: 200px;
83
+ }
84
+ .hfcm-meta-box-wrap.hfcm-grid .hfcm-label {
85
+ vertical-align: top;
86
+ margin: 0 0 10px;
87
+ }
88
+ .hfcm-meta-box-wrap.hfcm-grid .hfcm-label label {
89
+ font-weight: bold;
90
+ }
includes/hfcm-add-edit.php CHANGED
@@ -1,7 +1,7 @@
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)) {
@@ -49,299 +49,323 @@ wp_enqueue_script('hfcm_showboxes');
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"/>
67
- </td>
68
- </tr>
69
- <?php
70
- $darray = array(
71
- 'All' => esc_html__('Site Wide', '99robots-header-footer-code-manager'),
72
- 's_posts' => esc_html__('Specific Posts', '99robots-header-footer-code-manager'),
73
- 's_pages' => esc_html__('Specific Pages', '99robots-header-footer-code-manager'),
74
- 's_categories' => esc_html__('Specific Categories', '99robots-header-footer-code-manager'),
75
- 's_custom_posts' => esc_html__('Specific Post Types', '99robots-header-footer-code-manager'),
76
- 's_tags' => esc_html__('Specific Tags', '99robots-header-footer-code-manager'),
77
- 'latest_posts' => esc_html__('Latest Posts', '99robots-header-footer-code-manager'),
78
- 'manual' => esc_html__('Shortcode Only', '99robots-header-footer-code-manager'),
79
- ); ?>
80
- <tr>
81
- <th class="hfcm-th-width"><?php esc_html_e('Site Display', '99robots-header-footer-code-manager'); ?></th>
82
- <td>
83
- <select name="data[display_on]" onchange="hfcm_showotherboxes(this.value);">
84
- <?php
85
- foreach ($darray as $dkey => $statusv) {
86
- if ($display_on === $dkey) {
87
- printf('<option value="%1$s" selected="selected">%2$s</option>', $dkey, $statusv);
88
- } else {
89
- printf('<option value="%1$s">%2$s</option>', $dkey, $statusv);
90
- }
91
  }
92
- ?>
93
- </select>
94
- </td>
95
- </tr>
96
- <?php
97
- $pages = get_pages();
98
- $expagesstyle = ('s_pages' === $display_on) ? 'display:none;' : '';
99
- $expostsstyle = ('s_posts' === $display_on) ? 'display:none;' : '';
100
- $excategoriesstyle = 's_categories' === $display_on ? 'display:none;' : '';
101
- $extagsstyle = 's_tags' === $display_on ? 'display:none;' : '';
102
- $excpostssstyle = 's_custom_posts' === $display_on ? 'display:none;' : '';
103
- $exlpcountstyle = 'latest_posts' === $display_on ? 'display:none;' : '';
104
- $exmanualstyle = 'manual' === $display_on ? 'display:none;' : '';
105
- ?>
106
- <tr id="ex_pages"
107
- style="<?php echo $expagesstyle . $expostsstyle . $extagsstyle . $excpostssstyle . $excategoriesstyle . $exlpcountstyle . $exmanualstyle; ?>">
108
- <th class="hfcm-th-width"><?php esc_html_e('Exclude Pages', '99robots-header-footer-code-manager'); ?></th>
109
- <td>
110
- <select name="data[ex_pages][]" multiple>
111
- <?php
112
- foreach ($pages as $pdata) {
113
- if (in_array($pdata->ID, $ex_pages)) {
114
- printf('<option value="%1$s" selected="selected">%2$s</option>', $pdata->ID, $pdata->post_title);
115
- } else {
116
- printf('<option value="%1$s">%2$s</option>', $pdata->ID, $pdata->post_title);
117
- }
118
  }
119
- ?>
120
- </select>
121
- </td>
122
- </tr>
123
- <tr id="ex_posts"
124
- style="<?php echo $expagesstyle . $expostsstyle . $extagsstyle . $excpostssstyle . $excategoriesstyle . $exlpcountstyle . $exmanualstyle; ?>">
125
- <th class="hfcm-th-width"><?php esc_html_e('Exclude Posts', '99robots-header-footer-code-manager'); ?></th>
126
- <td>
127
- <select class="nnr-wraptext" name="data[ex_posts][]" multiple>
128
- <option disabled></option>
129
- </select> <img id="loader"
130
- src="<?php echo plugins_url('images/ajax-loader.gif', dirname(__FILE__)); ?>">
131
- </td>
132
- </tr>
133
- <?php
134
- $pages = get_pages();
135
- $spagesstyle = ('s_pages' === $display_on) ? '' : 'display:none;';
136
- ?>
137
- <tr id="s_pages" style="<?php echo $spagesstyle; ?>">
138
- <th class="hfcm-th-width"><?php esc_html_e('Page List', '99robots-header-footer-code-manager'); ?></th>
139
- <td>
140
- <select name="data[s_pages][]" multiple>
141
- <?php
142
- foreach ($pages as $pdata) {
143
- if (in_array($pdata->ID, $s_pages)) {
144
- printf('<option value="%1$s" selected="selected">%2$s</option>', $pdata->ID, $pdata->post_title);
145
- } else {
146
- printf('<option value="%1$s">%2$s</option>', $pdata->ID, $pdata->post_title);
147
- }
148
  }
149
- ?>
150
- </select>
151
- </td>
152
- </tr>
153
- <?php $spostsstyle = 's_posts' === $display_on ? '' : 'display:none;'; ?>
154
- <tr id="s_posts" style="<?php echo $spostsstyle; ?>">
155
- <th class="hfcm-th-width"><?php esc_html_e('Post List', '99robots-header-footer-code-manager'); ?></th>
156
- <td>
157
- <select class="nnr-wraptext" name="data[s_posts][]" multiple>
158
- <option disabled>...</option>
159
- </select>
160
- </td>
161
- </tr>
162
- <?php
163
- $args = array('hide_empty' => 0);
164
- $categories = get_categories($args);
165
- $tags = get_tags($args);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
 
167
- $scategoriesstyle = 's_categories' === $display_on ? '' : 'display:none;';
168
- $stagsstyle = 's_tags' === $display_on ? '' : 'display:none;';
169
- $cpostssstyle = 's_custom_posts' === $display_on ? '' : 'display:none;';
170
- $lpcountstyle = 'latest_posts' === $display_on ? '' : 'display:none;';
171
- $locationstyle = 'manual' === $display_on ? 'display:none;' : '';
172
 
173
- // Get all names of Post Types
174
- $args = array(
175
- 'public' => true,
176
- );
177
 
178
- $output = 'names';
179
- $operator = 'and';
180
 
181
- $c_posttypes = get_post_types($args, $output, $operator);
182
- $posttypes = array('post');
183
- foreach ($c_posttypes as $cpdata) {
184
- $posttypes[] = $cpdata;
185
- }
186
- ?>
187
- <tr id="s_categories" style="<?php echo $scategoriesstyle; ?>">
188
- <th class="hfcm-th-width"><?php esc_html_e('Category List', '99robots-header-footer-code-manager'); ?></th>
189
- <td>
190
- <select name="data[s_categories][]" multiple>
191
- <?php
192
- foreach ($categories as $cdata) {
193
- if (in_array($cdata->term_id, $s_categories)) {
194
- echo "<option value='{$cdata->term_id}' selected>{$cdata->name}</option>";
195
- } else {
196
- echo "<option value='{$cdata->term_id}'>{$cdata->name}</option>";
197
- }
198
  }
199
- ?>
200
- </select>
201
- </td>
202
- </tr>
203
- <tr id="s_tags" style="<?php echo $stagsstyle; ?>">
204
- <th class="hfcm-th-width"><?php esc_html_e('Tags List', '99robots-header-footer-code-manager'); ?></th>
205
- <td>
206
- <select name="data[s_tags][]" multiple>
207
- <?php
208
- foreach ($tags as $tdata) {
209
- if (in_array($tdata->term_id, $s_tags)) {
210
- echo "<option value='{$tdata->term_id}' selected>{$tdata->name}</option>";
211
- } else {
212
- echo "<option value='{$tdata->term_id}'>{$tdata->name}</option>";
213
- }
214
  }
215
- ?>
216
- </select>
217
- </td>
218
- </tr>
219
- <tr id="c_posttype" style="<?php echo $cpostssstyle; ?>">
220
- <th class="hfcm-th-width"><?php esc_html_e('Post Types', '99robots-header-footer-code-manager'); ?></th>
221
- <td>
222
- <select name="data[s_custom_posts][]" multiple>
223
- <?php
224
- foreach ($c_posttypes as $cpkey => $cpdata) {
225
- if (in_array($cpkey, $s_custom_posts)) {
226
- echo "<option value='$cpkey' selected>$cpdata</option>";
227
- } else {
228
- echo "<option value='$cpkey'>$cpdata</option>";
229
- }
230
  }
231
- ?>
232
- </select>
233
- </td>
234
- </tr>
235
- <tr id="lp_count" style="<?php echo $lpcountstyle; ?>">
236
- <th class="hfcm-th-width"><?php esc_html_e('Post Count', '99robots-header-footer-code-manager'); ?></th>
237
- <td>
238
- <select name="data[lp_count]">
239
- <option value=""></option>
240
- <?php
241
- for ($i = 1; $i <= 20; $i++) {
242
- if ($i === $lp_count) {
243
- echo "<option value='{$i}' selected>{$i}</option>";
244
- } else {
245
- echo "<option value='{$i}'>{$i}</option>";
246
- }
247
  }
248
- ?>
249
- </select>
250
- </td>
251
- </tr>
252
- <?php
253
- if (in_array($display_on, array('s_posts', 's_pages', 's_categories', 's_custom_posts', 's_tags', 'latest_posts'))) {
254
- $larray = array('header' => 'Header', 'before_content' => 'Before Content', 'after_content' => 'After Content', 'footer' => 'Footer');
255
- } else {
256
- $larray = array('header' => 'Header', 'footer' => 'Footer');
257
- }
258
- ?>
259
- <tr id="locationtr" style="<?php echo $locationstyle; ?>">
260
- <th class="hfcm-th-width"><?php esc_html_e('Location', '99robots-header-footer-code-manager'); ?></th>
261
- <td>
262
- <select name="data[location]" id="data_location">
263
- <?php
264
- foreach ($larray as $lkey => $statusv) {
265
- if ($location === $lkey) {
266
- echo "<option value='" . $lkey . "' selected='selected'>" . $statusv . '</option>';
267
- } else {
268
- echo "<option value='" . $lkey . "'>" . $statusv . '</option>';
269
- }
270
  }
271
- ?>
272
- </select>
273
- </td>
274
- </tr>
275
- <?php $devicetypearray = array('both' => 'Show on All Devices', 'desktop' => 'Only Desktop', 'mobile' => 'Only Mobile Devices') ?>
276
- <?php $statusarray = array('active' => 'Active', 'inactive' => 'Inactive') ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
277
  <tr>
278
- <th class="hfcm-th-width"><?php esc_html_e('Device Display', '99robots-header-footer-code-manager'); ?></th>
279
  <td>
280
- <select name="data[device_type]">
281
- <?php
282
- foreach ($devicetypearray as $smkey => $typev) {
283
- if ($device_type === $smkey) {
284
- echo "<option value='" . $smkey . "' selected='selected'>" . $typev . '</option>';
285
- } else {
286
- echo "<option value='" . $smkey . "'>" . $typev . '</option>';
287
- }
288
- }
289
- ?>
290
- </select>
291
  </td>
292
  </tr>
293
  <tr>
294
- <th class="hfcm-th-width"><?php esc_html_e('Status', '99robots-header-footer-code-manager'); ?></th>
295
  <td>
296
- <select name="data[status]">
297
- <?php
298
- foreach ($statusarray as $skey => $statusv) {
299
- if ($status === $skey) {
300
- echo "<option value='" . $skey . "' selected='selected'>" . $statusv . '</option>';
301
- } else {
302
- echo "<option value='" . $skey . "'>" . $statusv . '</option>';
303
- }
304
- }
305
- ?>
306
- </select>
307
  </td>
308
  </tr>
309
- <?php if ($update) : ?>
310
- <tr>
311
- <th class="hfcm-th-width"><?php esc_html_e('Shortcode', '99robots-header-footer-code-manager'); ?></th>
312
- <td>
313
- <p>[hfcm id="<?php echo $id; ?>"]</p>
314
- </td>
315
- </tr>
316
- <tr>
317
- <th class="hfcm-th-width"><?php esc_html_e('Changelog', '99robots-header-footer-code-manager'); ?></th>
318
- <td>
319
- <p>
320
- <?php esc_html_e('Snippet created by', '99robots-header-footer-code-manager'); ?>
321
- <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)) ?>
322
- <br/>
323
- <?php if (!empty($lastmodifiedby)) : ?>
324
- <?php esc_html_e('Last edited by', '99robots-header-footer-code-manager'); ?>
325
- <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)) ?>
326
- <?php endif; ?>
327
- </p>
328
- </td>
329
- </tr>
330
- <?php endif; ?>
331
- </table>
332
  <div class="wrap">
333
- <h1><?php esc_html_e('Snippet', '99robots-header-footer-code-manager'); ?>
334
- / <?php esc_html_e('Code', '99robots-header-footer-code-manager') ?></h1>
335
- <div class="wrap">
336
- <textarea name="data[snippet]" aria-describedby="newcontent-description" id="newcontent"
337
- name="newcontent" rows="10"><?php echo $snippet; ?></textarea>
338
- <div class="wp-core-ui">
339
- <input type="submit"
340
- name="<?php echo $update ? 'update' : 'insert'; ?>"
341
- value="<?php echo $update ? esc_html__('Update', '99robots-header-footer-code-manager') : esc_html__('Save', '99robots-header-footer-code-manager') ?>"
342
- class="button button-primary button-large nnr-btnsave">
343
- </div>
344
  </div>
345
  </div>
346
- </form>
 
347
  </div>
1
  <?php
2
 
3
  // Register the script
4
+ wp_register_script('hfcm_showboxes', plugins_url('js/nnr-hfcm-showboxes.js', dirname(__FILE__)), array('jquery'));
5
 
6
  // prepare ID (for AJAX)
7
  if (!isset($id)) {
49
  endif;
50
  endif;
51
 
52
+ if ($update) :
53
+ $hfcm_form_action = admin_url('admin.php?page=hfcm-request-handler&id=' . $id);
54
+ else :
55
+ $hfcm_form_action = admin_url('admin.php?page=hfcm-request-handler');
56
+ endif;
57
+ ?>
58
+ <form method="post" action="<?php echo $hfcm_form_action ?>">
59
  <?php
60
+ if ($update) :
61
+ wp_nonce_field('update-snippet_' . $id);
62
  else :
63
+ wp_nonce_field('create-snippet');
64
+ endif;
65
  ?>
66
+ <table class="wp-list-table widefat fixed hfcm-form-width form-table">
67
+ <tr>
68
+ <th class="hfcm-th-width"><?php esc_html_e('Snippet Name', '99robots-header-footer-code-manager'); ?></th>
69
+ <td><input type="text" name="data[name]" value="<?php echo $name; ?>" class="hfcm-field-width"/>
70
+ </td>
71
+ </tr>
72
  <?php
73
+ $nnr_hfcm_snippet_type_array = array(
74
+ 'html' => esc_html__('HTML', '99robots-header-footer-code-manager'),
75
+ 'css' => esc_html__('CSS', '99robots-header-footer-code-manager'),
76
+ 'js' => esc_html__('Javascript', '99robots-header-footer-code-manager')
77
+ ); ?>
78
+ <tr id="snippet_type">
79
+ <th class="hfcm-th-width"><?php esc_html_e('Snippet Type', '99robots-header-footer-code-manager'); ?></th>
80
+ <td>
81
+ <select name="data[snippet_type]">
82
+ <?php
83
+ foreach ($nnr_hfcm_snippet_type_array as $nnr_key => $nnr_item) {
84
+ if ($nnr_key === $nnr_snippet_type) {
85
+ echo "<option value='{$nnr_key}' selected>{$nnr_item}</option>";
86
+ } else {
87
+ echo "<option value='{$nnr_key}'>{$nnr_item}</option>";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  }
89
+ }
90
+ ?>
91
+ </select>
92
+ </td>
93
+ </tr>
94
+ <?php
95
+ $nnr_hfcm_display_array = array(
96
+ 'All' => esc_html__('Site Wide', '99robots-header-footer-code-manager'),
97
+ 's_posts' => esc_html__('Specific Posts', '99robots-header-footer-code-manager'),
98
+ 's_pages' => esc_html__('Specific Pages', '99robots-header-footer-code-manager'),
99
+ 's_categories' => esc_html__('Specific Categories', '99robots-header-footer-code-manager'),
100
+ 's_custom_posts' => esc_html__('Specific Post Types', '99robots-header-footer-code-manager'),
101
+ 's_tags' => esc_html__('Specific Tags', '99robots-header-footer-code-manager'),
102
+ 'latest_posts' => esc_html__('Latest Posts', '99robots-header-footer-code-manager'),
103
+ 'manual' => esc_html__('Shortcode Only', '99robots-header-footer-code-manager'),
104
+ ); ?>
105
+ <tr>
106
+ <th class="hfcm-th-width"><?php esc_html_e('Site Display', '99robots-header-footer-code-manager'); ?></th>
107
+ <td>
108
+ <select name="data[display_on]" onchange="hfcm_showotherboxes(this.value);">
109
+ <?php
110
+ foreach ($nnr_hfcm_display_array as $dkey => $statusv) {
111
+ if ($display_on === $dkey) {
112
+ printf('<option value="%1$s" selected="selected">%2$s</option>', $dkey, $statusv);
113
+ } else {
114
+ printf('<option value="%1$s">%2$s</option>', $dkey, $statusv);
115
  }
116
+ }
117
+ ?>
118
+ </select>
119
+ </td>
120
+ </tr>
121
+ <?php
122
+ $nnr_hfcm_pages = get_pages();
123
+ $expagesstyle = ('s_pages' === $display_on) ? 'display:none;' : '';
124
+ $expostsstyle = ('s_posts' === $display_on) ? 'display:none;' : '';
125
+ $excategoriesstyle = 's_categories' === $display_on ? 'display:none;' : '';
126
+ $extagsstyle = 's_tags' === $display_on ? 'display:none;' : '';
127
+ $excpostssstyle = 's_custom_posts' === $display_on ? 'display:none;' : '';
128
+ $exlpcountstyle = 'latest_posts' === $display_on ? 'display:none;' : '';
129
+ $exmanualstyle = 'manual' === $display_on ? 'display:none;' : '';
130
+ ?>
131
+ <tr id="ex_pages"
132
+ style="<?php echo $expagesstyle . $expostsstyle . $extagsstyle . $excpostssstyle . $excategoriesstyle . $exlpcountstyle . $exmanualstyle; ?>">
133
+ <th class="hfcm-th-width"><?php esc_html_e('Exclude Pages', '99robots-header-footer-code-manager'); ?></th>
134
+ <td>
135
+ <select name="data[ex_pages][]" multiple>
136
+ <?php
137
+ foreach ($nnr_hfcm_pages as $pdata) {
138
+ if (in_array($pdata->ID, $ex_pages)) {
139
+ printf('<option value="%1$s" selected="selected">%2$s</option>', $pdata->ID, $pdata->post_title);
140
+ } else {
141
+ printf('<option value="%1$s">%2$s</option>', $pdata->ID, $pdata->post_title);
 
 
 
142
  }
143
+ }
144
+ ?>
145
+ </select>
146
+ </td>
147
+ </tr>
148
+ <tr id="ex_posts"
149
+ style="<?php echo $expagesstyle . $expostsstyle . $extagsstyle . $excpostssstyle . $excategoriesstyle . $exlpcountstyle . $exmanualstyle; ?>">
150
+ <th class="hfcm-th-width"><?php esc_html_e('Exclude Posts', '99robots-header-footer-code-manager'); ?></th>
151
+ <td>
152
+ <select class="nnr-wraptext" name="data[ex_posts][]" multiple>
153
+ <option disabled></option>
154
+ </select> <img id="loader"
155
+ src="<?php echo plugins_url('images/ajax-loader.gif', dirname(__FILE__)); ?>">
156
+ </td>
157
+ </tr>
158
+ <?php
159
+ $nnr_hfcm_pages = get_pages();
160
+ $spagesstyle = ('s_pages' === $display_on) ? '' : 'display:none;';
161
+ ?>
162
+ <tr id="s_pages" style="<?php echo $spagesstyle; ?>">
163
+ <th class="hfcm-th-width"><?php esc_html_e('Page List', '99robots-header-footer-code-manager'); ?></th>
164
+ <td>
165
+ <select name="data[s_pages][]" multiple>
166
+ <?php
167
+ foreach ($nnr_hfcm_pages as $pdata) {
168
+ if (in_array($pdata->ID, $s_pages)) {
169
+ printf('<option value="%1$s" selected="selected">%2$s</option>', $pdata->ID, $pdata->post_title);
170
+ } else {
171
+ printf('<option value="%1$s">%2$s</option>', $pdata->ID, $pdata->post_title);
172
+ }
173
+ }
174
+ ?>
175
+ </select>
176
+ </td>
177
+ </tr>
178
+ <?php $spostsstyle = 's_posts' === $display_on ? '' : 'display:none;'; ?>
179
+ <tr id="s_posts" style="<?php echo $spostsstyle; ?>">
180
+ <th class="hfcm-th-width"><?php esc_html_e('Post List', '99robots-header-footer-code-manager'); ?></th>
181
+ <td>
182
+ <select class="nnr-wraptext" name="data[s_posts][]" multiple>
183
+ <option disabled>...</option>
184
+ </select>
185
+ </td>
186
+ </tr>
187
+ <?php
188
+ $args = array('hide_empty' => 0);
189
+ $categories = get_categories($args);
190
+ $tags = get_tags($args);
191
 
192
+ $scategoriesstyle = 's_categories' === $display_on ? '' : 'display:none;';
193
+ $stagsstyle = 's_tags' === $display_on ? '' : 'display:none;';
194
+ $cpostssstyle = 's_custom_posts' === $display_on ? '' : 'display:none;';
195
+ $lpcountstyle = 'latest_posts' === $display_on ? '' : 'display:none;';
196
+ $locationstyle = 'manual' === $display_on ? 'display:none;' : '';
197
 
198
+ // Get all names of Post Types
199
+ $args = array(
200
+ 'public' => true,
201
+ );
202
 
203
+ $output = 'names';
204
+ $operator = 'and';
205
 
206
+ $c_posttypes = get_post_types($args, $output, $operator);
207
+ $posttypes = array('post');
208
+ foreach ($c_posttypes as $cpdata) {
209
+ $posttypes[] = $cpdata;
210
+ }
211
+ ?>
212
+ <tr id="s_categories" style="<?php echo $scategoriesstyle; ?>">
213
+ <th class="hfcm-th-width"><?php esc_html_e('Category List', '99robots-header-footer-code-manager'); ?></th>
214
+ <td>
215
+ <select name="data[s_categories][]" multiple>
216
+ <?php
217
+ foreach ($categories as $cdata) {
218
+ if (in_array($cdata->term_id, $s_categories)) {
219
+ echo "<option value='{$cdata->term_id}' selected>{$cdata->name}</option>";
220
+ } else {
221
+ echo "<option value='{$cdata->term_id}'>{$cdata->name}</option>";
 
222
  }
223
+ }
224
+ ?>
225
+ </select>
226
+ </td>
227
+ </tr>
228
+ <tr id="s_tags" style="<?php echo $stagsstyle; ?>">
229
+ <th class="hfcm-th-width"><?php esc_html_e('Tags List', '99robots-header-footer-code-manager'); ?></th>
230
+ <td>
231
+ <select name="data[s_tags][]" multiple>
232
+ <?php
233
+ foreach ($tags as $tdata) {
234
+ if (in_array($tdata->term_id, $s_tags)) {
235
+ echo "<option value='{$tdata->term_id}' selected>{$tdata->name}</option>";
236
+ } else {
237
+ echo "<option value='{$tdata->term_id}'>{$tdata->name}</option>";
238
  }
239
+ }
240
+ ?>
241
+ </select>
242
+ </td>
243
+ </tr>
244
+ <tr id="c_posttype" style="<?php echo $cpostssstyle; ?>">
245
+ <th class="hfcm-th-width"><?php esc_html_e('Post Types', '99robots-header-footer-code-manager'); ?></th>
246
+ <td>
247
+ <select name="data[s_custom_posts][]" multiple>
248
+ <?php
249
+ foreach ($c_posttypes as $cpkey => $cpdata) {
250
+ if (in_array($cpkey, $s_custom_posts)) {
251
+ echo "<option value='$cpkey' selected>$cpdata</option>";
252
+ } else {
253
+ echo "<option value='$cpkey'>$cpdata</option>";
254
  }
255
+ }
256
+ ?>
257
+ </select>
258
+ </td>
259
+ </tr>
260
+ <tr id="lp_count" style="<?php echo $lpcountstyle; ?>">
261
+ <th class="hfcm-th-width"><?php esc_html_e('Post Count', '99robots-header-footer-code-manager'); ?></th>
262
+ <td>
263
+ <select name="data[lp_count]">
264
+ <?php
265
+ for ($i = 1; $i <= 20; $i++) {
266
+ if ($i == $lp_count) {
267
+ echo "<option value='{$i}' selected>{$i}</option>";
268
+ } else {
269
+ echo "<option value='{$i}'>{$i}</option>";
 
270
  }
271
+ }
272
+ ?>
273
+ </select>
274
+ </td>
275
+ </tr>
276
+ <?php
277
+ if (in_array($display_on, array('s_posts', 's_pages', 's_custom_posts', 's_tags', 'latest_posts'))) {
278
+ $nnr_hfcm_locations = array('header' => 'Header', 'before_content' => 'Before Content', 'after_content' => 'After Content', 'footer' => 'Footer');
279
+ } else {
280
+ $nnr_hfcm_locations = array('header' => 'Header', 'footer' => 'Footer');
281
+ }
282
+ ?>
283
+ <tr id="locationtr" style="<?php echo $locationstyle; ?>">
284
+ <th class="hfcm-th-width"><?php esc_html_e('Location', '99robots-header-footer-code-manager'); ?></th>
285
+ <td>
286
+ <select name="data[location]" id="data_location">
287
+ <?php
288
+ foreach ($nnr_hfcm_locations as $lkey => $statusv) {
289
+ if ($location === $lkey) {
290
+ echo "<option value='" . $lkey . "' selected='selected'>" . $statusv . '</option>';
291
+ } else {
292
+ echo "<option value='" . $lkey . "'>" . $statusv . '</option>';
293
  }
294
+ }
295
+ ?>
296
+ </select>
297
+ </td>
298
+ </tr>
299
+ <?php $devicetypearray = array('both' => 'Show on All Devices', 'desktop' => 'Only Desktop', 'mobile' => 'Only Mobile Devices') ?>
300
+ <?php $statusarray = array('active' => 'Active', 'inactive' => 'Inactive') ?>
301
+ <tr>
302
+ <th class="hfcm-th-width"><?php esc_html_e('Device Display', '99robots-header-footer-code-manager'); ?></th>
303
+ <td>
304
+ <select name="data[device_type]">
305
+ <?php
306
+ foreach ($devicetypearray as $smkey => $typev) {
307
+ if ($device_type === $smkey) {
308
+ echo "<option value='" . $smkey . "' selected='selected'>" . $typev . '</option>';
309
+ } else {
310
+ echo "<option value='" . $smkey . "'>" . $typev . '</option>';
311
+ }
312
+ }
313
+ ?>
314
+ </select>
315
+ </td>
316
+ </tr>
317
+ <tr>
318
+ <th class="hfcm-th-width"><?php esc_html_e('Status', '99robots-header-footer-code-manager'); ?></th>
319
+ <td>
320
+ <select name="data[status]">
321
+ <?php
322
+ foreach ($statusarray as $skey => $statusv) {
323
+ if ($status === $skey) {
324
+ echo "<option value='" . $skey . "' selected='selected'>" . $statusv . '</option>';
325
+ } else {
326
+ echo "<option value='" . $skey . "'>" . $statusv . '</option>';
327
+ }
328
+ }
329
+ ?>
330
+ </select>
331
+ </td>
332
+ </tr>
333
+ <?php if ($update) : ?>
334
  <tr>
335
+ <th class="hfcm-th-width"><?php esc_html_e('Shortcode', '99robots-header-footer-code-manager'); ?></th>
336
  <td>
337
+ <p>[hfcm id="<?php echo $id; ?>"]</p>
 
 
 
 
 
 
 
 
 
 
338
  </td>
339
  </tr>
340
  <tr>
341
+ <th class="hfcm-th-width"><?php esc_html_e('Changelog', '99robots-header-footer-code-manager'); ?></th>
342
  <td>
343
+ <p>
344
+ <?php esc_html_e('Snippet created by', '99robots-header-footer-code-manager'); ?>
345
+ <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)) ?>
346
+ <br/>
347
+ <?php if (!empty($lastmodifiedby)) : ?>
348
+ <?php esc_html_e('Last edited by', '99robots-header-footer-code-manager'); ?>
349
+ <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)) ?>
350
+ <?php endif; ?>
351
+ </p>
 
 
352
  </td>
353
  </tr>
354
+ <?php endif; ?>
355
+ </table>
356
+ <div class="wrap">
357
+ <h1><?php esc_html_e('Snippet', '99robots-header-footer-code-manager'); ?>
358
+ / <?php esc_html_e('Code', '99robots-header-footer-code-manager') ?></h1>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
359
  <div class="wrap">
360
+ <textarea name="data[snippet]" aria-describedby="nnr-newcontent-description" id="nnr_newcontent"
361
+ rows="10"><?php echo $snippet; ?></textarea>
362
+ <div class="wp-core-ui">
363
+ <input type="submit"
364
+ name="<?php echo $update ? 'update' : 'insert'; ?>"
365
+ value="<?php echo $update ? esc_html__('Update', '99robots-header-footer-code-manager') : esc_html__('Save', '99robots-header-footer-code-manager') ?>"
366
+ class="button button-primary button-large nnr-btnsave">
 
 
 
 
367
  </div>
368
  </div>
369
+ </div>
370
+ </form>
371
  </div>
includes/hfcm-create.php DELETED
@@ -1,30 +0,0 @@
1
- <?php
2
-
3
- // function for submenu "Add snippet" page
4
- function hfcm_create()
5
- {
6
-
7
- // check user capabilities
8
- current_user_can('administrator');
9
-
10
- // prepare variables for includes/hfcm-add-edit.php
11
- $name = '';
12
- $snippet = '';
13
- $device_type = '';
14
- $location = '';
15
- $display_on = '';
16
- $status = '';
17
- $lp_count = 5; // Default value
18
- $s_pages = array();
19
- $ex_pages = array();
20
- $s_posts = array();
21
- $ex_posts = array();
22
- $s_custom_posts = array();
23
- $s_categories = array();
24
- $s_tags = array();
25
-
26
- // Notify hfcm-add-edit.php NOT to make changes for update
27
- $update = false;
28
-
29
- require_once(plugin_dir_path(__FILE__) . 'hfcm-add-edit.php');
30
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/hfcm-list.php CHANGED
@@ -134,7 +134,7 @@ class Hfcm_Snippets_List extends WP_List_Table {
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' ),
@@ -161,7 +161,7 @@ class Hfcm_Snippets_List extends WP_List_Table {
161
  }
162
  }
163
 
164
- return esc_html( $darray[ $item[ $column_name ] ] );
165
 
166
  case 'location':
167
 
@@ -169,13 +169,13 @@ class Hfcm_Snippets_List extends WP_List_Table {
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
 
@@ -367,7 +367,7 @@ class Hfcm_Snippets_List extends WP_List_Table {
367
  } else {
368
  self::delete_snippet( absint( $_GET['snippet'] ) );
369
 
370
- hfcm_redirect( admin_url( 'admin.php?page=hfcm-list' ) );
371
  return;
372
  }
373
  }
@@ -384,7 +384,7 @@ class Hfcm_Snippets_List extends WP_List_Table {
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'] ) ||
@@ -398,7 +398,7 @@ class Hfcm_Snippets_List extends WP_List_Table {
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'] ) ||
@@ -412,58 +412,10 @@ class Hfcm_Snippets_List extends WP_List_Table {
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
- }
134
  return esc_html( $item[ $column_name ] );
135
 
136
  case 'display_on':
137
+ $nnr_hfcm_display_array = 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' ),
161
  }
162
  }
163
 
164
+ return esc_html( $nnr_hfcm_display_array[ $item[ $column_name ] ] );
165
 
166
  case 'location':
167
 
169
  return esc_html__( 'N/A', '99robots-header-footer-code-manager' );
170
  }
171
 
172
+ $nnr_hfcm_locations = 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( $nnr_hfcm_locations[ $item[ $column_name ] ] );
179
 
180
  case 'device_type':
181
 
367
  } else {
368
  self::delete_snippet( absint( $_GET['snippet'] ) );
369
 
370
+ NNR_HFCM::hfcm_redirect( admin_url( 'admin.php?page=hfcm-list' ) );
371
  return;
372
  }
373
  }
384
  self::delete_snippet( $id );
385
  }
386
 
387
+ NNR_HFCM::hfcm_redirect( admin_url( 'admin.php?page=hfcm-list' ) );
388
  return;
389
  } elseif (
390
  ( isset( $_POST['action'] ) && 'bulk-activate' === $_POST['action'] ) ||
398
  self::activate_snippet( $id );
399
  }
400
 
401
+ NNR_HFCM::hfcm_redirect( admin_url( 'admin.php?page=hfcm-list' ) );
402
  return;
403
  } elseif (
404
  ( isset( $_POST['action'] ) && 'bulk-deactivate' === $_POST['action'] ) ||
412
  self::deactivate_snippet( $id );
413
  }
414
 
415
+ NNR_HFCM::hfcm_redirect( admin_url( 'admin.php?page=hfcm-list' ) );
416
 
417
  return;
418
  }
419
  }
420
  }
421
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/hfcm-request-handler.php DELETED
@@ -1,241 +0,0 @@
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', '%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
- $ex_pages = hfcm_sanitize_array( 'ex_pages' );
60
- $s_posts = hfcm_sanitize_array( 's_posts' );
61
- $ex_posts = hfcm_sanitize_array( 'ex_posts' );
62
- $s_custom_posts = hfcm_sanitize_array( 's_custom_posts', 'string' );
63
- $s_categories = hfcm_sanitize_array( 's_categories' );
64
- $s_tags = hfcm_sanitize_array( 's_tags' );
65
-
66
- if ( 'manual' === $display_on ) {
67
- $location = '';
68
- }
69
- $lp_count = max( 1, (int) $lp_count );
70
-
71
- // Global vars
72
- global $wpdb;
73
- global $current_user;
74
- $table_name = $wpdb->prefix . 'hfcm_scripts';
75
-
76
- // Update snippet
77
- if ( isset( $id ) ) {
78
-
79
- $wpdb->update( $table_name, //table
80
- // Data
81
- array(
82
- 'name' => $name,
83
- 'snippet' => $snippet,
84
- 'device_type' => $device_type,
85
- 'location' => $location,
86
- 'display_on' => $display_on,
87
- 'status' => $status,
88
- 'lp_count' => $lp_count,
89
- 's_pages' => wp_json_encode( $s_pages ),
90
- 'ex_pages' => wp_json_encode( $ex_pages ),
91
- 's_posts' => wp_json_encode( $s_posts ),
92
- 'ex_posts' => wp_json_encode( $ex_posts ),
93
- 's_custom_posts' => wp_json_encode( $s_custom_posts ),
94
- 's_categories' => wp_json_encode( $s_categories ),
95
- 's_tags' => wp_json_encode( $s_tags ),
96
- 'last_revision_date' => current_time( 'Y-m-d H:i:s' ),
97
- 'last_modified_by' => sanitize_text_field( $current_user->display_name ),
98
- ),
99
- // Where
100
- array( 'script_id' => $id ),
101
- // Data format
102
- array(
103
- '%s',
104
- '%s',
105
- '%s',
106
- '%s',
107
- '%s',
108
- '%s',
109
- '%s',
110
- '%s',
111
- ),
112
- // Where format
113
- array( '%s' )
114
- );
115
- hfcm_redirect( admin_url( 'admin.php?page=hfcm-update&message=1&id=' . $id ) );
116
- } else {
117
-
118
- // Create new snippet
119
- $wpdb->insert( $table_name, //table
120
- array(
121
- 'name' => $name,
122
- 'snippet' => $snippet,
123
- 'device_type' => $device_type,
124
- 'location' => $location,
125
- 'display_on' => $display_on,
126
- 'status' => $status,
127
- 'lp_count' => $lp_count,
128
- 's_pages' => wp_json_encode( $s_pages ),
129
- 'ex_pages' => wp_json_encode( $ex_pages ),
130
- 's_posts' => wp_json_encode( $s_posts ),
131
- 'ex_posts' => wp_json_encode( $ex_posts ),
132
- 's_custom_posts' => wp_json_encode( $s_custom_posts ),
133
- 's_categories' => wp_json_encode( $s_categories ),
134
- 's_tags' => wp_json_encode( $s_tags ),
135
- 'created' => current_time( 'Y-m-d H:i:s' ),
136
- 'created_by' => sanitize_text_field( $current_user->display_name ),
137
- ), array(
138
- '%s',
139
- '%s',
140
- '%s',
141
- '%s',
142
- '%s',
143
- '%s',
144
- '%d',
145
- '%s',
146
- '%s',
147
- '%s',
148
- '%s',
149
- '%s',
150
- '%s',
151
- '%s',
152
- '%s',
153
- '%s',
154
- )
155
- );
156
- $lastid = $wpdb->insert_id;
157
- hfcm_redirect( admin_url( 'admin.php?page=hfcm-update&message=6&id=' . $lastid ) );
158
- }
159
- } elseif ( isset( $_POST['get_posts'] ) ) {
160
-
161
- // JSON return posts for AJAX
162
-
163
- // Check nonce
164
- check_ajax_referer( 'hfcm-get-posts', 'security' );
165
-
166
- // Global vars
167
- global $wpdb;
168
- $table_name = $wpdb->prefix . 'hfcm_scripts';
169
-
170
- // Get all selected posts
171
- if ( -1 === $id ) {
172
- $s_posts = array();
173
- $ex_posts = array();
174
- } else {
175
-
176
- // Select value to update
177
- $script = $wpdb->get_results( $wpdb->prepare( "SELECT s_posts from $table_name where script_id=%s", $id ) );
178
- foreach ( $script as $s ) {
179
- $s_posts = json_decode( $s->s_posts );
180
- if ( ! is_array( $s_posts ) ) {
181
- $s_posts = array();
182
- }
183
- }
184
-
185
- $script_ex = $wpdb->get_results( $wpdb->prepare( "SELECT ex_posts from $table_name where script_id=%s", $id ) );
186
- foreach ( $script_ex as $s ) {
187
- $ex_posts = json_decode( $s->ex_posts );
188
- if ( ! is_array( $ex_posts ) ) {
189
- $ex_posts = array();
190
- }
191
- }
192
- }
193
-
194
- // Get all posts
195
- $args = array(
196
- 'public' => true,
197
- '_builtin' => false,
198
- );
199
-
200
- $output = 'names'; // names or objects, note names is the default
201
- $operator = 'and'; // 'and' or 'or'
202
-
203
- $c_posttypes = get_post_types( $args, $output, $operator );
204
- $posttypes = array( 'post' );
205
- foreach ( $c_posttypes as $cpdata ) {
206
- $posttypes[] = $cpdata;
207
- }
208
- $posts = get_posts( array(
209
- 'post_type' => $posttypes,
210
- 'posts_per_page' => -1,
211
- 'numberposts' => -1,
212
- 'orderby' => 'title',
213
- 'order' => 'ASC',
214
- ) );
215
-
216
- $json_output = array(
217
- 'selected' => array(),
218
- 'posts' => array(),
219
- 'excluded' => array(),
220
- );
221
-
222
- foreach ( $posts as $pdata ) {
223
-
224
- if ( in_array( $pdata->ID, $ex_posts ) ) {
225
- $json_output['excluded'][] = $pdata->ID;
226
- }
227
-
228
- if ( in_array( $pdata->ID, $s_posts ) ) {
229
- $json_output['selected'][] = $pdata->ID;
230
- }
231
-
232
- $json_output['posts'][] = array(
233
- 'text' => sanitize_text_field( $pdata->post_title ),
234
- 'value' => $pdata->ID,
235
- );
236
- }
237
-
238
- echo wp_json_encode( $json_output );
239
- wp_die();
240
- }
241
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/hfcm-tools.php ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // Register the script
4
+ wp_register_script('hfcm_showboxes', plugins_url('js/nnr-hfcm-showboxes.js', dirname(__FILE__)), array('jquery'));
5
+
6
+
7
+ // Localize the script with new data
8
+ $translation_array = array(
9
+ 'header' => __('Header', '99robots-header-footer-code-manager'),
10
+ 'before_content' => __('Before Content', '99robots-header-footer-code-manager'),
11
+ 'after_content' => __('After Content', '99robots-header-footer-code-manager'),
12
+ 'footer' => __('Footer', '99robots-header-footer-code-manager'),
13
+ 'security' => wp_create_nonce('hfcm-get-posts'),
14
+ );
15
+ wp_localize_script('hfcm_showboxes', 'hfcm_localize', $translation_array);
16
+
17
+ // Enqueued script with localized data.
18
+ wp_enqueue_script('hfcm_showboxes');
19
+ ?>
20
+
21
+ <div class="wrap">
22
+ <h1>
23
+ Tools
24
+ </h1>
25
+ <div class="hfcm-meta-box-wrap hfcm-grid">
26
+ <div id="normal-sortables" class="meta-box-sortables">
27
+ <div id="hfcm-admin-tool-export" class="postbox ">
28
+ <div class="postbox-header">
29
+ <h2 class="hndle">Export Snippets</h2>
30
+ </div>
31
+ <div class="inside">
32
+ <form method="post">
33
+ <p>Select the snippets you would like to export and then select your export method. Use the
34
+ download button to export to a .json file which you can then import to another HFCM
35
+ installation.</p>
36
+ <div class="hfcm-notice notice-warning">
37
+ <p><?php _e('NOTE: Import/Export Functionality is only intended to operate within the same website. Using the export/import to move snippets from one website to a different site, may result in inconsistent behavior, particularly if you have specific elements as criteria such as pages, posts, categories, or tags.', '99robots-header-footer-code-manager'); ?></p>
38
+ </div>
39
+ <div class="hfcm-fields">
40
+ <div class="hfcm-field hfcm-field-checkbox" data-name="keys" data-type="checkbox">
41
+ <div class="hfcm-label">
42
+ <label for="keys">Select Snippets</label></div>
43
+ <div class="hfcm-input">
44
+ <input type="hidden" name="keys">
45
+ <ul class="hfcm-checkbox-list hfcm-bl">
46
+ <?php if (!empty($nnr_hfcm_snippets)) {
47
+ foreach ($nnr_hfcm_snippets as $nnr_key => $nnr_hfcm_snippet) {
48
+ ?>
49
+ <li>
50
+ <label>
51
+ <input type="checkbox" id="keys-snippet_<?php echo $nnr_hfcm_snippet->script_id; ?>"
52
+ name="nnr_hfcm_snippets[]" value="snippet_<?php echo $nnr_hfcm_snippet->script_id; ?>"> <?php echo $nnr_hfcm_snippet->name; ?>
53
+ </label>
54
+ </li>
55
+ <?php
56
+ }
57
+ } ?>
58
+ </ul>
59
+ </div>
60
+ </div>
61
+ </div>
62
+ <p class="hfcm-submit">
63
+ <button type="submit" name="action" class="button button-primary" value="download">
64
+ Export File
65
+ </button>
66
+ </p>
67
+ <?php wp_nonce_field('hfcm-nonce'); ?>
68
+ </form>
69
+ </div>
70
+ </div>
71
+ <div id="hfcm-admin-tool-import" class="postbox ">
72
+ <div class="postbox-header">
73
+ <h2 class="hndle">Import Snippets</h2>
74
+ </div>
75
+ <div class="inside">
76
+ <form method="post" enctype="multipart/form-data">
77
+ <p>Select the HFCM JSON file you would like to import. When you click the import button below,
78
+ HFCM will import the field groups.</p>
79
+ <div class="hfcm-fields">
80
+ <div class="hfcm-field hfcm-field-file" data-name="hfcm_import_file" data-type="file">
81
+ <div class="hfcm-label">
82
+ <label for="hfcm_import_file">Select File</label></div>
83
+ <div class="hfcm-input">
84
+ <div class="hfcm-file-uploader" data-library="all" data-mime_types=""
85
+ data-uploader="basic">
86
+ <div class="hide-if-value">
87
+ <label class="hfcm-basic-uploader">
88
+ <input type="file" name="nnr_hfcm_import_file" id="nnr_hfcm_import_file">
89
+ </label>
90
+ </div>
91
+ </div>
92
+ </div>
93
+ </div>
94
+ </div>
95
+ <p class="hfcm-submit">
96
+ <input type="submit" class="button button-primary" value="import">
97
+ </p>
98
+ <?php wp_nonce_field('hfcm-nonce'); ?>
99
+ </form>
100
+ </div>
101
+ </div>
102
+ </div>
103
+ </div>
104
+ </div>
includes/hfcm-update.php DELETED
@@ -1,85 +0,0 @@
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 ( empty( $_GET['id'] ) ) {
12
- die( 'Missing ID parameter.' );
13
- }
14
- $id = (int) $_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
- $ex_pages = json_decode( $s->ex_pages );
31
- $ex_posts = json_decode( $s->ex_posts );
32
-
33
- if ( ! is_array( $s_pages ) ) {
34
- $s_pages = array();
35
- }
36
-
37
- if ( ! is_array( $ex_pages ) ) {
38
- $ex_pages = array();
39
- }
40
-
41
- $s_posts = json_decode( $s->s_posts );
42
- if ( ! is_array( $s_posts ) ) {
43
- $s_posts = array();
44
- }
45
-
46
- $ex_posts = json_decode( $s->ex_posts );
47
- if ( ! is_array( $ex_posts ) ) {
48
- $ex_posts = array();
49
- }
50
-
51
- $s_custom_posts = json_decode( $s->s_custom_posts );
52
- if ( ! is_array( $s_custom_posts ) ) {
53
- $s_custom_posts = array();
54
- }
55
-
56
- $s_categories = json_decode( $s->s_categories );
57
- if ( ! is_array( $s_categories ) ) {
58
- $s_categories = array();
59
- }
60
-
61
- $s_tags = json_decode( $s->s_tags );
62
- if ( ! is_array( $s_tags ) ) {
63
- $s_tags = array();
64
- }
65
-
66
- $createdby = esc_html( $s->created_by );
67
- $lastmodifiedby = esc_html( $s->last_modified_by );
68
- $createdon = esc_html( $s->created );
69
- $lastrevisiondate = esc_html( $s->last_revision_date );
70
- }
71
-
72
- // escape for html output
73
- $name = esc_textarea( $name );
74
- $snippet = esc_textarea( $snippet );
75
- $device_type = esc_html( $device_type );
76
- $location = esc_html( $location );
77
- $display_on = esc_html( $display_on );
78
- $status = esc_html( $status );
79
- $lp_count = esc_html( $lp_count );
80
- $i = esc_html( $lp_count );
81
- // Notify hfcm-add-edit.php to make necesary changes for update
82
- $update = true;
83
-
84
- require_once( plugin_dir_path( __FILE__ ) . 'hfcm-add-edit.php' );
85
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/nnr-hfcm-showboxes.js ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // function to show dependent dropdowns for "Site Display" field.
2
+
3
+ function hfcm_showotherboxes(type) {
4
+ var header = '<option value="header">' + hfcm_localize.header + '</option>',
5
+ before_content = '<option value="before_content">' + hfcm_localize.before_content + '</option>',
6
+ after_content = '<option value="after_content">' + hfcm_localize.after_content + '</option>',
7
+ footer = '<option value="footer">' + hfcm_localize.footer + '</option>',
8
+ all_options = header + before_content + after_content + footer;
9
+
10
+ if (type == 'All') {
11
+ jQuery('#ex_pages, #ex_posts, #locationtr').show();
12
+ hfcm_remember_loc(header + footer);
13
+ jQuery('#s_categories, #s_pages, #s_tags, #c_posttype, #lp_count, #s_posts').hide();
14
+ } else if (type == 's_pages') {
15
+ jQuery('#s_pages, #locationtr').show();
16
+ hfcm_remember_loc(all_options);
17
+ jQuery('#s_categories, #s_tags, #ex_pages, #ex_posts, #c_posttype, #lp_count, #s_posts').hide();
18
+ } else if (type == 's_posts') {
19
+ jQuery('#s_posts, #locationtr').show();
20
+ hfcm_remember_loc(all_options);
21
+ jQuery('#s_pages, #s_categories, #ex_pages, #ex_posts, #s_tags, #c_posttype, #lp_count').hide();
22
+ } else if (type == 's_categories') {
23
+ jQuery('#s_categories, #locationtr').show();
24
+ hfcm_remember_loc(header + footer);
25
+ jQuery('#s_pages, #s_tags, #c_posttype, #ex_pages, #ex_posts, #lp_count, #s_posts').hide();
26
+ } else if (type == 's_custom_posts') {
27
+ jQuery('#c_posttype, #locationtr').show();
28
+ hfcm_remember_loc(all_options);
29
+ jQuery('#s_categories, #s_tags, #s_pages, #ex_pages, #ex_posts, #lp_count, #s_posts').hide();
30
+ } else if (type == 's_tags') {
31
+ hfcm_remember_loc(all_options);
32
+ jQuery('#s_tags, #locationtr').show();
33
+ jQuery('#s_categories, #s_pages, #c_posttype, #ex_pages, #ex_posts, #lp_count, #s_posts').hide();
34
+ } else if (type == 'latest_posts') {
35
+ hfcm_remember_loc(all_options);
36
+ jQuery('#s_pages, #s_categories, #s_tags, #ex_pages, #ex_posts, #c_posttype, #s_posts').hide();
37
+ jQuery('#lp_count, #locationtr').show();
38
+ } else if (type == 'manual') {
39
+ jQuery('#s_pages, #s_categories, #s_tags,#ex_pages, #ex_posts, #c_posttype, #lp_count, #locationtr, #s_posts').hide();
40
+ } else {
41
+ hfcm_remember_loc(header + footer);
42
+ jQuery('#s_pages, #s_categories, #s_tags, #c_posttype, #lp_count, #s_posts').hide();
43
+ jQuery('#locationtr').show();
44
+ }
45
+ }
46
+
47
+ function hfcm_remember_loc(new_html) {
48
+ var tmp = jQuery('#data_location option:selected').val();
49
+ jQuery('#data_location').html(new_html);
50
+ jQuery('#data_location option[value="' + tmp + '"]').prop('selected', true);
51
+ }
52
+
53
+ // init selectize.js
54
+ jQuery('#loader').show();
55
+ jQuery(function ($) {
56
+
57
+ var nnr_hfcm_data = {
58
+ action: 'hfcm-request',
59
+ id: hfcm_localize.id,
60
+ get_posts: true,
61
+ security: hfcm_localize.security
62
+ };
63
+
64
+ $.post(
65
+ ajaxurl,
66
+ nnr_hfcm_data,
67
+ function (new_data) {
68
+ var all_posts = $.merge([{text: "", value:""}], new_data.posts );
69
+ var options = {
70
+ plugins: ['remove_button'],
71
+ options: all_posts,
72
+ items: new_data.selected
73
+ };
74
+ $('#loader').hide();
75
+ $('#s_posts select').selectize(options);
76
+ var options = {
77
+ plugins: ['remove_button'],
78
+ options: new_data.posts,
79
+ items: new_data.excluded
80
+ };
81
+ $('#loader').hide();
82
+ $('#ex_posts select').selectize(options);
83
+ },
84
+ 'json', // ajax result format
85
+ );
86
+ // selectize all <select multiple> elements
87
+ $('#s_pages select, #s_categories select, #c_posttype select, #s_tags select, #ex_pages select').selectize({
88
+ plugins: ['remove_button']
89
+ });
90
+
91
+ if ($('#nnr_newcontent').length) {
92
+ var editorSettings = wp.codeEditor.defaultSettings ? _.clone(wp.codeEditor.defaultSettings) : {};
93
+ editorSettings.codemirror = _.extend(
94
+ {},
95
+ editorSettings.codemirror,
96
+ {
97
+ indentUnit: 2,
98
+ tabSize: 2,
99
+ //mode: 'javascript',
100
+ }
101
+ );
102
+ var editor = wp.codeEditor.initialize($('#nnr_newcontent'), editorSettings);
103
+ }
104
+ });
js/showboxes.js DELETED
@@ -1,87 +0,0 @@
1
- // function to show dependent dropdowns for "Site Display" field.
2
-
3
- function hfcm_showotherboxes( type ) {
4
- var header = '<option value="header">'+ hfcm_localize.header +'</option>',
5
- before_content = '<option value="before_content">'+ hfcm_localize.before_content +'</option>',
6
- after_content = '<option value="after_content">'+ hfcm_localize.after_content +'</option>',
7
- footer = '<option value="footer">'+ hfcm_localize.footer +'</option>',
8
- all_options = header + before_content + after_content + footer;
9
-
10
- if (type == 'All') {
11
- jQuery('#ex_pages, #ex_posts, #locationtr').show();
12
- hfcm_remember_loc( all_options );
13
- jQuery('#s_categories, #s_pages, #s_tags, #c_posttype, #lp_count, #s_posts').hide();
14
- }else if (type == 's_pages') {
15
- jQuery('#s_pages, #locationtr').show();
16
- hfcm_remember_loc( all_options );
17
- jQuery('#s_categories, #s_tags, #ex_pages, #ex_posts, #c_posttype, #lp_count, #s_posts').hide();
18
- } else if (type == 's_posts') {
19
- jQuery('#s_posts, #locationtr').show();
20
- hfcm_remember_loc( all_options );
21
- jQuery('#s_pages, #s_categories, #ex_pages, #ex_posts, #s_tags, #c_posttype, #lp_count').hide();
22
- } else if (type == 's_categories') {
23
- jQuery('#s_categories, #locationtr').show();
24
- hfcm_remember_loc( all_options );
25
- jQuery('#s_pages, #s_tags, #c_posttype, #ex_pages, #ex_posts, #lp_count, #s_posts').hide();
26
- } else if (type == 's_custom_posts') {
27
- jQuery('#c_posttype, #locationtr').show();
28
- hfcm_remember_loc( all_options );
29
- jQuery('#s_categories, #s_tags, #s_pages, #ex_pages, #ex_posts, #lp_count, #s_posts').hide();
30
- } else if (type == 's_tags') {
31
- hfcm_remember_loc( all_options );
32
- jQuery('#s_tags, #locationtr').show();
33
- jQuery('#s_categories, #s_pages, #c_posttype, #ex_pages, #ex_posts, #lp_count, #s_posts').hide();
34
- } else if (type == 'latest_posts') {
35
- hfcm_remember_loc( all_options );
36
- jQuery('#s_pages, #s_categories, #s_tags, #ex_pages, #ex_posts, #c_posttype, #s_posts').hide();
37
- jQuery('#lp_count, #locationtr').show();
38
- } else if (type == 'manual') {
39
- jQuery('#s_pages, #s_categories, #s_tags,#ex_pages, #ex_posts, #c_posttype, #lp_count, #locationtr, #s_posts').hide();
40
- } else {
41
- hfcm_remember_loc( header + footer );
42
- jQuery('#s_pages, #s_categories, #s_tags, #c_posttype, #lp_count, #s_posts').hide();
43
- jQuery('#locationtr').show();
44
- }
45
- }
46
-
47
- function hfcm_remember_loc( new_html ) {
48
- var tmp = jQuery('#data_location option:selected').val();
49
- jQuery('#data_location').html( new_html );
50
- jQuery('#data_location option[value="' + tmp + '"]').prop( 'selected', true );
51
- }
52
-
53
- // init selectize.js
54
- jQuery('#loader').show();
55
- jQuery(function($) {
56
-
57
- var data = {
58
- action: 'hfcm-request',
59
- id: hfcm_localize.id,
60
- get_posts: true,
61
- security: hfcm_localize.security
62
- };
63
-
64
- $.post(
65
- ajaxurl,
66
- data,
67
- function(new_data) {
68
- var options = {
69
- plugins: ['remove_button'],
70
- options: new_data.posts,
71
- items: new_data.selected,
72
- };
73
- $('#loader').hide();
74
- $('#s_posts select').selectize( options );
75
- var options = {
76
- plugins: ['remove_button'],
77
- options: new_data.posts,
78
- items: new_data.excluded
79
- };
80
- $('#loader').hide();
81
- $('#ex_posts select').selectize( options );
82
- },
83
- 'json', // ajax result format
84
- );
85
- // selectize all <select multiple> elements
86
- $('#s_pages select, #s_categories select, #c_posttype select, #s_tags select, #ex_pages select').selectize();
87
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: 99robots, charliepatel, DraftPress
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: 5.7.1
6
- Stable tag: 1.1.10
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Donate link: https://draftpress.com
@@ -112,6 +112,14 @@ A. Free plugins rely on user feedback. Therefore, the best thing you can do for
112
  A. If your script is not supported, just let us know and we'll look into it immediately. We will do our best to ensure all reputable services are supported. When requesting support for a particular script, it would be nice to get a sample of the script so that we can see its structure.
113
 
114
  == Changelog ==
 
 
 
 
 
 
 
 
115
  = 1.1.10 = 2021-04-23
116
  * FIXED: Warnings - Undefined Variables
117
  * UPDATED: Compatibility with WordPress 5.7.1
2
  Contributors: 99robots, charliepatel, DraftPress
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: 5.7.2
6
+ Stable tag: 1.1.11
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Donate link: https://draftpress.com
112
  A. If your script is not supported, just let us know and we'll look into it immediately. We will do our best to ensure all reputable services are supported. When requesting support for a particular script, it would be nice to get a sample of the script so that we can see its structure.
113
 
114
  == Changelog ==
115
+ = 1.1.11 = 2021-08-10
116
+ * FIXED: Warnings - Undefined Variables
117
+ * FIXED: Selectize issue of not able to select first option from the dropdown
118
+ * ADDED: Snippet types
119
+ * ADDED: Code Editor in place of textarea
120
+ * ADDED: Import/Export Snippets
121
+ * UPDATED: Compatibility with WordPress 5.8
122
+
123
  = 1.1.10 = 2021-04-23
124
  * FIXED: Warnings - Undefined Variables
125
  * UPDATED: Compatibility with WordPress 5.7.1