mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 01:09:21 +02:00
parent
4adb0758c5
commit
cb6e9a6a88
@ -545,33 +545,39 @@ function template_header($is_admin = false): string
|
||||
*/
|
||||
function template_footer(): string
|
||||
{
|
||||
global $views_counter;
|
||||
$ret = '';
|
||||
$footer = [];
|
||||
|
||||
if(admin()) {
|
||||
$ret .= generateLink(ADMIN_URL, 'Admin Panel', true);
|
||||
$footer[] = generateLink(ADMIN_URL, 'Admin Panel', true);
|
||||
}
|
||||
|
||||
if(setting('core.visitors_counter')) {
|
||||
global $visitors;
|
||||
$amount = $visitors->getAmountVisitors();
|
||||
$ret .= '<br/>Currently there ' . ($amount > 1 ? 'are' : 'is') . ' ' . $amount . ' visitor' . ($amount > 1 ? 's' : '') . '.';
|
||||
$footer[] = 'Currently there ' . ($amount > 1 ? 'are' : 'is') . ' ' . $amount . ' visitor' . ($amount > 1 ? 's' : '') . '.';
|
||||
}
|
||||
|
||||
if(setting('core.views_counter')) {
|
||||
$ret .= '<br/>Page has been viewed ' . $views_counter . ' times.';
|
||||
global $views_counter;
|
||||
$footer[] = 'Page has been viewed ' . $views_counter . ' times.';
|
||||
}
|
||||
|
||||
if(setting('core.footer_load_time')) {
|
||||
$ret .= '<br/>Load time: ' . round(microtime(true) - START_TIME, 4) . ' seconds.';
|
||||
$footer[] = 'Load time: ' . round(microtime(true) - START_TIME, 4) . ' seconds.';
|
||||
}
|
||||
|
||||
$settingFooter = setting('core.footer');
|
||||
if(isset($settingFooter[0])) {
|
||||
$ret .= '<br/>' . $settingFooter;
|
||||
$footer[] = '' . $settingFooter;
|
||||
}
|
||||
|
||||
// please respect my work and help spreading the word, thanks!
|
||||
return $ret . '<br/>' . base64_decode('UG93ZXJlZCBieSA8YSBocmVmPSJodHRwOi8vbXktYWFjLm9yZyIgdGFyZ2V0PSJfYmxhbmsiPk15QUFDLjwvYT4=');
|
||||
$footer[] = base64_decode('UG93ZXJlZCBieSA8YSBocmVmPSJodHRwOi8vbXktYWFjLm9yZyIgdGFyZ2V0PSJfYmxhbmsiPk15QUFDLjwvYT4=');
|
||||
|
||||
global $hooks;
|
||||
$footer = $hooks->triggerFilter(HOOK_FILTER_THEME_FOOTER, $footer);
|
||||
|
||||
return implode('<br/>', $footer);
|
||||
}
|
||||
|
||||
function template_ga_code()
|
||||
|
@ -37,6 +37,11 @@ class Hook
|
||||
return !isset($ret) || $ret == 1 || $ret;
|
||||
}
|
||||
|
||||
public function executeFilter(...$args) {
|
||||
return include BASE . $this->_file;
|
||||
}
|
||||
|
||||
public function name() {return $this->_name;}
|
||||
public function type() {return $this->_type;}
|
||||
public function file() {return $this->_file;}
|
||||
}
|
||||
|
@ -4,22 +4,23 @@ namespace MyAAC;
|
||||
|
||||
class Hooks
|
||||
{
|
||||
private static $_hooks = array();
|
||||
private static array $_hooks = [];
|
||||
|
||||
public function register($hook, $type = '', $file = null) {
|
||||
public function register($hook, $type = '', $file = null): void
|
||||
{
|
||||
if(!($hook instanceof Hook))
|
||||
$hook = new Hook($hook, $type, $file);
|
||||
|
||||
self::$_hooks[$hook->type()][] = $hook;
|
||||
}
|
||||
|
||||
public function trigger($type, $params = array())
|
||||
public function trigger($type, $params = []): bool
|
||||
{
|
||||
$ret = true;
|
||||
if(isset(self::$_hooks[$type]))
|
||||
{
|
||||
|
||||
if(isset(self::$_hooks[$type])) {
|
||||
foreach(self::$_hooks[$type] as $name => $hook) {
|
||||
/** @var $hook Hook */
|
||||
/** @var Hook $hook */
|
||||
if (!$hook->execute($params)) {
|
||||
$ret = false;
|
||||
}
|
||||
@ -29,11 +30,23 @@ class Hooks
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function exist($type) {
|
||||
public function triggerFilter($type, $args = [])
|
||||
{
|
||||
if(isset(self::$_hooks[$type])) {
|
||||
foreach(self::$_hooks[$type] as $hook) {
|
||||
/** @var Hook $hook */
|
||||
$args = $hook->executeFilter(...$args);
|
||||
}
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
public function exist($type): bool {
|
||||
return isset(self::$_hooks[$type]);
|
||||
}
|
||||
|
||||
public function load()
|
||||
public function load(): void
|
||||
{
|
||||
foreach(Plugins::getHooks() as $hook) {
|
||||
$this->register($hook['name'], $hook['type'], $hook['file']);
|
||||
|
28
system/src/Twig/EnvironmentBridge.php
Normal file
28
system/src/Twig/EnvironmentBridge.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace MyAAC\Twig;
|
||||
|
||||
use Twig\Environment;
|
||||
|
||||
class EnvironmentBridge extends Environment
|
||||
{
|
||||
public function display($name, array $context = []): void
|
||||
{
|
||||
global $hooks;
|
||||
|
||||
$context['viewName'] = $name;
|
||||
$context = $hooks->triggerFilter(HOOK_FILTER_TWIG_DISPLAY, $context);
|
||||
|
||||
parent::display($name, $context);
|
||||
}
|
||||
|
||||
public function render($name, array $context = []): string
|
||||
{
|
||||
global $hooks;
|
||||
|
||||
$context['viewName'] = $name;
|
||||
$context = $hooks->triggerFilter(HOOK_FILTER_TWIG_RENDER, $context);
|
||||
|
||||
return parent::render($name, $context);
|
||||
}
|
||||
}
|
@ -97,6 +97,11 @@ define('HOOK_CACHE_CLEAR', ++$i);
|
||||
define('HOOK_INSTALL_FINISH', ++$i);
|
||||
define('HOOK_INSTALL_FINISH_END', ++$i);
|
||||
|
||||
// hook filters
|
||||
define('HOOK_FILTER_TWIG_DISPLAY', ++$i);
|
||||
define('HOOK_FILTER_TWIG_RENDER', ++$i);
|
||||
define('HOOK_FILTER_THEME_FOOTER', ++$i);
|
||||
|
||||
const HOOK_FIRST = HOOK_INIT;
|
||||
define('HOOK_LAST', $i);
|
||||
|
||||
|
@ -9,8 +9,7 @@
|
||||
*/
|
||||
defined('MYAAC') or die('Direct access not allowed!');
|
||||
|
||||
use MyAAC\CsrfToken;
|
||||
use Twig\Environment as Twig_Environment;
|
||||
use MyAAC\Twig\EnvironmentBridge as MyAAC_Twig_EnvironmentBridge;
|
||||
use Twig\Extension\DebugExtension as Twig_DebugExtension;
|
||||
use Twig\Loader\FilesystemLoader as Twig_FilesystemLoader;
|
||||
use Twig\TwigFilter;
|
||||
@ -20,7 +19,7 @@ global $twig, $twig_loader;
|
||||
|
||||
$dev_mode = (config('env') === 'dev');
|
||||
$twig_loader = new Twig_FilesystemLoader(SYSTEM . 'templates');
|
||||
$twig = new Twig_Environment($twig_loader, array(
|
||||
$twig = new MyAAC_Twig_EnvironmentBridge($twig_loader, array(
|
||||
'cache' => CACHE . 'twig/',
|
||||
'auto_reload' => $dev_mode,
|
||||
'debug' => $dev_mode
|
||||
|
Loading…
x
Reference in New Issue
Block a user