3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
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.
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.
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/>.
20 if (!defined('LACONICA')) { exit(1); }
22 require_once(INSTALLDIR.'/lib/settingsaction.php');
24 class AvatarAction extends SettingsAction {
26 function show_form($msg=NULL, $success=false) {
27 common_show_header(_t('Avatar'));
28 $this->settings_menu();
29 $this->message($msg, $success);
31 $user = common_current_user();
32 $profile = $user->getProfile();
33 $original = $profile->getOriginal();
36 common_element('img', array('src' => $original->url,
37 'class' => 'avatar original',
38 'width' => $original->width,
39 'height' => $original->height,
40 'alt' => $user->nickname));
43 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
46 common_element('img', array('src' => $avatar->url,
47 'class' => 'avatar profile',
48 'width' => AVATAR_PROFILE_SIZE,
49 'height' => AVATAR_PROFILE_SIZE,
50 'alt' => $user->nickname));
53 common_element_start('form', array('enctype' => 'multipart/form-data',
57 common_local_url('avatar')));
58 common_element('input', array('name' => 'MAX_FILE_SIZE',
60 'id' => 'MAX_FILE_SIZE',
61 'value' => MAX_AVATAR_SIZE));
62 common_element('input', array('name' => 'avatarfile',
64 'id' => 'avatarfile'));
65 common_submit('submit', _t('Upload'));
66 common_element_end('form');
70 function handle_post() {
72 switch ($_FILES['avatarfile']['error']) {
73 case UPLOAD_ERR_OK: # success, jump out
75 case UPLOAD_ERR_INI_SIZE:
76 case UPLOAD_ERR_FORM_SIZE:
77 $this->show_form(_t('That file is too big.'));
79 case UPLOAD_ERR_PARTIAL:
80 @unlink($_FILES['avatarfile']['tmp_name']);
81 $this->show_form(_t('Partial upload.'));
84 $this->show_form(_t('System error uploading file.'));
88 $info = @getimagesize($_FILES['avatarfile']['tmp_name']);
91 @unlink($_FILES['avatarfile']['tmp_name']);
92 $this->show_form(_t('Not an image or corrupt file.'));
102 $this->show_form(_t('Unsupported image file format.'));
106 $user = common_current_user();
107 $profile = $user->getProfile();
109 if ($profile->setOriginal($_FILES['avatarfile']['tmp_name'])) {
110 $this->show_form(_t('Avatar updated.'), true);
112 $this->show_form(_t('Failed updating avatar.'));
115 @unlink($_FILES['avatarfile']['tmp_name']);