half database update and other shit

This commit is contained in:
flash 2016-02-25 17:06:29 +01:00
parent 562294412a
commit bca6c5be99
30 changed files with 827 additions and 1328 deletions

View file

@ -1,4 +1,12 @@
{
"name": "flashwave/sakura",
"description": "Flashii's backend",
"license": "Apache-2.0",
"homepage": "https://sakura.flash.moe",
"support": {
"email": "me@flash.moe",
"issues": "https://github.com/flashwave/sakura/issues"
},
"require": {
"php": ">=5.4.0",
"ext-curl": "*",
@ -7,7 +15,8 @@
"phpmailer/phpmailer": "*",
"paypal/rest-api-sdk-php": "*",
"jbbcode/jbbcode": "*",
"corneltek/cliframework": "*",
"phroute/phroute": "^2.1"
"corneltek/cliframework": "*",
"phroute/phroute": "^2.1",
"illuminate/database": "5.2.7"
}
}

View file

@ -21,23 +21,21 @@ define('SAKURA_NO_TPL', true);
require_once 'sakura.php';
// Clean expired sessions
$cleanSessions = DB::prepare('DELETE FROM `{prefix}sessions` WHERE `session_expire` < :time AND `session_remember` != 1');
$cleanSessions->execute([
'time' => time(),
]);
DB::table('sessions')
->where('session_expire', '<', time())
->where('session_remember', '!=', 1)
->delete();
// Delete notifications that are older than a month but not unread
$cleanAlerts = DB::prepare('DELETE FROM `{prefix}notifications` WHERE `alert_timestamp` < :time AND `alert_read` = 1');
$cleanAlerts->execute([
'time' => (time() - 109500),
]);
DB::table('notifications')
->where('alert_timestamp', '<', (time() - 109500))
->where('alert_read', 1)
->delete();
// Get expired premium accounts
$expiredPremium = DB::prepare('SELECT * FROM `{prefix}premium` WHERE `premium_expire` < :time');
$expiredPremium->execute([
'time' => time(),
]);
$expiredPremium = $expiredPremium->fetchAll();
$expiredPremium = DB::table('premium')
->where('premium_expire', '<', time())
->get();
// Process expired premium accounts, make this not stupid in the future
foreach ($expiredPremium as $expired) {

View file

@ -1,219 +0,0 @@
-- phpMyAdmin SQL Dump
-- version 4.5.2
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Dec 24, 2015 at 04:59 PM
-- Server version: 5.7.10-log
-- PHP Version: 7.0.1
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `sakura-development`
--
CREATE DATABASE IF NOT EXISTS `sakura-development` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
USE `sakura-development`;
--
-- Dumping data for table `sakura_config`
--
INSERT INTO `sakura_config` (`config_name`, `config_value`) VALUES
('admin_email', 'sakura@localhost'),
('alumni_rank_id', '9'),
('avatar_max_fsize', '2097152'),
('avatar_max_height', '512'),
('avatar_max_width', '512'),
('avatar_min_height', '20'),
('avatar_min_width', '20'),
('background_max_fsize', '5242880'),
('background_max_height', '1440'),
('background_max_width', '2560'),
('background_min_height', '16'),
('background_min_width', '16'),
('banned_avatar_img', 'public/content/data/{{ TPL }}/images/banned-av.png'),
('charset', 'utf-8'),
('comment_max_length', '500'),
('comment_min_length', '1'),
('content_path', '/content'),
('cookie_domain', 'flashii.test'),
('cookie_path', '/'),
('cookie_prefix', 'sakura_'),
('date_format', 'D Y-m-d H:i:s T'),
('deactivated_avatar_img', 'public/content/data/{{ TPL }}/images/deactivated-av.png'),
('disable_registration', '0'),
('enable_tpl_cache', '0'),
('forum_text_max', '60000'),
('forum_text_min', '1'),
('forum_title_max', '128'),
('forum_title_min', '4'),
('front_page_news_posts', '3'),
('header_announcement_image', ''),
('header_announcement_link', ''),
('lock_authentication', '0'),
('mail_signature', 'Team Flashii'),
('max_online_time', '120'),
('max_reg_keys', '5'),
('members_per_page', '30'),
('min_entropy', '1'),
('news_posts_per_page', '3'),
('no_avatar_img', 'public/content/data/{{ TPL }}/images/no-av.png'),
('no_background_img', 'public/content/pixel.png'),
('no_cron_interval', '30'),
('no_cron_last', '1450972327'),
('no_cron_service', '1'),
('no_header_img', 'public/content/images/default_header.png'),
('old_username_reserve', '90'),
('paypal_client_id', ''),
('paypal_secret', ''),
('pixel_img', 'public/content/pixel.png'),
('premium_amount_max', '24'),
('premium_price_per_month', '1.49'),
('premium_rank_id', '8'),
('recaptcha', '0'),
('recaptcha_private', ''),
('recaptcha_public', ''),
('require_activation', '0'),
('require_registration_code', '0'),
('session_check', '4'),
('site_closed', '0'),
('site_closed_reason', 'meow'),
('site_news_category', 'site-news'),
('site_style', 'yuuno'),
('sitedesc', 'Live development environment for the script that powers Flashii.net called Sakura.'),
('sitelogo', ''),
('sitename', 'Sakura'),
('sitetags', ''),
('smtp_auth', '1'),
('smtp_from_email', 'sakura@localhost'),
('smtp_from_name', 'Sakura No Reply'),
('smtp_password', ''),
('smtp_port', '587'),
('smtp_replyto_mail', 'sakura@localhost'),
('smtp_replyto_name', 'Sakura'),
('smtp_secure', 'tls'),
('smtp_server', ''),
('smtp_username', 'sakura@localhost'),
('url_main', 'flashii.test'),
('url_rewrite', '1'),
('use_gzip', '1'),
('user_uploads', 'uploads'),
('username_max_length', '16'),
('username_min_length', '3');
--
-- Dumping data for table `sakura_emoticons`
--
INSERT INTO `sakura_emoticons` (`emote_string`, `emote_path`) VALUES
(':amu:', '/content/images/emoticons/amu.png'),
(':angrier:', '/content/images/emoticons/angrier.png'),
(':angriest:', '/content/images/emoticons/angriest.png'),
(':angry:', '/content/images/emoticons/angry.gif'),
(':blank:', '/content/images/emoticons/blank.png'),
(':childish:', '/content/images/emoticons/childish.png'),
(':congrats:', '/content/images/emoticons/congrats.png'),
(':crying:', '/content/images/emoticons/crying.gif'),
(':dizzy:', '/content/images/emoticons/dizzy.gif'),
(':eat:', '/content/images/emoticons/eat.gif'),
(':evil:', '/content/images/emoticons/evil.png'),
(':extreme:', '/content/images/emoticons/extreme.png'),
(':glare:', '/content/images/emoticons/glare.gif'),
(':happy:', '/content/images/emoticons/happy.gif'),
(':horror:', '/content/images/emoticons/horror.gif'),
(':huh:', '/content/images/emoticons/huh.png'),
(':idea:', '/content/images/emoticons/idea.png'),
(':jew:', '/content/images/emoticons/jew.png'),
(':kiss:', '/content/images/emoticons/kiss.gif'),
(':lmao:', '/content/images/emoticons/lmao.gif'),
(':lol:', '/content/images/emoticons/lol.gif'),
(':love:', '/content/images/emoticons/love.png'),
(':meow:', '/content/images/emoticons/meow.png'),
(':omg:', '/content/images/emoticons/omg.gif'),
(':ouch:', '/content/images/emoticons/ouch.gif'),
(':puke:', '/content/images/emoticons/puke.gif'),
(':ruse:', '/content/images/emoticons/ruse.png'),
(':sad:', '/content/images/emoticons/sad.png'),
(':sigh:', '/content/images/emoticons/sigh.gif'),
(':suspicious:', '/content/images/emoticons/suspicious.gif'),
(':sweat:', '/content/images/emoticons/sweat.gif'),
(':tired:', '/content/images/emoticons/tired.gif'),
(':yay:', '/content/images/emoticons/vhappy.gif'),
(':winxp:', '/content/images/emoticons/winxp.png'),
(':wtf:', '/content/images/emoticons/wtf.gif'),
(':sleep:', '/content/images/emoticons/zzz.gif'),
(':what:', '/content/images/emoticons/what.png'),
(':smug:', '/content/images/emoticons/smug.png');
--
-- Dumping data for table `sakura_optionfields`
--
INSERT INTO `sakura_optionfields` (`option_id`, `option_name`, `option_description`, `option_type`, `option_permission`) VALUES
('disableProfileParallax', 'Disable Parallaxing', 'This will stop your background from responding to your mouse movement, this will only affect your background.', 'checkbox', 'CHANGE_BACKGROUND'),
('profileBackgroundSiteWide', 'Display profile background site wide', 'This will make the profile background you set on your profile appear on the entire site (except on other profiles).', 'checkbox', 'CREATE_BACKGROUND'),
('useMisaki', 'Use the testing style', 'This will make the site use the new Misaki style instead of Yuuno.', 'checkbox', 'ALTER_PROFILE');
--
-- Dumping data for table `sakura_permissions`
--
INSERT INTO `sakura_permissions` (`rank_id`, `user_id`, `permissions_site`, `permissions_manage`, `permissions_forums`, `permissions_inherit`) VALUES
(1, 0, '00000000000000000000000000000001', '00', '0', '000'),
(2, 0, '11110000111111111100111101101100', '00', '1', '000'),
(3, 0, '11110001111111111111111111111100', '11', '1', '000'),
(4, 0, '11110111111111111111111111111100', '11', '1', '000'),
(5, 0, '11110001111111111111111111111100', '11', '1', '000'),
(6, 0, '11110000111111111100111101101100', '00', '0', '000'),
(7, 0, '11110001111111111111111111111100', '01', '1', '000'),
(8, 0, '11110001111111111111111111111100', '00', '1', '000'),
(9, 0, '11110001111111111111111111111100', '00', '1', '000'),
(10, 0, '11110000000011010100101000100010', '00', '0', '000'),
(11, 0, '11110000111111111100111101101100', '00', '1', '000');
--
-- Dumping data for table `sakura_profilefields`
--
INSERT INTO `sakura_profilefields` (`field_id`, `field_name`, `field_type`, `field_link`, `field_linkformat`, `field_description`, `field_additional`) VALUES
(1, 'Website', 'url', 1, '{{ VAL }}', 'URL to your website', ''),
(2, 'Twitter', 'text', 1, 'https://twitter.com/{{ VAL }}', 'Your @twitter Username', ''),
(3, 'BitBucket', 'text', 1, 'https://bitbucket.org/{{ VAL }}', 'Your BitBucket Username', ''),
(4, 'Skype', 'text', 1, 'skype:{{ VAL }}?userinfo', 'Your Skype Username', ''),
(5, 'YouTube', 'text', 0, '', 'ID or Username excluding http://youtube.com/*/', '{"youtubetype": ["checkbox", "I <b>do not</b> have a Channel Username (url looks like https://www.youtube.com/channel/UCXZcw5hw5C7Neto-T_nRXBQ)."]}'),
(6, 'SoundCloud', 'text', 1, 'https://soundcloud.com/{{ VAL }}', 'Your SoundCloud username', ''),
(7, 'Steam', 'text', 1, 'https://steamcommunity.com/id/{{ VAL }}', 'Your Steam Community Username (may differ from login username)', ''),
(8, 'osu!', 'text', 1, 'https://osu.ppy.sh/u/{{ VAL }}', 'Your osu! Username', ''),
(9, 'Origin', 'text', 0, '', 'Your Origin User ID', ''),
(10, 'Xbox Live', 'text', 1, 'https://account.xbox.com/en-GB/Profile?Gamertag={{ VAL }}', 'Your Xbox User ID', ''),
(11, 'PSN', 'text', 1, 'http://psnprofiles.com/{{ VAL }}', 'Your PSN User ID', ''),
(12, 'Last.fm', 'text', 1, 'http://last.fm/user/{{ VAL }}', 'Your Last.fm username', '');
--
-- Dumping data for table `sakura_ranks`
--
INSERT INTO `sakura_ranks` (`rank_id`, `rank_hierarchy`, `rank_name`, `rank_multiple`, `rank_hidden`, `rank_colour`, `rank_description`, `rank_title`) VALUES
(1, 0, 'Deactivated', '', 1, '#555', 'Users that are yet to be activated or that deactivated their own account.', 'Deactivated'),
(2, 1, 'Regular user', 's', 0, 'inherit', 'Regular users with regular permissions.', 'Regular user'),
(3, 3, 'Site moderator', 's', 0, '#FA3703', 'Users with special permissions like being able to ban and modify users if needed.', 'Moderator'),
(4, 4, 'Administrator', 's', 0, '#824CA0', 'Users that manage the server and everything around that.', 'Administrator'),
(5, 3, 'Developer', 's', 0, '#6EAC0A', 'Users that either create or test new features of the site.', 'Developer'),
(6, 1, 'Bot', 's', 1, '#9E8DA7', 'Reserved user accounts for services.', 'Bot'),
(7, 2, 'Chat moderator', 's', 0, '#09F', 'Moderators of the chat room.', 'Moderator'),
(8, 1, 'Tenshi', '', 0, '#EE9400', 'Users that bought premium to help us keep the site and its services alive!', 'Tenshi'),
(9, 1, 'Alumnii', '', 0, '#FF69B4', 'People who have made big contributions to the community but have moved on.', 'Alumni'),
(10, 0, 'Restricted', '', 1, '#666', 'Users that are restricted.', 'Restricted'),
(11, 1, 'Early Supporter', 's', 0, '#0049EE', 'User that donated before the premium system.', 'Early Supporter');
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

File diff suppressed because it is too large Load diff

View file

@ -29,12 +29,10 @@ class ActionCode
$code = uniqid();
// Insert it
DB::prepare('INSERT INTO `{prefix}actioncodes` (`code_action`, `user_id`, `action_code`) VALUES (:action, :id, :code)')
->execute([
'action' => $action,
'id' => $user,
'code' => $code,
]);
DB::table('actioncodes')
->insert(
['action' => $action, 'id' => $user, 'code' => $code]
);
// Return the code
return $code;
@ -53,16 +51,14 @@ class ActionCode
public static function validate($action, $code, $user = 0, $invalidate = true)
{
// Fetch the code from the db
$get = DB::prepare('SELECT * FROM `{prefix}actioncodes` WHERE `code_action` = :code AND `action_code` = :action AND `user_id` = :id');
$get->execute([
'code' => $action,
'action' => $code,
'id' => $user,
]);
$get = $get->rowCount();
$get = DB::table('actioncodes')
->where('code_action', $action)
->where('action_code', $code)
->where('user_id', $user)
->count();
// Invalidate the code if requested
if ($invalidate) {
if ($get && $invalidate) {
self::invalidate($code);
}
@ -77,9 +73,8 @@ class ActionCode
*/
public static function invalidate($code)
{
DB::prepare('DELETE FROM `{prefix}actioncodes` WHERE `code_action` = :code')
->execute([
'code' => $code,
]);
DB::table('actioncodes')
->where('code_action', $code)
->delete();
}
}

View file

@ -48,9 +48,8 @@ class BBcode
public static function parseEmoticons($text)
{
// Get emoticons from the database
$emotes = DB::prepare('SELECT * FROM `{prefix}emoticons`');
$emotes->execute();
$emotes = $emotes->fetchAll();
$emotes = DB::table('emoticons')
->get();
// Parse all emoticons
foreach ($emotes as $emote) {

View file

@ -26,11 +26,9 @@ class Bans
{
// Attempt to get a ban from this user
$bans = DB::prepare('SELECT * FROM `{prefix}bans` WHERE `user_id` = :id');
$bans->execute([
'id' => $uid,
]);
$bans = $bans->fetchAll();
$bans = DB::table('bans')
->where('user_id', $uid)
->get();
// Reverse the array so new bans are listed first
$bans = array_reverse($bans);
@ -40,10 +38,9 @@ class Bans
// Check if it hasn't expired
if ($ban->ban_end != 0 && $ban->ban_end < time()) {
// If it has delete the entry and continue
DB::prepare('DELETE FROM `{prefix}bans` WHERE `ban_id` = :id')
->execute([
'id' => $ban->user_id,
]);
DB::table('bans')
->where('ban_id', $ban->ban_id)
->delete();
continue;
}

View file

@ -47,7 +47,7 @@ class Comments
$this->category = $category;
// Get the comments and assign them to $comments
$comments = DB::prepare('SELECT * FROM `{prefix}comments` WHERE `comment_category` = :category AND `comment_reply_to` = 0 ORDER BY `comment_id` DESC');
$comments = DBv2::prepare('SELECT * FROM `{prefix}comments` WHERE `comment_category` = :category AND `comment_reply_to` = 0 ORDER BY `comment_id` DESC');
$comments->execute([
'category' => $this->category,
]);
@ -96,7 +96,7 @@ class Comments
$this->count += 1;
// Attempt to get replies from the database
$replies = DB::prepare('SELECT * FROM `{prefix}comments` WHERE `comment_category` = :category AND `comment_reply_to` = :thread');
$replies = DBv2::prepare('SELECT * FROM `{prefix}comments` WHERE `comment_category` = :category AND `comment_reply_to` = :thread');
$replies->execute([
'category' => $this->category,
'thread' => $comment['comment_id'],
@ -123,7 +123,7 @@ class Comments
public function getComment($cid)
{
// Get from database
$comment = DB::prepare('SELECT * FROM `{prefix}comments` WHERE `comment_id` = :id');
$comment = DBv2::prepare('SELECT * FROM `{prefix}comments` WHERE `comment_id` = :id');
$comment->execute([
'id' => $cid,
]);
@ -140,7 +140,7 @@ class Comments
public function getVotes($cid)
{
// Get from database
$comment = DB::prepare('SELECT * FROM `{prefix}comment_votes` WHERE `vote_comment` = :id');
$comment = DBv2::prepare('SELECT * FROM `{prefix}comment_votes` WHERE `vote_comment` = :id');
$comment->execute([
'id' => $cid,
]);
@ -169,7 +169,7 @@ class Comments
}
// Insert into database
DB::prepare('INSERT INTO `{prefix}comments` (`comment_category`, `comment_timestamp`, `comment_poster`, `comment_reply_to`, `comment_text`) VALUES (:cat, :time, :user, :thread, :text)')
DBv2::prepare('INSERT INTO `{prefix}comments` (`comment_category`, `comment_timestamp`, `comment_poster`, `comment_reply_to`, `comment_text`) VALUES (:cat, :time, :user, :thread, :text)')
->execute([
'cat' => $this->category,
'time' => time(),
@ -194,7 +194,7 @@ class Comments
public function makeVote($uid, $cid, $mode)
{
// Attempt to get previous vote
$vote = DB::prepare('SELECT * FROM `{prefix}comment_votes` WHERE `vote_user` = :user AND `vote_comment` = :comment');
$vote = DBv2::prepare('SELECT * FROM `{prefix}comment_votes` WHERE `vote_user` = :user AND `vote_comment` = :comment');
$vote->execute([
'user' => $uid,
'comment' => $cid,
@ -206,14 +206,14 @@ class Comments
// Check if the vote that's being casted is the same
if ($vote['vote_state'] == $mode) {
// Delete the vote
DB::prepare('DELETE FROM `{prefix}comment_votes` WHERE `vote_user` = :user AND `vote_comment` = :comment')
DBv2::prepare('DELETE FROM `{prefix}comment_votes` WHERE `vote_user` = :user AND `vote_comment` = :comment')
->execute([
'user' => $uid,
'comment' => $cid,
]);
} else {
// Otherwise update the vote
DB::prepare('UPDATE `{prefix}comment_votes` SET `vote_state` = :state WHERE `vote_user` = :user AND `vote_comment` = :comment')
DBv2::prepare('UPDATE `{prefix}comment_votes` SET `vote_state` = :state WHERE `vote_user` = :user AND `vote_comment` = :comment')
->execute([
'state' => $mode,
'user' => $uid,
@ -222,7 +222,7 @@ class Comments
}
} else {
// Create a vote
DB::prepare('INSERT INTO `{prefix}comment_votes` (`vote_user`, `vote_comment`, `vote_state`) VALUES (:user, :comment, :state)')
DBv2::prepare('INSERT INTO `{prefix}comment_votes` (`vote_user`, `vote_comment`, `vote_state`) VALUES (:user, :comment, :state)')
->execute([
'user' => $uid,
'comment' => $cid,
@ -241,7 +241,7 @@ class Comments
public function removeComment($cid)
{
// Remove from database
DB::prepare('DELETE FROM `{prefix}comments` WHERE `comment_id` = :id')
DBv2::prepare('DELETE FROM `{prefix}comments` WHERE `comment_id` = :id')
->execute([
'id' => $cid,
]);

View file

@ -101,13 +101,14 @@ class Config
// Then return the value
return self::$database[$key];
} else {
$value = DB::prepare('SELECT * FROM `{prefix}config` WHERE `config_name` = :name');
$value->execute([
'name' => $key,
]);
$value = $value->fetch();
// Get the record from the database
$value = DB::table('config')
->where('config_name', $key)
->get();
// Check if it exists
if ($value) {
self::$database[$key] = $value->config_value;
self::$database[$key] = $value[0]->config_value;
return self::$database[$key];
}
}
@ -127,24 +128,20 @@ class Config
}
// Check if the value already exists
$exists = DB::prepare('SELECT * FROM `{prefix}config` WHERE `config_name` = :name');
$exists->execute([
'name' => $key,
]);
$exists = DB::table('config')
->where('config_name', $key)
->count();
// If it exists run an update
if ($exists->rowCount()) {
$set = DB::prepare('UPDATE `{prefix}config` SET `config_value` = :value WHERE `config_name` = :name');
if ($exists) {
DB::table('config')
->where('config_name', $key)
->update(['config_value' => $value]);
} else {
$set = DB::prepare('INSERT INTO `{prefix}config` (`config_name`, `config_value`) VALUES (:name, :value)');
DB::table('config')
->insert(['config_name' => $key, 'config_value' => $value]);
}
// Run the setter
$set->execute([
'name' => $key,
'value' => $value,
]);
// Return the value
return $value;
}

View file

@ -9,6 +9,7 @@ namespace Sakura\Controllers;
use Sakura\Config;
use Sakura\DB;
use Sakura\DBv2;
use Sakura\Forum;
use Sakura\Perms\Forum as ForumPerms;
use Sakura\Template;
@ -31,25 +32,18 @@ class Forums extends Controller
*/
public function index()
{
$userCount = DB::prepare("SELECT * FROM `{prefix}users` WHERE `password_algo` != 'disabled' AND `rank_main` != 1");
$userCount->execute();
$threadCount = DB::prepare('SELECT * FROM `{prefix}topics`');
$threadCount->execute();
$postCount = DB::prepare('SELECT * FROM `{prefix}posts`');
$postCount->execute();
// Merge index specific stuff with the global render data
Template::vars([
'forum' => (new Forum\Forum()),
'stats' => [
'userCount' => $userCount->rowCount(),
'userCount' => DB::table('users')->where('password_algo', '!=', 'disabled')->whereNotIn('rank_main', [1, 10])->count(),
'newestUser' => User::construct(Users::getNewestUserId()),
'lastRegData' => date_diff(
'lastRegDate' => date_diff(
date_create(date('Y-m-d', User::construct(Users::getNewestUserId())->registered)),
date_create(date('Y-m-d'))
)->format('%a'),
'topicCount' => $threadCount->rowCount(),
'postCount' => $postCount->rowCount(),
'topicCount' => DB::table('topics')->count(),
'postCount' => DB::table('posts')->count(),
'onlineUsers' => Users::checkAllOnline(),
],
]);

View file

@ -9,6 +9,7 @@ namespace Sakura\Controllers;
use Sakura\Config;
use Sakura\DB;
use Sakura\DBv2;
use Sakura\News;
use Sakura\Template;
use Sakura\User;
@ -30,26 +31,19 @@ class Meta extends Controller
*/
public function index()
{
$userCount = DB::prepare("SELECT * FROM `{prefix}users` WHERE `password_algo` != 'disabled' AND `rank_main` != 1");
$userCount->execute();
$threadCount = DB::prepare('SELECT * FROM `{prefix}topics`');
$threadCount->execute();
$postCount = DB::prepare('SELECT * FROM `{prefix}posts`');
$postCount->execute();
// Merge index specific stuff with the global render data
Template::vars([
'news' => new News(Config::get('site_news_category')),
'newsCount' => Config::get('front_page_news_posts'),
'stats' => [
'userCount' => $userCount->rowCount(),
'userCount' => DB::table('users')->where('password_algo', '!=', 'disabled')->whereNotIn('rank_main', [1, 10])->count(),
'newestUser' => User::construct(Users::getNewestUserId()),
'lastRegDate' => date_diff(
date_create(date('Y-m-d', User::construct(Users::getNewestUserId())->registered)),
date_create(date('Y-m-d'))
)->format('%a'),
'topicCount' => $threadCount->rowCount(),
'postCount' => $postCount->rowCount(),
'topicCount' => DB::table('topics')->count(),
'postCount' => DB::table('posts')->count(),
'onlineUsers' => Users::checkAllOnline(),
],
]);
@ -95,9 +89,9 @@ class Meta extends Controller
public function faq()
{
// Get faq entries
$faq = DB::prepare('SELECT * FROM `{prefix}faq` ORDER BY `faq_id`');
$faq->execute();
$faq = $faq->fetchAll();
$faq = DB::table('faq')
->orderBy('faq_id')
->get();
// Set parse variables
Template::vars([
@ -131,11 +125,9 @@ class Meta extends Controller
$id = strtolower($id);
// Get the page from the database
$ipData = DB::prepare('SELECT * FROM `{prefix}infopages` WHERE `page_shorthand` = :id');
$ipData->execute([
'id' => $id,
]);
$ipData = $ipData->fetch();
$ipData = DB::table('infopages')
->where('page_shorthand', $id)
->get();
// Get info page data from the database
if ($ipData) {
@ -143,8 +135,8 @@ class Meta extends Controller
Template::vars([
'page' => [
'id' => $id,
'title' => $ipData->page_title,
'content' => $ipData->page_content,
'title' => $ipData[0]->page_title,
'content' => $ipData[0]->page_content,
],
]);
}

View file

@ -9,6 +9,7 @@ namespace Sakura\Controllers;
use Sakura\Config;
use Sakura\DB;
use Sakura\DBv2;
use Sakura\Rank;
use Sakura\Template;
use Sakura\User as UserContext;
@ -39,18 +40,17 @@ class User extends Controller
// If the user id is zero check if there was a namechange
if ($profile->id == 0) {
// Fetch from username_history
$check = DB::prepare('SELECT `user_id` FROM `{prefix}username_history` WHERE `username_old_clean` = :uname ORDER BY `change_id` DESC');
$check->execute([
'uname' => Utils::cleanString($id, true, true),
]);
$check = $check->fetch();
$check = DB::table('username_history')
->where('username_old_clean', Utils::cleanString($id, true, true))
->orderBy('change_id', 'desc')
->get();
// Redirect if so
if ($check) {
Template::vars([
'page' => [
'message' => 'The user this profile belongs to changed their username, you are being redirected.',
'redirect' => (new \Sakura\Urls)->format('USER_PROFILE', [$check->user_id]),
'redirect' => (new \Sakura\Urls)->format('USER_PROFILE', [$check[0]->user_id]),
],
]);

View file

@ -1,112 +1,21 @@
<?php
/**
* Holds the database wrapper (v2).
* Holds the alias class for the Illuminate database thing.
*
* @package Sakura
*/
namespace Sakura;
use PDO;
use PDOException;
use PDOStatement;
use \Illuminate\Database\Capsule\Manager;
/**
* A wrapper to make the database communication experience smoother.
* The Illuminate (Laravel) database wrapper.
*
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class DB
class DB extends Manager
{
/**
* The container for the PDO object.
*
* @var PDO
*/
public static $db = null;
/**
* The table prefix
*
* @var string
*/
public static $prefix = '';
/**
* Open the SQL connection and creates a PDO object.
*
* @param string $server A PDO driver.
* @param array $dsnParts An array consisting out of DSN string parts.
* @param string $username The username used to authenticate with the SQL server.
* @param string $password The password for the same purpose.
* @param array $options Additional PDO options.
*/
public static function open($server, $dsnParts, $username = null, $password = null, $prefix = '', $options = [])
{
// Check if the selected driver is available
if (!in_array($server, PDO::getAvailableDrivers())) {
trigger_error('A driver for the selected SQL server wasn\'t found!', E_USER_ERROR);
return;
}
// Set the table prefix
self::$prefix = $prefix;
// Create start of the DSN
$dsn = "{$server}:";
// Append the parts
foreach ($dsnParts as $name => $value) {
$dsn .= "{$name}={$value};";
}
try {
// Connect to SQL server using PDO
self::$db = new PDO($dsn, $username, $password, $options);
} catch (PDOException $e) {
// Catch connection errors
trigger_error($e->getMessage(), E_USER_ERROR);
}
self::$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
self::$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
}
/**
* Closes the PDO object.
*/
public static function close()
{
self::$db = null;
}
/**
* Get the id of the item that was last inserted into the database.
*
* @param string $name Sequence of which the last id should be returned.
*
* @return string The last inserted id.
*/
public static function lastID($name = null)
{
return self::$db->lastInsertID($name);
}
/**
* Prepares a statement for execution and returns a statement object.
*
* @param string $stmt The statement to prepare.
* @param array $opts Statement specific driver options.
*
* @return PDOStatement
*/
public static function prepare($stmt, $opts = [])
{
// Replace the table prefix
$stmt = str_replace('{prefix}', self::$prefix, $stmt);
return self::$db->prepare($stmt, $opts);
}
// This class solely exists as an alias (for now at least)
}

112
libraries/DBv2.php Normal file
View file

@ -0,0 +1,112 @@
<?php
/**
* Holds the database wrapper (v2).
*
* @package Sakura
*/
namespace Sakura;
use PDO;
use PDOException;
use PDOStatement;
/**
* A wrapper to make the database communication experience smoother.
*
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class DBv2
{
/**
* The container for the PDO object.
*
* @var PDO
*/
public static $db = null;
/**
* The table prefix
*
* @var string
*/
public static $prefix = '';
/**
* Open the SQL connection and creates a PDO object.
*
* @param string $server A PDO driver.
* @param array $dsnParts An array consisting out of DSN string parts.
* @param string $username The username used to authenticate with the SQL server.
* @param string $password The password for the same purpose.
* @param array $options Additional PDO options.
*/
public static function open($server, $dsnParts, $username = null, $password = null, $prefix = '', $options = [])
{
// Check if the selected driver is available
if (!in_array($server, PDO::getAvailableDrivers())) {
trigger_error('A driver for the selected SQL server wasn\'t found!', E_USER_ERROR);
return;
}
// Set the table prefix
self::$prefix = $prefix;
// Create start of the DSN
$dsn = "{$server}:";
// Append the parts
foreach ($dsnParts as $name => $value) {
$dsn .= "{$name}={$value};";
}
try {
// Connect to SQL server using PDO
self::$db = new PDO($dsn, $username, $password, $options);
} catch (PDOException $e) {
// Catch connection errors
trigger_error($e->getMessage(), E_USER_ERROR);
}
self::$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
self::$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
}
/**
* Closes the PDO object.
*/
public static function close()
{
self::$db = null;
}
/**
* Get the id of the item that was last inserted into the database.
*
* @param string $name Sequence of which the last id should be returned.
*
* @return string The last inserted id.
*/
public static function lastID($name = null)
{
return self::$db->lastInsertID($name);
}
/**
* Prepares a statement for execution and returns a statement object.
*
* @param string $stmt The statement to prepare.
* @param array $opts Statement specific driver options.
*
* @return PDOStatement
*/
public static function prepare($stmt, $opts = [])
{
// Replace the table prefix
$stmt = str_replace('{prefix}', self::$prefix, $stmt);
return self::$db->prepare($stmt, $opts);
}
}

View file

@ -81,18 +81,15 @@ class File
$mime = (new finfo(FILEINFO_MIME_TYPE))->buffer($data);
// Insert it into the database
DB::prepare('INSERT INTO `{prefix}uploads` (`user_id`, `file_data`, `file_name`, `file_mime`, `file_time`, `file_expire`) VALUES (:id, :data, :name, :mime, :time, :expire)')
->execute([
'id' => $user->id,
'data' => $data,
'name' => $name,
'mime' => $mime,
'time' => time(),
'expire' => $expire,
]);
// Get the last insert id
$id = (int) DB::lastID();
$id = DB::table('uploads')
->insertGetId([
'user_id' => $user->id,
'file_data' => $data,
'file_name' => $name,
'file_mime' => $mime,
'file_time' => time(),
'file_expire' => $expire,
]);
// Return a new File object
return new File($id);
@ -106,14 +103,13 @@ class File
public function __construct($fileId)
{
// Attempt to get the database row
$fr = DB::prepare('SELECT * FROM `{prefix}uploads` WHERE `file_id` = :id');
$fr->execute([
'id' => $fileId,
]);
$fileRow = $fr->fetch();
$fileRow = DB::table('uploads')
->where('file_id', $fileId)
->get();
// If anything was returned populate the variables
if ($fileRow) {
$fileRow = $fileRow[0];
$this->id = $fileRow->file_id;
$this->user = User::construct($fileRow->user_id);
$this->data = $fileRow->file_data;
@ -129,9 +125,8 @@ class File
*/
public function delete()
{
DB::prepare('DELETE FROM `{prefix}uploads` WHERE `file_id` = :id')
->execute([
'id' => $this->id,
]);
DB::table('uploads')
->where('file_id', $this->id)
->delete();
}
}

View file

@ -8,6 +8,7 @@
namespace Sakura\Forum;
use Sakura\DB;
use Sakura\DBv2;
use Sakura\Users;
use Sakura\User;
use Sakura\Perms;
@ -118,17 +119,16 @@ class Forum
public function __construct($forumId = 0)
{
// Get the row from the database
$forumRow = DB::prepare('SELECT * FROM `{prefix}forums` WHERE `forum_id` = :id');
$forumRow->execute([
'id' => $forumId,
]);
$forumRow = $forumRow->fetch();
$forumRow = DB::table('forums')
->where('forum_id', $forumId)
->get();
// Create permissions object
$this->_permissions = new Perms(Perms::FORUM);
// Populate the variables
if ($forumRow) {
$forumRow = $forumRow[0];
$this->id = $forumRow->forum_id;
$this->order = $forumRow->forum_order;
$this->name = $forumRow->forum_name;
@ -177,11 +177,10 @@ class Forum
// Check if _forums is populated
if (!count($this->_forums)) {
// Get all rows with the category id set to the forum id
$forumRows = DB::prepare('SELECT `forum_id` FROM `{prefix}forums` WHERE `forum_category` = :cat ORDER BY forum_order');
$forumRows->execute([
'cat' => $this->id,
]);
$forumRows = $forumRows->fetchAll();
$forumRows = DB::table('forums')
->where('forum_category', $this->id)
->orderBy('forum_order')
->get(['forum_id']);
// Create a storage array
$forums = [];
@ -210,11 +209,11 @@ class Forum
// Check if _threads is populated
if (!count($this->_threads)) {
// Get all rows with the forum id for this forum
$threadRows = DB::prepare('SELECT * FROM `{prefix}topics` WHERE `forum_id` = :forum ORDER BY `topic_type` DESC, `topic_last_reply` DESC');
$threadRows->execute([
'forum' => $this->id,
]);
$threadRows = $threadRows->fetchAll();
$threadRows = DB::table('topics')
->where('forum_id', $this->id)
->orderBy('topic_type', 'desc')
->orderBy('topic_last_reply', 'desc')
->get(['topic_id']);
// Create a storage array
$threads = [];
@ -243,14 +242,14 @@ class Forum
// Check if _firstPost is set
if ($this->_firstPost === null) {
// Get the row
$firstPost = DB::prepare('SELECT `post_id` FROM `{prefix}posts` WHERE `forum_id` = :id ORDER BY `post_id` LIMIT 1');
$firstPost->execute([
'id' => $this->id,
]);
$firstPost = $firstPost->fetch();
$firstPost = DB::table('posts')
->where('forum_id', $this->id)
->orderBy('post_id')
->limit(1)
->get(['post_id']);
// Create the post object
$post = new Post(empty($firstPost) ? 0 : $firstPost->post_id);
$post = new Post(empty($firstPost) ? 0 : $firstPost[0]->post_id);
// Assign it to a "cache" variable
$this->_firstPost = $post;
@ -272,14 +271,14 @@ class Forum
// Check if _lastPost is set
if ($this->_lastPost === null) {
// Get the row
$lastPost = DB::prepare('SELECT `post_id` FROM `{prefix}posts` WHERE `forum_id` = :id ORDER BY `post_id` DESC LIMIT 1');
$lastPost->execute([
'id' => $this->id,
]);
$lastPost = $lastPost->fetch();
$lastPost = DB::table('posts')
->where('forum_id', $this->id)
->orderBy('post_id', 'desc')
->limit(1)
->get(['post_id']);
// Create the post object
$post = new Post(empty($lastPost) ? 0 : $lastPost->post_id);
$post = new Post(empty($lastPost) ? 0 : $lastPost[0]->post_id);
// Assign it to a "cache" variable
$this->_lastPost = $post;
@ -298,11 +297,9 @@ class Forum
*/
public function threadCount()
{
$count = DB::prepare('SELECT * FROM `{prefix}topics` WHERE `forum_id` = :id');
$count->execute([
'id' => $this->id,
]);
return $count->rowCount();
return DB::table('topics')
->where('forum_id', $this->id)
->count();
}
/**
@ -312,11 +309,9 @@ class Forum
*/
public function postCount()
{
$count = DB::prepare('SELECT * FROM `{prefix}posts` WHERE `forum_id` = :id');
$count->execute([
'id' => $this->id,
]);
return $count->rowCount();
return DB::table('posts')
->where('forum_id', $this->id)
->count();
}
/**

View file

@ -9,6 +9,7 @@ namespace Sakura\Forum;
use Sakura\Utils;
use Sakura\DB;
use Sakura\DBv2;
use Sakura\User;
use Sakura\BBcode;
use Sakura\Config;
@ -114,14 +115,13 @@ class Post
public function __construct($postId)
{
// Attempt to get the database row
$postRow = DB::prepare('SELECT * FROM `{prefix}posts` WHERE `post_id` = :id');
$postRow->execute([
'id' => $postId,
]);
$postRow = $postRow->fetch();
$postRow = DB::table('posts')
->where('post_id', $postId)
->get();
// Assign data if a row was returned
if ($postRow) {
$postRow = $postRow[0];
$this->id = $postRow->post_id;
$this->thread = $postRow->topic_id;
$this->forum = $postRow->forum_id;
@ -173,19 +173,16 @@ class Post
}
// Insert the post
DB::prepare('INSERT INTO `{prefix}posts` (`topic_id`, `forum_id`, `poster_id`, `poster_ip`, `post_time`, `post_subject`, `post_text`) VALUES (:thread, :forum, :user, :ip, :time, :subject, :text)')
->execute([
'thread' => $thread->id,
'forum' => $thread->forum,
'user' => $poster->id,
'ip' => Net::IP(),
'time' => time(),
'subject' => $subject,
'text' => $text,
]);
// Get post id
$id = (int) DB::lastID();
$id = DB::table('posts')
->insertGetId([
'topic_id' => $thread->id,
'forum_id' => $thread->forum,
'poster_id' => $poster->id,
'poster_ip' => Net::IP(),
'post_time' => time(),
'post_subject' => $subject,
'post_text' => $text,
]);
// Update the last post date
$thread->lastUpdate();
@ -213,20 +210,20 @@ class Post
$thread = new Thread($this->thread);
// Update the post
DB::prepare('UPDATE `{prefix}posts` SET `topic_id` = :thread, `forum_id` = :forum, `poster_id` = :user, `poster_ip` = :ip, `post_time` = :time, `post_subject` = :subject, `post_text` = :text, `post_edit_time` = :edit_time, `post_edit_reason` = :edit_reason, `post_edit_user` = :edit_user WHERE `post_id` = :post')
->execute([
'post' => $this->id,
'thread' => $thread->id,
'forum' => $thread->forum,
'user' => $this->poster->id,
'ip' => Net::pton(Net::IP()),
'time' => $this->time,
'subject' => $this->subject,
'text' => $this->text,
'edit_time' => $this->editTime,
'edit_reason' => $this->editReason,
'edit_user' => $this->editUser->id,
]);
DB::table('posts')
->where('post_id', $this->id)
->update([
'topic_id' => $thread->id,
'forum_id' => $thread->forum,
'poster_id' => $this->poster->id,
'poster_ip' => Net::pton(Net::IP()),
'post_time' => $this->time,
'post_subject' => $this->subject,
'post_text' => $this->text,
'post_edit_time' => $this->editTime,
'post_edit_reason' => $this->editReason,
'post_edit_user' => $this->editUser->id,
]);
// Return a new post object
return new Post($this->id);

View file

@ -8,6 +8,7 @@
namespace Sakura\Forum;
use Sakura\DB;
use Sakura\DBv2;
use Sakura\Utils;
/**
@ -129,14 +130,13 @@ class Thread
public function __construct($threadId)
{
// Attempt to get the database row
$threadRow = DB::prepare('SELECT * FROM `{prefix}topics` WHERE `topic_id` = :id');
$threadRow->execute([
'id' => $threadId,
]);
$threadRow = $threadRow->fetch();
$threadRow = DB::table('topics')
->where('topic_id', $threadId)
->get();
// Assign data if a row was returned
if ($threadRow) {
$threadRow = $threadRow[0];
$this->id = $threadRow->topic_id;
$this->forum = $threadRow->forum_id;
$this->hidden = (bool) $threadRow->topic_hidden;
@ -164,17 +164,17 @@ class Thread
public static function create($forum, $title, $status = 0, $type = 0)
{
// Create the database entry
DB::prepare('INSERT INTO `{prefix}topics` (`forum_id`, `topic_title`, `topic_time`, `topic_status`, `topic_type`) VALUES (:forum, :title, :time, :status, :type)')
->execute([
'forum' => $forum,
'title' => $title,
'time' => time(),
'status' => $status,
'type' => $type,
]);
$id = DB::table('topics')
->insertGetId([
'forum_id' => $forum,
'topic_title' => $title,
'topic_time' => time(),
'topic_status' => $status,
'topic_type' => $type,
]);
// Return the thread object
return new Thread(DB::lastID());
return new Thread($id);
}
/**
@ -183,16 +183,14 @@ class Thread
public function delete()
{
// Delete all posts
DB::prepare('DELETE FROM `{prefix}posts` WHERE `topic_id` = :id')
->execute([
'id' => $this->id,
]);
DB::table('posts')
->where('topic_id', $this->id)
->delete();
// Delete thread meta
DB::prepare('DELETE FROM `{prefix}topics` WHERE `topic_id` = :id')
->execute([
'id' => $this->id,
]);
DB::table('topics')
->where('topic_id', $this->id)
->delete();
}
/**
@ -204,19 +202,17 @@ class Thread
public function move($forum, $setOld = true)
{
// Update all posts
DB::prepare('UPDATE `{prefix}posts` SET `forum_id` = :forum WHERE `topic_id` = :thread')
->execute([
'forum' => $forum,
'thread' => $this->id,
]);
DB::table('posts')
->where('topic_id', $this->id)
->update(['forum_id' => $forum]);
// Update thread meta
DB::prepare('UPDATE `{prefix}topics` SET `forum_id` = :forum, `topic_old_forum` = :old WHERE `topic_id` = :thread')
->execute([
'forum' => $forum,
'old' => ($setOld ? $this->forum : 0),
'thread' => $this->id,
]);
DB::table('topics')
->where('topic_id', $this->id)
->update([
'forum_id' => $forum,
'topic_old_forum' => ($setOld ? $this->forum : 0),
]);
}
/**
@ -227,17 +223,17 @@ class Thread
public function update()
{
// Update row
DB::prepare('UPDATE `{prefix}topics` SET `topic_hidden` = :hidden, `topic_title` = :title, `topic_time_limit` = :limit, `topic_status` = :status, `topic_status_change` = :change, `topic_type` = :type, `topic_old_forum` = :old WHERE `topic_id` = :id')
->execute([
'hidden' => $this->hidden,
'title' => $this->title,
'limit' => $this->timeLimit,
'status' => $this->status,
'change' => $this->statusChange,
'type' => $this->type,
'old' => $this->oldForum,
'id' => $this->id,
]);
DB::table('topics')
->where('topic_id', $this->id)
->update([
'topic_hidden' => $this->hidden,
'topic_title' => $this->title,
'topic_limit' => $this->timeLimit,
'topic_status' => $this->status,
'topic_status_change' => $this->statusChange,
'topic_type' => $this->type,
'topic_old_forum' => $this->oldForum,
]);
// Return new object
return new Thread($this->id);
@ -253,11 +249,9 @@ class Thread
// Check if _posts is something
if (!count($this->_posts)) {
// Get all rows with the thread id
$postRows = DB::prepare('SELECT `post_id` FROM `{prefix}posts` WHERE `topic_id` = :thread');
$postRows->execute([
'thread' => $this->id,
]);
$postRows = $postRows->fetchAll();
$postRows = DB::table('posts')
->where('topic_id', $this->id)
->get(['post_id']);
// Create a storage array
$posts = [];
@ -289,14 +283,14 @@ class Thread
}
// Get the row from the database
$post = DB::prepare('SELECT `post_id` FROM `{prefix}posts` WHERE `topic_id` = :thread ORDER BY `post_id` LIMIT 1');
$post->execute([
'thread' => $this->id,
]);
$post = $post->fetch();
$post = DB::table('posts')
->where('topic_id', $this->id)
->orderBy('post_id')
->limit(1)
->get(['post_id']);
// Create the post class
$post = new Post($post ? $post->post_id : 0);
$post = new Post($post ? $post[0]->post_id : 0);
// Assign it to the cache var
$this->_firstPost = $post;
@ -318,14 +312,14 @@ class Thread
}
// Get the row from the database
$post = DB::prepare('SELECT `post_id` FROM `{prefix}posts` WHERE `topic_id` = :thread ORDER BY `post_id` DESC LIMIT 1');
$post->execute([
'thread' => $this->id,
]);
$post = $post->fetch();
$post = DB::table('posts')
->where('topic_id', $this->id)
->orderBy('post_id', 'desc')
->limit(1)
->get(['post_id']);
// Create the post class
$post = new Post($post ? $post->post_id : 0);
$post = new Post($post ? $post[0]->post_id : 0);
// Assign it to the cache var
$this->_lastPost = $post;
@ -341,11 +335,9 @@ class Thread
*/
public function replyCount()
{
$count = DB::prepare('SELECT * FROM `{prefix}posts` WHERE `topic_id` = :thread');
$count->execute([
'thread' => $this->id,
]);
return $count->rowCount();
return DB::table('posts')
->where('topic_id', $this->id)
->count();
}
/**
@ -358,15 +350,14 @@ class Thread
public function unread($user)
{
// Attempt to get track row from the database
$track = DB::prepare('SELECT * FROM `{prefix}topics_track` WHERE `user_id` = :user AND `topic_id` = :thread AND `mark_time` > :last');
$track->execute([
'user' => $user,
'thread' => $this->id,
'last' => $this->lastPost()->time,
]);
$track = DB::table('topics_track')
->where('user_id', $user)
->where('topic_id', $this->id)
->where('mark_time', '>', $this->lastPost()->time)
->count();
// If nothing was returned it's obvious that the status is unread
if (!$track->rowCount()) {
if (!$track) {
return true;
}
@ -382,30 +373,27 @@ class Thread
public function trackUpdate($user)
{
// Check if we already have a track record
$track = DB::prepare('SELECT * FROM `{prefix}topics_track` WHERE `user_id` = :user AND `topic_id` = :thread AND `forum_id` = :forum');
$track->execute([
'user' => $user,
'thread' => $this->id,
'forum' => $this->forum,
]);
$track = DB::table('topics_track')
->where('user_id', $user)
->where('topic_id', $this->id)
->where('forum_id', $this->forum)
->count();
// If so update it
if ($track->rowCount()) {
DB::prepare('UPDATE `{prefix}topics_track` SET `mark_time` = :time WHERE `user_id` = :user AND `topic_id` = :thread')
->execute([
'user' => $user,
'thread' => $this->id,
'time' => time(),
]);
if ($track) {
DB::table('topics_track')
->where('user_id', $user)
->where('topic_id', $this->id)
->update(['mark_time' => time()]);
} else {
// If not create a new record
DB::prepare('INSERT INTO `{prefix}topics_track` (`user_id`, `topic_id`, `forum_id`, `mark_time`) VALUES (:user, :thread, :forum, :time)')
->execute([
'user' => $user,
'thread' => $this->id,
'forum' => $this->forum,
'time' => time(),
]);
DB::table('topics_track')
->insert([
'user_id' => $user,
'topic_id' => $this->id,
'forum_id' => $this->forum,
'mark_time' => time(),
]);
}
}
@ -414,11 +402,9 @@ class Thread
*/
public function viewsUpdate()
{
DB::prepare('UPDATE `{prefix}topics` SET `topic_views` = :views WHERE `topic_id` = :thread')
->execute([
'views' => $this->views + 1,
'thread' => $this->id,
]);
DB::table('topics')
->where('topic_id', $this->id)
->increment('topic_views');
}
/**
@ -426,10 +412,8 @@ class Thread
*/
public function lastUpdate()
{
DB::prepare('UPDATE `{prefix}topics` SET `topic_last_reply` = :last WHERE `topic_id` = :thread')
->execute([
'last' => time(),
'thread' => $this->id,
]);
DB::table('topics')
->where('topic_id', $this->id)
->update(['topic_last_reply' => time()]);
}
}

View file

@ -31,7 +31,7 @@ class News
{
// Get the news posts and assign them to $posts
$posts = DB::prepare('SELECT * FROM `{prefix}news` WHERE `news_category` = :cat ORDER BY `news_id` DESC');
$posts = DBv2::prepare('SELECT * FROM `{prefix}news` WHERE `news_category` = :cat ORDER BY `news_id` DESC');
$posts->execute([
'cat' => $category,
]);

View file

@ -102,7 +102,7 @@ class Perms
}
// Prepare the statement
$get = DB::prepare($stmt);
$get = DBv2::prepare($stmt);
// Bind rank
$get->bindParam('rank', $rid);
@ -156,7 +156,7 @@ class Perms
}
// Prepare the statement
$get = DB::prepare($stmt);
$get = DBv2::prepare($stmt);
// Bind rank
$get->bindParam('user', $uid);

View file

@ -111,20 +111,19 @@ class Rank
/**
* Constructor.
*
* @param int $rid ID of the rank that should be constructed.
* @param int $rankId ID of the rank that should be constructed.
*/
private function __construct($rid)
private function __construct($rankId)
{
// Get the rank database row
$rankRow = DB::prepare('SELECT * FROM `{prefix}ranks` WHERE `rank_id` = :id');
$rankRow->execute([
'id' => $rid,
]);
$rankRow = $rankRow->fetch();
$rankRow = DB::table('ranks')
->where('rank_id', $rankId)
->get();
// Check if the rank actually exists
if ($rankRow) {
$rankRow = $rankRow[0];
$this->id = $rankRow->rank_id;
$this->name = $rankRow->rank_name;
$this->hierarchy = $rankRow->rank_hierarchy;
@ -189,7 +188,7 @@ class Rank
public function users($justIds = false)
{
// Fetch all users part of this rank
$fetch = DB::prepare('SELECT `user_id` FROM `{prefix}user_ranks` WHERE `rank_id` = :id');
$fetch = DBv2::prepare('SELECT `user_id` FROM `{prefix}user_ranks` WHERE `rank_id` = :id');
$fetch->execute([
'id' => $this->id,
]);

View file

@ -53,11 +53,10 @@ class Session
public function destroy()
{
// Invalidate the session key
DB::prepare('DELETE FROM `{prefix}sessions` WHERE `session_key` = :key AND `user_id` = :user')
->execute([
'key' => $this->sessionId,
'user' => $this->userId,
]);
DB::table('sessions')
->where('session_key', $this->sessionId)
->where('user_id', $this->userId)
->delete();
// Unset userId and sessionId
unset($this->userId);
@ -75,10 +74,9 @@ class Session
public function destroyAll()
{
// Delete all database entries with this user in it
DB::prepare('DELETE FROM `{prefix}sessions` WHERE `user_id` = :user')
->execute([
'user' => $this->userId,
]);
DB::table('sessions')
->where('user_id', $this->userId)
->delete();
// Destroy this session to finish it off
$this->destroy();
@ -97,16 +95,16 @@ class Session
$session = hash('sha256', $this->userId . base64_encode('sakura' . mt_rand(0, 99999999)) . time());
// Insert the session into the database
DB::prepare('INSERT INTO `{prefix}sessions` (`user_id`, `user_ip`, `user_agent`, `session_key`, `session_start`, `session_expire`, `session_remember`) VALUES (:id, :ip, :agent, :key, :start, :end, :remember)')
->execute([
'id' => $this->userId,
'ip' => Net::pton(Net::IP()),
'agent' => Utils::cleanString(isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'No user agent header.'),
'key' => $session,
'start' => time(),
'end' => time() + 604800,
'remember' => $permanent ? '1' : '0',
]);
DB::table('sessions')
->insert([
'user_id' => $this->userId,
'user_ip' => Net::pton(Net::IP()),
'user_agent' => Utils::cleanString(isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'No user agent header.'),
'session_key' => $session,
'session_start' => time(),
'session_expire' => time() + 604800,
'session_remember' => $permanent ? '1' : '0',
]);
// Return the session key
return $session;
@ -120,12 +118,10 @@ class Session
public function validate()
{
// Get session from database
$session = DB::prepare('SELECT * FROM `{prefix}sessions` WHERE `user_id` = :user AND `session_key` = :key');
$session->execute([
'user' => $this->userId,
'key' => $this->sessionId,
]);
$session = $session->fetch();
$session = DB::table('sessions')
->where('user_id', $this->userId)
->where('session_key', $this->sessionId)
->get();
// Check if we actually got something in return
if (!$session) {
@ -133,7 +129,7 @@ class Session
}
// Check if the session expired
if ($session->session_expire < time()) {
if ($session[0]->session_expire < time()) {
// ...and return false
return 0;
}
@ -144,7 +140,7 @@ class Session
// Origin checking
if ($ipCheck) {
// Split both IPs up
$sessionIP = explode('.', $session['user_ip']);
$sessionIP = explode('.', $session[0]->user_ip);
$userIP = explode('.', Net::IP());
// Take 1 off the ipCheck variable so it's equal to the array keys
@ -185,15 +181,13 @@ class Session
}
// If the remember flag is set extend the session time
if ($session->session_remember) {
DB::prepare('UPDATE `{prefix}sessions` SET `session_expire` = :expire WHERE `session_id` = :id')
->execute([
'expire' => time() + 604800,
'id' => $session->session_id,
]);
if ($session[0]->session_remember) {
DB::table('sessions')
->where('session_id', $session[0]->session_id)
->update(['session_expire' => time() + 604800]);
}
// Return 2 if the remember flag is set and return 1 if not
return $session->session_remember ? 2 : 1;
return $session[0]->session_remember ? 2 : 1;
}
}

View file

@ -258,7 +258,7 @@ class User
$password = Hashing::createHash($password);
// Insert the user into the database
DB::prepare('INSERT INTO `{prefix}users` (`username`, `username_clean`, `password_hash`, `password_salt`, `password_algo`, `password_iter`, `email`, `rank_main`, `register_ip`, `last_ip`, `user_registered`, `user_last_online`, `user_country`) VALUES (:uname, :uname_clean, :pw_hash, :pw_salt, :pw_algo, :pw_iter, :email, :rank, :r_ip, :l_ip, :registered, :l_online, :country)')
DBv2::prepare('INSERT INTO `{prefix}users` (`username`, `username_clean`, `password_hash`, `password_salt`, `password_algo`, `password_iter`, `email`, `rank_main`, `register_ip`, `last_ip`, `user_registered`, `user_last_online`, `user_country`) VALUES (:uname, :uname_clean, :pw_hash, :pw_salt, :pw_algo, :pw_iter, :email, :rank, :r_ip, :l_ip, :registered, :l_online, :country)')
->execute([
'uname' => $username,
'uname_clean' => $usernameClean,
@ -276,7 +276,7 @@ class User
]);
// Get the last id
$userId = DB::lastID();
$userId = DBv2::lastID();
// Create a user object
$user = self::construct($userId);
@ -299,7 +299,7 @@ class User
private function __construct($uid)
{
// Get the user database row
$userRow = DB::prepare('SELECT * FROM `{prefix}users` WHERE `user_id` = :id OR `username_clean` = :clean');
$userRow = DBv2::prepare('SELECT * FROM `{prefix}users` WHERE `user_id` = :id OR `username_clean` = :clean');
$userRow->execute([
'id' => $uid,
'clean' => Utils::cleanString($uid, true, true),
@ -334,7 +334,7 @@ class User
}
// Get all ranks
$ranks = DB::prepare('SELECT * FROM `{prefix}user_ranks` WHERE `user_id` = :id');
$ranks = DBv2::prepare('SELECT * FROM `{prefix}user_ranks` WHERE `user_id` = :id');
$ranks->execute([
'id' => $this->id,
]);
@ -426,7 +426,7 @@ class User
public function isOnline()
{
// Get all sessions
$sessions = DB::prepare('SELECT `user_id` FROM `{prefix}sessions` WHERE `user_id` = :id');
$sessions = DBv2::prepare('SELECT `user_id` FROM `{prefix}sessions` WHERE `user_id` = :id');
$sessions->execute([
'id' => $this->id,
]);
@ -447,12 +447,12 @@ class User
*/
public function forumStats()
{
$posts = DB::prepare('SELECT * FROM `{prefix}posts` WHERE `poster_id` = :id');
$posts = DBv2::prepare('SELECT * FROM `{prefix}posts` WHERE `poster_id` = :id');
$posts->execute([
'id' => $this->id,
]);
$threads = DB::prepare('SELECT DISTINCT * FROM `{prefix}posts` WHERE `poster_id` = :id GROUP BY `topic_id` ORDER BY `post_time`');
$threads = DBv2::prepare('SELECT DISTINCT * FROM `{prefix}posts` WHERE `poster_id` = :id GROUP BY `topic_id` ORDER BY `post_time`');
$threads->execute([
'id' => $this->id,
]);
@ -482,7 +482,7 @@ class User
// Save to the database
foreach ($ranks as $rank) {
DB::prepare('INSERT INTO `{prefix}ranks` (`rank_id`, `user_id`) VALUES (:rank, :user)')
DBv2::prepare('INSERT INTO `{prefix}ranks` (`rank_id`, `user_id`) VALUES (:rank, :user)')
->execute([
'rank' => $rank,
'user' => $this->id,
@ -502,7 +502,7 @@ class User
// Iterate over the ranks
foreach ($remove as $rank) {
DB::prepare('DELETE FROM `{prefix}user_ranks` WHERE `user_id` = :user AND `rank_id` = :rank')
DBv2::prepare('DELETE FROM `{prefix}user_ranks` WHERE `user_id` = :user AND `rank_id` = :rank')
->execute([
'user' => $this->id,
'rank' => $rank,
@ -520,7 +520,7 @@ class User
public function setMainRank($rank)
{
// If it does exist update their row
DB::prepare('UPDATE `{prefix}users` SET `rank_main` = :rank WHERE `user_id` = :id')
DBv2::prepare('UPDATE `{prefix}users` SET `rank_main` = :rank WHERE `user_id` = :id')
->execute([
'rank' => $rank,
'id' => $this->id,
@ -579,7 +579,7 @@ class User
}
// Add friend
DB::prepare('INSERT INTO `{prefix}friends` (`user_id`, `friend_id`, `friend_timestamp`) VALUES (:user, :friend, :time)')
DBv2::prepare('INSERT INTO `{prefix}friends` (`user_id`, `friend_id`, `friend_timestamp`) VALUES (:user, :friend, :time)')
->execute([
'user' => $this->id,
'friend' => $uid,
@ -609,7 +609,7 @@ class User
}
// Prepare the statement
$rem = DB::prepare('DELETE FROM `{prefix}friends` WHERE `user_id` = :user AND `friend_id` = :friend');
$rem = DBv2::prepare('DELETE FROM `{prefix}friends` WHERE `user_id` = :user AND `friend_id` = :friend');
// Remove friend
$rem->execute([
@ -639,7 +639,7 @@ class User
public function isFriends($with)
{
// Accepted from this user
$get = DB::prepare('SELECT * FROM `{prefix}friends` WHERE `user_id` = :user AND `friend_id` = :friend');
$get = DBv2::prepare('SELECT * FROM `{prefix}friends` WHERE `user_id` = :user AND `friend_id` = :friend');
$get->execute([
'user' => $this->id,
'friend' => $with,
@ -681,14 +681,14 @@ class User
// Mutual
case 2:
// Get all the current user's friends
$self = DB::prepare('SELECT `friend_id` FROM `{prefix}friends` WHERE `user_id` = :user');
$self = DBv2::prepare('SELECT `friend_id` FROM `{prefix}friends` WHERE `user_id` = :user');
$self->execute([
'user' => $this->id,
]);
$self = array_column($self->fetchAll(\PDO::FETCH_ASSOC), 'friend_id');
// Get all the people that added this user as a friend
$others = DB::prepare('SELECT `user_id` FROM `{prefix}friends` WHERE `friend_id` = :user');
$others = DBv2::prepare('SELECT `user_id` FROM `{prefix}friends` WHERE `friend_id` = :user');
$others->execute([
'user' => $this->id,
]);
@ -700,7 +700,7 @@ class User
// Non-mutual (from user perspective)
case 1:
$users = DB::prepare('SELECT `friend_id` FROM `{prefix}friends` WHERE `user_id` = :user');
$users = DBv2::prepare('SELECT `friend_id` FROM `{prefix}friends` WHERE `user_id` = :user');
$users->execute([
'user' => $this->id,
]);
@ -711,14 +711,14 @@ class User
case 0:
default:
// Get all the current user's friends
$self = DB::prepare('SELECT `friend_id` FROM `{prefix}friends` WHERE `user_id` = :user');
$self = DBv2::prepare('SELECT `friend_id` FROM `{prefix}friends` WHERE `user_id` = :user');
$self->execute([
'user' => $this->id,
]);
$self = array_column($self->fetchAll(\PDO::FETCH_ASSOC), 'friend_id');
// Get all the people that added this user as a friend
$others = DB::prepare('SELECT `user_id` FROM `{prefix}friends` WHERE `friend_id` = :user');
$others = DBv2::prepare('SELECT `user_id` FROM `{prefix}friends` WHERE `friend_id` = :user');
$others->execute([
'user' => $this->id,
]);
@ -731,14 +731,14 @@ class User
// Open requests
case -1:
// Get all the current user's friends
$self = DB::prepare('SELECT `friend_id` FROM `{prefix}friends` WHERE `user_id` = :user');
$self = DBv2::prepare('SELECT `friend_id` FROM `{prefix}friends` WHERE `user_id` = :user');
$self->execute([
'user' => $this->id,
]);
$self = array_column($self->fetchAll(\PDO::FETCH_ASSOC), 'friend_id');
// Get all the people that added this user as a friend
$others = DB::prepare('SELECT `user_id` FROM `{prefix}friends` WHERE `friend_id` = :user');
$others = DBv2::prepare('SELECT `user_id` FROM `{prefix}friends` WHERE `friend_id` = :user');
$others->execute([
'user' => $this->id,
]);
@ -824,11 +824,11 @@ class User
// Create array and get values
$profile = [];
$profileFields = DB::prepare('SELECT * FROM `{prefix}profilefields`');
$profileFields = DBv2::prepare('SELECT * FROM `{prefix}profilefields`');
$profileFields->execute();
$profileFields = $profileFields->fetchAll(\PDO::FETCH_ASSOC);
$profileValuesRaw = DB::prepare('SELECT * FROM `{prefix}user_profilefields` WHERE `user_id` = :user');
$profileValuesRaw = DBv2::prepare('SELECT * FROM `{prefix}user_profilefields` WHERE `user_id` = :user');
$profileValuesRaw->execute([
'user' => $this->id,
]);
@ -912,11 +912,11 @@ class User
// Create array and get values
$options = [];
$optionFields = DB::prepare('SELECT * FROM `{prefix}optionfields`');
$optionFields = DBv2::prepare('SELECT * FROM `{prefix}optionfields`');
$optionFields->execute();
$optionFields = $optionFields->fetchAll(\PDO::FETCH_ASSOC);
$optionValuesRaw = DB::prepare('SELECT * FROM `{prefix}user_optionfields` WHERE `user_id` = :user');
$optionValuesRaw = DBv2::prepare('SELECT * FROM `{prefix}user_optionfields` WHERE `user_id` = :user');
$optionValuesRaw->execute([
'user' => $this->id,
]);
@ -972,7 +972,7 @@ class User
}
// Attempt to retrieve the premium record from the database
$getRecord = DB::prepare('SELECT * FROM `{prefix}premium` WHERE `user_id` = :user');
$getRecord = DBv2::prepare('SELECT * FROM `{prefix}premium` WHERE `user_id` = :user');
$getRecord->execute([
'user' => $this->id,
]);
@ -1000,7 +1000,7 @@ class User
public function getWarnings()
{
// Do the database query
$getWarnings = DB::prepare('SELECT * FROM `{prefix}warnings` WHERE `user_id` = :user');
$getWarnings = DBv2::prepare('SELECT * FROM `{prefix}warnings` WHERE `user_id` = :user');
$getWarnings->execute([
'user' => $this->id,
]);
@ -1013,7 +1013,7 @@ class User
foreach ($getWarnings as $warning) {
// Check if it hasn't expired
if ($warning['warning_expires'] < time()) {
DB::prepare('DELETE FROM `{prefix}warnings` WHERE `warning_id` = :warn')
DBv2::prepare('DELETE FROM `{prefix}warnings` WHERE `warning_id` = :warn')
->execute([
'warn' => $warning['warning_id'],
]);
@ -1079,7 +1079,7 @@ class User
public function getUsernameHistory()
{
// Do the database query
$changes = DB::prepare('SELECT * FROM `{prefix}username_history` WHERE `user_id` = :user ORDER BY `change_id` DESC');
$changes = DBv2::prepare('SELECT * FROM `{prefix}username_history` WHERE `user_id` = :user ORDER BY `change_id` DESC');
$changes->execute([
'user' => $this->id,
]);
@ -1111,7 +1111,7 @@ class User
}
// Check if this username hasn't been used in the last amount of days set in the config
$getOld = DB::prepare('SELECT * FROM `{prefix}username_history` WHERE `username_old_clean` = :clean AND `change_time` > :time ORDER BY `change_id` DESC');
$getOld = DBv2::prepare('SELECT * FROM `{prefix}username_history` WHERE `username_old_clean` = :clean AND `change_time` > :time ORDER BY `change_id` DESC');
$getOld->execute([
'clean' => $username_clean,
'time' => (Config::get('old_username_reserve') * 24 * 60 * 60),
@ -1124,7 +1124,7 @@ class User
}
// Check if the username is already in use
$getInUse = DB::prepare('SELECT * FROM `{prefix}users` WHERE `username_clean` = :clean');
$getInUse = DBv2::prepare('SELECT * FROM `{prefix}users` WHERE `username_clean` = :clean');
$getInUse->execute([
'clean' => $username_clean,
]);
@ -1136,7 +1136,7 @@ class User
}
// Insert into username_history table
DB::prepare('INSERT INTO `{prefix}username_history` (`change_time`, `user_id`, `username_new`, `username_new_clean`, `username_old`, `username_old_clean`) VALUES (:time, :user, :new, :new_clean, :old, :old_clean)')
DBv2::prepare('INSERT INTO `{prefix}username_history` (`change_time`, `user_id`, `username_new`, `username_new_clean`, `username_old`, `username_old_clean`) VALUES (:time, :user, :new, :new_clean, :old, :old_clean)')
->execute([
'time' => time(),
'user' => $this->id,
@ -1147,7 +1147,7 @@ class User
]);
// Update userrow
DB::prepare('UPDATE `{prefix}users` SET `username` = :username, `username_clean` = :clean WHERE `user_id` = :id')
DBv2::prepare('UPDATE `{prefix}users` SET `username` = :username, `username_clean` = :clean WHERE `user_id` = :id')
->execute([
'username' => $username,
'clean' => $username_clean,
@ -1173,7 +1173,7 @@ class User
}
// Check if the username is already in use
$getInUse = DB::prepare('SELECT * FROM `{prefix}users` WHERE `email` = :email');
$getInUse = DBv2::prepare('SELECT * FROM `{prefix}users` WHERE `email` = :email');
$getInUse->execute([
'email' => $email,
]);
@ -1185,7 +1185,7 @@ class User
}
// Update userrow
DB::prepare('UPDATE `{prefix}users` SET `email` = :email WHERE `user_id` = :id')
DBv2::prepare('UPDATE `{prefix}users` SET `email` = :email WHERE `user_id` = :id')
->execute([
'email' => $email,
'id' => $this->id,
@ -1239,7 +1239,7 @@ class User
$password = Hashing::createHash($new);
// Update userrow
DB::prepare('UPDATE `{prefix}users` SET `password_hash` = :hash, `password_salt` = :salt, `password_algo` = :algo, `password_iter` = :iter, `password_chan` = :chan WHERE `user_id` = :id')
DBv2::prepare('UPDATE `{prefix}users` SET `password_hash` = :hash, `password_salt` = :salt, `password_algo` = :algo, `password_iter` = :iter, `password_chan` = :chan WHERE `user_id` = :id')
->execute([
'hash' => $password[3],
'salt' => $password[2],

View file

@ -85,7 +85,7 @@ class Users
}
// Update last online
DB::prepare('UPDATE `{prefix}users` SET `user_last_online` = :lo WHERE `user_id` = :id')
DBv2::prepare('UPDATE `{prefix}users` SET `user_last_online` = :lo WHERE `user_id` = :id')
->execute([
'lo' => time(),
'id' => $uid,
@ -116,7 +116,7 @@ class Users
}
// Check if we haven't hit the rate limit
$rates = DB::prepare('SELECT * FROM `{prefix}login_attempts` WHERE `attempt_ip` = :ip AND `attempt_timestamp` > :time AND `attempt_success` = 0');
$rates = DBv2::prepare('SELECT * FROM `{prefix}login_attempts` WHERE `attempt_ip` = :ip AND `attempt_timestamp` > :time AND `attempt_success` = 0');
$rates->execute([
'ip' => Net::pton(Net::IP()),
'time' => time() - 1800,
@ -285,7 +285,7 @@ class Users
}
// Check if the e-mail has already been used
$emailCheck = DB::prepare('SELECT `user_id` FROM `{prefix}users` WHERE `email` = :email');
$emailCheck = DBv2::prepare('SELECT `user_id` FROM `{prefix}users` WHERE `email` = :email');
$emailCheck->execute([
'email' => $email,
]);
@ -340,7 +340,7 @@ class Users
$emailClean = Utils::cleanString($email, true);
// Do database request
$user = DB::prepare('SELECT * FROM `{prefix}users` WHERE `username_clean` = :clean AND `email` = :email');
$user = DBv2::prepare('SELECT * FROM `{prefix}users` WHERE `username_clean` = :clean AND `email` = :email');
$user->execute([
'clean' => $usernameClean,
'email' => $emailClean,
@ -423,7 +423,7 @@ class Users
$password = Hashing::createHash($newpass);
// Update the user
DB::prepare('UPDATE `{prefix}users` SET `password_hash` = :hash, `password_salt` = :salt, `password_algo` = :algo, `password_iter` = :iter, `password_chan` = :chan WHERE `user_id` = :id')
DBv2::prepare('UPDATE `{prefix}users` SET `password_hash` = :hash, `password_salt` = :salt, `password_algo` = :algo, `password_iter` = :iter, `password_chan` = :chan WHERE `user_id` = :id')
->execute([
'hash' => $password[3],
'salt' => $password[2],
@ -457,7 +457,7 @@ class Users
$emailClean = Utils::cleanString($email, true);
// Do database request
$user = DB::prepare('SELECT * FROM `{prefix}users` WHERE `username_clean` = :clean AND `email` = :email');
$user = DBv2::prepare('SELECT * FROM `{prefix}users` WHERE `username_clean` = :clean AND `email` = :email');
$user->execute([
'clean' => $usernameClean,
'email' => $emailClean,
@ -590,7 +590,7 @@ class Users
public static function userExists($id, $unused = null)
{
// Do database request
$user = DB::prepare('SELECT * FROM `{prefix}users` WHERE `user_id` = :id OR `username_clean` = :clean');
$user = DBv2::prepare('SELECT * FROM `{prefix}users` WHERE `user_id` = :id OR `username_clean` = :clean');
$user->execute([
'id' => $id,
'clean' => Utils::cleanString($id, true, true),
@ -609,7 +609,7 @@ class Users
public static function getProfileFields()
{
// Get profile fields
$profileFields = DB::prepare('SELECT * FROM `{prefix}profilefields`');
$profileFields = DBv2::prepare('SELECT * FROM `{prefix}profilefields`');
$profileFields->execute();
$profileFields = $profileFields->fetchAll(\PDO::FETCH_ASSOC);
@ -640,7 +640,7 @@ class Users
public static function getOptionFields()
{
// Get option fields
$optionFields = DB::prepare('SELECT * FROM `{prefix}optionfields`');
$optionFields = DBv2::prepare('SELECT * FROM `{prefix}optionfields`');
$optionFields->execute();
$optionFields = $optionFields->fetchAll(\PDO::FETCH_ASSOC);
@ -680,7 +680,7 @@ class Users
$return = [];
// Get all online users in the past 5 minutes
$getAll = DB::prepare('SELECT * FROM `{prefix}users` WHERE `user_last_online` > :lo');
$getAll = DBv2::prepare('SELECT * FROM `{prefix}users` WHERE `user_last_online` > :lo');
$getAll->execute([
'lo' => $time,
]);
@ -705,7 +705,7 @@ class Users
public static function addUserPremium($id, $seconds)
{
// Check if there's already a record of premium for this user in the database
$getUser = DB::prepare('SELECT * FROM `{prefix}premium` WHERE `user_id` = :user');
$getUser = DBv2::prepare('SELECT * FROM `{prefix}premium` WHERE `user_id` = :user');
$getUser->execute([
'user' => $id,
]);
@ -717,14 +717,14 @@ class Users
// If the user already exists do an update call, otherwise an insert call
if (empty($getUser)) {
DB::prepare('INSERT INTO `{prefix}premium` (`user_id`, `premium_start`, `premium_expire`) VALUES (:user, :start, :expire)')
DBv2::prepare('INSERT INTO `{prefix}premium` (`user_id`, `premium_start`, `premium_expire`) VALUES (:user, :start, :expire)')
->execute([
'user' => $id,
'start' => $start,
'expire' => $expire,
]);
} else {
DB::prepare('UPDATE `{prefix}premium` SET `premium_expire` = :expire WHERE `user_id` = :id')
DBv2::prepare('UPDATE `{prefix}premium` SET `premium_expire` = :expire WHERE `user_id` = :id')
->execute([
'expire' => $expire,
'user_id' => $id,
@ -763,7 +763,7 @@ class Users
}
} elseif (!$check[0]) {
// Remove the expired entry
DB::prepare('DELETE FROM `{prefix}premium` WHERE `user_id` = :user')
DBv2::prepare('DELETE FROM `{prefix}premium` WHERE `user_id` = :user')
->execute([
'user' => $user->id,
]);
@ -783,7 +783,7 @@ class Users
public static function getUsersByIP($ip)
{
// Get the users
$users = DB::prepare('SELECT * FROM `{prefix}users` WHERE `register_ip` = :rip OR `last_ip` = :lip');
$users = DBv2::prepare('SELECT * FROM `{prefix}users` WHERE `register_ip` = :rip OR `last_ip` = :lip');
$users->execute([
'rip' => $ip,
'lip' => $ip,
@ -802,7 +802,7 @@ class Users
public static function getAllRanks()
{
// Execute query
$getRanks = DB::prepare('SELECT * FROM `{prefix}ranks`');
$getRanks = DBv2::prepare('SELECT * FROM `{prefix}ranks`');
$getRanks->execute();
$getRanks = $getRanks->fetchAll();
@ -836,7 +836,7 @@ class Users
$read = $excludeRead ? '0' : '%';
// Get notifications for the database
$notifications = DB::prepare('SELECT * FROM `{prefix}notifications` WHERE `user_id` = :user AND `alert_timestamp` > :time AND `alert_read` = :read');
$notifications = DBv2::prepare('SELECT * FROM `{prefix}notifications` WHERE `user_id` = :user AND `alert_timestamp` > :time AND `alert_read` = :read');
$notifications->execute([
'user' => $uid,
'time' => $time,
@ -871,7 +871,7 @@ class Users
public static function markNotificationRead($id, $mode = true)
{
// Execute an update statement
DB::prepare('UPDATE `{prefix}notifications` SET `alert_read` = :read WHERE `alert_id` = :id')
DBv2::prepare('UPDATE `{prefix}notifications` SET `alert_read` = :read WHERE `alert_id` = :id')
->execute([
'read' => ($mode ? 1 : 0),
'id' => $id,
@ -892,7 +892,7 @@ class Users
public static function createNotification($user, $title, $text, $timeout = 60000, $img = 'FONT:fa-info-circle', $link = '', $sound = 0)
{
// Insert it into the database
DB::prepare('INSERT INTO `{prefix}notifications` (`user_id`, `alert_timestamp`, `alert_read`, `alert_sound`, `alert_title`, `alert_text`, `alert_link`, `alert_img`, `alert_timeout`) VALUES (:user, :time, :read, :sound, :title, :text, :link, :img, :timeout)')
DBv2::prepare('INSERT INTO `{prefix}notifications` (`user_id`, `alert_timestamp`, `alert_read`, `alert_sound`, `alert_title`, `alert_text`, `alert_link`, `alert_img`, `alert_timeout`) VALUES (:user, :time, :read, :sound, :title, :text, :link, :img, :timeout)')
->execute([
'user' => $user,
'time' => time(),
@ -913,7 +913,7 @@ class Users
*/
public static function getNewestUserId()
{
$get = DB::prepare('SELECT `user_id` FROM `{prefix}users` WHERE `rank_main` != :restricted ORDER BY `user_id` DESC LIMIT 1');
$get = DBv2::prepare('SELECT `user_id` FROM `{prefix}users` WHERE `rank_main` != :restricted ORDER BY `user_id` DESC LIMIT 1');
$get->execute([
'restricted' => Config::get('restricted_rank_id'),
]);

View file

@ -61,12 +61,12 @@ class Utils
$errfile = str_replace(ROOT, '', $errfile);
// Attempt to log the error to the database
if (DB::$db !== null) {
if (DBv2::$db !== null) {
// Encode backtrace data
$backtrace = base64_encode(json_encode(debug_backtrace()));
// Check if this error has already been logged in the past
$past = DB::prepare('SELECT * FROM `{prefix}error_log` WHERE `error_backtrace` = :bc OR (`error_string` = :str AND `error_line` = :li)');
$past = DBv2::prepare('SELECT * FROM `{prefix}error_log` WHERE `error_backtrace` = :bc OR (`error_string` = :str AND `error_line` = :li)');
$past->execute([
'bc' => $backtrace,
'str' => $errstr,
@ -82,7 +82,7 @@ class Utils
$errid = substr(md5(microtime()), rand(0, 22), 10);
// Log the error
DB::prepare('INSERT INTO `{prefix}error_log` (`error_id`, `error_timestamp`, `error_revision`, `error_type`, `error_line`, `error_string`, `error_file`, `error_backtrace`) VALUES (:id, :time, :rev, :type, :line, :string, :file, :bc)')
DBv2::prepare('INSERT INTO `{prefix}error_log` (`error_id`, `error_timestamp`, `error_revision`, `error_type`, `error_line`, `error_string`, `error_file`, `error_backtrace`) VALUES (:id, :time, :rev, :type, :line, :string, :file, :bc)')
->execute([
'id' => $errid,
'time' => date("r"),
@ -431,7 +431,7 @@ class Utils
$data = [];
// Get database stuff
$table = DB::prepare('SELECT * FROM `{prefix}premium_log` ORDER BY `transaction_id` DESC');
$table = DBv2::prepare('SELECT * FROM `{prefix}premium_log` ORDER BY `transaction_id` DESC');
$table->execute();
$table = $table->fetchAll(\PDO::FETCH_ASSOC);
@ -468,7 +468,7 @@ class Utils
*/
public static function updatePremiumTracker($id, $amount, $comment)
{
DB::prepare('INSERT INTO `{prefix}premium_log` (`user_id`, `transaction_amount`, `transaction_date`, `transaction_comment`) VALUES (:user, :amount, :date, :comment)')
DBv2::prepare('INSERT INTO `{prefix}premium_log` (`user_id`, `transaction_amount`, `transaction_date`, `transaction_comment`) VALUES (:user, :amount, :date, :comment)')
->execute([
'user' => $id,
'amount' => $amount,

0
mahou Executable file → Normal file
View file

View file

@ -184,7 +184,7 @@ if (isset($_REQUEST['mode'])) {
// Check if we're not RATE_LIMIT
if ($login[1] != 'RATE_LIMIT') {
// Add to database
DB::prepare('INSERT INTO `{prefix}login_attempts` (`attempt_success`, `attempt_timestamp`, `attempt_ip`, `user_id`) VALUES (:succ, :time, :ip, :user)')
DBv2::prepare('INSERT INTO `{prefix}login_attempts` (`attempt_success`, `attempt_timestamp`, `attempt_ip`, `user_id`) VALUES (:succ, :time, :ip, :user)')
->execute([
'succ' => $login[0],
'time' => time(),

View file

@ -67,7 +67,7 @@ if (!isset($thread) && !$forum->permission(ForumPerms::CREATE_THREADS, $currentU
$mode = isset($_GET['f']) ? 'f' : (isset($_GET['t']) ? 't' : (isset($_GET['p']) ? 'p' : null));
$emotes = DB::prepare('SELECT * FROM `{prefix}emoticons`');
$emotes = DBv2::prepare('SELECT * FROM `{prefix}emoticons`');
$emotes->execute();
// Include emotes and bbcodes
@ -201,7 +201,7 @@ if ($mode != 'f') {
// Post deletion code
if (isset($_POST['yes'])) {
// Delete the post
DB::prepare('DELETE FROM `{prefix}posts` WHERE `post_id` = :post')
DBv2::prepare('DELETE FROM `{prefix}posts` WHERE `post_id` = :post')
->execute([
'post' => $_POST['post_id'],
]);
@ -211,7 +211,7 @@ if ($mode != 'f') {
// If there's no more posts left in the topic delete it as well
if (!$thread->replyCount()) {
DB::prepare('DELETE FROM `{prefix}topics` WHERE `topic_id` = :thread')
DBv2::prepare('DELETE FROM `{prefix}topics` WHERE `topic_id` = :thread')
->execute([
'thread' => $thread->id,
]);

View file

@ -617,7 +617,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
}
// Update table
DB::prepare($stmt)
DBv2::prepare($stmt)
->execute([
'img' => $fileId,
'user' => $currentUser->id,
@ -640,12 +640,12 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
foreach ($fields as $field) {
// Add to the store array
if (isset($_POST['profile_' . $field['field_identity']]) && !empty($_POST['profile_' . $field['field_identity']])) {
DB::prepare('DELETE FROM `{prefix}user_profilefields` WHERE `user_id` = :user AND `field_name` = :id')
DBv2::prepare('DELETE FROM `{prefix}user_profilefields` WHERE `user_id` = :user AND `field_name` = :id')
->execute([
'user' => $currentUser->id,
'id' => $field['field_identity'],
]);
DB::prepare('INSERT INTO `{prefix}user_profilefields` (`user_id`, `field_name`, `field_value`) VALUES (:user, :name, :value)')
DBv2::prepare('INSERT INTO `{prefix}user_profilefields` (`user_id`, `field_name`, `field_value`) VALUES (:user, :name, :value)')
->execute([
'user' => $currentUser->id,
'name' => $field['field_identity'],
@ -659,12 +659,12 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
foreach ($field['field_additional'] as $addKey => $addVal) {
// Add to the array
$store = (isset($_POST['profile_additional_' . $addKey]) || !empty($_POST['profile_additional_' . $addKey])) ? $_POST['profile_additional_' . $addKey] : false;
DB::prepare('DELETE FROM `{prefix}user_profilefields` WHERE `user_id` = :user AND `field_name` = :id')
DBv2::prepare('DELETE FROM `{prefix}user_profilefields` WHERE `user_id` = :user AND `field_name` = :id')
->execute([
'user' => $currentUser->id,
'id' => $addKey,
]);
DB::prepare('INSERT INTO `{prefix}user_profilefields` (`user_id`, `field_name`, `field_value`) VALUES (:user, :name, :value)')
DBv2::prepare('INSERT INTO `{prefix}user_profilefields` (`user_id`, `field_name`, `field_value`) VALUES (:user, :name, :value)')
->execute([
'user' => $currentUser->id,
'name' => $addKey,
@ -731,7 +731,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
[$_POST['birthday_year'], $_POST['birthday_month'], $_POST['birthday_day']]
);
DB::prepare('UPDATE `{prefix}users` SET `user_birthday` = :bd WHERE `user_id` = :id')
DBv2::prepare('UPDATE `{prefix}users` SET `user_birthday` = :bd WHERE `user_id` = :id')
->execute([
'bd' => $birthdate,
'id' => $currentUser->id,
@ -746,7 +746,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
// Go over each field
foreach ($fields as $field) {
DB::prepare('DELETE FROM `{prefix}user_optionfields` WHERE `user_id` = :user AND `field_name` = :id')
DBv2::prepare('DELETE FROM `{prefix}user_optionfields` WHERE `user_id` = :user AND `field_name` = :id')
->execute([
'user' => $currentUser->id,
'id' => $field['option_id'],
@ -759,7 +759,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
if (isset($_POST['option_' . $field['option_id']])
&& !empty($_POST['option_' . $field['option_id']])) {
DB::prepare('INSERT INTO `{prefix}user_optionfields` (`user_id`, `field_name`, `field_value`) VALUES (:user, :name, :value)')
DBv2::prepare('INSERT INTO `{prefix}user_optionfields` (`user_id`, `field_name`, `field_value`) VALUES (:user, :name, :value)')
->execute([
'user' => $currentUser->id,
'name' => $field['option_id'],
@ -801,7 +801,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
}
// Update database
DB::prepare('UPDATE `{prefix}users` SET `user_title` = :title WHERE `user_id` = :id')
DBv2::prepare('UPDATE `{prefix}users` SET `user_title` = :title WHERE `user_id` = :id')
->execute([
'title' => (isset($_POST['usertitle']) ? $_POST['usertitle'] : null),
'id' => $currentUser->id,
@ -938,7 +938,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
}
// Update database
DB::prepare('UPDATE `{prefix}users` SET `user_page` = :up WHERE `user_id` = :id')
DBv2::prepare('UPDATE `{prefix}users` SET `user_page` = :up WHERE `user_id` = :id')
->execute([
'up' => $_POST['userpage'],
'id' => $currentUser->id,
@ -964,7 +964,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
}
// Update database
DB::prepare('UPDATE `{prefix}users` SET `user_signature` = :us WHERE `user_id` = :id')
DBv2::prepare('UPDATE `{prefix}users` SET `user_signature` = :us WHERE `user_id` = :id')
->execute([
'us' => $_POST['signature'],
'id' => $currentUser->id,
@ -1049,7 +1049,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
// Check if sessionid is set to all
if ($_POST['sessionid'] === 'all') {
// Delete all sessions assigned to the current user
DB::prepare('DELETE FROM `{prefix}sessions` WHERE `user_id` = :user')
DBv2::prepare('DELETE FROM `{prefix}sessions` WHERE `user_id` = :user')
->execute([
'user' => $currentUser->id,
]);
@ -1064,7 +1064,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
}
// Check if the session is owned by the current user
$us = DB::prepare('SELECT * FROM `{prefix}sessions` WHERE `user_id` = :user AND `session_id` = :key');
$us = DBv2::prepare('SELECT * FROM `{prefix}sessions` WHERE `user_id` = :user AND `session_id` = :key');
$us->execute([
'user' => $currentUser->id,
'key' => $_POST['sessionid'],
@ -1079,7 +1079,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
}
// Delete the session
DB::prepare('DELETE FROM `{prefix}sessions` WHERE `user_id` = :user AND `session_id` = :session')
DBv2::prepare('DELETE FROM `{prefix}sessions` WHERE `user_id` = :user AND `session_id` = :session')
->execute([
'user' => $currentUser->id,
'session' => $_POST['sessionid'],
@ -1519,7 +1519,7 @@ if (Users::checkLogin()) {
// Sessions
case 'advanced.sessions':
$sessions = DB::prepare('SELECT * FROM `{prefix}sessions` WHERE `user_id` = :user');
$sessions = DBv2::prepare('SELECT * FROM `{prefix}sessions` WHERE `user_id` = :user');
$sessions->execute([
'user' => $currentUser->id,
]);

View file

@ -65,7 +65,7 @@ Config::init(ROOT . 'config/config.ini');
error_reporting(Config::local('dev', 'show_errors') ? -1 : 0);
// Make the database connection
DB::open(
DBv2::open(
Config::local('database', 'driver'),
Config::local('dsn'),
Config::local('database', 'username'),
@ -73,6 +73,15 @@ DB::open(
Config::local('database', 'prefix')
);
// Create a new database capsule
$capsule = new \Illuminate\Database\Capsule\Manager;
// Add the connection
$capsule->addConnection(Config::local('database'));
// Make the capsule globally accessible
$capsule->setAsGlobal();
// Check if we the system has a cron service
if (Config::get('no_cron_service')) {
// If not do an "asynchronous" call to the cron.php script