diff --git a/libraries/BBcode.php b/libraries/BBcode.php
index e3e54cf..9dddf80 100644
--- a/libraries/BBcode.php
+++ b/libraries/BBcode.php
@@ -38,6 +38,29 @@ class BBcode
self::loadStandardCodes();
}
+ /**
+ * Parse the emoticons.
+ *
+ * @param string $text String to parse emoticons from.
+ *
+ * @return string Parsed text.
+ */
+ public static function parseEmoticons($text)
+ {
+ // Get emoticons from the database
+ $emotes = Database::fetch('emoticons');
+
+ // Parse all emoticons
+ foreach($emotes as $emote) {
+ $image = "";
+ $icon = preg_quote($emote['emote_string'], '#');
+ $text = preg_replace("#$icon#", $image, $text);
+ }
+
+ // Return the parsed text
+ return $text;
+ }
+
/**
* Adds the standard BBcode.
*/
@@ -126,7 +149,7 @@ class BBcode
$parsed = nl2br(self::$bbcode->getAsHtml());
$parsed = Utils::fixCodeTags($parsed);
- $parsed = Utils::parseEmotes($parsed);
+ $parsed = self::parseEmoticons($parsed);
return $parsed;
}
diff --git a/libraries/Comments.php b/libraries/Comments.php
index 63444f3..4100aa4 100644
--- a/libraries/Comments.php
+++ b/libraries/Comments.php
@@ -76,7 +76,7 @@ class Comments
foreach ($comments as $comment) {
// Attach the poster
$comment['comment_poster'] = User::construct($comment['comment_poster']);
- $comment['comment_text'] = Utils::parseEmotes(Utils::cleanString($comment['comment_text']));
+ $comment['comment_text'] = BBcode::parseEmoticons(Utils::cleanString($comment['comment_text']));
// Get likes and dislikes
$votes = $this->getVotes($comment['comment_id']);
diff --git a/libraries/Controllers/Premium.php b/libraries/Controllers/Premium.php
new file mode 100644
index 0000000..22ef76f
--- /dev/null
+++ b/libraries/Controllers/Premium.php
@@ -0,0 +1,168 @@
+
+ */
+class Premium
+{
+ public static function index()
+ {
+ global $currentUser, $urls;
+
+ // Switch between modes (we only allow this to be used by logged in user)
+ if (isset($_REQUEST['mode'])
+ && Users::checkLogin()
+ && $currentUser->permission(Site::OBTAIN_PREMIUM)) {
+ // Initialise Payments class
+ if (!Payments::init()) {
+ header('Location: ' . $urls->format('SITE_PREMIUM') . '?fail=true');
+ } else {
+ switch ($_REQUEST['mode']) {
+ // Create the purchase
+ case 'purchase':
+ // Compare time and session so we know the link isn't forged
+ if (!isset($_REQUEST['time'])
+ || $_REQUEST['time'] < time() - 1000) {
+ return header('Location: ' . $urls->format('SITE_PREMIUM') . '?fail=true');
+ }
+
+ // Match session ids for the same reason
+ if (!isset($_REQUEST['session'])
+ || $_REQUEST['session'] != session_id()) {
+ return header('Location: ' . $urls->format('SITE_PREMIUM') . '?fail=true');
+ }
+
+ // Half if shit isn't gucci
+ if (!isset($_POST['months'])
+ || !is_numeric($_POST['months'])
+ || (int) $_POST['months'] < 1
+ || (int) $_POST['months'] > Config::get('premium_amount_max')) {
+ return header('Location: ' . $urls->format('SITE_PREMIUM') . '?fail=true');
+ } else {
+ // Calculate the total
+ $total = (float) Config::get('premium_price_per_month') * (int) $_POST['months'];
+ $total = number_format($total, 2, '.', '');
+
+ // Generate item name
+ $itemName = Config::get('sitename')
+ . ' Premium - '
+ . (string) $_POST['months']
+ . ' month'
+ . ((int) $_POST['months'] == 1 ? '' : 's');
+
+ // Attempt to create a transaction
+ if ($transaction = Payments::createTransaction(
+ $total,
+ $itemName,
+ Config::get('sitename') . ' Premium Purchase',
+ 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . Config::get('url_main') . $urls->format('SITE_PREMIUM')
+ )) {
+ // Store the amount of months in the global session array
+ $_SESSION['premiumMonths'] = (int) $_POST['months'];
+
+ return header('Location: ' . $transaction);
+ } else {
+ return header('Location: ' . $urls->format('SITE_PREMIUM') . '?fail=true');
+ }
+ }
+
+ // Finalising the purchase
+ case 'finish':
+ // Check if the success GET request is set and is true
+ if (isset($_GET['success'])
+ && isset($_GET['paymentId'])
+ && isset($_GET['PayerID'])
+ && isset($_SESSION['premiumMonths'])) {
+ // Attempt to complete the transaction
+ try {
+ $finalise = Payments::completeTransaction($_GET['paymentId'], $_GET['PayerID']);
+ }
+ catch (Exception $e) {
+ return trigger_error('Something went horribly wrong.', E_USER_ERROR);
+ }
+
+ // Attempt to complete the transaction
+ if ($finalise) {
+ // Make the user premium
+ Users::updatePremiumMeta($currentUser->id);
+ Utils::updatePremiumTracker(
+ $currentUser->id,
+ ((float) Config::get('premium_price_per_month') * $_SESSION['premiumMonths']),
+ $currentUser->username
+ . ' bought premium for '
+ . $_SESSION['premiumMonths']
+ . ' month'
+ . ($_SESSION['premiumMonths'] == 1 ? '' : 's')
+ . '.'
+ );
+
+ // Redirect to the complete
+ return header('Location: ' . $urls->format('SITE_PREMIUM') . '?mode=complete');
+ }
+ }
+
+ return header('Location: ' . $urls->format('SITE_PREMIUM') . '?fail=true');
+
+ case 'complete':
+ // Set parse variables
+ Template::vars([
+ 'page' => [
+ 'expiration' => ($prem = $currentUser->isPremium()[2]) !== null ? $prem : 0,
+ ],
+ ]);
+
+ // Print page contents
+ return Template::render('main/premiumcomplete');
+
+ default:
+ return header('Location: ' . $urls->format('SITE_PREMIUM'));
+
+ }
+ }
+ }
+
+ // Set parse variables
+ Template::vars([
+ 'page' => [
+ 'fail' => isset($_GET['fail']),
+ 'price' => Config::get('premium_price_per_month'),
+ 'current' => $currentUser->isPremium(),
+ 'amount_max' => Config::get('premium_amount_max'),
+ ],
+ ]);
+
+ // Print page contents
+ return Template::render('main/support');
+ }
+
+ public static function tracker()
+ {
+ // Set parse variables
+ Template::vars([
+ 'tracker' => Utils::getPremiumTrackerData(),
+ ]);
+
+ // Print page contents
+ return Template::render('main/supporttracker');
+ }
+}
diff --git a/libraries/Forum/Post.php b/libraries/Forum/Post.php
index d198512..45dd3f4 100644
--- a/libraries/Forum/Post.php
+++ b/libraries/Forum/Post.php
@@ -173,7 +173,7 @@ class Post
'topic_id' => $thread->id,
'forum_id' => $thread->forum,
'poster_id' => $poster->id,
- 'poster_ip' => Utils::getRemoteIP(),
+ 'poster_ip' => Net::IP(),
'post_time' => time(),
'post_subject' => $subject,
'post_text' => $text,
diff --git a/libraries/Net.php b/libraries/Net.php
index f8f42d7..7cd83e9 100644
--- a/libraries/Net.php
+++ b/libraries/Net.php
@@ -13,7 +13,8 @@ namespace Sakura;
* @package Sakura
* @author Julian van de Groep
*/
-class Net {
+class Net
+{
/**
* Returns the connecting IP.
*
diff --git a/libraries/Utils.php b/libraries/Utils.php
index 7324c3e..6ef6fdb 100644
--- a/libraries/Utils.php
+++ b/libraries/Utils.php
@@ -17,31 +17,6 @@ use PHPMailer;
*/
class Utils
{
- /**
- * Parse the emoticons.
- *
- * @param string $text String to parse emoticons from.
- *
- * @return string Parsed text.
- */
- public static function parseEmotes($text)
- {
- // Get emoticons from the database
- $emotes = Database::fetch('emoticons');
-
- // Do the replacements
- foreach ($emotes as $emote) {
- $text = str_replace(
- $emote['emote_string'],
- '',
- $text
- );
- }
-
- // Return the parsed text
- return $text;
- }
-
/**
* Verify a ReCaptcha
*
diff --git a/public/support.php b/public/support.php
deleted file mode 100644
index 75e4e39..0000000
--- a/public/support.php
+++ /dev/null
@@ -1,165 +0,0 @@
-permission(Site::OBTAIN_PREMIUM)) {
- // Initialise Payments class
- if (!Payments::init()) {
- header('Location: ' . $urls->format('SITE_PREMIUM') . '?fail=true');
- } else {
- switch ($_REQUEST['mode']) {
- // Create the purchase
- case 'purchase':
- // Compare time and session so we know the link isn't forged
- if (!isset($_REQUEST['time'])
- || $_REQUEST['time'] < time() - 1000) {
- header('Location: ' . $urls->format('SITE_PREMIUM') . '?fail=true');
- break;
- }
-
- // Match session ids for the same reason
- if (!isset($_REQUEST['session'])
- || $_REQUEST['session'] != session_id()) {
- header('Location: ' . $urls->format('SITE_PREMIUM') . '?fail=true');
- break;
- }
-
- // Half if shit isn't gucci
- if (!isset($_POST['months'])
- || !is_numeric($_POST['months'])
- || (int) $_POST['months'] < 1
- || (int) $_POST['months'] > Config::get('premium_amount_max')) {
- header('Location: ' . $urls->format('SITE_PREMIUM') . '?fail=true');
- } else {
- // Calculate the total
- $total = (float) Config::get('premium_price_per_month') * (int) $_POST['months'];
- $total = number_format($total, 2, '.', '');
-
- // Generate item name
- $itemName = Config::get('sitename')
- . ' Premium - '
- . (string) $_POST['months']
- . ' month'
- . ((int) $_POST['months'] == 1 ? '' : 's');
-
- // Attempt to create a transaction
- if ($transaction = Payments::createTransaction(
- $total,
- $itemName,
- Config::get('sitename') . ' Premium Purchase',
- 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . Config::get('url_main') . $urls->format('SITE_PREMIUM')
- )) {
- // Store the amount of months in the global session array
- $_SESSION['premiumMonths'] = (int) $_POST['months'];
-
- header('Location: ' . $transaction);
- exit;
- } else {
- header('Location: ' . $urls->format('SITE_PREMIUM') . '?fail=true');
- }
- }
-
- break;
-
- // Finalising the purchase
- case 'finish':
- // Check if the success GET request is set and is true
- if (isset($_GET['success'])
- && isset($_GET['paymentId'])
- && isset($_GET['PayerID'])
- && isset($_SESSION['premiumMonths'])) {
- // Attempt to complete the transaction
- try {
- $finalise = Payments::completeTransaction($_GET['paymentId'], $_GET['PayerID']);
- } catch (Exception $e) {
- trigger_error('Something went horribly wrong.', E_USER_ERROR);
- }
-
- // Attempt to complete the transaction
- if ($finalise) {
- // Make the user premium
- $expiration = Users::addUserPremium($currentUser->id, (2628000 * $_SESSION['premiumMonths']));
- Users::updatePremiumMeta($currentUser->id);
- Utils::updatePremiumTracker(
- $currentUser->id,
- ((float) Config::get('premium_price_per_month') * $_SESSION['premiumMonths']),
- $currentUser->username
- . ' bought premium for '
- . $_SESSION['premiumMonths']
- . ' month'
- . ($_SESSION['premiumMonths'] == 1 ? '' : 's')
- . '.'
- );
-
- // Redirect to the complete
- header('Location: ' . $urls->format('SITE_PREMIUM') . '?mode=complete');
- exit;
- }
- }
-
- header('Location: ' . $urls->format('SITE_PREMIUM') . '?fail=true');
- break;
-
- case 'complete':
- $renderData = array_merge([
- 'page' => [
- 'expiration' => ($prem = $currentUser->isPremium()[2]) !== null ? $prem : 0,
- ],
- ], $renderData);
-
- // Set parse variables
- Template::vars($renderData);
-
- // Print page contents
- echo Template::render('main/premiumcomplete');
- break;
-
- default:
- header('Location: ' . $urls->format('SITE_PREMIUM'));
- break;
-
- }
- }
-
- exit;
-}
-
-// Premium tracker
-if (isset($_GET['tracker'])) {
- $renderData['tracker'] = Utils::getPremiumTrackerData();
-
- // Set parse variables
- Template::vars($renderData);
-
- // Print page contents
- echo Template::render('main/supporttracker');
- exit;
-}
-
-// Set default variables
-$renderData['page'] = [
-
- 'fail' => isset($_GET['fail']),
- 'price' => Config::get('premium_price_per_month'),
- 'current' => $currentUser->isPremium(),
- 'amount_max' => Config::get('premium_amount_max'),
-
-];
-
-// Set parse variables
-Template::vars($renderData);
-
-// Print page contents
-echo Template::render('main/support');
diff --git a/routes.php b/routes.php
index fa6f415..375d55c 100644
--- a/routes.php
+++ b/routes.php
@@ -31,6 +31,10 @@ Router::get('/members/{rank}', 'Sakura\Controllers\User@members', 'members.rank'
// User
Router::get('/u/{id}', 'Sakura\Controllers\User@profile', 'user.profile');
+// Premium
+Router::get('/support', 'Sakura\Controllers\Premium@index', 'premium.index');
+Router::get('/support/tracker', 'Sakura\Controllers\Premium@tracker', 'premium.tracker');
+
// Redirections
Router::any('/index.php', function () {
// Info pages
@@ -117,6 +121,15 @@ Router::any('/viewforum.php', function () {
header('Location: /forum/');
});
+Router::any('/support.php', function () {
+ if (isset($_GET['tracker'])) {
+ header('Location: /support/tracker');
+ return;
+ }
+
+ header('Location: /support');
+});
+
Router::any('/faq.php', function () {
header('Location: /faq');
});
diff --git a/sakura.php b/sakura.php
index 617254a..9c6e069 100644
--- a/sakura.php
+++ b/sakura.php
@@ -35,40 +35,17 @@ if (!@include_once ROOT . 'vendor/autoload.php') {
die('Autoloader not found, did you run composer?');
}
-// Include core libraries
-require_once ROOT . 'libraries/ActionCode.php';
-require_once ROOT . 'libraries/Bans.php';
-require_once ROOT . 'libraries/BBcode.php';
-require_once ROOT . 'libraries/Comments.php';
-require_once ROOT . 'libraries/Config.php';
-require_once ROOT . 'libraries/CSRF.php';
-require_once ROOT . 'libraries/Database.php';
-require_once ROOT . 'libraries/File.php';
-require_once ROOT . 'libraries/Hashing.php';
-require_once ROOT . 'libraries/Net.php';
-require_once ROOT . 'libraries/News.php';
-require_once ROOT . 'libraries/Payments.php';
-require_once ROOT . 'libraries/Perms.php';
-require_once ROOT . 'libraries/Rank.php';
-require_once ROOT . 'libraries/Router.php';
-require_once ROOT . 'libraries/Session.php';
-require_once ROOT . 'libraries/Template.php';
-require_once ROOT . 'libraries/Trick.php';
-require_once ROOT . 'libraries/Urls.php';
-require_once ROOT . 'libraries/User.php';
-require_once ROOT . 'libraries/Users.php';
-require_once ROOT . 'libraries/Utils.php';
-require_once ROOT . 'libraries/Console/Application.php';
-require_once ROOT . 'libraries/Controllers/Auth.php';
-require_once ROOT . 'libraries/Controllers/Forums.php';
-require_once ROOT . 'libraries/Controllers/Meta.php';
-require_once ROOT . 'libraries/Controllers/User.php';
-require_once ROOT . 'libraries/Forum/Forum.php';
-require_once ROOT . 'libraries/Forum/Post.php';
-require_once ROOT . 'libraries/Forum/Thread.php';
-require_once ROOT . 'libraries/Perms/Forum.php';
-require_once ROOT . 'libraries/Perms/Manage.php';
-require_once ROOT . 'libraries/Perms/Site.php';
+// Setup the autoloader
+spl_autoload_register(function ($className) {
+ // Create a throwaway count variable
+ $i = 1;
+
+ // Replace the sakura namespace with the libraries directory
+ $className = str_replace('Sakura\\', 'libraries/', $className, $i);
+
+ // Require the file
+ require_once ROOT . $className . '.php';
+});
// Include database extensions
foreach (glob(ROOT . 'libraries/DBWrapper/*.php') as $driver) {