Ta-da-bump.
I just lost half page of text on this so I'll be brief this time. :(
- Would you like WP widget to promote WPSE and/or your activity on it?
- What killer features would you like to see implemented?
Plan (wishful thinking):
- Decide on features.
- Code.
- Host in official repository.
- Promote via community ad.
Old code
So, here is my draft of widget. Feel free to suggest (or code in) improvements:
/*
Plugin Name: WP Answers Widget
Plugin URI: http://meta.wordpress.stackexchange.com/q/246/847
Description: Launch countdown and stats widget for WordPress Answers StackExchange site
Version: 0.1
Author: Andrey "Rarst" Savchenko
Author URI: http://www.Rarst.net
License: GPL2
*/
add_action( 'widgets_init', 'wpanswers_widget_init' );
function wpanswers_widget_init() {
register_widget( 'Widget_WP_Answers' );
}
class Widget_WP_Answers extends WP_Widget {
function Widget_WP_Answers() {
$widget_ops = array( 'classname' => 'wpanswers', 'description' => __('Launch countdown and stats widget for WordPress Answers StackExchange site') );
$this->WP_Widget( 'wpanswers', __('WordPress Answers'), $widget_ops );
}
function widget($args, $instance) {
extract($args);
echo $before_widget;
$beta = round ( ( strtotime( '2010-11-10' ) - time() ) / ( 60*60*24 ) );
$title = 'WordPress Answers';
if( $beta > 0 )
$title .= ' Beta';
echo $before_title . "<a href='http://wordpress.stackexchange.com/'>$title</a>" . $after_title;
echo '<ul>';
if( $beta > 0 )
echo "<li><strong>{$beta}</strong> days of beta left</li>";
$stats = $this->query_api( 'stats' );
$stats = $stats->statistics[0];
echo "<li><strong>{$stats->total_questions}</strong> questions</li>";
echo "<li><strong>{$stats->total_answers}<strong> answers</li>";
echo "<li><strong>{$stats->total_users}<strong> users</li>";
$hot = $this->query_api( 'questions', array( 'pagesize' => 10, 'sort' => 'month' ) );
$hot = $hot->questions;
shuffle( $hot );
$hot = array_slice( $hot, 0, 3 );
echo $before_title . "<a href='http://wordpress.stackexchange.com/?tab=month'>Hot questions</a>" . $after_title;
foreach ( $hot as $question) {
$answers = $question->answer_count > 0 ? " ({$question->answer_count} answers)" : '';
echo "<li><a href='http://wordpress.stackexchange.com/questions/{$question->question_id}'>{$question->title}{$answers}</a></li>";
}
echo '</ul>';
echo $after_widget;
}
function query_api( $method, $query = array(), $api = 'http://api.wordpress.stackexchange.com/1.0/' ) {
$url = $api . $method;
if( !empty($query) )
$url .= '?' . http_build_query( $query );
$response = get_transient( md5( $url ) );
if( false === $response ) {
$response = wp_remote_retrieve_body( wp_remote_get( $url) );
$response = json_decode( $response );
if( !empty( $response ) )
set_transient( md5( $url ), $response, 60*60*12 );
}
return $response;
}
}
open_betastatus in stats, but not expected dates so there is no way to adjust automatically. – Rarst♦ Oct 21 '10 at 7:15