mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-01-16 19:05:08 -05:00
301 lines
13 KiB
PHP
301 lines
13 KiB
PHP
<?php
|
|
namespace Modules\MenuPlus\Services;
|
|
|
|
class AugmentationService
|
|
{
|
|
public function __construct() {
|
|
$this->addMetasRelationshipToMenuElement();
|
|
$this->updateMegaMenuBlade();
|
|
$this->addFooterMenuSupport();
|
|
$this->addFooterMenuColorSettings();
|
|
$this->updateProfileMenu();
|
|
$this->addMobileHeaderForStaffLogin();
|
|
$this->addGJSPageRelationshipToMenuElement();
|
|
$this->addGJSPageSupportToMegaMenu();
|
|
}
|
|
|
|
public static function addMetasRelationshipToMenuElement() {
|
|
if (isModuleActive('Menu')) {
|
|
$path = module_path('Menu', 'Entities/MenuElement.php');
|
|
if (file_exists($path)) {
|
|
$update = false;
|
|
$content = file_get_contents($path);
|
|
if (!preg_match("/public function metas\(\) {[.\s\S]+?}/", $content)) {
|
|
$matches = null;
|
|
preg_match("/public function childs\(\){[.\s\S]+?}/", $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
public function metas() {
|
|
return \$this->hasMany(Meta::class, 'element_id', 'id');
|
|
}
|
|
";
|
|
$code .= $snippet;
|
|
$content = preg_replace("/public function childs\(\){[.\s\S]+?}/", $code, $content);
|
|
//file_put_contents($path, $content);
|
|
$update = true;
|
|
}
|
|
}
|
|
|
|
if (!preg_match("/use Modules\\\MenuPlus\\\Entities\\\Meta;/", $content)) {
|
|
$matches = null;
|
|
preg_match("/use Modules\\\Setup\\\Entities\\\Tag;/", $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
use Modules\MenuPlus\Entities\Meta;
|
|
";
|
|
$code .= $snippet;
|
|
$content = preg_replace("/use Modules\\\Setup\\\Entities\\\Tag;/", $code, $content);
|
|
//file_put_contents($path, $content);
|
|
$update = true;
|
|
}
|
|
}
|
|
|
|
if ($update) {
|
|
file_put_contents($path, $content);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function updateMegaMenuBlade() {
|
|
$theme = app('theme');
|
|
if ($theme) {
|
|
$theme_name = app('theme')->folder_path;
|
|
$path = resource_path('views/frontend/amazy/partials/_mega_menu.blade.php');
|
|
if (file_exists($path)) {
|
|
$update = false;
|
|
$content = file_get_contents($path);
|
|
if (!preg_match("/MMSES/", $content)) {
|
|
$content = preg_replace_callback('|<li class="">[.\s\S]+?<\/li>|', function ($matches) {
|
|
$nli = preg_replace('/<li class="">/', "<li id=\"{{ app(\Modules\MenuPlus\Repositories\MetaRepository::class)->getValue(\$element->id, 'hash') }}\" class=\"{{ app(\Modules\MenuPlus\Repositories\MetaRepository::class)->getValue(\$element->id, 'class') }}\">", $matches[0]);
|
|
|
|
return "
|
|
{{-- MMSES --}}
|
|
@if (isModuleActive('MenuPlus'))
|
|
@if (app(\Modules\MenuPlus\Services\CommonService::class)->isVisible(\$element))
|
|
".$nli."
|
|
@endif
|
|
@else
|
|
".$matches[0]."
|
|
@endif";
|
|
}, $content);
|
|
file_put_contents($path, $content);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static function addFooterMenuColorSettings() {
|
|
if (isModuleActive('Appearance')) {
|
|
$path = module_path('Appearance', 'Resources/views/theme_color/index.blade.php');
|
|
if (file_exists($path)) {
|
|
$content = file_get_contents($path);
|
|
if (!preg_match("/@include\('menuplus::components\._footer_color_settings'\)/", $content)) {
|
|
$matches = null;
|
|
preg_match("/@error\('danger_color'\)[.\s\S]+?<\/div>[.\s\S]+?<\/div>/", $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
@if (isModuleActive('MenuPlus'))
|
|
@include('menuplus::components._footer_color_settings')
|
|
@endif
|
|
";
|
|
$code .= $snippet;
|
|
$content = preg_replace("/@error\('danger_color'\)[.\s\S]+?<\/div>[.\s\S]+?<\/div>/", $code, $content);
|
|
file_put_contents($path, $content);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function addFooterMenuSupport() {
|
|
$path = resource_path('views/frontend/amazy/partials/_footer.blade.php');
|
|
if (file_exists($path)) {
|
|
$update = false;
|
|
$content = file_get_contents($path);
|
|
if (!preg_match("/@include\('menuplus::components\._footer_style'\)/", $content)) {
|
|
$matches = null;
|
|
preg_match("/<!-- FOOTER::START -->/", $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
@if (isModuleActive('MenuPlus'))
|
|
@include('menuplus::components._footer_style')
|
|
@endif
|
|
";
|
|
$code = $snippet.$code;
|
|
$content = preg_replace("/<!-- FOOTER::START -->/", $code, $content);
|
|
//file_put_contents($path, $content);
|
|
$update = true;
|
|
}
|
|
}
|
|
|
|
if (!preg_match("/@include\('menuplus::components\._footer_menu_1'\)/", $content)) {
|
|
$matches = null;
|
|
preg_match("/@foreach\(\\\$sectionWidgets->where\('section','1'\)[.\s\S]+?@endforeach/", $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
@if (false)
|
|
".$code."
|
|
@endif
|
|
|
|
@if (isModuleActive('MenuPlus'))
|
|
@include('menuplus::components._footer_menu_1')
|
|
@endif
|
|
";
|
|
$code = $snippet;
|
|
$content = preg_replace("/@foreach\(\\\$sectionWidgets->where\('section','1'\)[.\s\S]+?@endforeach/", $code, $content);
|
|
//file_put_contents($path, $content);
|
|
$update = true;
|
|
}
|
|
}
|
|
|
|
if (!preg_match("/@include\('menuplus::components\._footer_menu_2'\)/", $content)) {
|
|
$matches = null;
|
|
preg_match("/@foreach\(\\\$sectionWidgets->where\('section','2'\)[.\s\S]+?@endforeach/", $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
@if (false)
|
|
".$code."
|
|
@endif
|
|
|
|
@if (isModuleActive('MenuPlus'))
|
|
@include('menuplus::components._footer_menu_2')
|
|
@endif
|
|
";
|
|
$code = $snippet;
|
|
$content = preg_replace("/@foreach\(\\\$sectionWidgets->where\('section','2'\)[.\s\S]+?@endforeach/", $code, $content);
|
|
//file_put_contents($path, $content);
|
|
$update = true;
|
|
}
|
|
}
|
|
|
|
if ($update) {
|
|
file_put_contents($path, $content);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function updateProfileMenu() {
|
|
$path = resource_path('views/backEnd/partials/_menu.blade.php');
|
|
if (file_exists($path)) {
|
|
$update = false;
|
|
$content = file_get_contents($path);
|
|
if (!preg_match("/@if \(isModuleActive\('MenuPlus'\)\)/", $content)) {
|
|
$matches = null;
|
|
preg_match('/<div class="profile_info_details">/', $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
@if (isModuleActive('MenuPlus'))
|
|
@include('menuplus::components._profile_menu')
|
|
@endif
|
|
";
|
|
$code .= $snippet;
|
|
$content = preg_replace('/<div class="profile_info_details">/', $code, $content);
|
|
$update = true;
|
|
}
|
|
}
|
|
|
|
if ($update) {
|
|
file_put_contents($path, $content);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function addMobileHeaderForStaffLogin() {
|
|
$path = resource_path('views/frontend/amazy/partials/_header.blade.php');
|
|
if (file_exists($path)) {
|
|
$update = false;
|
|
$content = file_get_contents($path);
|
|
if (!preg_match("/@include\('menuplus::components\._top_mobile_menu'\)/", $content)) {
|
|
$matches = null;
|
|
preg_match("/<!-- HEADER::START -->/", $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
@if (isModuleActive('MenuPlus'))
|
|
@include('menuplus::components._top_mobile_menu')
|
|
@endif
|
|
";
|
|
$code .= $snippet;
|
|
$content = preg_replace("/<!-- HEADER::START -->/", $code, $content);
|
|
//file_put_contents($path, $content);
|
|
$update = true;
|
|
}
|
|
}
|
|
|
|
if ($update) {
|
|
file_put_contents($path, $content);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static function addGJSPageRelationshipToMenuElement() {
|
|
if (isModuleActive('Menu')) {
|
|
$path = module_path('Menu', 'Entities/MenuElement.php');
|
|
if (file_exists($path)) {
|
|
$update = false;
|
|
$content = file_get_contents($path);
|
|
if (!preg_match("/public function gjspage\(\) {[.\s\S]+?}/", $content)) {
|
|
$matches = null;
|
|
preg_match("/public function childs\(\){[.\s\S]+?}/", $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
public function gjspage() {
|
|
return \$this->belongsTo(\Modules\PageBuilderPlus\Entities\GJSPage::class, 'element_id', 'id');
|
|
}
|
|
";
|
|
$code .= $snippet;
|
|
$content = preg_replace("/public function childs\(\){[.\s\S]+?}/", $code, $content);
|
|
//file_put_contents($path, $content);
|
|
$update = true;
|
|
}
|
|
}
|
|
|
|
if ($update) {
|
|
file_put_contents($path, $content);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function addGJSPageSupportToMegaMenu() {
|
|
$path = resource_path('views/frontend/amazy/partials/_mega_menu.blade.php');
|
|
if (file_exists($path)) {
|
|
$update = false;
|
|
$content = file_get_contents($path);
|
|
if (!preg_match("/\\\$element->type == 'gjspage'/", $content)) {
|
|
$matches = null;
|
|
preg_match("/@elseif\(\\\$element->type == 'category'\)/", $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
@elseif (\$element->type == 'gjspage')
|
|
@if (isModuleActive('PageBuilderPlus') && isModuleActive('MenuPlus'))
|
|
@if (app(\Modules\MenuPlus\Services\CommonService::class)->isVisible(\$element))
|
|
<li id=\"{{ app(\Modules\MenuPlus\Repositories\MetaRepository::class)->getValue(\$element->id, 'hash') }}\" class=\"{{ app(\Modules\MenuPlus\Repositories\MetaRepository::class)->getValue(\$element->id, 'class') }}\">
|
|
<a href=\"{{ url('pages/'.@\$element->gjspage->slug) }}\" target=\"{{\$element->is_newtab == 1?'_blank':''}}\">{{ ucfirst(textLimit(\$element->title, 20)) }}</a>
|
|
</li>
|
|
@endif
|
|
@endif
|
|
";
|
|
$code = $snippet.$code;
|
|
$content = preg_replace("/@elseif\(\\\$element->type == 'category'\)/", $code, $content);
|
|
//file_put_contents($path, $content);
|
|
$update = true;
|
|
}
|
|
}
|
|
|
|
if ($update) {
|
|
file_put_contents($path, $content);
|
|
}
|
|
}
|
|
}
|
|
} |