Skip to:
Content

BuddyPress.org

Changeset 10517


Ignore:
Timestamp:
02/05/2016 04:08:04 AM (5 years ago)
Author:
boonebgorges
Message:

Move bp-blogs classes to their own files.

See #6870.

Location:
trunk/src/bp-blogs
Files:
4 edited
4 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/bp-blogs-loader.php

    r10417 r10517  
    1515defined( 'ABSPATH' ) || exit;
    1616
    17 /**
    18  * Creates our Blogs component.
    19  */
    20 class BP_Blogs_Component extends BP_Component {
    21 
    22     /**
    23      * Start the blogs component creation process.
    24      *
    25      * @since 1.5.0
    26      */
    27     public function __construct() {
    28         parent::start(
    29             'blogs',
    30             __( 'Site Directory', 'buddypress' ),
    31             buddypress()->plugin_dir,
    32             array(
    33                 'adminbar_myaccount_order' => 30,
    34                 'search_query_arg' => 'sites_search',
    35             )
    36         );
    37     }
    38 
    39     /**
    40      * Set up global settings for the blogs component.
    41      *
    42      * The BP_BLOGS_SLUG constant is deprecated, and only used here for
    43      * backwards compatibility.
    44      *
    45      * @since 1.5.0
    46      *
    47      * @see BP_Component::setup_globals() for description of parameters.
    48      *
    49      * @param array $args See {@link BP_Component::setup_globals()}.
    50      */
    51     public function setup_globals( $args = array() ) {
    52         $bp = buddypress();
    53 
    54         if ( ! defined( 'BP_BLOGS_SLUG' ) ) {
    55             define ( 'BP_BLOGS_SLUG', $this->id );
    56         }
    57 
    58         // Global tables for messaging component.
    59         $global_tables = array(
    60             'table_name'          => $bp->table_prefix . 'bp_user_blogs',
    61             'table_name_blogmeta' => $bp->table_prefix . 'bp_user_blogs_blogmeta',
    62         );
    63 
    64         $meta_tables = array(
    65             'blog' => $bp->table_prefix . 'bp_user_blogs_blogmeta',
    66         );
    67 
    68         // All globals for blogs component.
    69         $args = array(
    70             'slug'                  => BP_BLOGS_SLUG,
    71             'root_slug'             => isset( $bp->pages->blogs->slug ) ? $bp->pages->blogs->slug : BP_BLOGS_SLUG,
    72             'has_directory'         => is_multisite(), // Non-multisite installs don't need a top-level Sites directory, since there's only one site.
    73             'directory_title'       => _x( 'Sites', 'component directory title', 'buddypress' ),
    74             'notification_callback' => 'bp_blogs_format_notifications',
    75             'search_string'         => __( 'Search sites...', 'buddypress' ),
    76             'autocomplete_all'      => defined( 'BP_MESSAGES_AUTOCOMPLETE_ALL' ),
    77             'global_tables'         => $global_tables,
    78             'meta_tables'           => $meta_tables,
    79         );
    80 
    81         // Setup the globals.
    82         parent::setup_globals( $args );
    83 
    84         /**
    85          * Filters if a blog is public.
    86          *
    87          * In case the config is not multisite, the blog_public option is ignored.
    88          *
    89          * @since 2.3.0
    90          *
    91          * @param int $value Whether or not the blog is public.
    92          */
    93         if ( 0 !== apply_filters( 'bp_is_blog_public', (int) get_option( 'blog_public' ) ) || ! is_multisite() ) {
    94 
    95             /**
    96              * Filters the post types to track for the Blogs component.
    97              *
    98              * @since 1.5.0
    99              * @deprecated 2.3.0
    100              *
    101              * @param array $value Array of post types to track.
    102              */
    103             $post_types = apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) );
    104 
    105             foreach ( $post_types as $post_type ) {
    106                 add_post_type_support( $post_type, 'buddypress-activity' );
    107             }
    108         }
    109 
    110         // Filter the generic track parameters for the 'post' post type.
    111         add_filter( 'bp_activity_get_post_type_tracking_args', array( $this, 'post_tracking_args' ), 10, 2 );
    112     }
    113 
    114     /**
    115      * Include bp-blogs files.
    116      *
    117      * @see BP_Component::includes() for description of parameters.
    118      *
    119      * @param array $includes See {@link BP_Component::includes()}.
    120      */
    121     public function includes( $includes = array() ) {
    122 
    123         // Files to include.
    124         $includes = array(
    125             'cache',
    126             'actions',
    127             'screens',
    128             'classes',
    129             'template',
    130             'filters',
    131             'activity',
    132             'functions',
    133         );
    134 
    135         if ( is_multisite() ) {
    136             $includes[] = 'widgets';
    137         }
    138 
    139         // Include the files.
    140         parent::includes( $includes );
    141     }
    142 
    143     /**
    144      * Set up component navigation for bp-blogs.
    145      *
    146      * @see BP_Component::setup_nav() for a description of arguments.
    147      *
    148      * @param array $main_nav Optional. See BP_Component::setup_nav() for
    149      *                        description.
    150      * @param array $sub_nav  Optional. See BP_Component::setup_nav() for
    151      *                        description.
    152      */
    153     public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    154 
    155         /**
    156          * Blog/post/comment menus should not appear on single WordPress setups.
    157          * Although comments and posts made by users will still show on their
    158          * activity stream.
    159          */
    160         if ( ! is_multisite() ) {
    161             return false;
    162         }
    163 
    164         // Determine user to use.
    165         if ( bp_displayed_user_domain() ) {
    166             $user_domain = bp_displayed_user_domain();
    167         } elseif ( bp_loggedin_user_domain() ) {
    168             $user_domain = bp_loggedin_user_domain();
    169         } else {
    170             return;
    171         }
    172 
    173         $slug       = bp_get_blogs_slug();
    174         $parent_url = trailingslashit( $user_domain . $slug );
    175 
    176         // Add 'Sites' to the main navigation.
    177         $count    = (int) bp_get_total_blog_count_for_user();
    178         $class    = ( 0 === $count ) ? 'no-count' : 'count';
    179         $nav_text = sprintf( __( 'Sites <span class="%s">%s</span>', 'buddypress' ), esc_attr( $class ), bp_core_number_format( $count )  );
    180         $main_nav = array(
    181             'name'                => $nav_text,
    182             'slug'                => $slug,
    183             'position'            => 30,
    184             'screen_function'     => 'bp_blogs_screen_my_blogs',
    185             'default_subnav_slug' => 'my-sites',
    186             'item_css_id'         => $this->id
    187         );
    188 
    189         $sub_nav[] = array(
    190             'name'            => __( 'My Sites', 'buddypress' ),
    191             'slug'            => 'my-sites',
    192             'parent_url'      => $parent_url,
    193             'parent_slug'     => $slug,
    194             'screen_function' => 'bp_blogs_screen_my_blogs',
    195             'position'        => 10
    196         );
    197 
    198         // Setup navigation.
    199         parent::setup_nav( $main_nav, $sub_nav );
    200     }
    201 
    202     /**
    203      * Set up bp-blogs integration with the WordPress admin bar.
    204      *
    205      * @since 1.5.0
    206      *
    207      * @see BP_Component::setup_admin_bar() for a description of arguments.
    208      *
    209      * @param array $wp_admin_nav See BP_Component::setup_admin_bar()
    210      *                            for description.
    211      * @return bool
    212      */
    213     public function setup_admin_bar( $wp_admin_nav = array() ) {
    214 
    215         /**
    216          * Site/post/comment menus should not appear on single WordPress setups.
    217          *
    218          * Comments and posts made by users will still show in their activity.
    219          */
    220         if ( ! is_multisite() ) {
    221             return false;
    222         }
    223 
    224         // Menus for logged in user.
    225         if ( is_user_logged_in() ) {
    226 
    227             // Setup the logged in user variables.
    228             $blogs_link = trailingslashit( bp_loggedin_user_domain() . bp_get_blogs_slug() );
    229 
    230             // Add the "Sites" sub menu.
    231             $wp_admin_nav[] = array(
    232                 'parent' => buddypress()->my_account_menu_id,
    233                 'id'     => 'my-account-' . $this->id,
    234                 'title'  => __( 'Sites', 'buddypress' ),
    235                 'href'   => $blogs_link
    236             );
    237 
    238             // My Sites.
    239             $wp_admin_nav[] = array(
    240                 'parent' => 'my-account-' . $this->id,
    241                 'id'     => 'my-account-' . $this->id . '-my-sites',
    242                 'title'  => __( 'My Sites', 'buddypress' ),
    243                 'href'   => $blogs_link
    244             );
    245 
    246             // Create a Site.
    247             if ( bp_blog_signup_enabled() ) {
    248                 $wp_admin_nav[] = array(
    249                     'parent' => 'my-account-' . $this->id,
    250                     'id'     => 'my-account-' . $this->id . '-create',
    251                     'title'  => __( 'Create a Site', 'buddypress' ),
    252                     'href'   => trailingslashit( bp_get_blogs_directory_permalink() . 'create' )
    253                 );
    254             }
    255         }
    256 
    257         parent::setup_admin_bar( $wp_admin_nav );
    258     }
    259 
    260     /**
    261      * Set up the title for pages and <title>.
    262      */
    263     public function setup_title() {
    264 
    265         // Set up the component options navigation for Site.
    266         if ( bp_is_blogs_component() ) {
    267             $bp = buddypress();
    268 
    269             if ( bp_is_my_profile() ) {
    270                 if ( bp_is_active( 'xprofile' ) ) {
    271                     $bp->bp_options_title = __( 'My Sites', 'buddypress' );
    272                 }
    273 
    274             // If we are not viewing the logged in user, set up the current
    275             // users avatar and name.
    276             } else {
    277                 $bp->bp_options_avatar = bp_core_fetch_avatar( array(
    278                     'item_id' => bp_displayed_user_id(),
    279                     'type'    => 'thumb',
    280                     'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() )
    281                 ) );
    282                 $bp->bp_options_title = bp_get_displayed_user_fullname();
    283             }
    284         }
    285 
    286         parent::setup_title();
    287     }
    288 
    289     /**
    290      * Setup cache groups
    291      *
    292      * @since 2.2.0
    293      */
    294     public function setup_cache_groups() {
    295 
    296         // Global groups.
    297         wp_cache_add_global_groups( array(
    298             'blog_meta'
    299         ) );
    300 
    301         parent::setup_cache_groups();
    302     }
    303 
    304     /**
    305      * Set up the tracking arguments for the 'post' post type.
    306      *
    307      * @since 2.2.0
    308      *
    309      * @see bp_activity_get_post_type_tracking_args() for information on parameters.
    310      *
    311      * @param object|null $params    Tracking arguments.
    312      * @param string|int  $post_type Post type to track.
    313      * @return object
    314      */
    315     public function post_tracking_args( $params = null, $post_type = 0 ) {
    316 
    317         /**
    318          * Filters the post types to track for the Blogs component.
    319          *
    320          * @since 1.5.0
    321          * @deprecated 2.3.0
    322          *
    323          * Make sure plugins still using 'bp_blogs_record_post_post_types'
    324          * to track their post types will generate new_blog_post activities
    325          * See https://buddypress.trac.wordpress.org/ticket/6306
    326          *
    327          * @param array $value Array of post types to track.
    328          */
    329         $post_types = apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) );
    330         $post_types_array = array_flip( $post_types );
    331 
    332         if ( ! isset( $post_types_array[ $post_type ] ) ) {
    333             return $params;
    334         }
    335 
    336         // Set specific params for the 'post' post type.
    337         $params->component_id    = $this->id;
    338         $params->action_id       = 'new_blog_post';
    339         $params->admin_filter    = __( 'New post published', 'buddypress' );
    340         $params->format_callback = 'bp_blogs_format_activity_action_new_blog_post';
    341         $params->front_filter    = __( 'Posts', 'buddypress' );
    342         $params->contexts        = array( 'activity', 'member' );
    343         $params->position        = 5;
    344 
    345         return $params;
    346     }
    347 }
     17require dirname( __FILE__ ) . '/classes/class-bp-blogs-component.php';
    34818
    34919/**
  • trunk/src/bp-blogs/bp-blogs-screens.php

    r10417 r10517  
    1010// Exit if accessed directly.
    1111defined( 'ABSPATH' ) || exit;
     12
     13require dirname( __FILE__ ) . '/classes/class-bp-blogs-theme-compat.php';
    1214
    1315/**
     
    7173/** Theme Compatibility *******************************************************/
    7274
    73 /**
    74  * The main theme compat class for BuddyPress Blogs.
    75  *
    76  * This class sets up the necessary theme compatibility actions to safely output
    77  * group template parts to the_title and the_content areas of a theme.
    78  *
    79  * @since 1.7.0
    80  */
    81 class BP_Blogs_Theme_Compat {
    82 
    83     /**
    84      * Set up theme compatibility for the Blogs component.
    85      *
    86      * @since 1.7.0
    87      */
    88     public function __construct() {
    89         add_action( 'bp_setup_theme_compat', array( $this, 'is_blogs' ) );
    90     }
    91 
    92     /**
    93      * Are we looking at something that needs Blogs theme compatibility?
    94      *
    95      * @since 1.7.0
    96      */
    97     public function is_blogs() {
    98 
    99         // Bail if not looking at a group.
    100         if ( ! bp_is_blogs_component() )
    101             return;
    102 
    103         // Bail if looking at a users sites.
    104         if ( bp_is_user() )
    105             return;
    106 
    107         // Blog Directory.
    108         if ( is_multisite() && ! bp_current_action() ) {
    109             bp_update_is_directory( true, 'blogs' );
    110 
    111             /**
    112              * Fires if in the blog directory and BuddyPress needs Blog theme compatibility,
    113              * before the actions and filters are added.
    114              *
    115              * @since 1.5.0
    116              */
    117             do_action( 'bp_blogs_screen_index' );
    118 
    119             add_filter( 'bp_get_buddypress_template',                array( $this, 'directory_template_hierarchy' ) );
    120             add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'directory_dummy_post' ) );
    121             add_filter( 'bp_replace_the_content',                    array( $this, 'directory_content'    ) );
    122 
    123         // Create blog.
    124         } elseif ( is_user_logged_in() && bp_blog_signup_enabled() ) {
    125             add_filter( 'bp_get_buddypress_template',                array( $this, 'create_template_hierarchy' ) );
    126             add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'create_dummy_post' ) );
    127             add_filter( 'bp_replace_the_content',                    array( $this, 'create_content'    ) );
    128         }
    129     }
    130 
    131     /** Directory *************************************************************/
    132 
    133     /**
    134      * Add template hierarchy to theme compat for the blog directory page.
    135      *
    136      * This is to mirror how WordPress has
    137      * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
    138      *
    139      * @since 1.8.0
    140      *
    141      * @param string $templates The templates from bp_get_theme_compat_templates().
    142      * @return array $templates Array of custom templates to look for.
    143      */
    144     public function directory_template_hierarchy( $templates ) {
    145 
    146         /**
    147          * Filters the custom templates used for theme compat with the blog directory page.
    148          *
    149          * @since 1.8.0
    150          *
    151          * @param array $value Array of template paths to add to template list to look for.
    152          */
    153         $new_templates = apply_filters( 'bp_template_hierarchy_blogs_create', array(
    154             'blogs/index-directory.php'
    155         ) );
    156 
    157         // Merge new templates with existing stack
    158         // @see bp_get_theme_compat_templates().
    159         $templates = array_merge( (array) $new_templates, $templates );
    160 
    161         return $templates;
    162     }
    163 
    164     /**
    165      * Update the global $post with directory data.
    166      *
    167      * @since 1.7.0
    168      */
    169     public function directory_dummy_post() {
    170 
    171         bp_theme_compat_reset_post( array(
    172             'ID'             => 0,
    173             'post_title'     => __( 'Sites', 'buddypress' ),
    174             'post_author'    => 0,
    175             'post_date'      => 0,
    176             'post_content'   => '',
    177             'post_type'      => 'page',
    178             'post_status'    => 'publish',
    179             'is_page'        => true,
    180             'comment_status' => 'closed'
    181         ) );
    182     }
    183 
    184     /**
    185      * Filter the_content with the groups index template part.
    186      *
    187      * @since 1.7.0
    188      */
    189     public function directory_content() {
    190         return bp_buffer_template_part( 'blogs/index', null, false );
    191     }
    192 
    193     /** Create ****************************************************************/
    194 
    195     /**
    196      * Add custom template hierarchy to theme compat for the blog create page.
    197      *
    198      * This is to mirror how WordPress has
    199      * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
    200      *
    201      * @since 1.8.0
    202      *
    203      * @param string $templates The templates from bp_get_theme_compat_templates().
    204      * @return array $templates Array of custom templates to look for.
    205      */
    206     public function create_template_hierarchy( $templates ) {
    207 
    208         /**
    209          * Filters the custom templates used for theme compat with the blog create page.
    210          *
    211          * @since 1.8.0
    212          *
    213          * @param array $value Array of template paths to add to template list to look for.
    214          */
    215         $new_templates = apply_filters( 'bp_template_hierarchy_blogs_create', array(
    216             'blogs/index-create.php'
    217         ) );
    218 
    219         // Merge new templates with existing stack
    220         // @see bp_get_theme_compat_templates().
    221         $templates = array_merge( (array) $new_templates, $templates );
    222 
    223         return $templates;
    224     }
    225 
    226     /**
    227      * Update the global $post with create screen data.
    228      *
    229      * @since 1.7.0
    230      */
    231     public function create_dummy_post() {
    232 
    233         // Title based on ability to create blogs.
    234         if ( is_user_logged_in() && bp_blog_signup_enabled() ) {
    235             $title = __( 'Create a Site', 'buddypress' );
    236         } else {
    237             $title = __( 'Sites', 'buddypress' );
    238         }
    239 
    240         bp_theme_compat_reset_post( array(
    241             'ID'             => 0,
    242             'post_title'     => $title,
    243             'post_author'    => 0,
    244             'post_date'      => 0,
    245             'post_content'   => '',
    246             'post_type'      => 'page',
    247             'post_status'    => 'publish',
    248             'is_page'        => true,
    249             'comment_status' => 'closed'
    250         ) );
    251     }
    252 
    253     /**
    254      * Filter the_content with the create screen template part.
    255      *
    256      * @since 1.7.0
    257      */
    258     public function create_content() {
    259         return bp_buffer_template_part( 'blogs/create', null, false );
    260     }
    261 }
    26275new BP_Blogs_Theme_Compat();
  • trunk/src/bp-blogs/bp-blogs-template.php

    r10417 r10517  
    1010// Exit if accessed directly.
    1111defined( 'ABSPATH' ) || exit;
     12
     13require dirname( __FILE__ ) . '/classes/class-bp-blogs-template.php';
    1214
    1315/**
     
    102104        return apply_filters( 'bp_get_blogs_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_blogs_root_slug() ) );
    103105    }
    104 
    105 /**
    106  * The main blog template loop class.
    107  *
    108  * Responsible for loading a group of blogs into a loop for display.
    109  */
    110 class BP_Blogs_Template {
    111 
    112     /**
    113      * The loop iterator.
    114      *
    115      * @var int
    116      */
    117     public $current_blog = -1;
    118 
    119     /**
    120      * The number of blogs returned by the paged query.
    121      *
    122      * @var int
    123      */
    124     public $blog_count = 0;
    125 
    126     /**
    127      * Array of blogs located by the query..
    128      *
    129      * @var array
    130      */
    131     public $blogs = array();
    132 
    133     /**
    134      * The blog object currently being iterated on.
    135      *
    136      * @var object
    137      */
    138     public $blog;
    139 
    140     /**
    141      * A flag for whether the loop is currently being iterated.
    142      *
    143      * @var bool
    144      */
    145     public $in_the_loop = false;
    146 
    147     /**
    148      * The page number being requested.
    149      *
    150      * @var int
    151      */
    152     public $pag_page = 1;
    153 
    154     /**
    155      * The number of items being requested per page.
    156      *
    157      * @var int
    158      */
    159     public $pag_num = 20;
    160 
    161     /**
    162      * An HTML string containing pagination links.
    163      *
    164      * @var string
    165      */
    166     public $pag_links = '';
    167 
    168     /**
    169      * The total number of blogs matching the query parameters.
    170      *
    171      * @var int
    172      */
    173     public $total_blog_count = 0;
    174 
    175     /**
    176      * Constructor method.
    177      *
    178      * @see BP_Blogs_Blog::get() for a description of parameters.
    179      *
    180      * @param string     $type              See {@link BP_Blogs_Blog::get()}.
    181      * @param string     $page              See {@link BP_Blogs_Blog::get()}.
    182      * @param string     $per_page          See {@link BP_Blogs_Blog::get()}.
    183      * @param string     $max               See {@link BP_Blogs_Blog::get()}.
    184      * @param string     $user_id           See {@link BP_Blogs_Blog::get()}.
    185      * @param string     $search_terms      See {@link BP_Blogs_Blog::get()}.
    186      * @param string     $page_arg          The string used as a query parameter in
    187      *                                      pagination links. Default: 'bpage'.
    188      * @param bool       $update_meta_cache Whether to pre-fetch metadata for
    189      *                                      queried blogs.
    190      * @param array|bool $include_blog_ids  Array of blog IDs to include.
    191      */
    192     public function __construct( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg = 'bpage', $update_meta_cache = true, $include_blog_ids = false ) {
    193 
    194         $this->pag_arg  = sanitize_key( $page_arg );
    195         $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $page     );
    196         $this->pag_num  = bp_sanitize_pagination_arg( 'num',          $per_page );
    197 
    198         // Backwards compatibility support for blogs by first letter.
    199         if ( ! empty( $_REQUEST['letter'] ) ) {
    200             $this->blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page );
    201 
    202         // Typical blogs query.
    203         } else {
    204             $this->blogs = bp_blogs_get_blogs( array(
    205                 'type'              => $type,
    206                 'per_page'          => $this->pag_num,
    207                 'page'              => $this->pag_page,
    208                 'user_id'           => $user_id,
    209                 'search_terms'      => $search_terms,
    210                 'update_meta_cache' => $update_meta_cache,
    211                 'include_blog_ids'  => $include_blog_ids,
    212             ) );
    213         }
    214 
    215         // Set the total blog count.
    216         if ( empty( $max ) || ( $max >= (int) $this->blogs['total'] ) ) {
    217             $this->total_blog_count = (int) $this->blogs['total'];
    218         } else {
    219             $this->total_blog_count = (int) $max;
    220         }
    221 
    222         // Set the blogs array (to loop through later.
    223         $this->blogs = $this->blogs['blogs'];
    224 
    225         // Get the current blog count to compare maximum against.
    226         $blog_count = count( $this->blogs );
    227 
    228         // Set the current blog count.
    229         if ( empty( $max ) || ( $max >= (int) $blog_count ) ) {
    230             $this->blog_count = (int) $blog_count;
    231         } else {
    232             $this->blog_count = (int) $max;
    233         }
    234 
    235         // Build pagination links based on total blogs and current page number.
    236         if ( ! empty( $this->total_blog_count ) && ! empty( $this->pag_num ) ) {
    237             $this->pag_links = paginate_links( array(
    238                 'base'      => add_query_arg( $this->pag_arg, '%#%' ),
    239                 'format'    => '',
    240                 'total'     => ceil( (int) $this->total_blog_count / (int) $this->pag_num ),
    241                 'current'   => (int) $this->pag_page,
    242                 'prev_text' => _x( '&larr;', 'Blog pagination previous text', 'buddypress' ),
    243                 'next_text' => _x( '&rarr;', 'Blog pagination next text',     'buddypress' ),
    244                 'mid_size'  => 1,
    245                 'add_args'  => array(),
    246             ) );
    247         }
    248     }
    249 
    250     /**
    251      * Whether there are blogs available in the loop.
    252      *
    253      * @see bp_has_blogs()
    254      *
    255      * @return bool True if there are items in the loop, otherwise false.
    256      */
    257     public function has_blogs() {
    258         return (bool) ! empty( $this->blog_count );
    259     }
    260 
    261     /**
    262      * Set up the next blog and iterate index.
    263      *
    264      * @return object The next blog to iterate over.
    265      */
    266     public function next_blog() {
    267         $this->current_blog++;
    268         $this->blog = $this->blogs[ $this->current_blog ];
    269 
    270         return $this->blog;
    271     }
    272 
    273     /**
    274      * Rewind the blogs and reset blog index.
    275      */
    276     public function rewind_blogs() {
    277         $this->current_blog = -1;
    278         if ( $this->blog_count > 0 ) {
    279             $this->blog = $this->blogs[0];
    280         }
    281     }
    282 
    283     /**
    284      * Whether there are blogs left in the loop to iterate over.
    285      *
    286      * This method is used by {@link bp_blogs()} as part of the while loop
    287      * that controls iteration inside the blogs loop, eg:
    288      *     while ( bp_blogs() ) { ...
    289      *
    290      * @see bp_blogs()
    291      *
    292      * @return bool True if there are more blogs to show, otherwise false.
    293      */
    294     public function blogs() {
    295         if ( ( $this->current_blog + 1 ) < $this->blog_count ) {
    296             return true;
    297         } elseif ( ( $this->current_blog + 1 ) === $this->blog_count ) {
    298 
    299             /**
    300              * Fires right before the rewinding of blogs listing after all are shown.
    301              *
    302              * @since 1.5.0
    303              */
    304             do_action( 'blog_loop_end' );
    305             // Do some cleaning up after the loop.
    306             $this->rewind_blogs();
    307         }
    308 
    309         $this->in_the_loop = false;
    310         return false;
    311     }
    312 
    313     /**
    314      * Set up the current blog inside the loop.
    315      *
    316      * Used by {@link bp_the_blog()} to set up the current blog data while
    317      * looping, so that template tags used during that iteration make
    318      * reference to the current blog.
    319      *
    320      * @see bp_the_blog()
    321      */
    322     public function the_blog() {
    323 
    324         $this->in_the_loop = true;
    325         $this->blog        = $this->next_blog();
    326 
    327         // Loop has just started.
    328         if ( 0 === $this->current_blog ) {
    329 
    330             /**
    331              * Fires if on the first blog in the loop.
    332              *
    333              * @since 1.5.0
    334              */
    335             do_action( 'blog_loop_start' );
    336         }
    337     }
    338 }
    339106
    340107/**
  • trunk/src/bp-blogs/bp-blogs-widgets.php

    r10417 r10517  
    1111defined( 'ABSPATH' ) || exit;
    1212
     13require dirname( __FILE__ ) . '/classes/class-bp-blogs-recent-posts-widget.php';
     14
    1315/**
    1416 * Register the widgets for the Blogs component.
     
    2224}
    2325add_action( 'bp_register_widgets', 'bp_blogs_register_widgets' );
    24 
    25 /**
    26  * The Recent Networkwide Posts widget.
    27  */
    28 class BP_Blogs_Recent_Posts_Widget extends WP_Widget {
    29 
    30     /**
    31      * Constructor method.
    32      */
    33     public function __construct() {
    34         $widget_ops = array(
    35             'description' => __( 'A list of recently published posts from across your network.', 'buddypress' ),
    36             'classname'   => 'widget_bp_blogs_widget buddypress widget',
    37         );
    38         parent::__construct( false, $name = _x( '(BuddyPress) Recent Networkwide Posts', 'widget name', 'buddypress' ), $widget_ops );
    39     }
    40 
    41     /**
    42      * Display the networkwide posts widget.
    43      *
    44      * @see WP_Widget::widget() for description of parameters.
    45      *
    46      * @param array $args     Widget arguments.
    47      * @param array $instance Widget settings, as saved by the user.
    48      */
    49     public function widget( $args, $instance ) {
    50 
    51         $title = ! empty( $instance['title'] )
    52             ? esc_html( $instance['title'] )
    53             : __( 'Recent Networkwide Posts', 'buddypress' );
    54 
    55         if ( ! empty( $instance['link_title'] ) ) {
    56             $title = '<a href="' . bp_get_blogs_directory_permalink() . '">' . esc_html( $title ) . '</a>';
    57         }
    58 
    59         /**
    60          * Filters the Blogs Recent Posts widget title.
    61          *
    62          * @since 2.2.0
    63          * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter.
    64          *
    65          * @param string $title    The widget title.
    66          * @param array  $instance The settings for the particular instance of the widget.
    67          * @param string $id_base  Root ID for all widgets of this type.
    68          */
    69         $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
    70 
    71         echo $args['before_widget'];
    72         echo $args['before_title'] . $title . $args['after_title'];
    73 
    74         if ( empty( $instance['max_posts'] ) || empty( $instance['max_posts'] ) ) {
    75             $instance['max_posts'] = 10;
    76         }
    77 
    78         $after_widget = $args['after_widget'];
    79 
    80         // Override some of the contextually set parameters for bp_has_activities().
    81         $args = array(
    82             'action'     => 'new_blog_post',
    83             'max'        => $instance['max_posts'],
    84             'per_page'   => $instance['max_posts'],
    85             'user_id'    => 0,
    86             'scope'      => false,
    87             'object'     => false,
    88             'primary_id' => false
    89         ); ?>
    90 
    91         <?php if ( bp_has_activities( $args ) ) : ?>
    92 
    93             <ul id="blog-post-list" class="activity-list item-list">
    94 
    95                 <?php while ( bp_activities() ) : bp_the_activity(); ?>
    96 
    97                     <li>
    98                         <div class="activity-content" style="margin: 0">
    99                             <div class="activity-header"><?php bp_activity_action(); ?></div>
    100 
    101                             <?php if ( bp_get_activity_content_body() ) : ?>
    102 
    103                                 <div class="activity-inner"><?php bp_activity_content_body(); ?></div>
    104 
    105                             <?php endif; ?>
    106 
    107                         </div>
    108                     </li>
    109 
    110                 <?php endwhile; ?>
    111 
    112             </ul>
    113 
    114         <?php else : ?>
    115 
    116             <div id="message" class="info">
    117                 <p><?php _e( 'Sorry, there were no posts found. Why not write one?', 'buddypress' ); ?></p>
    118             </div>
    119 
    120         <?php endif; ?>
    121 
    122         <?php echo $after_widget; ?>
    123     <?php
    124     }
    125 
    126     /**
    127      * Update the networkwide posts widget options.
    128      *
    129      * @param array $new_instance The new instance options.
    130      * @param array $old_instance The old instance options.
    131      * @return array $instance The parsed options to be saved.
    132      */
    133     public function update( $new_instance, $old_instance ) {
    134         $instance               = $old_instance;
    135         $instance['title']      = strip_tags( $new_instance['title'] );
    136         $instance['max_posts']  = strip_tags( $new_instance['max_posts'] );
    137         $instance['link_title'] = (bool) $new_instance['link_title'];
    138 
    139         return $instance;
    140     }
    141 
    142     /**
    143      * Output the networkwide posts widget options form.
    144      *
    145      * @param array $instance Settings for this widget.
    146      *
    147      * @return void
    148      */
    149     public function form( $instance ) {
    150         $instance = wp_parse_args( (array) $instance, array(
    151             'title'      => __( 'Recent Networkwide Posts', 'buddypress' ),
    152             'max_posts'  => 10,
    153             'link_title' => false,
    154         ) );
    155 
    156         $title      = strip_tags( $instance['title'] );
    157         $max_posts  = strip_tags( $instance['max_posts'] );
    158         $link_title = (bool) $instance['link_title'];
    159 
    160         ?>
    161 
    162         <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _ex( 'Title:', 'Label for the Title field of the Recent Networkwide Posts widget', 'buddypress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" style="width: 100%;" /></label></p>
    163         <p><label for="<?php echo $this->get_field_id( 'link_title' ); ?>"><input type="checkbox" name="<?php echo $this->get_field_name( 'link_title' ); ?>" value="1" <?php checked( $link_title ); ?> /> <?php _e( 'Link widget title to Blogs directory', 'buddypress' ); ?></label></p>
    164         <p><label for="<?php echo $this->get_field_id( 'max_posts' ); ?>"><?php _e( 'Max posts to show:', 'buddypress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_posts' ); ?>" name="<?php echo $this->get_field_name( 'max_posts' ); ?>" type="text" value="<?php echo esc_attr( $max_posts ); ?>" style="width: 30%" /></label></p>
    165         <?php
    166     }
    167 }
  • trunk/src/bp-blogs/classes/class-bp-blogs-component.php

    r10515 r10517  
    346346    }
    347347}
    348 
    349 /**
    350  * Set up the bp-blogs component.
    351  */
    352 function bp_setup_blogs() {
    353     buddypress()->blogs = new BP_Blogs_Component();
    354 }
    355 add_action( 'bp_setup_components', 'bp_setup_blogs', 6 );
  • trunk/src/bp-blogs/classes/class-bp-blogs-recent-posts-widget.php

    r10515 r10517  
    11<?php
    22/**
    3  * BuddyPress Blogs Widgets.
     3 * BuddyPress Blogs Recent Posts Widget.
    44 *
    55 * @package BuddyPress
     
    1010// Exit if accessed directly.
    1111defined( 'ABSPATH' ) || exit;
    12 
    13 /**
    14  * Register the widgets for the Blogs component.
    15  */
    16 function bp_blogs_register_widgets() {
    17     global $wpdb;
    18 
    19     if ( bp_is_active( 'activity' ) && bp_is_root_blog( $wpdb->blogid ) ) {
    20         add_action( 'widgets_init', create_function( '', 'return register_widget("BP_Blogs_Recent_Posts_Widget");' ) );
    21     }
    22 }
    23 add_action( 'bp_register_widgets', 'bp_blogs_register_widgets' );
    2412
    2513/**
  • trunk/src/bp-blogs/classes/class-bp-blogs-template.php

    r10515 r10517  
    11<?php
    22/**
    3  * BuddyPress Blogs Template Tags.
     3 * BuddyPress Blogs Template Class.
    44 *
    55 * @package BuddyPress
     
    1010// Exit if accessed directly.
    1111defined( 'ABSPATH' ) || exit;
    12 
    13 /**
    14  * Output the blogs component slug.
    15  *
    16  * @since 1.5.0
    17  *
    18  * @uses bp_get_blogs_slug()
    19  */
    20 function bp_blogs_slug() {
    21     echo bp_get_blogs_slug();
    22 }
    23     /**
    24      * Return the blogs component slug.
    25      *
    26      * @since 1.5.0
    27      *
    28      * @return string The 'blogs' slug.
    29      */
    30     function bp_get_blogs_slug() {
    31 
    32         /**
    33          * Filters the blogs component slug.
    34          *
    35          * @since 1.5.0
    36          *
    37          * @param string $slug Slug for the blogs component.
    38          */
    39         return apply_filters( 'bp_get_blogs_slug', buddypress()->blogs->slug );
    40     }
    41 
    42 /**
    43  * Output the blogs component root slug.
    44  *
    45  * @since 1.5.0
    46  *
    47  * @uses bp_get_blogs_root_slug()
    48  */
    49 function bp_blogs_root_slug() {
    50     echo bp_get_blogs_root_slug();
    51 }
    52     /**
    53      * Return the blogs component root slug.
    54      *
    55      * @since 1.5.0
    56      *
    57      * @return string The 'blogs' root slug.
    58      */
    59     function bp_get_blogs_root_slug() {
    60 
    61         /**
    62          * Filters the blogs component root slug.
    63          *
    64          * @since 1.5.0
    65          *
    66          * @param string $root_slug Root slug for the blogs component.
    67          */
    68         return apply_filters( 'bp_get_blogs_root_slug', buddypress()->blogs->root_slug );
    69     }
    70 
    71 /**
    72  * Output blog directory permalink.
    73  *
    74  * @since 1.5.0
    75  *
    76  * @uses bp_get_blogs_directory_permalink()
    77  */
    78 function bp_blogs_directory_permalink() {
    79     echo esc_url( bp_get_blogs_directory_permalink() );
    80 }
    81     /**
    82      * Return blog directory permalink.
    83      *
    84      * @since 1.5.0
    85      *
    86      * @uses apply_filters()
    87      * @uses trailingslashit()
    88      * @uses bp_get_root_domain()
    89      * @uses bp_get_blogs_root_slug()
    90      *
    91      * @return string The URL of the Blogs directory.
    92      */
    93     function bp_get_blogs_directory_permalink() {
    94 
    95         /**
    96          * Filters the blog directory permalink.
    97          *
    98          * @since 1.5.0
    99          *
    100          * @param string $value Permalink URL for the blog directory.
    101          */
    102         return apply_filters( 'bp_get_blogs_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_blogs_root_slug() ) );
    103     }
    10412
    10513/**
     
    337245    }
    338246}
    339 
    340 /**
    341  * Rewind the blogs and reset blog index.
    342  */
    343 function bp_rewind_blogs() {
    344     global $blogs_template;
    345 
    346     $blogs_template->rewind_blogs();
    347 }
    348 
    349 /**
    350  * Initialize the blogs loop.
    351  *
    352  * Based on the $args passed, bp_has_blogs() populates the $blogs_template
    353  * global, enabling the use of BuddyPress templates and template functions to
    354  * display a list of activity items.
    355  *
    356  * @global object $blogs_template {@link BP_Blogs_Template}
    357  *
    358  * @param array|string $args {
    359  *     Arguments for limiting the contents of the blogs loop. Most arguments
    360  *     are in the same format as {@link BP_Blogs_Blog::get()}. However, because
    361  *     the format of the arguments accepted here differs in a number of ways,
    362  *     and because bp_has_blogs() determines some default arguments in a
    363  *     dynamic fashion, we list all accepted arguments here as well.
    364  *
    365  *     Arguments can be passed as an associative array, or as a URL query
    366  *     string (eg, 'user_id=4&per_page=3').
    367  *
    368  *     @type int      $page             Which page of results to fetch. Using page=1 without
    369  *                                      per_page will result in no pagination. Default: 1.
    370  *     @type int|bool $per_page         Number of results per page. Default: 20.
    371  *     @type string   $page_arg         The string used as a query parameter in
    372  *                                      pagination links. Default: 'bpage'.
    373  *     @type int|bool $max              Maximum number of results to return.
    374  *                                      Default: false (unlimited).
    375  *     @type string   $type             The order in which results should be fetched.
    376  *                                      'active', 'alphabetical', 'newest', or 'random'.
    377  *     @type array    $include_blog_ids Array of blog IDs to limit results to.
    378  *     @type string   $sort             'ASC' or 'DESC'. Default: 'DESC'.
    379  *     @type string   $search_terms     Limit results by a search term. Default: the value of `$_REQUEST['s']` or
    380  *                                      `$_REQUEST['sites_search']`, if present.
    381  *     @type int      $user_id          The ID of the user whose blogs should be retrieved.
    382  *                                      When viewing a user profile page, 'user_id' defaults to the
    383  *                                      ID of the displayed user. Otherwise the default is false.
    384  * }
    385  * @return bool Returns true when blogs are found, otherwise false.
    386  */
    387 function bp_has_blogs( $args = '' ) {
    388     global $blogs_template;
    389 
    390     // Check for and use search terms.
    391     $search_terms_default = false;
    392     $search_query_arg = bp_core_get_component_search_query_arg( 'blogs' );
    393     if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) {
    394         $search_terms_default = stripslashes( $_REQUEST[ $search_query_arg ] );
    395     } elseif ( ! empty( $_REQUEST['s'] ) ) {
    396         $search_terms_default = stripslashes( $_REQUEST['s'] );
    397     }
    398 
    399     // Parse arguments.
    400     $r = bp_parse_args( $args, array(
    401         'type'              => 'active',
    402         'page_arg'          => 'bpage', // See https://buddypress.trac.wordpress.org/ticket/3679.
    403         'page'              => 1,
    404         'per_page'          => 20,
    405         'max'               => false,
    406         'user_id'           => bp_displayed_user_id(), // Pass a user_id to limit to only blogs this user is a member of.
    407         'include_blog_ids'  => false,
    408         'search_terms'      => $search_terms_default,
    409         'update_meta_cache' => true
    410     ), 'has_blogs' );
    411 
    412     // Set per_page to maximum if max is enforced.
    413     if ( ! empty( $r['max'] ) && ( (int) $r['per_page'] > (int) $r['max'] ) ) {
    414         $r['per_page'] = (int) $r['max'];
    415     }
    416 
    417     // Get the blogs.
    418     $blogs_template = new BP_Blogs_Template( $r['type'], $r['page'], $r['per_page'], $r['max'], $r['user_id'], $r['search_terms'], $r['page_arg'], $r['update_meta_cache'], $r['include_blog_ids'] );
    419 
    420     /**
    421      * Filters whether or not there are blogs to list.
    422      *
    423      * @since 1.1.0
    424      *
    425      * @param bool              $value          Whether or not there are blogs to list.
    426      * @param BP_Blogs_Template $blogs_template Current blogs template object.
    427      * @param array             $r              Parsed arguments used in blogs template query.
    428      */
    429     return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), $blogs_template, $r );
    430 }
    431 
    432 /**
    433  * Determine if there are still blogs left in the loop.
    434  *
    435  * @global object $blogs_template {@link BP_Blogs_Template}
    436  *
    437  * @return bool Returns true when blogs are found.
    438  */
    439 function bp_blogs() {
    440     global $blogs_template;
    441 
    442     return $blogs_template->blogs();
    443 }
    444 
    445 /**
    446  * Get the current blog object in the loop.
    447  *
    448  * @global object $blogs_template {@link BP_Blogs_Template}
    449  *
    450  * @return object The current blog within the loop.
    451  */
    452 function bp_the_blog() {
    453     global $blogs_template;
    454 
    455     return $blogs_template->the_blog();
    456 }
    457 
    458 /**
    459  * Output the blogs pagination count.
    460  *
    461  * @global object $blogs_template {@link BP_Blogs_Template}
    462  */
    463 function bp_blogs_pagination_count() {
    464     global $blogs_template;
    465 
    466     $start_num = intval( ( $blogs_template->pag_page - 1 ) * $blogs_template->pag_num ) + 1;
    467     $from_num  = bp_core_number_format( $start_num );
    468     $to_num    = bp_core_number_format( ( $start_num + ( $blogs_template->pag_num - 1 ) > $blogs_template->total_blog_count ) ? $blogs_template->total_blog_count : $start_num + ( $blogs_template->pag_num - 1 ) );
    469     $total     = bp_core_number_format( $blogs_template->total_blog_count );
    470 
    471     if ( 1 == $blogs_template->total_blog_count ) {
    472         $message = __( 'Viewing 1 site', 'buddypress' );
    473     } else {
    474         $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s site', 'Viewing %1$s - %2$s of %3$s sites', $blogs_template->total_blog_count, 'buddypress' ), $from_num, $to_num, $total );
    475     }
    476 
    477     echo $message;
    478 }
    479 
    480 /**
    481  * Output the blogs pagination links.
    482  */
    483 function bp_blogs_pagination_links() {
    484     echo bp_get_blogs_pagination_links();
    485 }
    486     /**
    487      * Return the blogs pagination links.
    488      *
    489      * @global object $blogs_template {@link BP_Blogs_Template}
    490      *
    491      * @return string HTML pagination links.
    492      */
    493     function bp_get_blogs_pagination_links() {
    494         global $blogs_template;
    495 
    496         /**
    497          * Filters the blogs pagination links.
    498          *
    499          * @since 1.0.0
    500          *
    501          * @param string $pag_links HTML pagination links.
    502          */
    503         return apply_filters( 'bp_get_blogs_pagination_links', $blogs_template->pag_links );
    504     }
    505 
    506 /**
    507  * Output a blog's avatar.
    508  *
    509  * @see bp_get_blog_avatar() for description of arguments.
    510  *
    511  * @param array|string $args See {@link bp_get_blog_avatar()}.
    512  */
    513 function bp_blog_avatar( $args = '' ) {
    514     echo bp_get_blog_avatar( $args );
    515 }
    516     /**
    517      * Get a blog's avatar.
    518      *
    519      * At the moment, blog avatars are simply the user avatars of the blog
    520      * admin. Filter 'bp_get_blog_avatar_' . $blog_id to customize.
    521      *
    522      * @since 2.4.0 Introduced `$title` argument.
    523      *
    524      * @see bp_core_fetch_avatar() For a description of arguments and
    525      *      return values.
    526      *
    527      * @param array|string $args  {
    528      *     Arguments are listed here with an explanation of their defaults.
    529      *     For more information about the arguments, see
    530      *     {@link bp_core_fetch_avatar()}.
    531      *     @type string   $alt     Default: 'Profile picture of site author [user name]'.
    532      *     @type string   $class   Default: 'avatar'.
    533      *     @type string   $title   Default: 'Profile picture of site author [user name]'.
    534      *     @type string   $type    Default: 'full'.
    535      *     @type int|bool $width   Default: false.
    536      *     @type int|bool $height  Default: false.
    537      *     @type bool     $id      Currently unused.
    538      *     @type bool     $no_grav Default: true.
    539      * }
    540      * @return string User avatar string.
    541      */
    542     function bp_get_blog_avatar( $args = '' ) {
    543         global $blogs_template;
    544 
    545         // Bail if avatars are turned off
    546         // @todo Should we maybe still filter this?
    547         if ( ! buddypress()->avatar->show_avatars ) {
    548             return false;
    549         }
    550 
    551         $author_displayname = bp_core_get_user_displayname( $blogs_template->blog->admin_user_id );
    552 
    553         // Parse the arguments.
    554         $r = bp_parse_args( $args, array(
    555             'type'    => 'full',
    556             'width'   => false,
    557             'height'  => false,
    558             'class'   => 'avatar',
    559             'title'   => sprintf( __( 'Profile picture of site author %s', 'buddypress' ), esc_attr( $author_displayname ) ),
    560             'id'      => false,
    561             'alt'     => sprintf( __( 'Profile picture of site author %s', 'buddypress' ), esc_attr( $author_displayname ) ),
    562             'no_grav' => true,
    563         ) );
    564 
    565         // Fetch the avatar.
    566         $avatar = bp_core_fetch_avatar( array(
    567             'item_id'    => $blogs_template->blog->admin_user_id,
    568             'title'      => $r['title'],
    569             // 'avatar_dir' => 'blog-avatars',
    570             // 'object'     => 'blog',
    571             'type'       => $r['type'],
    572             'alt'        => $r['alt'],
    573             'css_id'     => $r['id'],
    574             'class'      => $r['class'],
    575             'width'      => $r['width'],
    576             'height'     => $r['height']
    577         ) );
    578 
    579         /**
    580          * In future BuddyPress versions you will be able to set the avatar for a blog.
    581          * Right now you can use a filter with the ID of the blog to change it if you wish.
    582          * By default it will return the avatar for the primary blog admin.
    583          *
    584          * This filter is deprecated as of BuddyPress 1.5 and may be removed in a future version.
    585          * Use the 'bp_get_blog_avatar' filter instead.
    586          */
    587         $avatar = apply_filters( 'bp_get_blog_avatar_' . $blogs_template->blog->blog_id, $avatar );
    588 
    589         /**
    590          * Filters a blog's avatar.
    591          *
    592          * @since 1.5.0
    593          *
    594          * @param string $avatar  Formatted HTML <img> element, or raw avatar
    595          *                        URL based on $html arg.
    596          * @param int    $blog_id ID of the blog whose avatar is being displayed.
    597          * @param array  $r       Array of arguments used when fetching avatar.
    598          */
    599         return apply_filters( 'bp_get_blog_avatar', $avatar, $blogs_template->blog->blog_id, $r );
    600     }
    601 
    602 function bp_blog_permalink() {
    603     echo bp_get_blog_permalink();
    604 }
    605     function bp_get_blog_permalink() {
    606         global $blogs_template;
    607 
    608         if ( empty( $blogs_template->blog->domain ) )
    609             $permalink = bp_get_root_domain() . $blogs_template->blog->path;
    610         else {
    611             $protocol = 'http://';
    612             if ( is_ssl() )
    613                 $protocol = 'https://';
    614 
    615             $permalink = $protocol . $blogs_template->blog->domain . $blogs_template->blog->path;
    616         }
    617 
    618         /**
    619          * Filters the blog permalink.
    620          *
    621          * @since 1.0.0
    622          *
    623          * @param string $permalink Permalink URL for the blog.
    624          */
    625         return apply_filters( 'bp_get_blog_permalink', $permalink );
    626     }
    627 
    628 /**
    629  * Output the name of the current blog in the loop.
    630  */
    631 function bp_blog_name() {
    632     echo bp_get_blog_name();
    633 }
    634     /**
    635      * Return the name of the current blog in the loop.
    636      *
    637      * @return string The name of the current blog in the loop.
    638      */
    639     function bp_get_blog_name() {
    640         global $blogs_template;
    641 
    642         /**
    643          * Filters the name of the current blog in the loop.
    644          *
    645          * @since 1.2.0
    646          *
    647          * @param string $name Name of the current blog in the loop.
    648          */
    649         return apply_filters( 'bp_get_blog_name', $blogs_template->blog->name );
    650     }
    651 
    652 /**
    653  * Output the ID of the current blog in the loop.
    654  *
    655  * @since 1.7.0
    656  */
    657 function bp_blog_id() {
    658     echo bp_get_blog_id();
    659 }
    660     /**
    661      * Return the ID of the current blog in the loop.
    662      *
    663      * @since 1.7.0
    664      *
    665      * @return int ID of the current blog in the loop.
    666      */
    667     function bp_get_blog_id() {
    668         global $blogs_template;
    669 
    670         /**
    671          * Filters the ID of the current blog in the loop.
    672          *
    673          * @since 1.7.0
    674          *
    675          * @param int $blog_id ID of the current blog in the loop.
    676          */
    677         return apply_filters( 'bp_get_blog_id', $blogs_template->blog->blog_id );
    678     }
    679 
    680 /**
    681  * Output the description of the current blog in the loop.
    682  */
    683 function bp_blog_description() {
    684 
    685     /**
    686      * Filters the description of the current blog in the loop.
    687      *
    688      * @since 1.2.0
    689      *
    690      * @param string $value Description of the current blog in the loop.
    691      */
    692     echo apply_filters( 'bp_blog_description', bp_get_blog_description() );
    693 }
    694     /**
    695      * Return the description of the current blog in the loop.
    696      *
    697      * @return string Description of the current blog in the loop.
    698      */
    699     function bp_get_blog_description() {
    700         global $blogs_template;
    701 
    702         /**
    703          * Filters the description of the current blog in the loop.
    704          *
    705          * @since 1.0.0
    706          *
    707          * @param string $value Description of the current blog in the loop.
    708          */
    709         return apply_filters( 'bp_get_blog_description', $blogs_template->blog->description );
    710     }
    711 
    712 /**
    713  * Output the row class of the current blog in the loop.
    714  *
    715  * @since 1.7.0
    716  *
    717  * @param array $classes Array of custom classes.
    718  */
    719 function bp_blog_class( $classes = array() ) {
    720     echo bp_get_blog_class( $classes );
    721 }
    722     /**
    723      * Return the row class of the current blog in the loop.
    724      *
    725      * @since 1.7.0
    726      *
    727      * @global BP_Blogs_Template $blogs_template
    728      *
    729      * @param array $classes Array of custom classes.
    730      * @return string Row class of the site.
    731      */
    732     function bp_get_blog_class( $classes = array() ) {
    733         global $blogs_template;
    734 
    735         // Add even/odd classes, but only if there's more than 1 group.
    736         if ( $blogs_template->blog_count > 1 ) {
    737             $pos_in_loop = (int) $blogs_template->current_blog;
    738             $classes[]   = ( $pos_in_loop % 2 ) ? 'even' : 'odd';
    739 
    740         // If we've only one site in the loop, don't bother with odd and even.
    741         } else {
    742             $classes[] = 'bp-single-blog';
    743         }
    744 
    745         /**
    746          * Filters the row class of the current blog in the loop.
    747          *
    748          * @since 1.7.0
    749          *
    750          * @param array $classes Array of classes to be applied to row.
    751          */
    752         $classes = apply_filters( 'bp_get_blog_class', $classes );
    753         $classes = array_merge( $classes, array() );
    754         $retval  = 'class="' . join( ' ', $classes ) . '"';
    755 
    756         return $retval;
    757     }
    758 
    759 /**
    760  * Output the last active date of the current blog in the loop.
    761  *
    762  * @param array $args See {@link bp_get_blog_last_active()}.
    763  */
    764 function bp_blog_last_active( $args = array() ) {
    765     echo bp_get_blog_last_active( $args );
    766 }
    767     /**
    768      * Return the last active date of the current blog in the loop.
    769      *
    770      * @param array $args {
    771      *     Array of optional arguments.
    772      *     @type bool $active_format If true, formatted "Active 5 minutes ago".
    773      *                               If false, formatted "5 minutes ago".
    774      *                               Default: true.
    775      * }
    776      * @return string Last active date.
    777      */
    778     function bp_get_blog_last_active( $args = array() ) {
    779         global $blogs_template;
    780 
    781         // Parse the activity format.
    782         $r = bp_parse_args( $args, array(
    783             'active_format' => true
    784         ) );
    785 
    786         // Backwards compatibility for anyone forcing a 'true' active_format.
    787         if ( true === $r['active_format'] ) {
    788             $r['active_format'] = __( 'active %s', 'buddypress' );
    789         }
    790 
    791         // Blog has been posted to at least once.
    792         if ( isset( $blogs_template->blog->last_activity ) ) {
    793 
    794             // Backwards compatibility for pre 1.5 'ago' strings.
    795             $last_activity = ! empty( $r['active_format'] )
    796                 ? bp_core_get_last_activity( $blogs_template->blog->last_activity, $r['active_format'] )
    797                 : bp_core_time_since( $blogs_template->blog->last_activity );
    798 
    799         // Blog has never been posted to.
    800         } else {
    801             $last_activity = __( 'Never active', 'buddypress' );
    802         }
    803 
    804         /**
    805          * Filters the last active date of the current blog in the loop.
    806          *
    807          * @since
    808          *
    809          * @param string $last_activity Last active date.
    810          * @param array  $r             Array of parsed args used to determine formatting.
    811          */
    812         return apply_filters( 'bp_blog_last_active', $last_activity, $r );
    813     }
    814 
    815 /**
    816  * Output the latest post from the current blog in the loop.
    817  *
    818  * @param array $args See {@link bp_get_blog_latest_post()}.
    819  */
    820 function bp_blog_latest_post( $args = array() ) {
    821     echo bp_get_blog_latest_post( $args );
    822 }
    823     /**
    824      * Return the latest post from the current blog in the loop.
    825      *
    826      * @param array $args {
    827      *     Array of optional arguments.
    828      *     @type bool $latest_format If true, formatted "Latest post: [link to post]".
    829      *                               If false, formatted "[link to post]".
    830      *                               Default: true.
    831      * }
    832      * @return string $retval String of the form 'Latest Post: [link to post]'.
    833      */
    834     function bp_get_blog_latest_post( $args = array() ) {
    835         global $blogs_template;
    836 
    837         $r = wp_parse_args( $args, array(
    838             'latest_format' => true,
    839         ) );
    840 
    841         $retval = bp_get_blog_latest_post_title();
    842 
    843         if ( ! empty( $retval ) ) {
    844             if ( ! empty( $r['latest_format'] ) ) {
    845 
    846                 /**
    847                  * Filters the title text of the latest post for the current blog in loop.
    848                  *
    849                  * @since 1.0.0
    850                  *
    851                  * @param string $retval Title of the latest post.
    852                  */
    853                 $retval = sprintf( __( 'Latest Post: %s', 'buddypress' ), '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval ) . '</a>' );
    854             } else {
    855 
    856                 /** This filter is documented in bp-blogs/bp-blogs-template.php */
    857                 $retval = '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval ) . '</a>';
    858             }
    859         }
    860 
    861         /**
    862          * Filters the HTML markup result for the latest blog post in loop.
    863          *
    864          * @since 1.2.0
    865          *
    866          * @param string $retval HTML markup for the latest post.
    867          */
    868         return apply_filters( 'bp_get_blog_latest_post', $retval );
    869     }
    870 
    871 /**
    872  * Output the title of the latest post on the current blog in the loop.
    873  *
    874  * @since 1.7.0
    875  *
    876  * @see bp_get_blog_latest_post_title()
    877  */
    878 function bp_blog_latest_post_title() {
    879     echo bp_get_blog_latest_post_title();
    880 }
    881     /**
    882      * Return the title of the latest post on the current blog in the loop.
    883      *
    884      * @since 1.7.0
    885      *
    886      * @global BP_Blogs_Template
    887      *
    888      * @return string Post title.
    889      */
    890     function bp_get_blog_latest_post_title() {
    891         global $blogs_template;
    892 
    893         $retval = '';
    894 
    895         if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->post_title ) )
    896             $retval = $blogs_template->blog->latest_post->post_title;
    897 
    898         /**
    899          * Filters the title text of the latest post on the current blog in the loop.
    900          *
    901          * @since 1.7.0
    902          *
    903          * @param string $retval Title text for the latest post.
    904          */
    905         return apply_filters( 'bp_get_blog_latest_post_title', $retval );
    906     }
    907 
    908 /**
    909  * Output the permalink of the latest post on the current blog in the loop.
    910  *
    911  * @since 1.7.0
    912  *
    913  * @see bp_get_blog_latest_post_title()
    914  */
    915 function bp_blog_latest_post_permalink() {
    916     echo esc_url( bp_get_blog_latest_post_permalink() );
    917 }
    918     /**
    919      * Return the permalink of the latest post on the current blog in the loop.
    920      *
    921      * @since 1.7.0
    922      *
    923      * @global BP_Blogs_Template
    924      *
    925      * @return string URL of the blog's latest post.
    926      */
    927     function bp_get_blog_latest_post_permalink() {
    928         global $blogs_template;
    929 
    930         $retval = '';
    931 
    932         if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->ID ) )
    933             $retval = add_query_arg( 'p', $blogs_template->blog->latest_post->ID, bp_get_blog_permalink() );
    934 
    935         /**
    936          * Filters the permalink of the latest post on the current blog in the loop.
    937          *
    938          * @since 1.7.0
    939          *
    940          * @param string $retval Permalink URL of the latest post.
    941          */
    942         return apply_filters( 'bp_get_blog_latest_post_permalink', $retval );
    943     }
    944 
    945 /**
    946  * Output the content of the latest post on the current blog in the loop.
    947  *
    948  * @since 1.7.0
    949  *
    950  * @uses bp_get_blog_latest_post_content()
    951  */
    952 function bp_blog_latest_post_content() {
    953     echo bp_get_blog_latest_post_content();
    954 }
    955     /**
    956      * Return the content of the latest post on the current blog in the loop.
    957      *
    958      * @since 1.7.0
    959      *
    960      * @global BP_Blogs_Template
    961      *
    962      * @return string Content of the blog's latest post.
    963      */
    964     function bp_get_blog_latest_post_content() {
    965         global $blogs_template;
    966 
    967         $retval = '';
    968 
    969         if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->post_content ) )
    970             $retval = $blogs_template->blog->latest_post->post_content;
    971 
    972         /**
    973          * Filters the content of the latest post on the current blog in the loop.
    974          *
    975          * @since 1.7.0
    976          *
    977          * @param string $retval Content of the latest post on the current blog in the loop.
    978          */
    979         return apply_filters( 'bp_get_blog_latest_post_content', $retval );
    980     }
    981 
    982 /**
    983  * Output the featured image of the latest post on the current blog in the loop.
    984  *
    985  * @since 1.7.0
    986  *
    987  * @see bp_get_blog_latest_post_content() For description of parameters.
    988  *
    989  * @param string $size See {@link bp_get_blog_latest_post_featured_image()}.
    990  */
    991 function bp_blog_latest_post_featured_image( $size = 'thumbnail' ) {
    992     echo bp_get_blog_latest_post_featured_image( $size );
    993 }
    994     /**
    995      * Return the featured image of the latest post on the current blog in the loop.
    996      *
    997      * @since 1.7.0
    998      *
    999      * @global BP_Blogs_Template
    1000      *
    1001      * @param string $size Image version to return. 'thumbnail', 'medium',
    1002      *                     'large', or 'post-thumbnail'. Default: 'thumbnail'.
    1003      * @return string URL of the image.
    1004      */
    1005     function bp_get_blog_latest_post_featured_image( $size = 'thumbnail' ) {
    1006         global $blogs_template;
    1007 
    1008         $retval = '';
    1009 
    1010         if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->images[$size] ) )
    1011             $retval = $blogs_template->blog->latest_post->images[$size];
    1012 
    1013         /**
    1014          * Filters the featured image of the latest post on the current blog in the loop.
    1015          *
    1016          * @since 1.7.0
    1017          *
    1018          * @param string $retval The featured image of the latest post on the current blog in the loop.
    1019          */
    1020         return apply_filters( 'bp_get_blog_latest_post_featured_image', $retval );
    1021     }
    1022 
    1023 /**
    1024  * Does the latest blog post have a featured image?
    1025  *
    1026  * @since 1.7.0
    1027  *
    1028  * @param string $thumbnail Image version to return. 'thumbnail', 'medium', 'large',
    1029  *                          or 'post-thumbnail'. Default: 'thumbnail'.
    1030  * @return bool True if the latest blog post from the current blog has a
    1031  *              featured image of the given size.
    1032  */
    1033 function bp_blog_latest_post_has_featured_image( $thumbnail = 'thumbnail' ) {
    1034     $image  = bp_get_blog_latest_post_featured_image( $thumbnail );
    1035 
    1036     /**
    1037      * Filters whether or not the latest blog post has a featured image.
    1038      *
    1039      * @since 1.7.0
    1040      *
    1041      * @param bool   $value     Whether or not the latest blog post has a featured image.
    1042      * @param string $thumbnail Image version to return.
    1043      * @param string $image     Returned value from bp_get_blog_latest_post_featured_image.
    1044      */
    1045     return apply_filters( 'bp_blog_latest_post_has_featured_image', ! empty( $image ), $thumbnail, $image );
    1046 }
    1047 
    1048 /**
    1049  * Output hidden fields to help with form submissions in Sites directory.
    1050  *
    1051  * This function detects whether 's', 'letter', or 'blogs_search' requests are
    1052  * currently being made (as in a URL parameter), and creates corresponding
    1053  * hidden fields.
    1054  */
    1055 function bp_blog_hidden_fields() {
    1056     if ( isset( $_REQUEST['s'] ) )
    1057         echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['s'] ). '" name="search_terms" />';
    1058 
    1059     if ( isset( $_REQUEST['letter'] ) )
    1060         echo '<input type="hidden" id="selected_letter" value="' . esc_attr( $_REQUEST['letter'] ) . '" name="selected_letter" />';
    1061 
    1062     if ( isset( $_REQUEST['blogs_search'] ) )
    1063         echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['blogs_search'] ) . '" name="search_terms" />';
    1064 }
    1065 
    1066 /**
    1067  * Output the total number of blogs on the site.
    1068  */
    1069 function bp_total_blog_count() {
    1070     echo bp_get_total_blog_count();
    1071 }
    1072     /**
    1073      * Return the total number of blogs on the site.
    1074      *
    1075      * @return int Total number of blogs.
    1076      */
    1077     function bp_get_total_blog_count() {
    1078 
    1079         /**
    1080          * Filters the total number of blogs on the site.
    1081          *
    1082          * @since 1.2.0
    1083          *
    1084          * @param int $value Total number of blogs on the site.
    1085          */
    1086         return apply_filters( 'bp_get_total_blog_count', bp_blogs_total_blogs() );
    1087     }
    1088     add_filter( 'bp_get_total_blog_count', 'bp_core_number_format' );
    1089 
    1090 /**
    1091  * Output the total number of blogs for a given user.
    1092  *
    1093  * @param int $user_id ID of the user.
    1094  */
    1095 function bp_total_blog_count_for_user( $user_id = 0 ) {
    1096     echo bp_get_total_blog_count_for_user( $user_id );
    1097 }
    1098     /**
    1099      * Return the total number of blogs for a given user.
    1100      *
    1101      * @param int $user_id ID of the user.
    1102      * @return int Total number of blogs for the user.
    1103      */
    1104     function bp_get_total_blog_count_for_user( $user_id = 0 ) {
    1105 
    1106         /**
    1107          * Filters the total number of blogs for a given user.
    1108          *
    1109          * @since 1.2.0
    1110          *
    1111          * @param int $value Total number of blogs for a given user.
    1112          */
    1113         return apply_filters( 'bp_get_total_blog_count_for_user', bp_blogs_total_blogs_for_user( $user_id ) );
    1114     }
    1115     add_filter( 'bp_get_total_blog_count_for_user', 'bp_core_number_format' );
    1116 
    1117 
    1118 /** Blog Registration ********************************************************/
    1119 
    1120 /**
    1121  * Checks whether blog creation is enabled.
    1122  *
    1123  * Returns true when blog creation is enabled for logged-in users only, or
    1124  * when it's enabled for new registrations.
    1125  *
    1126  * @return bool True if blog registration is enabled.
    1127  */
    1128 function bp_blog_signup_enabled() {
    1129     $bp = buddypress();
    1130 
    1131     $active_signup = isset( $bp->site_options['registration'] )
    1132         ? $bp->site_options['registration']
    1133         : 'all';
    1134 
    1135     /**
    1136      * Filters whether or not blog creation is enabled.
    1137      *
    1138      * Return "all", "none", "blog" or "user".
    1139      *
    1140      * @since 1.0.0
    1141      *
    1142      * @param string $active_signup Value of the registration site option creation status.
    1143      */
    1144     $active_signup = apply_filters( 'wpmu_active_signup', $active_signup );
    1145 
    1146     if ( 'none' == $active_signup || 'user' == $active_signup )
    1147         return false;
    1148 
    1149     return true;
    1150 }
    1151 
    1152 /**
    1153  * Output the wrapper markup for the blog signup form.
    1154  *
    1155  * @param string          $blogname   Optional. The default blog name (path or domain).
    1156  * @param string          $blog_title Optional. The default blog title.
    1157  * @param string|WP_Error $errors     Optional. The WP_Error object returned by a previous
    1158  *                                    submission attempt.
    1159  */
    1160 function bp_show_blog_signup_form($blogname = '', $blog_title = '', $errors = '') {
    1161     global $current_user;
    1162 
    1163     if ( isset($_POST['submit']) ) {
    1164         bp_blogs_validate_blog_signup();
    1165     } else {
    1166         if ( ! is_wp_error($errors) ) {
    1167             $errors = new WP_Error();
    1168         }
    1169 
    1170         /**
    1171          * Filters the default values for Blog name, title, and any current errors.
    1172          *
    1173          * @since 1.0.0
    1174          *
    1175          * @param array $value {
    1176          *      string   $blogname   Default blog name provided.
    1177          *      string   $blog_title Default blog title provided.
    1178          *      WP_Error $errors     WP_Error object.
    1179          * }
    1180          */
    1181         $filtered_results = apply_filters('signup_another_blog_init', array('blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors ));
    1182         $blogname = $filtered_results['blogname'];
    1183         $blog_title = $filtered_results['blog_title'];
    1184         $errors = $filtered_results['errors'];
    1185 
    1186         if ( $errors->get_error_code() ) {
    1187             echo "<p>" . __('There was a problem; please correct the form below and try again.', 'buddypress') . "</p>";
    1188         }
    1189         ?>
    1190         <p><?php printf(__("By filling out the form below, you can <strong>add a site to your account</strong>. There is no limit to the number of sites that you can have, so create to your heart's content, but blog responsibly!", 'buddypress'), $current_user->display_name) ?></p>
    1191 
    1192         <p><?php _e("If you&#8217;re not going to use a great domain, leave it for a new user. Now have at it!", 'buddypress') ?></p>
    1193 
    1194         <form class="standard-form" id="setupform" method="post" action="">
    1195 
    1196             <input type="hidden" name="stage" value="gimmeanotherblog" />
    1197             <?php
    1198 
    1199             /**
    1200              * Fires after the default hidden fields in blog signup form markup.
    1201              *
    1202              * @since 1.0.0
    1203              */
    1204             do_action( 'signup_hidden_fields' ); ?>
    1205 
    1206             <?php bp_blogs_signup_blog($blogname, $blog_title, $errors); ?>
    1207             <p>
    1208                 <input id="submit" type="submit" name="submit" class="submit" value="<?php esc_attr_e('Create Site', 'buddypress') ?>" />
    1209             </p>
    1210 
    1211             <?php wp_nonce_field( 'bp_blog_signup_form' ) ?>
    1212         </form>
    1213         <?php
    1214     }
    1215 }
    1216 
    1217 /**
    1218  * Output the input fields for the blog creation form.
    1219  *
    1220  * @param string          $blogname   Optional. The default blog name (path or domain).
    1221  * @param string          $blog_title Optional. The default blog title.
    1222  * @param string|WP_Error $errors     Optional. The WP_Error object returned by a previous
    1223  *                                    submission attempt.
    1224  */
    1225 function bp_blogs_signup_blog( $blogname = '', $blog_title = '', $errors = '' ) {
    1226     global $current_site;
    1227 
    1228     // Blog name.
    1229     if( !is_subdomain_install() )
    1230         echo '<label for="blogname">' . __('Site Name:', 'buddypress') . '</label>';
    1231     else
    1232         echo '<label for="blogname">' . __('Site Domain:', 'buddypress') . '</label>';
    1233 
    1234     if ( $errmsg = $errors->get_error_message('blogname') ) { ?>
    1235 
    1236         <p class="error"><?php echo $errmsg ?></p>
    1237 
    1238     <?php }
    1239 
    1240     if ( !is_subdomain_install() )
    1241         echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span> <input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="63" /><br />';
    1242     else
    1243         echo '<input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="63" ' . bp_get_form_field_attributes( 'blogname' ) . '/> <span class="suffix_address">.' . bp_blogs_get_subdomain_base() . '</span><br />';
    1244 
    1245     if ( !is_user_logged_in() ) {
    1246         print '(<strong>' . __( 'Your address will be ' , 'buddypress');
    1247 
    1248         if ( !is_subdomain_install() ) {
    1249             print $current_site->domain . $current_site->path . __( 'blogname' , 'buddypress');
    1250         } else {
    1251             print __( 'domain.' , 'buddypress') . $current_site->domain . $current_site->path;
    1252         }
    1253 
    1254         echo '.</strong> ' . __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed so choose carefully!)' , 'buddypress') . '</p>';
    1255     }
    1256 
    1257     // Blog Title.
    1258     ?>
    1259 
    1260     <label for="blog_title"><?php _e('Site Title:', 'buddypress') ?></label>
    1261 
    1262     <?php if ( $errmsg = $errors->get_error_message('blog_title') ) { ?>
    1263 
    1264         <p class="error"><?php echo $errmsg ?></p>
    1265 
    1266     <?php }
    1267     echo '<input name="blog_title" type="text" id="blog_title" value="'.esc_html($blog_title, 1).'" /></p>';
    1268     ?>
    1269 
    1270     <p>
    1271         <label for="blog_public_on"><?php _e('Privacy:', 'buddypress') ?></label>
    1272         <?php _e( 'I would like my site to appear in search engines, and in public listings around this network.', 'buddypress' ); ?>
    1273 
    1274         <label class="checkbox" for="blog_public_on">
    1275             <input type="radio" id="blog_public_on" name="blog_public" value="1" <?php if( !isset( $_POST['blog_public'] ) || '1' == $_POST['blog_public'] ) { ?>checked="checked"<?php } ?> />
    1276             <strong><?php _e( 'Yes' , 'buddypress'); ?></strong>
    1277         </label>
    1278         <label class="checkbox" for="blog_public_off">
    1279             <input type="radio" id="blog_public_off" name="blog_public" value="0" <?php if( isset( $_POST['blog_public'] ) && '0' == $_POST['blog_public'] ) { ?>checked="checked"<?php } ?> />
    1280             <strong><?php _e( 'No' , 'buddypress'); ?></strong>
    1281         </label>
    1282     </p>
    1283 
    1284     <?php
    1285 
    1286     /**
    1287      * Fires at the end of all of the default input fields for blog creation form.
    1288      *
    1289      * @since 1.0.0
    1290      *
    1291      * @param WP_Error $errors WP_Error object if any present.
    1292      */
    1293     do_action('signup_blogform', $errors);
    1294 }
    1295 
    1296 /**
    1297  * Process a blog registration submission.
    1298  *
    1299  * Passes submitted values to {@link wpmu_create_blog()}.
    1300  *
    1301  * @return bool True on success, false on failure.
    1302  */
    1303 function bp_blogs_validate_blog_signup() {
    1304     global $wpdb, $current_user, $blogname, $blog_title, $errors, $domain, $path, $current_site;
    1305 
    1306     if ( !check_admin_referer( 'bp_blog_signup_form' ) )
    1307         return false;
    1308 
    1309     $current_user = wp_get_current_user();
    1310 
    1311     if( !is_user_logged_in() )
    1312         die();
    1313 
    1314     $result = bp_blogs_validate_blog_form();
    1315     extract($result);
    1316 
    1317     if ( $errors->get_error_code() ) {
    1318         unset($_POST['submit']);
    1319         bp_show_blog_signup_form( $blogname, $blog_title, $errors );
    1320         return false;
    1321     }
    1322 
    1323     $public = (int) $_POST['blog_public'];
    1324 
    1325     // Depreciated.
    1326     $meta = apply_filters( 'signup_create_blog_meta', array( 'lang_id' => 1, 'public' => $public ) );
    1327 
    1328     /**
    1329      * Filters the default values for Blog meta.
    1330      *
    1331      * @since 1.0.0
    1332      *
    1333      * @param array $meta {
    1334      *      string $value  Default blog language ID.
    1335      *      string $public Default public status.
    1336      * }
    1337      */
    1338     $meta = apply_filters( 'add_signup_meta', $meta );
    1339 
    1340     // If this is a subdomain install, set up the site inside the root domain.
    1341     if ( is_subdomain_install() )
    1342         $domain = $blogname . '.' . preg_replace( '|^www\.|', '', $current_site->domain );
    1343 
    1344     wpmu_create_blog( $domain, $path, $blog_title, $current_user->ID, $meta, $wpdb->siteid );
    1345     bp_blogs_confirm_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta);
    1346     return true;
    1347 }
    1348 
    1349 /**
    1350  * Validate a blog creation submission.
    1351  *
    1352  * Essentially, a wrapper for {@link wpmu_validate_blog_signup()}.
    1353  *
    1354  * @return array Contains the new site data and error messages.
    1355  */
    1356 function bp_blogs_validate_blog_form() {
    1357     $user = '';
    1358     if ( is_user_logged_in() )
    1359         $user = wp_get_current_user();
    1360 
    1361     return wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title'], $user);
    1362 }
    1363 
    1364 /**
    1365  * Display a message after successful blog registration.
    1366  *
    1367  * @param string       $domain     The new blog's domain.
    1368  * @param string       $path       The new blog's path.
    1369  * @param string       $blog_title The new blog's title.
    1370  * @param string       $user_name  The user name of the user who created the blog. Unused.
    1371  * @param string       $user_email The email of the user who created the blog. Unused.
    1372  * @param string|array $meta       Meta values associated with the new blog. Unused.
    1373  */
    1374 function bp_blogs_confirm_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = '' ) {
    1375     $protocol = is_ssl() ? 'https://' : 'http://';
    1376     $blog_url = $protocol . $domain . $path; ?>
    1377 
    1378     <p><?php _e( 'Congratulations! You have successfully registered a new site.', 'buddypress' ) ?></p>
    1379     <p>
    1380         <?php printf(__( '<a href="%1$s">%2$s</a> is your new site.  <a href="%3$s">Login</a> as "%4$s" using your existing password.', 'buddypress' ), $blog_url, $blog_url, $blog_url . "wp-login.php", $user_name ); ?>
    1381     </p>
    1382 
    1383 <?php
    1384 
    1385     /**
    1386      * Fires after the default successful blog registration message markup.
    1387      *
    1388      * @since 1.0.0
    1389      */
    1390     do_action('signup_finished');
    1391 }
    1392 
    1393 /**
    1394  * Output a "Create a Site" link for users viewing their own profiles.
    1395  *
    1396  * This function is not used by BuddyPress as of 1.2, but is kept here for older
    1397  * themes that may still be using it.
    1398  */
    1399 function bp_create_blog_link() {
    1400 
    1401     // Don't show this link when not on your own profile.
    1402     if ( ! bp_is_my_profile() ) {
    1403         return;
    1404     }
    1405 
    1406     /**
    1407      * Filters "Create a Site" links for users viewing their own profiles.
    1408      *
    1409      * @since 1.0.0
    1410      *
    1411      * @param string $value HTML link for creating a site.
    1412      */
    1413     echo apply_filters( 'bp_create_blog_link', '<a href="' . trailingslashit( bp_get_blogs_directory_permalink() . 'create' ) . '">' . __( 'Create a Site', 'buddypress' ) . '</a>' );
    1414 }
    1415 
    1416 /**
    1417  * Output navigation tabs for a user Blogs page.
    1418  *
    1419  * Currently unused by BuddyPress.
    1420  */
    1421 function bp_blogs_blog_tabs() {
    1422 
    1423     // Don't show these tabs on a user's own profile.
    1424     if ( bp_is_my_profile() ) {
    1425         return false;
    1426     } ?>
    1427 
    1428     <ul class="content-header-nav">
    1429         <li<?php if ( bp_is_current_action( 'my-blogs'        ) || !bp_current_action() ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_blogs_slug() . '/my-blogs'        ); ?>"><?php printf( __( "%s's Sites", 'buddypress' ),           bp_get_displayed_user_fullname() ); ?></a></li>
    1430         <li<?php if ( bp_is_current_action( 'recent-posts'    )                         ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_blogs_slug() . '/recent-posts'    ); ?>"><?php printf( __( "%s's Recent Posts", 'buddypress' ),    bp_get_displayed_user_fullname() ); ?></a></li>
    1431         <li<?php if ( bp_is_current_action( 'recent-comments' )                         ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_blogs_slug() . '/recent-comments' ); ?>"><?php printf( __( "%s's Recent Comments", 'buddypress' ), bp_get_displayed_user_fullname() ); ?></a></li>
    1432     </ul>
    1433 
    1434 <?php
    1435 
    1436     /**
    1437      * Fires after the markup for the navigation tabs for a user Blogs page.
    1438      *
    1439      * @since 1.0.0
    1440      */
    1441     do_action( 'bp_blogs_blog_tabs' );
    1442 }
    1443 
    1444 /**
    1445  * Output the blog directory search form.
    1446  */
    1447 function bp_directory_blogs_search_form() {
    1448 
    1449     $query_arg = bp_core_get_component_search_query_arg( 'blogs' );
    1450 
    1451     if ( ! empty( $_REQUEST[ $query_arg ] ) ) {
    1452         $search_value = stripslashes( $_REQUEST[ $query_arg ] );
    1453     } else {
    1454         $search_value = bp_get_search_default_text( 'blogs' );
    1455     }
    1456 
    1457     $search_form_html = '<form action="" method="get" id="search-blogs-form">
    1458         <label for="blogs_search"><input type="text" name="' . esc_attr( $query_arg ) . '" id="blogs_search" placeholder="'. esc_attr( $search_value ) .'" /></label>
    1459         <input type="submit" id="blogs_search_submit" name="blogs_search_submit" value="' . __( 'Search', 'buddypress' ) . '" />
    1460     </form>';
    1461 
    1462     /**
    1463      * Filters the output for the blog directory search form.
    1464      *
    1465      * @since 1.9.0
    1466      *
    1467      * @param string $search_form_html HTML markup for blog directory search form.
    1468      */
    1469     echo apply_filters( 'bp_directory_blogs_search_form', $search_form_html );
    1470 }
    1471 
    1472 /**
    1473  * Output the Create a Site button.
    1474  *
    1475  * @since 2.0.0
    1476  */
    1477 function bp_blog_create_button() {
    1478     echo bp_get_blog_create_button();
    1479 }
    1480     /**
    1481      * Get the Create a Site button.
    1482      *
    1483      * @since 2.0.0
    1484      *
    1485      * @return string
    1486      */
    1487     function bp_get_blog_create_button() {
    1488         if ( ! is_user_logged_in() ) {
    1489             return false;
    1490         }
    1491 
    1492         if ( ! bp_blog_signup_enabled() ) {
    1493             return false;
    1494         }
    1495 
    1496         $button_args = array(
    1497             'id'         => 'create_blog',
    1498             'component'  => 'blogs',
    1499             'link_text'  => __( 'Create a Site', 'buddypress' ),
    1500             'link_title' => __( 'Create a Site', 'buddypress' ),
    1501             'link_class' => 'blog-create no-ajax',
    1502             'link_href'  => trailingslashit( bp_get_blogs_directory_permalink() . 'create' ),
    1503             'wrapper'    => false,
    1504             'block_self' => false,
    1505         );
    1506 
    1507         /**
    1508          * Filters the Create a Site button.
    1509          *
    1510          * @since 2.0.0
    1511          *
    1512          * @param array $button_args Array of arguments to be used for the Create a Site button.
    1513          */
    1514         return bp_get_button( apply_filters( 'bp_get_blog_create_button', $button_args ) );
    1515     }
    1516 
    1517 /**
    1518  * Output the Create a Site nav item.
    1519  *
    1520  * @since 2.2.0
    1521  */
    1522 function bp_blog_create_nav_item() {
    1523     echo bp_get_blog_create_nav_item();
    1524 }
    1525 
    1526     /**
    1527      * Get the Create a Site nav item.
    1528      *
    1529      * @since 2.2.0
    1530      *
    1531      * @return string
    1532      */
    1533     function bp_get_blog_create_nav_item() {
    1534         // Get the create a site button.
    1535         $create_blog_button = bp_get_blog_create_button();
    1536 
    1537         // Make sure the button is available.
    1538         if ( empty( $create_blog_button ) ) {
    1539             return;
    1540         }
    1541 
    1542         $output = '<li id="blog-create-nav">' . $create_blog_button . '</li>';
    1543 
    1544         return apply_filters( 'bp_get_blog_create_nav_item', $output );
    1545     }
    1546 
    1547 /**
    1548  * Checks if a specific theme is still filtering the Blogs directory title
    1549  * if so, transform the title button into a Blogs directory nav item.
    1550  *
    1551  * @since 2.2.0
    1552  *
    1553  * @uses bp_blog_create_nav_item() to output the Create a Site nav item.
    1554  *
    1555  * @return string HTML Output
    1556  */
    1557 function bp_blog_backcompat_create_nav_item() {
    1558     // Bail if Blogs nav item is already used by bp-legacy.
    1559     if ( has_action( 'bp_blogs_directory_blog_types', 'bp_legacy_theme_blog_create_nav', 999 ) ) {
    1560         return;
    1561     }
    1562 
    1563     // Bail if the theme is not filtering the Blogs directory title.
    1564     if ( ! has_filter( 'bp_blogs_directory_header' ) ) {
    1565         return;
    1566     }
    1567 
    1568     bp_blog_create_nav_item();
    1569 }
    1570 add_action( 'bp_blogs_directory_blog_types', 'bp_blog_backcompat_create_nav_item', 1000 );
    1571 
    1572 /**
    1573  * Output button for visiting a blog in a loop.
    1574  *
    1575  * @see bp_get_blogs_visit_blog_button() for description of arguments.
    1576  *
    1577  * @param array|string $args See {@link bp_get_blogs_visit_blog_button()}.
    1578  */
    1579 function bp_blogs_visit_blog_button( $args = '' ) {
    1580     echo bp_get_blogs_visit_blog_button( $args );
    1581 }
    1582     /**
    1583      * Return button for visiting a blog in a loop.
    1584      *
    1585      * @see BP_Button for a complete description of arguments and return
    1586      *      value.
    1587      *
    1588      * @param array|string $args {
    1589      *     Arguments are listed below, with their default values. For a
    1590      *     complete description of arguments, see {@link BP_Button}.
    1591      *     @type string $id                Default: 'visit_blog'.
    1592      *     @type string $component         Default: 'blogs'.
    1593      *     @type bool   $must_be_logged_in Default: false.
    1594      *     @type bool   $block_self        Default: false.
    1595      *     @type string $wrapper_class     Default: 'blog-button visit'.
    1596      *     @type string $link_href         Permalink of the current blog in the loop.
    1597      *     @type string $link_class        Default: 'blog-button visit'.
    1598      *     @type string $link_text         Default: 'Visit Site'.
    1599      *     @type string $link_title        Default: 'Visit Site'.
    1600      * }
    1601      * @return string The HTML for the Visit button.
    1602      */
    1603     function bp_get_blogs_visit_blog_button( $args = '' ) {
    1604         $defaults = array(
    1605             'id'                => 'visit_blog',
    1606             'component'         => 'blogs',
    1607             'must_be_logged_in' => false,
    1608             'block_self'        => false,
    1609             'wrapper_class'     => 'blog-button visit',
    1610             'link_href'         => bp_get_blog_permalink(),
    1611             'link_class'        => 'blog-button visit',
    1612             'link_text'         => __( 'Visit Site', 'buddypress' ),
    1613             'link_title'        => __( 'Visit Site', 'buddypress' ),
    1614         );
    1615 
    1616         $button = wp_parse_args( $args, $defaults );
    1617 
    1618         /**
    1619          * Filters the button for visiting a blog in a loop.
    1620          *
    1621          * @since 1.2.10
    1622          *
    1623          * @param array $button Array of arguments to be used for the button to visit a blog.
    1624          */
    1625         return bp_get_button( apply_filters( 'bp_get_blogs_visit_blog_button', $button ) );
    1626     }
    1627 
    1628 /** Stats **********************************************************************/
    1629 
    1630 /**
    1631  * Display the number of blogs in user's profile.
    1632  *
    1633  * @since 2.0.0
    1634  *
    1635  * @uses bp_blogs_admin_get_profile_stats() to get the stats.
    1636  *
    1637  * @param array|string $args Before|after|user_id.
    1638  */
    1639 function bp_blogs_profile_stats( $args = '' ) {
    1640     echo bp_blogs_get_profile_stats( $args );
    1641 }
    1642 add_action( 'bp_members_admin_user_stats', 'bp_blogs_profile_stats', 9, 1 );
    1643 
    1644 /**
    1645  * Return the number of blogs in user's profile.
    1646  *
    1647  * @since 2.0.0
    1648  *
    1649  * @param array|string $args Before|after|user_id.
    1650  * @return string HTML for stats output.
    1651  */
    1652 function bp_blogs_get_profile_stats( $args = '' ) {
    1653 
    1654     // Parse the args.
    1655     $r = bp_parse_args( $args, array(
    1656         'before'  => '<li class="bp-blogs-profile-stats">',
    1657         'after'   => '</li>',
    1658         'user_id' => bp_displayed_user_id(),
    1659         'blogs'   => 0,
    1660         'output'  => ''
    1661     ), 'blogs_get_profile_stats' );
    1662 
    1663     // Allow completely overloaded output.
    1664     if ( is_multisite() && empty( $r['output'] ) ) {
    1665 
    1666         // Only proceed if a user ID was passed.
    1667         if ( ! empty( $r['user_id'] ) ) {
    1668 
    1669             // Get the user's blogs.
    1670             if ( empty( $r['blogs'] ) ) {
    1671                 $r['blogs'] = absint( bp_blogs_total_blogs_for_user( $r['user_id'] ) );
    1672             }
    1673 
    1674             // If blogs exist, show some formatted output.
    1675             $r['output'] = $r['before'] . sprintf( _n( '%s site', '%s sites', $r['blogs'], 'buddypress' ), '<strong>' . $r['blogs'] . '</strong>' ) . $r['after'];
    1676         }
    1677     }
    1678 
    1679     /**
    1680      * Filters the number of blogs in user's profile.
    1681      *
    1682      * @since 2.0.0
    1683      *
    1684      * @param string $value Output determined for the profile stats.
    1685      * @param array  $r     Array of arguments used for default output if none provided.
    1686      */
    1687     return apply_filters( 'bp_blogs_get_profile_stats', $r['output'], $r );
    1688 }
  • trunk/src/bp-blogs/classes/class-bp-blogs-theme-compat.php

    r10515 r10517  
    11<?php
    22/**
    3  * BuddyPress Blogs Screens.
     3 * BuddyPress Blogs Theme Compatibility.
    44 *
    55 * @package BuddyPress
     
    1010// Exit if accessed directly.
    1111defined( 'ABSPATH' ) || exit;
    12 
    13 /**
    14  * Load the "My Blogs" screen.
    15  */
    16 function bp_blogs_screen_my_blogs() {
    17     if ( !is_multisite() )
    18         return false;
    19 
    20     /**
    21      * Fires right before the loading of the My Blogs screen template file.
    22      *
    23      * @since 1.0.0
    24      */
    25     do_action( 'bp_blogs_screen_my_blogs' );
    26 
    27     bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'members/single/home' ) );
    28 }
    29 
    30 /**
    31  * Load the "Create a Blog" screen.
    32  */
    33 function bp_blogs_screen_create_a_blog() {
    34 
    35     if ( !is_multisite() ||  !bp_is_blogs_component() || !bp_is_current_action( 'create' ) )
    36         return false;
    37 
    38     if ( !is_user_logged_in() || !bp_blog_signup_enabled() )
    39         return false;
    40 
    41     /**
    42      * Fires right before the loading of the Create A Blog screen template file.
    43      *
    44      * @since 1.0.0
    45      */
    46     do_action( 'bp_blogs_screen_create_a_blog' );
    47 
    48     bp_core_load_template( apply_filters( 'bp_blogs_template_create_a_blog', 'blogs/create' ) );
    49 }
    50 add_action( 'bp_screens', 'bp_blogs_screen_create_a_blog', 3 );
    51 
    52 /**
    53  * Load the top-level Blogs directory.
    54  */
    55 function bp_blogs_screen_index() {
    56     if ( bp_is_blogs_directory() ) {
    57         bp_update_is_directory( true, 'blogs' );
    58 
    59         /**
    60          * Fires right before the loading of the top-level Blogs screen template file.
    61          *
    62          * @since 1.0.0
    63          */
    64         do_action( 'bp_blogs_screen_index' );
    65 
    66         bp_core_load_template( apply_filters( 'bp_blogs_screen_index', 'blogs/index' ) );
    67     }
    68 }
    69 add_action( 'bp_screens', 'bp_blogs_screen_index', 2 );
    70 
    71 /** Theme Compatibility *******************************************************/
    7212
    7313/**
     
    260200    }
    261201}
    262 new BP_Blogs_Theme_Compat();
Note: See TracChangeset for help on using the changeset viewer.