Skip to content

Commit

Permalink
Added extension template system
Browse files Browse the repository at this point in the history
  • Loading branch information
brnskn committed Nov 9, 2020
1 parent 8ba18a9 commit 5c2f043
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 53 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ jobs:
with:
path: package/liman/server

- name: Getting Liman' Extension Templates
uses: actions/checkout@v2
with:
repository: limanmys/extension_templates
path: package/liman/server/storage/extension_templates
token: ${{ secrets.CI_TOKEN }}

- name: Getting Liman' PHP Sandbox
uses: actions/checkout@v2
with:
Expand Down Expand Up @@ -60,6 +67,7 @@ jobs:
composer install --no-dev -d package/liman/server
git --git-dir=package/liman/server/.git log -30 --pretty=format:"%s%x09%ad" > package/liman/server/storage/changelog
rm -rf package/liman/server/.git package/liman/sandbox/php/.git
rm -rf package/liman/server/storage/extension_templates/.git
rm -rf package/liman/webssh/.git
rm -rf package/liman/server/node_modules
mv package/liman/server/storage/build_tools/DEBIAN package/
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "storage/extension_templates"]
path = storage/extension_templates
url = https://github.com/limanmys/extension_templates
71 changes: 27 additions & 44 deletions app/Http/Controllers/Extension/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,53 +285,40 @@ public function newExtension()
if (Extension::where("name", request("name"))->exists()) {
return respond("Bu isimle zaten bir eklenti var.", 201);
}

if (!in_array(request('template'), array_keys((array) fetchExtensionTemplates()->templates))) {
return respond("Lütfen geçerli bir tip seçiniz.", 201);
}

$template = request('template');
$template_folder = storage_path('extension_templates/'.$template.'/');

shell_exec("cp -r $template_folder $folder");
foreach(glob("$folder/*.json") as $file){
$content = file_get_contents($file);
$content = str_replace([
"<NAME>",
"<PUBLISHER>",
"<SUPPORTED_LIMAN>",
"<SUPPORT>"
], [
request("name"),
auth()->user()->name,
file_get_contents(storage_path('VERSION')),
auth()->user()->email
], $content);
file_put_contents($file, $content);
}

$json = json_decode(file_get_contents("$folder/db.json"));
$ext = Extension::create([
"name" => request("name"),
"version" => "0.0.1",
"icon" => "",
"service" => "",
"language" => request('language'),
"language" => $json->language,
]);

$json = [
"name" => $name,
"publisher" => auth()->user()->name,
"version" => "0.0.1",
"database" => [],
"widgets" => [],
"views" => [
[
"name" => "index",
"scripts" => "",
],
],
"language" => request('language'),
"status" => 0,
"service" => "",
"supportedLiman" => file_get_contents(storage_path('VERSION')),
"support" => auth()->user()->email,
"icon" => "",
];

shell_exec(
"
mkdir $folder;
mkdir $folder" .
DIRECTORY_SEPARATOR .
"views;
mkdir $folder" .
DIRECTORY_SEPARATOR .
"scripts;
"
);

touch($folder . DIRECTORY_SEPARATOR . "db.json");

file_put_contents(
$folder . DIRECTORY_SEPARATOR . "db.json",
json_encode($json, JSON_PRETTY_PRINT)
);

$system = rootSystem();

$system->userAdd($ext->id);
Expand All @@ -342,10 +329,6 @@ public function newExtension()
request()->request->add(['server' => "none"]);
request()->request->add(['extension_id' => $ext->id]);

foreach (sandbox(request('language'))->getInitialFiles() as $file) {
touch($folder . "/views/$file");
}

$system->fixExtensionPermissions($ext->id, $ext->name);

system_log(6, "EXTENSION_CREATE", [
Expand Down
8 changes: 8 additions & 0 deletions app/Http/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,14 @@ function endsWith($string, $endString)
}
}

if (!function_exists('fetchExtensionTemplates')) {
function fetchExtensionTemplates()
{
$path = storage_path('extension_templates/templates.json');
return json_decode(file_get_contents($path));
}
}

if (!function_exists('scanTranslations')) {
function scanTranslations($directory)
{
Expand Down
15 changes: 7 additions & 8 deletions resources/views/extension_pages/manager.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,20 @@ class="fa fa-cogs"></i></button>
"submit_text" => "İndir"
])

@php
$templates = fetchExtensionTemplates();
@endphp

@include('modal',[
"id"=>"newExtension",
"url" => route('extension_new'),
"next" => "debug",
"title" => "Yeni Eklenti Oluştur",
"selects" => [
"PHP 7.3:php" => [
"-:php" => "language:hidden"
],
/*"Python 3.7(BETA):python" => [
"-:python" => "language:hidden"
]*/
],
"inputs" => [
"Eklenti Adı" => "name:text",
"Tipi:template" => collect($templates->templates)->mapWithKeys(function($value, $key){
return [$value => $key];
})->toArray()
],
"submit_text" => "Oluştur"
])
Expand All @@ -165,6 +163,7 @@ class="fa fa-cogs"></i></button>
])

<script>
$('#newExtension').find('select[name=template]').val('{{ $templates->default }}');
$('input[name=ext_count]').val('{{getExtensionViewCount()}}');
var extensionUpdates = [];
function showExtensionUpdates(){
Expand Down
2 changes: 1 addition & 1 deletion storage/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.12
1.5.0
1 change: 1 addition & 0 deletions storage/extension_templates
Submodule extension_templates added at 0be3b9

0 comments on commit 5c2f043

Please sign in to comment.