Skip to:
Content

BuddyPress.org

Changeset 3728 for trunk/bp-blogs.php


Ignore:
Timestamp:
01/18/2011 12:53:31 PM (13 years ago)
Author:
johnjamesjacoby
Message:

Code normalization and whitespace clean-up. Introduce bp-core-deprecated.php. Introduce root_slug globals into components with directories, to help with WP page slugs. Fixes #2600. Optimus Props boonebgorges

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-blogs.php

    r3708 r3728  
    11<?php
     2
     3// Required Files
    24require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-classes.php' );
    35require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-templatetags.php' );
    46
    5 /* Include the sitewide blog posts widget if this is a multisite installation */
     7// Include the sitewide blog posts widget if this is a multisite installation
    68if ( is_multisite() )
    79    require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-widgets.php' );
     
    1113
    1214    if ( !defined( 'BP_BLOGS_SLUG' ) && isset( $bp->pages->blogs->slug ) )
    13         define ( 'BP_BLOGS_SLUG', $bp->pages->blogs->slug );
    14     elseif( !defined( 'BP_BLOGS_SLUG' ) )
     15        define ( 'BP_BLOGS_SLUG', bp_core_component_slug_from_root_slug( $bp->pages->blogs->slug ) );
     16    else if( !defined( 'BP_BLOGS_SLUG' ) )
    1517        define ( 'BP_BLOGS_SLUG', 'blogs' );
    1618
    1719    // For internal identification
    18     $bp->blogs->id = 'blogs';
    19 
    20     $bp->blogs->slug = BP_BLOGS_SLUG;
    21 
     20    $bp->blogs->id   = 'blogs';
     21    $bp->blogs->name = $bp->pages->blogs->name;
     22
     23    // Slugs
     24    $bp->blogs->slug      = BP_BLOGS_SLUG;
     25    $bp->blogs->root_slug = $bp->pages->blogs->slug;
     26
     27    // Tables
    2228    $bp->blogs->table_name          = $bp->table_prefix . 'bp_user_blogs';
    2329    $bp->blogs->table_name_blogmeta = $bp->table_prefix . 'bp_user_blogs_blogmeta';
    2430
    25     $bp->blogs->format_notification_function = 'bp_blogs_format_notifications';
     31    // Notifications
     32    $bp->blogs->format_notification_function      = 'bp_blogs_format_notifications';
    2633
    2734    // Register this in the active components array
    28     $bp->active_components[$bp->blogs->slug] = $bp->blogs->id;
     35    $bp->active_components[$bp->blogs->slug]      = $bp->blogs->id;
    2936
    3037    // The default text for the blogs directory search box
     
    3643
    3744/**
    38  * bp_blogs_setup_nav()
    39  *
    4045 * Adds "Blog" to the navigation arrays for the current and logged in user.
    4146 *
     
    4752    global $bp;
    4853
    49     /* Blog/post/comment menus should not appear on single WordPress setups. Although comments
    50        and posts made by users will still show on their activity stream .*/
     54    /**
     55     * Blog/post/comment menus should not appear on single WordPress setups.
     56     * Although comments and posts made by users will still show on their
     57     * activity stream.
     58     */
    5159    if ( !is_multisite() )
    5260        return false;
    5361
    54     /* Add 'Blogs' to the main navigation */
     62    // Add 'Blogs' to the main navigation
    5563    bp_core_new_nav_item( array( 'name' => sprintf( __( 'Blogs <span>(%d)</span>', 'buddypress' ), bp_blogs_total_blogs_for_user() ), 'slug' => $bp->blogs->slug, 'position' => 30, 'screen_function' => 'bp_blogs_screen_my_blogs', 'default_subnav_slug' => 'my-blogs', 'item_css_id' => $bp->blogs->id ) );
    5664
    5765    $blogs_link = $bp->loggedin_user->domain . $bp->blogs->slug . '/';
    5866
    59     /* Set up the component options navigation for Blog */
     67    // Set up the component options navigation for Blog
    6068    if ( $bp->blogs->slug == $bp->current_component ) {
    6169        if ( bp_is_my_profile() ) {
     
    6472            }
    6573        } else {
    66             /* If we are not viewing the logged in user, set up the current users avatar and name */
     74            // If we are not viewing the logged in user, set up the current
     75            // users avatar and name
    6776            $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
    6877            $bp->bp_options_title = $bp->displayed_user->fullname;
     
    8796
    8897
    89 /********************************************************************************
     98/*******************************************************************************
    9099 * Screen Functions
    91100 *
     
    117126    bp_core_load_template( apply_filters( 'bp_blogs_template_create_a_blog', 'blogs/create' ) );
    118127}
    119 /* The create screen is not attached to a nav item, so we need to attach it to an action */
    120128add_action( 'wp', 'bp_blogs_screen_create_a_blog', 3 );
    121129
    122130
    123 /********************************************************************************
     131/*******************************************************************************
    124132 * Activity & Notification Functions
    125133 *
     
    148156        return false;
    149157
    150     /* Because blog, comment, and blog post code execution happens before anything else
    151        we may need to manually instantiate the activity component globals */
     158    /**
     159     * Because blog, comment, and blog post code execution happens before
     160     * anything else we may need to manually instantiate the activity
     161     * component globals.
     162     */
    152163    if ( !$bp->activity && function_exists('bp_activity_setup_globals') )
    153164        bp_activity_setup_globals();
    154165
    155166    $defaults = array(
    156         'user_id' => $bp->loggedin_user->id,
    157         'action' => '',
    158         'content' => '',
    159         'primary_link' => '',
    160         'component' => $bp->blogs->id,
    161         'type' => false,
    162         'item_id' => false,
     167        'user_id'           => $bp->loggedin_user->id,
     168        'action'            => '',
     169        'content'           => '',
     170        'primary_link'      => '',
     171        'component'         => $bp->blogs->id,
     172        'type'              => false,
     173        'item_id'           => false,
    163174        'secondary_item_id' => false,
    164         'recorded_time' => bp_core_current_time(),
    165         'hide_sitewide' => false
     175        'recorded_time'     => bp_core_current_time(),
     176        'hide_sitewide'     => false
    166177    );
    167178
     
    169180    extract( $r, EXTR_SKIP );
    170181
    171     /* Remove large images and replace them with just one image thumbnail */
     182    // Remove large images and replace them with just one image thumbnail
    172183    if ( function_exists( 'bp_activity_thumbnail_content_images' ) && !empty( $content ) )
    173184        $content = bp_activity_thumbnail_content_images( $content, $primary_link );
     
    179190        $content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $content ), $content );
    180191
    181     /* Check for an existing entry and update if one exists. */
     192    // Check for an existing entry and update if one exists.
    182193    $id = bp_activity_get_activity_id( array(
    183194        'user_id' => $user_id,
     
    194205    global $bp;
    195206
    196     if ( function_exists('bp_activity_delete_by_item_id') ) {
     207    if ( function_exists( 'bp_activity_delete_by_item_id' ) ) {
    197208        $defaults = array(
    198             'item_id' => false,
    199             'component' => $bp->blogs->id,
    200             'type' => false,
    201             'user_id' => false,
     209            'item_id'           => false,
     210            'component'         => $bp->blogs->id,
     211            'type'              => false,
     212            'user_id'           => false,
    202213            'secondary_item_id' => false
    203214        );
     
    229240
    230241    $defaults = array(
    231         'type' => 'active', // active, alphabetical, newest, or random.
    232         'user_id' => false, // Pass a user_id to limit to only blogs that this user has privilages higher than subscriber on.
    233         'search_terms' => false, // Limit to blogs that match these search terms
    234 
    235         'per_page' => 20, // The number of results to return per page
    236         'page' => 1, // The page to return if limiting per page
     242        'type'         => 'active', // active, alphabetical, newest, or random
     243        'user_id'      => false,    // Pass a user_id to limit to only blogs that this user has privilages higher than subscriber on
     244        'search_terms' => false,    // Limit to blogs that match these search terms
     245        'per_page'     => 20,       // The number of results to return per page
     246        'page'         => 1,        // The page to return if limiting per page
    237247    );
    238248
     
    246256    global $bp, $wpdb;
    247257
    248     /* Truncate user blogs table and re-record. */
     258    // Truncate user blogs table and re-record.
    249259    $wpdb->query( "TRUNCATE TABLE {$bp->blogs->table_name}" );
    250260
     
    320330
    321331/**
    322  * bp_blogs_update_option_blogname()
    323  *
    324332 * Updates blogname in BuddyPress blogmeta table
    325333 *
     
    330338function bp_blogs_update_option_blogname( $oldvalue, $newvalue ) {
    331339    global $wpdb;
     340
    332341    bp_blogs_update_blogmeta( $wpdb->blogid, 'name', $newvalue );
    333342}
     
    335344
    336345/**
    337  * bp_blogs_update_option_blogdescription()
    338  *
    339346 * Updates blogdescription in BuddyPress blogmeta table
    340347 *
     
    345352function bp_blogs_update_option_blogdescription( $oldvalue, $newvalue ) {
    346353    global $wpdb;
     354
    347355    bp_blogs_update_blogmeta( $wpdb->blogid, 'description', $newvalue );
    348356}
     
    380388
    381389            bp_blogs_record_activity( array(
    382                 'user_id'            => (int)$post->post_author,
     390                'user_id'           => (int)$post->post_author,
    383391                'action'            => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, &$post, $post_permalink ),
    384392                'content'           => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink ),
     
    402410
    403411/**
    404  * bp_blogs_record_comment()
    405  *
    406412 * Record blog comment activity. Checks if blog is public and post is not
    407413 * password protected.
     
    428434
    429435    // Get the user_id from the comment author email.
    430     $user = get_user_by_email( $recorded_comment->comment_author_email );
     436    $user    = get_user_by_email( $recorded_comment->comment_author_email );
    431437    $user_id = (int)$user->ID;
    432438
     
    436442
    437443    // Get blog and post data
    438     $blog_id = (int)$wpdb->blogid;
     444    $blog_id                = (int)$wpdb->blogid;
    439445    $recorded_comment->post = get_post( $recorded_comment->comment_post_ID );
    440446
     
    451457
    452458        // Prepare to record in activity streams
    453         if ( is_multisite() ) {
    454             $activity_action    = sprintf( __( '%1$s commented on the blog post %2$s on the blog %3$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' );
    455         } else {
    456             $activity_action    = sprintf( __( '%1$s commented on the blog post %2$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>' );
    457         }
     459        if ( is_multisite() )
     460            $activity_action = sprintf( __( '%1$s commented on the blog post %2$s on the blog %3$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' );
     461        else
     462            $activity_action = sprintf( __( '%1$s commented on the blog post %2$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>' );
    458463
    459464        $activity_content   = $recorded_comment->comment_content;
     
    478483}
    479484add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
    480 add_action( 'edit_comment', 'bp_blogs_record_comment', 10 );
     485add_action( 'edit_comment', 'bp_blogs_record_comment', 10    );
    481486
    482487function bp_blogs_manage_comment( $comment_id, $comment_status ) {
     
    509514}
    510515add_action( 'add_user_to_blog', 'bp_blogs_add_user_to_blog', 10, 3 );
    511 add_action( 'profile_update', 'bp_blogs_add_user_to_blog' );
    512 add_action( 'user_register', 'bp_blogs_add_user_to_blog' );
     516add_action( 'profile_update',   'bp_blogs_add_user_to_blog'        );
     517add_action( 'user_register',    'bp_blogs_add_user_to_blog'        );
    513518
    514519function bp_blogs_remove_user_from_blog( $user_id, $blog_id = false ) {
     
    605610    global $bp;
    606611
    607     /* If this is regular blog, delete all data for that blog. */
     612    // If this is regular blog, delete all data for that blog.
    608613    BP_Blogs_Blog::delete_blog_for_all( $blog_id );
    609614
     
    643648
    644649
    645 //
    646 // Blog meta functions
    647 // These functions are used to store specific blogmeta in one global table, rather than in each
    648 // blog's options table. Significantly speeds up global blog queries.
    649 // By default each blog's name, description and last updated time are stored and synced here.
    650 //
     650/*******************************************************************************
     651 * Blog meta functions
     652 *
     653 * These functions are used to store specific blogmeta in one global table,
     654 * rather than in each blog's options table. Significantly speeds up global blog
     655 * queries. By default each blog's name, description and last updated time are
     656 * stored and synced here.
     657 */
    651658
    652659function bp_blogs_delete_blogmeta( $blog_id, $meta_key = false, $meta_value = false ) {
     
    663670    $meta_value = trim( $meta_value );
    664671
    665     if ( !$meta_key ) {
     672    if ( !$meta_key )
    666673        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d", $blog_id ) );
    667     } else if ( $meta_value ) {
     674    else if ( $meta_value )
    668675        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s AND meta_value = %s", $blog_id, $meta_key, $meta_value ) );
    669     } else {
     676    else
    670677        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key ) );
    671     }
    672678
    673679    wp_cache_delete( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, 'bp' );
     
    723729    $meta_value = maybe_serialize($meta_value);
    724730
    725     if (empty($meta_value)) {
     731    if (empty( $meta_value ) )
    726732        return bp_blogs_delete_blogmeta( $blog_id, $meta_key );
    727     }
    728733
    729734    $cur = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key ) );
    730735
    731     if ( !$cur ) {
     736    if ( !$cur )
    732737        $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name_blogmeta} ( blog_id, meta_key, meta_value ) VALUES ( %d, %s, %s )", $blog_id, $meta_key, $meta_value ) );
    733     } else if ( $cur->meta_value != $meta_value ) {
     738    else if ( $cur->meta_value != $meta_value )
    734739        $wpdb->query( $wpdb->prepare( "UPDATE {$bp->blogs->table_name_blogmeta} SET meta_value = %s WHERE blog_id = %d AND meta_key = %s", $meta_value, $blog_id, $meta_key ) );
    735     } else {
    736         return false;
    737     }
     740    else
     741        return false;
    738742
    739743    wp_cache_set( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, $meta_value, 'bp' );
     
    746750        return false;
    747751
    748     /* If this is regular blog, delete all data for that blog. */
     752    // If this is regular blog, delete all data for that blog.
    749753    BP_Blogs_Blog::delete_blogs_for_user( $user_id );
    750754
    751755    do_action( 'bp_blogs_remove_data', $user_id );
    752756}
    753 add_action( 'wpmu_delete_user', 'bp_blogs_remove_data' );
    754 add_action( 'delete_user', 'bp_blogs_remove_data' );
     757add_action( 'wpmu_delete_user',  'bp_blogs_remove_data' );
     758add_action( 'delete_user',       'bp_blogs_remove_data' );
    755759add_action( 'bp_make_spam_user', 'bp_blogs_remove_data' );
    756760
    757761
    758 /********************************************************************************
     762/*******************************************************************************
    759763 * Caching
    760764 *
     
    775779// List actions to clear object caches on
    776780add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 );
    777 add_action( 'bp_blogs_new_blog', 'bp_blogs_format_clear_blog_cache', 10, 2 );
     781add_action( 'bp_blogs_new_blog',             'bp_blogs_format_clear_blog_cache', 10, 2 );
    778782
    779783// List actions to clear super cached pages on, if super cache is installed
    780784add_action( 'bp_blogs_remove_data_for_blog', 'bp_core_clear_cache' );
    781 add_action( 'bp_blogs_remove_comment', 'bp_core_clear_cache' );
    782 add_action( 'bp_blogs_remove_post', 'bp_core_clear_cache' );
     785add_action( 'bp_blogs_remove_comment',       'bp_core_clear_cache' );
     786add_action( 'bp_blogs_remove_post',          'bp_core_clear_cache' );
    783787add_action( 'bp_blogs_remove_blog_for_user', 'bp_core_clear_cache' );
    784 add_action( 'bp_blogs_remove_blog', 'bp_core_clear_cache' );
    785 add_action( 'bp_blogs_new_blog_comment', 'bp_core_clear_cache' );
    786 add_action( 'bp_blogs_new_blog_post', 'bp_core_clear_cache' );
    787 add_action( 'bp_blogs_new_blog', 'bp_core_clear_cache' );
    788 add_action( 'bp_blogs_remove_data', 'bp_core_clear_cache' );
     788add_action( 'bp_blogs_remove_blog',          'bp_core_clear_cache' );
     789add_action( 'bp_blogs_new_blog_comment',     'bp_core_clear_cache' );
     790add_action( 'bp_blogs_new_blog_post',        'bp_core_clear_cache' );
     791add_action( 'bp_blogs_new_blog',             'bp_core_clear_cache' );
     792add_action( 'bp_blogs_remove_data',          'bp_core_clear_cache' );
    789793
    790794?>
Note: See TracChangeset for help on using the changeset viewer.