Subversion

PopularityWidget

[/] [popularity-contest-widget.php] - Rev 2

Compare with Previous - Blame


<?php
/*
Plugin Name: Popularity Contest Widget
Plugin URI: http://tech.sobriquet.net
Description: A widget to display the most popular posts. Requires <a href="http://alexking.org/">Alex King</a>'s Popularity Contest plugin
Version: 1.01
Author: Richard Rosalion
Author URI: http://tech.sobriquet.net
*/

function popularity_widget($args) {
    
extract($args);

    
$options get_option('popularityWidget');
    
$title $options['title'];

        echo 
"<!-- Start popularityWidget -->\n";
    echo 
$before_widget $before_title $title $after_title "\n";
    if( !
function_exists('akpc_most_popular') ) {
        echo 
"   <p>You don't appear to have the Popularity Contest plugin installed.</p>\n";
    } else {
// Code to display in sidebar goes after here,
// leave closing and opening php tags intact
?>
   <ul>
   <?php akpc_most_popular(); ?>
   </ul>
<?php
// end of sidebar code
    
}
    echo 
$after_widget"\n";
        echo 
"<!-- End popularityWidget -->";
}

function 
popularity_widget_control() {
    
$options get_option('popularityWidget');

    if ( !
is_array($options) )
        
$options = array('title' => 'Most Popular Posts');

    if ( 
$_POST['popularitySubmit'] ) {
        
$options['title'] = htmlentities(stripslashes($_POST['popularityTitle']));
        
update_option('popularityWidget'$options);
    }
    
    
$title htmlspecialchars($options['title'], ENT_QUOTES);
    
    echo 
'
        <p style="text-align:right;">
            <label for="popularityTitle">Title:
                <input style="width: 200px;" id="popularityTitle" name="popularityTitle" type="text" value="'
.$title.'" />
            </label>
        </p>
    <input type="hidden" id="popularitySubmit" name="popularitySubmit" value="1" />
    '
;
}

function 
popularity_widget_init() {
    if ( !
function_exists('register_sidebar_widget') )
        return;
    
    
register_sidebar_widget(__('Popularity Contest'NRTD), 'popularity_widget'null'popular-posts');
    
register_widget_control(__('Popularity Contest'NRTD), 'popularity_widget_control'300100'popular-posts');
}

add_action('plugins_loaded''popularity_widget_init');

?>

Powered by WebSVN v2.0rc4