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_top($arr) {
30 $this->message($msg, $success);
32 common_element('div', 'instructions',
33 _t('Upload a new "avatar" (user image) here. ' .
34 'You can\'t edit the picture after you upload it, so ' .
35 'make sure it\'s more or less square. ' .
36 'It must be under the site license, also. ' .
37 'Use a picture that belongs to you and that you ' .
40 $this->settings_menu();
43 function show_form($msg=NULL, $success=false) {
44 common_show_header(_t('Avatar'), NULL, array($msg, $success), array($this, 'show_top'));
46 $user = common_current_user();
47 $profile = $user->getProfile();
48 $original = $profile->getOriginalAvatar();
51 common_element('img', array('src' => $original->url,
52 'class' => 'avatar original',
53 'width' => $original->width,
54 'height' => $original->height,
55 'alt' => $user->nickname));
58 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
61 common_element('img', array('src' => $avatar->url,
62 'class' => 'avatar profile',
63 'width' => AVATAR_PROFILE_SIZE,
64 'height' => AVATAR_PROFILE_SIZE,
65 'alt' => $user->nickname));
68 common_element_start('form', array('enctype' => 'multipart/form-data',
72 common_local_url('avatar')));
73 common_element('input', array('name' => 'MAX_FILE_SIZE',
75 'id' => 'MAX_FILE_SIZE',
76 'value' => MAX_AVATAR_SIZE));
77 common_element('input', array('name' => 'avatarfile',
79 'id' => 'avatarfile'));
80 common_submit('submit', _t('Upload'));
81 common_element_end('form');
85 function handle_post() {
87 switch ($_FILES['avatarfile']['error']) {
88 case UPLOAD_ERR_OK: # success, jump out
90 case UPLOAD_ERR_INI_SIZE:
91 case UPLOAD_ERR_FORM_SIZE:
92 $this->show_form(_t('That file is too big.'));
94 case UPLOAD_ERR_PARTIAL:
95 @unlink($_FILES['avatarfile']['tmp_name']);
96 $this->show_form(_t('Partial upload.'));
99 $this->show_form(_t('System error uploading file.'));
103 $info = @getimagesize($_FILES['avatarfile']['tmp_name']);
106 @unlink($_FILES['avatarfile']['tmp_name']);
107 $this->show_form(_t('Not an image or corrupt file.'));
117 $this->show_form(_t('Unsupported image file format.'));
121 $user = common_current_user();
122 $profile = $user->getProfile();
124 if ($profile->setOriginal($_FILES['avatarfile']['tmp_name'])) {
125 $this->show_form(_t('Avatar updated.'), true);
127 $this->show_form(_t('Failed updating avatar.'));
130 @unlink($_FILES['avatarfile']['tmp_name']);