2008-05-17 21:20:45 +09:00
< ? php
/*
* Laconica - a distributed open - source microblogging tool
* Copyright ( C ) 2008 , Controlez - Vous , Inc .
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Affero General Public License for more details .
*
* You should have received a copy of the GNU Affero General Public License
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*/
2008-05-18 00:47:01 +09:00
if ( ! defined ( 'LACONICA' )) { exit ( 1 ); }
2008-05-17 21:20:45 +09:00
2008-05-18 02:54:16 +09:00
require_once ( INSTALLDIR . '/lib/settingsaction.php' );
2008-05-17 21:20:45 +09:00
class AvatarAction extends SettingsAction {
2008-07-23 02:15:01 +09:00
function is_readonly () {
return false ;
}
2008-07-01 02:03:42 +09:00
function get_instructions () {
2008-07-13 13:46:08 +09:00
return _ ( 'Upload a new "avatar" (user image) here. You can\'t edit the picture after you upload it, so make sure it\'s more or less square. It must be under the site license, also. Use a picture that belongs to you and that you want to share.' );
2008-06-18 12:57:39 +09:00
}
2008-07-01 02:03:42 +09:00
2008-06-18 12:57:39 +09:00
function show_form ( $msg = NULL , $success = false ) {
2008-07-01 02:03:42 +09:00
2008-07-08 18:45:31 +09:00
$this -> form_header ( _ ( 'Avatar' ), $msg , $success );
2008-05-17 21:20:45 +09:00
$user = common_current_user ();
$profile = $user -> getProfile ();
2008-06-13 01:52:01 +09:00
$original = $profile -> getOriginalAvatar ();
2008-05-17 21:20:45 +09:00
if ( $original ) {
common_element ( 'img' , array ( 'src' => $original -> url ,
'class' => 'avatar original' ,
'width' => $original -> width ,
2008-05-20 22:46:31 +09:00
'height' => $original -> height ,
'alt' => $user -> nickname ));
2008-05-17 21:20:45 +09:00
}
$avatar = $profile -> getAvatar ( AVATAR_PROFILE_SIZE );
if ( $avatar ) {
common_element ( 'img' , array ( 'src' => $avatar -> url ,
'class' => 'avatar profile' ,
'width' => AVATAR_PROFILE_SIZE ,
2008-05-20 22:46:31 +09:00
'height' => AVATAR_PROFILE_SIZE ,
'alt' => $user -> nickname ));
2008-05-17 21:20:45 +09:00
}
2008-05-18 02:04:30 +09:00
common_element_start ( 'form' , array ( 'enctype' => 'multipart/form-data' ,
2008-05-17 21:20:45 +09:00
'method' => 'POST' ,
'id' => 'avatar' ,
'action' =>
common_local_url ( 'avatar' )));
common_element ( 'input' , array ( 'name' => 'MAX_FILE_SIZE' ,
'type' => 'hidden' ,
'id' => 'MAX_FILE_SIZE' ,
'value' => MAX_AVATAR_SIZE ));
common_element ( 'input' , array ( 'name' => 'avatarfile' ,
'type' => 'file' ,
'id' => 'avatarfile' ));
2008-07-08 18:45:31 +09:00
common_submit ( 'submit' , _ ( 'Upload' ));
2008-05-18 02:04:30 +09:00
common_element_end ( 'form' );
2008-05-21 03:19:06 +09:00
common_show_footer ();
2008-05-17 21:20:45 +09:00
}
function handle_post () {
switch ( $_FILES [ 'avatarfile' ][ 'error' ]) {
case UPLOAD_ERR_OK : # success, jump out
break ;
case UPLOAD_ERR_INI_SIZE :
case UPLOAD_ERR_FORM_SIZE :
2008-07-08 18:45:31 +09:00
$this -> show_form ( _ ( 'That file is too big.' ));
2008-05-17 21:20:45 +09:00
return ;
case UPLOAD_ERR_PARTIAL :
@ unlink ( $_FILES [ 'avatarfile' ][ 'tmp_name' ]);
2008-07-08 18:45:31 +09:00
$this -> show_form ( _ ( 'Partial upload.' ));
2008-05-17 21:20:45 +09:00
return ;
default :
2008-07-08 18:45:31 +09:00
$this -> show_form ( _ ( 'System error uploading file.' ));
2008-05-17 21:20:45 +09:00
return ;
}
$info = @ getimagesize ( $_FILES [ 'avatarfile' ][ 'tmp_name' ]);
if ( ! $info ) {
@ unlink ( $_FILES [ 'avatarfile' ][ 'tmp_name' ]);
2008-07-08 18:45:31 +09:00
$this -> show_form ( _ ( 'Not an image or corrupt file.' ));
2008-05-17 21:20:45 +09:00
return ;
}
switch ( $info [ 2 ]) {
case IMAGETYPE_GIF :
case IMAGETYPE_JPEG :
case IMAGETYPE_PNG :
break ;
default :
2008-07-08 18:45:31 +09:00
$this -> show_form ( _ ( 'Unsupported image file format.' ));
2008-05-17 21:20:45 +09:00
return ;
}
2008-05-19 04:46:53 +09:00
2008-05-17 21:20:45 +09:00
$user = common_current_user ();
2008-06-06 04:37:08 +09:00
$profile = $user -> getProfile ();
2008-07-01 02:03:42 +09:00
2008-06-06 04:37:08 +09:00
if ( $profile -> setOriginal ( $_FILES [ 'avatarfile' ][ 'tmp_name' ])) {
2008-07-08 18:45:31 +09:00
$this -> show_form ( _ ( 'Avatar updated.' ), true );
2008-05-17 21:20:45 +09:00
} else {
2008-07-08 18:45:31 +09:00
$this -> show_form ( _ ( 'Failed updating avatar.' ));
2008-05-17 21:20:45 +09:00
}
2008-05-19 04:46:53 +09:00
2008-06-06 04:37:08 +09:00
@ unlink ( $_FILES [ 'avatarfile' ][ 'tmp_name' ]);
2008-05-17 21:20:45 +09:00
}
}