Advertisement
Guest User

kino

a guest
Mar 18th, 2009
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. <?
  2. /*
  3. Plugin Name: List blogs widget
  4. Plugin URI: http://wordpress.org/#
  5. Description: Show off all your blogs (public ones or not) in your sidebar
  6. Version: 1.0
  7. Author: Anton Lindqvist
  8. Author URI: http://qvister.se
  9. */
  10. /*
  11. Modified by Jukka Alander (kino@kolumbus.fi) 02.2009
  12. - Now supporting $before_title and $after_title tags
  13. */
  14.  
  15. define(LIST_BLOGS_WIDGET_ID, 'widget_list_blogs');
  16. define(LIST_BLOGS_WIDGET_CACHE, 'widget_list_blogs_cache');
  17. define(LIST_BLOGS_WIDGET_CACHETIME, 'widget_list_blogs_cachetime');
  18.  
  19. function order($x,$y) {
  20. if($x['blogname'] == $y['blogname']) return 0;
  21. return ($x['blogname'] < $y['blogname']) ? -1 : 1;
  22. }
  23. function list_blogs($private=false,$title=null,$force=false) {
  24. global $wpdb;
  25.  
  26. if(get_option(LIST_BLOGS_WIDGET_CACHETIME) < time() - 3 || $force) {
  27. $title = (!$title) ? 'Blogs' : $title;
  28. $return = '<ul>';
  29. // $return = $title.'<ul>';
  30. // $return = '<h2>'.$title.'</h2></div><div class="indent"><div id="jepjep"><ul>';
  31. $query = 'select blog_id from '.$wpdb->blogs.' where archived=\'0\' and spam=\'0\' and deleted=\'0\' and blog_id > 1';
  32. $query .= (!$private) ? ' and public=\'1\'' : ' and public >= -1';
  33. $results = $wpdb->get_results($query);
  34.  
  35. foreach($results as $row) {
  36. $blogname = get_blog_option($row->blog_id,'blogname');
  37. $siteurl = get_blog_option($row->blog_id,'siteurl');
  38. $blogs[] = array(
  39. 'id' => $row->blog_id,
  40. 'blogname' => $blogname,
  41. 'siteurl' => $siteurl
  42. );
  43. }
  44.  
  45. usort($blogs,'order');
  46.  
  47. foreach($blogs as $blog) {
  48. $return .= '<li id="id_'.$blog['id'].'"><a href="'.$blog['siteurl'].'" title="'.$blog['blogname'].'">'.$blog['blogname'].'</a></li>';
  49. }
  50.  
  51. $return .= '</ul>';
  52. update_option(LIST_BLOGS_WIDGET_CACHE,$return);
  53. update_option(LIST_BLOGS_WIDGET_CACHETIME,time());
  54.  
  55. if(!$force) {
  56. echo $return;
  57. } else {
  58. return;
  59. }
  60. } else {
  61. echo get_option(LIST_BLOGS_WIDGET_CACHE);
  62. }
  63. }
  64. function widget_list_blogs($args) {
  65. extract($args, EXTR_SKIP);
  66. $options = get_option(LIST_BLOGS_WIDGET_ID);
  67. $private = $options['private'];
  68. $title = 'Blogs';
  69. $title = $options['title'];
  70. // $before_widget = '<div class="widget" id="list_blogs"><div class="corner-bot"><div class="corner-top"></div><div class="title">';
  71. // $after_widget = '</div><div class="clear"/></div></div></div></div>';
  72.  
  73. // $title = (!$title) ? 'Blogs' : $title;
  74. // $return = $title.'<ul>';
  75. //$title = 'Blogs';
  76.  
  77.  
  78. echo $before_widget;
  79. echo $before_title.$title.$after_title;
  80. list_blogs($private,$title,false,$before_title,$after_title);
  81. echo $after_widget;
  82. }
  83. function widget_list_blogs_init() {
  84. wp_register_sidebar_widget(LIST_BLOGS_WIDGET_ID,
  85. __('List blogs'),'widget_list_blogs');
  86. wp_register_widget_control(LIST_BLOGS_WIDGET_ID,
  87. __('List blogs'),'widget_list_blogs_control');
  88. }
  89. function widget_list_blogs_control() {
  90. $options = get_option(LIST_BLOGS_WIDGET_ID);
  91.  
  92. if(!is_array($options)) {
  93. $options = array();
  94. }
  95.  
  96. $widget_data = $_POST[LIST_BLOGS_WIDGET_ID];
  97.  
  98. if($widget_data['submit']) {
  99. $options['private'] = $widget_data['private'];
  100. $options['title'] = $widget_data['title'];
  101. update_option(LIST_BLOGS_WIDGET_ID, $options);
  102. list_blogs($options['private'],$options['title'],true);
  103. }
  104.  
  105. $title = $options['title'];
  106. $private = $options['private'];
  107. ?>
  108. <p>
  109. <label for="<?=LIST_BLOGS_WIDGET_ID;?>-title">Custom title:</label>
  110. <input class="widefat" type="text" name="<?=LIST_BLOGS_WIDGET_ID?>[title]" id="<?=LIST_BLOGS_WIDGET_ID?>-num-posts" value="<?=$title?>" />
  111. </p>
  112. <p>
  113. <label for="<?php echo LIST_BLOGS_WIDGET_ID;?>-private">Show private blogs:</label>
  114. <select class="widefat" name="<?=LIST_BLOGS_WIDGET_ID?>[private]" id="<?=LIST_BLOGS_WIDGET_ID?>-private">
  115. <option value="1" <?=($private == '1') ? 'selected' : ''?>>Yes</option>
  116. <option value="0" <?=($private == '1') ? '' : 'selected'?>>No</option>
  117. </select>
  118. </p>
  119. <input type="hidden" name="<?=LIST_BLOGS_WIDGET_ID?>[submit]" value="1" />
  120. <?
  121. }
  122. add_action('plugins_loaded','widget_list_blogs_init');
  123. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement