| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) |
| 3 |
exit; |
| 4 |
global $wpdb; |
| 5 |
add_shortcode('xyz-ips','xyz_ips_display_content'); |
| 6 |
function xyz_ips_display_content($xyz_snippet_name){ |
| 7 |
global $wpdb; |
| 8 |
if(is_array($xyz_snippet_name)&& isset($xyz_snippet_name['snippet'])){ |
| 9 |
$snippet_name = $xyz_snippet_name['snippet']; |
| 10 |
$query = $wpdb->get_results($wpdb->prepare( "SELECT * FROM ".$wpdb->prefix."xyz_ips_short_code WHERE title=%s" ,$snippet_name)); |
| 11 |
if(!empty($query))//if(count($query)>0) |
| 12 |
{ |
| 13 |
foreach ($query as $sippetdetails){ |
| 14 |
if($sippetdetails->status==1){ |
| 15 |
/* if(is_numeric(ini_get('output_buffering'))){ |
| 16 |
$tmp=ob_get_contents(); |
| 17 |
if(strlen($tmp)>0) |
| 18 |
ob_clean();*/ |
| 19 |
ob_start(); |
| 20 |
$content_to_eval=$sippetdetails->content; |
| 21 |
|
| 22 |
/***** to handle old codes : start *****/ |
| 23 |
|
| 24 |
if(get_option('xyz_ips_auto_insert')==1){ |
| 25 |
$xyz_ips_content_start='<?php'; |
| 26 |
$new_line="\r\n"; |
| 27 |
$xyz_ips_content_end='?>'; |
| 28 |
|
| 29 |
if (stripos($content_to_eval, '<?php') !== false) |
| 30 |
$tag_start_position=stripos($content_to_eval,'<?php'); |
| 31 |
else |
| 32 |
$tag_start_position="-1"; |
| 33 |
|
| 34 |
if (stripos($content_to_eval, '?>') !== false) |
| 35 |
$tag_end_position=stripos($content_to_eval,'?>'); |
| 36 |
else |
| 37 |
$tag_end_position="-1"; |
| 38 |
|
| 39 |
if(stripos($content_to_eval, '<?php') === false && stripos($content_to_eval, '?>') === false) |
| 40 |
{ |
| 41 |
$content_to_eval=$xyz_ips_content_start.$new_line.$content_to_eval; |
| 42 |
} |
| 43 |
else if(stripos($content_to_eval, '<?php') !== false) |
| 44 |
{ |
| 45 |
if($tag_start_position>=0 && $tag_end_position>=0 && $tag_start_position>$tag_end_position) |
| 46 |
{ |
| 47 |
$content_to_eval=$xyz_ips_content_start.$new_line.$content_to_eval; |
| 48 |
} |
| 49 |
} |
| 50 |
else if(stripos($content_to_eval, '<?php') === false) |
| 51 |
{ |
| 52 |
if (stripos($content_to_eval, '?>') !== false) |
| 53 |
{ |
| 54 |
$content_to_eval=$xyz_ips_content_start.$new_line.$content_to_eval; |
| 55 |
} |
| 56 |
} |
| 57 |
$content_to_eval='?>'.$content_to_eval; |
| 58 |
} |
| 59 |
|
| 60 |
/***** to handle old codes : end *****/ |
| 61 |
else{ |
| 62 |
if(substr(trim($content_to_eval), 0,5)=='<?php') |
| 63 |
$content_to_eval='?>'.$content_to_eval; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
$exception_occur=0; |
| 68 |
$exception_msg=""; |
| 69 |
|
| 70 |
if(get_option('xyz_ips_auto_exception')==1) { |
| 71 |
|
| 72 |
$str1 = " \r\ntry{"; |
| 73 |
$var="$"; |
| 74 |
$str2 = "\r\n}catch(Exception ".$var."e) {echo 'Caught exception: '.".$var."e->getMessage();".$var."exception_occur=1;".$var."exception_msg=".$var."e->getMessage();}"; |
| 75 |
|
| 76 |
$first_start_tag=strpos($content_to_eval,"<?php"); |
| 77 |
$last_end_tag=strrpos($content_to_eval,"?>"); |
| 78 |
$last_start_tag=strrpos($content_to_eval,"<?php"); |
| 79 |
|
| 80 |
if($first_start_tag>=0) { |
| 81 |
$new_pos=$first_start_tag+5; //add length of php start tag |
| 82 |
$content_to_eval=substr_replace( $content_to_eval, $str1, $new_pos, 0 ); |
| 83 |
} |
| 84 |
if($last_end_tag<$last_start_tag) { |
| 85 |
$content_to_eval=$content_to_eval.$str2; |
| 86 |
} |
| 87 |
else { |
| 88 |
if($last_end_tag>0) { |
| 89 |
$new_pos=$last_end_tag+7; //add length of $str1 |
| 90 |
$content_to_eval=substr_replace( $content_to_eval, $str2, $new_pos, 0 ); |
| 91 |
} |
| 92 |
else if($last_end_tag==0) { |
| 93 |
$content_to_eval=$content_to_eval.$str2; |
| 94 |
} |
| 95 |
} |
| 96 |
//echo $content_to_eval;die; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
eval($content_to_eval); |
| 101 |
|
| 102 |
if($exception_occur==1) { |
| 103 |
|
| 104 |
global $post; |
| 105 |
$post_slug = $post->post_name; |
| 106 |
|
| 107 |
if($post_slug!="xyz-ics-preview-page") { |
| 108 |
|
| 109 |
if(get_option('xyz_ips_exception_email')!="0" && get_option('xyz_ips_exception_email')!="") { |
| 110 |
|
| 111 |
$email=get_option('xyz_ips_exception_email'); |
| 112 |
$headers= "Content-type: text/html"; |
| 113 |
$subject="Exception Report"; |
| 114 |
$message="Hi,<br>An exception occured while running one of the snippet.The snippet name is ".$snippet_name; |
| 115 |
$message.=".<br>Exception details are given below<br>"; |
| 116 |
$message.=$exception_msg; |
| 117 |
wp_mail($email, $subject, $message,$headers); |
| 118 |
} |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
$xyz_em_content = ob_get_contents(); |
| 123 |
// ob_clean(); |
| 124 |
ob_end_clean(); |
| 125 |
return $xyz_em_content; |
| 126 |
/* } |
| 127 |
else{ |
| 128 |
eval($sippetdetails->content); |
| 129 |
}*/ |
| 130 |
} |
| 131 |
else{ |
| 132 |
return ''; |
| 133 |
} |
| 134 |
break; |
| 135 |
} |
| 136 |
} |
| 137 |
else{ |
| 138 |
return ''; |
| 139 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
add_filter('widget_text', 'do_shortcode'); // to run shortcodes in text widgets |
| 143 |
|