Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/05/2016 03:54:56 AM (10 years ago)
Author:
boonebgorges
Message:

Move bp-activity classes to their own files.

See #6870.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-screens.php

    r10417 r10516  
    1414// Exit if accessed directly.
    1515defined( 'ABSPATH' ) || exit;
     16
     17require dirname( __FILE__ ) . '/classes/class-bp-activity-theme-compat.php';
    1618
    1719/**
     
    417419/** Theme Compatibility *******************************************************/
    418420
    419 /**
    420  * The main theme compat class for BuddyPress Activity.
    421  *
    422  * This class sets up the necessary theme compatibility actions to safely output
    423  * activity template parts to the_title and the_content areas of a theme.
    424  *
    425  * @since 1.7.0
    426  */
    427 class BP_Activity_Theme_Compat {
    428 
    429     /**
    430      * Set up the activity component theme compatibility.
    431      *
    432      * @since 1.7.0
    433      */
    434     public function __construct() {
    435         add_action( 'bp_setup_theme_compat', array( $this, 'is_activity' ) );
    436     }
    437 
    438     /**
    439      * Set up the theme compatibility hooks, if we're looking at an activity page.
    440      *
    441      * @since 1.7.0
    442      */
    443     public function is_activity() {
    444 
    445         // Bail if not looking at a group.
    446         if ( ! bp_is_activity_component() )
    447             return;
    448 
    449         // Activity Directory.
    450         if ( ! bp_displayed_user_id() && ! bp_current_action() ) {
    451             bp_update_is_directory( true, 'activity' );
    452 
    453             /** This action is documented in bp-activity/bp-activity-screens.php */
    454             do_action( 'bp_activity_screen_index' );
    455 
    456             add_filter( 'bp_get_buddypress_template',                array( $this, 'directory_template_hierarchy' ) );
    457             add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'directory_dummy_post' ) );
    458             add_filter( 'bp_replace_the_content',                    array( $this, 'directory_content'    ) );
    459 
    460         // Single activity.
    461         } elseif ( bp_is_single_activity() ) {
    462             add_filter( 'bp_get_buddypress_template',                array( $this, 'single_template_hierarchy' ) );
    463             add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'single_dummy_post' ) );
    464             add_filter( 'bp_replace_the_content',                    array( $this, 'single_dummy_content'    ) );
    465         }
    466     }
    467 
    468     /** Directory *************************************************************/
    469 
    470     /**
    471      * Add template hierarchy to theme compat for the activity directory page.
    472      *
    473      * This is to mirror how WordPress has {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
    474      *
    475      * @since 1.8.0
    476      *
    477      * @param string $templates The templates from bp_get_theme_compat_templates().
    478      * @return array $templates Array of custom templates to look for.
    479      */
    480     public function directory_template_hierarchy( $templates ) {
    481 
    482         /**
    483          * Filters the template hierarchy for the activity directory page.
    484          *
    485          * @since 1.8.0
    486          *
    487          * @param array $index-directory Array holding template names to be merged into template list.
    488          */
    489         $new_templates = apply_filters( 'bp_template_hierarchy_activity_directory', array(
    490             'activity/index-directory.php'
    491         ) );
    492 
    493         // Merge new templates with existing stack
    494         // @see bp_get_theme_compat_templates().
    495         $templates = array_merge( (array) $new_templates, $templates );
    496 
    497         return $templates;
    498     }
    499 
    500     /**
    501      * Update the global $post with directory data.
    502      *
    503      * @since 1.7.0
    504      */
    505     public function directory_dummy_post() {
    506         bp_theme_compat_reset_post( array(
    507             'ID'             => 0,
    508             'post_title'     => bp_get_directory_title( 'activity' ),
    509             'post_author'    => 0,
    510             'post_date'      => 0,
    511             'post_content'   => '',
    512             'post_type'      => 'page',
    513             'post_status'    => 'publish',
    514             'is_page'        => true,
    515             'comment_status' => 'closed'
    516         ) );
    517     }
    518 
    519     /**
    520      * Filter the_content with the groups index template part.
    521      *
    522      * @since 1.7.0
    523      */
    524     public function directory_content() {
    525         return bp_buffer_template_part( 'activity/index', null, false );
    526     }
    527 
    528     /** Single ****************************************************************/
    529 
    530     /**
    531      * Add custom template hierarchy to theme compat for activity permalink pages.
    532      *
    533      * This is to mirror how WordPress has {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
    534      *
    535      * @since 1.8.0
    536      *
    537      * @param string $templates The templates from bp_get_theme_compat_templates().
    538      * @return array $templates Array of custom templates to look for.
    539      */
    540     public function single_template_hierarchy( $templates ) {
    541 
    542         /**
    543          * Filters the template hierarchy for the activity permalink pages.
    544          *
    545          * @since 1.8.0
    546          *
    547          * @param array $index Array holding template names to be merged into template list.
    548          */
    549         $new_templates = apply_filters( 'bp_template_hierarchy_activity_single_item', array(
    550             'activity/single/index.php'
    551         ) );
    552 
    553         // Merge new templates with existing stack
    554         // @see bp_get_theme_compat_templates().
    555         $templates = array_merge( (array) $new_templates, $templates );
    556 
    557         return $templates;
    558     }
    559 
    560     /**
    561      * Update the global $post with the displayed user's data.
    562      *
    563      * @since 1.7.0
    564      */
    565     public function single_dummy_post() {
    566         bp_theme_compat_reset_post( array(
    567             'ID'             => 0,
    568             'post_title'     => __( 'Activity', 'buddypress' ),
    569             'post_author'    => 0,
    570             'post_date'      => 0,
    571             'post_content'   => '',
    572             'post_type'      => 'page',
    573             'post_status'    => 'publish',
    574             'is_page'        => true,
    575             'comment_status' => 'closed'
    576         ) );
    577     }
    578 
    579     /**
    580      * Filter the_content with the members' activity permalink template part.
    581      *
    582      * @since 1.7.0
    583      */
    584     public function single_dummy_content() {
    585         return bp_buffer_template_part( 'activity/single/home', null, false );
    586     }
    587 }
    588421new BP_Activity_Theme_Compat();
Note: See TracChangeset for help on using the changeset viewer.