More premium things

This commit is contained in:
flash 2015-07-01 16:29:12 +02:00
parent 2afb1bdc12
commit a1b1999c44
11 changed files with 259 additions and 65 deletions

View file

@ -16,7 +16,7 @@ CREATE TABLE `sakura_actioncodes` (
`actkey` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'The URL key for using this code.',
`instruction` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Things the backend should do upon using this code',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
DROP TABLE IF EXISTS `sakura_apikeys`;
@ -52,7 +52,7 @@ CREATE TABLE `sakura_bbcodes` (
`replace` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'What to replace it with.',
`description` varchar(512) COLLATE utf8_bin NOT NULL COMMENT 'Description of what this does.',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
DROP TABLE IF EXISTS `sakura_config`;
@ -69,7 +69,7 @@ CREATE TABLE `sakura_faq` (
`question` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'The question.',
`answer` text COLLATE utf8_bin NOT NULL COMMENT 'The answer.',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
DROP TABLE IF EXISTS `sakura_forums`;
@ -86,7 +86,7 @@ CREATE TABLE `sakura_forums` (
`forum_last_poster_id` bigint(255) unsigned NOT NULL DEFAULT '0' COMMENT 'ID of last poster in forum.',
`forum_icon` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Display icon for the forum.',
PRIMARY KEY (`forum_id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
DROP TABLE IF EXISTS `sakura_friends`;
@ -118,7 +118,7 @@ CREATE TABLE `sakura_logs` (
PRIMARY KEY (`id`),
KEY `uid` (`uid`),
CONSTRAINT `sakura_logs_ibfk_1` FOREIGN KEY (`uid`) REFERENCES `sakura_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
DROP TABLE IF EXISTS `sakura_logtypes`;
@ -139,7 +139,7 @@ CREATE TABLE `sakura_messages` (
`subject` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Title of the message',
`content` text COLLATE utf8_bin NOT NULL COMMENT 'Contents of the message.',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
DROP TABLE IF EXISTS `sakura_news`;
@ -150,7 +150,7 @@ CREATE TABLE `sakura_news` (
`title` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Title of the post.',
`content` text COLLATE utf8_bin NOT NULL COMMENT 'Contents of the post',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
DROP TABLE IF EXISTS `sakura_notifications`;
@ -168,7 +168,7 @@ CREATE TABLE `sakura_notifications` (
PRIMARY KEY (`id`),
KEY `uid` (`uid`),
CONSTRAINT `sakura_notifications_ibfk_1` FOREIGN KEY (`uid`) REFERENCES `sakura_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=65 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
DROP TABLE IF EXISTS `sakura_permissions`;
@ -200,18 +200,21 @@ CREATE TABLE `sakura_posts` (
PRIMARY KEY (`post_id`),
KEY `topic_id` (`topic_id`),
KEY `forum_id` (`forum_id`),
CONSTRAINT `sakura_posts_ibfk_2` FOREIGN KEY (`forum_id`) REFERENCES `sakura_forums` (`forum_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `sakura_posts_ibfk_1` FOREIGN KEY (`topic_id`) REFERENCES `sakura_topics` (`topic_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
KEY `poster_id` (`poster_id`),
CONSTRAINT `sakura_posts_ibfk_3` FOREIGN KEY (`poster_id`) REFERENCES `sakura_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `sakura_posts_ibfk_1` FOREIGN KEY (`topic_id`) REFERENCES `sakura_topics` (`topic_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `sakura_posts_ibfk_2` FOREIGN KEY (`forum_id`) REFERENCES `sakura_forums` (`forum_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
DROP TABLE IF EXISTS `sakura_premium`;
CREATE TABLE `sakura_premium` (
`id` bigint(255) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Automatically generated ID by MySQL for management.',
`expiredate` int(16) unsigned NOT NULL COMMENT 'Expiration timestamp.',
`uid` bigint(255) unsigned NOT NULL COMMENT 'ID of the user that purchased Tenshi.',
`startdate` int(11) unsigned NOT NULL COMMENT 'Timestamp of first purchase.',
`expiredate` int(11) unsigned NOT NULL COMMENT 'Expiration timestamp.',
PRIMARY KEY (`id`),
KEY `uid` (`uid`),
UNIQUE KEY `uid` (`uid`),
CONSTRAINT `sakura_premium_ibfk_1` FOREIGN KEY (`uid`) REFERENCES `sakura_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
@ -226,7 +229,7 @@ CREATE TABLE `sakura_profilefields` (
`description` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Description of the field displayed in the control panel.',
`additional` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Undocumented JSON array containing special options if needed (probably only going to be used for the YouTube field).',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
DROP TABLE IF EXISTS `sakura_ranks`;
@ -238,7 +241,7 @@ CREATE TABLE `sakura_ranks` (
`description` text COLLATE utf8_bin NOT NULL COMMENT 'A description of what a user of this rank can do/is supposed to do.',
`title` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Default user title if user has none set.',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
DROP TABLE IF EXISTS `sakura_regcodes`;
@ -251,7 +254,7 @@ CREATE TABLE `sakura_regcodes` (
PRIMARY KEY (`id`),
KEY `created_by` (`created_by`),
CONSTRAINT `sakura_regcodes_ibfk_1` FOREIGN KEY (`created_by`) REFERENCES `sakura_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
DROP TABLE IF EXISTS `sakura_reports`;
@ -280,7 +283,7 @@ CREATE TABLE `sakura_sessions` (
PRIMARY KEY (`id`),
KEY `userid` (`userid`),
CONSTRAINT `sakura_sessions_ibfk_1` FOREIGN KEY (`userid`) REFERENCES `sakura_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=103 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
DROP TABLE IF EXISTS `sakura_sock_perms`;
@ -305,14 +308,16 @@ CREATE TABLE `sakura_topics` (
`topic_status` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT 'Status of topic.',
`topic_status_change` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Date the topic status was changed (used for deletion cooldown as well).',
`topic_type` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT 'Type of the topic.',
`topic_first_post_id` bigint(255) unsigned NOT NULL DEFAULT '0' COMMENT 'ID of first post made in this topic.',
`topic_first_poster_id` bigint(255) unsigned NOT NULL DEFAULT '0' COMMENT 'User ID of person who made the first post.',
`topic_last_post_id` bigint(255) unsigned NOT NULL DEFAULT '0' COMMENT 'ID of last post made in this topic.',
`topic_last_poster_id` bigint(255) unsigned NOT NULL DEFAULT '0' COMMENT 'User ID of person who made the last post.',
`topic_first_post_id` bigint(255) unsigned DEFAULT NULL COMMENT 'ID of first post made in this topic.',
`topic_first_poster_id` bigint(255) unsigned DEFAULT NULL COMMENT 'User ID of person who made the first post.',
`topic_last_post_id` bigint(255) unsigned DEFAULT NULL COMMENT 'ID of last post made in this topic.',
`topic_last_poster_id` bigint(255) unsigned DEFAULT NULL COMMENT 'User ID of person who made the last post.',
PRIMARY KEY (`topic_id`),
KEY `forum_id` (`forum_id`),
KEY `topic_first_poster_id` (`topic_first_poster_id`),
KEY `topic_last_poster_id` (`topic_last_poster_id`),
CONSTRAINT `sakura_topics_ibfk_1` FOREIGN KEY (`forum_id`) REFERENCES `sakura_forums` (`forum_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
DROP TABLE IF EXISTS `sakura_users`;
@ -341,7 +346,7 @@ CREATE TABLE `sakura_users` (
`userData` varchar(512) COLLATE utf8_bin NOT NULL DEFAULT '[]' COMMENT 'All additional profile data.',
PRIMARY KEY (`id`),
UNIQUE KEY `username_clean` (`username_clean`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
DROP TABLE IF EXISTS `sakura_warnings`;
@ -357,7 +362,7 @@ CREATE TABLE `sakura_warnings` (
KEY `iid` (`iid`),
CONSTRAINT `sakura_warnings_ibfk_2` FOREIGN KEY (`iid`) REFERENCES `sakura_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `sakura_warnings_ibfk_1` FOREIGN KEY (`uid`) REFERENCES `sakura_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
DROP TABLE IF EXISTS `sock_banned_users`;
@ -379,7 +384,7 @@ CREATE TABLE `sock_channels` (
`priv` int(11) DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`chname`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS `sock_logs`;
@ -394,7 +399,7 @@ CREATE TABLE `sock_logs` (
`message` longtext NOT NULL,
`flags` varchar(10) NOT NULL DEFAULT '10010',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=49 DEFAULT CHARSET=latin1;
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS `sock_online_users`;
@ -407,4 +412,4 @@ CREATE TABLE `sock_online_users` (
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- 2015-07-01 00:56:09
-- 2015-07-01 14:27:30

View file

@ -1385,6 +1385,10 @@
{
"type": "FIX",
"change": "Fixed a multitude of fuckups."
},
{
"type": "ADD",
"change": "Added automatic rank management for premium."
}
]

View file

@ -214,7 +214,7 @@ class Forum {
'user' => ($_POSTER = Users::getUser($post['poster_id'])),
'rank' => Users::getRank($_POSTER['rank_main']),
'country' => Main::getCountryName($_POSTER['country']),
'is_tenshi' => Users::checkUserTenshi($_POSTER['id']),
'is_premium' => Users::checkUserPremium($_POSTER['id'])[0],
'is_online' => Users::checkUserOnline($_POSTER['id']),
'is_friend' => Users::checkFriend($_POSTER['id']),
'parsed_post' => self::parseMarkUp($post['post_text'], $post['parse_mode']),

View file

@ -89,6 +89,9 @@ class Users {
]
]);
// Update the premium meta
Users::updatePremiumMeta($uid);
// Redirect people that need to change their password to the new format
if(self::getUser($uid)['password_algo'] == 'legacy' && $_SERVER['PHP_SELF'] != '/authenticate.php' && $_SERVER['PHP_SELF'] != '/imageserve.php')
header('Location: /authenticate.php?legacy=true');
@ -130,7 +133,7 @@ class Users {
$user['password_salt'],
$user['password_hash']
]))
return [0, 'INCORRECT_PASSWORD'];
return [0, 'INCORRECT_PASSWORD', $user['password_chan']];
}
@ -652,6 +655,106 @@ class Users {
}
// Set the default rank of a user
public static function setDefaultRank($uid, $rid, $userIdIsUserData = false) {
// Get the specified user
$user = $userIdIsUserData ? $uid : self::getUser($uid);
// Decode the json
$ranks = json_decode($user['ranks'], true);
// Check if the rank we're trying to set is actually there
if(!in_array($rid, $ranks))
return false;
// Update the row
Database::update('users', [
[
'rank_main' => $rid
],
[
'id' => [$uid, '=']
]
]);
// Return true if everything was successful
return true;
}
// Add a rank to a user
public static function addRanksToUser($ranks, $uid, $userIdIsUserData = false) {
// Get the specified user
$user = $userIdIsUserData ? $uid : self::getUser($uid);
// Decode the array
$current = json_decode($user['ranks'], true);
// Go over all the new ranks
foreach($ranks as $rank) {
// Check if the user already has this rank and set it if not
if(!in_array($rank, $current))
$current[] = (int)$rank;
}
// Encode the array
$current = json_encode($current);
// Update the row
Database::update('users', [
[
'ranks' => $current
],
[
'id' => [$uid, '=']
]
]);
// Return true because
return true;
}
// Removing ranks from a user
public static function removeRanksFromUser($ranks, $uid, $userIdIsUserData = false) {
// Get the specified user
$user = $userIdIsUserData ? $uid : self::getUser($uid);
// Get the ranks
$current = json_decode($user['ranks'], true);
// Check the current ranks for ranks in the set array
foreach($current as $key => $rank) {
// Unset the rank
if(in_array($rank, $ranks))
unset($current[$key]);
}
// Encode the array
$current = json_encode($current);
// Update the row
Database::update('users', [
[
'ranks' => $current
],
[
'id' => [$uid, '=']
]
]);
// Return true
return true;
}
// Check if a user has these ranks
public static function checkIfUserHasRanks($ranks, $userid, $userIdIsUserData = false) {
@ -851,12 +954,105 @@ class Users {
}
// Add premium to
// Add premium to a user
public static function addUserPremium($id, $seconds) {
// Check if user has Premium [ REWRITE THIS ]
// Check if there's already a record of premium for this user in the database
$getUser = Database::fetch('premium', false, [
'uid' => [$id, '=']
]);
// Calculate the (new) start and expiration timestamp
$start = isset($getUser['startdate']) ? $getUser['startdate'] : time();
$expire = isset($getUser['expiredate']) ? $getUser['expiredate'] + $seconds : time() + $seconds;
// If the user already exists do an update call, otherwise an insert call
if(empty($getUser)) {
Database::insert('premium', [
'uid' => $id,
'startdate' => $start,
'expiredate' => $expire
]);
} else {
Database::update('premium', [
[
'expiredate' => $expire
],
[
'uid' => [$id, '=']
]
]);
}
// Return the expiration timestamp
return $expire;
}
// Remove the premium status of a user
public static function removeUserPremium($id) {
Database::delete('premium', [
'uid' => [$id, '=']
]);
}
// Check if user has Premium
public static function checkUserPremium($id) {
return false;
// Attempt to retrieve the premium record from the database
$getRecord = Database::fetch('premium', false, [
'uid' => [$id, '=']
]);
// If nothing was returned just return false
if(empty($getRecord))
return [0];
// Check if the Tenshi hasn't expired
if($getRecord['expiredate'] < time()) {
self::removeUserPremium($id);
self::updatePremiumMeta($id);
return [0, $getRecord['startdate'], $getRecord['expiredate']];
}
// Else return the start and expiration date
return [1, $getRecord['startdate'], $getRecord['expiredate']];
}
// Update the premium data
public static function updatePremiumMeta($id) {
// Get the ID for the premium user rank from the database
$premiumRank = Configuration::getConfig('premium_rank_id');
// Run the check
$check = self::checkUserPremium($id);
// Check if the user has premium
if($check[0] == 1) {
// If so add the rank to them
self::addRanksToUser([$premiumRank], $id);
// Check if the user's default rank is standard user and update it to premium
if(self::getUser($id)['rank_main'] == 2)
self::setDefaultRank($id, $premiumRank);
} elseif($check[0] == 0 && count($check) > 1) {
// Else remove the rank from them
self::removeRanksFromUser([$premiumRank], $id);
}
}

View file

@ -2,5 +2,6 @@
<div class="content standalone" style="text-align: center;">
<h1 class="stylised" style="margin: 1em auto;">Thank you for your contribution!</h1>
<h1 class="fa fa-heart stylised" style="font-size: 20em;"></h1>
<h3>Your Tenshi will expire on {{ page.expiration|date("l \\t\\h\\e jS F o") }}.</h3>
</div>
{% include 'global/footer.tpl' %}

View file

@ -11,7 +11,7 @@
<img src="/a/{{ post.user.id }}" alt="{{ post.user.username }}" class="avatar" style="box-shadow: 0 3px 7px #{% if post.is_online %}484{% else %}844{% endif %};" />
<div class="userdata">
<div class="usertitle">{% if not post.user.usertitle %}{{ post.rank.title }}{% else %}{{ post.user.usertitle }}{% endif %}</div>
<img src="//{{ sakura.urls.content }}/images/tenshi.png" alt="Tenshi"{% if not post.is_tenshi %} style="opacity: 0;"{% endif %} /> <img src="//{{ sakura.urls.content }}/images/flags/{% if post.user.country|lower == 'eu' %}europeanunion{% else %}{{ post.user.country|lower }}{% endif %}.png" alt="{{ post.country }}" />
<img src="//{{ sakura.urls.content }}/images/tenshi.png" alt="Tenshi"{% if not post.is_premium %} style="opacity: 0;"{% endif %} /> <img src="//{{ sakura.urls.content }}/images/flags/{% if post.user.country|lower == 'eu' %}europeanunion{% else %}{{ post.user.country|lower }}{% endif %}.png" alt="{{ post.country }}" />
<div class="actions">
{% if user.data.id == post.user.id %}
<a class="fa fa-pencil-square-o" title="Edit this post" href="#"></a>

View file

@ -19,7 +19,7 @@
<br /><span style="font-size: .8em;">{{ profile.ranktitle }}</span>
<h1 style="color: {{ profile.colour }}; text-shadow: 0 0 7px #888; padding: 0 0 2px;">{{ profile.user.username }}</h1>
{% if profile.user.rank_main > 1 %}
{% if profile.istenshi %}<img src="//{{ sakura.urls.content }}/images/tenshi.png" alt="Tenshi" /> {% endif %}<img src="//{{ sakura.urls.content }}/images/flags/{% if profile.user.country|lower == 'eu' %}europeanunion{% else %}{{ profile.user.country|lower }}{% endif %}.png" alt="{{ profile.user.country }}" /> <span style="font-size: .9em; line-height: 11px;">{{ profile.country }}</span>
{% if profile.is_premium %}<img src="//{{ sakura.urls.content }}/images/tenshi.png" alt="Tenshi" /> {% endif %}<img src="//{{ sakura.urls.content }}/images/flags/{% if profile.user.country|lower == 'eu' %}europeanunion{% else %}{{ profile.user.country|lower }}{% endif %}.png" alt="{{ profile.user.country }}" /> <span style="font-size: .9em; line-height: 11px;">{{ profile.country }}</span>
{% if user.checklogin %}
<div class="user-actions">
{% if user.data.id == profile.user.id %}

View file

@ -18,7 +18,7 @@ RewriteRule ^feedback/?$ https://github.com/circlestorm/Sakura/issues [L,QSA]
RewriteRule ^credits/?$ credits.php [L,QSA]
RewriteRule ^index/?$ index.php [L,QSA]
RewriteRule ^login/?$|^logout/?$|^activate/?$|^register/?$|^forgotpassword/?|^authenticate/?$ authenticate.php [L,QSA]
RewriteRule ^donate/?$|^support/?$ donate.php [L,QSA]
RewriteRule ^donate/?$|^support/?$ support.php [L,QSA]
RewriteRule ^contact/?$ infopage.php?r=contact [L,QSA]
RewriteRule ^changelog/?$ changelog.php [L,QSA]
RewriteRule ^faq/?$ faq.php [L,QSA]

View file

@ -19,8 +19,8 @@ if(isset($_GET['u'])) {
'colour' => ($_PROFILE_USER_DATA['name_colour'] == null ? $_PROFILE_RANK_DATA['colour'] : $_PROFILE_USER_DATA['name_colour']),
'ranktitle' => ($_PROFILE_USER_DATA['usertitle'] == null ? $_PROFILE_RANK_DATA['title'] : $_PROFILE_USER_DATA['usertitle']),
'country' => Main::getCountryName($_PROFILE_USER_DATA['country']),
'istenshi' => Users::checkUserPremium($_PROFILE_USER_DATA['id']),
'online' => Users::checkUserOnline($_PROFILE_USER_DATA['id']),
'is_premium' => Users::checkUserPremium($_PROFILE_USER_DATA['id'])[0],
'is_online' => Users::checkUserOnline($_PROFILE_USER_DATA['id']),
'profilePage' => Users::getProfilePage($_PROFILE_USER_DATA['userData'], true),
'fields' => Users::getUserProfileFields($_PROFILE_USER_DATA['userData'], true),
'warnings' => Users::getWarnings($_PROFILE_USER_DATA['id']),

View file

@ -15,11 +15,7 @@ if(isset($_REQUEST['mode']) && Users::checkLogin() && Permissions::check('SITE',
// Initialise Payments class
if(!Payments::init()) {
$renderData['page'] = [
'title' => 'Action failed',
'redirect' => '/support',
'message' => 'Failed to initialise the Payment handling components, contact a staff member as soon as possible.'
];
header('Location: /support?fail=true');
} else {
@ -31,12 +27,7 @@ if(isset($_REQUEST['mode']) && Users::checkLogin() && Permissions::check('SITE',
// Compare time and session so we know the link isn't forged
if(!isset($_REQUEST['time']) || $_REQUEST['time'] < time() - 1000) {
$renderData['page'] = [
'title' => 'Action failed',
'redirect' => '/support',
'message' => 'Timestamps differ too much, refresh the page and try again.'
];
header('Location: /support?fail=true');
break;
}
@ -44,12 +35,7 @@ if(isset($_REQUEST['mode']) && Users::checkLogin() && Permissions::check('SITE',
// Match session ids for the same reason
if(!isset($_REQUEST['session']) || $_REQUEST['session'] != session_id()) {
$renderData['page'] = [
'title' => 'Action failed',
'redirect' => '/support',
'message' => 'Invalid session, please try again.'
];
header('Location: /support?fail=true');
break;
}
@ -79,12 +65,7 @@ if(isset($_REQUEST['mode']) && Users::checkLogin() && Permissions::check('SITE',
} else {
// Add page specific things
$renderData['page'] = [
'title' => 'Information',
'redirect' => '/support',
'message' => 'An error has occurred while trying to create the transaction, try again later.'
];
header('Location: /support?fail=true');
}
@ -99,12 +80,19 @@ if(isset($_REQUEST['mode']) && Users::checkLogin() && Permissions::check('SITE',
if(isset($_GET['success']) && isset($_GET['paymentId']) && isset($_GET['PayerID']) && isset($_SESSION['premiumMonths'])) {
// Attempt to complete the transaction
if(Payments::completeTransaction($_GET['paymentId'], $_GET['PayerID'])) {
try{
$finalise = Payments::completeTransaction($_GET['paymentId'], $_GET['PayerID']);
} catch(Exception $e) {}
// execution of tenshification here
// Attempt to complete the transaction
if($finalise) {
// Make the user premium
$expiration = Users::addUserPremium(Session::$userId, (2628000 * $_SESSION['premiumMonths']));
Users::updatePremiumMeta(Session::$userId);
// Redirect to the complete
header('Location: ?mode=complete');
header('Location: ?mode=complete&expire='. $expiration);
exit;
}
@ -115,7 +103,7 @@ if(isset($_REQUEST['mode']) && Users::checkLogin() && Permissions::check('SITE',
break;
case 'complete':
print Templates::render('errors/premiumComplete.tpl', array_merge(['page' => ['title' => 'Premium purchase complete!']], $renderData));
print Templates::render('errors/premiumComplete.tpl', array_merge(['page' => ['title' => 'Premium purchase complete!', 'expiration' => isset($_GET['expire']) ? $_GET['expire'] : 0]], $renderData));
break;
default:
@ -189,4 +177,4 @@ $renderData['page'] = [
];
// Print page contents
print Templates::render('main/donate.tpl', $renderData);
print Templates::render('main/support.tpl', $renderData);