Ticket #2242: 2242.diff
File 2242.diff, 20.9 KB (added by , 11 years ago) |
---|
-
bp-themes/bp-default/groups/groups-loop.php
37 37 38 38 <?php while ( bp_groups() ) : bp_the_group(); ?> 39 39 40 <li >40 <li <?php bp_groups_group_class();?>> 41 41 <div class="item-avatar"> 42 42 <a href="<?php bp_group_permalink(); ?>"><?php bp_group_avatar( 'type=thumb&width=50&height=50' ); ?></a> 43 43 </div> -
bp-themes/bp-default/_inc/css/default.css
2208 2208 right: 0; 2209 2209 text-align: right; 2210 2210 } 2211 ul.item-list li.sticky { 2212 background:#fff9db; 2213 padding:5px; 2214 } 2215 ul.item-list li.sticky div.action{ 2216 right:5px; 2217 } 2211 2218 ul.item-list li div.meta { 2212 2219 color: #888; 2213 2220 font-size: 11px; … … 2434 2441 .field-visibility-settings legend, 2435 2442 .field-visibility-settings-toggle { 2436 2443 font-style: italic; 2437 } 2438 No newline at end of file 2444 } -
bp-core/admin/bp-core-settings.php
197 197 <?php 198 198 } 199 199 200 /** 201 * Allow Administrators to stick a group to front of Groups Directory 202 * 203 * 204 * @uses checked() To display the checked attribute 205 */ 206 function bp_admin_setting_callback_group_sticky() { 207 ?> 208 209 <input id="bp_allow_sticky_group" name="bp_allow_sticky_group" type="checkbox" value="1" <?php checked( bp_allow_sticky_group( false ) ); ?> /> 210 <label for="bp_allow_sticky_group"><?php _e( 'Enable sticky groups in Groups Directory', 'buddypress' ); ?></label> 211 <p class="description"><?php _e( 'Administrators can set groups as sticky, regardless of this setting.', 'buddypress' ); ?></p> 212 213 <?php 214 } 215 216 /** 217 * Sanitization for bp_allow_sticky_group setting 218 * 219 * In the UI, a checkbox asks whether you'd like to *enable* sticky groups. For 220 * legacy reasons, the option that we store is 1 if these comments are *disabled*. So we use this 221 * function to flip the boolean before saving the intval. 222 */ 223 function bp_admin_sanitize_callback_sticky_group( $value = false ) { 224 return $value ? 0 : 1; 225 } 226 200 227 /** Forums Section ************************************************************/ 201 228 202 229 /** … … 302 329 'bp_disable_blogforum_comments', 303 330 'bp-disable-profile-sync', 304 331 'bp_restrict_group_creation', 332 'bp_allow_sticky_group', 305 333 'hide-loggedout-adminbar', 306 334 ); 307 335 -
bp-core/bp-core-admin.php
275 275 // Add the main section 276 276 add_settings_section( 'bp_groups', __( 'Groups Settings', 'buddypress' ), 'bp_admin_setting_callback_groups_section', 'buddypress' ); 277 277 278 // Allow subscriptions setting278 // Allow group creation for non admin 279 279 add_settings_field( 'bp_restrict_group_creation', __( 'Group Creation', 'buddypress' ), 'bp_admin_setting_callback_group_creation', 'buddypress', 'bp_groups' ); 280 280 register_setting ( 'buddypress', 'bp_restrict_group_creation', 'intval' ); 281 282 // Allow admin to stick groups to front of Groups Directory 283 add_settings_field( 'bp_allow_sticky_group', __( 'Sticky Groups', 'buddypress' ), 'bp_admin_setting_callback_group_sticky', 'buddypress', 'bp_groups' ); 284 register_setting ( 'buddypress', 'bp_allow_sticky_group', 'bp_admin_sanitize_callback_sticky_group' ); 281 285 } 282 286 283 287 /** Forums ************************************************************/ -
bp-core/bp-core-options.php
458 458 } 459 459 460 460 /** 461 * can we stick groups? 462 * 463 * 464 * @param bool $default Optional. Default value true 465 * 466 * @todo Move into groups component 467 * @uses bp_get_option() To get the group creation 468 * @return bool Allow sticky groups? 469 */ 470 function bp_allow_sticky_group( $default = false ) { 471 return (bool) apply_filters( 'bp_allow_sticky_group', (bool) bp_get_option( 'bp_allow_sticky_group', $default ) ); 472 } 473 474 /** 461 475 * Have we migrated to using the WordPress Toolbar? 462 476 * 463 477 * @since BuddyPress (1.6) -
bp-templates/bp-legacy/buddypress/groups/groups-loop.php
37 37 38 38 <?php while ( bp_groups() ) : bp_the_group(); ?> 39 39 40 <li >40 <li <?php bp_groups_group_class();?>> 41 41 <div class="item-avatar"> 42 42 <a href="<?php bp_group_permalink(); ?>"><?php bp_group_avatar( 'type=thumb&width=50&height=50' ); ?></a> 43 43 </div> -
bp-templates/bp-legacy/css/buddypress.css
1173 1173 right: 0; 1174 1174 text-align: right; 1175 1175 } 1176 1177 #buddypress ul.item-list li.sticky { 1178 background:#fff9db; 1179 padding:5px; 1180 } 1181 1182 #buddypress ul.item-list li.sticky div.action{ 1183 right:5px; 1184 } 1176 1185 #buddypress ul.item-list li div.meta { 1177 1186 color: #888; 1178 1187 font-size: 80%; -
bp-groups/admin/css/admin.css
55 55 white-space: nowrap; 56 56 padding-left: 15px; 57 57 } 58 59 body.toplevel_page_bp-groups table.groups tr.sticky { 60 background:#fff9db; 61 } -
bp-groups/admin/css/admin.min.css
1 body.toplevel_page_bp-groups table.groups th#status,body.toplevel_page_bp-groups table.groups th#members{width:10%}body.toplevel_page_bp-groups table.groups th#last_active{width:15%}#bp-groups-edit-form input{outline:medium none;padding:3px 8px}#bp-groups-edit-form input#bp-groups-name{font-size:1.7em;width:100%}#bp-groups-edit-form input#bp-groups-new-members{width:100%;max-width:90%;border:0}.bp-groups-settings-section{margin-bottom:15px}.bp-groups-member-type{position:relative;padding-bottom:1.7em}.bp-groups-member-type>h4{margin-bottom:.5em}ul.bp-group-delete-list{list-style-type:disc;margin:4px 26px}.bp-group-admin-pagination{position:absolute;text-align:right;width:100%}.bp-group-admin-pagination.table-top{top:0}.bp-group-admin-pagination.table-bottom{bottom:0}.bp-group-admin-pagination-viewing{font-family:Georgia,"Times New Roman","Bitstream Charter",Times,serif;color:#777;font-size:12px;font-style:italic}.bp-group-admin-pagination-links{white-space:nowrap;padding-left:15px} 2 No newline at end of file 1 body.toplevel_page_bp-groups table.groups th#status,body.toplevel_page_bp-groups table.groups th#members{width:10%}body.toplevel_page_bp-groups table.groups th#last_active{width:15%}#bp-groups-edit-form input{outline:medium none;padding:3px 8px}#bp-groups-edit-form input#bp-groups-name{font-size:1.7em;width:100%}#bp-groups-edit-form input#bp-groups-new-members{width:100%;max-width:90%;border:0}.bp-groups-settings-section{margin-bottom:15px}.bp-groups-member-type{position:relative;padding-bottom:1.7em}.bp-groups-member-type>h4{margin-bottom:.5em}ul.bp-group-delete-list{list-style-type:disc;margin:4px 26px}.bp-group-admin-pagination{position:absolute;text-align:right;width:100%}.bp-group-admin-pagination.table-top{top:0}.bp-group-admin-pagination.table-bottom{bottom:0}.bp-group-admin-pagination-viewing{font-family:Georgia,"Times New Roman","Bitstream Charter",Times,serif;color:#777;font-size:12px;font-style:italic}.bp-group-admin-pagination-links{white-space:nowrap;padding-left:15px}body.toplevel_page_bp-groups table.groups tr.sticky{background:#fff9db;} -
bp-groups/bp-groups-admin.php
215 215 $error = $group_id; 216 216 } 217 217 218 // Stick group to front 219 $sticky_group = ( isset( $_POST['group-stick-group'] ) ) ? 1 : 0; 220 221 if( !empty( $sticky_group ) ) 222 groups_update_groupmeta( $group_id, 'sticky', 1 ); 223 else 224 groups_delete_groupmeta( $group_id, 'sticky' ); 225 218 226 // Process new members 219 227 $user_names = array(); 220 228 … … 663 671 </div> 664 672 <?php endif; ?> 665 673 674 <?php if ( groups_can_stick_group( $item ) ) : ?> 675 <div class="bp-groups-settings-section" id="bp-groups-settings-section-sticky"> 676 <label for="group-stick-group"><input type="checkbox" name="group-stick-group" id="group-stick-group" <?php checked( groups_get_groupmeta( $item->id, 'sticky' ) ); ?> /> <?php _e( 'Stick to front of Groups Directory', 'buddypress' ) ?><br /> 677 </div> 678 <?php endif; ?> 679 666 680 <div class="bp-groups-settings-section" id="bp-groups-settings-section-status"> 667 681 <label for="group-status"><?php _e( 'Privacy', 'buddypress' ); ?></label> 668 682 … … 1193 1207 function single_row( $item = array() ) { 1194 1208 static $row_class = ''; 1195 1209 1210 $row_classes = array(); 1211 1196 1212 if ( empty( $row_class ) ) { 1197 $row_class = ' class="alternate odd"';1213 $row_classes[] = 'alternate odd'; 1198 1214 } else { 1199 $row_class = ' class="even"';1215 $row_classes[] = 'even'; 1200 1216 } 1201 1217 1218 if( groups_get_groupmeta( $item['id'], 'sticky' ) && bp_allow_sticky_group() ) 1219 $row_classes[] = 'sticky'; 1220 1221 $row_class = ' class="' .implode( ' ', $row_classes ) .'"'; 1222 1202 1223 echo '<tr' . $row_class . ' id="group-' . esc_attr( $item['id'] ) . '" data-parent_id="' . esc_attr( $item['id'] ) . '" data-root_id="' . esc_attr( $item['id'] ) . '">'; 1203 1224 echo $this->single_row_columns( $item ); 1204 1225 echo '</tr>'; 1226 1227 if( in_array( 'even', $row_classes ) ) 1228 $row_class = ''; 1205 1229 } 1206 1230 1207 1231 /** -
bp-groups/bp-groups-classes.php
346 346 'populate_extras' => true, 347 347 'exclude' => false, 348 348 'show_hidden' => false, 349 'sticky' => false, 349 350 ); 350 351 351 352 $r = wp_parse_args( $args, $defaults ); 352 353 353 354 $sql = array(); 354 355 $total_sql = array(); 356 $stickies = false; 355 357 356 358 $sql['select'] = "SELECT DISTINCT g.id, g.*, gm1.meta_value AS total_member_count, gm2.meta_value AS last_activity"; 357 359 $sql['from'] = " FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2,"; … … 429 431 // Convert 'orderby' into the proper ORDER BY term 430 432 $orderby = self::convert_orderby_to_order_by_term( $orderby ); 431 433 434 // sticky groups 435 if( !empty( $r['sticky'] ) ) { 436 $sper_page = $r['per_page']; 437 $spage = $r['page']; 438 439 $stickies = self::get_stickies( $sql, $meta_query_sql, $r['per_page'], $order, $orderby ); 440 $sticky_num = is_array( $stickies ) ? count( $stickies ) : false; 441 442 if( !empty( $sticky_num ) ) { 443 444 // We use the exclude arguments to avoid duplicate display of sticky groups 445 $exclude_stickies = array(); 446 447 foreach( $stickies as $stick ) { 448 $exclude_stickies[] = $stick->id; 449 } 450 451 // if exclude argument is set, merge it with exclude stickies one 452 $group_excluded = !empty( $exclude ) ? array_merge( $exclude_stickies, explode( ',', $exclude ) ) : $exclude_stickies; 453 $group_excluded = implode( ',', $group_excluded ); 454 455 $sql['exclude'] = " AND g.id NOT IN ({$group_excluded})"; 456 457 if( $r['page'] <= 1 ) 458 $r['per_page'] -= $sticky_num; 459 else 460 $r['page'] = $r['page'] - ( $sticky_num / $r['per_page'] ) ; 461 } 462 463 } 464 432 465 // Random order is a special case 433 466 if ( 'rand()' === $orderby ) { 434 467 $sql[] = "ORDER BY rand()"; … … 436 469 $sql[] = "ORDER BY {$orderby} {$order}"; 437 470 } 438 471 439 if ( ! empty( $r['per_page'] ) && ! empty( $r['page'] ) ) { 440 $sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $r['page'] - 1 ) * $r['per_page']), intval( $r['per_page'] ) ); 472 /* 473 If Number of stickies is equal to the per page argument, and we're on first page 474 A new query with a null offset is not necessary ;) 475 */ 476 if( empty( $sticky_num ) || $sticky_num < $sper_page || $spage > 1 ) { 477 478 // we need to use the round function as for instance intval( (1.4 - 1) * 5 ) == 1 instead of 2 ?! 479 if ( ! empty( $r['per_page'] ) && ! empty( $r['page'] ) ) { 480 $sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( round( ( $r['page'] - 1 ) * $r['per_page'] ) ), intval( $r['per_page'] ) ); 481 } 482 483 // Get paginated results 484 $paged_groups_sql = apply_filters( 'bp_groups_get_paged_groups_sql', join( ' ', (array) $sql ), $sql ); 485 $paged_groups = $wpdb->get_results( $paged_groups_sql ); 486 441 487 } 442 488 443 // Get paginated results444 $paged_groups_sql = apply_filters( 'bp_groups_get_paged_groups_sql', join( ' ', (array) $sql ), $sql );445 $paged_groups = $wpdb->get_results( $paged_groups_sql );446 447 489 $total_sql['select'] = "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name} g, {$bp->groups->table_name_members} gm1, {$bp->groups->table_name_groupmeta} gm2"; 448 490 449 491 if ( ! empty( $r['user_id'] ) ) { … … 498 540 $total_groups = $wpdb->get_var( $total_groups_sql ); 499 541 500 542 $group_ids = array(); 543 544 // merging if we still have regular groups 545 if( !empty( $sticky_num ) && $spage <= 1 ) 546 $paged_groups = !empty( $paged_groups ) ? array_merge( $stickies, (array) $paged_groups ) : $stickies ; 547 501 548 foreach ( (array) $paged_groups as $group ) { 502 549 $group_ids[] = $group->id; 503 550 } … … 517 564 } 518 565 519 566 /** 520 * Get the SQL for the 'meta_query' param in BP_ Activity_Activity::get()567 * Get the SQL for the 'meta_query' param in BP_Groups_Group::get() 521 568 * 522 569 * We use WP_Meta_Query to do the heavy lifting of parsing the 523 570 * meta_query array and creating the necessary SQL clauses. However, … … 577 624 } 578 625 579 626 /** 627 * Gets the stickies to add to the groups queried in BP_Groups_Group::get() 628 * 629 * @access protected 630 * 631 * @global $wpdb the WordPress DB API 632 * @param array $sticky_sql the sql array calculated by BP_Groups_Group::get() 633 * @param array $meta_query_sql the sql array of an eventual meta query 634 * @param integer $per_page the query offset 635 * @param string $order DESC or ASC ? 636 * @param string $orderby how to order the sticky query 637 * @uses buddypress() to get main instance of the plugin 638 * @return array the sticky groups found 639 */ 640 protected static function get_stickies( $sticky_sql = array(), $meta_query_sql = array(), $per_page = 0, $order = '', $orderby = '' ) { 641 global $wpdb; 642 $bp = buddypress(); 643 644 if( empty( $sticky_sql ) || !is_array( $sticky_sql ) ) 645 return false; 646 647 // When searching a group, stickies would be annoying.. 648 if ( ! empty($sticky_sql['search'] ) ) 649 return false; 650 651 // In case of restricting the group query to limited groups, we don't need stickies 652 if ( ! empty( $sticky_sql['include'] ) ) 653 return false; 654 655 // We only play in Group Directory so a user id tells us we're no on groups directory 656 if ( ! empty( $sticky_sql['members_from'] ) ) 657 return false; 658 659 // hidden can't be sticky 660 $sticky_sql['hidden'] = " AND g.status != 'hidden'"; 661 662 // If a meta query, don't apply it on stickies 663 if( !empty( $meta_query_sql['join'] ) ) 664 $sticky_sql['from'] = str_replace( $meta_query_sql['join'], '', $sticky_sql['from'] ); 665 666 if ( ! empty( $meta_query_sql['where'] ) ) 667 unset( $sticky_sql['meta'] ); 668 669 // Adding this will spread in global $groups_template ( $groups_template->group->sticky ) 670 $sticky_sql['select'] .= ", 1 as sticky"; 671 672 // Adding the specific sticky part for the group query 673 $sticky_sql['from'] .= "{$bp->groups->table_name_groupmeta} gms,"; 674 $sticky_sql['where'] .= " AND g.id = gms.group_id AND gms.meta_key = 'sticky'"; 675 676 if( !empty( $orderby ) && !empty( $order ) ) 677 $sticky_sql[] = "ORDER BY {$orderby} {$order}"; 678 679 /* max is per_page, after it's no more a sticky group... */ 680 if ( ! empty( $per_page ) ) { 681 $sticky_sql['pagination'] = $wpdb->prepare( "LIMIT %d", intval( $per_page ) ); 682 } 683 684 // Plugin authors can modify the query if they need to 685 $sticky_query = apply_filters( 'bp_groups_get_stickies_sql', join( ' ', (array) $sticky_sql ), $sticky_sql ); 686 687 // returning the found stickies. 688 return (array) $wpdb->get_results( $sticky_query ); 689 } 690 691 /** 580 692 * Convert the 'type' parameter to 'order' and 'orderby' 581 693 * 582 694 * @since BuddyPress (1.8) -
bp-groups/bp-groups-functions.php
465 465 'per_page' => 20, // The number of results to return per page 466 466 'page' => 1, // The page to return if limiting per page 467 467 'populate_extras' => true, // Fetch meta such as is_banned and is_member 468 'sticky' => false 468 469 ); 469 470 470 471 $r = wp_parse_args( $args, $defaults ); … … 480 481 'per_page' => $r['per_page'], 481 482 'page' => $r['page'], 482 483 'populate_extras' => $r['populate_extras'], 484 'sticky' => $r['sticky'], 483 485 'order' => $r['order'], 484 'orderby' => $r['orderby'] ,486 'orderby' => $r['orderby'] 485 487 ) ); 486 488 487 489 return apply_filters_ref_array( 'groups_get_groups', array( &$groups, &$r ) ); … … 1078 1080 add_action( 'wpmu_delete_user', 'groups_remove_data_for_user' ); 1079 1081 add_action( 'delete_user', 'groups_remove_data_for_user' ); 1080 1082 add_action( 'bp_make_spam_user', 'groups_remove_data_for_user' ); 1083 1084 1085 /*** Sticky group *****/ 1086 1087 /** 1088 * Checks if a group can be sticky according to blog settings and group status 1089 * 1090 * @param BP_Groups_Group $group the group object 1091 * @uses groups_get_current_group() if the argument is not defined to try to find current group 1092 * @uses bp_allow_sticky_group() to get blog settings for the stick to front group setting 1093 * @return boolean true||false 1094 */ 1095 function groups_can_stick_group( $group = false ) { 1096 if( empty( $group ) ) 1097 $group = groups_get_current_group(); 1098 1099 if( $group->status != 'hidden' ) 1100 return bp_allow_sticky_group(); 1101 else 1102 return false; 1103 1104 } -
bp-groups/bp-groups-template.php
145 145 'exclude' => false, 146 146 'search_terms' => '', 147 147 'meta_query' => false, 148 'populate_extras' => true 148 'populate_extras' => true, 149 'sticky' => false, 149 150 ); 150 151 151 152 $r = wp_parse_args( $args, $defaults ); … … 176 177 'include' => $include, 177 178 'exclude' => $exclude, 178 179 'populate_extras' => $populate_extras, 179 'show_hidden' => $show_hidden 180 'show_hidden' => $show_hidden, 181 'sticky' => $sticky 180 182 ) ); 181 183 } 182 184 … … 291 293 $type = ''; 292 294 $user_id = 0; 293 295 $order = ''; 296 $sticky = false; 294 297 295 298 // User filtering 296 299 if ( bp_displayed_user_id() ) … … 342 345 else 343 346 $r['search_terms'] = false; 344 347 } 348 349 if ( bp_is_groups_component() && !bp_current_action() && !bp_current_item() && empty( $r['search_terms'] ) ) 350 $sticky = bp_allow_sticky_group(); 345 351 346 352 $groups_template = new BP_Groups_Template( array( 347 353 'type' => $r['type'], … … 358 364 'meta_query' => $r['meta_query'], 359 365 'include' => $r['include'], 360 366 'exclude' => $r['exclude'], 361 'populate_extras' => (bool) $r['populate_extras'] 367 'populate_extras' => (bool) $r['populate_extras'], 368 'sticky' => (bool) $sticky 362 369 ) ); 363 370 364 371 return apply_filters( 'bp_has_groups', $groups_template->has_groups(), $groups_template, $r ); … … 407 414 } 408 415 409 416 /** 417 * Output the row class of a group in the groups loop 418 */ 419 function bp_groups_group_class() { 420 echo bp_get_groups_group_class(); 421 } 422 /** 423 * Return the row class of a group in the groups loop 424 * 425 * @global BP_Groups_Template $groups_template 426 * @uses apply_filters() to let plugins add their classes 427 * @return string Row class of the group 428 */ 429 function bp_get_groups_group_class() { 430 global $groups_template; 431 432 $classes = array(); 433 434 if( !empty( $groups_template->group->sticky ) ) 435 $classes[] = 'sticky'; 436 437 $classes = apply_filters( 'bp_get_groups_class', $classes ); 438 $classes = array_merge( $classes, array() ); 439 $retval = 'class="' . join( ' ', $classes ) . '"'; 440 return $retval; 441 } 442 443 /** 410 444 * Output the row class of a group 411 445 * 412 446 * @since BuddyPress (1.7)