AJAX loading of dashboard for slow stuff

git-svn-id: http://svn.automattic.com/wordpress/trunk@4484 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
matt 2006-11-18 23:12:39 +00:00
parent 80550746c6
commit 089d98d09c
2 changed files with 88 additions and 58 deletions

67
wp-admin/index-extra.php Normal file
View File

@ -0,0 +1,67 @@
<?php
require_once('admin.php');
require_once (ABSPATH . WPINC . '/rss.php');
switch ( $_GET['jax'] ) {
case 'incominglinks' :
$rss = @fetch_rss('http://feeds.technorati.com/cosmos/rss/?url='. trailingslashit(get_option('home')) .'&partner=wordpress');
if ( isset($rss->items) && 1 < count($rss->items) ) { // Technorati returns a 1-item feed when it has no results
?>
<h3><?php _e('Incoming Links'); ?> <cite><a href="http://www.technorati.com/search/<?php echo trailingslashit(get_option('home')); ?>?partner=wordpress"><?php _e('More &raquo;'); ?></a></cite></h3>
<ul>
<?php
$rss->items = array_slice($rss->items, 0, 10);
foreach ($rss->items as $item ) {
?>
<li><a href="<?php echo wp_filter_kses($item['link']); ?>"><?php echo wptexturize(wp_specialchars($item['title'])); ?></a></li>
<?php } ?>
</ul>
<?php
}
break;
case 'devnews' :
$rss = @fetch_rss('http://wordpress.org/development/feed/');
if ( isset($rss->items) && 0 != count($rss->items) ) {
?>
<h3><?php _e('WordPress Development Blog'); ?></h3>
<?php
$rss->items = array_slice($rss->items, 0, 3);
foreach ($rss->items as $item ) {
?>
<h4><a href='<?php echo wp_filter_kses($item['link']); ?>'><?php echo wp_specialchars($item['title']); ?></a> &#8212; <?php printf(__('%s ago'), human_time_diff(strtotime($item['pubdate'], time() ) ) ); ?></h4>
<p><?php echo $item['description']; ?></p>
<?php
}
}
?>
<?php
break;
case 'planetnews' :
$rss = @fetch_rss('http://planet.wordpress.org/feed/');
if ( isset($rss->items) && 0 != count($rss->items) ) {
?>
<h3><?php _e('Other WordPress News'); ?></h3>
<ul>
<?php
$rss->items = array_slice($rss->items, 0, 20);
foreach ($rss->items as $item ) {
$title = wp_specialchars($item['title']);
$author = preg_replace( '|(.+?):.+|s', '$1', $item['title'] );
$post = preg_replace( '|.+?:(.+)|s', '$1', $item['title'] );
?>
<li><a href='<?php echo wp_filter_kses($item['link']); ?>'><span class="post"><?php echo $post; ?></span><span class="hidden"> - </span><cite><?php echo $author; ?></cite></a></li>
<?php
}
?>
</ul>
<p class="readmore"><a href="http://planet.wordpress.org/"><?php _e('Read more'); ?> &raquo;</a></p>
<?php
}
break;
}
?>

View File

@ -1,9 +1,24 @@
<?php <?php
require_once('admin.php'); require_once('admin.php');
function index_js() {
?>
<script type="text/javascript">
Event.observe( window, 'load', dashboard_init, false );
function dashboard_init() {
var update1 = new Ajax.Updater( 'incominglinks', 'index-extra.php?jax=incominglinks' );
var update2 = new Ajax.Updater( 'devnews', 'index-extra.php?jax=devnews' );
var update3 = new Ajax.Updater( 'planetnews', 'index-extra.php?jax=planetnews' );
}
</script>
<?php
}
add_action( 'admin_head', 'index_js' );
wp_enqueue_script('prototype');
$title = __('Dashboard'); $title = __('Dashboard');
$parent_file = 'index.php'; $parent_file = 'index.php';
require_once('admin-header.php'); require_once('admin-header.php');
require_once (ABSPATH . WPINC . '/rss.php');
$today = current_time('mysql', 1); $today = current_time('mysql', 1);
?> ?>
@ -15,22 +30,7 @@ $today = current_time('mysql', 1);
<div id="zeitgeist"> <div id="zeitgeist">
<h2><?php _e('Latest Activity'); ?></h2> <h2><?php _e('Latest Activity'); ?></h2>
<?php <div id="incominglinks"></div>
$rss = @fetch_rss('http://feeds.technorati.com/cosmos/rss/?url='. trailingslashit(get_option('home')) .'&partner=wordpress');
if ( isset($rss->items) && 0 != count($rss->items) ) {
?>
<div id="incominglinks">
<h3><?php _e('Incoming Links'); ?> <cite><a href="http://www.technorati.com/search/<?php echo trailingslashit(get_option('home')); ?>?partner=wordpress"><?php _e('More &raquo;'); ?></a></cite></h3>
<ul>
<?php
$rss->items = array_slice($rss->items, 0, 10);
foreach ($rss->items as $item ) {
?>
<li><a href="<?php echo wp_filter_kses($item['link']); ?>"><?php echo wptexturize(wp_specialchars($item['title'])); ?></a></li>
<?php } ?>
</ul>
</div>
<?php } ?>
<?php <?php
$comments = $wpdb->get_results("SELECT comment_author, comment_author_url, comment_ID, comment_post_ID FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 5"); $comments = $wpdb->get_results("SELECT comment_author, comment_author_url, comment_ID, comment_post_ID FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 5");
@ -128,48 +128,11 @@ if (0 < $numcats) $numcats = number_format($numcats);
<?php endif; ?> <?php endif; ?>
</ul> </ul>
<p><?php _e("Need help with WordPress? Please see our <a href='http://codex.wordpress.org/'>documentation</a> or visit the <a href='http://wordpress.org/support/'>support forums</a>."); ?></p> <p><?php _e("Need help with WordPress? Please see our <a href='http://codex.wordpress.org/'>documentation</a> or visit the <a href='http://wordpress.org/support/'>support forums</a>."); ?></p>
<?php
$rss = @fetch_rss('http://wordpress.org/development/feed/');
if ( isset($rss->items) && 0 != count($rss->items) ) {
?>
<div id="devnews">
<h3><?php _e('WordPress Development Blog'); ?></h3>
<?php
$rss->items = array_slice($rss->items, 0, 3);
foreach ($rss->items as $item ) {
?>
<h4><a href='<?php echo wp_filter_kses($item['link']); ?>'><?php echo wp_specialchars($item['title']); ?></a> &#8212; <?php printf(__('%s ago'), human_time_diff(strtotime($item['pubdate'], time() ) ) ); ?></h4>
<p><?php echo $item['description']; ?></p>
<?php
}
}
?>
</div>
<?php <div id="devnews"></div>
$rss = @fetch_rss('http://planet.wordpress.org/feed/');
if ( isset($rss->items) && 0 != count($rss->items) ) { <div id="planetnews"></div>
?>
<div id="planetnews">
<h3><?php _e('Other WordPress News'); ?></h3>
<ul>
<?php
$rss->items = array_slice($rss->items, 0, 20);
foreach ($rss->items as $item ) {
$title = wp_specialchars($item['title']);
$author = preg_replace( '|(.+?):.+|s', '$1', $item['title'] );
$post = preg_replace( '|.+?:(.+)|s', '$1', $item['title'] );
?>
<li><a href='<?php echo wp_filter_kses($item['link']); ?>'><span class="post"><?php echo $post; ?></span><span class="hidden"> - </span><cite><?php echo $author; ?></cite></a></li>
<?php
}
?>
</ul>
<p class="readmore"><a href="http://planet.wordpress.org/"><?php _e('Read more'); ?> &raquo;</a></p>
</div>
<?php
}
?>
<div style="clear: both">&nbsp; <div style="clear: both">&nbsp;
<br clear="all" /> <br clear="all" />
</div> </div>