mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Use built in method to render a string with Blade (#13688)
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
namespace LibreNMS\Alert;
|
namespace LibreNMS\Alert;
|
||||||
|
|
||||||
use App\Models\AlertTemplate;
|
use App\Models\AlertTemplate;
|
||||||
|
use Illuminate\Support\Facades\Blade;
|
||||||
use LibreNMS\Enum\AlertState;
|
use LibreNMS\Enum\AlertState;
|
||||||
|
|
||||||
class Template
|
class Template
|
||||||
@@ -74,9 +75,9 @@ class Template
|
|||||||
{
|
{
|
||||||
$alert['alert'] = new AlertData($data['alert']);
|
$alert['alert'] = new AlertData($data['alert']);
|
||||||
try {
|
try {
|
||||||
return view(['template' => $data['template']->template], $alert)->__toString();
|
return Blade::render($data['template']->template, $alert);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return view(['template' => $this->getDefaultTemplate()], $alert)->__toString();
|
return Blade::render($this->getDefaultTemplate(), $alert);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,9 +91,9 @@ class Template
|
|||||||
{
|
{
|
||||||
$alert['alert'] = new AlertData($data['alert']);
|
$alert['alert'] = new AlertData($data['alert']);
|
||||||
try {
|
try {
|
||||||
return view(['template' => $data['title']], $alert)->__toString();
|
return Blade::render($data['title'], $alert);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $data['title'] ?: view(['template' => 'Template ' . $data['name']], $alert)->__toString();
|
return $data['title'] ?: Blade::render('Template ' . $data['name'], $alert);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,6 +10,7 @@ use Gate;
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Blade;
|
||||||
use LibreNMS\Config;
|
use LibreNMS\Config;
|
||||||
use LibreNMS\Util\Debug;
|
use LibreNMS\Util\Debug;
|
||||||
use LibreNMS\Util\Graph;
|
use LibreNMS\Util\Graph;
|
||||||
@@ -166,7 +167,7 @@ class DeviceController extends Controller
|
|||||||
foreach (array_values(Arr::wrap(Config::get('html.device.links'))) as $index => $link) {
|
foreach (array_values(Arr::wrap(Config::get('html.device.links'))) as $index => $link) {
|
||||||
$device_links['custom' . ($index + 1)] = [
|
$device_links['custom' . ($index + 1)] = [
|
||||||
'icon' => $link['icon'] ?? 'fa-external-link',
|
'icon' => $link['icon'] ?? 'fa-external-link',
|
||||||
'url' => view(['template' => $link['url']], ['device' => $device])->__toString(),
|
'url' => Blade::render($link['url'], ['device' => $device]),
|
||||||
'title' => $link['title'],
|
'title' => $link['title'],
|
||||||
'external' => $link['external'] ?? true,
|
'external' => $link['external'] ?? true,
|
||||||
];
|
];
|
||||||
|
@@ -30,6 +30,7 @@ use App\Models\Location;
|
|||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Blade;
|
||||||
use LibreNMS\Config;
|
use LibreNMS\Config;
|
||||||
use LibreNMS\Util\Rewrite;
|
use LibreNMS\Util\Rewrite;
|
||||||
use LibreNMS\Util\Time;
|
use LibreNMS\Util\Time;
|
||||||
@@ -341,7 +342,7 @@ class DeviceController extends TableController
|
|||||||
foreach (array_values(Arr::wrap(Config::get('html.device.links'))) as $index => $custom) {
|
foreach (array_values(Arr::wrap(Config::get('html.device.links'))) as $index => $custom) {
|
||||||
if ($custom['action'] ?? false) {
|
if ($custom['action'] ?? false) {
|
||||||
$row = $this->isDetailed() ? $index % 2 : 0;
|
$row = $this->isDetailed() ? $index % 2 : 0;
|
||||||
$custom['href'] = view(['template' => $custom['url']], ['device' => $device])->__toString(); // @phpstan-ignore-line
|
$custom['href'] = Blade::render($custom['url'], ['device' => $device]);
|
||||||
$actions[$row][] = $custom;
|
$actions[$row][] = $custom;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -52,8 +52,7 @@
|
|||||||
"rmccue/requests": "^1.7",
|
"rmccue/requests": "^1.7",
|
||||||
"symfony/yaml": "^4.0",
|
"symfony/yaml": "^4.0",
|
||||||
"tecnickcom/tcpdf": "^6.4",
|
"tecnickcom/tcpdf": "^6.4",
|
||||||
"tightenco/ziggy": "^0.9",
|
"tightenco/ziggy": "^0.9"
|
||||||
"wpb/string-blade-compiler": "^6.0"
|
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"barryvdh/laravel-debugbar": "^3.5",
|
"barryvdh/laravel-debugbar": "^3.5",
|
||||||
|
60
composer.lock
generated
60
composer.lock
generated
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "15408329c31958767d7e83c43760020d",
|
"content-hash": "cba65087f343b0ca7fa81ea5cb3dc1b5",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "amenadiel/jpgraph",
|
"name": "amenadiel/jpgraph",
|
||||||
@@ -7896,62 +7896,6 @@
|
|||||||
"source": "https://github.com/webmozarts/assert/tree/1.10.0"
|
"source": "https://github.com/webmozarts/assert/tree/1.10.0"
|
||||||
},
|
},
|
||||||
"time": "2021-03-09T10:59:23+00:00"
|
"time": "2021-03-09T10:59:23+00:00"
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "wpb/string-blade-compiler",
|
|
||||||
"version": "6.0.3",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/TerrePorter/StringBladeCompiler.git",
|
|
||||||
"reference": "89fa88cd782c05d4eabd7b18273a14f6490fba09"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://api.github.com/repos/TerrePorter/StringBladeCompiler/zipball/89fa88cd782c05d4eabd7b18273a14f6490fba09",
|
|
||||||
"reference": "89fa88cd782c05d4eabd7b18273a14f6490fba09",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"laravel/framework": "^6.0|^7.0|^8.0",
|
|
||||||
"php": "^7.2|^8.0"
|
|
||||||
},
|
|
||||||
"type": "library",
|
|
||||||
"extra": {
|
|
||||||
"laravel": {
|
|
||||||
"providers": [
|
|
||||||
"Wpb\\String_Blade_Compiler\\StringBladeServiceProvider"
|
|
||||||
],
|
|
||||||
"aliases": {
|
|
||||||
"StringBlade": "Wpb\\String_Blade_Compiler\\Facades\\StringBlade"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"Wpb\\String_Blade_Compiler\\": "src/"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
|
||||||
"license": [
|
|
||||||
"MIT"
|
|
||||||
],
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Terre Porter",
|
|
||||||
"email": "tporter@webpage-builders.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Laravel Blade String Compiler, render string as blade templates",
|
|
||||||
"keywords": [
|
|
||||||
"blade",
|
|
||||||
"compiler",
|
|
||||||
"laravel"
|
|
||||||
],
|
|
||||||
"support": {
|
|
||||||
"issues": "https://github.com/TerrePorter/StringBladeCompiler/issues",
|
|
||||||
"source": "https://github.com/TerrePorter/StringBladeCompiler/tree/6.0.3"
|
|
||||||
},
|
|
||||||
"time": "2020-12-18T14:17:09+00:00"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"packages-dev": [
|
"packages-dev": [
|
||||||
@@ -12542,5 +12486,5 @@
|
|||||||
"ext-xml": "*"
|
"ext-xml": "*"
|
||||||
},
|
},
|
||||||
"platform-dev": [],
|
"platform-dev": [],
|
||||||
"plugin-api-version": "2.1.0"
|
"plugin-api-version": "2.2.0"
|
||||||
}
|
}
|
||||||
|
@@ -33,7 +33,7 @@ $template_newid = 0;
|
|||||||
$create = true;
|
$create = true;
|
||||||
|
|
||||||
$name = $vars['name'];
|
$name = $vars['name'];
|
||||||
if (isset($vars['template']) && empty(view(['template' => $vars['template']], [])->__toString())) {
|
if (isset($vars['template']) && empty(Blade::render($vars['template']))) {
|
||||||
$message = 'Template failed to be parsed, please check the syntax';
|
$message = 'Template failed to be parsed, please check the syntax';
|
||||||
} elseif (! empty($name)) {
|
} elseif (! empty($name)) {
|
||||||
if ($vars['template'] && is_numeric($vars['template_id'])) {
|
if ($vars['template'] && is_numeric($vars['template_id'])) {
|
||||||
|
@@ -75,16 +75,6 @@ parameters:
|
|||||||
count: 1
|
count: 1
|
||||||
path: LibreNMS/Alert/Template.php
|
path: LibreNMS/Alert/Template.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Parameter \\#1 \\$view of function view expects view\\-string\\|null, array\\<string, mixed\\> given\\.$#"
|
|
||||||
count: 2
|
|
||||||
path: LibreNMS/Alert/Template.php
|
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Parameter \\#1 \\$view of function view expects view\\-string\\|null, array\\<string, string\\> given\\.$#"
|
|
||||||
count: 2
|
|
||||||
path: LibreNMS/Alert/Template.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Property LibreNMS\\\\Alert\\\\Template\\:\\:\\$template has no type specified\\.$#"
|
message: "#^Property LibreNMS\\\\Alert\\\\Template\\:\\:\\$template has no type specified\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
@@ -7810,11 +7800,6 @@ parameters:
|
|||||||
count: 1
|
count: 1
|
||||||
path: app/Http/Controllers/DeviceController.php
|
path: app/Http/Controllers/DeviceController.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Parameter \\#1 \\$view of function view expects view\\-string\\|null, array\\<string, mixed\\> given\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: app/Http/Controllers/DeviceController.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Property App\\\\Http\\\\Controllers\\\\DeviceController\\:\\:\\$tabs has no type specified\\.$#"
|
message: "#^Property App\\\\Http\\\\Controllers\\\\DeviceController\\:\\:\\$tabs has no type specified\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
|
Reference in New Issue
Block a user