Plugin Directory

Changeset 565111


Ignore:
Timestamp:
06/28/2012 08:51:18 PM (14 years ago)
Author:
paddelboot
Message:

Version 1.2b

Location:
3pagination/trunk
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • 3pagination/trunk/3pagination.php

    r564699 r565111  
    11<?php
     2
    23/**
    34 * Plugin Name: 3pagination
    45 * Description: Reach any page with no more than 3 clicks
    5  * Version: 1.0
     6 * Version: 1.2b
    67 * Author: Michael Schröder <ms@ts-webdesign.net>
    78 * TextDomain: 3pagination
     
    910 */
    1011
    11 // Load example CSS
    12 add_action( 'wp_enqueue_scripts', 'load_example_css' );
    13 
    14 // Example callback function
    15 function load_example_css () {
    16     wp_enqueue_style( 'threepagination-css', plugins_url( 'examples/style.css', __FILE__ ) );
    17 }
    18 
    19 if ( ! class_exists( 'threepagination' ) ) {
     12if ( !class_exists( 'threepagination' ) ) {
    2013
    2114    class threepagination {
     15
     16        /**
     17         * Textdomain string
     18         *
     19         * @var string
     20         */
     21        protected $textdomain;
     22
     23        /**
     24         * Class init
     25         *
     26         * @since 1.1
     27         */
     28        public function __construct() {
     29           
     30            // Get files
     31            $this->include_files();
     32
     33            // Set textdomain string
     34            add_filter( 'admin_init', array( $this, 'set_textdomain' ), 1 );
     35           
     36            add_filter( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
     37            add_filter( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
     38        }
     39       
     40        /**
     41         * Include files
     42         *
     43         * @since 1.2b
     44         */
     45        private function include_files() {
     46           
     47            require_once( plugin_dir_path( __FILE__) . 'class.settings.php' );
     48        }
     49
     50        /**
     51         * Set plugin's textdomain
     52         *
     53         * @since 1.2b
     54         */
     55        public function set_textdomain() {
     56
     57            $this->textdomain = '3pagination';
     58        }
     59       
     60        /**
     61         * Load admin scripts
     62         *
     63         * @since 1.2b
     64         */
     65        public function admin_scripts() {
     66           
     67            wp_enqueue_style( 'threepagination-css', plugins_url( 'examples/style.css', __FILE__ ) );
     68        }
     69       
     70        /**
     71         * Load frontend scripts
     72         *
     73         * @since 1.2b
     74         */
     75        public function frontend_scripts() {
     76           
     77            wp_enqueue_style( 'threepagination-css', plugins_url( 'examples/style.css', __FILE__ ) );
     78           
     79            wp_enqueue_script( '3pagination-js', plugins_url( '/js/3pagination.js', __FILE__ ), array( 'jquery', 'json2' ) );
     80            wp_localize_script( '3pagination-js', 'threepag_vars', $this->frontend_vars() );               
     81        }
     82       
     83        /**
     84         * Set frontend vars
     85         *
     86         * @return type
     87         * @since 1.2b
     88         */
     89        private function frontend_vars() {
     90           
     91            $vars = array();
     92           
     93            $settings = get_option( '3pagination_settings' );
     94           
     95            // Check placement
     96            if ( 'on' == $this->init_var( $settings, 'placement_header_index' ) && is_home() ||
     97                    'on' == $this->init_var( $settings, 'placement_header_archive' ) && is_archive() ||
     98                    'on' == $this->init_var( $settings, 'placement_header_category' ) && is_category() ||
     99                    'on' == $this->init_var( $settings, 'placement_header_search' ) && is_search() )
     100                    $vars[ 'placement_header' ] = TRUE;
     101           
     102            if ( 'on' == $this->init_var( $settings, 'placement_footer_index' ) && is_home() ||
     103                    'on' == $this->init_var( $settings, 'placement_footer_archive' ) && is_archive() ||
     104                    'on' == $this->init_var( $settings, 'placement_footer_category' ) && is_category() ||
     105                    'on' == $this->init_var( $settings, 'placement_footer_search' ) && is_search() )
     106                    $vars[ 'placement_footer' ] = TRUE;
     107           
     108            if ( 'on' == $this->init_var( $settings, 'placement_prepend_index' ) && is_home() ||
     109                    'on' == $this->init_var( $settings, 'placement_prepend_archive' ) && is_archive() ||
     110                    'on' == $this->init_var( $settings, 'placement_prepend_category' ) && is_category() ||
     111                    'on' == $this->init_var( $settings, 'placement_prepend_search' ) && is_search() ) {
     112                    $vars[ 'placement_prepend' ] = TRUE;
     113                    $vars[ 'placement_prepend_id' ] = $settings[ 'placement_prepend_id' ];
     114                    }
     115           
     116            if ( 'on' == $this->init_var( $settings, 'placement_append_index' ) && is_home() ||
     117                    'on' == $this->init_var( $settings, 'placement_append_archive' ) && is_archive() ||
     118                    'on' == $this->init_var( $settings, 'placement_append_category' ) && is_category() ||
     119                    'on' == $this->init_var( $settings, 'placement_append_search' ) && is_search() ) {
     120                    $vars[ 'placement_append' ] = TRUE;
     121                    $vars[ 'placement_append_id' ] = $settings[ 'placement_append_id' ];
     122                    }
     123           
     124            // HTML output
     125            $vars[ 'html' ] = json_encode( self::get() );
     126           
     127            return $vars;
     128        }
    22129
    23130        /**
     
    33140         * @since 0.1a
    34141         */
    35         public static function get ( $pretty = TRUE, $max_num_pages = FALSE, $labels = TRUE, $css = 'classic' ) {
     142        public static function get( $pretty = TRUE, $max_num_pages = FALSE, $labels = TRUE, $css = 'classic' ) {
    36143
    37144            global $wp_query, $wp;
    38 
     145           
    39146            // Get the page count
    40147            $total_pages = ( FALSE == $max_num_pages ) ? $wp_query->max_num_pages : $max_num_pages;
     
    43150            if ( 1 == $total_pages )
    44151                return;
     152           
     153            // For now, 3pagination supports up to 999 pages only
     154            if ( 999 < $total_pages )
     155                $total_pages = 999;
    45156
    46157            // Get currently visited page
     
    92203                    }
    93204                    break;
    94                    
     205
    95206                default:
    96207                    for ( $i = 1; $i <= 999; ++$i ) {
     
    111222                    break;
    112223            }
     224           
     225            $settings = get_option( '3pagination_settings' );
     226           
     227            $css = isset( $settings[ 'css_class' ] ) ? $settings[ 'css_class' ] : $css;
    113228
    114229            // Navigation labels
    115             if ( FALSE !== $labels ) {
     230            if ( FALSE !== $labels && 'on' == $settings[ 'labels_show' ] ) {
     231                           
    116232                if ( $on_page > 1 ) {
    117233                    $i = $on_page - 1;
    118                     $page_string = "<a class='page-numbers label-first' href='" . self::url( $wp, 1, $pretty ) . "'>&laquo;</a>&nbsp;" . $page_string;
    119                     $page_string = "<a class='page-numbers label-previous' href='" . self::url( $wp, $i, $pretty ) . "'>&lsaquo;</a>&nbsp;" . $page_string;
     234                    $page_string = "<a class='page-numbers label-first' href='" . self::url( $wp, 1, $pretty ) . "'>" . self::init_var( $settings, 'labels_first', '&laquo;', TRUE ) . "</a>&nbsp;" . $page_string;
     235                    $page_string = "<a class='page-numbers label-previous' href='" . self::url( $wp, $i, $pretty ) . "'>" . self::init_var( $settings, 'labels_previous', '&lsaquo;', TRUE ) . "</a>&nbsp;" . $page_string;
    120236                }
    121237
    122238                if ( $on_page < $total_pages ) {
    123239                    $i = $on_page + 1;
    124                     $page_string .= "&nbsp;<a class='page-numbers label-last' href='" . self::url( $wp, $total_pages, $pretty ) . "'>&raquo;</a>";
    125                     $page_string .= "&nbsp;<a class='page-numbers label-next' href='" . self::url( $wp, $i, $pretty ) . "'>&rsaquo;</a>";
     240                    $page_string .= "&nbsp;<a class='page-numbers label-last' href='" . self::url( $wp, $total_pages, $pretty ) . "'>" . self::init_var( $settings, 'labels_last', '&raquo;', TRUE ) . "</a>";
     241                    $page_string .= "&nbsp;<a class='page-numbers label-next' href='" . self::url( $wp, $i, $pretty ) . "'>" . self::init_var( $settings, 'labels_next', '&rsaquo;', TRUE ) . "</a>";
    126242                }
    127243            }
     
    133249            return $page_string;
    134250        }
    135        
     251
    136252        /**
    137253         * Main display function. Should be called in a static fashion:
     
    148264         * @since 0.1a
    149265         */
    150         public static function draw ( $pretty = TRUE, $max_num_pages = FALSE, $labels = TRUE, $css = 'classic' ) {
     266        public static function draw( $pretty = TRUE, $max_num_pages = FALSE, $labels = TRUE, $css = 'classic' ) {
    151267
    152268            echo self::get( $pretty, $max_num_pages, $labels, $css );
    153269        }
    154        
     270
    155271        /**
    156272         * Create link href
     
    162278         */
    163279        private static function url( $wp, $i, $pretty ) {
    164                    
     280
     281            // Pretty permalinks
    165282            if ( TRUE == $pretty ) {
    166283                if ( get_query_var( 'paged' ) )
    167284                    $url = preg_replace( '!(/page/\d+)/?$!', '/page/' . $i, home_url( $wp->request ) );
    168                 else 
    169                     $url = home_url( $wp->request ) . '/page/' . $i; 
     285                else
     286                    $url = home_url( $wp->request ) . '/page/' . $i;
    170287            }
     288            // GET parameters
    171289            else
    172290                $url = home_url( $wp->request ) . '?paged=' . $i;
    173291           
    174             return $url;   
    175         }
    176 
     292            //This might be a search query, where WP uses GET parameters (who knows why):
     293            $params = parse_url( "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" );
     294            if ( isset( $params[ 'query' ] ) )
     295                $url.= '?' . $params[ 'query' ];
     296
     297            return $url;
     298        }
     299
     300        /**
     301         * For not getting pissed of too much by PHP notices. This function should
     302         * help to keep the "flow" of the code, i.e. limiting the amount of conditional
     303         * statements in HTML blocks, etc.
     304         *
     305         * Example use: selected( $this->init_var( $var2, $index ), $var )
     306         * Instead of: if( !empty( $var2[ $index ] ) ) : selected( $var2[ $index ], $var ); endif;
     307         *
     308         * @access  public
     309         * @param   var $var | the variable to check
     310         * @param   string $index | the index of the variable
     311         * @param   string, boolean $default | var default value
     312         * @param   bool $override_set_empty | Set var to default if it is emtpy
     313         * @return  var $var[ $index ] | the value of $var[ $index ]
     314         * @since   0.1a
     315         */
     316        public function init_var ( $var, $index, $default = FALSE, $override_set_empty = FALSE ) {
     317
     318            // is the $index of $var not yet set or (optional) set but empty?
     319            if ( !isset( $var[ $index ] ) || ( TRUE == $override_set_empty && empty( $var[ $index ] ) ) )
     320                $var[ $index ] = ( FALSE == $default ) ? FALSE : $default;
     321
     322            return $var[ $index ];
     323        }
    177324    }
    178325
     326    // Instantiate class
     327    new threepagination();
    179328}
     329
    180330?>
  • 3pagination/trunk/examples/style.css

    r564699 r565111  
    88/* Navigation items: classic style */
    99.threepagination.classic {
    10     margin: 30px 0px;
    11     width: 100%;
     10        clear: both;
     11    margin: 30px 0px 20px;
    1212    padding: 5px;
    1313    overflow: hidden;
     
    1616.threepagination.classic span.current {
    1717    display: inline-block;
    18     padding: 0 3px;
     18        padding: 2px 2px 0;
    1919    margin: 2px -1px;
    2020
     
    3636/* Navigation items: classic-glow style */
    3737.threepagination.classic-glow {
    38     margin: 30px 0px;
    39     width: 100%;
     38        clear: both;
     39    margin: 30px 0px 20px;
    4040    padding: 5px;
    4141    overflow: hidden;
     
    4444.threepagination.classic-glow span.current {
    4545    display: inline-block;
    46     padding: 0 3px;
     46        padding: 2px 2px 0;
    4747    margin: 2px -1px;
    4848
     
    6969/* Navigation items: classic-small style */
    7070.threepagination.classic-small {
    71     margin: 30px 0px;
    72     width: 100%;
     71        clear: both;   
     72    margin: 30px 0px 20px;
    7373    padding: 5px;
    7474    overflow: hidden;
     
    7777.threepagination.classic-small span.current {
    7878    display: inline-block;
    79     padding: 0 3px;
     79        padding: 2px 2px 0;
    8080    margin: 1px -1px;
    8181
  • 3pagination/trunk/readme.txt

    r564703 r565111  
    33Tags: pagination
    44Requires at least: 3.3.2
    5 Tested up to: 3.4
    6 Stable tag: 1.0
     5Tested up to: 3.4.1
     6Stable tag: 1.2b
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1212== Description ==
    1313
    14 Give your visitors the ability to easily access all your site's content. This is meant for sites with high page numbers. Any page between 1 and 999 can be accessed with a maximum of 3 clicks (see screenshots).
     14Give your visitors the ability to easily access all your site's content. Any page between 1 and 999 can be accessed with a maximum of 3 clicks (see screenshots).
     15<ul>
     16<li>Easy access to all your website's content.</li>
     17<li>Please searchengines by creating a more complete internal linking structure.</li>
     18<li>No need to modify theme files (see below)!</li>
     19<li>So far, this code has been tested on index, archive, category and search pages of some of the most popular WordPress themes.</li>
     20</ul>
    1521
    16 So far, this code has been tested on index, archive and category pages of some of the most popular WordPress themes.
    17 
    18 Please leave feedback, bug reports or comments at https://github.com/paddelboot/3pagination/issues
     22Please leave feedback, bug reports or comments at https://github.com/paddelboot/3pagination/issues.
    1923
    2024== Installation ==
     
    25293. Display the pagination using `<?php if ( class_exists( 'threepagination' ) ) : threepagination::draw(); endif; ?>`
    2630
     31<h4>Implementation</h4>
     32All options can be set in an options page, the pagination container can be injected or appended to the existing DOM.
     33
    2734<h4>Functions</h4>
     35You can, if you want (or to have your website degrade gracefully), call the class methods in your theme files.
     36
    2837draw() : Display the pagination
    2938`draw ( $pretty = TRUE, $max_num_pages = FALSE, $labels = TRUE, $css = 'classic' )`
     
    6675- Fixed support of custom css styles via function parameter
    6776
     77= 1.2b =
     78- Added backend settings page
     79- Inject pagination into DOM
     80- Support for search templates
     81
    6882== A brief Markdown Example ==
    6983
Note: See TracChangeset for help on using the changeset viewer.