Skip to:
Content

BuddyPress.org

Changeset 5686


Ignore:
Timestamp:
02/09/2012 10:36:36 PM (14 years ago)
Author:
johnjamesjacoby
Message:

Remove unneeded globals and clean up some code in Blogs component. See #3989.

Location:
trunk/bp-blogs
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-blogs/bp-blogs-actions.php

    r4961 r5686  
    11<?php
     2
     3/**
     4 * BuddyPress Blogs Actions
     5 *
     6 * @package BuddyPress
     7 * @subpackage BlogsActions
     8 */
     9
    210// Exit if accessed directly
    311if ( !defined( 'ABSPATH' ) ) exit;
    412
     13/**
     14 * Redirect to a random blog in the multisite network
     15 *
     16 * @since BuddyPress (1.0)
     17 * @package BuddyPress
     18 * @subpackage BlogsActions
     19 */
    520function bp_blogs_redirect_to_random_blog() {
    6     global $bp, $wpdb;
    721
    8     if ( bp_is_blogs_component() && isset( $_GET['random-blog'] ) ) {
     22    // Bail if not looking for a random blog
     23    if ( ! bp_is_blogs_component() || ! isset( $_GET['random-blog'] ) )
     24        return;
     25
     26    // Multisite is active so find a random blog
     27    if ( is_multisite() ) {
    928        $blog = bp_blogs_get_random_blogs( 1, 1 );
     29        bp_core_redirect( get_site_url( $blog['blogs'][0]->blog_id ) );
    1030
    11         bp_core_redirect( get_site_url( $blog['blogs'][0]->blog_id ) );
     31    // No multisite and still called, always redirect to root
     32    } else {
     33        bp_core_redirect( bp_core_get_root_domain() );
    1234    }
    1335}
  • trunk/bp-blogs/bp-blogs-activity.php

    r5302 r5686  
    11<?php
    2 /******************************************************************************
    3  * These functions handle the recording, deleting and formatting of activity and
    4  * notifications for the user and for this specific component.
     2
     3/**
     4 * BuddyPress Blogs Activity
     5 *
     6 * @package BuddyPress
     7 * @subpackage BlogsActivity
    58 */
    69
     
    811if ( !defined( 'ABSPATH' ) ) exit;
    912
    10 
     13/**
     14 * Register activity actions for the blogs component
     15 *
     16 * @since BuddyPress (1.0)
     17 * @package BuddyPress
     18 * @subpackage BlogsActivity
     19 * @global type $bp
     20 * @return boolean
     21 */
    1122function bp_blogs_register_activity_actions() {
    1223    global $bp;
    1324
    14     if ( !bp_is_active( 'activity' ) )
     25    // Bail if activity is not active
     26    if ( ! bp_is_active( 'activity' ) )
    1527        return false;
    1628
     
    2335add_action( 'bp_register_activity_actions', 'bp_blogs_register_activity_actions' );
    2436
     37/**
     38 * Record the activity to the actvity stream
     39 *
     40 * @since BuddyPress (1.0)
     41 * @package BuddyPress
     42 * @subpackage BlogsActivity
     43 * @global BuddyPress $bp
     44 * @param array $args
     45 * @return boolean
     46 */
    2547function bp_blogs_record_activity( $args = '' ) {
    2648    global $bp;
    2749
    28     if ( !bp_is_active( 'activity' ) )
     50    // Bail if activity is not active
     51    if ( ! bp_is_active( 'activity' ) )
    2952        return false;
    3053
     
    4669
    4770    // Remove large images and replace them with just one image thumbnail
    48     if ( bp_is_active( 'activity' ) && !empty( $content ) )
     71    if ( !empty( $content ) )
    4972        $content = bp_activity_thumbnail_content_images( $content, $primary_link );
    5073
     
    6790}
    6891
     92/**
     93 * Delete a blogs activity stream item
     94 *
     95 * @since BuddyPress (1.0)
     96 * @package BuddyPress
     97 * @subpackage BlogsActivity
     98 * @global BuddyPress $bp
     99 * @param array $args
     100 * @return If activity is not active
     101 */
    69102function bp_blogs_delete_activity( $args = true ) {
    70103    global $bp;
    71104
    72     if ( bp_is_active( 'activity' ) ) {
    73         $defaults = array(
    74             'item_id'           => false,
    75             'component'         => $bp->blogs->id,
    76             'type'              => false,
    77             'user_id'           => false,
    78             'secondary_item_id' => false
    79         );
     105    // Bail if activity is not active
     106    if ( ! bp_is_active( 'activity' ) )
     107        return false;
    80108
    81         $params = wp_parse_args( $args, $defaults );
    82         extract( $params, EXTR_SKIP );
     109    $defaults = array(
     110        'item_id'           => false,
     111        'component'         => $bp->blogs->id,
     112        'type'              => false,
     113        'user_id'           => false,
     114        'secondary_item_id' => false
     115    );
    83116
    84         bp_activity_delete_by_item_id( array(
    85             'item_id'           => $item_id,
    86             'component'         => $component,
    87             'type'              => $type,
    88             'user_id'           => $user_id,
    89             'secondary_item_id' => $secondary_item_id
    90         ) );
    91     }
     117    $params = wp_parse_args( $args, $defaults );
     118    extract( $params, EXTR_SKIP );
     119
     120    bp_activity_delete_by_item_id( array(
     121        'item_id'           => $item_id,
     122        'component'         => $component,
     123        'type'              => $type,
     124        'user_id'           => $user_id,
     125        'secondary_item_id' => $secondary_item_id
     126    ) );
    92127}
    93128
  • trunk/bp-blogs/bp-blogs-buddybar.php

    r5302 r5686  
    11<?php
     2
     3/**
     4 * BuddyPress Blogs Activity
     5 *
     6 * @package BuddyPress
     7 * @subpackage BlogsBuddyBar
     8 */
     9
    210// Exit if accessed directly
    311if ( !defined( 'ABSPATH' ) ) exit;
    412
    5 // *** "My Blogs" Menu ********
     13/**
     14 * Add a Sites menu to the BuddyBar
     15 *
     16 * @since BuddyPress (1.0)
     17 * @package BuddyPress
     18 * @subpackage BlogsBuddyBar
     19 * @global BuddyPress $bp
     20 * @return boolean
     21 */
     22   
    623function bp_adminbar_blogs_menu() {
    724    global $bp;
     
    1330        return false;
    1431
    15     if ( !$blogs = wp_cache_get( 'bp_blogs_of_user_' . bp_loggedin_user_id() . '_inc_hidden', 'bp' ) ) {
     32    $blogs = wp_cache_get( 'bp_blogs_of_user_' . bp_loggedin_user_id() . '_inc_hidden', 'bp' );
     33    if ( empty( $blogs ) ) {
    1634        $blogs = bp_blogs_get_blogs_for_user( bp_loggedin_user_id(), true );
    1735        wp_cache_set( 'bp_blogs_of_user_' . bp_loggedin_user_id() . '_inc_hidden', $blogs, 'bp' );
  • trunk/bp-blogs/bp-blogs-cache.php

    r4961 r5686  
    11<?php
    2 /*******************************************************************************
    3  * Caching
     2
     3/**
     4 * BuddyPress Blogs Caching
    45 *
    56 * Caching functions handle the clearing of cached objects and pages on specific
    67 * actions throughout BuddyPress.
     8 *
     9 * @package BuddyPress
     10 * @subpackage BlogsBuddyBar
    711 */
    812
     
    1014if ( !defined( 'ABSPATH' ) ) exit;
    1115
     16/**
     17 * Clear the blog object cache
     18 *
     19 * @since BuddyPress (1.0)
     20 * @package BuddyPress
     21 * @subpackage BlogsBuddyBar
     22 * @param int $blog_id
     23 * @param int $user_id
     24 */
    1225function bp_blogs_clear_blog_object_cache( $blog_id, $user_id ) {
    13     wp_cache_delete( 'bp_blogs_of_user_' . $user_id, 'bp' );
     26    wp_cache_delete( 'bp_blogs_of_user_'        . $user_id, 'bp' );
    1427    wp_cache_delete( 'bp_total_blogs_for_user_' . $user_id, 'bp' );
    1528}
    1629
     30/**
     31 * Clear cache when a new blog is created
     32 *
     33 * @since BuddyPress (1.0)
     34 * @package BuddyPress
     35 * @subpackage BlogsBuddyBar
     36 * @param Blog $recorded_blog_obj
     37 */
    1738function bp_blogs_format_clear_blog_cache( $recorded_blog_obj ) {
    1839    bp_blogs_clear_blog_object_cache( false, $recorded_blog_obj->user_id );
  • trunk/bp-blogs/bp-blogs-classes.php

    r5329 r5686  
    11<?php
     2
     3/**
     4 * BuddyPress Blogs Classes
     5 *
     6 * @package BuddyPress
     7 * @subpackage BlogsClasses
     8 */
     9
    210// Exit if accessed directly
    311if ( !defined( 'ABSPATH' ) ) exit;
    412
    5 Class BP_Blogs_Blog {
     13/**
     14 * The main BuddyPress blog class
     15 *
     16 * @since BuddyPress (1.0)
     17 * @package BuddyPress
     18 * @subpackage BlogsClasses
     19 */
     20class BP_Blogs_Blog {
    621    var $id;
    722    var $user_id;
     
    1328
    1429    function __construct( $id = null ) {
    15         global $bp, $wpdb;
    16 
    17         $user_id = bp_displayed_user_id();
    18 
    19         if ( $id ) {
     30        if ( !empty( $id ) ) {
    2031            $this->id = $id;
    2132            $this->populate();
     
    280291    }
    281292}
     293
    282294?>
  • trunk/bp-blogs/bp-blogs-functions.php

    r5606 r5686  
    1818
    1919function bp_blogs_get_blogs( $args = '' ) {
    20     global $bp;
    2120
    2221    $defaults = array(
     
    7473 * Makes BuddyPress aware of a new site so that it can track its activity.
    7574 *
    76  * @global object $bp BuddyPress global settings
     75 * @since BuddyPress (1.0)
    7776 * @param int $blog_id
    7877 * @param int $user_id
    7978 * @param $bool $no_activity ; optional.
    80  * @since 1.0
    8179 * @uses BP_Blogs_Blog
    8280 */
    8381function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) {
    84     global $bp;
    85 
    86     if ( !$user_id )
     82
     83    if ( empty( $user_id ) )
    8784        $user_id = bp_loggedin_user_id();
    8885
     
    9693    $recorded_blog->user_id = $user_id;
    9794    $recorded_blog->blog_id = $blog_id;
    98 
    99     $recorded_blog_id = $recorded_blog->save();
    100 
    101     $is_recorded = !empty( $recorded_blog_id ) ? true : false;
     95    $recorded_blog_id       = $recorded_blog->save();
     96    $is_recorded            = !empty( $recorded_blog_id ) ? true : false;
    10297
    10398    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'name', $name );
     
    234229 * password protected.
    235230 *
    236  * @global $bp $bp
    237231 * @param int $comment_id
    238232 * @param bool $is_approved
     
    240234 */
    241235function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
    242     global $bp;
    243236
    244237    // Get the users comment
     
    365358
    366359function bp_blogs_remove_blog_for_user( $user_id, $blog_id ) {
    367     global $bp, $current_user;
    368 
    369     $blog_id = (int)$blog_id;
    370     $user_id = (int)$user_id;
     360    global $bp;
     361
     362    $blog_id = (int) $blog_id;
     363    $user_id = (int) $user_id;
    371364
    372365    do_action( 'bp_blogs_before_remove_blog_for_user', $blog_id, $user_id );
     
    375368
    376369    // Delete activity stream item
    377     bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->id, 'type' => 'new_blog' ) );
     370    bp_blogs_delete_activity( array(
     371        'item_id'   => $blog_id,
     372        'component' => $bp->blogs->id,
     373        'type'      => 'new_blog'
     374    ) );
    378375
    379376    do_action( 'bp_blogs_remove_blog_for_user', $blog_id, $user_id );
     
    405402
    406403function bp_blogs_remove_comment( $comment_id ) {
    407     global $wpdb, $bp;
     404    global $wpdb;
    408405
    409406    // Delete activity stream item
     
    497494
    498495function bp_blogs_total_blogs_for_user( $user_id = 0 ) {
    499     global $bp;
    500 
    501     if ( !$user_id )
     496
     497    if ( empty( $user_id ) )
    502498        $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
    503499
     
    653649add_action( 'delete_user',       'bp_blogs_remove_data' );
    654650add_action( 'bp_make_spam_user', 'bp_blogs_remove_data' );
     651
    655652?>
  • trunk/bp-blogs/bp-blogs-loader.php

    r5478 r5686  
    11<?php
     2
    23/**
    34 * BuddyPress Blogs Streams Loader
  • trunk/bp-blogs/bp-blogs-screens.php

    r4961 r5686  
    11<?php
     2
     3/**
     4 * BuddyPress Blogs Screens
     5 *
     6 * @package BuddyPress
     7 * @subpackage BlogsScreens
     8 */
     9
    210// Exit if accessed directly
    311if ( !defined( 'ABSPATH' ) ) exit;
  • trunk/bp-blogs/bp-blogs-template.php

    r5478 r5686  
    11<?php
     2
     3/**
     4 * BuddyPress Blogs Template Tags
     5 *
     6 * @package BuddyPress
     7 * @subpackage BlogsTemplate
     8 */
     9
    210// Exit if accessed directly
    311if ( !defined( 'ABSPATH' ) ) exit;
     
    715 *
    816 * @package BuddyPress
    9  * @subpackage Blogs Template
     17 * @subpackage BlogsTemplate
    1018 * @since BuddyPress (r4100)
    1119 *
     
    1927     *
    2028     * @package BuddyPress
    21      * @subpackage Blogs Template
     29     * @subpackage BlogsTemplate
    2230     * @since BuddyPress (r4100)
    2331     */
     
    3139 *
    3240 * @package BuddyPress
    33  * @subpackage Blogs Template
     41 * @subpackage BlogsTemplate
    3442 * @since BuddyPress (r4100)
    3543 *
     
    4351     *
    4452     * @package BuddyPress
    45      * @subpackage Blogs Template
     53     * @subpackage BlogsTemplate
    4654     * @since BuddyPress (r4100)
    4755     */
     
    5563 *
    5664 * @package BuddyPress
    57  * @subpackage Blogs Template
     65 * @subpackage BlogsTemplate
    5866 * @since 1.5
    5967 * @uses bp_get_blogs_directory_permalink()
     
    6674     *
    6775     * @package BuddyPress
    68      * @subpackage Blogs Template
     76     * @subpackage BlogsTemplate
    6977     * @since 1.5
    7078     * @uses apply_filters()
     
    100108
    101109    function __construct( $type, $page, $per_page, $max, $user_id, $search_terms ) {
    102         global $bp;
    103110
    104111        $this->pag_page = isset( $_REQUEST['bpage'] ) ? intval( $_REQUEST['bpage'] ) : $page;
     
    175182
    176183    function the_blog() {
    177         global $blog;
    178184
    179185        $this->in_the_loop = true;
     
    192198
    193199function bp_has_blogs( $args = '' ) {
    194     global $bp, $blogs_template;
     200    global $blogs_template;
    195201
    196202    /***
     
    228234
    229235    if ( $max ) {
    230         if ( $per_page > $max )
     236        if ( $per_page > $max ) {
    231237            $per_page = $max;
     238        }
    232239    }
    233240
     
    249256
    250257function bp_blogs_pagination_count() {
    251     global $bp, $blogs_template;
     258    global $blogs_template;
    252259
    253260    $start_num = intval( ( $blogs_template->pag_page - 1 ) * $blogs_template->pag_num ) + 1;
     
    272279}
    273280    function bp_get_blog_avatar( $args = '' ) {
    274         global $blogs_template, $bp;
     281        global $blogs_template;
    275282       
    276283        $defaults = array(
     
    402409
    403410function bp_show_blog_signup_form($blogname = '', $blog_title = '', $errors = '') {
    404     global $current_user, $current_site;
    405     global $bp;
     411    global $current_user;
    406412
    407413    if ( isset($_POST['submit']) ) {
     
    582588
    583589function bp_create_blog_link() {
    584     global $bp;
    585 
    586590    if ( bp_is_my_profile() )
    587591        echo apply_filters( 'bp_create_blog_link', '<a href="' . bp_get_root_domain() . '/' . bp_get_blogs_root_slug() . '/create/">' . __( 'Create a Site', 'buddypress' ) . '</a>' );
     
    589593
    590594function bp_blogs_blog_tabs() {
    591     global $bp, $groups_template;
    592595
    593596    // Don't show these tabs on a user's own profile
     
    608611
    609612function bp_directory_blogs_search_form() {
    610     global $bp;
    611613
    612614    $default_search_value = bp_get_search_default_text();
    613     $search_value = !empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value; ?>
     615    $search_value         = !empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value; ?>
    614616
    615617    <form action="" method="get" id="search-blogs-form">
  • trunk/bp-blogs/bp-blogs-widgets.php

    r4819 r5686  
    11<?php
     2
     3/**
     4 * BuddyPress Blogs Widgets
     5 *
     6 * @package BuddyPress
     7 * @subpackage BlogsWidgets
     8 */
     9
    210// Exit if accessed directly
    311if ( !defined( 'ABSPATH' ) ) exit;
    412
    5 /***
    6  * The recent blogs widget is actually just the activity feed filtered on "new_blog_post".
    7  * Why not make some of your own widgets using a filtered activity stream?
    8  */
     13// @todo not use create_function()
     14function bp_blogs_register_widgets() {
     15    global $wpdb;
    916
    10 function bp_blogs_register_widgets() {
    11     global $wpdb, $bp;
    12 
    13     if ( bp_is_active( 'activity' ) && (int)$wpdb->blogid == bp_get_root_blog_id() )
     17    if ( bp_is_active( 'activity' ) && (int) $wpdb->blogid == bp_get_root_blog_id() )
    1418        add_action('widgets_init', create_function('', 'return register_widget("BP_Blogs_Recent_Posts_Widget");') );
    1519}
     
    2731
    2832    function widget($args, $instance) {
    29         global $bp;
    3033
    3134        extract( $args );
Note: See TracChangeset for help on using the changeset viewer.