[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-blogs/ -> bp-blogs-template.php (source)

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


Generated: Mon Aug 10 01:01:38 2020 Cross-referenced by PHPXref 0.7.1