Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- /*
- Plugin Name: List blogs widget
- Plugin URI: http://wordpress.org/#
- Description: Show off all your blogs (public ones or not) in your sidebar
- Version: 1.0
- Author: Anton Lindqvist
- Author URI: http://qvister.se
- */
- /*
- Modified by Jukka Alander (kino@kolumbus.fi) 02.2009
- - Now supporting $before_title and $after_title tags
- */
- define(LIST_BLOGS_WIDGET_ID, 'widget_list_blogs');
- define(LIST_BLOGS_WIDGET_CACHE, 'widget_list_blogs_cache');
- define(LIST_BLOGS_WIDGET_CACHETIME, 'widget_list_blogs_cachetime');
- function order($x,$y) {
- if($x['blogname'] == $y['blogname']) return 0;
- return ($x['blogname'] < $y['blogname']) ? -1 : 1;
- }
- function list_blogs($private=false,$title=null,$force=false) {
- global $wpdb;
- if(get_option(LIST_BLOGS_WIDGET_CACHETIME) < time() - 3 || $force) {
- $title = (!$title) ? 'Blogs' : $title;
- $return = '<ul>';
- // $return = $title.'<ul>';
- // $return = '<h2>'.$title.'</h2></div><div class="indent"><div id="jepjep"><ul>';
- $query = 'select blog_id from '.$wpdb->blogs.' where archived=\'0\' and spam=\'0\' and deleted=\'0\' and blog_id > 1';
- $query .= (!$private) ? ' and public=\'1\'' : ' and public >= -1';
- $results = $wpdb->get_results($query);
- foreach($results as $row) {
- $blogname = get_blog_option($row->blog_id,'blogname');
- $siteurl = get_blog_option($row->blog_id,'siteurl');
- $blogs[] = array(
- 'id' => $row->blog_id,
- 'blogname' => $blogname,
- 'siteurl' => $siteurl
- );
- }
- usort($blogs,'order');
- foreach($blogs as $blog) {
- $return .= '<li id="id_'.$blog['id'].'"><a href="'.$blog['siteurl'].'" title="'.$blog['blogname'].'">'.$blog['blogname'].'</a></li>';
- }
- $return .= '</ul>';
- update_option(LIST_BLOGS_WIDGET_CACHE,$return);
- update_option(LIST_BLOGS_WIDGET_CACHETIME,time());
- if(!$force) {
- echo $return;
- } else {
- return;
- }
- } else {
- echo get_option(LIST_BLOGS_WIDGET_CACHE);
- }
- }
- function widget_list_blogs($args) {
- extract($args, EXTR_SKIP);
- $options = get_option(LIST_BLOGS_WIDGET_ID);
- $private = $options['private'];
- $title = 'Blogs';
- $title = $options['title'];
- // $before_widget = '<div class="widget" id="list_blogs"><div class="corner-bot"><div class="corner-top"></div><div class="title">';
- // $after_widget = '</div><div class="clear"/></div></div></div></div>';
- // $title = (!$title) ? 'Blogs' : $title;
- // $return = $title.'<ul>';
- //$title = 'Blogs';
- echo $before_widget;
- echo $before_title.$title.$after_title;
- list_blogs($private,$title,false,$before_title,$after_title);
- echo $after_widget;
- }
- function widget_list_blogs_init() {
- wp_register_sidebar_widget(LIST_BLOGS_WIDGET_ID,
- __('List blogs'),'widget_list_blogs');
- wp_register_widget_control(LIST_BLOGS_WIDGET_ID,
- __('List blogs'),'widget_list_blogs_control');
- }
- function widget_list_blogs_control() {
- $options = get_option(LIST_BLOGS_WIDGET_ID);
- if(!is_array($options)) {
- $options = array();
- }
- $widget_data = $_POST[LIST_BLOGS_WIDGET_ID];
- if($widget_data['submit']) {
- $options['private'] = $widget_data['private'];
- $options['title'] = $widget_data['title'];
- update_option(LIST_BLOGS_WIDGET_ID, $options);
- list_blogs($options['private'],$options['title'],true);
- }
- $title = $options['title'];
- $private = $options['private'];
- ?>
- <p>
- <label for="<?=LIST_BLOGS_WIDGET_ID;?>-title">Custom title:</label>
- <input class="widefat" type="text" name="<?=LIST_BLOGS_WIDGET_ID?>[title]" id="<?=LIST_BLOGS_WIDGET_ID?>-num-posts" value="<?=$title?>" />
- </p>
- <p>
- <label for="<?php echo LIST_BLOGS_WIDGET_ID;?>-private">Show private blogs:</label>
- <select class="widefat" name="<?=LIST_BLOGS_WIDGET_ID?>[private]" id="<?=LIST_BLOGS_WIDGET_ID?>-private">
- <option value="1" <?=($private == '1') ? 'selected' : ''?>>Yes</option>
- <option value="0" <?=($private == '1') ? '' : 'selected'?>>No</option>
- </select>
- </p>
- <input type="hidden" name="<?=LIST_BLOGS_WIDGET_ID?>[submit]" value="1" />
- <?
- }
- add_action('plugins_loaded','widget_list_blogs_init');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement