PluginProbe
Insert PHP Code Snippet / trunk
Insert PHP Code Snippet vtrunk
1.4.7 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 1.4.4 1.4.5 1.4.6 trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 All 27 releases
← All changes | admin/snippets.php +514 -113 1.2trunk View file →
@@ -1,17 +1,90 @@
1 -<?php
1 +<?php
2 +if ( ! defined( 'ABSPATH' ) )
3 + exit;
4 +
2 5 global $wpdb;
3 6 $_GET = stripslashes_deep($_GET);
4 -$xyz_ips_message = '';
7 +$xyz_ips_message =$search_name_db=$search_name= '';
8 +
5 9 if(isset($_GET['xyz_ips_msg'])){
6 - $xyz_ips_message = $_GET['xyz_ips_msg'];
10 + $xyz_ips_message = intval($_GET['xyz_ips_msg']);
7 11 }
12 +if($_POST)
13 +{
14 + if(isset($_POST['search']))
15 + {
16 + if(!isset($_REQUEST['_wpnonce'])||!wp_verify_nonce($_REQUEST['_wpnonce'],'snipp-manage_') ){
17 + wp_nonce_ays( 'snipp-manage_' );
18 + exit;
19 + }
20 + }
21 + // if(isset($_POST['textFieldButton2']))
22 + // {
23 + // if(!isset($_REQUEST['_wpnonce'])||!wp_verify_nonce($_REQUEST['_wpnonce'],'bulk_actions_ips') ){
24 + // wp_nonce_ays( 'bulk_actions_ips' );
25 + // exit;
26 + // }
27 + // }
28 + if (isset($_POST['apply_ips_bulk_actions'])){
29 + if (isset($_POST['ips_bulk_actions_snippet'])){
30 + if(!isset($_REQUEST['_wpnonce'])||!wp_verify_nonce($_REQUEST['_wpnonce'],'bulk_actions_ips') )
31 + {
32 + wp_nonce_ays( 'bulk_actions_ips' );
33 + exit;
34 + }
35 + $xyz_ips_snippet_ids = [];
36 + $ips_bulk_actions_snippet=$_POST['ips_bulk_actions_snippet'];
37 + if (isset($_POST['xyz_ips_snippet_ids']) && is_array($_POST['xyz_ips_snippet_ids']))
38 + $xyz_ips_snippet_ids = array_map('intval', $_POST['xyz_ips_snippet_ids']);
39 + $xyz_ips_pageno = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
40 + if (empty($xyz_ips_snippet_ids))
41 + {
42 + wp_safe_redirect(admin_url('admin.php?page=insert-php-code-snippet-manage&xyz_ips_msg=8&pagenum='.$xyz_ips_pageno));
43 + exit();
44 + }
45 + if ($ips_bulk_actions_snippet==2)//bulk-delete
46 + {
47 + foreach ($xyz_ips_snippet_ids as $snippet_id)
48 + {
49 + $wpdb->query($wpdb->prepare( 'DELETE FROM '.$wpdb->prefix.'xyz_ips_short_code WHERE id=%d',$snippet_id)) ;
50 + }
51 + wp_safe_redirect(admin_url('admin.php?page=insert-php-code-snippet-manage&xyz_ips_msg=3&pagenum='.$xyz_ips_pageno));
52 + exit();
53 + }
54 + elseif ($ips_bulk_actions_snippet==0)//bulk-Deactivate
55 + {
56 + foreach ($xyz_ips_snippet_ids as $xyz_ips_snippetId)
57 + $wpdb->update($wpdb->prefix.'xyz_ips_short_code', array('status'=>2), array('id'=>$xyz_ips_snippetId));
58 + wp_safe_redirect(admin_url('admin.php?page=insert-php-code-snippet-manage&xyz_ips_msg=4&pagenum='.$xyz_ips_pageno));
59 + exit();
60 + }
61 + elseif ($ips_bulk_actions_snippet==1)//bulk-activate
62 + {
63 + foreach ($xyz_ips_snippet_ids as $xyz_ips_snippetId)
64 + $wpdb->update($wpdb->prefix.'xyz_ips_short_code', array('status'=>1), array('id'=>$xyz_ips_snippetId));
65 + wp_safe_redirect(admin_url('admin.php?page=insert-php-code-snippet-manage&xyz_ips_msg=4&pagenum='.$xyz_ips_pageno));
66 + exit();
67 + }
68 + elseif ($ips_bulk_actions_snippet==-1)//no action selected
69 + {
70 + wp_safe_redirect(admin_url('admin.php?page=insert-php-code-snippet-manage&xyz_ips_msg=7&pagenum='.$xyz_ips_pageno));
71 + exit();
72 + }
73 + }
74 +
75 + }
76 +
77 +}
8 78 if($xyz_ips_message == 1){
9 79
10 80 ?>
11 -<div class="system_notice_area_style1" id="system_notice_area">
12 -PHP Snippet successfully added.&nbsp;&nbsp;&nbsp;<span
13 -id="system_notice_area_dismiss">Dismiss</span>
81 +<div class="xyz_ips_system_notice_area_style1" id="xyz_ips_system_notice_area">
82 +<span id="system_notice_area_common_msg">
83 +PHP Snippet successfully added.&nbsp;&nbsp;&nbsp;
84 +</span>
85 +<span
86 +id="xyz_ips_system_notice_area_dismiss">Dismiss</span>
14 87 </div>
15 88 <?php
16 89
17 90 }
@@ -17,11 +90,14 @@
17 90 }
18 91 if($xyz_ips_message == 2){
19 92
20 93 ?>
21 -<div class="system_notice_area_style0" id="system_notice_area">
22 -PHP Snippet not found.&nbsp;&nbsp;&nbsp;<span
23 -id="system_notice_area_dismiss">Dismiss</span>
94 +<div class="xyz_ips_system_notice_area_style0" id="xyz_ips_system_notice_area">
95 +<span id="system_notice_area_common_msg">
96 +PHP Snippet not found.&nbsp;&nbsp;&nbsp;
97 +</span>
98 +<span
99 +id="xyz_ips_system_notice_area_dismiss">Dismiss</span>
24 100 </div>
25 101 <?php
26 102
27 103 }
@@ -27,11 +103,14 @@
27 103 }
28 104 if($xyz_ips_message == 3){
29 105
30 106 ?>
31 -<div class="system_notice_area_style1" id="system_notice_area">
32 -PHP Snippet successfully deleted.&nbsp;&nbsp;&nbsp;<span
33 -id="system_notice_area_dismiss">Dismiss</span>
107 +<div class="xyz_ips_system_notice_area_style1" id="xyz_ips_system_notice_area">
108 +<span id="system_notice_area_common_msg">
109 +PHP Snippet successfully deleted.&nbsp;&nbsp;&nbsp;
110 +</span>
111 +<span
112 +id="xyz_ips_system_notice_area_dismiss">Dismiss</span>
34 113 </div>
35 114 <?php
36 115
37 116 }
@@ -37,11 +116,14 @@
37 116 }
38 117 if($xyz_ips_message == 4){
39 118
40 119 ?>
41 -<div class="system_notice_area_style1" id="system_notice_area">
42 -PHP Snippet status successfully changed.&nbsp;&nbsp;&nbsp;<span
43 -id="system_notice_area_dismiss">Dismiss</span>
120 +<div class="xyz_ips_system_notice_area_style1" id="xyz_ips_system_notice_area">
121 +<span id="system_notice_area_common_msg">
122 +PHP Snippet status successfully changed.&nbsp;&nbsp;&nbsp;
123 +</span>
124 +<span
125 +id="xyz_ips_system_notice_area_dismiss">Dismiss</span>
44 126 </div>
45 127 <?php
46 128
47 129 }
@@ -47,132 +129,313 @@
47 129 }
48 130 if($xyz_ips_message == 5){
49 131
50 132 ?>
51 -<div class="system_notice_area_style1" id="system_notice_area">
52 -PHP Snippet successfully updated.&nbsp;&nbsp;&nbsp;<span
53 -id="system_notice_area_dismiss">Dismiss</span>
133 +<div class="xyz_ips_system_notice_area_style1" id="xyz_ips_system_notice_area">
134 +<span id="system_notice_area_common_msg">
135 +PHP Snippet successfully updated.&nbsp;&nbsp;&nbsp;
136 +</span>
137 +<span
138 +id="xyz_ips_system_notice_area_dismiss">Dismiss</span>
54 139 </div>
55 140 <?php
56 141
57 142 }
143 +if($xyz_ips_message == 7)
144 +{
145 + ?>
146 + <div class="xyz_ips_system_notice_area_style1" id="xyz_ips_system_notice_area">
147 + <span id="system_notice_area_common_msg"> Please select an action to apply.&nbsp;&nbsp;&nbsp;
148 + </span>
149 + <span id="xyz_ips_system_notice_area_dismiss">Dismiss</span>
150 + </div>
151 +<?php
152 +}
153 +if($xyz_ips_message == 8)
154 +{
155 + ?>
156 + <div class="xyz_ips_system_notice_area_style1" id="xyz_ips_system_notice_area">
157 + <span id="system_notice_area_common_msg">
158 + Please select at least one snippet to perform this action.&nbsp;&nbsp;&nbsp;
159 + </span>
160 + <span id="xyz_ips_system_notice_area_dismiss">Dismiss</span>
161 + </div>
162 +<?php
163 +}
58 164 ?>
59 165
60 -
61 166 <div >
62 167
63 168
64 169 <form method="post">
65 - <fieldset
66 - style="width: 99%; border: 1px solid #F7F7F7; padding: 10px 0px;">
170 + <?php wp_nonce_field( 'bulk_actions_ips');?>
171 + <fieldset style="width: 98.8%; border: 1px solid #4d3e3e2e; padding: 10px 0px;">
67 172 <legend><h3>PHP Code Snippets</h3></legend>
68 - <?php
173 + <?php
69 174 global $wpdb;
70 - $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
71 - $limit = get_option('xyz_ips_limit');
175 +
176 + if ((get_option('xyz_ips_sync_needed') != 0) && (get_option('xyz_ips_show_snippet_usage')==1))
177 + {
178 + echo '<div id="ips-sync-notice" class="notice notice-warning is-dismissible">
179 + <p>
180 + <strong>Usage Tracking Sync Required.</strong><br>
181 + Your site needs a one-time synchronization to build snippet usage records.
182 + This helps in displaying accurate usage statistics.
183 + <button id="xyz-start-sync" class="button button-primary" data-offset ="'. get_option('xyz_ips_sync_needed').'">
184 + '.(get_option('xyz_ips_sync_needed') > 1 ? 'Resume Sync' : 'Start Sync').'
185 + </button>
186 + <span id="sync-progress" style="margin-left:10px;"></span>
187 + </p>
188 + </div>';
189 + }
190 + $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
191 + $limit = get_option('xyz_ips_limit');
72 192 $offset = ( $pagenum - 1 ) * $limit;
73 193
74 194
75 195 $field=get_option('xyz_ips_sort_field_name');
76 196 $order=get_option('xyz_ips_sort_order');
77 -
78 - $entries = $wpdb->get_results( "SELECT * FROM ".$wpdb->prefix."xyz_ips_short_code ORDER BY $field $order LIMIT $offset,$limit" );
197 + if(isset($_POST['snippet_name']))
198 + {
199 + $search_name=sanitize_text_field($_POST['snippet_name']);
200 + $search_name_db=esc_sql($search_name);
201 + }
202 + if(isset($_POST['insertionMethod']))
203 + {
204 + $insertionMethod =intval($_POST["insertionMethod"]);
205 + }
206 + else
207 + {
208 + $insertionMethod =0;
209 + }
210 + $strInsertionMethod='';
211 + if (intval($insertionMethod)>0)
212 + {
213 + $strInsertionMethod=" AND insertionMethod=$insertionMethod";
214 + }
79 215
216 + //$entries = $wpdb->get_results( "SELECT * FROM ".$wpdb->prefix."xyz_ips_short_code WHERE title like '%".$search_name_db."%'".$strInsertionMethod." ORDER BY $field $order LIMIT $offset,$limit" );
217 + $entries = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}xyz_ips_short_code WHERE title LIKE %s {$strInsertionMethod} ORDER BY $field $order LIMIT %d, %d", '%' . $wpdb->esc_like($search_name_db) . '%',$offset,$limit
218 + )
219 + );
80 220
81 -
82 221 ?>
83 - <input id="submit_ips"
222 + <input id="xyz_ips_submit_ips"
84 223 style="cursor: pointer; margin-bottom:10px; margin-left:8px;" type="button"
85 224 name="textFieldButton2" value="Add New PHP Code Snippet"
86 225 onClick='document.location.href="<?php echo admin_url('admin.php?page=insert-php-code-snippet-manage&action=snippet-add');?>"'>
87 - <table class="widefat" style="width: 99%; margin: 0 auto; border-bottom:none;">
88 - <thead>
89 - <tr>
90 - <th scope="col" >Tracking Name</th>
91 - <th scope="col" >Snippet Short Code</th>
92 - <th scope="col" >Status</th>
93 - <th scope="col" colspan="3" style="text-align: center;">Action</th>
94 - </tr>
95 - </thead>
96 - <tbody>
97 - <?php
98 - if( count($entries)>0 ) {
99 - $count=1;
100 - $class = '';
101 - foreach( $entries as $entry ) {
102 - $class = ( $count % 2 == 0 ) ? ' class="alternate"' : '';
103 - ?>
104 - <tr <?php echo $class; ?>>
105 - <td id="vAlign"><?php
106 - echo esc_html($entry->title);
107 - ?></td>
108 - <td id="vAlign"><?php
109 - if($entry->status == 2){echo 'NA';}
110 - else
111 - echo '[xyz-ips snippet="'.esc_html($entry->title).'"]';
112 - ?></td>
113 - <td id="vAlign">
114 - <?php
115 - if($entry->status == 2){
116 - echo "Inactive";
117 - }elseif ($entry->status == 1){
118 - echo "Active";
119 - }
120 -
121 - ?>
122 - </td>
123 - <?php
124 - if($entry->status == 2){
125 - ?>
126 - <td style="text-align: center;"><a
127 - href='<?php echo admin_url('admin.php?page=insert-php-code-snippet-manage&action=snippet-status&snippetId='.$entry->id.'&status=1&pageno='.$pagenum); ?>'><img
128 - id="img" title="Activate"
129 - src="<?php echo plugins_url('insert-php-code-snippet/images/activate.png')?>">
130 - </a>
131 - </td>
132 - <?php
133 - }elseif ($entry->status == 1){
134 - ?>
135 - <td style="text-align: center;"><a
136 - href='<?php echo admin_url('admin.php?page=insert-php-code-snippet-manage&action=snippet-status&snippetId='.$entry->id.'&status=2&pageno='.$pagenum); ?>'><img
137 - id="img" title="Deactivate"
138 - src="<?php echo plugins_url('insert-php-code-snippet/images/pause.png')?>">
139 - </a>
140 - </td>
141 - <?php
142 - }
143 -
144 - ?>
145 -
146 - <td style="text-align: center;"><a
147 - href='<?php echo admin_url('admin.php?page=insert-php-code-snippet-manage&action=snippet-edit&snippetId='.$entry->id.'&pageno='.$pagenum); ?>'><img
148 - id="img" title="Edit Snippet"
149 - src="<?php echo plugins_url('insert-php-code-snippet/images/edit.png')?>">
150 - </a>
151 - </td>
152 - <td style="text-align: center;" ><a
153 - href='<?php echo admin_url('admin.php?page=insert-php-code-snippet-manage&action=snippet-delete&snippetId='.$entry->id.'&pageno='.$pagenum); ?>'
154 - onclick="javascript: return confirm('Please click \'OK\' to confirm ');"><img
155 - id="img" title="Delete Snippet"
156 - src="<?php echo plugins_url('insert-php-code-snippet/images/delete.png')?>">
157 - </a></td>
158 - </tr>
226 + <br>
227 +<span style="padding-left: 6px;color:#21759B;">With Selected : </span>
228 + <select name="ips_bulk_actions_snippet" id="ips_bulk_actions_snippet" style="width:130px;height:29px;">
229 + <option value="-1">Bulk Actions</option>
230 + <option value="0">Deactivate</option>
231 + <option value="1">Activate</option>
232 + <option value="2">Delete</option>
233 +</select>
234 +<input type="submit" title="Apply" name="apply_ips_bulk_actions" value="Apply" style="color:#21759B;cursor:pointer;padding: 5px;background:linear-gradient(to top, #ECECEC, #F9F9F9) repeat scroll 0 0 #F1F1F1;border: 2px solid #DFDFDF;">
235 +</form>
236 +
237 +
238 +<table class="xyz-ips-manage-header">
239 + <tr>
240 + <td>
241 +<form name="manage_snippets" action="" method="post">
242 + <?php wp_nonce_field('snipp-manage_');?>
243 + <div class="xyz_ips_search_div" style="float:right;">
244 + <table class="xyz_ips_search_div_table" style="width:100%;">
245 + &nbsp;&nbsp;
246 +
247 +<span>Snippet Placement</span>&nbsp;
248 + <select name="insertionMethod" id="insertionMethod" >
249 + <option value="0" <?php if($insertionMethod==0) { echo "selected"; } ?>>All</option>
250 + <option value="1" <?php if($insertionMethod==1) { echo "selected"; } ?>>Automatic</option>
251 + <option value="2" <?php if($insertionMethod==2) { echo "selected"; } ?>>Short Code</option>
252 + <option value="3" <?php if($insertionMethod==3) { echo "selected"; } ?>>Execute On Demand</option>
253 +</select>
254 + &nbsp;&nbsp;
255 + <tr>
256 + <input type="text" name="snippet_name" value= "<?php if(isset($search_name)){echo esc_attr($search_name);}?>" placeholder="Search" >
257 + <input type="submit" name="search" class="xyz-ips-go" value="Go" />
258 + </tr>
259 + </table>
260 + </div>
261 +</form>
262 +
263 +</td>
264 + </tr>
265 +</table>
266 +<table class="widefat" style="width: 99%; margin: 0 auto; border-bottom:none;">
267 + <thead>
268 + <tr>
269 + <th scope="col" width="3%"><input type="checkbox" id="chkAllSnippets" /></th>
270 + <th scope="col" >Tracking Name</th>
271 + <th scope="col">Snippet Placement </th>
272 + <th scope="col">Placement Details</th>
273 + <th scope="col" >Status</th>
274 + <th scope="col" colspan="4" style="text-align: center;">Action</th>
275 + </tr>
276 + </thead>
277 + <tbody>
278 + <?php
279 + if( !empty($entries) )//if( count($entries)>0 )
280 + {
281 + $count=1;
282 + $class = '';
283 + foreach( $entries as $entry ) {
284 + $class = ( $count % 2 == 0 ) ? ' class="alternate"' : '';
285 + $snippetId=intval($entry->id);
286 + ?>
287 + <tr <?php echo $class; ?>>
288 + <td style="vertical-align: middle !important;padding-left: 18px;">
289 + <input type="checkbox" class="chk" value="<?php echo $snippetId; ?>" name="xyz_ips_snippet_ids[]" id="xyz_ips_snippet_ids" />
290 + </td>
291 + <td id="xyz_ips_vAlign" title="<?php echo esc_attr($entry->description); ?>" ><?php
292 + echo esc_html($entry->title);
293 + ?></td>
294 + <td>
295 +
296 +
297 + <?php
298 + $placement_text = '';
299 + if($entry->status == 2){
300 + $placement_text ='NA';
301 + } else{
302 +/* AUTOMATIC PLACEMENT */
303 +if ($entry->insertionMethod == 1) {
304 + $placement_text =
305 + '<span class="ips-badge ips-badge-auto">Automatic</span>';
306 +}
307 +/* SHORTCODE PLACEMENT */
308 +elseif ($entry->insertionMethod == 2) {
309 +
310 +
311 + $placement_text =
312 + '<span class="ips-badge ips-badge-shortcode">Shortcode</span> ' .
313 + '<span onclick="xyz_ips_copy_shortcode(' . (int) $entry->id . ')" ' .
314 + 'class="xyz_ips_copy_shortcode" id="xyz_ips_shortcode_' . (int) $entry->id . '">' .
315 + '[xyz-ips snippet="' . esc_html($entry->title) . '"]</span>' .
316 + '<span onclick="xyz_ips_copy_shortcode(' . (int) $entry->id . ')">' .
317 + '<img class="xyz_ips_img xyz_ips_img_table" title="Click to copy" ' .
318 + 'src="' . esc_url(plugins_url('insert-php-code-snippet/images/copy-document.png')) . '">' .
319 + '</span>';
320 +}
321 +elseif ($entry->insertionMethod == 3) {
322 + $placement_text ='<span class="ips-badge ips-badge-ondemand">Execute on demand</span>'.'<img onclick=xyz_ips_execute_shortcode('.$entry->id.') class="xyz_ips_img xyz_ips_img_table" id="xyz_ips_img_execute_shortcode" title="Click to execute" src="'.plugins_url('insert-php-code-snippet/images/play-button.png').'">';
323 +}
324 +echo $placement_text;
325 +}?>
326 +</td>
327 + <td id="xyz_ips_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_ips_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_ips_usage WHERE snippet_id = %d",
343 + $entry->id
344 + ));
345 + if ($post_count > 0 && (get_option('xyz_ips_show_snippet_usage')==1)) {
346 + echo 'Used in ' . $count . ' posts/pages';
347 + }else {
348 + if(get_option('xyz_ips_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 + }
353 + elseif ($entry->insertionMethod == 3) {
354 + echo 'Manually triggered';
355 + }
356 + ?>
357 +</td>
358 + <td id="xyz_ips_vAlign">
359 + <?php
360 + if($entry->status == 2){
361 + echo "Inactive";
362 + }elseif ($entry->status == 1){
363 + echo "Active";
364 + }
365 +
366 + ?>
367 + </td>
368 + <?php
369 + if($entry->status == 2){
370 + $stat1 = admin_url('admin.php?page=insert-php-code-snippet-manage&action=snippet-status&snippetId='.$snippetId.'&status=1&pageno='.$pagenum);
371 + ?>
372 + <td style="text-align: center;"><a
373 + href='<?php echo wp_nonce_url($stat1,'ips-pstat_'.$snippetId); ?>'><img
374 + id="xyz_ips_img" title="Activate"
375 + src="<?php echo plugins_url('images/activate.png',XYZ_INSERT_PHP_PLUGIN_FILE)?>">
376 + </a>
377 + </td>
378 + <?php
379 + }elseif ($entry->status == 1){
380 + $stat2 = admin_url('admin.php?page=insert-php-code-snippet-manage&action=snippet-status&snippetId='.$snippetId.'&status=2&pageno='.$pagenum);
381 + ?>
382 + <td style="text-align: center;"><a
383 + href='<?php echo wp_nonce_url($stat2,'ips-pstat_'.$snippetId); ?>'><img
384 + id="xyz_ips_img" title="Deactivate"
385 + src="<?php echo plugins_url('images/pause.png',XYZ_INSERT_PHP_PLUGIN_FILE)?>">
386 + </a>
387 + </td>
159 388 <?php
160 - $count++;
161 - }
162 - } else { ?>
163 - <tr>
164 - <td colspan="6" >PHP Code Snippets not found</td>
165 - </tr>
166 - <?php } ?>
167 - </tbody>
168 - </table>
169 -
170 - <input id="submit_ips"
389 + }
390 +
391 + ?>
392 +
393 + <td style="text-align: center;"><a
394 + href='<?php echo admin_url('admin.php?page=insert-php-code-snippet-manage&action=snippet-edit&snippetId='.$snippetId.'&pageno='.$pagenum); ?>'><img
395 + id="xyz_ips_img" title="Edit Snippet"
396 + src="<?php echo plugins_url('images/edit.png',XYZ_INSERT_PHP_PLUGIN_FILE)?>">
397 + </a>
398 + </td>
399 +
400 + <?php $delurl = admin_url('admin.php?page=insert-php-code-snippet-manage&action=snippet-delete&snippetId='.$snippetId.'&pageno='.$pagenum);?>
401 + <td style="text-align: center;" ><a
402 + href='<?php echo wp_nonce_url($delurl,'ips-pdel_'.$snippetId); ?>'
403 + onclick="javascript: return confirm('Please click \'OK\' to confirm ');"><img
404 + id="xyz_ips_img" title="Delete Snippet"
405 + src="<?php echo plugins_url('images/delete.png',XYZ_INSERT_PHP_PLUGIN_FILE)?>">
406 + </a></td>
407 +
408 + <?php
409 + $page_url =xyz_ips_get_link_by_slug('xyz-ics-preview-page');
410 + $page_url =add_query_arg( 'preview', 'true', $page_url );
411 + $page_url =add_query_arg( 'snippetId', $snippetId, $page_url );
412 + $prewurl =esc_url($page_url);
413 + ?>
414 + <td style="text-align: center;" >
415 + <?php if($entry->insertionMethod ==2) {?>
416 + <a href='<?php echo $prewurl;?>' target="_blank">
417 + <img id="xyz_ips_img" title="Preview" src="<?php echo plugins_url('images/preview.png',XYZ_INSERT_PHP_PLUGIN_FILE)?>">
418 + </a>
419 + <?php }?>
420 + </td>
421 + </tr>
422 + <?php
423 + $count++;
424 + }
425 + } else { ?>
426 + <tr>
427 + <td colspan="7" >PHP Code Snippets not found</td>
428 + </tr>
429 + <?php } ?>
430 + </tbody>
431 +</table>
432 +
433 + <input id="xyz_ips_submit_ips"
171 434 style="cursor: pointer; margin-top:10px;margin-left:8px;" type="button"
172 435 name="textFieldButton2" value="Add New PHP Code Snippet"
173 436 onClick='document.location.href="<?php echo admin_url('admin.php?page=insert-php-code-snippet-manage&action=snippet-add');?>"'>
174 -
437 +
175 438 <?php
176 439 $total = $wpdb->get_var( "SELECT COUNT(`id`) FROM ".$wpdb->prefix."xyz_ips_short_code" );
177 440 $num_of_pages = ceil( $total / $limit );
178 441
@@ -194,8 +457,146 @@
194 457 ?>
195 458
196 459 </fieldset>
197 460
198 - </form>
461 +
199 462
200 463 </div>
464 +<script type="text/javascript">
465 +jQuery(document).ready(function(){
466 + jQuery("#chkAllSnippets").click(function(){
467 + jQuery(".chk").prop("checked",jQuery("#chkAllSnippets").prop("checked"));
468 + });
469 + // Handling the Sync Button click
470 + jQuery(document).on('click', '#xyz-start-sync', function(e) {
471 + e.preventDefault();
472 + let btn = jQuery(this);
473 + let progress = jQuery('#sync-progress');
474 + btn.prop('disabled', true).text('Syncing...');
475 + // Read initial offset from button data attribute
476 + let initialOffset = parseInt(btn.data('offset')) || 0;
477 + function runSyncBatch(offset) {
478 + jQuery.ajax({
479 + url: ajaxurl,
480 + type: 'POST',
481 + data: {
482 + action: 'xyz_ips_sync_usage',
483 + offset: offset
484 + },
485 + success: function(response) {
486 + if (response.success && response.data.status === 'processing') {
487 + progress.text('Processed ' + response.data.new_offset + ' posts...');
488 + // Update button data-offset to keep track
489 + btn.data('offset', response.data.new_offset);
490 + runSyncBatch(response.data.new_offset);
491 + } else {
492 + progress.text('✅ Sync Complete!');
493 + btn.prop('disabled', false).text('Sync Usage Now');
494 + btn.data('offset', 0); // reset offset
495 + location.reload();
496 + }
497 + },
498 + error: function() {
499 + progress.text('❌ Sync failed. Please try again.');
500 + btn.prop('disabled', false).text('Sync Usage Now');
501 + }
502 + });
503 + }
504 + runSyncBatch(initialOffset);
505 +});
506 +});
507 +const xyz_ips_copy_shortcode = (id) => {
201 508
509 + var span = document.getElementById("xyz_ips_shortcode_" + id);
510 + var tempTextarea = document.createElement("textarea");
511 + tempTextarea.value = span.textContent;
512 + document.body.appendChild(tempTextarea);
513 + tempTextarea.select();
514 + tempTextarea.setSelectionRange(0, 99999); // For mobile devices
515 + document.execCommand("copy");
516 + document.body.removeChild(tempTextarea);
517 +
518 +
519 + (typeof xyz_ips_notice === 'function')? xyz_ips_notice('Short code copied successfully',1):null;
520 +
521 +};
522 +
523 +
524 +const xyz_ips_notice = (msg = '', flag = 0) => {
525 +
526 +
527 +const noticeElement = jQuery('#xyz_ips_system_notice_area');
528 +if (noticeElement.length > 0)
529 +{
530 +
531 + jQuery('#system_notice_area_common_msg').text(msg);
532 + if (flag === 0) {
533 + if(noticeElement.hasClass('xyz_ips_system_notice_area_style1'))
534 + noticeElement.removeClass('xyz_ips_system_notice_area_style1')
535 + if(! noticeElement.hasClass('xyz_ips_system_notice_area_style0'))
536 + noticeElement.addClass('xyz_ips_system_notice_area_style0');
537 +
538 + } else {
539 + if(noticeElement.hasClass('xyz_ips_system_notice_area_style0'))
540 + noticeElement.removeClass('xyz_ips_system_notice_area_style0')
541 + if(! noticeElement.hasClass('xyz_ips_system_notice_area_style1'))
542 + noticeElement.addClass('xyz_ips_system_notice_area_style1');
543 +
544 + }
545 + noticeElement.animate({
546 + opacity: 'show',
547 + height: 'show'
548 + }, 500);
549 +
550 +}
551 +else{
552 +
553 +
554 +
555 + let noticeElementString =
556 + `<div class="xyz_ips_system_notice_area_style${flag}" id="xyz_ips_system_notice_area">
557 + <span id="system_notice_area_common_msg">${msg}.&nbsp;&nbsp;&nbsp;</span>
558 + <span id="xyz_ips_system_notice_area_dismiss">Dismiss</span>
559 + </div>`;
560 +
561 + let noticeElement = jQuery(noticeElementString);
562 + jQuery('body').append(noticeElement);
563 + noticeElement.animate({
564 + opacity: 'show',
565 + height: 'show'
566 + }, 500);
567 +
568 +
569 +
570 +
571 +
572 +}
573 +
574 +};
575 +
576 +function xyz_ips_execute_shortcode(id) {
577 +
578 +
579 +var nonce= '<?php echo wp_create_nonce('xyz_ips_execute_shortcode');?>';
580 +jQuery.ajax({
581 + url: ajaxurl,
582 + type: 'POST',
583 + dataType: 'json',
584 + data: {
585 + action: 'xyz_ips_execute_shortcode',
586 + _wpnonce: nonce,
587 + id: id
588 + },
589 + success: function(response) {
590 + if (response.status === 1) {
591 + xyz_ips_notice(response.message,1);
592 +
593 + } else {
594 + xyz_ips_notice(response.message,0);
595 + }
596 + },
597 + error: function(xhr, status, error) {
598 + xyz_ips_notice('An error occurred: ' + error, 0);
599 + }
600 +});
601 +}
602 +</script>