stuff i did at school
This commit is contained in:
parent
b7cc440984
commit
f69f2742cd
5 changed files with 37 additions and 27 deletions
|
@ -10,6 +10,7 @@ namespace Sakura\Controllers;
|
|||
use Sakura\Config;
|
||||
use Sakura\File;
|
||||
use Sakura\Perms\Site;
|
||||
use Sakura\Template;
|
||||
use Sakura\User;
|
||||
|
||||
/**
|
||||
|
@ -44,11 +45,9 @@ class FileController extends Controller
|
|||
*/
|
||||
public function avatar($id = 0)
|
||||
{
|
||||
global $templateName;
|
||||
|
||||
$noAvatar = ROOT . str_replace(
|
||||
'{{ TPL }}',
|
||||
$templateName,
|
||||
Template::$name,
|
||||
Config::get('no_avatar_img')
|
||||
);
|
||||
$none = [
|
||||
|
@ -59,7 +58,7 @@ class FileController extends Controller
|
|||
|
||||
$deactivePath = ROOT . str_replace(
|
||||
'{{ TPL }}',
|
||||
$templateName,
|
||||
Template::$name,
|
||||
Config::get('deactivated_avatar_img')
|
||||
);
|
||||
$deactive = [
|
||||
|
@ -70,7 +69,7 @@ class FileController extends Controller
|
|||
|
||||
$bannedPath = ROOT . str_replace(
|
||||
'{{ TPL }}',
|
||||
$templateName,
|
||||
Template::$name,
|
||||
Config::get('banned_avatar_img')
|
||||
);
|
||||
$banned = [
|
||||
|
@ -109,8 +108,6 @@ class FileController extends Controller
|
|||
*/
|
||||
public function background($id = 0)
|
||||
{
|
||||
global $templateName;
|
||||
|
||||
$noBg = ROOT . Config::get('no_background_img');
|
||||
$none = [
|
||||
'name' => basename($noBg),
|
||||
|
@ -146,8 +143,6 @@ class FileController extends Controller
|
|||
*/
|
||||
public function header($id = 0)
|
||||
{
|
||||
global $templateName;
|
||||
|
||||
$noHeader = ROOT . Config::get('no_header_img');
|
||||
$none = [
|
||||
'name' => basename($noHeader),
|
||||
|
|
|
@ -33,14 +33,21 @@ class Template
|
|||
*
|
||||
* @var Twig_Environment
|
||||
*/
|
||||
private static $template;
|
||||
private static $engine;
|
||||
|
||||
/**
|
||||
* The template name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $templateName;
|
||||
public static $name;
|
||||
|
||||
/**
|
||||
* The path to the client side resources
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $resources;
|
||||
|
||||
/**
|
||||
* The file extension used by template files
|
||||
|
@ -55,7 +62,10 @@ class Template
|
|||
public static function set($name)
|
||||
{
|
||||
// Set variables
|
||||
self::$templateName = $name;
|
||||
self::$name = $name;
|
||||
|
||||
// Set reources path
|
||||
self::$resources = Config::get('content_path') . '/data/' . self::$name;
|
||||
|
||||
// Reinitialise
|
||||
self::init();
|
||||
|
@ -67,7 +77,7 @@ class Template
|
|||
public static function init()
|
||||
{
|
||||
// Initialise Twig Filesystem Loader
|
||||
$twigLoader = new Twig_Loader_Filesystem(ROOT . 'templates/' . self::$templateName);
|
||||
$twigLoader = new Twig_Loader_Filesystem(ROOT . 'templates/' . self::$name);
|
||||
|
||||
// Environment variable
|
||||
$twigEnv = [];
|
||||
|
@ -78,26 +88,31 @@ class Template
|
|||
}
|
||||
|
||||
// And now actually initialise the templating engine
|
||||
self::$template = new Twig_Environment($twigLoader, $twigEnv);
|
||||
self::$engine = new Twig_Environment($twigLoader, $twigEnv);
|
||||
|
||||
// Load String template loader
|
||||
self::$template->addExtension(new Twig_Extension_StringLoader());
|
||||
self::$engine->addExtension(new Twig_Extension_StringLoader());
|
||||
|
||||
// Add route function
|
||||
self::$template->addFunction(new Twig_SimpleFunction('route', function ($name, $args = null) {
|
||||
self::$engine->addFunction(new Twig_SimpleFunction('route', function ($name, $args = null) {
|
||||
return Router::route($name, $args);
|
||||
}));
|
||||
|
||||
// Add config function
|
||||
self::$template->addFunction(new Twig_SimpleFunction('config', function ($name) {
|
||||
self::$engine->addFunction(new Twig_SimpleFunction('config', function ($name) {
|
||||
return Config::get($name);
|
||||
}));
|
||||
|
||||
// Add resource function
|
||||
self::$engine->addFunction(new Twig_SimpleFunction('resource', function ($path = "") {
|
||||
return self::$resources . "/{$path}";
|
||||
}));
|
||||
|
||||
// Method of getting the currently active session id
|
||||
self::$template->addFunction(new Twig_SimpleFunction('session_id', 'session_id'));
|
||||
self::$engine->addFunction(new Twig_SimpleFunction('session_id', 'session_id'));
|
||||
|
||||
// json_decode filter (why doesn't this exist to begin with?)
|
||||
self::$template->addFilter(new Twig_SimpleFilter('json_decode', 'json_decode'));
|
||||
self::$engine->addFilter(new Twig_SimpleFilter('json_decode', 'json_decode'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -120,7 +135,7 @@ class Template
|
|||
public static function render($file)
|
||||
{
|
||||
try {
|
||||
return self::$template->render($file . self::FILE_EXT, self::$vars);
|
||||
return self::$engine->render($file . self::FILE_EXT, self::$vars);
|
||||
} catch (\Exception $e) {
|
||||
return trigger_error($e->getMessage(), E_USER_ERROR);
|
||||
}
|
||||
|
|
|
@ -35,11 +35,11 @@
|
|||
<link rel="manifest" href="/manifest.json" />
|
||||
{{ block('meta') }}
|
||||
<!-- CSS -->
|
||||
<link rel="stylesheet" type="text/css" href="{{ sakura.resources }}/css/yuuno.css" />
|
||||
<link rel="stylesheet" type="text/css" href="{{ resource('css/yuuno.css') }}" />
|
||||
{{ block('css') }}
|
||||
<!-- JS -->
|
||||
<script type="text/javascript" src="{{ config('content_path') }}/scripts/sakura.js"></script>
|
||||
<script type="text/javascript" src="{{ sakura.resources }}/js/yuuno.js"></script>
|
||||
<script type="text/javascript" src="{{ resource('js/yuuno.js') }}"></script>
|
||||
<script type="text/javascript">
|
||||
// Create an object so we can access certain settings from remote JavaScript files
|
||||
var sakuraVars = {
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Cannot find page</title>
|
||||
<link rel="stylesheet" type="text/css" href="{{ sakura.resources }}/css/error.css" />
|
||||
<link rel="stylesheet" type="text/css" href="{{ resource('css/error.css') }}" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="wrap">
|
||||
<h1>
|
||||
<img src="{{ sakura.resources }}/images/404-info.gif" />
|
||||
<img src="{{ resource('images/404-info.gif') }}" />
|
||||
The page cannot be found
|
||||
</h1>
|
||||
<p>
|
||||
|
@ -29,11 +29,11 @@
|
|||
home page, and then look for links to the information you want.
|
||||
</li>
|
||||
<li>
|
||||
Click the <img src="{{ sakura.resources }}/images/404-back.gif" /><a href="javascript:void(0);" onclick="history.go(-1);">Back</a>
|
||||
Click the <img src="{{ resource('images/404-back.gif') }}" /><a href="javascript:void(0);" onclick="history.go(-1);">Back</a>
|
||||
button to try another link.
|
||||
</li>
|
||||
<li>
|
||||
Click <img src="{{ sakura.resources }}/images/404-search.gif" /><a href="{{ route('main.search') }}">Search</a>
|
||||
Click <img src="{{ resource('images/404-search.gif') }}" /><a href="{{ route('main.search') }}">Search</a>
|
||||
to look for information on the Internet.
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
@ -16,5 +16,5 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
<script type="text/javascript" src="{{ sakura.resources }}/js/ybabstat.js"></script>
|
||||
<script type="text/javascript" src="{{ resource('js/ybabstat.js') }}"></script>
|
||||
{% endblock %}
|
||||
|
|
Reference in a new issue