| 1 | Index: wp-includes/widgets.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-includes/widgets.php (revision 6294) |
|---|
| 4 | +++ wp-includes/widgets.php (working copy) |
|---|
| 5 | @@ -527,6 +527,181 @@ |
|---|
| 6 | <?php |
|---|
| 7 | } |
|---|
| 8 | |
|---|
| 9 | +function wp_widget_bgbookmarks($args, $number = 1) { |
|---|
| 10 | + extract($args, EXTR_SKIP); |
|---|
| 11 | + |
|---|
| 12 | + $options = get_option('widget_bgbookmarks'); |
|---|
| 13 | + |
|---|
| 14 | + $linkcat_id = $options[$number]['linkcat_id']; |
|---|
| 15 | + $showdesc = $options[$number]['showdesc']; |
|---|
| 16 | + $bydate = $options[$number]['bydate']; |
|---|
| 17 | + |
|---|
| 18 | + $linkcat_name = get_term_field('name', $linkcat_id, 'link_category'); |
|---|
| 19 | + |
|---|
| 20 | + $bookmark_args = array( |
|---|
| 21 | + 'title_before' => $before_title, 'title_after' => $after_title, |
|---|
| 22 | + 'category_before' => $before_widget, 'category_after' => $after_widget, |
|---|
| 23 | + 'show_images' => true, 'class' => 'linkcat widget', |
|---|
| 24 | + 'categorize' => 0, |
|---|
| 25 | + 'category_name' => $linkcat_name, 'category' => $linkcat_id, |
|---|
| 26 | + 'show_description' => $showdesc |
|---|
| 27 | + ); |
|---|
| 28 | + |
|---|
| 29 | + if ($bydate) { |
|---|
| 30 | + $bookmark_args['orderby'] = 'id'; |
|---|
| 31 | + $bookmark_args['order'] = 'DESC'; |
|---|
| 32 | + $bookmark_args['limit'] = 10; // xxx parameterize |
|---|
| 33 | + } |
|---|
| 34 | + |
|---|
| 35 | + $bookmark_args['title_li'] = $linkcat_name; |
|---|
| 36 | + |
|---|
| 37 | + wp_list_bookmarks($bookmark_args); |
|---|
| 38 | +} |
|---|
| 39 | + |
|---|
| 40 | +function wp_widget_bgbookmarks_register() { |
|---|
| 41 | + $options = get_option('widget_bgbookmarks'); |
|---|
| 42 | + if (!isset($options['number'])) |
|---|
| 43 | + $options = wp_widget_bgbookmarks_upgrade(); |
|---|
| 44 | + $number = (int) $options['number']; |
|---|
| 45 | + |
|---|
| 46 | + if ( $number > 9 ) { |
|---|
| 47 | + $number = 9; |
|---|
| 48 | + } elseif ( $number < 1 ) { |
|---|
| 49 | + $number = 1; |
|---|
| 50 | + } |
|---|
| 51 | + |
|---|
| 52 | + $dims = array( 'width' => 350, 'height' => 170 ); |
|---|
| 53 | + $class = array( 'classname' => 'widget_bgbookmarks' ); |
|---|
| 54 | + |
|---|
| 55 | + for ( $i = 1; $i <= 9; $i++ ) { |
|---|
| 56 | + $name = sprintf( __( 'BGBookmarks %d' ), $i ); |
|---|
| 57 | + $id = 'bgbookmarks-' . $i; |
|---|
| 58 | + |
|---|
| 59 | + $widget_callback = ( $i <= $number ) ? 'wp_widget_bgbookmarks' : ''; |
|---|
| 60 | + $control_callback = ( $i <= $number ) ? 'wp_widget_bgbookmarks_control' : ''; |
|---|
| 61 | + |
|---|
| 62 | + wp_register_sidebar_widget( $id, $name, $widget_callback, $class, $i ); |
|---|
| 63 | + wp_register_widget_control( $id, $name, $control_callback, $dims, $i ); |
|---|
| 64 | + } |
|---|
| 65 | + |
|---|
| 66 | + add_action( 'sidebar_admin_setup', 'wp_widget_bgbookmarks_setup' ); |
|---|
| 67 | + add_action( 'sidebar_admin_page', 'wp_widget_bgbookmarks_page' ); |
|---|
| 68 | +} |
|---|
| 69 | + |
|---|
| 70 | +function wp_widget_bgbookmarks_setup() { |
|---|
| 71 | + $options = $newoptions = get_option( 'widget_bgbookmarks' ); |
|---|
| 72 | + |
|---|
| 73 | + if ( isset( $_POST['bgbookmarks-number-submit'] ) ) { |
|---|
| 74 | + $number = (int) $_POST['bgbookmarks-number']; |
|---|
| 75 | + |
|---|
| 76 | + if ( $number > 9 ) { |
|---|
| 77 | + $number = 9; |
|---|
| 78 | + } elseif ( $number < 1 ) { |
|---|
| 79 | + $number = 1; |
|---|
| 80 | + } |
|---|
| 81 | + |
|---|
| 82 | + $newoptions['number'] = $number; |
|---|
| 83 | + } |
|---|
| 84 | + |
|---|
| 85 | + if ( $newoptions != $options ) { |
|---|
| 86 | + $options = $newoptions; |
|---|
| 87 | + update_option( 'widget_bgbookmarks', $options ); |
|---|
| 88 | + wp_widget_bgbookmarks_register( $options['number'] ); |
|---|
| 89 | + } |
|---|
| 90 | +} |
|---|
| 91 | + |
|---|
| 92 | +function wp_widget_bgbookmarks_page() { |
|---|
| 93 | + $options = get_option( 'widget_bgbookmarks' ); |
|---|
| 94 | +?> |
|---|
| 95 | + <div class="wrap"> |
|---|
| 96 | + <form method="post"> |
|---|
| 97 | + <h2><?php _e( 'BGBookmarks Widgets' ); ?></h2> |
|---|
| 98 | + <p style="line-height: 30px;"><?php _e( 'How many bgbookmarks widgets would you like?' ); ?> |
|---|
| 99 | + <select id="bgbookmarks-number" name="bgbookmarks-number" value="<?php echo attribute_escape( $options['number'] ); ?>"> |
|---|
| 100 | + <?php |
|---|
| 101 | + for ( $i = 1; $i < 10; $i++ ) { |
|---|
| 102 | + echo '<option value="' . $i . '"' . ( $i == $options['number'] ? ' selected="selected"' : '' ) . '>' . $i . "</option>\n"; |
|---|
| 103 | + } |
|---|
| 104 | + ?> |
|---|
| 105 | + </select> |
|---|
| 106 | + <span class="submit"> |
|---|
| 107 | + <input type="submit" value="<?php echo attribute_escape( __( 'Save' ) ); ?>" id="bgbookmarks-number-submit" name="bgbookmarks-number-submit" /> |
|---|
| 108 | + </span> |
|---|
| 109 | + </p> |
|---|
| 110 | + </form> |
|---|
| 111 | + </div> |
|---|
| 112 | +<?php |
|---|
| 113 | +} |
|---|
| 114 | + |
|---|
| 115 | +function wp_widget_bgbookmarks_upgrade() { |
|---|
| 116 | + $options = get_option( 'widget_bgbookmarks' ); |
|---|
| 117 | + |
|---|
| 118 | + $newoptions = array( 'number' => 1, 1 => $options ); |
|---|
| 119 | + |
|---|
| 120 | + update_option( 'widget_bgbookmarks', $newoptions ); |
|---|
| 121 | + |
|---|
| 122 | + $sidebars_widgets = get_option( 'sidebars_widgets' ); |
|---|
| 123 | + if ( is_array( $sidebars_widgets ) ) { |
|---|
| 124 | + foreach ( $sidebars_widgets as $sidebar => $widgets ) { |
|---|
| 125 | + if ( is_array( $widgets ) ) { |
|---|
| 126 | + foreach ( $widgets as $widget ) |
|---|
| 127 | + $new_widgets[$sidebar][] = ( $widget == 'bgbookmarks' ) ? 'bgbookmarks-1' : $widget; |
|---|
| 128 | + } else { |
|---|
| 129 | + $new_widgets[$sidebar] = $widgets; |
|---|
| 130 | + } |
|---|
| 131 | + } |
|---|
| 132 | + if ( $new_widgets != $sidebars_widgets ) |
|---|
| 133 | + update_option( 'sidebars_widgets', $new_widgets ); |
|---|
| 134 | + } |
|---|
| 135 | + |
|---|
| 136 | + if ( isset( $_POST['bgbookmarks-submit'] ) ) { |
|---|
| 137 | + $_POST['bgbookmarks-submit-1'] = $_POST['bgbookmarks-submit']; |
|---|
| 138 | + $_POST['bgbookmarks-linkcat_id-1'] = $_POST['bgbookmarks-linkcat_id']; |
|---|
| 139 | + $_POST['bgbookmarks-showdesc-1'] = $_POST['bgbookmarks-showdesc']; |
|---|
| 140 | + $_POST['bgbookmarks-bydate-1'] = $_POST['bgbookmarks-bydate']; |
|---|
| 141 | + } |
|---|
| 142 | + |
|---|
| 143 | + return $newoptions; |
|---|
| 144 | +} |
|---|
| 145 | + |
|---|
| 146 | +function wp_widget_bgbookmarks_control($number) { |
|---|
| 147 | + $options = $newoptions = get_option('widget_bgbookmarks'); |
|---|
| 148 | + if ($_POST["bgbookmarks-submit-$number"]) { |
|---|
| 149 | + $newoptions[$number]['linkcat_id'] = $_POST["bgbookmarks-linkcat_id-$number"]; |
|---|
| 150 | + $newoptions[$number]['showdesc'] = isset($_POST["bgbookmarks-showdesc-$number"]); |
|---|
| 151 | + $newoptions[$number]['bydate'] = isset($_POST["bgbookmarks-bydate-$number"]); |
|---|
| 152 | + } |
|---|
| 153 | + if ($options != $newoptions) { |
|---|
| 154 | + $options = $newoptions; |
|---|
| 155 | + update_option('widget_bgbookmarks', $options); |
|---|
| 156 | + } |
|---|
| 157 | + $linkcat_id = $options[$number]['linkcat_id']; |
|---|
| 158 | + $showdesc = $options[$number]['showdesc']; |
|---|
| 159 | + $bydate = $options[$number]['bydate']; |
|---|
| 160 | +?> |
|---|
| 161 | + <p> |
|---|
| 162 | + <label for="bgbookmarks-linkcat_id-<?php echo $number; ?>"> |
|---|
| 163 | + <?php _e('Category:'); ?> <select id="bgbookmarks-linkcat_id-<?php echo $number; ?>" name="bgbookmarks-linkcat_id-<?php echo $number; ?>"> |
|---|
| 164 | + <?php foreach (get_categories('type=link') as $linkcat) { $linkcat_id = $linkcat->term_id; $linkcat_name = $linkcat->name; echo "<option value=\"$linkcat_id\">$linkcat_name ($linkcat_id)</option>"; } ?> |
|---|
| 165 | + </select> |
|---|
| 166 | + </label></p> |
|---|
| 167 | + </p> |
|---|
| 168 | + <p> |
|---|
| 169 | + <label for="bgbookmarks-showdesc-<?php echo $number; ?>"> |
|---|
| 170 | + <input type="checkbox" class="checkbox" id="bgbookmarks-showdesc-<?php echo $number; ?>" name="bgbookmarks-showdesc-<?php echo $number; ?>" <?php echo $showdesc ? 'checked="checked"' : ''; ?> /> |
|---|
| 171 | + <?php _e('Show descriptions'); ?> |
|---|
| 172 | + </label> |
|---|
| 173 | + </p> |
|---|
| 174 | + <p> |
|---|
| 175 | + <label for="bgbookmarks-bydate-<?php echo $number; ?>"> |
|---|
| 176 | + <input type="checkbox" class="checkbox" id="bgbookmarks-bydate-<?php echo $number; ?>" name="bgbookmarks-bydate-<?php echo $number; ?>" <?php echo $bydate ? 'checked="checked"' : ''; ?> /> |
|---|
| 177 | + <?php _e('Order by date'); ?> |
|---|
| 178 | + </label> |
|---|
| 179 | + </p> |
|---|
| 180 | + <input type="hidden" id="bgbookmarks-submit-<?php echo $number; ?>" name="bgbookmarks-submit-<?php echo $number; ?>" value="1" /> |
|---|
| 181 | +<?php |
|---|
| 182 | +} |
|---|
| 183 | + |
|---|
| 184 | function wp_widget_text($args, $number = 1) { |
|---|
| 185 | extract($args); |
|---|
| 186 | $options = get_option('widget_text'); |
|---|
| 187 | @@ -1158,6 +1333,7 @@ |
|---|
| 188 | wp_widget_text_register(); |
|---|
| 189 | wp_widget_rss_register(); |
|---|
| 190 | wp_widget_recent_comments_register(); |
|---|
| 191 | + wp_widget_bgbookmarks_register(); |
|---|
| 192 | |
|---|
| 193 | $GLOBALS['wp_register_widget_defaults'] = false; |
|---|
| 194 | |
|---|