Skip to content

Commit

Permalink
[FIX] Domain default.
Browse files Browse the repository at this point in the history
  • Loading branch information
Seiger committed Dec 15, 2023
1 parent 9616bf4 commit dcc52d3
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ public function up()
$table->integer('unauthorized_page')->default(0);
$table->timestamps();
});

// Seed default domain
$default = [
'active' => 1,
'resource' => 0,
'key' => 'default',
'domain' => get_by_key($_SERVER, 'HTTP_HOST', 'localhost'),
'site_name' => evo()->getConfig('site_name', 'Default'),
'site_start' => evo()->getConfig('site_start', 1),
'error_page' => evo()->getConfig('error_page', 1),
'unauthorized_page' => evo()->getConfig('unauthorized_page', 1),
];

$item = new \Seiger\sMultisite\Models\sMultisite();
foreach ($default as $key => $value) {
$item->{$key} = $value;
}
$item->save();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ github_repo: sMultisite
# discord: https://community.discord.com

# If you have a logo, put here to include in meta tags
logo: assets/img/sit-logo-blue.png
logo: assets/img/logo.svg

# branch to edit on GitHub
github_branch: main
Expand Down
Binary file added docs/assets/img/smultisitetools.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions docs/pages/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ php artisan vendor:publish --provider="Seiger\sMultisite\sMultisiteServiceProvid
```console
php artisan migrate
```

## Configuration in backend

Plugin settings are located at **Admin Panel -> Tools -> sMultisite**.
{% include figure.html path="assets/img/smultisitetools.jpg" %}
4 changes: 1 addition & 3 deletions docs/pages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ permalink: /
The sMultisite package allows you to use one Evolution CMS
installation for several independent sites managed from the same admin.

> [!IMPORTANT]
>
> To use additional domains for your site, they must be registered with your domain name registrar.
{% include callout.html text="To use additional domains for your site, they must be registered with your domain name registrar." color="skyblue" %}

[Getting Started]({{ site.baseurl }}/getting-started/){: .btn .btn-sky}

Expand Down
6 changes: 3 additions & 3 deletions plugins/sMultisitePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* Correcting urls
*/
Event::listen('evolution.OnWebPageInit', function() {
$domainIds = Cache::get('domain-' . evo()->getConfig('site_key', 'default') . '-resources') ?? [];
$domainIds = Cache::get('sMultisite-' . evo()->getConfig('site_key', 'default') . '-resources') ?? [];
if (!in_array(evo()->documentIdentifier, $domainIds)) {
evo()->sendErrorPage();
}
Expand Down Expand Up @@ -98,7 +98,7 @@
Event::listen('evolution.OnManagerTreeRender', function($params) {
$tree = '';
$_style = ManagerTheme::getStyle();
$domains = \Seiger\sMultisite\Models\sMultisite::where('hide_from_tree', 0)->get();
$domains = \Seiger\sMultisite\Models\sMultisite::where('hide_from_tree', 0)->whereNot('key', 'default')->get();
if ($domains) {
foreach ($domains as $domain) {
$tree .= '<div id="node'.$domain->resource.'" class="rootNode" style="position:initial;">';
Expand All @@ -120,7 +120,7 @@
* Resources manipulation
*/
Event::listen('evolution.OnManagerNodePrerender', function($params) {
$domains = \Seiger\sMultisite\Models\sMultisite::where('hide_from_tree', 0)->get();
$domains = \Seiger\sMultisite\Models\sMultisite::where('hide_from_tree', 0)->whereNot('key', 'default')->get();
if ($domains) {
$_style = ManagerTheme::getStyle();
$startResources = $domains->pluck('site_start')->toArray();
Expand Down
26 changes: 24 additions & 2 deletions src/sMultisite.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@

class sMultisite
{
public function domains()
{
$domains = [];

$default = [
'key' => 'default',
];

$items = \Seiger\sMultisite\Models\sMultisite::whereActive(1)->get();
if ($items) {
foreach ($items as $item) {
//dd($item);
}
}
//dd($domains);
}

/**
* Get url from route name
*
Expand All @@ -20,6 +37,11 @@ public function route(string $name): string
return $route . '/';
}

/**
* Update resiurces tree with domains
*
* @return void
*/
public function domainsTree()
{
$domains = \Seiger\sMultisite\Models\sMultisite::all();
Expand All @@ -30,7 +52,7 @@ public function domainsTree()

foreach ($domains as $domain) {
$domainIds = evo()->getChildIds($domain->resource);
Cache::rememberForever('domain-' . $domain->key . '-resources', function () use ($domainIds) {
Cache::rememberForever('sMultisite-' . $domain->key . '-resources', function () use ($domainIds) {
return $domainIds;
});
}
Expand All @@ -40,7 +62,7 @@ public function domainsTree()
foreach ($domainBaseIds as $domainBaseId) {
$domainDefaultIds = array_merge($domainDefaultIds, evo()->getChildIds($domainBaseId));
}
Cache::rememberForever('domain-default-resources', function () use ($domainDefaultIds) {
Cache::rememberForever('sMultisite-default-resources', function () use ($domainDefaultIds) {
return $domainDefaultIds;
});
}
Expand Down
59 changes: 25 additions & 34 deletions views/configureTab.blade.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
<form id="form" name="form" method="post" action="{{sMultisite::route('sMultisite.update')}}" onsubmit="documentDirty=false;">
<div id="domain-0">
<div class="row form-row form-element-input">
<label class="control-label col-5 col-md-4 col-lg-2">
<span>@lang('sMultisite::global.default_domain')</span>
<i class="fa fa-question-circle" data-tooltip="@lang('sMultisite::global.default_domain_help')"></i>
</label>
<div class="col-7 col-md-8 col-lg-10">
<h4><span class="badge bg-seigerit">{{evo()->getConfig('site_name', 'New website')}}</span></h4>
</div>
</div>
<div class="split my-3"></div>
</div>
@foreach(Seiger\sMultisite\Models\sMultisite::all() as $domain)
<div id="domain-{{$domain->id}}">
<div class="row form-row form-element-input">
<label class="control-label col-5 col-md-4 col-lg-2">
<span>@lang('sMultisite::global.domain')</span>
<i class="fa fa-question-circle" data-tooltip="@lang('sMultisite::global.domain_help')"></i>
@if($domain->key == 'default')<sup><span class="badge bg-seigerit">Default</span></sup>@endif
</label>
<div class="col-7 col-md-8 col-lg-10">
<input name="domains[{{$domain->id}}][domain]" value="{{$domain->domain}}" data-validate="textNoEmpty" data-text="<b>@lang('sMultisite::global.domain')</b> @lang('sMultisite::global.empty_field')" placeholder="example.com" type="text" class="form-control" onchange="documentDirty=true;">
Expand Down Expand Up @@ -58,32 +47,34 @@
<input name="domains[{{$domain->id}}][unauthorized_page]" value="{{$domain->unauthorized_page}}" type="text" class="form-control" onchange="documentDirty=true;">
</div>
</div>
<div class="row form-row form-element-input">
<label class="control-label col-5 col-md-4 col-lg-2">
<span>@lang('sMultisite::global.domain_on')</span>
<i class="fa fa-question-circle" data-tooltip="@lang('sMultisite::global.domain_on_help')"></i>
</label>
<div class="col-7 col-md-8 col-lg-10">
<div class="custom-control custom-switch">
<input type="checkbox" id="active_on_check" class="custom-control-input" name="active_on_check" value="" onchange="documentDirty=true;" onclick="changestate(document.form.active_on);" @if($domain->active == 1) checked @endif>
<label class="custom-control-label" for="active_on_check"></label>
<input type="hidden" id="active_on" name="domains[{{$domain->id}}][active]" value="{{$domain->active}}" onchange="documentDirty=true;">
@if($domain->key != 'default')
<div class="row form-row form-element-input">
<label class="control-label col-5 col-md-4 col-lg-2">
<span>@lang('sMultisite::global.domain_on')</span>
<i class="fa fa-question-circle" data-tooltip="@lang('sMultisite::global.domain_on_help')"></i>
</label>
<div class="col-7 col-md-8 col-lg-10">
<div class="custom-control custom-switch">
<input type="checkbox" id="active_on_check" class="custom-control-input" name="active_on_check" value="" onchange="documentDirty=true;" onclick="changestate(document.form.active_on);" @if($domain->active == 1) checked @endif>
<label class="custom-control-label" for="active_on_check"></label>
<input type="hidden" id="active_on" name="domains[{{$domain->id}}][active]" value="{{$domain->active}}" onchange="documentDirty=true;">
</div>
</div>
</div>
</div>
<div class="row form-row form-element-input">
<label class="control-label col-5 col-md-4 col-lg-2">
<span>@lang('sMultisite::global.hide_from_tree')</span>
<i class="fa fa-question-circle" data-tooltip="@lang('sMultisite::global.hide_from_tree_help')"></i>
</label>
<div class="col-7 col-md-8 col-lg-10">
<div class="custom-control custom-switch">
<input type="checkbox" id="hide_from_tree_check" class="custom-control-input" name="hide_from_tree_check" data-validate="hideFromTreeCheck" data-text="<b>@lang('sMultisite::global.hide_from_tree')</b> @lang('sMultisite::global.must_be_dis-active')" onchange="documentDirty=true;" onclick="changestate(document.form.hide_from_tree);" @if($domain->hide_from_tree == 1) checked @endif>
<label class="custom-control-label" for="hide_from_tree_check"></label>
<input type="hidden" id="hide_from_tree" name="domains[{{$domain->id}}][hide_from_tree]" value="{{$domain->hide_from_tree}}" onchange="documentDirty=true;">
<div class="row form-row form-element-input">
<label class="control-label col-5 col-md-4 col-lg-2">
<span>@lang('sMultisite::global.hide_from_tree')</span>
<i class="fa fa-question-circle" data-tooltip="@lang('sMultisite::global.hide_from_tree_help')"></i>
</label>
<div class="col-7 col-md-8 col-lg-10">
<div class="custom-control custom-switch">
<input type="checkbox" id="hide_from_tree_check" class="custom-control-input" name="hide_from_tree_check" data-validate="hideFromTreeCheck" data-text="<b>@lang('sMultisite::global.hide_from_tree')</b> @lang('sMultisite::global.must_be_dis-active')" onchange="documentDirty=true;" onclick="changestate(document.form.hide_from_tree);" @if($domain->hide_from_tree == 1) checked @endif>
<label class="custom-control-label" for="hide_from_tree_check"></label>
<input type="hidden" id="hide_from_tree" name="domains[{{$domain->id}}][hide_from_tree]" value="{{$domain->hide_from_tree}}" onchange="documentDirty=true;">
</div>
</div>
</div>
</div>
@endif
<div class="split my-3"></div>
</div>
@endforeach
Expand Down

0 comments on commit dcc52d3

Please sign in to comment.