User Photo - Version 0.7

Version Description

Download this release

Release Info

Developer westonruter
Plugin Icon wp plugin User Photo
Version 0.7
Comparing to
See all releases

Version 0.7

Files changed (3) hide show
  1. admin.css +54 -0
  2. readme.txt +25 -0
  3. user-photo.php +585 -0
admin.css ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ #userphoto-status-pending {
4
+ background-color:yellow;
5
+ padding:3px;
6
+ }
7
+ #userphoto-upload-error,
8
+ #userphoto-status-rejected {
9
+ color:red;
10
+ }
11
+
12
+ #userphoto .field-hint {
13
+ color:gray;
14
+ font-size:smaller
15
+ }
16
+ #userphoto_delete {
17
+ width:auto !important;
18
+ }
19
+ #userphoto-approvalstatus-controls.pending label {
20
+ background-color:yellow;
21
+ /*padding:3px;*/
22
+ padding:4px 0 4px 5px;
23
+ }
24
+
25
+ #userphoto_level_moderated option.none,
26
+ #userphoto_admin_notified option.none {
27
+ font-style:italic;
28
+ }
29
+
30
+ #userphoto p.image {
31
+ border:solid 1px #CCC;
32
+ text-align:center;
33
+ padding:3px;
34
+ float:left;
35
+ margin-right:20px;
36
+ margin-bottom:0;
37
+ }
38
+ #userphoto hr {
39
+ clear:both;
40
+ margin:0;
41
+ padding:0;
42
+ height:1px;
43
+ visibility:hidden;
44
+ }
45
+
46
+ #userphoto p.image img {
47
+ /*padding:2px;*/
48
+ border:solid 1px #CCC;
49
+ }
50
+
51
+ #userphoto_options_form input[type=number],
52
+ #userphoto_options_form input[type=range]{
53
+ text-align:right;
54
+ }
readme.txt ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Plugin Name ===
2
+ Contributors: westonruter
3
+ Tags: users, photos, images
4
+ Tested up to: 2.3.1
5
+ Stable tag: 0.7
6
+
7
+ Allows a user to associate a photo with their account and for this photo to be displayed in their posts and comments.
8
+
9
+ == Description ==
10
+
11
+ Allows users to associate photos with their accounts by accessing their "Your Profile" page. Admins may
12
+ add a user photo by accessing the "Edit User" page. Uploaded images are resized to fit the dimensions specified
13
+ on the options page; a thumbnail image is also generated. New template tags introduced are:
14
+
15
+ * <code>the_author_photo()</code>
16
+ * <code>the_author_thumbnail()</code>
17
+ * <code>comment_author_photo()</code>
18
+ * <code>comment_author_thumbnail()</code>
19
+
20
+ Uploaded images may be moderated by administrators via the "Edit User" page.
21
+
22
+ == Todo ==
23
+ 1. Add a management page to allow admins to quickly approve/reject user photos.
24
+ 1. Add option so that when a photo is rejected, the user is notified.
25
+ 1. Restrict image types acceptable?
user-photo.php ADDED
@@ -0,0 +1,585 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ Plugin Name: User Photo
5
+ Plugin URI: http://wordpress.org/extend/plugins/user-photo/
6
+ Description: Allows users to associate photos with their accounts by accessing their "Your Profile" page. Uploaded images are resized to fit the dimensions specified on the options page; a thumbnail image is also generated. New template tags introduced are: <code>the_author_photo</code>, <code>the_author_thumbnail</code>, <code>comment_author_photo</code>, and <code>comment_author_thumbnail</code>. Uploaded images may be moderated by administrators.
7
+ Author: Weston Ruter
8
+ Version: 0.7
9
+ Author URI: http://weston.ruter.net/
10
+
11
+ */
12
+
13
+ if(!function_exists('imagecopyresampled'))
14
+ trigger_error(__("Plugin not usable on this system because image resizing is not available, specifically the imagecopyresampled() and related functions.", 'userphoto'), E_USER_ERROR);
15
+
16
+
17
+ $userphoto_validtypes = array(
18
+ "image/jpeg" => true,
19
+ "image/pjpeg" => true,
20
+ "image/gif" => true,
21
+ "image/png" => true,
22
+ "image/x-png" => true
23
+ );
24
+
25
+ define('USERPHOTO_PENDING', 0);
26
+ define('USERPHOTO_REJECTED', 1);
27
+ define('USERPHOTO_APPROVED', 2);
28
+ #define('USERPHOTO_DEFAULT_MAX_DIMENSION', 150);
29
+ #define('USERPHOTO_DEFAULT_THUMB_DIMENSION', 80);
30
+ #define('USERPHOTO_DEFAULT_JPEG_COMPRESSION', 90);
31
+ #define('USERPHOTO_DEFAULT_LEVEL_MODERATED', 2);
32
+
33
+ add_option("userphoto_jpeg_compression", 90);
34
+ add_option("userphoto_maximum_dimension", 150);
35
+ add_option("userphoto_thumb_dimension", 80);
36
+ add_option("userphoto_admin_notified", 0); //0 means disable
37
+ add_option("userphoto_level_moderated", 2); //Note: -1 means disable
38
+
39
+ function get_the_author_photo($user_id = false){
40
+ global $authordata;
41
+ global $comment;
42
+ if(!$user_id){
43
+ if(isset($comment) && $comment->user_id)
44
+ $user_id = $comment->user_id;
45
+ else if(isset($authordata))
46
+ $user_id = $authordata->ID;
47
+ else trigger_error("Unable to discern user ID.");
48
+ }
49
+ if(($userdata = get_userdata($user_id)) && $userdata->userphoto_image_file){
50
+ print '<img src="' . get_option('home') . '/wp-content/uploads/userphoto/' . $userdata->userphoto_image_file . '"';
51
+ print ' alt="' . htmlspecialchars($userdata->display_name) . '"';
52
+ print ' width="' . htmlspecialchars($userdata->userphoto_image_width) . '"';
53
+ print ' height="' . htmlspecialchars($userdata->userphoto_image_height) . '"';
54
+ print " />";
55
+ }
56
+ }
57
+ function get_the_author_thumbnail($user_id){
58
+ global $authordata;
59
+ global $comment;
60
+ if(!$user_id){
61
+ if(isset($comment) && $comment->user_id)
62
+ $user_id = $comment->user_id;
63
+ else if(isset($authordata))
64
+ $user_id = $authordata->ID;
65
+ else trigger_error("Unable to discern user ID.");
66
+ }
67
+ if(($userdata = get_userdata($user_id)) && $userdata->userphoto_thumb_file){
68
+ print '<img src="' . get_option('home') . '/wp-content/uploads/userphoto/' . $userdata->userphoto_thumb_file . '"';
69
+ print ' alt="' . htmlspecialchars($userdata->display_name) . '"';
70
+ print ' width="' . htmlspecialchars($userdata->userphoto_thumb_width) . '"';
71
+ print ' height="' . htmlspecialchars($userdata->userphoto_thumb_height) . '"';
72
+ print " />";
73
+ }
74
+ }
75
+
76
+ function comment_author_photo(){
77
+ global $comment;
78
+ echo get_the_author_photo($comment->user_id);
79
+ }
80
+ function comment_author_thumbnail(){
81
+ global $comment;
82
+ echo get_the_author_thumbnail($comment->user_id);
83
+ }
84
+ function the_author_photo(){
85
+ global $authordata;
86
+ echo get_the_author_photo($authordata->ID);
87
+ }
88
+ function the_author_thumbnail(){
89
+ global $authordata;
90
+ echo get_the_author_thumbnail($authordata->ID);
91
+ }
92
+
93
+
94
+ function userphoto_profile_update($userID){
95
+ global $userphoto_validtypes;
96
+ global $current_user;
97
+
98
+ $userdata = get_userdata($userID);
99
+
100
+ #Delete photo
101
+ if(@$_POST['userphoto_delete']){
102
+ delete_usermeta($userID, "userphoto_error");
103
+ if($userdata->userphoto_image_file){
104
+ $imagepath = ABSPATH . "/wp-content/uploads/userphoto/" . basename($userdata->userphoto_image_file);
105
+ $thumbpath = ABSPATH . "/wp-content/uploads/userphoto/" . basename($userdata->userphoto_image_file);
106
+
107
+ if(file_exists($imagepath) && !@unlink($imagepath)){
108
+ update_usermeta($userID, 'userphoto_error', __("Unable to delete photo.", 'userphoto'));
109
+ }
110
+ else {
111
+ delete_usermeta($userID, "userphoto_image_file");
112
+ delete_usermeta($userID, "userphoto_approvalstatus");
113
+ delete_usermeta($userID, "userphoto_image_width");
114
+ delete_usermeta($userID, "userphoto_image_height");
115
+ }
116
+ }
117
+ }
118
+ #Upload photo or change approval status
119
+ else {
120
+ #Upload the file
121
+ if(isset($_FILES['userphoto_image_file']) && @$_FILES['userphoto_image_file']['name']){
122
+
123
+ #Upload error
124
+ $error = '';
125
+ if($_FILES['userphoto_image_file']['error']){
126
+ switch($_FILES['userphoto_image_file']['error']){
127
+ case UPLOAD_ERR_INI_SIZE:
128
+ case UPLOAD_ERR_FORM_SIZE:
129
+ $error = __("The uploaded file exceeds the max upload size.", 'userphoto');
130
+ break;
131
+ case UPLOAD_ERR_PARTIAL:
132
+ $error = __("The uploaded file was only partially uploaded.", 'userphoto');
133
+ break;
134
+ case UPLOAD_ERR_NO_FILE:
135
+ $error = __("No file was uploaded.", 'userphoto');
136
+ break;
137
+ case UPLOAD_ERR_NO_TMP_DIR:
138
+ $error = __("Missing a temporary folder.", 'userphoto');
139
+ break;
140
+ case UPLOAD_ERR_CANT_WRITE:
141
+ $error = __("Failed to write file to disk.", 'userphoto');
142
+ break;
143
+ case UPLOAD_ERR_EXTENSION:
144
+ $error = __("File upload stopped by extension.", 'userphoto');
145
+ break;
146
+ default:
147
+ $error = __("File upload failed due to unknown error.", 'userphoto');
148
+ }
149
+ }
150
+ else if(!$_FILES['userphoto_image_file']['size'])
151
+ $error = sprintf(__("The file &ldquo;%s&rdquo; was not uploaded. Did you provide the correct filename?", 'userphoto'), $_FILES['userphoto_image_file']['name']);
152
+ else if(@!$userphoto_validtypes[$_FILES['userphoto_image_file']['type']]) //!preg_match("/\.(" . join('|', $userphoto_validextensions) . ")$/i", $_FILES['userphoto_image_file']['name'])) ||
153
+ $error = sprintf(__("The uploaded file type &ldquo;%s&rdquo; is not allowed.", 'userphoto'), $_FILES['userphoto_image_file']['type']);
154
+
155
+ $tmppath = $_FILES['userphoto_image_file']['tmp_name'];
156
+
157
+ $imageinfo = null;
158
+ $thumbinfo = null;
159
+ if(!$error){
160
+ $userphoto_maximum_dimension = get_option( 'userphoto_maximum_dimension' );
161
+ #if(empty($userphoto_maximum_dimension))
162
+ # $userphoto_maximum_dimension = USERPHOTO_DEFAULT_MAX_DIMENSION;
163
+
164
+ $imageinfo = getimagesize($tmppath);
165
+ if(!$imageinfo || !$imageinfo[0] || !$imageinfo[1])
166
+ $error = __("Unable to get image dimensions.", 'userphoto');
167
+ else if($imageinfo[0] > $userphoto_maximum_dimension || $imageinfo[1] > $userphoto_maximum_dimension){
168
+ if(userphoto_resize_image($tmppath, null, $userphoto_maximum_dimension, $error))
169
+ $imageinfo = getimagesize($tmppath);
170
+ }
171
+
172
+ //else if($imageinfo[0] > $userphoto_maximum_dimension)
173
+ // $error = sprintf(__("The uploaded image had a width of %d pixels. The max width is %d.", 'userphoto'), $imageinfo[0], $userphoto_maximum_dimension);
174
+ //else if($imageinfo[0] > $userphoto_maximum_dimension)
175
+ // $error = sprintf(__("The uploaded image had a height of %d pixels. The max height is %d.", 'userphoto'), $imageinfo[1], $userphoto_maximum_dimension);
176
+ }
177
+
178
+ if(!$error){
179
+ $dir = ABSPATH . "/wp-content/uploads/userphoto";
180
+ #$umask = umask(0);
181
+ if(!file_exists($dir) && !mkdir($dir, 0777))
182
+ $error = __("The userphoto upload content directory does not exist and could not be created.", 'userphoto');
183
+ #umask($umask);
184
+
185
+ if(!$error){
186
+ #$oldFile = basename($userdata->userphoto_image_file);
187
+ $imagefile = preg_replace('/^.+(?=\.\w+$)/', $userdata->user_nicename, $_FILES['userphoto_image_file']['name']);
188
+ $imagepath = $dir . '/' . $imagefile;
189
+ $thumbfile = preg_replace("/(?=\.\w+$)/", '.thumbnail', $imagefile);
190
+ $thumbpath = $dir . '/' . $thumbfile;
191
+
192
+ if(!move_uploaded_file($tmppath, $imagepath)){
193
+ $error = __("Unable to move the file to the user photo upload content directory.", 'userphoto');
194
+ }
195
+ else {
196
+ #Generate thumbnail
197
+ $userphoto_thumb_dimension = get_option( 'userphoto_thumb_dimension' );
198
+ #if(empty($userphoto_thumb_dimension))
199
+ # $userphoto_thumb_dimension = USERPHOTO_DEFAULT_THUMB_DIMENSION;
200
+ if(!($userphoto_thumb_dimension >= $imageinfo[0] && $userphoto_thumb_dimension >= $imageinfo[1])){
201
+ userphoto_resize_image($imagepath, $thumbpath, $userphoto_thumb_dimension, $error);
202
+ }
203
+ else {
204
+ copy($imagepath, $thumbpath);
205
+ }
206
+ $thumbinfo = getimagesize($thumbpath);
207
+
208
+ #Update usermeta
209
+ if($current_user->user_level <= get_option('userphoto_level_moderated') ){
210
+ update_usermeta($userID, "userphoto_approvalstatus", USERPHOTO_PENDING);
211
+
212
+ $admin_notified = get_option('userphoto_admin_notified');
213
+ if($admin_notified){
214
+ $admin = get_userdata($admin_notified);
215
+ @mail($admin->user_email,
216
+ "User Photo for " . $userdata->display_name . " Needs Approval",
217
+ get_option("home") . "/wp-admin/user-edit.php?user_id=" . $userdata->ID . "#userphoto");
218
+ }
219
+ }
220
+ else {
221
+ update_usermeta($userID, "userphoto_approvalstatus", USERPHOTO_APPROVED);
222
+ }
223
+ update_usermeta($userID, "userphoto_image_file", $imagefile); //TODO: use userphoto_image
224
+ update_usermeta($userID, "userphoto_image_width", $imageinfo[0]); //TODO: use userphoto_image_width
225
+ update_usermeta($userID, "userphoto_image_height", $imageinfo[1]);
226
+ update_usermeta($userID, "userphoto_thumb_file", $thumbfile);
227
+ update_usermeta($userID, "userphoto_thumb_width", $thumbinfo[0]);
228
+ update_usermeta($userID, "userphoto_thumb_height", $thumbinfo[1]);
229
+
230
+ #if($oldFile && $oldFile != $newFile)
231
+ # @unlink($dir . '/' . $oldFile);
232
+ }
233
+ }
234
+ }
235
+ }
236
+
237
+ #Set photo approval status
238
+ if($current_user->has_cap('edit_users') &&
239
+ array_key_exists('userphoto_approvalstatus', $_POST) &&
240
+ in_array((int)$_POST['userphoto_approvalstatus'], array(USERPHOTO_PENDING, USERPHOTO_REJECTED, USERPHOTO_APPROVED))
241
+ ){
242
+ update_usermeta($userID, "userphoto_approvalstatus", (int)$_POST['userphoto_approvalstatus']);
243
+ if((int)$_POST['userphoto_approvalstatus'] == USERPHOTO_REJECTED)
244
+ update_usermeta($userID, "userphoto_rejectionreason", $_POST['userphoto_rejectionreason']);
245
+ else
246
+ delete_usermeta($userID, "userphoto_rejectionreason");
247
+ }
248
+ }
249
+
250
+ if($error)
251
+ update_usermeta($userID, 'userphoto_error', $error);
252
+ else
253
+ delete_usermeta($userID, "userphoto_error");
254
+ }
255
+ add_action('profile_update', 'userphoto_profile_update');
256
+ #add_action('personal_options_update', ???);
257
+
258
+ #QUESTION: Should we store a serialized datastructure in the usermeta...
259
+ # Width, height, size, filename/path
260
+
261
+
262
+ function userphoto_delete_user($userID){
263
+ $userdata = get_userdata($userID);
264
+ if($userdata->userphoto_image_file)
265
+ @unlink(ABSPATH . "/wp-content/uploads/userphoto/" . basename($userdata->userphoto_image_file));
266
+ if($userdata->userphoto_thumb_file)
267
+ @unlink(ABSPATH . "/wp-content/uploads/userphoto/" . basename($userdata->userphoto_thumb_file));
268
+ }
269
+ add_action('delete_user', 'userphoto_delete_user');
270
+
271
+
272
+ function userphoto_admin_useredit_head(){
273
+ if(preg_match("/(user-edit\.php|profile.php)$/", $_SERVER['PHP_SELF']))
274
+ print '<link rel="stylesheet" href="../wp-content/plugins/userphoto/admin.css" />';
275
+ }
276
+ function userphoto_admin_options_head(){
277
+ print '<link rel="stylesheet" href="../wp-content/plugins/userphoto/admin.css" />';
278
+ }
279
+
280
+ add_action('admin_head-options_page_userphoto/userphoto', 'userphoto_admin_options_head');
281
+ add_action('admin_head', 'userphoto_admin_useredit_head');
282
+ #add_action('admin_head-userphoto', 'userphoto_admin_head');
283
+
284
+ function userphoto_display_selector_fieldset(){
285
+ #NOTE: an email needs to be sent to the admin when a contributor uploads a photo
286
+
287
+ global $profileuser;
288
+ global $current_user;
289
+ global $userphoto_error;
290
+
291
+ $isSelf = $profileuser->ID == $current_user->ID;
292
+
293
+ #if($isSelf)
294
+ # $userdata = get_userdata($profileuser->ID);
295
+ #else
296
+ # $userdata = get_userdata($current_user->ID);
297
+
298
+ #$userphoto = unserialize($userdata->userphoto);
299
+
300
+ ?>
301
+ <fieldset id='userphoto'>
302
+ <script type="text/javascript">
303
+ var form = document.getElementById('your-profile');
304
+ //form.enctype = "multipart/form-data"; //FireFox, Opera, et al
305
+ form.encoding = "multipart/form-data"; //IE5.5
306
+ form.setAttribute('enctype', 'multipart/form-data'); //required for IE6 (is interpreted into "encType")
307
+
308
+ function userphoto_onclick(){
309
+ var is_delete = document.getElementById('userphoto_delete').checked;
310
+ document.getElementById('userphoto_image_file').disabled = is_delete;
311
+
312
+ if(document.getElementById('userphoto_approvalstatus'))
313
+ document.getElementById('userphoto_approvalstatus').disabled = is_delete;
314
+ if(document.getElementById('userphoto_rejectionreason'))
315
+ document.getElementById('userphoto_rejectionreason').disabled = is_delete;
316
+ }
317
+ function userphoto_approvalstatus_onchange(){
318
+ var select = document.getElementById('userphoto_approvalstatus');
319
+ document.getElementById('userphoto_rejectionreason').style.display = (select.options[select.selectedIndex].value == <?php echo USERPHOTO_REJECTED ?> ? 'block' : 'none');
320
+ }
321
+ <?php if($profileuser->userphoto_error && @$_POST['action'] == 'update'): ?>
322
+ window.location = "#userphoto";
323
+ <?php endif; ?>
324
+
325
+ </script>
326
+ <legend><?php echo $isSelf ? _e("Your Photo", 'userphoto') : _e("User Photo", 'userphoto') ?></legend>
327
+ <?php if($profileuser->userphoto_image_file): ?>
328
+ <p class='image'><img src="<?php echo get_option('home') . '/wp-content/uploads/userphoto/' . $profileuser->userphoto_image_file . "?" . rand() ?>" alt="Full size image" /><br />
329
+ Full size
330
+ </p>
331
+ <p class='image'><img src="<?php echo get_option('home') . '/wp-content/uploads/userphoto/' . $profileuser->userphoto_thumb_file . "?" . rand() ?>" alt="Thumbnail image" /><br />
332
+ Thumb
333
+ </p>
334
+ <hr />
335
+
336
+ <?php if(!$current_user->has_cap('edit_users')): ?>
337
+ <?php if($profileuser->userphoto_approvalstatus == USERPHOTO_PENDING): ?>
338
+ <p id='userphoto-status-pending'><?php echo _e("Your profile photo has been submitted for review.", 'userphoto') ?></p>
339
+ <?php elseif($profileuser->userphoto_approvalstatus == USERPHOTO_REJECTED): ?>
340
+ <p id='userphoto-status-rejected'><strong>Notice: </strong> <?php _e("Your chosen profile photo has been rejected.", 'userphoto') ?>
341
+ <?php
342
+ if($profileuser->userphoto_rejectionreason){
343
+ _e("Reason: ", 'userphoto');
344
+ echo htmlspecialchars($profileuser->userphoto_rejectionreason);
345
+ }
346
+ ?>
347
+ </p>
348
+ <?php endif; ?>
349
+ <?php endif; ?>
350
+ <?php endif; ?>
351
+
352
+ <?php if($profileuser->userphoto_error): ?>
353
+ <p id='userphoto-upload-error'><strong>Upload error:</strong> <?php echo $profileuser->userphoto_error ?></p>
354
+ <?php endif; ?>
355
+ <p id='userphoto_image_file_control'>
356
+ <label><?php echo _e("Upload image file:", 'userphoto') ?>
357
+ <span class='field-hint'>(<?php
358
+ //if(!get_option('userphoto_autoresize'))
359
+ // printf(__("max dimensions %d&times;%d;"), get_option('userphoto_maximum_dimension'), get_option('userphoto_maximum_dimension'));
360
+ printf(__("max upload size %s"),ini_get("upload_max_filesize"));
361
+ ?>)</span>
362
+ <input type="file" name="userphoto_image_file" id="userphoto_image_file" /></label>
363
+ </p>
364
+ <!--<em>or</em>
365
+ <label for="uphoto-fileURL">Image URL: </label><input type="url" name="uphoto-fileURL" id="uphoto-fileURL" value="http://" /><br />-->
366
+ <?php if($current_user->has_cap('edit_users') && ($profileuser->ID != $current_user->ID) && $profileuser->userphoto_image_file): ?>
367
+ <p id="userphoto-approvalstatus-controls" <?php if($profileuser->userphoto_approvalstatus == USERPHOTO_PENDING) echo "class='pending'" ?>>
368
+ <label><?php _e("Approval status:", 'userphoto') ?>
369
+ <select name="userphoto_approvalstatus" id="userphoto_approvalstatus" onchange="userphoto_approvalstatus_onchange()">
370
+ <option value="<?php echo USERPHOTO_PENDING ?>" <?php if($profileuser->userphoto_approvalstatus == USERPHOTO_PENDING) echo " selected='selected' " ?>><?php _e("pending", 'userphoto') ?></option>
371
+ <option value="<?php echo USERPHOTO_REJECTED ?>" <?php if($profileuser->userphoto_approvalstatus == USERPHOTO_REJECTED) echo " selected='selected' " ?>><?php _e("rejected", 'userphoto') ?></option>
372
+ <option value="<?php echo USERPHOTO_APPROVED ?>" <?php if($profileuser->userphoto_approvalstatus == USERPHOTO_APPROVED) echo " selected='selected' " ?>><?php _e("approved", 'userphoto') ?></option>
373
+ </select></label><br /><textarea name="userphoto_rejectionreason" <?php
374
+ if($profileuser->userphoto_approvalstatus != USERPHOTO_REJECTED)
375
+ echo ' style="display:none"';
376
+ ?> id="userphoto_rejectionreason"><?php echo $profileuser->userphoto_rejectionreason ? $profileuser->userphoto_rejectionreason : __('The photo is inappropriate.', 'userphoto') ?></textarea>
377
+ </p>
378
+ <script type="text/javascript">userphoto_approvalstatus_onchange()</script>
379
+ <?php endif; ?>
380
+ <?php if($profileuser->userphoto_image_file): ?>
381
+ <p><label><input type="checkbox" name="userphoto_delete" id="userphoto_delete" onclick="userphoto_onclick()" /> <?php _e('Delete photo?', 'userphoto')?></label></p>
382
+ <?php endif; ?>
383
+ </fieldset>
384
+ <?php
385
+ }
386
+ add_action('show_user_profile', 'userphoto_display_selector_fieldset');
387
+ add_action('edit_user_profile', 'userphoto_display_selector_fieldset');
388
+
389
+ /***** ADMIN ******************************************/
390
+
391
+ function userphoto_add_page() {
392
+ //if (function_exists('add_options_page'))
393
+ add_options_page('User Photo', 'User Photo', 8, __FILE__, 'userphoto_options_page');
394
+ }
395
+ add_action('admin_menu', 'userphoto_add_page');
396
+
397
+ function userphoto_options_page(){
398
+ #Get option values
399
+ $userphoto_jpeg_compression = get_option( 'userphoto_jpeg_compression' );
400
+ $userphoto_maximum_dimension = get_option( 'userphoto_maximum_dimension' );
401
+ $userphoto_thumb_dimension = get_option( 'userphoto_thumb_dimension' );
402
+ $userphoto_admin_notified = get_option( 'userphoto_admin_notified' );
403
+ $userphoto_level_moderated = get_option( 'userphoto_level_moderated' );
404
+
405
+ #Get new updated option values, and save them
406
+ if( @$_POST['action'] == 'update' ) {
407
+ $userphoto_jpeg_compression = (int)$_POST['userphoto_jpeg_compression'];
408
+ update_option('userphoto_jpeg_compression', $userphoto_jpeg_compression);
409
+
410
+ $userphoto_maximum_dimension = (int)$_POST['userphoto_maximum_dimension'];
411
+ update_option('userphoto_maximum_dimension', $userphoto_maximum_dimension);
412
+
413
+ $userphoto_thumb_dimension = (int)$_POST['userphoto_thumb_dimension'];
414
+ update_option('userphoto_thumb_dimension', $userphoto_thumb_dimension);
415
+
416
+ $userphoto_admin_notified = (int)$_POST['userphoto_admin_notified'];
417
+ update_option('userphoto_admin_notified', $userphoto_admin_notified);
418
+
419
+ $userphoto_level_moderated = (int)$_POST['userphoto_level_moderated'];
420
+ update_option('userphoto_level_moderated', $userphoto_level_moderated);
421
+
422
+ ?>
423
+ <div class="updated"><p><strong><?php _e('Options saved.' ); ?></strong></p></div>
424
+ <?php
425
+ }
426
+
427
+ ?>
428
+ <div class="wrap">
429
+ <h2>User Photo Options</h2>
430
+ <form method="post" action="options.php" id='userphoto_options_form'>
431
+ <?php wp_nonce_field('update-options') ?>
432
+ <p>
433
+ <label>
434
+ <?php _e("Maximum dimension: ", 'userphoto') ?>
435
+ <input type="number" min="1" step="1" size="3" name="userphoto_maximum_dimension" value="<?php echo $userphoto_maximum_dimension ?>" />px
436
+ </label>
437
+ </p>
438
+ <p>
439
+ <label>
440
+ <?php _e("Thumbnail dimension: ", 'userphoto') ?>
441
+ <input type="number" min="1" step="1" size="3" name="userphoto_thumb_dimension" value="<?php echo $userphoto_thumb_dimension ?>" />px
442
+ </label>
443
+ </p>
444
+ <p>
445
+ <label>
446
+ <?php _e("JPEG compression: ", 'userphoto') ?>
447
+ <input type="range" min="1" max="100" step="1" size="3" name="userphoto_jpeg_compression" value="<?php echo $userphoto_jpeg_compression ?>" />%
448
+ </label>
449
+ </p>
450
+ <p>
451
+ <label>
452
+ <?php _e("Notify this administrator by email when user photo needs approval: ", 'userphoto') ?>
453
+ <select id='userphoto_admin_notified' name="userphoto_admin_notified">
454
+ <option value="0" class='none'>(none)</option>
455
+ <?php
456
+ global $wpdb;
457
+ $users = $wpdb->get_results("SELECT ID FROM $wpdb->users ORDER BY user_login");
458
+ foreach($users as $user){
459
+ $u = get_userdata($user->ID);
460
+ if($u->user_level == 10){ #if($u->has_cap('administrator')){
461
+ print "<option value='" . $u->ID . "'";
462
+ if($userphoto_admin_notified == $u->ID)
463
+ print " selected='selected'";
464
+ print ">" . $u->user_login . "</option>";
465
+ }
466
+ }
467
+ ?>
468
+ </select>
469
+ </label>
470
+ </p>
471
+ <p>
472
+ <label>
473
+ <!--<input type="checkbox" id="userphoto_do_moderation" onclick="document.getElementById('userphoto_level_moderated').disabled = !this.checked" <?php /*if(isset($userphoto_level_moderated)) echo ' checked="checked"'*/ ?> />-->
474
+ <?php _e("Require user photo moderation for all users at or below this level: ", 'userphoto') ?>
475
+ <select name="userphoto_level_moderated" id="userphoto_level_moderated">
476
+ <option value="-1" <?php if($userphoto_level_moderated == -1) echo ' selected="selected"' ?> class='none'>(none)</option>
477
+ <option value="0" <?php if($userphoto_level_moderated == 0) echo ' selected="selected"' ?>>Subscriber</option>
478
+ <option value="1" <?php if($userphoto_level_moderated == 1) echo ' selected="selected"' ?>>Contributor</option>
479
+ <option value="2" <?php if($userphoto_level_moderated == 2) echo ' selected="selected"' ?>>Author</option>
480
+ <option value="7" <?php if($userphoto_level_moderated == 7) echo ' selected="selected"' ?>>Editor</option>
481
+ </select>
482
+ </label>
483
+ <!--<script type="text/javascript">
484
+ document.getElementById('userphoto_do_moderation').onclick();
485
+ </script>-->
486
+ </p>
487
+
488
+ <input type="hidden" name="action" value="update" />
489
+ <input type="hidden" name="page_options" value="userphoto_jpeg_compression,userphoto_admin_notified,userphoto_maximum_dimension,userphoto_thumb_dimension,userphoto_level_moderated" />
490
+
491
+ <p class="submit">
492
+ <input type="submit" name="Submit" value="<?php _e('Update options &raquo;'); ?>" />
493
+ </p>
494
+ </form>
495
+ </div>
496
+ <?php
497
+ }
498
+
499
+
500
+ function userphoto_resize_image($filename, $newFilename, $maxdimension, &$error){
501
+ if(!$newFilename)
502
+ $newFilename = $filename;
503
+ $userphoto_jpeg_compression = (int)get_option( 'userphoto_jpeg_compression' );
504
+ #if(empty($userphoto_jpeg_compression))
505
+ # $userphoto_jpeg_compression = USERPHOTO_DEFAULT_JPEG_COMPRESSION;
506
+
507
+ $info = @getimagesize($filename);
508
+ if(!$info || !$info[0] || !$info[1]){
509
+ $error = __("Unable to get image dimensions.", 'userphoto');
510
+ }
511
+ //From WordPress image.php line 22
512
+ else if (
513
+ !function_exists( 'imagegif' ) && $info[2] == IMAGETYPE_GIF
514
+ ||
515
+ !function_exists( 'imagejpeg' ) && $info[2] == IMAGETYPE_JPEG
516
+ ||
517
+ !function_exists( 'imagepng' ) && $info[2] == IMAGETYPE_PNG
518
+ ) {
519
+ $error = __( 'Filetype not supported.', 'userphoto' );
520
+ }
521
+ else {
522
+ // create the initial copy from the original file
523
+ if ( $info[2] == IMAGETYPE_GIF ) {
524
+ $image = imagecreatefromgif( $filename );
525
+ }
526
+ elseif ( $info[2] == IMAGETYPE_JPEG ) {
527
+ $image = imagecreatefromjpeg( $filename );
528
+ }
529
+ elseif ( $info[2] == IMAGETYPE_PNG ) {
530
+ $image = imagecreatefrompng( $filename );
531
+ }
532
+ if(!isset($image)){
533
+ $error = __("Unrecognized image format.", 'userphoto');
534
+ return false;
535
+ }
536
+ if ( function_exists( 'imageantialias' ))
537
+ imageantialias( $image, TRUE );
538
+
539
+ // figure out the longest side
540
+
541
+ if ( $info[0] > $info[1] ) {
542
+ $image_width = $info[0];
543
+ $image_height = $info[1];
544
+ $image_new_width = $maxdimension;
545
+
546
+ $image_ratio = $image_width / $image_new_width;
547
+ $image_new_height = $image_height / $image_ratio;
548
+ //width is > height
549
+ } else {
550
+ $image_width = $info[0];
551
+ $image_height = $info[1];
552
+ $image_new_height = $maxdimension;
553
+
554
+ $image_ratio = $image_height / $image_new_height;
555
+ $image_new_width = $image_width / $image_ratio;
556
+ //height > width
557
+ }
558
+
559
+ $imageresized = imagecreatetruecolor( $image_new_width, $image_new_height);
560
+ @ imagecopyresampled( $imageresized, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $info[0], $info[1] );
561
+
562
+ // move the thumbnail to its final destination
563
+ if ( $info[2] == IMAGETYPE_GIF ) {
564
+ if (!imagegif( $imageresized, $newFilename ) ) {
565
+ $error = __( "Thumbnail path invalid" );
566
+ }
567
+ }
568
+ elseif ( $info[2] == IMAGETYPE_JPEG ) {
569
+ if (!imagejpeg( $imageresized, $newFilename, $userphoto_jpeg_compression ) ) {
570
+ $error = __( "Thumbnail path invalid" );
571
+ }
572
+ }
573
+ elseif ( $info[2] == IMAGETYPE_PNG ) {
574
+ if (!imagepng( $imageresized, $newFilename ) ) {
575
+ $error = __( "Thumbnail path invalid" );
576
+ }
577
+ }
578
+ }
579
+ if(!empty($error))
580
+ return false;
581
+ return true;
582
+ }
583
+
584
+
585
+ ?>