17 Nov - Static Sites to laravel
This commit is contained in:
parent
610aa1e202
commit
5ff57a21a7
3661 changed files with 569001 additions and 771 deletions
88
app/Http/Controllers/AttributeController.php
Executable file
88
app/Http/Controllers/AttributeController.php
Executable file
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
|
||||
use App\Models\Attribute;
|
||||
use App\Models\ProductAttribute;
|
||||
use Input;
|
||||
|
||||
|
||||
class AttributeController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('admin');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
$data = [
|
||||
'values' => Attribute::all(),
|
||||
'trans' => array_keys(config('localization.supportedLocales')),
|
||||
];
|
||||
return view('admin.attribute.index', $data);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
|
||||
|
||||
|
||||
$data = Input::all();
|
||||
if($data['id'] == "new"){
|
||||
$model = Attribute::create([
|
||||
'parent_id' => null,
|
||||
'name' => $data['name'],
|
||||
'pos' => $data['pos'],
|
||||
'active' => isset($data['active']) ? true : false,
|
||||
]);
|
||||
}else{
|
||||
$model = Attribute::find($data['id']);
|
||||
$model->parent_id = null;
|
||||
$model->name = $data['name'];
|
||||
$model->pos = $data['pos'];
|
||||
$model->active = isset($data['active']) ? true : false;
|
||||
$model->save();
|
||||
}
|
||||
|
||||
if(!empty($data['trans'])){
|
||||
$trans = [];
|
||||
foreach ($data['trans'] as $lang => $value){
|
||||
if($value && $value != null){
|
||||
$trans[$lang] = $value;
|
||||
}
|
||||
}
|
||||
if(count($trans)){
|
||||
$model->trans_name = $trans;
|
||||
$model->save();
|
||||
}
|
||||
}
|
||||
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect(route('admin_product_attributes'));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function delete($id){
|
||||
|
||||
if(ProductAttribute::where('attribute_id', $id)->count()){
|
||||
\Session()->flash('alert-error', 'Eintrag wird als Produktattribute verwendet');
|
||||
return redirect(route('admin_product_attributes'));
|
||||
}
|
||||
/* if(Attribute::where('parent_id', $id)->count()){
|
||||
\Session()->flash('alert-error', 'Eintrag wird als Main Attribute verwendet');
|
||||
return redirect(route('admin_industry_sectors'));
|
||||
}
|
||||
*/
|
||||
$model = Attribute::findOrFail($id);
|
||||
$model->delete();
|
||||
\Session()->flash('alert-success', 'Eintrag gelöscht');
|
||||
return redirect(route('admin_product_attributes'));
|
||||
}
|
||||
|
||||
}
|
||||
85
app/Http/Controllers/CategoryController.php
Executable file
85
app/Http/Controllers/CategoryController.php
Executable file
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\ProductCategory;
|
||||
use Input;
|
||||
|
||||
|
||||
class CategoryController extends Controller
|
||||
{
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('admin');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
$data = [
|
||||
'values' => Category::all(),
|
||||
'trans' => array_keys(config('localization.supportedLocales')),
|
||||
];
|
||||
return view('admin.category.index', $data);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
|
||||
$data = Input::all();
|
||||
if($data['id'] == "new"){
|
||||
$model = Category::create([
|
||||
'parent_id' => isset($data['parent_id']) ? $data['parent_id'] : null,
|
||||
'name' => $data['name'],
|
||||
'pos' => $data['pos'],
|
||||
'active' => isset($data['active']) ? true : false,
|
||||
]);
|
||||
}else{
|
||||
$model = Category::find($data['id']);
|
||||
$model->parent_id = isset($data['parent_id']) ? $data['parent_id'] : null;
|
||||
$model->name = $data['name'];
|
||||
$model->pos = $data['pos'];
|
||||
$model->active = isset($data['active']) ? true : false;
|
||||
$model->save();
|
||||
}
|
||||
|
||||
if(!empty($data['trans'])){
|
||||
$trans = [];
|
||||
foreach ($data['trans'] as $lang => $value){
|
||||
if($value && $value != null){
|
||||
$trans[$lang] = $value;
|
||||
}
|
||||
}
|
||||
if(count($trans)){
|
||||
$model->trans_name = $trans;
|
||||
$model->save();
|
||||
}
|
||||
}
|
||||
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect(route('admin_product_categories'));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function delete($id){
|
||||
|
||||
if(ProductCategory::where('category_id', $id)->count()){
|
||||
\Session()->flash('alert-error', 'Eintrag wird als Produkt-Kategorie verwendet');
|
||||
return redirect(route('admin_product_categories'));
|
||||
}
|
||||
if(Category::where('parent_id', $id)->count()){
|
||||
\Session()->flash('alert-error', 'Eintrag wird als Haup-Kategorie verwendet');
|
||||
return redirect(route('admin_product_categories'));
|
||||
}
|
||||
$model = Category::findOrFail($id);
|
||||
$model->delete();
|
||||
\Session()->flash('alert-success', 'Eintrag gelöscht');
|
||||
return redirect(route('admin_product_categories'));
|
||||
}
|
||||
|
||||
}
|
||||
106
app/Http/Controllers/ImportProductController.php
Executable file
106
app/Http/Controllers/ImportProductController.php
Executable file
|
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductImage;
|
||||
use App\Repositories\ProductRepository;
|
||||
use Input;
|
||||
use Validator;
|
||||
|
||||
|
||||
|
||||
class ImportProductController extends Controller
|
||||
{
|
||||
protected $productRepo;
|
||||
|
||||
public function __construct(ProductRepository $productRepo)
|
||||
{
|
||||
$this->middleware('admin');
|
||||
$this->productRepo = $productRepo;
|
||||
|
||||
}
|
||||
|
||||
public function import(){
|
||||
|
||||
$path = app_path().'/../_static/products/';
|
||||
|
||||
include($path.'_all_products.php');
|
||||
|
||||
$slugs = array();
|
||||
|
||||
foreach ($get_products as $c_id => $values){
|
||||
|
||||
foreach ($values as $val){
|
||||
if(in_array($val['slug'], $slugs)){
|
||||
continue;
|
||||
}
|
||||
$slugs[] = $val['slug'];
|
||||
|
||||
include($path.$val['slug'].'.php');
|
||||
|
||||
$data = [
|
||||
'id' => 'new',
|
||||
'name' => $val['name'],
|
||||
'title' => '',
|
||||
'copy' => $copy,
|
||||
'price' => $price,
|
||||
'price_ek' => 0,
|
||||
'tax' => 19,
|
||||
'price_old' => null,
|
||||
'contents' => $content,
|
||||
'number' => $item_no,
|
||||
'icons' => $icons,
|
||||
'description' => $description,
|
||||
'usage' => $usage,
|
||||
'ingredients' => $ingredients,
|
||||
'pos' => null,
|
||||
'amount' => 0,
|
||||
'active' => 1,
|
||||
'categories' => array($c_id),
|
||||
];
|
||||
|
||||
|
||||
$product = $this->productRepo->update($data);
|
||||
//images
|
||||
foreach($images as $image){
|
||||
$i_path = storage_path().'/'.'app'.'/products/' .$val['slug'].'/'.$image['image'];
|
||||
$mine = \File::mimeType($i_path);
|
||||
$ext = \File::extension($i_path);
|
||||
$size = \File::size($i_path);
|
||||
$original_name = $image['image'];
|
||||
|
||||
$name = \App\Services\Slim::sanitizeFileName($image['image']);
|
||||
$name = uniqid() . '_' . $name;
|
||||
|
||||
$img = \Image::make($i_path);
|
||||
$img->resize(600, 800, function ($c) {
|
||||
// $c->aspectRatio();
|
||||
$c->upsize();
|
||||
});
|
||||
//
|
||||
\Storage::put('/public/images/product/'.$product->id.'/'.$name, (string) $img->encode());
|
||||
|
||||
|
||||
ProductImage::create([
|
||||
'product_id' => $product->id,
|
||||
'filename' => $name,
|
||||
'original_name' => $original_name,
|
||||
'ext' => $ext,
|
||||
'mine' => $mine,
|
||||
'size' => $size
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
die("okay");
|
||||
//array('slug' => 'aloe-vera-gel99', 'name' => 'Aloe Vera Gel 99%', 'first' => 'aloe-vera-gel99-1.jpg', 'hover' => 'aloe-vera-gel99-2.jpg'),
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
166
app/Http/Controllers/ProductController.php
Executable file
166
app/Http/Controllers/ProductController.php
Executable file
|
|
@ -0,0 +1,166 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductImage;
|
||||
use App\Repositories\ProductRepository;
|
||||
use Input;
|
||||
use Validator;
|
||||
|
||||
|
||||
|
||||
class ProductController extends Controller
|
||||
{
|
||||
protected $productRepo;
|
||||
|
||||
public function __construct(ProductRepository $productRepo)
|
||||
{
|
||||
$this->middleware('admin');
|
||||
$this->productRepo = $productRepo;
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
$data = [
|
||||
'values' => Product::all(),
|
||||
];
|
||||
return view('admin.product.index', $data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
if($id == "new"){
|
||||
$model = new Product();
|
||||
$model->active = true;
|
||||
}else{
|
||||
$model = Product::findOrFail($id);
|
||||
}
|
||||
$data = [
|
||||
'product' => $model,
|
||||
];
|
||||
return view('admin.product.edit', $data);
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
|
||||
$data = Input::all();
|
||||
|
||||
$rules = array(
|
||||
'name' => 'required',
|
||||
);
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
|
||||
if($data['id'] == "new"){
|
||||
$model = new Product();
|
||||
}else{
|
||||
$model = Product::findOrFail($data['id']);
|
||||
}
|
||||
$data = [
|
||||
'product' => $model,
|
||||
];
|
||||
|
||||
if ($validator->fails()) {
|
||||
|
||||
return view('admin.product.edit', $data)->withErrors($validator);
|
||||
|
||||
} else {
|
||||
$product = $this->productRepo->update(Input::all());
|
||||
\Session()->flash('alert-save', true);
|
||||
return redirect(route('admin_product_edit', [$product->id]));
|
||||
}
|
||||
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect(route('admin_product_show'));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function delete($id){
|
||||
$model = Product::findOrFail($id);
|
||||
$model->delete();
|
||||
\Session()->flash('alert-success', 'Eintrag gelöscht');
|
||||
return redirect(route('admin_product_show'));
|
||||
}
|
||||
|
||||
|
||||
// Upload FILE -----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public function uploadImage(){
|
||||
|
||||
$product_id = Input::get('product_id');
|
||||
$product = Product::findOrFail($product_id);
|
||||
|
||||
try {
|
||||
$image = \App\Services\Slim::getImages('images')[0];
|
||||
|
||||
if ( isset($image['output']['data']) )
|
||||
{
|
||||
|
||||
// Base64 of the image
|
||||
$data = $image['output']['data'];
|
||||
$file_ex = array( 'image/jpeg' => 'jpg', 'image/png' => 'png');
|
||||
|
||||
if (!isset($file_ex[$image['output']['type']])) {
|
||||
\Session()->flash('alert-danger', 'File is not jpg or png!');
|
||||
return redirect(route('admin_product_edit', [$product->id]));
|
||||
}
|
||||
|
||||
$ext = $file_ex[$image['output']['type']];
|
||||
// Original file name
|
||||
$name = $image['output']['name'];
|
||||
$name = \App\Services\Slim::sanitizeFileName($name);
|
||||
$name = uniqid() . '_' . $name;
|
||||
|
||||
$data = \Storage::disk('public')->put(
|
||||
'images/product/'.$product->id.'/'.$name,
|
||||
$data
|
||||
);
|
||||
|
||||
ProductImage::create([
|
||||
'product_id' => $product->id,
|
||||
'filename' => $name,
|
||||
'original_name' => $image['output']['name'],
|
||||
'ext' => $ext,
|
||||
'mine' => $image['output']['type'],
|
||||
'size' => $image['input']['size']
|
||||
]);
|
||||
|
||||
|
||||
\Session()->flash('alert-success', "Datei hochgeladen");
|
||||
return redirect(route('admin_product_edit', [$product->id]));
|
||||
}
|
||||
\Session()->flash('alert-danger', "Datei leer");
|
||||
return redirect(route('admin_product_edit', [$product->id]));
|
||||
|
||||
}
|
||||
catch (Exception $e) {
|
||||
\Session()->flash('alert-danger', "Fehler".$e);
|
||||
return redirect(route('admin_product_edit', [$product->id]));
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteImage($image_id, $product_id){
|
||||
|
||||
$product = Product::findOrFail($product_id);
|
||||
$product_image = ProductImage::findOrFail($image_id);
|
||||
|
||||
if($product_image->product_id == $product->id){
|
||||
$file = 'images/product/'.$product->id.'/'.$product_image->filename;
|
||||
\Storage::disk('public')->delete($file);
|
||||
|
||||
$product_image->delete();
|
||||
|
||||
\Session()->flash('alert-success', "Datei gelöscht");
|
||||
return redirect(route('admin_product_edit', [$product->id]));
|
||||
|
||||
}
|
||||
\Session()->flash('alert-danger', "Datei nicht gefunden");
|
||||
return redirect(route('admin_product_edit', [$product->id]));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ class TranslationController extends Controller
|
|||
*/
|
||||
public function index()
|
||||
{
|
||||
return redirect('admin/translate/edit/de');
|
||||
return redirect('admin/translate/all/edit/de');
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ class TranslationController extends Controller
|
|||
$jsonData = json_encode($ret, TRUE);
|
||||
file_put_contents($file, $jsonData);
|
||||
return redirect()
|
||||
->route('admin_translate_edit', [$language])
|
||||
->route('admin_translate_all_edit', [$language])
|
||||
->with('message', 'Translation added successfully');
|
||||
}
|
||||
|
||||
|
|
|
|||
288
app/Http/Controllers/TranslationFileController.php
Executable file
288
app/Http/Controllers/TranslationFileController.php
Executable file
|
|
@ -0,0 +1,288 @@
|
|||
<?php
|
||||
|
||||
//use Input;
|
||||
//use Request;
|
||||
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App;
|
||||
use File;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
use Illuminate\Support\Collection;
|
||||
use App\Requests\TranslationRequest;
|
||||
|
||||
|
||||
|
||||
|
||||
class TranslationFileController extends Controller
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Translator
|
||||
*
|
||||
* @var \Illuminate\Translation\Translator
|
||||
*/
|
||||
protected $translator;
|
||||
/**
|
||||
* Translation loader
|
||||
*
|
||||
* @var \Illuminate\Translation\LoaderInterface
|
||||
*/
|
||||
protected $loader;
|
||||
|
||||
/**
|
||||
* @var \League\Flysystem\Adapter\Local
|
||||
*/
|
||||
protected $filesystem;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $languagesPath;
|
||||
|
||||
protected $languageRead;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->directory_separator = DIRECTORY_SEPARATOR;
|
||||
$this->translator = App::make('translator');
|
||||
$this->loader = Lang::getLoader();
|
||||
$this->languagesPath = App::langPath();
|
||||
$this->directory_separator = DIRECTORY_SEPARATOR;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$language = App::getLocale();
|
||||
$langsource = 'de';
|
||||
$this->languageRead = $language;
|
||||
$langs = array_keys(config('localization.supportedLocales'));
|
||||
$files = $this->files();
|
||||
$translations = null;
|
||||
$edit = false;
|
||||
$show = 'all';
|
||||
return view('translation.index_file', compact('files', 'translations', 'language', 'langsource', 'langs', 'edit', 'show'));
|
||||
|
||||
//return view('admin.transitions', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display edit form page
|
||||
*
|
||||
* @param string $language
|
||||
* @param string $file
|
||||
* @param string|null $namespace
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($file, $language = 'en', $langsource = 'de', $show = 'all')
|
||||
{
|
||||
$this->languageRead = $language;
|
||||
$langs = array_keys(config('localization.supportedLocales'));
|
||||
$files = $this->files();
|
||||
$translations = $this->translations($file, $langsource);
|
||||
$prefix = $this->groupName($file);
|
||||
$langsource = $langsource;
|
||||
$edit = $file;
|
||||
$show = $show;
|
||||
|
||||
return view('translation.index_file', compact('files', 'language', 'langsource', 'file', 'translations', 'prefix', 'langs', 'edit', 'show'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save translation file
|
||||
*
|
||||
* @param \GeniusTS\TranslationManager\Requests\TranslationRequest $request
|
||||
* @param string $language
|
||||
* @param string $file
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(TranslationRequest $request, $file, $language, $langsource, $show)
|
||||
{
|
||||
$keys = array_keys($this->translations($file));
|
||||
|
||||
$this->exportFile($request->only($keys), $file, $language);
|
||||
|
||||
return redirect()
|
||||
->route('admin_translate_file_edit', [$file, $language, $langsource, $show])
|
||||
->with('message', 'Translation added successfully');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a translation file
|
||||
*
|
||||
* @param array $translation
|
||||
* @param $filename
|
||||
* @param $language
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function exportFile($translation, $filename, $language)
|
||||
{
|
||||
$path = "{$this->languagesPath}{$this->directory_separator}{$language}{$this->directory_separator}{$filename}.php";
|
||||
|
||||
$this->backup($path, $language, $filename);
|
||||
|
||||
$content = "<?php \n\n return " . var_export($translation, true) . ";";
|
||||
|
||||
return (bool) file_put_contents($path, $content);
|
||||
|
||||
//return (bool) $this->filesystem->write($path, $content, new Config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Backup the existing translation files
|
||||
*/
|
||||
private function backup($path, $language, $filename)
|
||||
{
|
||||
if(!File::exists($path)){
|
||||
return;
|
||||
}
|
||||
if (!File::exists(storage_path('language/'.time().'/'.$language))) {
|
||||
File::makeDirectory(storage_path('language/'.time().'/'.$language), 0755, true);
|
||||
}
|
||||
|
||||
return File::copy($path, storage_path('language/'.time().'/'.$language.'/'.$filename.'.php'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the translation of a group and name space
|
||||
*
|
||||
* @param string $file
|
||||
* @param string|null $namespace
|
||||
* @param string|null $language
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function translations($file, $language = null)
|
||||
{
|
||||
$group = $this->groupName($file);
|
||||
$key = $group;
|
||||
|
||||
return $this->translator->trans($key, [], $language ?: $this->defaultLanguage());
|
||||
}
|
||||
|
||||
public function files($lang = false)
|
||||
{
|
||||
$path = $this->namespacePath($this->languagesPath, $lang);
|
||||
|
||||
$content = $this->pathContent($path);
|
||||
|
||||
return $content
|
||||
->map(function ($file) use ($path) {
|
||||
$path = ltrim($path . DIRECTORY_SEPARATOR, '/');
|
||||
//read file empty entries
|
||||
$count = $this->countEmptyEntries(Str::replaceLast($path, '', $file));
|
||||
//var_dump($translations);
|
||||
return array(ltrim($this->groupName(Str::replaceLast($path, '', $file)), '/') => ltrim($this->groupName(Str::replaceLast($path, '', $file)), '/')." (".$count.")");
|
||||
})
|
||||
->flatten();
|
||||
}
|
||||
|
||||
public function countEmptyEntries($file){
|
||||
|
||||
$translation = $this->translations($file);
|
||||
$group = $this->groupName($file);
|
||||
$entries = 0;
|
||||
$count = 0;
|
||||
foreach ($translation as $key => $value)
|
||||
{
|
||||
$this->searchForEmpty($key, $value, null, $count, $entries, $group);
|
||||
}
|
||||
return $entries."/".$count;
|
||||
}
|
||||
|
||||
protected function searchForEmpty($key, $value, $prefix, &$count, &$entries, $group)
|
||||
{
|
||||
$prefix = $prefix ? "{$prefix}.{$key}" : $group.".".$key;
|
||||
if (is_array($value))
|
||||
{
|
||||
foreach ($value as $subKey => $subValue)
|
||||
{
|
||||
$this->searchForEmpty($subKey, $subValue, $prefix, $count,$entries, $group);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Lang::has($prefix, $this->languageRead, false)){
|
||||
$count++;
|
||||
}
|
||||
|
||||
if(Lang::has($prefix, 'de', false)){
|
||||
$entries ++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default language
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function defaultLanguage()
|
||||
{
|
||||
return config('app.fallback_locale', 'de');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the group name from a filename
|
||||
*
|
||||
* @param $filename
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function groupName($filename)
|
||||
{
|
||||
return preg_replace('/\.php$/', '', $filename);
|
||||
}
|
||||
/**
|
||||
* Get default language
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $language
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function namespacePath($path, $language = null)
|
||||
{
|
||||
return "{$path}{$this->directory_separator}" . ($language ?: $this->defaultLanguage());
|
||||
}
|
||||
|
||||
/**
|
||||
* List content of a path
|
||||
*
|
||||
* @param null $path
|
||||
* @param bool $recursive
|
||||
*
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
protected function pathContent($path = null, $recursive = false)
|
||||
{
|
||||
|
||||
//var_dump($this->filesystem->listContents($path, $recursive));
|
||||
//return new Collection(($this->filesystem->listContents($path, $recursive)));
|
||||
return new Collection(File::files($path));
|
||||
}
|
||||
|
||||
}
|
||||
86
app/Http/Controllers/Web/SiteController.php
Executable file
86
app/Http/Controllers/Web/SiteController.php
Executable file
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Web;
|
||||
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Category;
|
||||
use App\Models\Product;
|
||||
use Carbon\Carbon;
|
||||
use Request;
|
||||
use Input;
|
||||
|
||||
class SiteController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('web.index');
|
||||
}
|
||||
|
||||
public function site($site, $subsite = false, $product_slug = false)
|
||||
{
|
||||
|
||||
if($product_slug){
|
||||
$category = Category::where('slug', $subsite)->where('active', true)->first();
|
||||
$product = Product::where('slug', $product_slug)->where('active', true)->first();
|
||||
if ($category && $product) {
|
||||
|
||||
|
||||
$data = [
|
||||
'subsite' => $subsite,
|
||||
'categories' => Category::where('active', true)->orderBy('pos', 'DESC')->get(),
|
||||
'product' => $product,
|
||||
'p_count' => Product::where('active', true)->count(),
|
||||
|
||||
];
|
||||
return view('web.templates.produkte-show', $data);
|
||||
}
|
||||
}
|
||||
|
||||
if($site == 'produkte'){
|
||||
|
||||
if($subsite || $subsite != 'alle-produkte') {
|
||||
$category = Category::where('slug', $subsite)->where('active', true)->first();
|
||||
if ($category) {
|
||||
$data = [
|
||||
'subsite' => $subsite,
|
||||
'categories' => Category::where('active', true)->orderBy('pos', 'DESC')->get(),
|
||||
'products' => Product::whereHas('categories', function ($query) use ($category) {
|
||||
$query->where('category_id', '=', $category->id);
|
||||
|
||||
})->where('active', true)->orderBy('pos', 'DESC')->get(),
|
||||
'p_count' => Product::where('active', true)->count(),
|
||||
|
||||
];
|
||||
return view('web.templates.' . $site, $data);
|
||||
|
||||
}
|
||||
}
|
||||
$data = [
|
||||
'subsite' => 'alle-produkte',
|
||||
'categories' => Category::where('active', true)->orderBy('pos', 'DESC')->get(),
|
||||
'products' => Product::where('active', true)->orderBy('pos', 'DESC')->get(),
|
||||
'p_count' => Product::where('active', true)->count(),
|
||||
];
|
||||
return view('web.templates.'.$site, $data);
|
||||
}
|
||||
|
||||
if($subsite){
|
||||
return view('web.templates.'.$subsite);
|
||||
}
|
||||
|
||||
return view('web.templates.'.$site);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -29,18 +29,13 @@ class MailActivateUser extends Mailable
|
|||
{
|
||||
$salutation = __('Dear customer').",";
|
||||
|
||||
if($this->user->account){
|
||||
if($this->user->account->salutation == "mr"){
|
||||
$salutation = __('Dear Sir')." ".$this->user->account->last_name.",";
|
||||
}else{
|
||||
$salutation = __('Dear Mrs')." ".$this->user->account->last_name.",";
|
||||
}
|
||||
}
|
||||
/* $message = [
|
||||
'link' => route('user.update_email_confirm', $token),
|
||||
'line1' => 'Bitte aktivieren Sie Ihre neue E-Mail über diesen Link:',
|
||||
'line2' => 'oder kopieren Sie diesen Link in die Adressleiste Ihre Browsers.',
|
||||
];*/
|
||||
/*if($this->user->account){
|
||||
if($this->user->account->salutation == "mr"){
|
||||
$salutation = __('Dear Sir')." ".$this->user->account->last_name.",";
|
||||
}else{
|
||||
$salutation = __('Dear Mrs')." ".$this->user->account->last_name.",";
|
||||
}
|
||||
}*/
|
||||
return $this->view('emails.auth')->with([
|
||||
'url' => route('user_update_email_confirm', $this->token),
|
||||
'salutation' => $salutation,
|
||||
|
|
|
|||
|
|
@ -28,14 +28,13 @@ class MailResetPassword extends Mailable
|
|||
public function build()
|
||||
{
|
||||
$salutation = __('Dear customer').",";
|
||||
if($this->user->account){
|
||||
if($this->user->account->salutation == "mr"){
|
||||
$salutation = __('Dear Sir')." ".$this->user->account->last_name.",";
|
||||
}else{
|
||||
$salutation = __('Dear Mrs')." ".$this->user->account->last_name.",";
|
||||
}
|
||||
}
|
||||
|
||||
/*if($this->user->account){
|
||||
if($this->user->account->salutation == "mr"){
|
||||
$salutation = __('Dear Sir')." ".$this->user->account->last_name.",";
|
||||
}else{
|
||||
$salutation = __('Dear Mrs')." ".$this->user->account->last_name.",";
|
||||
}
|
||||
}*/
|
||||
return $this->view('emails.auth')->with([
|
||||
'url' => route('password.reset', $this->token),
|
||||
'salutation' => $salutation,
|
||||
|
|
|
|||
|
|
@ -28,13 +28,13 @@ class MailVerifyAccount extends Mailable
|
|||
public function build()
|
||||
{
|
||||
$salutation = __('Dear customer').",";
|
||||
if($this->user->account){
|
||||
if($this->user->account->salutation == "mr"){
|
||||
$salutation = __('Dear Sir')." ".$this->user->account->last_name.",";
|
||||
}else{
|
||||
$salutation = __('Dear Mrs')." ".$this->user->account->last_name.",";
|
||||
}
|
||||
}
|
||||
/*if($this->user->account){
|
||||
if($this->user->account->salutation == "mr"){
|
||||
$salutation = __('Dear Sir')." ".$this->user->account->last_name.",";
|
||||
}else{
|
||||
$salutation = __('Dear Mrs')." ".$this->user->account->last_name.",";
|
||||
}
|
||||
}*/
|
||||
|
||||
return $this->view('emails.auth')->with([
|
||||
'url' => route('register_verify', $this->confirmation_code),
|
||||
|
|
|
|||
|
|
@ -28,13 +28,13 @@ class MailVerifyContact extends Mailable
|
|||
public function build()
|
||||
{
|
||||
$salutation = __('Dear customer').",";
|
||||
if($this->user->account){
|
||||
/*if($this->user->account){
|
||||
if($this->user->account->salutation == "mr"){
|
||||
$salutation = __('Dear Sir')." ".$this->user->account->last_name.",";
|
||||
}else{
|
||||
$salutation = __('Dear Mrs')." ".$this->user->account->last_name.",";
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
return $this->view('emails.auth')->with([
|
||||
'url' => route('register_verify', $this->confirmation_code),
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Cviebrock\EloquentSluggable\Sluggable;
|
||||
|
||||
/**
|
||||
* App\Models\Category
|
||||
|
|
@ -29,6 +30,8 @@ use Illuminate\Database\Eloquent\Model;
|
|||
*/
|
||||
class Category extends Model
|
||||
{
|
||||
use Sluggable;
|
||||
|
||||
protected $table = 'categories';
|
||||
|
||||
protected $casts = ['trans_name' => 'array'];
|
||||
|
|
@ -37,6 +40,14 @@ class Category extends Model
|
|||
'parent_id', 'name', 'pos', 'active',
|
||||
];
|
||||
|
||||
public function sluggable()
|
||||
{
|
||||
return [
|
||||
'slug' => [
|
||||
'source' => 'name'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function parent()
|
||||
{
|
||||
|
|
@ -48,6 +59,12 @@ class Category extends Model
|
|||
return $this->hasMany('App\Models\Category', 'parent_id', 'id');
|
||||
}
|
||||
|
||||
|
||||
public function product_categories()
|
||||
{
|
||||
return $this->hasMany('App\Models\ProductCategory', 'category_id', 'id');
|
||||
}
|
||||
|
||||
public function setPosAttribute($value){
|
||||
$this->attributes['pos'] = is_numeric($value) ? $value : null;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Cviebrock\EloquentSluggable\Sluggable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
|
|
@ -84,10 +85,39 @@ class Product extends Model
|
|||
'trans_usage' => 'array',
|
||||
'trans_ingredients' => 'array'
|
||||
];
|
||||
use Sluggable;
|
||||
|
||||
use SoftDeletes;
|
||||
|
||||
protected $dates = ['deleted_at'];
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'title',
|
||||
'copy',
|
||||
'price',
|
||||
'price_ek',
|
||||
'tax',
|
||||
'price_old',
|
||||
'contents',
|
||||
'number',
|
||||
'icons',
|
||||
'description',
|
||||
'usage',
|
||||
'ingredients',
|
||||
'pos',
|
||||
'amount',
|
||||
'active'
|
||||
];
|
||||
|
||||
public function sluggable()
|
||||
{
|
||||
return [
|
||||
'slug' => [
|
||||
'source' => 'name'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function attributes(){
|
||||
return $this->hasMany('App\Models\ProductAttribute', 'product_id', 'id');
|
||||
|
|
@ -101,6 +131,35 @@ class Product extends Model
|
|||
return $this->hasMany('App\Models\ProductImage', 'product_id', 'id');
|
||||
}
|
||||
|
||||
/*
|
||||
public function isImageAfter(){
|
||||
if(empty($this->attributes['filename_after']) || @$this->attributes['filename_after'] == null || @$this->attributes['filename_after'] == ""){
|
||||
return false;
|
||||
}
|
||||
if(!\Storage::disk('public')->has('images/'.$this->id.'/'.$this->filename_after)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function getImage($file){
|
||||
|
||||
if($file == "before" && $this->isImageBefore()){
|
||||
$link = 'images/'.$this->id.'/'.$this->filename_before;
|
||||
return '/storage/'.$link.'?=lm='.\Storage::disk('public')->lastModified($link);
|
||||
}
|
||||
|
||||
if($file == "after" && $this->isImageAfter()){
|
||||
$link = 'images/'.$this->id.'/'.$this->filename_after;
|
||||
return '/storage/'.$link.'?=lm='.\Storage::disk('public')->lastModified($link);
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
public function _format_number($value){
|
||||
return preg_replace("/[^0-9,]/", "", $value);
|
||||
|
|
@ -110,7 +169,7 @@ class Product extends Model
|
|||
$value = $this->_format_number($value);
|
||||
$this->attributes['price'] = floatval(str_replace(',', '.', $value));
|
||||
}
|
||||
public function setPriceVkAttribute( $value ) {
|
||||
public function setPriceEkAttribute( $value ) {
|
||||
$value = $this->_format_number($value);
|
||||
$this->attributes['price_ek'] = floatval(str_replace(',', '.', $value));
|
||||
}
|
||||
|
|
@ -131,7 +190,7 @@ class Product extends Model
|
|||
return number_format($this->attributes['price'], 2, ',', '.');
|
||||
}
|
||||
|
||||
public function getFormattedPriceVk()
|
||||
public function getFormattedPriceEk()
|
||||
{
|
||||
if(\App::getLocale() == "en"){
|
||||
return number_format($this->attributes['price_ek'], 2, '.', ',');
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Cviebrock\EloquentSluggable\Sluggable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
|
|
@ -32,12 +33,24 @@ use Illuminate\Database\Eloquent\Model;
|
|||
*/
|
||||
class ProductImage extends Model
|
||||
{
|
||||
use Sluggable;
|
||||
|
||||
|
||||
protected $table = 'product_images';
|
||||
|
||||
protected $fillable = [
|
||||
'product_id', 'filename', 'original_name', 'ext', 'mine', 'size'
|
||||
];
|
||||
|
||||
public function sluggable()
|
||||
{
|
||||
return [
|
||||
'slug' => [
|
||||
'source' => 'original_name'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function product()
|
||||
{
|
||||
|
|
|
|||
95
app/Repositories/ProductRepository.php
Normal file
95
app/Repositories/ProductRepository.php
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
|
||||
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductAttribute;
|
||||
use App\Models\ProductCategory;
|
||||
|
||||
class ProductRepository extends BaseRepository {
|
||||
|
||||
|
||||
public function __construct(Product $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* refresh.
|
||||
*/
|
||||
public function update($data)
|
||||
{
|
||||
|
||||
$data['active'] = isset($data['active']) ? 1 : 0;
|
||||
|
||||
|
||||
if($data['id'] == "new"){
|
||||
$this->model = Product::create($data);
|
||||
}
|
||||
else{
|
||||
$this->model = $this->getById($data['id']);
|
||||
$this->model->fill($data);
|
||||
$this->model->save();
|
||||
}
|
||||
|
||||
$this->updateCategories(isset($data['categories']) ? $data['categories'] : array());
|
||||
$this->updateAttributes(isset($data['attributes']) ? $data['attributes'] : array());
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
public function updateCategories($data = array())
|
||||
{
|
||||
foreach ($this->model->categories as $category) {
|
||||
if(($pos = array_search($category->category_id, $data)) !== FALSE){
|
||||
unset($data[$pos]);
|
||||
}else{
|
||||
$category->delete();
|
||||
}
|
||||
}
|
||||
//set attr
|
||||
if(is_array($data)){
|
||||
foreach ($data as $id) {
|
||||
ProductCategory::create([
|
||||
'product_id' => $this->model->id,
|
||||
'category_id' => $id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function updateAttributes($data = array())
|
||||
{
|
||||
foreach ($this->model->attributes as $attribute) {
|
||||
if(($pos = array_search($attribute->attribute_id, $data)) !== FALSE){
|
||||
unset($data[$pos]);
|
||||
}else{
|
||||
$attribute->delete();
|
||||
}
|
||||
}
|
||||
//set attr
|
||||
if(is_array($data)){
|
||||
foreach ($data as $id) {
|
||||
ProductAttribute::create([
|
||||
'product_id' => $this->model->id,
|
||||
'attribute_id' => $id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function delete()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Attribute;
|
||||
use App\Models\Category;
|
||||
use App\Models\Country;
|
||||
use App\Models\IndustrySector;
|
||||
use App\Models\Interest;
|
||||
|
|
@ -64,8 +66,6 @@ class HTMLHelper
|
|||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function getYearSelectOptions(){
|
||||
$start = date("Y", strtotime("-5 years", time()));
|
||||
$end = date("Y", strtotime("+1 years", time()));
|
||||
|
|
@ -79,6 +79,66 @@ class HTMLHelper
|
|||
return $ret;
|
||||
}
|
||||
|
||||
public static function getAttributesWithoutParents($id = false, $sameId = false, $all = true){
|
||||
$values = Attribute::where('parent_id', null)->get();
|
||||
$ret = "";
|
||||
if($all){
|
||||
$ret .= '<option value="">'.__('no').'</option>\n';
|
||||
}
|
||||
foreach ($values as $value){
|
||||
if($sameId == $value->id){
|
||||
continue;
|
||||
}
|
||||
$attr = ($value->id == $id) ? 'selected="selected"' : '';
|
||||
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$value->name.'</option>\n';
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public static function getCategoriesWithoutParents($id = false, $sameId = false, $all = true){
|
||||
$values = Category::where('parent_id', null)->get();
|
||||
$ret = "";
|
||||
if($all){
|
||||
$ret .= '<option value="">'.__('no').'</option>\n';
|
||||
}
|
||||
foreach ($values as $value){
|
||||
if($sameId == $value->id){
|
||||
continue;
|
||||
}
|
||||
$attr = ($value->id == $id) ? 'selected="selected"' : '';
|
||||
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$value->name.'</option>\n';
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public static function getCategoriesOptions($ids = array(), $all = true){
|
||||
$values = Category::where('active', 1)->get();
|
||||
$ret = "";
|
||||
if($all){
|
||||
$ret .= '<option value="">'.__('no').'</option>\n';
|
||||
}
|
||||
foreach ($values as $value){
|
||||
$attr = in_array($value->id, $ids) ? 'selected="selected"' : '';
|
||||
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$value->name.'</option>\n';
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public static function getAttributesOptions($ids = array(), $all = true){
|
||||
$values = Attribute::where('active', 1)->get();
|
||||
$ret = "";
|
||||
if($all){
|
||||
$ret .= '<option value="">'.__('no').'</option>\n';
|
||||
}
|
||||
foreach ($values as $value){
|
||||
$attr = in_array($value->id, $ids) ? 'selected="selected"' : '';
|
||||
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$value->name.'</option>\n';
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* public static function getCompanyOptions($company){
|
||||
$options = array(1 => __('business'), 0 => __('private'), );
|
||||
$ret = "";
|
||||
|
|
|
|||
254
app/Services/Slim.php
Normal file
254
app/Services/Slim.php
Normal file
|
|
@ -0,0 +1,254 @@
|
|||
<?php
|
||||
namespace App\Services;
|
||||
|
||||
abstract class SlimStatus {
|
||||
const FAILURE = 'failure';
|
||||
const SUCCESS = 'success';
|
||||
}
|
||||
|
||||
class Slim {
|
||||
|
||||
public static function getImages($inputName = 'slim') {
|
||||
|
||||
$values = Slim::getPostData($inputName);
|
||||
|
||||
// test for errors
|
||||
if ($values === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// determine if contains multiple input values, if is singular, put in array
|
||||
$data = array();
|
||||
if (!is_array($values)) {
|
||||
$values = array($values);
|
||||
}
|
||||
|
||||
// handle all posted fields
|
||||
foreach ($values as $value) {
|
||||
$inputValue = Slim::parseInput($value);
|
||||
if ($inputValue) {
|
||||
array_push($data, $inputValue);
|
||||
}
|
||||
}
|
||||
|
||||
// return the data collected from the fields
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
// $value should be in JSON format
|
||||
private static function parseInput($value) {
|
||||
|
||||
// if no json received, exit, don't handle empty input values.
|
||||
if (empty($value)) {return null;}
|
||||
|
||||
// If magic quotes enabled
|
||||
if (get_magic_quotes_gpc()) {
|
||||
$value = stripslashes($value);
|
||||
}
|
||||
|
||||
// The data is posted as a JSON String so to be used it needs to be deserialized first
|
||||
$data = json_decode($value);
|
||||
|
||||
// shortcut
|
||||
$input = null;
|
||||
$actions = null;
|
||||
$output = null;
|
||||
$meta = null;
|
||||
|
||||
if (isset ($data->input)) {
|
||||
|
||||
$inputData = null;
|
||||
if (isset($data->input->image)) {
|
||||
$inputData = Slim::getBase64Data($data->input->image);
|
||||
}
|
||||
else if (isset($data->input->field)) {
|
||||
$filename = $_FILES[$data->input->field]['tmp_name'];
|
||||
if ($filename) {
|
||||
$inputData = file_get_contents($filename);
|
||||
}
|
||||
}
|
||||
|
||||
$input = array(
|
||||
'data' => $inputData,
|
||||
'name' => $data->input->name,
|
||||
'type' => $data->input->type,
|
||||
'size' => $data->input->size,
|
||||
'width' => $data->input->width,
|
||||
'height' => $data->input->height,
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if (isset($data->output)) {
|
||||
|
||||
$outputDate = null;
|
||||
if (isset($data->output->image)) {
|
||||
$outputData = Slim::getBase64Data($data->output->image);
|
||||
}
|
||||
else if (isset ($data->output->field)) {
|
||||
$filename = $_FILES[$data->output->field]['tmp_name'];
|
||||
if ($filename) {
|
||||
$outputData = file_get_contents($filename);
|
||||
}
|
||||
}
|
||||
|
||||
$output = array(
|
||||
'data' => $outputData,
|
||||
'name' => $data->output->name,
|
||||
'type' => $data->output->type,
|
||||
'width' => $data->output->width,
|
||||
'height' => $data->output->height
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($data->actions)) {
|
||||
$actions = array(
|
||||
'crop' => $data->actions->crop ? array(
|
||||
'x' => $data->actions->crop->x,
|
||||
'y' => $data->actions->crop->y,
|
||||
'width' => $data->actions->crop->width,
|
||||
'height' => $data->actions->crop->height,
|
||||
'type' => $data->actions->crop->type
|
||||
) : null,
|
||||
'size' => $data->actions->size ? array(
|
||||
'width' => $data->actions->size->width,
|
||||
'height' => $data->actions->size->height
|
||||
) : null,
|
||||
'rotation' => $data->actions->rotation,
|
||||
'filters' => $data->actions->filters ? array(
|
||||
'sharpen' => $data->actions->filters->sharpen
|
||||
) : null
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($data->meta)) {
|
||||
$meta = $data->meta;
|
||||
}
|
||||
|
||||
// We've sanitized the base64data and will now return the clean file object
|
||||
return array(
|
||||
'input' => $input,
|
||||
'output' => $output,
|
||||
'actions' => $actions,
|
||||
'meta' => $meta
|
||||
);
|
||||
}
|
||||
|
||||
// $path should have trailing slash
|
||||
public static function saveFile($data, $name, $path = 'tmp/', $uid = true) {
|
||||
|
||||
// Add trailing slash if omitted
|
||||
if (substr($path, -1) !== '/') {
|
||||
$path .= '/';
|
||||
}
|
||||
|
||||
// Test if directory already exists
|
||||
if(!is_dir($path)){
|
||||
mkdir($path, 0755, true);
|
||||
}
|
||||
|
||||
// Sanitize characters in file name
|
||||
$name = Slim::sanitizeFileName($name);
|
||||
|
||||
// Let's put a unique id in front of the filename so we don't accidentally overwrite other files
|
||||
if ($uid) {
|
||||
$name = uniqid() . '_' . $name;
|
||||
}
|
||||
|
||||
// Add name to path, we need the full path including the name to save the file
|
||||
$path = $path . $name;
|
||||
|
||||
// store the file
|
||||
Slim::save($data, $path);
|
||||
|
||||
// return the files new name and location
|
||||
return array(
|
||||
'name' => $name,
|
||||
'path' => $path
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data from remote URL
|
||||
* @param $url
|
||||
* @return string
|
||||
*/
|
||||
public static function fetchURL($url, $maxFileSize) {
|
||||
if (!ini_get('allow_url_fopen')) {
|
||||
return null;
|
||||
}
|
||||
$content = null;
|
||||
try {
|
||||
$content = @file_get_contents($url, false, null, 0, $maxFileSize);
|
||||
} catch(Exception $e) {
|
||||
return false;
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
public static function outputJSON($data) {
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* http://stackoverflow.com/a/2021729
|
||||
* Remove anything which isn't a word, whitespace, number
|
||||
* or any of the following characters -_~,;[]().
|
||||
* If you don't need to handle multi-byte characters
|
||||
* you can use preg_replace rather than mb_ereg_replace
|
||||
* @param $str
|
||||
* @return string
|
||||
*/
|
||||
public static function sanitizeFileName($str) {
|
||||
// Basic clean up
|
||||
$str = preg_replace('([^\w\s\d\-_~,;\[\]\(\).])', '', $str);
|
||||
// Remove any runs of periods
|
||||
$str = preg_replace('([\.]{2,})', '', $str);
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the posted data from the POST or FILES object. If was using Slim to upload it will be in POST (as posted with hidden field) if not enhanced with Slim it'll be in FILES.
|
||||
* @param $inputName
|
||||
* @return array|bool
|
||||
*/
|
||||
private static function getPostData($inputName) {
|
||||
|
||||
$values = array();
|
||||
|
||||
if (isset($_POST[$inputName])) {
|
||||
$values = $_POST[$inputName];
|
||||
}
|
||||
else if (isset($_FILES[$inputName])) {
|
||||
// Slim was not used to upload this file
|
||||
return false;
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the data to a given location
|
||||
* @param $data
|
||||
* @param $path
|
||||
* @return bool
|
||||
*/
|
||||
private static function save($data, $path) {
|
||||
if (!file_put_contents($path, $data)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips the "data:image..." part of the base64 data string so PHP can save the string as a file
|
||||
* @param $data
|
||||
* @return string
|
||||
*/
|
||||
private static function getBase64Data($data) {
|
||||
return base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue