PluginProbe
Insert Html Snippet / 1.3.4
Insert Html Snippet v1.3.4
1.4.6 trunk 1.0 1.0.1 1.1 1.1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3 1.3.1 1.3.2 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 All 27 releases
insert-html-snippet / widget.php

widget.php in Insert Html Snippet 1.3.4, at widget.php

120 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) )
3 exit;
4 /**
5 * XYZScripts Insert PHP Snippet Widget Class
6 */
7 ////*****************************Sidebar Widget**********************************////
8 class Xyz_Insert_Php_Widget extends WP_Widget {
9 /** constructor -- name this the same as the class above */
10 function __construct() {
11 parent::__construct(false, $name = 'Insert PHP Snippet');
12 }
13 /** @see WP_Widget::widget -- do not rename this */
14 function widget($args, $instance){
15 extract( $args );
16 global $wpdb;
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 ));
20 $entry = $entries[0];
21 echo $before_widget;
22 if ( $title )
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
64 eval($content_to_eval);
65 echo $after_widget;
66 }
67 /** @see WP_Widget::update -- do not rename this */
68 function update($new_instance, $old_instance) {
69 $instance = $old_instance;
70 $instance['title'] = strip_tags($new_instance['title']);
71 $instance['message'] = strip_tags($new_instance['message']);
72 return $instance;
73 }
74 /** @see WP_Widget::form -- do not rename this */
75 function form($instance) {
76 global $wpdb;
77 $entries = $wpdb->get_results($wpdb->prepare( "SELECT * FROM ".$wpdb->prefix."xyz_ips_short_code WHERE status=%d ORDER BY id DESC",1 ));
78 if(isset($instance['title'])){
79 $title = esc_attr($instance['title']);
80 }else{
81 $title = '';
82 }
83 if(isset($instance['message'])){
84 $message = esc_attr($instance['message']);
85 }else{
86 $message = '';
87 }
88 ?>
89 <p>
90 <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
91 <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; ?>" />
92 </p>
93 <p>
94 <label for="<?php echo $this->get_field_id('message'); ?>"><?php _e('Choose Snippet :'); ?></label>
95 <select name="<?php echo $this->get_field_name('message'); ?>">
96 <?php
97 if(!empty($entries))//if( count($entries)>0 )
98 {
99 $count=1;
100 $class = '';
101 foreach( $entries as $entry ) {
102 ?>
103 <option value="<?php echo $entry->id;?>" <?php if($message==$entry->id)echo "selected"; ?>><?php echo $entry->title;?></option>
104 <?php
105 }
106 }
107 ?>
108 </select>
109 </p>
110 <?php
111 }
112 } // end class Xyz_Insert_Php_Widget
113
114 function xyz_ips_add_snippet_widget(){
115 register_widget("Xyz_Insert_Php_Widget");
116 }
117 add_action('widgets_init','xyz_ips_add_snippet_widget');
118
119 ?>
120