Ticket #6544: 6544.patch
File 6544.patch, 8.1 KB (added by , 9 years ago) |
---|
-
src/bp-blogs/bp-blogs-functions.php
diff --git src/bp-blogs/bp-blogs-functions.php src/bp-blogs/bp-blogs-functions.php index 025ed79..a885a17 100644
function bp_blogs_restore_data( $user_id = 0 ) { 1477 1477 } 1478 1478 } 1479 1479 add_action( 'bp_make_ham_user', 'bp_blogs_restore_data', 10, 1 ); 1480 1481 /** 1482 * Generate the avatar upload directory path for a given blog. 1483 * 1484 * @since BuddyPress (2.4.0) 1485 * 1486 * @param int $blog_id Optional. ID of the blog. Default: ID of the 1487 * current blog. 1488 * @return string 1489 */ 1490 function blogs_avatar_upload_dir( $blog_id = 0 ) { 1491 1492 if ( empty( $blog_id ) ) { 1493 $blog_id = get_current_blog_id(); 1494 } 1495 1496 $directory = 'blog-avatars'; 1497 $path = bp_core_avatar_upload_path() . '/' . $directory . '/' . $blog_id; 1498 $newbdir = $path; 1499 $newurl = bp_core_avatar_url() . '/' . $directory . '/' . $blog_id; 1500 $newburl = $newurl; 1501 $newsubdir = '/' . $directory . '/' . $blog_id; 1502 1503 /** 1504 * Filters the avatar upload directory path for a given blog. 1505 * 1506 * @since BuddyPress (2.4.0) 1507 * 1508 * @param array $value Array of parts related to the blog avatar upload directory. 1509 */ 1510 return apply_filters( 'blogs_avatar_upload_dir', array( 1511 'path' => $path, 1512 'url' => $newurl, 1513 'subdir' => $newsubdir, 1514 'basedir' => $newbdir, 1515 'baseurl' => $newburl, 1516 'error' => false 1517 ) ); 1518 } 1519 1520 /** 1521 * Update the blog's profile photo if the site icon was updated 1522 * 1523 * @since BuddyPress (2.4.0) 1524 * 1525 * @param string $option name of the option. Passed by do_action() but 1526 * unused here. 1527 * @param string $value Value to save meta to. 1528 */ 1529 function bp_blogs_use_site_icon_as_avatar( $option = 'site_icon', $value = 0 ) { 1530 /** 1531 * Filter here to disable blog's avatar / site icon synchronization 1532 * 1533 * @since BuddyPress (2.4.0) 1534 * 1535 * @param bool True to use the site icon as the blog's profile photo. 1536 * False otherwise 1537 */ 1538 if ( ! is_multisite() || false === (bool) apply_filters( 'bp_blogs_use_site_icon_as_avatar', true ) ) { 1539 return; 1540 } 1541 1542 $site_icon_id = (int) $value; 1543 $site_icon_data = wp_get_attachment_metadata( $site_icon_id ); 1544 1545 if ( empty( $site_icon_data['file'] ) ) { 1546 return false; 1547 } 1548 1549 // Get the blog's upload dir 1550 $upload_dir = wp_upload_dir(); 1551 $blog_id = get_current_blog_id(); 1552 1553 // Create a profile photo for the blog 1554 if ( bp_avatar_create_item_avatar( array( 1555 'item_id' => $blog_id, 1556 'object' => 'blog', 1557 'component' => buddypress()->blogs->id, 1558 'image' => trailingslashit( $upload_dir['basedir'] ) . $site_icon_data['file'], 1559 'crop_w' => $site_icon_data['width'], 1560 'crop_h' => $site_icon_data['height'], 1561 ) ) ) { 1562 //The blog's profile photo is synchronized with the site icon 1563 bp_blogs_update_blogmeta( $blog_id, 'blog_avatar_type', 'site_icon' ); 1564 } 1565 } 1566 add_action( 'add_option_site_icon', 'bp_blogs_use_site_icon_as_avatar', 10, 2 ); 1567 1568 /** 1569 * Delete the blog's profile photo if the site icon was deleted 1570 * and if the site icon was used as the blog's profile photo 1571 * 1572 * @since BuddyPress (2.4.0) 1573 */ 1574 function bp_blogs_delete_blog_profile_photo() { 1575 if ( ! is_multisite() ) { 1576 return; 1577 } 1578 1579 $blog_id = get_current_blog_id(); 1580 1581 // Only delete the blog's avatar if synced with site icon 1582 if ( 'site_icon' === bp_blogs_get_blogmeta( $blog_id, 'blog_avatar_type' ) ) { 1583 // Remove the blog's profile photo 1584 bp_core_delete_existing_avatar( array( 'item_id' => $blog_id, 'object' => 'blog' ) ); 1585 1586 // Reset the blog avatar type 1587 bp_blogs_delete_blogmeta( $blog_id, 'blog_avatar_type' ); 1588 } 1589 } 1590 add_action( 'delete_option_site_icon', 'bp_blogs_delete_blog_profile_photo' ); -
src/bp-blogs/bp-blogs-template.php
diff --git src/bp-blogs/bp-blogs-template.php src/bp-blogs/bp-blogs-template.php index dd629d1..a13aebf 100644
function bp_blog_avatar( $args = '' ) { 566 566 'no_grav' => true, 567 567 ) ); 568 568 569 // Defaults to the admin avatar 570 $item_id = $blogs_template->blog->admin_user_id; 571 $object = 'user'; 572 $avatar_dir = 'avatars'; 573 574 if ( function_exists( 'has_site_icon' ) ) { 575 $object = 'blog'; 576 $avatar_dir = 'blog-avatars'; 577 $item_id = $blogs_template->blog->blog_id; 578 $r['title'] = sprintf( __( 'Site logo of %s', 'buddypress' ), esc_attr( $blogs_template->blog->name ) ); 579 $r['class'] = 'avatar blog-' . $blogs_template->blog->blog_id . '-avatar'; 580 $r['alt'] = sprintf( __( 'Site logo of %s', 'buddypress' ), esc_attr( $blogs_template->blog->name ) ); 581 } 582 569 583 // Fetch the avatar 570 584 $avatar = bp_core_fetch_avatar( array( 571 585 'item_id' => $blogs_template->blog->admin_user_id, 572 586 'title' => $r['title'], 573 //'avatar_dir' => 'blog-avatars',574 //'object' => 'blog',587 'avatar_dir' => $avatar_dir, 588 'object' => $object, 575 589 'type' => $r['type'], 576 590 'alt' => $r['alt'], 577 591 'css_id' => $r['id'], -
src/bp-core/bp-core-avatars.php
diff --git src/bp-core/bp-core-avatars.php src/bp-core/bp-core-avatars.php index bef7735..7f5a801 100644
function bp_avatar_ajax_set() { 1236 1236 add_action( 'wp_ajax_bp_avatar_set', 'bp_avatar_ajax_set' ); 1237 1237 1238 1238 /** 1239 * Use the absolute path to an image to set an object's avatar 1240 * 1241 * @since BuddyPress (?) 1242 * 1243 * @param array $args { 1244 * @type int $item_id The ID of the object 1245 * @type string $object The object type (eg: group, user, blog) 1246 * @type string $component The component for the object (eg: groups, xprofile, blogs) 1247 * @type string $image The absolute path to the image 1248 * @type int $crop_w Crop width. Default: the global 'full' avatar width, 1249 * as retrieved by bp_core_avatar_full_width(). 1250 * @type int $crop_h Crop height. Default: the global 'full' avatar height, 1251 * as retrieved by bp_core_avatar_full_height(). 1252 * @type int $crop_x The horizontal starting point of the crop. Default: 0. 1253 * @type int $crop_y The vertical starting point of the crop. Default: 0. 1254 * } 1255 * @return bool true on success, false otherwise 1256 */ 1257 function bp_avatar_create_item_avatar( $args = array() ) { 1258 $r = bp_parse_args( $args, array( 1259 'item_id' => 0, 1260 'object' => 'user', 1261 'component' => 'xprofile', 1262 'image' => '', 1263 'crop_w' => bp_core_avatar_full_width(), 1264 'crop_h' => bp_core_avatar_full_height(), 1265 'crop_x' => 0, 1266 'crop_y' => 0 1267 ), 'create_item_avatar' ); 1268 1269 if ( empty( $r['item_id'] ) || ! file_exists( $r['image'] ) || ! @getimagesize( $r['image'] ) ) { 1270 return false; 1271 } 1272 1273 if ( is_callable( $r['component'] . '_avatar_upload_dir' ) ) { 1274 $dir_args = array( $r['item_id'] ); 1275 1276 // In case of xprofile, we need an extra argument 1277 if ( 'xprofile' === $r['component'] ) { 1278 $dir_args = array( false, $r['item_id'] ); 1279 } 1280 1281 $avatar_data = call_user_func_array( $r['component'] . '_avatar_upload_dir', $dir_args ); 1282 } 1283 1284 if ( ! isset( $avatar_data['path'] ) || ! isset( $avatar_data['subdir'] ) ) { 1285 return false; 1286 } 1287 1288 // It's not a regular upload, we may need to create this folder 1289 if( ! is_dir( $avatar_data['path'] ) ) { 1290 if ( ! wp_mkdir_p( $avatar_data['path'] ) ) { 1291 return false; 1292 } 1293 } 1294 1295 $image_file_name = wp_unique_filename( $avatar_data['path'], basename( $r['image'] ) ); 1296 1297 // Copy the image file into the avatar dir 1298 copy( $r['image'], $avatar_data['path'] . '/' . $image_file_name ); 1299 1300 // Check the original file is copied 1301 if ( ! file_exists( $avatar_data['path'] . '/' . $image_file_name ) ) { 1302 return false; 1303 } 1304 1305 if ( ! bp_core_avatar_handle_crop( array( 1306 'object' => $r['object'], 1307 'avatar_dir' => trim( dirname( $avatar_data['subdir'] ), '/' ), 1308 'item_id' => (int) $r['item_id'], 1309 'original_file' => trailingslashit( $avatar_data['subdir'] ) . $image_file_name, 1310 'crop_w' => $r['crop_w'], 1311 'crop_h' => $r['crop_h'], 1312 'crop_x' => $r['crop_x'], 1313 'crop_y' => $r['crop_y'] 1314 ) ) ) { 1315 return false; 1316 } else { 1317 return true; 1318 } 1319 } 1320 1321 /** 1239 1322 * Replace default WordPress avatars with BP avatars, if available. 1240 1323 * 1241 1324 * Filters 'get_avatar'.