Commit b07acbb3 authored by Tino Goratsch's avatar Tino Goratsch

- refactored the MoveToBottom and MoveToHead classes

- brought the same element moving capabilities to the install wizard
parent 0787340e
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\View\Renderer\Smarty\Filters;
/**
* Class AbstractMoveElementFilter
* @package ACP3\Core\View\Renderer\Smarty\Filters
*/
abstract class AbstractMoveElementFilter extends AbstractFilter
{
const ELEMENT_CATCHER_REGEX_PATTERN = '';
const PLACEHOLDER = '';
/**
* @param string $tplOutput
* @return string
*/
protected function getCleanedUpTemplateOutput($tplOutput)
{
return preg_replace(static::ELEMENT_CATCHER_REGEX_PATTERN, '', $tplOutput);
}
/**
* @param string $tplOutput
* @return string
*/
protected function addElementsFromTemplates($tplOutput)
{
$matches = [];
preg_match_all(static::ELEMENT_CATCHER_REGEX_PATTERN, $tplOutput, $matches);
return implode("\n", array_unique($matches[1])) . "\n";
}
}
......@@ -8,8 +8,11 @@ use ACP3\Core\Http\RequestInterface;
* Class MoveToBottom
* @package ACP3\Core\View\Renderer\Smarty\Filters
*/
class MoveToBottom extends AbstractFilter
class MoveToBottom extends AbstractMoveElementFilter
{
const ELEMENT_CATCHER_REGEX_PATTERN = '!@@@SMARTY:JAVASCRIPTS:BEGIN@@@(.*?)@@@SMARTY:JAVASCRIPTS:END@@@!is';
const PLACEHOLDER = '<!-- JAVASCRIPTS -->';
/**
* @var \ACP3\Core\Assets\AbstractMinifier
*/
......@@ -44,23 +47,26 @@ class MoveToBottom extends AbstractFilter
*/
public function process($tplOutput, \Smarty_Internal_Template $smarty)
{
$pattern = '!@@@SMARTY:JAVASCRIPTS:BEGIN@@@(.*?)@@@SMARTY:JAVASCRIPTS:END@@@!is';
if (strpos($tplOutput, '<!-- JAVASCRIPTS -->') !== false) {
$matches = [];
preg_match_all($pattern, $tplOutput, $matches);
// Remove placeholder comments
$tplOutput = preg_replace($pattern, '', $tplOutput);
$minifyJs = '';
if (!$this->request->isAjax()) {
$minifyJs = '<script type="text/javascript" src="' . $this->minifier->getURI() . '"></script>' . "\n";
}
return str_replace('<!-- JAVASCRIPTS -->', $minifyJs . implode("\n", array_unique($matches[1])) . "\n", $tplOutput);
if (strpos($tplOutput, static::PLACEHOLDER) !== false) {
return str_replace(
static::PLACEHOLDER,
$this->addElementFromMinifier() . $this->addElementsFromTemplates($tplOutput),
$this->getCleanedUpTemplateOutput($tplOutput)
);
}
return $tplOutput;
}
/**
* @return string
*/
protected function addElementFromMinifier()
{
$minifyJs = '';
if (!$this->request->isAjax()) {
$minifyJs = '<script type="text/javascript" src="' . $this->minifier->getURI() . '"></script>' . "\n";
}
return $minifyJs;
}
}
......@@ -7,8 +7,11 @@ use ACP3\Core\Assets\MinifierInterface;
* Class MoveToHead
* @package ACP3\Core\View\Renderer\Smarty\Filters
*/
class MoveToHead extends AbstractFilter
class MoveToHead extends AbstractMoveElementFilter
{
const ELEMENT_CATCHER_REGEX_PATTERN = "!@@@SMARTY:STYLESHEETS:BEGIN@@@(.*?)@@@SMARTY:STYLESHEETS:END@@@!is";
const PLACEHOLDER = '<!-- STYLESHEETS -->';
/**
* @var \ACP3\Core\Assets\MinifierInterface
*/
......@@ -35,16 +38,22 @@ class MoveToHead extends AbstractFilter
*/
public function process($tplOutput, \Smarty_Internal_Template $smarty)
{
if (strpos($tplOutput, '<!-- STYLESHEETS -->') !== false) {
$matches = [];
preg_match_all('!@@@SMARTY:STYLESHEETS:BEGIN@@@(.*?)@@@SMARTY:STYLESHEETS:END@@@!is', $tplOutput, $matches);
// Remove placeholder comments
$tplOutput = preg_replace("!@@@SMARTY:STYLESHEETS:BEGIN@@@(.*?)@@@SMARTY:STYLESHEETS:END@@@!is", '', $tplOutput);
$minifyCss = '<link rel="stylesheet" type="text/css" href="' . $this->minifier->getURI() . '">' . "\n";
return str_replace('<!-- STYLESHEETS -->', $minifyCss . implode("\n", array_unique($matches[1])) . "\n", $tplOutput);
if (strpos($tplOutput, static::PLACEHOLDER) !== false) {
$tplOutput = str_replace(
static::PLACEHOLDER,
$this->addElementFromMinifier() . $this->addElementsFromTemplates($tplOutput),
$this->getCleanedUpTemplateOutput($tplOutput)
);
}
return $tplOutput;
}
/**
* @return string
*/
protected function addElementFromMinifier()
{
return '<link rel="stylesheet" type="text/css" href="' . $this->minifier->getURI() . '">' . "\n";
}
}
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Installer\Core\View\Renderer\Smarty\Filters;
/**
* Class MoveToBottom
* @package ACP3\Installer\Core\View\Renderer\Smarty\Filters
*/
class MoveToBottom extends \ACP3\Core\View\Renderer\Smarty\Filters\MoveToBottom
{
public function __construct()
{
;
}
/**
* @inheritdoc
*/
protected function addElementFromMinifier()
{
return '';
}
}
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Installer\Core\View\Renderer\Smarty\Filters;
/**
* Class MoveToHead
* @package ACP3\Installer\Core\View\Renderer\Smarty\Filters
*/
class MoveToHead extends \ACP3\Core\View\Renderer\Smarty\Filters\MoveToHead
{
public function __construct()
{
;
}
/**
* @inheritdoc
*/
protected function addElementFromMinifier()
{
return '';
}
}
......@@ -14,6 +14,17 @@ services:
smarty.resource.asset:
class: ACP3\Installer\Core\View\Renderer\Smarty\Resources\Asset
arguments:
- @core.environment.application_path
- '@core.environment.application_path'
tags:
- { name: core.view.extension }
smarty.filter.move_to_bottom:
class: ACP3\Installer\Core\View\Renderer\Smarty\Filters\MoveToBottom
tags:
- { name: core.view.extension }
smarty.filter.move_to_head:
class: ACP3\Installer\Core\View\Renderer\Smarty\Filters\MoveToHead
tags:
- { name: core.view.extension }
......@@ -9,6 +9,7 @@ imports:
- { resource: ../View/Renderer/Smarty/config/services.yml }
- { resource: ../../Modules/Errors/Resources/config/services.yml }
- { resource: ../../Modules/Install/Resources/config/services.yml }
- { resource: ../../../../ACP3/Core/View/Renderer/Smarty/Blocks/config/services.yml }
services:
core.application.front_controller:
......
......@@ -80,7 +80,7 @@ class Index extends AbstractAction
public function execute()
{
if ($this->request->getPost()->isEmpty() === false) {
if ($this->request->getPost()->isEmpty() === false && !$this->request->getPost()->get('languages')) {
$this->executePost($this->request->getPost()->all());
}
......
{extends file="asset:layout.tpl"}
{block CONTENT prepend}
{stylesheets}
<link rel="stylesheet" type="text/css" href="{$INSTALLER_ROOT_DIR}Installer/Modules/Install/Resources/Assets/css/style.css">
{/stylesheets}
<div class="well well-sm licence">
<h3>Table of Contents</h3>
<ul>
......@@ -188,4 +192,4 @@
<a href="{uri args="install/index/requirements"}" class="btn btn-success">{lang t="install|accept"}</a>
<a href="{uri args="install"}" class="btn btn-danger">{lang t="install|decline"}</a>
</div>
{/block}
\ No newline at end of file
{/block}
/*
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
jQuery(document).ready(function ($) {
var $doc = $(document);
$doc.data('has-changes', false);
$('input, select').change(function () {
if ($(this).attr('id') !== 'lang') {
$doc.data('has-changes', true);
}
});
// Sprachdropdown
$('#languages').find(':submit').hide();
$('#lang').change(function () {
var allowPageReload = true;
if ($doc.length > 0 && $doc.data('has-changes') == true) {
allowPageReload = confirm($('#lang').data('change-language-warning'));
}
if (allowPageReload === true) {
$('#languages').submit();
}
});
});
......@@ -8,8 +8,8 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="{$ROOT_DIR}ACP3/Modules/ACP3/System/Resources/Assets/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="{$INSTALLER_ROOT_DIR}design/Assets/css/style.css">
<link rel="stylesheet" type="text/css" href="{$INSTALLER_ROOT_DIR}Installer/Modules/Install/Resources/Assets/css/style.css">
<link rel="stylesheet" type="text/css" href="{$DESIGN_PATH}Assets/css/style.css">
<!-- STYLESHEETS -->
<!--[if lt IE 9]>
<script src="{$ROOT_DIR}ACP3/Modules/ACP3/System/Resources/Assets/js/libs/html5shiv.js"></script>
<![endif]-->
......@@ -46,7 +46,11 @@
{/if}
<form action="{$REQUEST_URI}" method="post" id="languages" class="navbar-form navbar-right">
<div class="form-group">
<select name="lang" id="lang" class="form-control" title="{lang t="install|select_language"}">
<select name="lang"
id="lang"
class="form-control"
title="{lang t="install|select_language"}"
data-change-language-warning="{lang t="install|form_change_warning"}">
{foreach $LANGUAGES as $row}
<option value="{$row.language}"{$row.selected}>{$row.name}</option>
{/foreach}
......@@ -63,30 +67,8 @@
</div>
<script type="text/javascript" src="{$ROOT_DIR}ACP3/Modules/ACP3/System/Resources/Assets/js/libs/jquery.min.js"></script>
<script type="text/javascript" src="{$ROOT_DIR}ACP3/Modules/ACP3/System/Resources/Assets/js/libs/bootstrap.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function ($) {
var $configForm = $('#config-form');
if ($configForm.length > 0) {
$configForm.data('changed', false);
$configForm.find('input, select').change(function () {
$configForm.data('changed', true);
});
}
// Sprachdropdown
$('#languages').find(':submit').hide();
$('#lang').change(function () {
var reload = true;
if ($configForm.length > 0 && $configForm.data('changed') == true) {
reload = confirm('{lang t="install|form_change_warning"}');
}
if (reload === true) {
$('#languages').submit();
}
});
});
</script>
<script type="text/javascript" src="{$DESIGN_PATH}Assets/js/language-switcher.js"></script>
<!-- JAVASCRIPTS -->
</body>
</html>
{/if}
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