PluginProbe
Front End PM / trunk
Front End PM vtrunk
trunk 1.1 1.2 1.3 10.1.1 10.1.2 10.1.3 10.1.4 10.1.5 10.1.6 10.1.7 10.2.1 11.1.1 11.2.1 11.2.2 11.2.3 11.3.1 11.3.3 11.3.4 11.3.5 11.3.6 11.3.7 11.3.8 11.3.9 11.4.1 All 58 releases
front-end-pm / includes / fep-widgets.php

fep-widgets.php in Front End PM trunk, at includes/fep-widgets.php

271 lines 9.8 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; // Exit if accessed directly.
4 }
5
6 class FEP_menu_widget extends WP_Widget {
7 /**
8 * Register widget with WordPress.
9 */
10 function __construct() {
11 parent::__construct(
12 'fep_menu_widget', // Base ID
13 __( 'FEP Menu Widget', 'front-end-pm' ), // Name
14 array( 'description' => __( 'Front End PM Menu Widget', 'front-end-pm' ), ) // Args
15 );
16 }
17
18 /**
19 * Front-end display of widget.
20 *
21 * @see WP_Widget::widget()
22 *
23 * @param array $args Widget arguments.
24 * @param array $instance Saved values from database.
25 */
26 public function widget( $args, $instance ) {
27 echo $args['before_widget'];
28 if ( ! empty( $instance['title'] ) ) {
29 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
30 }
31
32 echo '<div id="fep-menu">';
33 do_action( 'fep_menu_button' );
34 echo '</div>';
35 echo $args['after_widget'];
36 }
37
38 /**
39 * Back-end widget form.
40 *
41 * @see WP_Widget::form()
42 *
43 * @param array $instance Previously saved values from database.
44 */
45 public function form( $instance ) {
46 $title = isset( $instance['title'] ) ? $instance['title'] : __( 'FEP Menu Widget', 'front-end-pm' );
47 ?>
48 <p>
49 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
50 <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 ); ?>">
51 </p>
52 <?php
53 }
54
55 /**
56 * Sanitize widget form values as they are saved.
57 *
58 * @see WP_Widget::update()
59 *
60 * @param array $new_instance Values just sent to be saved.
61 * @param array $old_instance Previously saved values from database.
62 *
63 * @return array Updated safe values to be saved.
64 */
65 public function update( $new_instance, $old_instance ) {
66 $instance = array();
67 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
68 return $instance;
69 }
70 }
71
72 // register FEP_menu_widget widget
73 function register_fep_menu_widget() {
74 if ( fep_current_user_can( 'access_message' ) ) {
75 register_widget( 'FEP_menu_widget' );
76 }
77 }
78 add_action( 'widgets_init', 'register_fep_menu_widget' );
79
80 class FEP_text_widget extends WP_Widget {
81 /**
82 * Register widget with WordPress.
83 */
84 function __construct() {
85 parent::__construct(
86 'fep_text_widget', // Base ID
87 __( 'FEP Text Widget', 'front-end-pm' ), // Name
88 array( 'description' => __( 'Front End PM Text Widget', 'front-end-pm' ), ) // Args
89 );
90 }
91
92 /**
93 * Front-end display of widget.
94 *
95 * @see WP_Widget::widget()
96 *
97 * @param array $args Widget arguments.
98 * @param array $instance Saved values from database.
99 */
100 public function widget( $args, $instance ) {
101 global $user_ID;
102 echo $args['before_widget'];
103 if ( ! empty( $instance['title'] ) ) {
104 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
105 }
106 $show_messagebox = isset( $instance['show_messagebox'] ) ? $instance['show_messagebox'] : false;
107 $show_announcement = isset( $instance['show_announcement'] ) ? $instance['show_announcement'] : false;
108
109 if ( $show_messagebox || $show_announcement ) {
110 echo __( 'Welcome', 'front-end-pm' ) . ' ' . fep_user_name( $user_ID ). '<br />';
111 echo __( 'You have', 'front-end-pm' );
112 if ( $show_messagebox ) {
113 echo ' ';
114 $unread_count = fep_get_new_message_number();
115 $sm = sprintf( _n( '%s message', '%s messages', $unread_count, 'front-end-pm'), number_format_i18n( $unread_count ) );
116 echo '<a href="' . fep_query_url('messagebox') . '"><span class="fep_unread_message_count_text">' . $sm . '</span></a>';
117 }
118 if ( $show_messagebox && $show_announcement ) {
119 echo ' ';
120 echo __( 'and', 'front-end-pm' );
121 }
122 if ( $show_announcement ) {
123 echo ' ';
124 $unread_ann_count = fep_get_new_announcement_number();
125 $sa = sprintf( _n( '%s announcement', '%s announcements', $unread_ann_count, 'front-end-pm' ), number_format_i18n( $unread_ann_count ) );
126 echo '<a href="' . fep_query_url('announcements') . '"><span class="fep_unread_announcement_count_text">' . $sa . '</span></a>';
127 }
128 echo ' ';
129 echo __( 'unread', 'front-end-pm' );
130 }
131 do_action( 'fep_text_widget' );
132 echo $args['after_widget'];
133 }
134
135 /**
136 * Back-end widget form.
137 *
138 * @see WP_Widget::form()
139 *
140 * @param array $instance Previously saved values from database.
141 */
142 public function form( $instance ) {
143 $title = isset( $instance['title'] ) ? $instance['title'] : __( 'FEP Text Widget', 'front-end-pm' );
144 $show_messagebox = isset( $instance['show_messagebox'] ) ? $instance['show_messagebox'] : false;
145 $show_announcement = isset( $instance['show_announcement'] ) ? $instance['show_announcement'] : false;
146 ?>
147 <p>
148 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
149 <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 ); ?>">
150 </p>
151 <p>
152 <input class="checkbox" type="checkbox" <?php checked( $show_messagebox, 1 ); ?> id="<?php echo $this->get_field_id( 'show_messagebox' ); ?>" name="<?php echo $this->get_field_name( 'show_messagebox' ); ?>" value="1"/>
153 <label for="<?php echo $this->get_field_id( 'show_messagebox' ); ?>"><?php _e( 'Show Messagebox?', 'front-end-pm' ); ?></label>
154 </p>
155 <p>
156 <input class="checkbox" type="checkbox" <?php checked( $show_announcement, 1 ); ?> id="<?php echo $this->get_field_id( 'show_announcement' ); ?>" name="<?php echo $this->get_field_name( 'show_announcement' ); ?>" value="1"/>
157 <label for="<?php echo $this->get_field_id( 'show_announcement' ); ?>"><?php _e( 'Show Announcement?', 'front-end-pm' ); ?></label>
158 </p>
159 <?php
160 }
161
162 /**
163 * Sanitize widget form values as they are saved.
164 *
165 * @see WP_Widget::update()
166 *
167 * @param array $new_instance Values just sent to be saved.
168 * @param array $old_instance Previously saved values from database.
169 *
170 * @return array Updated safe values to be saved.
171 */
172 public function update( $new_instance, $old_instance ) {
173 $instance = array();
174 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
175 $instance['show_messagebox'] = ( ! empty( $new_instance['show_messagebox'] ) ) ? strip_tags( $new_instance['show_messagebox'] ) : '';
176 $instance['show_announcement'] = ( ! empty( $new_instance['show_announcement'] ) ) ? strip_tags( $new_instance['show_announcement'] ) : '';
177 return $instance;
178 }
179 }
180
181 // register FEP_menu_widget widget
182 function register_fep_text_widget() {
183 if ( fep_current_user_can( 'access_message' ) ) {
184 register_widget( 'FEP_text_widget' );
185 }
186 }
187 add_action( 'widgets_init', 'register_fep_text_widget' );
188
189 class FEP_empty_widget extends WP_Widget {
190 /**
191 * Register widget with WordPress.
192 */
193 function __construct() {
194 parent::__construct(
195 'fep_empty_widget', // Base ID
196 __( 'FEP Empty Widget', 'front-end-pm' ), // Name
197 array( 'description' => __( 'Front End PM Empty Widget', 'front-end-pm' ), ) // Args
198 );
199 }
200
201 /**
202 * Front-end display of widget.
203 *
204 * @see WP_Widget::widget()
205 *
206 * @param array $args Widget arguments.
207 * @param array $instance Saved values from database.
208 */
209 public function widget( $args, $instance ) {
210 echo $args['before_widget'];
211 if ( ! empty( $instance['title'] ) ) {
212 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];
213 }
214 $show_help = isset( $instance['show_help'] ) ? $instance['show_help'] : false;
215 if ( $show_help ) {
216 _e( 'Use <code>add_action( \'fep_empty_widget_' . $this->number . '\', \'your_function\' );</code> to hook to ONLY this widget where \'your_function\' is your callback function.', 'front-end-pm' );
217 _e( '<br />Use <code>add_action(\'fep_empty_widget\', \'your_function\' );</code> to hook to all FEP Empty widget where \'your_function\' is your callback function', 'front-end-pm' );
218 }
219 do_action( 'fep_empty_widget_' . $this->number );
220 do_action( 'fep_empty_widget' );
221 echo $args['after_widget'];
222 }
223
224 /**
225 * Back-end widget form.
226 *
227 * @see WP_Widget::form()
228 *
229 * @param array $instance Previously saved values from database.
230 */
231 public function form( $instance ) {
232 $title = isset( $instance['title'] ) ? $instance['title'] : __( 'FEP Empty Widget', 'front-end-pm' );
233 $show_help = isset( $instance['show_help'] ) ? $instance['show_help'] : false;
234 ?>
235 <p>
236 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
237 <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 ); ?>">
238 </p>
239 <p>
240 <input class="checkbox" type="checkbox" <?php checked( $show_help, 1 ); ?> id="<?php echo $this->get_field_id( 'show_help' ); ?>" name="<?php echo $this->get_field_name( 'show_help' ); ?>" value="1"/>
241 <label for="<?php echo $this->get_field_id( 'show_help' ); ?>"><?php _e( 'Display help to configure this widget in front end?', 'front-end-pm'); ?></label>
242 </p>
243 <?php
244 }
245
246 /**
247 * Sanitize widget form values as they are saved.
248 *
249 * @see WP_Widget::update()
250 *
251 * @param array $new_instance Values just sent to be saved.
252 * @param array $old_instance Previously saved values from database.
253 *
254 * @return array Updated safe values to be saved.
255 */
256 public function update( $new_instance, $old_instance ) {
257 $instance = array();
258 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
259 $instance['show_help'] = ( ! empty( $new_instance['show_help'] ) ) ? strip_tags( $new_instance['show_help'] ) : '';
260 return $instance;
261 }
262 }
263
264 // register FEP_menu_widget widget
265 function register_fep_empty_widget() {
266 if ( fep_current_user_can( 'access_message' ) ) {
267 register_widget( 'FEP_empty_widget' );
268 }
269 }
270 add_action( 'widgets_init', 'register_fep_empty_widget' );
271