Skip to:
Content

BuddyPress.org

Changeset 3635


Ignore:
Timestamp:
01/01/2011 06:26:18 PM (14 years ago)
Author:
djpaul
Message:

Improves avatars' HTML alt and title tags. Fixes #2606.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-templatetags.php

    r3610 r3635  
    457457            'height' => 20,
    458458            'class'  => 'avatar',
    459             'alt'    => __( 'Avatar', 'buddypress' ),
     459            'alt'    => __( 'Profile picture of %s', 'buddypress' ),
    460460            'email'  => false
    461461        );
     
    503503            'height' => 20,
    504504            'class'  => 'avatar',
    505             'alt'    => __( 'Avatar', 'buddypress' ),
    506505            'email'  => false
    507506        );
     
    515514                $object = 'group';
    516515                $item_id = $activities_template->activity->item_id;
     516
     517                if ( !$alt )
     518                    $alt = __( 'Group logo of %s', 'buddypress' );
     519
    517520                break;
    518521            case 'blogs' :
    519522                $object = 'blog';
    520523                $item_id = $activities_template->activity->item_id;
     524
     525                if ( !$alt )
     526                    $alt = sprintf( __( 'Blog authored by %s', 'buddypress' ), get_blog_option( $item_id, 'blogname' ) );
     527
    521528                break;
    522529            case 'friends' :
    523530                $object  = 'user';
    524531                $item_id = $activities_template->activity->secondary_item_id;
     532
     533                if ( !$alt )
     534                    $alt = __( 'Profile picture of %s', 'buddypress' );
     535
    525536                break;
    526537            default :
     
    528539                $item_id = $activities_template->activity->user_id;
    529540                $email = $activities_template->activity->user_email;
     541
     542                if ( !$alt )
     543                    $alt = __( 'Profile picture of %s', 'buddypress' );
     544
    530545                break;
    531546        }
  • trunk/bp-blogs/bp-blogs-templatetags.php

    r3627 r3635  
    200200            'class' => 'avatar',
    201201            'id' => false,
    202             'alt' => __( 'Blog avatar', 'buddypress' ),
     202            'alt' => __( 'Blog authored by %s', 'buddypress' ),
    203203            'no_grav' => true
    204204        );
  • trunk/bp-core/bp-core-avatars.php

    r3592 r3635  
    5353 * default, but can be extended to include your own custom components too.
    5454 *
    55  * @global object $bp
    56  * @global object $current_blog
     55 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     56 * @global $current_blog WordPress global containing information and settings for the current blog being viewed.
    5757 * @param array $args Determine the output of this function
    5858 * @return string Formatted HTML <img> element, or raw avatar URL based on $html arg
     
    6262
    6363    // Set a few default variables
    64     $def_object     = 'user';
    65     $def_type       = 'thumb';
    66     $def_class      = 'avatar';
    67     $def_alt        = __( 'Avatar Image', 'buddypress' );
     64    $def_object = 'user';
     65    $def_type   = 'thumb';
     66    $def_class  = 'avatar';
     67    $def_alt    = __( 'Avatar Image', 'buddypress' );
    6868
    6969    // Set the default variables array
    7070    $defaults = array(
    71         'item_id'       => false,
    72         'object'        => $def_object, // user/group/blog/custom type (if you use filters)
    73         'type'          => $def_type,   // thumb or full
    74         'avatar_dir'    => false,       // Specify a custom avatar directory for your object
    75         'width'         => false,       // Custom width (int)
    76         'height'        => false,       // Custom height (int)
    77         'class'         => $def_class,  // Custom <img> class (string)
    78         'css_id'        => false,       // Custom <img> ID (string)
    79         'alt'           => $def_alt,    // Custom <img> alt (string)
    80         'email'         => false,       // Pass the user email (for gravatar) to prevent querying the DB for it
    81         'no_grav'       => false,       // If there is no avatar found, return false instead of a grav?
    82         'html'          => true         // Wrap the return img URL in <img />
     71        'item_id'    => false,
     72        'object'     => $def_object, // user/group/blog/custom type (if you use filters)
     73        'type'       => $def_type,   // thumb or full
     74        'avatar_dir' => false,       // Specify a custom avatar directory for your object
     75        'width'      => false,       // Custom width (int)
     76        'height'     => false,       // Custom height (int)
     77        'class'      => $def_class,  // Custom <img> class (string)
     78        'css_id'     => false,       // Custom <img> ID (string)
     79        'alt'        => $def_alt,    // Custom <img> alt (string)
     80        'email'      => false,       // Pass the user email (for gravatar) to prevent querying the DB for it
     81        'no_grav'    => false,       // If there is no avatar found, return false instead of a grav?
     82        'html'       => true,        // Wrap the return img URL in <img />
     83        'title'      => ''           // Custom <img> title (string)
    8384    );
    8485
     
    9899        $item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object );
    99100
    100         if ( !$item_id ) return false;
     101        if ( !$item_id )
     102            return false;
    101103    }
    102104
     
    112114        $avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object );
    113115
    114         if ( !$avatar_dir ) return false;
     116        if ( !$avatar_dir )
     117            return false;
    115118    }
    116119
    117120    // Add an identifying class to each item
    118121    $class .= ' ' . $object . '-' . $item_id . '-avatar';
     122
     123    // Get item name for alt/title tags
     124    $item_name = '';
     125
     126    if ( 'user' == $object )
     127        $item_name = bp_core_get_user_displayname( $item_id );
     128    elseif ( 'group' == $object )
     129        $item_name = bp_get_group_name( new BP_Groups_Group( $item_id ) );
     130    elseif ( 'blog' == $object )
     131        $item_name = get_blog_option( $item_id, 'blogname' );
     132
     133    $alt = sprintf( $alt, apply_filters( 'bp_core_avatar_alt', $item_name, $item_id, $object ) );
     134
     135    // Set title tag
     136    if ( $title )
     137        $title = " title='" . esc_attr( apply_filters( 'bp_core_avatar_title', $title, $item_id, $object ) ) . "'";
     138    elseif ( $item_name )
     139        $title = " title='" . esc_attr( apply_filters( 'bp_core_avatar_title', $item_name, $item_id, $object ) ) . "'";
    119140
    120141    // Set CSS ID if passed
     
    196217            // Return it wrapped in an <img> element
    197218            if ( true === $html ) {
    198                 return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $avatar_url . '" alt="' . $alt . '" class="' . $class . '"' . $css_id . $html_width . $html_height . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
     219                return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $avatar_url . '" alt="' . esc_attr( $alt ) . '" class="' . esc_attr( $class ) . '"' . $css_id . $html_width . $html_height . $title . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
    199220
    200221            // ...or only the URL
     
    247268        // Return gravatar wrapped in <img />
    248269        if ( true === $html )
    249             return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $gravatar . '" alt="' . $alt . '" class="' . $class . '"' . $css_id . $html_width . $html_height . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
     270            return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $gravatar . '" alt="' . esc_attr( $alt ) . '" class="' . esc_attr( $class ) . '"' . $css_id . $html_width . $html_height . $title . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
    250271
    251272        // ...or only return the gravatar URL
     
    506527        return !empty( $avatar ) ? $avatar : $default;
    507528
     529    if ( !$alt )
     530        $alt = __( 'Avatar of %s', 'buddypress' );
     531
    508532    // Let BuddyPress handle the fetching of the avatar
    509533    $bp_avatar = bp_core_fetch_avatar( array( 'item_id' => $id, 'width' => $size, 'height' => $size, 'alt' => $alt ) );
  • trunk/bp-core/bp-core-templatetags.php

    r3631 r3635  
    322322            'class' => 'avatar',
    323323            'id' => false,
    324             'alt' => __( 'Member avatar', 'buddypress' )
     324            'alt' => __( 'Profile picture of %s', 'buddypress' )
    325325        );
    326326
     
    671671            'width'     => false,
    672672            'height'    => false,
    673             'html'      => true
     673            'html'      => true,
     674            'alt' => __( 'Profile picture of %s', 'buddypress' )
    674675        );
    675676
     
    677678        extract( $r, EXTR_SKIP );
    678679
    679         return apply_filters( 'bp_get_loggedin_user_avatar', bp_core_fetch_avatar( array( 'item_id' => $bp->loggedin_user->id, 'type' => $type, 'width' => $width, 'height' => $height, 'html' => $html ) ) );
     680        return apply_filters( 'bp_get_loggedin_user_avatar', bp_core_fetch_avatar( array( 'item_id' => $bp->loggedin_user->id, 'type' => $type, 'width' => $width, 'height' => $height, 'html' => $html, 'alt' => $alt ) ) );
    680681    }
    681682
     
    690691            'width'     => false,
    691692            'height'    => false,
    692             'html'      => true
     693            'html'      => true,
     694            'alt' => __( 'Profile picture of %s', 'buddypress' )
    693695        );
    694696
     
    696698        extract( $r, EXTR_SKIP );
    697699
    698         return apply_filters( 'bp_get_displayed_user_avatar', bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => $type, 'width' => $width, 'height' => $height, 'html' => $html ) ) );
     700        return apply_filters( 'bp_get_displayed_user_avatar', bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => $type, 'width' => $width, 'height' => $height, 'html' => $html, 'alt' => $alt ) ) );
    699701    }
    700702
  • trunk/bp-forums/bp-forums-templatetags.php

    r3627 r3635  
    288288            'width' => false,
    289289            'height' => false,
     290            'alt' => __( 'Profile picture of %s', 'buddypress' )
    290291        );
    291292
     
    293294        extract( $r, EXTR_SKIP );
    294295
    295         return apply_filters( 'bp_get_the_topic_poster_avatar', bp_core_fetch_avatar( array( 'item_id' => $forum_template->topic->topic_poster, 'type' => $type, 'width' => $width, 'height' => $height ) ) );
     296        return apply_filters( 'bp_get_the_topic_poster_avatar', bp_core_fetch_avatar( array( 'item_id' => $forum_template->topic->topic_poster, 'type' => $type, 'width' => $width, 'height' => $height, 'alt' => $alt ) ) );
    296297    }
    297298
     
    369370            'width' => false,
    370371            'height' => false,
     372            'alt' => __( 'Group logo for %s', 'buddypress' )
    371373        );
    372374
     
    374376        extract( $r, EXTR_SKIP );
    375377
    376         return apply_filters( 'bp_get_the_topic_object_avatar', bp_core_fetch_avatar( array( 'item_id' => $forum_template->topic->object_id, 'type' => $type, 'object' => 'group', 'width' => $width, 'height' => $height ) ) );
     378        return apply_filters( 'bp_get_the_topic_object_avatar', bp_core_fetch_avatar( array( 'item_id' => $forum_template->topic->object_id, 'type' => $type, 'object' => 'group', 'width' => $width, 'height' => $height, 'alt' => $alt ) ) );
    377379    }
    378380
     
    387389            'width' => false,
    388390            'height' => false,
     391            'alt' => __( 'Profile picture of %s', 'buddypress' )
    389392        );
    390393
     
    392395        extract( $r, EXTR_SKIP );
    393396
    394         return apply_filters( 'bp_get_the_topic_last_poster_avatar', bp_core_fetch_avatar( array( 'email' => $forum_template->topic->topic_last_poster_email, 'item_id' => $forum_template->topic->topic_last_poster, 'type' => $type, 'width' => $width, 'height' => $height ) ) );
     397        return apply_filters( 'bp_get_the_topic_last_poster_avatar', bp_core_fetch_avatar( array( 'email' => $forum_template->topic->topic_last_poster_email, 'item_id' => $forum_template->topic->topic_last_poster, 'type' => $type, 'width' => $width, 'height' => $height, 'alt' => $alt ) ) );
    395398    }
    396399
     
    909912            'width' => 20,
    910913            'height' => 20,
     914            'alt' => __( 'Profile picture of %s', 'buddypress' )
    911915        );
    912916
     
    914918        extract( $r, EXTR_SKIP );
    915919
    916         return apply_filters( 'bp_get_the_topic_post_poster_avatar', bp_core_fetch_avatar( array( 'item_id' => $topic_template->post->poster_id, 'type' => $type, 'width' => $width, 'height' => $height ) ) );
     920        return apply_filters( 'bp_get_the_topic_post_poster_avatar', bp_core_fetch_avatar( array( 'item_id' => $topic_template->post->poster_id, 'type' => $type, 'width' => $width, 'height' => $height, 'alt' => $alt ) ) );
    917921    }
    918922
  • trunk/bp-groups/bp-groups-templatetags.php

    r3627 r3635  
    291291            'class' => 'avatar',
    292292            'id' => false,
    293             'alt' => __( 'Group avatar', 'buddypress' )
     293            'alt' => __( 'Group logo of %s', 'buddypress' )
    294294        );
    295295
     
    474474            <?php foreach( (array)$group->admins as $admin ) { ?>
    475475                <li>
    476                     <a href="<?php echo bp_core_get_user_domain( $admin->user_id, $admin->user_nicename, $admin->user_login ) ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $admin->user_id, 'email' => $admin->user_email ) ) ?></a>
     476                    <a href="<?php echo bp_core_get_user_domain( $admin->user_id, $admin->user_nicename, $admin->user_login ) ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $admin->user_id, 'email' => $admin->user_email, 'alt' => __( 'Profile picture of %s', 'buddypress' ) ) ) ?></a>
    477477                </li>
    478478            <?php } ?>
     
    494494            <?php foreach( (array)$group->mods as $mod ) { ?>
    495495                <li>
    496                     <a href="<?php echo bp_core_get_user_domain( $mod->user_id, $mod->user_nicename, $mod->user_login ) ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $mod->user_id, 'email' => $mod->user_email ) ) ?></a>
     496                    <a href="<?php echo bp_core_get_user_domain( $mod->user_id, $mod->user_nicename, $mod->user_login ) ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $mod->user_id, 'email' => $mod->user_email, 'alt' => __( 'Profile picture of %s', 'buddypress' ) ) ) ?></a>
    497497                </li>
    498498            <?php } ?>
     
    737737            <?php if ( $admin_list ) { ?>
    738738            <li>
    739                 <?php echo bp_core_fetch_avatar( array( 'item_id' => $admin->user_id, 'type' => 'thumb', 'width' => 30, 'height' => 30 ) ) ?>
     739                <?php echo bp_core_fetch_avatar( array( 'item_id' => $admin->user_id, 'type' => 'thumb', 'width' => 30, 'height' => 30, 'alt' => __( 'Profile picture of %s', 'buddypress' ) ) ) ?>
    740740                <h5><?php echo bp_core_get_userlink( $admin->user_id ) ?>  <span class="small"> &mdash; <a class="confirm admin-demote-to-member" href="<?php bp_group_member_demote_link($admin->user_id) ?>"><?php _e( 'Demote to Member', 'buddypress' ) ?></a></span></h5>
    741741            </li>
    742742            <?php } else { ?>
    743743            <li>
    744                 <?php echo bp_core_fetch_avatar( array( 'item_id' => $admin->user_id, 'type' => 'thumb' ) ) ?>
     744                <?php echo bp_core_fetch_avatar( array( 'item_id' => $admin->user_id, 'type' => 'thumb', 'alt' => __( 'Profile picture of %s', 'buddypress' ) ) ) ?>
    745745                <h5><?php echo bp_core_get_userlink( $admin->user_id ) ?></h5>
    746746                <span class="activity"><?php echo bp_core_get_last_activity( strtotime( $admin->date_modified ), __( 'joined %s ago', 'buddypress') ); ?></span>
     
    775775                <?php if ( $admin_list ) { ?>
    776776                <li>
    777                     <?php echo bp_core_fetch_avatar( array( 'item_id' => $mod->user_id, 'type' => 'thumb', 'width' => 30, 'height' => 30 ) ) ?>
     777                    <?php echo bp_core_fetch_avatar( array( 'item_id' => $mod->user_id, 'type' => 'thumb', 'width' => 30, 'height' => 30, 'alt' => __( 'Profile picture of %s', 'buddypress' ) ) ) ?>
    778778                    <h5><?php echo bp_core_get_userlink( $mod->user_id ) ?>  <span class="small"> &mdash; <a href="<?php bp_group_member_promote_admin_link( array( 'user_id' => $mod->user_id ) ) ?>" class="confirm mod-promote-to-admin" title="<?php _e( 'Promote to Admin', 'buddypress' ); ?>"><?php _e( 'Promote to Admin', 'buddypress' ); ?></a> | <a class="confirm mod-demote-to-member" href="<?php bp_group_member_demote_link($mod->user_id) ?>"><?php _e( 'Demote to Member', 'buddypress' ) ?></a></span></h5>
    779779                </li>
    780780                <?php } else { ?>
    781781                <li>
    782                     <?php echo bp_core_fetch_avatar( array( 'item_id' => $mod->user_id, 'type' => 'thumb' ) ) ?>
     782                    <?php echo bp_core_fetch_avatar( array( 'item_id' => $mod->user_id, 'type' => 'thumb', 'alt' => __( 'Profile picture of %s', 'buddypress' ) ) ) ?>
    783783                    <h5><?php echo bp_core_get_userlink( $mod->user_id ) ?></h5>
    784784                    <span class="activity"><?php echo bp_core_get_last_activity( strtotime( $mod->date_modified ), __( 'joined %s ago', 'buddypress') ); ?></span>
     
    14421442        global $members_template;
    14431443
    1444         return apply_filters( 'bp_get_group_member_avatar', bp_core_fetch_avatar( array( 'item_id' => $members_template->member->user_id, 'type' => 'full', 'email' => $members_template->member->user_email ) ) );
     1444        return apply_filters( 'bp_get_group_member_avatar', bp_core_fetch_avatar( array( 'item_id' => $members_template->member->user_id, 'type' => 'full', 'email' => $members_template->member->user_email, 'alt' => __( 'Profile picture of %s', 'buddypress' ) ) ) );
    14451445    }
    14461446
     
    14511451        global $members_template;
    14521452
    1453         return apply_filters( 'bp_get_group_member_avatar_thumb', bp_core_fetch_avatar( array( 'item_id' => $members_template->member->user_id, 'type' => 'thumb', 'email' => $members_template->member->user_email ) ) );
     1453        return apply_filters( 'bp_get_group_member_avatar_thumb', bp_core_fetch_avatar( array( 'item_id' => $members_template->member->user_id, 'type' => 'thumb', 'email' => $members_template->member->user_email, 'alt' => __( 'Profile picture of %s', 'buddypress' ) ) ) );
    14541454    }
    14551455
     
    14601460        global $members_template;
    14611461
    1462         return apply_filters( 'bp_get_group_member_avatar_mini', bp_core_fetch_avatar( array( 'item_id' => $members_template->member->user_id, 'type' => 'thumb', 'width' => $width, 'height' => $height, 'email' => $members_template->member->user_email ) ) );
     1462        return apply_filters( 'bp_get_group_member_avatar_mini', bp_core_fetch_avatar( array( 'item_id' => $members_template->member->user_id, 'type' => 'thumb', 'width' => $width, 'height' => $height, 'email' => $members_template->member->user_email, 'alt' => __( 'Profile picture of %s', 'buddypress' ) ) ) );
    14631463    }
    14641464
     
    21172117    global $requests_template;
    21182118
    2119     echo apply_filters( 'bp_group_request_user_avatar_thumb', bp_core_fetch_avatar( array( 'item_id' => $requests_template->request->user_id, 'type' => 'thumb' ) ) );
     2119    echo apply_filters( 'bp_group_request_user_avatar_thumb', bp_core_fetch_avatar( array( 'item_id' => $requests_template->request->user_id, 'type' => 'thumb', 'alt' => __( 'Profile picture of %s', 'buddypress' ) ) ) );
    21202120}
    21212121
Note: See TracChangeset for help on using the changeset viewer.