Skip to content

Commit

Permalink
Merge branch 'release/releasing-localization-demo-v2'
Browse files Browse the repository at this point in the history
  • Loading branch information
themodernpk committed Feb 15, 2020
2 parents eb68cf5 + 2ae4079 commit 2e1873a
Show file tree
Hide file tree
Showing 16 changed files with 423 additions and 15 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"keywords": ["laravel", "cms"],
"homepage": "https://www.webreinvent.com",
"license": "MIT",
"version": "0.3.6",
"version": "0.3.7",
"authors": [
{
"name": "WebReinvent",
Expand Down
5 changes: 4 additions & 1 deletion src/Config/vaahcms.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
'minified' => 0,
'api_route' => 'https://cms.vaah.dev/api',
'debug' => 1,
'uploads' => [
'allowed_extensions' => ["jpg", "jpeg", 'png', "gif", "csv"]
]
];

return $settings;
return $settings;
89 changes: 89 additions & 0 deletions src/Entities/LanguageString.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use WebReinvent\VaahCms\Traits\CrudObservantTrait;

Expand Down Expand Up @@ -251,6 +253,93 @@ public static function storeList($request)

}
//-------------------------------------------------
public static function deleteItem($request)
{

$rules = array(
'slug' => 'required',
);

$validator = \Validator::make( $request->all(), $rules);
if ( $validator->fails() ) {

$errors = errorsToArray($validator->errors());
$response['status'] = 'failed';
$response['errors'] = $errors;
return $response;
}

static::where('slug', $request->slug)->forceDelete();

$response['status'] = 'success';
$response['data'][] = '';
return $response;

}
//-------------------------------------------------
public static function generateLangFiles()
{

$languages = Language::all();
$categories = LanguageCategory::all();

foreach ($languages as $language)
{

foreach ($categories as $category)
{
$strings = static::where('vh_lang_language_id', $language->id)
->where('vh_lang_category_id', $category->id)
->whereNotNull('slug')
->whereNotNull('content')
->get();

if($strings->count() > 0)
{
$inputs = [
"language" => $language,
"category" => $category,
"strings" => $strings,
];

$html = view('vaahcms::templates.lang')
->with($inputs)
->render();
$html = html_entity_decode($html);

$html = "<?php "."\n".$html;

$folder_path = 'resources\lang\/'.$language->locale_code_iso_639;
$folder_path_relative = base_path($folder_path);

if(!File::exists($folder_path_relative)) {
File::makeDirectory($folder_path_relative, 0755, true, true);
}

$file_name = 'vaahcms-'.$category->slug.'.php';

$file_path = base_path($folder_path.'\/'.$file_name);

File::put($file_path, $html);
}


}

}


}
//-------------------------------------------------
public static function syncAndGenerateStrings($request)
{
LanguageString::syncStrings($request);
LanguageString::generateLangFiles();

Artisan::call('cache:clear');
Artisan::call('view:clear');
}
//-------------------------------------------------


}
12 changes: 12 additions & 0 deletions src/Facades/VaahExcelFacade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
namespace WebReinvent\VaahCms\Facades;

use Illuminate\Support\Facades\Facade;

class VaahExcelFacade extends Facade {

protected static function getFacadeAccessor() {
return 'vaahexcel';
}

}
12 changes: 12 additions & 0 deletions src/Facades/VaahFileFacade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
namespace WebReinvent\VaahCms\Facades;

use Illuminate\Support\Facades\Facade;

class VaahFileFacade extends Facade {

protected static function getFacadeAccessor() {
return 'vaahfile';
}

}
34 changes: 33 additions & 1 deletion src/Http/Controllers/Admin/Settings/LocalizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\File;
use WebReinvent\VaahCms\Entities\Language;
use WebReinvent\VaahCms\Entities\LanguageCategory;
use WebReinvent\VaahCms\Entities\LanguageString;
Expand Down Expand Up @@ -100,14 +102,44 @@ public function storeCategory(Request $request)
public function sync(Request $request)
{

LanguageString::syncStrings($request);
LanguageString::syncAndGenerateStrings($request);


$response = LanguageString::getList($request);

$response['messages'][] = "Language files successfully generated";

return response()->json($response);

}
//----------------------------------------------------------
public function delete(Request $request)
{

$response = LanguageString::deleteItem($request);

return response()->json($response);

}
//----------------------------------------------------------
public function upload(Request $request)
{

/*echo \VaahExcel::helloWorld();
die("<hr/>line number=123");
$response = \VaahFile::upload($request);
echo "<pre>";
print_r($response);
echo "</pre>";
die("<hr/>line number=123");
return response()->json($response);*/

}
//----------------------------------------------------------
//----------------------------------------------------------
//----------------------------------------------------------


Expand Down
10 changes: 10 additions & 0 deletions src/Libraries/VaahExcel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace WebReinvent\VaahCms\Libraries;

class VaahExcel{

public function helloWorld() {
echo "Testing the Facades in Laravel.";
}

}
123 changes: 123 additions & 0 deletions src/Libraries/VaahFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php
namespace WebReinvent\VaahCms\Libraries;

use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;

class VaahFile{

//------------------------------------------------------------
public function upload($request) {



if(!$request->hasFile('file')){
$response['status'] = 'failed';
$response['errors'][] = 'No file to upload.';
return $response;
}

$file_params = $this->getUploadFileParams($request);

echo "<pre>";
print_r($file_params);
echo "</pre>";
die("<hr/>line number=123");

$request->merge($file_params);

$rules = array(
'file' => 'required',
'path' => 'required',
'allowed_extensions' => 'required|array',
);

$validator = \Validator::make( $request->all(), $rules);
if ( $validator->fails() ) {

$errors = errorsToArray($validator->errors());
$response['status'] = 'failed';
$response['errors'] = $errors;
return $response;
}

if(!in_array($request->file_extension, $request->allowed_extensions))
{
$response['status'] = 'failed';
$response['errors'][] = 'File extension '.$request->file_extension.' is not allowed to upload';
return $response;
}


try{

Storage::disk('local')->putFileAs(
$request->upload_folder_path,
$request->file('file'),
$request->upload_file_name
);

}catch(\Exception $e)
{
$response['status'] = 'failed';
$response['messages'][] = $e->getMessage();
return $response;
}






}
//------------------------------------------------------------
public function getUploadFileParams($request)
{

$params = $request->all();
if(!$request->has('upload_folder_path'))
{
$date = date('y-m-d');
$folder = storage_path('uploads/'.$date);
$params['upload_folder_path'] = $folder;
}

if(!$request->has('file_name'))
{
$params['file_name'] = $request->file('file')->getClientOriginalName();
}

$params['file_extension'] = $request->file('file')->getClientOriginalExtension();

$params['upload_file_name'] = $params['file_name'].".".$params['file_extension'];

$params['upload_file_path'] = $params['upload_folder_path']."/".$params['upload_file_name'];

if(File::exist($params['upload_file_path']))
{
$file_name = $params['file_name']."-".date('Y-m-d-H-i-s');
$file_name = $file_name.".".$params['file_extension'];
$params['upload_file_name'] = $file_name;
$params['upload_file_path'] = $params['upload_folder_path']."/".$file_name;
}


if(!$request->has('allowed_extensions'))
{
$uploads = config('vaahcms.uploads');
$allowed_extensions = $uploads['allowed_extensions'];
$params['allowed_extensions'] = $allowed_extensions;
}

return $params;

}
//------------------------------------------------------------

//------------------------------------------------------------
//------------------------------------------------------------
//------------------------------------------------------------
//------------------------------------------------------------
//------------------------------------------------------------

}
38 changes: 38 additions & 0 deletions src/Providers/FacadesServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace WebReinvent\VaahCms\Providers;

use App;

use Illuminate\Support\ServiceProvider;
use WebReinvent\VaahCms\Libraries\VaahExcel;
use WebReinvent\VaahCms\Libraries\VaahFile;



class FacadesServiceProvider extends ServiceProvider
{
/**
* Booting the package.
*/
public function boot()
{
}

/**
* Register the provider.
*/
public function register()
{

App::bind('vaahexcel',function() {
return new VaahExcel();
});

App::bind('vaahfile',function() {
return new VaahFile();
});

}

}
2 changes: 1 addition & 1 deletion src/Resources/assets/admin/default/builds/app.js

Large diffs are not rendered by default.

Loading

0 comments on commit 2e1873a

Please sign in to comment.