| 1906 | | * If the 'show_all' argument is set to true, then it will show all of the pages |
| 1907 | | * instead of a short list of the pages near the current page. By default, the |
| 1908 | | * 'show_all' is set to false and controlled by the 'end_size' and 'mid_size' |
| 1909 | | * arguments. The 'end_size' argument is how many numbers on either the start |
| 1910 | | * and the end list edges, by default is 1. The 'mid_size' argument is how many |
| 1911 | | * numbers to either side of current page, but not including current page. |
| 1912 | | * |
| 1923 | | 'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below) |
| 1924 | | 'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number |
| 1925 | | 'total' => 1, |
| 1926 | | 'current' => 0, |
| 1927 | | 'show_all' => false, |
| 1928 | | 'prev_next' => true, |
| 1929 | | 'prev_text' => __('« Previous'), |
| 1930 | | 'next_text' => __('Next »'), |
| 1931 | | 'end_size' => 1, |
| 1932 | | 'mid_size' => 2, |
| 1933 | | 'type' => 'plain', |
| 1934 | | 'add_args' => false, // array of query args to add |
| 1935 | | 'add_fragment' => '' |
| | 1916 | 'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below) |
| | 1917 | 'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number |
| | 1918 | 'total' => 1, // How many pages there are in total |
| | 1919 | 'current' => 0, // Current page. First page is 1, not 0. |
| | 1920 | 'type' => 'plain', // Plain for text, array or list for a ul. |
| | 1921 | 'text_page' => __('Page'), // Text: Page (shown in the titles) |
| | 1922 | 'add_args' => false, // array of query args to add |
| | 1923 | 'add_fragment' => '', // ??? |
| 1945 | | $current = (int) $current; |
| 1946 | | $end_size = 0 < (int) $end_size ? (int) $end_size : 1; // Out of bounds? Make it the default. |
| 1947 | | $mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2; |
| 1948 | | $add_args = is_array($add_args) ? $add_args : false; |
| 1949 | | $r = ''; |
| | 1933 | |
| | 1934 | if (!function_exists('paginate_link_prepare')): |
| | 1935 | /** |
| | 1936 | * Shorthand function to prepare the first/prev/next/last page links. |
| | 1937 | * |
| | 1938 | * @param array $args See above. Default options. |
| | 1939 | * @param array $options Specificically for this page link. Basically only 'page' => int is specified. |
| | 1940 | */ |
| | 1941 | function paginate_link_prepare($args, $options) { |
| | 1942 | $args = array_merge($args, $options); |
| | 1943 | $link = str_replace('%_%', $args['format'], $args['base']); |
| | 1944 | $link = str_replace('%#%', $args['page'], $link); |
| | 1945 | $link = esc_url( apply_filters( 'paginate_links', $link ) ); |
| | 1946 | if ( $args['add_args'] ) |
| | 1947 | $link = add_query_arg( $args['add_args'], $link ); |
| | 1948 | $link .= $args['$add_fragment']; |
| | 1949 | return $link; |
| | 1950 | } |
| | 1951 | endif; |
| | 1952 | |
| | 1953 | $neighborPages = array( |
| | 1954 | 'first' => 1, |
| | 1955 | 'prev' => ($current > 1 ? $current-1 : 1), |
| | 1956 | 'next' => ($current < $total ? $current+1 : $total), |
| | 1957 | 'last' => $total, |
| | 1958 | ); |
| | 1959 | |
| | 1960 | // Prepare the titles that will be displayed when hovering over the sprites |
| | 1961 | $titles = array( |
| | 1962 | 'first' => $args['text_page'].' '.number_format_i18n( $neighborPages['first'] ), |
| | 1963 | 'prev' => $args['text_page'].' '.number_format_i18n( $neighborPages['prev'] ), |
| | 1964 | 'next' => $args['text_page'].' '.number_format_i18n( $neighborPages['next'] ), |
| | 1965 | 'last' => $args['text_page'].' '.number_format_i18n( $neighborPages['last'] ), |
| | 1966 | ); |
| | 1967 | |
| 1951 | | $n = 0; |
| 1952 | | $dots = false; |
| 1953 | | |
| 1954 | | if ( $prev_next && $current && 1 < $current ) : |
| 1955 | | $link = str_replace('%_%', 2 == $current ? '' : $format, $base); |
| 1956 | | $link = str_replace('%#%', $current - 1, $link); |
| 1957 | | if ( $add_args ) |
| 1958 | | $link = add_query_arg( $add_args, $link ); |
| 1959 | | $link .= $add_fragment; |
| 1960 | | $page_links[] = "<a class='prev page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>$prev_text</a>"; |
| | 1969 | |
| | 1970 | // First and previous links. Do they need to be active? |
| | 1971 | if ($current > 1): |
| | 1972 | // First |
| | 1973 | $link = paginate_link_prepare($args, array('page' => 0)); |
| | 1974 | $page_links[] = '<div class="part sprite first first_enabled" title="'.$titles['first'].'"><a href="'.$link.'">'.$neighborPages['first'].'</a></div>'; |
| | 1975 | |
| | 1976 | // Previous |
| | 1977 | $link = paginate_link_prepare($args, array('page' => $neighborPages['prev'])); |
| | 1978 | $page_links[] = '<div class="part sprite prev prev_enabled" title="'.$titles['prev'].'"><a href="'.$link.'">'.$neighborPages['prev'].'</a></div>'; |
| | 1979 | else: |
| | 1980 | $page_links[] = '<div class="part sprite first first_disabled" title="'.$titles['first'].'">'.$neighborPages['first'].'</div>'; |
| | 1981 | $page_links[] = '<div class="part sprite prev prev_disabled" title="'.$titles['prev'].'">'.$neighborPages['prev'].'</div>'; |
| 1962 | | for ( $n = 1; $n <= $total; $n++ ) : |
| 1963 | | $n_display = number_format_i18n($n); |
| 1964 | | if ( $n == $current ) : |
| 1965 | | $page_links[] = "<span class='page-numbers current'>$n_display</span>"; |
| 1966 | | $dots = true; |
| 1967 | | else : |
| 1968 | | if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) : |
| 1969 | | $link = str_replace('%_%', 1 == $n ? '' : $format, $base); |
| 1970 | | $link = str_replace('%#%', $n, $link); |
| 1971 | | if ( $add_args ) |
| 1972 | | $link = add_query_arg( $add_args, $link ); |
| 1973 | | $link .= $add_fragment; |
| 1974 | | $page_links[] = "<a class='page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>$n_display</a>"; |
| 1975 | | $dots = true; |
| 1976 | | elseif ( $dots && !$show_all ) : |
| 1977 | | $page_links[] = "<span class='page-numbers dots'>...</span>"; |
| 1978 | | $dots = false; |
| 1979 | | endif; |
| 1980 | | endif; |
| | 1983 | |
| | 1984 | // Create a javascript array of filtered page links. |
| | 1985 | $linksJSArray = array(); |
| | 1986 | for($n = 1; $n <= $total; $n++): |
| | 1987 | $link = paginate_link_prepare($args, array('page' => $n)); |
| | 1988 | $linksJSArray[] = "$n : \"" . $link . "\""; |
| 1982 | | if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) : |
| 1983 | | $link = str_replace('%_%', $format, $base); |
| 1984 | | $link = str_replace('%#%', $current + 1, $link); |
| 1985 | | if ( $add_args ) |
| 1986 | | $link = add_query_arg( $add_args, $link ); |
| 1987 | | $link .= $add_fragment; |
| 1988 | | $page_links[] = "<a class='next page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>$next_text</a>"; |
| | 1990 | |
| | 1991 | // Page select box thing |
| | 1992 | $page_selector_class = 'page_selector_' . rand(0, time()); |
| | 1993 | $size = strlen($total); // It shouldn't be bigger than necessary. |
| | 1994 | $page_links[] = |
| | 1995 | ' |
| | 1996 | <div class="part page"> |
| | 1997 | <div class="current"> |
| | 1998 | <input type="text" class="'.$page_selector_class.'" value="'.number_format_i18n($current).'" size="'.$size.'" maxlength="'.$size.'" style="text-align: center;" /> |
| | 1999 | </div> |
| | 2000 | |
| | 2001 | <script type="text/javascript"> |
| | 2002 | var pages = {'.implode(',', $linksJSArray).'}; |
| | 2003 | |
| | 2004 | jQuery(document).ready(function(){ |
| | 2005 | jQuery(".'.$page_selector_class.'").click(function(){ |
| | 2006 | jQuery(this).select(); |
| | 2007 | }); |
| | 2008 | |
| | 2009 | jQuery(".'.$page_selector_class.'").keyup(function(e){ |
| | 2010 | if(e.keyCode == 13){ |
| | 2011 | var value = parseInt(jQuery(this).val()); |
| | 2012 | if (value == Number.NaN) |
| | 2013 | { |
| | 2014 | value = 1; |
| | 2015 | } |
| | 2016 | window.location(pages[value]); |
| | 2017 | } |
| | 2018 | }) |
| | 2019 | }); |
| | 2020 | </script> |
| | 2021 | </div> |
| | 2022 | '; |
| | 2023 | |
| | 2024 | // And finally, the next and last page links |
| | 2025 | if ($current < $total): |
| | 2026 | // Next |
| | 2027 | $link = paginate_link_prepare($args, array('page' => $neighborPages['next'])); |
| | 2028 | $page_links[] = '<div class="part sprite next next_enabled" title="'.$titles['next'].'"><a href="'.$link.'">'.$neighborPages['next'].'</a></div>'; |
| | 2029 | |
| | 2030 | // Last |
| | 2031 | |
| | 2032 | $link = paginate_link_prepare($args, array('page' => $neighborPages['last'])); |
| | 2033 | $page_links[] = '<div class="part sprite last last_enabled" title="'.$titles['last'].'"><a href="'.$link.'">'.$neighborPages['last'].'</a></div>'; |
| | 2034 | else: |
| | 2035 | $page_links[] = '<div class="part sprite next next_disabled" title="'.$titles['next'].'">'.$neighborPages['next'].'</div>'; |
| | 2036 | $page_links[] = '<div class="part sprite last last_disabled" title="'.$titles['last'].'">'.$neighborPages['last'].'</div>'; |