Commit 875a59c8 authored by Tino Goratsch's avatar Tino Goratsch

Added the new Smarty function "image" which makes it possible to include an...

Added the new Smarty function "image" which makes it possible to include an image from the Assets/img folder of a design
parent 325f7a91
<?php
/**
* Copyright (c) 2017 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\View\Renderer\Smarty\Functions;
use ACP3\Core\Application\BootstrapInterface;
use ACP3\Core\Assets\FileResolver;
use ACP3\Core\Environment\ApplicationPath;
class Image extends AbstractFunction
{
/**
* @var FileResolver
*/
private $fileResolver;
/**
* @var ApplicationPath
*/
private $appPath;
/**
* Image constructor.
* @param FileResolver $fileResolver
* @param ApplicationPath $appPath
*/
public function __construct(FileResolver $fileResolver, ApplicationPath $appPath)
{
$this->fileResolver = $fileResolver;
$this->appPath = $appPath;
}
/**
* @inheritdoc
*/
public function process(array $params, \Smarty_Internal_Template $smarty)
{
if (isset($params['file']) === true && (bool)preg_match('=\./=', $params['file']) === false) {
$file = $params['file'];
$path = $this->fileResolver->getStaticAssetPath('/', '/', 'Assets/img', $file);
if (strpos($path, '/ACP3/Modules/') !== false) {
$path = $this->appPath->getWebRoot() . substr($path, strpos($path, '/ACP3/Modules/') + 1);
} else {
$path = $this->appPath->getWebRoot() . substr($path, strlen(ACP3_ROOT_DIR));
}
return $path . '?v=' . BootstrapInterface::VERSION;
}
throw new \Exception('Not all necessary arguments for the function ' . __FUNCTION__ . ' were passed!');
}
/**
* @return string
*/
public function getExtensionName()
{
return 'image';
}
}
......@@ -28,16 +28,16 @@ class IncludeJs extends AbstractFunction
/**
* @param \ACP3\Core\Assets $assets
* @param \ACP3\Core\Assets\FileResolver $fileResolved
* @param \ACP3\Core\Assets\FileResolver $fileResolver
* @param \ACP3\Core\Environment\ApplicationPath $appPath
*/
public function __construct(
Core\Assets $assets,
Core\Assets\FileResolver $fileResolved,
Core\Assets\FileResolver $fileResolver,
Core\Environment\ApplicationPath $appPath
) {
$this->assets = $assets;
$this->fileResolver = $fileResolved;
$this->fileResolver = $fileResolver;
$this->appPath = $appPath;
}
......
......@@ -41,6 +41,12 @@ services:
tags:
- { name: core.view.extension }
smarty.plugin.image:
class: ACP3\Core\View\Renderer\Smarty\Functions\Image
arguments: ['@core.assets.file_resolver', '@core.environment.application_path']
tags:
- { name: core.view.extension }
smarty.plugin.include_js:
class: ACP3\Core\View\Renderer\Smarty\Functions\IncludeJs
arguments: ['@core.assets', '@core.assets.file_resolver', '@core.environment.application_path']
......
......@@ -8,8 +8,8 @@
<div class="container text-center">
<h1 id="logo">
<a href="{uri args=""}">
<img src="{$DESIGN_PATH}Assets/img/logo.png"
srcset="{$DESIGN_PATH}Assets/img/logo.png 1x, {$DESIGN_PATH}Assets/img/logo@2x.png 2x"
<img src="{image file="logo.png"}"
srcset="{image file="logo.png"} 1x, {image file="logo@2x.png"} 2x"
alt="{site_title}">
</a>
</h1>
......
......@@ -6,16 +6,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased] - 2017-xx-xx
### Added
- updated the IncludeJs Smarty function to append a query string with the current version of the ACP3 for HTTP cache busting
- Updated the IncludeJs Smarty function to append a query string with the current version of the ACP3 for HTTP cache busting
- Added reCAPATCHA as a new captcha type
- Added the new Smarty function "image" which makes it possible to include an image from the Assets/img folder of a design
### Changed
- Refactored the captcha system so that it can be extended with different captcha types
- Refactored the URI alias generation for gallery pictures into an event
- improved the page titles when editing entries via the admin panel to make them more easily identifiable
- Improved the page titles when editing entries via the admin panel to make them more easily identifiable
### Fixed
- fixed the picture number generation when adding a new gallery picture
- Fixed the picture number generation when adding a new gallery picture
## [4.7.1] - 2017-02-27
### Fixed
......
......@@ -10,13 +10,13 @@
<div id="wrapper" class="container">
<h1 id="logo" class="hidden-xs">
{if $IS_HOMEPAGE}
<img src="{$DESIGN_PATH}Assets/img/logo.png"
srcset="{$DESIGN_PATH}Assets/img/logo.png 1x, {$DESIGN_PATH}Assets/img/logo@2x.png 2x"
<img src="{image file="logo.png"}"
srcset="{image file="logo.png"} 1x, {image file="logo@2x.png"} 2x"
alt="{site_title}">
{else}
<a href="{uri args=""}">
<img src="{$DESIGN_PATH}Assets/img/logo.png"
srcset="{$DESIGN_PATH}Assets/img/logo.png 1x, {$DESIGN_PATH}Assets/img/logo@2x.png 2x"
<img src="{image file="logo.png"}"
srcset="{image file="logo.png"} 1x, {image file="logo@2x.png"} 2x"
alt="{site_title}">
</a>
{/if}
......@@ -31,8 +31,8 @@
<span class="icon-bar"></span>
</button>
<a href="{$ROOT_DIR}" class="navbar-brand hidden-sm hidden-md hidden-lg">
<img src="{$DESIGN_PATH}Assets/img/logo.png"
srcset="{$DESIGN_PATH}Assets/img/logo.png 1x, {$DESIGN_PATH}Assets/img/logo@2x.png 2x"
<img src="{image file="logo.png"}"
srcset="{image file="logo.png"} 1x, {image file="logo@2x.png"} 2x"
alt="{site_title}">
</a>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment