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 +432 -79 1.0trunk View file →
@@ -1,17 +1,106 @@
1 -<?php
2 -global $wpdb;
3 -$_GET = stripslashes_deep($_GET);
4 -$xyz_ihs_message = '';
5 -if(isset($_GET['xyz_ihs_msg'])){
6 - $xyz_ihs_message = $_GET['xyz_ihs_msg'];
7 -}
8 -if($xyz_ihs_message == 1){
1 +<?php
2 +if ( ! defined( 'ABSPATH' ) )
3 + exit;
4 +
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 + }
20 + $_GET = stripslashes_deep($_GET);
21 + $xyz_ihs_message = $search_name_db=$search_name='';
22 +
23 + if(isset($_GET['xyz_ihs_msg'])){
24 + $xyz_ihs_message = intval($_GET['xyz_ihs_msg']);
25 + }
26 + if($_POST)
27 + {
28 + if(isset($_POST['search']))
29 + {
30 + if(!isset($_REQUEST['_wpnonce'])||!wp_verify_nonce($_REQUEST['_wpnonce'],'snipp-manage_') ){
31 + wp_nonce_ays( 'snipp-manage_' );
32 + exit;
33 + }
34 + }
35 + // if(isset($_POST['textFieldButton2']))
36 + // {
37 + // if(!isset($_REQUEST['_wpnonce'])||!wp_verify_nonce($_REQUEST['_wpnonce'],'bulk_actions_ihs') ){
38 + // wp_nonce_ays( 'bulk_actions_ihs' );
39 + // exit;
40 + // }
41 + // }
42 + if (isset($_POST['apply_ihs_bulk_actions'])){
43 + if (isset($_POST['ihs_bulk_actions_snippet']))
44 + {
45 + if(!isset($_REQUEST['_wpnonce'])||!wp_verify_nonce($_REQUEST['_wpnonce'],'bulk_actions_ihs') )
46 + {
47 + wp_nonce_ays( 'bulk_actions_ihs' );
48 + exit;
49 + }
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']);
54 + $xyz_ihs_pageno = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
55 +
56 + if (empty($xyz_ihs_snippet_ids))
57 + {
58 + wp_safe_redirect(admin_url('admin.php?page=insert-html-snippet-manage&xyz_ihs_msg=8&pagenum='.$xyz_ihs_pageno));
59 + exit();
60 + }
61 + if ($ihs_bulk_actions_snippet==2)//bulk-delete
62 + {
63 + foreach ($xyz_ihs_snippet_ids as $snippet_id)
64 + {
65 + $wpdb->query($wpdb->prepare( 'DELETE FROM '.$wpdb->prefix.'xyz_ihs_short_code WHERE id=%d',$snippet_id)) ;
66 + }
67 + wp_safe_redirect(admin_url('admin.php?page=insert-html-snippet-manage&xyz_ihs_msg=3&pagenum='.$xyz_ihs_pageno));
68 + exit();
69 + }
70 + elseif ($ihs_bulk_actions_snippet==0)//bulk-Deactivate
71 + {
72 + foreach ($xyz_ihs_snippet_ids as $xyz_ihs_snippetId)
73 + $wpdb->update($wpdb->prefix.'xyz_ihs_short_code', array('status'=>2), array('id'=>$xyz_ihs_snippetId));
74 + wp_safe_redirect(admin_url('admin.php?page=insert-html-snippet-manage&xyz_ihs_msg=4&pagenum='.$xyz_ihs_pageno));
75 + exit();
76 + }
77 + elseif ($ihs_bulk_actions_snippet==1)//bulk-activate
78 + {
79 + foreach ($xyz_ihs_snippet_ids as $xyz_ihs_snippetId)
80 + $wpdb->update($wpdb->prefix.'xyz_ihs_short_code', array('status'=>1), array('id'=>$xyz_ihs_snippetId));
81 + wp_safe_redirect(admin_url('admin.php?page=insert-html-snippet-manage&xyz_ihs_msg=4&pagenum='.$xyz_ihs_pageno));
82 + exit();
83 + }
84 + elseif ($ihs_bulk_actions_snippet==-1)//no action selected
85 + {
86 + wp_safe_redirect(admin_url('admin.php?page=insert-html-snippet-manage&xyz_ihs_msg=7&pagenum='.$xyz_ihs_pageno));
87 + exit();
88 + }
89 + }
90 +
91 + }
9 92
10 - ?>
11 -<div class="system_notice_area_style1" id="system_notice_area">
12 -HTML Snippet successfully added.&nbsp;&nbsp;&nbsp;<span
13 -id="system_notice_area_dismiss">Dismiss</span>
93 +
94 + }
95 + if($xyz_ihs_message == 1){
96 + ?>
97 +<div class="xyz_ihs_system_notice_area_style1" id="xyz_ihs_system_notice_area">
98 +<span id="system_notice_area_common_msg">
99 +HTML Snippet successfully added.&nbsp;&nbsp;&nbsp;
100 +</span>
101 +<span
102 +id="xyz_ihs_system_notice_area_dismiss">Dismiss</span>
14 103 </div>
15 104 <?php
16 105
17 106 }
@@ -17,11 +106,13 @@
17 106 }
18 107 if($xyz_ihs_message == 2){
19 108
20 109 ?>
21 -<div class="system_notice_area_style0" id="system_notice_area">
22 -HTML Snippet not found.&nbsp;&nbsp;&nbsp;<span
23 -id="system_notice_area_dismiss">Dismiss</span>
110 +<div class="xyz_ihs_system_notice_area_style0" id="xyz_ihs_system_notice_area">
111 +<span id="system_notice_area_common_msg">HTML Snippet not found.&nbsp;&nbsp;&nbsp;
112 +</span>
113 +<span
114 +id="xyz_ihs_system_notice_area_dismiss">Dismiss</span>
24 115 </div>
25 116 <?php
26 117
27 118 }
@@ -27,11 +118,14 @@
27 118 }
28 119 if($xyz_ihs_message == 3){
29 120
30 121 ?>
31 -<div class="system_notice_area_style1" id="system_notice_area">
32 -HTML Snippet successfully deleted.&nbsp;&nbsp;&nbsp;<span
33 -id="system_notice_area_dismiss">Dismiss</span>
122 +<div class="xyz_ihs_system_notice_area_style1" id="xyz_ihs_system_notice_area">
123 +<span id="system_notice_area_common_msg">
124 +HTML Snippet successfully deleted.&nbsp;&nbsp;&nbsp;
125 +</span>
126 +<span
127 +id="xyz_ihs_system_notice_area_dismiss">Dismiss</span>
34 128 </div>
35 129 <?php
36 130
37 131 }
@@ -37,11 +131,14 @@
37 131 }
38 132 if($xyz_ihs_message == 4){
39 133
40 134 ?>
41 -<div class="system_notice_area_style1" id="system_notice_area">
42 -HTML Snippet status successfully changed.&nbsp;&nbsp;&nbsp;<span
43 -id="system_notice_area_dismiss">Dismiss</span>
135 +<div class="xyz_ihs_system_notice_area_style1" id="xyz_ihs_system_notice_area">
136 +<span id="system_notice_area_common_msg">
137 +HTML Snippet status successfully changed.&nbsp;&nbsp;&nbsp;
138 +</span>
139 +<span
140 +id="xyz_ihs_system_notice_area_dismiss">Dismiss</span>
44 141 </div>
45 142 <?php
46 143
47 144 }
@@ -47,44 +144,135 @@
47 144 }
48 145 if($xyz_ihs_message == 5){
49 146
50 147 ?>
51 -<div class="system_notice_area_style1" id="system_notice_area">
52 -HTML Snippet successfully updated.&nbsp;&nbsp;&nbsp;<span
53 -id="system_notice_area_dismiss">Dismiss</span>
148 +<div class="xyz_ihs_system_notice_area_style1" id="xyz_ihs_system_notice_area">
149 +<span id="system_notice_area_common_msg">
150 +HTML Snippet successfully updated.&nbsp;&nbsp;&nbsp;
151 +</span>
152 +<span
153 +id="xyz_ihs_system_notice_area_dismiss">Dismiss</span>
54 154 </div>
155 +<div class="notice notice-success is-dismissible">
156 + <p><strong>HTML Snippet successfully updated. &nbsp;&nbsp;&nbsp;</strong></p>
157 +</div>
55 158 <?php
56 -
57 159 }
160 +if($xyz_ihs_message == 7)
161 +{
58 162 ?>
59 -
60 -
163 + <div class="xyz_ihs_system_notice_area_style1" id="xyz_ihs_system_notice_area">
164 + <span id="system_notice_area_common_msg">
165 +Please select an action to apply.&nbsp;&nbsp;&nbsp;
166 +</span>
167 + <span id="xyz_ihs_system_notice_area_dismiss">Dismiss</span>
168 + </div>
169 +<?php
170 +}
171 +if($xyz_ihs_message == 8)
172 +{
173 + ?>
174 + <div class="xyz_ihs_system_notice_area_style1" id="xyz_ihs_system_notice_area">
175 +<span id="system_notice_area_common_msg">
176 +Please select at least one snippet to perform this action.&nbsp;&nbsp;&nbsp;
177 +</span
178 +<span id="xyz_ihs_system_notice_area_dismiss">Dismiss</span>
179 + </div>
180 +<?php
181 +}
182 +?>
61 183 <div >
62 184
63 185
64 186 <form method="post">
65 - <fieldset
66 - style="width: 99%; border: 1px solid #F7F7F7; padding: 10px 0px;">
67 - <legend>HTML Snippets</legend>
187 + <?php wp_nonce_field( 'bulk_actions_ihs');?>
188 + <fieldset
189 + style="width: 98.8%; border: 1px solid #4d3e3e2e; padding: 10px 0px;">
190 + <legend><h3>HTML Snippets</h3></legend>
68 191 <?php
69 192 global $wpdb;
70 193 $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
71 - $limit = 20;
194 + $limit = get_option('xyz_ihs_limit');
72 195 $offset = ( $pagenum - 1 ) * $limit;
196 + $field=get_option('xyz_ihs_sort_field_name');
197 + $order=get_option('xyz_ihs_sort_order');
198 + if(isset($_POST['snippet_name']))
199 + {
200 + $search_name=sanitize_text_field($_POST['snippet_name']);
201 + $search_name_db=esc_sql($search_name);
202 + }
203 +
204 + if(isset($_POST['insertionMethod']))
205 + {
206 + $insertionMethod =intval($_POST["insertionMethod"]);
207 + }
208 + else
209 + {
210 + $insertionMethod =0;
211 + }
212 + $strInsertionMethod='';
213 + if (intval($insertionMethod)>0)
214 + {
215 + $strInsertionMethod=" AND insertionMethod=$insertionMethod";
216 + }
217 +
218 +
219 + $entries = $wpdb->get_results( "SELECT * FROM ".$wpdb->prefix."xyz_ihs_short_code WHERE title like '%".$search_name_db."%'".$strInsertionMethod." ORDER BY $field $order LIMIT $offset,$limit" );
220 +
221 + ?>
73 222
74 223
75 - $entries = $wpdb->get_results( "SELECT * FROM ".$wpdb->prefix."xyz_ihs_short_code ORDER BY id DESC LIMIT $offset,$limit" );
224 +
225 + <input id="xyz_ihs_submit" style="cursor: pointer; margin-bottom:10px; margin-left:8px;" type="button" name="textFieldButton2" value="Add New HTML Snippet" onClick='document.location.href="<?php echo admin_url('admin.php?page=insert-html-snippet-manage&action=snippet-add');?>"'>
226 + <br>
76 227
77 - ?>
78 - <input class="button-primary" id="textFieldButton2"
79 - style="cursor: pointer; margin-bottom:10px;" type="button"
80 - name="textFieldButton2" value="Add New HTML Snippet"
81 - onClick='document.location.href="<?php echo admin_url('admin.php?page=insert-html-snippet-manage&action=snippet-add');?>"'>
228 +
229 +
230 +
231 +
232 +<span style="padding-left: 6px;color:#21759B;">With Selected : </span>
233 + <select name="ihs_bulk_actions_snippet" id="ihs_bulk_actions_snippet" style="width:130px;height:29px;">
234 + <option value="-1">Bulk Actions</option>
235 + <option value="0">Deactivate</option>
236 + <option value="1">Activate</option>
237 + <option value="2">Delete</option>
238 +</select>
239 +<input type="submit" title="Apply" name="apply_ihs_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;">
240 +
241 +</form>
242 +<form name="manage_snippets" action="" method="post">
243 + <?php wp_nonce_field('snipp-manage_');?>
244 + <div class="xyz_ihs_search_div" style="float:right;margin:5px;">
245 + <table class="xyz_ihs_search_div_table" style="width:100%;">
246 + <tr>
247 +
248 + <div><span>Snippet Placement</span>&nbsp;</div>
249 + <div>
250 + <select name="insertionMethod" id="insertionMethod" >
251 + <option value="0" <?php if($insertionMethod==0) { echo "selected"; } ?>>All</option>
252 + <option value="1" <?php if($insertionMethod==1) { echo "selected"; } ?>>Automatic</option>
253 + <option value="2" <?php if($insertionMethod==2) { echo "selected"; } ?>>Short Code</option>
254 +
255 + </select>
256 + </div>
257 +
258 + <div> <input type="text" name="snippet_name" value= "<?php if(isset($search_name)){echo esc_attr($search_name);}?>" placeholder="Search" ></div>
259 + <div><input style="padding:5px;margin-left: 5px;margin-right: 5px;" type="submit" name="search" value="Go" /></div>
260 +
261 + </tr>
262 + </table>
263 + </div>
264 +</form>
265 +
266 +
82 267 <table class="widefat" style="width: 99%; margin: 0 auto; border-bottom:none;">
83 268 <thead>
84 269 <tr>
270 + <th scope="col" width="3%"><input type="checkbox" id="chkAllSnippets" /></th>
85 271 <th scope="col" >Tracking Name</th>
86 - <th scope="col" >Snippet Short Code</th>
272 + <th scope="col">Snippet Placement</th>
273 + <th scope="col">Placement Details</th>
274 +
87 275 <th scope="col" >Status</th>
88 276 <th scope="col" colspan="3" style="text-align: center;">Action</th>
89 277 </tr>
90 278 </thead>
@@ -89,24 +277,83 @@
89 277 </tr>
90 278 </thead>
91 279 <tbody>
92 280 <?php
93 - if( count($entries)>0 ) {
281 +
282 + if(!empty($entries))//if( count($entries)>0 )
283 + {
94 284 $count=1;
95 285 $class = '';
96 286 foreach( $entries as $entry ) {
97 287 $class = ( $count % 2 == 0 ) ? ' class="alternate"' : '';
288 + $snippetId=intval($entry->id);
98 289 ?>
99 290 <tr <?php echo $class; ?>>
100 - <td><?php
101 - echo esc_html($entry->title);
102 - ?></td>
103 - <td><?php
104 - if($entry->status == 2){echo 'NA';}
105 - else
106 - echo '[xyz-ihs snippet="'.esc_html($entry->title).'"]';
107 - ?></td>
108 - <td>
291 + <td style="vertical-align: middle !important;padding-left: 18px;">
292 + <input type="checkbox" class="chk" value="<?php echo $snippetId; ?>" name="xyz_ihs_snippet_ids[]" id="xyz_ihs_snippet_ids" />
293 + </td>
294 + <td id="xyz_ihs_vAlign" title="<?php echo esc_attr($entry->description); ?>" ><?php
295 + echo esc_html($entry->title); ?></td>
296 +<td id="xyz_ihs_vAlign">
297 + <?php
298 +$placement_text = '';
299 + if ($entry->status == 2) {
300 +
301 + $placement_text = 'NA';
302 + } else {
303 + /* AUTOMATIC PLACEMENT */
304 + if ($entry->insertionMethod == 1) {
305 +
306 + $placement_text =
307 + '<span class="ihs-badge ihs-badge-auto">Automatic</span>';
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 + }
353 + ?>
354 +</td>
355 + <td id="xyz_ihs_vAlign">
109 356 <?php
110 357 if($entry->status == 2){
111 358 echo "Inactive";
112 359 }elseif ($entry->status == 1){
@@ -116,40 +363,44 @@
116 363 ?>
117 364 </td>
118 365 <?php
119 366 if($entry->status == 2){
367 + $stat1 = admin_url('admin.php?page=insert-html-snippet-manage&action=snippet-status&snippetId='.$snippetId.'&status=1&pageno='.$pagenum);
120 368 ?>
121 369 <td style="text-align: center;"><a
122 - href='<?php echo admin_url('admin.php?page=insert-html-snippet-manage&action=snippet-status&snippetId='.$entry->id.'&status=1&pageno='.$pagenum); ?>'><img
123 - id="img" title="Activate"
124 - src="<?php echo plugins_url('insert-html-snippet/images/activate.png')?>">
370 + href='<?php echo wp_nonce_url($stat1,'ihs-stat_'.$snippetId); ?>'><img
371 + id="xyz_ihs_img" title="Activate"
372 + src="<?php echo plugins_url('images/activate.png', XYZ_INSERT_HTML_PLUGIN_FILE )?>">
125 373 </a>
126 374 </td>
127 375 <?php
128 376 }elseif ($entry->status == 1){
377 + $stat2 = admin_url('admin.php?page=insert-html-snippet-manage&action=snippet-status&snippetId='.$snippetId.'&status=2&pageno='.$pagenum);
129 378 ?>
130 379 <td style="text-align: center;"><a
131 - href='<?php echo admin_url('admin.php?page=insert-html-snippet-manage&action=snippet-status&snippetId='.$entry->id.'&status=2&pageno='.$pagenum); ?>'><img
132 - id="img" title="Deactivate"
133 - src="<?php echo plugins_url('insert-html-snippet/images/pause.png')?>">
380 + href='<?php echo wp_nonce_url($stat2,'ihs-stat_'.$snippetId); ?>'><img
381 + id="xyz_ihs_img" title="Deactivate"
382 + src="<?php echo plugins_url('images/pause.png',XYZ_INSERT_HTML_PLUGIN_FILE)?>">
134 383 </a>
135 384 </td>
136 385 <?php
137 386 }
138 -
387 +
139 388 ?>
140 389
141 390 <td style="text-align: center;"><a
142 - href='<?php echo admin_url('admin.php?page=insert-html-snippet-manage&action=snippet-edit&snippetId='.$entry->id.'&pageno='.$pagenum); ?>'><img
143 - id="img" title="Edit Snippet"
144 - src="<?php echo plugins_url('insert-html-snippet/images/edit.png')?>">
391 + href='<?php echo admin_url('admin.php?page=insert-html-snippet-manage&action=snippet-edit&snippetId='.$snippetId.'&pageno='.$pagenum); ?>'><img
392 + id="xyz_ihs_img" title="Edit Snippet"
393 + src="<?php echo plugins_url('images/edit.png',XYZ_INSERT_HTML_PLUGIN_FILE)?>">
145 394 </a>
146 395 </td>
396 +
397 + <?php $delurl = admin_url('admin.php?page=insert-html-snippet-manage&action=snippet-delete&snippetId='.$snippetId.'&pageno='.$pagenum);?>
147 398 <td style="text-align: center;" ><a
148 - href='<?php echo admin_url('admin.php?page=insert-html-snippet-manage&action=snippet-delete&snippetId='.$entry->id.'&pageno='.$pagenum); ?>'
399 + href='<?php echo wp_nonce_url($delurl,'ihs-del_'.$snippetId); ?>'
149 400 onclick="javascript: return confirm('Please click \'OK\' to confirm ');"><img
150 - id="img" title="Delete Snippet"
151 - src="<?php echo plugins_url('insert-html-snippet/images/delete.png')?>">
401 + id="xyz_ihs_img" title="Delete Snippet"
402 + src="<?php echo plugins_url('images/delete.png',XYZ_INSERT_HTML_PLUGIN_FILE)?>">
152 403 </a></td>
153 404 </tr>
154 405 <?php
155 406 $count++;
@@ -161,39 +412,141 @@
161 412 <?php } ?>
162 413 </tbody>
163 414 </table>
164 415
165 - <input class="button-primary" id="textFieldButton2"
166 - style="cursor: pointer; margin-top:10px;" type="button"
167 - name="textFieldButton2" value="Add New HTML Snippet"
168 - onClick='document.location.href="<?php echo admin_url('admin.php?page=insert-html-snippet-manage&action=snippet-add');?>"'>
416 + <input id="xyz_ihs_submit" style="cursor: pointer; margin-top:10px;margin-left:8px;" type="button" name="textFieldButton2" value="Add New HTML Snippet" onClick='document.location.href="<?php echo admin_url('admin.php?page=insert-html-snippet-manage&action=snippet-add');?>"'>
169 417
170 - <?
171 -
172 -
173 -
418 + <?php
174 419 $total = $wpdb->get_var( "SELECT COUNT(`id`) FROM ".$wpdb->prefix."xyz_ihs_short_code" );
175 420 $num_of_pages = ceil( $total / $limit );
176 421
177 422 $page_links = paginate_links( array(
178 423 'base' => add_query_arg( 'pagenum','%#%'),
179 - 'format' => '',
180 - 'prev_text' => '&laquo;',
181 - 'next_text' => '&raquo;',
182 - 'total' => $num_of_pages,
183 - 'current' => $pagenum
424 + 'format' => '',
425 + 'prev_text' => '&laquo;',
426 + 'next_text' => '&raquo;',
427 + 'total' => $num_of_pages,
428 + 'current' => $pagenum
184 429 ) );
185 430
186 -
187 -
188 431 if ( $page_links ) {
189 432 echo '<div class="tablenav" style="width:99%"><div class="tablenav-pages" style="margin: 1em 0">' . $page_links . '</div></div>';
190 433 }
191 434
192 435 ?>
436 + </fieldset>
437 +
438 +</div>
439 +<script type="text/javascript">
440 +jQuery(document).ready(function(){
441 + jQuery("#chkAllSnippets").click(function(){
442 + jQuery(".chk").prop("checked",jQuery("#chkAllSnippets").prop("checked"));
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);
480 +});
481 +});
482 +const xyz_ihs_copy_shortcode = (id) => {
193 483
194 - </fieldset>
484 + var span = document.getElementById("xyz_ihs_shortcode_" + id);
485 + var tempTextarea = document.createElement("textarea");
486 + tempTextarea.value = span.textContent;
487 + document.body.appendChild(tempTextarea);
488 + tempTextarea.select();
489 + tempTextarea.setSelectionRange(0, 99999); // For mobile devices
490 + document.execCommand("copy");
491 + document.body.removeChild(tempTextarea);
195 492
196 - </form>
197 493
198 -</div>
494 + (typeof xyz_ihs_notice === 'function')? xyz_ihs_notice('Short code copied successfully',1):null;
199 495
496 +};
497 +
498 +
499 +const xyz_ihs_notice = (msg = '', flag = 0) => {
500 +
501 +
502 +const noticeElement = jQuery('#xyz_ihs_system_notice_area');
503 +if (noticeElement.length > 0)
504 +{
505 +
506 + jQuery('#system_notice_area_common_msg').text(msg);
507 + if (flag === 0) {
508 + if(noticeElement.hasClass('xyz_ihs_system_notice_area_style1'))
509 + noticeElement.removeClass('xyz_ihs_system_notice_area_style1')
510 + if(! noticeElement.hasClass('xyz_ihs_system_notice_area_style0'))
511 + noticeElement.addClass('xyz_ihs_system_notice_area_style0');
512 +
513 + } else {
514 + if(noticeElement.hasClass('xyz_ihs_system_notice_area_style0'))
515 + noticeElement.removeClass('xyz_ihs_system_notice_area_style0')
516 + if(! noticeElement.hasClass('xyz_ihs_system_notice_area_style1'))
517 + noticeElement.addClass('xyz_ihs_system_notice_area_style1');
518 +
519 + }
520 + noticeElement.animate({
521 + opacity: 'show',
522 + height: 'show'
523 + }, 500);
524 +
525 +}
526 +else{
527 +
528 +
529 +
530 + let noticeElementString =
531 +`<div class="xyz_ihs_system_notice_area_style${flag}" id="xyz_ihs_system_notice_area">
532 + <span id="system_notice_area_common_msg">${msg}.&nbsp;&nbsp;&nbsp;</span>
533 + <span id="xyz_ihs_system_notice_area_dismiss">Dismiss</span>
534 + </div>`;
535 +
536 + let noticeElement = jQuery(noticeElementString);
537 + jQuery('body').append(noticeElement);
538 + noticeElement.animate({
539 + opacity: 'show',
540 + height: 'show'
541 + }, 500);
542 +
543 +
544 +
545 +
546 +
547 +}
548 +
549 +};
550 +
551 +
552 +</script>