PluginProbe
Insert PHP Code Snippet / 1.4.2
Insert PHP Code Snippet v1.4.2
1.4.7 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 All 27 releases
insert-php-code-snippet / admin / snippets.php

snippets.php in Insert PHP Code Snippet 1.4.2, at admin/snippets.php

500 lines 15.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) )
3 exit;
4
5 global $wpdb;
6 $_GET = stripslashes_deep($_GET);
7 $xyz_ips_message =$search_name_db=$search_name= '';
8
9 if(isset($_GET['xyz_ips_msg'])){
10 $xyz_ips_message = intval($_GET['xyz_ips_msg']);
11 }
12 if($_POST)
13 {
14 if(isset($_POST['search']))
15 {
16 if(!isset($_REQUEST['_wpnonce'])||!wp_verify_nonce($_REQUEST['_wpnonce'],'snipp-manage_') ){
17 wp_nonce_ays( 'snipp-manage_' );
18 exit;
19 }
20 }
21 // if(isset($_POST['textFieldButton2']))
22 // {
23 // if(!isset($_REQUEST['_wpnonce'])||!wp_verify_nonce($_REQUEST['_wpnonce'],'bulk_actions_ips') ){
24 // wp_nonce_ays( 'bulk_actions_ips' );
25 // exit;
26 // }
27 // }
28 if (isset($_POST['apply_ips_bulk_actions'])){
29 if (isset($_POST['ips_bulk_actions_snippet'])){
30 if(!isset($_REQUEST['_wpnonce'])||!wp_verify_nonce($_REQUEST['_wpnonce'],'bulk_actions_ips') )
31 {
32 wp_nonce_ays( 'bulk_actions_ips' );
33 exit;
34 }
35 $ips_bulk_actions_snippet=$_POST['ips_bulk_actions_snippet'];
36 if (isset($_POST['xyz_ips_snippet_ids']))
37 $xyz_ips_snippet_ids = $_POST['xyz_ips_snippet_ids'];
38 $xyz_ips_pageno = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
39 if (empty($xyz_ips_snippet_ids))
40 {
41 header("Location:".admin_url('admin.php?page=insert-php-code-snippet-manage&xyz_ips_msg=8&pagenum='.$xyz_ips_pageno));
42 exit();
43 }
44 if ($ips_bulk_actions_snippet==2)//bulk-delete
45 {
46 foreach ($xyz_ips_snippet_ids as $snippet_id)
47 {
48 $wpdb->query($wpdb->prepare( 'DELETE FROM '.$wpdb->prefix.'xyz_ips_short_code WHERE id=%d',$snippet_id)) ;
49 }
50 header("Location:".admin_url('admin.php?page=insert-php-code-snippet-manage&xyz_ips_msg=3&pagenum='.$xyz_ips_pageno));
51 exit();
52 }
53 elseif ($ips_bulk_actions_snippet==0)//bulk-Deactivate
54 {
55 foreach ($xyz_ips_snippet_ids as $xyz_ips_snippetId)
56 $wpdb->update($wpdb->prefix.'xyz_ips_short_code', array('status'=>2), array('id'=>$xyz_ips_snippetId));
57 header("Location:".admin_url('admin.php?page=insert-php-code-snippet-manage&xyz_ips_msg=4&pagenum='.$xyz_ips_pageno));
58 exit();
59 }
60 elseif ($ips_bulk_actions_snippet==1)//bulk-activate
61 {
62 foreach ($xyz_ips_snippet_ids as $xyz_ips_snippetId)
63 $wpdb->update($wpdb->prefix.'xyz_ips_short_code', array('status'=>1), array('id'=>$xyz_ips_snippetId));
64 header("Location:".admin_url('admin.php?page=insert-php-code-snippet-manage&xyz_ips_msg=4&pagenum='.$xyz_ips_pageno));
65 exit();
66 }
67 elseif ($ips_bulk_actions_snippet==-1)//no action selected
68 {
69 header("Location:".admin_url('admin.php?page=insert-php-code-snippet-manage&xyz_ips_msg=7&pagenum='.$xyz_ips_pageno));
70 exit();
71 }
72 }
73
74 }
75
76 }
77 if($xyz_ips_message == 1){
78
79 ?>
80 <div class="xyz_ips_system_notice_area_style1" id="xyz_ips_system_notice_area">
81 <span id="system_notice_area_common_msg">
82 PHP Snippet successfully added.&nbsp;&nbsp;&nbsp;
83 </span>
84 <span
85 id="xyz_ips_system_notice_area_dismiss">Dismiss</span>
86 </div>
87 <?php
88
89 }
90 if($xyz_ips_message == 2){
91
92 ?>
93 <div class="xyz_ips_system_notice_area_style0" id="xyz_ips_system_notice_area">
94 <span id="system_notice_area_common_msg">
95 PHP Snippet not found.&nbsp;&nbsp;&nbsp;
96 </span>
97 <span
98 id="xyz_ips_system_notice_area_dismiss">Dismiss</span>
99 </div>
100 <?php
101
102 }
103 if($xyz_ips_message == 3){
104
105 ?>
106 <div class="xyz_ips_system_notice_area_style1" id="xyz_ips_system_notice_area">
107 <span id="system_notice_area_common_msg">
108 PHP Snippet successfully deleted.&nbsp;&nbsp;&nbsp;
109 </span>
110 <span
111 id="xyz_ips_system_notice_area_dismiss">Dismiss</span>
112 </div>
113 <?php
114
115 }
116 if($xyz_ips_message == 4){
117
118 ?>
119 <div class="xyz_ips_system_notice_area_style1" id="xyz_ips_system_notice_area">
120 <span id="system_notice_area_common_msg">
121 PHP Snippet status successfully changed.&nbsp;&nbsp;&nbsp;
122 </span>
123 <span
124 id="xyz_ips_system_notice_area_dismiss">Dismiss</span>
125 </div>
126 <?php
127
128 }
129 if($xyz_ips_message == 5){
130
131 ?>
132 <div class="xyz_ips_system_notice_area_style1" id="xyz_ips_system_notice_area">
133 <span id="system_notice_area_common_msg">
134 PHP Snippet successfully updated.&nbsp;&nbsp;&nbsp;
135 </span>
136 <span
137 id="xyz_ips_system_notice_area_dismiss">Dismiss</span>
138 </div>
139 <?php
140
141 }
142 if($xyz_ips_message == 7)
143 {
144 ?>
145 <div class="xyz_ips_system_notice_area_style1" id="xyz_ips_system_notice_area">
146 <span id="system_notice_area_common_msg"> Please select an action to apply.&nbsp;&nbsp;&nbsp;
147 </span>
148 <span id="xyz_ips_system_notice_area_dismiss">Dismiss</span>
149 </div>
150 <?php
151 }
152 if($xyz_ips_message == 8)
153 {
154 ?>
155 <div class="xyz_ips_system_notice_area_style1" id="xyz_ips_system_notice_area">
156 <span id="system_notice_area_common_msg">
157 Please select at least one snippet to perform this action.&nbsp;&nbsp;&nbsp;
158 </span>
159 <span id="xyz_ips_system_notice_area_dismiss">Dismiss</span>
160 </div>
161 <?php
162 }
163 ?>
164
165 <div >
166
167
168 <form method="post">
169 <?php wp_nonce_field( 'bulk_actions_ips');?>
170 <fieldset
171 style="width: 99%; border: 1px solid #F7F7F7; padding: 10px 0px;">
172 <legend><h3>PHP Code Snippets</h3></legend>
173 <?php
174 global $wpdb;
175 $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
176 $limit = get_option('xyz_ips_limit');
177 $offset = ( $pagenum - 1 ) * $limit;
178
179
180 $field=get_option('xyz_ips_sort_field_name');
181 $order=get_option('xyz_ips_sort_order');
182 if(isset($_POST['snippet_name']))
183 {
184 $search_name=sanitize_text_field($_POST['snippet_name']);
185 $search_name_db=esc_sql($search_name);
186 }
187 if(isset($_POST['insertionMethod']))
188 {
189 $insertionMethod =intval($_POST["insertionMethod"]);
190 }
191 else
192 {
193 $insertionMethod =0;
194 }
195 $strInsertionMethod='';
196 if (intval($insertionMethod)>0)
197 {
198 $strInsertionMethod=" AND insertionMethod=$insertionMethod";
199 }
200
201 $entries = $wpdb->get_results( "SELECT * FROM ".$wpdb->prefix."xyz_ips_short_code WHERE title like '%".$search_name_db."%'".$strInsertionMethod." ORDER BY $field $order LIMIT $offset,$limit" );
202
203
204 ?>
205 <input id="xyz_ips_submit_ips"
206 style="cursor: pointer; margin-bottom:10px; margin-left:8px;" type="button"
207 name="textFieldButton2" value="Add New PHP Code Snippet"
208 onClick='document.location.href="<?php echo admin_url('admin.php?page=insert-php-code-snippet-manage&action=snippet-add');?>"'>
209 <br>
210 <span style="padding-left: 6px;color:#21759B;">With Selected : </span>
211 <select name="ips_bulk_actions_snippet" id="ips_bulk_actions_snippet" style="width:130px;height:29px;">
212 <option value="-1">Bulk Actions</option>
213 <option value="0">Deactivate</option>
214 <option value="1">Activate</option>
215 <option value="2">Delete</option>
216 </select>
217 <input type="submit" title="Apply" name="apply_ips_bulk_actions" value="Apply" style="color:#21759B;cursor:pointer;padding: 5px;background:linear-gradient(to top, #ECECEC, #F9F9F9) repeat scroll 0 0 #F1F1F1;border: 2px solid #DFDFDF;">
218 </form>
219
220
221 <table class="xyz-ips-manage-header">
222 <tr>
223 <td>
224 <form name="manage_snippets" action="" method="post">
225 <?php wp_nonce_field('snipp-manage_');?>
226 <div class="xyz_ips_search_div" style="float:right;">
227 <table class="xyz_ips_search_div_table" style="width:100%;">
228 &nbsp;&nbsp;
229
230 <span>Snippet Placement</span>&nbsp;
231 <select name="insertionMethod" id="insertionMethod" >
232 <option value="0" <?php if($insertionMethod==0) { echo "selected"; } ?>>All</option>
233 <option value="1" <?php if($insertionMethod==1) { echo "selected"; } ?>>Automatic</option>
234 <option value="2" <?php if($insertionMethod==2) { echo "selected"; } ?>>Short Code</option>
235 <option value="3" <?php if($insertionMethod==3) { echo "selected"; } ?>>Execute On Demand</option>
236 </select>
237 &nbsp;&nbsp;
238 <tr>
239 <input type="text" name="snippet_name" value= "<?php if(isset($search_name)){echo esc_attr($search_name);}?>" placeholder="Search" >
240 <input type="submit" name="search" class="xyz-ips-go" value="Go" />
241 </tr>
242 </table>
243 </div>
244 </form>
245
246 </td>
247 </tr>
248 </table>
249 <table class="widefat" style="width: 99%; margin: 0 auto; border-bottom:none;">
250 <thead>
251 <tr>
252 <th scope="col" width="3%"><input type="checkbox" id="chkAllSnippets" /></th>
253 <th scope="col" >Tracking Name</th>
254 <th scope="col">Snippet Placement
255 </th>
256 <th scope="col" >Status</th>
257 <th scope="col" colspan="4" style="text-align: center;">Action</th>
258 </tr>
259 </thead>
260 <tbody>
261 <?php
262 if( !empty($entries) )//if( count($entries)>0 )
263 {
264 $count=1;
265 $class = '';
266 foreach( $entries as $entry ) {
267 $class = ( $count % 2 == 0 ) ? ' class="alternate"' : '';
268 $snippetId=intval($entry->id);
269 ?>
270 <tr <?php echo $class; ?>>
271 <td style="vertical-align: middle !important;padding-left: 18px;">
272 <input type="checkbox" class="chk" value="<?php echo $snippetId; ?>" name="xyz_ips_snippet_ids[]" id="xyz_ips_snippet_ids" />
273 </td>
274 <td id="xyz_ips_vAlign"><?php
275 echo esc_html($entry->title);
276 ?></td>
277 <td>
278
279
280 <?php if($entry->status == 2){
281 echo 'NA';
282 } else{
283 echo ($entry->insertionMethod == 1) ? 'Automatic' :
284 (($entry->insertionMethod == 2) ?
285 '<span onclick=xyz_ips_copy_shortcode('.$entry->id.') class="xyz_ic_copy_shortcode" id="xyz_ips_shortcode_'.$entry->id.'">[xyz-ips snippet="'.esc_html($entry->title).'"]</span>'.
286 '<span onclick=xyz_ips_copy_shortcode('.$entry->id.')><img class="xyz_ips_img xyz_ips_img_table" title="Click to copy" src="'.plugins_url('insert-php-code-snippet/images/copy-document.png').'"></span>'
287
288 :
289 (($entry->insertionMethod == 3) ? 'Execute on demand'.'<img onclick=xyz_ips_execute_shortcode('.$entry->id.') class="xyz_ips_img xyz_ips_img_table" id="xyz_ips_img_execute_shortcode" title="Click to execute" src="'.plugins_url('xyz-wp-insert-code-snippet/images/play-button.png').'">':
290 '')); }?>
291 </td>
292 <td id="xyz_ips_vAlign">
293 <?php
294 if($entry->status == 2){
295 echo "Inactive";
296 }elseif ($entry->status == 1){
297 echo "Active";
298 }
299
300 ?>
301 </td>
302 <?php
303 if($entry->status == 2){
304 $stat1 = admin_url('admin.php?page=insert-php-code-snippet-manage&action=snippet-status&snippetId='.$snippetId.'&status=1&pageno='.$pagenum);
305 ?>
306 <td style="text-align: center;"><a
307 href='<?php echo wp_nonce_url($stat1,'ips-pstat_'.$snippetId); ?>'><img
308 id="xyz_ips_img" title="Activate"
309 src="<?php echo plugins_url('images/activate.png',XYZ_INSERT_PHP_PLUGIN_FILE)?>">
310 </a>
311 </td>
312 <?php
313 }elseif ($entry->status == 1){
314 $stat2 = admin_url('admin.php?page=insert-php-code-snippet-manage&action=snippet-status&snippetId='.$snippetId.'&status=2&pageno='.$pagenum);
315 ?>
316 <td style="text-align: center;"><a
317 href='<?php echo wp_nonce_url($stat2,'ips-pstat_'.$snippetId); ?>'><img
318 id="xyz_ips_img" title="Deactivate"
319 src="<?php echo plugins_url('images/pause.png',XYZ_INSERT_PHP_PLUGIN_FILE)?>">
320 </a>
321 </td>
322 <?php
323 }
324
325 ?>
326
327 <td style="text-align: center;"><a
328 href='<?php echo admin_url('admin.php?page=insert-php-code-snippet-manage&action=snippet-edit&snippetId='.$snippetId.'&pageno='.$pagenum); ?>'><img
329 id="xyz_ips_img" title="Edit Snippet"
330 src="<?php echo plugins_url('images/edit.png',XYZ_INSERT_PHP_PLUGIN_FILE)?>">
331 </a>
332 </td>
333
334 <?php $delurl = admin_url('admin.php?page=insert-php-code-snippet-manage&action=snippet-delete&snippetId='.$snippetId.'&pageno='.$pagenum);?>
335 <td style="text-align: center;" ><a
336 href='<?php echo wp_nonce_url($delurl,'ips-pdel_'.$snippetId); ?>'
337 onclick="javascript: return confirm('Please click \'OK\' to confirm ');"><img
338 id="xyz_ips_img" title="Delete Snippet"
339 src="<?php echo plugins_url('images/delete.png',XYZ_INSERT_PHP_PLUGIN_FILE)?>">
340 </a></td>
341
342 <?php
343 $page_url =xyz_ips_get_link_by_slug('xyz-ics-preview-page');
344 $page_url =add_query_arg( 'preview', 'true', $page_url );
345 $page_url =add_query_arg( 'snippetId', $snippetId, $page_url );
346 $prewurl =esc_url($page_url);
347 ?>
348 <td style="text-align: center;" >
349 <?php if($entry->insertionMethod ==2) {?>
350 <a href='<?php echo $prewurl;?>' target="_blank">
351 <img id="xyz_ips_img" title="Preview" src="<?php echo plugins_url('images/preview.png',XYZ_INSERT_PHP_PLUGIN_FILE)?>">
352 </a>
353 <?php }?>
354 </td>
355 </tr>
356 <?php
357 $count++;
358 }
359 } else { ?>
360 <tr>
361 <td colspan="7" >PHP Code Snippets not found</td>
362 </tr>
363 <?php } ?>
364 </tbody>
365 </table>
366
367 <input id="xyz_ips_submit_ips"
368 style="cursor: pointer; margin-top:10px;margin-left:8px;" type="button"
369 name="textFieldButton2" value="Add New PHP Code Snippet"
370 onClick='document.location.href="<?php echo admin_url('admin.php?page=insert-php-code-snippet-manage&action=snippet-add');?>"'>
371
372 <?php
373 $total = $wpdb->get_var( "SELECT COUNT(`id`) FROM ".$wpdb->prefix."xyz_ips_short_code" );
374 $num_of_pages = ceil( $total / $limit );
375
376 $page_links = paginate_links( array(
377 'base' => add_query_arg( 'pagenum','%#%'),
378 'format' => '',
379 'prev_text' => '&laquo;',
380 'next_text' => '&raquo;',
381 'total' => $num_of_pages,
382 'current' => $pagenum
383 ) );
384
385
386
387 if ( $page_links ) {
388 echo '<div class="tablenav" style="width:99%"><div class="tablenav-pages" style="margin: 1em 0">' . $page_links . '</div></div>';
389 }
390
391 ?>
392
393 </fieldset>
394
395
396
397 </div>
398 <script type="text/javascript">
399 jQuery(document).ready(function(){
400 jQuery("#chkAllSnippets").click(function(){
401 jQuery(".chk").prop("checked",jQuery("#chkAllSnippets").prop("checked"));
402 });
403 });
404 const xyz_ips_copy_shortcode = (id) => {
405
406 var span = document.getElementById("xyz_ips_shortcode_" + id);
407 var tempTextarea = document.createElement("textarea");
408 tempTextarea.value = span.textContent;
409 document.body.appendChild(tempTextarea);
410 tempTextarea.select();
411 tempTextarea.setSelectionRange(0, 99999); // For mobile devices
412 document.execCommand("copy");
413 document.body.removeChild(tempTextarea);
414
415
416 (typeof xyz_ips_notice === 'function')? xyz_ips_notice('Short code copied successfully',1):null;
417
418 };
419
420
421 const xyz_ips_notice = (msg = '', flag = 0) => {
422
423
424 const noticeElement = jQuery('#xyz_ips_system_notice_area');
425 if (noticeElement.length > 0)
426 {
427
428 jQuery('#system_notice_area_common_msg').text(msg);
429 if (flag === 0) {
430 if(noticeElement.hasClass('xyz_ips_system_notice_area_style1'))
431 noticeElement.removeClass('xyz_ips_system_notice_area_style1')
432 if(! noticeElement.hasClass('xyz_ips_system_notice_area_style0'))
433 noticeElement.addClass('xyz_ips_system_notice_area_style0');
434
435 } else {
436 if(noticeElement.hasClass('xyz_ips_system_notice_area_style0'))
437 noticeElement.removeClass('xyz_ips_system_notice_area_style0')
438 if(! noticeElement.hasClass('xyz_ips_system_notice_area_style1'))
439 noticeElement.addClass('xyz_ips_system_notice_area_style1');
440
441 }
442 noticeElement.animate({
443 opacity: 'show',
444 height: 'show'
445 }, 500);
446
447 }
448 else{
449
450
451
452 let noticeElementString =
453 `<div class="xyz_ips_system_notice_area_style${flag}" id="xyz_ips_system_notice_area">
454 <span id="system_notice_area_common_msg">${msg}.&nbsp;&nbsp;&nbsp;</span>
455 <span id="xyz_ips_system_notice_area_dismiss">Dismiss</span>
456 </div>`;
457
458 let noticeElement = jQuery(noticeElementString);
459 jQuery('body').append(noticeElement);
460 noticeElement.animate({
461 opacity: 'show',
462 height: 'show'
463 }, 500);
464
465
466
467
468
469 }
470
471 };
472
473 function xyz_ips_execute_shortcode(id) {
474
475
476 var nonce= '<?php echo wp_create_nonce('xyz_ips_execute_shortcode');?>';
477 jQuery.ajax({
478 url: ajaxurl,
479 type: 'POST',
480 dataType: 'json',
481 data: {
482 action: 'xyz_ips_execute_shortcode',
483 _wpnonce: nonce,
484 id: id
485 },
486 success: function(response) {
487 if (response.status === 1) {
488 xyz_ips_notice(response.message,1);
489
490 } else {
491 xyz_ips_notice(response.message,0);
492 }
493 },
494 error: function(xhr, status, error) {
495 xyz_ips_notice('An error occurred: ' + error, 0);
496 }
497 });
498 }
499 </script>
500