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


Generated: Thu Nov 21 01:00:57 2024 Cross-referenced by PHPXref 0.7.1