mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Invalid filter algorithm error in pdf generation #1443
This commit is contained in:
parent
1a27cf27d1
commit
114da7b81c
@ -1019,13 +1019,9 @@ class AccountController extends BaseController
|
|||||||
/* Logo image file */
|
/* Logo image file */
|
||||||
if ($uploaded = Input::file('logo')) {
|
if ($uploaded = Input::file('logo')) {
|
||||||
$path = Input::file('logo')->getRealPath();
|
$path = Input::file('logo')->getRealPath();
|
||||||
|
|
||||||
$disk = $account->getLogoDisk();
|
$disk = $account->getLogoDisk();
|
||||||
if ($account->hasLogo() && ! Utils::isNinjaProd()) {
|
|
||||||
$disk->delete($account->logo);
|
|
||||||
}
|
|
||||||
|
|
||||||
$extension = strtolower($uploaded->getClientOriginalExtension());
|
$extension = strtolower($uploaded->getClientOriginalExtension());
|
||||||
|
|
||||||
if (empty(Document::$types[$extension]) && ! empty(Document::$extraExtensions[$extension])) {
|
if (empty(Document::$types[$extension]) && ! empty(Document::$extraExtensions[$extension])) {
|
||||||
$documentType = Document::$extraExtensions[$extension];
|
$documentType = Document::$extraExtensions[$extension];
|
||||||
} else {
|
} else {
|
||||||
@ -1041,7 +1037,7 @@ class AccountController extends BaseController
|
|||||||
$size = filesize($filePath);
|
$size = filesize($filePath);
|
||||||
|
|
||||||
if ($size / 1000 > MAX_DOCUMENT_SIZE) {
|
if ($size / 1000 > MAX_DOCUMENT_SIZE) {
|
||||||
Session::flash('warning', trans('texts.logo_warning_too_large'));
|
Session::flash('error', trans('texts.logo_warning_too_large'));
|
||||||
} else {
|
} else {
|
||||||
if ($documentType != 'gif') {
|
if ($documentType != 'gif') {
|
||||||
$account->logo = $account->account_key.'.'.$documentType;
|
$account->logo = $account->account_key.'.'.$documentType;
|
||||||
@ -1058,15 +1054,20 @@ class AccountController extends BaseController
|
|||||||
$image->interlace(false);
|
$image->interlace(false);
|
||||||
$imageStr = (string) $image->encode($documentType);
|
$imageStr = (string) $image->encode($documentType);
|
||||||
$disk->put($account->logo, $imageStr);
|
$disk->put($account->logo, $imageStr);
|
||||||
|
|
||||||
$account->logo_size = strlen($imageStr);
|
$account->logo_size = strlen($imageStr);
|
||||||
|
} else {
|
||||||
|
if (Utils::isInterlaced($filePath)) {
|
||||||
|
$account->clearLogo();
|
||||||
|
Session::flash('error', trans('texts.logo_warning_invalid'));
|
||||||
} else {
|
} else {
|
||||||
$stream = fopen($filePath, 'r');
|
$stream = fopen($filePath, 'r');
|
||||||
$disk->getDriver()->putStream($account->logo, $stream, ['mimetype' => $documentTypeData['mime']]);
|
$disk->getDriver()->putStream($account->logo, $stream, ['mimetype' => $documentTypeData['mime']]);
|
||||||
fclose($stream);
|
fclose($stream);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
Session::flash('warning', trans('texts.logo_warning_invalid'));
|
$account->clearLogo();
|
||||||
|
Session::flash('error', trans('texts.logo_warning_invalid'));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (extension_loaded('fileinfo')) {
|
if (extension_loaded('fileinfo')) {
|
||||||
@ -1080,7 +1081,7 @@ class AccountController extends BaseController
|
|||||||
$account->logo_width = $image->width();
|
$account->logo_width = $image->width();
|
||||||
$account->logo_height = $image->height();
|
$account->logo_height = $image->height();
|
||||||
} else {
|
} else {
|
||||||
Session::flash('warning', trans('texts.logo_warning_fileinfo'));
|
Session::flash('error', trans('texts.logo_warning_fileinfo'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1240,4 +1240,13 @@ class Utils
|
|||||||
{
|
{
|
||||||
return strlen($string) > $length ? rtrim(substr($string, 0, $length)) . '...' : $string;
|
return strlen($string) > $length ? rtrim(substr($string, 0, $length)) . '...' : $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// http://stackoverflow.com/a/14238078/497368
|
||||||
|
public static function isInterlaced($filename)
|
||||||
|
{
|
||||||
|
$handle = fopen($filename, 'r');
|
||||||
|
$contents = fread($handle, 32);
|
||||||
|
fclose($handle);
|
||||||
|
return( ord($contents[28]) != 0 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,13 @@ use App\Events\UserSettingsChanged;
|
|||||||
use App\Models\Traits\GeneratesNumbers;
|
use App\Models\Traits\GeneratesNumbers;
|
||||||
use App\Models\Traits\PresentsInvoice;
|
use App\Models\Traits\PresentsInvoice;
|
||||||
use App\Models\Traits\SendsEmails;
|
use App\Models\Traits\SendsEmails;
|
||||||
|
use App\Models\Traits\HasLogo;
|
||||||
use Cache;
|
use Cache;
|
||||||
use Carbon;
|
use Carbon;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Eloquent;
|
use Eloquent;
|
||||||
use Event;
|
use Event;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
use Laracasts\Presenter\PresentableTrait;
|
use Laracasts\Presenter\PresentableTrait;
|
||||||
use Session;
|
use Session;
|
||||||
use Utils;
|
use Utils;
|
||||||
@ -28,6 +28,7 @@ class Account extends Eloquent
|
|||||||
use PresentsInvoice;
|
use PresentsInvoice;
|
||||||
use GeneratesNumbers;
|
use GeneratesNumbers;
|
||||||
use SendsEmails;
|
use SendsEmails;
|
||||||
|
use HasLogo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
@ -836,101 +837,6 @@ class Account extends Eloquent
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function hasLogo()
|
|
||||||
{
|
|
||||||
return ! empty($this->logo);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function getLogoDisk()
|
|
||||||
{
|
|
||||||
return Storage::disk(env('LOGO_FILESYSTEM', 'logos'));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function calculateLogoDetails()
|
|
||||||
{
|
|
||||||
$disk = $this->getLogoDisk();
|
|
||||||
|
|
||||||
if ($disk->exists($this->account_key.'.png')) {
|
|
||||||
$this->logo = $this->account_key.'.png';
|
|
||||||
} elseif ($disk->exists($this->account_key.'.jpg')) {
|
|
||||||
$this->logo = $this->account_key.'.jpg';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! empty($this->logo)) {
|
|
||||||
$image = imagecreatefromstring($disk->get($this->logo));
|
|
||||||
$this->logo_width = imagesx($image);
|
|
||||||
$this->logo_height = imagesy($image);
|
|
||||||
$this->logo_size = $disk->size($this->logo);
|
|
||||||
} else {
|
|
||||||
$this->logo = null;
|
|
||||||
}
|
|
||||||
$this->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return null
|
|
||||||
*/
|
|
||||||
public function getLogoRaw()
|
|
||||||
{
|
|
||||||
if (! $this->hasLogo()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$disk = $this->getLogoDisk();
|
|
||||||
|
|
||||||
return $disk->get($this->logo);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param bool $cachebuster
|
|
||||||
*
|
|
||||||
* @return null|string
|
|
||||||
*/
|
|
||||||
public function getLogoURL($cachebuster = false)
|
|
||||||
{
|
|
||||||
if (! $this->hasLogo()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$disk = $this->getLogoDisk();
|
|
||||||
$adapter = $disk->getAdapter();
|
|
||||||
|
|
||||||
if ($adapter instanceof \League\Flysystem\Adapter\Local) {
|
|
||||||
// Stored locally
|
|
||||||
$logoUrl = url('/logo/' . $this->logo);
|
|
||||||
|
|
||||||
if ($cachebuster) {
|
|
||||||
$logoUrl .= '?no_cache='.time();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $logoUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Document::getDirectFileUrl($this->logo, $this->getLogoDisk());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getLogoPath()
|
|
||||||
{
|
|
||||||
if (! $this->hasLogo()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$disk = $this->getLogoDisk();
|
|
||||||
$adapter = $disk->getAdapter();
|
|
||||||
|
|
||||||
if ($adapter instanceof \League\Flysystem\Adapter\Local) {
|
|
||||||
return $adapter->applyPathPrefix($this->logo);
|
|
||||||
} else {
|
|
||||||
return Document::getDirectFileUrl($this->logo, $this->getLogoDisk());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
@ -958,30 +864,6 @@ class Account extends Eloquent
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return mixed|null
|
|
||||||
*/
|
|
||||||
public function getLogoWidth()
|
|
||||||
{
|
|
||||||
if (! $this->hasLogo()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->logo_width;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return mixed|null
|
|
||||||
*/
|
|
||||||
public function getLogoHeight()
|
|
||||||
{
|
|
||||||
if (! $this->hasLogo()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->logo_height;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $entityType
|
* @param $entityType
|
||||||
* @param null $clientId
|
* @param null $clientId
|
||||||
@ -1348,26 +1230,6 @@ class Account extends Eloquent
|
|||||||
return Carbon::instance($date);
|
return Carbon::instance($date);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return float|null
|
|
||||||
*/
|
|
||||||
public function getLogoSize()
|
|
||||||
{
|
|
||||||
if (! $this->hasLogo()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return round($this->logo_size / 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isLogoTooLarge()
|
|
||||||
{
|
|
||||||
return $this->getLogoSize() > MAX_LOGO_FILE_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $eventId
|
* @param $eventId
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user