]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/avatar.php
debugging for addopenid problem
[quix0rs-gnu-social.git] / actions / avatar.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 require_once(INSTALLDIR.'/lib/settingsaction.php');
23
24 class AvatarAction extends SettingsAction {
25
26         function show_form($msg=NULL, $success=false) {
27                 common_show_header(_t('Avatar'), NULL, NULL, array($this, 'settings_menu'));
28                 if ($msg) {
29                         $this->message($msg, $success);
30                 } else {
31                         common_element('div', 'instructions', 
32                                                    _t('You can upload a new "avatar" (user picture) here. ' .
33                                                           'You can\'t edit the picture after you upload it, so you should ' .
34                                                           'edit it in your desktop image-manipulation software first. ' .
35                                                           'Everything works best if your picture is more or less square. ' . 
36                                                           'And remember: your image will be released under the site license, ' .
37                                                           'So don\'t upload images that don\'t belong to you or that you don\'t ' .
38                                                           'want to share.'));
39                 }
40
41                 $user = common_current_user();
42                 $profile = $user->getProfile();
43                 $original = $profile->getOriginalAvatar();
44
45                 if ($original) {
46                         common_element('img', array('src' => $original->url,
47                                                                                 'class' => 'avatar original',
48                                                                                 'width' => $original->width,
49                                                                                 'height' => $original->height,
50                                                                                 'alt' => $user->nickname));
51                 }
52
53                 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
54
55                 if ($avatar) {
56                         common_element('img', array('src' => $avatar->url,
57                                                                                 'class' => 'avatar profile',
58                                                                                 'width' => AVATAR_PROFILE_SIZE,
59                                                                                 'height' => AVATAR_PROFILE_SIZE,
60                                                                                 'alt' => $user->nickname));
61                 }
62
63                 common_element_start('form', array('enctype' => 'multipart/form-data',
64                                                                                    'method' => 'POST',
65                                                                                    'id' => 'avatar',
66                                                                                    'action' =>
67                                                                                    common_local_url('avatar')));
68                 common_element('input', array('name' => 'MAX_FILE_SIZE',
69                                                                           'type' => 'hidden',
70                                                                           'id' => 'MAX_FILE_SIZE',
71                                                                           'value' => MAX_AVATAR_SIZE));
72                 common_element('input', array('name' => 'avatarfile',
73                                                                           'type' => 'file',
74                                                                           'id' => 'avatarfile'));
75                 common_submit('submit', _t('Upload'));
76                 common_element_end('form');
77                 common_show_footer();
78         }
79
80         function handle_post() {
81
82                 switch ($_FILES['avatarfile']['error']) {
83                  case UPLOAD_ERR_OK: # success, jump out
84                         break;
85                  case UPLOAD_ERR_INI_SIZE:
86                  case UPLOAD_ERR_FORM_SIZE:
87                         $this->show_form(_t('That file is too big.'));
88                         return;
89                  case UPLOAD_ERR_PARTIAL:
90                         @unlink($_FILES['avatarfile']['tmp_name']);
91                         $this->show_form(_t('Partial upload.'));
92                         return;
93                  default:
94                         $this->show_form(_t('System error uploading file.'));
95                         return;
96                 }
97
98                 $info = @getimagesize($_FILES['avatarfile']['tmp_name']);
99
100                 if (!$info) {
101                         @unlink($_FILES['avatarfile']['tmp_name']);
102                         $this->show_form(_t('Not an image or corrupt file.'));
103                         return;
104                 }
105
106                 switch ($info[2]) {
107                  case IMAGETYPE_GIF:
108                  case IMAGETYPE_JPEG:
109                  case IMAGETYPE_PNG:
110                         break;
111                  default:
112                         $this->show_form(_t('Unsupported image file format.'));
113                         return;
114                 }
115
116                 $user = common_current_user();
117                 $profile = $user->getProfile();
118                 
119                 if ($profile->setOriginal($_FILES['avatarfile']['tmp_name'])) {
120                         $this->show_form(_t('Avatar updated.'), true);
121                 } else {
122                         $this->show_form(_t('Failed updating avatar.'));
123                 }
124
125                 @unlink($_FILES['avatarfile']['tmp_name']);
126         }
127 }
128