<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][5468] trunk/bp-core/bp-core-avatars.php: Remove debug cruft from r5466.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://buddypress.trac.wordpress.org/changeset/5468">5468</a></dd>
<dt>Author</dt> <dd>johnjamesjacoby</dd>
<dt>Date</dt> <dd>2011-12-09 04:22:44 +0000 (Fri, 09 Dec 2011)</dd>
</dl>
<h3>Log Message</h3>
<pre>Remove debug cruft from r5466.
In bp_core_fetch_avatar():
* Use switch statements to set defaults
* Use empty() to prevent notices
* General code clean-up
* See <a href="http://buddypress.trac.wordpress.org/ticket/3806">#3806</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpcorebpcoreavatarsphp">trunk/bp-core/bp-core-avatars.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpcorebpcoreavatarsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/bp-core-avatars.php (5467 => 5468)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/bp-core-avatars.php        2011-12-09 01:31:09 UTC (rev 5467)
+++ trunk/bp-core/bp-core-avatars.php        2011-12-09 04:22:44 UTC (rev 5468)
</span><span class="lines">@@ -110,83 +110,132 @@
</span><span class="cx">         $params = wp_parse_args( $args, $defaults );
</span><span class="cx">         extract( $params, EXTR_SKIP );
</span><span class="cx">
</span><del>-        // Set item_id if not passed
-        if ( !$item_id ) {
-                if ( 'user' == $object )
-                        $item_id = bp_displayed_user_id();
-                else if ( bp_is_active( 'groups' ) && 'group' == $object )
-                        $item_id = $bp->groups->current_group->id;
-                else if ( 'blog' == $object )
-                        $item_id = $current_blog->id;
</del><ins>+        /** Set item_id ***********************************************************/
+        
+        if ( empty( $item_id ) ) {
</ins><span class="cx">
</span><ins>+                switch ( $object ) {
+
+                        case 'blog' :
+                                $item_id = $current_blog->id;
+                                break;
+
+                        case 'group' :
+                                if ( bp_is_active( 'groups' ) ) {
+                                        $item_id = $bp->groups->current_group->id;
+                                } else {
+                                        $item_id = false;
+                                }
+
+                                break;
+                        
+                        case 'user' :
+                        default :
+                                $item_id = bp_displayed_user_id();
+                                break;
+                }
+
</ins><span class="cx">                 $item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object );
</span><span class="cx">
</span><del>-                if ( !$item_id )
</del><ins>+                if ( empty( $item_id ) ) {
</ins><span class="cx">                         return false;
</span><ins>+                }
</ins><span class="cx">         }
</span><span class="cx">
</span><del>-        // Set avatar_dir if not passed (uses $object)
-        if ( !$avatar_dir ) {
-                if ( 'user' == $object )
-                        $avatar_dir = 'avatars';
-                else if ( bp_is_active( 'groups' ) && 'group' == $object )
-                        $avatar_dir = 'group-avatars';
-                else if ( 'blog' == $object )
-                        $avatar_dir = 'blog-avatars';
</del><ins>+        /** Set avatar_dir ********************************************************/
</ins><span class="cx">
</span><ins>+        if ( empty( $avatar_dir ) ) {
+
+                switch ( $object ) {
+
+                        case 'blog' :
+                                $avatar_dir = 'blog-avatars';
+                                break;
+
+                        case 'group' :
+                                if ( bp_is_active( 'groups' ) ) {
+                                        $avatar_dir = 'group-avatars';
+                                } else {
+                                        $avatar_dir = false;
+                                }
+
+                                break;
+                        
+                        case 'user' :
+                        default :
+                                $avatar_dir = 'avatars';
+                                break;
+                }
+
</ins><span class="cx">                 $avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object );
</span><span class="cx">
</span><del>-                if ( !$avatar_dir )
</del><ins>+                if ( empty( $avatar_dir ) ) {
</ins><span class="cx">                         return false;
</span><ins>+                }
</ins><span class="cx">         }
</span><span class="cx">
</span><del>-        // Add an identifying class to each item
-        $class .= ' ' . $object . '-' . $item_id . '-avatar';
</del><ins>+        /** <img> alt *************************************************************/
</ins><span class="cx">
</span><del>-        // Get item name for alt/title tags
-        $item_name = '';
-        
-        // Backpat for the 'alt' parameter, which used to encourage sprintf()-style values
</del><span class="cx">         if ( false !== strpos( $alt, '%s' ) || false !== strpos( $alt, '%1$s' ) ) {
</span><del>-                var_dump( 'yes' );
-                if ( 'user' == $object )
-                        $item_name = bp_core_get_user_displayname( $item_id );
-                elseif ( 'group' == $object )
-                        $item_name = bp_get_group_name( groups_get_group( array( 'group_id' => $item_id ) ) );
-                elseif ( 'blog' == $object )
-                        $item_name = get_blog_option( $item_id, 'blogname' );
</del><span class="cx">                 
</span><del>-                $alt = sprintf( $alt, apply_filters( 'bp_core_avatar_alt', $item_name, $item_id, $object ) );
</del><ins>+                // Get item name for alt/title tags
+                $item_name = '';
+
+                switch ( $object ) {
+
+                        case 'blog' :
+                                $item_name = get_blog_option( $item_id, 'blogname' );
+                                break;
+
+                        case 'group' :
+                                $item_name = bp_get_group_name( groups_get_group( array( 'group_id' => $item_id ) ) );
+                                break;
+                        
+                        case 'user' :
+                        default :
+                                $item_name = bp_core_get_user_displayname( $item_id );
+                                break;
+                }
+
+                $item_name = apply_filters( 'bp_core_avatar_alt', $item_name, $item_id, $object );
+                $alt = sprintf( $alt, $item_name );
</ins><span class="cx">         }
</span><span class="cx">
</span><ins>+        /** Sanity Checks *********************************************************/
+
</ins><span class="cx">         // Get a fallback for the 'alt' parameter        
</span><del>-        if ( !$alt ) {
</del><ins>+        if ( empty( $alt ) )
</ins><span class="cx">                 $alt = __( 'Avatar Image', 'buddypress' );
</span><del>-        }
</del><span class="cx">
</span><span class="cx">         // Set title tag, if it's been provided
</span><del>-        if ( $title )
</del><ins>+        if ( !empty( $title ) )
</ins><span class="cx">                 $title = " title='" . esc_attr( apply_filters( 'bp_core_avatar_title', $title, $item_id, $object ) ) . "'";
</span><span class="cx">
</span><span class="cx">         // Set CSS ID if passed
</span><span class="cx">         if ( !empty( $css_id ) )
</span><del>-                $css_id = " id='{$css_id}'";
</del><ins>+                $css_id = ' id="' . $css_id . '"';
</ins><span class="cx">
</span><del>-        // Set avatar width
-        if ( $width )
-                $html_width = " width='{$width}'";
</del><ins>+        // Set image width
+        if ( false !== $width )
+                $html_width = ' width="' . $width . '"';
</ins><span class="cx">         else
</span><span class="cx">                 $html_width = ( 'thumb' == $type ) ? ' width="' . bp_core_avatar_thumb_width() . '"' : ' width="' . bp_core_avatar_full_width() . '"';
</span><span class="cx">
</span><del>-        // Set avatar height
-        if ( $height )
-                $html_height = " height='{$height}'";
</del><ins>+        // Set image height
+        if ( false !== $height )
+                $html_height = ' height="' . $height . '"';
</ins><span class="cx">         else
</span><span class="cx">                 $html_height = ( 'thumb' == $type ) ? ' height="' . bp_core_avatar_thumb_height() . '"' : ' height="' . bp_core_avatar_full_height() . '"';
</span><span class="cx">
</span><del>-        // Set avatar URL and DIR based on prepopulated constants
-        $avatar_folder_url = apply_filters( 'bp_core_avatar_folder_url', bp_core_avatar_url() . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
-        $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', bp_core_avatar_upload_path() . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
</del><ins>+        // Set img URL and DIR based on prepopulated constants
+        $avatar_loc = array();
+        $avatar_loc[] = trailingslashit( bp_core_avatar_upload_path() );
+        $avatar_loc[] = trailingslashit( bp_core_avatar_url() );
+        $avatar_loc[] = trailingslashit( $avatar_dir );
+        $avatar_folder_url = apply_filters( 'bp_core_avatar_folder_url', ( $avatar_loc[1] . $avatar_loc[2] . $item_id ), $item_id, $object, $avatar_dir );
+        $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', ( $avatar_loc[0] . $avatar_loc[2] . $item_id ), $item_id, $object, $avatar_dir );
+        // Add an identifying class
+        $class .= ' ' . $object . '-' . $item_id . '-avatar';
</ins><span class="cx">
</span><span class="cx">         /****
</span><span class="cx">          * Look for uploaded avatar first. Use it if it exists.
</span><span class="lines">@@ -205,10 +254,11 @@
</span><span class="cx">
</span><span class="cx">                         // Stash files in an array once to check for one that matches
</span><span class="cx">                         $avatar_files = array();
</span><del>-                        while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
</del><ins>+                        while ( false !== ( $avatar_file = readdir( $av_dir ) ) ) {
</ins><span class="cx">                                 // Only add files to the array (skip directories)
</span><del>-                                if ( 2 < strlen( $avatar_file ) )
</del><ins>+                                if ( 2 < strlen( $avatar_file ) ) {
</ins><span class="cx">                                         $avatar_files[] = $avatar_file;
</span><ins>+                                }
</ins><span class="cx">                         }
</span><span class="cx">
</span><span class="cx">                         // Check for array
</span><span class="lines">@@ -216,22 +266,25 @@
</span><span class="cx">
</span><span class="cx">                                 // Check for current avatar
</span><span class="cx">                                 foreach( $avatar_files as $key => $value ) {
</span><del>-                                        if ( strpos ( $value, $avatar_size )!== false )
</del><ins>+                                        if ( strpos ( $value, $avatar_size )!== false ) {
</ins><span class="cx">                                                 $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
</span><ins>+                                        }
</ins><span class="cx">                                 }
</span><span class="cx">
</span><span class="cx">                                 // Legacy avatar check
</span><span class="cx">                                 if ( !isset( $avatar_url ) ) {
</span><span class="cx">                                         foreach( $avatar_files as $key => $value ) {
</span><del>-                                                if ( strpos ( $value, $legacy_user_avatar_name )!== false )
</del><ins>+                                                if ( strpos ( $value, $legacy_user_avatar_name )!== false ) {
</ins><span class="cx">                                                         $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
</span><ins>+                                                }
</ins><span class="cx">                                         }
</span><span class="cx">
</span><span class="cx">                                         // Legacy group avatar check
</span><span class="cx">                                         if ( !isset( $avatar_url ) ) {
</span><span class="cx">                                                 foreach( $avatar_files as $key => $value ) {
</span><del>-                                                        if ( strpos ( $value, $legacy_group_avatar_name )!== false )
</del><ins>+                                                        if ( strpos ( $value, $legacy_group_avatar_name )!== false ) {
</ins><span class="cx">                                                                 $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
</span><ins>+                                                        }
</ins><span class="cx">                                                 }
</span><span class="cx">                                         }
</span><span class="cx">                                 }
</span><span class="lines">@@ -261,20 +314,22 @@
</span><span class="cx">         if ( ! apply_filters( 'bp_core_fetch_avatar_no_grav', $no_grav ) ) {
</span><span class="cx">
</span><span class="cx">                 // Set gravatar size
</span><del>-                if ( $width )
</del><ins>+                if ( false !== $width ) {
</ins><span class="cx">                         $grav_size = $width;
</span><del>-                else if ( 'full' == $type )
</del><ins>+                } else if ( 'full' == $type ) {
</ins><span class="cx">                         $grav_size = bp_core_avatar_full_width();
</span><del>-                else if ( 'thumb' == $type )
</del><ins>+                } else if ( 'thumb' == $type ) {
</ins><span class="cx">                         $grav_size = bp_core_avatar_thumb_width();
</span><ins>+                }
</ins><span class="cx">
</span><span class="cx">                 // Set gravatar type
</span><del>-                if ( empty( $bp->grav_default->{$object} ) )
</del><ins>+                if ( empty( $bp->grav_default->{$object} ) ) {
</ins><span class="cx">                         $default_grav = 'wavatar';
</span><del>-                else if ( 'mystery' == $bp->grav_default->{$object} )
</del><ins>+                } else if ( 'mystery' == $bp->grav_default->{$object} ) {
</ins><span class="cx">                         $default_grav = apply_filters( 'bp_core_mysteryman_src', bp_core_avatar_default(), $grav_size );
</span><del>-                else
</del><ins>+                } else {
</ins><span class="cx">                         $default_grav = $bp->grav_default->{$object};
</span><ins>+                }
</ins><span class="cx">
</span><span class="cx">                 // Set gravatar object
</span><span class="cx">                 if ( empty( $email ) ) {
</span><span class="lines">@@ -286,17 +341,17 @@
</span><span class="cx">                 }
</span><span class="cx">
</span><span class="cx">                 // Set host based on if using ssl
</span><del>-                if ( is_ssl() )
</del><ins>+                $host = 'http://www.gravatar.com/avatar/';
+                if ( is_ssl() ) {
</ins><span class="cx">                         $host = 'https://secure.gravatar.com/avatar/';
</span><del>-                else
-                        $host = 'http://www.gravatar.com/avatar/';
</del><ins>+                }
</ins><span class="cx">
</span><span class="cx">                 // Filter gravatar vars
</span><span class="cx">                 $email = apply_filters( 'bp_core_gravatar_email', $email, $item_id, $object );
</span><span class="cx">                 $gravatar = apply_filters( 'bp_gravatar_url', $host ) . md5( strtolower( $email ) ) . '?d=' . $default_grav . '&amp;s=' . $grav_size;
</span><span class="cx">
</span><ins>+        // No avatar was found, and we've been told not to use a gravatar.
</ins><span class="cx">         } else {
</span><del>-                // No avatar was found, and we've been told not to use a gravatar.
</del><span class="cx">                 $gravatar = apply_filters( "bp_core_default_avatar_$object", BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg', $params );
</span><span class="cx">         }
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>