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


Generated: Tue Nov 19 01:01:36 2019 Cross-referenced by PHPXref 0.7.1