PluginProbe
Insert PHP Code Snippet / trunk
Insert PHP Code Snippet vtrunk
1.4.7 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 All 27 releases
← All changes | widget.php +130 -74 1.2trunk View file →
@@ -1,95 +1,151 @@
1 1 <?php
2 -
2 +if ( ! defined( 'ABSPATH' ) )
3 + exit;
3 4 /**
4 - * XYZScripts Insert PHP Snippet Widget Class
5 - */
6 -
5 +* XYZScripts Insert PHP Snippet Widget Class
6 +*/
7 7 ////*****************************Sidebar Widget**********************************////
8 -
9 8 class Xyz_Insert_Php_Widget extends WP_Widget {
10 -
11 -
12 9 /** constructor -- name this the same as the class above */
13 - function Xyz_Insert_Php_Widget() {
14 - parent::__construct(false, $name = 'Insert PHP Snippet');
10 + function __construct() {
11 + parent::__construct(false, $name = 'Insert PHP Snippet');
15 12 }
16 -
17 13 /** @see WP_Widget::widget -- do not rename this */
18 - function widget($args, $instance) {
14 + function widget($args, $instance){
19 15 extract( $args );
20 16 global $wpdb;
21 - $title = apply_filters('widget_title', $instance['title']);
22 - $xyz_ips_id = $instance['message'];
23 -
24 - $entries = $wpdb->get_results($wpdb->prepare( "SELECT content FROM ".$wpdb->prefix."xyz_ips_short_code WHERE id=%d",$xyz_ips_id ));
25 -
17 + $title = apply_filters('widget_title', $instance['title']);
18 + $xyz_ips_id = $instance['message'];
19 + $entries = $wpdb->get_results($wpdb->prepare( "SELECT content FROM ".$wpdb->prefix."xyz_ips_short_code WHERE id=%d",$xyz_ips_id ));
26 20 $entry = $entries[0];
27 -
28 21 echo $before_widget;
29 22 if ( $title )
30 - echo $before_title . $title . $after_title;
31 - $content_to_eval=$entry->content;
32 - if(substr($content_to_eval, 0,5)=='<?php')
33 - $content_to_eval='?>'.$content_to_eval;
34 - eval($content_to_eval);
35 -
23 + echo $before_title . $title . $after_title;
24 + $content_to_eval=$entry->content;
25 + /***** to handle old codes : start *****/
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 + if (stripos($content_to_eval, '<?php') !== false)
31 + $tag_start_position=stripos($content_to_eval,'<?php');
32 + else
33 + $tag_start_position="-1";
34 + if (stripos($content_to_eval, '?>') !== false)
35 + $tag_end_position=stripos($content_to_eval,'?>');
36 + else
37 + $tag_end_position="-1";
38 + if(stripos($content_to_eval, '<?php') === false && stripos($content_to_eval, '?>') === false)
39 + {
40 + $content_to_eval=$xyz_ips_content_start.$new_line.$content_to_eval;
41 + }
42 + else if(stripos($content_to_eval, '<?php') !== false)
43 + {
44 + if($tag_start_position>=0 && $tag_end_position>=0 && $tag_start_position>$tag_end_position)
45 + {
46 + $content_to_eval=$xyz_ips_content_start.$new_line.$content_to_eval;
47 + }
48 + }
49 + else if(stripos($content_to_eval, '<?php') === false)
50 + {
51 + if (stripos($content_to_eval, '?>') !== false)
52 + {
53 + $content_to_eval=$xyz_ips_content_start.$new_line.$content_to_eval;
54 + }
55 + }
56 + $content_to_eval='?>'.$content_to_eval;
57 + }
58 + /***** to handle old codes : end *****/
59 + else{
60 + if(substr(trim($content_to_eval), 0,5)=='<?php')
61 + $content_to_eval='?>'.$content_to_eval;
62 + }
63 + $exception_occur=0;
64 + $exception_msg="";
65 + //////// code for error handling in exception mail////////
66 + try {
67 + eval($content_to_eval);
68 + } catch (Throwable $e) { // For PHP 7 and later
69 + $exception_occur = 1;
70 + $exception_msg = $e->getMessage();
71 + }
72 + catch (Exception $e) { // For PHP 5
73 + $exception_occur = 1;
74 + $exception_msg = $e->getMessage();
75 + }
76 + ///////////////////////////////////////////////////////////
77 + if($exception_occur==1) {
78 + // global $post;
79 + // $post_slug = $post->post_name;
80 + // if($post_slug!="xyz-ics-preview-page" && !is_customize_preview())
81 + {
82 + $status=1;
83 + $wpdb->update($wpdb->prefix.'xyz_ips_short_code', array('exception_status'=>$status), array('title'=>$snippet_name));
84 + if(get_option('xyz_ips_exception_email')!="0" && get_option('xyz_ips_exception_email')!="" && get_option('xyz_ips_auto_exception')==1)
85 + {
86 + $email=get_option('xyz_ips_exception_email');
87 + $headers= "Content-type: text/html";
88 + $subject="Exception Report";
89 + $message="Hi,<br>An exception occurred while running one of the snippet in the widget.The snippet name is ".$snippet_name;
90 + $message.=".<br>Exception details are given below : <br>";
91 + $message.=$exception_msg;
92 + wp_mail($email, $subject, $message,$headers);
93 + }
94 + }
95 + }
96 + //eval($content_to_eval);
36 97 echo $after_widget;
37 -
38 98 }
39 -
40 99 /** @see WP_Widget::update -- do not rename this */
41 - function update($new_instance, $old_instance) {
42 - $instance = $old_instance;
43 - $instance['title'] = strip_tags($new_instance['title']);
44 - $instance['message'] = strip_tags($new_instance['message']);
100 + function update($new_instance, $old_instance) {
101 + $instance = $old_instance;
102 + $instance['title'] = strip_tags($new_instance['title']);
103 + $instance['message'] = strip_tags($new_instance['message']);
45 104 return $instance;
46 105 }
47 -
48 106 /** @see WP_Widget::form -- do not rename this */
49 - function form($instance) {
50 - global $wpdb;
51 - $entries = $wpdb->get_results($wpdb->prepare( "SELECT * FROM ".$wpdb->prefix."xyz_ips_short_code WHERE status=%d ORDER BY id DESC",1 ));
52 -
53 -
54 - if(isset($instance['title'])){
55 - $title = esc_attr($instance['title']);
56 - }else{
57 - $title = '';
58 - }
59 -
60 - if(isset($instance['message'])){
61 - $message = esc_attr($instance['message']);
62 - }else{
63 - $message = '';
64 - }
65 -
107 + function form($instance) {
108 + global $wpdb;
109 + $entries = $wpdb->get_results($wpdb->prepare( "SELECT * FROM ".$wpdb->prefix."xyz_ips_short_code WHERE status=%d ORDER BY id DESC",1 ));
110 + if(isset($instance['title'])){
111 + $title = esc_attr($instance['title']);
112 + }else{
113 + $title = '';
114 + }
115 + if(isset($instance['message'])){
116 + $message = esc_attr($instance['message']);
117 + }else{
118 + $message = '';
119 + }
120 +?>
121 +<p>
122 + <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
123 + <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
124 +</p>
125 +<p>
126 + <label for="<?php echo $this->get_field_id('message'); ?>"><?php _e('Choose Snippet :'); ?></label>
127 + <select name="<?php echo $this->get_field_name('message'); ?>">
128 + <?php
129 + if(!empty($entries))//if( count($entries)>0 )
130 + {
131 + $count=1;
132 + $class = '';
133 + foreach( $entries as $entry ) {
66 134 ?>
67 - <p>
68 - <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
69 - <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
70 - </p>
71 - <p>
72 - <label for="<?php echo $this->get_field_id('message'); ?>"><?php _e('Choose Snippet :'); ?></label>
73 -
74 - <!-- <input class="widefat" id="<?php echo $this->get_field_id('message'); ?>" name="<?php echo $this->get_field_name('message'); ?>" type="text" value="<?php echo $message; ?>" />-->
75 - <select name="<?php echo $this->get_field_name('message'); ?>">
76 - <?php
77 - if( count($entries)>0 ) {
78 - $count=1;
79 - $class = '';
80 - foreach( $entries as $entry ) {
81 - ?>
82 - <option value="<?php echo $entry->id;?>" <?php if($message==$entry->id)echo "selected"; ?>><?php echo $entry->title;?></option>
83 - <?php
84 - }
85 - }
86 - ?>
87 - </select>
88 - </p>
89 - <?php
135 + <option value="<?php echo $entry->id;?>" <?php if($message==$entry->id)echo "selected"; ?>><?php echo $entry->title;?></option>
136 + <?php
137 + }
138 + }
139 + ?>
140 + </select>
141 +</p>
142 +<?php
90 143 }
91 -
92 -
93 144 } // end class Xyz_Insert_Php_Widget
94 -add_action('widgets_init', create_function('', 'return register_widget("Xyz_Insert_Php_Widget");'));
95 -?>
145 +
146 +function xyz_ips_add_snippet_widget(){
147 + register_widget("Xyz_Insert_Php_Widget");
148 +}
149 +add_action('widgets_init','xyz_ips_add_snippet_widget');
150 +
151 +?>