mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-01-16 19:05:08 -05:00
339 lines
16 KiB
PHP
339 lines
16 KiB
PHP
<?php
|
|
namespace Modules\Subscription\Services;
|
|
|
|
class AugmentationService
|
|
{
|
|
public function __construct() {
|
|
$this->addSubscriptionGeneralSettings();
|
|
$this->updateRegistrationForm();
|
|
$this->updateWelcomePage();
|
|
$this->updateProductDetailsPage();
|
|
$this->updateProfileMenu();
|
|
$this->updateCategoryPaginatePage();
|
|
$this->updateListingPaginatePage();
|
|
$this->updateBackendCustomerPage();
|
|
}
|
|
|
|
public function addSubscriptionGeneralSettings() {
|
|
if (isModuleActive('GeneralSetting')) {
|
|
$path = module_path('GeneralSetting', 'Http/Controllers/GeneralSettingController.php');
|
|
if (file_exists($path)) {
|
|
$content = file_get_contents($path);
|
|
if (!preg_match("/updateOption\('customer_subscription'/", $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('Subscription')) {
|
|
app(\Modules\Subscription\Http\Controllers\SettingController::class)->updateOption('customer_subscription', \$request->customer_subscription);
|
|
}
|
|
";
|
|
$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\('subscription::components\._customer_subscription_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('Subscription'))
|
|
@include('subscription::components._customer_subscription_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 function updateRegistrationForm() {
|
|
$theme = app('theme');
|
|
if ($theme) {
|
|
$theme_name = app('theme')->folder_path;
|
|
$path = resource_path('views/frontend/amazy/auth/register.blade.php');
|
|
if (file_exists($path)) {
|
|
$update = false;
|
|
$content = file_get_contents($path);
|
|
|
|
if (!preg_match('/@include\(\'subscription::components\._stripe_form\'\)/', $content)) {
|
|
$matches = null;
|
|
preg_match('/sign_up_text[.\s\S]+?<\/div>[.\s\S]+?<\/div>/', $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
@if (isModuleActive('Subscription') && isModuleActive('PaymentGateway'))
|
|
@include('subscription::components._stripe_form')
|
|
@endif
|
|
";
|
|
$code .= $snippet;
|
|
$content = preg_replace('/sign_up_text[.\s\S]+?<\/div>[.\s\S]+?<\/div>/', $code, $content);
|
|
$update = true;
|
|
}
|
|
}
|
|
|
|
if (!preg_match('/@include\(\'subscription::components\._register_button\'\)/', $content)) {
|
|
$content_bak = $content;
|
|
$matches = null;
|
|
preg_match('/@if\(env\(\'NOCAPTCHA_FOR_REG\'\)[.\s\S]+?@endif[.\s\S]+?@endif[.\s\S]+?<\/div>/', $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
@endif
|
|
";
|
|
$code .= $snippet;
|
|
$content = preg_replace('/@if\(env\(\'NOCAPTCHA_FOR_REG\'\)[.\s\S]+?@endif[.\s\S]+?@endif[.\s\S]+?<\/div>/', $code, $content);
|
|
$has_post_snippet = true;
|
|
}
|
|
|
|
$matches = null;
|
|
preg_match('/@if\(env\(\'NOCAPTCHA_FOR_REG\'\)[.\s\S]+?@endif[.\s\S]+?@endif/', $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
@if (isModuleActive('Subscription') && isModuleActive('PaymentGateway'))
|
|
@include('subscription::components._register_button')
|
|
@else
|
|
";
|
|
$code .= $snippet;
|
|
$content = preg_replace('/@if\(env\(\'NOCAPTCHA_FOR_REG\'\)[.\s\S]+?@endif[.\s\S]+?@endif/', $code, $content);
|
|
$has_pre_snippet = true;
|
|
}
|
|
|
|
if ($has_pre_snippet && $has_post_snippet) {
|
|
$update = true;
|
|
}
|
|
else {
|
|
$content = $content_bak;
|
|
}
|
|
}
|
|
|
|
if (!preg_match('/@include\(\'subscription::components\._plan_select_field\'\)/', $content)) {
|
|
$matches = null;
|
|
preg_match('/[.\s\S]+password_confirmation[.\s\S]+?<\/div>/', $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
@if (isModuleActive('Subscription') && isModuleActive('PaymentGateway'))
|
|
@include('subscription::components._plan_select_field')
|
|
@endif
|
|
";
|
|
$code .= $snippet;
|
|
$content = preg_replace('/[.\s\S]+password_confirmation[.\s\S]+?<\/div>/', $code, $content);
|
|
$update = true;
|
|
}
|
|
}
|
|
|
|
if (!preg_match('/@include\(\'subscription::components\._form_head\'\)/', $content)) {
|
|
$matches = null;
|
|
preg_match('/<form action="{{[\s\S]*?route\(\'register\'\)[.\s\S]+?>/', $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
@if (isModuleActive('Subscription') && isModuleActive('PaymentGateway'))
|
|
@include('subscription::components._form_head')
|
|
@else
|
|
<form action=\"{{ route('register') }}\" method=\"POST\" name=\"register\" id=\"register_form\" enctype=\"multipart/form-data\">
|
|
@endif
|
|
";
|
|
$code = $snippet;
|
|
$content = preg_replace('/<form action="{{[\s\S]*?route\(\'register\'\)[.\s\S]+?>/', $code, $content);
|
|
$update = true;
|
|
}
|
|
}
|
|
|
|
if ($update) {
|
|
file_put_contents($path, $content);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function updateWelcomePage() {
|
|
$theme = app('theme');
|
|
if ($theme) {
|
|
$theme_name = app('theme')->folder_path;
|
|
$path = resource_path('views/frontend/amazy/welcome.blade.php');
|
|
if (file_exists($path)) {
|
|
$update = false;
|
|
$content = file_get_contents($path);
|
|
if (!preg_match("/WPSES/", $content)) {
|
|
$content = preg_replace_callback('|<a class="add_cart add_to_cart[.\s\S]+?<\/a>|', function ($matches) {
|
|
return "
|
|
{{-- WPSES --}}
|
|
@if (isModuleActive('Subscription') && isModuleActive('PaymentGateway') && app(\Modules\Subscription\Http\Controllers\SubscriptionController::class)->isAddToCartAllowed())
|
|
".$matches[0]."
|
|
@endif";
|
|
}, $content);
|
|
file_put_contents($path, $content);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function updateProductDetailsPage() {
|
|
$theme = app('theme');
|
|
if ($theme) {
|
|
$theme_name = app('theme')->folder_path;
|
|
$path = resource_path('views/frontend/amazy/pages/product_details.blade.php');
|
|
if (file_exists($path)) {
|
|
$update = false;
|
|
$content = file_get_contents($path);
|
|
if (!preg_match("/PDSSB/", $content)) {
|
|
$matches = null;
|
|
preg_match('/<div class="row mt_30 " id="add_to_cart_div">/', $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
{{-- PDSSB --}}
|
|
@if (isModuleActive('Subscription') && isModuleActive('PaymentGateway'))
|
|
@include('subscription::components._add_to_cart_div')
|
|
@else
|
|
";
|
|
$code = $code.$snippet;
|
|
$content = preg_replace('/<div class="row mt_30 " id="add_to_cart_div">/', $code, $content);
|
|
//file_put_contents($path, $content);
|
|
$update = true;
|
|
}
|
|
|
|
$matches = null;
|
|
preg_match('/<div class="row mt_30 " id="add_to_cart_div">[.\s\S]+?@endif/', $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
@endif
|
|
";
|
|
$code = $code.$snippet;
|
|
$content = preg_replace('/<div class="row mt_30 " id="add_to_cart_div">[.\s\S]+?@endif/', $code, $content);
|
|
//file_put_contents($path, $content);
|
|
$update = true;
|
|
}
|
|
|
|
if ($update) {
|
|
file_put_contents($path, $content);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function updateProfileMenu() {
|
|
$theme = app('theme');
|
|
if ($theme) {
|
|
$theme_name = app('theme')->folder_path;
|
|
$path = resource_path('views/frontend/amazy/pages/profile/partials/_menu.blade.php');
|
|
if (file_exists($path)) {
|
|
$update = false;
|
|
$content = file_get_contents($path);
|
|
if (!preg_match("/@include\('subscription::components\._dashboard_menu'\)/", $content)) {
|
|
$matches = null;
|
|
preg_match('/<li[.\s\S]+?{{url\(\'\/profile\'\)}}[.\s\S]+?<\/li>/', $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
@if (isModuleActive('Subscription') && isModuleActive('PaymentGateway'))
|
|
@include('subscription::components._dashboard_menu')
|
|
@endif
|
|
";
|
|
$code = $code.$snippet;
|
|
$content = preg_replace('/<li[.\s\S]+?{{url\(\'\/profile\'\)}}[.\s\S]+?<\/li>/', $code, $content);
|
|
//file_put_contents($path, $content);
|
|
$update = true;
|
|
}
|
|
|
|
if ($update) {
|
|
file_put_contents($path, $content);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function updateCategoryPaginatePage() {
|
|
$theme = app('theme');
|
|
if ($theme) {
|
|
$theme_name = app('theme')->folder_path;
|
|
$path = resource_path('views/frontend/amazy/partials/category_paginate_data.blade.php');
|
|
if (file_exists($path)) {
|
|
$update = false;
|
|
$content = file_get_contents($path);
|
|
if (!preg_match("/WCPSES/", $content)) {
|
|
$content = preg_replace_callback('|<a class="add_cart add_to_cart addToCartFromThumnail"[.\s\S]+?<\/a>|', function ($matches) {
|
|
return "
|
|
{{-- WCPSES --}}
|
|
@if (isModuleActive('Subscription') && isModuleActive('PaymentGateway') && app(\Modules\Subscription\Http\Controllers\SubscriptionController::class)->isAddToCartAllowed())
|
|
".$matches[0]."
|
|
@endif";
|
|
}, $content);
|
|
file_put_contents($path, $content);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function updateListingPaginatePage() {
|
|
$theme = app('theme');
|
|
if ($theme) {
|
|
$theme_name = app('theme')->folder_path;
|
|
$path = resource_path('views/frontend/amazy/partials/listing_paginate_data.blade.php');
|
|
if (file_exists($path)) {
|
|
$update = false;
|
|
$content = file_get_contents($path);
|
|
if (!preg_match("/WCPSES/", $content)) {
|
|
$content = preg_replace_callback('|<a class="add_cart add_to_cart addToCartFromThumnail"[.\s\S]+?<\/a>|', function ($matches) {
|
|
return "
|
|
{{-- WCPSES --}}
|
|
@if (isModuleActive('Subscription') && isModuleActive('PaymentGateway') && app(\Modules\Subscription\Http\Controllers\SubscriptionController::class)->isAddToCartAllowed())
|
|
".$matches[0]."
|
|
@endif";
|
|
}, $content);
|
|
|
|
$content = preg_replace_callback('|<a class="add_cart add_to_cart add_to_cart_gift_thumnail"[.\s\S]+?<\/a>|', function ($matches) {
|
|
return "
|
|
{{-- WCPSES --}}
|
|
@if (isModuleActive('Subscription') && isModuleActive('PaymentGateway') && app(\Modules\Subscription\Http\Controllers\SubscriptionController::class)->isAddToCartAllowed())
|
|
".$matches[0]."
|
|
@endif";
|
|
}, $content);
|
|
|
|
file_put_contents($path, $content);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function updateBackendCustomerPage() {
|
|
if (isModuleActive('Customer')) {
|
|
$path = module_path('Customer', 'Resources/views/customers/index.blade.php');
|
|
if (file_exists($path)) {
|
|
$content = file_get_contents($path);
|
|
if (!preg_match("/@include\('subscription::components\._add_plan_button_to_customer'\)/", $content)) {
|
|
$matches = null;
|
|
preg_match("/@if \(permissionCheck\('admin\.customer\.create'\)\)[.\s\S]+?@endif/", $content, $matches);
|
|
if (count($matches) > 0) {
|
|
$code = $matches[0];
|
|
$snippet = "
|
|
@if (isModuleActive('Subscription'))
|
|
@include('subscription::components._add_plan_button_to_customer')
|
|
@endif
|
|
";
|
|
$code = $snippet.$code;
|
|
$content = preg_replace("/@if \(permissionCheck\('admin\.customer\.create'\)\)[.\s\S]+?@endif/", $code, $content);
|
|
file_put_contents($path, $content);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |