Files
wticreatorstudio/Modules/StudioPlus/Services/AugmentationService.php
T
2024-02-12 22:54:20 -05:00

133 lines
5.5 KiB
PHP

<?php
namespace Modules\StudioPlus\Services;
class AugmentationService
{
public function __construct()
{
$this->addCodesToMaster();
$this->addModalVueToMaster();
//$this->addCreateStudioToMenu();
$this->addBootstrapIconToHead();
$this->addGenerateTokenToLoginController();
}
public function addCodesToMaster()
{
$masterPath = resource_path('/views/backEnd/master.blade.php');
if (file_exists($masterPath)) {
$content = file_get_contents($masterPath);
$elementExists = null;
preg_match("/window.authToken/", $content, $elementExists);
if ($elementExists) return;
$matchedElement = null;
preg_match("/\@include\('backEnd.partials._scripts'\)\r\n/", $content, $matchedElement);
$codes = "";
if ($matchedElement) {
$codes .= "
<script>
window.authToken = @json(\Modules\StudioPlus\Services\App::token());
window.Auth = @json(\Modules\StudioPlus\Services\App::auth());
</script>
";
$codes .= $matchedElement[0];
$appendContent = preg_replace("/\@include\('backEnd.partials._scripts'\)\r\n/", $codes, $content);
file_put_contents($masterPath, $appendContent, LOCK_EX);
}
}
}
public function addModalVueToMaster()
{
$masterPath = resource_path('/views/backEnd/master.blade.php');
if (file_exists($masterPath)) {
$content = file_get_contents($masterPath);
$elementExists = null;
preg_match('/\<div id\="modalVue"\>\<\/div\>/', $content, $elementExists);
if ($elementExists) return;
preg_match("/\@include\('backEnd.partials._footer'\)\r\n/", $content, $matchedElement);
$codes = "";
if ($matchedElement) {
$codes .= "<div id=\"modalVue\"></div>
{$matchedElement[0]}
";
$appendContent = preg_replace("/\@include\('backEnd.partials._footer'\)\r\n/", $codes, $content);
file_put_contents($masterPath, $appendContent, LOCK_EX);
}
}
}
public function addCreateStudioToMenu()
{
$path = resource_path('/views/backEnd/partials/_menu.blade.php');
if (file_exists($path)) {
$content = file_get_contents($path);
$elementExists = null;
preg_match("/\@include\('studioplus::create-studio'\)\r\n/", $content, $elementExists);
if ($elementExists) return;
preg_match("/<div class=\"header_notification_warp d-flex align-items-center\">/", $content, $matchedElement);
$codes = "";
if ($matchedElement) {
/*$codes = "<div class=\"header_notification_warp d-flex align-items-center\">
@include('studioplus::create-studio')
";*/
$codes = "<div class=\"header_notification_warp d-flex align-items-center\">
";
$appendContent = preg_replace("/<div class=\"header_notification_warp d-flex align-items-center\">/", $codes, $content);
file_put_contents($path, $appendContent, LOCK_EX);
}
}
}
public function addBootstrapIconToHead()
{
$path = resource_path('/views/backEnd/partials/_head.blade.php');
if (file_exists($path)) {
$content = file_get_contents($path);
$elementExists = null;
preg_match("/\<link rel=\"stylesheet\" href=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap-icons\@1.10.2\/font\/bootstrap-icons.css\" \/>/", $content, $elementExists);
if ($elementExists) return;
preg_match("/\<link rel=\"stylesheet\" href=\"\{\{asset\(asset_path\('backend\/css\/solid_style.css'\)\)\}\}\"/", $content, $matchedElement);
$codes = "";
if ($matchedElement) {
$codes = "<link rel=\"stylesheet\" href=\"{{asset(asset_path('backend/css/solid_style.css'))}}\" />
<link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css\" />";
$appendContent = preg_replace("/\<link rel=\"stylesheet\" href=\"\{\{asset\(asset_path\('backend\/css\/solid_style.css'\)\)\}\}\" \/>/", $codes, $content);
file_put_contents($path, $appendContent, LOCK_EX);
}
}
}
public function addGenerateTokenToLoginController()
{
$path = app_path('Http/Controllers/Auth/LoginController.php');
if (file_exists($path)) {
$content = file_get_contents($path);
$elementExists = null;
preg_match("/\(new \\\Modules\\\StudioPlus\\\Services\\\HandleAuthToken\)->generateToken\(\);/", $content, $elementExists);
if ($elementExists) return;
preg_match("/return \\\$this->sendLoginResponse\(\\\$request\)/", $content, $matchedElement);
$codes = "";
if ($matchedElement) {
$codes = "(new \Modules\StudioPlus\Services\HandleAuthToken)->generateToken();
return \$this->sendLoginResponse(\$request);";
$appendContent = preg_replace("/return \\\$this->sendLoginResponse\(\\\$request\);/", $codes, $content);
file_put_contents($path, $appendContent, LOCK_EX);
}
}
}
}