| 1 |
<?php |
| 2 |
|
| 3 |
global $wpdb; |
| 4 |
|
| 5 |
$_POST = stripslashes_deep($_POST); |
| 6 |
$_POST = xyz_trim_deep($_POST); |
| 7 |
|
| 8 |
if(isset($_POST) && isset($_POST['addSubmit'])){ |
| 9 |
|
| 10 |
// echo '<pre>'; |
| 11 |
// print_r($_POST); |
| 12 |
// die("JJJ"); |
| 13 |
|
| 14 |
$temp_xyz_ips_title = str_replace(' ', '', $_POST['snippetTitle']); |
| 15 |
$temp_xyz_ips_title = str_replace('-', '', $temp_xyz_ips_title); |
| 16 |
|
| 17 |
$xyz_ips_title = str_replace(' ', '-', $_POST['snippetTitle']); |
| 18 |
|
| 19 |
|
| 20 |
$xyz_ips_content = $_POST['snippetContent']; |
| 21 |
|
| 22 |
if($xyz_ips_title != "" && $xyz_ips_content != ""){ |
| 23 |
if(ctype_alnum($temp_xyz_ips_title)){ |
| 24 |
|
| 25 |
$snippet_count = $wpdb->query( 'SELECT * FROM '.$wpdb->prefix.'xyz_ips_short_code WHERE title="'.$xyz_ips_title.'"' ) ; |
| 26 |
if($snippet_count == 0){ |
| 27 |
$xyz_shortCode = '[xyz-ips snippet="'.$xyz_ips_title.'"]'; |
| 28 |
$wpdb->insert($wpdb->prefix.'xyz_ips_short_code', array('title' =>$xyz_ips_title,'content'=>$xyz_ips_content,'short_code'=>$xyz_shortCode,'status'=>'1'),array('%s','%s','%s','%d')); |
| 29 |
|
| 30 |
header("Location:".admin_url('admin.php?page=insert-php-code-snippet-manage&xyz_ips_msg=1')); |
| 31 |
}else{ |
| 32 |
?> |
| 33 |
<div class="system_notice_area_style0" id="system_notice_area"> |
| 34 |
PHP Snippet already exists. <span id="system_notice_area_dismiss">Dismiss</span> |
| 35 |
</div> |
| 36 |
<?php |
| 37 |
} |
| 38 |
}else{ |
| 39 |
?> |
| 40 |
<div class="system_notice_area_style0" id="system_notice_area"> |
| 41 |
PHP Snippet title can have only alphabets,numbers or hyphen. <span id="system_notice_area_dismiss">Dismiss</span> |
| 42 |
</div> |
| 43 |
<?php |
| 44 |
} |
| 45 |
}else{ |
| 46 |
?> |
| 47 |
<div class="system_notice_area_style0" id="system_notice_area"> |
| 48 |
Fill all mandatory fields. <span id="system_notice_area_dismiss">Dismiss</span> |
| 49 |
</div> |
| 50 |
<?php |
| 51 |
} |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
?> |
| 56 |
|
| 57 |
<div > |
| 58 |
<fieldset |
| 59 |
style="width: 99%; border: 1px solid #F7F7F7; padding: 10px 0px;"> |
| 60 |
<legend> |
| 61 |
<b>Add PHP Snippet</b> |
| 62 |
</legend> |
| 63 |
<form name="frmmainForm" id="frmmainForm" method="post"> |
| 64 |
|
| 65 |
<div> |
| 66 |
<table |
| 67 |
style="width: 99%; background-color: #F9F9F9; border: 1px solid #E4E4E4; border-width: 1px;margin: 0 auto"> |
| 68 |
<tr><td><br/> |
| 69 |
<div id="shortCode"></div> |
| 70 |
<br/></td></tr> |
| 71 |
<tr valign="top"> |
| 72 |
<td style="border-bottom: none;width:20%;"> Tracking Name <font color="red">*</font></td> |
| 73 |
<td style="border-bottom: none;width:1px;"> : </td> |
| 74 |
<td><input style="width:80%;" |
| 75 |
type="text" name="snippetTitle" id="snippetTitle" |
| 76 |
value="<?php if(isset($_POST['snippetTitle'])){ echo esc_attr($_POST['snippetTitle']);}?>"></td> |
| 77 |
</tr> |
| 78 |
<tr> |
| 79 |
<td style="border-bottom: none;width:20%; "> PHP code (without <?php ?>) <font color="red">*</font></td> |
| 80 |
<td style="border-bottom: none;width:1px;"> : </td> |
| 81 |
<td > |
| 82 |
<textarea name="snippetContent" style="width:80%;height:150px;"><?php if(isset($_POST['snippetContent'])){ echo esc_textarea($_POST['snippetContent']);}?></textarea> |
| 83 |
</td> |
| 84 |
</tr> |
| 85 |
|
| 86 |
<tr> |
| 87 |
<td></td><td></td> |
| 88 |
<td><input class="button-primary" style="cursor: pointer;" |
| 89 |
type="submit" name="addSubmit" value="Create"></td> |
| 90 |
</tr> |
| 91 |
<tr><td><br/></td></tr> |
| 92 |
</table> |
| 93 |
</div> |
| 94 |
|
| 95 |
</form> |
| 96 |
</fieldset> |
| 97 |
|
| 98 |
</div> |
| 99 |
|