mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2024-12-27 06:29:19 +08:00
add useful functions for plugins
This commit is contained in:
parent
f6aadc71f0
commit
954329a8e7
@ -72,23 +72,35 @@ class Hook
|
||||
}, 999);
|
||||
}
|
||||
|
||||
public static function addStyleFileToPage($urls, $priority = 1)
|
||||
public static function addStyleFileToPage($urls, $pages = ['*'], $priority = 1)
|
||||
{
|
||||
Event::listen(Events\RenderingHeader::class, function($event) use ($urls)
|
||||
Event::listen(Events\RenderingHeader::class, function($event) use ($urls, $pages)
|
||||
{
|
||||
foreach ((array) $urls as $url) {
|
||||
$event->addContent("<link rel=\"stylesheet\" href=\"$url\">");
|
||||
foreach ($pages as $pattern) {
|
||||
if (!app('request')->is($pattern))
|
||||
continue;
|
||||
|
||||
foreach ((array) $urls as $url) {
|
||||
$event->addContent("<link rel=\"stylesheet\" href=\"$url\">");
|
||||
}
|
||||
}
|
||||
|
||||
}, $priority);
|
||||
}
|
||||
|
||||
public static function addScriptFileToPage($urls, $priority = 1)
|
||||
public static function addScriptFileToPage($urls, $pages = ['*'], $priority = 1)
|
||||
{
|
||||
Event::listen(Events\RenderingFooter::class, function($event) use ($urls)
|
||||
Event::listen(Events\RenderingFooter::class, function($event) use ($urls, $pages)
|
||||
{
|
||||
foreach ((array) $urls as $url) {
|
||||
$event->addContent("<script src=\"$url\"></script>");
|
||||
foreach ($pages as $pattern) {
|
||||
if (!app('request')->is($pattern))
|
||||
continue;
|
||||
|
||||
foreach ((array) $urls as $url) {
|
||||
$event->addContent("<script src=\"$url\"></script>");
|
||||
}
|
||||
}
|
||||
|
||||
}, $priority);
|
||||
}
|
||||
}
|
||||
|
@ -103,6 +103,11 @@ class Plugin implements Arrayable, ArrayAccess
|
||||
return Arr::get($this->packageInfo, $name);
|
||||
}
|
||||
|
||||
public function assets($relativeUri)
|
||||
{
|
||||
return url("plugins/{$this->getDirname()}/$relativeUri");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $installed
|
||||
* @return Plugin
|
||||
|
@ -36,25 +36,33 @@ if (! function_exists('avatar')) {
|
||||
|
||||
if (! function_exists('assets')) {
|
||||
|
||||
function assets($relative_uri)
|
||||
function assets($relativeUri)
|
||||
{
|
||||
// add query string to fresh cache
|
||||
if (Str::startsWith($relative_uri, 'css') || Str::startsWith($relative_uri, 'js')) {
|
||||
return url("resources/assets/dist/$relative_uri")."?v=".config('app.version');
|
||||
} elseif (Str::startsWith($relative_uri, 'lang')) {
|
||||
return url("resources/$relative_uri");
|
||||
if (Str::startsWith($relativeUri, 'css') || Str::startsWith($relativeUri, 'js')) {
|
||||
return url("resources/assets/dist/$relativeUri")."?v=".config('app.version');
|
||||
} elseif (Str::startsWith($relativeUri, 'lang')) {
|
||||
return url("resources/$relativeUri");
|
||||
} else {
|
||||
return url("resources/assets/$relative_uri");
|
||||
return url("resources/assets/$relativeUri");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('plugin')) {
|
||||
|
||||
function plugin($id)
|
||||
{
|
||||
return app('plugins')->getPlugin($id);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('plugin_assets')) {
|
||||
|
||||
function plugin_assets($id, $relative_uri)
|
||||
function plugin_assets($id, $relativeUri)
|
||||
{
|
||||
if ($plugin = app('plugins')->getPlugin($id)) {
|
||||
return url("plugins/{$plugin->getDirname()}/$relative_uri");
|
||||
if ($plugin = plugin($id)) {
|
||||
return $plugin->assets($relativeUri);
|
||||
} else {
|
||||
throw new InvalidArgumentException("No such plugin.");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user