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": { "require": {
"php": ">=5.4.0", "php": ">=5.4.0",
"ext-curl": "*", "ext-curl": "*",
@ -8,6 +16,7 @@
"paypal/rest-api-sdk-php": "*", "paypal/rest-api-sdk-php": "*",
"jbbcode/jbbcode": "*", "jbbcode/jbbcode": "*",
"corneltek/cliframework": "*", "corneltek/cliframework": "*",
"phroute/phroute": "^2.1" "phroute/phroute": "^2.1",
"illuminate/database": "5.2.7"
} }
} }

View file

@ -21,23 +21,21 @@ define('SAKURA_NO_TPL', true);
require_once 'sakura.php'; require_once 'sakura.php';
// Clean expired sessions // Clean expired sessions
$cleanSessions = DB::prepare('DELETE FROM `{prefix}sessions` WHERE `session_expire` < :time AND `session_remember` != 1'); DB::table('sessions')
$cleanSessions->execute([ ->where('session_expire', '<', time())
'time' => time(), ->where('session_remember', '!=', 1)
]); ->delete();
// Delete notifications that are older than a month but not unread // 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'); DB::table('notifications')
$cleanAlerts->execute([ ->where('alert_timestamp', '<', (time() - 109500))
'time' => (time() - 109500), ->where('alert_read', 1)
]); ->delete();
// Get expired premium accounts // Get expired premium accounts
$expiredPremium = DB::prepare('SELECT * FROM `{prefix}premium` WHERE `premium_expire` < :time'); $expiredPremium = DB::table('premium')
$expiredPremium->execute([ ->where('premium_expire', '<', time())
'time' => time(), ->get();
]);
$expiredPremium = $expiredPremium->fetchAll();
// Process expired premium accounts, make this not stupid in the future // Process expired premium accounts, make this not stupid in the future
foreach ($expiredPremium as $expired) { 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(); $code = uniqid();
// Insert it // Insert it
DB::prepare('INSERT INTO `{prefix}actioncodes` (`code_action`, `user_id`, `action_code`) VALUES (:action, :id, :code)') DB::table('actioncodes')
->execute([ ->insert(
'action' => $action, ['action' => $action, 'id' => $user, 'code' => $code]
'id' => $user, );
'code' => $code,
]);
// Return the code // Return the code
return $code; return $code;
@ -53,16 +51,14 @@ class ActionCode
public static function validate($action, $code, $user = 0, $invalidate = true) public static function validate($action, $code, $user = 0, $invalidate = true)
{ {
// Fetch the code from the db // 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 = DB::table('actioncodes')
$get->execute([ ->where('code_action', $action)
'code' => $action, ->where('action_code', $code)
'action' => $code, ->where('user_id', $user)
'id' => $user, ->count();
]);
$get = $get->rowCount();
// Invalidate the code if requested // Invalidate the code if requested
if ($invalidate) { if ($get && $invalidate) {
self::invalidate($code); self::invalidate($code);
} }
@ -77,9 +73,8 @@ class ActionCode
*/ */
public static function invalidate($code) public static function invalidate($code)
{ {
DB::prepare('DELETE FROM `{prefix}actioncodes` WHERE `code_action` = :code') DB::table('actioncodes')
->execute([ ->where('code_action', $code)
'code' => $code, ->delete();
]);
} }
} }

View file

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

View file

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

View file

@ -47,7 +47,7 @@ class Comments
$this->category = $category; $this->category = $category;
// Get the comments and assign them to $comments // 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([ $comments->execute([
'category' => $this->category, 'category' => $this->category,
]); ]);
@ -96,7 +96,7 @@ class Comments
$this->count += 1; $this->count += 1;
// Attempt to get replies from the database // 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([ $replies->execute([
'category' => $this->category, 'category' => $this->category,
'thread' => $comment['comment_id'], 'thread' => $comment['comment_id'],
@ -123,7 +123,7 @@ class Comments
public function getComment($cid) public function getComment($cid)
{ {
// Get from database // 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([ $comment->execute([
'id' => $cid, 'id' => $cid,
]); ]);
@ -140,7 +140,7 @@ class Comments
public function getVotes($cid) public function getVotes($cid)
{ {
// Get from database // 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([ $comment->execute([
'id' => $cid, 'id' => $cid,
]); ]);
@ -169,7 +169,7 @@ class Comments
} }
// Insert into database // 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([ ->execute([
'cat' => $this->category, 'cat' => $this->category,
'time' => time(), 'time' => time(),
@ -194,7 +194,7 @@ class Comments
public function makeVote($uid, $cid, $mode) public function makeVote($uid, $cid, $mode)
{ {
// Attempt to get previous vote // 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([ $vote->execute([
'user' => $uid, 'user' => $uid,
'comment' => $cid, 'comment' => $cid,
@ -206,14 +206,14 @@ class Comments
// Check if the vote that's being casted is the same // Check if the vote that's being casted is the same
if ($vote['vote_state'] == $mode) { if ($vote['vote_state'] == $mode) {
// Delete the vote // 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([ ->execute([
'user' => $uid, 'user' => $uid,
'comment' => $cid, 'comment' => $cid,
]); ]);
} else { } else {
// Otherwise update the vote // 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([ ->execute([
'state' => $mode, 'state' => $mode,
'user' => $uid, 'user' => $uid,
@ -222,7 +222,7 @@ class Comments
} }
} else { } else {
// Create a vote // 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([ ->execute([
'user' => $uid, 'user' => $uid,
'comment' => $cid, 'comment' => $cid,
@ -241,7 +241,7 @@ class Comments
public function removeComment($cid) public function removeComment($cid)
{ {
// Remove from database // Remove from database
DB::prepare('DELETE FROM `{prefix}comments` WHERE `comment_id` = :id') DBv2::prepare('DELETE FROM `{prefix}comments` WHERE `comment_id` = :id')
->execute([ ->execute([
'id' => $cid, 'id' => $cid,
]); ]);

View file

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

View file

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

View file

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

View file

@ -9,6 +9,7 @@ namespace Sakura\Controllers;
use Sakura\Config; use Sakura\Config;
use Sakura\DB; use Sakura\DB;
use Sakura\DBv2;
use Sakura\Rank; use Sakura\Rank;
use Sakura\Template; use Sakura\Template;
use Sakura\User as UserContext; 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 the user id is zero check if there was a namechange
if ($profile->id == 0) { if ($profile->id == 0) {
// Fetch from username_history // 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 = DB::table('username_history')
$check->execute([ ->where('username_old_clean', Utils::cleanString($id, true, true))
'uname' => Utils::cleanString($id, true, true), ->orderBy('change_id', 'desc')
]); ->get();
$check = $check->fetch();
// Redirect if so // Redirect if so
if ($check) { if ($check) {
Template::vars([ Template::vars([
'page' => [ 'page' => [
'message' => 'The user this profile belongs to changed their username, you are being redirected.', '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 <?php
/** /**
* Holds the database wrapper (v2). * Holds the alias class for the Illuminate database thing.
* *
* @package Sakura * @package Sakura
*/ */
namespace Sakura; namespace Sakura;
use PDO; use \Illuminate\Database\Capsule\Manager;
use PDOException;
use PDOStatement;
/** /**
* A wrapper to make the database communication experience smoother. * The Illuminate (Laravel) database wrapper.
* *
* @package Sakura * @package Sakura
* @author Julian van de Groep <me@flash.moe> * @author Julian van de Groep <me@flash.moe>
*/ */
class DB class DB extends Manager
{ {
/** // This class solely exists as an alias (for now at least)
* 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);
}
} }

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

View file

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

View file

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

View file

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

View file

@ -31,7 +31,7 @@ class News
{ {
// Get the news posts and assign them to $posts // 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([ $posts->execute([
'cat' => $category, 'cat' => $category,
]); ]);

View file

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

View file

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

View file

@ -53,11 +53,10 @@ class Session
public function destroy() public function destroy()
{ {
// Invalidate the session key // Invalidate the session key
DB::prepare('DELETE FROM `{prefix}sessions` WHERE `session_key` = :key AND `user_id` = :user') DB::table('sessions')
->execute([ ->where('session_key', $this->sessionId)
'key' => $this->sessionId, ->where('user_id', $this->userId)
'user' => $this->userId, ->delete();
]);
// Unset userId and sessionId // Unset userId and sessionId
unset($this->userId); unset($this->userId);
@ -75,10 +74,9 @@ class Session
public function destroyAll() public function destroyAll()
{ {
// Delete all database entries with this user in it // Delete all database entries with this user in it
DB::prepare('DELETE FROM `{prefix}sessions` WHERE `user_id` = :user') DB::table('sessions')
->execute([ ->where('user_id', $this->userId)
'user' => $this->userId, ->delete();
]);
// Destroy this session to finish it off // Destroy this session to finish it off
$this->destroy(); $this->destroy();
@ -97,15 +95,15 @@ class Session
$session = hash('sha256', $this->userId . base64_encode('sakura' . mt_rand(0, 99999999)) . time()); $session = hash('sha256', $this->userId . base64_encode('sakura' . mt_rand(0, 99999999)) . time());
// Insert the session into the database // 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)') DB::table('sessions')
->execute([ ->insert([
'id' => $this->userId, 'user_id' => $this->userId,
'ip' => Net::pton(Net::IP()), 'user_ip' => Net::pton(Net::IP()),
'agent' => Utils::cleanString(isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'No user agent header.'), 'user_agent' => Utils::cleanString(isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'No user agent header.'),
'key' => $session, 'session_key' => $session,
'start' => time(), 'session_start' => time(),
'end' => time() + 604800, 'session_expire' => time() + 604800,
'remember' => $permanent ? '1' : '0', 'session_remember' => $permanent ? '1' : '0',
]); ]);
// Return the session key // Return the session key
@ -120,12 +118,10 @@ class Session
public function validate() public function validate()
{ {
// Get session from database // Get session from database
$session = DB::prepare('SELECT * FROM `{prefix}sessions` WHERE `user_id` = :user AND `session_key` = :key'); $session = DB::table('sessions')
$session->execute([ ->where('user_id', $this->userId)
'user' => $this->userId, ->where('session_key', $this->sessionId)
'key' => $this->sessionId, ->get();
]);
$session = $session->fetch();
// Check if we actually got something in return // Check if we actually got something in return
if (!$session) { if (!$session) {
@ -133,7 +129,7 @@ class Session
} }
// Check if the session expired // Check if the session expired
if ($session->session_expire < time()) { if ($session[0]->session_expire < time()) {
// ...and return false // ...and return false
return 0; return 0;
} }
@ -144,7 +140,7 @@ class Session
// Origin checking // Origin checking
if ($ipCheck) { if ($ipCheck) {
// Split both IPs up // Split both IPs up
$sessionIP = explode('.', $session['user_ip']); $sessionIP = explode('.', $session[0]->user_ip);
$userIP = explode('.', Net::IP()); $userIP = explode('.', Net::IP());
// Take 1 off the ipCheck variable so it's equal to the array keys // 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 the remember flag is set extend the session time
if ($session->session_remember) { if ($session[0]->session_remember) {
DB::prepare('UPDATE `{prefix}sessions` SET `session_expire` = :expire WHERE `session_id` = :id') DB::table('sessions')
->execute([ ->where('session_id', $session[0]->session_id)
'expire' => time() + 604800, ->update(['session_expire' => time() + 604800]);
'id' => $session->session_id,
]);
} }
// Return 2 if the remember flag is set and return 1 if not // 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); $password = Hashing::createHash($password);
// Insert the user into the database // 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([ ->execute([
'uname' => $username, 'uname' => $username,
'uname_clean' => $usernameClean, 'uname_clean' => $usernameClean,
@ -276,7 +276,7 @@ class User
]); ]);
// Get the last id // Get the last id
$userId = DB::lastID(); $userId = DBv2::lastID();
// Create a user object // Create a user object
$user = self::construct($userId); $user = self::construct($userId);
@ -299,7 +299,7 @@ class User
private function __construct($uid) private function __construct($uid)
{ {
// Get the user database row // 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([ $userRow->execute([
'id' => $uid, 'id' => $uid,
'clean' => Utils::cleanString($uid, true, true), 'clean' => Utils::cleanString($uid, true, true),
@ -334,7 +334,7 @@ class User
} }
// Get all ranks // 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([ $ranks->execute([
'id' => $this->id, 'id' => $this->id,
]); ]);
@ -426,7 +426,7 @@ class User
public function isOnline() public function isOnline()
{ {
// Get all sessions // 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([ $sessions->execute([
'id' => $this->id, 'id' => $this->id,
]); ]);
@ -447,12 +447,12 @@ class User
*/ */
public function forumStats() 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([ $posts->execute([
'id' => $this->id, '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([ $threads->execute([
'id' => $this->id, 'id' => $this->id,
]); ]);
@ -482,7 +482,7 @@ class User
// Save to the database // Save to the database
foreach ($ranks as $rank) { 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([ ->execute([
'rank' => $rank, 'rank' => $rank,
'user' => $this->id, 'user' => $this->id,
@ -502,7 +502,7 @@ class User
// Iterate over the ranks // Iterate over the ranks
foreach ($remove as $rank) { 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([ ->execute([
'user' => $this->id, 'user' => $this->id,
'rank' => $rank, 'rank' => $rank,
@ -520,7 +520,7 @@ class User
public function setMainRank($rank) public function setMainRank($rank)
{ {
// If it does exist update their row // 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([ ->execute([
'rank' => $rank, 'rank' => $rank,
'id' => $this->id, 'id' => $this->id,
@ -579,7 +579,7 @@ class User
} }
// Add friend // 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([ ->execute([
'user' => $this->id, 'user' => $this->id,
'friend' => $uid, 'friend' => $uid,
@ -609,7 +609,7 @@ class User
} }
// Prepare the statement // 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 // Remove friend
$rem->execute([ $rem->execute([
@ -639,7 +639,7 @@ class User
public function isFriends($with) public function isFriends($with)
{ {
// Accepted from this user // 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([ $get->execute([
'user' => $this->id, 'user' => $this->id,
'friend' => $with, 'friend' => $with,
@ -681,14 +681,14 @@ class User
// Mutual // Mutual
case 2: case 2:
// Get all the current user's friends // 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([ $self->execute([
'user' => $this->id, 'user' => $this->id,
]); ]);
$self = array_column($self->fetchAll(\PDO::FETCH_ASSOC), 'friend_id'); $self = array_column($self->fetchAll(\PDO::FETCH_ASSOC), 'friend_id');
// Get all the people that added this user as a friend // 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([ $others->execute([
'user' => $this->id, 'user' => $this->id,
]); ]);
@ -700,7 +700,7 @@ class User
// Non-mutual (from user perspective) // Non-mutual (from user perspective)
case 1: 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([ $users->execute([
'user' => $this->id, 'user' => $this->id,
]); ]);
@ -711,14 +711,14 @@ class User
case 0: case 0:
default: default:
// Get all the current user's friends // 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([ $self->execute([
'user' => $this->id, 'user' => $this->id,
]); ]);
$self = array_column($self->fetchAll(\PDO::FETCH_ASSOC), 'friend_id'); $self = array_column($self->fetchAll(\PDO::FETCH_ASSOC), 'friend_id');
// Get all the people that added this user as a friend // 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([ $others->execute([
'user' => $this->id, 'user' => $this->id,
]); ]);
@ -731,14 +731,14 @@ class User
// Open requests // Open requests
case -1: case -1:
// Get all the current user's friends // 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([ $self->execute([
'user' => $this->id, 'user' => $this->id,
]); ]);
$self = array_column($self->fetchAll(\PDO::FETCH_ASSOC), 'friend_id'); $self = array_column($self->fetchAll(\PDO::FETCH_ASSOC), 'friend_id');
// Get all the people that added this user as a friend // 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([ $others->execute([
'user' => $this->id, 'user' => $this->id,
]); ]);
@ -824,11 +824,11 @@ class User
// Create array and get values // Create array and get values
$profile = []; $profile = [];
$profileFields = DB::prepare('SELECT * FROM `{prefix}profilefields`'); $profileFields = DBv2::prepare('SELECT * FROM `{prefix}profilefields`');
$profileFields->execute(); $profileFields->execute();
$profileFields = $profileFields->fetchAll(\PDO::FETCH_ASSOC); $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([ $profileValuesRaw->execute([
'user' => $this->id, 'user' => $this->id,
]); ]);
@ -912,11 +912,11 @@ class User
// Create array and get values // Create array and get values
$options = []; $options = [];
$optionFields = DB::prepare('SELECT * FROM `{prefix}optionfields`'); $optionFields = DBv2::prepare('SELECT * FROM `{prefix}optionfields`');
$optionFields->execute(); $optionFields->execute();
$optionFields = $optionFields->fetchAll(\PDO::FETCH_ASSOC); $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([ $optionValuesRaw->execute([
'user' => $this->id, 'user' => $this->id,
]); ]);
@ -972,7 +972,7 @@ class User
} }
// Attempt to retrieve the premium record from the database // 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([ $getRecord->execute([
'user' => $this->id, 'user' => $this->id,
]); ]);
@ -1000,7 +1000,7 @@ class User
public function getWarnings() public function getWarnings()
{ {
// Do the database query // 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([ $getWarnings->execute([
'user' => $this->id, 'user' => $this->id,
]); ]);
@ -1013,7 +1013,7 @@ class User
foreach ($getWarnings as $warning) { foreach ($getWarnings as $warning) {
// Check if it hasn't expired // Check if it hasn't expired
if ($warning['warning_expires'] < time()) { 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([ ->execute([
'warn' => $warning['warning_id'], 'warn' => $warning['warning_id'],
]); ]);
@ -1079,7 +1079,7 @@ class User
public function getUsernameHistory() public function getUsernameHistory()
{ {
// Do the database query // 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([ $changes->execute([
'user' => $this->id, '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 // 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([ $getOld->execute([
'clean' => $username_clean, 'clean' => $username_clean,
'time' => (Config::get('old_username_reserve') * 24 * 60 * 60), 'time' => (Config::get('old_username_reserve') * 24 * 60 * 60),
@ -1124,7 +1124,7 @@ class User
} }
// Check if the username is already in use // 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([ $getInUse->execute([
'clean' => $username_clean, 'clean' => $username_clean,
]); ]);
@ -1136,7 +1136,7 @@ class User
} }
// Insert into username_history table // 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([ ->execute([
'time' => time(), 'time' => time(),
'user' => $this->id, 'user' => $this->id,
@ -1147,7 +1147,7 @@ class User
]); ]);
// Update userrow // 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([ ->execute([
'username' => $username, 'username' => $username,
'clean' => $username_clean, 'clean' => $username_clean,
@ -1173,7 +1173,7 @@ class User
} }
// Check if the username is already in use // 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([ $getInUse->execute([
'email' => $email, 'email' => $email,
]); ]);
@ -1185,7 +1185,7 @@ class User
} }
// Update userrow // 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([ ->execute([
'email' => $email, 'email' => $email,
'id' => $this->id, 'id' => $this->id,
@ -1239,7 +1239,7 @@ class User
$password = Hashing::createHash($new); $password = Hashing::createHash($new);
// Update userrow // 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([ ->execute([
'hash' => $password[3], 'hash' => $password[3],
'salt' => $password[2], 'salt' => $password[2],

View file

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

View file

@ -61,12 +61,12 @@ class Utils
$errfile = str_replace(ROOT, '', $errfile); $errfile = str_replace(ROOT, '', $errfile);
// Attempt to log the error to the database // Attempt to log the error to the database
if (DB::$db !== null) { if (DBv2::$db !== null) {
// Encode backtrace data // Encode backtrace data
$backtrace = base64_encode(json_encode(debug_backtrace())); $backtrace = base64_encode(json_encode(debug_backtrace()));
// Check if this error has already been logged in the past // 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([ $past->execute([
'bc' => $backtrace, 'bc' => $backtrace,
'str' => $errstr, 'str' => $errstr,
@ -82,7 +82,7 @@ class Utils
$errid = substr(md5(microtime()), rand(0, 22), 10); $errid = substr(md5(microtime()), rand(0, 22), 10);
// Log the error // 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([ ->execute([
'id' => $errid, 'id' => $errid,
'time' => date("r"), 'time' => date("r"),
@ -431,7 +431,7 @@ class Utils
$data = []; $data = [];
// Get database stuff // 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->execute();
$table = $table->fetchAll(\PDO::FETCH_ASSOC); $table = $table->fetchAll(\PDO::FETCH_ASSOC);
@ -468,7 +468,7 @@ class Utils
*/ */
public static function updatePremiumTracker($id, $amount, $comment) 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([ ->execute([
'user' => $id, 'user' => $id,
'amount' => $amount, '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 // Check if we're not RATE_LIMIT
if ($login[1] != 'RATE_LIMIT') { if ($login[1] != 'RATE_LIMIT') {
// Add to database // 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([ ->execute([
'succ' => $login[0], 'succ' => $login[0],
'time' => time(), '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)); $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(); $emotes->execute();
// Include emotes and bbcodes // Include emotes and bbcodes
@ -201,7 +201,7 @@ if ($mode != 'f') {
// Post deletion code // Post deletion code
if (isset($_POST['yes'])) { if (isset($_POST['yes'])) {
// Delete the post // Delete the post
DB::prepare('DELETE FROM `{prefix}posts` WHERE `post_id` = :post') DBv2::prepare('DELETE FROM `{prefix}posts` WHERE `post_id` = :post')
->execute([ ->execute([
'post' => $_POST['post_id'], '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 there's no more posts left in the topic delete it as well
if (!$thread->replyCount()) { if (!$thread->replyCount()) {
DB::prepare('DELETE FROM `{prefix}topics` WHERE `topic_id` = :thread') DBv2::prepare('DELETE FROM `{prefix}topics` WHERE `topic_id` = :thread')
->execute([ ->execute([
'thread' => $thread->id, 'thread' => $thread->id,
]); ]);

View file

@ -617,7 +617,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
} }
// Update table // Update table
DB::prepare($stmt) DBv2::prepare($stmt)
->execute([ ->execute([
'img' => $fileId, 'img' => $fileId,
'user' => $currentUser->id, 'user' => $currentUser->id,
@ -640,12 +640,12 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
foreach ($fields as $field) { foreach ($fields as $field) {
// Add to the store array // Add to the store array
if (isset($_POST['profile_' . $field['field_identity']]) && !empty($_POST['profile_' . $field['field_identity']])) { 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([ ->execute([
'user' => $currentUser->id, 'user' => $currentUser->id,
'id' => $field['field_identity'], '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([ ->execute([
'user' => $currentUser->id, 'user' => $currentUser->id,
'name' => $field['field_identity'], 'name' => $field['field_identity'],
@ -659,12 +659,12 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
foreach ($field['field_additional'] as $addKey => $addVal) { foreach ($field['field_additional'] as $addKey => $addVal) {
// Add to the array // Add to the array
$store = (isset($_POST['profile_additional_' . $addKey]) || !empty($_POST['profile_additional_' . $addKey])) ? $_POST['profile_additional_' . $addKey] : false; $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([ ->execute([
'user' => $currentUser->id, 'user' => $currentUser->id,
'id' => $addKey, '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([ ->execute([
'user' => $currentUser->id, 'user' => $currentUser->id,
'name' => $addKey, 'name' => $addKey,
@ -731,7 +731,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
[$_POST['birthday_year'], $_POST['birthday_month'], $_POST['birthday_day']] [$_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([ ->execute([
'bd' => $birthdate, 'bd' => $birthdate,
'id' => $currentUser->id, 'id' => $currentUser->id,
@ -746,7 +746,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
// Go over each field // Go over each field
foreach ($fields as $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([ ->execute([
'user' => $currentUser->id, 'user' => $currentUser->id,
'id' => $field['option_id'], 'id' => $field['option_id'],
@ -759,7 +759,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
if (isset($_POST['option_' . $field['option_id']]) if (isset($_POST['option_' . $field['option_id']])
&& !empty($_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([ ->execute([
'user' => $currentUser->id, 'user' => $currentUser->id,
'name' => $field['option_id'], 'name' => $field['option_id'],
@ -801,7 +801,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
} }
// Update database // 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([ ->execute([
'title' => (isset($_POST['usertitle']) ? $_POST['usertitle'] : null), 'title' => (isset($_POST['usertitle']) ? $_POST['usertitle'] : null),
'id' => $currentUser->id, 'id' => $currentUser->id,
@ -938,7 +938,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
} }
// Update database // 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([ ->execute([
'up' => $_POST['userpage'], 'up' => $_POST['userpage'],
'id' => $currentUser->id, 'id' => $currentUser->id,
@ -964,7 +964,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
} }
// Update database // 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([ ->execute([
'us' => $_POST['signature'], 'us' => $_POST['signature'],
'id' => $currentUser->id, 'id' => $currentUser->id,
@ -1049,7 +1049,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
// Check if sessionid is set to all // Check if sessionid is set to all
if ($_POST['sessionid'] === 'all') { if ($_POST['sessionid'] === 'all') {
// Delete all sessions assigned to the current user // 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([ ->execute([
'user' => $currentUser->id, '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 // 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([ $us->execute([
'user' => $currentUser->id, 'user' => $currentUser->id,
'key' => $_POST['sessionid'], 'key' => $_POST['sessionid'],
@ -1079,7 +1079,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification
} }
// Delete the session // 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([ ->execute([
'user' => $currentUser->id, 'user' => $currentUser->id,
'session' => $_POST['sessionid'], 'session' => $_POST['sessionid'],
@ -1519,7 +1519,7 @@ if (Users::checkLogin()) {
// Sessions // Sessions
case 'advanced.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([ $sessions->execute([
'user' => $currentUser->id, 'user' => $currentUser->id,
]); ]);

View file

@ -65,7 +65,7 @@ Config::init(ROOT . 'config/config.ini');
error_reporting(Config::local('dev', 'show_errors') ? -1 : 0); error_reporting(Config::local('dev', 'show_errors') ? -1 : 0);
// Make the database connection // Make the database connection
DB::open( DBv2::open(
Config::local('database', 'driver'), Config::local('database', 'driver'),
Config::local('dsn'), Config::local('dsn'),
Config::local('database', 'username'), Config::local('database', 'username'),
@ -73,6 +73,15 @@ DB::open(
Config::local('database', 'prefix') 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 // Check if we the system has a cron service
if (Config::get('no_cron_service')) { if (Config::get('no_cron_service')) {
// If not do an "asynchronous" call to the cron.php script // If not do an "asynchronous" call to the cron.php script