Added avatar image upload
This commit is contained in:
@@ -60,6 +60,7 @@ use Pimple\Container;
|
||||
* @property \Kanboard\Formatter\GroupAutoCompleteFormatter $groupAutoCompleteFormatter
|
||||
* @property \Kanboard\Model\Action $action
|
||||
* @property \Kanboard\Model\ActionParameter $actionParameter
|
||||
* @property \Kanboard\Model\AvatarFile $avatarFile
|
||||
* @property \Kanboard\Model\Board $board
|
||||
* @property \Kanboard\Model\Category $category
|
||||
* @property \Kanboard\Model\Color $color
|
||||
|
||||
@@ -13,6 +13,24 @@ use Kanboard\Core\Csv;
|
||||
*/
|
||||
class Response extends Base
|
||||
{
|
||||
/**
|
||||
* Send headers to cache a resource
|
||||
*
|
||||
* @access public
|
||||
* @param integer $duration
|
||||
* @param string $etag
|
||||
*/
|
||||
public function cache($duration, $etag = '')
|
||||
{
|
||||
header('Pragma: cache');
|
||||
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $duration) . ' GMT');
|
||||
header('Cache-Control: public, max-age=' . $duration);
|
||||
|
||||
if ($etag) {
|
||||
header('ETag: "' . $etag . '"');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send no cache headers
|
||||
*
|
||||
|
||||
172
app/Core/Thumbnail.php
Normal file
172
app/Core/Thumbnail.php
Normal file
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Core;
|
||||
|
||||
/**
|
||||
* Thumbnail Generator
|
||||
*
|
||||
* @package core
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Thumbnail
|
||||
{
|
||||
protected $metadata = array();
|
||||
protected $srcImage;
|
||||
protected $dstImage;
|
||||
|
||||
/**
|
||||
* Create a thumbnail from a local file
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @param string $filename
|
||||
* @return Thumbnail
|
||||
*/
|
||||
public static function createFromFile($filename)
|
||||
{
|
||||
$self = new static();
|
||||
$self->fromFile($filename);
|
||||
return $self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a thumbnail from a string
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @param string $blob
|
||||
* @return Thumbnail
|
||||
*/
|
||||
public static function createFromString($blob)
|
||||
{
|
||||
$self = new static();
|
||||
$self->fromString($blob);
|
||||
return $self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the local image file in memory with GD
|
||||
*
|
||||
* @access public
|
||||
* @param string $filename
|
||||
* @return Thumbnail
|
||||
*/
|
||||
public function fromFile($filename)
|
||||
{
|
||||
$this->metadata = getimagesize($filename);
|
||||
$this->srcImage = imagecreatefromstring(file_get_contents($filename));
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the image blob in memory with GD
|
||||
*
|
||||
* @access public
|
||||
* @param string $blob
|
||||
* @return Thumbnail
|
||||
*/
|
||||
public function fromString($blob)
|
||||
{
|
||||
if (!function_exists('getimagesizefromstring')) {
|
||||
$uri = 'data://application/octet-stream;base64,' . base64_encode($blob);
|
||||
$this->metadata = getimagesize($uri);
|
||||
} else {
|
||||
$this->metadata = getimagesizefromstring($blob);
|
||||
}
|
||||
|
||||
$this->srcImage = imagecreatefromstring($blob);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize the image
|
||||
*
|
||||
* @access public
|
||||
* @param int $width
|
||||
* @param int $height
|
||||
* @return Thumbnail
|
||||
*/
|
||||
public function resize($width = 250, $height = 100)
|
||||
{
|
||||
$srcWidth = $this->metadata[0];
|
||||
$srcHeight = $this->metadata[1];
|
||||
$dstX = 0;
|
||||
$dstY = 0;
|
||||
|
||||
if ($width == 0 && $height == 0) {
|
||||
$width = 100;
|
||||
$height = 100;
|
||||
}
|
||||
|
||||
if ($width > 0 && $height == 0) {
|
||||
$dstWidth = $width;
|
||||
$dstHeight = floor($srcHeight * ($width / $srcWidth));
|
||||
$this->dstImage = imagecreatetruecolor($dstWidth, $dstHeight);
|
||||
} elseif ($width == 0 && $height > 0) {
|
||||
$dstWidth = floor($srcWidth * ($height / $srcHeight));
|
||||
$dstHeight = $height;
|
||||
$this->dstImage = imagecreatetruecolor($dstWidth, $dstHeight);
|
||||
} else {
|
||||
$srcRatio = $srcWidth / $srcHeight;
|
||||
$resizeRatio = $width / $height;
|
||||
|
||||
if ($srcRatio <= $resizeRatio) {
|
||||
$dstWidth = $width;
|
||||
$dstHeight = floor($srcHeight * ($width / $srcWidth));
|
||||
$dstY = ($dstHeight - $height) / 2 * (-1);
|
||||
} else {
|
||||
$dstWidth = floor($srcWidth * ($height / $srcHeight));
|
||||
$dstHeight = $height;
|
||||
$dstX = ($dstWidth - $width) / 2 * (-1);
|
||||
}
|
||||
|
||||
$this->dstImage = imagecreatetruecolor($width, $height);
|
||||
}
|
||||
|
||||
imagecopyresampled($this->dstImage, $this->srcImage, $dstX, $dstY, 0, 0, $dstWidth, $dstHeight, $srcWidth, $srcHeight);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the thumbnail to a local file
|
||||
*
|
||||
* @access public
|
||||
* @param string $filename
|
||||
* @return Thumbnail
|
||||
*/
|
||||
public function toFile($filename)
|
||||
{
|
||||
imagejpeg($this->dstImage, $filename);
|
||||
imagedestroy($this->dstImage);
|
||||
imagedestroy($this->srcImage);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the thumbnail as a string
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
ob_start();
|
||||
imagejpeg($this->dstImage, null);
|
||||
imagedestroy($this->dstImage);
|
||||
imagedestroy($this->srcImage);
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the thumbnail directly to the browser or stdout
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function toOutput()
|
||||
{
|
||||
imagejpeg($this->dstImage, null);
|
||||
imagedestroy($this->dstImage);
|
||||
imagedestroy($this->srcImage);
|
||||
}
|
||||
}
|
||||
@@ -75,78 +75,4 @@ class Tool
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a jpeg thumbnail from an image
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @param string $src_file Source file image
|
||||
* @param string $dst_file Destination file image
|
||||
* @param integer $resize_width Desired image width
|
||||
* @param integer $resize_height Desired image height
|
||||
*/
|
||||
public static function generateThumbnail($src_file, $dst_file, $resize_width = 250, $resize_height = 100)
|
||||
{
|
||||
$metadata = getimagesize($src_file);
|
||||
$src_width = $metadata[0];
|
||||
$src_height = $metadata[1];
|
||||
$dst_y = 0;
|
||||
$dst_x = 0;
|
||||
|
||||
if (empty($metadata['mime'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($resize_width == 0 && $resize_height == 0) {
|
||||
$resize_width = 100;
|
||||
$resize_height = 100;
|
||||
}
|
||||
|
||||
if ($resize_width > 0 && $resize_height == 0) {
|
||||
$dst_width = $resize_width;
|
||||
$dst_height = floor($src_height * ($resize_width / $src_width));
|
||||
$dst_image = imagecreatetruecolor($dst_width, $dst_height);
|
||||
} elseif ($resize_width == 0 && $resize_height > 0) {
|
||||
$dst_width = floor($src_width * ($resize_height / $src_height));
|
||||
$dst_height = $resize_height;
|
||||
$dst_image = imagecreatetruecolor($dst_width, $dst_height);
|
||||
} else {
|
||||
$src_ratio = $src_width / $src_height;
|
||||
$resize_ratio = $resize_width / $resize_height;
|
||||
|
||||
if ($src_ratio <= $resize_ratio) {
|
||||
$dst_width = $resize_width;
|
||||
$dst_height = floor($src_height * ($resize_width / $src_width));
|
||||
|
||||
$dst_y = ($dst_height - $resize_height) / 2 * (-1);
|
||||
} else {
|
||||
$dst_width = floor($src_width * ($resize_height / $src_height));
|
||||
$dst_height = $resize_height;
|
||||
|
||||
$dst_x = ($dst_width - $resize_width) / 2 * (-1);
|
||||
}
|
||||
|
||||
$dst_image = imagecreatetruecolor($resize_width, $resize_height);
|
||||
}
|
||||
|
||||
switch ($metadata['mime']) {
|
||||
case 'image/jpeg':
|
||||
case 'image/jpg':
|
||||
$src_image = imagecreatefromjpeg($src_file);
|
||||
break;
|
||||
case 'image/png':
|
||||
$src_image = imagecreatefrompng($src_file);
|
||||
break;
|
||||
case 'image/gif':
|
||||
$src_image = imagecreatefromgif($src_file);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
|
||||
imagejpeg($dst_image, $dst_file);
|
||||
imagedestroy($dst_image);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,23 +32,25 @@ class AvatarManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Render avatar html element
|
||||
* Render avatar HTML element
|
||||
*
|
||||
* @access public
|
||||
* @param string $user_id
|
||||
* @param string $username
|
||||
* @param string $name
|
||||
* @param string $email
|
||||
* @param string $avatar_path
|
||||
* @param int $size
|
||||
* @return string
|
||||
*/
|
||||
public function render($user_id, $username, $name, $email, $size)
|
||||
public function render($user_id, $username, $name, $email, $avatar_path, $size)
|
||||
{
|
||||
$user = array(
|
||||
'id' => $user_id,
|
||||
'username' => $username,
|
||||
'name' => $name,
|
||||
'email' => $email,
|
||||
'avatar_path' => $avatar_path,
|
||||
);
|
||||
|
||||
krsort($this->providers);
|
||||
@@ -80,6 +82,7 @@ class AvatarManager
|
||||
'username' => '',
|
||||
'name' => '?',
|
||||
'email' => '',
|
||||
'avatar_path' => '',
|
||||
);
|
||||
|
||||
return $provider->render($user, $size);
|
||||
|
||||
@@ -13,6 +13,19 @@ use Kanboard\Core\Security\Role;
|
||||
*/
|
||||
class UserSession extends Base
|
||||
{
|
||||
/**
|
||||
* Refresh current session if necessary
|
||||
*
|
||||
* @access public
|
||||
* @param integer $user_id
|
||||
*/
|
||||
public function refresh($user_id)
|
||||
{
|
||||
if ($this->getId() == $user_id) {
|
||||
$this->initialize($this->user->getById($user_id));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user session
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user