Plugin Directory

Changeset 612862


Ignore:
Timestamp:
10/15/2012 05:47:43 PM (13 years ago)
Author:
dgilfoy
Message:

pushing code cleanup, bug fixes and added features from github

Location:
posts-in-page/trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • posts-in-page/trunk/posts_in_page.php

    r611176 r612862  
    77 *  Author: IvyCat Web Services
    88 *  Author URI: http://www.ivycat.com
    9  *  version: 1.0.10
     9 *  version: 1.1.1
    1010 *  License: GNU General Public License v2.0
    1111 *  License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1212 
    1313 ------------------------------------------------------------------------
    14     IvyCat AJAX Slider, Copyright 2012 IvyCat, Inc. (admins@ivycat.com)
     14    IvyCat Posts in Page, Copyright 2012 IvyCat, Inc. (admins@ivycat.com)
    1515   
    1616    This program is free software; you can redistribute it and/or modify
     
    3030 */
    3131
    32 define( 'POSTSPAGE_DIR', dirname( __FILE__ ) );
    33 define( 'POSTPAGE_URL', str_replace( ABSPATH, site_url( '/' ), POSTSPAGE_DIR ) );
     32if ( !function_exists( 'add_action' ) )
     33    wp_die( 'You are trying to access this file in a manner not allowed.', 'Direct Access Forbidden', array( 'response' => '403' ) );
    3434
    35 class AddPostsToPage{
     35if ( ! defined( 'POSTSPAGE_DIR' ) )
     36    define( 'POSTSPAGE_DIR', plugin_dir_path( __FILE__ ) );
     37   
     38if ( ! defined( 'POSTPAGE_URL' ) )
     39    define( 'POSTPAGE_URL', plugin_dir_url( __FILE__ ) );
     40
     41require_once 'lib/page_posts.php';
     42
     43class ICAddPostsToPage {
    3644   
    37     protected $args;
    38    
    39     public function __construct(){
     45    public function __construct( ) {
    4046        add_shortcode( 'ic_add_posts', array( &$this, 'posts_in_page' ) );
    4147        add_shortcode( 'ic_add_post', array( &$this, 'post_in_page' ) );
     
    4450    }
    4551   
     52    /**
     53     *  Add settings link on plugins page.
     54     */
    4655    public function plugin_action_links( $actions, $plugin_file, $plugin_data, $context ) {
    4756        if ( is_plugin_active( $plugin_file ) )
     
    5059    }
    5160 
    52     public function posts_in_page( $atts ){
    53         extract( shortcode_atts( array(
    54             'category' => false,
    55             'cats' => false,
    56             'post_type' => false,
    57             'tax' => false,
    58             'term' => false,
    59             'showposts' => 10,
    60             'tag' => false,
    61             'template' => false,
    62             'ids' => false,
    63             'orderby' => false,
    64             'order' => false
    65         ), $atts ) );
    66         self::set_args( $atts );
    67         return self::output_posts();
     61    /**
     62     *  Main Shortcode
     63     *
     64     *  @param array $atts An array of shortcode parameters.  None required
     65     */
     66    public function posts_in_page( $atts ) {
     67        $posts = new ICPagePosts( $atts );
     68        return $posts->output_posts( );
    6869    }
    69 
    70     public function plugin_page_init(){
    71         if( !current_user_can( 'administrator' ) ) return;   
    72         $hooks = array();
     70   
     71    /**
     72     *  Depreciated Shortcode (routing to posts in page function now )
     73     *
     74     *  @todo Remove this depreciated function.
     75     */
     76    public function post_in_page( $atts ) {
     77        return self::posts_in_page( $atts );
     78    }
     79   
     80    /**
     81     *  Init Plugin, add menu page and setup hooks to load assets on the plugin options page
     82     */
     83    public function plugin_page_init() {
     84        if( !current_user_can( 'administrator' ) )
     85            return;
     86       
     87        $hooks = array( );
    7388        $hooks[] = add_options_page( __( 'Posts In Page' ), __( 'Posts In Page' ), 'read', 'posts_in_page',
    74             array( $this, 'plugin_page') );
    75         foreach($hooks as $hook) {
    76             add_action("admin_print_styles-{$hook}", array($this, 'load_assets'));
     89            array( $this, 'plugin_page' ) );
     90       
     91        foreach ( $hooks as $hook ) {
     92            add_action( "admin_print_styles-{$hook}", array( $this, 'load_assets' ) );
    7793        }
    7894    }
    7995
    80     public function load_assets(){
     96    /**
     97     * Enqueue Plugin Assets (Scripts and Styles)
     98     */
     99    public function load_assets( ) {
    81100        wp_enqueue_style( 'postpagestyle', POSTPAGE_URL. '/assets/post-page_styles.css' );
    82101        wp_enqueue_script( 'postpagescript', POSTPAGE_URL. '/assets/post-page_scripts.js' );
    83102    }
    84 
    85     public function plugin_page(){
     103   
     104    /**
     105     * Plugin Setting page - includes view for the page
     106     */
     107    public function plugin_page( ) {
    86108        require_once 'assets/posts_in_page_help_view.php';
    87109    }
    88110   
    89     protected function output_posts(){
    90         $page_posts = new WP_Query( $this->args );
    91         $output = '';
    92         if( $page_posts->have_posts() ): while( $page_posts->have_posts()):
    93         $output .= self::add_template_part( $page_posts );
    94         endwhile; endif;
    95         wp_reset_postdata();
    96         return $output;
    97     }
    98    
    99     public function post_in_page( $atts ){
    100         $args = array( 'post_type' => (  $atts['post_type'] ) ? $atts['post_type'] : 'post' );
    101         if( $atts['id'] ) {
    102             $ids = explode( ',', $atts['id'] );
    103             if( count( $ids ) > 1 ):
    104                 $args['post__in'] = $ids;
    105                 $args['posts_per_page'] = count( $ids );
    106             else:
    107                 $args['p'] = $atts['id'];
    108                 $args['posts_per_page'] = 1;
    109             endif;
    110         }
    111        
    112         $page_posts = new WP_Query( $args );
    113         //fprint_r( $page_posts );
    114         $output = '';
    115         if( $page_posts->have_posts() ): while( $page_posts->have_posts()):
    116         $output .= self::add_template_part( $page_posts );
    117         endwhile; endif;
    118         wp_reset_postdata();
    119         return $output;
    120     }
    121    
    122     protected function set_args( $atts ){
    123         global $wp_query;
    124         $this->args = array( 'post_type' => (  $atts['post_type'] ) ? $atts['post_type'] : 'post' );
    125         $this->args['post_status'] = 'publish';
    126         if($atts['ids'] ){
    127             $post_ids = explode( ',', $atts['ids'] );
    128             $this->args['post__in'] = $post_ids;
    129             $this->args['posts_per_page'] = count( $post_ids );
    130         }
    131         if( $atts['orderby'] ){
    132             $this->args['orderby'] = $atts['orderby'];
    133         }
    134         if( $atts['order'] )
    135             $this->args['order'] = $atts['order'];
    136            
    137         if( $atts['template'] ) $this->args['template'] = $atts['template'];
    138         if( $atts['category'] ){
    139             $cats = explode( ',', $atts['category'] );
    140             $this->args['category_name'] = ( count( $cats ) > 1 ) ? $cats : $atts['category'];
    141         }elseif( $atts['cats'] ){
    142             $cats = explode( ',', $atts['cats'] );
    143             $this->args['category_name'] = ( count( $cats ) > 1 ) ? $cats : $atts['cats'];
    144         }
    145         if( $atts['tax'] ){
    146             if( $atts['term'] ){
    147                 $terms = explode( ',', $atts['term'] );
    148                 $this->args['tax_query'] = array(
    149                     array( 'taxonomy' => $atts['tax'], 'field' => 'slug', 'terms' => ( count( $terms ) > 1 ) ? $terms : $atts['term'] )
    150                 );
    151             }
    152         }
    153         if( $atts['tag'] ){
    154             $tags = explode( ',', $atts['category'] );
    155             $this->args['tag'] = ( count( $tags ) > 1 ) ? $tags : $atts['tag'];
    156         }
    157         if( !$this->args['posts_per_page'] ) $this->args[ 'posts_per_page' ] = $atts['showposts'];
    158         if( $wp_query->query_vars['page'] > 1 ){
    159             $this->args['paged'] = $wp_query->query_vars['page'];
    160         }
    161     }
    162    
    163     protected function has_theme_template(){
    164         $template_file = ( $this->args['template'] ) ? self::current_theme_path()  . '/' . $this->args['template'] : self::current_theme_path() . '/posts_loop_template.php';
    165        
    166         return ( file_exists( $template_file ) ) ? $template_file : false;
    167     }
    168    
    169    protected function add_template_part( $ic_posts, $singles=false ){
    170         if( $singles ){
    171             setup_postdata( $ic_posts );
    172         }else{
    173             $ic_posts->the_post();
    174         }
    175         ob_start();
    176         require ( $file_path = self::has_theme_template() ) ? str_replace( site_url(), '', $file_path ) : 'posts_loop_template.php';
    177         $output .= ob_get_contents();
    178         return ob_get_clean();
    179    }
    180    
    181     protected function current_theme_path(){
    182         $theme_data = explode( '/', get_bloginfo( 'stylesheet_directory' ) );
    183         $theme_path = get_theme_root();
    184         return $theme_path . '/' . $theme_data[ count( $theme_data ) -1 ];
    185     }
    186    
    187 } new AddPostsToPage();
     111}
     112
     113/**
     114* Instantiate the Plugin - called using the plugins_loaded action hook.
     115*/
     116function init_ic_posts_in_page( ) {
     117    new ICAddPostsToPage( );
     118}
     119
     120add_action( 'plugins_loaded', 'init_ic_posts_in_page' );
  • posts-in-page/trunk/readme.txt

    r611176 r612862  
    55Requires at least: 3.0
    66Tested up to: 3.4.1
    7 Stable tag: 1.0.10
     7Stable tag: 1.1.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3535
    3636* `[ic_add_posts]`  - Add all posts to a page (limit to what number posts in WordPress is set to), essentially adds blog "page" to page.
    37 * `[ic_add_posts ids='1,2,3']` - show one or many posts by specifying the post ID(s) (currently only one post type per shortcode)
     37* `[ic_add_posts ids='1,2,3']` - show one or many posts by specifying the post ID(s) ( specify all post types )
    3838* `[ic_add_posts post_type='post_type']` - show posts from a custom post type by specifying the post type slug ( must give post type if not a standard post )
     39    add multiple post types by separating with commas (i.e post_type1,post_type2)
    3940* `[ic_add_posts showposts='5']` - limit number of posts (or override default setting)
    4041* `[ic_add_posts orderby='title' order='ASC']` - orderby title - supports all WP orderby variables.  Order is optional, WP default
     
    4546* `[ic_add_posts template='template-in-theme-dir.php']` - In case you want to style your markup, add meta data, etc.  Each shortcode can reference a different template.  These templates must exist in the theme directory.
    4647
    47 Or any combination above.
     48Or any combination of the above.
    4849
    4950== Screenshots ==
     
    6869
    6970== Changelog ==
     71
     72= 1.1.1 =
     73* Code maintenance, fix for category bug, also added ability for multiple post types per shortcode.
     74
     75= 1.1.0 =
     76* Code maintenance, squash non-critical debug notices.
    7077
    7178= 1.0.10 =
     
    9299
    93100== Upgrade Notice ==
     101
     102= 1.1.0 =
     103* Code maintenance & housekeeping - non-critical update.
    94104
    95105= 1.0.10 =
Note: See TracChangeset for help on using the changeset viewer.