Updates
This commit is contained in:
117
app/FaveoStorage/Controllers/SettingsController.php
Normal file
117
app/FaveoStorage/Controllers/SettingsController.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace App\FaveoStorage\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Model\helpdesk\Settings\CommonSettings;
|
||||
use Exception;
|
||||
use RecursiveIteratorIterator;
|
||||
use RecursiveDirectoryIterator;
|
||||
use Artisan;
|
||||
use Lang;
|
||||
|
||||
class SettingsController extends Controller {
|
||||
|
||||
public function settingsIcon() {
|
||||
return ' <div class="col-md-2 col-sm-6">
|
||||
<div class="settingiconblue">
|
||||
<div class="settingdivblue">
|
||||
<a href="' . url('storage') . '">
|
||||
<span class="fa-stack fa-2x">
|
||||
<i class="fa fa-save fa-stack-1x"></i>
|
||||
</span>
|
||||
</a>
|
||||
</div>
|
||||
<p class="box-title" >'.Lang::get("storage::lang.storage").'</p>
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
public function settings() {
|
||||
try {
|
||||
$settings = new CommonSettings();
|
||||
$directories = $this->directories();
|
||||
$def = $settings->getOptionValue('storage', 'default');
|
||||
$ro = $settings->getOptionValue('storage', 'root');
|
||||
$default = 'local';
|
||||
$root = storage_path('app');
|
||||
if ($def) {
|
||||
$default = $def->option_value;
|
||||
}
|
||||
if ($ro) {
|
||||
$root = $ro->option_value;
|
||||
}
|
||||
return view('storage::settings', compact('default', 'root', 'directories'));
|
||||
} catch (Exception $ex) {
|
||||
return redirect()->back()->with('fails', $ex->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function postSettings(Request $request) {
|
||||
try {
|
||||
$requests = $request->except('_token');
|
||||
$this->delete();
|
||||
if (count($requests) > 0) {
|
||||
foreach ($requests as $key => $value) {
|
||||
if ($value) {
|
||||
$this->save($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return redirect()->back()->with('success', 'Updated');
|
||||
} catch (Exception $ex) {
|
||||
return redirect()->back()->with('fails', $ex->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$settings = CommonSettings::where('option_name', 'storage')->get();
|
||||
if ($settings->count() > 0) {
|
||||
foreach ($settings as $setting) {
|
||||
$setting->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function save($key, $value) {
|
||||
CommonSettings::create([
|
||||
'option_name' => 'storage',
|
||||
'optional_field' => $key,
|
||||
'option_value' => $value,
|
||||
]);
|
||||
}
|
||||
|
||||
public function directories($root = "") {
|
||||
if ($root == "") {
|
||||
$root = base_path();
|
||||
}
|
||||
|
||||
$iter = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($root, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied"
|
||||
);
|
||||
|
||||
$paths = array($root);
|
||||
foreach ($iter as $path => $dir) {
|
||||
if ($dir->isDir()) {
|
||||
$paths[$path] = $path;
|
||||
}
|
||||
}
|
||||
|
||||
return $paths;
|
||||
}
|
||||
|
||||
public function attachment() {
|
||||
$storage = new StorageController();
|
||||
$storage->upload();
|
||||
}
|
||||
|
||||
public function activate(){
|
||||
$path = "app".DIRECTORY_SEPARATOR."FaveoStorage".DIRECTORY_SEPARATOR."database".DIRECTORY_SEPARATOR."migrations";
|
||||
Artisan::call('migrate', [
|
||||
'--path' => $path,
|
||||
'--force'=>true,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
225
app/FaveoStorage/Controllers/StorageController.php
Normal file
225
app/FaveoStorage/Controllers/StorageController.php
Normal file
@@ -0,0 +1,225 @@
|
||||
<?php
|
||||
|
||||
namespace App\FaveoStorage\Controllers;
|
||||
|
||||
use Storage;
|
||||
use App\Model\helpdesk\Settings\CommonSettings;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Config;
|
||||
use App\Model\helpdesk\Ticket\Ticket_attachments;
|
||||
use App\Model\helpdesk\Ticket\Ticket_Thread;
|
||||
|
||||
class StorageController extends Controller {
|
||||
|
||||
protected $default;
|
||||
protected $driver;
|
||||
protected $root;
|
||||
protected $s3_key;
|
||||
protected $s3_region;
|
||||
protected $s3_secret;
|
||||
protected $s3_bucket;
|
||||
protected $rackspace_key;
|
||||
protected $rackspace_region;
|
||||
protected $rackspace_username;
|
||||
protected $rackspace_container;
|
||||
protected $rackspace_endpoint;
|
||||
protected $rackspace_url_type;
|
||||
|
||||
public function __construct() {
|
||||
$this->default = $this->defaults();
|
||||
$this->driver = $this->driver();
|
||||
$this->root = $this->root();
|
||||
$this->s3_key = $this->s3Key();
|
||||
$this->s3_region = $this->s3Region();
|
||||
$this->s3_bucket = $this->s3Bucket();
|
||||
$this->rackspace_container = $this->rackspaceContainer();
|
||||
$this->rackspace_endpoint = $this->rackspaceEndpoint();
|
||||
$this->rackspace_key = $this->rackspaceKey();
|
||||
$this->rackspace_region = $this->rackspaceRegion();
|
||||
$this->rackspace_url_type = $this->rackspaceUrlType();
|
||||
$this->rackspace_username = $this->rackspaceUsername();
|
||||
}
|
||||
|
||||
protected function settings($option) {
|
||||
$settings = new CommonSettings();
|
||||
$setting = $settings->getOptionValue('storage', $option);
|
||||
$value = "";
|
||||
if ($setting) {
|
||||
$value = $setting->option_value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function defaults() {
|
||||
$default = "local";
|
||||
if ($this->settings('default')) {
|
||||
$default = $this->settings('default');
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
public function driver() {
|
||||
return $this->settings('default');
|
||||
}
|
||||
|
||||
public function root() {
|
||||
$root = storage_path('app');
|
||||
if ($this->settings('root')) {
|
||||
$root = $this->settings('root');
|
||||
}
|
||||
return $root;
|
||||
}
|
||||
|
||||
public function s3Key() {
|
||||
return $this->settings('s3_key');
|
||||
}
|
||||
|
||||
public function s3Region() {
|
||||
return $this->settings('s3_region');
|
||||
}
|
||||
|
||||
public function s3Secret() {
|
||||
return $this->settings('s3_secret');
|
||||
}
|
||||
|
||||
public function s3Bucket() {
|
||||
return $this->settings('s3_bucket');
|
||||
}
|
||||
|
||||
public function rackspaceKey() {
|
||||
return $this->settings('root');
|
||||
}
|
||||
|
||||
public function rackspaceRegion() {
|
||||
return $this->settings('rackspace_region');
|
||||
}
|
||||
|
||||
public function rackspaceUsername() {
|
||||
return $this->settings('rackspace_username');
|
||||
}
|
||||
|
||||
public function rackspaceContainer() {
|
||||
return $this->settings('rackspace_container');
|
||||
}
|
||||
|
||||
public function rackspaceEndpoint() {
|
||||
return $this->settings('rackspace_endpoint');
|
||||
}
|
||||
|
||||
public function rackspaceUrlType() {
|
||||
return $this->settings('rackspace_url_type');
|
||||
}
|
||||
|
||||
protected function setFileSystem() {
|
||||
$config = $this->config();
|
||||
//dd($config);
|
||||
foreach ($config as $key => $con) {
|
||||
if (is_array($con)) {
|
||||
foreach ($con as $k => $v) {
|
||||
Config::set("filesystem.$key.$k", $v);
|
||||
}
|
||||
}
|
||||
Config::set("filesystem.$key", $con);
|
||||
}
|
||||
return Config::get('filesystem');
|
||||
}
|
||||
|
||||
protected function config() {
|
||||
return [
|
||||
'default' => $this->default,
|
||||
'cloud' => 's3',
|
||||
'disks' => $this->disks(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function disks() {
|
||||
return [
|
||||
"local" => [
|
||||
'driver' => "local",
|
||||
'root' => $this->root . '/attachments',
|
||||
],
|
||||
"s3" => [
|
||||
'driver' => "s3",
|
||||
'key' => $this->s3_key,
|
||||
'secret' => $this->s3_secret,
|
||||
'region' => $this->s3_region,
|
||||
'bucket' => $this->s3_bucket,
|
||||
],
|
||||
"rackspace" => [
|
||||
'driver' => "rackspace",
|
||||
'username' => $this->rackspace_username,
|
||||
'key' => $this->rackspace_key,
|
||||
'container' => $this->rackspace_container,
|
||||
'endpoint' => $this->rackspace_endpoint,
|
||||
'region' => $this->rackspace_region,
|
||||
'url_type' => $this->rackspace_url_type,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function upload($data, $filename, $type, $size, $disposition, $thread_id) {
|
||||
$upload = new Ticket_attachments();
|
||||
$upload->thread_id = $thread_id;
|
||||
$upload->name = $filename;
|
||||
$upload->type = $type;
|
||||
$upload->size = $size;
|
||||
$upload->poster = $disposition;
|
||||
$upload->driver = $this->default;
|
||||
$upload->path = $this->root;
|
||||
if ($this->default !== "database") {
|
||||
$this->setFileSystem();
|
||||
Storage::disk($this->default)->put($filename, $data);
|
||||
} else {
|
||||
$upload->file = $data;
|
||||
}
|
||||
if ($data && $size && $disposition) {
|
||||
$upload->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function saveAttachments($thread_id, $attachments = []) {
|
||||
if (is_array($attachments) && count($attachments) > 0) {
|
||||
foreach ($attachments as $attachment) {
|
||||
$structure = $attachment->getStructure();
|
||||
$disposition = 'ATTACHMENT';
|
||||
if (isset($structure->disposition)) {
|
||||
$disposition = $structure->disposition;
|
||||
}
|
||||
$filename = str_random(16) . '-' . $attachment->getFileName();
|
||||
$type = $attachment->getMimeType();
|
||||
$size = $attachment->getSize();
|
||||
$data = $attachment->getData();
|
||||
$this->upload($data, $filename, $type, $size, $disposition, $thread_id);
|
||||
$this->updateBody($attachment, $thread_id, $filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function updateBody($attachment, $thread_id, $filename) {
|
||||
$structure = $attachment->getStructure();
|
||||
$disposition = 'ATTACHMENT';
|
||||
if (isset($structure->disposition)) {
|
||||
$disposition = $structure->disposition;
|
||||
}
|
||||
if ($disposition == 'INLINE' || $disposition == 'inline') {
|
||||
$id = str_replace(">", "", str_replace("<", "", $structure->id));
|
||||
$threads = new Ticket_Thread();
|
||||
$thread = $threads->find($thread_id);
|
||||
$body = $thread->body;
|
||||
$body = str_replace('cid:' . $id, $filename, $body);
|
||||
$thread->body = $body;
|
||||
$thread->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function getFile($drive, $name) {
|
||||
//dd($drive,$name);
|
||||
if ($drive != "database") {
|
||||
$this->setFileSystem();
|
||||
if(Storage::disk($this->default)->exists($name)){
|
||||
return Storage::disk($this->default)->get($name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
48
app/FaveoStorage/StorageServiceProvider.php
Normal file
48
app/FaveoStorage/StorageServiceProvider.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\FaveoStorage;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class StorageServiceProvider extends ServiceProvider {
|
||||
|
||||
/**
|
||||
* Bootstrap the application events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot() {
|
||||
|
||||
$view_path = app_path() . DIRECTORY_SEPARATOR . 'FaveoStorage' . DIRECTORY_SEPARATOR . 'views';
|
||||
$this->loadViewsFrom($view_path, 'storage');
|
||||
|
||||
$lang_path = app_path() . DIRECTORY_SEPARATOR . 'FaveoStorage' . DIRECTORY_SEPARATOR . 'lang';
|
||||
$this->loadTranslationsFrom($lang_path, "storage");
|
||||
|
||||
if (isInstall()) {
|
||||
$controller = new Controllers\SettingsController();
|
||||
$controller->activate();
|
||||
}
|
||||
|
||||
if (class_exists('Breadcrumbs')) {
|
||||
require __DIR__ . '/breadcrumbs.php';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
// Add routes
|
||||
if (isInstall()) {
|
||||
$routes = app_path('/FaveoStorage/routes.php');
|
||||
if (file_exists($routes)) {
|
||||
require $routes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
6
app/FaveoStorage/breadcrumbs.php
Normal file
6
app/FaveoStorage/breadcrumbs.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
Breadcrumbs::register('storage', function($breadcrumbs)
|
||||
{
|
||||
$breadcrumbs->parent('setting');
|
||||
$breadcrumbs->push('Storage', route('storage'));
|
||||
});
|
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AlterAttachmentTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('ticket_attachment', function (Blueprint $table) {
|
||||
$table->string('driver');
|
||||
$table->string('path');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('ticket_attachment', function (Blueprint $table) {
|
||||
$table->string('driver');
|
||||
$table->string('path');
|
||||
});
|
||||
}
|
||||
}
|
17
app/FaveoStorage/lang/en/lang.php
Normal file
17
app/FaveoStorage/lang/en/lang.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'settings'=>'Settings',
|
||||
'storage'=>'Storage',
|
||||
'default'=>'Default',
|
||||
'root'=>'Root',
|
||||
'region'=>'Region',
|
||||
'key'=>'Key',
|
||||
'secret'=>'Secret',
|
||||
'bucket'=>'Bucket',
|
||||
'username'=>'Username',
|
||||
'container'=>'Container',
|
||||
'endpoint'=>'End Point',
|
||||
'url_type'=>'Url Type',
|
||||
];
|
||||
|
16
app/FaveoStorage/routes.php
Normal file
16
app/FaveoStorage/routes.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
\Event::listen('settings.system',function(){
|
||||
$controller = new \App\FaveoStorage\Controllers\SettingsController();
|
||||
echo $controller->settingsIcon();
|
||||
});
|
||||
|
||||
|
||||
Route::group(['middleware'=>['web']],function(){
|
||||
Route::get('storage',['as'=>'storage','uses'=>'App\FaveoStorage\Controllers\SettingsController@settings']);
|
||||
Route::post('storage',['as'=>'post.storage','uses'=>'App\FaveoStorage\Controllers\SettingsController@postSettings']);
|
||||
Route::get('attachment',['as'=>'attach','uses'=>'App\FaveoStorage\Controllers\SettingsController@attachment']);
|
||||
|
||||
});
|
||||
|
||||
|
139
app/FaveoStorage/views/settings.blade.php
Normal file
139
app/FaveoStorage/views/settings.blade.php
Normal file
@@ -0,0 +1,139 @@
|
||||
@extends('themes.default1.admin.layout.admin')
|
||||
@section('content')
|
||||
<section class="content-header">
|
||||
<h1> {{Lang::get('storage::lang.settings')}} </h1>
|
||||
|
||||
</section>
|
||||
<div class="box box-primary">
|
||||
|
||||
<div class="box-header with-border">
|
||||
<h4> {{Lang::get('storage::lang.storage')}} </h4>
|
||||
@if (count($errors) > 0)
|
||||
<div class="alert alert-danger">
|
||||
<strong>Whoops!</strong> There were some problems with your input.<br><br>
|
||||
<ul>
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if(Session::has('success'))
|
||||
<div class="alert alert-success alert-dismissable">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||
{{Session::get('success')}}
|
||||
</div>
|
||||
@endif
|
||||
<!-- fail message -->
|
||||
@if(Session::has('fails'))
|
||||
<div class="alert alert-danger alert-dismissable">
|
||||
<i class="fa fa-ban"></i>
|
||||
<b>{{Lang::get('message.alert')}}!</b> {{Lang::get('message.failed')}}.
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||
{{Session::get('fails')}}
|
||||
</div>
|
||||
@endif
|
||||
{!! Form::open(['url'=>'storage','method'=>'post']) !!}
|
||||
</div><!-- /.box-header -->
|
||||
<!-- /.box-header -->
|
||||
<div class="box-body">
|
||||
<div class="row">
|
||||
<div class="form-group col-md-8 {{ $errors->has('default') ? 'has-error' : '' }}">
|
||||
{!! Form::label('default',Lang::get('storage::lang.default')) !!}
|
||||
{!! Form::select('default',['database'=>'Database','local'=>'Local'],$default,['class'=>'form-control']) !!}
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-6 {{ $errors->has('root') ? 'has-error' : '' }}" id="root" style="display: none;">
|
||||
{!! Form::label('root',Lang::get('storage::lang.root')) !!}
|
||||
{!! Form::select('root',$directories,$root,['class'=>'form-control']) !!}
|
||||
</div>
|
||||
<div id="common" style="display: none;">
|
||||
<div class="form-group col-md-6 {{ $errors->has('key') ? 'has-error' : '' }}">
|
||||
{!! Form::label('key',Lang::get('storage::lang.key')) !!}
|
||||
{!! Form::text('key',null,['class'=>'form-control']) !!}
|
||||
</div>
|
||||
<div class="form-group col-md-6 {{ $errors->has('region') ? 'has-error' : '' }}">
|
||||
{!! Form::label('region',Lang::get('storage::lang.region')) !!}
|
||||
{!! Form::text('region',null,['class'=>'form-control']) !!}
|
||||
</div>
|
||||
</div>
|
||||
<div id="s3" style="display: none;">
|
||||
<div class="form-group col-md-6 {{ $errors->has('secret') ? 'has-error' : '' }}">
|
||||
{!! Form::label('secret',Lang::get('storage::lang.secret')) !!}
|
||||
{!! Form::text('secret',null,['class'=>'form-control']) !!}
|
||||
</div>
|
||||
<div class="form-group col-md-6 {{ $errors->has('bucket') ? 'has-error' : '' }}">
|
||||
{!! Form::label('bucket',Lang::get('storage::lang.bucket')) !!}
|
||||
{!! Form::text('bucket',null,['class'=>'form-control']) !!}
|
||||
</div>
|
||||
</div>
|
||||
<div id="rackspace" style="display: none;">
|
||||
<div class="form-group col-md-6 {{ $errors->has('username') ? 'has-error' : '' }}">
|
||||
{!! Form::label('username',Lang::get('storage::lang.username')) !!}
|
||||
{!! Form::text('username',null,['class'=>'form-control']) !!}
|
||||
</div>
|
||||
<div class="form-group col-md-6 {{ $errors->has('container') ? 'has-error' : '' }}">
|
||||
{!! Form::label('container',Lang::get('storage::lang.container')) !!}
|
||||
{!! Form::text('container',null,['class'=>'form-control']) !!}
|
||||
</div>
|
||||
<div class="form-group col-md-6 {{ $errors->has('endpoint') ? 'has-error' : '' }}">
|
||||
{!! Form::label('endpoint',Lang::get('storage::lang.endpoint')) !!}
|
||||
{!! Form::text('endpoint',null,['class'=>'form-control']) !!}
|
||||
</div>
|
||||
<div class="form-group col-md-6 {{ $errors->has('url_type') ? 'has-error' : '' }}">
|
||||
{!! Form::label('url_type',Lang::get('storage::lang.url_type')) !!}
|
||||
{!! Form::text('url_type',null,['class'=>'form-control']) !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
<!-- /.box-body -->
|
||||
</div>
|
||||
<div class="box-footer">
|
||||
{!! Form::submit('Save',['class'=>'btn btn-success']) !!}
|
||||
{!! Form::close() !!}
|
||||
</div>
|
||||
<!-- /.box -->
|
||||
</div>
|
||||
@stop
|
||||
@section('FooterInclude')
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
var defaults = $("#default").val();
|
||||
switches(defaults);
|
||||
$("#default").on("change", function () {
|
||||
defaults = $("#default").val();
|
||||
switches(defaults);
|
||||
});
|
||||
function switches(defaults) {
|
||||
if(defaults=="local"){
|
||||
$("#common").hide();
|
||||
$("#s3").hide();
|
||||
$("#rackspace").hide();
|
||||
$("#root").show();
|
||||
}
|
||||
if(defaults=="s3"){
|
||||
$("#root").hide();
|
||||
$("#rackspace").hide();
|
||||
$("#common").show();
|
||||
$("#s3").show();
|
||||
}
|
||||
if(defaults=="rackspace"){
|
||||
$("#root").hide();
|
||||
$("#s3").hide();
|
||||
$("#common").show();
|
||||
$("#rackspace").show();
|
||||
}
|
||||
if(defaults=="database"){
|
||||
$("#root").hide();
|
||||
$("#s3").hide();
|
||||
$("#common").hide();
|
||||
$("#rackspace").hide();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@stop
|
Reference in New Issue
Block a user