[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * BuddyPress Blogs Template Tags
   5   *
   6   * @package BuddyPress
   7   * @subpackage BlogsTemplate
   8   */
   9  
  10  // Exit if accessed directly
  11  if ( !defined( 'ABSPATH' ) ) exit;
  12  
  13  /**
  14   * Output the blogs component slug
  15   *
  16   * @package BuddyPress
  17   * @subpackage BlogsTemplate
  18   * @since BuddyPress (1.5)
  19   *
  20   * @uses bp_get_blogs_slug()
  21   */
  22  function bp_blogs_slug() {
  23      echo bp_get_blogs_slug();
  24  }
  25      /**
  26       * Return the blogs component slug
  27       *
  28       * @package BuddyPress
  29       * @subpackage BlogsTemplate
  30       * @since BuddyPress (1.5)
  31       */
  32  	function bp_get_blogs_slug() {
  33          return apply_filters( 'bp_get_blogs_slug', buddypress()->blogs->slug );
  34      }
  35  
  36  /**
  37   * Output the blogs component root slug
  38   *
  39   * @package BuddyPress
  40   * @subpackage BlogsTemplate
  41   * @since BuddyPress (1.5)
  42   *
  43   * @uses bp_get_blogs_root_slug()
  44   */
  45  function bp_blogs_root_slug() {
  46      echo bp_get_blogs_root_slug();
  47  }
  48      /**
  49       * Return the blogs component root slug
  50       *
  51       * @package BuddyPress
  52       * @subpackage BlogsTemplate
  53       * @since BuddyPress (1.5)
  54       */
  55  	function bp_get_blogs_root_slug() {
  56          return apply_filters( 'bp_get_blogs_root_slug', buddypress()->blogs->root_slug );
  57      }
  58  
  59  /**
  60   * Output blog directory permalink
  61   *
  62   * @package BuddyPress
  63   * @subpackage BlogsTemplate
  64   * @since BuddyPress (1.5)
  65   * @uses bp_get_blogs_directory_permalink()
  66   */
  67  function bp_blogs_directory_permalink() {
  68      echo bp_get_blogs_directory_permalink();
  69  }
  70      /**
  71       * Return blog directory permalink
  72       *
  73       * @package BuddyPress
  74       * @subpackage BlogsTemplate
  75       * @since BuddyPress (1.5)
  76       * @uses apply_filters()
  77       * @uses traisingslashit()
  78       * @uses bp_get_root_domain()
  79       * @uses bp_get_blogs_root_slug()
  80       * @return string
  81       */
  82  	function bp_get_blogs_directory_permalink() {
  83          return apply_filters( 'bp_get_blogs_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_blogs_root_slug() ) );
  84      }
  85  
  86  /**********************************************************************
  87   * Blog listing template class.
  88   */
  89  
  90  class BP_Blogs_Template {
  91      var $current_blog = -1;
  92      var $blog_count;
  93      var $blogs;
  94      var $blog;
  95  
  96      var $in_the_loop;
  97  
  98      var $pag_page;
  99      var $pag_num;
 100      var $pag_links;
 101      var $total_blog_count;
 102  
 103  	function __construct( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg = 'bpage' ) {
 104  
 105          $this->pag_page = isset( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[$page_arg] ) : $page;
 106          $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
 107  
 108          if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] )
 109              $this->blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page );
 110          else
 111              $this->blogs = bp_blogs_get_blogs( array( 'type' => $type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms ) );
 112  
 113          if ( !$max || $max >= (int) $this->blogs['total'] )
 114              $this->total_blog_count = (int) $this->blogs['total'];
 115          else
 116              $this->total_blog_count = (int) $max;
 117  
 118          $this->blogs = $this->blogs['blogs'];
 119  
 120          if ( $max ) {
 121              if ( $max >= count($this->blogs) ) {
 122                  $this->blog_count = count( $this->blogs );
 123              } else {
 124                  $this->blog_count = (int) $max;
 125              }
 126          } else {
 127              $this->blog_count = count( $this->blogs );
 128          }
 129  
 130          if ( (int) $this->total_blog_count && (int) $this->pag_num ) {
 131              $this->pag_links = paginate_links( array(
 132                  'base'      => add_query_arg( $page_arg, '%#%' ),
 133                  'format'    => '',
 134                  'total'     => ceil( (int) $this->total_blog_count / (int) $this->pag_num ),
 135                  'current'   => (int) $this->pag_page,
 136                  'prev_text' => _x( '&larr;', 'Blog pagination previous text', 'buddypress' ),
 137                  'next_text' => _x( '&rarr;', 'Blog pagination next text', 'buddypress' ),
 138                  'mid_size'  => 1
 139              ) );
 140          }
 141      }
 142  
 143  	function has_blogs() {
 144          if ( $this->blog_count )
 145              return true;
 146  
 147          return false;
 148      }
 149  
 150  	function next_blog() {
 151          $this->current_blog++;
 152          $this->blog = $this->blogs[$this->current_blog];
 153  
 154          return $this->blog;
 155      }
 156  
 157  	function rewind_blogs() {
 158          $this->current_blog = -1;
 159          if ( $this->blog_count > 0 ) {
 160              $this->blog = $this->blogs[0];
 161          }
 162      }
 163  
 164  	function blogs() {
 165          if ( $this->current_blog + 1 < $this->blog_count ) {
 166              return true;
 167          } elseif ( $this->current_blog + 1 == $this->blog_count ) {
 168              do_action('blog_loop_end');
 169              // Do some cleaning up after the loop
 170              $this->rewind_blogs();
 171          }
 172  
 173          $this->in_the_loop = false;
 174          return false;
 175      }
 176  
 177  	function the_blog() {
 178  
 179          $this->in_the_loop = true;
 180          $this->blog        = $this->next_blog();
 181  
 182          if ( 0 == $this->current_blog ) // loop has just started
 183              do_action('blog_loop_start');
 184      }
 185  }
 186  
 187  function bp_rewind_blogs() {
 188      global $blogs_template;
 189  
 190      $blogs_template->rewind_blogs();
 191  }
 192  
 193  function bp_has_blogs( $args = '' ) {
 194      global $blogs_template;
 195  
 196      /***
 197       * Set the defaults based on the current page. Any of these will be overridden
 198       * if arguments are directly passed into the loop. Custom plugins should always
 199       * pass their parameters directly to the loop.
 200       */
 201      $type         = 'active';
 202      $user_id      = 0;
 203      $search_terms = null;
 204  
 205      // User filtering
 206      if ( bp_displayed_user_id() )
 207          $user_id = bp_displayed_user_id();
 208  
 209      $defaults = array(
 210          'type'         => $type,
 211          'page'         => 1,
 212          'per_page'     => 20,
 213          'max'          => false,
 214  
 215          'page_arg'     => 'bpage',        // See https://buddypress.trac.wordpress.org/ticket/3679
 216  
 217          'user_id'      => $user_id,       // Pass a user_id to limit to only blogs this user has higher than subscriber access to
 218          'search_terms' => $search_terms   // Pass search terms to filter on the blog title or description.
 219      );
 220  
 221      $r = wp_parse_args( $args, $defaults );
 222      extract( $r );
 223  
 224      if ( is_null( $search_terms ) ) {
 225          if ( isset( $_REQUEST['s'] ) && !empty( $_REQUEST['s'] ) )
 226              $search_terms = $_REQUEST['s'];
 227          else
 228              $search_terms = false;
 229      }
 230  
 231      if ( $max ) {
 232          if ( $per_page > $max ) {
 233              $per_page = $max;
 234          }
 235      }
 236  
 237      $blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg );
 238      return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), $blogs_template );
 239  }
 240  
 241  function bp_blogs() {
 242      global $blogs_template;
 243  
 244      return $blogs_template->blogs();
 245  }
 246  
 247  function bp_the_blog() {
 248      global $blogs_template;
 249  
 250      return $blogs_template->the_blog();
 251  }
 252  
 253  function bp_blogs_pagination_count() {
 254      global $blogs_template;
 255  
 256      $start_num = intval( ( $blogs_template->pag_page - 1 ) * $blogs_template->pag_num ) + 1;
 257      $from_num  = bp_core_number_format( $start_num );
 258      $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 ) );
 259      $total     = bp_core_number_format( $blogs_template->total_blog_count );
 260  
 261      echo sprintf( __( 'Viewing site %1$s to %2$s (of %3$s sites)', 'buddypress' ), $from_num, $to_num, $total );
 262  }
 263  
 264  function bp_blogs_pagination_links() {
 265      echo bp_get_blogs_pagination_links();
 266  }
 267  	function bp_get_blogs_pagination_links() {
 268          global $blogs_template;
 269  
 270          return apply_filters( 'bp_get_blogs_pagination_links', $blogs_template->pag_links );
 271      }
 272  
 273  function bp_blog_avatar( $args = '' ) {
 274      echo bp_get_blog_avatar( $args );
 275  }
 276  	function bp_get_blog_avatar( $args = '' ) {
 277          global $blogs_template;
 278  
 279          $defaults = array(
 280              'type'    => 'full',
 281              'width'   => false,
 282              'height'  => false,
 283              'class'   => 'avatar',
 284              'id'      => false,
 285              'alt'     => sprintf( __( 'Profile picture of site author %s', 'buddypress' ), bp_core_get_user_displayname( $blogs_template->blog->admin_user_id ) ),
 286              'no_grav' => true
 287          );
 288  
 289          $r = wp_parse_args( $args, $defaults );
 290          extract( $r, EXTR_SKIP );
 291  
 292          /***
 293           * In future BuddyPress versions you will be able to set the avatar for a blog.
 294           * Right now you can use a filter with the ID of the blog to change it if you wish.
 295           * By default it will return the avatar for the primary blog admin.
 296           *
 297           * This filter is deprecated as of BuddyPress 1.5 and may be removed in a future version.
 298           * Use the 'bp_get_blog_avatar' filter instead.
 299           */
 300          $avatar = apply_filters( 'bp_get_blog_avatar_' . $blogs_template->blog->blog_id, bp_core_fetch_avatar( array( 'item_id' => $blogs_template->blog->admin_user_id, 'type' => $type, 'alt' => $alt, 'width' => $width, 'height' => $height, 'class' => $class, 'email' => $blogs_template->blog->admin_user_email ) ) );
 301  
 302          return apply_filters( 'bp_get_blog_avatar', $avatar, $blogs_template->blog->blog_id, array( 'item_id' => $blogs_template->blog->admin_user_id, 'type' => $type, 'alt' => $alt, 'width' => $width, 'height' => $height, 'class' => $class, 'email' => $blogs_template->blog->admin_user_email ) );
 303      }
 304  
 305  function bp_blog_permalink() {
 306      echo bp_get_blog_permalink();
 307  }
 308  	function bp_get_blog_permalink() {
 309          global $blogs_template;
 310  
 311          if ( empty( $blogs_template->blog->domain ) )
 312              $permalink = bp_get_root_domain() . $blogs_template->blog->path;
 313          else {
 314              $protocol = 'http://';
 315              if ( is_ssl() )
 316                  $protocol = 'https://';
 317  
 318              $permalink = $protocol . $blogs_template->blog->domain . $blogs_template->blog->path;
 319          }
 320  
 321          return apply_filters( 'bp_get_blog_permalink', $permalink );
 322      }
 323  
 324  function bp_blog_name() {
 325      echo bp_get_blog_name();
 326  }
 327  	function bp_get_blog_name() {
 328          global $blogs_template;
 329  
 330          return apply_filters( 'bp_get_blog_name', $blogs_template->blog->name );
 331      }
 332  
 333  /**
 334   * Outputs the blog ID
 335   *
 336   * @since BuddyPress (1.7)
 337   */
 338  function bp_blog_id() {
 339      echo bp_get_blog_id();
 340  }
 341      /**
 342       * Returns the blog ID
 343       *
 344       * @return int
 345       * @since BuddyPress (1.7)
 346       */
 347  	function bp_get_blog_id() {
 348          global $blogs_template;
 349  
 350          return apply_filters( 'bp_get_blog_id', $blogs_template->blog->blog_id );
 351      }
 352  
 353  function bp_blog_description() {
 354      echo apply_filters( 'bp_blog_description', bp_get_blog_description() );
 355  }
 356  	function bp_get_blog_description() {
 357          global $blogs_template;
 358  
 359          return apply_filters( 'bp_get_blog_description', $blogs_template->blog->description );
 360      }
 361  
 362  
 363  /**
 364   * Output the row class of a site
 365   *
 366   * @since BuddyPress (1.7)
 367   */
 368  function bp_blog_class() {
 369      echo bp_get_blog_class();
 370  }
 371      /**
 372       * Return the row class of a site
 373       *
 374       * @global BP_Blogs_Template $blogs_template
 375       * @return string Row class of the site
 376       * @since BuddyPress (1.7)
 377       */
 378  	function bp_get_blog_class() {
 379          global $blogs_template;
 380  
 381          $classes     = array();
 382          $pos_in_loop = (int) $blogs_template->current_blog;
 383  
 384          // If we've only one site in the loop, don't bother with odd and even.
 385          if ( $blogs_template->blog_count > 1 )
 386              $classes[] = ( $pos_in_loop % 2 ) ? 'even' : 'odd';
 387          else
 388              $classes[] = 'bp-single-blog';
 389  
 390          $classes = apply_filters( 'bp_get_blog_class', $classes );
 391          $classes = array_merge( $classes, array() );
 392  
 393          $retval = 'class="' . join( ' ', $classes ) . '"';
 394          return $retval;
 395      }
 396  
 397  function bp_blog_last_active() {
 398      echo bp_get_blog_last_active();
 399  }
 400  	function bp_get_blog_last_active() {
 401          global $blogs_template;
 402  
 403          return apply_filters( 'bp_blog_last_active', bp_core_get_last_activity( $blogs_template->blog->last_activity, __( 'active %s', 'buddypress' ) ) );
 404      }
 405  
 406  function bp_blog_latest_post() {
 407      echo bp_get_blog_latest_post();
 408  }
 409  	function bp_get_blog_latest_post() {
 410          global $blogs_template;
 411  
 412          $retval = bp_get_blog_latest_post_title();
 413  
 414          if ( ! empty( $retval ) )
 415              $retval = sprintf( __( 'Latest Post: %s', 'buddypress' ), '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval ) . '</a>' );
 416  
 417          return apply_filters( 'bp_get_blog_latest_post', $retval );
 418      }
 419  
 420  /**
 421   * Prints this site's latest article's title
 422   *
 423   * @since BuddyPress (1.7)
 424   *
 425   * @see bp_get_blog_latest_post_title()
 426   */
 427  function bp_blog_latest_post_title() {
 428      echo bp_get_blog_latest_post_title();
 429  }
 430      /**
 431       * Returns this site's latest article's title
 432       *
 433       * @since BuddyPress (1.7)
 434       *
 435       * @global BP_Blogs_Template
 436       * @return string
 437       */
 438  	function bp_get_blog_latest_post_title() {
 439          global $blogs_template;
 440  
 441          $retval = '';
 442  
 443          if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->post_title ) )
 444              $retval = $blogs_template->blog->latest_post->post_title;
 445  
 446          return apply_filters( 'bp_get_blog_latest_post_title', $retval );
 447      }
 448  
 449  /**
 450   * Prints this site's latest article's permalink
 451   *
 452   * @see bp_get_blog_latest_post_title()
 453   * @since BuddyPress (1.7)
 454   */
 455  function bp_blog_latest_post_permalink() {
 456      echo bp_get_blog_latest_post_permalink();
 457  }
 458      /**
 459       * Returns this site's latest article's permalink
 460       *
 461       * @global BP_Blogs_Template
 462       * @return string
 463       * @since BuddyPress (1.7)
 464       */
 465  	function bp_get_blog_latest_post_permalink() {
 466          global $blogs_template;
 467  
 468          $retval = '';
 469  
 470          if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->ID ) )
 471              $retval = add_query_arg( 'p', $blogs_template->blog->latest_post->ID, bp_get_blog_permalink() );
 472  
 473          return apply_filters( 'bp_get_blog_latest_post_permalink', $retval );
 474      }
 475  
 476  /**
 477   * Prints this site's latest article's content
 478   *
 479   * @since BuddyPress (1.7)
 480   *
 481   * @uses bp_get_blog_latest_post_content()
 482   */
 483  function bp_blog_latest_post_content() {
 484      echo bp_get_blog_latest_post_content();
 485  }
 486      /**
 487       * Returns this site's latest article's content
 488       *
 489       * @since BuddyPress (1.7)
 490       *
 491       * @global BP_Blogs_Template
 492       * @return string
 493       */
 494  	function bp_get_blog_latest_post_content() {
 495          global $blogs_template;
 496  
 497          $retval = '';
 498  
 499          if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->post_content ) )
 500              $retval = $blogs_template->blog->latest_post->post_content;
 501  
 502          return apply_filters( 'bp_get_blog_latest_post_content', $retval );
 503      }
 504  
 505  /**
 506   * Prints this site's latest article's featured image
 507   *
 508   * @since BuddyPress (1.7)
 509   *
 510   * @param string $size Image version to return. Either "thumbnail", "medium", "large", "post-thumbnail".
 511   * @see bp_get_blog_latest_post_content()
 512   */
 513  function bp_blog_latest_post_featured_image( $size = 'thumbnail' ) {
 514      echo bp_get_blog_latest_post_featured_image( $size );
 515  }
 516      /**
 517       * Returns this site's latest article's featured image
 518       *
 519       * @since BuddyPress (1.7)
 520       *
 521       * @global BP_Blogs_Template
 522       * @param string $size Image version to return. Either "thumbnail", "medium", "large", "post-thumbnail".
 523       * @return string
 524       */
 525  	function bp_get_blog_latest_post_featured_image( $size = 'thumbnail' ) {
 526          global $blogs_template;
 527  
 528          $retval = '';
 529  
 530          if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->images[$size] ) )
 531              $retval = $blogs_template->blog->latest_post->images[$size];
 532  
 533          return apply_filters( 'bp_get_blog_latest_post_featured_image', $retval );
 534      }
 535  
 536  /**
 537   * Does the latest blog post have a featured image?
 538   *
 539   * @param string $size Image version to check for. Either "thumbnail", "medium", "large", "post-thumbnail".
 540   * @return bool
 541   * @since BuddyPress (1.7)
 542   */
 543  function bp_blog_latest_post_has_featured_image( $thumbnail = 'thumbnail' ) {
 544      $image  = bp_get_blog_latest_post_featured_image( $thumbnail );
 545  
 546      return apply_filters( 'bp_blog_latest_post_has_featured_image', ! empty( $image ), $thumbnail, $image );
 547  }
 548  
 549  function bp_blog_hidden_fields() {
 550      if ( isset( $_REQUEST['s'] ) )
 551          echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['s'] ). '" name="search_terms" />';
 552  
 553      if ( isset( $_REQUEST['letter'] ) )
 554          echo '<input type="hidden" id="selected_letter" value="' . esc_attr( $_REQUEST['letter'] ) . '" name="selected_letter" />';
 555  
 556      if ( isset( $_REQUEST['blogs_search'] ) )
 557          echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['blogs_search'] ) . '" name="search_terms" />';
 558  }
 559  
 560  function bp_total_blog_count() {
 561      echo bp_get_total_blog_count();
 562  }
 563  	function bp_get_total_blog_count() {
 564          return apply_filters( 'bp_get_total_blog_count', bp_blogs_total_blogs() );
 565      }
 566      add_filter( 'bp_get_total_blog_count', 'bp_core_number_format' );
 567  
 568  function bp_total_blog_count_for_user( $user_id = 0 ) {
 569      echo bp_get_total_blog_count_for_user( $user_id );
 570  }
 571  	function bp_get_total_blog_count_for_user( $user_id = 0 ) {
 572          return apply_filters( 'bp_get_total_blog_count_for_user', bp_blogs_total_blogs_for_user( $user_id ) );
 573      }
 574      add_filter( 'bp_get_total_blog_count_for_user', 'bp_core_number_format' );
 575  
 576  
 577  /* Blog registration template tags */
 578  
 579  function bp_blog_signup_enabled() {
 580      global $bp;
 581  
 582      $active_signup = isset( $bp->site_options['registration'] ) ? $bp->site_options['registration'] : 'all';
 583  
 584      $active_signup = apply_filters( 'wpmu_active_signup', $active_signup ); // return "all", "none", "blog" or "user"
 585  
 586      if ( 'none' == $active_signup || 'user' == $active_signup )
 587          return false;
 588  
 589      return true;
 590  }
 591  
 592  function bp_show_blog_signup_form($blogname = '', $blog_title = '', $errors = '') {
 593      global $current_user;
 594  
 595      if ( isset($_POST['submit']) ) {
 596          bp_blogs_validate_blog_signup();
 597      } else {
 598          if ( ! is_wp_error($errors) ) {
 599              $errors = new WP_Error();
 600          }
 601  
 602          // allow definition of default variables
 603          $filtered_results = apply_filters('signup_another_blog_init', array('blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors ));
 604          $blogname = $filtered_results['blogname'];
 605          $blog_title = $filtered_results['blog_title'];
 606          $errors = $filtered_results['errors'];
 607  
 608          if ( $errors->get_error_code() ) {
 609              echo "<p>" . __('There was a problem, please correct the form below and try again.', 'buddypress') . "</p>";
 610          }
 611          ?>
 612          <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>
 613  
 614          <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>
 615  
 616          <form class="standard-form" id="setupform" method="post" action="">
 617  
 618              <input type="hidden" name="stage" value="gimmeanotherblog" />
 619              <?php do_action( 'signup_hidden_fields' ); ?>
 620  
 621              <?php bp_blogs_signup_blog($blogname, $blog_title, $errors); ?>
 622              <p>
 623                  <input id="submit" type="submit" name="submit" class="submit" value="<?php _e('Create Site', 'buddypress') ?>" />
 624              </p>
 625  
 626              <?php wp_nonce_field( 'bp_blog_signup_form' ) ?>
 627          </form>
 628          <?php
 629      }
 630  }
 631  
 632  function bp_blogs_signup_blog( $blogname = '', $blog_title = '', $errors = '' ) {
 633      global $current_site;
 634  
 635      // Blog name
 636      if( !is_subdomain_install() )
 637          echo '<label for="blogname">' . __('Site Name:', 'buddypress') . '</label>';
 638      else
 639          echo '<label for="blogname">' . __('Site Domain:', 'buddypress') . '</label>';
 640  
 641      if ( $errmsg = $errors->get_error_message('blogname') ) { ?>
 642  
 643          <p class="error"><?php echo $errmsg ?></p>
 644  
 645      <?php }
 646  
 647      if ( !is_subdomain_install() )
 648          echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span> <input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="63" /><br />';
 649      else
 650          echo '<input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="63" /> <span class="suffix_address">.' . bp_blogs_get_subdomain_base() . '</span><br />';
 651  
 652      if ( !is_user_logged_in() ) {
 653          print '(<strong>' . __( 'Your address will be ' , 'buddypress');
 654  
 655          if ( !is_subdomain_install() ) {
 656              print $current_site->domain . $current_site->path . __( 'blogname' , 'buddypress');
 657          } else {
 658              print __( 'domain.' , 'buddypress') . $current_site->domain . $current_site->path;
 659          }
 660  
 661          echo '.</strong> ' . __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed so choose carefully!)' , 'buddypress') . '</p>';
 662      }
 663  
 664      // Blog Title
 665      ?>
 666  
 667      <label for="blog_title"><?php _e('Site Title:', 'buddypress') ?></label>
 668  
 669      <?php if ( $errmsg = $errors->get_error_message('blog_title') ) { ?>
 670  
 671          <p class="error"><?php echo $errmsg ?></p>
 672  
 673      <?php }
 674      echo '<input name="blog_title" type="text" id="blog_title" value="'.esc_html($blog_title, 1).'" /></p>';
 675      ?>
 676  
 677      <p>
 678          <label for="blog_public_on"><?php _e('Privacy:', 'buddypress') ?></label>
 679          <?php _e( 'I would like my site to appear in search engines, and in public listings around this network.', 'buddypress' ); ?>
 680  
 681          <label class="checkbox" for="blog_public_on">
 682              <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 } ?> />
 683              <strong><?php _e( 'Yes' , 'buddypress'); ?></strong>
 684          </label>
 685          <label class="checkbox" for="blog_public_off">
 686              <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 } ?> />
 687              <strong><?php _e( 'No' , 'buddypress'); ?></strong>
 688          </label>
 689      </p>
 690  
 691      <?php
 692      do_action('signup_blogform', $errors);
 693  }
 694  
 695  /**
 696   * Echo the value of bp_blogs_get_subdomain_base()
 697   *
 698   * @since BuddyPress (1.6)
 699   */
 700  function bp_blogs_subdomain_base() {
 701      echo bp_blogs_get_subdomain_base();
 702  }
 703      /**
 704       * Return the base URL to be displayed when a user chooses an address for a new blog, on
 705       * a subdomain installation of WordPress MS
 706       *
 707       * @since BuddyPress (1.6)
 708       * @return str The base URL - eg, 'example.com' for site_url() example.com or www.example.com
 709       */
 710  	function bp_blogs_get_subdomain_base() {
 711          global $current_site;
 712  
 713          return apply_filters( 'bp_blogs_subdomain_base', preg_replace( '|^www\.|', '', $current_site->domain ) . $current_site->path );
 714      }
 715  
 716  function bp_blogs_validate_blog_signup() {
 717      global $wpdb, $current_user, $blogname, $blog_title, $errors, $domain, $path, $current_site;
 718  
 719      if ( !check_admin_referer( 'bp_blog_signup_form' ) )
 720          return false;
 721  
 722      $current_user = wp_get_current_user();
 723  
 724      if( !is_user_logged_in() )
 725          die();
 726  
 727      $result = bp_blogs_validate_blog_form();
 728      extract($result);
 729  
 730      if ( $errors->get_error_code() ) {
 731          unset($_POST['submit']);
 732          bp_show_blog_signup_form( $blogname, $blog_title, $errors );
 733          return false;
 734      }
 735  
 736      $public = (int) $_POST['blog_public'];
 737  
 738      $meta = apply_filters( 'signup_create_blog_meta', array( 'lang_id' => 1, 'public' => $public ) ); // depreciated
 739      $meta = apply_filters( 'add_signup_meta', $meta );
 740  
 741      // If this is a subdomain install, set up the site inside the root domain.
 742      if ( is_subdomain_install() )
 743          $domain = $blogname . '.' . preg_replace( '|^www\.|', '', $current_site->domain );
 744  
 745      wpmu_create_blog( $domain, $path, $blog_title, $current_user->ID, $meta, $wpdb->siteid );
 746      bp_blogs_confirm_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta);
 747      return true;
 748  }
 749  
 750  function bp_blogs_validate_blog_form() {
 751      $user = '';
 752      if ( is_user_logged_in() )
 753          $user = wp_get_current_user();
 754  
 755      return wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title'], $user);
 756  }
 757  
 758  function bp_blogs_confirm_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = '' ) {
 759      $protocol = is_ssl() ? 'https://' : 'http://';
 760      $blog_url = $protocol . $domain . $path; ?>
 761  
 762      <p><?php _e( 'Congratulations! You have successfully registered a new site.', 'buddypress' ) ?></p>
 763      <p>
 764          <?php printf(__( '<a href="%1$s">%2$s</a> is your new site.  <a href="%3$s">Login</a> as "%4$s" using your existing password.', 'buddypress' ), $blog_url, $blog_url, $blog_url . "wp-login.php", $user_name ); ?>
 765      </p>
 766  
 767  <?php
 768      do_action('signup_finished');
 769  }
 770  
 771  function bp_create_blog_link() {
 772      if ( bp_is_my_profile() )
 773          echo apply_filters( 'bp_create_blog_link', '<a href="' . bp_get_root_domain() . '/' . bp_get_blogs_root_slug() . '/create/">' . __( 'Create a Site', 'buddypress' ) . '</a>' );
 774  }
 775  
 776  function bp_blogs_blog_tabs() {
 777  
 778      // Don't show these tabs on a user's own profile
 779      if ( bp_is_my_profile() )
 780          return false;
 781  
 782      ?>
 783  
 784      <ul class="content-header-nav">
 785          <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>
 786          <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>
 787          <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>
 788      </ul>
 789  
 790  <?php
 791  
 792      // @todo where does $current_tab come from?
 793      do_action( 'bp_blogs_blog_tabs', $current_tab );
 794  }
 795  
 796  function bp_directory_blogs_search_form() {
 797  
 798      $default_search_value = bp_get_search_default_text();
 799      $search_value         = !empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value; ?>
 800  
 801      <form action="" method="get" id="search-blogs-form">
 802          <label><input type="text" name="s" id="blogs_search" placeholder="<?php echo esc_attr( $search_value ) ?>" /></label>
 803          <input type="submit" id="blogs_search_submit" name="blogs_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
 804      </form>
 805  
 806  <?php
 807  }
 808  
 809  /**
 810   * bp_blogs_visit_blog_button()
 811   *
 812   * Output button for visiting a blog in a loop
 813   *
 814   * @param array $args Custom button properties
 815   */
 816  function bp_blogs_visit_blog_button( $args = '' ) {
 817      echo bp_get_blogs_visit_blog_button( $args );
 818  }
 819      /**
 820       * bp_get_blogs_visit_blog_button()
 821       *
 822       * Return button for visiting a blog in a loop
 823       *
 824       * @param array $args Custom button properties
 825       * @return string
 826       */
 827  	function bp_get_blogs_visit_blog_button( $args = '' ) {
 828          $defaults = array(
 829              'id'                => 'visit_blog',
 830              'component'         => 'blogs',
 831              'must_be_logged_in' => false,
 832              'block_self'        => false,
 833              'wrapper_class'     => 'blog-button visit',
 834              'link_href'         => bp_get_blog_permalink(),
 835              'link_class'        => 'blog-button visit',
 836              'link_text'         => __( 'Visit Site', 'buddypress' ),
 837              'link_title'        => __( 'Visit Site', 'buddypress' ),
 838          );
 839  
 840          $button = wp_parse_args( $args, $defaults );
 841  
 842          // Filter and return the HTML button
 843          return bp_get_button( apply_filters( 'bp_get_blogs_visit_blog_button', $button ) );
 844      }


Generated: Sat May 18 03:58:58 2013 Hosted by follow the white rabbit.