Skip to:
Content

bbPress.org


Ignore:
Timestamp:
01/09/2011 10:06:53 PM (15 years ago)
Author:
johnjamesjacoby
Message:

Introduce views API into plugin. Allows for creating specific topic views with code rather than with templates. The 'no-replies' view is included as default. Props GautamGupta via Google Code-in

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbpress.php

    r2786 r2789  
    11<?php
     2/**
     3 * The bbPress Plugin
     4 *
     5 * bbPress is forum software with a twist from the creators of WordPress.
     6 *
     7 * @package bbPress
     8 * @subpackage Main
     9 */
     10
    211/**
    312 * Plugin Name: bbPress
     
    1019
    1120/**
    12  * The bbPress Plugin
    13  *
    14  * bbPress is forum software with a twist from the creators of WordPress.
    15  *
    16  * @package bbPress
    17  * @subpackage Main
    18  */
    19 /**
    2021 * bbPress vesion
    2122 *
     
    103104    var $user_slug;
    104105
     106    /**
     107     * @var string View slug
     108     */
     109    var $view_slug;
     110
    105111    // Absolute Paths
    106112
     
    191197     */
    192198    var $errors;
     199
     200    // Views
     201
     202    /**
     203     * @var array An array of registered bbPress views
     204     */
     205    var $views;
    193206
    194207    /**
     
    222235
    223236        // bbPress root directory
    224         $this->file              = __FILE__;
    225         $this->plugin_dir        = plugin_dir_path( $this->file );
    226         $this->plugin_url        = plugin_dir_url ( $this->file );
     237        $this->file             = __FILE__;
     238        $this->plugin_dir       = plugin_dir_path( $this->file );
     239        $this->plugin_url       = plugin_dir_url ( $this->file );
    227240
    228241        // Images
    229         $this->images_url        = $this->plugin_url . 'bbp-images';
     242        $this->images_url       = $this->plugin_url . 'bbp-images';
    230243
    231244        // Themes
    232         $this->themes_dir        = WP_PLUGIN_DIR . '/' . basename( dirname( __FILE__ ) ) . '/bbp-themes';
    233         $this->themes_url        = $this->plugin_url . 'bbp-themes';
     245        $this->themes_dir       = WP_PLUGIN_DIR . '/' . basename( dirname( __FILE__ ) ) . '/bbp-themes';
     246        $this->themes_url       = $this->plugin_url . 'bbp-themes';
    234247
    235248        /** Identifiers ***********************************************/
    236249
    237250        // Post type identifiers
    238         $this->forum_id           = apply_filters( 'bbp_forum_post_type',  'bbp_forum'     );
    239         $this->topic_id           = apply_filters( 'bbp_topic_post_type',  'bbp_topic'     );
    240         $this->reply_id           = apply_filters( 'bbp_reply_post_type',  'bbp_reply'     );
    241         $this->topic_tag_id       = apply_filters( 'bbp_topic_tag_id',     'bbp_topic_tag' );
     251        $this->forum_id         = apply_filters( 'bbp_forum_post_type',  'bbp_forum'     );
     252        $this->topic_id         = apply_filters( 'bbp_topic_post_type',  'bbp_topic'     );
     253        $this->reply_id         = apply_filters( 'bbp_reply_post_type',  'bbp_reply'     );
     254        $this->topic_tag_id     = apply_filters( 'bbp_topic_tag_id',     'bbp_topic_tag' );
    242255
    243256        // Status identifiers
     
    249262
    250263        // Root forum slug
    251         $this->root_slug          = apply_filters( 'bbp_root_slug',      get_option( '_bbp_root_slug', 'forums' ) );
     264        $this->root_slug        = apply_filters( 'bbp_root_slug',      get_option( '_bbp_root_slug', 'forums' ) );
    252265
    253266        // Should we include the root slug in front of component slugs
     
    255268
    256269        // Component slugs
    257         $this->user_slug          = apply_filters( 'bbp_user_slug',      get_option( '_bbp_user_slug',      $prefix . 'user'  ) );
    258         $this->forum_slug         = apply_filters( 'bbp_forum_slug',     get_option( '_bbp_forum_slug',     $prefix . 'forum' ) );
    259         $this->topic_slug         = apply_filters( 'bbp_topic_slug',     get_option( '_bbp_topic_slug',     $prefix . 'topic' ) );
    260         $this->reply_slug         = apply_filters( 'bbp_reply_slug',     get_option( '_bbp_reply_slug',     $prefix . 'reply' ) );
    261         $this->topic_tag_slug     = apply_filters( 'bbp_topic_tag_slug', get_option( '_bbp_topic_tag_slug', $prefix . 'tag'   ) );
     270        $this->user_slug        = apply_filters( 'bbp_user_slug',      $prefix . get_option( '_bbp_user_slug',      'user'  ) );
     271        $this->view_slug        = apply_filters( 'bbp_view_slug',      $prefix . get_option( '_bbp_view_slug',      'view'  ) );
     272        $this->forum_slug       = apply_filters( 'bbp_forum_slug',     $prefix . get_option( '_bbp_forum_slug',     'forum' ) );
     273        $this->topic_slug       = apply_filters( 'bbp_topic_slug',     $prefix . get_option( '_bbp_topic_slug',     'topic' ) );
     274        $this->reply_slug       = apply_filters( 'bbp_reply_slug',     $prefix . get_option( '_bbp_reply_slug',     'reply' ) );
     275        $this->topic_tag_slug   = apply_filters( 'bbp_topic_tag_slug', $prefix . get_option( '_bbp_topic_tag_slug', 'tag'   ) );
    262276
    263277        /** Misc ******************************************************/
     
    265279        // Errors
    266280        $this->errors = new WP_Error();
     281
     282        // Views
     283        $this->views  = array();
    267284    }
    268285
     
    326343        add_action( 'bbp_register_taxonomies',      array( $this, 'register_taxonomies'      ), 10, 2 );
    327344
    328         // Register theme directory
     345        // Register the views
     346        add_action( 'bbp_register_views',           array( $this, 'register_views'           ), 10, 2 );
     347
     348        // Register the theme directory
    329349        add_action( 'bbp_register_theme_directory', array( $this, 'register_theme_directory' ), 10, 2 );
    330350
     
    651671
    652672    /**
     673     * Register the bbPress views
     674     *
     675     * @since bbPress (r2789)
     676     *
     677     * @uses bbp_register_view() To register the views
     678     */
     679    function register_views() {
     680
     681        // Topics with no replies
     682        $no_replies = apply_filters( 'bbp_register_view_no_replies', array(
     683            'meta_key'     => '_bbp_topic_reply_count',
     684            'meta_value'   => 1,
     685            'meta_compare' => '<',
     686            'orderby'      => ''
     687        ) );
     688
     689        bbp_register_view( 'no-replies', __( 'Topics with no replies', 'bbpress' ), $no_replies );
     690
     691    }
     692
     693    /**
    653694     * Setup the currently logged-in user
    654695     *
     
    679720        // User Profile tag
    680721        add_rewrite_tag( '%bbp_user%', '([^/]+)'   );
     722
     723        // View Page tag
     724        add_rewrite_tag( '%bbp_view%', '([^/]+)'   );
    681725
    682726        // Edit Page tag
     
    705749            // Profile Page
    706750            $this->user_slug . '/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?bbp_user=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ),
    707             $this->user_slug . '/([^/]+)/?$'                   => 'index.php?bbp_user=' . $wp_rewrite->preg_index( 1 )
     751            $this->user_slug . '/([^/]+)/?$'                   => 'index.php?bbp_user=' . $wp_rewrite->preg_index( 1 ),
     752
     753            // @todo - view feeds
     754            //$this->view_slug . '/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?bbp_view=' . $wp_rewrite->preg_index( 1 ) . '&feed='  . $wp_rewrite->preg_index( 2 ),
     755
     756            // View Page
     757            $this->view_slug . '/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?bbp_view=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ),
     758            $this->view_slug . '/([^/]+)/?$'                   => 'index.php?bbp_view=' . $wp_rewrite->preg_index( 1 )
    708759        );
    709760
Note: See TracChangeset for help on using the changeset viewer.