| @@ -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. <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. | |
| 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. <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. | |
| 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. <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. | |
| 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. <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. | |
| 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,24 +144,50 @@ | ||
| 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. <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. | |
| 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. </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. | |
| 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 | +?> | |
| 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;"> | |
| 187 | + <?php wp_nonce_field( 'bulk_actions_ihs');?> | |
| 188 | + <fieldset | |
| 189 | + style="width: 98.8%; border: 1px solid #4d3e3e2e; padding: 10px 0px;"> | |
| 67 | 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,21 +194,85 @@ | ||
| 71 | 194 | $limit = get_option('xyz_ihs_limit'); |
| 72 | 195 | $offset = ( $pagenum - 1 ) * $limit; |
| 73 | 196 | $field=get_option('xyz_ihs_sort_field_name'); |
| 74 | 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 | + ?> | |
| 75 | 222 | |
| 76 | - $entries = $wpdb->get_results( "SELECT * FROM ".$wpdb->prefix."xyz_ihs_short_code ORDER BY $field $order LIMIT $offset,$limit" ); | |
| 77 | 223 | |
| 78 | - ?> | |
| 79 | - <input id="submit_ihs" | |
| 80 | - style="cursor: pointer; margin-bottom:10px; margin-left:8px;" type="button" | |
| 81 | - name="textFieldButton2" value="Add New HTML Snippet" | |
| 82 | - onClick='document.location.href="<?php echo admin_url('admin.php?page=insert-html-snippet-manage&action=snippet-add');?>"'> | |
| 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 | + | |
| 83 | 267 | <table class="widefat" style="width: 99%; margin: 0 auto; border-bottom:none;"> |
| 84 | 268 | <thead> |
| 85 | 269 | <tr> |
| 270 | + <th scope="col" width="3%"><input type="checkbox" id="chkAllSnippets" /></th> | |
| 86 | 271 | <th scope="col" >Tracking Name</th> |
| 87 | - <th scope="col" >Snippet Short Code</th> | |
| 272 | + <th scope="col">Snippet Placement</th> | |
| 273 | + <th scope="col">Placement Details</th> | |
| 274 | + | |
| 88 | 275 | <th scope="col" >Status</th> |
| 89 | 276 | <th scope="col" colspan="3" style="text-align: center;">Action</th> |
| 90 | 277 | </tr> |
| 91 | 278 | </thead> |
| @@ -90,24 +277,83 @@ | ||
| 90 | 277 | </tr> |
| 91 | 278 | </thead> |
| 92 | 279 | <tbody> |
| 93 | 280 | <?php |
| 94 | - if( count($entries)>0 ) { | |
| 281 | + | |
| 282 | + if(!empty($entries))//if( count($entries)>0 ) | |
| 283 | + { | |
| 95 | 284 | $count=1; |
| 96 | 285 | $class = ''; |
| 97 | 286 | foreach( $entries as $entry ) { |
| 98 | 287 | $class = ( $count % 2 == 0 ) ? ' class="alternate"' : ''; |
| 288 | + $snippetId=intval($entry->id); | |
| 99 | 289 | ?> |
| 100 | 290 | <tr <?php echo $class; ?>> |
| 101 | - <td><?php | |
| 102 | - echo esc_html($entry->title); | |
| 103 | - ?></td> | |
| 104 | - <td><?php | |
| 105 | - if($entry->status == 2){echo 'NA';} | |
| 106 | - else | |
| 107 | - echo '[xyz-ihs snippet="'.esc_html($entry->title).'"]'; | |
| 108 | - ?></td> | |
| 109 | - <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 "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"> | |
| 110 | 356 | <?php |
| 111 | 357 | if($entry->status == 2){ |
| 112 | 358 | echo "Inactive"; |
| 113 | 359 | }elseif ($entry->status == 1){ |
| @@ -117,40 +363,44 @@ | ||
| 117 | 363 | ?> |
| 118 | 364 | </td> |
| 119 | 365 | <?php |
| 120 | 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); | |
| 121 | 368 | ?> |
| 122 | 369 | <td style="text-align: center;"><a |
| 123 | - href='<?php echo admin_url('admin.php?page=insert-html-snippet-manage&action=snippet-status&snippetId='.$entry->id.'&status=1&pageno='.$pagenum); ?>'><img | |
| 124 | - id="img" title="Activate" | |
| 125 | - 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 )?>"> | |
| 126 | 373 | </a> |
| 127 | 374 | </td> |
| 128 | 375 | <?php |
| 129 | 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); | |
| 130 | 378 | ?> |
| 131 | 379 | <td style="text-align: center;"><a |
| 132 | - href='<?php echo admin_url('admin.php?page=insert-html-snippet-manage&action=snippet-status&snippetId='.$entry->id.'&status=2&pageno='.$pagenum); ?>'><img | |
| 133 | - id="img" title="Deactivate" | |
| 134 | - 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)?>"> | |
| 135 | 383 | </a> |
| 136 | 384 | </td> |
| 137 | 385 | <?php |
| 138 | 386 | } |
| 139 | - | |
| 387 | + | |
| 140 | 388 | ?> |
| 141 | 389 | |
| 142 | 390 | <td style="text-align: center;"><a |
| 143 | - href='<?php echo admin_url('admin.php?page=insert-html-snippet-manage&action=snippet-edit&snippetId='.$entry->id.'&pageno='.$pagenum); ?>'><img | |
| 144 | - id="img" title="Edit Snippet" | |
| 145 | - 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)?>"> | |
| 146 | 394 | </a> |
| 147 | 395 | </td> |
| 396 | + | |
| 397 | + <?php $delurl = admin_url('admin.php?page=insert-html-snippet-manage&action=snippet-delete&snippetId='.$snippetId.'&pageno='.$pagenum);?> | |
| 148 | 398 | <td style="text-align: center;" ><a |
| 149 | - 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); ?>' | |
| 150 | 400 | onclick="javascript: return confirm('Please click \'OK\' to confirm ');"><img |
| 151 | - id="img" title="Delete Snippet" | |
| 152 | - 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)?>"> | |
| 153 | 403 | </a></td> |
| 154 | 404 | </tr> |
| 155 | 405 | <?php |
| 156 | 406 | $count++; |
| @@ -162,12 +412,9 @@ | ||
| 162 | 412 | <?php } ?> |
| 163 | 413 | </tbody> |
| 164 | 414 | </table> |
| 165 | 415 | |
| 166 | - <input id="submit_ihs" | |
| 167 | - style="cursor: pointer; margin-top:10px;margin-left:8px;" type="button" | |
| 168 | - name="textFieldButton2" value="Add New HTML Snippet" | |
| 169 | - 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');?>"'> | |
| 170 | 417 | |
| 171 | 418 | <?php |
| 172 | 419 | $total = $wpdb->get_var( "SELECT COUNT(`id`) FROM ".$wpdb->prefix."xyz_ihs_short_code" ); |
| 173 | 420 | $num_of_pages = ceil( $total / $limit ); |
| @@ -180,18 +427,126 @@ | ||
| 180 | 427 | 'total' => $num_of_pages, |
| 181 | 428 | 'current' => $pagenum |
| 182 | 429 | ) ); |
| 183 | 430 | |
| 184 | - | |
| 185 | - | |
| 186 | 431 | if ( $page_links ) { |
| 187 | 432 | echo '<div class="tablenav" style="width:99%"><div class="tablenav-pages" style="margin: 1em 0">' . $page_links . '</div></div>'; |
| 188 | 433 | } |
| 189 | 434 | |
| 190 | 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) => { | |
| 191 | 483 | |
| 192 | - </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); | |
| 193 | 492 | |
| 194 | - </form> | |
| 195 | 493 | |
| 196 | -</div> | |
| 494 | + (typeof xyz_ihs_notice === 'function')? xyz_ihs_notice('Short code copied successfully',1):null; | |
| 197 | 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 | + | |
| 552 | +</script> | |