PluginProbe
Insert Html Snippet / 1.4
Insert Html Snippet v1.4
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
insert-html-snippet / admin / snippets.php

snippets.php in Insert Html Snippet 1.4, at admin/snippets.php

454 lines 15.3 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_ihs_message = $search_name_db=$search_name='';
8
9 if(isset($_GET['xyz_ihs_msg'])){
10 $xyz_ihs_message = intval($_GET['xyz_ihs_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_ihs') ){
24 // wp_nonce_ays( 'bulk_actions_ihs' );
25 // exit;
26 // }
27 // }
28 if (isset($_POST['apply_ihs_bulk_actions'])){
29 if (isset($_POST['ihs_bulk_actions_snippet'])){
30 if(!isset($_REQUEST['_wpnonce'])||!wp_verify_nonce($_REQUEST['_wpnonce'],'bulk_actions_ihs') )
31 {
32 wp_nonce_ays( 'bulk_actions_ihs' );
33 exit;
34 }
35 $ihs_bulk_actions_snippet=$_POST['ihs_bulk_actions_snippet'];
36 if (isset($_POST['xyz_ihs_snippet_ids']))
37 $xyz_ihs_snippet_ids = $_POST['xyz_ihs_snippet_ids'];
38 $xyz_ihs_pageno = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
39
40 if (empty($xyz_ihs_snippet_ids))
41 {
42 header("Location:".admin_url('admin.php?page=insert-html-snippet-manage&xyz_ihs_msg=8&pagenum='.$xyz_ihs_pageno));
43 exit();
44 }
45 if ($ihs_bulk_actions_snippet==2)//bulk-delete
46 {
47 foreach ($xyz_ihs_snippet_ids as $snippet_id)
48 {
49 $wpdb->query($wpdb->prepare( 'DELETE FROM '.$wpdb->prefix.'xyz_ihs_short_code WHERE id=%d',$snippet_id)) ;
50 }
51 header("Location:".admin_url('admin.php?page=insert-html-snippet-manage&xyz_ihs_msg=3&pagenum='.$xyz_ihs_pageno));
52 exit();
53 }
54 elseif ($ihs_bulk_actions_snippet==0)//bulk-Deactivate
55 {
56 foreach ($xyz_ihs_snippet_ids as $xyz_ihs_snippetId)
57 $wpdb->update($wpdb->prefix.'xyz_ihs_short_code', array('status'=>2), array('id'=>$xyz_ihs_snippetId));
58 header("Location:".admin_url('admin.php?page=insert-html-snippet-manage&xyz_ihs_msg=4&pagenum='.$xyz_ihs_pageno));
59 exit();
60 }
61 elseif ($ihs_bulk_actions_snippet==1)//bulk-activate
62 {
63 foreach ($xyz_ihs_snippet_ids as $xyz_ihs_snippetId)
64 $wpdb->update($wpdb->prefix.'xyz_ihs_short_code', array('status'=>1), array('id'=>$xyz_ihs_snippetId));
65 header("Location:".admin_url('admin.php?page=insert-html-snippet-manage&xyz_ihs_msg=4&pagenum='.$xyz_ihs_pageno));
66 exit();
67 }
68 elseif ($ihs_bulk_actions_snippet==-1)//no action selected
69 {
70 header("Location:".admin_url('admin.php?page=insert-html-snippet-manage&xyz_ihs_msg=7&pagenum='.$xyz_ihs_pageno));
71 exit();
72 }
73 }
74
75 }
76
77
78 }
79 if($xyz_ihs_message == 1){
80 ?>
81 <div class="xyz_system_notice_area_style1" id="xyz_system_notice_area">
82 <span id="system_notice_area_common_msg">
83 HTML Snippet successfully added.&nbsp;&nbsp;&nbsp;
84 </span>
85 <span
86 id="xyz_system_notice_area_dismiss">Dismiss</span>
87 </div>
88 <?php
89
90 }
91 if($xyz_ihs_message == 2){
92
93 ?>
94 <div class="xyz_system_notice_area_style0" id="xyz_system_notice_area">
95 <span id="system_notice_area_common_msg">HTML Snippet not found.&nbsp;&nbsp;&nbsp;
96 </span>
97 <span
98 id="xyz_system_notice_area_dismiss">Dismiss</span>
99 </div>
100 <?php
101
102 }
103 if($xyz_ihs_message == 3){
104
105 ?>
106 <div class="xyz_system_notice_area_style1" id="xyz_system_notice_area">
107 <span id="system_notice_area_common_msg">
108 HTML Snippet successfully deleted.&nbsp;&nbsp;&nbsp;
109 </span>
110 <span
111 id="xyz_system_notice_area_dismiss">Dismiss</span>
112 </div>
113 <?php
114
115 }
116 if($xyz_ihs_message == 4){
117
118 ?>
119 <div class="xyz_system_notice_area_style1" id="xyz_system_notice_area">
120 <span id="system_notice_area_common_msg">
121 HTML Snippet status successfully changed.&nbsp;&nbsp;&nbsp;
122 </span>
123 <span
124 id="xyz_system_notice_area_dismiss">Dismiss</span>
125 </div>
126 <?php
127
128 }
129 if($xyz_ihs_message == 5){
130
131 ?>
132 <div class="xyz_system_notice_area_style1" id="xyz_system_notice_area">
133 <span id="system_notice_area_common_msg">
134 HTML Snippet successfully updated.&nbsp;&nbsp;&nbsp;
135 </span>
136 <span
137 id="xyz_system_notice_area_dismiss">Dismiss</span>
138 </div>
139 <?php
140 }
141 if($xyz_ihs_message == 7)
142 {
143 ?>
144 <div class="xyz_system_notice_area_style1" id="xyz_system_notice_area">
145 <span id="system_notice_area_common_msg">
146 Please select an action to apply.&nbsp;&nbsp;&nbsp;
147 </span>
148 <span id="xyz_system_notice_area_dismiss">Dismiss</span>
149 </div>
150 <?php
151 }
152 if($xyz_ihs_message == 8)
153 {
154 ?>
155 <div class="xyz_system_notice_area_style1" id="xyz_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_system_notice_area_dismiss">Dismiss</span>
160 </div>
161 <?php
162 }
163 ?>
164 <div >
165
166
167 <form method="post">
168 <?php wp_nonce_field( 'bulk_actions_ihs');?>
169 <fieldset
170 style="width: 99%; border: 1px solid #F7F7F7; padding: 10px 0px;">
171 <legend><h3>HTML Snippets</h3></legend>
172 <?php
173 global $wpdb;
174 $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
175 $limit = get_option('xyz_ihs_limit');
176 $offset = ( $pagenum - 1 ) * $limit;
177 $field=get_option('xyz_ihs_sort_field_name');
178 $order=get_option('xyz_ihs_sort_order');
179 if(isset($_POST['snippet_name']))
180 {
181 $search_name=sanitize_text_field($_POST['snippet_name']);
182 $search_name_db=esc_sql($search_name);
183 }
184
185 if(isset($_POST['insertionMethod']))
186 {
187 $insertionMethod =intval($_POST["insertionMethod"]);
188 }
189 else
190 {
191 $insertionMethod =0;
192 }
193 $strInsertionMethod='';
194 if (intval($insertionMethod)>0)
195 {
196 $strInsertionMethod=" AND insertionMethod=$insertionMethod";
197 }
198
199
200 $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" );
201
202 ?>
203
204
205
206 <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');?>"'>
207 <br>
208
209
210
211
212
213 <span style="padding-left: 6px;color:#21759B;">With Selected : </span>
214 <select name="ihs_bulk_actions_snippet" id="ihs_bulk_actions_snippet" style="width:130px;height:29px;">
215 <option value="-1">Bulk Actions</option>
216 <option value="0">Deactivate</option>
217 <option value="1">Activate</option>
218 <option value="2">Delete</option>
219 </select>
220 <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;">
221
222 </form>
223 <form name="manage_snippets" action="" method="post">
224 <?php wp_nonce_field('snipp-manage_');?>
225 <div class="xyz_ihs_search_div" style="float:right;margin:5px;">
226 <table class="xyz_ihs_search_div_table" style="width:100%;">
227 <tr>
228
229 <div><span>Snippet Placement</span>&nbsp;</div>
230 <div>
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
236 </select>
237 </div>
238
239 <div> <input type="text" name="snippet_name" value= "<?php if(isset($search_name)){echo esc_attr($search_name);}?>" placeholder="Search" ></div>
240 <div><input style="padding:5px;margin-left: 5px;margin-right: 5px;" type="submit" name="search" value="Go" /></div>
241
242 </tr>
243 </table>
244 </div>
245 </form>
246
247
248 <table class="widefat" style="width: 99%; margin: 0 auto; border-bottom:none;">
249 <thead>
250 <tr>
251 <th scope="col" width="3%"><input type="checkbox" id="chkAllSnippets" /></th>
252 <th scope="col" >Tracking Name</th>
253 <th scope="col">Snippet Placement
254
255 </th>
256 <th scope="col" >Status</th>
257 <th scope="col" colspan="3" style="text-align: center;">Action</th>
258 </tr>
259 </thead>
260 <tbody>
261 <?php
262
263 if(!empty($entries))//if( count($entries)>0 )
264 {
265 $count=1;
266 $class = '';
267 foreach( $entries as $entry ) {
268 $class = ( $count % 2 == 0 ) ? ' class="alternate"' : '';
269 $snippetId=intval($entry->id);
270 ?>
271 <tr <?php echo $class; ?>>
272 <td style="vertical-align: middle !important;padding-left: 18px;">
273 <input type="checkbox" class="chk" value="<?php echo $snippetId; ?>" name="xyz_ihs_snippet_ids[]" id="xyz_ihs_snippet_ids" />
274 </td>
275 <td id="xyz_ihs_vAlign"><?php
276 echo esc_html($entry->title);
277 ?></td>
278 <td id="xyz_ihs_vAlign">
279 <?php
280 if ($entry->status == 2) {
281 echo 'NA';
282 } else {
283 echo ($entry->insertionMethod == 1) ?
284 'Automatic' :
285 (($entry->insertionMethod == 2) ?
286 '<span onclick="xyz_ihs_copy_shortcode(' . $entry->id . ')" class="xyz_ic_copy_shortcode" id="xyz_ihs_shortcode_' . $entry->id . '">[xyz-ihs snippet="' . esc_html($entry->title) . '"]</span>' .
287 '<span onclick="xyz_ihs_copy_shortcode(' . $entry->id . ')"><img class="xyz_ihs_img xyz_ihs_img_table" title="Click to copy" src="' . plugins_url('insert-html-snippet/images/copy-document.png') . '"></span>'
288 :
289 '');
290 }
291 ?>
292 </td>
293 <td id="xyz_ihs_vAlign">
294 <?php
295 if($entry->status == 2){
296 echo "Inactive";
297 }elseif ($entry->status == 1){
298 echo "Active";
299 }
300
301 ?>
302 </td>
303 <?php
304 if($entry->status == 2){
305 $stat1 = admin_url('admin.php?page=insert-html-snippet-manage&action=snippet-status&snippetId='.$snippetId.'&status=1&pageno='.$pagenum);
306 ?>
307 <td style="text-align: center;"><a
308 href='<?php echo wp_nonce_url($stat1,'ihs-stat_'.$snippetId); ?>'><img
309 id="xyz_ihs_img" title="Activate"
310 src="<?php echo plugins_url('images/activate.png', XYZ_INSERT_HTML_PLUGIN_FILE )?>">
311 </a>
312 </td>
313 <?php
314 }elseif ($entry->status == 1){
315 $stat2 = admin_url('admin.php?page=insert-html-snippet-manage&action=snippet-status&snippetId='.$snippetId.'&status=2&pageno='.$pagenum);
316 ?>
317 <td style="text-align: center;"><a
318 href='<?php echo wp_nonce_url($stat2,'ihs-stat_'.$snippetId); ?>'><img
319 id="xyz_ihs_img" title="Deactivate"
320 src="<?php echo plugins_url('images/pause.png',XYZ_INSERT_HTML_PLUGIN_FILE)?>">
321 </a>
322 </td>
323 <?php
324 }
325
326 ?>
327
328 <td style="text-align: center;"><a
329 href='<?php echo admin_url('admin.php?page=insert-html-snippet-manage&action=snippet-edit&snippetId='.$snippetId.'&pageno='.$pagenum); ?>'><img
330 id="xyz_ihs_img" title="Edit Snippet"
331 src="<?php echo plugins_url('images/edit.png',XYZ_INSERT_HTML_PLUGIN_FILE)?>">
332 </a>
333 </td>
334
335 <?php $delurl = admin_url('admin.php?page=insert-html-snippet-manage&action=snippet-delete&snippetId='.$snippetId.'&pageno='.$pagenum);?>
336 <td style="text-align: center;" ><a
337 href='<?php echo wp_nonce_url($delurl,'ihs-del_'.$snippetId); ?>'
338 onclick="javascript: return confirm('Please click \'OK\' to confirm ');"><img
339 id="xyz_ihs_img" title="Delete Snippet"
340 src="<?php echo plugins_url('images/delete.png',XYZ_INSERT_HTML_PLUGIN_FILE)?>">
341 </a></td>
342 </tr>
343 <?php
344 $count++;
345 }
346 } else { ?>
347 <tr>
348 <td colspan="6" >HTML Snippets not found</td>
349 </tr>
350 <?php } ?>
351 </tbody>
352 </table>
353
354 <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');?>"'>
355
356 <?php
357 $total = $wpdb->get_var( "SELECT COUNT(`id`) FROM ".$wpdb->prefix."xyz_ihs_short_code" );
358 $num_of_pages = ceil( $total / $limit );
359
360 $page_links = paginate_links( array(
361 'base' => add_query_arg( 'pagenum','%#%'),
362 'format' => '',
363 'prev_text' => '&laquo;',
364 'next_text' => '&raquo;',
365 'total' => $num_of_pages,
366 'current' => $pagenum
367 ) );
368
369 if ( $page_links ) {
370 echo '<div class="tablenav" style="width:99%"><div class="tablenav-pages" style="margin: 1em 0">' . $page_links . '</div></div>';
371 }
372
373 ?>
374 </fieldset>
375
376 </div>
377 <script type="text/javascript">
378 jQuery(document).ready(function(){
379 jQuery("#chkAllSnippets").click(function(){
380 jQuery(".chk").prop("checked",jQuery("#chkAllSnippets").prop("checked"));
381 });
382 });
383 const xyz_ihs_copy_shortcode = (id) => {
384
385 var span = document.getElementById("xyz_ihs_shortcode_" + id);
386 var tempTextarea = document.createElement("textarea");
387 tempTextarea.value = span.textContent;
388 document.body.appendChild(tempTextarea);
389 tempTextarea.select();
390 tempTextarea.setSelectionRange(0, 99999); // For mobile devices
391 document.execCommand("copy");
392 document.body.removeChild(tempTextarea);
393
394
395 (typeof xyz_ihs_notice === 'function')? xyz_ihs_notice('Short code copied successfully',1):null;
396
397 };
398
399
400 const xyz_ihs_notice = (msg = '', flag = 0) => {
401
402
403 const noticeElement = jQuery('#xyz_system_notice_area');
404 if (noticeElement.length > 0)
405 {
406
407 jQuery('#system_notice_area_common_msg').text(msg);
408 if (flag === 0) {
409 if(noticeElement.hasClass('system_notice_area_style1'))
410 noticeElement.removeClass('system_notice_area_style1')
411 if(! noticeElement.hasClass('system_notice_area_style0'))
412 noticeElement.addClass('system_notice_area_style0');
413
414 } else {
415 if(noticeElement.hasClass('system_notice_area_style0'))
416 noticeElement.removeClass('system_notice_area_style0')
417 if(! noticeElement.hasClass('system_notice_area_style1'))
418 noticeElement.addClass('system_notice_area_style1');
419
420 }
421 noticeElement.animate({
422 opacity: 'show',
423 height: 'show'
424 }, 500);
425
426 }
427 else{
428
429
430
431 let noticeElementString =
432 `<div class="system_notice_area_style${flag}" id="xyz_system_notice_area">
433 <span id="system_notice_area_common_msg">${msg}.&nbsp;&nbsp;&nbsp;</span>
434 <span id="xyz_system_notice_area_dismiss">Dismiss</span>
435 </div>`;
436
437 let noticeElement = jQuery(noticeElementString);
438 jQuery('body').append(noticeElement);
439 noticeElement.animate({
440 opacity: 'show',
441 height: 'show'
442 }, 500);
443
444
445
446
447
448 }
449
450 };
451
452
453 </script>
454