mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-08-03 15:17:03 -04:00
141 lines
6.5 KiB
PHP
141 lines
6.5 KiB
PHP
<?php
|
|
namespace Modules\HomePageSwitcher\Services;
|
|
|
|
use Modules\FrontendCMS\Entities\DynamicPage;
|
|
use Modules\PageBuilderPlus\Entities\GJSPage;
|
|
|
|
class AugmentationService
|
|
{
|
|
public function __construct() {
|
|
$this->updateWelcomeController();
|
|
$this->addHomepageSettingsToGeneralSettings();
|
|
}
|
|
|
|
public function updateWelcomeController() {
|
|
$path = app_path('Http/Controllers/Frontend/WelcomeController.php');
|
|
if (file_exists($path)) {
|
|
$content = file_get_contents($path);
|
|
if (!preg_match("/[.\s\S]+index[.\s\S]+?generatlSetting[.\s\S]+?homepage_slug[.\s\S]+?}[.\s\S]+?}/", $content)) {
|
|
$matches = null;
|
|
preg_match('/[.\s\S]+index[.\s\S]+?VisitorHistory::create[.\s\S]+?}/', $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
if (isModuleActive('PageBuilderPlus')) {
|
|
\$generatlSetting = \Modules\GeneralSetting\Entities\GeneralSetting::first();
|
|
if(\$generatlSetting->homepage != null || \$generatlSetting->homepage != 0){
|
|
\$page = \Modules\PageBuilderPlus\Entities\GJSPage::find(\$generatlSetting->homepage);
|
|
|
|
if (\$page) {
|
|
\$html = \$page->html;
|
|
\$css = \$page->css;
|
|
|
|
return view('pagebuilderplus::show', compact('html', 'css'));
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
\$generatlSetting = \Modules\GeneralSetting\Entities\GeneralSetting::first();
|
|
if(\$generatlSetting->homepage_slug != null){
|
|
|
|
\$pageData = DynamicPage::where('is_page_builder',1)->where('slug',\$generatlSetting->homepage_slug)->first();
|
|
if(\$pageData){
|
|
return view(theme('pages.dynamic_page'),compact('pageData'));
|
|
}
|
|
}
|
|
}
|
|
";
|
|
$code .= $snippet;
|
|
$content = preg_replace('/[.\s\S]+index[.\s\S]+?VisitorHistory::create[.\s\S]+?}/', $code, $content);
|
|
file_put_contents($path, $content);
|
|
}
|
|
}
|
|
|
|
if (!preg_match("/[.\s\S]+index[.\s\S]+?\\\$generalSetting\-\>homepage_redirect/", $content)) {
|
|
$matches = null;
|
|
preg_match('/[.\s\S]+index[.\s\S]+?VisitorHistory::create[.\s\S]+?}/', $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
|
|
if (isModuleActive('HomePageSwitcher')) {
|
|
\$generalSetting = \Modules\GeneralSetting\Entities\GeneralSetting::first();
|
|
if((\$generalSetting->homepage_redirect != null || \$generalSetting->homepage_redirect != 0) && \$generalSetting->homepage_type == 'redirect_url'){
|
|
if (auth()->check()) {
|
|
if (auth()->user()->role->type == 'superadmin' || auth()->user()->role->type == 'admin' || auth()->user()->role->type == 'staff') {
|
|
return redirect('/admin-dashboard');
|
|
} elseif (auth()->user()->role->type == 'seller') {
|
|
return redirect('/seller/dashboard');
|
|
}
|
|
return redirect('/profile/dashboard');
|
|
} else {
|
|
return redirect(\$generalSetting->homepage_redirect);
|
|
}
|
|
}
|
|
}
|
|
";
|
|
$code .= $snippet;
|
|
$content = preg_replace('/[.\s\S]+index[.\s\S]+?VisitorHistory::create[.\s\S]+?}/', $code, $content);
|
|
file_put_contents($path, $content);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
public static function addHomepageSettingsToGeneralSettings() {
|
|
if (isModuleActive('GeneralSetting')) {
|
|
$path = module_path('GeneralSetting', 'Http/Controllers/GeneralSettingController.php');
|
|
/*if (file_exists($path)) {
|
|
$content = file_get_contents($path);
|
|
if (!preg_match("/updateOption\('guest_hide_prices'/", $content)) {
|
|
$matches = null;
|
|
preg_match("/if\(\\\$request->has\('pwa_app_name'\)[.\s\S]+?}/", $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
if (isModuleActive('ExtraSettings')) {
|
|
app(\Modules\ExtraSettings\Repositories\SettingRepository::class)->updateOption('guest_hide_prices', \$request->guest_hide_prices);
|
|
}
|
|
";
|
|
$code .= $snippet;
|
|
$content = preg_replace("/if\(\\\$request->has\('pwa_app_name'\)[.\s\S]+?}/", $code, $content);
|
|
file_put_contents($path, $content);
|
|
}
|
|
}
|
|
}*/
|
|
|
|
$path = module_path('GeneralSetting', 'Resources/views/page_components/general_settings.blade.php');
|
|
if (file_exists($path)) {
|
|
$content = file_get_contents($path);
|
|
if (!preg_match("/@include\('homepageswitcher::components\._homepage_control'\)/", $content)) {
|
|
$matches = null;
|
|
preg_match('/[.\s\S]+pwa_app_name[.\s\S]+?<\/div>[.\s\S]+?<\/div>/', $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
@if (isModuleActive('HomePageSwitcher'))
|
|
@include('homepageswitcher::components._homepage_control')
|
|
@endif
|
|
";
|
|
$code .= $snippet;
|
|
$content = preg_replace('/[.\s\S]+pwa_app_name[.\s\S]+?<\/div>[.\s\S]+?<\/div>/', $code, $content);
|
|
file_put_contents($path, $content);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static function getPages() {
|
|
if (isModuleActive('PageBuilderPlus')) {
|
|
$pages_list = GJSPage::orderBy('title')->get();
|
|
}
|
|
else {
|
|
$dynamicPage = new DynamicPage();
|
|
$pages_list = $dynamicPage->select(['slug','title'])->where('is_page_builder',1)->orderBy('title')->get();
|
|
}
|
|
|
|
return $pages_list;
|
|
}
|
|
} |