Changeset 2168 for trunk/bp-blogs/bp-blogs-templatetags.php
- Timestamp:
- 12/14/2009 03:24:05 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/bp-blogs/bp-blogs-templatetags.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-blogs/bp-blogs-templatetags.php
r2088 r2168 1 1 <?php 2 2 3 /* Blog registration template tags */4 5 function bp_blog_signup_enabled() {6 $active_signup = get_site_option( 'registration' );7 8 if ( !$active_signup )9 $active_signup = 'all';10 11 $active_signup = apply_filters( 'wpmu_active_signup', $active_signup ); // return "all", "none", "blog" or "user"12 13 if ( 'none' == $active_signup || 'user' == $active_signup )14 return false;15 16 return true;17 }18 19 function bp_show_blog_signup_form($blogname = '', $blog_title = '', $errors = '') {20 global $current_user, $current_site;21 global $bp;22 23 require_once( ABSPATH . WPINC . '/registration.php' );24 25 if ( isset($_POST['submit']) ) {26 bp_blogs_validate_blog_signup();27 } else {28 if ( ! is_wp_error($errors) ) {29 $errors = new WP_Error();30 }31 32 // allow definition of default variables33 $filtered_results = apply_filters('signup_another_blog_init', array('blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors ));34 $blogname = $filtered_results['blogname'];35 $blog_title = $filtered_results['blog_title'];36 $errors = $filtered_results['errors'];37 38 if ( $errors->get_error_code() ) {39 echo "<p>" . __('There was a problem, please correct the form below and try again.', 'buddypress') . "</p>";40 }41 ?>42 <p><?php printf(__("By filling out the form below, you can <strong>add a blog to your account</strong>. There is no limit to the number of blogs you can have, so create to your heart's content, but blog responsibly.", 'buddypress'), $current_user->display_name) ?></p>43 44 <p><?php _e("If you’re not going to use a great blog domain, leave it for a new user. Now have at it!", 'buddypress') ?></p>45 46 <form class="standard-form" id="setupform" method="post" action="<?php echo $bp->loggedin_user->domain . $bp->blogs->slug . '/create-a-blog' ?>">47 48 <input type="hidden" name="stage" value="gimmeanotherblog" />49 <?php do_action( "signup_hidden_fields" ); ?>50 51 <?php bp_blogs_signup_blog($blogname, $blog_title, $errors); ?>52 <p>53 <input id="submit" type="submit" name="submit" class="submit" value="<?php _e('Create Blog »', 'buddypress') ?>" />54 </p>55 56 <?php wp_nonce_field( 'bp_blog_signup_form' ) ?>57 </form>58 <?php59 }60 }61 62 function bp_blogs_signup_blog( $blogname = '', $blog_title = '', $errors = '' ) {63 global $current_site;64 65 // Blog name66 if( 'no' == constant( "VHOST" ) )67 echo '<label for="blogname">' . __('Blog Name:', 'buddypress') . '</label>';68 else69 echo '<label for="blogname">' . __('Blog Domain:', 'buddypress') . '</label>';70 71 if ( $errmsg = $errors->get_error_message('blogname') ) { ?>72 <p class="error"><?php echo $errmsg ?></p>73 <?php }74 75 if( 'no' == constant( "VHOST" ) ) {76 echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span><input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /><br />';77 } else {78 echo '<input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /><span class="suffix_address">.' . $current_site->domain . $current_site->path . '</span><br />';79 }80 if ( !is_user_logged_in() ) {81 print '(<strong>' . __( 'Your address will be ' , 'buddypress');82 if( 'no' == constant( "VHOST" ) ) {83 print $current_site->domain . $current_site->path . __( 'blogname' , 'buddypress');84 } else {85 print __( 'domain.' , 'buddypress') . $current_site->domain . $current_site->path;86 }87 echo '.</strong> ' . __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed so choose carefully!)' , 'buddypress') . '</p>';88 }89 90 // Blog Title91 ?>92 <label for="blog_title"><?php _e('Blog Title:', 'buddypress') ?></label>93 <?php if ( $errmsg = $errors->get_error_message('blog_title') ) { ?>94 <p class="error"><?php echo $errmsg ?></p>95 <?php }96 echo '<input name="blog_title" type="text" id="blog_title" value="'.wp_specialchars($blog_title, 1).'" /></p>';97 ?>98 99 <p>100 <label for="blog_public_on"><?php _e('Privacy:', 'buddypress') ?></label>101 <?php _e('I would like my blog to appear in search engines like Google and Technorati, and in public listings around this site.', 'buddypress'); ?>102 103 104 <label class="checkbox" for="blog_public_on">105 <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 } ?> />106 <strong><?php _e( 'Yes' , 'buddypress'); ?></strong>107 </label>108 <label class="checkbox" for="blog_public_off">109 <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 } ?> />110 <strong><?php _e( 'No' , 'buddypress'); ?></strong>111 </label>112 </p>113 114 <?php115 do_action('signup_blogform', $errors);116 }117 118 function bp_blogs_validate_blog_signup() {119 global $wpdb, $current_user, $blogname, $blog_title, $errors, $domain, $path;120 121 if ( !check_admin_referer( 'bp_blog_signup_form' ) )122 return false;123 124 $current_user = wp_get_current_user();125 126 if( !is_user_logged_in() )127 die();128 129 $result = bp_blogs_validate_blog_form();130 extract($result);131 132 if ( $errors->get_error_code() ) {133 unset($_POST['submit']);134 bp_show_blog_signup_form( $blogname, $blog_title, $errors );135 return false;136 }137 138 $public = (int) $_POST['blog_public'];139 140 $meta = apply_filters( 'signup_create_blog_meta', array( 'lang_id' => 1, 'public' => $public ) ); // depreciated141 $meta = apply_filters( 'add_signup_meta', $meta );142 143 /* If this is a VHOST install, remove the username from the domain as we are setting this blog144 up inside a user domain, not the root domain. */145 146 wpmu_create_blog( $domain, $path, $blog_title, $current_user->id, $meta, $wpdb->siteid );147 bp_blogs_confirm_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta);148 return true;149 }150 151 function bp_blogs_validate_blog_form() {152 $user = '';153 if ( is_user_logged_in() )154 $user = wp_get_current_user();155 156 return wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title'], $user);157 }158 159 function bp_blogs_confirm_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = '' ) {160 ?>161 <p><?php _e('Congratulations! You have successfully registered a new blog.', 'buddypress') ?></p>162 <p>163 <?php printf(__('<a href="http://%1$s">http://%2$s</a> is your new blog. <a href="%3$s">Login</a> as "%4$s" using your existing password.', 'buddypress'), $domain.$path, $domain.$path, "http://" . $domain.$path . "wp-login.php", $user_name) ?>164 </p>165 <?php166 do_action('signup_finished');167 }168 169 function bp_create_blog_link() {170 global $bp;171 172 if ( bp_is_home() ) {173 echo apply_filters( 'bp_create_blog_link', '<a href="' . $bp->loggedin_user->domain . $bp->blogs->slug . '/create-a-blog">' . __('Create a Blog', 'buddypress') . '</a>' );174 }175 }176 177 function bp_blogs_blog_tabs() {178 global $bp, $groups_template;179 180 // Don't show these tabs on a user's own profile181 if ( bp_is_home() )182 return false;183 184 $current_tab = $bp->current_action185 ?>186 <ul class="content-header-nav">187 <li<?php if ( 'my-blogs' == $current_tab || empty( $current_tab ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . $bp->blogs->slug ?>/my-blogs"><?php printf( __( "%s's Blogs", 'buddypress' ), $bp->displayed_user->fullname ) ?></a></li>188 <li<?php if ( 'recent-posts' == $current_tab ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . $bp->blogs->slug ?>/recent-posts"><?php printf( __( "%s's Recent Posts", 'buddypress' ), $bp->displayed_user->fullname ) ?></a></li>189 <li<?php if ( 'recent-comments' == $current_tab ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . $bp->blogs->slug ?>/recent-comments"><?php printf( __( "%s's Recent Comments", 'buddypress' ), $bp->displayed_user->fullname ) ?></a></li>190 </ul>191 <?php192 do_action( 'bp_blogs_blog_tabs', $current_tab );193 }194 195 3 /********************************************************************** 196 * User Blog listing template class4 * Blog listing template class. 197 5 */ 198 6 199 class BP_Blogs_ User_Blogs_Template {7 class BP_Blogs_Template { 200 8 var $current_blog = -1; 201 9 var $blog_count; … … 210 18 var $total_blog_count; 211 19 212 function bp_blogs_ user_blogs_template( $user_id, $per_page, $max) {20 function bp_blogs_template( $type, $page, $per_page, $max, $user_id, $search_terms ) { 213 21 global $bp; 214 22 215 if ( !$user_id ) 216 $user_id = $bp->displayed_user->id; 217 218 $this->pag_page = isset( $_GET['fpage'] ) ? intval( $_GET['fpage'] ) : 1; 219 $this->pag_num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : $per_page; 220 221 if ( !$this->blogs = wp_cache_get( 'bp_blogs_for_user_' . $user_id, 'bp' ) ) { 222 $this->blogs = bp_blogs_get_blogs_for_user( $user_id ); 223 wp_cache_set( 'bp_blogs_for_user_' . $user_id, $this->blogs, 'bp' ); 224 } 225 226 if ( !$max || $max >= (int)$this->blogs['count'] ) 227 $this->total_blog_count = (int)$this->blogs['count']; 23 $this->pag_page = isset( $_REQUEST['bpage'] ) ? intval( $_REQUEST['bpage'] ) : $page; 24 $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page; 25 26 if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] ) { 27 $this->blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page ); 28 } else { 29 switch ( $type ) { 30 case 'random': 31 $this->blogs = BP_Blogs_Blog::get_random( $this->pag_num, $this->pag_page, $user_id, $search_terms ); 32 break; 33 34 case 'alphabetical': 35 $this->blogs = BP_Blogs_Blog::get_alphabetical( $this->pag_num, $this->pag_page, $user_id, $search_terms ); 36 break; 37 38 case 'newest': 39 $this->blogs = BP_Blogs_Blog::get_newest( $this->pag_num, $this->pag_page, $user_id, $search_terms ); 40 break; 41 42 case 'active': default: 43 $this->blogs = BP_Blogs_Blog::get_active( $this->pag_num, $this->pag_page, $user_id, $search_terms ); 44 break; 45 } 46 } 47 48 if ( !$max || $max >= (int)$this->blogs['total'] ) 49 $this->total_blog_count = (int)$this->blogs['total']; 228 50 else 229 51 $this->total_blog_count = (int)$max; 230 52 231 $this->blogs = array_slice( (array)$this->blogs['blogs'], intval( ( $this->pag_page - 1 ) * $this->pag_num), intval( $this->pag_num ) );53 $this->blogs = $this->blogs['blogs']; 232 54 233 55 if ( $max ) { … … 241 63 242 64 $this->pag_links = paginate_links( array( 243 'base' => add_query_arg( ' fpage', '%#%' ),65 'base' => add_query_arg( 'bpage', '%#%' ), 244 66 'format' => '', 245 'total' => ceil( $this->total_blog_count / $this->pag_num),246 'current' => $this->pag_page,247 'prev_text' => '&la quo;',248 'next_text' => '&ra quo;',67 'total' => ceil( (int) $this->total_blog_count / (int) $this->pag_num ), 68 'current' => (int) $this->pag_page, 69 'prev_text' => '←', 70 'next_text' => '→', 249 71 'mid_size' => 1 250 72 )); … … 272 94 } 273 95 274 function user_blogs() {96 function blogs() { 275 97 if ( $this->current_blog + 1 < $this->blog_count ) { 276 98 return true; … … 289 111 290 112 $this->in_the_loop = true; 291 $ blog = $this->next_blog();113 $this->blog = $this->next_blog(); 292 114 293 115 if ( 0 == $this->current_blog ) // loop has just started … … 296 118 } 297 119 120 function bp_rewind_blogs() { 121 global $blogs_template; 122 123 $blogs_template->rewind_blogs(); 124 } 125 298 126 function bp_has_blogs( $args = '' ) { 299 127 global $blogs_template; 300 128 301 129 $defaults = array( 302 'user_id' => false, 303 'per_page' => 10, 304 'max' => false 130 'type' => 'active', 131 'page' => 1, 132 'per_page' => 20, 133 'max' => false, 134 135 'user_id' => false, // Pass a user_id to limit to only blogs this user has higher than subscriber access to 136 'search_terms' => false // Pass search terms to filter on the blog title or description. 305 137 ); 306 138 … … 308 140 extract( $r, EXTR_SKIP ); 309 141 310 $blogs_template = new BP_Blogs_User_Blogs_Template( $user_id, $per_page, $max ); 311 return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), &$blogs_template ); 142 // type: active ( default ) | random | newest | alphabetical 143 144 if ( !empty( $_REQUEST['s'] ) ) 145 $search_terms = $_REQUEST['s']; 146 147 if ( $max ) { 148 if ( $per_page > $max ) 149 $per_page = $max; 150 } 151 152 $blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms ); 153 154 return $blogs_template->has_blogs(); 312 155 } 313 156 314 157 function bp_blogs() { 315 158 global $blogs_template; 316 return $blogs_template->user_blogs(); 159 160 return $blogs_template->blogs(); 317 161 } 318 162 319 163 function bp_the_blog() { 320 164 global $blogs_template; 165 321 166 return $blogs_template->the_blog(); 322 167 } … … 341 186 } 342 187 343 function bp_blog_title() { 344 echo bp_get_blog_title(); 345 } 346 function bp_get_blog_title() { 188 function bp_blog_avatar() { 189 echo bp_get_blog_avatar(); 190 } 191 function bp_get_blog_avatar() { 192 global $blogs_template, $bp; 193 194 /*** 195 * In future BuddyPress versions you will be able to set the avatar for a blog. 196 * Right now you can use a filter with the ID of the blog to change it if you wish. 197 */ 198 return apply_filters( 'bp_get_blog_avatar_' . $blogs_template->blog->blog_id, '<img src="' . apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' ) . md5( $blogs_template->blog->blog_id . '.blogs@' . $bp->root_domain ) . '?d=identicon&s=150" class="avatar blog-avatar" alt="' . __( 'Blog Avatar', 'buddypress' ) . '" />', $blogs_template->blog->blog_id ); 199 } 200 201 function bp_blog_avatar_thumb() { 202 echo bp_get_blog_avatar_thumb(); 203 } 204 function bp_get_blog_avatar_thumb() { 205 global $blogs_template, $bp; 206 207 return apply_filters( 'bp_get_blog_avatar_thumb_' . $blogs_template->blog->blog_id, '<img src="' . apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' ) . md5( $blogs_template->blog->blog_id . '.blogs@' . $bp->root_domain ) . '?d=identicon&s=50" class="avatar blog-avatar thumb" alt="' . __( 'Blog Avatar', 'buddypress' ) . '" />', $blogs_template->blog->blog_id ); 208 } 209 210 function bp_blog_avatar_mini() { 211 echo bp_get_blog_avatar_mini(); 212 } 213 function bp_get_blog_avatar_mini() { 214 global $blogs_template, $bp; 215 216 return apply_filters( 'bp_get_blog_avatar_mini_' . $blogs_template->blog->blog_id, '<img src="' . apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' ) . md5( $blogs_template->blog->blog_id . '.blogs@' . $bp->root_domain ) . '?d=identicon&s=25" class="avatar blog-avatar mini" alt="' . __( 'Blog Avatar', 'buddypress' ) . '" />', $blogs_template->blog->blog_id ); 217 } 218 219 function bp_blog_permalink() { 220 echo bp_get_blog_permalink(); 221 } 222 function bp_get_blog_permalink() { 347 223 global $blogs_template; 348 224 349 return apply_filters( 'bp_get_blog_title', $blogs_template->blog->name ); 225 return apply_filters( 'bp_get_blog_permalink', get_blog_option( $blogs_template->blog->blog_id, 'siteurl' ) ); 226 } 227 228 function bp_blog_name() { 229 echo bp_get_blog_name(); 230 } 231 function bp_get_blog_name() { 232 global $blogs_template; 233 234 return apply_filters( 'bp_get_blog_name', get_blog_option( $blogs_template->blog->blog_id, 'blogname' ) ); 350 235 } 351 236 352 237 function bp_blog_description() { 353 echo bp_get_blog_description();238 echo apply_filters( 'bp_blog_description', bp_get_blog_description() ); 354 239 } 355 240 function bp_get_blog_description() { 356 241 global $blogs_template; 357 242 358 return apply_filters( 'bp_get_blog_description', $blogs_template->blog->description);359 } 360 361 function bp_blog_ permalink() {362 echo bp_get_blog_ permalink();363 } 364 function bp_get_blog_ permalink() {243 return apply_filters( 'bp_get_blog_description', get_blog_option( $blogs_template->blog->blog_id, 'blogdescription' ) ); 244 } 245 246 function bp_blog_last_active() { 247 echo bp_get_blog_last_active(); 248 } 249 function bp_get_blog_last_active() { 365 250 global $blogs_template; 366 251 367 return apply_filters( 'bp_get_blog_permalink', $blogs_template->blog->siteurl ); 368 } 369 252 return apply_filters( 'bp_blog_last_active', bp_core_get_last_activity( bp_blogs_get_blogmeta( $blogs_template->blog->blog_id, 'last_activity' ), __( 'active %s ago', 'buddypress' ) ) ); 253 } 254 255 function bp_blog_latest_post() { 256 echo bp_get_blog_latest_post(); 257 } 258 function bp_get_blog_latest_post() { 259 global $blogs_template; 260 261 if ( $post = bp_blogs_get_latest_posts( $blogs_template->blog->blog_id, 1 ) ) { 262 return apply_filters( 'bp_get_blog_latest_post', sprintf( __( 'Latest Post: %s', 'buddypress' ), '<a href="' . bp_post_get_permalink( $post[0], $blogs_template->blog->blog_id ) . '">' . apply_filters( 'the_title', $post[0]->post_title ) . '</a>' ) ); 263 } 264 } 265 266 function bp_blog_hidden_fields() { 267 if ( isset( $_REQUEST['s'] ) ) { 268 echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['s'] ). '" name="search_terms" />'; 269 } 270 271 if ( isset( $_REQUEST['letter'] ) ) { 272 echo '<input type="hidden" id="selected_letter" value="' . attribute_escape( $_REQUEST['letter'] ) . '" name="selected_letter" />'; 273 } 274 275 if ( isset( $_REQUEST['blogs_search'] ) ) { 276 echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['blogs_search'] ) . '" name="search_terms" />'; 277 } 278 } 279 280 /*** 281 * Technically the template loops for blog posts and comments are deprecated. 282 * Instead you should be using the activity stream template loop and filtering 283 * on blog posts and blog comments either with or without a user_id. 284 * 285 * They remain here because they are used in the bp-sn-parent theme, but they 286 * are running on thin ice. 287 */ 370 288 371 289 /********************************************************************** … … 1051 969 } 1052 970 1053 /********************************************************************** 1054 * Site Wide Blog listing template class 1055 */ 1056 1057 class BP_Blogs_Site_Blogs_Template { 1058 var $current_blog = -1; 1059 var $blog_count; 1060 var $blogs; 1061 var $blog; 1062 1063 var $in_the_loop; 1064 1065 var $pag_page; 1066 var $pag_num; 1067 var $pag_links; 1068 var $total_blog_count; 1069 1070 function bp_blogs_site_blogs_template( $type, $per_page, $max ) { 1071 global $bp; 1072 1073 $this->pag_page = isset( $_REQUEST['bpage'] ) ? intval( $_REQUEST['bpage'] ) : 1; 1074 $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page; 1075 1076 if ( isset( $_REQUEST['s'] ) && '' != $_REQUEST['s'] && $type != 'random' ) { 1077 $this->blogs = BP_Blogs_Blog::search_blogs( $_REQUEST['s'], $this->pag_num, $this->pag_page ); 1078 } else if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] ) { 1079 $this->blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page ); 971 972 /* Blog registration template tags */ 973 974 function bp_blog_signup_enabled() { 975 $active_signup = get_site_option( 'registration' ); 976 977 if ( !$active_signup ) 978 $active_signup = 'all'; 979 980 $active_signup = apply_filters( 'wpmu_active_signup', $active_signup ); // return "all", "none", "blog" or "user" 981 982 if ( 'none' == $active_signup || 'user' == $active_signup ) 983 return false; 984 985 return true; 986 } 987 988 function bp_show_blog_signup_form($blogname = '', $blog_title = '', $errors = '') { 989 global $current_user, $current_site; 990 global $bp; 991 992 require_once( ABSPATH . WPINC . '/registration.php' ); 993 994 if ( isset($_POST['submit']) ) { 995 bp_blogs_validate_blog_signup(); 996 } else { 997 if ( ! is_wp_error($errors) ) { 998 $errors = new WP_Error(); 999 } 1000 1001 // allow definition of default variables 1002 $filtered_results = apply_filters('signup_another_blog_init', array('blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors )); 1003 $blogname = $filtered_results['blogname']; 1004 $blog_title = $filtered_results['blog_title']; 1005 $errors = $filtered_results['errors']; 1006 1007 if ( $errors->get_error_code() ) { 1008 echo "<p>" . __('There was a problem, please correct the form below and try again.', 'buddypress') . "</p>"; 1009 } 1010 ?> 1011 <p><?php printf(__("By filling out the form below, you can <strong>add a blog to your account</strong>. There is no limit to the number of blogs you can have, so create to your heart's content, but blog responsibly.", 'buddypress'), $current_user->display_name) ?></p> 1012 1013 <p><?php _e("If you’re not going to use a great blog domain, leave it for a new user. Now have at it!", 'buddypress') ?></p> 1014 1015 <form class="standard-form" id="setupform" method="post" action=""> 1016 1017 <input type="hidden" name="stage" value="gimmeanotherblog" /> 1018 <?php do_action( "signup_hidden_fields" ); ?> 1019 1020 <?php bp_blogs_signup_blog($blogname, $blog_title, $errors); ?> 1021 <p> 1022 <input id="submit" type="submit" name="submit" class="submit" value="<?php _e('Create Blog »', 'buddypress') ?>" /> 1023 </p> 1024 1025 <?php wp_nonce_field( 'bp_blog_signup_form' ) ?> 1026 </form> 1027 <?php 1028 } 1029 } 1030 1031 function bp_blogs_signup_blog( $blogname = '', $blog_title = '', $errors = '' ) { 1032 global $current_site; 1033 1034 // Blog name 1035 if( 'no' == constant( "VHOST" ) ) 1036 echo '<label for="blogname">' . __('Blog Name:', 'buddypress') . '</label>'; 1037 else 1038 echo '<label for="blogname">' . __('Blog Domain:', 'buddypress') . '</label>'; 1039 1040 if ( $errmsg = $errors->get_error_message('blogname') ) { ?> 1041 <p class="error"><?php echo $errmsg ?></p> 1042 <?php } 1043 1044 if( 'no' == constant( "VHOST" ) ) { 1045 echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span> <input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /><br />'; 1046 } else { 1047 echo '<input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /> <span class="suffix_address">.' . $current_site->domain . $current_site->path . '</span><br />'; 1048 } 1049 if ( !is_user_logged_in() ) { 1050 print '(<strong>' . __( 'Your address will be ' , 'buddypress'); 1051 if( 'no' == constant( "VHOST" ) ) { 1052 print $current_site->domain . $current_site->path . __( 'blogname' , 'buddypress'); 1080 1053 } else { 1081 switch ( $type ) { 1082 case 'random': 1083 $this->blogs = BP_Blogs_Blog::get_random( $this->pag_num, $this->pag_page ); 1084 break; 1085 1086 case 'newest': 1087 $this->blogs = BP_Blogs_Blog::get_newest( $this->pag_num, $this->pag_page ); 1088 break; 1089 1090 case 'active': default: 1091 $this->blogs = BP_Blogs_Blog::get_active( $this->pag_num, $this->pag_page ); 1092 break; 1093 } 1094 } 1095 1096 if ( !$max || $max >= (int)$this->blogs['total'] ) 1097 $this->total_blog_count = (int)$this->blogs['total']; 1098 else 1099 $this->total_blog_count = (int)$max; 1100 1101 $this->blogs = $this->blogs['blogs']; 1102 1103 if ( $max ) { 1104 if ( $max >= count($this->blogs) ) 1105 $this->blog_count = count($this->blogs); 1106 else 1107 $this->blog_count = (int)$max; 1108 } else { 1109 $this->blog_count = count($this->blogs); 1110 } 1111 1112 $this->pag_links = paginate_links( array( 1113 'base' => add_query_arg( 'bpage', '%#%' ), 1114 'format' => '', 1115 'total' => ceil( (int) $this->total_blog_count / (int) $this->pag_num ), 1116 'current' => (int) $this->pag_page, 1117 'prev_text' => '«', 1118 'next_text' => '»', 1119 'mid_size' => 1 1120 )); 1121 } 1122 1123 function has_blogs() { 1124 if ( $this->blog_count ) 1125 return true; 1126 1054 print __( 'domain.' , 'buddypress') . $current_site->domain . $current_site->path; 1055 } 1056 echo '.</strong> ' . __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed so choose carefully!)' , 'buddypress') . '</p>'; 1057 } 1058 1059 // Blog Title 1060 ?> 1061 <label for="blog_title"><?php _e('Blog Title:', 'buddypress') ?></label> 1062 <?php if ( $errmsg = $errors->get_error_message('blog_title') ) { ?> 1063 <p class="error"><?php echo $errmsg ?></p> 1064 <?php } 1065 echo '<input name="blog_title" type="text" id="blog_title" value="'.wp_specialchars($blog_title, 1).'" /></p>'; 1066 ?> 1067 1068 <p> 1069 <label for="blog_public_on"><?php _e('Privacy:', 'buddypress') ?></label> 1070 <?php _e('I would like my blog to appear in search engines like Google and Technorati, and in public listings around this site.', 'buddypress'); ?> 1071 1072 1073 <label class="checkbox" for="blog_public_on"> 1074 <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 } ?> /> 1075 <strong><?php _e( 'Yes' , 'buddypress'); ?></strong> 1076 </label> 1077 <label class="checkbox" for="blog_public_off"> 1078 <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 } ?> /> 1079 <strong><?php _e( 'No' , 'buddypress'); ?></strong> 1080 </label> 1081 </p> 1082 1083 <?php 1084 do_action('signup_blogform', $errors); 1085 } 1086 1087 function bp_blogs_validate_blog_signup() { 1088 global $wpdb, $current_user, $blogname, $blog_title, $errors, $domain, $path; 1089 1090 if ( !check_admin_referer( 'bp_blog_signup_form' ) ) 1127 1091 return false; 1128 } 1129 1130 function next_blog() { 1131 $this->current_blog++; 1132 $this->blog = $this->blogs[$this->current_blog]; 1133 1134 return $this->blog; 1135 } 1136 1137 function rewind_blogs() { 1138 $this->current_blog = -1; 1139 if ( $this->blog_count > 0 ) { 1140 $this->blog = $this->blogs[0]; 1141 } 1142 } 1143 1144 function blogs() { 1145 if ( $this->current_blog + 1 < $this->blog_count ) { 1146 return true; 1147 } elseif ( $this->current_blog + 1 == $this->blog_count ) { 1148 do_action('loop_end'); 1149 // Do some cleaning up after the loop 1150 $this->rewind_blogs(); 1151 } 1152 1153 $this->in_the_loop = false; 1092 1093 $current_user = wp_get_current_user(); 1094 1095 if( !is_user_logged_in() ) 1096 die(); 1097 1098 $result = bp_blogs_validate_blog_form(); 1099 extract($result); 1100 1101 if ( $errors->get_error_code() ) { 1102 unset($_POST['submit']); 1103 bp_show_blog_signup_form( $blogname, $blog_title, $errors ); 1154 1104 return false; 1155 1105 } 1156 1106 1157 function the_blog() { 1158 global $blog; 1159 1160 $this->in_the_loop = true; 1161 $this->blog = $this->next_blog(); 1162 1163 if ( 0 == $this->current_blog ) // loop has just started 1164 do_action('loop_start'); 1165 } 1166 } 1167 1168 function bp_rewind_site_blogs() { 1169 global $site_blogs_template; 1170 1171 $site_blogs_template->rewind_blogs(); 1172 } 1173 1174 function bp_has_site_blogs( $args = '' ) { 1175 global $site_blogs_template; 1176 1177 $defaults = array( 1178 'type' => 'active', 1179 'per_page' => 10, 1180 'max' => false 1181 ); 1182 1183 $r = wp_parse_args( $args, $defaults ); 1184 extract( $r, EXTR_SKIP ); 1185 1186 // type: active ( default ) | random | newest | popular 1187 1188 if ( $max ) { 1189 if ( $per_page > $max ) 1190 $per_page = $max; 1191 } 1192 1193 $site_blogs_template = new BP_Blogs_Site_Blogs_Template( $type, $per_page, $max ); 1194 1195 return $site_blogs_template->has_blogs(); 1196 } 1197 1198 function bp_site_blogs() { 1199 global $site_blogs_template; 1200 1201 return $site_blogs_template->blogs(); 1202 } 1203 1204 function bp_the_site_blog() { 1205 global $site_blogs_template; 1206 1207 return $site_blogs_template->the_blog(); 1208 } 1209 1210 function bp_site_blogs_pagination_count() { 1211 global $bp, $site_blogs_template; 1212 1213 $from_num = intval( ( $site_blogs_template->pag_page - 1 ) * $site_blogs_template->pag_num ) + 1; 1214 $to_num = ( $from_num + ( $site_blogs_template->pag_num - 1 ) > $site_blogs_template->total_blog_count ) ? $site_blogs_template->total_blog_count : $from_num + ( $site_blogs_template->pag_num - 1 ) ; 1215 1216 echo sprintf( __( 'Viewing blog %d to %d (of %d blogs)', 'buddypress' ), $from_num, $to_num, $site_blogs_template->total_blog_count ); ?> 1217 <span class="ajax-loader"></span><?php 1218 } 1219 1220 function bp_site_blogs_pagination_links() { 1221 echo bp_get_site_blogs_pagination_links(); 1222 } 1223 function bp_get_site_blogs_pagination_links() { 1224 global $site_blogs_template; 1225 1226 return apply_filters( 'bp_get_site_blogs_pagination_links', $site_blogs_template->pag_links ); 1227 } 1228 1229 function bp_the_site_blog_avatar() { 1230 echo bp_get_the_site_blog_avatar(); 1231 } 1232 function bp_get_the_site_blog_avatar() { 1233 global $site_blogs_template, $bp; 1234 1235 /*** 1236 * In future BuddyPress versions you will be able to set the avatar for a blog. 1237 * Right now you can use a filter with the ID of the blog to change it if you wish. 1238 */ 1239 return apply_filters( 'bp_get_blogs_blog_avatar_' . $site_blogs_template->blog->blog_id, '<img src="' . apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' ) . md5( $site_blogs_template->blog->blog_id . '.blogs@' . $bp->root_domain ) . '?d=identicon&s=150" class="avatar blog-avatar" alt="' . __( 'Blog Avatar', 'buddypress' ) . '" />', $site_blogs_template->blog->blog_id ); 1240 } 1241 1242 function bp_the_site_blog_avatar_thumb() { 1243 echo bp_get_the_site_blog_avatar_thumb(); 1244 } 1245 function bp_get_the_site_blog_avatar_thumb() { 1246 global $site_blogs_template, $bp; 1247 1248 return apply_filters( 'bp_get_blogs_blog_avatar_thumb_' . $site_blogs_template->blog->blog_id, '<img src="' . apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' ) . md5( $site_blogs_template->blog->blog_id . '.blogs@' . $bp->root_domain ) . '?d=identicon&s=50" class="avatar blog-avatar thumb" alt="' . __( 'Blog Avatar', 'buddypress' ) . '" />', $site_blogs_template->blog->blog_id ); 1249 } 1250 1251 function bp_the_site_blog_avatar_mini() { 1252 echo bp_get_the_site_blog_avatar_mini(); 1253 } 1254 function bp_get_the_site_blog_avatar_mini() { 1255 global $site_blogs_template, $bp; 1256 1257 return apply_filters( 'bp_get_blogs_blog_avatar_mini_' . $site_blogs_template->blog->blog_id, '<img src="' . apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' ) . md5( $site_blogs_template->blog->blog_id . '.blogs@' . $bp->root_domain ) . '?d=identicon&s=25" class="avatar blog-avatar mini" alt="' . __( 'Blog Avatar', 'buddypress' ) . '" />', $site_blogs_template->blog->blog_id ); 1258 } 1259 1260 function bp_the_site_blog_link() { 1261 echo bp_get_the_site_blog_link(); 1262 } 1263 function bp_get_the_site_blog_link() { 1264 global $site_blogs_template; 1265 1266 return apply_filters( 'bp_get_the_site_blog_link', get_blog_option( $site_blogs_template->blog->blog_id, 'siteurl' ) ); 1267 } 1268 1269 function bp_the_site_blog_name() { 1270 echo bp_get_the_site_blog_name(); 1271 } 1272 function bp_get_the_site_blog_name() { 1273 global $site_blogs_template; 1274 1275 return apply_filters( 'bp_get_the_site_blog_name', get_blog_option( $site_blogs_template->blog->blog_id, 'blogname' ) ); 1276 } 1277 1278 function bp_the_site_blog_description() { 1279 echo apply_filters( 'bp_the_site_blog_description', bp_get_the_site_blog_description() ); 1280 } 1281 function bp_get_the_site_blog_description() { 1282 global $site_blogs_template; 1283 1284 return apply_filters( 'bp_get_the_site_blog_description', get_blog_option( $site_blogs_template->blog->blog_id, 'blogdescription' ) ); 1285 } 1286 1287 function bp_the_site_blog_last_active() { 1288 echo bp_get_the_site_blog_last_active(); 1289 } 1290 function bp_get_the_site_blog_last_active() { 1291 global $site_blogs_template; 1292 1293 return apply_filters( 'bp_the_site_blog_last_active', bp_core_get_last_activity( bp_blogs_get_blogmeta( $site_blogs_template->blog->blog_id, 'last_activity' ), __( 'active %s ago', 'buddypress' ) ) ); 1294 } 1295 1296 function bp_the_site_blog_latest_post() { 1297 echo bp_get_the_site_blog_latest_post(); 1298 } 1299 function bp_get_the_site_blog_latest_post() { 1300 global $site_blogs_template; 1301 1302 if ( $post = bp_blogs_get_latest_posts( $site_blogs_template->blog->blog_id, 1 ) ) { 1303 return apply_filters( 'bp_get_the_site_blog_latest_post', sprintf( __( 'Latest Post: %s', 'buddypress' ), '<a href="' . bp_post_get_permalink( $post[0], $site_blogs_template->blog->blog_id ) . '">' . apply_filters( 'the_title', $post[0]->post_title ) . '</a>' ) ); 1304 } 1305 } 1306 1307 function bp_the_site_blog_hidden_fields() { 1308 if ( isset( $_REQUEST['s'] ) ) { 1309 echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['s'] ). '" name="search_terms" />'; 1310 } 1311 1312 if ( isset( $_REQUEST['letter'] ) ) { 1313 echo '<input type="hidden" id="selected_letter" value="' . attribute_escape( $_REQUEST['letter'] ) . '" name="selected_letter" />'; 1314 } 1315 1316 if ( isset( $_REQUEST['blogs_search'] ) ) { 1317 echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['blogs_search'] ) . '" name="search_terms" />'; 1318 } 1107 $public = (int) $_POST['blog_public']; 1108 1109 $meta = apply_filters( 'signup_create_blog_meta', array( 'lang_id' => 1, 'public' => $public ) ); // depreciated 1110 $meta = apply_filters( 'add_signup_meta', $meta ); 1111 1112 /* If this is a VHOST install, remove the username from the domain as we are setting this blog 1113 up inside a user domain, not the root domain. */ 1114 1115 wpmu_create_blog( $domain, $path, $blog_title, $current_user->id, $meta, $wpdb->siteid ); 1116 bp_blogs_confirm_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta); 1117 return true; 1118 } 1119 1120 function bp_blogs_validate_blog_form() { 1121 $user = ''; 1122 if ( is_user_logged_in() ) 1123 $user = wp_get_current_user(); 1124 1125 return wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title'], $user); 1126 } 1127 1128 function bp_blogs_confirm_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = '' ) { 1129 ?> 1130 <p><?php _e('Congratulations! You have successfully registered a new blog.', 'buddypress') ?></p> 1131 <p> 1132 <?php printf(__('<a href="http://%1$s">http://%2$s</a> is your new blog. <a href="%3$s">Login</a> as "%4$s" using your existing password.', 'buddypress'), $domain.$path, $domain.$path, "http://" . $domain.$path . "wp-login.php", $user_name) ?> 1133 </p> 1134 <?php 1135 do_action('signup_finished'); 1136 } 1137 1138 function bp_create_blog_link() { 1139 global $bp; 1140 1141 if ( bp_is_home() ) { 1142 echo apply_filters( 'bp_create_blog_link', '<a href="' . $bp->loggedin_user->domain . $bp->blogs->slug . '/create-a-blog">' . __('Create a Blog', 'buddypress') . '</a>' ); 1143 } 1144 } 1145 1146 function bp_blogs_blog_tabs() { 1147 global $bp, $groups_template; 1148 1149 // Don't show these tabs on a user's own profile 1150 if ( bp_is_home() ) 1151 return false; 1152 1153 $current_tab = $bp->current_action 1154 ?> 1155 <ul class="content-header-nav"> 1156 <li<?php if ( 'my-blogs' == $current_tab || empty( $current_tab ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . $bp->blogs->slug ?>/my-blogs"><?php printf( __( "%s's Blogs", 'buddypress' ), $bp->displayed_user->fullname ) ?></a></li> 1157 <li<?php if ( 'recent-posts' == $current_tab ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . $bp->blogs->slug ?>/recent-posts"><?php printf( __( "%s's Recent Posts", 'buddypress' ), $bp->displayed_user->fullname ) ?></a></li> 1158 <li<?php if ( 'recent-comments' == $current_tab ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . $bp->blogs->slug ?>/recent-comments"><?php printf( __( "%s's Recent Comments", 'buddypress' ), $bp->displayed_user->fullname ) ?></a></li> 1159 </ul> 1160 <?php 1161 do_action( 'bp_blogs_blog_tabs', $current_tab ); 1319 1162 } 1320 1163 … … 1328 1171 } 1329 1172 1173 function bp_total_blogs_for_user( $user_id = false ) { 1174 global $bp; 1175 1176 if ( !$user_id ) 1177 $user_id = $bp->displayed_user->id; 1178 1179 return apply_filters( 'bp_total_blogs_for_user', bp_blogs_total_blogs_for_user( $user_id ) ); 1180 } 1181 1182 function bp_get_total_blog_count() { 1183 return apply_filters( 'bp_get_total_blog_count', bp_blogs_total_blogs() ); 1184 } 1330 1185 1331 1186 ?>
Note: See TracChangeset
for help on using the changeset viewer.