Texturize and autop the text widgets, and allow pages to be sorted by a specified field. Props Denis de Bernardy. see #4259

git-svn-id: http://svn.automattic.com/wordpress/trunk@5486 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
rob1n 2007-05-18 02:29:11 +00:00
parent 8da6590866
commit 5d40bf562c
1 changed files with 43 additions and 13 deletions

View File

@ -326,19 +326,43 @@ function wp_get_widget_defaults() {
/* Default Widgets */ /* Default Widgets */
function wp_widget_pages($args) { function wp_widget_pages( $args ) {
extract($args); extract( $args );
$options = get_option('widget_pages'); $options = get_option( 'widget_pages' );
$title = empty($options['title']) ? __('Pages') : $options['title'];
echo $before_widget . $before_title . $title . $after_title . "<ul>\n"; $title = empty( $options['title'] ) ? __( 'Pages' ) : $options['title'];
wp_list_pages("title_li="); $sortby = empty( $options['sortby'] ) ? 'menu_order' : $options['sortby'];
echo "</ul>\n" . $after_widget;
if ( $sortby == 'menu_order' ) {
$sortby = 'menu_order, post_title';
}
$out = wp_list_pages( 'title_li=&echo=0&sort_column=' . $sortby );
if ( !empty( $out ) ) {
?>
<?php echo $before_widget; ?>
<?php echo $before_title . $title . $after_title; ?>
<ul>
<?php echo $out; ?>
</ul>
<?php echo $after_widget; ?>
<?php
}
} }
function wp_widget_pages_control() { function wp_widget_pages_control() {
$options = $newoptions = get_option('widget_pages'); $options = $newoptions = get_option('widget_pages');
if ( $_POST["pages-submit"] ) { if ( $_POST['pages-submit'] ) {
$newoptions['title'] = strip_tags(stripslashes($_POST["pages-title"])); $newoptions['title'] = strip_tags(stripslashes($_POST['pages-title']));
$sortby = stripslashes( $_POST['pages-sortby'] );
if ( in_array( $sortby, array( 'post_title', 'menu_order', 'ID' ) ) ) {
$newoptions['sortby'] = $sortby;
} else {
$newoptions['sortby'] = 'menu_order';
}
} }
if ( $options != $newoptions ) { if ( $options != $newoptions ) {
$options = $newoptions; $options = $newoptions;
@ -347,6 +371,12 @@ function wp_widget_pages_control() {
$title = attribute_escape($options['title']); $title = attribute_escape($options['title']);
?> ?>
<p><label for="pages-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="pages-title" name="pages-title" type="text" value="<?php echo $title; ?>" /></label></p> <p><label for="pages-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="pages-title" name="pages-title" type="text" value="<?php echo $title; ?>" /></label></p>
<p><label for="pages-sortby"><?php _e( 'Sort by:' ); ?>
<select name="pages-sortby" id="pages-sortby">
<option value="post_title"><?php _e('Page title'); ?></option>
<option value="menu_order"><?php _e('Menu order'); ?></option>
<option value="ID"><?php _e( 'Page ID' ); ?></option>
</select></label></p>
<input type="hidden" id="pages-submit" name="pages-submit" value="1" /> <input type="hidden" id="pages-submit" name="pages-submit" value="1" />
<?php <?php
} }
@ -495,10 +525,10 @@ function wp_widget_text($args, $number = 1) {
$title = $options[$number]['title']; $title = $options[$number]['title'];
if ( empty($title) ) if ( empty($title) )
$title = '&nbsp;'; $title = '&nbsp;';
$text = $options[$number]['text']; $text = apply_filters( 'the_content', $options[$number]['text'] );
?> ?>
<?php echo $before_widget; ?> <?php echo $before_widget; ?>
<?php $title ? print($before_title . $title . $after_title) : null; ?> <?php !empty( $title ) ? print($before_title . $title . $after_title) : null; ?>
<div class="textwidget"><?php echo $text; ?></div> <div class="textwidget"><?php echo $text; ?></div>
<?php echo $after_widget; ?> <?php echo $after_widget; ?>
<?php <?php
@ -521,8 +551,8 @@ function wp_widget_text_control($number) {
$title = attribute_escape($options[$number]['title']); $title = attribute_escape($options[$number]['title']);
$text = attribute_escape($options[$number]['text']); $text = attribute_escape($options[$number]['text']);
?> ?>
<input style="width: 450px;" id="text-title-<?php echo "$number"; ?>" name="text-title-<?php echo "$number"; ?>" type="text" value="<?php echo $title; ?>" /> <input style="width: 450px;" id="text-title-<?php echo $number; ?>" name="text-title-<?php echo $number; ?>" type="text" value="<?php echo $title; ?>" />
<textarea style="width: 450px; height: 280px;" id="text-text-<?php echo "$number"; ?>" name="text-text-<?php echo "$number"; ?>"><?php echo $text; ?></textarea> <textarea style="width: 450px; height: 280px;" id="text-text-<?php echo $number; ?>" name="text-text-<?php echo $number; ?>"><?php echo $text; ?></textarea>
<input type="hidden" id="text-submit-<?php echo "$number"; ?>" name="text-submit-<?php echo "$number"; ?>" value="1" /> <input type="hidden" id="text-submit-<?php echo "$number"; ?>" name="text-submit-<?php echo "$number"; ?>" value="1" />
<?php <?php
} }