r20151106

Signed-off-by: Flashwave <me@flash.moe>
This commit is contained in:
flash 2015-11-06 23:30:37 +01:00
parent 2f79bba118
commit fcc1dcdf1f
31 changed files with 460 additions and 410 deletions

View file

@ -117,12 +117,12 @@ class Comments
{
// Check if the comment is long enough
if (strlen($content) < Configuration::getConfig('comment_min_length')) {
if (strlen($content) < Config::getConfig('comment_min_length')) {
return [0, 'TOO_SHORT'];
}
// Check if the comment isn't too long
if (strlen($content) > Configuration::getConfig('comment_max_length')) {
if (strlen($content) > Config::getConfig('comment_max_length')) {
return [0, 'TOO_LONG'];
}

View file

@ -6,10 +6,10 @@
namespace Sakura;
/**
* Class Configuration
* Class Config
* @package Sakura
*/
class Configuration
class Config
{
// Configuration data
private static $local = [];

View file

@ -1,14 +1,14 @@
<?php
/*
* File uploads handler
* File handler
*/
namespace Sakura;
/**
* Class Upload
* Class File
* @package Sakura
*/
class Upload
class File
{
}

View file

@ -6,7 +6,7 @@
namespace Sakura;
/**
* Class Forum
* Class Forums
* @package Sakura
*/
class Forums

View file

@ -19,13 +19,13 @@ class Main
{
// Configuration Management and local configuration
Configuration::init($config);
Config::init($config);
// Database
Database::init(Configuration::getLocalConfig('database', 'driver'));
Database::init(Config::getLocalConfig('database', 'driver'));
// "Dynamic" Configuration
Configuration::initDB();
Config::initDB();
}
// Parse markdown
@ -101,7 +101,7 @@ class Main
// Attempt to get the response
$resp = @file_get_contents(
'https://www.google.com/recaptcha/api/siteverify?secret='
. Configuration::getConfig('recaptcha_private')
. Config::getConfig('recaptcha_private')
. '&response='
. $response
);
@ -277,28 +277,28 @@ class Main
$mail->isSMTP();
// Set the SMTP server host
$mail->Host = Configuration::getConfig('smtp_server');
$mail->Host = Config::getConfig('smtp_server');
// Do we require authentication?
$mail->SMTPAuth = Configuration::getConfig('smtp_auth');
$mail->SMTPAuth = Config::getConfig('smtp_auth');
// Do we encrypt as well?
$mail->SMTPSecure = Configuration::getConfig('smtp_secure');
$mail->SMTPSecure = Config::getConfig('smtp_secure');
// Set the port to the SMTP server
$mail->Port = Configuration::getConfig('smtp_port');
$mail->Port = Config::getConfig('smtp_port');
// If authentication is required log in as well
if (Configuration::getConfig('smtp_auth')) {
$mail->Username = Configuration::getConfig('smtp_username');
$mail->Password = base64_decode(Configuration::getConfig('smtp_password'));
if (Config::getConfig('smtp_auth')) {
$mail->Username = Config::getConfig('smtp_username');
$mail->Password = base64_decode(Config::getConfig('smtp_password'));
}
// Add a reply-to header
$mail->addReplyTo(Configuration::getConfig('smtp_replyto_mail'), Configuration::getConfig('smtp_replyto_name'));
$mail->addReplyTo(Config::getConfig('smtp_replyto_mail'), Config::getConfig('smtp_replyto_name'));
// Set a from address as well
$mail->setFrom(Configuration::getConfig('smtp_from_email'), Configuration::getConfig('smtp_from_name'));
$mail->setFrom(Config::getConfig('smtp_from_email'), Config::getConfig('smtp_from_name'));
// Set the addressee
foreach ($to as $email => $name) {
@ -315,8 +315,8 @@ class Main
$htmlMail = file_get_contents(ROOT . '_sakura/templates/htmlEmail.tpl');
// Replace template tags
$htmlMail = str_replace('{{ sitename }}', Configuration::getConfig('sitename'), $htmlMail);
$htmlMail = str_replace('{{ siteurl }}', '//' . Configuration::getConfig('url_main'), $htmlMail);
$htmlMail = str_replace('{{ sitename }}', Config::getConfig('sitename'), $htmlMail);
$htmlMail = str_replace('{{ siteurl }}', '//' . Config::getConfig('url_main'), $htmlMail);
$htmlMail = str_replace('{{ contents }}', self::mdParse($body), $htmlMail);
// Set HTML body
@ -345,7 +345,7 @@ class Main
{
// Run common sanitisation function over string
$string = htmlentities($string, ENT_NOQUOTES | ENT_HTML401, Configuration::getConfig('charset'));
$string = htmlentities($string, ENT_NOQUOTES | ENT_HTML401, Config::getConfig('charset'));
$string = stripslashes($string);
$string = strip_tags($string);
@ -482,7 +482,7 @@ class Main
// Get CloudFlare Subnet list
$cfhosts = file_get_contents(
ROOT . '_sakura/' . Configuration::getLocalConfig('data', 'cfipv' . (self::ipVersion($ip)))
ROOT . '_sakura/' . Config::getLocalConfig('data', 'cfipv' . (self::ipVersion($ip)))
);
// Replace \r\n with \n
@ -617,7 +617,7 @@ class Main
$iso3166 = json_decode(
utf8_encode(
file_get_contents(
ROOT . '_sakura/' . Configuration::getLocalConfig('data', 'iso3166')
ROOT . '_sakura/' . Config::getLocalConfig('data', 'iso3166')
)
),
true

View file

@ -32,8 +32,8 @@ class Payments
try {
self::$paypal = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
Configuration::getConfig('paypal_client_id'),
Configuration::getConfig('paypal_secret')
Config::getConfig('paypal_client_id'),
Config::getConfig('paypal_secret')
)
);
} catch (\Exception $e) {

View file

@ -93,7 +93,7 @@ class Session
}
// IP Check
$ipCheck = Configuration::getConfig('session_check');
$ipCheck = Config::getConfig('session_check');
// Origin checking
if ($ipCheck) {

View file

@ -25,7 +25,7 @@ class Template
public function __construct()
{
// Set template to default
$this->setTemplate(Configuration::getConfig('site_style'));
$this->setTemplate(Config::getConfig('site_style'));
}
// Set a template name
@ -42,11 +42,6 @@ class Template
// 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;
@ -64,7 +59,7 @@ class Template
$twigEnv = [];
// Enable caching
if (Configuration::getConfig('enable_tpl_cache')) {
if (Config::getConfig('enable_tpl_cache')) {
$twigEnv['cache'] = ROOT . 'cache';
}

View file

@ -1,81 +0,0 @@
<?php
/*
* Template Engine Wrapper
*/
namespace Sakura;
use Twig_Environment;
use Twig_Extension_StringLoader;
use Twig_Loader_Filesystem;
/**
* Class Templates
* @package Sakura
*/
class Templates
{
// Engine container, template folder name and options
public static $engine;
public static $template;
public static $configuration;
// Initialise templating engine and data
public static function init($template)
{
// Set template folder name
self::$template = $template;
// Assign config path to a variable so we don't have to type it out twice
$confPath = ROOT . '_sakura/templates/' . self::$template . '/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
self::$configuration = 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) self::$configuration['manage']['mode'] != (bool) SAKURA_MANAGE) {
trigger_error('Incorrect template type', E_USER_ERROR);
}
// Start Twig
self::twigLoader();
}
// Twig Loader
private static function twigLoader()
{
// Initialise Twig Filesystem Loader
$twigLoader = new Twig_Loader_Filesystem(ROOT . '_sakura/templates/' . self::$template);
// Environment variable
$twigEnv = [];
// Enable caching
if (Configuration::getConfig('enable_tpl_cache')) {
$twigEnv['cache'] = ROOT . 'cache';
}
// And now actually initialise the templating engine
self::$engine = new Twig_Environment($twigLoader, $twigEnv);
// Load String template loader
self::$engine->addExtension(new Twig_Extension_StringLoader());
}
// Render template
public static function render($file, $tags)
{
try {
return self::$engine->render($file, $tags);
} catch (\Exception $e) {
trigger_error($e->getMessage(), E_USER_ERROR);
}
}
}

View file

@ -284,7 +284,7 @@ class Urls
}
// Check if mod_rewrite is enabled
$rewrite = ($rewrite === null ? Configuration::getConfig('url_rewrite') : $rewrite) ? 1 : 0;
$rewrite = ($rewrite === null ? Config::getConfig('url_rewrite') : $rewrite) ? 1 : 0;
// Format urls
$formatted = vsprintf($this->urls[$lid][$rewrite], $args);

View file

@ -19,7 +19,6 @@ class User
// Initialise the user object
public function __construct($uid)
{
// Get the user database row
$this->data = Database::fetch(
'users',
@ -65,7 +64,6 @@ class User
// Check if the user has the specified ranks
public function checkIfUserHasRanks($ranks)
{
// Check if the main rank is the specified rank
if ($this->mainRank->id() === $ranks) {
return true;
@ -99,29 +97,26 @@ class User
public function country()
{
return [
'long' => Main::getCountryName($this->data['user_country']),
'short' => $this->data['user_country'],
];
}
// Check if a user is online
public function checkOnline()
{
return $this->data['user_last_online'] > (time() - Configuration::getConfig('max_online_time'));
return $this->data['user_last_online'] > (time() - Config::getConfig('max_online_time'));
}
// Get user's forum statistics
public function forumStats()
{
return Forum::getUserStats($this->data['user_id']);
return Forums::getUserStats($this->data['user_id']);
}
// Add a new friend
public function addFriend($uid)
{
// Create the foreign object
$user = new User($uid);
@ -152,7 +147,6 @@ class User
// Remove a friend
public function removeFriend($uid, $deleteRequest = false)
{
// Create the foreign object
$user = new User($uid);
@ -187,7 +181,6 @@ class User
// Check if the user is friends with the currently authenticated
public function checkFriends($with)
{
// Get the friend's friends
$friend = in_array($this->data['user_id'], (new User($with))->getFriends());
@ -236,18 +229,15 @@ class User
public function elapsed($append = ' ago', $none = 'Just now')
{
return [
'joined' => Main::timeElapsed($this->data['user_registered'], $append, $none),
'lastOnline' => Main::timeElapsed($this->data['user_last_online'], $append, $none),
'birth' => Main::timeElapsed(strtotime($this->data['user_birthday']), $append, $none),
];
}
// Get the user's profile fields
public function profileFields()
{
// Get profile fields
$profileFields = Database::fetch('profilefields');
@ -314,7 +304,6 @@ class User
// Get the user's option fields
public function optionFields()
{
// Get option fields
$optionFields = Database::fetch('optionfields');
@ -384,7 +373,6 @@ class User
// Get all warnings issued to the user
public function getWarnings()
{
// Do the database query
$getWarnings = Database::fetch('warnings', true, [
'user_id' => [$this->data['user_id'], '='],
@ -462,7 +450,6 @@ class User
// Get username change history
public function getUsernameHistory()
{
// Do the database query
$changes = Database::fetch('username_history', true, [
'user_id' => [$this->data['user_id'], '='],
@ -475,24 +462,23 @@ class User
// Set a new username
public function setUsername($username)
{
// Create a cleaned version
$username_clean = Main::cleanString($username, true);
// Check if the username is too short
if (strlen($username_clean) < Configuration::getConfig('username_min_length')) {
if (strlen($username_clean) < Config::getConfig('username_min_length')) {
return [0, 'TOO_SHORT'];
}
// Check if the username is too long
if (strlen($username_clean) > Configuration::getConfig('username_max_length')) {
if (strlen($username_clean) > Config::getConfig('username_max_length')) {
return [0, 'TOO_LONG'];
}
// Check if this username hasn't been used in the last amount of days set in the config
$getOld = Database::fetch('username_history', false, [
'username_old_clean' => [$username_clean, '='],
'change_time' => [(Configuration::getConfig('old_username_reserve') * 24 * 60 * 60), '>'],
'change_time' => [(Config::getConfig('old_username_reserve') * 24 * 60 * 60), '>'],
], ['change_id', true]);
// Check if anything was returned
@ -538,7 +524,6 @@ class User
// Set a new e-mail address
public function setEMailAddress($email)
{
// Validate e-mail address
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
return [0, 'INVALID'];
@ -591,7 +576,7 @@ class User
}
// Check password entropy
if (Main::pwdEntropy($new) < Configuration::getConfig('min_entropy')) {
if (Main::pwdEntropy($new) < Config::getConfig('min_entropy')) {
return [0, 'PASS_TOO_SHIT'];
}

View file

@ -53,11 +53,11 @@ class Users
{
// Assign $uid and $sid
$uid = $uid ? $uid : (isset($_COOKIE[Configuration::getConfig('cookie_prefix') . 'id'])
? $_COOKIE[Configuration::getConfig('cookie_prefix') . 'id']
$uid = $uid ? $uid : (isset($_COOKIE[Config::getConfig('cookie_prefix') . 'id'])
? $_COOKIE[Config::getConfig('cookie_prefix') . 'id']
: 0);
$sid = $sid ? $sid : (isset($_COOKIE[Configuration::getConfig('cookie_prefix') . 'session'])
? $_COOKIE[Configuration::getConfig('cookie_prefix') . 'session']
$sid = $sid ? $sid : (isset($_COOKIE[Config::getConfig('cookie_prefix') . 'session'])
? $_COOKIE[Config::getConfig('cookie_prefix') . 'session']
: 0);
// Get session
@ -70,20 +70,20 @@ class Users
if ($sessionValid == 0 || Permissions::check('SITE', 'DEACTIVATED', $uid, 1)) {
// Unset User ID
setcookie(
Configuration::getConfig('cookie_prefix') . 'id',
Config::getConfig('cookie_prefix') . 'id',
0,
time() - 60,
Configuration::getConfig('cookie_path'),
Configuration::getConfig('cookie_domain')
Config::getConfig('cookie_path'),
Config::getConfig('cookie_domain')
);
// Unset Session ID
setcookie(
Configuration::getConfig('cookie_prefix') . 'session',
Config::getConfig('cookie_prefix') . 'session',
'',
time() - 60,
Configuration::getConfig('cookie_path'),
Configuration::getConfig('cookie_domain')
Config::getConfig('cookie_path'),
Config::getConfig('cookie_domain')
);
return false;
@ -93,20 +93,20 @@ class Users
if ($sessionValid == 2) {
// User ID cookie
setcookie(
Configuration::getConfig('cookie_prefix') . 'id',
Config::getConfig('cookie_prefix') . 'id',
$uid,
time() + 604800,
Configuration::getConfig('cookie_path'),
Configuration::getConfig('cookie_domain')
Config::getConfig('cookie_path'),
Config::getConfig('cookie_domain')
);
// Session ID cookie
setcookie(
Configuration::getConfig('cookie_prefix') . 'session',
Config::getConfig('cookie_prefix') . 'session',
$sid,
time() + 604800,
Configuration::getConfig('cookie_path'),
Configuration::getConfig('cookie_domain')
Config::getConfig('cookie_path'),
Config::getConfig('cookie_domain')
);
}
@ -132,7 +132,7 @@ class Users
{
// Check if authentication is disallowed
if (Configuration::getConfig('lock_authentication')) {
if (Config::getConfig('lock_authentication')) {
return [0, 'AUTH_LOCKED'];
}
@ -189,20 +189,20 @@ class Users
if ($cookies) {
// User ID cookie
setcookie(
Configuration::getConfig('cookie_prefix') . 'id',
Config::getConfig('cookie_prefix') . 'id',
$user['user_id'],
time() + 604800,
Configuration::getConfig('cookie_path'),
Configuration::getConfig('cookie_domain')
Config::getConfig('cookie_path'),
Config::getConfig('cookie_domain')
);
// Session ID cookie
setcookie(
Configuration::getConfig('cookie_prefix') . 'session',
Config::getConfig('cookie_prefix') . 'session',
$sessionKey,
time() + 604800,
Configuration::getConfig('cookie_path'),
Configuration::getConfig('cookie_domain')
Config::getConfig('cookie_path'),
Config::getConfig('cookie_domain')
);
}
@ -224,20 +224,20 @@ class Users
// Unset User ID
setcookie(
Configuration::getConfig('cookie_prefix') . 'id',
Config::getConfig('cookie_prefix') . 'id',
0,
time() - 60,
Configuration::getConfig('cookie_path'),
Configuration::getConfig('cookie_domain')
Config::getConfig('cookie_path'),
Config::getConfig('cookie_domain')
);
// Unset Session ID
setcookie(
Configuration::getConfig('cookie_prefix') . 'session',
Config::getConfig('cookie_prefix') . 'session',
'',
time() - 60,
Configuration::getConfig('cookie_path'),
Configuration::getConfig('cookie_domain')
Config::getConfig('cookie_path'),
Config::getConfig('cookie_domain')
);
// Return true indicating a successful logout
@ -249,17 +249,17 @@ class Users
{
// Check if authentication is disallowed
if (Configuration::getConfig('lock_authentication')) {
if (Config::getConfig('lock_authentication')) {
return [0, 'AUTH_LOCKED'];
}
// Check if registration is even enabled
if (Configuration::getConfig('disable_registration')) {
if (Config::getConfig('disable_registration')) {
return [0, 'DISABLED'];
}
// Check if registration codes are required
if (Configuration::getConfig('require_registration_code')) {
if (Config::getConfig('require_registration_code')) {
// Check if the code is valid
if (!self::checkRegistrationCode($regkey)) {
return [0, 'INVALID_REG_KEY'];
@ -272,7 +272,7 @@ class Users
}
// Verify the captcha if it's enabled
if (Configuration::getConfig('recaptcha')) {
if (Config::getConfig('recaptcha')) {
if (!Main::verifyCaptcha($captcha)['success']) {
return [0, 'CAPTCHA_FAIL'];
}
@ -284,12 +284,12 @@ class Users
}
// Username too short
if (strlen($username) < Configuration::getConfig('username_min_length')) {
if (strlen($username) < Config::getConfig('username_min_length')) {
return [0, 'NAME_TOO_SHORT'];
}
// Username too long
if (strlen($username) > Configuration::getConfig('username_max_length')) {
if (strlen($username) > Config::getConfig('username_max_length')) {
return [0, 'NAME_TOO_LONG'];
}
@ -304,7 +304,7 @@ class Users
}
// Check password entropy
if (Main::pwdEntropy($password) < Configuration::getConfig('min_entropy')) {
if (Main::pwdEntropy($password) < Config::getConfig('min_entropy')) {
return [0, 'PASS_TOO_SHIT'];
}
@ -317,7 +317,7 @@ class Users
$usernameClean = Main::cleanString($username, true);
$emailClean = Main::cleanString($email, true);
$password = Hashing::createHash($password);
$requireActive = Configuration::getConfig('require_activation');
$requireActive = Config::getConfig('require_activation');
$userRank = $requireActive ? [1] : [2];
$userRankJson = json_encode($userRank);
@ -350,7 +350,7 @@ class Users
}
// Check if registration codes are required
if (Configuration::getConfig('require_registration_code')) {
if (Config::getConfig('require_registration_code')) {
// If we do mark the registration code that was used as used
self::markRegistrationCodeUsed($regkey, $uid);
}
@ -364,7 +364,7 @@ class Users
{
// Check if authentication is disallowed
if (Configuration::getConfig('lock_authentication')) {
if (Config::getConfig('lock_authentication')) {
return [0, 'AUTH_LOCKED'];
}
@ -400,17 +400,17 @@ class Users
// Build the e-mail
$message = "Hello " . $user['username'] . ",\r\n\r\n";
$message .= "You are receiving this notification because you have (or someone pretending to be you has) requested a password reset link to be sent for your account on \"" . Configuration::getConfig('sitename') . "\". If you did not request this notification then please ignore it, if you keep receiving it please contact the site administrator.\r\n\r\n";
$message .= "You are receiving this notification because you have (or someone pretending to be you has) requested a password reset link to be sent for your account on \"" . Config::getConfig('sitename') . "\". If you did not request this notification then please ignore it, if you keep receiving it please contact the site administrator.\r\n\r\n";
$message .= "To use this password reset key you need to go to a special page. To do this click the link provided below.\r\n\r\n";
$message .= "http://" . Configuration::getConfig('url_main') . $urls->format('SITE_FORGOT_PASSWORD') . "?pw=true&uid=" . $user['user_id'] . "&key=" . $verk . "\r\n\r\n";
$message .= "http://" . Config::getConfig('url_main') . $urls->format('SITE_FORGOT_PASSWORD') . "?pw=true&uid=" . $user['user_id'] . "&key=" . $verk . "\r\n\r\n";
$message .= "If successful you should be able to change your password here.\r\n\r\n";
$message .= "Alternatively if the above method fails for some reason you can go to http://" . Configuration::getConfig('url_main') . $urls->format('SITE_FORGOT_PASSWORD') . "?pw=true&uid=" . $user['user_id'] . " and use the key listed below:\r\n\r\n";
$message .= "Alternatively if the above method fails for some reason you can go to http://" . Config::getConfig('url_main') . $urls->format('SITE_FORGOT_PASSWORD') . "?pw=true&uid=" . $user['user_id'] . " and use the key listed below:\r\n\r\n";
$message .= "Verification key: " . $verk . "\r\n\r\n";
$message .= "You can of course change this password yourself via the profile page. If you have any difficulties please contact the site administrator.\r\n\r\n";
$message .= "--\r\n\r\nThanks\r\n\r\n" . Configuration::getConfig('mail_signature');
$message .= "--\r\n\r\nThanks\r\n\r\n" . Config::getConfig('mail_signature');
// Send the message
Main::sendMail([$user['email'] => $user['username']], Configuration::getConfig('sitename') . ' password restoration', $message);
Main::sendMail([$user['email'] => $user['username']], Config::getConfig('sitename') . ' password restoration', $message);
// Return success
return [1, 'SUCCESS'];
@ -421,12 +421,12 @@ class Users
{
// Check if authentication is disallowed
if (Configuration::getConfig('lock_authentication')) {
if (Config::getConfig('lock_authentication')) {
return [0, 'AUTH_LOCKED'];
}
// Check password entropy
if (Main::pwdEntropy($newpass) < Configuration::getConfig('min_entropy')) {
if (Main::pwdEntropy($newpass) < Config::getConfig('min_entropy')) {
return [0, 'PASS_TOO_SHIT'];
}
@ -470,7 +470,7 @@ class Users
{
// Check if authentication is disallowed
if (Configuration::getConfig('lock_authentication')) {
if (Config::getConfig('lock_authentication')) {
return [0, 'AUTH_LOCKED'];
}
@ -525,25 +525,25 @@ class Users
$urls = new Urls();
// Build the e-mail
$message = "Welcome to " . Configuration::getConfig('sitename') . "!\r\n\r\n";
$message = "Welcome to " . Config::getConfig('sitename') . "!\r\n\r\n";
$message .= "Please keep this e-mail for your records. Your account intormation is as follows:\r\n\r\n";
$message .= "----------------------------\r\n\r\n";
$message .= "Username: " . $user['username'] . "\r\n\r\n";
$message .= "Your profile: http://" . Configuration::getConfig('url_main') . $urls->format('USER_PROFILE', [$user['user_id']]) . "\r\n\r\n";
$message .= "Your profile: http://" . Config::getConfig('url_main') . $urls->format('USER_PROFILE', [$user['user_id']]) . "\r\n\r\n";
$message .= "----------------------------\r\n\r\n";
$message .= "Please visit the following link in order to activate your account:\r\n\r\n";
$message .= "http://" . Configuration::getConfig('url_main') . $urls->format('SITE_ACTIVATE') . "?mode=activate&u=" . $user['user_id'] . "&k=" . $activate . "\r\n\r\n";
$message .= "http://" . Config::getConfig('url_main') . $urls->format('SITE_ACTIVATE') . "?mode=activate&u=" . $user['user_id'] . "&k=" . $activate . "\r\n\r\n";
$message .= "Your password has been securely stored in our database and cannot be retrieved. ";
$message .= "In the event that it is forgotten, you will be able to reset it using the email address associated with your account.\r\n\r\n";
$message .= "Thank you for registering.\r\n\r\n";
$message .= "--\r\n\r\nThanks\r\n\r\n" . Configuration::getConfig('mail_signature');
$message .= "--\r\n\r\nThanks\r\n\r\n" . Config::getConfig('mail_signature');
// Send the message
Main::sendMail(
[
$user['email'] => $user['username'],
],
Configuration::getConfig('sitename') . ' Activation Mail',
Config::getConfig('sitename') . ' Activation Mail',
$message
);
@ -685,7 +685,7 @@ class Users
'regcodes',
true,
['uid' => [$userId, '=']]
)[0] >= Configuration::getConfig('max_reg_keys')) {
)[0] >= Config::getConfig('max_reg_keys')) {
return false;
}
@ -1078,7 +1078,7 @@ class Users
{
// Get the ID for the premium user rank from the database
$premiumRank = Configuration::getConfig('premium_rank_id');
$premiumRank = Config::getConfig('premium_rank_id');
// Run the check
$check = self::checkUserPremium($id);

View file

@ -7,7 +7,7 @@ namespace Sakura\DBWrapper;
use PDO;
use PDOException;
use \Sakura\Configuration;
use \Sakura\Config;
/**
* Class MySQL
@ -31,23 +31,23 @@ class mysql
// Initialise connection
$this->initConnect(
(
Configuration::getLocalConfig('database', 'unixsocket') ?
Config::getLocalConfig('database', 'unixsocket') ?
$this->prepareSock(
Configuration::getLocalConfig('database', 'host'),
Configuration::getLocalConfig('database', 'database')
Config::getLocalConfig('database', 'host'),
Config::getLocalConfig('database', 'database')
) :
$this->prepareHost(
Configuration::getLocalConfig('database', 'host'),
Configuration::getLocalConfig('database', 'database'),
Config::getLocalConfig('database', 'host'),
Config::getLocalConfig('database', 'database'),
(
Configuration::getLocalConfig('database', 'port') !== null ?
Configuration::getLocalConfig('database', 'port') :
Config::getLocalConfig('database', 'port') !== null ?
Config::getLocalConfig('database', 'port') :
3306
)
)
),
Configuration::getLocalConfig('database', 'username'),
Configuration::getLocalConfig('database', 'password')
Config::getLocalConfig('database', 'username'),
Config::getLocalConfig('database', 'password')
);
}
@ -88,7 +88,7 @@ class mysql
{
// Begin preparation of the statement
$prepare = 'SELECT ' . ($distinct ? 'DISTINCT ' : '') . ($column == '*' ? '' : '`') . $column . ($column == '*' ? '' : '`') . ' FROM `' . ($prefix ? $prefix : Configuration::getLocalConfig('database', 'prefix')) . $table . '`';
$prepare = 'SELECT ' . ($distinct ? 'DISTINCT ' : '') . ($column == '*' ? '' : '`') . $column . ($column == '*' ? '' : '`') . ' FROM `' . ($prefix ? $prefix : Config::getLocalConfig('database', 'prefix')) . $table . '`';
// If $data is set and is an array continue
if (is_array($data)) {
@ -200,7 +200,7 @@ class mysql
{
// Begin preparation of the statement
$prepare = 'INSERT INTO `' . ($prefix ? $prefix : Configuration::getLocalConfig('database', 'prefix')) . $table . '` ';
$prepare = 'INSERT INTO `' . ($prefix ? $prefix : Config::getLocalConfig('database', 'prefix')) . $table . '` ';
// Run the foreach statement twice for (`stuff`) VALUES (:stuff)
for ($i = 0; $i < 2; $i++) {
@ -241,7 +241,7 @@ class mysql
{
// Begin preparation of the statement
$prepare = 'UPDATE `' . ($prefix ? $prefix : Configuration::getLocalConfig('database', 'prefix')) . $table . '`';
$prepare = 'UPDATE `' . ($prefix ? $prefix : Config::getLocalConfig('database', 'prefix')) . $table . '`';
// Run a foreach on $data and complete the statement
foreach ($data as $key => $values) {
@ -294,7 +294,7 @@ class mysql
{
// Begin preparation of the statement
$prepare = 'DELETE FROM `' . ($prefix ? $prefix : Configuration::getLocalConfig('database', 'prefix')) . $table . '`';
$prepare = 'DELETE FROM `' . ($prefix ? $prefix : Config::getLocalConfig('database', 'prefix')) . $table . '`';
// If $data is set and is an array continue
if (is_array($data)) {
@ -333,7 +333,7 @@ class mysql
{
// Begin preparation of the statement
$prepare = 'SELECT COUNT(*) FROM `' . ($prefix ? $prefix : Configuration::getLocalConfig('database', 'prefix')) . $table . '`';
$prepare = 'SELECT COUNT(*) FROM `' . ($prefix ? $prefix : Config::getLocalConfig('database', 'prefix')) . $table . '`';
// If $data is set and is an array continue
if (is_array($data)) {

View file

@ -8,7 +8,7 @@
namespace Sakura;
// Define Sakura version
define('SAKURA_VERSION', '20151104');
define('SAKURA_VERSION', '20151106');
define('SAKURA_VLABEL', 'Eminence');
define('SAKURA_COLOUR', '#6C3082');
define('SAKURA_STABLE', false);
@ -31,17 +31,16 @@ if (version_compare(phpversion(), '5.4.0', '<')) {
require_once ROOT . '_sakura/vendor/autoload.php';
require_once ROOT . '_sakura/components/Main.php';
require_once ROOT . '_sakura/components/Hashing.php';
require_once ROOT . '_sakura/components/Configuration.php';
require_once ROOT . '_sakura/components/Config.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';
require_once ROOT . '_sakura/components/User.php';
require_once ROOT . '_sakura/components/Rank.php';
require_once ROOT . '_sakura/components/Users.php';
require_once ROOT . '_sakura/components/Forums.php';
require_once ROOT . '_sakura/components/Users.php'; //<
require_once ROOT . '_sakura/components/Forums.php'; //<
require_once ROOT . '_sakura/components/News.php';
require_once ROOT . '_sakura/components/Comments.php';
require_once ROOT . '_sakura/components/Manage.php';
@ -62,12 +61,12 @@ set_error_handler(['Sakura\Main', 'errorHandler']);
Main::init(ROOT . '_sakura/config/config.ini');
// Assign servers file to whois class
Whois::setServers(ROOT . '_sakura/' . Configuration::getLocalConfig('data', 'whoisservers'));
Whois::setServers(ROOT . '_sakura/' . Config::getLocalConfig('data', 'whoisservers'));
// Check if we the system has a cron service
if (Configuration::getConfig('no_cron_service')) {
if (Config::getConfig('no_cron_service')) {
// If not do an "asynchronous" call to the cron.php script
if (Configuration::getConfig('no_cron_last') < (time() - Configuration::getConfig('no_cron_interval'))) {
if (Config::getConfig('no_cron_last') < (time() - Config::getConfig('no_cron_interval'))) {
// Check OS
if (substr(strtolower(PHP_OS), 0, 3) == 'win') {
pclose(popen('start /B ' . PHP_BINDIR . '\php.exe ' . addslashes(ROOT . '_sakura\cron.php'), 'r'));
@ -88,7 +87,7 @@ if (Configuration::getConfig('no_cron_service')) {
}
// Start output buffering
ob_start(Configuration::getConfig('use_gzip') ? 'ob_gzhandler' : null);
ob_start(Config::getConfig('use_gzip') ? 'ob_gzhandler' : null);
// Auth check
$authCheck = Users::checkLogin();
@ -102,7 +101,7 @@ $urls = new Urls();
// Prepare the name of the template to load (outside of SAKURA_NO_TPL because it's used in imageserve.php)
$templateName =
defined('SAKURA_MANAGE') ?
Configuration::getConfig('manage_style') :
Config::getConfig('manage_style') :
(
(
isset($currentUser->data['user_data']['userOptions']['useMisaki']) &&
@ -110,105 +109,90 @@ Configuration::getConfig('manage_style') :
$currentUser->checkPermission('SITE', 'ALTER_PROFILE')
) ?
'misaki' :
Configuration::getConfig('site_style')
Config::getConfig('site_style')
);
if (!defined('SAKURA_NO_TPL')) {
// Initialise templating engine
Templates::init($templateName);
// Set base page rendering data
$renderData = [
/*
* Idea for flexibility in templates and to reduce redundancy;
* Attempt to use a class instead of an assoc. array for the
* template variables since twig supports this to make accessing
* certain functions, like the time elapsed function easier.
* Update 2015-09-08: Apparently this will be added in PHP 7 so
* we'll be looking out for that.
*/
'sakura' => [
'versionInfo' => [
'version' => SAKURA_VERSION,
'label' => SAKURA_VLABEL,
'colour' => SAKURA_COLOUR,
'stable' => SAKURA_STABLE,
],
'cookie' => [
'prefix' => Configuration::getConfig('cookie_prefix'),
'domain' => Configuration::getConfig('cookie_domain'),
'path' => Configuration::getConfig('cookie_path'),
'prefix' => Config::getConfig('cookie_prefix'),
'domain' => Config::getConfig('cookie_domain'),
'path' => Config::getConfig('cookie_path'),
],
'urlMain' => Configuration::getConfig('url_main'),
'urlApi' => Configuration::getConfig('url_api'),
'urlMain' => Config::getConfig('url_main'),
'urlApi' => Config::getConfig('url_api'),
'contentPath' => Configuration::getConfig('content_path'),
'resources' => Configuration::getConfig('content_path') . '/data/' . strtolower(Templates::$template),
'contentPath' => Config::getConfig('content_path'),
'resources' => Config::getConfig('content_path') . '/data/' . $templateName,
'charset' => Configuration::getConfig('charset'),
'siteName' => Configuration::getConfig('sitename'),
'siteLogo' => Configuration::getConfig('sitelogo'),
'siteDesc' => Configuration::getConfig('sitedesc'),
'siteTags' => implode(", ", json_decode(Configuration::getConfig('sitetags'), true)),
'dateFormat' => Configuration::getConfig('date_format'),
'charset' => Config::getConfig('charset'),
'siteName' => Config::getConfig('sitename'),
'siteLogo' => Config::getConfig('sitelogo'),
'siteDesc' => Config::getConfig('sitedesc'),
'siteTags' => implode(", ", json_decode(Config::getConfig('sitetags'), true)),
'dateFormat' => Config::getConfig('date_format'),
'currentPage' => '//' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
'referrer' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null),
'recaptchaPublic' => Configuration::getConfig('recaptcha_public'),
'recaptchaEnabled' => Configuration::getConfig('recaptcha'),
'disableRegistration' => Configuration::getConfig('disable_registration'),
'lockAuth' => Configuration::getConfig('lock_authentication'),
'requireRegCodes' => Configuration::getConfig('require_registration_code'),
'requireActivation' => Configuration::getConfig('require_activation'),
'minPwdEntropy' => Configuration::getConfig('min_entropy'),
'minUsernameLength' => Configuration::getConfig('username_min_length'),
'maxUsernameLength' => Configuration::getConfig('username_max_length'),
'recaptchaPublic' => Config::getConfig('recaptcha_public'),
'recaptchaEnabled' => Config::getConfig('recaptcha'),
'disableRegistration' => Config::getConfig('disable_registration'),
'lockAuth' => Config::getConfig('lock_authentication'),
'requireRegCodes' => Config::getConfig('require_registration_code'),
'requireActivation' => Config::getConfig('require_activation'),
'minPwdEntropy' => Config::getConfig('min_entropy'),
'minUsernameLength' => Config::getConfig('username_min_length'),
'maxUsernameLength' => Config::getConfig('username_max_length'),
],
'php' => [
'sessionid' => \session_id(),
'time' => \time(),
'self' => $_SERVER['PHP_SELF'],
],
'session' => [
'checkLogin' => $authCheck,
'sessionId' => $authCheck[1],
'userId' => $authCheck[0],
],
'user' => $currentUser,
'urls' => $urls,
];
// Site closing
if (Configuration::getConfig('site_closed')) {
if (Config::getConfig('site_closed')) {
// Additional render data
$renderData = array_merge($renderData, [
'page' => [
'message' => Configuration::getConfig('site_closed_reason'),
'message' => Config::getConfig('site_closed_reason'),
],
]);
print Templates::render('global/information.tpl', $renderData);
// Initialise templating engine
$template = new Template();
// Change templating engine
$template->setTemplate($templateName);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
echo $template->render('global/information.tpl');
exit;
}
@ -227,7 +211,18 @@ if (!defined('SAKURA_NO_TPL')) {
]);
Users::logout();
print Templates::render('main/banned.tpl', $renderData);
// Initialise templating engine
$template = new Template();
// Change templating engine
$template->setTemplate($templateName);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
echo $template->render('main/banned.tpl');
exit;
}
}

View file

@ -12,5 +12,14 @@ require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . '_sakura/sa
// Set 404 header
header('HTTP/1.0 404 Not Found');
// Initialise templating engine
$template = new Template();
// Change templating engine
$template->setTemplate($templateName);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
print Templates::render('global/notfound.tpl', $renderData);
echo $template->render('global/notfound.tpl');

View file

@ -9,6 +9,12 @@ namespace Sakura;
// Include components
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . '_sakura/sakura.php';
// Initialise templating engine
$template = new Template();
// Change templating engine
$template->setTemplate($templateName);
// Page actions
if (isset($_REQUEST['mode'])) {
// Continue
@ -214,12 +220,12 @@ if (isset($_REQUEST['mode'])) {
$_REQUEST['email'],
isset($_REQUEST['tos']),
(
Configuration::getConfig('recaptcha') ?
Config::getConfig('recaptcha') ?
$_REQUEST['g-recaptcha-response'] :
null
),
(
Configuration::getConfig('require_registration_code') ?
Config::getConfig('require_registration_code') ?
$_REQUEST['registercode'] :
null
)
@ -241,7 +247,7 @@ if (isset($_REQUEST['mode'])) {
'INVALID_EMAIL' => 'Your e-mail address is formatted incorrectly.',
'INVALID_MX' => 'No valid MX-Record found on the e-mail address you supplied.',
'EMAILSENT' => 'Your registration went through! An activation e-mail has been sent.',
'SUCCESS' => 'Your registration went through! Welcome to ' . Configuration::getConfig('sitename') . '!',
'SUCCESS' => 'Your registration went through! Welcome to ' . Config::getConfig('sitename') . '!',
];
@ -284,13 +290,14 @@ if (isset($_REQUEST['mode'])) {
}
// Print page contents or if the AJAX request is set only display the render data
print isset($_REQUEST['ajax']) ?
(
$renderData['page']['message'] . '|' .
if (isset($_REQUEST['ajax'])) {
echo $renderData['page']['message'] . '|' .
$renderData['page']['success'] . '|' .
$renderData['page']['redirect']
) :
Templates::render('global/information.tpl', $renderData);
$renderData['page']['redirect'];
} else {
$template->setVariables($renderData);
echo $template->render('global/information.tpl');
}
exit;
}
@ -316,7 +323,8 @@ if (Users::checkLogin()) {
];
print Templates::render('global/information.tpl', $renderData);
$template->setVariables($renderData);
echo $template->render('global/information.tpl');
exit;
}
@ -339,9 +347,11 @@ if (isset($_REQUEST['pw']) && $_REQUEST['pw']) {
$renderData['auth']['forgotKey'] = $_REQUEST['key'];
}
print Templates::render('main/forgotpassword.tpl', $renderData);
$template->setVariables($renderData);
echo $template->render('main/forgotpassword.tpl');
exit;
}
// Print page contents
print Templates::render('main/authenticate.tpl', $renderData);
$template->setVariables($renderData);
echo $template->render('main/authenticate.tpl');

View file

@ -17,5 +17,14 @@ $renderData['page'] = [
];
// Initialise templating engine
$template = new Template();
// Change templating engine
$template->setTemplate($templateName);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
print Templates::render('main/faq.tpl', $renderData);
echo $template->render('main/faq.tpl');

View file

@ -9,5 +9,14 @@ namespace Sakura;
// Include components
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . '_sakura/sakura.php';
// Initialise templating engine
$template = new Template();
// Change templating engine
$template->setTemplate($templateName);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
print Templates::render('group/index.tpl', $renderData);
echo $template->render('group/index.tpl');

View file

@ -16,7 +16,7 @@ require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . '_sakura/sa
header('Content-Type: application/octet-stream');
// Path to user uploads
$userDirPath = ROOT . Configuration::getConfig('user_uploads') . '/';
$userDirPath = ROOT . Config::getConfig('user_uploads') . '/';
// Check if the m(ode) GET request is set
if (isset($_GET['m'])) {
@ -26,17 +26,17 @@ if (isset($_GET['m'])) {
$noAvatar = ROOT . str_replace(
'{{ TPL }}',
$templateName,
Configuration::getConfig('no_avatar_img')
Config::getConfig('no_avatar_img')
);
$deactiveAvatar = ROOT . str_replace(
'{{ TPL }}',
$templateName,
Configuration::getConfig('deactivated_avatar_img')
Config::getConfig('deactivated_avatar_img')
);
$bannedAvatar = ROOT . str_replace(
'{{ TPL }}',
$templateName,
Configuration::getConfig('banned_avatar_img')
Config::getConfig('banned_avatar_img')
);
// If ?u= isn't set or if it isn't numeric
@ -72,7 +72,7 @@ if (isset($_GET['m'])) {
case 'background':
// Set paths
$noBackground = ROOT . Configuration::getConfig('no_background_img');
$noBackground = ROOT . Config::getConfig('no_background_img');
// If ?u= isn't set or if it isn't numeric
if (!isset($_GET['u']) || !is_numeric($_GET['u'])) {
@ -108,7 +108,7 @@ if (isset($_GET['m'])) {
case 'header':
// Set paths
$noHeader = ROOT . Configuration::getConfig('no_header_img');
$noHeader = ROOT . Config::getConfig('no_header_img');
// If ?u= isn't set or if it isn't numeric
if (!isset($_GET['u']) || !is_numeric($_GET['u'])) {
@ -143,11 +143,11 @@ if (isset($_GET['m'])) {
break;
default:
$serveImage = ROOT . Configuration::getConfig('pixel_img');
$serveImage = ROOT . Config::getConfig('pixel_img');
}
} else {
$serveImage = ROOT . Configuration::getConfig('pixel_img');
$serveImage = ROOT . Config::getConfig('pixel_img');
}
$serveImage = file_get_contents($serveImage);

View file

@ -9,6 +9,12 @@ namespace Sakura;
// Include components
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . '_sakura/sakura.php';
// Initialise templating engine
$template = new Template();
// Change templating engine
$template->setTemplate($templateName);
// Info pages
if (isset($_GET['p'])) {
// Set default variables
@ -33,17 +39,20 @@ if (isset($_GET['p'])) {
];
}
// Set parse variables
$template->setVariables($renderData);
// Print page contents
print Templates::render('main/infopage.tpl', $renderData);
echo $template->render('main/infopage.tpl');
exit;
}
// Are we in forum mode?
$forumMode = isset($_GET['forum']) ? ($_GET['forum'] == true) : false;
$renderData['news'] = ($forumMode ? null : (new News(Configuration::getConfig('site_news_category'))));
$renderData['news'] = ($forumMode ? null : (new News(Config::getConfig('site_news_category'))));
$renderData['newsCount'] = Configuration::getConfig('front_page_news_posts');
$renderData['newsCount'] = Config::getConfig('front_page_news_posts');
$renderData['page'] = [
'friend_req' => Users::getPendingFriends(),
@ -74,12 +83,6 @@ $renderData['stats'] = [
'onlineUsers' => Users::checkAllOnline(),
];
// Initialise templating engine
$template = new Template();
// Change templating engine
$template->setTemplate($templateName);
// Set parse variables
$template->setVariables($renderData);

View file

@ -81,5 +81,14 @@ switch ($category . '.' . $mode) {
break;
}
// Initialise templating engine
$template = new Template();
// Change templating engine
$template->setTemplate($templateName);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
print Templates::render('pages/' . $mode . '.' . $category . '.tpl', $renderData);
echo $template->render('pages/' . $mode . '.' . $category . '.tpl');

View file

@ -9,6 +9,12 @@ namespace Sakura;
// Include components
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . '_sakura/sakura.php';
// Initialise templating engine
$template = new Template();
// Change templating engine
$template->setTemplate($templateName);
// CHeck if the user is logged in
if (Users::checkLogin()) {
// Add page specific things
@ -31,13 +37,19 @@ if (Users::checkLogin()) {
'page' => isset($_GET['page']) && ($_GET['page'] - 1) >= 0 ? $_GET['page'] - 1 : 0,
'users' => array_chunk($_MEMBERLIST_ACTIVE && !$_MEMBERLIST_NFOUND ?
Users::getUsersInRank($_MEMBERLIST_ACTIVE, null, true) :
Users::getAllUsers(), Configuration::getConfig('members_per_page'), true),
Users::getAllUsers(), Config::getConfig('members_per_page'), true),
];
// Set parse variables
$template->setVariables($renderData);
// Print page contents
print Templates::render('main/memberlist.tpl', $renderData);
echo $template->render('main/memberlist.tpl');
} else {
// Else return the restricted page
print Templates::render('global/restricted.tpl', $renderData);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
echo $template->render('global/restricted.tpl');
}

View file

@ -13,7 +13,7 @@ use DOMDocument;
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . '_sakura/sakura.php';
// Create a new News object
$news = new News(isset($_GET['cat']) ? $_GET['cat'] : Configuration::getConfig('site_news_category'));
$news = new News(isset($_GET['cat']) ? $_GET['cat'] : Config::getConfig('site_news_category'));
// News XML feed
if (isset($_GET['xml'])) {
@ -22,27 +22,23 @@ if (isset($_GET['xml'])) {
// Meta data attributes
$metaData = [
'title' => ($_FEED_TITLE = Configuration::getConfig('sitename')) . ' News',
'link' => ($_FEED_URL = 'http://' . Configuration::getConfig('url_main')),
'title' => ($_FEED_TITLE = Config::getConfig('sitename')) . ' News',
'link' => ($_FEED_URL = 'http://' . Config::getConfig('url_main')),
'description' => 'News about ' . $_FEED_TITLE,
'language' => 'en-gb',
'webMaster' => Configuration::getConfig('admin_email') . ' (' . $_FEED_TITLE . ' Webmaster)',
'webMaster' => Config::getConfig('admin_email') . ' (' . $_FEED_TITLE . ' Webmaster)',
'pubDate' => ($_FEED_DATE = date('r', $posts[array_keys($posts)[0]]['news_timestamp'])),
'lastBuildDate' => $_FEED_DATE,
];
// Item attributes
$itemData = [
'title' => ['text' => '0', 'eval' => '$post["news_title"]'],
'link' => ['text' => $_FEED_URL . (new Urls())->format('SITE_NEWS_POST', ['0']), 'eval' => '$post["news_id"]'],
'guid' => ['text' => $_FEED_URL . (new Urls())->format('SITE_NEWS_POST', ['0']), 'eval' => '$post["news_id"]'],
'pubDate' => ['text' => '{EVAL}', 'eval' => 'date("D, d M Y G:i:s O", $post["news_timestamp"])'],
'dc:publisher' => ['text' => '0', 'eval' => '$post["news_poster"]->data["username"]'],
'description' => ['cdata' => '0', 'eval' => '$post["news_content_parsed"]'],
];
// Create a new DOM document
@ -123,14 +119,21 @@ if (isset($_GET['xml'])) {
}
$renderData = array_merge($renderData, [
'news' => $news,
'postsPerPage' => Configuration::getConfig('news_posts_per_page'),
'postsPerPage' => Config::getConfig('news_posts_per_page'),
'viewPost' => isset($_GET['id']),
'postExists' => $news->postExists(isset($_GET['id']) ? $_GET['id'] : 0),
'currentPage' => isset($_GET['page']) && ($_GET['page'] - 1) >= 0 ? $_GET['page'] - 1 : 0,
]);
// Initialise templating engine
$template = new Template();
// Change templating engine
$template->setTemplate($templateName);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
print Templates::render('main/news.tpl', $renderData);
echo $template->render('main/news.tpl');

View file

@ -9,6 +9,12 @@ namespace Sakura;
// Include components
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . '_sakura/sakura.php';
// Initialise templating engine
$template = new Template();
// Change templating engine
$template->setTemplate($templateName);
// Set location
$topicId = isset($_GET['t']) ?
$_GET['t'] :
@ -33,7 +39,7 @@ $posting = [
// Check if we're in reply mode
if ($mode != 'f') {
// Attempt to get the topic
$topic = Forum::getTopic($topicId, true);
$topic = Forums::getTopic($topicId, true);
// Prompt an error if the topic doesn't exist
if (!$topic) {
@ -43,8 +49,11 @@ if ($mode != 'f') {
'message' => 'The requested post does not exist.',
];
// Render information page
print Templates::render('global/information.tpl', $renderData);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
echo $template->render('global/information.tpl');
exit;
}
@ -66,8 +75,11 @@ if ($mode != 'f') {
'message' => 'You can only edit your own posts!',
];
// Render information page
print Templates::render('global/information.tpl', $renderData);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
echo $template->render('global/information.tpl');
exit;
}
@ -90,8 +102,11 @@ if ($mode != 'f') {
'message' => 'You can only delete your own posts!',
];
// Render information page
print Templates::render('global/information.tpl', $renderData);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
echo $template->render('global/information.tpl');
exit;
}
@ -120,8 +135,11 @@ if ($mode != 'f') {
'message' => 'Your post has been deleted!',
];
// Render information page
print Templates::render('global/information.tpl', $renderData);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
echo $template->render('global/information.tpl');
exit;
// Return to previous page
} else {
@ -138,8 +156,11 @@ if ($mode != 'f') {
],
]);
// Render confirmation form
print Templates::render('global/confirm.tpl', $renderData);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
echo $template->render('global/confirm.tpl');
exit;
}
@ -177,13 +198,17 @@ if (isset($_POST['post'])) {
];
// Print page contents or if the AJAX request is set only display the render data
print isset($_REQUEST['ajax']) ?
(
$renderData['page']['message'] . '|' .
if (isset($_REQUEST['ajax'])) {
echo $renderData['page']['message'] . '|' .
$renderData['page']['success'] . '|' .
$renderData['page']['redirect']
) :
Templates::render('global/information.tpl', $renderData);
$renderData['page']['redirect'];
} else {
// Set parse variables
$template->setVariables($renderData);
// Print page contents
echo $template->render('global/information.tpl');
}
exit;
}
@ -192,4 +217,8 @@ $renderData = array_merge($renderData, [
'posting' => $posting,
]);
print Templates::render('forum/posting.tpl', $renderData);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
echo $template->render('forum/posting.tpl');

View file

@ -9,6 +9,12 @@ namespace Sakura;
// Include components
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . '_sakura/sakura.php';
// Initialise templating engine
$template = new Template();
// Change templating engine
$template->setTemplate($templateName);
// Get the user's context
$profile = new User(isset($_GET['u']) ? $_GET['u'] : 0);
@ -25,5 +31,8 @@ $views = [
$renderData['profile'] = $profile;
$renderData['profileView'] = isset($_GET['view']) && in_array($_GET['view'], $views) ? $_GET['view'] : $views[0];
// Set parse variables
$template->setVariables($renderData);
// Print page contents
print Templates::render('main/profile.tpl', $renderData);
echo $template->render('main/profile.tpl');

View file

@ -9,4 +9,14 @@ namespace Sakura;
// Include components
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . '_sakura/sakura.php';
print Templates::render('main/report.tpl', $renderData);
// Initialise templating engine
$template = new Template();
// Change templating engine
$template->setTemplate($templateName);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
echo $template->render('main/report.tpl');

View file

@ -16,5 +16,14 @@ $renderData['page'] = [
];
// Initialise templating engine
$template = new Template();
// Change templating engine
$template->setTemplate($templateName);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
print Templates::render('main/search.tpl', $renderData);
echo $template->render('main/search.tpl');

View file

@ -14,6 +14,14 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
// Include components
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . '_sakura/sakura.php';
if (!defined('SAKURA_NO_TPL')) {
// Initialise templating engine
$template = new Template();
// Change templating engine
$template->setTemplate($templateName);
}
// Notifications
if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications']) {
// Create the notification container array
@ -57,11 +65,9 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
// Match session ids for the same reason
if (!Users::checkLogin()) {
$renderData['page'] = [
'redirect' => $redirect,
'message' => 'You must be logged in to do that!',
'success' => 0,
];
// Prevent
@ -71,11 +77,9 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
// Match session ids for the same reason
if (!isset($_REQUEST['session']) || $_REQUEST['session'] != session_id()) {
$renderData['page'] = [
'redirect' => $redirect,
'message' => 'Invalid session, please try again.',
'success' => 0,
];
// Prevent
@ -85,11 +89,9 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
// Match session ids for the same reason
if (!isset($_REQUEST['category'])) {
$renderData['page'] = [
'redirect' => $redirect,
'message' => 'No category was set.',
'success' => 0,
];
// Prevent
@ -107,11 +109,9 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
// Check if the comment was actually made by the current user
if (!$comment) {
$renderData['page'] = [
'redirect' => $redirect,
'message' => 'The requested comment does not exist.',
'success' => 0,
];
break;
}
@ -119,11 +119,9 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
// Check if the user can delete comments
if (!$currentUser->checkPermission('SITE', 'VOTE_COMMENTS')) {
$renderData['page'] = [
'redirect' => $redirect,
'message' => 'You aren\'t allowed to vote on comments.',
'success' => 0,
];
break;
}
@ -135,11 +133,9 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
);
$renderData['page'] = [
'redirect' => $redirect,
'message' => 'Your vote has been cast!',
'success' => 1,
];
break;
@ -149,11 +145,9 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
// Check if the comment was actually made by the current user
if (!$comment) {
$renderData['page'] = [
'redirect' => $redirect,
'message' => 'The requested comment does not exist.',
'success' => 0,
];
break;
}
@ -161,11 +155,9 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
// Check if the user can delete comments
if (!$currentUser->checkPermission('SITE', 'DELETE_COMMENTS')) {
$renderData['page'] = [
'redirect' => $redirect,
'message' => 'You aren\'t allowed to delete comments.',
'success' => 0,
];
break;
}
@ -173,11 +165,9 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
// Check if the comment was actually made by the current user
if ($comment['comment_poster'] !== $currentUser->data['id']) {
$renderData['page'] = [
'redirect' => $redirect,
'message' => 'You can\'t delete the comments of others.',
'success' => 0,
];
break;
}
@ -185,11 +175,9 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
$comments->removeComment(isset($_REQUEST['id']) ? $_REQUEST['id'] : 0);
$renderData['page'] = [
'redirect' => $redirect,
'message' => 'The comment has been deleted!',
'success' => 1,
];
break;
@ -197,11 +185,9 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
// Check if the user can delete comments
if (!$currentUser->checkPermission('SITE', 'CREATE_COMMENTS')) {
$renderData['page'] = [
'redirect' => $redirect,
'message' => 'You aren\'t allowed to comment.',
'success' => 0,
];
break;
}
@ -217,21 +203,17 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
];
$renderData['page'] = [
'redirect' => $redirect,
'message' => $messages[$comment[1]],
'success' => $comment[0],
];
break;
default:
$renderData['page'] = [
'redirect' => $redirect,
'message' => 'Unknown action.',
'success' => 0,
];
}
}
@ -360,8 +342,8 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
sprintf($notifStrings[$action[1]][0], $user->data['username']),
$notifStrings[$action[1]][1],
60000,
'//' . Configuration::getConfig('url_main') . '/a/' . $user->data['user_id'],
'//' . Configuration::getConfig('url_main') . '/u/' . $user->data['user_id'],
'//' . Config::getConfig('url_main') . '/a/' . $user->data['user_id'],
'//' . Config::getConfig('url_main') . '/u/' . $user->data['user_id'],
'1'
);
}
@ -455,7 +437,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
}
// Set path variables
$filepath = ROOT . Configuration::getConfig('user_uploads') . '/';
$filepath = ROOT . Config::getConfig('user_uploads') . '/';
$filename = $filepath . $mode . '_' . $currentUser->data['user_id'];
$currfile = isset($currentUser->data['user_data'][$userDataKey])
&& !empty($_OLDFILE = $currentUser->data['user_data'][$userDataKey]) ? $_OLDFILE : null;
@ -544,8 +526,8 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
}
// Check if the image is too large
if (($metadata[0] > Configuration::getConfig($mode . '_max_width')
|| $metadata[1] > Configuration::getConfig($mode . '_max_height'))) {
if (($metadata[0] > Config::getConfig($mode . '_max_width')
|| $metadata[1] > Config::getConfig($mode . '_max_height'))) {
// Set render data
$renderData['page'] = [
@ -559,8 +541,8 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
}
// Check if the image is too small
if (($metadata[0] < Configuration::getConfig($mode . '_min_width')
|| $metadata[1] < Configuration::getConfig($mode . '_min_height'))) {
if (($metadata[0] < Config::getConfig($mode . '_min_width')
|| $metadata[1] < Config::getConfig($mode . '_min_height'))) {
// Set render data
$renderData['page'] = [
@ -574,7 +556,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
}
// Check if the file is too large
if ((filesize($_FILES[$mode]['tmp_name']) > Configuration::getConfig($mode . '_max_fsize'))) {
if ((filesize($_FILES[$mode]['tmp_name']) > Config::getConfig($mode . '_max_fsize'))) {
// Set render data
$renderData['page'] = [
@ -1403,7 +1385,12 @@ if (Users::checkLogin()) {
|| empty($mode)
|| !$pages[$category]['modes'][$mode]['access']) {
header('HTTP/1.0 404 Not Found');
print Templates::render('global/notfound.tpl', $renderData);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
echo $template->render('global/notfound.tpl');
exit;
}
@ -1484,12 +1471,12 @@ if (Users::checkLogin()) {
case 'appearance.background':
$renderData[$mode] = [
'max_width' => Configuration::getConfig($mode . '_max_width'),
'max_height' => Configuration::getConfig($mode . '_max_height'),
'min_width' => Configuration::getConfig($mode . '_min_width'),
'min_height' => Configuration::getConfig($mode . '_min_height'),
'max_size' => Configuration::getConfig($mode . '_max_fsize'),
'max_size_view' => Main::getByteSymbol(Configuration::getConfig($mode . '_max_fsize')),
'max_width' => Config::getConfig($mode . '_max_width'),
'max_height' => Config::getConfig($mode . '_max_height'),
'min_width' => Config::getConfig($mode . '_min_width'),
'min_height' => Config::getConfig($mode . '_min_height'),
'max_size' => Config::getConfig($mode . '_max_fsize'),
'max_size_view' => Main::getByteSymbol(Config::getConfig($mode . '_max_fsize')),
];
break;
@ -1510,9 +1497,15 @@ if (Users::checkLogin()) {
break;
}
// Set parse variables
$template->setVariables($renderData);
// Print page contents
print Templates::render('main/settings.tpl', $renderData);
echo $template->render('main/settings.tpl');
} else {
// If not allowed print the restricted page
print Templates::render('global/restricted.tpl', $renderData);
$template->setVariables($renderData);
// Print page contents
echo $template->render('global/restricted.tpl');
}

View file

@ -9,6 +9,12 @@ namespace Sakura;
// Include components
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . '_sakura/sakura.php';
// Initialise templating engine
$template = new Template();
// Change templating engine
$template->setTemplate($templateName);
// Switch between modes (we only allow this to be used by logged in user)
if (isset($_REQUEST['mode'])
&& Users::checkLogin()
@ -38,15 +44,15 @@ if (isset($_REQUEST['mode'])
if (!isset($_POST['months'])
|| !is_numeric($_POST['months'])
|| (int) $_POST['months'] < 1
|| (int) $_POST['months'] > Configuration::getConfig('premium_amount_max')) {
|| (int) $_POST['months'] > Config::getConfig('premium_amount_max')) {
header('Location: ' . $urls->format('SITE_PREMIUM') . '?fail=true');
} else {
// Calculate the total
$total = (float) Configuration::getConfig('premium_price_per_month') * (int) $_POST['months'];
$total = (float) Config::getConfig('premium_price_per_month') * (int) $_POST['months'];
$total = number_format($total, 2, '.', '');
// Generate item name
$itemName = Configuration::getConfig('sitename')
$itemName = Config::getConfig('sitename')
. ' Premium - '
. (string) $_POST['months']
. ' month'
@ -56,8 +62,8 @@ if (isset($_REQUEST['mode'])
if ($transaction = Payments::createTransaction(
$total,
$itemName,
Configuration::getConfig('sitename') . ' Premium Purchase',
'http://' . Configuration::getConfig('url_main') . $urls->format('SITE_PREMIUM')
Config::getConfig('sitename') . ' Premium Purchase',
'http://' . Config::getConfig('url_main') . $urls->format('SITE_PREMIUM')
)) {
// Store the amount of months in the global session array
$_SESSION['premiumMonths'] = (int) $_POST['months'];
@ -92,7 +98,7 @@ if (isset($_REQUEST['mode'])
Users::updatePremiumMeta($currentUser->data['user_id']);
Main::updatePremiumTracker(
$currentUser->data['user_id'],
((float) Configuration::getConfig('premium_price_per_month') * $_SESSION['premiumMonths']),
((float) Config::getConfig('premium_price_per_month') * $_SESSION['premiumMonths']),
$currentUser->data['username']
. ' bought premium for '
. $_SESSION['premiumMonths']
@ -111,15 +117,17 @@ if (isset($_REQUEST['mode'])
break;
case 'complete':
print Templates::render('main/premiumcomplete.tpl', array_merge([
$renderData = array_merge([
'page' => [
'expiration' => ($prem = Users::checkUserPremium($currentUser->data['user_id'])[2]) !== null ? $prem : 0,
],
], $renderData);
], $renderData));
// Set parse variables
$template->setVariables($renderData);
// Print page contents
echo $template->render('main/premiumcomplete.tpl');
break;
default:
@ -142,7 +150,11 @@ if (isset($_GET['tracker'])) {
];
print Templates::render('main/supporttracker.tpl', $renderData);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
echo $template->render('main/supporttracker.tpl');
exit;
}
@ -150,11 +162,14 @@ if (isset($_GET['tracker'])) {
$renderData['page'] = [
'fail' => isset($_GET['fail']),
'price' => Configuration::getConfig('premium_price_per_month'),
'price' => Config::getConfig('premium_price_per_month'),
'current' => $currentUser->checkPremium(),
'amount_max' => Configuration::getConfig('premium_amount_max'),
'amount_max' => Config::getConfig('premium_amount_max'),
];
// Set parse variables
$template->setVariables($renderData);
// Print page contents
print Templates::render('main/support.tpl', $renderData);
echo $template->render('main/support.tpl');

View file

@ -12,6 +12,12 @@ require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . '_sakura/sa
// Get the forum's data
$forum = Forums::getForum(isset($_GET['f']) ? $_GET['f'] : 0);
// Initialise templating engine
$template = new Template();
// Change templating engine
$template->setTemplate($templateName);
// Check if the forum exists
if (!$forum) {
// Set render data
@ -20,8 +26,11 @@ if (!$forum) {
'message' => 'The subforum you tried to access does not exist.',
];
// Print template
print Templates::render('global/information.tpl', $renderData);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
echo $template->render('global/information.tpl');
exit;
}
@ -34,8 +43,11 @@ if ($forum['forum']['forum_type'] === 2) {
'redirect' => $forum['forum']['forum_link'],
];
// Print template
print Templates::render('global/information.tpl', $renderData);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
echo $template->render('global/information.tpl');
exit;
}
@ -49,5 +61,8 @@ $renderData['board'] = [
];
$renderData['currentPage'] = isset($_GET['page']) && ($_GET['page'] - 1) >= 0 ? $_GET['page'] - 1 : 0;
// Set parse variables
$template->setVariables($renderData);
// Print page contents
print Templates::render('forum/viewforum.tpl', $renderData);
echo $template->render('forum/viewforum.tpl');

View file

@ -16,6 +16,12 @@ $topic = Forums::getTopic(
: (isset($_GET['t']) ? $_GET['t'] : 0)
);
// Initialise templating engine
$template = new Template();
// Change templating engine
$template->setTemplate($templateName);
// Check if the forum exists
if (!$topic) {
// Set render data
@ -23,8 +29,11 @@ if (!$topic) {
'message' => 'The topic you tried to access does not exist.',
];
// Print template
print Templates::render('global/information.tpl', $renderData);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
echo $template->render('global/information.tpl');
exit;
}
@ -38,5 +47,8 @@ $renderData = array_merge($renderData, $topic, [
'currentPage' => isset($_GET['page']) && ($_GET['page'] - 1) >= 0 ? $_GET['page'] - 1 : 0,
]);
// Set parse variables
$template->setVariables($renderData);
// Print page contents
print Templates::render('forum/viewtopic.tpl', $renderData);
echo $template->render('forum/viewtopic.tpl');