PluginProbe
Edit Flow / 0.7.4
Edit Flow v0.7.4
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.7.4, at modules/dashboard/dashboard.php

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