PluginProbe
Front End PM / 7.3
Front End PM v7.3
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 7.3, at includes/fep-widgets.php

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