Enhanced Text Widget - Version 1.4

Version Description

  • Display text field in monospace font
  • Code refactoring
Download this release

Release Info

Developer bostondv
Plugin Icon wp plugin Enhanced Text Widget
Version 1.4
Comparing to
See all releases

Code changes from version 1.3.4 to 1.4

Files changed (3) hide show
  1. enhanced-text-widget.php +143 -71
  2. readme.txt +7 -1
  3. screenshot-1.png +0 -0
enhanced-text-widget.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Enhanced Text Widget
4
  Plugin URI: http://pomelodesign.com/enhanced-text-widget
5
  Description: An enhanced version of the default text widget where you may have Text, HTML, CSS, JavaScript, Flash, and/or PHP as content with linkable widget title.
6
- Version: 1.3.4
7
  Author: Pomelo Design
8
  Author URI: http://pomelodesign.com/
9
  License: GPL2
@@ -25,21 +25,47 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
 
26
  class EnhancedTextWidget extends WP_Widget {
27
 
28
- function EnhancedTextWidget() {
29
- $widget_ops = array('classname' => 'widget_text', 'description' => __('Widget supporting Text, HTML, CSS, PHP, Flash, JavaScript, Shortcodes'));
 
 
 
30
  $control_ops = array('width' => 400, 'height' => 350);
31
- $this->WP_Widget('EnhancedTextWidget', __('Enhanced Text'), $widget_ops, $control_ops);
 
32
  }
33
 
 
 
 
34
  function widget( $args, $instance ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  extract($args);
 
36
  $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance);
37
- $hideTitle = $instance['hideTitle'] ? true : false;
38
- $titleUrl = apply_filters('widget_title', empty($instance['titleUrl']) ? '' : $instance['titleUrl'], $instance);
39
- $newWindow = $instance['newWindow'] ? true : false;
40
- $cssClass = apply_filters('widget_title', empty($instance['cssClass']) ? '' : $instance['cssClass'], $instance);
41
- $bare = $instance['bare'] ? true : false;
42
- $text = apply_filters( 'widget_text', $instance['text'], $instance );
 
 
43
  if ( $cssClass ) {
44
  if( strpos($before_widget, 'class') === false ) {
45
  $before_widget = str_replace('>', 'class="'. $cssClass . '"', $before_widget);
@@ -47,87 +73,133 @@ class EnhancedTextWidget extends WP_Widget {
47
  $before_widget = str_replace('class="', 'class="'. $cssClass . ' ', $before_widget);
48
  }
49
  }
 
50
  echo $bare ? '' : $before_widget;
51
- if($hideTitle == false) {
52
- if( $titleUrl && $title ) {
53
- $title = '<a href="'.$titleUrl.'"'.($newWindow == true?' target="_blank"':'').' title="'.$title.'">'.$title.'</a>';
54
- }
55
- if ( !empty( $title ) ) {
56
- echo $bare ? $title : $before_title . $title . $after_title;
57
- }
58
  }
59
- ?>
60
- <div class="textwidget">
61
- <?php if($instance['filter']) {
62
- ob_start();
63
- eval("?>$text<?php ");
64
- $output = ob_get_contents();
65
- ob_end_clean();
66
- echo wpautop($output);
67
- } else {
68
- eval("?>".$text."<?php ");
69
- } ?>
70
- </div>
71
- <?php
72
- echo $bare ? '' : $after_widget;
73
  }
74
 
 
 
 
75
  function update( $new_instance, $old_instance ) {
76
  $instance = $old_instance;
77
  $instance['title'] = strip_tags($new_instance['title']);
78
- $instance['hideTitle'] = isset($new_instance['hideTitle']);
79
- $instance['titleUrl'] = strip_tags($new_instance['titleUrl']);
80
- $instance['cssClass'] = strip_tags($new_instance['cssClass']);
81
- $instance['newWindow'] = isset($new_instance['newWindow']);
82
  if ( current_user_can('unfiltered_html') )
83
  $instance['text'] = $new_instance['text'];
84
  else
85
- $instance['text'] = wp_filter_post_kses( $new_instance['text'] );
 
 
 
 
86
  $instance['filter'] = isset($new_instance['filter']);
87
  $instance['bare'] = isset($new_instance['bare']);
 
 
 
 
 
 
 
 
 
88
  return $instance;
89
  }
90
 
 
 
 
 
 
 
 
 
 
 
91
  function form( $instance ) {
92
- $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'titleUrl' => '', 'text' => '' ) );
93
- $title = "";
94
- if(isset($instance['title'])){
95
- $title = strip_tags($instance['title']);
96
- }
97
- $titleUrl = "";
98
- if(isset($instance['titleUrl'])){
99
- $titleUrl = strip_tags($instance['titleUrl']);
100
- }
101
- $cssClass = "";
102
- if(isset($instance['cssClass'])){
103
- $cssClass = strip_tags($instance['cssClass']);
104
- }
105
- $text = "";
106
- if(isset($instance['text'])){
107
- $text = format_to_edit($instance['text']);
108
- }
109
  ?>
110
- <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
111
- <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
112
- <p><label for="<?php echo $this->get_field_id('titleUrl'); ?>"><?php _e('URL:'); ?></label>
113
- <input class="widefat" id="<?php echo $this->get_field_id('titleUrl'); ?>" name="<?php echo $this->get_field_name('titleUrl'); ?>" type="text" value="<?php echo esc_attr($titleUrl); ?>" /></p>
114
-
115
- <p><label for="<?php echo $this->get_field_id('cssClass'); ?>"><?php _e('CSS Classes:'); ?></label>
116
- <input class="widefat" id="<?php echo $this->get_field_id('cssClass'); ?>" name="<?php echo $this->get_field_name('cssClass'); ?>" type="text" value="<?php echo esc_attr($cssClass); ?>" /></p>
117
- <p><label for="<?php echo $this->get_field_id('text'); ?>"><?php _e('Content:'); ?></label>
118
- <textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $text; ?></textarea>
119
- <p><input id="<?php echo $this->get_field_id('hideTitle'); ?>" name="<?php echo $this->get_field_name('hideTitle'); ?>" type="checkbox" <?php checked(isset($instance['hideTitle']) ? $instance['hideTitle'] : 0); ?> />&nbsp;<label for="<?php echo $this->get_field_id('hideTitle'); ?>"><?php _e('Do not display the title'); ?></label></p>
120
- <p><input type="checkbox" id="<?php echo $this->get_field_id('newWindow'); ?>" name="<?php echo $this->get_field_name('newWindow'); ?>" <?php checked(isset($instance['newWindow']) ? $instance['newWindow'] : 0); ?> />
121
- <label for="<?php echo $this->get_field_id('newWindow'); ?>"><?php _e('Open the URL in a new window'); ?></label></p>
122
- <p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked(isset($instance['filter']) ? $instance['filter'] : 0); ?> />&nbsp;<label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs to the content'); ?></label></p>
123
- <p><input id="<?php echo $this->get_field_id('bare'); ?>" name="<?php echo $this->get_field_name('bare'); ?>" type="checkbox" <?php checked(isset($instance['bare']) ? $instance['bare'] : 0); ?> />&nbsp;<label for="<?php echo $this->get_field_id('bare'); ?>"><?php _e('Do not output before/after_widget/title'); ?></label></p>
124
- <p class="credits"><small>Developed by <a href="http://pomelodesign.com">Pomelo Design</a></small></p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  <?php
126
  }
127
  }
128
- function EnhancedTextWidgetInit() {
 
 
 
 
129
  register_widget('EnhancedTextWidget');
130
  }
131
 
132
- add_action('widgets_init', 'EnhancedTextWidgetInit');
133
- ?>
3
  Plugin Name: Enhanced Text Widget
4
  Plugin URI: http://pomelodesign.com/enhanced-text-widget
5
  Description: An enhanced version of the default text widget where you may have Text, HTML, CSS, JavaScript, Flash, and/or PHP as content with linkable widget title.
6
+ Version: 1.4
7
  Author: Pomelo Design
8
  Author URI: http://pomelodesign.com/
9
  License: GPL2
25
 
26
  class EnhancedTextWidget extends WP_Widget {
27
 
28
+ /**
29
+ * Widget construction
30
+ */
31
+ function __construct() {
32
+ $widget_ops = array('classname' => 'widget_text enhanced-text-widget', 'description' => __('Text, HTML, CSS, PHP, Flash, JavaScript, Shortcodes', 'enhancedtext'));
33
  $control_ops = array('width' => 400, 'height' => 350);
34
+ parent::__construct('EnhancedTextWidget', __('Enhanced Text', 'enhancedtext'), $widget_ops, $control_ops);
35
+ load_plugin_textdomain('enhancedtext', false, basename( dirname( __FILE__ ) ) . '/languages' );
36
  }
37
 
38
+ /**
39
+ * Setup the widget output
40
+ */
41
  function widget( $args, $instance ) {
42
+ $cache = wp_cache_get('EnhancedTextWidget', 'widget');
43
+
44
+ if (!is_array($cache)) {
45
+ $cache = array();
46
+ }
47
+
48
+ if (!isset($args['widget_id'])) {
49
+ $args['widget_id'] = null;
50
+ }
51
+
52
+ if (isset($cache[$args['widget_id']])) {
53
+ echo $cache[$args['widget_id']];
54
+ return;
55
+ }
56
+
57
+ ob_start();
58
  extract($args);
59
+
60
  $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance);
61
+ $titleUrl = empty($instance['titleUrl']) ? '' : $instance['titleUrl'];
62
+ $cssClass = empty($instance['cssClass']) ? '' : $instance['cssClass'];
63
+ $text = apply_filters('widget_text', $instance['text'], $instance);
64
+ $hideTitle = !empty($instance['hideTitle']) ? true : false;
65
+ $newWindow = !empty($instance['newWindow']) ? true : false;
66
+ $filterText = !empty($instance['filter']) ? true : false;
67
+ $bare = !empty($instance['bare']) ? true : false;
68
+
69
  if ( $cssClass ) {
70
  if( strpos($before_widget, 'class') === false ) {
71
  $before_widget = str_replace('>', 'class="'. $cssClass . '"', $before_widget);
73
  $before_widget = str_replace('class="', 'class="'. $cssClass . ' ', $before_widget);
74
  }
75
  }
76
+
77
  echo $bare ? '' : $before_widget;
78
+
79
+ if ($newWindow) $newWindow = "target='_blank'";
80
+
81
+ if(!$hideTitle && $title) {
82
+ if($titleUrl) $title = "<a href='$titleUrl' $newWindow>$title</a>";
83
+ echo $bare ? $title : $before_title . $title . $after_title;
 
84
  }
85
+
86
+ echo $bare ? '' : '<div class="textwidget widget-text">';
87
+
88
+ ob_start();
89
+ eval('?>' . $text);
90
+ $text = ob_get_contents();
91
+ ob_end_clean();
92
+ echo $filterText ? wpautop($text) : $text;
93
+
94
+ echo $bare ? '' : '</div>' . $after_widget;
95
+
96
+ $cache[$args['widget_id']] = ob_get_flush();
97
+ wp_cache_set('EnhancedTextWidget', $cache, 'widget');
 
98
  }
99
 
100
+ /**
101
+ * Run on widget update
102
+ */
103
  function update( $new_instance, $old_instance ) {
104
  $instance = $old_instance;
105
  $instance['title'] = strip_tags($new_instance['title']);
 
 
 
 
106
  if ( current_user_can('unfiltered_html') )
107
  $instance['text'] = $new_instance['text'];
108
  else
109
+ $instance['text'] = wp_filter_post_kses($new_instance['text']);
110
+ $instance['titleUrl'] = strip_tags($new_instance['titleUrl']);
111
+ $instance['cssClass'] = strip_tags($new_instance['cssClass']);
112
+ $instance['hideTitle'] = isset($new_instance['hideTitle']);
113
+ $instance['newWindow'] = isset($new_instance['newWindow']);
114
  $instance['filter'] = isset($new_instance['filter']);
115
  $instance['bare'] = isset($new_instance['bare']);
116
+
117
+ $this->flush_widget_cache();
118
+
119
+ $alloptions = wp_cache_get('alloptions', 'options');
120
+
121
+ if (isset($alloptions['EnhancedTextWidget'])) {
122
+ delete_option('EnhancedTextWidget');
123
+ }
124
+
125
  return $instance;
126
  }
127
 
128
+ /**
129
+ * Flush widget cache
130
+ */
131
+ function flush_widget_cache() {
132
+ wp_cache_delete('EnhancedTextWidget', 'widget');
133
+ }
134
+
135
+ /**
136
+ * Setup the widget admin form
137
+ */
138
  function form( $instance ) {
139
+ $instance = wp_parse_args( (array) $instance, array(
140
+ 'title' => '',
141
+ 'titleUrl' => '',
142
+ 'cssClass' => '',
143
+ 'text' => ''
144
+ ));
145
+ $title = $instance['title'];
146
+ $titleUrl = $instance['titleUrl'];
147
+ $cssClass = $instance['cssClass'];
148
+ $text = format_to_edit($instance['text']);
 
 
 
 
 
 
 
149
  ?>
150
+
151
+ <style>
152
+ .monospace { font-family: Consolas, Lucida Console, monospace; }
153
+ </style>
154
+
155
+ <p>
156
+ <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'enhancedtext'); ?>:</label>
157
+ <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; ?>" />
158
+ </p>
159
+
160
+ <p>
161
+ <label for="<?php echo $this->get_field_id('titleUrl'); ?>"><?php _e('URL', 'enhancedtext'); ?>:</label>
162
+ <input class="widefat" id="<?php echo $this->get_field_id('titleUrl'); ?>" name="<?php echo $this->get_field_name('titleUrl'); ?>" type="text" value="<?php echo $titleUrl; ?>" />
163
+ </p>
164
+
165
+ <p>
166
+ <label for="<?php echo $this->get_field_id('cssClass'); ?>"><?php _e('CSS Classes', 'enhancedtext'); ?>:</label>
167
+ <input class="widefat" id="<?php echo $this->get_field_id('cssClass'); ?>" name="<?php echo $this->get_field_name('cssClass'); ?>" type="text" value="<?php echo $cssClass; ?>" />
168
+ </p>
169
+
170
+ <p>
171
+ <label for="<?php echo $this->get_field_id('text'); ?>"><?php _e('Content', 'enhancedtext'); ?>:</label>
172
+ <textarea class="widefat monospace" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $text; ?></textarea>
173
+ </p>
174
+
175
+ <p>
176
+ <input id="<?php echo $this->get_field_id('hideTitle'); ?>" name="<?php echo $this->get_field_name('hideTitle'); ?>" type="checkbox" <?php checked(isset($instance['hideTitle']) ? $instance['hideTitle'] : 0); ?> />&nbsp;<label for="<?php echo $this->get_field_id('hideTitle'); ?>"><?php _e('Do not display the title', 'enhancedtext'); ?></label>
177
+ </p>
178
+
179
+ <p>
180
+ <input type="checkbox" id="<?php echo $this->get_field_id('newWindow'); ?>" name="<?php echo $this->get_field_name('newWindow'); ?>" <?php checked(isset($instance['newWindow']) ? $instance['newWindow'] : 0); ?> />
181
+ <label for="<?php echo $this->get_field_id('newWindow'); ?>"><?php _e('Open the URL in a new window', 'enhancedtext'); ?></label>
182
+ </p>
183
+
184
+ <p>
185
+ <input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked(isset($instance['filter']) ? $instance['filter'] : 0); ?> />&nbsp;<label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs to the content', 'enhancedtext'); ?></label>
186
+ </p>
187
+
188
+ <p>
189
+ <input id="<?php echo $this->get_field_id('bare'); ?>" name="<?php echo $this->get_field_name('bare'); ?>" type="checkbox" <?php checked(isset($instance['bare']) ? $instance['bare'] : 0); ?> />&nbsp;<label for="<?php echo $this->get_field_id('bare'); ?>"><?php _e('Do not output before/after_widget/title', 'enhancedtext'); ?></label>
190
+ </p>
191
+
192
+ <p class="credits"><small><?php _e('Developed by', 'enhancedtext'); ?> <a href="http://pomelodesign.com">Pomelo Design</a></small></p>
193
+
194
  <?php
195
  }
196
  }
197
+
198
+ /**
199
+ * Register the widget
200
+ */
201
+ function enhanced_text_widget_init() {
202
  register_widget('EnhancedTextWidget');
203
  }
204
 
205
+ add_action('widgets_init', 'enhanced_text_widget_init');
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://pomelodesign.com/donate/
4
  Tags: widget, clickable, linkable, linked title, text, php, javascript, flash, linked title text, linked, text widget, php widget, link widget title, bare widget, widget shortcodes
5
  Requires at least: 3.0
6
  Tested up to: 3.5.1
7
- Stable tag: 1.3.4
8
  License: GPL2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -27,6 +27,8 @@ Options:
27
 
28
  For support please [wordpress.org](http://wordpress.org/support/plugin/enhanced-text-widget). Visit [our website](http://pomelodesign.com), follow [@pomelod](http://twitter.com/pomelod/) or like [on facebook](http://www.facebook.com/pomelodesign/) for updates.
29
 
 
 
30
  == Installation ==
31
 
32
  1. Download and extract the zip archive
@@ -58,6 +60,10 @@ This is the initial release.
58
 
59
  == Changelog ==
60
 
 
 
 
 
61
  = 1.3.4 =
62
  * This adds option to hide the title
63
  * Tested up to 3.5.1
4
  Tags: widget, clickable, linkable, linked title, text, php, javascript, flash, linked title text, linked, text widget, php widget, link widget title, bare widget, widget shortcodes
5
  Requires at least: 3.0
6
  Tested up to: 3.5.1
7
+ Stable tag: 1.4
8
  License: GPL2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
27
 
28
  For support please [wordpress.org](http://wordpress.org/support/plugin/enhanced-text-widget). Visit [our website](http://pomelodesign.com), follow [@pomelod](http://twitter.com/pomelod/) or like [on facebook](http://www.facebook.com/pomelodesign/) for updates.
29
 
30
+ Fork or contribute on [Github](https://github.com/bostondv/enhanced-text-widget)
31
+
32
  == Installation ==
33
 
34
  1. Download and extract the zip archive
60
 
61
  == Changelog ==
62
 
63
+ = 1.4 =
64
+ * Display text field in monospace font
65
+ * Code refactoring
66
+
67
  = 1.3.4 =
68
  * This adds option to hide the title
69
  * Tested up to 3.5.1
screenshot-1.png CHANGED
Binary file