| 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 |
$xyz_ips_insertionLocation =''; |
| 10 |
if(isset($_POST) && isset($_POST['addSubmit'])){ |
| 11 |
if (! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce($_REQUEST['_wpnonce'],'ips-padd_')){ |
| 12 |
wp_nonce_ays( 'ips-padd_' ); |
| 13 |
exit; |
| 14 |
} |
| 15 |
$goback=intval($_POST['goback']); |
| 16 |
$goback++; |
| 17 |
$temp_xyz_ips_title = str_replace(' ', '', $_POST['snippetTitle']); |
| 18 |
$temp_xyz_ips_title = str_replace('-', '', $temp_xyz_ips_title); |
| 19 |
$xyz_ips_title = str_replace(' ', '-', $_POST['snippetTitle']); |
| 20 |
$xyz_ips_insertionMethod = intval($_POST['xyz_ips_insertionMethod']); |
| 21 |
$xyz_ips_insertionMethod = ($xyz_ips_insertionMethod >= XYZ_IPS_INSERTION_METHOD['AUTOMATIC'] && $xyz_ips_insertionMethod <= XYZ_IPS_INSERTION_METHOD['EXECUTE_ON_DEMAND']) ? $xyz_ips_insertionMethod : XYZ_IPS_INSERTION_METHOD['AUTOMATIC']; |
| 22 |
$xyz_ips_insertionLocation = intval($_POST['xyz_ips_insertionLocation']); |
| 23 |
if ($xyz_ips_insertionLocation == XYZ_IPS_INSERTION_LOCATION['ADMIN_RUN_ON_HEADER'] || $xyz_ips_insertionLocation == XYZ_IPS_INSERTION_LOCATION['ADMIN_RUN_ON_FOOTER']) { |
| 24 |
$xyz_ips_insertionLocationType = XYZ_IPS_INSERTION_LOCATION_TYPE['ADMIN']; |
| 25 |
} |
| 26 |
else if($xyz_ips_insertionLocation == XYZ_IPS_INSERTION_LOCATION['FRONTEND_RUN_ON_HEADER'] || $xyz_ips_insertionLocation == XYZ_IPS_INSERTION_LOCATION['FRONTEND_RUN_ON_FOOTER']){ |
| 27 |
$xyz_ips_insertionLocationType = XYZ_IPS_INSERTION_LOCATION_TYPE['FRONT_END']; |
| 28 |
} |
| 29 |
else{ |
| 30 |
|
| 31 |
$xyz_ips_insertionLocationType = 0; |
| 32 |
} |
| 33 |
$xyz_ips_content = $_POST['snippetContent']; |
| 34 |
|
| 35 |
if($xyz_ips_title != "" && $xyz_ips_content != ""){ |
| 36 |
if(ctype_alnum($temp_xyz_ips_title)){ |
| 37 |
$snippet_count = $wpdb->query($wpdb->prepare( 'SELECT * FROM '.$wpdb->prefix.'xyz_ips_short_code WHERE title=%s',$xyz_ips_title) ) ; |
| 38 |
if($snippet_count == 0){ |
| 39 |
|
| 40 |
if(get_option('xyz_ips_auto_insert')==1){ |
| 41 |
$xyz_ips_content_start='<?php'; |
| 42 |
$new_line="\r\n"; |
| 43 |
$xyz_ips_content_end='?>'; |
| 44 |
|
| 45 |
if (stripos($xyz_ips_content, '<?php') !== false) |
| 46 |
$tag_start_position=stripos($xyz_ips_content,'<?php'); |
| 47 |
else |
| 48 |
$tag_start_position="-1"; |
| 49 |
|
| 50 |
if (stripos($xyz_ips_content, '?>') !== false) |
| 51 |
$tag_end_position=stripos($xyz_ips_content,'?>'); |
| 52 |
else |
| 53 |
$tag_end_position="-1"; |
| 54 |
|
| 55 |
if(stripos($xyz_ips_content, '<?php') === false && stripos($xyz_ips_content, '?>') === false){ |
| 56 |
$xyz_ips_content=$xyz_ips_content_start.$new_line.$xyz_ips_content; |
| 57 |
} |
| 58 |
else if(stripos($xyz_ips_content, '<?php') !== false){ |
| 59 |
if($tag_start_position>=0 && $tag_end_position>=0 && $tag_start_position>$tag_end_position){ |
| 60 |
$xyz_ips_content=$xyz_ips_content_start.$new_line.$xyz_ips_content; |
| 61 |
} |
| 62 |
} |
| 63 |
else if(stripos($xyz_ips_content, '<?php') === false){ |
| 64 |
if (stripos($xyz_ips_content, '?>') !== false){ |
| 65 |
$xyz_ips_content=$xyz_ips_content_start.$new_line.$xyz_ips_content; |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
$xyz_shortCode = '[xyz-ips snippet="'.$xyz_ips_title.'"]'; |
| 72 |
$wpdb->insert($wpdb->prefix.'xyz_ips_short_code', array('title' =>$xyz_ips_title,'insertionMethod' => $xyz_ips_insertionMethod, 'insertionLocation' => $xyz_ips_insertionLocation, 'insertionLocationType' => $xyz_ips_insertionLocationType,'content'=>$xyz_ips_content,'short_code'=>$xyz_shortCode,'status'=>'1'),array('%s','%d','%d','%d','%s','%s','%d')); |
| 73 |
header("Location:".admin_url('admin.php?page=insert-php-code-snippet-manage&xyz_ips_msg=1')); |
| 74 |
} |
| 75 |
else{ |
| 76 |
?> |
| 77 |
<div class="xyz_ips_system_notice_area_style0" id="xyz_ips_system_notice_area"> |
| 78 |
PHP Snippet already exists. |
| 79 |
<span id="xyz_ips_system_notice_area_dismiss">Dismiss</span> |
| 80 |
</div> |
| 81 |
<?php |
| 82 |
} |
| 83 |
} |
| 84 |
else{ |
| 85 |
?> |
| 86 |
<div class="xyz_ips_system_notice_area_style0" id="xyz_ips_system_notice_area"> |
| 87 |
PHP Snippet title can have only alphabets,numbers or hyphen. |
| 88 |
<span id="xyz_ips_system_notice_area_dismiss">Dismiss</span> |
| 89 |
</div> |
| 90 |
<?php |
| 91 |
} |
| 92 |
}else{ |
| 93 |
?> |
| 94 |
<div class="xyz_ips_system_notice_area_style0" id="xyz_ips_system_notice_area"> |
| 95 |
Fill all mandatory fields. |
| 96 |
<span id="xyz_ips_system_notice_area_dismiss">Dismiss</span> |
| 97 |
</div> |
| 98 |
<?php |
| 99 |
} |
| 100 |
} |
| 101 |
?> |
| 102 |
<div > |
| 103 |
<fieldset |
| 104 |
style="width: 99%; border: 1px solid #F7F7F7; padding: 10px 0px;"> |
| 105 |
<legend> |
| 106 |
<b> |
| 107 |
Add PHP Snippet |
| 108 |
</b> |
| 109 |
</legend> |
| 110 |
<form name="frmmainForm" id="frmmainForm" method="post"> |
| 111 |
<?php wp_nonce_field('ips-padd_'); ?> |
| 112 |
|
| 113 |
|
| 114 |
<div> |
| 115 |
<input type="hidden" name="goback" value=<?php echo $goback;?>> |
| 116 |
<table |
| 117 |
style="width: 99%; background-color: #F9F9F9; border: 1px solid #E4E4E4; border-width: 1px;margin: 0 auto"> |
| 118 |
<tr> |
| 119 |
<td> |
| 120 |
<br/> |
| 121 |
<div id="shortCode"> |
| 122 |
</div> |
| 123 |
<br/> |
| 124 |
</td> |
| 125 |
</tr> |
| 126 |
<tr valign="top"> |
| 127 |
<td style="border-bottom: none;width:20%;"> |
| 128 |
Placement Methods |
| 129 |
<font color="red"> |
| 130 |
* |
| 131 |
</font> |
| 132 |
</td> |
| 133 |
<td style="border-bottom: none;width:1px;"> |
| 134 |
|
| 135 |
</td> |
| 136 |
<td> |
| 137 |
<select class="xyz_ips_uniq_select" name="xyz_ips_insertionMethod" |
| 138 |
id="xyz_ips_insertionMethod"> |
| 139 |
<option value="<?php echo XYZ_IPS_INSERTION_METHOD['AUTOMATIC']; ?>" <?php if (isset($_POST['xyz_ips_insertionMethod']) && $_POST['xyz_ips_insertionMethod'] == XYZ_IPS_INSERTION_METHOD['AUTOMATIC']) { |
| 140 |
echo "selected"; |
| 141 |
} ?>>Automatic</option> |
| 142 |
<option value="<?php echo XYZ_IPS_INSERTION_METHOD['SHORT_CODE']; ?>" <?php if (isset($_POST['xyz_ips_insertionMethod']) && $_POST['xyz_ips_insertionMethod'] == XYZ_IPS_INSERTION_METHOD['SHORT_CODE']) { |
| 143 |
echo "selected"; |
| 144 |
} ?>>Short code (Manual)</option> |
| 145 |
<option value="<?php echo XYZ_IPS_INSERTION_METHOD['EXECUTE_ON_DEMAND']; ?>" <?php if (isset($_POST['xyz_ips_insertionMethod']) && $_POST['xyz_ips_insertionMethod'] == XYZ_IPS_INSERTION_METHOD['EXECUTE_ON_DEMAND']) { |
| 146 |
echo "selected"; |
| 147 |
} ?>>Execute on demand</option> |
| 148 |
</select> |
| 149 |
</td> |
| 150 |
</tr> |
| 151 |
|
| 152 |
|
| 153 |
<tr valign="top" id="xyz_ips_insertionLocationTR"> |
| 154 |
<td style="border-bottom: none;width:20%;"> |
| 155 |
Insertion Location |
| 156 |
<font color="red"> |
| 157 |
* |
| 158 |
</font> |
| 159 |
</td> |
| 160 |
<td style="border-bottom: none;width:1px;"> |
| 161 |
|
| 162 |
</td> |
| 163 |
<td> |
| 164 |
<div> |
| 165 |
<div class="xyz_ips_insertionLocationDiv"> |
| 166 |
<span id="xyz_ips_insertion-location-txt">Select Insertion Location </span><span><i class="fa fa-angle-down" aria-hidden="true"></i> <i class="fa fa-angle-up" aria-hidden="true"></i></span> |
| 167 |
|
| 168 |
</div> |
| 169 |
<input type="hidden" id="xyz_ips_insertionLocation" name="xyz_ips_insertionLocation" value="<?php echo intval($xyz_ips_insertionLocation);?>"> |
| 170 |
<ul id="xyz_ips_uniq_list" class="xyz_ips_uniq_list"> |
| 171 |
<div class="xyz_ips_left_column"> |
| 172 |
|
| 173 |
<li class="xyz_ips_li_h2"><label>Admin</label></li> |
| 174 |
<li class="xyz_ips_li_option <?php echo ($xyz_ips_insertionLocation == XYZ_IPS_INSERTION_LOCATION['ADMIN_RUN_ON_HEADER']) ? 'selected' : ''; ?>" |
| 175 |
data-value="<?php echo XYZ_IPS_INSERTION_LOCATION['ADMIN_RUN_ON_HEADER']; ?>"> |
| 176 |
Run on header |
| 177 |
</li> |
| 178 |
<li class="xyz_ips_li_option <?php echo ($xyz_ips_insertionLocation == XYZ_IPS_INSERTION_LOCATION['ADMIN_RUN_ON_FOOTER']) ? 'selected' : ''; ?>" |
| 179 |
data-value="<?php echo XYZ_IPS_INSERTION_LOCATION['ADMIN_RUN_ON_FOOTER']; ?>"> |
| 180 |
Run on footer |
| 181 |
</li> |
| 182 |
<li class="xyz_ips_li_h2"><label>Front end</label></li> |
| 183 |
<li class="xyz_ips_li_option <?php echo ($xyz_ips_insertionLocation == XYZ_IPS_INSERTION_LOCATION['FRONTEND_RUN_ON_HEADER']) ? 'selected' : ''; ?>" |
| 184 |
data-value="<?php echo XYZ_IPS_INSERTION_LOCATION['FRONTEND_RUN_ON_HEADER']; ?>"> |
| 185 |
Run on header |
| 186 |
</li> |
| 187 |
<li class="xyz_ips_li_option <?php echo ($xyz_ips_insertionLocation == XYZ_IPS_INSERTION_LOCATION['FRONTEND_RUN_ON_FOOTER']) ? 'selected' : ''; ?>" |
| 188 |
data-value="<?php echo XYZ_IPS_INSERTION_LOCATION['FRONTEND_RUN_ON_FOOTER']; ?>"> |
| 189 |
Run on footer |
| 190 |
</li> |
| 191 |
|
| 192 |
</div> |
| 193 |
<div class="xyz_ips_right_column"> |
| 194 |
|
| 195 |
</div> |
| 196 |
</ul> |
| 197 |
</div> |
| 198 |
|
| 199 |
</td> |
| 200 |
</tr> |
| 201 |
<tr valign="top"> |
| 202 |
<td style="border-bottom: none;width:20%;"> |
| 203 |
Tracking Name |
| 204 |
<font color="red"> |
| 205 |
* |
| 206 |
</font> |
| 207 |
</td> |
| 208 |
<td style="border-bottom: none;width:1px;"> |
| 209 |
: |
| 210 |
</td> |
| 211 |
<td> |
| 212 |
<input style="width:80%;" |
| 213 |
type="text" name="snippetTitle" id="snippetTitle" |
| 214 |
value="<?php if(isset($_POST['snippetTitle'])){ echo esc_attr($_POST['snippetTitle']);}?>"> |
| 215 |
</td> |
| 216 |
</tr> |
| 217 |
<tr> |
| 218 |
|
| 219 |
<td style="border-bottom: none;width:20%;"> |
| 220 |
<?php |
| 221 |
if(get_option('xyz_ips_auto_insert')==1){ |
| 222 |
?> |
| 223 |
PHP code |
| 224 |
<?php |
| 225 |
} |
| 226 |
else{ |
| 227 |
?> |
| 228 |
PHP code (without <?php ?>) |
| 229 |
<?php |
| 230 |
} |
| 231 |
?> |
| 232 |
<font color="red"> |
| 233 |
* |
| 234 |
</font> |
| 235 |
</td> |
| 236 |
|
| 237 |
<td style="border-bottom: none;width:1px;"> |
| 238 |
: |
| 239 |
</td> |
| 240 |
<td > |
| 241 |
<textarea name="snippetContent" style="width:80%;height:150px;"><?php if(isset($_POST['snippetContent'])){ echo esc_textarea($_POST['snippetContent']);}?></textarea> |
| 242 |
</td> |
| 243 |
</tr> |
| 244 |
<tr> |
| 245 |
<td> |
| 246 |
</td> |
| 247 |
<td> |
| 248 |
|
| 249 |
|
| 250 |
<input class="button-primary" style="cursor: pointer;" |
| 251 |
type="button" name="back" value="Back" onclick=" window.history.go(-<?php echo $goback;?>);" > |
| 252 |
</td> |
| 253 |
<td> |
| 254 |
<input class="button-primary" style="cursor: pointer;" |
| 255 |
type="submit" name="addSubmit" value="Create"> |
| 256 |
</td> |
| 257 |
</tr> |
| 258 |
<tr> |
| 259 |
<td> |
| 260 |
<br/> |
| 261 |
</td> |
| 262 |
</tr> |
| 263 |
</table> |
| 264 |
</div> |
| 265 |
</form> |
| 266 |
</fieldset> |
| 267 |
</div> |
| 268 |
<?php |
| 269 |
require( dirname( __FILE__ ) . '/snippet-js.php' ); |
| 270 |
?> |
| 271 |
|