Skip to content

Commit

Permalink
Merge pull request #498 from Groruk/qol-patch
Browse files Browse the repository at this point in the history
QOL | Start of templating rework
  • Loading branch information
Groruk authored Jul 29, 2018
2 parents 5597728 + ae10eab commit 83d8c61
Show file tree
Hide file tree
Showing 93 changed files with 5,387 additions and 1,289 deletions.
2 changes: 1 addition & 1 deletion web/configs/version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.7.0",
"git": "788",
"git": "808",
"dev": true
}
18 changes: 18 additions & 0 deletions web/includes/AdminTabs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
class AdminTabs
{
private $tabs = [];
public function __construct(array $tabs, $userbank)
{
foreach ($tabs as $tab) {
if ($userbank->HasAccess($tab['permission'])) {
if (!isset($tab['config']) || $tab['config']) {
$this->tabs[] = $tab;
}
}
}
Template::render('core/admin_tabs', [
'tabs' => $this->tabs
]);
}
}
53 changes: 0 additions & 53 deletions web/includes/CTabsMenu.php

This file was deleted.

88 changes: 88 additions & 0 deletions web/includes/Mustache/Autoloader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

/*
* This file is part of Mustache.php.
*
* (c) 2010-2017 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* Mustache class autoloader.
*/
class Mustache_Autoloader
{
private $baseDir;

/**
* An array where the key is the baseDir and the key is an instance of this
* class.
*
* @var array
*/
private static $instances;

/**
* Autoloader constructor.
*
* @param string $baseDir Mustache library base directory (default: dirname(__FILE__).'/..')
*/
public function __construct($baseDir = null)
{
if ($baseDir === null) {
$baseDir = dirname(__FILE__) . '/..';
}

// realpath doesn't always work, for example, with stream URIs
$realDir = realpath($baseDir);
if (is_dir($realDir)) {
$this->baseDir = $realDir;
} else {
$this->baseDir = $baseDir;
}
}

/**
* Register a new instance as an SPL autoloader.
*
* @param string $baseDir Mustache library base directory (default: dirname(__FILE__).'/..')
*
* @return Mustache_Autoloader Registered Autoloader instance
*/
public static function register($baseDir = null)
{
$key = $baseDir ? $baseDir : 0;

if (!isset(self::$instances[$key])) {
self::$instances[$key] = new self($baseDir);
}

$loader = self::$instances[$key];
spl_autoload_register(array($loader, 'autoload'));

return $loader;
}

/**
* Autoload Mustache classes.
*
* @param string $class
*/
public function autoload($class)
{
if ($class[0] === '\\') {
$class = substr($class, 1);
}

if (strpos($class, 'Mustache') !== 0) {
return;
}

$file = sprintf('%s/%s.php', $this->baseDir, str_replace('_', '/', $class));
if (is_file($file)) {
require $file;
}
}
}
36 changes: 36 additions & 0 deletions web/includes/Mustache/Cache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of Mustache.php.
*
* (c) 2010-2017 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* Mustache Cache interface.
*
* Interface for caching and loading Mustache_Template classes
* generated by the Mustache_Compiler.
*/
interface Mustache_Cache
{
/**
* Load a compiled Mustache_Template class from cache.
*
* @param string $key
*
* @return bool indicates successfully class load
*/
public function load($key);

/**
* Cache and load a compiled Mustache_Template class.
*
* @param string $key
* @param string $value
*/
public function cache($key, $value);
}
60 changes: 60 additions & 0 deletions web/includes/Mustache/Cache/AbstractCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/*
* This file is part of Mustache.php.
*
* (c) 2010-2017 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* Abstract Mustache Cache class.
*
* Provides logging support to child implementations.
*
* @abstract
*/
abstract class Mustache_Cache_AbstractCache implements Mustache_Cache
{
private $logger = null;

/**
* Get the current logger instance.
*
* @return Mustache_Logger|Psr\Log\LoggerInterface
*/
public function getLogger()
{
return $this->logger;
}

/**
* Set a logger instance.
*
* @param Mustache_Logger|Psr\Log\LoggerInterface $logger
*/
public function setLogger($logger = null)
{
if ($logger !== null && !($logger instanceof Mustache_Logger || is_a($logger, 'Psr\\Log\\LoggerInterface'))) {
throw new Mustache_Exception_InvalidArgumentException('Expected an instance of Mustache_Logger or Psr\\Log\\LoggerInterface.');
}

$this->logger = $logger;
}

/**
* Add a log record if logging is enabled.
*
* @param int $level The logging level
* @param string $message The log message
* @param array $context The log context
*/
protected function log($level, $message, array $context = array())
{
if (isset($this->logger)) {
$this->logger->log($level, $message, $context);
}
}
}
Loading

0 comments on commit 83d8c61

Please sign in to comment.