function woo_pagination( $args = array(), $query = '' ) {
global $wp_rewrite, $wp_query;

do_action( 'woo_pagination_start' );

if ( $query ) {

$wp_query = $query;

} // End IF Statement

/* If there's not more than one page, return nothing. */
if ( 1 >= $wp_query->max_num_pages )
return;

/* Get the current page. */
$current = ( get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1 );

/* Get the max number of pages. */
$max_num_pages = intval( $wp_query->max_num_pages );

/* Set up some default arguments for the paginate_links() function. */
$defaults = array(
'base' => add_query_arg( 'paged', '%#%' ),
'format' => '',
'total' => $max_num_pages,
'current' => $current,
'prev_next' => true,
'prev_text' => __( '← Previous', 'woothemes' ), // Translate in WordPress. This is the default.
'next_text' => __( 'Next →', 'woothemes' ), // Translate in WordPress. This is the default.
'show_all' => false,
'end_size' => 1,
'mid_size' => 1,
'add_fragment' => '',
'type' => 'plain',
'before' => '<div class="pagination woo-pagination">', // Begin woo_pagination() arguments.
'after' => '</div>',
'echo' => true,
'use_search_permastruct' => true
);

/* Allow themes/plugins to filter the default arguments. */
$defaults = apply_filters( 'woo_pagination_args_defaults', $defaults );

/* Add the $base argument to the array if the user is using permalinks. */
if( $wp_rewrite->using_permalinks() && ! is_search() )
$defaults['base'] = user_trailingslashit( trailingslashit( get_pagenum_link() ) . 'page/%#%' );

/* Force search links to use raw permastruct for more accurate multi-word searching. */
if ( is_search() )
$defaults['use_search_permastruct'] = false;

/* If we're on a search results page, we need to change this up a bit. */
if ( is_search() ) {
/* If we're in BuddyPress, or the user has selected to do so, use the default "unpretty" URL structure. */
if ( class_exists( 'BP_Core_User' ) || $defaults['use_search_permastruct'] == false ) {
$search_query = get_query_var( 's' );
$paged = get_query_var( 'paged' );
$base = add_query_arg( 's', urlencode( $search_query ) );
$base = add_query_arg( 'paged', '%#%' );
$defaults['base'] = $base;
} else {
$search_permastruct = $wp_rewrite->get_search_permastruct();
if ( ! empty( $search_permastruct ) ) {
$base = get_search_link();
$base = add_query_arg( 'paged', '%#%', $base );
$defaults['base'] = $base;
}
}
}

/* Merge the arguments input with the defaults. */
$args = wp_parse_args( $args, $defaults );

/* Allow developers to overwrite the arguments with a filter. */
$args = apply_filters( 'woo_pagination_args', $args );

/* Don't allow the user to set this to an array. */
if ( 'array' == $args['type'] )
$args['type'] = 'plain';

/* Make sure raw querystrings are displayed at the end of the URL, if using pretty permalinks. */
$pattern = '/\?(.*?)\//i';

preg_match( $pattern, $args['base'], $raw_querystring );

if( $wp_rewrite->using_permalinks() && $raw_querystring )
$raw_querystring[0] = str_replace( '', '', $raw_querystring[0] );
@$args['base'] = str_replace( $raw_querystring[0], '', $args['base'] );
@$args['base'] .= substr( $raw_querystring[0], 0, -1 );

/* Get the paginated links. */
$page_links = paginate_links( $args );

/* Remove 'page/1' from the entire output since it's not needed. */
$page_links = str_replace( array( '&#038;paged=1\'', '/page/1\'' ), '\'', $page_links );

/* Wrap the paginated links with the $before and $after elements. */
$page_links = $args['before'] . $page_links . $args['after'];

/* Allow devs to completely overwrite the output. */
$page_links = apply_filters( 'woo_pagination', $page_links );

do_action( 'woo_pagination_end' );

/* Return the paginated links for use in themes. */
if ( $args['echo'] )
echo $page_links;
else
return $page_links;
} // End woo_pagination()