mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Migrate logos to use Laravel Filesystem
This commit is contained in:
parent
9fbee962de
commit
5640c74f35
@ -9,6 +9,7 @@ use Cache;
|
|||||||
use App;
|
use App;
|
||||||
use File;
|
use File;
|
||||||
use App\Events\UserSettingsChanged;
|
use App\Events\UserSettingsChanged;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Laracasts\Presenter\PresentableTrait;
|
use Laracasts\Presenter\PresentableTrait;
|
||||||
|
|
||||||
@ -384,26 +385,64 @@ class Account extends Eloquent
|
|||||||
|
|
||||||
public function hasLogo()
|
public function hasLogo()
|
||||||
{
|
{
|
||||||
return file_exists($this->getLogoFullPath());
|
if($this->logo == ''){
|
||||||
|
$this->calculateLogoDetails();
|
||||||
|
}
|
||||||
|
|
||||||
|
return !empty($this->logo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLogoPath()
|
public function getLogoDisk(){
|
||||||
{
|
return Storage::disk(env('LOGO_DISK', 'logos'));
|
||||||
$fileName = 'logo/' . $this->account_key;
|
|
||||||
|
|
||||||
return file_exists($fileName.'.png') ? $fileName.'.png' : $fileName.'.jpg';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLogoFullPath()
|
protected function calculateLogoDetails(){
|
||||||
{
|
$disk = $this->getLogoDisk();
|
||||||
$fileName = public_path() . '/logo/' . $this->account_key;
|
|
||||||
|
|
||||||
return file_exists($fileName.'.png') ? $fileName.'.png' : $fileName.'.jpg';
|
if($disk->exists($this->account_key.'.png')){
|
||||||
|
$this->logo = $this->account_key.'.png';
|
||||||
|
} else if($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();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLogoRaw(){
|
||||||
|
if(!$this->hasLogo()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$disk = $this->getLogoDisk();
|
||||||
|
return $disk->get($this->logo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLogoURL()
|
public function getLogoURL()
|
||||||
{
|
{
|
||||||
return SITE_URL . '/' . $this->getLogoPath();
|
if(!$this->hasLogo()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$disk = $this->getLogoDisk();
|
||||||
|
$adapter = $disk->getAdapter();
|
||||||
|
|
||||||
|
if($adapter instanceof \League\Flysystem\Adapter\Local) {
|
||||||
|
// Stored locally
|
||||||
|
$logo_url = str_replace(public_path(), url('/'), $adapter->applyPathPrefix($this->logo), $count);
|
||||||
|
if($count == 1){
|
||||||
|
return str_replace(DIRECTORY_SEPARATOR, '/', $logo_url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getToken($name)
|
public function getToken($name)
|
||||||
@ -419,24 +458,20 @@ class Account extends Eloquent
|
|||||||
|
|
||||||
public function getLogoWidth()
|
public function getLogoWidth()
|
||||||
{
|
{
|
||||||
$path = $this->getLogoFullPath();
|
if(!$this->hasLogo()){
|
||||||
if (!file_exists($path)) {
|
return null;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
list($width, $height) = getimagesize($path);
|
|
||||||
|
|
||||||
return $width;
|
return $this->logo_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLogoHeight()
|
public function getLogoHeight()
|
||||||
{
|
{
|
||||||
$path = $this->getLogoFullPath();
|
if(!$this->hasLogo()){
|
||||||
if (!file_exists($path)) {
|
return null;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
list($width, $height) = getimagesize($path);
|
|
||||||
|
|
||||||
return $height;
|
return $this->logo_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createInvoice($entityType = ENTITY_INVOICE, $clientId = null)
|
public function createInvoice($entityType = ENTITY_INVOICE, $clientId = null)
|
||||||
@ -815,12 +850,11 @@ class Account extends Eloquent
|
|||||||
|
|
||||||
public function getLogoSize()
|
public function getLogoSize()
|
||||||
{
|
{
|
||||||
if (!$this->hasLogo()) {
|
if(!$this->hasLogo()){
|
||||||
return 0;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$filename = $this->getLogoFullPath();
|
return round($this->logo_size / 1000);
|
||||||
return round(File::size($filename) / 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isLogoTooLarge()
|
public function isLogoTooLarge()
|
||||||
|
@ -475,7 +475,7 @@ class AccountRepository
|
|||||||
$item->account_id = $user->account->id;
|
$item->account_id = $user->account->id;
|
||||||
$item->account_name = $user->account->getDisplayName();
|
$item->account_name = $user->account->getDisplayName();
|
||||||
$item->pro_plan_paid = $user->account->pro_plan_paid;
|
$item->pro_plan_paid = $user->account->pro_plan_paid;
|
||||||
$item->logo_path = $user->account->hasLogo() ? $user->account->getLogoPath() : null;
|
$item->logo_url = $user->account->hasLogo() ? $user->account->getLogoUrl() : null;
|
||||||
$data[] = $item;
|
$data[] = $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,8 +22,15 @@ class AppServiceProvider extends ServiceProvider {
|
|||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
Form::macro('image_data', function($imagePath) {
|
Form::macro('image_data', function($image, $contents = false) {
|
||||||
return 'data:image/jpeg;base64,' . base64_encode(file_get_contents($imagePath));
|
if(!$contents){
|
||||||
|
$contents = file_get_contents($image);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$contents = $image;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'data:image/jpeg;base64,' . base64_encode($contents);
|
||||||
});
|
});
|
||||||
|
|
||||||
Form::macro('nav_link', function($url, $text, $url2 = '', $extra = '') {
|
Form::macro('nav_link', function($url, $text, $url2 = '', $extra = '') {
|
||||||
|
@ -48,22 +48,32 @@ return [
|
|||||||
'root' => storage_path().'/app',
|
'root' => storage_path().'/app',
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'logos' => [
|
||||||
|
'driver' => 'local',
|
||||||
|
'root' => env('LOGO_PATH', public_path().'/logo'),
|
||||||
|
],
|
||||||
|
|
||||||
|
'documents' => [
|
||||||
|
'driver' => 'local',
|
||||||
|
'root' => storage_path().'/documents',
|
||||||
|
],
|
||||||
|
|
||||||
's3' => [
|
's3' => [
|
||||||
'driver' => 's3',
|
'driver' => 's3',
|
||||||
'key' => 'your-key',
|
'key' => env('S3_KEY', ''),
|
||||||
'secret' => 'your-secret',
|
'secret' => env('S3_SECRET', ''),
|
||||||
'region' => 'your-region',
|
'region' => env('S3_REGION', ''),
|
||||||
'bucket' => 'your-bucket',
|
'bucket' => env('S3_BUCKET', ''),
|
||||||
],
|
],
|
||||||
|
|
||||||
'rackspace' => [
|
'rackspace' => [
|
||||||
'driver' => 'rackspace',
|
'driver' => 'rackspace',
|
||||||
'username' => 'your-username',
|
'username' => env('RACKSPACE_USERNAME', ''),
|
||||||
'key' => 'your-key',
|
'key' => env('RACKSPACE_KEY', ''),
|
||||||
'container' => 'your-container',
|
'container' => env('RACKSPACE_CONTAINER', ''),
|
||||||
'endpoint' => 'https://identity.api.rackspacecloud.com/v2.0/',
|
'endpoint' => env('RACKSPACE_ENDPOINT', 'https://identity.api.rackspacecloud.com/v2.0/'),
|
||||||
'region' => 'IAD',
|
'region' => env('RACKSPACE_REGION', 'https://identity.api.rackspacecloud.com/v2.0/'),
|
||||||
'url_type' => 'publicURL'
|
'url_type' => env('RACKSPACE_URL_TYPE', 'publicURL')
|
||||||
],
|
],
|
||||||
|
|
||||||
],
|
],
|
||||||
|
37
database/migrations/2016_03_22_168364_add_documents.php
Normal file
37
database/migrations/2016_03_22_168364_add_documents.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use DB;
|
||||||
|
|
||||||
|
class AddDocuments extends Migration {
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
/*Schema::table('accounts', function($table) {
|
||||||
|
$table->string('logo')->nullable()->default(null);
|
||||||
|
$table->unsignedInteger('logo_width');
|
||||||
|
$table->unsignedInteger('logo_height');
|
||||||
|
$table->unsignedInteger('logo_size');
|
||||||
|
});*/
|
||||||
|
|
||||||
|
DB::table('accounts')->update(array('logo' => ''));
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('accounts', function($table) {
|
||||||
|
$table->dropColumn('logo');
|
||||||
|
$table->dropColumn('logo_width');
|
||||||
|
$table->dropColumn('logo_height');
|
||||||
|
$table->dropColumn('logo_size');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -51,8 +51,8 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="col-lg-4 col-sm-4"></div>
|
<div class="col-lg-4 col-sm-4"></div>
|
||||||
<div class="col-lg-8 col-sm-8">
|
<div class="col-lg-8 col-sm-8">
|
||||||
<a href="/{{ $account->getLogoPath().'?no_cache='.time() }}" target="_blank">
|
<a href="{{ $account->getLogoUrl().'?no_cache='.time() }}" target="_blank">
|
||||||
{!! HTML::image($account->getLogoPath().'?no_cache='.time(), 'Logo', ['max-width' => 200]) !!}
|
{!! HTML::image($account->getLogoUrl().'?no_cache='.time(), 'Logo', ['max-width' => 200]) !!}
|
||||||
</a>
|
</a>
|
||||||
<a href="#" onclick="deleteLogo()">{{ trans('texts.remove_logo') }}</a>
|
<a href="#" onclick="deleteLogo()">{{ trans('texts.remove_logo') }}</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<a href="{{ $account->website }}" style="color: #19BB40; text-decoration: underline;">
|
<a href="{{ $account->website }}" style="color: #19BB40; text-decoration: underline;">
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
<img src="{{ $message->embed($account->getLogoFullPath()) }}" style="max-height:50px; max-width:140px; margin-left: 33px;" />
|
<img src="{{ $message->embed($account->getLogoURL()) }}" style="max-height:50px; max-width:140px; margin-left: 33px;" />
|
||||||
|
|
||||||
@if ($account->website)
|
@if ($account->website)
|
||||||
</a>
|
</a>
|
||||||
|
@ -448,7 +448,7 @@
|
|||||||
'user_id' => $item->user_id,
|
'user_id' => $item->user_id,
|
||||||
'account_name' => $item->account_name,
|
'account_name' => $item->account_name,
|
||||||
'user_name' => $item->user_name,
|
'user_name' => $item->user_name,
|
||||||
'logo_path' => isset($item->logo_path) ? $item->logo_path : "",
|
'logo_url' => isset($item->logo_url) ? $item->logo_url : "",
|
||||||
'selected' => true,
|
'selected' => true,
|
||||||
])
|
])
|
||||||
@endif
|
@endif
|
||||||
@ -460,7 +460,7 @@
|
|||||||
'user_id' => $item->user_id,
|
'user_id' => $item->user_id,
|
||||||
'account_name' => $item->account_name,
|
'account_name' => $item->account_name,
|
||||||
'user_name' => $item->user_name,
|
'user_name' => $item->user_name,
|
||||||
'logo_path' => isset($item->logo_path) ? $item->logo_path : "",
|
'logo_url' => isset($item->logo_url) ? $item->logo_url : "",
|
||||||
'selected' => false,
|
'selected' => false,
|
||||||
])
|
])
|
||||||
@endif
|
@endif
|
||||||
@ -469,7 +469,7 @@
|
|||||||
@include('user_account', [
|
@include('user_account', [
|
||||||
'account_name' => Auth::user()->account->name ?: trans('texts.untitled'),
|
'account_name' => Auth::user()->account->name ?: trans('texts.untitled'),
|
||||||
'user_name' => Auth::user()->getDisplayName(),
|
'user_name' => Auth::user()->getDisplayName(),
|
||||||
'logo_path' => Auth::user()->account->getLogoPath(),
|
'logo_url' => Auth::user()->account->getLogoURL(),
|
||||||
'selected' => true,
|
'selected' => true,
|
||||||
])
|
])
|
||||||
@endif
|
@endif
|
||||||
|
@ -95,7 +95,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-3 logo">
|
<div class="col-md-3 logo">
|
||||||
@if ($account->hasLogo())
|
@if ($account->hasLogo())
|
||||||
{!! HTML::image($account->getLogoPath()) !!}
|
{!! HTML::image($account->getLogoURL()) !!}
|
||||||
@else
|
@else
|
||||||
<h2>{{ $account->name}}</h2>
|
<h2>{{ $account->name}}</h2>
|
||||||
@endif
|
@endif
|
||||||
|
@ -971,7 +971,7 @@
|
|||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if ($account->hasLogo())
|
@if ($account->hasLogo())
|
||||||
invoice.image = "{{ Form::image_data($account->getLogoPath()) }}";
|
invoice.image = "{{ Form::image_data($account->getLogoRaw(), true) }}";
|
||||||
invoice.imageWidth = {{ $account->getLogoWidth() }};
|
invoice.imageWidth = {{ $account->getLogoWidth() }};
|
||||||
invoice.imageHeight = {{ $account->getLogoHeight() }};
|
invoice.imageHeight = {{ $account->getLogoHeight() }};
|
||||||
@endif
|
@endif
|
||||||
|
@ -75,7 +75,7 @@
|
|||||||
logoImages.imageLogoHeight3 = 81/2;
|
logoImages.imageLogoHeight3 = 81/2;
|
||||||
|
|
||||||
@if ($account->hasLogo())
|
@if ($account->hasLogo())
|
||||||
window.accountLogo = "{{ Form::image_data($account->getLogoPath()) }}";
|
window.accountLogo = "{{ Form::image_data($account->getLogoRaw(), true) }}";
|
||||||
if (window.invoice) {
|
if (window.invoice) {
|
||||||
invoice.image = window.accountLogo;
|
invoice.image = window.accountLogo;
|
||||||
invoice.imageWidth = {{ $account->getLogoWidth() }};
|
invoice.imageWidth = {{ $account->getLogoWidth() }};
|
||||||
|
@ -9,9 +9,9 @@
|
|||||||
<a href="{{ URL::to("/settings/user_details") }}">
|
<a href="{{ URL::to("/settings/user_details") }}">
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if (file_exists($logo_path))
|
@if (!empty($logo_url))
|
||||||
<div class="pull-left" style="height: 40px; margin-right: 16px;">
|
<div class="pull-left" style="height: 40px; margin-right: 16px;">
|
||||||
<img style="width: 40px; margin-top:6px" src="{{ asset($logo_path) }}"/>
|
<img style="width: 40px; margin-top:6px" src="{{ asset($logo_url) }}"/>
|
||||||
</div>
|
</div>
|
||||||
@else
|
@else
|
||||||
<div class="pull-left" style="width: 40px; min-height: 40px; margin-right: 16px"> </div>
|
<div class="pull-left" style="width: 40px; min-height: 40px; margin-right: 16px"> </div>
|
||||||
|
@ -24,8 +24,8 @@
|
|||||||
@foreach (Session::get(SESSION_USER_ACCOUNTS) as $account)
|
@foreach (Session::get(SESSION_USER_ACCOUNTS) as $account)
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
@if (isset($account->logo_path))
|
@if (isset($account->logo_url))
|
||||||
{!! HTML::image($account->logo_path.'?no_cache='.time(), 'Logo', ['width' => 100]) !!}
|
{!! HTML::image($account->logo_url.'?no_cache='.time(), 'Logo', ['width' => 100]) !!}
|
||||||
@endif
|
@endif
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user