Links widget options. Props DD32. see #9196

git-svn-id: http://svn.automattic.com/wordpress/trunk@10712 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2009-03-04 23:49:21 +00:00
parent 423b468ebf
commit 2b430c9751
2 changed files with 55 additions and 10 deletions

View File

@ -72,10 +72,6 @@ function _walk_bookmarks($bookmarks, $args = '' ) {
if ( !empty($bookmark->link_url) )
$the_link = clean_url($bookmark->link_url);
$rel = $bookmark->link_rel;
if ( '' != $rel )
$rel = ' rel="' . $rel . '"';
$desc = attribute_escape(sanitize_bookmark_field('link_description', $bookmark->link_description, $bookmark->link_id, 'display'));
$name = attribute_escape(sanitize_bookmark_field('link_name', $bookmark->link_name, $bookmark->link_id, 'display'));
$title = $desc;
@ -87,21 +83,25 @@ function _walk_bookmarks($bookmarks, $args = '' ) {
$title .= ')';
}
$alt = ' alt="' . $name . ( $show_description ? ' ' . $title : '' ) . '"';
if ( '' != $title )
$title = ' title="' . $title . '"';
$alt = ' alt="' . $name . '"';
$rel = $bookmark->link_rel;
if ( '' != $rel )
$rel = ' rel="' . $rel . '"';
$target = $bookmark->link_target;
if ( '' != $target )
$target = ' target="' . $target . '"';
$output .= '<a href="' . $the_link . '"' . $rel . $title . $target. '>';
$output .= '<a href="' . $the_link . '"' . $rel . $title . $target . '>';
$output .= $link_before;
if ( $bookmark->link_image != null && $show_images ) {
if ( strpos($bookmark->link_image, 'http') !== false )
if ( strpos($bookmark->link_image, 'http') === 0 )
$output .= "<img src=\"$bookmark->link_image\" $alt $title />";
else // If it's a relative path
$output .= "<img src=\"" . get_option('siteurl') . "$bookmark->link_image\" $alt $title />";
@ -121,9 +121,8 @@ function _walk_bookmarks($bookmarks, $args = '' ) {
if ( $show_description && '' != $desc )
$output .= $between . $desc;
if ($show_rating) {
if ( $show_rating )
$output .= $between . sanitize_bookmark_field('link_rating', $bookmark->link_rating, $bookmark->link_id, 'display');
}
$output .= "$after\n";
} // end while

View File

@ -748,14 +748,59 @@ function wp_widget_pages_control() {
function wp_widget_links($args) {
extract($args, EXTR_SKIP);
$link_options = get_option('widget_links');
$show_description = isset($link_options['description']) ? $link_options['description'] : false;
$show_name = isset($link_options['name']) ? $link_options['name'] : false;
$show_rating = isset($link_options['rating']) ? $link_options['rating'] : false;
$show_images = isset($link_options['images']) ? $link_options['images'] : true;
$before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget);
wp_list_bookmarks(apply_filters('widget_links_args', array(
'title_before' => $before_title, 'title_after' => $after_title,
'category_before' => $before_widget, 'category_after' => $after_widget,
'show_images' => true, 'class' => 'linkcat widget'
'show_images' => $show_images, 'show_description' => $show_description,
'show_name' => $show_name, 'show_rating' => $show_rating,
'class' => 'linkcat widget'
)));
}
/**
* Display and process links widget options form.
*
* @since 2.8.0
*/
function wp_widget_links_control() {
$options = $newoptions = get_option('widget_links');
//Defaults
if ( ! $newoptions )
$newoptions = array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false);
if ( isset($_POST['links-submit']) ) {
$newoptions['description'] = isset($_POST['links-description']);
$newoptions['name'] = isset($_POST['links-name']);
$newoptions['rating'] = isset($_POST['links-rating']);
$newoptions['images'] = isset($_POST['links-images']);
}
if ( $options != $newoptions ) {
$options = $newoptions;
update_option('widget_links', $options);
}
?>
<p>
<label for="links-images"><input class="checkbox" type="checkbox" <?php checked($options['images'], true) ?> id="links-images" name="links-images" /> <?php _e('Show Link Image'); ?></label>
<br />
<label for="links-name"><input class="checkbox" type="checkbox" <?php checked($options['name'], true) ?> id="links-name" name="links-name" /> <?php _e('Show Link Name'); ?></label>
<br />
<label for="links-description"><input class="checkbox" type="checkbox" <?php checked($options['description'], true) ?> id="links-description" name="links-description" /> <?php _e('Show Link Description'); ?></label>
<br />
<label for="links-rating"><input class="checkbox" type="checkbox" <?php checked($options['rating'], true) ?> id="links-rating" name="links-rating" /> <?php _e('Show Link Rating'); ?></label>
</p>
<input type="hidden" id="links-submit" name="links-submit" value="1" />
<?php
}
/**
* Display search widget.
*
@ -1923,6 +1968,7 @@ function wp_widgets_init() {
$widget_ops = array('classname' => 'widget_links', 'description' => __( "Your blogroll") );
wp_register_sidebar_widget('links', __('Links'), 'wp_widget_links', $widget_ops);
wp_register_widget_control('links', __('Links'), 'wp_widget_links_control' );
$widget_ops = array('classname' => 'widget_meta', 'description' => __( "Log in/out, admin, feed and WordPress links") );
wp_register_sidebar_widget('meta', __('Meta'), 'wp_widget_meta', $widget_ops);