<!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][6468] trunk/bp-core/bp-core-avatars.php: Avatars:</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/6468">6468</a></dd>
<dt>Author</dt> <dd>johnjamesjacoby</dd>
<dt>Date</dt> <dd>2012-10-26 17:13:59 +0000 (Fri, 26 Oct 2012)</dd>
</dl>
<h3>Log Message</h3>
<pre>Avatars:
* Obey 'show_avatars' option, and bail early if avatars are totally disabled.
* Replace $bp global with buddypress() usage in bp-core-avatars.php.</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 (6467 => 6468)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/bp-core-avatars.php        2012-10-26 06:35:11 UTC (rev 6467)
+++ trunk/bp-core/bp-core-avatars.php        2012-10-26 17:13:59 UTC (rev 6468)
</span><span class="lines">@@ -11,7 +11,6 @@
</span><span class="cx"> * Set up the constants we need for avatar support
</span><span class="cx"> */
</span><span class="cx"> function bp_core_set_avatar_constants() {
</span><del>-        global $bp;
</del><span class="cx">
</span><span class="cx">         if ( !defined( 'BP_AVATAR_THUMB_WIDTH' ) )
</span><span class="cx">                 define( 'BP_AVATAR_THUMB_WIDTH', 50 );
</span><span class="lines">@@ -29,6 +28,9 @@
</span><span class="cx">                 define( 'BP_AVATAR_ORIGINAL_MAX_WIDTH', 450 );
</span><span class="cx">
</span><span class="cx">         if ( !defined( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE' ) ) {
</span><ins>+
+                $bp = buddypress();
+
</ins><span class="cx">                 if ( !isset( $bp->site_options['fileupload_maxk'] ) ) {
</span><span class="cx">                         define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', 5120000 ); // 5mb
</span><span class="cx">                 } else {
</span><span class="lines">@@ -45,7 +47,7 @@
</span><span class="cx"> add_action( 'bp_init', 'bp_core_set_avatar_constants', 3 );
</span><span class="cx">
</span><span class="cx"> function bp_core_set_avatar_globals() {
</span><del>-        global $bp;
</del><ins>+        $bp = buddypress();
</ins><span class="cx">
</span><span class="cx">         $bp->avatar = new stdClass;
</span><span class="cx">         $bp->avatar->thumb = new stdClass;
</span><span class="lines">@@ -87,14 +89,20 @@
</span><span class="cx"> * Fetches an avatar from a BuddyPress object. Supports user/group/blog as
</span><span class="cx"> * default, but can be extended to include your own custom components too.
</span><span class="cx"> *
</span><del>- * @global BuddyPress $bp The one true BuddyPress instance
</del><span class="cx"> * @global $current_blog WordPress global containing information and settings for the current blog being viewed.
</span><span class="cx"> * @param array $args Determine the output of this function
</span><span class="cx"> * @return string Formatted HTML <img> element, or raw avatar URL based on $html arg
</span><span class="cx"> */
</span><span class="cx"> function bp_core_fetch_avatar( $args = '' ) {
</span><del>-        global $bp, $current_blog;
</del><span class="cx">
</span><ins>+        // If avatars are disabled for the root site, obey that request and bail
+        if ( ! bp_get_option( 'show_avatars' ) )
+                return;
+
+        global $current_blog;
+
+        $bp = buddypress();
+
</ins><span class="cx">         // Set a few default variables
</span><span class="cx">         $def_object = 'user';
</span><span class="cx">         $def_type = 'thumb';
</span><span class="lines">@@ -372,11 +380,11 @@
</span><span class="cx">
</span><span class="cx">         // No avatar was found, and we've been told not to use a gravatar.
</span><span class="cx">         } else {
</span><del>-                $gravatar = apply_filters( "bp_core_default_avatar_$object", BP_PLUGIN_URL . 'bp-core/images/mystery-man.jpg', $params );
</del><ins>+                $gravatar = urlencode( apply_filters( "bp_core_default_avatar_$object", BP_PLUGIN_URL . 'bp-core/images/mystery-man.jpg', $params ) );
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         if ( true === $html )
</span><del>-                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 );
</del><ins>+                return apply_filters( 'bp_core_fetch_avatar', '<img src="' . esc_attr( $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 );
</ins><span class="cx">         else
</span><span class="cx">                 return apply_filters( 'bp_core_fetch_avatar_url', $gravatar );
</span><span class="cx"> }
</span><span class="lines">@@ -389,12 +397,10 @@
</span><span class="cx"> * object - the objetc type user, group, blog, etc.
</span><span class="cx"> * avatar_dir - The directory where the avatars to be uploaded.
</span><span class="cx"> *
</span><del>- * @global object $bp BuddyPress global settings
</del><span class="cx"> * @param mixed $args
</span><span class="cx"> * @return bool Success/failure
</span><span class="cx"> */
</span><span class="cx"> function bp_core_delete_existing_avatar( $args = '' ) {
</span><del>-        global $bp;
</del><span class="cx">
</span><span class="cx">         $defaults = array(
</span><span class="cx">                 'item_id' => false,
</span><span class="lines">@@ -409,7 +415,7 @@
</span><span class="cx">                 if ( 'user' == $object )
</span><span class="cx">                         $item_id = bp_displayed_user_id();
</span><span class="cx">                 else if ( 'group' == $object )
</span><del>-                        $item_id = $bp->groups->current_group->id;
</del><ins>+                        $item_id = buddypress()->groups->current_group->id;
</ins><span class="cx">                 else if ( 'blog' == $object )
</span><span class="cx">                         $item_id = $current_blog->id;
</span><span class="cx">
</span><span class="lines">@@ -458,7 +464,6 @@
</span><span class="cx"> * It then checks that the file size is within limits, and that it has an accepted file extension (jpg, gif, png).
</span><span class="cx"> * If everything checks out, crop the image and move it to its real location.
</span><span class="cx"> *
</span><del>- * @global object $bp BuddyPress global settings
</del><span class="cx"> * @param array $file The appropriate entry the from $_FILES superglobal.
</span><span class="cx"> * @param string $upload_dir_filter A filter to be applied to upload_dir
</span><span class="cx"> * @return bool Success/failure
</span><span class="lines">@@ -466,7 +471,6 @@
</span><span class="cx"> * @see bp_core_check_avatar_type()
</span><span class="cx"> */
</span><span class="cx"> function bp_core_avatar_handle_upload( $file, $upload_dir_filter ) {
</span><del>-        global $bp;
</del><span class="cx">
</span><span class="cx">         /***
</span><span class="cx">          * You may want to hook into this filter if you want to override this function.
</span><span class="lines">@@ -505,6 +509,8 @@
</span><span class="cx">         // Filter the upload location
</span><span class="cx">         add_filter( 'upload_dir', $upload_dir_filter, 10, 0 );
</span><span class="cx">
</span><ins>+        $bp = buddypress();
+
</ins><span class="cx">         $bp->avatar_admin->original = wp_handle_upload( $file['file'], array( 'action'=> 'bp_avatar_upload' ) );
</span><span class="cx">
</span><span class="cx">         // Move the file to the correct upload location.
</span><span class="lines">@@ -735,7 +741,7 @@
</span><span class="cx"> * @return string Absolute path to WP upload directory
</span><span class="cx"> */
</span><span class="cx"> function bp_core_avatar_upload_path() {
</span><del>-        global $bp;
</del><ins>+        $bp = buddypress();
</ins><span class="cx">
</span><span class="cx">         // See if the value has already been calculated and stashed in the $bp global
</span><span class="cx">         if ( isset( $bp->avatar->upload_path ) ) {
</span><span class="lines">@@ -781,7 +787,7 @@
</span><span class="cx"> * @return string Full URL to current upload location
</span><span class="cx"> */
</span><span class="cx"> function bp_core_avatar_url() {
</span><del>-        global $bp;
</del><ins>+        $bp = buddypress();
</ins><span class="cx">
</span><span class="cx">         // See if the value has already been calculated and stashed in the $bp global
</span><span class="cx">         if ( isset( $bp->avatar->url ) ) {
</span><span class="lines">@@ -849,8 +855,7 @@
</span><span class="cx"> * @return int $dim The dimension
</span><span class="cx"> */
</span><span class="cx"> function bp_core_avatar_dimension( $type = 'thumb', $h_or_w = 'height' ) {
</span><del>-        global $bp;
-
</del><ins>+        $bp = buddypress();
</ins><span class="cx">         $dim = isset( $bp->avatar->{$type}->{$h_or_w} ) ? (int) $bp->avatar->{$type}->{$h_or_w} : false;
</span><span class="cx">
</span><span class="cx">         return apply_filters( 'bp_core_avatar_dimension', $dim, $type, $h_or_w );
</span><span class="lines">@@ -913,9 +918,7 @@
</span><span class="cx"> * @return int The width
</span><span class="cx"> */
</span><span class="cx"> function bp_core_avatar_original_max_width() {
</span><del>-        global $bp;
-
-        return apply_filters( 'bp_core_avatar_original_max_width', (int) $bp->avatar->original_max_width );
</del><ins>+        return apply_filters( 'bp_core_avatar_original_max_width', (int) buddypress()->avatar->original_max_width );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -927,9 +930,7 @@
</span><span class="cx"> * @return int The filesize
</span><span class="cx"> */
</span><span class="cx"> function bp_core_avatar_original_max_filesize() {
</span><del>-        global $bp;
-
-        return apply_filters( 'bp_core_avatar_original_max_filesize', (int) $bp->avatar->original_max_filesize );
</del><ins>+        return apply_filters( 'bp_core_avatar_original_max_filesize', (int) buddypress()->avatar->original_max_filesize );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -941,9 +942,7 @@
</span><span class="cx"> * @return int The URL of the default avatar
</span><span class="cx"> */
</span><span class="cx"> function bp_core_avatar_default() {
</span><del>-        global $bp;
-
-        return apply_filters( 'bp_core_avatar_default', $bp->avatar->full->default );
</del><ins>+        return apply_filters( 'bp_core_avatar_default', buddypress()->avatar->full->default );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -955,7 +954,5 @@
</span><span class="cx"> * @return int The URL of the default avatar thumb
</span><span class="cx"> */
</span><span class="cx"> function bp_core_avatar_default_thumb() {
</span><del>-        global $bp;
-
-        return apply_filters( 'bp_core_avatar_thumb', $bp->avatar->thumb->default );
</del><ins>+        return apply_filters( 'bp_core_avatar_thumb', buddypress()->avatar->thumb->default );
</ins><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>