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


Generated: Sat Sep 21 01:01:46 2019 Cross-referenced by PHPXref 0.7.1