| @@ -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'])){ |
| @@ -17,25 +31,32 @@ | ||
| 17 | 31 | wp_nonce_ays( 'snipp-manage_' ); |
| 18 | 32 | exit; |
| 19 | 33 | } |
| 20 | 34 | } |
| 21 | - if(isset($_POST['textFieldButton2'])) | |
| 22 | - { | |
| 23 | - if(!isset($_REQUEST['_wpnonce'])||!wp_verify_nonce($_REQUEST['_wpnonce'],'bulk_actions_ihs') ){ | |
| 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 | + { | |
| 24 | 47 | wp_nonce_ays( 'bulk_actions_ihs' ); |
| 25 | 48 | exit; |
| 26 | 49 | } |
| 27 | - } | |
| 28 | - if (isset($_POST['apply_ihs_bulk_actions'])){ | |
| 29 | - if (isset($_POST['ihs_bulk_actions_snippet'])){ | |
| 30 | - $ihs_bulk_actions_snippet=$_POST['ihs_bulk_actions_snippet']; | |
| 31 | - if (isset($_POST['xyz_ihs_snippet_ids'])) | |
| 32 | - $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']); | |
| 33 | 54 | $xyz_ihs_pageno = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1; |
| 34 | 55 | |
| 35 | 56 | if (empty($xyz_ihs_snippet_ids)) |
| 36 | 57 | { |
| 37 | - 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)); | |
| 38 | 59 | exit(); |
| 39 | 60 | } |
| 40 | 61 | if ($ihs_bulk_actions_snippet==2)//bulk-delete |
| 41 | 62 | { |
| @@ -42,9 +63,9 @@ | ||
| 42 | 63 | foreach ($xyz_ihs_snippet_ids as $snippet_id) |
| 43 | 64 | { |
| 44 | 65 | $wpdb->query($wpdb->prepare( 'DELETE FROM '.$wpdb->prefix.'xyz_ihs_short_code WHERE id=%d',$snippet_id)) ; |
| 45 | 66 | } |
| 46 | - 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)); | |
| 47 | 68 | exit(); |
| 48 | 69 | } |
| 49 | 70 | elseif ($ihs_bulk_actions_snippet==0)//bulk-Deactivate |
| 50 | 71 | { |
| @@ -49,9 +70,9 @@ | ||
| 49 | 70 | elseif ($ihs_bulk_actions_snippet==0)//bulk-Deactivate |
| 50 | 71 | { |
| 51 | 72 | foreach ($xyz_ihs_snippet_ids as $xyz_ihs_snippetId) |
| 52 | 73 | $wpdb->update($wpdb->prefix.'xyz_ihs_short_code', array('status'=>2), array('id'=>$xyz_ihs_snippetId)); |
| 53 | - 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)); | |
| 54 | 75 | exit(); |
| 55 | 76 | } |
| 56 | 77 | elseif ($ihs_bulk_actions_snippet==1)//bulk-activate |
| 57 | 78 | { |
| @@ -56,14 +77,14 @@ | ||
| 56 | 77 | elseif ($ihs_bulk_actions_snippet==1)//bulk-activate |
| 57 | 78 | { |
| 58 | 79 | foreach ($xyz_ihs_snippet_ids as $xyz_ihs_snippetId) |
| 59 | 80 | $wpdb->update($wpdb->prefix.'xyz_ihs_short_code', array('status'=>1), array('id'=>$xyz_ihs_snippetId)); |
| 60 | - 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)); | |
| 61 | 82 | exit(); |
| 62 | 83 | } |
| 63 | 84 | elseif ($ihs_bulk_actions_snippet==-1)//no action selected |
| 64 | 85 | { |
| 65 | - 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)); | |
| 66 | 87 | exit(); |
| 67 | 88 | } |
| 68 | 89 | } |
| 69 | 90 | |
| @@ -69,22 +90,17 @@ | ||
| 69 | 90 | |
| 70 | 91 | } |
| 71 | 92 | |
| 72 | 93 | |
| 73 | - | |
| 74 | - | |
| 75 | - | |
| 76 | - | |
| 77 | - | |
| 78 | - | |
| 79 | - | |
| 80 | - | |
| 81 | 94 | } |
| 82 | 95 | if($xyz_ihs_message == 1){ |
| 83 | 96 | ?> |
| 84 | -<div class="xyz_system_notice_area_style1" id="xyz_system_notice_area"> | |
| 85 | -HTML Snippet successfully added. <span | |
| 86 | -id="xyz_system_notice_area_dismiss">Dismiss</span> | |
| 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> | |
| 87 | 103 | </div> |
| 88 | 104 | <?php |
| 89 | 105 | |
| 90 | 106 | } |
| @@ -90,11 +106,13 @@ | ||
| 90 | 106 | } |
| 91 | 107 | if($xyz_ihs_message == 2){ |
| 92 | 108 | |
| 93 | 109 | ?> |
| 94 | -<div class="xyz_system_notice_area_style0" id="xyz_system_notice_area"> | |
| 95 | -HTML Snippet not found. <span | |
| 96 | -id="xyz_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. | |
| 112 | +</span> | |
| 113 | +<span | |
| 114 | +id="xyz_ihs_system_notice_area_dismiss">Dismiss</span> | |
| 97 | 115 | </div> |
| 98 | 116 | <?php |
| 99 | 117 | |
| 100 | 118 | } |
| @@ -100,11 +118,14 @@ | ||
| 100 | 118 | } |
| 101 | 119 | if($xyz_ihs_message == 3){ |
| 102 | 120 | |
| 103 | 121 | ?> |
| 104 | -<div class="xyz_system_notice_area_style1" id="xyz_system_notice_area"> | |
| 105 | -HTML Snippet successfully deleted. <span | |
| 106 | -id="xyz_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. | |
| 125 | +</span> | |
| 126 | +<span | |
| 127 | +id="xyz_ihs_system_notice_area_dismiss">Dismiss</span> | |
| 107 | 128 | </div> |
| 108 | 129 | <?php |
| 109 | 130 | |
| 110 | 131 | } |
| @@ -110,11 +131,14 @@ | ||
| 110 | 131 | } |
| 111 | 132 | if($xyz_ihs_message == 4){ |
| 112 | 133 | |
| 113 | 134 | ?> |
| 114 | -<div class="xyz_system_notice_area_style1" id="xyz_system_notice_area"> | |
| 115 | -HTML Snippet status successfully changed. <span | |
| 116 | -id="xyz_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. | |
| 138 | +</span> | |
| 139 | +<span | |
| 140 | +id="xyz_ihs_system_notice_area_dismiss">Dismiss</span> | |
| 117 | 141 | </div> |
| 118 | 142 | <?php |
| 119 | 143 | |
| 120 | 144 | } |
| @@ -120,20 +144,28 @@ | ||
| 120 | 144 | } |
| 121 | 145 | if($xyz_ihs_message == 5){ |
| 122 | 146 | |
| 123 | 147 | ?> |
| 124 | -<div class="xyz_system_notice_area_style1" id="xyz_system_notice_area"> | |
| 125 | -HTML Snippet successfully updated. <span | |
| 126 | -id="xyz_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. | |
| 151 | +</span> | |
| 152 | +<span | |
| 153 | +id="xyz_ihs_system_notice_area_dismiss">Dismiss</span> | |
| 127 | 154 | </div> |
| 155 | +<div class="notice notice-success is-dismissible"> | |
| 156 | + <p><strong>HTML Snippet successfully updated. </strong></p> | |
| 157 | +</div> | |
| 128 | 158 | <?php |
| 129 | 159 | } |
| 130 | 160 | if($xyz_ihs_message == 7) |
| 131 | 161 | { |
| 132 | 162 | ?> |
| 133 | - <div class="xyz_system_notice_area_style1" id="xyz_system_notice_area"> | |
| 134 | - Please select an action to apply. | |
| 135 | - <span id="xyz_system_notice_area_dismiss">Dismiss</span> | |
| 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> | |
| 136 | 168 | </div> |
| 137 | 169 | <?php |
| 138 | 170 | } |
| 139 | 171 | if($xyz_ihs_message == 8) |
| @@ -138,11 +170,13 @@ | ||
| 138 | 170 | } |
| 139 | 171 | if($xyz_ihs_message == 8) |
| 140 | 172 | { |
| 141 | 173 | ?> |
| 142 | - <div class="xyz_system_notice_area_style1" id="xyz_system_notice_area"> | |
| 143 | - Please select at least one snippet to perform this action. | |
| 144 | - <span id="xyz_system_notice_area_dismiss">Dismiss</span> | |
| 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> | |
| 145 | 179 | </div> |
| 146 | 180 | <?php |
| 147 | 181 | } |
| 148 | 182 | ?> |
| @@ -151,9 +185,9 @@ | ||
| 151 | 185 | |
| 152 | 186 | <form method="post"> |
| 153 | 187 | <?php wp_nonce_field( 'bulk_actions_ihs');?> |
| 154 | 188 | <fieldset |
| 155 | - style="width: 99%; border: 1px solid #F7F7F7; padding: 10px 0px;"> | |
| 189 | + style="width: 98.8%; border: 1px solid #4d3e3e2e; padding: 10px 0px;"> | |
| 156 | 190 | <legend><h3>HTML Snippets</h3></legend> |
| 157 | 191 | <?php |
| 158 | 192 | global $wpdb; |
| 159 | 193 | $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1; |
| @@ -166,10 +200,25 @@ | ||
| 166 | 200 | $search_name=sanitize_text_field($_POST['snippet_name']); |
| 167 | 201 | $search_name_db=esc_sql($search_name); |
| 168 | 202 | } |
| 169 | 203 | |
| 170 | - $entries = $wpdb->get_results( "SELECT * FROM ".$wpdb->prefix."xyz_ihs_short_code WHERE title like '%".$search_name_db."%'"." ORDER BY $field $order LIMIT $offset,$limit" ); | |
| 171 | - | |
| 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 | + | |
| 172 | 221 | ?> |
| 173 | 222 | |
| 174 | 223 | |
| 175 | 224 | |
| @@ -188,18 +237,27 @@ | ||
| 188 | 237 | <option value="2">Delete</option> |
| 189 | 238 | </select> |
| 190 | 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;"> |
| 191 | 240 | |
| 192 | - | |
| 241 | +</form> | |
| 193 | 242 | <form name="manage_snippets" action="" method="post"> |
| 194 | - <?php wp_nonce_field('snipp-manage_');?> | |
| 195 | - <div class="xyz_ics_search_div" style="float:right;"> | |
| 196 | - <table class="xyz_ics_search_div_table" style="width:100%;"> | |
| 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%;"> | |
| 197 | 246 | <tr> |
| 198 | 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> | |
| 199 | 257 | |
| 200 | - <input type="text" name="snippet_name" value= "<?php if(isset($search_name)){echo esc_attr($search_name);}?>" placeholder="Search" > | |
| 201 | - <input type="submit" name="search" value="Go" /> | |
| 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> | |
| 202 | 260 | |
| 203 | 261 | </tr> |
| 204 | 262 | </table> |
| 205 | 263 | </div> |
| @@ -210,9 +268,11 @@ | ||
| 210 | 268 | <thead> |
| 211 | 269 | <tr> |
| 212 | 270 | <th scope="col" width="3%"><input type="checkbox" id="chkAllSnippets" /></th> |
| 213 | 271 | <th scope="col" >Tracking Name</th> |
| 214 | - <th scope="col" >Snippet Short Code</th> | |
| 272 | + <th scope="col">Snippet Placement</th> | |
| 273 | + <th scope="col">Placement Details</th> | |
| 274 | + | |
| 215 | 275 | <th scope="col" >Status</th> |
| 216 | 276 | <th scope="col" colspan="3" style="text-align: center;">Action</th> |
| 217 | 277 | </tr> |
| 218 | 278 | </thead> |
| @@ -217,9 +277,11 @@ | ||
| 217 | 277 | </tr> |
| 218 | 278 | </thead> |
| 219 | 279 | <tbody> |
| 220 | 280 | <?php |
| 221 | - if( count($entries)>0 ) { | |
| 281 | + | |
| 282 | + if(!empty($entries))//if( count($entries)>0 ) | |
| 283 | + { | |
| 222 | 284 | $count=1; |
| 223 | 285 | $class = ''; |
| 224 | 286 | foreach( $entries as $entry ) { |
| 225 | 287 | $class = ( $count % 2 == 0 ) ? ' class="alternate"' : ''; |
| @@ -228,16 +290,69 @@ | ||
| 228 | 290 | <tr <?php echo $class; ?>> |
| 229 | 291 | <td style="vertical-align: middle !important;padding-left: 18px;"> |
| 230 | 292 | <input type="checkbox" class="chk" value="<?php echo $snippetId; ?>" name="xyz_ihs_snippet_ids[]" id="xyz_ihs_snippet_ids" /> |
| 231 | 293 | </td> |
| 232 | - <td id="xyz_ihs_vAlign"><?php | |
| 233 | - echo esc_html($entry->title); | |
| 234 | - ?></td> | |
| 235 | - <td id="xyz_ihs_vAlign"><?php | |
| 236 | - if($entry->status == 2){echo 'NA';} | |
| 237 | - else | |
| 238 | - echo '[xyz-ihs snippet="'.esc_html($entry->title).'"]'; | |
| 239 | - ?></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> | |
| 240 | 355 | <td id="xyz_ihs_vAlign"> |
| 241 | 356 | <?php |
| 242 | 357 | if($entry->status == 2){ |
| 243 | 358 | echo "Inactive"; |
| @@ -318,9 +433,9 @@ | ||
| 318 | 433 | } |
| 319 | 434 | |
| 320 | 435 | ?> |
| 321 | 436 | </fieldset> |
| 322 | - </form> | |
| 437 | + | |
| 323 | 438 | </div> |
| 324 | 439 | <script type="text/javascript"> |
| 325 | 440 | jQuery(document).ready(function(){ |
| 326 | 441 | jQuery("#chkAllSnippets").click(function(){ |
| @@ -325,6 +440,113 @@ | ||
| 325 | 440 | jQuery(document).ready(function(){ |
| 326 | 441 | jQuery("#chkAllSnippets").click(function(){ |
| 327 | 442 | jQuery(".chk").prop("checked",jQuery("#chkAllSnippets").prop("checked")); |
| 328 | 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); | |
| 329 | 480 | }); |
| 481 | +}); | |
| 482 | +const xyz_ihs_copy_shortcode = (id) => { | |
| 483 | + | |
| 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); | |
| 492 | + | |
| 493 | + | |
| 494 | + (typeof xyz_ihs_notice === 'function')? xyz_ihs_notice('Short code copied successfully',1):null; | |
| 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}. </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 | + | |
| 330 | 552 | </script> |