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