Skip to content

Commit

Permalink
Use wp_parse_args(). fixes #4237
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.automattic.com/wordpress/trunk@5444 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
rob1n committed May 11, 2007
1 parent 70c17cc commit e6c1899
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 192 deletions.
15 changes: 7 additions & 8 deletions wp-includes/author-template.php
Expand Up @@ -175,14 +175,13 @@ function get_author_name( $auth_id ) {
function wp_list_authors($args = '') {
global $wpdb;

if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);

$defaults = array('optioncount' => false, 'exclude_admin' => true, 'show_fullname' => false, 'hide_empty' => true,
'feed' => '', 'feed_image' => '');
$r = array_merge($defaults, $r);
$defaults = array(
'optioncount' => false, 'exclude_admin' => true,
'show_fullname' => false, 'hide_empty' => true,
'feed' => '', 'feed_image' => ''
);

$r = wp_parse_args( $args, $defaults );
extract($r);

// TODO: Move select to get_authors().
Expand Down
78 changes: 37 additions & 41 deletions wp-includes/bookmark-template.php
Expand Up @@ -9,28 +9,23 @@
**/
function wp_get_links($args = '') {
global $wpdb;

if ( empty($args) )
return;

if ( false === strpos($args, '=') ) {

if ( strpos( $args, '=' ) === false ) {
$cat_id = $args;
$args = add_query_arg('category', $cat_id, $args);
$args = add_query_arg( 'category', $cat_id, $args );
}

parse_str($args);

if ( !isset($category) ) $category = -1;
if ( !isset($before) ) $before = '';
if ( !isset($after) ) $after = '<br />';
if ( !isset($between) ) $between = ' ';
if ( !isset($show_images) ) $show_images = true;
if ( !isset($orderby) ) $orderby = 'name';
if ( !isset($show_description) ) $show_description = true;
if ( !isset($show_rating) ) $show_rating = false;
if ( !isset($limit) ) $limit = -1;
if ( !isset($show_updated) ) $show_updated = 1;
if ( !isset($echo) ) $echo = true;

$defaults = array(
'category' => -1, 'before' => '',
'after' => '<br />', 'between' => ' ',
'show_images' => true, 'orderby' => 'name',
'show_description' => true, 'show_rating' => false,
'limit' => -1, 'show_updated' => true,
'echo' => true
);

$r = wp_parse_args( $args, $defaults );
extract( $r );

return get_links($category, $before, $after, $between, $show_images, $orderby, $show_description, $show_rating, $limit, $show_updated, $echo);
} // end wp_get_links
Expand Down Expand Up @@ -245,15 +240,14 @@ function get_links_list($order = 'name', $hide_if_empty = 'obsolete') {
}

function _walk_bookmarks($bookmarks, $args = '' ) {
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);

$defaults = array('show_updated' => 0, 'show_description' => 0, 'show_images' => 1, 'before' => '<li>',
'after' => '</li>', 'between' => "\n");
$r = array_merge($defaults, $r);
extract($r);
$defaults = array(
'show_updated' => 0, 'show_description' => 0,
'show_images' => 1, 'before' => '<li>',
'after' => '</li>', 'between' => "\n"
);

$r = wp_parse_args( $args, $defaults );
extract( $r );

foreach ( (array) $bookmarks as $bookmark ) {
if ( !isset($bookmark->recently_updated) )
Expand Down Expand Up @@ -320,18 +314,20 @@ function _walk_bookmarks($bookmarks, $args = '' ) {
}

function wp_list_bookmarks($args = '') {
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);

$defaults = array('orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => '',
'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0, 'echo' => 1,
'categorize' => 1, 'title_li' => __('Bookmarks'), 'title_before' => '<h2>', 'title_after' => '</h2>',
'category_orderby' => 'name', 'category_order' => 'ASC', 'class' => 'linkcat',
'category_before' => '<li id="%id" class="%class">', 'category_after' => '</li>');
$r = array_merge($defaults, $r);
extract($r);
$defaults = array(
'orderby' => 'name', 'order' => 'ASC',
'limit' => -1, 'category' => '',
'category_name' => '', 'hide_invisible' => 1,
'show_updated' => 0, 'echo' => 1,
'categorize' => 1, 'title_li' => __('Bookmarks'),
'title_before' => '<h2>', 'title_after' => '</h2>',
'category_orderby' => 'name', 'category_order' => 'ASC',
'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">',
'category_after' => '</li>'
);

$r = wp_parse_args( $args, $defaults );
extract( $r );

$output = '';

Expand Down
21 changes: 11 additions & 10 deletions wp-includes/bookmark.php
Expand Up @@ -25,16 +25,17 @@ function get_link($bookmark_id, $output = OBJECT) {

function get_bookmarks($args = '') {
global $wpdb;

if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);

$defaults = array('orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => '',
'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0, 'include' => '', 'exclude' => '');
$r = array_merge($defaults, $r);
extract($r);

$defaults = array(
'orderby' => 'name', 'order' => 'ASC',
'limit' => -1, 'category' => '',
'category_name' => '', 'hide_invisible' => 1,
'show_updated' => 0, 'include' => '',
'exclude' => ''
);

$r = wp_parse_args( $args, $defaults );
extract( $r );

$key = md5( serialize( $r ) );
if ( $cache = wp_cache_get( 'get_bookmarks', 'bookmark' ) )
Expand Down
60 changes: 33 additions & 27 deletions wp-includes/category-template.php
Expand Up @@ -169,20 +169,21 @@ function category_description($category = 0) {
}

function wp_dropdown_categories($args = '') {
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);

$defaults = array('show_option_all' => '', 'show_option_none' => '', 'orderby' => 'ID',
'order' => 'ASC', 'show_last_update' => 0, 'show_count' => 0,
'hide_empty' => 1, 'child_of' => 0, 'exclude' => '', 'echo' => 1,
'selected' => 0, 'hierarchical' => 0, 'name' => 'cat',
'class' => 'postform');
$defaults = array(
'show_option_all' => '', 'show_option_none' => '',
'orderby' => 'ID', 'order' => 'ASC',
'show_last_update' => 0, 'show_count' => 0,
'hide_empty' => 1, 'child_of' => 0,
'exclude' => '', 'echo' => 1,
'selected' => 0, 'hierarchical' => 0,
'name' => 'cat', 'class' => 'postform'
);

$defaults['selected'] = ( is_category() ) ? get_query_var('cat') : 0;
$r = array_merge($defaults, $r);

$r = wp_parse_args( $args, $defaults );
$r['include_last_update_time'] = $r['show_last_update'];
extract($r);
extract( $r );

$categories = get_categories($r);

Expand Down Expand Up @@ -218,23 +219,28 @@ function wp_dropdown_categories($args = '') {
}

function wp_list_categories($args = '') {
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);

$defaults = array('show_option_all' => '', 'orderby' => 'name',
'order' => 'ASC', 'show_last_update' => 0, 'style' => 'list',
'show_count' => 0, 'hide_empty' => 1, 'use_desc_for_title' => 1,
'child_of' => 0, 'feed' => '', 'feed_image' => '', 'exclude' => '',
'hierarchical' => true, 'title_li' => __('Categories'));
$r = array_merge($defaults, $r);
if ( !isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical'] )
$defaults = array(
'show_option_all' => '', 'orderby' => 'name',
'order' => 'ASC', 'show_last_update' => 0,
'style' => 'list', 'show_count' => 0,
'hide_empty' => 1, 'use_desc_for_title' => 1,
'child_of' => 0, 'feed' => '',
'feed_image' => '', 'exclude' => '',
'hierarchical' => true, 'title_li' => __('Categories')
);

$r = wp_parse_args( $args, $defaults );

if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
$r['pad_counts'] = true;
if ( isset($r['show_date']) )
}

if ( isset( $r['show_date'] ) ) {
$r['include_last_update_time'] = $r['show_date'];
extract($r);

}

extract( $r );

$categories = get_categories($r);

$output = '';
Expand Down
33 changes: 18 additions & 15 deletions wp-includes/category.php
Expand Up @@ -16,22 +16,25 @@ function get_all_category_ids() {

function &get_categories($args = '') {
global $wpdb, $category_links;

if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);

$defaults = array('type' => 'post', 'child_of' => 0, 'orderby' => 'name', 'order' => 'ASC',
'hide_empty' => true, 'include_last_update_time' => false, 'hierarchical' => 1, 'exclude' => '', 'include' => '',
'number' => '', 'pad_counts' => false);
$r = array_merge($defaults, $r);
if ( 'count' == $r['orderby'] )

$defaults = array(
'type' => 'post', 'child_of' => 0,
'orderby' => 'name', 'order' => 'ASC',
'hide_empty' => true, 'include_last_update_time' => false,
'hierarchical' => 1, 'exclude' => '',
'include' => '', 'number' => '',
'pad_counts' => false
);

$r = wp_parse_args( $args, $defaults );

if ( $r['orderby'] == 'count' ) {
$r['orderby'] = 'category_count';
else
$r['orderby'] = "cat_" . $r['orderby']; // restricts order by to cat_ID and cat_name fields
$r['number'] = (int) $r['number'];
extract($r);
} else {
$r['orderby'] = 'cat_' . $r['orderby'];
}

extract( $r );

$key = md5( serialize( $r ) );
if ( $cache = wp_cache_get( 'get_categories', 'category' ) )
Expand Down
18 changes: 8 additions & 10 deletions wp-includes/classes.php
Expand Up @@ -687,16 +687,14 @@ function WP_Ajax_Response( $args = '' ) {

// a WP_Error object can be passed in 'id' or 'data'
function add( $args = '' ) {
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);

$defaults = array('what' => 'object', 'action' => false, 'id' => '0', 'old_id' => false,
'data' => '', 'supplemental' => array());

$r = array_merge($defaults, $r);
extract($r);
$defaults = array(
'what' => 'object', 'action' => false,
'id' => '0', 'old_id' => false,
'data' => '', 'supplemental' => array()
);

$r = wp_parse_args( $args, $defaults );
extract( $r );

if ( is_wp_error($id) ) {
$data = $id;
Expand Down
5 changes: 1 addition & 4 deletions wp-includes/deprecated.php
Expand Up @@ -427,10 +427,7 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde
}

function wp_list_cats($args = '') {
if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);
$r = wp_parse_args( $args );

// Map to new names.
if ( isset($r['optionall']) && isset($r['all']))
Expand Down
20 changes: 10 additions & 10 deletions wp-includes/general-template.php
Expand Up @@ -313,16 +313,16 @@ function get_archives_link($url, $text, $format = 'html', $before = '', $after =


function wp_get_archives($args = '') {
global $wp_locale, $wpdb;

if ( is_array($args) )
$r = &$args;
else
parse_str($args, $r);

$defaults = array('type' => 'monthly', 'limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false);
$r = array_merge($defaults, $r);
extract($r);
global $wpdb;
$defaults = array(
'type' => 'monthly', 'limit' => '',
'format' => 'html', 'before' => '',
'after' => '', 'show_post_count' => false
);

$r = wp_parse_args( $args, $defaults );
extract( $r );

if ( '' == $type )
$type = 'monthly';
Expand Down

0 comments on commit e6c1899

Please sign in to comment.