PluginProbe
Insert Html Snippet / trunk
Insert Html Snippet vtrunk
1.4.6 trunk 1.0 1.0.1 1.1 1.1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.4 1.4.1 1.4.2 1.4.3 All 27 releases
← All changes | admin/snippets.php +123 -24 1.4.1trunk View file →
@@ -2,8 +2,22 @@
2 2 if ( ! defined( 'ABSPATH' ) )
3 3 exit;
4 4
5 5 global $wpdb;
6 + if ((get_option('xyz_ihs_sync_needed') != 0) && (get_option('xyz_ihs_show_snippet_usage')==1))
7 + {
8 + echo '<div id="ics-sync-notice" class="notice notice-warning is-dismissible">
9 + <p>
10 + <strong>Usage Tracking Sync Required.</strong><br>
11 + Your site needs a one-time synchronization to build snippet usage records.
12 + This helps in displaying accurate usage statistics.
13 + <button id="xyz-start-sync" class="button button-primary" data-offset ="'. get_option('xyz_ihs_sync_needed').'">
14 + '.(get_option('xyz_ihs_sync_needed') > 1 ? 'Resume Sync' : 'Start Sync').'
15 + </button>
16 + <span id="sync-progress" style="margin-left:10px;"></span>
17 + </p>
18 + </div>';
19 + }
6 20 $_GET = stripslashes_deep($_GET);
7 21 $xyz_ihs_message = $search_name_db=$search_name='';
8 22
9 23 if(isset($_GET['xyz_ihs_msg'])){
@@ -25,22 +39,24 @@
25 39 // exit;
26 40 // }
27 41 // }
28 42 if (isset($_POST['apply_ihs_bulk_actions'])){
29 - if (isset($_POST['ihs_bulk_actions_snippet'])){
43 + if (isset($_POST['ihs_bulk_actions_snippet']))
44 + {
30 45 if(!isset($_REQUEST['_wpnonce'])||!wp_verify_nonce($_REQUEST['_wpnonce'],'bulk_actions_ihs') )
31 46 {
32 47 wp_nonce_ays( 'bulk_actions_ihs' );
33 48 exit;
34 49 }
35 - $ihs_bulk_actions_snippet=$_POST['ihs_bulk_actions_snippet'];
36 - if (isset($_POST['xyz_ihs_snippet_ids']))
37 - $xyz_ihs_snippet_ids = $_POST['xyz_ihs_snippet_ids'];
50 + $ihs_bulk_actions_snippet=intval($_POST['ihs_bulk_actions_snippet']);
51 + $xyz_ihs_snippet_ids = [];
52 + if (isset($_POST['xyz_ihs_snippet_ids']) && is_array($_POST['xyz_ihs_snippet_ids']))
53 + $xyz_ihs_snippet_ids = array_map('intval', $_POST['xyz_ihs_snippet_ids']);
38 54 $xyz_ihs_pageno = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
39 55
40 56 if (empty($xyz_ihs_snippet_ids))
41 57 {
42 - header("Location:".admin_url('admin.php?page=insert-html-snippet-manage&xyz_ihs_msg=8&pagenum='.$xyz_ihs_pageno));
58 + wp_safe_redirect(admin_url('admin.php?page=insert-html-snippet-manage&xyz_ihs_msg=8&pagenum='.$xyz_ihs_pageno));
43 59 exit();
44 60 }
45 61 if ($ihs_bulk_actions_snippet==2)//bulk-delete
46 62 {
@@ -47,9 +63,9 @@
47 63 foreach ($xyz_ihs_snippet_ids as $snippet_id)
48 64 {
49 65 $wpdb->query($wpdb->prepare( 'DELETE FROM '.$wpdb->prefix.'xyz_ihs_short_code WHERE id=%d',$snippet_id)) ;
50 66 }
51 - header("Location:".admin_url('admin.php?page=insert-html-snippet-manage&xyz_ihs_msg=3&pagenum='.$xyz_ihs_pageno));
67 + wp_safe_redirect(admin_url('admin.php?page=insert-html-snippet-manage&xyz_ihs_msg=3&pagenum='.$xyz_ihs_pageno));
52 68 exit();
53 69 }
54 70 elseif ($ihs_bulk_actions_snippet==0)//bulk-Deactivate
55 71 {
@@ -54,9 +70,9 @@
54 70 elseif ($ihs_bulk_actions_snippet==0)//bulk-Deactivate
55 71 {
56 72 foreach ($xyz_ihs_snippet_ids as $xyz_ihs_snippetId)
57 73 $wpdb->update($wpdb->prefix.'xyz_ihs_short_code', array('status'=>2), array('id'=>$xyz_ihs_snippetId));
58 - header("Location:".admin_url('admin.php?page=insert-html-snippet-manage&xyz_ihs_msg=4&pagenum='.$xyz_ihs_pageno));
74 + wp_safe_redirect(admin_url('admin.php?page=insert-html-snippet-manage&xyz_ihs_msg=4&pagenum='.$xyz_ihs_pageno));
59 75 exit();
60 76 }
61 77 elseif ($ihs_bulk_actions_snippet==1)//bulk-activate
62 78 {
@@ -61,14 +77,14 @@
61 77 elseif ($ihs_bulk_actions_snippet==1)//bulk-activate
62 78 {
63 79 foreach ($xyz_ihs_snippet_ids as $xyz_ihs_snippetId)
64 80 $wpdb->update($wpdb->prefix.'xyz_ihs_short_code', array('status'=>1), array('id'=>$xyz_ihs_snippetId));
65 - header("Location:".admin_url('admin.php?page=insert-html-snippet-manage&xyz_ihs_msg=4&pagenum='.$xyz_ihs_pageno));
81 + wp_safe_redirect(admin_url('admin.php?page=insert-html-snippet-manage&xyz_ihs_msg=4&pagenum='.$xyz_ihs_pageno));
66 82 exit();
67 83 }
68 84 elseif ($ihs_bulk_actions_snippet==-1)//no action selected
69 85 {
70 - header("Location:".admin_url('admin.php?page=insert-html-snippet-manage&xyz_ihs_msg=7&pagenum='.$xyz_ihs_pageno));
86 + wp_safe_redirect(admin_url('admin.php?page=insert-html-snippet-manage&xyz_ihs_msg=7&pagenum='.$xyz_ihs_pageno));
71 87 exit();
72 88 }
73 89 }
74 90
@@ -135,8 +151,11 @@
135 151 </span>
136 152 <span
137 153 id="xyz_ihs_system_notice_area_dismiss">Dismiss</span>
138 154 </div>
155 +<div class="notice notice-success is-dismissible">
156 + <p><strong>HTML Snippet successfully updated. &nbsp;&nbsp;&nbsp;</strong></p>
157 +</div>
139 158 <?php
140 159 }
141 160 if($xyz_ihs_message == 7)
142 161 {
@@ -166,9 +185,9 @@
166 185
167 186 <form method="post">
168 187 <?php wp_nonce_field( 'bulk_actions_ihs');?>
169 188 <fieldset
170 - style="width: 99%; border: 1px solid #F7F7F7; padding: 10px 0px;">
189 + style="width: 98.8%; border: 1px solid #4d3e3e2e; padding: 10px 0px;">
171 190 <legend><h3>HTML Snippets</h3></legend>
172 191 <?php
173 192 global $wpdb;
174 193 $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
@@ -249,11 +268,11 @@
249 268 <thead>
250 269 <tr>
251 270 <th scope="col" width="3%"><input type="checkbox" id="chkAllSnippets" /></th>
252 271 <th scope="col" >Tracking Name</th>
253 - <th scope="col">Snippet Placement
272 + <th scope="col">Snippet Placement</th>
273 + <th scope="col">Placement Details</th>
254 274
255 -</th>
256 275 <th scope="col" >Status</th>
257 276 <th scope="col" colspan="3" style="text-align: center;">Action</th>
258 277 </tr>
259 278 </thead>
@@ -271,24 +290,67 @@
271 290 <tr <?php echo $class; ?>>
272 291 <td style="vertical-align: middle !important;padding-left: 18px;">
273 292 <input type="checkbox" class="chk" value="<?php echo $snippetId; ?>" name="xyz_ihs_snippet_ids[]" id="xyz_ihs_snippet_ids" />
274 293 </td>
275 - <td id="xyz_ihs_vAlign"><?php
276 - echo esc_html($entry->title);
277 - ?></td>
294 + <td id="xyz_ihs_vAlign" title="<?php echo esc_attr($entry->description); ?>" ><?php
295 + echo esc_html($entry->title); ?></td>
278 296 <td id="xyz_ihs_vAlign">
279 297 <?php
298 +$placement_text = '';
280 299 if ($entry->status == 2) {
281 - echo 'NA';
300 +
301 + $placement_text = 'NA';
282 302 } else {
283 - echo ($entry->insertionMethod == 1) ?
284 - 'Automatic' :
285 - (($entry->insertionMethod == 2) ?
286 - '<span onclick="xyz_ihs_copy_shortcode(' . $entry->id . ')" class="xyz_ihs_copy_shortcode" id="xyz_ihs_shortcode_' . $entry->id . '">[xyz-ihs snippet="' . esc_html($entry->title) . '"]</span>' .
287 - '<span onclick="xyz_ihs_copy_shortcode(' . $entry->id . ')"><img class="xyz_ihs_img xyz_ihs_img_table" title="Click to copy" src="' . plugins_url('insert-html-snippet/images/copy-document.png') . '"></span>'
288 - :
289 - '');
303 + /* AUTOMATIC PLACEMENT */
304 + if ($entry->insertionMethod == 1) {
305 +
306 + $placement_text =
307 + '<span class="ihs-badge ihs-badge-auto">Automatic</span>';
290 308 }
309 + /* SHORTCODE PLACEMENT */
310 + elseif ($entry->insertionMethod == 2) {
311 +
312 +
313 + $placement_text =
314 + '<span class="ihs-badge ihs-badge-shortcode">Shortcode</span> ' .
315 + '<span onclick="xyz_ihs_copy_shortcode(' . (int) $entry->id . ')" ' .
316 + 'class="xyz_ihs_copy_shortcode" id="xyz_ihs_shortcode_' . (int) $entry->id . '">' .
317 + '[xyz-ihs snippet="' . esc_html($entry->title) . '"]</span>' .
318 + '<span onclick="xyz_ihs_copy_shortcode(' . (int) $entry->id . ')">' .
319 + '<img class="xyz_ihs_img xyz_ihs_img_table" title="Click to copy" ' .
320 + 'src="' . esc_url(plugins_url('insert-html-snippet/images/copy-document.png')) . '">' .
321 + '</span>';
322 + }
323 +}
324 +echo $placement_text;
325 +?>
326 +</td>
327 + <td id="xyz_ihs_vAlign" style="color:#1c331cbf;">
328 + <?php
329 + if ($entry->status == 2) {
330 + echo '—';
331 + } elseif ($entry->insertionMethod == 1) {
332 + if (!empty($entry->insertionLocation)) {
333 + echo esc_html(
334 + xyz_ihs_get_insertion_location_label($entry->insertionLocation)
335 + );
336 + } else {
337 + echo '—';
338 + }
339 + } elseif ($entry->insertionMethod == 2) {
340 + $post_count=0;
341 + $post_count = $wpdb->get_var($wpdb->prepare(
342 + "SELECT COUNT(*) FROM {$wpdb->prefix}xyz_ihs_usage WHERE snippet_id = %d",
343 + $entry->id
344 + ));
345 + if ($post_count > 0 && (get_option('xyz_ihs_show_snippet_usage')==1)) {
346 + echo 'Used in ' . $count . ' posts/pages';
347 + }else {
348 + if(get_option('xyz_ihs_show_snippet_usage')!=1)
349 + echo '<span title="Usage details are hidden. Enable &quot;Show Snippet Usage Details&quot; in settings." style="cursor: help;">Hidden</span>'; else
350 + echo 'Not used';
351 + }
352 + }
291 353 ?>
292 354 </td>
293 355 <td id="xyz_ihs_vAlign">
294 356 <?php
@@ -378,9 +440,46 @@
378 440 jQuery(document).ready(function(){
379 441 jQuery("#chkAllSnippets").click(function(){
380 442 jQuery(".chk").prop("checked",jQuery("#chkAllSnippets").prop("checked"));
381 443 });
444 + // Handling the Sync Button click
445 + jQuery(document).on('click', '#xyz-start-sync', function(e) {
446 + e.preventDefault();
447 + let btn = jQuery(this);
448 + let progress = jQuery('#sync-progress');
449 + btn.prop('disabled', true).text('Syncing...');
450 + // Read initial offset from button data attribute
451 + let initialOffset = parseInt(btn.data('offset')) || 0;
452 + function runSyncBatch(offset) {
453 + jQuery.ajax({
454 + url: ajaxurl,
455 + type: 'POST',
456 + data: {
457 + action: 'xyz_ihs_sync_usage',
458 + offset: offset
459 + },
460 + success: function(response) {
461 + if (response.success && response.data.status === 'processing') {
462 + progress.text('Processed ' + response.data.new_offset + ' posts...');
463 + // Update button data-offset to keep track
464 + btn.data('offset', response.data.new_offset);
465 + runSyncBatch(response.data.new_offset);
466 + } else {
467 + progress.text('✅ Sync Complete!');
468 + btn.prop('disabled', false).text('Sync Usage Now');
469 + btn.data('offset', 0); // reset offset
470 + location.reload();
471 + }
472 + },
473 + error: function() {
474 + progress.text('❌ Sync failed. Please try again.');
475 + btn.prop('disabled', false).text('Sync Usage Now');
476 + }
477 + });
478 + }
479 + runSyncBatch(initialOffset);
382 480 });
481 +});
383 482 const xyz_ihs_copy_shortcode = (id) => {
384 483
385 484 var span = document.getElementById("xyz_ihs_shortcode_" + id);
386 485 var tempTextarea = document.createElement("textarea");
@@ -428,9 +527,9 @@
428 527
429 528
430 529
431 530 let noticeElementString =
432 - `<div class="system_notice_area_style${flag}" id="xyz_ihs_system_notice_area">
531 +`<div class="xyz_ihs_system_notice_area_style${flag}" id="xyz_ihs_system_notice_area">
433 532 <span id="system_notice_area_common_msg">${msg}.&nbsp;&nbsp;&nbsp;</span>
434 533 <span id="xyz_ihs_system_notice_area_dismiss">Dismiss</span>
435 534 </div>`;
436 535