r20151031

This commit is contained in:
flash 2015-10-31 19:14:54 +01:00
parent f7433beba6
commit 2c120186f7
7 changed files with 243 additions and 66 deletions

View file

@ -0,0 +1,14 @@
<?php
/*
* BBcode parser
*/
namespace Sakura;
/**
* Class BBcode
* @package Sakura
*/
class BBcode
{
}

View file

@ -1,14 +1,145 @@
<?php
/*
* Template engine wrapper (new)
* Template engine wrapper
*/
namespace Sakura;
use Twig_Environment;
use Twig_Extension_StringLoader;
use Twig_Loader_Filesystem;
/**
* Class Template
* @package Sakura
*/
class Template
{
// Engine container, template folder name, options and template variables
private $vars = [];
private $template;
private $templateName;
private $templateOptions;
private $fallback;
private $fallbackName;
private $fallbackOptions;
// Initialise templating engine and data
function __construct()
{
// Set template to default
$this->setTemplate(Configuration::getConfig('site_style'));
// Set a fallback
$this->setFallback(Configuration::getConfig('site_style'));
}
// Set a template name
public function setTemplate($name) {
// Assign config path to a variable so we don't have to type it out twice
$confPath = ROOT . '_sakura/templates/' . $name . '/template.ini';
// Check if the configuration file exists
if (!file_exists($confPath)) {
trigger_error('Template configuration does not exist', E_USER_ERROR);
}
// Parse and store the configuration
$this->templateOptions = parse_ini_file($confPath, true);
// Make sure we're not using a manage template for the main site or the other way around
if (defined('SAKURA_MANAGE') && (bool) $this->templateOptions['manage']['mode'] != (bool) SAKURA_MANAGE) {
trigger_error('Incorrect template type', E_USER_ERROR);
}
// Set variables
$this->templateName = $name;
// Reinitialise
$this->initTemplate();
}
// Initialise main template engine
public function initTemplate() {
// Initialise Twig Filesystem Loader
$twigLoader = new Twig_Loader_Filesystem(ROOT . '_sakura/templates/' . $this->templateName);
// Environment variable
$twigEnv = [];
// Enable caching
if (Configuration::getConfig('enable_tpl_cache')) {
$twigEnv['cache'] = ROOT . 'cache';
}
// And now actually initialise the templating engine
$this->template = new Twig_Environment($twigLoader, $twigEnv);
// Load String template loader
$this->template->addExtension(new Twig_Extension_StringLoader());
}
// Set a fallback
private function setFallback($name) {
// Assign config path to a variable so we don't have to type it out twice
$confPath = ROOT . '_sakura/templates/' . $name . '/template.ini';
// Check if the configuration file exists
if (!file_exists($confPath)) {
trigger_error('Template configuration does not exist', E_USER_ERROR);
}
// Parse and store the configuration
$this->fallbackOptions = parse_ini_file($confPath, true);
// Make sure we're not using a manage template for the main site or the other way around
if (defined('SAKURA_MANAGE') && (bool) $this->fallbackOptions['manage']['mode'] != (bool) SAKURA_MANAGE) {
trigger_error('Incorrect template type', E_USER_ERROR);
}
// Set variables
$this->fallbackName = $name;
// Reinitialise
$this->initFallback();
}
// Initialise main fallback engine
public function initFallback() {
// Initialise Twig Filesystem Loader
$twigLoader = new Twig_Loader_Filesystem(ROOT . '_sakura/templates/' . $this->fallbackName);
// Environment variable
$twigEnv = [];
// Enable caching
if (Configuration::getConfig('enable_tpl_cache')) {
$twigEnv['cache'] = ROOT . 'cache';
}
// And now actually initialise the templating engine
$this->fallback = new Twig_Environment($twigLoader, $twigEnv);
// Load String template loader
$this->fallback->addExtension(new Twig_Extension_StringLoader());
}
// Set variables
public function setVariables($vars) {
$this->vars = array_merge($this->vars, $vars);
}
// Render a template
public function render($file)
{
try {
return $this->template->render($file, $this->vars);
} catch (\Exception $e) {
try {
return $this->fallback->render($file, $this->vars);
} catch (\Exception $e) {
trigger_error($e->getMessage(), E_USER_ERROR);
}
}
}
}

View file

@ -8,7 +8,7 @@
namespace Sakura;
// Define Sakura version
define('SAKURA_VERSION', '20151024');
define('SAKURA_VERSION', '20151031');
define('SAKURA_VLABEL', 'Eminence');
define('SAKURA_COLOUR', '#6C3082');
define('SAKURA_STABLE', false);
@ -34,6 +34,7 @@ require_once ROOT . '_sakura/components/Hashing.php';
require_once ROOT . '_sakura/components/Configuration.php';
require_once ROOT . '_sakura/components/Database.php';
require_once ROOT . '_sakura/components/Urls.php';
require_once ROOT . '_sakura/components/Template.php';
require_once ROOT . '_sakura/components/Templates.php';
require_once ROOT . '_sakura/components/Permissions.php';
require_once ROOT . '_sakura/components/Session.php';

View file

@ -14,44 +14,34 @@
background-image: linear-gradient(0deg, transparent 0%, transparent 12%, rgba(0, 0, 0, .7) 30%,
transparent 76%, transparent 100%), url('{{ urls.format('IMAGE_HEADER', [profile.data.user_id]) }}');
}
#profileHeader.floating {
background-image: linear-gradient(90deg, transparent 0%, transparent 40%, #3A2E44 45%), url('{{ urls.format('IMAGE_HEADER', [profile.data.user_id]) }}');
background-size: auto 130px;
background-repeat: no-repeat;
background-position: left top;
}
</style>
{% endblock %}
{# block js %}
{% block js %}
<script type="text/javascript">
// Header
window.addEventListener("scroll", function(e) {
if(e.pageY > 244) {
if(e.pageY > 250) {
var profileHeader = document.getElementById('profileHeader');
var profileContent = document.getElementById('profileContent');
var userAvatar = document.getElementById('userAvatar');
profileHeader.style.position = 'fixed';
profileHeader.style.paddingTop = '30px';
profileHeader.style.top = '0';
profileHeader.style.maxWidth = '1018px';
profileHeader.style.height = '100px';
profileContent.style.marginTop = '264px';
userAvatar.style.height = '80px';
userAvatar.style.width = '80px';
userAvatar.style.margin = '10px';
userAvatar.style.transition = '.2s';
profileHeader.className = 'profileHeaderContent floating';
profileContent.className = 'profileContainer headerFloating';
} else {
var profileHeader = document.getElementById('profileHeader');
var profileContent = document.getElementById('profileContent');
var userAvatar = document.getElementById('userAvatar');
profileHeader.style.position = null;
profileHeader.style.paddingTop = null;
profileHeader.style.top = null;
profileHeader.style.maxWidth = null;
profileHeader.style.height = null;
profileContent.style.marginTop = null;
userAvatar.style.height = null;
userAvatar.style.width = null;
userAvatar.style.margin = null;
profileHeader.className = 'profileHeaderContent';
profileContent.className = 'profileContainer';
}
});
</script>
{% endblock #}
{% endblock %}
{% block content %}
<div class="profile" id="u{{ profile.data.user_id }}">

View file

@ -265,7 +265,7 @@ a:active {
padding-bottom: 100px;
}
#wrapper > #content {
#content {
position: relative;
max-width: 1018px;
margin: 0 auto;
@ -276,16 +276,20 @@ a:active {
border: 1px solid rgba(148, 117, 178, .6);
}
#content.floatingNavigation {
padding-top: 37px;
}
/*
* Header navigation
*/
#content > #navigation {
#navigation {
width: 100%;
height: 30px;
height: 25px;
background: linear-gradient(0deg, transparent, #453851 50%, #342740) transparent;
font-family: "Exo2-0-LightItalic", sans-serif;
font-size: 2em;
line-height: 30px;
font-size: 1.5em;
line-height: 25px;
letter-spacing: 0;
text-shadow: 1px 1px 3px #111;
margin-bottom: 5px;
@ -294,14 +298,19 @@ a:active {
max-width: 1018px;
}
#content > #navigation > ul > li {
#content.floatingNavigation #navigation {
position: fixed;
top: 0;
}
#navigation > ul > li {
list-style: none;
float: left;
}
#content > #navigation > ul > li > a:not(.ignore) {
height: 30px;
line-height: 30px;
#navigation > ul > li > a:not(.ignore) {
height: 25px;
line-height: 25px;
display: inline-block;
text-align: center;
color: inherit;
@ -310,56 +319,57 @@ a:active {
transition: .2s;
}
#content > #navigation > ul > li > a {
#navigation > ul > li > a {
z-index: 901;
position: relative;
}
#content > #navigation > .nav-left > li > a:not(.ignore):hover {
#navigation > .nav-left > li > a:not(.ignore):hover {
background: rgba(0, 0, 0, .2);
}
#content > #navigation > .nav-left > li > a:not(.ignore):active {
#navigation > .nav-left > li > a:not(.ignore):active {
background: rgba(0, 0, 0, .3);
}
#content > #navigation .nav-usermenu > a {
#navigation .nav-usermenu > a {
display: block !important;
text-align: right !important;
}
#content > #navigation .nav-usermenu > a:after {
#navigation .nav-usermenu > a:after {
font-family: FontAwesome;
content: " \f0d7";
}
#content > #navigation .nav-usermenu:hover > a:after {
#navigation .nav-usermenu:hover > a:after {
font-family: FontAwesome;
content: " \f0d8";
}
#content > #navigation .nav-avatar {
height: 30px;
width: 30px;
#navigation .nav-avatar {
height: 25px;
width: 25px;
background: url('/pixel.png') no-repeat scroll left center / cover transparent;
}
#content > #navigation > ul > li > ul {
#navigation > ul > li > ul {
display: none;
}
#content > #navigation > ul > li:hover > ul {
#navigation > ul > li:hover > ul {
display: block;
z-index: 900;
background: rgba(69, 56, 81, .5);
background: rgba(69, 56, 81, .8);
position: absolute;
top: 0;
right: 0;
list-style: none;
padding: 35px 4px 5px;
padding: 30px 4px 5px;
box-shadow: 0 2px 6px rgba(0, 0, 0, .75);
}
#content > #navigation > ul > li > ul > li > a {
#navigation > ul > li > ul > li > a {
color: inherit;
text-decoration: none;
display: block;
@ -367,15 +377,15 @@ a:active {
padding: 2px 7px;
}
#content > #navigation > ul > li > ul > li > a:hover {
background: rgba(0, 0, 0, .1);
}
#content > #navigation > ul > li > ul > li > a:active {
#navigation > ul > li > ul > li > a:hover {
background: rgba(0, 0, 0, .2);
}
#content > #navigation .nav-usermenu ul {
#navigation > ul > li > ul > li > a:active {
background: rgba(0, 0, 0, .3);
}
#navigation .nav-usermenu ul {
right: -30px;
text-align: right;
min-width: 150px;
@ -404,8 +414,8 @@ a:active {
align-content: stretch;
width: 100%;
position: relative;
top: -35px;
margin-bottom: -35px;
top: -31px;
margin-bottom: -31px;
}
.profile .profileContainer {
@ -436,6 +446,15 @@ a:active {
align-items: flex-end;
}
#profileHeader.floating {
position: fixed;
top: 0;
padding-top: 30px;
max-width: 1018px;
height: 95px;
box-shadow: 0 2px 6px rgba(0, 0, 0, .75);
}
#userAvatar {
font-size: 0;
background: transparent no-repeat scroll left center / cover;
@ -446,6 +465,13 @@ a:active {
margin: 10px;
margin-bottom: -10px;
flex-shrink: 0;
transition: .2s;
}
#profileHeader.floating #userAvatar {
height: 100px;
width: 100px;
margin: 5px 5px -5px;
}
#profileHeader > .userData {
@ -456,6 +482,14 @@ a:active {
width: 100%;
}
#profileHeader.floating > .userData {
position: initial;
top: 0;
height: 100%;
font-size: .8em;
line-height: 1.5em;
}
#profileHeader > .userData > .headerLeft {
flex-grow: 1;
}
@ -478,6 +512,10 @@ a:active {
margin: 10px 10px 0 0;
}
#profileContent.headerFloating {
margin-top: 264px;
}
#profileContent > .userDataBar {
width: 210px;
margin-top: 10px;

View file

@ -84,15 +84,9 @@ function convertParallaxPositionValue(pos, dir, neg) {
window.addEventListener("scroll", function(e) {
if(e.pageY > 123) {
var content = document.getElementById('content');
var navigation = document.getElementById('navigation');
navigation.style.position = 'fixed';
navigation.style.top = '0';
content.style.paddingTop = '37px';
content.className = 'floatingNavigation';
} else {
var content = document.getElementById('content');
var navigation = document.getElementById('navigation');
navigation.style.position = null;
navigation.style.top = null;
content.style.paddingTop = null;
content.className = null;
}
});

View file

@ -74,5 +74,14 @@ $renderData['stats'] = [
'onlineUsers' => Users::checkAllOnline(),
];
// Initialise templating engine
$template = new Template();
// Change templating engine
$template->setTemplate($templateName);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
print Templates::render(($forumMode ? 'forum' : 'main') . '/index.tpl', $renderData);
echo $template->render(($forumMode ? 'forum' : 'main') . '/index.tpl');