| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | if ( ! defined( 'ABSPATH' ) ) { |
| 14: | exit; |
| 15: | } |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | if ( ! class_exists( 'EPL_Pagination_Call' ) ) : |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | class EPL_Pagination_Call { |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | protected $args; |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | public function __construct( $args ) { |
| 46: | $this->args = $args; |
| 47: | } |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | public function __get( $key ) { |
| 58: | return $this->args[ $key ]; |
| 59: | } |
| 60: | |
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: | |
| 66: | public function get_pagination_args() { |
| 67: | global $numpages; |
| 68: | |
| 69: | $query = $this->query; |
| 70: | |
| 71: | switch ( $this->type ) { |
| 72: | case 'multipart': |
| 73: | |
| 74: | $posts_per_page = 1; |
| 75: | $paged = max( 1, absint( get_query_var( 'page' ) ) ); |
| 76: | $total_pages = max( 1, $numpages ); |
| 77: | break; |
| 78: | case 'users': |
| 79: | |
| 80: | $posts_per_page = $query->query_vars['number']; |
| 81: | $paged = max( 1, floor( $query->query_vars['offset'] / $posts_per_page ) + 1 ); |
| 82: | $total_pages = max( 1, ceil( $query->total_users / $posts_per_page ) ); |
| 83: | break; |
| 84: | default: |
| 85: | |
| 86: | $posts_per_page = intval( $query->get( 'posts_per_page' ) ); |
| 87: | $paged = max( 1, absint( $query->get( 'paged' ) ) ); |
| 88: | $total_pages = max( 1, absint( $query->max_num_pages ) ); |
| 89: | break; |
| 90: | } |
| 91: | |
| 92: | return array( $posts_per_page, $paged, $total_pages ); |
| 93: | } |
| 94: | |
| 95: | |
| 96: | |
| 97: | |
| 98: | |
| 99: | |
| 100: | |
| 101: | |
| 102: | |
| 103: | |
| 104: | |
| 105: | |
| 106: | |
| 107: | public function get_single( $page, $raw_text, $attr, $format = '%PAGE_NUMBER%', $tag = 'a' ) { |
| 108: | if ( empty( $raw_text ) ) { |
| 109: | return ''; |
| 110: | } |
| 111: | |
| 112: | $text = str_replace( $format, number_format_i18n( $page ), $raw_text ); |
| 113: | $text = apply_filters( 'epl_pagination_single_content_text', $text, $raw_text ); |
| 114: | |
| 115: | $attr['href'] = $this->get_url( $page ); |
| 116: | |
| 117: | list( $posts_per_page, $paged, $total_pages ) = $this->get_pagination_args(); |
| 118: | $tag = apply_filters( 'epl_pagination_single_tag', $tag, $page, $paged ); |
| 119: | |
| 120: | return apply_filters( 'epl_pagination_single', epl_pagination_html( $tag, $attr, $text ), $page, $paged, $total_pages, $posts_per_page ); |
| 121: | } |
| 122: | |
| 123: | |
| 124: | |
| 125: | |
| 126: | |
| 127: | |
| 128: | |
| 129: | |
| 130: | |
| 131: | |
| 132: | public function get_single_dot( $tag = 'span', $content = '...', array $attributes = array() ) { |
| 133: | $tag = apply_filters( 'epl_pagination_single_dot_tag', $tag ); |
| 134: | $content = apply_filters( 'epl_pagination_single_dot_content', $content ); |
| 135: | $attributes = apply_filters( 'epl_pagination_single_dot_attributes', $attributes ); |
| 136: | |
| 137: | $output = '<' . $tag; |
| 138: | if ( is_array( $attributes ) && count( $attributes ) ) { |
| 139: | foreach ( $attributes as $key => $value ) { |
| 140: | if ( ! empty( $key ) && ! empty( $value ) ) { |
| 141: | $output .= ' ' . $key . '="' . $value . '"'; |
| 142: | } |
| 143: | } |
| 144: | } |
| 145: | |
| 146: | if ( in_array( $tag, array( 'area', 'base', 'basefont', 'br', 'hr', 'input', 'img', 'link', 'meta' ), true ) ) { |
| 147: | $output .= ' />'; |
| 148: | } else { |
| 149: | |
| 150: | $output .= '>' . $content . '</' . $tag . '>'; |
| 151: | } |
| 152: | |
| 153: | return apply_filters( 'epl_pagination_single_dot', $output ); |
| 154: | } |
| 155: | |
| 156: | |
| 157: | |
| 158: | |
| 159: | |
| 160: | |
| 161: | |
| 162: | |
| 163: | |
| 164: | |
| 165: | |
| 166: | |
| 167: | public function get_url( $page ) { |
| 168: | $link = ( 'multipart' === $this->type ) ? epl_get_multipage_link( $page ) : get_pagenum_link( $page ); |
| 169: | |
| 170: | if ( $this->query->get( 'is_epl_shortcode' ) && |
| 171: | in_array( $this->query->get( 'epl_shortcode_name' ), epl_get_shortcode_list(), true ) ) { |
| 172: | $permalink_structure = get_option( 'permalink_structure' ); |
| 173: | |
| 174: | if ( empty( $permalink_structure ) ) { |
| 175: | $link = epl_add_or_update_params( $link, 'paged', $page ); |
| 176: | } |
| 177: | $link = epl_add_or_update_params( $link, 'pagination_id', $this->query->get( 'instance_id' ) ); |
| 178: | $link = epl_add_or_update_params( $link, 'instance_id', $this->query->get( 'instance_id' ) ); |
| 179: | } |
| 180: | |
| 181: | return $link; |
| 182: | } |
| 183: | } |
| 184: | endif; |
| 185: | |