raw
mp-wp_genesis           1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * WordPress Dashboard Widget Administration Panel API
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 * @subpackage Administration
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /**
mp-wp_genesis 10 * Registers dashboard widgets.
mp-wp_genesis 11 *
mp-wp_genesis 12 * handles POST data, sets up filters.
mp-wp_genesis 13 *
mp-wp_genesis 14 * @since unknown
mp-wp_genesis 15 */
mp-wp_genesis 16 function wp_dashboard_setup() {
mp-wp_genesis 17 global $wp_registered_widgets, $wp_registered_widget_controls, $wp_dashboard_control_callbacks;
mp-wp_genesis 18 $wp_dashboard_control_callbacks = array();
mp-wp_genesis 19
mp-wp_genesis 20 $update = false;
mp-wp_genesis 21 $widget_options = get_option( 'dashboard_widget_options' );
mp-wp_genesis 22 if ( !$widget_options || !is_array($widget_options) )
mp-wp_genesis 23 $widget_options = array();
mp-wp_genesis 24
mp-wp_genesis 25 /* Register Widgets and Controls */
mp-wp_genesis 26
mp-wp_genesis 27 // Right Now
mp-wp_genesis 28 wp_add_dashboard_widget( 'dashboard_right_now', __( 'Right Now' ), 'wp_dashboard_right_now' );
mp-wp_genesis 29
mp-wp_genesis 30 // Recent Comments Widget
mp-wp_genesis 31 $recent_comments_title = __( 'Recent Comments' );
mp-wp_genesis 32 wp_add_dashboard_widget( 'dashboard_recent_comments', $recent_comments_title, 'wp_dashboard_recent_comments' );
mp-wp_genesis 33
mp-wp_genesis 34 // Incoming Links Widget
mp-wp_genesis 35 if ( !isset( $widget_options['dashboard_incoming_links'] ) || !isset( $widget_options['dashboard_incoming_links']['home'] ) || $widget_options['dashboard_incoming_links']['home'] != get_option('home') ) {
mp-wp_genesis 36 $update = true;
mp-wp_genesis 37 $widget_options['dashboard_incoming_links'] = array(
mp-wp_genesis 38 'home' => get_option('home'),
mp-wp_genesis 39 'link' => apply_filters( 'dashboard_incoming_links_link', 'http://blogsearch.google.com/blogsearch?hl=en&scoring=d&partner=wordpress&q=link:' . trailingslashit( get_option('home') ) ),
mp-wp_genesis 40 'url' => apply_filters( 'dashboard_incoming_links_feed', 'http://blogsearch.google.com/blogsearch_feeds?hl=en&scoring=d&ie=utf-8&num=10&output=rss&partner=wordpress&q=link:' . trailingslashit( get_option('home') ) ),
mp-wp_genesis 41 'items' => isset($widget_options['dashboard_incoming_links']['items']) ? $widget_options['dashboard_incoming_links']['items'] : 10,
mp-wp_genesis 42 'show_date' => isset($widget_options['dashboard_incoming_links']['show_date']) ? $widget_options['dashboard_incoming_links']['show_date'] : false
mp-wp_genesis 43 );
mp-wp_genesis 44 }
mp-wp_genesis 45 wp_add_dashboard_widget( 'dashboard_incoming_links', __( 'Incoming Links' ), 'wp_dashboard_incoming_links', 'wp_dashboard_incoming_links_control' );
mp-wp_genesis 46
mp-wp_genesis 47 // WP Plugins Widget
mp-wp_genesis 48 if ( current_user_can( 'activate_plugins' ) )
mp-wp_genesis 49 wp_add_dashboard_widget( 'dashboard_plugins', __( 'Plugins' ), 'wp_dashboard_plugins' );
mp-wp_genesis 50
mp-wp_genesis 51 // QuickPress Widget
mp-wp_genesis 52 if ( current_user_can('edit_posts') )
mp-wp_genesis 53 wp_add_dashboard_widget( 'dashboard_quick_press', __( 'QuickPress' ), 'wp_dashboard_quick_press' );
mp-wp_genesis 54
mp-wp_genesis 55 // Recent Drafts
mp-wp_genesis 56 if ( current_user_can('edit_posts') )
mp-wp_genesis 57 wp_add_dashboard_widget( 'dashboard_recent_drafts', __('Recent Drafts'), 'wp_dashboard_recent_drafts' );
mp-wp_genesis 58
mp-wp_genesis 59 // Primary feed (Dev Blog) Widget
mp-wp_genesis 60 if ( !isset( $widget_options['dashboard_primary'] ) ) {
mp-wp_genesis 61 $update = true;
mp-wp_genesis 62 $widget_options['dashboard_primary'] = array(
mp-wp_genesis 63 'link' => apply_filters( 'dashboard_primary_link', __( 'http://wordpress.org/development/' ) ),
mp-wp_genesis 64 'url' => apply_filters( 'dashboard_primary_feed', __( 'http://wordpress.org/development/feed/' ) ),
mp-wp_genesis 65 'title' => apply_filters( 'dashboard_primary_title', __( 'WordPress Development Blog' ) ),
mp-wp_genesis 66 'items' => 2,
mp-wp_genesis 67 'show_summary' => 1,
mp-wp_genesis 68 'show_author' => 0,
mp-wp_genesis 69 'show_date' => 1
mp-wp_genesis 70 );
mp-wp_genesis 71 }
mp-wp_genesis 72 wp_add_dashboard_widget( 'dashboard_primary', $widget_options['dashboard_primary']['title'], 'wp_dashboard_primary', 'wp_dashboard_primary_control' );
mp-wp_genesis 73
mp-wp_genesis 74 // Secondary Feed (Planet) Widget
mp-wp_genesis 75 if ( !isset( $widget_options['dashboard_secondary'] ) ) {
mp-wp_genesis 76 $update = true;
mp-wp_genesis 77 $widget_options['dashboard_secondary'] = array(
mp-wp_genesis 78 'link' => apply_filters( 'dashboard_secondary_link', __( 'http://planet.wordpress.org/' ) ),
mp-wp_genesis 79 'url' => apply_filters( 'dashboard_secondary_feed', __( 'http://planet.wordpress.org/feed/' ) ),
mp-wp_genesis 80 'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ),
mp-wp_genesis 81 'items' => 5
mp-wp_genesis 82 );
mp-wp_genesis 83 }
mp-wp_genesis 84 wp_add_dashboard_widget( 'dashboard_secondary', $widget_options['dashboard_secondary']['title'], 'wp_dashboard_secondary', 'wp_dashboard_secondary_control' );
mp-wp_genesis 85
mp-wp_genesis 86 // Hook to register new widgets
mp-wp_genesis 87 do_action( 'wp_dashboard_setup' );
mp-wp_genesis 88
mp-wp_genesis 89 // Filter widget order
mp-wp_genesis 90 $dashboard_widgets = apply_filters( 'wp_dashboard_widgets', array() );
mp-wp_genesis 91
mp-wp_genesis 92 foreach ( $dashboard_widgets as $widget_id ) {
mp-wp_genesis 93 $name = empty( $wp_registered_widgets[$widget_id]['all_link'] ) ? $wp_registered_widgets[$widget_id]['name'] : $wp_registered_widgets[$widget_id]['name'] . " <a href='{$wp_registered_widgets[$widget_id]['all_link']}' class='edit-box open-box'>" . __('View all') . '</a>';
mp-wp_genesis 94 wp_add_dashboard_widget( $widget_id, $name, $wp_registered_widgets[$widget_id]['callback'], $wp_registered_widget_controls[$widget_id]['callback'] );
mp-wp_genesis 95 }
mp-wp_genesis 96
mp-wp_genesis 97 if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget_id']) ) {
mp-wp_genesis 98 ob_start(); // hack - but the same hack wp-admin/widgets.php uses
mp-wp_genesis 99 wp_dashboard_trigger_widget_control( $_POST['widget_id'] );
mp-wp_genesis 100 ob_end_clean();
mp-wp_genesis 101 wp_redirect( remove_query_arg( 'edit' ) );
mp-wp_genesis 102 exit;
mp-wp_genesis 103 }
mp-wp_genesis 104
mp-wp_genesis 105 if ( $update )
mp-wp_genesis 106 update_option( 'dashboard_widget_options', $widget_options );
mp-wp_genesis 107
mp-wp_genesis 108 do_action('do_meta_boxes', 'dashboard', 'normal', '');
mp-wp_genesis 109 do_action('do_meta_boxes', 'dashboard', 'side', '');
mp-wp_genesis 110 }
mp-wp_genesis 111
mp-wp_genesis 112 function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null ) {
mp-wp_genesis 113 global $wp_dashboard_control_callbacks;
mp-wp_genesis 114 if ( $control_callback && current_user_can( 'edit_dashboard' ) && is_callable( $control_callback ) ) {
mp-wp_genesis 115 $wp_dashboard_control_callbacks[$widget_id] = $control_callback;
mp-wp_genesis 116 if ( isset( $_GET['edit'] ) && $widget_id == $_GET['edit'] ) {
mp-wp_genesis 117 list($url) = explode( '#', add_query_arg( 'edit', false ), 2 );
mp-wp_genesis 118 $widget_name .= ' <span class="postbox-title-action"><a href="' . clean_url( $url ) . '">' . __( 'Cancel' ) . '</a></span>';
mp-wp_genesis 119 add_meta_box( $widget_id, $widget_name, '_wp_dashboard_control_callback', 'dashboard', 'normal', 'core' );
mp-wp_genesis 120 return;
mp-wp_genesis 121 }
mp-wp_genesis 122 list($url) = explode( '#', add_query_arg( 'edit', $widget_id ), 2 );
mp-wp_genesis 123 $widget_name .= ' <span class="postbox-title-action"><a href="' . clean_url( "$url#$widget_id" ) . '" class="edit-box open-box">' . __( 'Configure' ) . '</a></span>';
mp-wp_genesis 124 }
mp-wp_genesis 125 $side_widgets = array('dashboard_quick_press', 'dashboard_recent_drafts', 'dashboard_primary', 'dashboard_secondary');
mp-wp_genesis 126 $location = 'normal';
mp-wp_genesis 127 if ( in_array($widget_id, $side_widgets) )
mp-wp_genesis 128 $location = 'side';
mp-wp_genesis 129 add_meta_box( $widget_id, $widget_name , $callback, 'dashboard', $location, 'core' );
mp-wp_genesis 130 }
mp-wp_genesis 131
mp-wp_genesis 132 function _wp_dashboard_control_callback( $dashboard, $meta_box ) {
mp-wp_genesis 133 echo '<form action="" method="post" class="dashboard-widget-control-form">';
mp-wp_genesis 134 wp_dashboard_trigger_widget_control( $meta_box['id'] );
mp-wp_genesis 135 echo "<p class='submit'><input type='hidden' name='widget_id' value='$meta_box[id]' /><input type='submit' value='" . __( 'Submit' ) . "' /></p>";
mp-wp_genesis 136
mp-wp_genesis 137 echo '</form>';
mp-wp_genesis 138 }
mp-wp_genesis 139
mp-wp_genesis 140 /**
mp-wp_genesis 141 * Displays the dashboard.
mp-wp_genesis 142 *
mp-wp_genesis 143 * @since unknown
mp-wp_genesis 144 */
mp-wp_genesis 145 function wp_dashboard() {
mp-wp_genesis 146 echo "<div id='dashboard-widgets' class='metabox-holder'>\n\n";
mp-wp_genesis 147
mp-wp_genesis 148 echo "<div id='side-info-column' class='inner-sidebar'>\n\n";
mp-wp_genesis 149 $class = do_meta_boxes( 'dashboard', 'side', '' ) ? ' class="has-sidebar"' : '';
mp-wp_genesis 150 echo "</div>\n\n";
mp-wp_genesis 151
mp-wp_genesis 152 echo "<div id='post-body'$class>\n\n";
mp-wp_genesis 153 echo "<div id='dashboard-widgets-main-content' class='has-sidebar-content'>\n\n";
mp-wp_genesis 154 do_meta_boxes( 'dashboard', 'normal', '' );
mp-wp_genesis 155 echo "</div>\n\n";
mp-wp_genesis 156 echo "</div>\n\n";
mp-wp_genesis 157
mp-wp_genesis 158 echo "<form style='display: none' method='get' action=''>\n<p>\n";
mp-wp_genesis 159 wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
mp-wp_genesis 160 wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
mp-wp_genesis 161 echo "</p>\n</form>\n";
mp-wp_genesis 162
mp-wp_genesis 163 echo "</div>";
mp-wp_genesis 164 }
mp-wp_genesis 165
mp-wp_genesis 166 /* Dashboard Widgets */
mp-wp_genesis 167
mp-wp_genesis 168 function wp_dashboard_right_now() {
mp-wp_genesis 169 $num_posts = wp_count_posts( 'post' );
mp-wp_genesis 170 $num_pages = wp_count_posts( 'page' );
mp-wp_genesis 171
mp-wp_genesis 172 $num_cats = wp_count_terms('category');
mp-wp_genesis 173
mp-wp_genesis 174 $num_tags = wp_count_terms('post_tag');
mp-wp_genesis 175
mp-wp_genesis 176 $num_comm = wp_count_comments( );
mp-wp_genesis 177
mp-wp_genesis 178 echo "\n\t".'<p class="sub">' . __('At a Glance') . '</p>';
mp-wp_genesis 179 echo "\n\t".'<div class="table">'."\n\t".'<table>';
mp-wp_genesis 180 echo "\n\t".'<tr class="first">';
mp-wp_genesis 181
mp-wp_genesis 182 // Posts
mp-wp_genesis 183 $num = number_format_i18n( $num_posts->publish );
mp-wp_genesis 184 if ( current_user_can( 'edit_posts' ) )
mp-wp_genesis 185 $text = "<a href='edit.php'>$num</a>";
mp-wp_genesis 186 else
mp-wp_genesis 187 $text = $num;
mp-wp_genesis 188 echo '<td class="first b b-posts">' . $text . '</td>';
mp-wp_genesis 189 echo '<td class="t posts">' . __ngettext( 'Post', 'Posts', intval($num_posts->publish) ) . '</td>';
mp-wp_genesis 190 /* TODO: Show status breakdown on hover
mp-wp_genesis 191 if ( $can_edit_pages && !empty($num_pages->publish) ) { // how many pages is not exposed in feeds. Don't show if !current_user_can
mp-wp_genesis 192 $post_type_texts[] = '<a href="edit-pages.php">'.sprintf( __ngettext( '%s page', '%s pages', $num_pages->publish ), number_format_i18n( $num_pages->publish ) ).'</a>';
mp-wp_genesis 193 }
mp-wp_genesis 194 if ( $can_edit_posts && !empty($num_posts->draft) ) {
mp-wp_genesis 195 $post_type_texts[] = '<a href="edit.php?post_status=draft">'.sprintf( __ngettext( '%s draft', '%s drafts', $num_posts->draft ), number_format_i18n( $num_posts->draft ) ).'</a>';
mp-wp_genesis 196 }
mp-wp_genesis 197 if ( $can_edit_posts && !empty($num_posts->future) ) {
mp-wp_genesis 198 $post_type_texts[] = '<a href="edit.php?post_status=future">'.sprintf( __ngettext( '%s scheduled post', '%s scheduled posts', $num_posts->future ), number_format_i18n( $num_posts->future ) ).'</a>';
mp-wp_genesis 199 }
mp-wp_genesis 200 if ( current_user_can('publish_posts') && !empty($num_posts->pending) ) {
mp-wp_genesis 201 $pending_text = sprintf( __ngettext( 'There is <a href="%1$s">%2$s post</a> pending your review.', 'There are <a href="%1$s">%2$s posts</a> pending your review.', $num_posts->pending ), 'edit.php?post_status=pending', number_format_i18n( $num_posts->pending ) );
mp-wp_genesis 202 } else {
mp-wp_genesis 203 $pending_text = '';
mp-wp_genesis 204 }
mp-wp_genesis 205 */
mp-wp_genesis 206
mp-wp_genesis 207 // Total Comments
mp-wp_genesis 208 $num = number_format_i18n($num_comm->total_comments);
mp-wp_genesis 209 if ( current_user_can( 'moderate_comments' ) )
mp-wp_genesis 210 $num = "<a href='edit-comments.php'>$num</a>";
mp-wp_genesis 211 echo '<td class="b b-comments">'.$num.'</td>';
mp-wp_genesis 212 echo '<td class="last t comments">' . __ngettext( 'Comment', 'Comments', $num_comm->total_comments ) . '</td>';
mp-wp_genesis 213
mp-wp_genesis 214 echo '</tr><tr>';
mp-wp_genesis 215
mp-wp_genesis 216 // Pages
mp-wp_genesis 217 $num = number_format_i18n( $num_pages->publish );
mp-wp_genesis 218 if ( current_user_can( 'edit_pages' ) )
mp-wp_genesis 219 $num = "<a href='edit-pages.php'>$num</a>";
mp-wp_genesis 220 echo '<td class="first b b_pages">'.$num.'</td>';
mp-wp_genesis 221 echo '<td class="t pages">' . __ngettext( 'Page', 'Pages', $num_pages->publish ) . '</td>';
mp-wp_genesis 222
mp-wp_genesis 223 // Approved Comments
mp-wp_genesis 224 $num = number_format_i18n($num_comm->approved);
mp-wp_genesis 225 if ( current_user_can( 'moderate_comments' ) )
mp-wp_genesis 226 $num = "<a href='edit-comments.php?comment_status=approved'>$num</a>";
mp-wp_genesis 227 echo '<td class="b b_approved">'.$num.'</td>';
mp-wp_genesis 228 echo '<td class="last t approved">' . __ngettext( 'Approved', 'Approved', $num_comm->approved ) . '</td>';
mp-wp_genesis 229
mp-wp_genesis 230 echo "</tr>\n\t<tr>";
mp-wp_genesis 231
mp-wp_genesis 232 // Categories
mp-wp_genesis 233 $num = number_format_i18n( $num_cats );
mp-wp_genesis 234 if ( current_user_can( 'manage_categories' ) )
mp-wp_genesis 235 $num = "<a href='categories.php'>$num</a>";
mp-wp_genesis 236 echo '<td class="first b b-cats">'.$num.'</td>';
mp-wp_genesis 237 echo '<td class="t cats">' . __ngettext( 'Category', 'Categories', $num_cats ) . '</td>';
mp-wp_genesis 238
mp-wp_genesis 239 // Pending Comments
mp-wp_genesis 240 $num = number_format_i18n($num_comm->moderated);
mp-wp_genesis 241 if ( current_user_can( 'moderate_comments' ) )
mp-wp_genesis 242 $num = "<a href='edit-comments.php?comment_status=moderated'><span class='pending-count'>$num</span></a>";
mp-wp_genesis 243 echo '<td class="b b-waiting">'.$num.'</td>';
mp-wp_genesis 244 echo '<td class="last t waiting">' . __ngettext( 'Pending', 'Pending', $num_comm->moderated ) . '</td>';
mp-wp_genesis 245
mp-wp_genesis 246 echo "</tr>\n\t<tr>";
mp-wp_genesis 247
mp-wp_genesis 248 // Tags
mp-wp_genesis 249 $num = number_format_i18n( $num_tags );
mp-wp_genesis 250 if ( current_user_can( 'manage_categories' ) )
mp-wp_genesis 251 $num = "<a href='edit-tags.php'>$num</a>";
mp-wp_genesis 252 echo '<td class="first b b-tags">'.$num.'</td>';
mp-wp_genesis 253 echo '<td class="t tags">' . __ngettext( 'Tag', 'Tags', $num_tags ) . '</td>';
mp-wp_genesis 254
mp-wp_genesis 255 // Spam Comments
mp-wp_genesis 256 $num = number_format_i18n($num_comm->spam);
mp-wp_genesis 257 if ( current_user_can( 'moderate_comments' ) )
mp-wp_genesis 258 $num = "<a href='edit-comments.php?comment_status=spam'><span class='spam-count'>$num</span></a>";
mp-wp_genesis 259 echo '<td class="b b-spam">'.$num.'</td>';
mp-wp_genesis 260 echo '<td class="last t spam">' . __ngettext( 'Spam', 'Spam', $num_comm->spam ) . '</td>';
mp-wp_genesis 261
mp-wp_genesis 262 echo "</tr>";
mp-wp_genesis 263 do_action('right_now_table_end');
mp-wp_genesis 264 echo "\n\t</table>\n\t</div>";
mp-wp_genesis 265
mp-wp_genesis 266 echo "\n\t".'<div class="versions">';
mp-wp_genesis 267 $ct = current_theme_info();
mp-wp_genesis 268 $sidebars_widgets = wp_get_sidebars_widgets();
mp-wp_genesis 269 $num_widgets = array_reduce( $sidebars_widgets, create_function( '$prev, $curr', 'return $prev+count($curr);' ), 0 );
mp-wp_genesis 270 $num = number_format_i18n( $num_widgets );
mp-wp_genesis 271
mp-wp_genesis 272 echo "\n\t<p>";
mp-wp_genesis 273 if ( current_user_can( 'switch_themes' ) ) {
mp-wp_genesis 274 echo '<a href="themes.php" class="button rbutton">' . __('Change Theme') . '</a>';
mp-wp_genesis 275 printf(__ngettext('Theme <span class="b"><a href="themes.php">%1$s</a></span> with <span class="b"><a href="widgets.php">%2$s Widget</a></span>', 'Theme <span class="b"><a href="themes.php">%1$s</a></span> with <span class="b"><a href="widgets.php">%2$s Widgets</a></span>', $num_widgets), $ct->title, $num);
mp-wp_genesis 276 } else {
mp-wp_genesis 277 printf(__ngettext('Theme <span class="b">%1$s</span> with <span class="b">%2$s Widget</span>', 'Theme <span class="b">%1$s</span> with <span class="b">%2$s Widgets</span>', $num_widgets), $ct->title, $num);
mp-wp_genesis 278 }
mp-wp_genesis 279
mp-wp_genesis 280 echo '</p>';
mp-wp_genesis 281
mp-wp_remove-tiny... 282 echo sprintf('<span id="wp-version-message">You are using <span class="b">WordPress %s</span></span>', $GLOBALS['wp_version']);
mp-wp_genesis 283
mp-wp_genesis 284 echo "\n\t".'</div>';
mp-wp_genesis 285 do_action( 'rightnow_end' );
mp-wp_genesis 286 do_action( 'activity_box_end' );
mp-wp_genesis 287 }
mp-wp_genesis 288
mp-wp_genesis 289 function wp_dashboard_quick_press() {
mp-wp_genesis 290 $drafts = false;
mp-wp_genesis 291 if ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['action'] ) && 0 === strpos( $_POST['action'], 'post-quickpress' ) && (int) $_POST['post_ID'] ) {
mp-wp_genesis 292 $view = get_permalink( $_POST['post_ID'] );
mp-wp_genesis 293 $edit = clean_url( get_edit_post_link( $_POST['post_ID'] ) );
mp-wp_genesis 294 if ( 'post-quickpress-publish' == $_POST['action'] ) {
mp-wp_genesis 295 if ( current_user_can('publish_posts') )
mp-wp_genesis 296 printf( '<div class="message"><p>' . __( 'Post Published. <a href="%s">View post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', clean_url( $view ), $edit );
mp-wp_genesis 297 else
mp-wp_genesis 298 printf( '<div class="message"><p>' . __( 'Post submitted. <a href="%s">Preview post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', clean_url( add_query_arg( 'preview', 1, $view ) ), $edit );
mp-wp_genesis 299 } else {
mp-wp_genesis 300 printf( '<div class="message"><p>' . __( 'Draft Saved. <a href="%s">Preview post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', clean_url( add_query_arg( 'preview', 1, $view ) ), $edit );
mp-wp_genesis 301 $drafts_query = new WP_Query( array(
mp-wp_genesis 302 'post_type' => 'post',
mp-wp_genesis 303 'what_to_show' => 'posts',
mp-wp_genesis 304 'post_status' => 'draft',
mp-wp_genesis 305 'author' => $GLOBALS['current_user']->ID,
mp-wp_genesis 306 'posts_per_page' => 1,
mp-wp_genesis 307 'orderby' => 'modified',
mp-wp_genesis 308 'order' => 'DESC'
mp-wp_genesis 309 ) );
mp-wp_genesis 310
mp-wp_genesis 311 if ( $drafts_query->posts )
mp-wp_genesis 312 $drafts =& $drafts_query->posts;
mp-wp_genesis 313 }
mp-wp_genesis 314 printf('<p class="textright">' . __('You can also try %s, easy blogging from anywhere on the Web.') . '</p>', '<a href="tools.php">' . __('Press This') . '</a>' );
mp-wp_genesis 315 $_REQUEST = array(); // hack for get_default_post_to_edit()
mp-wp_genesis 316 }
mp-wp_genesis 317
mp-wp_genesis 318 $post = get_default_post_to_edit();
mp-wp_genesis 319 ?>
mp-wp_genesis 320
mp-wp_genesis 321 <form name="post" action="<?php echo clean_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press">
mp-wp_genesis 322 <h4 id="quick-post-title"><label for="title"><?php _e('Title') ?></label></h4>
mp-wp_genesis 323 <div class="input-text-wrap">
mp-wp_genesis 324 <input type="text" name="post_title" id="title" tabindex="1" autocomplete="off" value="<?php echo attribute_escape( $post->post_title ); ?>" />
mp-wp_genesis 325 </div>
mp-wp_genesis 326
mp-wp_genesis 327 <?php if ( current_user_can( 'upload_files' ) ) : ?>
mp-wp_genesis 328 <div id="media-buttons" class="hide-if-no-js">
mp-wp_genesis 329 <?php do_action( 'media_buttons' ); ?>
mp-wp_genesis 330 </div>
mp-wp_genesis 331 <?php endif; ?>
mp-wp_genesis 332
mp-wp_genesis 333 <h4 id="content-label"><label for="content"><?php _e('Content') ?></label></h4>
mp-wp_genesis 334 <div class="textarea-wrap">
mp-wp_remove-tiny... 335 <textarea name="content" id="content" rows="3" cols="15" tabindex="2"><?php echo $post->post_content; ?></textarea>
mp-wp_genesis 336 </div>
mp-wp_genesis 337
mp-wp_genesis 338 <script type="text/javascript">edCanvas = document.getElementById('content');edInsertContent = null;</script>
mp-wp_genesis 339
mp-wp_genesis 340 <h4><label for="tags-input"><?php _e('Tags') ?></label></h4>
mp-wp_genesis 341 <div class="input-text-wrap">
mp-wp_genesis 342 <input type="text" name="tags_input" id="tags-input" tabindex="3" value="<?php echo get_tags_to_edit( $post->ID ); ?>" />
mp-wp_genesis 343 </div>
mp-wp_genesis 344
mp-wp_genesis 345 <p class="submit">
mp-wp_genesis 346 <input type="hidden" name="action" id="quickpost-action" value="post-quickpress-save" />
mp-wp_genesis 347 <input type="hidden" name="quickpress_post_ID" value="<?php echo (int) $post->ID; ?>" />
mp-wp_genesis 348 <?php wp_nonce_field('add-post'); ?>
mp-wp_genesis 349 <input type="submit" name="save" id="save-post" class="button" tabindex="4" value="<?php _e('Save Draft'); ?>" />
mp-wp_genesis 350 <input type="reset" value="<?php _e( 'Cancel' ); ?>" class="cancel" />
mp-wp_genesis 351 <?php if ( current_user_can('publish_posts') ) { ?>
mp-wp_genesis 352 <input type="submit" name="publish" id="publish" accesskey="p" tabindex="5" class="button-primary" value="<?php _e('Publish'); ?>" />
mp-wp_genesis 353 <?php } else { ?>
mp-wp_genesis 354 <input type="submit" name="publish" id="publish" accesskey="p" tabindex="5" class="button-primary" value="<?php _e('Submit for Review'); ?>" />
mp-wp_genesis 355 <?php } ?>
mp-wp_genesis 356 <br class="clear" />
mp-wp_genesis 357 </p>
mp-wp_genesis 358
mp-wp_genesis 359 </form>
mp-wp_genesis 360
mp-wp_genesis 361 <?php
mp-wp_genesis 362 if ( $drafts )
mp-wp_genesis 363 wp_dashboard_recent_drafts( $drafts );
mp-wp_genesis 364 }
mp-wp_genesis 365
mp-wp_genesis 366 function wp_dashboard_recent_drafts( $drafts = false ) {
mp-wp_genesis 367 if ( !$drafts ) {
mp-wp_genesis 368 $drafts_query = new WP_Query( array(
mp-wp_genesis 369 'post_type' => 'post',
mp-wp_genesis 370 'what_to_show' => 'posts',
mp-wp_genesis 371 'post_status' => 'draft',
mp-wp_genesis 372 'author' => $GLOBALS['current_user']->ID,
mp-wp_genesis 373 'posts_per_page' => 5,
mp-wp_genesis 374 'orderby' => 'modified',
mp-wp_genesis 375 'order' => 'DESC'
mp-wp_genesis 376 ) );
mp-wp_genesis 377 $drafts =& $drafts_query->posts;
mp-wp_genesis 378 }
mp-wp_genesis 379
mp-wp_genesis 380 if ( $drafts && is_array( $drafts ) ) {
mp-wp_genesis 381 $list = array();
mp-wp_genesis 382 foreach ( $drafts as $draft ) {
mp-wp_genesis 383 $url = get_edit_post_link( $draft->ID );
mp-wp_genesis 384 $title = _draft_or_post_title( $draft->ID );
mp-wp_genesis 385 $item = "<h4><a href='$url' title='" . sprintf( __( 'Edit "%s"' ), attribute_escape( $title ) ) . "'>$title</a> <abbr title='" . get_the_time(__('Y/m/d g:i:s A'), $draft) . "'>" . get_the_time( get_option( 'date_format' ), $draft ) . '</abbr></h4>';
mp-wp_genesis 386 if ( $the_content = preg_split( '#\s#', strip_tags( $draft->post_content ), 11, PREG_SPLIT_NO_EMPTY ) )
mp-wp_genesis 387 $item .= '<p>' . join( ' ', array_slice( $the_content, 0, 10 ) ) . ( 10 < count( $the_content ) ? '&hellip;' : '' ) . '</p>';
mp-wp_genesis 388 $list[] = $item;
mp-wp_genesis 389 }
mp-wp_genesis 390 ?>
mp-wp_genesis 391 <ul>
mp-wp_genesis 392 <li><?php echo join( "</li>\n<li>", $list ); ?></li>
mp-wp_genesis 393 </ul>
mp-wp_genesis 394 <p class="textright"><a href="edit.php?post_status=draft" class="button"><?php _e('View all'); ?></a></p>
mp-wp_genesis 395 <?php
mp-wp_genesis 396 } else {
mp-wp_genesis 397 _e('There are no drafts at the moment');
mp-wp_genesis 398 }
mp-wp_genesis 399 }
mp-wp_genesis 400
mp-wp_genesis 401 /**
mp-wp_genesis 402 * Display recent comments dashboard widget content.
mp-wp_genesis 403 *
mp-wp_genesis 404 * @since unknown
mp-wp_genesis 405 */
mp-wp_genesis 406 function wp_dashboard_recent_comments() {
mp-wp_genesis 407 global $wpdb;
mp-wp_genesis 408
mp-wp_genesis 409 if ( current_user_can('edit_posts') )
mp-wp_genesis 410 $allowed_states = array('0', '1');
mp-wp_genesis 411 else
mp-wp_genesis 412 $allowed_states = array('1');
mp-wp_genesis 413
mp-wp_genesis 414 // Select all comment types and filter out spam later for better query performance.
mp-wp_genesis 415 $comments = array();
mp-wp_genesis 416 $start = 0;
mp-wp_genesis 417
mp-wp_genesis 418 while ( count( $comments ) < 5 && $possible = $wpdb->get_results( "SELECT * FROM $wpdb->comments ORDER BY comment_date_gmt DESC LIMIT $start, 50" ) ) {
mp-wp_genesis 419
mp-wp_genesis 420 foreach ( $possible as $comment ) {
mp-wp_genesis 421 if ( count( $comments ) >= 5 )
mp-wp_genesis 422 break;
mp-wp_genesis 423 if ( in_array( $comment->comment_approved, $allowed_states ) )
mp-wp_genesis 424 $comments[] = $comment;
mp-wp_genesis 425 }
mp-wp_genesis 426
mp-wp_genesis 427 $start = $start + 50;
mp-wp_genesis 428 }
mp-wp_genesis 429
mp-wp_genesis 430 if ( $comments ) :
mp-wp_genesis 431 ?>
mp-wp_genesis 432
mp-wp_genesis 433 <div id="the-comment-list" class="list:comment">
mp-wp_genesis 434 <?php
mp-wp_genesis 435 foreach ( $comments as $comment )
mp-wp_genesis 436 _wp_dashboard_recent_comments_row( $comment );
mp-wp_genesis 437 ?>
mp-wp_genesis 438
mp-wp_genesis 439 </div>
mp-wp_genesis 440
mp-wp_genesis 441 <?php
mp-wp_genesis 442 if ( current_user_can('edit_posts') ) { ?>
mp-wp_genesis 443 <p class="textright"><a href="edit-comments.php" class="button"><?php _e('View all'); ?></a></p>
mp-wp_genesis 444 <?php }
mp-wp_genesis 445
mp-wp_genesis 446 wp_comment_reply( -1, false, 'dashboard', false );
mp-wp_genesis 447
mp-wp_genesis 448 else :
mp-wp_genesis 449 ?>
mp-wp_genesis 450
mp-wp_genesis 451 <p><?php _e( 'No comments yet.' ); ?></p>
mp-wp_genesis 452
mp-wp_genesis 453 <?php
mp-wp_genesis 454 endif; // $comments;
mp-wp_genesis 455 }
mp-wp_genesis 456
mp-wp_genesis 457 function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
mp-wp_genesis 458 $GLOBALS['comment'] =& $comment;
mp-wp_genesis 459
mp-wp_genesis 460 $comment_post_url = get_edit_post_link( $comment->comment_post_ID );
mp-wp_genesis 461 $comment_post_title = get_the_title( $comment->comment_post_ID );
mp-wp_genesis 462 $comment_post_link = "<a href='$comment_post_url'>$comment_post_title</a>";
mp-wp_genesis 463 $comment_link = '<a class="comment-link" href="' . get_comment_link() . '">#</a>';
mp-wp_genesis 464
mp-wp_genesis 465 $delete_url = clean_url( wp_nonce_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "delete-comment_$comment->comment_ID" ) );
mp-wp_genesis 466 $approve_url = clean_url( wp_nonce_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "approve-comment_$comment->comment_ID" ) );
mp-wp_genesis 467 $unapprove_url = clean_url( wp_nonce_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "unapprove-comment_$comment->comment_ID" ) );
mp-wp_genesis 468 $spam_url = clean_url( wp_nonce_url( "comment.php?action=deletecomment&dt=spam&p=$comment->comment_post_ID&c=$comment->comment_ID", "delete-comment_$comment->comment_ID" ) );
mp-wp_genesis 469
mp-wp_genesis 470 $actions = array();
mp-wp_genesis 471
mp-wp_genesis 472 $actions_string = '';
mp-wp_genesis 473 if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
mp-wp_genesis 474 $actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved vim-a' title='" . __( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
mp-wp_genesis 475 $actions['unapprove'] = "<a href='$unapprove_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved vim-u' title='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
mp-wp_genesis 476 $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . __('Edit comment') . "'>". __('Edit') . '</a>';
mp-wp_genesis 477 //$actions['quickedit'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$comment->comment_post_ID.'\',\'edit\');return false;" class="vim-q" title="'.__('Quick Edit').'" href="#">' . __('Quick&nbsp;Edit') . '</a>';
mp-wp_genesis 478 $actions['reply'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$comment->comment_post_ID.'\');return false;" class="vim-r hide-if-no-js" title="'.__('Reply to this comment').'" href="#">' . __('Reply') . '</a>';
mp-wp_genesis 479 $actions['spam'] = "<a href='$spam_url' class='delete:the-comment-list:comment-$comment->comment_ID::spam=1 vim-s vim-destructive' title='" . __( 'Mark this comment as spam' ) . "'>" . _c( 'Spam|verb' ) . '</a>';
mp-wp_genesis 480 $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Delete') . '</a>';
mp-wp_genesis 481
mp-wp_genesis 482 $actions = apply_filters( 'comment_row_actions', $actions, $comment );
mp-wp_genesis 483
mp-wp_genesis 484 $i = 0;
mp-wp_genesis 485 foreach ( $actions as $action => $link ) {
mp-wp_genesis 486 ++$i;
mp-wp_genesis 487 ( ( ('approve' == $action || 'unapprove' == $action) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
mp-wp_genesis 488
mp-wp_genesis 489 // Reply and quickedit need a hide-if-no-js span
mp-wp_genesis 490 if ( 'reply' == $action || 'quickedit' == $action )
mp-wp_genesis 491 $action .= ' hide-if-no-js';
mp-wp_genesis 492
mp-wp_genesis 493 $actions_string .= "<span class='$action'>$sep$link</span>";
mp-wp_genesis 494 }
mp-wp_genesis 495 }
mp-wp_genesis 496
mp-wp_genesis 497 ?>
mp-wp_genesis 498
mp-wp_genesis 499 <div id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status($comment->comment_ID) ) ); ?>>
mp-wp_genesis 500 <?php if ( !$comment->comment_type || 'comment' == $comment->comment_type ) : ?>
mp-wp_genesis 501
mp-wp_genesis 502 <?php echo get_avatar( $comment, 50 ); ?>
mp-wp_genesis 503 <h4 class="comment-meta"><?php printf( __( 'From %1$s on %2$s%3$s' ), '<cite class="comment-author">' . get_comment_author_link() . '</cite>', $comment_post_link." ".$comment_link, ' <span class="approve">' . __( '[Pending]' ) . '</span>' ); ?></h4>
mp-wp_genesis 504
mp-wp_genesis 505 <?php
mp-wp_genesis 506 else :
mp-wp_genesis 507 switch ( $comment->comment_type ) :
mp-wp_genesis 508 case 'pingback' :
mp-wp_genesis 509 $type = __( 'Pingback' );
mp-wp_genesis 510 break;
mp-wp_genesis 511 case 'trackback' :
mp-wp_genesis 512 $type = __( 'Trackback' );
mp-wp_genesis 513 break;
mp-wp_genesis 514 default :
mp-wp_genesis 515 $type = ucwords( $comment->comment_type );
mp-wp_genesis 516 endswitch;
mp-wp_genesis 517 $type = wp_specialchars( $type );
mp-wp_genesis 518 ?>
mp-wp_genesis 519
mp-wp_genesis 520 <h4 class="comment-meta"><?php printf( __( '%1$s on %2$s' ), "<strong>$type</strong>", $comment_post_link ); ?></h4>
mp-wp_genesis 521 <p class="comment-author"><?php comment_author_link(); ?></p>
mp-wp_genesis 522
mp-wp_genesis 523 <?php endif; // comment_type ?>
mp-wp_genesis 524 <blockquote><p><?php comment_excerpt(); ?></p></blockquote>
mp-wp_genesis 525 <p class="row-actions"><?php echo $actions_string; ?></p>
mp-wp_genesis 526
mp-wp_genesis 527 <div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden">
mp-wp_genesis 528 <textarea class="comment" rows="3" cols="10"><?php echo $comment->comment_content; ?></textarea>
mp-wp_genesis 529 <div class="author-email"><?php echo attribute_escape( $comment->comment_author_email ); ?></div>
mp-wp_genesis 530 <div class="author"><?php echo attribute_escape( $comment->comment_author ); ?></div>
mp-wp_genesis 531 <div class="author-url"><?php echo attribute_escape( $comment->comment_author_url ); ?></div>
mp-wp_genesis 532 <div class="comment_status"><?php echo $comment->comment_approved; ?></div>
mp-wp_genesis 533 </div>
mp-wp_genesis 534
mp-wp_genesis 535 </div>
mp-wp_genesis 536 <?php
mp-wp_genesis 537 }
mp-wp_genesis 538
mp-wp_genesis 539 function wp_dashboard_incoming_links() {
mp-wp_genesis 540 wp_dashboard_cached_rss_widget( 'dashboard_incoming_links', 'wp_dashboard_incoming_links_output' );
mp-wp_genesis 541 }
mp-wp_genesis 542
mp-wp_genesis 543 /**
mp-wp_genesis 544 * Display incoming links dashboard widget content.
mp-wp_genesis 545 *
mp-wp_genesis 546 * @since unknown
mp-wp_genesis 547 */
mp-wp_genesis 548 function wp_dashboard_incoming_links_output() {
mp-wp_genesis 549 $widgets = get_option( 'dashboard_widget_options' );
mp-wp_genesis 550 @extract( @$widgets['dashboard_incoming_links'], EXTR_SKIP );
mp-wp_genesis 551 $rss = @fetch_rss( $url );
mp-wp_genesis 552 if ( isset($rss->items) && 0 < count($rss->items) ) {
mp-wp_genesis 553
mp-wp_genesis 554 echo "<ul>\n";
mp-wp_genesis 555
mp-wp_genesis 556 $rss->items = array_slice($rss->items, 0, $items);
mp-wp_genesis 557 foreach ( $rss->items as $item ) {
mp-wp_genesis 558 $publisher = '';
mp-wp_genesis 559 $site_link = '';
mp-wp_genesis 560 $link = '';
mp-wp_genesis 561 $content = '';
mp-wp_genesis 562 $date = '';
mp-wp_genesis 563 $link = clean_url( strip_tags( $item['link'] ) );
mp-wp_genesis 564
mp-wp_genesis 565 if ( isset( $item['author_uri'] ) )
mp-wp_genesis 566 $site_link = clean_url( strip_tags( $item['author_uri'] ) );
mp-wp_genesis 567
mp-wp_genesis 568 if ( !$publisher = wp_specialchars( strip_tags( isset($item['dc']['publisher']) ? $item['dc']['publisher'] : $item['author_name'] ) ) )
mp-wp_genesis 569 $publisher = __( 'Somebody' );
mp-wp_genesis 570 if ( $site_link )
mp-wp_genesis 571 $publisher = "<a href='$site_link'>$publisher</a>";
mp-wp_genesis 572 else
mp-wp_genesis 573 $publisher = "<strong>$publisher</strong>";
mp-wp_genesis 574
mp-wp_genesis 575 if ( isset($item['description']) )
mp-wp_genesis 576 $content = $item['description'];
mp-wp_genesis 577 elseif ( isset($item['summary']) )
mp-wp_genesis 578 $content = $item['summary'];
mp-wp_genesis 579 elseif ( isset($item['atom_content']) )
mp-wp_genesis 580 $content = $item['atom_content'];
mp-wp_genesis 581 else
mp-wp_genesis 582 $content = __( 'something' );
mp-wp_genesis 583 $content = wp_html_excerpt($content, 50) . ' ...';
mp-wp_genesis 584 if ( $link )
mp-wp_genesis 585 $text = _c( '%1$s linked here <a href="%2$s">saying</a>, "%3$s"|feed_display' );
mp-wp_genesis 586 else
mp-wp_genesis 587 $text = _c( '%1$s linked here saying, "%3$s"|feed_display' );
mp-wp_genesis 588
mp-wp_genesis 589 if ( $show_date ) {
mp-wp_genesis 590 if ( $show_author || $show_summary )
mp-wp_genesis 591 $text .= _c( ' on %4$s|feed_display' );
mp-wp_genesis 592 $date = wp_specialchars( strip_tags( isset($item['pubdate']) ? $item['pubdate'] : $item['published'] ) );
mp-wp_genesis 593 $date = strtotime( $date );
mp-wp_genesis 594 $date = gmdate( get_option( 'date_format' ), $date );
mp-wp_genesis 595 }
mp-wp_genesis 596
mp-wp_genesis 597 echo "\t<li>" . sprintf( _c( "$text|feed_display" ), $publisher, $link, $content, $date ) . "</li>\n";
mp-wp_genesis 598 }
mp-wp_genesis 599
mp-wp_genesis 600 echo "</ul>\n";
mp-wp_genesis 601
mp-wp_genesis 602 } else {
mp-wp_genesis 603 echo '<p>' . __('This dashboard widget queries <a href="http://blogsearch.google.com/">Google Blog Search</a> so that when another blog links to your site it will show up here. It has found no incoming links&hellip; yet. It&#8217;s okay &#8212; there is no rush.') . "</p>\n";
mp-wp_genesis 604 }
mp-wp_genesis 605 }
mp-wp_genesis 606
mp-wp_genesis 607 function wp_dashboard_incoming_links_control() {
mp-wp_genesis 608 wp_dashboard_rss_control( 'dashboard_incoming_links', array( 'title' => false, 'show_summary' => false, 'show_author' => false ) );
mp-wp_genesis 609 }
mp-wp_genesis 610
mp-wp_genesis 611 function wp_dashboard_primary() {
mp-wp_genesis 612 wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_rss_output' );
mp-wp_genesis 613 }
mp-wp_genesis 614
mp-wp_genesis 615 function wp_dashboard_primary_control() {
mp-wp_genesis 616 wp_dashboard_rss_control( 'dashboard_primary' );
mp-wp_genesis 617 }
mp-wp_genesis 618
mp-wp_genesis 619 /**
mp-wp_genesis 620 * {@internal Missing Short Description}}
mp-wp_genesis 621 *
mp-wp_genesis 622 * @since unknown
mp-wp_genesis 623 *
mp-wp_genesis 624 * @param int $widget_id
mp-wp_genesis 625 */
mp-wp_genesis 626 function wp_dashboard_rss_output( $widget_id ) {
mp-wp_genesis 627 $widgets = get_option( 'dashboard_widget_options' );
mp-wp_genesis 628 echo "<div class='rss-widget'>";
mp-wp_genesis 629 wp_widget_rss_output( $widgets[$widget_id] );
mp-wp_genesis 630 echo "</div>";
mp-wp_genesis 631 }
mp-wp_genesis 632
mp-wp_genesis 633 function wp_dashboard_secondary() {
mp-wp_genesis 634 wp_dashboard_cached_rss_widget( 'dashboard_secondary', 'wp_dashboard_secondary_output' );
mp-wp_genesis 635 }
mp-wp_genesis 636
mp-wp_genesis 637 function wp_dashboard_secondary_control() {
mp-wp_genesis 638 wp_dashboard_rss_control( 'dashboard_secondary' );
mp-wp_genesis 639 }
mp-wp_genesis 640
mp-wp_genesis 641 /**
mp-wp_genesis 642 * Display secondary dashboard RSS widget feed.
mp-wp_genesis 643 *
mp-wp_genesis 644 * @since unknown
mp-wp_genesis 645 *
mp-wp_genesis 646 * @return unknown
mp-wp_genesis 647 */
mp-wp_genesis 648 function wp_dashboard_secondary_output() {
mp-wp_genesis 649 $widgets = get_option( 'dashboard_widget_options' );
mp-wp_genesis 650 @extract( @$widgets['dashboard_secondary'], EXTR_SKIP );
mp-wp_genesis 651 $rss = @fetch_rss( $url );
mp-wp_genesis 652
mp-wp_genesis 653 if ( !isset($rss->items) || 0 == count($rss->items) )
mp-wp_genesis 654 return false;
mp-wp_genesis 655
mp-wp_genesis 656 $rss->items = array_slice($rss->items, 0, $items);
mp-wp_genesis 657
mp-wp_genesis 658 if ( 'http://planet.wordpress.org/' == $rss->channel['link'] ) {
mp-wp_genesis 659 foreach ( array_keys($rss->items) as $i ) {
mp-wp_genesis 660 list($site, $description) = explode( ':', wp_specialchars($rss->items[$i]['title']), 2 );
mp-wp_genesis 661 $rss->items[$i]['dc']['creator'] = trim($site);
mp-wp_genesis 662 $rss->items[$i]['title'] = trim($description);
mp-wp_genesis 663 }
mp-wp_genesis 664 }
mp-wp_genesis 665
mp-wp_genesis 666 echo "<div class='rss-widget'>";
mp-wp_genesis 667 wp_widget_rss_output( $rss, $widgets['dashboard_secondary'] );
mp-wp_genesis 668 echo "</div>";
mp-wp_genesis 669 }
mp-wp_genesis 670
mp-wp_genesis 671 function wp_dashboard_plugins() {
mp-wp_genesis 672 wp_dashboard_cached_rss_widget( 'dashboard_plugins', 'wp_dashboard_plugins_output', array(
mp-wp_genesis 673 'http://wordpress.org/extend/plugins/rss/browse/popular/',
mp-wp_genesis 674 'http://wordpress.org/extend/plugins/rss/browse/new/',
mp-wp_genesis 675 'http://wordpress.org/extend/plugins/rss/browse/updated/'
mp-wp_genesis 676 ) );
mp-wp_genesis 677 }
mp-wp_genesis 678
mp-wp_genesis 679 /**
mp-wp_genesis 680 * Display plugins most popular, newest plugins, and recently updated widget text.
mp-wp_genesis 681 *
mp-wp_genesis 682 * @since unknown
mp-wp_genesis 683 */
mp-wp_genesis 684 function wp_dashboard_plugins_output() {
mp-wp_genesis 685 $popular = @fetch_rss( 'http://wordpress.org/extend/plugins/rss/browse/popular/' );
mp-wp_genesis 686 $new = @fetch_rss( 'http://wordpress.org/extend/plugins/rss/browse/new/' );
mp-wp_genesis 687 $updated = @fetch_rss( 'http://wordpress.org/extend/plugins/rss/browse/updated/' );
mp-wp_genesis 688
mp-wp_genesis 689 foreach ( array( 'popular' => __('Most Popular'), 'new' => __('Newest Plugins'), 'updated' => __('Recently Updated') ) as $feed => $label ) {
mp-wp_genesis 690 if ( !isset($$feed->items) || 0 == count($$feed->items) )
mp-wp_genesis 691 continue;
mp-wp_genesis 692
mp-wp_genesis 693 $$feed->items = array_slice($$feed->items, 0, 5);
mp-wp_genesis 694 $item_key = array_rand($$feed->items);
mp-wp_genesis 695
mp-wp_genesis 696 // Eliminate some common badly formed plugin descriptions
mp-wp_genesis 697 while ( ( null !== $item_key = array_rand($$feed->items) ) && false !== strpos( $$feed->items[$item_key]['description'], 'Plugin Name:' ) )
mp-wp_genesis 698 unset($$feed->items[$item_key]);
mp-wp_genesis 699
mp-wp_genesis 700 if ( !isset($$feed->items[$item_key]) )
mp-wp_genesis 701 continue;
mp-wp_genesis 702
mp-wp_genesis 703 $item = $$feed->items[$item_key];
mp-wp_genesis 704
mp-wp_genesis 705 // current bbPress feed item titles are: user on "topic title"
mp-wp_genesis 706 if ( preg_match( '/"(.*)"/s', $item['title'], $matches ) )
mp-wp_genesis 707 $title = $matches[1];
mp-wp_genesis 708 else // but let's make it forward compatible if things change
mp-wp_genesis 709 $title = $item['title'];
mp-wp_genesis 710 $title = wp_specialchars( $title );
mp-wp_genesis 711
mp-wp_genesis 712 $description = wp_specialchars( strip_tags(html_entity_decode($item['description'], ENT_QUOTES)) );
mp-wp_genesis 713
mp-wp_genesis 714 list($link, $frag) = explode( '#', $item['link'] );
mp-wp_genesis 715
mp-wp_genesis 716 $link = clean_url($link);
mp-wp_genesis 717 if( preg_match('|/([^/]+?)/?$|', $link, $matches) )
mp-wp_genesis 718 $slug = $matches[1];
mp-wp_genesis 719 else
mp-wp_genesis 720 $slug = '';
mp-wp_genesis 721
mp-wp_genesis 722 $ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) .
mp-wp_genesis 723 '&amp;TB_iframe=true&amp;width=600&amp;height=800';
mp-wp_genesis 724
mp-wp_genesis 725 echo "<h4>$label</h4>\n";
mp-wp_genesis 726 echo "<h5><a href='$link'>$title</a></h5>&nbsp;<span>(<a href='$ilink' class='thickbox' title='$title'>" . __( 'Install' ) . "</a>)</span>\n";
mp-wp_genesis 727 echo "<p>$description</p>\n";
mp-wp_genesis 728 }
mp-wp_genesis 729 }
mp-wp_genesis 730
mp-wp_genesis 731 /**
mp-wp_genesis 732 * Checks to see if all of the feed url in $check_urls are cached.
mp-wp_genesis 733 *
mp-wp_genesis 734 * If $check_urls is empty, look for the rss feed url found in the dashboard
mp-wp_genesis 735 * widget optios of $widget_id. If cached, call $callback, a function that
mp-wp_genesis 736 * echoes out output for this widget. If not cache, echo a "Loading..." stub
mp-wp_genesis 737 * which is later replaced by AJAX call (see top of /wp-admin/index.php)
mp-wp_genesis 738 *
mp-wp_genesis 739 * @since unknown
mp-wp_genesis 740 *
mp-wp_genesis 741 * @param int $widget_id
mp-wp_genesis 742 * @param callback $callback
mp-wp_genesis 743 * @param array $check_urls RSS feeds
mp-wp_genesis 744 * @return bool False on failure. True on success.
mp-wp_genesis 745 */
mp-wp_genesis 746 function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) {
mp-wp_genesis 747 $loading = '<p class="widget-loading">' . __( 'Loading&#8230;' ) . '</p>';
mp-wp_genesis 748
mp-wp_genesis 749 if ( empty($check_urls) ) {
mp-wp_genesis 750 $widgets = get_option( 'dashboard_widget_options' );
mp-wp_genesis 751 if ( empty($widgets[$widget_id]['url']) ) {
mp-wp_genesis 752 echo $loading;
mp-wp_genesis 753 return false;
mp-wp_genesis 754 }
mp-wp_genesis 755 $check_urls = array( $widgets[$widget_id]['url'] );
mp-wp_genesis 756 }
mp-wp_genesis 757
mp-wp_genesis 758
mp-wp_genesis 759 require_once( ABSPATH . WPINC . '/rss.php' );
mp-wp_genesis 760 init(); // initialize rss constants
mp-wp_genesis 761
mp-wp_genesis 762 $cache = new RSSCache( MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE );
mp-wp_genesis 763
mp-wp_genesis 764 foreach ( $check_urls as $check_url ) {
mp-wp_genesis 765 $status = $cache->check_cache( $check_url );
mp-wp_genesis 766 if ( 'HIT' !== $status ) {
mp-wp_genesis 767 echo $loading;
mp-wp_genesis 768 return false;
mp-wp_genesis 769 }
mp-wp_genesis 770 }
mp-wp_genesis 771
mp-wp_genesis 772 if ( $callback && is_callable( $callback ) ) {
mp-wp_genesis 773 $args = array_slice( func_get_args(), 2 );
mp-wp_genesis 774 array_unshift( $args, $widget_id );
mp-wp_genesis 775 call_user_func_array( $callback, $args );
mp-wp_genesis 776 }
mp-wp_genesis 777
mp-wp_genesis 778 return true;
mp-wp_genesis 779 }
mp-wp_genesis 780
mp-wp_genesis 781 /* Dashboard Widgets Controls */
mp-wp_genesis 782
mp-wp_genesis 783 // Calls widget_control callback
mp-wp_genesis 784 /**
mp-wp_genesis 785 * Calls widget control callback.
mp-wp_genesis 786 *
mp-wp_genesis 787 * @since unknown
mp-wp_genesis 788 *
mp-wp_genesis 789 * @param int $widget_control_id Registered Widget ID.
mp-wp_genesis 790 */
mp-wp_genesis 791 function wp_dashboard_trigger_widget_control( $widget_control_id = false ) {
mp-wp_genesis 792 global $wp_dashboard_control_callbacks;
mp-wp_genesis 793
mp-wp_genesis 794 if ( is_scalar($widget_control_id) && $widget_control_id && isset($wp_dashboard_control_callbacks[$widget_control_id]) && is_callable($wp_dashboard_control_callbacks[$widget_control_id]) ) {
mp-wp_genesis 795 call_user_func( $wp_dashboard_control_callbacks[$widget_control_id], '', array( 'id' => $widget_control_id, 'callback' => $wp_dashboard_control_callbacks[$widget_control_id] ) );
mp-wp_genesis 796 }
mp-wp_genesis 797 }
mp-wp_genesis 798
mp-wp_genesis 799 /**
mp-wp_genesis 800 * The RSS dashboard widget control.
mp-wp_genesis 801 *
mp-wp_genesis 802 * Sets up $args to be used as input to wp_widget_rss_form(). Handles POST data
mp-wp_genesis 803 * from RSS-type widgets.
mp-wp_genesis 804 *
mp-wp_genesis 805 * @since unknown
mp-wp_genesis 806 *
mp-wp_genesis 807 * @param string widget_id
mp-wp_genesis 808 * @param array form_inputs
mp-wp_genesis 809 */
mp-wp_genesis 810 function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
mp-wp_genesis 811 if ( !$widget_options = get_option( 'dashboard_widget_options' ) )
mp-wp_genesis 812 $widget_options = array();
mp-wp_genesis 813
mp-wp_genesis 814 if ( !isset($widget_options[$widget_id]) )
mp-wp_genesis 815 $widget_options[$widget_id] = array();
mp-wp_genesis 816
mp-wp_genesis 817 $number = 1; // Hack to use wp_widget_rss_form()
mp-wp_genesis 818 $widget_options[$widget_id]['number'] = $number;
mp-wp_genesis 819
mp-wp_genesis 820 if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-rss'][$number]) ) {
mp-wp_genesis 821 $_POST['widget-rss'][$number] = stripslashes_deep( $_POST['widget-rss'][$number] );
mp-wp_genesis 822 $widget_options[$widget_id] = wp_widget_rss_process( $_POST['widget-rss'][$number] );
mp-wp_genesis 823 // title is optional. If black, fill it if possible
mp-wp_genesis 824 if ( !$widget_options[$widget_id]['title'] && isset($_POST['widget-rss'][$number]['title']) ) {
mp-wp_genesis 825 require_once(ABSPATH . WPINC . '/rss.php');
mp-wp_genesis 826 $rss = fetch_rss($widget_options[$widget_id]['url']);
mp-wp_genesis 827 $widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->channel['title']));
mp-wp_genesis 828 }
mp-wp_genesis 829 update_option( 'dashboard_widget_options', $widget_options );
mp-wp_genesis 830 }
mp-wp_genesis 831
mp-wp_genesis 832 wp_widget_rss_form( $widget_options[$widget_id], $form_inputs );
mp-wp_genesis 833 }
mp-wp_genesis 834
mp-wp_genesis 835 /**
mp-wp_genesis 836 * Empty function usable by plugins to output empty dashboard widget (to be populated later by JS).
mp-wp_genesis 837 */
mp-wp_genesis 838 function wp_dashboard_empty() {}
mp-wp_genesis 839
mp-wp_genesis 840 ?>