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\Config;
|
||||||
use Sakura\File;
|
use Sakura\File;
|
||||||
use Sakura\Perms\Site;
|
use Sakura\Perms\Site;
|
||||||
|
use Sakura\Template;
|
||||||
use Sakura\User;
|
use Sakura\User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,11 +45,9 @@ class FileController extends Controller
|
||||||
*/
|
*/
|
||||||
public function avatar($id = 0)
|
public function avatar($id = 0)
|
||||||
{
|
{
|
||||||
global $templateName;
|
|
||||||
|
|
||||||
$noAvatar = ROOT . str_replace(
|
$noAvatar = ROOT . str_replace(
|
||||||
'{{ TPL }}',
|
'{{ TPL }}',
|
||||||
$templateName,
|
Template::$name,
|
||||||
Config::get('no_avatar_img')
|
Config::get('no_avatar_img')
|
||||||
);
|
);
|
||||||
$none = [
|
$none = [
|
||||||
|
@ -59,7 +58,7 @@ class FileController extends Controller
|
||||||
|
|
||||||
$deactivePath = ROOT . str_replace(
|
$deactivePath = ROOT . str_replace(
|
||||||
'{{ TPL }}',
|
'{{ TPL }}',
|
||||||
$templateName,
|
Template::$name,
|
||||||
Config::get('deactivated_avatar_img')
|
Config::get('deactivated_avatar_img')
|
||||||
);
|
);
|
||||||
$deactive = [
|
$deactive = [
|
||||||
|
@ -70,7 +69,7 @@ class FileController extends Controller
|
||||||
|
|
||||||
$bannedPath = ROOT . str_replace(
|
$bannedPath = ROOT . str_replace(
|
||||||
'{{ TPL }}',
|
'{{ TPL }}',
|
||||||
$templateName,
|
Template::$name,
|
||||||
Config::get('banned_avatar_img')
|
Config::get('banned_avatar_img')
|
||||||
);
|
);
|
||||||
$banned = [
|
$banned = [
|
||||||
|
@ -109,8 +108,6 @@ class FileController extends Controller
|
||||||
*/
|
*/
|
||||||
public function background($id = 0)
|
public function background($id = 0)
|
||||||
{
|
{
|
||||||
global $templateName;
|
|
||||||
|
|
||||||
$noBg = ROOT . Config::get('no_background_img');
|
$noBg = ROOT . Config::get('no_background_img');
|
||||||
$none = [
|
$none = [
|
||||||
'name' => basename($noBg),
|
'name' => basename($noBg),
|
||||||
|
@ -146,8 +143,6 @@ class FileController extends Controller
|
||||||
*/
|
*/
|
||||||
public function header($id = 0)
|
public function header($id = 0)
|
||||||
{
|
{
|
||||||
global $templateName;
|
|
||||||
|
|
||||||
$noHeader = ROOT . Config::get('no_header_img');
|
$noHeader = ROOT . Config::get('no_header_img');
|
||||||
$none = [
|
$none = [
|
||||||
'name' => basename($noHeader),
|
'name' => basename($noHeader),
|
||||||
|
|
|
@ -33,14 +33,21 @@ class Template
|
||||||
*
|
*
|
||||||
* @var Twig_Environment
|
* @var Twig_Environment
|
||||||
*/
|
*/
|
||||||
private static $template;
|
private static $engine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The template name.
|
* The template name.
|
||||||
*
|
*
|
||||||
* @var string
|
* @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
|
* The file extension used by template files
|
||||||
|
@ -55,7 +62,10 @@ class Template
|
||||||
public static function set($name)
|
public static function set($name)
|
||||||
{
|
{
|
||||||
// Set variables
|
// Set variables
|
||||||
self::$templateName = $name;
|
self::$name = $name;
|
||||||
|
|
||||||
|
// Set reources path
|
||||||
|
self::$resources = Config::get('content_path') . '/data/' . self::$name;
|
||||||
|
|
||||||
// Reinitialise
|
// Reinitialise
|
||||||
self::init();
|
self::init();
|
||||||
|
@ -67,7 +77,7 @@ class Template
|
||||||
public static function init()
|
public static function init()
|
||||||
{
|
{
|
||||||
// Initialise Twig Filesystem Loader
|
// Initialise Twig Filesystem Loader
|
||||||
$twigLoader = new Twig_Loader_Filesystem(ROOT . 'templates/' . self::$templateName);
|
$twigLoader = new Twig_Loader_Filesystem(ROOT . 'templates/' . self::$name);
|
||||||
|
|
||||||
// Environment variable
|
// Environment variable
|
||||||
$twigEnv = [];
|
$twigEnv = [];
|
||||||
|
@ -78,26 +88,31 @@ class Template
|
||||||
}
|
}
|
||||||
|
|
||||||
// And now actually initialise the templating engine
|
// 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
|
// Load String template loader
|
||||||
self::$template->addExtension(new Twig_Extension_StringLoader());
|
self::$engine->addExtension(new Twig_Extension_StringLoader());
|
||||||
|
|
||||||
// Add route function
|
// 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);
|
return Router::route($name, $args);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Add config function
|
// 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);
|
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
|
// 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?)
|
// 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)
|
public static function render($file)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return self::$template->render($file . self::FILE_EXT, self::$vars);
|
return self::$engine->render($file . self::FILE_EXT, self::$vars);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return trigger_error($e->getMessage(), E_USER_ERROR);
|
return trigger_error($e->getMessage(), E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,11 +35,11 @@
|
||||||
<link rel="manifest" href="/manifest.json" />
|
<link rel="manifest" href="/manifest.json" />
|
||||||
{{ block('meta') }}
|
{{ block('meta') }}
|
||||||
<!-- CSS -->
|
<!-- 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') }}
|
{{ block('css') }}
|
||||||
<!-- JS -->
|
<!-- JS -->
|
||||||
<script type="text/javascript" src="{{ config('content_path') }}/scripts/sakura.js"></script>
|
<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">
|
<script type="text/javascript">
|
||||||
// Create an object so we can access certain settings from remote JavaScript files
|
// Create an object so we can access certain settings from remote JavaScript files
|
||||||
var sakuraVars = {
|
var sakuraVars = {
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>Cannot find page</title>
|
<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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="wrap">
|
<div id="wrap">
|
||||||
<h1>
|
<h1>
|
||||||
<img src="{{ sakura.resources }}/images/404-info.gif" />
|
<img src="{{ resource('images/404-info.gif') }}" />
|
||||||
The page cannot be found
|
The page cannot be found
|
||||||
</h1>
|
</h1>
|
||||||
<p>
|
<p>
|
||||||
|
@ -29,11 +29,11 @@
|
||||||
home page, and then look for links to the information you want.
|
home page, and then look for links to the information you want.
|
||||||
</li>
|
</li>
|
||||||
<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.
|
button to try another link.
|
||||||
</li>
|
</li>
|
||||||
<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.
|
to look for information on the Internet.
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -16,5 +16,5 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block js %}
|
{% block js %}
|
||||||
<script type="text/javascript" src="{{ sakura.resources }}/js/ybabstat.js"></script>
|
<script type="text/javascript" src="{{ resource('js/ybabstat.js') }}"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Reference in a new issue