PluginProbe
Edit Flow / 0.8
Edit Flow v0.8
0.11.1 0.11.0 0.7.2 0.7.3 0.7.4 0.7.5 0.7.6 0.8 0.8.1 0.8.2 0.9 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5 0.9.6 0.9.7 0.9.8 0.9.9 trunk 0.1.5 0.10.0 0.10.1 0.10.2 All 44 releases
edit-flow / modules / dashboard / dashboard.php

dashboard.php in Edit Flow 0.8, at modules/dashboard/dashboard.php

334 lines 11.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * class EF_Dashboard
4 * All of the code for the dashboard widgets from Edit Flow
5 *
6 * Dashboard widgets currently:
7 * - Post Status Widget - Shows numbers for all (custom|post) statuses
8 * - Posts I'm Following Widget - Show the headlines with edit links for posts I'm following
9 *
10 * @todo for 0.7
11 * - Update the Posts I'm Following widget to use new activity class
12 */
13
14 if ( !class_exists('EF_Dashboard') ) {
15
16 class EF_Dashboard extends EF_Module {
17
18 public $widgets;
19
20 /**
21 * Load the EF_Dashboard class as an Edit Flow module
22 */
23 function __construct() {
24 global $edit_flow;
25
26 // Register the module with Edit Flow
27 $this->module_url = $this->get_module_url( __FILE__ );
28 $args = array(
29 'title' => __( 'Dashboard Widgets', 'edit-flow' ),
30 'short_description' => __( 'Track your content from the WordPress dashboard.', 'edit-flow' ),
31 'extended_description' => __( 'Enable dashboard widgets to quickly get an overview of what state your content is in.', 'edit-flow' ),
32 'module_url' => $this->module_url,
33 'img_url' => $this->module_url . 'lib/dashboard_s128.png',
34 'slug' => 'dashboard',
35 'post_type_support' => 'ef_dashboard',
36 'default_options' => array(
37 'enabled' => 'on',
38 'post_status_widget' => 'on',
39 'my_posts_widget' => 'on',
40 'notepad_widget' => 'on',
41 ),
42 'configure_page_cb' => 'print_configure_view',
43 'configure_link_text' => __( 'Widget Options', 'edit-flow' ),
44 );
45 $this->module = EditFlow()->register_module( 'dashboard', $args );
46 }
47
48 /**
49 * Initialize all of the class' functionality if its enabled
50 */
51 function init() {
52
53 $this->widgets = new stdClass;
54
55 if ( 'on' == $this->module->options->notepad_widget ) {
56 require_once dirname( __FILE__ ) . '/widgets/dashboard-notepad.php';
57 $this->widgets->notepad_widget = new EF_Dashboard_Notepad_Widget;
58 $this->widgets->notepad_widget->init();
59 }
60
61 // Add the widgets to the dashboard
62 add_action( 'wp_dashboard_setup', array( $this, 'add_dashboard_widgets') );
63
64 // Register our settings
65 add_action( 'admin_init', array( $this, 'register_settings' ) );
66 }
67
68 /**
69 * Upgrade our data in case we need to
70 *
71 * @since 0.7
72 */
73 function upgrade( $previous_version ) {
74 global $edit_flow;
75
76 // Upgrade path to v0.7
77 if ( version_compare( $previous_version, '0.7' , '<' ) ) {
78 // Migrate whether dashboard widgets were enabled or not
79 if ( $enabled = get_option( 'edit_flow_dashboard_widgets_enabled' ) )
80 $enabled = 'on';
81 else
82 $enabled = 'off';
83 $edit_flow->update_module_option( $this->module->name, 'enabled', $enabled );
84 delete_option( 'edit_flow_dashboard_widgets_enabled' );
85 // Migrate whether the post status widget was on
86 if ( $post_status_widget = get_option( 'edit_flow_post_status_widget_enabled' ) )
87 $post_status_widget = 'on';
88 else
89 $post_status_widget = 'off';
90 $edit_flow->update_module_option( $this->module->name, 'post_status_widget', $post_status_widget );
91 delete_option( 'edit_flow_post_status_widget_enabled' );
92 // Migrate whether the my posts widget was on
93 if ( $my_posts_widget = get_option( 'edit_flow_myposts_widget_enabled' ) )
94 $my_posts_widget = 'on';
95 else
96 $my_posts_widget = 'off';
97 $edit_flow->update_module_option( $this->module->name, 'post_status_widget', $my_posts_widget );
98 delete_option( 'edit_flow_myposts_widget_enabled' );
99 // Delete legacy option
100 delete_option( 'edit_flow_quickpitch_widget_enabled' );
101
102 // Technically we've run this code before so we don't want to auto-install new data
103 $edit_flow->update_module_option( $this->module->name, 'loaded_once', true );
104 }
105
106 }
107
108 /**
109 * Add Edit Flow dashboard widgets to the WordPress admin dashboard
110 */
111 function add_dashboard_widgets() {
112
113 // Only show dashboard widgets for Contributor or higher
114 if ( !current_user_can('edit_posts') )
115 return;
116
117 wp_enqueue_style( 'edit-flow-dashboard-css', $this->module_url . 'lib/dashboard.css', false, EDIT_FLOW_VERSION, 'all' );
118
119 // Set up Post Status widget but, first, check to see if it's enabled
120 if ( $this->module->options->post_status_widget == 'on')
121 wp_add_dashboard_widget( 'post_status_widget', __( 'Unpublished Content', 'edit-flow' ), array( $this, 'post_status_widget' ) );
122
123 // Set up the Notepad widget if it's enabled
124 if ( 'on' == $this->module->options->notepad_widget )
125 wp_add_dashboard_widget( 'notepad_widget', __( 'Notepad', 'edit-flow' ), array( $this->widgets->notepad_widget, 'notepad_widget' ) );
126
127 // Add the MyPosts widget, if enabled
128 if ( $this->module->options->my_posts_widget == 'on' && $this->module_enabled( 'notifications' ) )
129 wp_add_dashboard_widget( 'myposts_widget', __( 'Posts I\'m Following', 'edit-flow' ), array( $this, 'myposts_widget' ) );
130
131 }
132
133 /**
134 * Creates Post Status widget
135 * Display an at-a-glance view of post counts for all (post|custom) statuses in the system
136 *
137 * @todo Support custom post types
138 */
139 function post_status_widget () {
140 global $edit_flow;
141
142 $statuses = $this->get_post_statuses();
143 $statuses[] = (object)array(
144 'name' => __( 'Scheduled', 'edit-flow' ),
145 'description' => '',
146 'slug' => 'future',
147 );
148 $statuses = apply_filters( 'ef_dashboard_post_status_widget_statuses', $statuses );
149 // If custom statuses are enabled, we'll output a link to edit the terms just below the post counts
150 if ( $this->module_enabled( 'custom_status' ) )
151 $edit_custom_status_url = add_query_arg( 'page', 'ef-custom-status-settings', get_admin_url( null, 'admin.php' ) );
152
153 ?>
154 <p class="sub"><?php _e('Posts at a Glance', 'edit-flow') ?></p>
155
156 <div class="table">
157 <table>
158 <tbody>
159 <?php $post_count = wp_count_posts( 'post' ); ?>
160 <?php foreach($statuses as $status) : ?>
161 <?php $filter_link = $this->filter_posts_link( $status->slug ); ?>
162 <tr>
163 <td class="b">
164 <a href="<?php echo esc_url( $filter_link ); ?>">
165 <?php
166 $slug = $status->slug;
167 echo esc_html( $post_count->$slug ); ?>
168 </a>
169 </td>
170 <td>
171 <a href="<?php echo esc_url( $filter_link ); ?>"><?php echo esc_html( $status->name ); ?></a>
172 </td>
173 </tr>
174
175 <?php endforeach; ?>
176 </tbody>
177 </table>
178 <?php if ( isset( $edit_custom_status_url ) ) : ?>
179 <span class="small"><a href="<?php echo esc_url( $edit_custom_status_url ); ?>"><?php _e( 'Edit Custom Statuses', 'edit-flow' ); ?></a></span>
180 <?php endif; ?>
181 </div>
182 <?php
183 }
184
185 /**
186 * Creates My Posts widget
187 * Shows a list of the "posts you're following" sorted by most recent activity.
188 */
189 function myposts_widget() {
190 global $edit_flow;
191
192 $myposts = $edit_flow->notifications->get_user_following_posts();
193
194 ?>
195 <div class="ef-myposts">
196 <?php if( !empty($myposts) ) : ?>
197
198 <?php foreach( $myposts as $post ) : ?>
199 <?php
200 $url = esc_url(get_edit_post_link( $post->ID ));
201 $title = esc_html($post->post_title);
202 ?>
203 <li>
204 <h4><a href="<?php echo $url ?>" title="<?php _e('Edit this post', 'edit-flow') ?>"><?php echo $title; ?></a></h4>
205 <span class="ef-myposts-timestamp"><?php _e('This post was last updated on', 'edit-flow') ?> <?php echo get_the_time('F j, Y \\a\\t g:i a', $post) ?></span>
206 </li>
207 <?php endforeach; ?>
208 <?php else : ?>
209 <p><?php _e('Sorry! You\'re not subscribed to any posts!', 'edit-flow') ?></p>
210 <?php endif; ?>
211 </div>
212 <?php
213 }
214
215 /**
216 * Register settings for notifications so we can partially use the Settings API
217 * (We use the Settings API for form generation, but not saving)
218 *
219 * @since 0.7
220 */
221 function register_settings() {
222
223 add_settings_section( $this->module->options_group_name . '_general', false, '__return_false', $this->module->options_group_name );
224 add_settings_field( 'post_status_widget', __( 'Post Status Widget', 'edit-flow' ), array( $this, 'settings_post_status_widget_option' ), $this->module->options_group_name, $this->module->options_group_name . '_general' );
225 add_settings_field( 'my_posts_widget',__( 'Posts I\'m Following', 'edit-flow' ), array( $this, 'settings_my_posts_widget_option' ), $this->module->options_group_name, $this->module->options_group_name . '_general' );
226 add_settings_field( 'notepad_widget',__( 'Notepad', 'edit-flow' ), array( $this, 'settings_notepad_widget_option' ), $this->module->options_group_name, $this->module->options_group_name . '_general' );
227
228 }
229
230 /**
231 * Enable or disable the Post Status Widget for the WP dashboard
232 *
233 * @since 0.7
234 */
235 function settings_post_status_widget_option() {
236 $options = array(
237 'off' => __( 'Disabled', 'edit-flow' ),
238 'on' => __( 'Enabled', 'edit-flow' ),
239 );
240 echo '<select id="post_status_widget" name="' . $this->module->options_group_name . '[post_status_widget]">';
241 foreach ( $options as $value => $label ) {
242 echo '<option value="' . esc_attr( $value ) . '"';
243 echo selected( $this->module->options->post_status_widget, $value );
244 echo '>' . esc_html( $label ) . '</option>';
245 }
246 echo '</select>';
247 }
248
249 /**
250 * Enable or disable the Posts I'm Following Widget for the WP dashboard
251 *
252 * @since 0.7
253 */
254 function settings_my_posts_widget_option() {
255 global $edit_flow;
256 $options = array(
257 'off' => __( 'Disabled', 'edit-flow' ),
258 'on' => __( 'Enabled', 'edit-flow' ),
259 );
260 echo '<select id="my_posts_widget" name="' . $this->module->options_group_name . '[my_posts_widget]"';
261 // Notifications module has to be enabled for the My Posts widget to work
262 if ( !$this->module_enabled('notifications') ) {
263 echo ' disabled="disabled"';
264 $this->module->options->my_posts_widget = 'off';
265 }
266 echo '>';
267 foreach ( $options as $value => $label ) {
268 echo '<option value="' . esc_attr( $value ) . '"';
269 echo selected( $this->module->options->my_posts_widget, $value );
270 echo '>' . esc_html( $label ) . '</option>';
271 }
272 echo '</select>';
273 if ( !$this->module_enabled('notifications') ) {
274 echo '&nbsp;&nbsp;&nbsp;<span class="description">' . __( 'The notifications module will need to be enabled for this widget to display.', 'edit-flow' );
275 }
276 }
277
278 /**
279 * Enable or disable the Notepad widget for the dashboard
280 *
281 * @since 0.8
282 */
283 function settings_notepad_widget_option() {
284 $options = array(
285 'off' => __( 'Disabled', 'edit-flow' ),
286 'on' => __( 'Enabled', 'edit-flow' ),
287 );
288 echo '<select id="notepad_widget" name="' . $this->module->options_group_name . '[notepad_widget]">';
289 foreach ( $options as $value => $label ) {
290 echo '<option value="' . esc_attr( $value ) . '"';
291 echo selected( $this->module->options->notepad_widget, $value );
292 echo '>' . esc_html( $label ) . '</option>';
293 }
294 echo '</select>';
295 }
296
297 /**
298 * Validate the field submitted by the user
299 *
300 * @since 0.7
301 */
302 function settings_validate( $new_options ) {
303
304 // Follow whitelist validation for modules
305 if ( array_key_exists( 'post_status_widget', $new_options ) && $new_options['post_status_widget'] != 'on' )
306 $new_options['post_status_widget'] = 'off';
307
308 if ( array_key_exists( 'my_posts_widget', $new_options ) && $new_options['my_posts_widget'] != 'on' )
309 $new_options['my_posts_widget'] = 'off';
310
311 return $new_options;
312 }
313
314 /**
315 * Settings page for the dashboard
316 *
317 * @since 0.7
318 */
319 function print_configure_view() {
320 ?>
321 <form class="basic-settings" action="<?php echo esc_url( menu_page_url( $this->module->settings_slug, false ) ); ?>" method="post">
322 <?php settings_fields( $this->module->options_group_name ); ?>
323 <?php do_settings_sections( $this->module->options_group_name ); ?>
324 <?php
325 echo '<input id="edit_flow_module_name" name="edit_flow_module_name" type="hidden" value="' . esc_attr( $this->module->name ) . '" />';
326 ?>
327 <p class="submit"><?php submit_button( null, 'primary', 'submit', false ); ?><a class="cancel-settings-link" href="<?php echo EDIT_FLOW_SETTINGS_PAGE; ?>"><?php _e( 'Back to Edit Flow', 'edit-flow' ); ?></a></p>
328 </form>
329 <?php
330 }
331 }
332
333 } // END - !class_exists('EF_Dashboard')
334