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 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/classes/class-bp-activity-theme-compat.php

    r10515 r10516  
    11<?php
    22/**
    3  * BuddyPress Activity Screens.
    4  *
    5  * The functions in this file detect, with each page load, whether an Activity
    6  * component page is being requested. If so, it parses any necessary data from
    7  * the URL, and tells BuddyPress to load the appropriate template.
     3 * BuddyPress Activity Theme Compatibility.
    84 *
    95 * @package BuddyPress
    10  * @subpackage ActivityScreens
    11  * @since 1.5.0
     6 * @since 1.7.0
    127 */
    138
    149// Exit if accessed directly.
    1510defined( 'ABSPATH' ) || exit;
    16 
    17 /**
    18  * Load the Activity directory.
    19  *
    20  * @since 1.5.0
    21  *
    22  * @uses bp_displayed_user_id()
    23  * @uses bp_is_activity_component()
    24  * @uses bp_current_action()
    25  * @uses bp_update_is_directory()
    26  * @uses do_action() To call the 'bp_activity_screen_index' hook.
    27  * @uses bp_core_load_template()
    28  * @uses apply_filters() To call the 'bp_activity_screen_index' hook.
    29  */
    30 function bp_activity_screen_index() {
    31     if ( bp_is_activity_directory() ) {
    32         bp_update_is_directory( true, 'activity' );
    33 
    34         /**
    35          * Fires right before the loading of the Activity directory screen template file.
    36          *
    37          * @since 1.5.0
    38          */
    39         do_action( 'bp_activity_screen_index' );
    40 
    41         /**
    42          * Filters the template to load for the Activity directory screen.
    43          *
    44          * @since 1.5.0
    45          *
    46          * @param string $template Path to the activity template to load.
    47          */
    48         bp_core_load_template( apply_filters( 'bp_activity_screen_index', 'activity/index' ) );
    49     }
    50 }
    51 add_action( 'bp_screens', 'bp_activity_screen_index' );
    52 
    53 /**
    54  * Load the 'My Activity' page.
    55  *
    56  * @since 1.0.0
    57  *
    58  * @uses do_action() To call the 'bp_activity_screen_my_activity' hook.
    59  * @uses bp_core_load_template()
    60  * @uses apply_filters() To call the 'bp_activity_template_my_activity' hook.
    61  */
    62 function bp_activity_screen_my_activity() {
    63 
    64     /**
    65      * Fires right before the loading of the "My Activity" screen template file.
    66      *
    67      * @since 1.0.0
    68      */
    69     do_action( 'bp_activity_screen_my_activity' );
    70 
    71     /**
    72      * Filters the template to load for the "My Activity" screen.
    73      *
    74      * @since 1.0.0
    75      *
    76      * @param string $template Path to the activity template to load.
    77      */
    78     bp_core_load_template( apply_filters( 'bp_activity_template_my_activity', 'members/single/home' ) );
    79 }
    80 
    81 /**
    82  * Load the 'My Friends' activity page.
    83  *
    84  * @since 1.0.0
    85  *
    86  * @uses bp_is_active()
    87  * @uses bp_update_is_item_admin()
    88  * @uses bp_current_user_can()
    89  * @uses do_action() To call the 'bp_activity_screen_friends' hook.
    90  * @uses bp_core_load_template()
    91  * @uses apply_filters() To call the 'bp_activity_template_friends_activity' hook.
    92  */
    93 function bp_activity_screen_friends() {
    94     if ( !bp_is_active( 'friends' ) )
    95         return false;
    96 
    97     bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' );
    98 
    99     /**
    100      * Fires right before the loading of the "My Friends" screen template file.
    101      *
    102      * @since 1.2.0
    103      */
    104     do_action( 'bp_activity_screen_friends' );
    105 
    106     /**
    107      * Filters the template to load for the "My Friends" screen.
    108      *
    109      * @since 1.0.0
    110      *
    111      * @param string $template Path to the activity template to load.
    112      */
    113     bp_core_load_template( apply_filters( 'bp_activity_template_friends_activity', 'members/single/home' ) );
    114 }
    115 
    116 /**
    117  * Load the 'My Groups' activity page.
    118  *
    119  * @since 1.2.0
    120  *
    121  * @uses bp_is_active()
    122  * @uses bp_update_is_item_admin()
    123  * @uses bp_current_user_can()
    124  * @uses do_action() To call the 'bp_activity_screen_groups' hook.
    125  * @uses bp_core_load_template()
    126  * @uses apply_filters() To call the 'bp_activity_template_groups_activity' hook.
    127  */
    128 function bp_activity_screen_groups() {
    129     if ( !bp_is_active( 'groups' ) )
    130         return false;
    131 
    132     bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' );
    133 
    134     /**
    135      * Fires right before the loading of the "My Groups" screen template file.
    136      *
    137      * @since 1.2.0
    138      */
    139     do_action( 'bp_activity_screen_groups' );
    140 
    141     /**
    142      * Filters the template to load for the "My Groups" screen.
    143      *
    144      * @since 1.2.0
    145      *
    146      * @param string $template Path to the activity template to load.
    147      */
    148     bp_core_load_template( apply_filters( 'bp_activity_template_groups_activity', 'members/single/home' ) );
    149 }
    150 
    151 /**
    152  * Load the 'Favorites' activity page.
    153  *
    154  * @since 1.2.0
    155  *
    156  * @uses bp_update_is_item_admin()
    157  * @uses bp_current_user_can()
    158  * @uses do_action() To call the 'bp_activity_screen_favorites' hook.
    159  * @uses bp_core_load_template()
    160  * @uses apply_filters() To call the 'bp_activity_template_favorite_activity' hook.
    161  */
    162 function bp_activity_screen_favorites() {
    163     bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' );
    164 
    165     /**
    166      * Fires right before the loading of the "Favorites" screen template file.
    167      *
    168      * @since 1.2.0
    169      */
    170     do_action( 'bp_activity_screen_favorites' );
    171 
    172     /**
    173      * Filters the template to load for the "Favorites" screen.
    174      *
    175      * @since 1.2.0
    176      *
    177      * @param string $template Path to the activity template to load.
    178      */
    179     bp_core_load_template( apply_filters( 'bp_activity_template_favorite_activity', 'members/single/home' ) );
    180 }
    181 
    182 /**
    183  * Load the 'Mentions' activity page.
    184  *
    185  * @since 1.2.0
    186  *
    187  * @uses bp_update_is_item_admin()
    188  * @uses bp_current_user_can()
    189  * @uses do_action() To call the 'bp_activity_screen_mentions' hook.
    190  * @uses bp_core_load_template()
    191  * @uses apply_filters() To call the 'bp_activity_template_mention_activity' hook.
    192  */
    193 function bp_activity_screen_mentions() {
    194     bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' );
    195 
    196     /**
    197      * Fires right before the loading of the "Mentions" screen template file.
    198      *
    199      * @since 1.2.0
    200      */
    201     do_action( 'bp_activity_screen_mentions' );
    202 
    203     /**
    204      * Filters the template to load for the "Mentions" screen.
    205      *
    206      * @since 1.2.0
    207      *
    208      * @param string $template Path to the activity template to load.
    209      */
    210     bp_core_load_template( apply_filters( 'bp_activity_template_mention_activity', 'members/single/home' ) );
    211 }
    212 
    213 /**
    214  * Reset the logged-in user's new mentions data when he visits his mentions screen.
    215  *
    216  * @since 1.5.0
    217  *
    218  * @uses bp_is_my_profile()
    219  * @uses bp_activity_clear_new_mentions()
    220  * @uses bp_loggedin_user_id()
    221  */
    222 function bp_activity_reset_my_new_mentions() {
    223     if ( bp_is_my_profile() )
    224         bp_activity_clear_new_mentions( bp_loggedin_user_id() );
    225 }
    226 add_action( 'bp_activity_screen_mentions', 'bp_activity_reset_my_new_mentions' );
    227 
    228 /**
    229  * Load the page for a single activity item.
    230  *
    231  * @since 1.2.0
    232  *
    233  * @uses bp_is_activity_component()
    234  * @uses bp_activity_get_specific()
    235  * @uses bp_current_action()
    236  * @uses bp_action_variables()
    237  * @uses bp_do_404()
    238  * @uses bp_is_active()
    239  * @uses groups_get_group()
    240  * @uses groups_is_user_member()
    241  * @uses apply_filters_ref_array() To call the 'bp_activity_permalink_access' hook.
    242  * @uses do_action() To call the 'bp_activity_screen_single_activity_permalink' hook.
    243  * @uses bp_core_add_message()
    244  * @uses is_user_logged_in()
    245  * @uses bp_core_redirect()
    246  * @uses site_url()
    247  * @uses esc_url()
    248  * @uses bp_get_root_domain()
    249  * @uses bp_get_activity_root_slug()
    250  * @uses bp_core_load_template()
    251  * @uses apply_filters() To call the 'bp_activity_template_profile_activity_permalink' hook.
    252  */
    253 function bp_activity_screen_single_activity_permalink() {
    254     $bp = buddypress();
    255 
    256     // No displayed user or not viewing activity component.
    257     if ( !bp_is_activity_component() )
    258         return false;
    259 
    260     if ( ! bp_current_action() || !is_numeric( bp_current_action() ) )
    261         return false;
    262 
    263     // Get the activity details.
    264     $activity = bp_activity_get_specific( array( 'activity_ids' => bp_current_action(), 'show_hidden' => true, 'spam' => 'ham_only', ) );
    265 
    266     // 404 if activity does not exist
    267     if ( empty( $activity['activities'][0] ) || bp_action_variables() ) {
    268         bp_do_404();
    269         return;
    270 
    271     } else {
    272         $activity = $activity['activities'][0];
    273     }
    274 
    275     // Default access is true.
    276     $has_access = true;
    277 
    278     // If activity is from a group, do an extra cap check.
    279     if ( isset( $bp->groups->id ) && $activity->component == $bp->groups->id ) {
    280 
    281         // Activity is from a group, but groups is currently disabled.
    282         if ( !bp_is_active( 'groups') ) {
    283             bp_do_404();
    284             return;
    285         }
    286 
    287         // Check to see if the group is not public, if so, check the
    288         // user has access to see this activity.
    289         if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) ) {
    290 
    291             // Group is not public.
    292             if ( 'public' != $group->status ) {
    293 
    294                 // User is not a member of group.
    295                 if ( !groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) {
    296                     $has_access = false;
    297                 }
    298             }
    299         }
    300     }
    301 
    302     /**
    303      * Filters the access permission for a single activity view.
    304      *
    305      * @since 1.2.0
    306      *
    307      * @param array $access Array holding the current $has_access value and current activity item instance.
    308      */
    309     $has_access = apply_filters_ref_array( 'bp_activity_permalink_access', array( $has_access, &$activity ) );
    310 
    311     /**
    312      * Fires before the loading of a single activity template file.
    313      *
    314      * @since 1.2.0
    315      *
    316      * @param BP_Activity_Activity $activity   Object representing the current activity item being displayed.
    317      * @param bool                 $has_access Whether or not the current user has access to view activity.
    318      */
    319     do_action( 'bp_activity_screen_single_activity_permalink', $activity, $has_access );
    320 
    321     // Access is specifically disallowed.
    322     if ( false === $has_access ) {
    323 
    324         // User feedback.
    325         bp_core_add_message( __( 'You do not have access to this activity.', 'buddypress' ), 'error' );
    326 
    327         // Redirect based on logged in status.
    328         if ( is_user_logged_in() ) {
    329             $url = bp_loggedin_user_domain();
    330 
    331         } else {
    332             $url = sprintf(
    333                 site_url( 'wp-login.php?redirect_to=%s' ),
    334                 urlencode( esc_url_raw( bp_activity_get_permalink( (int) bp_current_action() ) ) )
    335             );
    336         }
    337 
    338         bp_core_redirect( $url );
    339     }
    340 
    341     /**
    342      * Filters the template to load for a single activity screen.
    343      *
    344      * @since 1.0.0
    345      *
    346      * @param string $template Path to the activity template to load.
    347      */
    348     bp_core_load_template( apply_filters( 'bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink' ) );
    349 }
    350 add_action( 'bp_screens', 'bp_activity_screen_single_activity_permalink' );
    351 
    352 /**
    353  * Add activity notifications settings to the notifications settings page.
    354  *
    355  * @since 1.2.0
    356  *
    357  * @uses bp_get_user_meta()
    358  * @uses bp_core_get_username()
    359  * @uses do_action() To call the 'bp_activity_screen_notification_settings' hook.
    360  */
    361 function bp_activity_screen_notification_settings() {
    362 
    363     if ( bp_activity_do_mentions() ) {
    364         if ( ! $mention = bp_get_user_meta( bp_displayed_user_id(), 'notification_activity_new_mention', true ) ) {
    365             $mention = 'yes';
    366         }
    367     }
    368 
    369     if ( ! $reply = bp_get_user_meta( bp_displayed_user_id(), 'notification_activity_new_reply', true ) ) {
    370         $reply = 'yes';
    371     }
    372 
    373     ?>
    374 
    375     <table class="notification-settings" id="activity-notification-settings">
    376         <thead>
    377             <tr>
    378                 <th class="icon">&nbsp;</th>
    379                 <th class="title"><?php _e( 'Activity', 'buddypress' ) ?></th>
    380                 <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>
    381                 <th class="no"><?php _e( 'No', 'buddypress' )?></th>
    382             </tr>
    383         </thead>
    384 
    385         <tbody>
    386             <?php if ( bp_activity_do_mentions() ) : ?>
    387                 <tr id="activity-notification-settings-mentions">
    388                     <td>&nbsp;</td>
    389                     <td><?php printf( __( 'A member mentions you in an update using "@%s"', 'buddypress' ), bp_core_get_username( bp_displayed_user_id() ) ) ?></td>
    390                     <td class="yes"><input type="radio" name="notifications[notification_activity_new_mention]" id="notification-activity-new-mention-yes" value="yes" <?php checked( $mention, 'yes', true ) ?>/><label for="notification-activity-new-mention-yes" class="bp-screen-reader-text"><?php _e( 'Yes, send email', 'buddypress' ); ?></label></td>
    391                     <td class="no"><input type="radio" name="notifications[notification_activity_new_mention]" id="notification-activity-new-mention-no" value="no" <?php checked( $mention, 'no', true ) ?>/><label for="notification-activity-new-mention-no" class="bp-screen-reader-text"><?php _e( 'No, do not send email', 'buddypress' ); ?></label></td>
    392                 </tr>
    393             <?php endif; ?>
    394 
    395             <tr id="activity-notification-settings-replies">
    396                 <td>&nbsp;</td>
    397                 <td><?php _e( "A member replies to an update or comment you've posted", 'buddypress' ) ?></td>
    398                 <td class="yes"><input type="radio" name="notifications[notification_activity_new_reply]" id="notification-activity-new-reply-yes" value="yes" <?php checked( $reply, 'yes', true ) ?>/><label for="notification-activity-new-reply-yes" class="bp-screen-reader-text"><?php _e( 'Yes, send email', 'buddypress' ); ?></label></td>
    399                 <td class="no"><input type="radio" name="notifications[notification_activity_new_reply]" id="notification-activity-new-reply-no" value="no" <?php checked( $reply, 'no', true ) ?>/><label for="notification-activity-new-reply-no" class="bp-screen-reader-text"><?php _e( 'No, do not send email', 'buddypress' ); ?></label></td>
    400             </tr>
    401 
    402             <?php
    403 
    404             /**
    405              * Fires inside the closing </tbody> tag for activity screen notification settings.
    406              *
    407              * @since 1.2.0
    408              */
    409             do_action( 'bp_activity_screen_notification_settings' ) ?>
    410         </tbody>
    411     </table>
    412 
    413 <?php
    414 }
    415 add_action( 'bp_notification_settings', 'bp_activity_screen_notification_settings', 1 );
    416 
    417 /** Theme Compatibility *******************************************************/
    41811
    41912/**
     
    586179    }
    587180}
    588 new BP_Activity_Theme_Compat();
Note: See TracChangeset for help on using the changeset viewer.