| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) |
| 3 |
exit; |
| 4 |
|
| 5 |
global $wpdb; |
| 6 |
$goback=1; |
| 7 |
$_POST = stripslashes_deep($_POST); |
| 8 |
$_POST = xyz_trim_deep($_POST); |
| 9 |
if(isset($_POST) && isset($_POST['addSubmit'])){ |
| 10 |
if (! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce($_REQUEST['_wpnonce'],'ips-padd_')){ |
| 11 |
wp_nonce_ays( 'ips-padd_' ); |
| 12 |
exit; |
| 13 |
} |
| 14 |
$goback=intval($_POST['goback']); |
| 15 |
$goback++; |
| 16 |
$temp_xyz_ips_title = str_replace(' ', '', $_POST['snippetTitle']); |
| 17 |
$temp_xyz_ips_title = str_replace('-', '', $temp_xyz_ips_title); |
| 18 |
$xyz_ips_title = str_replace(' ', '-', $_POST['snippetTitle']); |
| 19 |
$xyz_ips_content = $_POST['snippetContent']; |
| 20 |
|
| 21 |
if($xyz_ips_title != "" && $xyz_ips_content != ""){ |
| 22 |
if(ctype_alnum($temp_xyz_ips_title)){ |
| 23 |
$snippet_count = $wpdb->query($wpdb->prepare( 'SELECT * FROM '.$wpdb->prefix.'xyz_ips_short_code WHERE title=%s',$xyz_ips_title) ) ; |
| 24 |
if($snippet_count == 0){ |
| 25 |
|
| 26 |
if(get_option('xyz_ips_auto_insert')==1){ |
| 27 |
$xyz_ips_content_start='<?php'; |
| 28 |
$new_line="\r\n"; |
| 29 |
$xyz_ips_content_end='?>'; |
| 30 |
|
| 31 |
if (stripos($xyz_ips_content, '<?php') !== false) |
| 32 |
$tag_start_position=stripos($xyz_ips_content,'<?php'); |
| 33 |
else |
| 34 |
$tag_start_position="-1"; |
| 35 |
|
| 36 |
if (stripos($xyz_ips_content, '?>') !== false) |
| 37 |
$tag_end_position=stripos($xyz_ips_content,'?>'); |
| 38 |
else |
| 39 |
$tag_end_position="-1"; |
| 40 |
|
| 41 |
if(stripos($xyz_ips_content, '<?php') === false && stripos($xyz_ips_content, '?>') === false){ |
| 42 |
$xyz_ips_content=$xyz_ips_content_start.$new_line.$xyz_ips_content; |
| 43 |
} |
| 44 |
else if(stripos($xyz_ips_content, '<?php') !== false){ |
| 45 |
if($tag_start_position>=0 && $tag_end_position>=0 && $tag_start_position>$tag_end_position){ |
| 46 |
$xyz_ips_content=$xyz_ips_content_start.$new_line.$xyz_ips_content; |
| 47 |
} |
| 48 |
} |
| 49 |
else if(stripos($xyz_ips_content, '<?php') === false){ |
| 50 |
if (stripos($xyz_ips_content, '?>') !== false){ |
| 51 |
$xyz_ips_content=$xyz_ips_content_start.$new_line.$xyz_ips_content; |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
$xyz_shortCode = '[xyz-ips snippet="'.$xyz_ips_title.'"]'; |
| 58 |
$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')); |
| 59 |
header("Location:".admin_url('admin.php?page=insert-php-code-snippet-manage&xyz_ips_msg=1')); |
| 60 |
} |
| 61 |
else{ |
| 62 |
?> |
| 63 |
<div class="xyz_system_notice_area_style0" id="xyz_system_notice_area"> |
| 64 |
PHP Snippet already exists. |
| 65 |
<span id="xyz_system_notice_area_dismiss">Dismiss</span> |
| 66 |
</div> |
| 67 |
<?php |
| 68 |
} |
| 69 |
} |
| 70 |
else{ |
| 71 |
?> |
| 72 |
<div class="xyz_system_notice_area_style0" id="xyz_system_notice_area"> |
| 73 |
PHP Snippet title can have only alphabets,numbers or hyphen. |
| 74 |
<span id="xyz_system_notice_area_dismiss">Dismiss</span> |
| 75 |
</div> |
| 76 |
<?php |
| 77 |
} |
| 78 |
}else{ |
| 79 |
?> |
| 80 |
<div class="xyz_system_notice_area_style0" id="xyz_system_notice_area"> |
| 81 |
Fill all mandatory fields. |
| 82 |
<span id="xyz_system_notice_area_dismiss">Dismiss</span> |
| 83 |
</div> |
| 84 |
<?php |
| 85 |
} |
| 86 |
} |
| 87 |
?> |
| 88 |
<div > |
| 89 |
<fieldset |
| 90 |
style="width: 99%; border: 1px solid #F7F7F7; padding: 10px 0px;"> |
| 91 |
<legend> |
| 92 |
<b> |
| 93 |
Add PHP Snippet |
| 94 |
</b> |
| 95 |
</legend> |
| 96 |
<form name="frmmainForm" id="frmmainForm" method="post"> |
| 97 |
<?php wp_nonce_field('ips-padd_'); ?> |
| 98 |
|
| 99 |
|
| 100 |
<div> |
| 101 |
<input type="hidden" name="goback" value=<?php echo $goback;?>> |
| 102 |
<table |
| 103 |
style="width: 99%; background-color: #F9F9F9; border: 1px solid #E4E4E4; border-width: 1px;margin: 0 auto"> |
| 104 |
<tr> |
| 105 |
<td> |
| 106 |
<br/> |
| 107 |
<div id="shortCode"> |
| 108 |
</div> |
| 109 |
<br/> |
| 110 |
</td> |
| 111 |
</tr> |
| 112 |
<tr valign="top"> |
| 113 |
<td style="border-bottom: none;width:20%;"> |
| 114 |
Tracking Name |
| 115 |
<font color="red"> |
| 116 |
* |
| 117 |
</font> |
| 118 |
</td> |
| 119 |
<td style="border-bottom: none;width:1px;"> |
| 120 |
: |
| 121 |
</td> |
| 122 |
<td> |
| 123 |
<input style="width:80%;" |
| 124 |
type="text" name="snippetTitle" id="snippetTitle" |
| 125 |
value="<?php if(isset($_POST['snippetTitle'])){ echo esc_attr($_POST['snippetTitle']);}?>"> |
| 126 |
</td> |
| 127 |
</tr> |
| 128 |
<tr> |
| 129 |
|
| 130 |
<td style="border-bottom: none;width:20%;"> |
| 131 |
<?php |
| 132 |
if(get_option('xyz_ips_auto_insert')==1){ |
| 133 |
?> |
| 134 |
PHP code |
| 135 |
<?php |
| 136 |
} |
| 137 |
else{ |
| 138 |
?> |
| 139 |
PHP code (without <?php ?>) |
| 140 |
<?php |
| 141 |
} |
| 142 |
?> |
| 143 |
<font color="red"> |
| 144 |
* |
| 145 |
</font> |
| 146 |
</td> |
| 147 |
|
| 148 |
<td style="border-bottom: none;width:1px;"> |
| 149 |
: |
| 150 |
</td> |
| 151 |
<td > |
| 152 |
<textarea name="snippetContent" style="width:80%;height:150px;"><?php if(isset($_POST['snippetContent'])){ echo esc_textarea($_POST['snippetContent']);}?></textarea> |
| 153 |
</td> |
| 154 |
</tr> |
| 155 |
<tr> |
| 156 |
<td> |
| 157 |
</td> |
| 158 |
<td> |
| 159 |
|
| 160 |
|
| 161 |
<input class="button-primary" style="cursor: pointer;" |
| 162 |
type="button" name="back" value="back" onclick=" window.history.go(-<?php echo $goback;?>);" > |
| 163 |
</td> |
| 164 |
<td> |
| 165 |
<input class="button-primary" style="cursor: pointer;" |
| 166 |
type="submit" name="addSubmit" value="Create"> |
| 167 |
</td> |
| 168 |
</tr> |
| 169 |
<tr> |
| 170 |
<td> |
| 171 |
<br/> |
| 172 |
</td> |
| 173 |
</tr> |
| 174 |
</table> |
| 175 |
</div> |
| 176 |
</form> |
| 177 |
</fieldset> |
| 178 |
</div> |
| 179 |
|