Version Description
- Added functionality to remove avatar
- Default image is Gravatar if it exists, else it will be the image selected from settings >> discussion
Download this release
Release Info
Developer | oltdev |
Plugin | User Avatar |
Version | 1.2 |
Comparing to | |
See all releases |
Version 1.2
- css/user-avatar.css +80 -0
- images/mystery-man-50.jpg +0 -0
- images/mystery-man.jpg +0 -0
- readme.txt +55 -0
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
- screenshot-3.png +0 -0
- screenshot-4.png +0 -0
- screenshot-5.png +0 -0
- screenshot-6.png +0 -0
- user-avatar.php +710 -0
css/user-avatar.css
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
Plugin Name: User Avatar
|
3 |
+
Plugin URI: http://wordpress.org/extend/plugins/user-avatar/
|
4 |
+
Description: Allows users to associate photos with their accounts by accessing their "Your Profile" page that default as Gravatar or WordPress Default image (from Discussion Page).
|
5 |
+
Version: 1.2.1
|
6 |
+
Author: Enej Bajgoric / Gagan Sandhu / CTLT DEV
|
7 |
+
|
8 |
+
|
9 |
+
GNU General Public License, Free Software Foundation <http://creativecommons.org/licenses/GPL/2.0/>
|
10 |
+
This program is free software; you can redistribute it and/or modify
|
11 |
+
it under the terms of the GNU General Public License as published by
|
12 |
+
the Free Software Foundation; either version 2 of the License, or
|
13 |
+
(at your option) any later version.
|
14 |
+
|
15 |
+
This program is distributed in the hope that it will be useful,
|
16 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
+
GNU General Public License for more details.
|
19 |
+
|
20 |
+
You should have received a copy of the GNU General Public License
|
21 |
+
along with this program; if not, write to the Free Software
|
22 |
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23 |
+
*/
|
24 |
+
|
25 |
+
#user-avatar-step1{
|
26 |
+
float:left;
|
27 |
+
margin-top: 15px;
|
28 |
+
margin-left:-200px;
|
29 |
+
}
|
30 |
+
#testWrap{
|
31 |
+
position: relative;
|
32 |
+
width:400px;
|
33 |
+
float:left;
|
34 |
+
}
|
35 |
+
#user-avatar-preview{
|
36 |
+
float:right;
|
37 |
+
width:200px;
|
38 |
+
}
|
39 |
+
#step1-image{
|
40 |
+
float:left;
|
41 |
+
margin: 15px 0px 0px 15px;
|
42 |
+
}
|
43 |
+
#user-avatar-display{
|
44 |
+
position:absolute;
|
45 |
+
background-color:#F1F1F1;
|
46 |
+
border-color:#E3E3E3;
|
47 |
+
top:525px;
|
48 |
+
right: 180px;
|
49 |
+
text-align: center;
|
50 |
+
margin: 0 auto;
|
51 |
+
padding: 0px 20px 20px 20px;
|
52 |
+
}
|
53 |
+
#user-avatar-display-image{
|
54 |
+
border:8px solid #FFFFFF;
|
55 |
+
}
|
56 |
+
#user-avatar-link{
|
57 |
+
float:left;
|
58 |
+
margin:0 0 10px 30px;
|
59 |
+
}
|
60 |
+
#user-avatar-remove{
|
61 |
+
float:left;
|
62 |
+
clear:left;
|
63 |
+
margin:0 0 0 18px;
|
64 |
+
}
|
65 |
+
#uploadForm{
|
66 |
+
margin-left:230px;
|
67 |
+
}
|
68 |
+
#iframe-crop-form{
|
69 |
+
margin-left:15px;
|
70 |
+
}
|
71 |
+
#user-avatar-step3{
|
72 |
+
margin-left:15px;
|
73 |
+
}
|
74 |
+
#user-avatar-step3-close{
|
75 |
+
float:left;
|
76 |
+
margin-top: 15px;
|
77 |
+
clear:both;
|
78 |
+
}
|
79 |
+
|
80 |
+
/* --- END OF FILE --- */
|
images/mystery-man-50.jpg
ADDED
Binary file
|
images/mystery-man.jpg
ADDED
Binary file
|
readme.txt
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== User Avatar ===
|
2 |
+
Contributors: sgagan, enej, oltdev
|
3 |
+
Tags: people lists, people, list, form, user profile, user avatar, thumbnail, upload photo, user, users, profile, biography, profile biography, user profile, description, profile description, rich text, wysiwyg, tinyMCE, photos, images, members, directory, profiles, jQuery, sortable, tabbable, thickbox, overlay, media button, Your Profile
|
4 |
+
Requires at least: 3.0
|
5 |
+
Tested up to: 3.0
|
6 |
+
Stable Tag: trunk
|
7 |
+
|
8 |
+
Provides a thumbnail area in Your Profile, for users to upload & crop new images in an overlay to be saved and stored to their profile.
|
9 |
+
|
10 |
+
== Description ==
|
11 |
+
|
12 |
+
This plugin provides a thumbnail area in the Your Profile section, where users can upload & crop new images in an overlay and upon cropping the image, the new image will be saved and stored. This gives users with any role the chance to easily upload an image and view their current thumbnail, all in one go. In Discussion, the default image associated with the user will be replaced with the user avatar image uploaded and this will then be the image shown in comments and also in People Lists (see below).
|
13 |
+
|
14 |
+
**This plugin was developed for [People Lists](http://wordpress.org/extend/plugins/people-lists/ "People Lists WordPress Plugin Homepage") and this plugin provides a rich text editor on the profile page for easy modifications of specific user profile information that can be displayed on any page using the [people-lists list=example-list] shortcode. Admins will also be able to add custom fields to the Your Profile section on Wordpress and these fields can be displayed on any page using the People Lists template (which can be styled using HTML) that provides codes for every field that is desired to be displayed. There is a specific code in People Lists that hooks this thumbnail into your lists template display, so grab People Lists plugin as well!!**
|
15 |
+
|
16 |
+
Take a look at the screenshots!
|
17 |
+
|
18 |
+
|
19 |
+
== Installation ==
|
20 |
+
|
21 |
+
1. Download the plugin package `user-avatar.zip`
|
22 |
+
1. Unzip the package and upload to the `/wp-content/plugins/` directory
|
23 |
+
1. Activate the plugin through the 'Plugins' menu in WordPress
|
24 |
+
|
25 |
+
== Screenshots ==
|
26 |
+
|
27 |
+
1. The user avatar thumbnail area in Your Profile.
|
28 |
+
2. Step 1: Upload an image
|
29 |
+
3. Step 2: Crop your image
|
30 |
+
4. Step 3: Image is ready
|
31 |
+
5. The user avatar thumbnail will change to your new image.
|
32 |
+
6. Newly updated remove user avatar button that defaults to Gravatar or default WordPress image chosen on Discussion Page.
|
33 |
+
|
34 |
+
== Changelog ==
|
35 |
+
|
36 |
+
= 1.2.1 =
|
37 |
+
* Fixed Error bug in comments
|
38 |
+
|
39 |
+
= 1.2 =
|
40 |
+
* Added functionality to remove avatar
|
41 |
+
* Default image is Gravatar if it exists, else it will be the image selected from settings >> discussion
|
42 |
+
|
43 |
+
= 0.5 =
|
44 |
+
* First Public Release
|
45 |
+
|
46 |
+
== Upgrade Notice ==
|
47 |
+
|
48 |
+
= Upgrade to version 1.2.1 =
|
49 |
+
* September 2nd, 2010
|
50 |
+
|
51 |
+
= Upgrade to version 1.2 =
|
52 |
+
* August 27th, 2010
|
53 |
+
|
54 |
+
= No Upgrades yet =
|
55 |
+
* August 1st, 2010
|
screenshot-1.png
ADDED
Binary file
|
screenshot-2.png
ADDED
Binary file
|
screenshot-3.png
ADDED
Binary file
|
screenshot-4.png
ADDED
Binary file
|
screenshot-5.png
ADDED
Binary file
|
screenshot-6.png
ADDED
Binary file
|
user-avatar.php
ADDED
@@ -0,0 +1,710 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: User Avatar
|
4 |
+
Plugin URI: http://wordpress.org/extend/plugins/user-avatar/
|
5 |
+
Description: Allows users to associate photos with their accounts by accessing their "Your Profile" page that default as Gravatar or WordPress Default image (from Discussion Page).
|
6 |
+
Version: 1.2.1
|
7 |
+
Author: Enej Bajgoric / Gagan Sandhu / CTLT DEV
|
8 |
+
|
9 |
+
|
10 |
+
GNU General Public License, Free Software Foundation <http://creativecommons.org/licenses/GPL/2.0/>
|
11 |
+
This program is free software; you can redistribute it and/or modify
|
12 |
+
it under the terms of the GNU General Public License as published by
|
13 |
+
the Free Software Foundation; either version 2 of the License, or
|
14 |
+
(at your option) any later version.
|
15 |
+
|
16 |
+
This program is distributed in the hope that it will be useful,
|
17 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
+
GNU General Public License for more details.
|
20 |
+
|
21 |
+
You should have received a copy of the GNU General Public License
|
22 |
+
along with this program; if not, write to the Free Software
|
23 |
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
24 |
+
*/
|
25 |
+
|
26 |
+
add_action('init', 'user_avatar_core_set_avatar_constants', 8 );
|
27 |
+
add_action('show_user_profile', 'user_avatar_form');
|
28 |
+
add_action('edit_user_profile', 'user_avatar_form');
|
29 |
+
add_action('wp_ajax_user_avatar_add_photo', 'user_avatar_add_photo');
|
30 |
+
add_action('user_avatar_iframe_head','user_avatar_init');
|
31 |
+
|
32 |
+
|
33 |
+
if($GLOBALS['pagenow'] == 'profile.php' or $GLOBALS['pagenow'] == 'user-edit.php') {
|
34 |
+
wp_enqueue_script("thickbox");
|
35 |
+
wp_enqueue_style("thickbox");
|
36 |
+
add_action( 'init', 'user_avatar_init');
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* user_avatar_init function.
|
41 |
+
* Description: Initializing user avatar style.
|
42 |
+
* @access public
|
43 |
+
* @return void
|
44 |
+
*/
|
45 |
+
function user_avatar_init(){
|
46 |
+
wp_enqueue_style('user-avatar', plugins_url('/user-avatar/css/user-avatar.css'), 'css');
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* user_avatar_core_set_avatar_constants function.
|
51 |
+
* Description: Establishing restraints on sizes of files and dimensions of images.
|
52 |
+
* Sets the default constants
|
53 |
+
* @access public
|
54 |
+
* @return void
|
55 |
+
*/
|
56 |
+
function user_avatar_core_set_avatar_constants() {
|
57 |
+
global $bp;
|
58 |
+
|
59 |
+
if ( !defined( 'USER_AVATAR_UPLOAD_PATH' ) )
|
60 |
+
define( 'USER_AVATAR_UPLOAD_PATH', user_avatar_core_avatar_upload_path() );
|
61 |
+
|
62 |
+
if ( !defined( 'USER_AVATAR_URL' ) )
|
63 |
+
define( 'USER_AVATAR_URL', user_avatar_core_avatar_url() );
|
64 |
+
|
65 |
+
if ( !defined( 'USER_AVATAR_THUMB_WIDTH' ) )
|
66 |
+
define( 'USER_AVATAR_THUMB_WIDTH', 50 );
|
67 |
+
|
68 |
+
if ( !defined( 'USER_AVATAR_THUMB_HEIGHT' ) )
|
69 |
+
define( 'USER_AVATAR_THUMB_HEIGHT', 50 );
|
70 |
+
|
71 |
+
if ( !defined( 'USER_AVATAR_FULL_WIDTH' ) )
|
72 |
+
define( 'USER_AVATAR_FULL_WIDTH', 150 );
|
73 |
+
|
74 |
+
if ( !defined( 'USER_AVATAR_FULL_HEIGHT' ) )
|
75 |
+
define( 'USER_AVATAR_FULL_HEIGHT', 150 );
|
76 |
+
|
77 |
+
if ( !defined( 'USER_AVATAR_ORIGINAL_MAX_FILESIZE' ) ) {
|
78 |
+
if ( !get_site_option( 'fileupload_maxk', 1500 ) )
|
79 |
+
define( 'USER_AVATAR_ORIGINAL_MAX_FILESIZE', 5120000 ); /* 5mb */
|
80 |
+
else
|
81 |
+
define( 'USER_AVATAR_ORIGINAL_MAX_FILESIZE', get_site_option( 'fileupload_maxk', 1500 ) * 1024 );
|
82 |
+
}
|
83 |
+
|
84 |
+
if ( !defined( 'USER_AVATAR_DEFAULT' ) )
|
85 |
+
define( 'USER_AVATAR_DEFAULT', plugins_url('/user-avatar/images/mystery-man.jpg') );
|
86 |
+
|
87 |
+
if ( !defined( 'USER_AVATAR_DEFAULT_THUMB' ) )
|
88 |
+
define( 'USER_AVATAR_DEFAULT_THUMB', plugins_url('/user-avatar/images/mystery-man-50.jpg') );
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* user_avatar_core_avatar_upload_path function.
|
93 |
+
* Description: Establishing upload path/area where images that are uploaded will be stored.
|
94 |
+
* @access public
|
95 |
+
* @return void
|
96 |
+
*/
|
97 |
+
function user_avatar_core_avatar_upload_path()
|
98 |
+
{
|
99 |
+
if( !file_exists(WP_CONTENT_DIR."/uploads/avatars/") )
|
100 |
+
mkdir(WP_CONTENT_DIR."/uploads/avatars/", 0777 ,true);
|
101 |
+
|
102 |
+
return WP_CONTENT_DIR."/uploads/avatars/";
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* user_avatar_core_avatar_url function.
|
107 |
+
* Description: Establishing the path of the core content avatar area.
|
108 |
+
* @access public
|
109 |
+
* @return void
|
110 |
+
*/
|
111 |
+
function user_avatar_core_avatar_url()
|
112 |
+
{
|
113 |
+
return WP_CONTENT_URL."/uploads/avatars/";
|
114 |
+
}
|
115 |
+
|
116 |
+
/**
|
117 |
+
* user_avatar_add_photo function.
|
118 |
+
* The content inside the iframe
|
119 |
+
* Description: Creating panels for the different steps users take to upload a file and checking their uploads.
|
120 |
+
* @access public
|
121 |
+
* @return void
|
122 |
+
*/
|
123 |
+
function user_avatar_add_photo() {
|
124 |
+
global $current_user;
|
125 |
+
|
126 |
+
|
127 |
+
if(($_GET['uid'] == $current_user->ID || is_super_admin($current_user->ID)) && is_numeric($_GET['uid']))
|
128 |
+
{
|
129 |
+
$uid = $_GET['uid'];
|
130 |
+
|
131 |
+
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
132 |
+
<html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
|
133 |
+
<head>
|
134 |
+
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
|
135 |
+
<title><?php bloginfo('name') ?> › <?php _e('Uploads'); ?> — <?php _e('WordPress'); ?></title>
|
136 |
+
<?php
|
137 |
+
|
138 |
+
wp_enqueue_style( 'global' );
|
139 |
+
wp_enqueue_style( 'wp-admin' );
|
140 |
+
wp_enqueue_style( 'colors' );
|
141 |
+
wp_enqueue_style( 'ie' );
|
142 |
+
|
143 |
+
wp_enqueue_style('imgareaselect');
|
144 |
+
wp_enqueue_script('imgareaselect');
|
145 |
+
do_action('user_avatar_iframe_head');
|
146 |
+
do_action('admin_print_styles');
|
147 |
+
do_action('admin_print_scripts');
|
148 |
+
do_action('admin_head');
|
149 |
+
?>
|
150 |
+
</head>
|
151 |
+
<body>
|
152 |
+
<?php
|
153 |
+
switch($_GET['step'])
|
154 |
+
{
|
155 |
+
case 1:
|
156 |
+
user_avatar_add_photo_step1($uid);
|
157 |
+
break;
|
158 |
+
|
159 |
+
case 2:
|
160 |
+
user_avatar_add_photo_step2($uid);
|
161 |
+
break;
|
162 |
+
|
163 |
+
case 3:
|
164 |
+
user_avatar_add_photo_step3($uid);
|
165 |
+
break;
|
166 |
+
}
|
167 |
+
|
168 |
+
do_action('admin_print_footer_scripts');
|
169 |
+
?>
|
170 |
+
<script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script>
|
171 |
+
</body>
|
172 |
+
</html>
|
173 |
+
<?php
|
174 |
+
}else {
|
175 |
+
wp_die("You are not allowed to do that.");
|
176 |
+
}
|
177 |
+
die();
|
178 |
+
}
|
179 |
+
|
180 |
+
/**
|
181 |
+
* user_avatar_add_photo_step1 function.
|
182 |
+
* The First Step in the process
|
183 |
+
* Description: Displays the users photo and they can choose to upload another if they please.
|
184 |
+
* @access public
|
185 |
+
* @param mixed $uid
|
186 |
+
* @return void
|
187 |
+
*/
|
188 |
+
function user_avatar_add_photo_step1($uid)
|
189 |
+
{
|
190 |
+
?>
|
191 |
+
<p id="step1-image" >
|
192 |
+
<?php
|
193 |
+
echo get_avatar( $uid , 150);
|
194 |
+
?>
|
195 |
+
</p>
|
196 |
+
<div id="user-avatar-step1">
|
197 |
+
<form enctype="multipart/form-data" id="uploadForm" method="POST" action="<?php echo admin_url('admin-ajax.php'); ?>?action=user_avatar_add_photo&step=2&uid=<?php echo $uid; ?>" >
|
198 |
+
<label for="upload"><?php _e('Choose an image from your computer:'); ?></label><br /><input type="file" id="upload" name="uploadedfile" />
|
199 |
+
<input type="hidden" name="action" value="save" />
|
200 |
+
<?php wp_nonce_field('user-avatar') ?>
|
201 |
+
<p class="submit"><input type="submit" value="<?php esc_attr_e('Upload'); ?>" /></p>
|
202 |
+
</form>
|
203 |
+
</div>
|
204 |
+
|
205 |
+
<?php
|
206 |
+
}
|
207 |
+
|
208 |
+
/**
|
209 |
+
* user_avatar_add_photo_step2 function.
|
210 |
+
* The Second Step in the process
|
211 |
+
* Description: Takes the uploaded photo and saves it to database.
|
212 |
+
* @access public
|
213 |
+
* @param mixed $uid
|
214 |
+
* @return void
|
215 |
+
*/
|
216 |
+
function user_avatar_add_photo_step2($uid)
|
217 |
+
{
|
218 |
+
check_admin_referer('user-avatar');
|
219 |
+
|
220 |
+
if (!(($_FILES["uploadedfile"]["type"] == "image/gif") || ($_FILES["uploadedfile"]["type"] == "image/jpeg") || ($_FILES["uploadedfile"]["type"] == "image/png") || ($_FILES["uploadedfile"]["type"] == "image/pjpeg") || ($_FILES["uploadedfile"]["type"] == "image/x-png"))){
|
221 |
+
echo "<div class='error'><p>Please upload an image file (.jpeg, .gif, .png).</p></div>";
|
222 |
+
user_avatar_add_photo_step1($uid);
|
223 |
+
die();
|
224 |
+
}
|
225 |
+
$overrides = array('test_form' => false);
|
226 |
+
$file = wp_handle_upload($_FILES['uploadedfile'], $overrides);
|
227 |
+
|
228 |
+
if ( isset($file['error']) ){
|
229 |
+
die( $file['error'] );
|
230 |
+
}
|
231 |
+
|
232 |
+
$url = $file['url'];
|
233 |
+
$type = $file['type'];
|
234 |
+
$file = $file['file'];
|
235 |
+
$filename = basename($file);
|
236 |
+
|
237 |
+
// Construct the object array
|
238 |
+
$object = array(
|
239 |
+
'post_title' => $filename,
|
240 |
+
'post_content' => $url,
|
241 |
+
'post_mime_type' => $type,
|
242 |
+
'guid' => $url);
|
243 |
+
|
244 |
+
// Save the data
|
245 |
+
list($width, $height, $type, $attr) = getimagesize( $file );
|
246 |
+
|
247 |
+
if ( $width > 500 ) {
|
248 |
+
$oitar = $width / 500;
|
249 |
+
$image = wp_crop_image($file, 0, 0, $width, $height, 500, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));
|
250 |
+
|
251 |
+
|
252 |
+
$url = str_replace(basename($url), basename($image), $url);
|
253 |
+
$width = $width / $oitar;
|
254 |
+
$height = $height / $oitar;
|
255 |
+
} else {
|
256 |
+
$oitar = 1;
|
257 |
+
}
|
258 |
+
|
259 |
+
|
260 |
+
?>
|
261 |
+
<form id="iframe-crop-form" method="POST" action="<?php echo admin_url('admin-ajax.php'); ?>?action=user_avatar_add_photo&step=3&uid=<?php echo $uid; ?>">
|
262 |
+
|
263 |
+
<h4><?php _e('Choose the part of the image you want to use as your profile image.'); ?></h4>
|
264 |
+
|
265 |
+
<div id="testWrap">
|
266 |
+
<img src="<?php echo $url; ?>" id="upload" width="<?php echo $width; ?>" height="<?php echo $height; ?>" />
|
267 |
+
</div>
|
268 |
+
<div id="user-avatar-preview">
|
269 |
+
<h4>Preview</h4>
|
270 |
+
<div id="preview" style="width: <?php echo USER_AVATAR_FULL_WIDTH; ?>px; height: <?php echo USER_AVATAR_FULL_HEIGHT; ?>px; overflow: hidden;">
|
271 |
+
<img src="<?php echo $url; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>">
|
272 |
+
</div>
|
273 |
+
<p class="submit" >
|
274 |
+
<input type="hidden" name="x1" id="x1" value="0" />
|
275 |
+
<input type="hidden" name="y1" id="y1" value="0" />
|
276 |
+
<input type="hidden" name="x2" id="x2" />
|
277 |
+
<input type="hidden" name="y2" id="y2" />
|
278 |
+
<input type="hidden" name="width" id="width" value="<?php echo $width ?>" />
|
279 |
+
<input type="hidden" name="height" id="height" value="<?php echo $height ?>" />
|
280 |
+
<input type="hidden" name="attachment_file" id="attachment_file" value="<?php echo esc_url($file); ?>" />
|
281 |
+
<input type="hidden" name="oitar" id="oitar" value="<?php echo esc_attr($oitar); ?>" />
|
282 |
+
<?php wp_nonce_field('user-avatar') ?>
|
283 |
+
<input type="submit" id="user-avatar-crop-button" value="<?php esc_attr_e('Crop Image'); ?>" /></p>
|
284 |
+
</div>
|
285 |
+
</form>
|
286 |
+
|
287 |
+
<script type="text/javascript">
|
288 |
+
|
289 |
+
function onEndCrop( coords ) {
|
290 |
+
jQuery( '#x1' ).val(coords.x);
|
291 |
+
jQuery( '#y1' ).val(coords.y);
|
292 |
+
jQuery( '#width' ).val(coords.w);
|
293 |
+
jQuery( '#height' ).val(coords.h);
|
294 |
+
}
|
295 |
+
|
296 |
+
jQuery(document).ready(function() {
|
297 |
+
var xinit = <?php echo USER_AVATAR_FULL_WIDTH; ?>;
|
298 |
+
var yinit = <?php echo USER_AVATAR_FULL_HEIGHT; ?>;
|
299 |
+
var ratio = xinit / yinit;
|
300 |
+
var ximg = jQuery('img#upload').width();
|
301 |
+
var yimg = jQuery('img#upload').height();
|
302 |
+
|
303 |
+
if ( yimg < yinit || ximg < xinit ) {
|
304 |
+
if ( ximg / yimg > ratio ) {
|
305 |
+
yinit = yimg;
|
306 |
+
xinit = yinit * ratio;
|
307 |
+
} else {
|
308 |
+
xinit = ximg;
|
309 |
+
yinit = xinit / ratio;
|
310 |
+
}
|
311 |
+
}
|
312 |
+
|
313 |
+
jQuery('img#upload').imgAreaSelect({
|
314 |
+
handles: true,
|
315 |
+
keys: true,
|
316 |
+
aspectRatio: xinit + ':' + yinit,
|
317 |
+
show: true,
|
318 |
+
x1: 0,
|
319 |
+
y1: 0,
|
320 |
+
x2: xinit,
|
321 |
+
y2: yinit,
|
322 |
+
//maxHeight: <?php echo USER_AVATAR_FULL_HEIGHT; ?>,
|
323 |
+
//maxWidth: <?php echo USER_AVATAR_FULL_WIDTH; ?>,
|
324 |
+
onInit: function () {
|
325 |
+
jQuery('#width').val(xinit);
|
326 |
+
jQuery('#height').val(yinit);
|
327 |
+
},
|
328 |
+
onSelectChange: function(img, c) {
|
329 |
+
jQuery('#x1').val(c.x1);
|
330 |
+
jQuery('#y1').val(c.y1);
|
331 |
+
jQuery('#width').val(c.width);
|
332 |
+
jQuery('#height').val(c.height);
|
333 |
+
|
334 |
+
|
335 |
+
|
336 |
+
if (!c.width || !c.height)
|
337 |
+
return;
|
338 |
+
|
339 |
+
var scaleX = <?php echo USER_AVATAR_FULL_WIDTH; ?> / c.width;
|
340 |
+
var scaleY = <?php echo USER_AVATAR_FULL_HEIGHT; ?> / c.height;
|
341 |
+
|
342 |
+
jQuery('#preview img').css({
|
343 |
+
width: Math.round(scaleX * <?php echo $width; ?>),
|
344 |
+
height: Math.round(scaleY * <?php echo $height; ?>),
|
345 |
+
marginLeft: -Math.round(scaleX * c.x1),
|
346 |
+
marginTop: -Math.round(scaleY * c.y1)
|
347 |
+
});
|
348 |
+
|
349 |
+
}
|
350 |
+
});
|
351 |
+
});
|
352 |
+
</script>
|
353 |
+
<?php
|
354 |
+
}
|
355 |
+
/**
|
356 |
+
* user_avatar_add_photo_step3 function.
|
357 |
+
* The Third Step in the Process
|
358 |
+
* Description: Deletes previous uploaded picture and creates a new cropped image in its place.
|
359 |
+
* @access public
|
360 |
+
* @param mixed $uid
|
361 |
+
* @return void
|
362 |
+
*/
|
363 |
+
function user_avatar_add_photo_step3($uid)
|
364 |
+
{
|
365 |
+
check_admin_referer('user-avatar');
|
366 |
+
|
367 |
+
if ( $_POST['oitar'] > 1 ) {
|
368 |
+
$_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
|
369 |
+
$_POST['y1'] = $_POST['y1'] * $_POST['oitar'];
|
370 |
+
$_POST['width'] = $_POST['width'] * $_POST['oitar'];
|
371 |
+
$_POST['height'] = $_POST['height'] * $_POST['oitar'];
|
372 |
+
}
|
373 |
+
|
374 |
+
if( !file_exists($_POST['attachment_file']) ) {
|
375 |
+
echo "<div class='error'><p>Sorry, No file available</p></div>";
|
376 |
+
return true;
|
377 |
+
}
|
378 |
+
|
379 |
+
$original_file = $_POST['attachment_file'];
|
380 |
+
|
381 |
+
$cropped_full = USER_AVATAR_UPLOAD_PATH."{$uid}/".time()."-bpfull.jpg";
|
382 |
+
$cropped_thumb = USER_AVATAR_UPLOAD_PATH."{$uid}/".time()."-bpthumb.jpg";
|
383 |
+
|
384 |
+
// delete the previous files
|
385 |
+
user_avatar_delete_files($uid);
|
386 |
+
|
387 |
+
if(!file_exists(USER_AVATAR_UPLOAD_PATH."{$uid}/"))
|
388 |
+
mkdir(USER_AVATAR_UPLOAD_PATH."{$uid}/");
|
389 |
+
|
390 |
+
// update the files
|
391 |
+
$cropped_full = wp_crop_image( $original_file, $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], USER_AVATAR_FULL_WIDTH, USER_AVATAR_FULL_HEIGHT, false, $cropped_full );
|
392 |
+
|
393 |
+
$cropped_thumb = wp_crop_image( $original_file, $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], USER_AVATAR_THUMB_WIDTH, USER_AVATAR_THUMB_HEIGHT, false, $cropped_thumb );
|
394 |
+
|
395 |
+
/* Remove the original */
|
396 |
+
@unlink( $original_file );
|
397 |
+
|
398 |
+
if ( is_wp_error( $cropped_full ) )
|
399 |
+
wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
|
400 |
+
?>
|
401 |
+
|
402 |
+
<script type="text/javascript">
|
403 |
+
self.parent.user_avatar_refresh_image('<?php echo get_avatar($uid, 150); ?>');
|
404 |
+
</script>
|
405 |
+
<div id="user-avatar-step3">
|
406 |
+
<h3>Here's your new profile picture...</h3>
|
407 |
+
<span style="float:left;">
|
408 |
+
<?php
|
409 |
+
echo get_avatar( $uid, 150);
|
410 |
+
?>
|
411 |
+
</span>
|
412 |
+
<a id="user-avatar-step3-close" class="button" onclick="self.parent.tb_remove();" >Close</a>
|
413 |
+
</div>
|
414 |
+
<?php
|
415 |
+
}
|
416 |
+
/**
|
417 |
+
* user_avatar_delete_files function.
|
418 |
+
* Description: Deletes the avatar files based on the user id.
|
419 |
+
* @access public
|
420 |
+
* @param mixed $uid
|
421 |
+
* @return void
|
422 |
+
*/
|
423 |
+
function user_avatar_delete_files($uid)
|
424 |
+
{
|
425 |
+
$avatar_folder_dir = USER_AVATAR_UPLOAD_PATH."{$uid}/";
|
426 |
+
if ( !file_exists( $avatar_folder_dir ) )
|
427 |
+
return false;
|
428 |
+
|
429 |
+
if ( $av_dir = opendir( $avatar_folder_dir ) ) {
|
430 |
+
while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
|
431 |
+
if ( ( preg_match( "/-bpfull/", $avatar_file ) || preg_match( "/-bpthumb/", $avatar_file ) ) && '.' != $avatar_file && '..' != $avatar_file )
|
432 |
+
@unlink( $avatar_folder_dir . '/' . $avatar_file );
|
433 |
+
}
|
434 |
+
}
|
435 |
+
closedir($av_dir);
|
436 |
+
|
437 |
+
@rmdir( $avatar_folder_dir );
|
438 |
+
|
439 |
+
}
|
440 |
+
|
441 |
+
/**
|
442 |
+
* Based on the
|
443 |
+
* user_avatar_core_fetch_avatar_filter() 1.2.5 BP
|
444 |
+
*
|
445 |
+
* Description: Attempts to filter get_avatar function and let Word/BuddyPress have a go at
|
446 |
+
* finding an avatar that may have been uploaded locally.
|
447 |
+
*
|
448 |
+
* @global array $authordata
|
449 |
+
* @param string $avatar The result of get_avatar from before-filter
|
450 |
+
* @param int|string|object $user A user ID, email address, or comment object
|
451 |
+
* @param int $size Size of the avatar image (thumb/full)
|
452 |
+
* @param string $default URL to a default image to use if no avatar is available
|
453 |
+
* @param string $alt Alternate text to use in image tag. Defaults to blank
|
454 |
+
* @return <type>
|
455 |
+
*/
|
456 |
+
function user_avatar_fetch_avatar_filter( $avatar, $user, $size, $default, $alt ) {
|
457 |
+
global $pagenow;
|
458 |
+
|
459 |
+
//If user is on discussion page, return $avatar
|
460 |
+
if($pagenow == "options-discussion.php")
|
461 |
+
return $avatar;
|
462 |
+
|
463 |
+
// If passed an object, assume $user->user_id
|
464 |
+
if ( is_object( $user ) )
|
465 |
+
$id = $user->user_id;
|
466 |
+
|
467 |
+
// If passed a number, assume it was a $user_id
|
468 |
+
else if ( is_numeric( $user ) )
|
469 |
+
$id = $user;
|
470 |
+
|
471 |
+
// If passed a string and that string returns a user, get the $id
|
472 |
+
else if ( is_string( $user ) && ( $user_by_email = get_user_by_email( $user ) ) )
|
473 |
+
$id = $user_by_email->ID;
|
474 |
+
|
475 |
+
// If somehow $id hasn't been assigned, return the result of get_avatar
|
476 |
+
if ( empty( $id ) )
|
477 |
+
return !empty( $avatar ) ? $avatar : $default;
|
478 |
+
|
479 |
+
// Let us handle the fetching of the avatar
|
480 |
+
$user_avatar = user_avatar_fetch_avatar( array( 'item_id' => $id, 'width' => $size, 'height' => $size, 'alt' => $alt ) );
|
481 |
+
|
482 |
+
// If we found an avatar, use it. If not, use the result of get_avatar
|
483 |
+
$avatar_folder_dir = USER_AVATAR_UPLOAD_PATH."{$id}/";
|
484 |
+
if ( file_exists( $avatar_folder_dir ) )
|
485 |
+
return $user_avatar;
|
486 |
+
// Otherwise, load the gravatar if it exists, or the selected default image from the Discussions page if not.
|
487 |
+
else if(!file_exists( $avatar_folder_dir )){
|
488 |
+
return $avatar;
|
489 |
+
}
|
490 |
+
}
|
491 |
+
|
492 |
+
add_filter( 'get_avatar', 'user_avatar_fetch_avatar_filter', 10, 5 );
|
493 |
+
|
494 |
+
/**
|
495 |
+
* user_avatar_core_fetch_avatar()
|
496 |
+
*
|
497 |
+
* Description: Fetches an avatar from a BuddyPress object. Supports user/group/blog as
|
498 |
+
* default, but can be extended to include your own custom components too.
|
499 |
+
*
|
500 |
+
* @global object $bp
|
501 |
+
* @global object $current_blog
|
502 |
+
* @param array $args Determine the output of this function
|
503 |
+
* @return string Formatted HTML <img> element, or raw avatar URL based on $html arg
|
504 |
+
*/
|
505 |
+
function user_avatar_fetch_avatar( $args = '' ) {
|
506 |
+
//var_dump($args);
|
507 |
+
$defaults = array(
|
508 |
+
'item_id' => false,
|
509 |
+
'object' => $def_object, // user/group/blog/custom type (if you use filters)
|
510 |
+
'type' => $def_type, // thumb or full
|
511 |
+
'avatar_dir' => false, // Specify a custom avatar directory for your object
|
512 |
+
'width' => false, // Custom width (int)
|
513 |
+
'height' => false, // Custom height (int)
|
514 |
+
'class' => $def_class, // Custom <img> class (string)
|
515 |
+
'css_id' => false, // Custom <img> ID (string)
|
516 |
+
'alt' => $def_alt, // Custom <img> alt (string)
|
517 |
+
'email' => false, // Pass the user email (for gravatar) to prevent querying the DB for it
|
518 |
+
'no_grav' => false, // If there is no avatar found, return false instead of a grav?
|
519 |
+
'html' => true // Wrap the return img URL in <img />
|
520 |
+
);
|
521 |
+
|
522 |
+
// Compare defaults to passed and extract
|
523 |
+
$params = wp_parse_args( $args, $defaults );
|
524 |
+
extract( $params, EXTR_SKIP );
|
525 |
+
|
526 |
+
$avatar_folder_dir = USER_AVATAR_UPLOAD_PATH."{$item_id}/";
|
527 |
+
$avatar_folder_url = USER_AVATAR_URL."{$item_id}";
|
528 |
+
if($width > 50)
|
529 |
+
$type = "full";
|
530 |
+
$avatar_size = ( 'full' == $type ) ? '-bpfull' : '-bpthumb';
|
531 |
+
|
532 |
+
|
533 |
+
// Add an identifying class to each item
|
534 |
+
$class .= ' ' . $object . '-' . $item_id . '-avatar';
|
535 |
+
|
536 |
+
// Set CSS ID if passed
|
537 |
+
if ( !empty( $css_id ) )
|
538 |
+
$css_id = " id=\"{$css_id}\"";
|
539 |
+
|
540 |
+
// Set avatar width
|
541 |
+
if ( $width )
|
542 |
+
$html_width = " width=\"{$width}\"";
|
543 |
+
else
|
544 |
+
$html_width = ( 'thumb' == $type ) ? ' width="' . USER_AVATAR_THUMB_WIDTH . '"' : ' width="' . USER_AVATAR_FULL_WIDTH . '"';
|
545 |
+
|
546 |
+
// Set avatar height
|
547 |
+
if ( $height )
|
548 |
+
$html_height = " height=\"{$height}\"";
|
549 |
+
else
|
550 |
+
$html_height = ( 'thumb' == $type ) ? ' height="' . USER_AVATAR_THUMB_HEIGHT . '"' : ' height="' . USER_AVATAR_FULL_HEIGHT . '"';
|
551 |
+
|
552 |
+
|
553 |
+
// Check for directory
|
554 |
+
if ( file_exists( $avatar_folder_dir ) ) {
|
555 |
+
|
556 |
+
// Open directory
|
557 |
+
if ( $av_dir = opendir( $avatar_folder_dir ) ) {
|
558 |
+
|
559 |
+
// Stash files in an array once to check for one that matches
|
560 |
+
$avatar_files = array();
|
561 |
+
while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
|
562 |
+
// Only add files to the array (skip directories)
|
563 |
+
if ( 2 < strlen( $avatar_file ) )
|
564 |
+
$avatar_files[] = $avatar_file;
|
565 |
+
}
|
566 |
+
|
567 |
+
// Check for array
|
568 |
+
if ( 0 < count( $avatar_files ) ) {
|
569 |
+
|
570 |
+
// Check for current avatar
|
571 |
+
if( is_array($avatar_files) ):
|
572 |
+
foreach( $avatar_files as $key => $value ) {
|
573 |
+
if ( strpos ( $value, $avatar_size )!== false )
|
574 |
+
$avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
|
575 |
+
}
|
576 |
+
endif;
|
577 |
+
|
578 |
+
}
|
579 |
+
}
|
580 |
+
|
581 |
+
// Close the avatar directory
|
582 |
+
closedir( $av_dir );
|
583 |
+
|
584 |
+
// If we found a locally uploaded avatar
|
585 |
+
if ( $avatar_url ) {
|
586 |
+
|
587 |
+
// Return it wrapped in an <img> element
|
588 |
+
if ( true === $html ) {
|
589 |
+
return '<img src="' . $avatar_url . '" alt="' . $alt . '" class="' . $class . '"' . $css_id . $html_width . $html_height . ' />';
|
590 |
+
// ...or only the URL
|
591 |
+
} else {
|
592 |
+
return $avatar_url ;
|
593 |
+
}
|
594 |
+
}
|
595 |
+
}
|
596 |
+
|
597 |
+
// Skips gravatar check if $no_grav is passed
|
598 |
+
if ( !$no_grav ) {
|
599 |
+
|
600 |
+
// Set gravatar size
|
601 |
+
if ( $width )
|
602 |
+
$grav_size = $width;
|
603 |
+
else if ( 'full' == $type )
|
604 |
+
$grav_size = USER_AVATAR_FULL_WIDTH;
|
605 |
+
else if ( 'thumb' == $type )
|
606 |
+
$grav_size = USER_AVATAR_THUMB_WIDTH;
|
607 |
+
|
608 |
+
// Set gravatar type
|
609 |
+
if ( empty( $bp->grav_default->{$object} ) )
|
610 |
+
$default_grav = 'wavatar';
|
611 |
+
else if ( 'mystery' == $bp->grav_default->{$object} )
|
612 |
+
$default_grav = apply_filters( 'bp_core_mysteryman_src', BP_AVATAR_DEFAULT, $grav_size );
|
613 |
+
else
|
614 |
+
$default_grav = $bp->grav_default->{$object};
|
615 |
+
|
616 |
+
// Set gravatar object
|
617 |
+
if ( empty( $email ) ) {
|
618 |
+
if ( 'user' == $object ) {
|
619 |
+
$email = bp_core_get_user_email( $item_id );
|
620 |
+
} else if ( 'group' == $object || 'blog' == $object ) {
|
621 |
+
$email = "{$item_id}-{$object}@{$bp->root_domain}";
|
622 |
+
}
|
623 |
+
}
|
624 |
+
|
625 |
+
// Set host based on if using ssl
|
626 |
+
if ( is_ssl() )
|
627 |
+
$host = 'https://secure.gravatar.com/avatar/';
|
628 |
+
else
|
629 |
+
$host = 'http://www.gravatar.com/avatar/';
|
630 |
+
|
631 |
+
// Filter gravatar vars
|
632 |
+
$email = apply_filters( 'bp_core_gravatar_email', $email, $item_id, $object );
|
633 |
+
$gravatar = apply_filters( 'bp_gravatar_url', $host ) . md5( strtolower( $email ) ) . '?d=' . $default_grav . '&s=' . $grav_size;
|
634 |
+
|
635 |
+
// Return gravatar wrapped in <img />
|
636 |
+
if ( true === $html )
|
637 |
+
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 );
|
638 |
+
|
639 |
+
// ...or only return the gravatar URL
|
640 |
+
else
|
641 |
+
return $gravatar;
|
642 |
+
|
643 |
+
} else {
|
644 |
+
return apply_filters( 'bp_core_fetch_avatar', false, $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
|
645 |
+
}
|
646 |
+
}
|
647 |
+
|
648 |
+
/**
|
649 |
+
* user_avatar_form function.
|
650 |
+
* Description: Creation and calling of appropriate functions on the overlay form.
|
651 |
+
* @access public
|
652 |
+
* @param mixed $profile
|
653 |
+
* @return void
|
654 |
+
*/
|
655 |
+
function user_avatar_form($profile)
|
656 |
+
{
|
657 |
+
global $current_user;
|
658 |
+
|
659 |
+
// Check if it is current user or super admin role
|
660 |
+
if(($profile->ID == $current_user->ID || is_super_admin($current_user->ID)))
|
661 |
+
{
|
662 |
+
$avatar_folder_dir = USER_AVATAR_UPLOAD_PATH."{$profile->ID}/";
|
663 |
+
|
664 |
+
// Remove the User-Avatar button if there is no uploaded image
|
665 |
+
if ( !file_exists( $avatar_folder_dir ) ){
|
666 |
+
?> <style type="text/css">#user-avatar-remove{display:none;}</style>
|
667 |
+
<?php
|
668 |
+
}
|
669 |
+
|
670 |
+
// If user clicks the remove avatar button, in URL deleter_avatar=true
|
671 |
+
if(isset($_GET['delete_avatar']))
|
672 |
+
{
|
673 |
+
$avatar_folder_dir = USER_AVATAR_UPLOAD_PATH."{$profile->ID}/";
|
674 |
+
|
675 |
+
// Redirect to profile.php if user does not have uploaded images
|
676 |
+
if ( !file_exists( $avatar_folder_dir ) ){
|
677 |
+
wp_redirect(get_option('siteurl') . '/wp-admin/profile.php');
|
678 |
+
}
|
679 |
+
// If user has an uploaded User Avatar, delete the directory is associated with their uploaded avatars
|
680 |
+
else{
|
681 |
+
if ( $av_dir = opendir( $avatar_folder_dir ) ) {
|
682 |
+
while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
|
683 |
+
if ( ( preg_match( "/-bpfull/", $avatar_file ) || preg_match( "/-bpthumb/", $avatar_file ) ) && '.' != $avatar_file && '..' != $avatar_file )
|
684 |
+
@unlink( $avatar_folder_dir . '/' . $avatar_file );
|
685 |
+
}
|
686 |
+
}
|
687 |
+
closedir($av_dir);
|
688 |
+
|
689 |
+
@rmdir( $avatar_folder_dir );
|
690 |
+
}
|
691 |
+
}
|
692 |
+
|
693 |
+
?>
|
694 |
+
<div id="user-avatar-display" >
|
695 |
+
<h3>Picture</h3>
|
696 |
+
<p id="user-avatar-display-image"><?php echo get_avatar($profile->ID, 150); ?></p>
|
697 |
+
<a id="user-avatar-link" class="button thickbox" href="<?php echo admin_url('admin-ajax.php'); ?>?action=user_avatar_add_photo&step=1&uid=<?php echo $profile->ID; ?>&TB_iframe=true&width=720&height=450" title="Upload and Crop an Image to be Displayed" >Change Picture</a>
|
698 |
+
<a id="user-avatar-remove" class="button" href="?delete_avatar=true" title="Remove User Avatar Image" >Remove User Avatar</a>
|
699 |
+
</div>
|
700 |
+
<script>
|
701 |
+
function user_avatar_refresh_image(img){
|
702 |
+
jQuery('#user-avatar-display-image').html(img);
|
703 |
+
}
|
704 |
+
</script>
|
705 |
+
<?php
|
706 |
+
}
|
707 |
+
}
|
708 |
+
|
709 |
+
/* --- END OF FILE --- */
|
710 |
+
?>
|