more meows

This commit is contained in:
flash 2016-02-13 14:36:21 +01:00
parent 72ebb6898a
commit 9b135ba9b6
9 changed files with 220 additions and 228 deletions

View file

@ -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 = "<img src='{$emote['emote_path']}' alt='{$emote['emote_string']}' class='emoticon' />";
$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;
}

View file

@ -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']);

View file

@ -0,0 +1,168 @@
<?php
/**
* Holds the premium pages controllers.
*
* @package Sakura
*/
namespace Sakura\Controllers;
use Sakura\Config;
use Sakura\Database;
use Sakura\News;
use Sakura\Template;
use Sakura\User;
use Sakura\Users;
use Sakura\Utils;
use Sakura\Payments;
use Sakura\Perms\Site;
/**
* Premium pages controller.
*
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
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');
}
}

View file

@ -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,

View file

@ -13,7 +13,8 @@ namespace Sakura;
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class Net {
class Net
{
/**
* Returns the connecting IP.
*

View file

@ -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'],
'<img src="' . $emote['emote_path'] . '" class="emoticon" alt="' . $emote['emote_string'] . '" />',
$text
);
}
// Return the parsed text
return $text;
}
/**
* Verify a ReCaptcha
*

View file

@ -1,165 +0,0 @@
<?php
/*
* Sakura Support/Donate page
*/
// Declare Namespace
namespace Sakura;
use Sakura\Perms\Site;
// Include components
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . 'sakura.php';
// 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) {
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');

View file

@ -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');
});

View file

@ -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) {