summaryrefslogtreecommitdiff
path: root/modules_v4
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@webtrees.net>2019-03-13 18:23:34 +0000
committerGreg Roach <fisharebest@webtrees.net>2019-03-13 18:23:34 +0000
commit9ef73392e918bb739aaf4bae10ef7ee867ad703d (patch)
tree94df0318fe8ea1a5f261f8617e48f744a680e4cf /modules_v4
parentc291702fe0d88b376ff3cc4d8448c5bee9b80e6a (diff)
downloadwebtrees-9ef73392e918bb739aaf4bae10ef7ee867ad703d.tar.gz
webtrees-9ef73392e918bb739aaf4bae10ef7ee867ad703d.tar.bz2
webtrees-9ef73392e918bb739aaf4bae10ef7ee867ad703d.zip
Add utility function to custom theme trait
Diffstat (limited to 'modules_v4')
-rw-r--r--modules_v4/example-theme.disable/module.php85
1 files changed, 0 insertions, 85 deletions
diff --git a/modules_v4/example-theme.disable/module.php b/modules_v4/example-theme.disable/module.php
index cb0abe53e1..8b0b2d8590 100644
--- a/modules_v4/example-theme.disable/module.php
+++ b/modules_v4/example-theme.disable/module.php
@@ -2,19 +2,10 @@
namespace MyCustomNamespace;
-use Fisharebest\Webtrees\Carbon;
use Fisharebest\Webtrees\Module\MinimalTheme;
use Fisharebest\Webtrees\Module\ModuleCustomInterface;
use Fisharebest\Webtrees\Module\ModuleCustomTrait;
use Fisharebest\Webtrees\View;
-use Illuminate\Support\Str;
-use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
-use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
-use function filemtime;
-use function pathinfo;
-use const PATHINFO_EXTENSION;
/**
* Example theme. Here we are extending an existing theme.
@@ -69,80 +60,4 @@ return new class extends MinimalTheme implements ModuleCustomInterface {
return $stylesheets;
}
-
- /**
- * Create a URL for an asset.
- *
- * @param string $asset e.g. "css/theme.css" or "img/banner.png"
- *
- * @return string
- */
- public function assetUrl(string $asset): string
- {
- $file = $this->resourceFolder() . $asset;
-
- // Add the file's modification time to the URL, so we can set long expiry cache headers.
- $hash = filemtime($file);
-
- return route('module', [
- 'module' => $this->name(),
- 'action' => 'asset',
- 'asset' => $asset,
- 'hash' => $hash,
- ]);
- }
-
- /**
- * Serve a CSS/JS file.
- *
- * @param Request $request
- *
- * @return Response
- */
- public function getAssetAction(Request $request): Response
- {
- // The file being requested. e.g. "css/theme.css"
- $asset = $request->get('asset');
-
- // Do not allow requests that try to access parent folders.
- if (Str::contains($asset, '..')) {
- throw new AccessDeniedHttpException($asset);
- }
-
- // Find the file for this asset.
- // Note that we could also generate CSS files using views/templates.
- // e.g. $file = view(....
- $file = $this->resourceFolder() . $asset;
-
- if (!file_exists($file)) {
- throw new NotFoundHttpException($file);
- }
-
- $content = file_get_contents($file);
- $expiry_date = Carbon::now()->addYears(10);
-
- $extension = pathinfo($asset, PATHINFO_EXTENSION);
-
- $mime_types = [
- 'css' => 'text/css',
- 'gif' => 'image/gif',
- 'js' => 'application/javascript',
- 'jpg' => 'image/jpg',
- 'jpeg' => 'image/jpg',
- 'json' => 'application/json',
- 'png' => 'image/png',
- 'txt' => 'text/plain',
- ];
-
- $mime_type = $mime_types[$extension] ?? 'application/octet-stream';
-
- $headers = [
- 'Content-Type' => $mime_type,
- ];
-
- $response = new Response($content, Response::HTTP_OK, $headers);
-
- return $response
- ->setExpires($expiry_date);
- }
};