WordPress.org

Plugin Directory

Changeset 410442


Ignore:
Timestamp:
07/15/11 20:46:19 (3 years ago)
Author:
MrWiblog
Message:

Version 0.3: Added pagination

Location:
themebrowser/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • themebrowser/trunk/readme.txt

    r241220 r410442  
    44Tags: buddypress, themes, styles, templates, wpmu, multisite, showcase, advertise 
    55Requires at least: 2.7 
    6 Tested up to: 2.9.3 
    7 Stable tag: 0.2.1 
     6Tested up to: 3.2.1 
     7Stable tag: 0.3 
    88 
    99Show off the themes available for blogs in your WPMU site or Wordpress MultiSite with a simple shortcode in any post or page. 
     
    1212 
    1313If you run a WPMU (called Wordpress MultiSite in version 3 or above) webite where people can create their own blogs and choose a theme, it would be great to show off the available themes before people sign up. That's always a been a bit hard to do, until now. This very simple plugin allows you to add a shortcode - [themebrowser] - to any post or page where you want the full list of enabled themes to show. 
     14 
     15You can also paginate the themes by adding a "perpage" attribute to the shortcode, like this: [themebrowser perpage="10"] 
    1416 
    1517The list does not include themes that you have disabled in Site Admin. The details shown are the theme name, description and a screenshot (themes without a screenshot are also not included). 
     
    3537== Changelog == 
    3638 
     390.3: Added pagination 
    37400.2.1 Updated plugin URI. Added buddypress tag. 
    38410.2 Added Plugin Register 
  • themebrowser/trunk/themebrowser.php

    r241220 r410442  
    44Plugin URI: http://www.stillbreathing.co.uk/wordpress/themebrowser/ 
    55Description: Shows the list of installed themes in your site 
    6 Version: 0.2.1 
     6Version: 0.3 
    77Author: Chris Taylor 
    88Author URI: http://www.stillbreathing.co.uk 
     
    1414$register->slug = "themebrowser"; 
    1515$register->name = "Theme Browser"; 
    16 $register->version = "0.2.1"; 
     16$register->version = "0.3"; 
    1717$register->developer = "Chris Taylor"; 
    1818$register->homepage = "http://www.stillbreathing.co.uk"; 
     
    2222add_shortcode( 'themebrowser', 'themebrowser_shortcode' ); 
    2323 
    24 function themebrowser_shortcode() { 
     24function themebrowser_shortcode( $atts ) { 
     25 
     26    // get the number of thumbnails to show per page 
     27    extract( shortcode_atts( array(  
     28        'perpage' => '' 
     29    ), $atts ) ); 
     30     
     31    // the number of thumbnails per page must be -1 for unlimited, or a positive number 
     32    $perpage = (int) $perpage; 
     33    if ( $perpage == 0 ) $perpage = -1; 
     34 
     35    // set up pagination start 
     36    $start = themebrowser_findstart( $perpage ); 
     37    $end = $start + $perpage; 
     38 
    2539    // get all themes 
    2640    $themes = get_themes(); 
     
    2943    if ( function_exists( "get_site_option" ) ) { 
    3044        $allowed_themes = get_site_option( 'allowedthemes' ); 
     45    } else { 
     46        $allowed_themes = $themes; 
    3147    } 
     48     
     49    // filter out disallowed themes 
     50    $themestoshow = array(); 
     51    if ( $allowed_themes != "" ) { 
     52        foreach( $themes as $theme ) { 
     53            // check the themes is allowed, and it has a screenshot 
     54            if ( $theme["Screenshot"] != "" && ( $allowed_themes == "" || isset( $allowed_themes[ wp_specialchars( $theme[ 'Stylesheet' ] ) ] ) == true ) ) { 
     55                $themestoshow[] = $theme; 
     56            } 
     57        } 
     58    } else { 
     59        $themestoshow = $themes; 
     60    } 
     61     
     62    // get the total number of themes to show 
     63    $total_themes = count( $themestoshow ); 
     64     
     65    // get the number of pages 
     66    $pages = themebrowser_findpages( $total_themes, $perpage ); 
     67     
     68    // get the limit for this page 
     69    $end = $start + $perpage; 
     70    if ( $end > $total_themes ) $end = $total_themes; 
     71     
     72    // if pagination isn't enabled 
     73    if ( $perpage < 1 ) { 
     74        $start = 0; 
     75        $end = $total_themes; 
     76    } 
     77     
     78    // set up the pagination links 
     79    $pagelist = paginate_links( array( 
     80        'base' => add_query_arg( 'themebrowserpage', '%#%' ), 
     81        'format' => '', 
     82        'prev_text' => __('&laquo;'), 
     83        'next_text' => __('&raquo;'), 
     84        'total' => $pages, 
     85        'current' => $_GET['themebrowserpage'] 
     86    )); 
     87     
     88    if ( $perpage > 0 && $pagelist != "" ) { 
     89        echo '<p>Showing themes ' . ( $start + 1 ) . ' to ' . $end . ' (' . $perpage . ' per page).</p>'; 
     90        echo '<p style="clear:left;">' . $pagelist . '</p>'; 
     91    } 
     92     
    3293    // loop themes 
    33     foreach( $themes as $theme ) { 
    34         // check the themes is allowed, and it has a screenshot 
    35         if ( $theme["Screenshot"] != "" && ( $allowed_themes == "" || isset( $allowed_themes[ wp_specialchars( $theme['Stylesheet'] ) ] ) == true ) ) { 
    36             // echo the details 
    37             echo ' 
    38             <h3 style="clear:left;">' . $theme["Title"] . ' by ' . $theme["Author"] . '</h3> 
    39             <p><img src="' . $theme["Theme Root URI"] . "/" . $theme["Template"] . "/" . $theme["Screenshot"] . '" alt="' . $theme["Title"] . '" style="float: left; margin: 0 1em 1em 0;" width="300px" /> ' . $theme["Description"] . '</p> 
    40             '; 
    41         } 
     94    for( $x = $start; $x < $end; $x++  ) { 
     95     
     96        // get this theme 
     97        $theme = $themestoshow[ $x ]; 
     98 
     99        // echo the details 
     100        echo ' 
     101        <h3 style="clear:left;">' . $theme[ "Title" ] . ' by ' . $theme[ "Author" ] . '</h3> 
     102        <p><img src="' . $theme[ "Theme Root URI" ] . "/" . $theme[ "Template" ] . "/" . $theme[ "Screenshot" ] . '" alt="' . $theme[ "Title" ] . '" style="float: left; margin: 0 1em 1em 0;" width="300px" /> ' . $theme[ "Description" ] . '</p> 
     103        '; 
     104    } 
     105     
     106    if ( $perpage > 0 && $pagelist != "" ) { 
     107        echo '<p style="clear:left;">' . $pagelist . '</p>'; 
    42108    } 
    43109} 
     110 
     111function themebrowser_findstart( $limit ) { 
     112    if ( ( ! isset( $_GET[ 'themebrowserpage' ] ) ) || ( $_GET[ 'themebrowserpage' ] == "1" ) ) { 
     113        $start = 0; 
     114        $_GET[ 'themebrowserpage' ] = 1; 
     115    } else { 
     116        $start = ( $_GET[ 'themebrowserpage' ] -1 ) * $limit; 
     117    } 
     118    return $start; 
     119} 
     120 
     121function themebrowser_findpages( $count, $limit ) { 
     122     $pages = ( ( $count % $limit ) == 0 ) ? $count / $limit : floor( $count / $limit ) + 1;  
     123     return $pages; 
     124} 
     125 
     126function themebrowser_pagelist( $curpage, $pages, $count, $limit ) { 
     127    $qs = preg_replace( "&themebrowserpage=([0-9]+)", "", $_SERVER[ 'QUERY_STRING' ] ); 
     128    $start = themebrowser_findstart( $limit ); 
     129    $end = $start + $limit; 
     130    $page_list  = "<span class=\"displaying-num\">Displaying " . ( $start + 1 ). "&#8211;" . $end . " of " . $count . "</span>\n";  
     131 
     132    /* Print the first and previous page links if necessary */ 
     133    if ( ( $curpage != 1 ) && ( $curpage ) ) { 
     134       $page_list .= "<a href=\"" . $_SERVER[ 'PHP_SELF' ]."?" . $qs . "&amp;themebrowserpage=1\" class=\"page-numbers\">&laquo;</a>\n"; 
     135    }  
     136 
     137    if ( ( $curpage - 1 ) > 0 ) { 
     138       $page_list .= "<a href=\"" . $_SERVER[ 'PHP_SELF' ] . "?" . $qs . "&amp;themebrowserpage=" . ( $curpage - 1 ) . "\" class=\"page-numbers\">&lt;</a>\n"; 
     139    }  
     140 
     141    /* Print the numeric page list; make the current page unlinked and bold */ 
     142    for ( $i = 1; $i <= $pages; $i++ ) { 
     143        if ( $i == $curpage ) { 
     144            $page_list .= "<span class=\"page-numbers current\">" . $i . "</span>"; 
     145        } else { 
     146            $page_list .= "<a href=\"" . $_SERVER['PHP_SELF'] . "?" . $qs . "&amp;themebrowserpage=" . $i . "\" class=\"page-numbers\">" . $i . "</a>\n"; 
     147        } 
     148        $page_list .= " "; 
     149      }  
     150 
     151     /* Print the Next and Last page links if necessary */ 
     152     if ( ( $curpage + 1 ) <= $pages ) { 
     153        $page_list .= "<a href=\"" . $_SERVER['PHP_SELF'] . "?" . $qs . "&amp;themebrowserpage=" . ( $curpage + 1 ) . "\" class=\"page-numbers\">&gt;</a>\n"; 
     154     }  
     155 
     156     if ( ( $curpage != $pages ) && ( $pages != 0 ) ) { 
     157        $page_list .= "<a href=\"" . $_SERVER[ 'PHP_SELF' ] . "?" . $qs . "&amp;themebrowserpage=" . $pages . "\" class=\"page-numbers\">&raquo;</a>\n"; 
     158     } 
     159     $page_list .= "\n";  
     160 
     161     return $page_list; 
     162} 
    44163?> 
Note: See TracChangeset for help on using the changeset viewer.