| 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 |
} |
| 92 |
|
| 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. |
| 100 |
</span> |
| 101 |
<span |
| 102 |
id="xyz_ihs_system_notice_area_dismiss">Dismiss</span> |
| 103 |
</div> |
| 104 |
<?php |
| 105 |
|
| 106 |
} |
| 107 |
if($xyz_ihs_message == 2){ |
| 108 |
|
| 109 |
?> |
| 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. |
| 112 |
</span> |
| 113 |
<span |
| 114 |
id="xyz_ihs_system_notice_area_dismiss">Dismiss</span> |
| 115 |
</div> |
| 116 |
<?php |
| 117 |
|
| 118 |
} |
| 119 |
if($xyz_ihs_message == 3){ |
| 120 |
|
| 121 |
?> |
| 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. |
| 125 |
</span> |
| 126 |
<span |
| 127 |
id="xyz_ihs_system_notice_area_dismiss">Dismiss</span> |
| 128 |
</div> |
| 129 |
<?php |
| 130 |
|
| 131 |
} |
| 132 |
if($xyz_ihs_message == 4){ |
| 133 |
|
| 134 |
?> |
| 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. |
| 138 |
</span> |
| 139 |
<span |
| 140 |
id="xyz_ihs_system_notice_area_dismiss">Dismiss</span> |
| 141 |
</div> |
| 142 |
<?php |
| 143 |
|
| 144 |
} |
| 145 |
if($xyz_ihs_message == 5){ |
| 146 |
|
| 147 |
?> |
| 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. |
| 151 |
</span> |
| 152 |
<span |
| 153 |
id="xyz_ihs_system_notice_area_dismiss">Dismiss</span> |
| 154 |
</div> |
| 155 |
<div class="notice notice-success is-dismissible"> |
| 156 |
<p><strong>HTML Snippet successfully updated. </strong></p> |
| 157 |
</div> |
| 158 |
<?php |
| 159 |
} |
| 160 |
if($xyz_ihs_message == 7) |
| 161 |
{ |
| 162 |
?> |
| 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. |
| 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. |
| 177 |
</span |
| 178 |
<span id="xyz_ihs_system_notice_area_dismiss">Dismiss</span> |
| 179 |
</div> |
| 180 |
<?php |
| 181 |
} |
| 182 |
?> |
| 183 |
<div > |
| 184 |
|
| 185 |
|
| 186 |
<form method="post"> |
| 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> |
| 191 |
<?php |
| 192 |
global $wpdb; |
| 193 |
$pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1; |
| 194 |
$limit = get_option('xyz_ihs_limit'); |
| 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 |
?> |
| 222 |
|
| 223 |
|
| 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> |
| 227 |
|
| 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> </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 |
|
| 267 |
<table class="widefat" style="width: 99%; margin: 0 auto; border-bottom:none;"> |
| 268 |
<thead> |
| 269 |
<tr> |
| 270 |
<th scope="col" width="3%"><input type="checkbox" id="chkAllSnippets" /></th> |
| 271 |
<th scope="col" >Tracking Name</th> |
| 272 |
<th scope="col">Snippet Placement</th> |
| 273 |
<th scope="col">Placement Details</th> |
| 274 |
|
| 275 |
<th scope="col" >Status</th> |
| 276 |
<th scope="col" colspan="3" style="text-align: center;">Action</th> |
| 277 |
</tr> |
| 278 |
</thead> |
| 279 |
<tbody> |
| 280 |
<?php |
| 281 |
|
| 282 |
if(!empty($entries))//if( count($entries)>0 ) |
| 283 |
{ |
| 284 |
$count=1; |
| 285 |
$class = ''; |
| 286 |
foreach( $entries as $entry ) { |
| 287 |
$class = ( $count % 2 == 0 ) ? ' class="alternate"' : ''; |
| 288 |
$snippetId=intval($entry->id); |
| 289 |
?> |
| 290 |
<tr <?php echo $class; ?>> |
| 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 "Show Snippet Usage Details" in settings." style="cursor: help;">Hidden</span>'; else |
| 350 |
echo 'Not used'; |
| 351 |
} |
| 352 |
} |
| 353 |
?> |
| 354 |
</td> |
| 355 |
<td id="xyz_ihs_vAlign"> |
| 356 |
<?php |
| 357 |
if($entry->status == 2){ |
| 358 |
echo "Inactive"; |
| 359 |
}elseif ($entry->status == 1){ |
| 360 |
echo "Active"; |
| 361 |
} |
| 362 |
|
| 363 |
?> |
| 364 |
</td> |
| 365 |
<?php |
| 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); |
| 368 |
?> |
| 369 |
<td style="text-align: center;"><a |
| 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 )?>"> |
| 373 |
</a> |
| 374 |
</td> |
| 375 |
<?php |
| 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); |
| 378 |
?> |
| 379 |
<td style="text-align: center;"><a |
| 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)?>"> |
| 383 |
</a> |
| 384 |
</td> |
| 385 |
<?php |
| 386 |
} |
| 387 |
|
| 388 |
?> |
| 389 |
|
| 390 |
<td style="text-align: center;"><a |
| 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)?>"> |
| 394 |
</a> |
| 395 |
</td> |
| 396 |
|
| 397 |
<?php $delurl = admin_url('admin.php?page=insert-html-snippet-manage&action=snippet-delete&snippetId='.$snippetId.'&pageno='.$pagenum);?> |
| 398 |
<td style="text-align: center;" ><a |
| 399 |
href='<?php echo wp_nonce_url($delurl,'ihs-del_'.$snippetId); ?>' |
| 400 |
onclick="javascript: return confirm('Please click \'OK\' to confirm ');"><img |
| 401 |
id="xyz_ihs_img" title="Delete Snippet" |
| 402 |
src="<?php echo plugins_url('images/delete.png',XYZ_INSERT_HTML_PLUGIN_FILE)?>"> |
| 403 |
</a></td> |
| 404 |
</tr> |
| 405 |
<?php |
| 406 |
$count++; |
| 407 |
} |
| 408 |
} else { ?> |
| 409 |
<tr> |
| 410 |
<td colspan="6" >HTML Snippets not found</td> |
| 411 |
</tr> |
| 412 |
<?php } ?> |
| 413 |
</tbody> |
| 414 |
</table> |
| 415 |
|
| 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');?>"'> |
| 417 |
|
| 418 |
<?php |
| 419 |
$total = $wpdb->get_var( "SELECT COUNT(`id`) FROM ".$wpdb->prefix."xyz_ihs_short_code" ); |
| 420 |
$num_of_pages = ceil( $total / $limit ); |
| 421 |
|
| 422 |
$page_links = paginate_links( array( |
| 423 |
'base' => add_query_arg( 'pagenum','%#%'), |
| 424 |
'format' => '', |
| 425 |
'prev_text' => '«', |
| 426 |
'next_text' => '»', |
| 427 |
'total' => $num_of_pages, |
| 428 |
'current' => $pagenum |
| 429 |
) ); |
| 430 |
|
| 431 |
if ( $page_links ) { |
| 432 |
echo '<div class="tablenav" style="width:99%"><div class="tablenav-pages" style="margin: 1em 0">' . $page_links . '</div></div>'; |
| 433 |
} |
| 434 |
|
| 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('� |
| 468 |
Sync Complete!'); |
| 469 |
btn.prop('disabled', false).text('Sync Usage Now'); |
| 470 |
btn.data('offset', 0); // reset offset |
| 471 |
location.reload(); |
| 472 |
} |
| 473 |
}, |
| 474 |
error: function() { |
| 475 |
progress.text('❌ Sync failed. Please try again.'); |
| 476 |
btn.prop('disabled', false).text('Sync Usage Now'); |
| 477 |
} |
| 478 |
}); |
| 479 |
} |
| 480 |
runSyncBatch(initialOffset); |
| 481 |
}); |
| 482 |
}); |
| 483 |
const xyz_ihs_copy_shortcode = (id) => { |
| 484 |
|
| 485 |
var span = document.getElementById("xyz_ihs_shortcode_" + id); |
| 486 |
var tempTextarea = document.createElement("textarea"); |
| 487 |
tempTextarea.value = span.textContent; |
| 488 |
document.body.appendChild(tempTextarea); |
| 489 |
tempTextarea.select(); |
| 490 |
tempTextarea.setSelectionRange(0, 99999); // For mobile devices |
| 491 |
document.execCommand("copy"); |
| 492 |
document.body.removeChild(tempTextarea); |
| 493 |
|
| 494 |
|
| 495 |
(typeof xyz_ihs_notice === 'function')? xyz_ihs_notice('Short code copied successfully',1):null; |
| 496 |
|
| 497 |
}; |
| 498 |
|
| 499 |
|
| 500 |
const xyz_ihs_notice = (msg = '', flag = 0) => { |
| 501 |
|
| 502 |
|
| 503 |
const noticeElement = jQuery('#xyz_ihs_system_notice_area'); |
| 504 |
if (noticeElement.length > 0) |
| 505 |
{ |
| 506 |
|
| 507 |
jQuery('#system_notice_area_common_msg').text(msg); |
| 508 |
if (flag === 0) { |
| 509 |
if(noticeElement.hasClass('xyz_ihs_system_notice_area_style1')) |
| 510 |
noticeElement.removeClass('xyz_ihs_system_notice_area_style1') |
| 511 |
if(! noticeElement.hasClass('xyz_ihs_system_notice_area_style0')) |
| 512 |
noticeElement.addClass('xyz_ihs_system_notice_area_style0'); |
| 513 |
|
| 514 |
} else { |
| 515 |
if(noticeElement.hasClass('xyz_ihs_system_notice_area_style0')) |
| 516 |
noticeElement.removeClass('xyz_ihs_system_notice_area_style0') |
| 517 |
if(! noticeElement.hasClass('xyz_ihs_system_notice_area_style1')) |
| 518 |
noticeElement.addClass('xyz_ihs_system_notice_area_style1'); |
| 519 |
|
| 520 |
} |
| 521 |
noticeElement.animate({ |
| 522 |
opacity: 'show', |
| 523 |
height: 'show' |
| 524 |
}, 500); |
| 525 |
|
| 526 |
} |
| 527 |
else{ |
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
let noticeElementString = |
| 532 |
`<div class="xyz_ihs_system_notice_area_style${flag}" id="xyz_ihs_system_notice_area"> |
| 533 |
<span id="system_notice_area_common_msg">${msg}. </span> |
| 534 |
<span id="xyz_ihs_system_notice_area_dismiss">Dismiss</span> |
| 535 |
</div>`; |
| 536 |
|
| 537 |
let noticeElement = jQuery(noticeElementString); |
| 538 |
jQuery('body').append(noticeElement); |
| 539 |
noticeElement.animate({ |
| 540 |
opacity: 'show', |
| 541 |
height: 'show' |
| 542 |
}, 500); |
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
} |
| 549 |
|
| 550 |
}; |
| 551 |
|
| 552 |
|
| 553 |
</script> |
| 554 |
|