better upload of group logos

This commit is contained in:
Evan Prodromou 2009-01-28 23:00:01 -05:00
parent 2d6a9b4fbe
commit de47c827b7

View File

@ -34,6 +34,8 @@ if (!defined('LACONICA')) {
require_once INSTALLDIR.'/lib/accountsettingsaction.php'; require_once INSTALLDIR.'/lib/accountsettingsaction.php';
define('MAX_ORIGINAL', 480);
/** /**
* Upload an avatar * Upload an avatar
* *
@ -53,6 +55,8 @@ class GrouplogoAction extends Action
var $mode = null; var $mode = null;
var $imagefile = null; var $imagefile = null;
var $filename = null; var $filename = null;
var $msg = null;
var $success = null;
/** /**
* Prepare to run * Prepare to run
@ -121,9 +125,11 @@ class GrouplogoAction extends Action
} }
} }
function showForm($msg = null) function showForm($msg = null, $success = false)
{ {
$this->msg = $msg; $this->msg = $msg;
$this->success = $success;
$this->showPage(); $this->showPage();
} }
@ -281,6 +287,7 @@ class GrouplogoAction extends Action
'type' => 'hidden', 'type' => 'hidden',
'id' => $crop_info)); 'id' => $crop_info));
} }
$this->submit('crop', _('Crop')); $this->submit('crop', _('Crop'));
$this->elementEnd('li'); $this->elementEnd('li');
@ -310,9 +317,9 @@ class GrouplogoAction extends Action
} }
if ($this->arg('upload')) { if ($this->arg('upload')) {
$this->uploadAvatar(); $this->uploadLogo();
} else if ($this->arg('crop')) { } else if ($this->arg('crop')) {
$this->cropAvatar(); $this->cropLogo();
} else { } else {
$this->showForm(_('Unexpected form submission.')); $this->showForm(_('Unexpected form submission.'));
} }
@ -327,7 +334,7 @@ class GrouplogoAction extends Action
* @return void * @return void
*/ */
function uploadAvatar() function uploadLogo()
{ {
try { try {
$imagefile = ImageFile::fromUpload('avatarfile'); $imagefile = ImageFile::fromUpload('avatarfile');
@ -367,7 +374,7 @@ class GrouplogoAction extends Action
* @return void * @return void
*/ */
function cropAvatar() function cropLogo()
{ {
$user = common_current_user(); $user = common_current_user();
@ -407,20 +414,20 @@ class GrouplogoAction extends Action
return; return;
} }
common_debug("W = $w, H = $h, X = $x, Y = $y"); $size = ($w > MAX_ORIGINAL) ? MAX_ORIGINAL : $w;
$image_dest = imagecreatetruecolor($w, $h); $image_dest = imagecreatetruecolor($size, $size);
$background = imagecolorallocate($image_dest, 0, 0, 0); $background = imagecolorallocate($image_dest, 0, 0, 0);
ImageColorTransparent($image_dest, $background); ImageColorTransparent($image_dest, $background);
imagealphablending($image_dest, false); imagealphablending($image_dest, false);
imagecopyresized($image_dest, $image_src, 0, 0, $x, $y, $w, $h, $w, $h); imagecopyresized($image_dest, $image_src,
0, 0, $x, $y,
$cur = common_current_user(); $size, $size, $w, $h);
$filename = common_avatar_filename($this->group->id, $filename = common_avatar_filename($this->group->id,
image_type_to_extension($imagefile->type), image_type_to_extension($filedata['type']),
null, null,
'group-'.common_timestamp()); 'group-'.common_timestamp());
@ -494,6 +501,7 @@ class GrouplogoAction extends Action
{ {
parent::showScripts(); parent::showScripts();
if ($this->mode == 'crop') {
$jcropPack = common_path('js/jcrop/jquery.Jcrop.pack.js'); $jcropPack = common_path('js/jcrop/jquery.Jcrop.pack.js');
$jcropGo = common_path('js/jcrop/jquery.Jcrop.go.js'); $jcropGo = common_path('js/jcrop/jquery.Jcrop.go.js');
@ -502,6 +510,7 @@ class GrouplogoAction extends Action
$this->element('script', array('type' => 'text/javascript', $this->element('script', array('type' => 'text/javascript',
'src' => $jcropGo)); 'src' => $jcropGo));
} }
}
function showLocalNav() function showLocalNav()
{ {