From bca6c5be99766e9be5154aebb9ed77145ede5806 Mon Sep 17 00:00:00 2001 From: flashwave Date: Thu, 25 Feb 2016 17:06:29 +0100 Subject: [PATCH] half database update and other shit --- composer.json | 13 +- cron.php | 24 +- database/data.sql | 219 -------- database/structure.sql | 911 +++++++++++-------------------- libraries/ActionCode.php | 31 +- libraries/BBcode.php | 5 +- libraries/Bans.php | 15 +- libraries/Comments.php | 20 +- libraries/Config.php | 35 +- libraries/Controllers/Forums.php | 16 +- libraries/Controllers/Meta.php | 32 +- libraries/Controllers/User.php | 12 +- libraries/DB.php | 101 +--- libraries/DBv2.php | 112 ++++ libraries/File.php | 37 +- libraries/Forum/Forum.php | 69 ++- libraries/Forum/Post.php | 61 +-- libraries/Forum/Thread.php | 190 +++---- libraries/News.php | 2 +- libraries/Perms.php | 4 +- libraries/Rank.php | 15 +- libraries/Session.php | 62 +-- libraries/User.php | 70 +-- libraries/Users.php | 40 +- libraries/Utils.php | 10 +- mahou | 0 public/authenticate.php | 2 +- public/posting.php | 6 +- public/settings.php | 30 +- sakura.php | 11 +- 30 files changed, 827 insertions(+), 1328 deletions(-) delete mode 100644 database/data.sql create mode 100644 libraries/DBv2.php mode change 100755 => 100644 mahou diff --git a/composer.json b/composer.json index fd872a7..43da77f 100644 --- a/composer.json +++ b/composer.json @@ -1,4 +1,12 @@ { + "name": "flashwave/sakura", + "description": "Flashii's backend", + "license": "Apache-2.0", + "homepage": "https://sakura.flash.moe", + "support": { + "email": "me@flash.moe", + "issues": "https://github.com/flashwave/sakura/issues" + }, "require": { "php": ">=5.4.0", "ext-curl": "*", @@ -7,7 +15,8 @@ "phpmailer/phpmailer": "*", "paypal/rest-api-sdk-php": "*", "jbbcode/jbbcode": "*", - "corneltek/cliframework": "*", - "phroute/phroute": "^2.1" + "corneltek/cliframework": "*", + "phroute/phroute": "^2.1", + "illuminate/database": "5.2.7" } } diff --git a/cron.php b/cron.php index 56ab8af..a91ee12 100644 --- a/cron.php +++ b/cron.php @@ -21,23 +21,21 @@ define('SAKURA_NO_TPL', true); require_once 'sakura.php'; // Clean expired sessions -$cleanSessions = DB::prepare('DELETE FROM `{prefix}sessions` WHERE `session_expire` < :time AND `session_remember` != 1'); -$cleanSessions->execute([ - 'time' => time(), -]); +DB::table('sessions') + ->where('session_expire', '<', time()) + ->where('session_remember', '!=', 1) + ->delete(); // Delete notifications that are older than a month but not unread -$cleanAlerts = DB::prepare('DELETE FROM `{prefix}notifications` WHERE `alert_timestamp` < :time AND `alert_read` = 1'); -$cleanAlerts->execute([ - 'time' => (time() - 109500), -]); +DB::table('notifications') + ->where('alert_timestamp', '<', (time() - 109500)) + ->where('alert_read', 1) + ->delete(); // Get expired premium accounts -$expiredPremium = DB::prepare('SELECT * FROM `{prefix}premium` WHERE `premium_expire` < :time'); -$expiredPremium->execute([ - 'time' => time(), -]); -$expiredPremium = $expiredPremium->fetchAll(); +$expiredPremium = DB::table('premium') + ->where('premium_expire', '<', time()) + ->get(); // Process expired premium accounts, make this not stupid in the future foreach ($expiredPremium as $expired) { diff --git a/database/data.sql b/database/data.sql deleted file mode 100644 index db04f4c..0000000 --- a/database/data.sql +++ /dev/null @@ -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 do not 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 */; diff --git a/database/structure.sql b/database/structure.sql index 88b1a7d..a918ad4 100644 --- a/database/structure.sql +++ b/database/structure.sql @@ -1,783 +1,526 @@ --- phpMyAdmin SQL Dump --- version 4.5.2 --- http://www.phpmyadmin.net --- --- Host: localhost --- Generation Time: Dec 24, 2015 at 04:58 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"; - +-- -------------------------------------------------------- +-- Host: 127.0.0.1 +-- Server version: 5.7.10-log - MySQL Community Server (GPL) +-- Server OS: Win64 +-- HeidiSQL Version: 9.3.0.4984 +-- -------------------------------------------------------- /*!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 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; --- --- Database: `sakura-development` --- -CREATE DATABASE IF NOT EXISTS `sakura-development` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin; +-- Dumping database structure for sakura-development +CREATE DATABASE IF NOT EXISTS `sakura-development` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */; USE `sakura-development`; --- -------------------------------------------------------- --- --- Table structure for table `sakura_actioncodes` --- - -DROP TABLE IF EXISTS `sakura_actioncodes`; -CREATE TABLE `sakura_actioncodes` ( - `id` bigint(255) NOT NULL COMMENT 'Automatically generated ID by MySQL for management.', - `action` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Action identifier so the backend knows what to do.', - `userid` bigint(255) NOT NULL COMMENT 'ID of the user that would be affected by this action', - `actkey` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'The URL key for using this code.', - `instruction` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Things the backend should do upon using this code' +-- Dumping structure for table sakura-development.sakura_actioncodes +CREATE TABLE IF NOT EXISTS `sakura_actioncodes` ( + `code_action` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Action identifier so the backend knows what to do.', + `user_id` bigint(255) unsigned NOT NULL COMMENT 'ID of the user that would be affected by this action', + `action_code` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'The URL key for using this code.' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_bans` --- -DROP TABLE IF EXISTS `sakura_bans`; -CREATE TABLE `sakura_bans` ( - `ban_id` bigint(255) UNSIGNED NOT NULL COMMENT 'Automatically generated ID by MySQL for management.', - `user_id` bigint(255) UNSIGNED NOT NULL COMMENT 'ID of user that was banned, 0 for just an IP ban.', - `ban_begin` int(11) UNSIGNED NOT NULL COMMENT 'Timestamp when the user was banned.', - `ban_end` int(11) UNSIGNED NOT NULL COMMENT 'Timestamp when the user should regain access to the site.', +-- Dumping structure for table sakura-development.sakura_bans +CREATE TABLE IF NOT EXISTS `sakura_bans` ( + `ban_id` bigint(255) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Automatically generated ID by MySQL for management.', + `user_id` bigint(255) unsigned NOT NULL COMMENT 'ID of user that was banned, 0 for just an IP ban.', + `ban_begin` int(11) unsigned NOT NULL COMMENT 'Timestamp when the user was banned.', + `ban_end` int(11) unsigned NOT NULL COMMENT 'Timestamp when the user should regain access to the site.', `ban_reason` varchar(512) COLLATE utf8_bin DEFAULT NULL COMMENT 'Reason given for the ban.', - `ban_moderator` bigint(255) UNSIGNED NOT NULL COMMENT 'ID of moderator that banned this user,' + `ban_moderator` bigint(255) unsigned NOT NULL COMMENT 'ID of moderator that banned this user,', + PRIMARY KEY (`ban_id`), + KEY `uid` (`user_id`), + KEY `mod_id` (`ban_moderator`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_comments` --- -DROP TABLE IF EXISTS `sakura_comments`; -CREATE TABLE `sakura_comments` ( - `comment_id` bigint(255) UNSIGNED NOT NULL COMMENT 'MySQL Generated ID used for sorting.', +-- Dumping structure for table sakura-development.sakura_bbcodes +CREATE TABLE IF NOT EXISTS `sakura_bbcodes` ( + `bbcode_id` int(64) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Automatically generated ID by MySQL for management.', + `bbcode_regex` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Regular expression string for the BBCode.', + `bbcode_replace` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'What to replace it with.', + `bbcode_title` varchar(128) COLLATE utf8_bin NOT NULL COMMENT 'Button title for this bbcode.', + `bbcode_description` varchar(512) COLLATE utf8_bin NOT NULL COMMENT 'Description of what this does.', + `bbcode_display` tinyint(1) unsigned NOT NULL COMMENT 'Set if this bbcode is displayed on the posting page.', + PRIMARY KEY (`bbcode_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +-- Data exporting was unselected. + + +-- Dumping structure for table sakura-development.sakura_comments +CREATE TABLE IF NOT EXISTS `sakura_comments` ( + `comment_id` bigint(255) unsigned NOT NULL AUTO_INCREMENT COMMENT 'MySQL Generated ID used for sorting.', `comment_category` varchar(32) COLLATE utf8_bin NOT NULL COMMENT 'Comment category.', - `comment_timestamp` int(11) UNSIGNED NOT NULL COMMENT 'Timestamp of when this comment was posted.', - `comment_poster` bigint(255) UNSIGNED NOT NULL COMMENT 'User ID of the poster.', - `comment_reply_to` bigint(255) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'ID of the comment this comment is a reply to', - `comment_text` text COLLATE utf8_bin NOT NULL COMMENT 'Content of the comment.' + `comment_timestamp` int(11) unsigned NOT NULL COMMENT 'Timestamp of when this comment was posted.', + `comment_poster` bigint(255) unsigned NOT NULL COMMENT 'User ID of the poster.', + `comment_reply_to` bigint(255) unsigned NOT NULL DEFAULT '0' COMMENT 'ID of the comment this comment is a reply to', + `comment_text` text COLLATE utf8_bin NOT NULL COMMENT 'Content of the comment.', + PRIMARY KEY (`comment_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_comment_votes` --- -DROP TABLE IF EXISTS `sakura_comment_votes`; -CREATE TABLE `sakura_comment_votes` ( - `vote_comment` bigint(255) UNSIGNED NOT NULL COMMENT 'ID of the comment that was voted on.', - `vote_user` bigint(255) UNSIGNED NOT NULL COMMENT 'ID of the voter.', - `vote_state` tinyint(1) UNSIGNED NOT NULL COMMENT '0 = dislike, 1 = like.' +-- Dumping structure for table sakura-development.sakura_comment_votes +CREATE TABLE IF NOT EXISTS `sakura_comment_votes` ( + `vote_comment` bigint(255) unsigned NOT NULL COMMENT 'ID of the comment that was voted on.', + `vote_user` bigint(255) unsigned NOT NULL COMMENT 'ID of the voter.', + `vote_state` tinyint(1) unsigned NOT NULL COMMENT '0 = dislike, 1 = like.' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_config` --- -DROP TABLE IF EXISTS `sakura_config`; -CREATE TABLE `sakura_config` ( +-- Dumping structure for table sakura-development.sakura_config +CREATE TABLE IF NOT EXISTS `sakura_config` ( `config_name` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Array key for configuration value', - `config_value` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'The value, obviously.' + `config_value` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'The value, obviously.', + UNIQUE KEY `config_name` (`config_name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_emoticons` --- -DROP TABLE IF EXISTS `sakura_emoticons`; -CREATE TABLE `sakura_emoticons` ( +-- Dumping structure for table sakura-development.sakura_emoticons +CREATE TABLE IF NOT EXISTS `sakura_emoticons` ( `emote_string` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'String to catch and replace', `emote_path` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Path to the image file relative to the content domain.' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_error_log` --- -DROP TABLE IF EXISTS `sakura_error_log`; -CREATE TABLE `sakura_error_log` ( +-- Dumping structure for table sakura-development.sakura_error_log +CREATE TABLE IF NOT EXISTS `sakura_error_log` ( `error_id` varchar(32) COLLATE utf8_bin NOT NULL COMMENT 'An ID that is created when an error occurs.', `error_timestamp` varchar(128) COLLATE utf8_bin NOT NULL COMMENT 'A datestring from when the error occurred.', - `error_revision` int(16) UNSIGNED NOT NULL COMMENT 'Sakura Revision number.', - `error_type` int(16) UNSIGNED NOT NULL COMMENT 'The PHP error type of this error.', - `error_line` int(32) UNSIGNED NOT NULL COMMENT 'The line that caused this error.', + `error_revision` int(16) unsigned NOT NULL COMMENT 'Sakura Revision number.', + `error_type` int(16) unsigned NOT NULL COMMENT 'The PHP error type of this error.', + `error_line` int(32) unsigned NOT NULL COMMENT 'The line that caused this error.', `error_string` varchar(512) COLLATE utf8_bin NOT NULL COMMENT 'PHP''s description of this error.', `error_file` varchar(512) COLLATE utf8_bin NOT NULL COMMENT 'The file in which this error occurred.', `error_backtrace` text COLLATE utf8_bin NOT NULL COMMENT 'A full base64 and json encoded backtrace containing all environment data.' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_faq` --- -DROP TABLE IF EXISTS `sakura_faq`; -CREATE TABLE `sakura_faq` ( - `faq_id` bigint(128) UNSIGNED NOT NULL COMMENT 'MySQL Generated ID used for sorting.', +-- Dumping structure for table sakura-development.sakura_faq +CREATE TABLE IF NOT EXISTS `sakura_faq` ( + `faq_id` bigint(128) unsigned NOT NULL AUTO_INCREMENT COMMENT 'MySQL Generated ID used for sorting.', `faq_shorthand` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Used for linking directly to a question.', `faq_question` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'The question.', - `faq_answer` text COLLATE utf8_bin NOT NULL COMMENT 'The answer.' + `faq_answer` text COLLATE utf8_bin NOT NULL COMMENT 'The answer.', + PRIMARY KEY (`faq_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_forums` --- -DROP TABLE IF EXISTS `sakura_forums`; -CREATE TABLE `sakura_forums` ( - `forum_id` bigint(255) UNSIGNED NOT NULL COMMENT 'MySQL Generated ID used for sorting.', +-- Dumping structure for table sakura-development.sakura_forums +CREATE TABLE IF NOT EXISTS `sakura_forums` ( + `forum_id` bigint(255) unsigned NOT NULL AUTO_INCREMENT COMMENT 'MySQL Generated ID used for sorting.', + `forum_order` bigint(255) unsigned NOT NULL COMMENT 'Forum sorting order.', `forum_name` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Display name of the forum.', `forum_desc` text COLLATE utf8_bin NOT NULL COMMENT 'Description of the forum.', `forum_link` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'If set forum will display as a link.', - `forum_category` bigint(255) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'ID of the category this forum falls under.', - `forum_type` tinyint(4) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Forum type, 0 for regular board, 1 for category and 2 for link.', - `forum_icon` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Display icon for the forum.' + `forum_category` bigint(255) unsigned NOT NULL DEFAULT '0' COMMENT 'ID of the category this forum falls under.', + `forum_type` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT 'Forum type, 0 for regular board, 1 for category and 2 for link.', + `forum_icon` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Display icon for the forum.', + PRIMARY KEY (`forum_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_forums_permissions` --- -DROP TABLE IF EXISTS `sakura_forums_permissions`; -CREATE TABLE `sakura_forums_permissions` ( - `forum_id` bigint(255) UNSIGNED NOT NULL COMMENT 'Forum ID', - `rank_id` bigint(128) UNSIGNED NOT NULL COMMENT 'Rank ID, leave 0 for a user', - `user_id` bigint(255) UNSIGNED NOT NULL COMMENT 'User ID, leave 0 for a rank', +-- Dumping structure for table sakura-development.sakura_forum_permissions +CREATE TABLE IF NOT EXISTS `sakura_forum_permissions` ( + `forum_id` bigint(255) unsigned NOT NULL COMMENT 'Forum ID', + `rank_id` bigint(128) unsigned NOT NULL COMMENT 'Rank ID, leave 0 for a user', + `user_id` bigint(255) unsigned NOT NULL COMMENT 'User ID, leave 0 for a rank', `forum_perms` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Forum action permission string' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_friends` --- -DROP TABLE IF EXISTS `sakura_friends`; -CREATE TABLE `sakura_friends` ( - `user_id` bigint(255) UNSIGNED NOT NULL COMMENT 'ID of the user that added the friend.', - `friend_id` bigint(255) UNSIGNED NOT NULL COMMENT 'ID of the user that was added as a friend.', - `friend_timestamp` int(11) UNSIGNED NOT NULL COMMENT 'Timestamp of action.' +-- Dumping structure for table sakura-development.sakura_friends +CREATE TABLE IF NOT EXISTS `sakura_friends` ( + `user_id` bigint(255) unsigned NOT NULL COMMENT 'ID of the user that added the friend.', + `friend_id` bigint(255) unsigned NOT NULL COMMENT 'ID of the user that was added as a friend.', + `friend_timestamp` int(11) unsigned NOT NULL COMMENT 'Timestamp of action.', + KEY `uid` (`user_id`), + KEY `fid` (`friend_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_infopages` --- -DROP TABLE IF EXISTS `sakura_infopages`; -CREATE TABLE `sakura_infopages` ( +-- Dumping structure for table sakura-development.sakura_infopages +CREATE TABLE IF NOT EXISTS `sakura_infopages` ( `page_shorthand` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Name used for calling this page up in the /r/URL', `page_title` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Title displayed on the top of the page', `page_content` text COLLATE utf8_bin NOT NULL COMMENT 'Content of the page' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_login_attempts` --- -DROP TABLE IF EXISTS `sakura_login_attempts`; -CREATE TABLE `sakura_login_attempts` ( - `attempt_id` bigint(255) UNSIGNED NOT NULL COMMENT 'MySQL Generated ID used for sorting.', - `attempt_success` tinyint(1) UNSIGNED NOT NULL COMMENT 'Success boolean.', - `attempt_timestamp` int(11) UNSIGNED NOT NULL COMMENT 'Unix timestamp of the event.', +-- Dumping structure for table sakura-development.sakura_login_attempts +CREATE TABLE IF NOT EXISTS `sakura_login_attempts` ( + `attempt_id` bigint(255) unsigned NOT NULL AUTO_INCREMENT COMMENT 'MySQL Generated ID used for sorting.', + `attempt_success` tinyint(1) unsigned NOT NULL COMMENT 'Success boolean.', + `attempt_timestamp` int(11) unsigned NOT NULL COMMENT 'Unix timestamp of the event.', `attempt_ip` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'IP that made this attempt.', - `user_id` bigint(255) UNSIGNED NOT NULL COMMENT 'ID of the user that was attempted to log in to.' + `user_id` bigint(255) unsigned NOT NULL COMMENT 'ID of the user that was attempted to log in to.', + PRIMARY KEY (`attempt_id`) ) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_messages` --- -DROP TABLE IF EXISTS `sakura_messages`; -CREATE TABLE `sakura_messages` ( - `id` bigint(128) UNSIGNED NOT NULL COMMENT 'Automatically generated ID by MySQL for management.', - `from_user` bigint(255) UNSIGNED NOT NULL COMMENT 'ID of the user that sent this message.', - `to_user` bigint(255) UNSIGNED NOT NULL COMMENT 'ID of user that should receive this message.', +-- Dumping structure for table sakura-development.sakura_messages +CREATE TABLE IF NOT EXISTS `sakura_messages` ( + `id` bigint(128) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Automatically generated ID by MySQL for management.', + `from_user` bigint(255) unsigned NOT NULL COMMENT 'ID of the user that sent this message.', + `to_user` bigint(255) unsigned NOT NULL COMMENT 'ID of user that should receive this message.', `read` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'IDs of users who read this message.', `deleted` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Indicator if one of the parties deleted the message, if it is already 1 the script will remove this row.', - `timestamp` int(11) UNSIGNED NOT NULL COMMENT 'Timestamp of the time this message was sent', + `timestamp` int(11) unsigned NOT NULL COMMENT 'Timestamp of the time this message was sent', `subject` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Title of the message', - `content` text COLLATE utf8_bin NOT NULL COMMENT 'Contents of the message.' + `content` text COLLATE utf8_bin NOT NULL COMMENT 'Contents of the message.', + PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_news` --- -DROP TABLE IF EXISTS `sakura_news`; -CREATE TABLE `sakura_news` ( - `news_id` bigint(255) UNSIGNED NOT NULL COMMENT 'Automatically generated ID by MySQL for management.', +-- Dumping structure for table sakura-development.sakura_news +CREATE TABLE IF NOT EXISTS `sakura_news` ( + `news_id` bigint(255) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Automatically generated ID by MySQL for management.', `news_category` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Category ID.', - `user_id` bigint(255) UNSIGNED NOT NULL COMMENT 'ID of user who posted this news message.', - `news_timestamp` int(11) UNSIGNED NOT NULL COMMENT 'News post timestamp.', + `user_id` bigint(255) unsigned NOT NULL COMMENT 'ID of user who posted this news message.', + `news_timestamp` int(11) unsigned NOT NULL COMMENT 'News post timestamp.', `news_title` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Title of the post.', - `news_content` text COLLATE utf8_bin NOT NULL COMMENT 'Contents of the post' + `news_content` text COLLATE utf8_bin NOT NULL COMMENT 'Contents of the post', + PRIMARY KEY (`news_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_notifications` --- -DROP TABLE IF EXISTS `sakura_notifications`; -CREATE TABLE `sakura_notifications` ( - `alert_id` bigint(255) UNSIGNED NOT NULL COMMENT 'Automatically generated ID by MySQL for management.', - `user_id` bigint(255) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'User ID this notification is intended for.', - `alert_timestamp` int(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Timestamp when this notification was created.', - `alert_read` tinyint(1) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Toggle for unread and read.', - `alert_sound` tinyint(1) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Toggle if a sound should be played upon receiving the notification.', +-- Dumping structure for table sakura-development.sakura_notifications +CREATE TABLE IF NOT EXISTS `sakura_notifications` ( + `alert_id` bigint(255) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Automatically generated ID by MySQL for management.', + `user_id` bigint(255) unsigned NOT NULL DEFAULT '0' COMMENT 'User ID this notification is intended for.', + `alert_timestamp` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Timestamp when this notification was created.', + `alert_read` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT 'Toggle for unread and read.', + `alert_sound` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT 'Toggle if a sound should be played upon receiving the notification.', `alert_title` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Title displayed on the notification.', `alert_text` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Text displayed.', `alert_link` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT 'Link (empty for no link).', `alert_img` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Image path, prefix with font: to use a font class instead of an image.', - `alert_timeout` int(16) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'How long the notification should stay on screen in milliseconds, 0 for forever.' + `alert_timeout` int(16) unsigned NOT NULL DEFAULT '0' COMMENT 'How long the notification should stay on screen in milliseconds, 0 for forever.', + PRIMARY KEY (`alert_id`), + KEY `uid` (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_optionfields` --- -DROP TABLE IF EXISTS `sakura_optionfields`; -CREATE TABLE `sakura_optionfields` ( +-- Dumping structure for table sakura-development.sakura_optionfields +CREATE TABLE IF NOT EXISTS `sakura_optionfields` ( `option_id` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Unique identifier for accessing this option.', `option_name` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Description of the field in a proper way.', `option_description` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Longer description of the option.', `option_type` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Type attribute in the input element.', - `option_permission` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'The minimum permission level this option requires.' + `option_permission` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'The minimum permission level this option requires.', + UNIQUE KEY `id` (`option_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_permissions` --- -DROP TABLE IF EXISTS `sakura_permissions`; -CREATE TABLE `sakura_permissions` ( - `rank_id` bigint(255) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'ID of the rank this permissions set is used for.', - `user_id` bigint(255) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'ID of the user this permissions set is used for.', +-- Dumping structure for table sakura-development.sakura_permissions +CREATE TABLE IF NOT EXISTS `sakura_permissions` ( + `rank_id` bigint(255) unsigned NOT NULL DEFAULT '0' COMMENT 'ID of the rank this permissions set is used for.', + `user_id` bigint(255) unsigned NOT NULL DEFAULT '0' COMMENT 'ID of the user this permissions set is used for.', `permissions_site` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '0' COMMENT 'Site permissions.', - `permissions_manage` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '0' COMMENT 'Site management permissions', - `permissions_forums` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '0' COMMENT 'Forum permissions.', - `permissions_inherit` varchar(4) COLLATE utf8_bin NOT NULL DEFAULT '0' COMMENT 'Rank inheritance, only used when user specific.' + `permissions_manage` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '0' COMMENT 'Site management permissions' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_posts` --- -DROP TABLE IF EXISTS `sakura_posts`; -CREATE TABLE `sakura_posts` ( - `post_id` bigint(255) UNSIGNED NOT NULL COMMENT 'MySQL Generated ID used for sorting.', - `topic_id` bigint(255) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'ID of topic this post is a part of.', - `forum_id` bigint(255) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'ID of forum this was posted in.', - `poster_id` bigint(255) UNSIGNED DEFAULT '0' COMMENT 'ID of poster of this post.', +-- Dumping structure for table sakura-development.sakura_posts +CREATE TABLE IF NOT EXISTS `sakura_posts` ( + `post_id` bigint(255) unsigned NOT NULL AUTO_INCREMENT COMMENT 'MySQL Generated ID used for sorting.', + `topic_id` bigint(255) unsigned NOT NULL DEFAULT '0' COMMENT 'ID of topic this post is a part of.', + `forum_id` bigint(255) unsigned NOT NULL DEFAULT '0' COMMENT 'ID of forum this was posted in.', + `poster_id` bigint(255) unsigned DEFAULT '0' COMMENT 'ID of poster of this post.', `poster_ip` varchar(40) COLLATE utf8_bin NOT NULL COMMENT 'IP of poster.', - `post_time` int(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Time this post was made.', - `post_signature` tinyint(1) UNSIGNED NOT NULL DEFAULT '1' COMMENT 'Toggle if signature should be shown.', + `post_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Time this post was made.', `post_subject` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Subject of the post.', `post_text` text COLLATE utf8_bin NOT NULL COMMENT 'Contents of the post.', - `post_edit_time` int(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Time this post was last edited.', + `post_edit_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Time this post was last edited.', `post_edit_reason` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT 'Reason this was edited.', - `post_edit_user` int(255) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'ID of user that edited.' + `post_edit_user` int(255) unsigned NOT NULL DEFAULT '0' COMMENT 'ID of user that edited.', + PRIMARY KEY (`post_id`), + KEY `topic_id` (`topic_id`), + KEY `forum_id` (`forum_id`), + KEY `poster_id` (`poster_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_premium` --- -DROP TABLE IF EXISTS `sakura_premium`; -CREATE TABLE `sakura_premium` ( - `user_id` bigint(255) UNSIGNED NOT NULL COMMENT 'ID of the user that purchased Tenshi.', - `premium_start` int(11) UNSIGNED NOT NULL COMMENT 'Timestamp of first purchase.', - `premium_expire` int(11) UNSIGNED NOT NULL COMMENT 'Expiration timestamp.' +-- Dumping structure for table sakura-development.sakura_premium +CREATE TABLE IF NOT EXISTS `sakura_premium` ( + `user_id` bigint(255) unsigned NOT NULL COMMENT 'ID of the user that purchased Tenshi.', + `premium_start` int(11) unsigned NOT NULL COMMENT 'Timestamp of first purchase.', + `premium_expire` int(11) unsigned NOT NULL COMMENT 'Expiration timestamp.', + UNIQUE KEY `uid` (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_premium_log` --- -DROP TABLE IF EXISTS `sakura_premium_log`; -CREATE TABLE `sakura_premium_log` ( - `transaction_id` int(16) UNSIGNED NOT NULL COMMENT 'MySQL Generated ID used for sorting.', - `user_id` bigint(255) UNSIGNED NOT NULL COMMENT 'User ID of purchaser', +-- Dumping structure for table sakura-development.sakura_premium_log +CREATE TABLE IF NOT EXISTS `sakura_premium_log` ( + `transaction_id` int(16) unsigned NOT NULL AUTO_INCREMENT COMMENT 'MySQL Generated ID used for sorting.', + `user_id` bigint(255) unsigned NOT NULL COMMENT 'User ID of purchaser', `transaction_amount` float NOT NULL COMMENT 'Amount that was transferred.', - `transaction_date` int(11) UNSIGNED NOT NULL COMMENT 'Date when the purchase was made.', - `transaction_comment` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'A short description of the action taken.' + `transaction_date` int(11) unsigned NOT NULL COMMENT 'Date when the purchase was made.', + `transaction_comment` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'A short description of the action taken.', + PRIMARY KEY (`transaction_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_profilefields` --- -DROP TABLE IF EXISTS `sakura_profilefields`; -CREATE TABLE `sakura_profilefields` ( - `field_id` int(64) UNSIGNED NOT NULL COMMENT 'ID used for ordering on the userpage.', +-- Dumping structure for table sakura-development.sakura_profilefields +CREATE TABLE IF NOT EXISTS `sakura_profilefields` ( + `field_id` int(64) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID used for ordering on the userpage.', `field_name` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Name of the field.', `field_type` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Type attribute in the input element.', - `field_link` tinyint(1) UNSIGNED NOT NULL COMMENT 'Set if this value should be put in a href.', + `field_link` tinyint(1) unsigned NOT NULL COMMENT 'Set if this value should be put in a href.', `field_linkformat` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'If the form is a link how should it be formatted? {{ VAL }} gets replace with the value.', `field_description` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Description of the field displayed in the control panel.', - `field_additional` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Undocumented JSON array containing special options if needed (probably only going to be used for the YouTube field).' + `field_additional` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Undocumented JSON array containing special options if needed (probably only going to be used for the YouTube field).', + PRIMARY KEY (`field_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_ranks` --- -DROP TABLE IF EXISTS `sakura_ranks`; -CREATE TABLE `sakura_ranks` ( - `rank_id` bigint(128) UNSIGNED NOT NULL COMMENT 'Automatically generated ID by MySQL for management.', - `rank_hierarchy` int(11) UNSIGNED NOT NULL COMMENT 'Rank hierarchy.', +-- Dumping structure for table sakura-development.sakura_ranks +CREATE TABLE IF NOT EXISTS `sakura_ranks` ( + `rank_id` bigint(128) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Automatically generated ID by MySQL for management.', + `rank_hierarchy` int(11) unsigned NOT NULL COMMENT 'Rank hierarchy.', `rank_name` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Display name of the rank.', `rank_multiple` varchar(10) COLLATE utf8_bin DEFAULT NULL COMMENT 'Used when addressing this rank as a multiple', - `rank_hidden` tinyint(1) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Don''t show any public links to this rank.', + `rank_hidden` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT 'Don''t show any public links to this rank.', `rank_colour` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Colour used for the username of a member of this rank.', `rank_description` text COLLATE utf8_bin NOT NULL COMMENT 'A description of what a user of this rank can do/is supposed to do.', - `rank_title` varchar(64) COLLATE utf8_bin NOT NULL COMMENT 'Default user title if user has none set.' + `rank_title` varchar(64) COLLATE utf8_bin NOT NULL COMMENT 'Default user title if user has none set.', + PRIMARY KEY (`rank_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_reports` --- -DROP TABLE IF EXISTS `sakura_reports`; -CREATE TABLE `sakura_reports` ( - `id` bigint(255) UNSIGNED NOT NULL COMMENT 'MySQL Generated ID used for sorting.', - `type` int(32) UNSIGNED NOT NULL COMMENT 'Report type, entirely handled on the script side.', - `issuer` bigint(255) UNSIGNED NOT NULL COMMENT 'ID of the person who issued this report.', - `subject` bigint(255) UNSIGNED NOT NULL COMMENT 'ID pointing out what was reported (a more accurate description isn''t possible due to the type column).', +-- Dumping structure for table sakura-development.sakura_regcodes +CREATE TABLE IF NOT EXISTS `sakura_regcodes` ( + `id` bigint(255) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Automatically generated ID by MySQL for management.', + `code` varchar(32) COLLATE utf8_bin NOT NULL COMMENT 'Randomly generated registration key.', + `created_by` bigint(255) unsigned NOT NULL COMMENT 'ID of user who generated this code.', + `used_by` bigint(255) unsigned NOT NULL COMMENT 'ID of user who used this code.', + `key_used` tinyint(1) unsigned NOT NULL COMMENT 'Boolean for setting this key as used.', + PRIMARY KEY (`id`), + KEY `created_by` (`created_by`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +-- Data exporting was unselected. + + +-- Dumping structure for table sakura-development.sakura_reports +CREATE TABLE IF NOT EXISTS `sakura_reports` ( + `id` bigint(255) unsigned NOT NULL AUTO_INCREMENT COMMENT 'MySQL Generated ID used for sorting.', + `type` int(32) unsigned NOT NULL COMMENT 'Report type, entirely handled on the script side.', + `issuer` bigint(255) unsigned NOT NULL COMMENT 'ID of the person who issued this report.', + `subject` bigint(255) unsigned NOT NULL COMMENT 'ID pointing out what was reported (a more accurate description isn''t possible due to the type column).', `title` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'A quick description of this report.', `description` text COLLATE utf8_bin NOT NULL COMMENT 'And a detailed description.', - `reviewed` bigint(255) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'ID of the moderator that reviewed this report.' + `reviewed` bigint(255) unsigned NOT NULL DEFAULT '0' COMMENT 'ID of the moderator that reviewed this report.', + PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_sessions` --- -DROP TABLE IF EXISTS `sakura_sessions`; -CREATE TABLE `sakura_sessions` ( - `session_id` bigint(255) UNSIGNED NOT NULL COMMENT 'Automatically generated ID by MySQL for management. ', - `user_id` bigint(255) UNSIGNED NOT NULL COMMENT 'ID of the user this session is spawned for. ', +-- Dumping structure for table sakura-development.sakura_sessions +CREATE TABLE IF NOT EXISTS `sakura_sessions` ( + `session_id` bigint(255) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Automatically generated ID by MySQL for management. ', + `user_id` bigint(255) unsigned NOT NULL COMMENT 'ID of the user this session is spawned for. ', `user_ip` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'IP of the user this session is spawned for.', `user_agent` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT 'User agent of the user this session is spawned for.', `session_key` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Session key, allow direct access to the user''s account. ', - `session_start` int(16) UNSIGNED NOT NULL COMMENT 'The timestamp for when the session was started. ', - `session_expire` int(16) UNSIGNED NOT NULL COMMENT 'The timestamp for when this session should end, -1 for permanent. ', - `session_remember` tinyint(1) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'If set to 1 session will be extended each time a page is loaded.' + `session_start` int(16) unsigned NOT NULL COMMENT 'The timestamp for when the session was started. ', + `session_expire` int(16) unsigned NOT NULL COMMENT 'The timestamp for when this session should end, -1 for permanent. ', + `session_remember` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT 'If set to 1 session will be extended each time a page is loaded.', + PRIMARY KEY (`session_id`), + KEY `userid` (`user_id`) ) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_topics` --- -DROP TABLE IF EXISTS `sakura_topics`; -CREATE TABLE `sakura_topics` ( - `topic_id` bigint(255) UNSIGNED NOT NULL COMMENT 'MySQL Generated ID used for sorting.', - `forum_id` bigint(255) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'ID of forum this topic was created in.', - `topic_hidden` tinyint(1) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Boolean to set the topic as hidden.', +-- Dumping structure for table sakura-development.sakura_topics +CREATE TABLE IF NOT EXISTS `sakura_topics` ( + `topic_id` bigint(255) unsigned NOT NULL AUTO_INCREMENT COMMENT 'MySQL Generated ID used for sorting.', + `forum_id` bigint(255) unsigned NOT NULL DEFAULT '0' COMMENT 'ID of forum this topic was created in.', + `topic_hidden` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT 'Boolean to set the topic as hidden.', `topic_title` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Title of the topic.', - `topic_time` int(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Timestamp when the topic was created.', - `topic_time_limit` int(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'After how long a topic should be locked.', - `topic_views` bigint(255) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Amount of times the topic has been viewed.', - `topic_status` tinyint(3) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Status of topic.', - `topic_status_change` int(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Date the topic status was changed (used for deletion cooldown as well).', - `topic_type` tinyint(3) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Type of the topic.', - `topic_last_reply` int(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Timestamp of when the last reply made to this thread.' + `topic_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Timestamp when the topic was created.', + `topic_time_limit` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'After how long a topic should be locked.', + `topic_views` bigint(255) unsigned NOT NULL DEFAULT '0' COMMENT 'Amount of times the topic has been viewed.', + `topic_status` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT 'Status of topic.', + `topic_status_change` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Date the topic status was changed (used for deletion cooldown as well).', + `topic_type` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT 'Type of the topic.', + `topic_last_reply` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Timestamp of when the last reply made to this thread.', + `topic_old_forum` bigint(255) unsigned NOT NULL DEFAULT '0' COMMENT 'Pre-move forum id.', + PRIMARY KEY (`topic_id`), + KEY `forum_id` (`forum_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_topics_track` --- -DROP TABLE IF EXISTS `sakura_topics_track`; -CREATE TABLE `sakura_topics_track` ( - `user_id` bigint(255) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'ID of the user this row applies to.', - `topic_id` bigint(255) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'ID of the thread in question.', - `forum_id` bigint(255) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'ID of the forum in question.', - `mark_time` int(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Timestamp of the event.' +-- Dumping structure for table sakura-development.sakura_topics_track +CREATE TABLE IF NOT EXISTS `sakura_topics_track` ( + `user_id` bigint(255) unsigned NOT NULL DEFAULT '0' COMMENT 'ID of the user this row applies to.', + `topic_id` bigint(255) unsigned NOT NULL DEFAULT '0' COMMENT 'ID of the thread in question.', + `forum_id` bigint(255) unsigned NOT NULL DEFAULT '0' COMMENT 'ID of the forum in question.', + `mark_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Timestamp of the event.' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_username_history` --- -DROP TABLE IF EXISTS `sakura_username_history`; -CREATE TABLE `sakura_username_history` ( - `change_id` int(11) UNSIGNED NOT NULL COMMENT 'Identifier', - `change_time` int(11) UNSIGNED NOT NULL COMMENT 'Timestamp of change', - `user_id` bigint(255) UNSIGNED NOT NULL COMMENT 'User ID', +-- Dumping structure for table sakura-development.sakura_uploads +CREATE TABLE IF NOT EXISTS `sakura_uploads` ( + `file_id` bigint(255) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Automatically generated value for management', + `user_id` bigint(255) unsigned NOT NULL COMMENT 'ID of the user that uploaded the file', + `file_data` longblob NOT NULL COMMENT 'Contents of the file', + `file_name` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Name of the file', + `file_mime` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Static mime type of the file', + `file_time` int(11) unsigned NOT NULL COMMENT 'Timestamp of when the file was uploaded', + `file_expire` int(11) unsigned NOT NULL COMMENT 'When should the file be removed, 0 for never', + PRIMARY KEY (`file_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +-- Data exporting was unselected. + + +-- Dumping structure for table sakura-development.sakura_username_history +CREATE TABLE IF NOT EXISTS `sakura_username_history` ( + `change_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Identifier', + `change_time` int(11) unsigned NOT NULL COMMENT 'Timestamp of change', + `user_id` bigint(255) unsigned NOT NULL COMMENT 'User ID', `username_new` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'New username', `username_new_clean` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Clean new username', `username_old` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Old username', - `username_old_clean` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Clean old username' + `username_old_clean` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Clean old username', + PRIMARY KEY (`change_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_users` --- -DROP TABLE IF EXISTS `sakura_users`; -CREATE TABLE `sakura_users` ( - `user_id` bigint(255) UNSIGNED NOT NULL COMMENT 'Automatically generated ID by MySQL for management. ', +-- Dumping structure for table sakura-development.sakura_users +CREATE TABLE IF NOT EXISTS `sakura_users` ( + `user_id` bigint(255) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Automatically generated ID by MySQL for management. ', `username` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Username set at registration.', `username_clean` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'A more cleaned up version of the username for backend usage.', `password_hash` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Hashing algo used for the password hash.', `password_salt` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Salt used for the password hash.', `password_algo` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Algorithm used for the password hash.', - `password_iter` int(11) UNSIGNED NOT NULL COMMENT 'Password hash iterations.', - `password_chan` int(11) UNSIGNED NOT NULL COMMENT 'Last time the user changed their password.', + `password_iter` int(11) unsigned NOT NULL COMMENT 'Password hash iterations.', + `password_chan` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Last time the user changed their password.', `email` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'E-mail of the user for password restoring etc.', - `rank_main` mediumint(4) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Main rank of the user.', - `user_ranks` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '[0]' COMMENT 'Array containing the ranks the user is part of.', + `rank_main` mediumint(4) unsigned NOT NULL DEFAULT '0' COMMENT 'Main rank of the user.', `user_colour` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT 'Additional name colour, when empty colour defaults to group colour.', - `register_ip` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'IP used for the creation of this account.', - `last_ip` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Last IP that was used to log into this account.', + `register_ip` varbinary(50) NOT NULL COMMENT 'IP used for the creation of this account.', + `last_ip` varbinary(50) NOT NULL COMMENT 'Last IP that was used to log into this account.', `user_title` varchar(64) COLLATE utf8_bin DEFAULT NULL COMMENT 'Custom user title of the user, when empty reverts to their derault group name.', - `user_registered` int(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Timestamp of account creation.', - `user_last_online` int(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Last time anything was done on this account.', - `user_birthday` date NOT NULL COMMENT 'Birthdate of the user.', - `user_country` char(2) COLLATE utf8_bin NOT NULL COMMENT 'Contains ISO 3166 country code of user''s registration location.', - `user_data` text COLLATE utf8_bin COMMENT 'All additional profile data.' + `user_registered` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Timestamp of account creation.', + `user_last_online` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Last time anything was done on this account.', + `user_birthday` date NOT NULL DEFAULT '0000-00-00' COMMENT 'Birthdate of the user.', + `user_country` char(2) COLLATE utf8_bin NOT NULL DEFAULT 'XX' COMMENT 'Contains ISO 3166 country code of user''s registration location.', + `user_avatar` bigint(255) unsigned NOT NULL DEFAULT '0' COMMENT 'ID of the avatar in the uploads table.', + `user_background` bigint(255) unsigned NOT NULL DEFAULT '0' COMMENT 'ID of the background in the uploads table.', + `user_header` bigint(255) unsigned NOT NULL DEFAULT '0' COMMENT 'ID of the profile header in the uploads table.', + `user_page` longtext COLLATE utf8_bin COMMENT 'Contents of the userpage.', + `user_signature` text COLLATE utf8_bin COMMENT 'Signature displayed below forum posts.', + PRIMARY KEY (`user_id`), + UNIQUE KEY `username_clean` (`username_clean`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- -------------------------------------------------------- +-- Data exporting was unselected. --- --- Table structure for table `sakura_warnings` --- -DROP TABLE IF EXISTS `sakura_warnings`; -CREATE TABLE `sakura_warnings` ( - `warning_id` bigint(255) UNSIGNED NOT NULL COMMENT 'Automatically generated ID by MySQL for management.', - `user_id` bigint(255) UNSIGNED NOT NULL COMMENT 'ID of user that was warned.', - `moderator_id` bigint(255) UNSIGNED NOT NULL COMMENT 'ID of the user that issued the warning.', - `warning_issued` int(16) UNSIGNED NOT NULL COMMENT 'Timestamp of the date the warning was issued.', - `warning_expires` int(16) UNSIGNED NOT NULL COMMENT 'Timstamp when the warning should expire, 0 for a permanent warning.', - `warning_action` tinyint(1) UNSIGNED DEFAULT NULL COMMENT 'Action taken.', - `warning_reason` varchar(512) COLLATE utf8_bin DEFAULT NULL COMMENT 'Reason for the warning.' +-- Dumping structure for table sakura-development.sakura_user_optionfields +CREATE TABLE IF NOT EXISTS `sakura_user_optionfields` ( + `user_id` bigint(255) unsigned NOT NULL COMMENT 'User this field applies to', + `field_name` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Identifier of the field', + `field_value` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Value of the field' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- --- Indexes for dumped tables --- +-- Data exporting was unselected. --- --- Indexes for table `sakura_actioncodes` --- -ALTER TABLE `sakura_actioncodes` - ADD PRIMARY KEY (`id`); --- --- Indexes for table `sakura_bans` --- -ALTER TABLE `sakura_bans` - ADD PRIMARY KEY (`ban_id`), - ADD KEY `uid` (`user_id`), - ADD KEY `mod_id` (`ban_moderator`); +-- Dumping structure for table sakura-development.sakura_user_profilefields +CREATE TABLE IF NOT EXISTS `sakura_user_profilefields` ( + `user_id` bigint(255) unsigned NOT NULL COMMENT 'User this field applies to', + `field_name` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Identifier of the field', + `field_value` varchar(255) COLLATE utf8_bin NOT NULL COMMENT 'Value of the field' +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- --- Indexes for table `sakura_bbcodes` --- -ALTER TABLE `sakura_bbcodes` - ADD PRIMARY KEY (`bbcode_id`); +-- Data exporting was unselected. --- --- Indexes for table `sakura_comments` --- -ALTER TABLE `sakura_comments` - ADD PRIMARY KEY (`comment_id`); --- --- Indexes for table `sakura_config` --- -ALTER TABLE `sakura_config` - ADD UNIQUE KEY `config_name` (`config_name`); +-- Dumping structure for table sakura-development.sakura_user_ranks +CREATE TABLE IF NOT EXISTS `sakura_user_ranks` ( + `user_id` bigint(255) unsigned NOT NULL, + `rank_id` bigint(128) unsigned NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- --- Indexes for table `sakura_faq` --- -ALTER TABLE `sakura_faq` - ADD PRIMARY KEY (`faq_id`); +-- Data exporting was unselected. --- --- Indexes for table `sakura_forums` --- -ALTER TABLE `sakura_forums` - ADD PRIMARY KEY (`forum_id`); --- --- Indexes for table `sakura_friends` --- -ALTER TABLE `sakura_friends` - ADD KEY `uid` (`user_id`), - ADD KEY `fid` (`friend_id`); +-- Dumping structure for table sakura-development.sakura_warnings +CREATE TABLE IF NOT EXISTS `sakura_warnings` ( + `warning_id` bigint(255) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Automatically generated ID by MySQL for management.', + `user_id` bigint(255) unsigned NOT NULL COMMENT 'ID of user that was warned.', + `moderator_id` bigint(255) unsigned NOT NULL COMMENT 'ID of the user that issued the warning.', + `warning_issued` int(16) unsigned NOT NULL COMMENT 'Timestamp of the date the warning was issued.', + `warning_expires` int(16) unsigned NOT NULL COMMENT 'Timstamp when the warning should expire, 0 for a permanent warning.', + `warning_action` tinyint(1) unsigned DEFAULT NULL COMMENT 'Action taken.', + `warning_reason` varchar(512) COLLATE utf8_bin DEFAULT NULL COMMENT 'Reason for the warning.', + PRIMARY KEY (`warning_id`), + KEY `uid` (`user_id`), + KEY `iid` (`moderator_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; --- --- Indexes for table `sakura_login_attempts` --- -ALTER TABLE `sakura_login_attempts` - ADD PRIMARY KEY (`attempt_id`); - --- --- Indexes for table `sakura_messages` --- -ALTER TABLE `sakura_messages` - ADD PRIMARY KEY (`id`); - --- --- Indexes for table `sakura_news` --- -ALTER TABLE `sakura_news` - ADD PRIMARY KEY (`news_id`); - --- --- Indexes for table `sakura_notifications` --- -ALTER TABLE `sakura_notifications` - ADD PRIMARY KEY (`alert_id`), - ADD KEY `uid` (`user_id`); - --- --- Indexes for table `sakura_optionfields` --- -ALTER TABLE `sakura_optionfields` - ADD UNIQUE KEY `id` (`option_id`); - --- --- Indexes for table `sakura_posts` --- -ALTER TABLE `sakura_posts` - ADD PRIMARY KEY (`post_id`), - ADD KEY `topic_id` (`topic_id`), - ADD KEY `forum_id` (`forum_id`), - ADD KEY `poster_id` (`poster_id`); - --- --- Indexes for table `sakura_premium` --- -ALTER TABLE `sakura_premium` - ADD UNIQUE KEY `uid` (`user_id`); - --- --- Indexes for table `sakura_premium_log` --- -ALTER TABLE `sakura_premium_log` - ADD PRIMARY KEY (`transaction_id`); - --- --- Indexes for table `sakura_profilefields` --- -ALTER TABLE `sakura_profilefields` - ADD PRIMARY KEY (`field_id`); - --- --- Indexes for table `sakura_ranks` --- -ALTER TABLE `sakura_ranks` - ADD PRIMARY KEY (`rank_id`); - --- --- Indexes for table `sakura_reports` --- -ALTER TABLE `sakura_reports` - ADD PRIMARY KEY (`id`); - --- --- Indexes for table `sakura_sessions` --- -ALTER TABLE `sakura_sessions` - ADD PRIMARY KEY (`session_id`), - ADD KEY `userid` (`user_id`); - --- --- Indexes for table `sakura_topics` --- -ALTER TABLE `sakura_topics` - ADD PRIMARY KEY (`topic_id`), - ADD KEY `forum_id` (`forum_id`); - --- --- Indexes for table `sakura_username_history` --- -ALTER TABLE `sakura_username_history` - ADD PRIMARY KEY (`change_id`); - --- --- Indexes for table `sakura_users` --- -ALTER TABLE `sakura_users` - ADD PRIMARY KEY (`user_id`), - ADD UNIQUE KEY `username_clean` (`username_clean`); - --- --- Indexes for table `sakura_warnings` --- -ALTER TABLE `sakura_warnings` - ADD PRIMARY KEY (`warning_id`), - ADD KEY `uid` (`user_id`), - ADD KEY `iid` (`moderator_id`); - --- --- AUTO_INCREMENT for dumped tables --- - --- --- AUTO_INCREMENT for table `sakura_actioncodes` --- -ALTER TABLE `sakura_actioncodes` - MODIFY `id` bigint(255) NOT NULL AUTO_INCREMENT COMMENT 'Automatically generated ID by MySQL for management.'; --- --- AUTO_INCREMENT for table `sakura_bans` --- -ALTER TABLE `sakura_bans` - MODIFY `ban_id` bigint(255) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Automatically generated ID by MySQL for management.'; --- --- AUTO_INCREMENT for table `sakura_bbcodes` --- -ALTER TABLE `sakura_bbcodes` - MODIFY `bbcode_id` int(64) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Automatically generated ID by MySQL for management.', AUTO_INCREMENT=10; --- --- AUTO_INCREMENT for table `sakura_comments` --- -ALTER TABLE `sakura_comments` - MODIFY `comment_id` bigint(255) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'MySQL Generated ID used for sorting.', AUTO_INCREMENT=90; --- --- AUTO_INCREMENT for table `sakura_faq` --- -ALTER TABLE `sakura_faq` - MODIFY `faq_id` bigint(128) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'MySQL Generated ID used for sorting.', AUTO_INCREMENT=4; --- --- AUTO_INCREMENT for table `sakura_forums` --- -ALTER TABLE `sakura_forums` - MODIFY `forum_id` bigint(255) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'MySQL Generated ID used for sorting.', AUTO_INCREMENT=22; --- --- AUTO_INCREMENT for table `sakura_login_attempts` --- -ALTER TABLE `sakura_login_attempts` - MODIFY `attempt_id` bigint(255) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'MySQL Generated ID used for sorting.', AUTO_INCREMENT=2; --- --- AUTO_INCREMENT for table `sakura_messages` --- -ALTER TABLE `sakura_messages` - MODIFY `id` bigint(128) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Automatically generated ID by MySQL for management.', AUTO_INCREMENT=2; --- --- AUTO_INCREMENT for table `sakura_news` --- -ALTER TABLE `sakura_news` - MODIFY `news_id` bigint(255) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Automatically generated ID by MySQL for management.', AUTO_INCREMENT=8; --- --- AUTO_INCREMENT for table `sakura_notifications` --- -ALTER TABLE `sakura_notifications` - MODIFY `alert_id` bigint(255) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Automatically generated ID by MySQL for management.', AUTO_INCREMENT=92; --- --- AUTO_INCREMENT for table `sakura_posts` --- -ALTER TABLE `sakura_posts` - MODIFY `post_id` bigint(255) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'MySQL Generated ID used for sorting.', AUTO_INCREMENT=304; --- --- AUTO_INCREMENT for table `sakura_premium_log` --- -ALTER TABLE `sakura_premium_log` - MODIFY `transaction_id` int(16) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'MySQL Generated ID used for sorting.', AUTO_INCREMENT=157; --- --- AUTO_INCREMENT for table `sakura_profilefields` --- -ALTER TABLE `sakura_profilefields` - MODIFY `field_id` int(64) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID used for ordering on the userpage.', AUTO_INCREMENT=13; --- --- AUTO_INCREMENT for table `sakura_ranks` --- -ALTER TABLE `sakura_ranks` - MODIFY `rank_id` bigint(128) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Automatically generated ID by MySQL for management.', AUTO_INCREMENT=12; --- --- AUTO_INCREMENT for table `sakura_reports` --- -ALTER TABLE `sakura_reports` - MODIFY `id` bigint(255) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'MySQL Generated ID used for sorting.'; --- --- AUTO_INCREMENT for table `sakura_sessions` --- -ALTER TABLE `sakura_sessions` - MODIFY `session_id` bigint(255) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Automatically generated ID by MySQL for management. ', AUTO_INCREMENT=2; --- --- AUTO_INCREMENT for table `sakura_topics` --- -ALTER TABLE `sakura_topics` - MODIFY `topic_id` bigint(255) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'MySQL Generated ID used for sorting.', AUTO_INCREMENT=120; --- --- AUTO_INCREMENT for table `sakura_username_history` --- -ALTER TABLE `sakura_username_history` - MODIFY `change_id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Identifier', AUTO_INCREMENT=20; --- --- AUTO_INCREMENT for table `sakura_users` --- -ALTER TABLE `sakura_users` - MODIFY `user_id` bigint(255) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Automatically generated ID by MySQL for management. ', AUTO_INCREMENT=32; --- --- AUTO_INCREMENT for table `sakura_warnings` --- -ALTER TABLE `sakura_warnings` - MODIFY `warning_id` bigint(255) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Automatically generated ID by MySQL for management.'; +-- Data exporting was unselected. +/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; +/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */; /*!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 */; diff --git a/libraries/ActionCode.php b/libraries/ActionCode.php index 49c874c..14179e2 100644 --- a/libraries/ActionCode.php +++ b/libraries/ActionCode.php @@ -29,12 +29,10 @@ class ActionCode $code = uniqid(); // Insert it - DB::prepare('INSERT INTO `{prefix}actioncodes` (`code_action`, `user_id`, `action_code`) VALUES (:action, :id, :code)') - ->execute([ - 'action' => $action, - 'id' => $user, - 'code' => $code, - ]); + DB::table('actioncodes') + ->insert( + ['action' => $action, 'id' => $user, 'code' => $code] + ); // Return the code return $code; @@ -53,16 +51,14 @@ class ActionCode public static function validate($action, $code, $user = 0, $invalidate = true) { // Fetch the code from the db - $get = DB::prepare('SELECT * FROM `{prefix}actioncodes` WHERE `code_action` = :code AND `action_code` = :action AND `user_id` = :id'); - $get->execute([ - 'code' => $action, - 'action' => $code, - 'id' => $user, - ]); - $get = $get->rowCount(); + $get = DB::table('actioncodes') + ->where('code_action', $action) + ->where('action_code', $code) + ->where('user_id', $user) + ->count(); // Invalidate the code if requested - if ($invalidate) { + if ($get && $invalidate) { self::invalidate($code); } @@ -77,9 +73,8 @@ class ActionCode */ public static function invalidate($code) { - DB::prepare('DELETE FROM `{prefix}actioncodes` WHERE `code_action` = :code') - ->execute([ - 'code' => $code, - ]); + DB::table('actioncodes') + ->where('code_action', $code) + ->delete(); } } diff --git a/libraries/BBcode.php b/libraries/BBcode.php index a4d3a6c..1f7730d 100644 --- a/libraries/BBcode.php +++ b/libraries/BBcode.php @@ -48,9 +48,8 @@ class BBcode public static function parseEmoticons($text) { // Get emoticons from the database - $emotes = DB::prepare('SELECT * FROM `{prefix}emoticons`'); - $emotes->execute(); - $emotes = $emotes->fetchAll(); + $emotes = DB::table('emoticons') + ->get(); // Parse all emoticons foreach ($emotes as $emote) { diff --git a/libraries/Bans.php b/libraries/Bans.php index 1dca80c..4fc6ce5 100644 --- a/libraries/Bans.php +++ b/libraries/Bans.php @@ -26,11 +26,9 @@ class Bans { // Attempt to get a ban from this user - $bans = DB::prepare('SELECT * FROM `{prefix}bans` WHERE `user_id` = :id'); - $bans->execute([ - 'id' => $uid, - ]); - $bans = $bans->fetchAll(); + $bans = DB::table('bans') + ->where('user_id', $uid) + ->get(); // Reverse the array so new bans are listed first $bans = array_reverse($bans); @@ -40,10 +38,9 @@ class Bans // Check if it hasn't expired if ($ban->ban_end != 0 && $ban->ban_end < time()) { // If it has delete the entry and continue - DB::prepare('DELETE FROM `{prefix}bans` WHERE `ban_id` = :id') - ->execute([ - 'id' => $ban->user_id, - ]); + DB::table('bans') + ->where('ban_id', $ban->ban_id) + ->delete(); continue; } diff --git a/libraries/Comments.php b/libraries/Comments.php index 458d37a..68ca818 100644 --- a/libraries/Comments.php +++ b/libraries/Comments.php @@ -47,7 +47,7 @@ class Comments $this->category = $category; // Get the comments and assign them to $comments - $comments = DB::prepare('SELECT * FROM `{prefix}comments` WHERE `comment_category` = :category AND `comment_reply_to` = 0 ORDER BY `comment_id` DESC'); + $comments = DBv2::prepare('SELECT * FROM `{prefix}comments` WHERE `comment_category` = :category AND `comment_reply_to` = 0 ORDER BY `comment_id` DESC'); $comments->execute([ 'category' => $this->category, ]); @@ -96,7 +96,7 @@ class Comments $this->count += 1; // Attempt to get replies from the database - $replies = DB::prepare('SELECT * FROM `{prefix}comments` WHERE `comment_category` = :category AND `comment_reply_to` = :thread'); + $replies = DBv2::prepare('SELECT * FROM `{prefix}comments` WHERE `comment_category` = :category AND `comment_reply_to` = :thread'); $replies->execute([ 'category' => $this->category, 'thread' => $comment['comment_id'], @@ -123,7 +123,7 @@ class Comments public function getComment($cid) { // Get from database - $comment = DB::prepare('SELECT * FROM `{prefix}comments` WHERE `comment_id` = :id'); + $comment = DBv2::prepare('SELECT * FROM `{prefix}comments` WHERE `comment_id` = :id'); $comment->execute([ 'id' => $cid, ]); @@ -140,7 +140,7 @@ class Comments public function getVotes($cid) { // Get from database - $comment = DB::prepare('SELECT * FROM `{prefix}comment_votes` WHERE `vote_comment` = :id'); + $comment = DBv2::prepare('SELECT * FROM `{prefix}comment_votes` WHERE `vote_comment` = :id'); $comment->execute([ 'id' => $cid, ]); @@ -169,7 +169,7 @@ class Comments } // Insert into database - DB::prepare('INSERT INTO `{prefix}comments` (`comment_category`, `comment_timestamp`, `comment_poster`, `comment_reply_to`, `comment_text`) VALUES (:cat, :time, :user, :thread, :text)') + DBv2::prepare('INSERT INTO `{prefix}comments` (`comment_category`, `comment_timestamp`, `comment_poster`, `comment_reply_to`, `comment_text`) VALUES (:cat, :time, :user, :thread, :text)') ->execute([ 'cat' => $this->category, 'time' => time(), @@ -194,7 +194,7 @@ class Comments public function makeVote($uid, $cid, $mode) { // Attempt to get previous vote - $vote = DB::prepare('SELECT * FROM `{prefix}comment_votes` WHERE `vote_user` = :user AND `vote_comment` = :comment'); + $vote = DBv2::prepare('SELECT * FROM `{prefix}comment_votes` WHERE `vote_user` = :user AND `vote_comment` = :comment'); $vote->execute([ 'user' => $uid, 'comment' => $cid, @@ -206,14 +206,14 @@ class Comments // Check if the vote that's being casted is the same if ($vote['vote_state'] == $mode) { // Delete the vote - DB::prepare('DELETE FROM `{prefix}comment_votes` WHERE `vote_user` = :user AND `vote_comment` = :comment') + DBv2::prepare('DELETE FROM `{prefix}comment_votes` WHERE `vote_user` = :user AND `vote_comment` = :comment') ->execute([ 'user' => $uid, 'comment' => $cid, ]); } else { // Otherwise update the vote - DB::prepare('UPDATE `{prefix}comment_votes` SET `vote_state` = :state WHERE `vote_user` = :user AND `vote_comment` = :comment') + DBv2::prepare('UPDATE `{prefix}comment_votes` SET `vote_state` = :state WHERE `vote_user` = :user AND `vote_comment` = :comment') ->execute([ 'state' => $mode, 'user' => $uid, @@ -222,7 +222,7 @@ class Comments } } else { // Create a vote - DB::prepare('INSERT INTO `{prefix}comment_votes` (`vote_user`, `vote_comment`, `vote_state`) VALUES (:user, :comment, :state)') + DBv2::prepare('INSERT INTO `{prefix}comment_votes` (`vote_user`, `vote_comment`, `vote_state`) VALUES (:user, :comment, :state)') ->execute([ 'user' => $uid, 'comment' => $cid, @@ -241,7 +241,7 @@ class Comments public function removeComment($cid) { // Remove from database - DB::prepare('DELETE FROM `{prefix}comments` WHERE `comment_id` = :id') + DBv2::prepare('DELETE FROM `{prefix}comments` WHERE `comment_id` = :id') ->execute([ 'id' => $cid, ]); diff --git a/libraries/Config.php b/libraries/Config.php index ed8f475..16ae134 100644 --- a/libraries/Config.php +++ b/libraries/Config.php @@ -101,13 +101,14 @@ class Config // Then return the value return self::$database[$key]; } else { - $value = DB::prepare('SELECT * FROM `{prefix}config` WHERE `config_name` = :name'); - $value->execute([ - 'name' => $key, - ]); - $value = $value->fetch(); + // Get the record from the database + $value = DB::table('config') + ->where('config_name', $key) + ->get(); + + // Check if it exists if ($value) { - self::$database[$key] = $value->config_value; + self::$database[$key] = $value[0]->config_value; return self::$database[$key]; } } @@ -127,24 +128,20 @@ class Config } // Check if the value already exists - $exists = DB::prepare('SELECT * FROM `{prefix}config` WHERE `config_name` = :name'); - $exists->execute([ - 'name' => $key, - ]); + $exists = DB::table('config') + ->where('config_name', $key) + ->count(); // If it exists run an update - if ($exists->rowCount()) { - $set = DB::prepare('UPDATE `{prefix}config` SET `config_value` = :value WHERE `config_name` = :name'); + if ($exists) { + DB::table('config') + ->where('config_name', $key) + ->update(['config_value' => $value]); } else { - $set = DB::prepare('INSERT INTO `{prefix}config` (`config_name`, `config_value`) VALUES (:name, :value)'); + DB::table('config') + ->insert(['config_name' => $key, 'config_value' => $value]); } - // Run the setter - $set->execute([ - 'name' => $key, - 'value' => $value, - ]); - // Return the value return $value; } diff --git a/libraries/Controllers/Forums.php b/libraries/Controllers/Forums.php index dbd8266..7850798 100644 --- a/libraries/Controllers/Forums.php +++ b/libraries/Controllers/Forums.php @@ -9,6 +9,7 @@ namespace Sakura\Controllers; use Sakura\Config; use Sakura\DB; +use Sakura\DBv2; use Sakura\Forum; use Sakura\Perms\Forum as ForumPerms; use Sakura\Template; @@ -31,25 +32,18 @@ class Forums extends Controller */ public function index() { - $userCount = DB::prepare("SELECT * FROM `{prefix}users` WHERE `password_algo` != 'disabled' AND `rank_main` != 1"); - $userCount->execute(); - $threadCount = DB::prepare('SELECT * FROM `{prefix}topics`'); - $threadCount->execute(); - $postCount = DB::prepare('SELECT * FROM `{prefix}posts`'); - $postCount->execute(); - // Merge index specific stuff with the global render data Template::vars([ 'forum' => (new Forum\Forum()), 'stats' => [ - 'userCount' => $userCount->rowCount(), + 'userCount' => DB::table('users')->where('password_algo', '!=', 'disabled')->whereNotIn('rank_main', [1, 10])->count(), 'newestUser' => User::construct(Users::getNewestUserId()), - 'lastRegData' => date_diff( + 'lastRegDate' => date_diff( date_create(date('Y-m-d', User::construct(Users::getNewestUserId())->registered)), date_create(date('Y-m-d')) )->format('%a'), - 'topicCount' => $threadCount->rowCount(), - 'postCount' => $postCount->rowCount(), + 'topicCount' => DB::table('topics')->count(), + 'postCount' => DB::table('posts')->count(), 'onlineUsers' => Users::checkAllOnline(), ], ]); diff --git a/libraries/Controllers/Meta.php b/libraries/Controllers/Meta.php index d298b76..4da8bca 100644 --- a/libraries/Controllers/Meta.php +++ b/libraries/Controllers/Meta.php @@ -9,6 +9,7 @@ namespace Sakura\Controllers; use Sakura\Config; use Sakura\DB; +use Sakura\DBv2; use Sakura\News; use Sakura\Template; use Sakura\User; @@ -30,26 +31,19 @@ class Meta extends Controller */ public function index() { - $userCount = DB::prepare("SELECT * FROM `{prefix}users` WHERE `password_algo` != 'disabled' AND `rank_main` != 1"); - $userCount->execute(); - $threadCount = DB::prepare('SELECT * FROM `{prefix}topics`'); - $threadCount->execute(); - $postCount = DB::prepare('SELECT * FROM `{prefix}posts`'); - $postCount->execute(); - // Merge index specific stuff with the global render data Template::vars([ 'news' => new News(Config::get('site_news_category')), 'newsCount' => Config::get('front_page_news_posts'), 'stats' => [ - 'userCount' => $userCount->rowCount(), + 'userCount' => DB::table('users')->where('password_algo', '!=', 'disabled')->whereNotIn('rank_main', [1, 10])->count(), 'newestUser' => User::construct(Users::getNewestUserId()), 'lastRegDate' => date_diff( date_create(date('Y-m-d', User::construct(Users::getNewestUserId())->registered)), date_create(date('Y-m-d')) )->format('%a'), - 'topicCount' => $threadCount->rowCount(), - 'postCount' => $postCount->rowCount(), + 'topicCount' => DB::table('topics')->count(), + 'postCount' => DB::table('posts')->count(), 'onlineUsers' => Users::checkAllOnline(), ], ]); @@ -95,9 +89,9 @@ class Meta extends Controller public function faq() { // Get faq entries - $faq = DB::prepare('SELECT * FROM `{prefix}faq` ORDER BY `faq_id`'); - $faq->execute(); - $faq = $faq->fetchAll(); + $faq = DB::table('faq') + ->orderBy('faq_id') + ->get(); // Set parse variables Template::vars([ @@ -131,11 +125,9 @@ class Meta extends Controller $id = strtolower($id); // Get the page from the database - $ipData = DB::prepare('SELECT * FROM `{prefix}infopages` WHERE `page_shorthand` = :id'); - $ipData->execute([ - 'id' => $id, - ]); - $ipData = $ipData->fetch(); + $ipData = DB::table('infopages') + ->where('page_shorthand', $id) + ->get(); // Get info page data from the database if ($ipData) { @@ -143,8 +135,8 @@ class Meta extends Controller Template::vars([ 'page' => [ 'id' => $id, - 'title' => $ipData->page_title, - 'content' => $ipData->page_content, + 'title' => $ipData[0]->page_title, + 'content' => $ipData[0]->page_content, ], ]); } diff --git a/libraries/Controllers/User.php b/libraries/Controllers/User.php index 5a6159a..6ab8024 100644 --- a/libraries/Controllers/User.php +++ b/libraries/Controllers/User.php @@ -9,6 +9,7 @@ namespace Sakura\Controllers; use Sakura\Config; use Sakura\DB; +use Sakura\DBv2; use Sakura\Rank; use Sakura\Template; use Sakura\User as UserContext; @@ -39,18 +40,17 @@ class User extends Controller // If the user id is zero check if there was a namechange if ($profile->id == 0) { // Fetch from username_history - $check = DB::prepare('SELECT `user_id` FROM `{prefix}username_history` WHERE `username_old_clean` = :uname ORDER BY `change_id` DESC'); - $check->execute([ - 'uname' => Utils::cleanString($id, true, true), - ]); - $check = $check->fetch(); + $check = DB::table('username_history') + ->where('username_old_clean', Utils::cleanString($id, true, true)) + ->orderBy('change_id', 'desc') + ->get(); // Redirect if so if ($check) { Template::vars([ 'page' => [ 'message' => 'The user this profile belongs to changed their username, you are being redirected.', - 'redirect' => (new \Sakura\Urls)->format('USER_PROFILE', [$check->user_id]), + 'redirect' => (new \Sakura\Urls)->format('USER_PROFILE', [$check[0]->user_id]), ], ]); diff --git a/libraries/DB.php b/libraries/DB.php index 7ebeeee..4c189ce 100644 --- a/libraries/DB.php +++ b/libraries/DB.php @@ -1,112 +1,21 @@ */ -class DB +class DB extends Manager { - /** - * The container for the PDO object. - * - * @var PDO - */ - public static $db = null; - - /** - * The table prefix - * - * @var string - */ - public static $prefix = ''; - - /** - * Open the SQL connection and creates a PDO object. - * - * @param string $server A PDO driver. - * @param array $dsnParts An array consisting out of DSN string parts. - * @param string $username The username used to authenticate with the SQL server. - * @param string $password The password for the same purpose. - * @param array $options Additional PDO options. - */ - public static function open($server, $dsnParts, $username = null, $password = null, $prefix = '', $options = []) - { - // Check if the selected driver is available - if (!in_array($server, PDO::getAvailableDrivers())) { - trigger_error('A driver for the selected SQL server wasn\'t found!', E_USER_ERROR); - return; - } - - // Set the table prefix - self::$prefix = $prefix; - - // Create start of the DSN - $dsn = "{$server}:"; - - // Append the parts - foreach ($dsnParts as $name => $value) { - $dsn .= "{$name}={$value};"; - } - - try { - // Connect to SQL server using PDO - self::$db = new PDO($dsn, $username, $password, $options); - } catch (PDOException $e) { - // Catch connection errors - trigger_error($e->getMessage(), E_USER_ERROR); - } - - self::$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); - self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - self::$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); - } - - /** - * Closes the PDO object. - */ - public static function close() - { - self::$db = null; - } - - /** - * Get the id of the item that was last inserted into the database. - * - * @param string $name Sequence of which the last id should be returned. - * - * @return string The last inserted id. - */ - public static function lastID($name = null) - { - return self::$db->lastInsertID($name); - } - - /** - * Prepares a statement for execution and returns a statement object. - * - * @param string $stmt The statement to prepare. - * @param array $opts Statement specific driver options. - * - * @return PDOStatement - */ - public static function prepare($stmt, $opts = []) - { - // Replace the table prefix - $stmt = str_replace('{prefix}', self::$prefix, $stmt); - - return self::$db->prepare($stmt, $opts); - } + // This class solely exists as an alias (for now at least) } diff --git a/libraries/DBv2.php b/libraries/DBv2.php new file mode 100644 index 0000000..402ad5e --- /dev/null +++ b/libraries/DBv2.php @@ -0,0 +1,112 @@ + + */ +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); + } +} diff --git a/libraries/File.php b/libraries/File.php index e20bf3e..50f28c6 100644 --- a/libraries/File.php +++ b/libraries/File.php @@ -81,18 +81,15 @@ class File $mime = (new finfo(FILEINFO_MIME_TYPE))->buffer($data); // Insert it into the database - DB::prepare('INSERT INTO `{prefix}uploads` (`user_id`, `file_data`, `file_name`, `file_mime`, `file_time`, `file_expire`) VALUES (:id, :data, :name, :mime, :time, :expire)') - ->execute([ - 'id' => $user->id, - 'data' => $data, - 'name' => $name, - 'mime' => $mime, - 'time' => time(), - 'expire' => $expire, - ]); - - // Get the last insert id - $id = (int) DB::lastID(); + $id = DB::table('uploads') + ->insertGetId([ + 'user_id' => $user->id, + 'file_data' => $data, + 'file_name' => $name, + 'file_mime' => $mime, + 'file_time' => time(), + 'file_expire' => $expire, + ]); // Return a new File object return new File($id); @@ -106,14 +103,13 @@ class File public function __construct($fileId) { // Attempt to get the database row - $fr = DB::prepare('SELECT * FROM `{prefix}uploads` WHERE `file_id` = :id'); - $fr->execute([ - 'id' => $fileId, - ]); - $fileRow = $fr->fetch(); + $fileRow = DB::table('uploads') + ->where('file_id', $fileId) + ->get(); // If anything was returned populate the variables if ($fileRow) { + $fileRow = $fileRow[0]; $this->id = $fileRow->file_id; $this->user = User::construct($fileRow->user_id); $this->data = $fileRow->file_data; @@ -129,9 +125,8 @@ class File */ public function delete() { - DB::prepare('DELETE FROM `{prefix}uploads` WHERE `file_id` = :id') - ->execute([ - 'id' => $this->id, - ]); + DB::table('uploads') + ->where('file_id', $this->id) + ->delete(); } } diff --git a/libraries/Forum/Forum.php b/libraries/Forum/Forum.php index 0703426..e9fd634 100644 --- a/libraries/Forum/Forum.php +++ b/libraries/Forum/Forum.php @@ -8,6 +8,7 @@ namespace Sakura\Forum; use Sakura\DB; +use Sakura\DBv2; use Sakura\Users; use Sakura\User; use Sakura\Perms; @@ -118,17 +119,16 @@ class Forum public function __construct($forumId = 0) { // Get the row from the database - $forumRow = DB::prepare('SELECT * FROM `{prefix}forums` WHERE `forum_id` = :id'); - $forumRow->execute([ - 'id' => $forumId, - ]); - $forumRow = $forumRow->fetch(); + $forumRow = DB::table('forums') + ->where('forum_id', $forumId) + ->get(); // Create permissions object $this->_permissions = new Perms(Perms::FORUM); // Populate the variables if ($forumRow) { + $forumRow = $forumRow[0]; $this->id = $forumRow->forum_id; $this->order = $forumRow->forum_order; $this->name = $forumRow->forum_name; @@ -177,11 +177,10 @@ class Forum // Check if _forums is populated if (!count($this->_forums)) { // Get all rows with the category id set to the forum id - $forumRows = DB::prepare('SELECT `forum_id` FROM `{prefix}forums` WHERE `forum_category` = :cat ORDER BY forum_order'); - $forumRows->execute([ - 'cat' => $this->id, - ]); - $forumRows = $forumRows->fetchAll(); + $forumRows = DB::table('forums') + ->where('forum_category', $this->id) + ->orderBy('forum_order') + ->get(['forum_id']); // Create a storage array $forums = []; @@ -210,11 +209,11 @@ class Forum // Check if _threads is populated if (!count($this->_threads)) { // Get all rows with the forum id for this forum - $threadRows = DB::prepare('SELECT * FROM `{prefix}topics` WHERE `forum_id` = :forum ORDER BY `topic_type` DESC, `topic_last_reply` DESC'); - $threadRows->execute([ - 'forum' => $this->id, - ]); - $threadRows = $threadRows->fetchAll(); + $threadRows = DB::table('topics') + ->where('forum_id', $this->id) + ->orderBy('topic_type', 'desc') + ->orderBy('topic_last_reply', 'desc') + ->get(['topic_id']); // Create a storage array $threads = []; @@ -243,14 +242,14 @@ class Forum // Check if _firstPost is set if ($this->_firstPost === null) { // Get the row - $firstPost = DB::prepare('SELECT `post_id` FROM `{prefix}posts` WHERE `forum_id` = :id ORDER BY `post_id` LIMIT 1'); - $firstPost->execute([ - 'id' => $this->id, - ]); - $firstPost = $firstPost->fetch(); + $firstPost = DB::table('posts') + ->where('forum_id', $this->id) + ->orderBy('post_id') + ->limit(1) + ->get(['post_id']); // Create the post object - $post = new Post(empty($firstPost) ? 0 : $firstPost->post_id); + $post = new Post(empty($firstPost) ? 0 : $firstPost[0]->post_id); // Assign it to a "cache" variable $this->_firstPost = $post; @@ -272,14 +271,14 @@ class Forum // Check if _lastPost is set if ($this->_lastPost === null) { // Get the row - $lastPost = DB::prepare('SELECT `post_id` FROM `{prefix}posts` WHERE `forum_id` = :id ORDER BY `post_id` DESC LIMIT 1'); - $lastPost->execute([ - 'id' => $this->id, - ]); - $lastPost = $lastPost->fetch(); + $lastPost = DB::table('posts') + ->where('forum_id', $this->id) + ->orderBy('post_id', 'desc') + ->limit(1) + ->get(['post_id']); // Create the post object - $post = new Post(empty($lastPost) ? 0 : $lastPost->post_id); + $post = new Post(empty($lastPost) ? 0 : $lastPost[0]->post_id); // Assign it to a "cache" variable $this->_lastPost = $post; @@ -298,11 +297,9 @@ class Forum */ public function threadCount() { - $count = DB::prepare('SELECT * FROM `{prefix}topics` WHERE `forum_id` = :id'); - $count->execute([ - 'id' => $this->id, - ]); - return $count->rowCount(); + return DB::table('topics') + ->where('forum_id', $this->id) + ->count(); } /** @@ -312,11 +309,9 @@ class Forum */ public function postCount() { - $count = DB::prepare('SELECT * FROM `{prefix}posts` WHERE `forum_id` = :id'); - $count->execute([ - 'id' => $this->id, - ]); - return $count->rowCount(); + return DB::table('posts') + ->where('forum_id', $this->id) + ->count(); } /** diff --git a/libraries/Forum/Post.php b/libraries/Forum/Post.php index cbefc59..1247721 100644 --- a/libraries/Forum/Post.php +++ b/libraries/Forum/Post.php @@ -9,6 +9,7 @@ namespace Sakura\Forum; use Sakura\Utils; use Sakura\DB; +use Sakura\DBv2; use Sakura\User; use Sakura\BBcode; use Sakura\Config; @@ -114,14 +115,13 @@ class Post public function __construct($postId) { // Attempt to get the database row - $postRow = DB::prepare('SELECT * FROM `{prefix}posts` WHERE `post_id` = :id'); - $postRow->execute([ - 'id' => $postId, - ]); - $postRow = $postRow->fetch(); + $postRow = DB::table('posts') + ->where('post_id', $postId) + ->get(); // Assign data if a row was returned if ($postRow) { + $postRow = $postRow[0]; $this->id = $postRow->post_id; $this->thread = $postRow->topic_id; $this->forum = $postRow->forum_id; @@ -173,19 +173,16 @@ class Post } // Insert the post - DB::prepare('INSERT INTO `{prefix}posts` (`topic_id`, `forum_id`, `poster_id`, `poster_ip`, `post_time`, `post_subject`, `post_text`) VALUES (:thread, :forum, :user, :ip, :time, :subject, :text)') - ->execute([ - 'thread' => $thread->id, - 'forum' => $thread->forum, - 'user' => $poster->id, - 'ip' => Net::IP(), - 'time' => time(), - 'subject' => $subject, - 'text' => $text, - ]); - - // Get post id - $id = (int) DB::lastID(); + $id = DB::table('posts') + ->insertGetId([ + 'topic_id' => $thread->id, + 'forum_id' => $thread->forum, + 'poster_id' => $poster->id, + 'poster_ip' => Net::IP(), + 'post_time' => time(), + 'post_subject' => $subject, + 'post_text' => $text, + ]); // Update the last post date $thread->lastUpdate(); @@ -213,20 +210,20 @@ class Post $thread = new Thread($this->thread); // Update the post - DB::prepare('UPDATE `{prefix}posts` SET `topic_id` = :thread, `forum_id` = :forum, `poster_id` = :user, `poster_ip` = :ip, `post_time` = :time, `post_subject` = :subject, `post_text` = :text, `post_edit_time` = :edit_time, `post_edit_reason` = :edit_reason, `post_edit_user` = :edit_user WHERE `post_id` = :post') - ->execute([ - 'post' => $this->id, - 'thread' => $thread->id, - 'forum' => $thread->forum, - 'user' => $this->poster->id, - 'ip' => Net::pton(Net::IP()), - 'time' => $this->time, - 'subject' => $this->subject, - 'text' => $this->text, - 'edit_time' => $this->editTime, - 'edit_reason' => $this->editReason, - 'edit_user' => $this->editUser->id, - ]); + DB::table('posts') + ->where('post_id', $this->id) + ->update([ + 'topic_id' => $thread->id, + 'forum_id' => $thread->forum, + 'poster_id' => $this->poster->id, + 'poster_ip' => Net::pton(Net::IP()), + 'post_time' => $this->time, + 'post_subject' => $this->subject, + 'post_text' => $this->text, + 'post_edit_time' => $this->editTime, + 'post_edit_reason' => $this->editReason, + 'post_edit_user' => $this->editUser->id, + ]); // Return a new post object return new Post($this->id); diff --git a/libraries/Forum/Thread.php b/libraries/Forum/Thread.php index 9effe50..ecaa1a3 100644 --- a/libraries/Forum/Thread.php +++ b/libraries/Forum/Thread.php @@ -8,6 +8,7 @@ namespace Sakura\Forum; use Sakura\DB; +use Sakura\DBv2; use Sakura\Utils; /** @@ -129,14 +130,13 @@ class Thread public function __construct($threadId) { // Attempt to get the database row - $threadRow = DB::prepare('SELECT * FROM `{prefix}topics` WHERE `topic_id` = :id'); - $threadRow->execute([ - 'id' => $threadId, - ]); - $threadRow = $threadRow->fetch(); + $threadRow = DB::table('topics') + ->where('topic_id', $threadId) + ->get(); // Assign data if a row was returned if ($threadRow) { + $threadRow = $threadRow[0]; $this->id = $threadRow->topic_id; $this->forum = $threadRow->forum_id; $this->hidden = (bool) $threadRow->topic_hidden; @@ -164,17 +164,17 @@ class Thread public static function create($forum, $title, $status = 0, $type = 0) { // Create the database entry - DB::prepare('INSERT INTO `{prefix}topics` (`forum_id`, `topic_title`, `topic_time`, `topic_status`, `topic_type`) VALUES (:forum, :title, :time, :status, :type)') - ->execute([ - 'forum' => $forum, - 'title' => $title, - 'time' => time(), - 'status' => $status, - 'type' => $type, - ]); + $id = DB::table('topics') + ->insertGetId([ + 'forum_id' => $forum, + 'topic_title' => $title, + 'topic_time' => time(), + 'topic_status' => $status, + 'topic_type' => $type, + ]); // Return the thread object - return new Thread(DB::lastID()); + return new Thread($id); } /** @@ -183,16 +183,14 @@ class Thread public function delete() { // Delete all posts - DB::prepare('DELETE FROM `{prefix}posts` WHERE `topic_id` = :id') - ->execute([ - 'id' => $this->id, - ]); + DB::table('posts') + ->where('topic_id', $this->id) + ->delete(); // Delete thread meta - DB::prepare('DELETE FROM `{prefix}topics` WHERE `topic_id` = :id') - ->execute([ - 'id' => $this->id, - ]); + DB::table('topics') + ->where('topic_id', $this->id) + ->delete(); } /** @@ -204,19 +202,17 @@ class Thread public function move($forum, $setOld = true) { // Update all posts - DB::prepare('UPDATE `{prefix}posts` SET `forum_id` = :forum WHERE `topic_id` = :thread') - ->execute([ - 'forum' => $forum, - 'thread' => $this->id, - ]); + DB::table('posts') + ->where('topic_id', $this->id) + ->update(['forum_id' => $forum]); // Update thread meta - DB::prepare('UPDATE `{prefix}topics` SET `forum_id` = :forum, `topic_old_forum` = :old WHERE `topic_id` = :thread') - ->execute([ - 'forum' => $forum, - 'old' => ($setOld ? $this->forum : 0), - 'thread' => $this->id, - ]); + DB::table('topics') + ->where('topic_id', $this->id) + ->update([ + 'forum_id' => $forum, + 'topic_old_forum' => ($setOld ? $this->forum : 0), + ]); } /** @@ -227,17 +223,17 @@ class Thread public function update() { // Update row - DB::prepare('UPDATE `{prefix}topics` SET `topic_hidden` = :hidden, `topic_title` = :title, `topic_time_limit` = :limit, `topic_status` = :status, `topic_status_change` = :change, `topic_type` = :type, `topic_old_forum` = :old WHERE `topic_id` = :id') - ->execute([ - 'hidden' => $this->hidden, - 'title' => $this->title, - 'limit' => $this->timeLimit, - 'status' => $this->status, - 'change' => $this->statusChange, - 'type' => $this->type, - 'old' => $this->oldForum, - 'id' => $this->id, - ]); + DB::table('topics') + ->where('topic_id', $this->id) + ->update([ + 'topic_hidden' => $this->hidden, + 'topic_title' => $this->title, + 'topic_limit' => $this->timeLimit, + 'topic_status' => $this->status, + 'topic_status_change' => $this->statusChange, + 'topic_type' => $this->type, + 'topic_old_forum' => $this->oldForum, + ]); // Return new object return new Thread($this->id); @@ -253,11 +249,9 @@ class Thread // Check if _posts is something if (!count($this->_posts)) { // Get all rows with the thread id - $postRows = DB::prepare('SELECT `post_id` FROM `{prefix}posts` WHERE `topic_id` = :thread'); - $postRows->execute([ - 'thread' => $this->id, - ]); - $postRows = $postRows->fetchAll(); + $postRows = DB::table('posts') + ->where('topic_id', $this->id) + ->get(['post_id']); // Create a storage array $posts = []; @@ -289,14 +283,14 @@ class Thread } // Get the row from the database - $post = DB::prepare('SELECT `post_id` FROM `{prefix}posts` WHERE `topic_id` = :thread ORDER BY `post_id` LIMIT 1'); - $post->execute([ - 'thread' => $this->id, - ]); - $post = $post->fetch(); + $post = DB::table('posts') + ->where('topic_id', $this->id) + ->orderBy('post_id') + ->limit(1) + ->get(['post_id']); // Create the post class - $post = new Post($post ? $post->post_id : 0); + $post = new Post($post ? $post[0]->post_id : 0); // Assign it to the cache var $this->_firstPost = $post; @@ -318,14 +312,14 @@ class Thread } // Get the row from the database - $post = DB::prepare('SELECT `post_id` FROM `{prefix}posts` WHERE `topic_id` = :thread ORDER BY `post_id` DESC LIMIT 1'); - $post->execute([ - 'thread' => $this->id, - ]); - $post = $post->fetch(); + $post = DB::table('posts') + ->where('topic_id', $this->id) + ->orderBy('post_id', 'desc') + ->limit(1) + ->get(['post_id']); // Create the post class - $post = new Post($post ? $post->post_id : 0); + $post = new Post($post ? $post[0]->post_id : 0); // Assign it to the cache var $this->_lastPost = $post; @@ -341,11 +335,9 @@ class Thread */ public function replyCount() { - $count = DB::prepare('SELECT * FROM `{prefix}posts` WHERE `topic_id` = :thread'); - $count->execute([ - 'thread' => $this->id, - ]); - return $count->rowCount(); + return DB::table('posts') + ->where('topic_id', $this->id) + ->count(); } /** @@ -358,15 +350,14 @@ class Thread public function unread($user) { // Attempt to get track row from the database - $track = DB::prepare('SELECT * FROM `{prefix}topics_track` WHERE `user_id` = :user AND `topic_id` = :thread AND `mark_time` > :last'); - $track->execute([ - 'user' => $user, - 'thread' => $this->id, - 'last' => $this->lastPost()->time, - ]); + $track = DB::table('topics_track') + ->where('user_id', $user) + ->where('topic_id', $this->id) + ->where('mark_time', '>', $this->lastPost()->time) + ->count(); // If nothing was returned it's obvious that the status is unread - if (!$track->rowCount()) { + if (!$track) { return true; } @@ -382,30 +373,27 @@ class Thread public function trackUpdate($user) { // Check if we already have a track record - $track = DB::prepare('SELECT * FROM `{prefix}topics_track` WHERE `user_id` = :user AND `topic_id` = :thread AND `forum_id` = :forum'); - $track->execute([ - 'user' => $user, - 'thread' => $this->id, - 'forum' => $this->forum, - ]); + $track = DB::table('topics_track') + ->where('user_id', $user) + ->where('topic_id', $this->id) + ->where('forum_id', $this->forum) + ->count(); // If so update it - if ($track->rowCount()) { - DB::prepare('UPDATE `{prefix}topics_track` SET `mark_time` = :time WHERE `user_id` = :user AND `topic_id` = :thread') - ->execute([ - 'user' => $user, - 'thread' => $this->id, - 'time' => time(), - ]); + if ($track) { + DB::table('topics_track') + ->where('user_id', $user) + ->where('topic_id', $this->id) + ->update(['mark_time' => time()]); } else { // If not create a new record - DB::prepare('INSERT INTO `{prefix}topics_track` (`user_id`, `topic_id`, `forum_id`, `mark_time`) VALUES (:user, :thread, :forum, :time)') - ->execute([ - 'user' => $user, - 'thread' => $this->id, - 'forum' => $this->forum, - 'time' => time(), - ]); + DB::table('topics_track') + ->insert([ + 'user_id' => $user, + 'topic_id' => $this->id, + 'forum_id' => $this->forum, + 'mark_time' => time(), + ]); } } @@ -414,11 +402,9 @@ class Thread */ public function viewsUpdate() { - DB::prepare('UPDATE `{prefix}topics` SET `topic_views` = :views WHERE `topic_id` = :thread') - ->execute([ - 'views' => $this->views + 1, - 'thread' => $this->id, - ]); + DB::table('topics') + ->where('topic_id', $this->id) + ->increment('topic_views'); } /** @@ -426,10 +412,8 @@ class Thread */ public function lastUpdate() { - DB::prepare('UPDATE `{prefix}topics` SET `topic_last_reply` = :last WHERE `topic_id` = :thread') - ->execute([ - 'last' => time(), - 'thread' => $this->id, - ]); + DB::table('topics') + ->where('topic_id', $this->id) + ->update(['topic_last_reply' => time()]); } } diff --git a/libraries/News.php b/libraries/News.php index 1d1654b..9231c68 100644 --- a/libraries/News.php +++ b/libraries/News.php @@ -31,7 +31,7 @@ class News { // Get the news posts and assign them to $posts - $posts = DB::prepare('SELECT * FROM `{prefix}news` WHERE `news_category` = :cat ORDER BY `news_id` DESC'); + $posts = DBv2::prepare('SELECT * FROM `{prefix}news` WHERE `news_category` = :cat ORDER BY `news_id` DESC'); $posts->execute([ 'cat' => $category, ]); diff --git a/libraries/Perms.php b/libraries/Perms.php index ecc8a58..62a04cc 100644 --- a/libraries/Perms.php +++ b/libraries/Perms.php @@ -102,7 +102,7 @@ class Perms } // Prepare the statement - $get = DB::prepare($stmt); + $get = DBv2::prepare($stmt); // Bind rank $get->bindParam('rank', $rid); @@ -156,7 +156,7 @@ class Perms } // Prepare the statement - $get = DB::prepare($stmt); + $get = DBv2::prepare($stmt); // Bind rank $get->bindParam('user', $uid); diff --git a/libraries/Rank.php b/libraries/Rank.php index 4446b10..03c3bc2 100644 --- a/libraries/Rank.php +++ b/libraries/Rank.php @@ -111,20 +111,19 @@ class Rank /** * Constructor. * - * @param int $rid ID of the rank that should be constructed. + * @param int $rankId ID of the rank that should be constructed. */ - private function __construct($rid) + private function __construct($rankId) { // Get the rank database row - $rankRow = DB::prepare('SELECT * FROM `{prefix}ranks` WHERE `rank_id` = :id'); - $rankRow->execute([ - 'id' => $rid, - ]); - $rankRow = $rankRow->fetch(); + $rankRow = DB::table('ranks') + ->where('rank_id', $rankId) + ->get(); // Check if the rank actually exists if ($rankRow) { + $rankRow = $rankRow[0]; $this->id = $rankRow->rank_id; $this->name = $rankRow->rank_name; $this->hierarchy = $rankRow->rank_hierarchy; @@ -189,7 +188,7 @@ class Rank public function users($justIds = false) { // Fetch all users part of this rank - $fetch = DB::prepare('SELECT `user_id` FROM `{prefix}user_ranks` WHERE `rank_id` = :id'); + $fetch = DBv2::prepare('SELECT `user_id` FROM `{prefix}user_ranks` WHERE `rank_id` = :id'); $fetch->execute([ 'id' => $this->id, ]); diff --git a/libraries/Session.php b/libraries/Session.php index 8b3b997..8a078ae 100644 --- a/libraries/Session.php +++ b/libraries/Session.php @@ -53,11 +53,10 @@ class Session public function destroy() { // Invalidate the session key - DB::prepare('DELETE FROM `{prefix}sessions` WHERE `session_key` = :key AND `user_id` = :user') - ->execute([ - 'key' => $this->sessionId, - 'user' => $this->userId, - ]); + DB::table('sessions') + ->where('session_key', $this->sessionId) + ->where('user_id', $this->userId) + ->delete(); // Unset userId and sessionId unset($this->userId); @@ -75,10 +74,9 @@ class Session public function destroyAll() { // Delete all database entries with this user in it - DB::prepare('DELETE FROM `{prefix}sessions` WHERE `user_id` = :user') - ->execute([ - 'user' => $this->userId, - ]); + DB::table('sessions') + ->where('user_id', $this->userId) + ->delete(); // Destroy this session to finish it off $this->destroy(); @@ -97,16 +95,16 @@ class Session $session = hash('sha256', $this->userId . base64_encode('sakura' . mt_rand(0, 99999999)) . time()); // Insert the session into the database - DB::prepare('INSERT INTO `{prefix}sessions` (`user_id`, `user_ip`, `user_agent`, `session_key`, `session_start`, `session_expire`, `session_remember`) VALUES (:id, :ip, :agent, :key, :start, :end, :remember)') - ->execute([ - 'id' => $this->userId, - 'ip' => Net::pton(Net::IP()), - 'agent' => Utils::cleanString(isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'No user agent header.'), - 'key' => $session, - 'start' => time(), - 'end' => time() + 604800, - 'remember' => $permanent ? '1' : '0', - ]); + DB::table('sessions') + ->insert([ + 'user_id' => $this->userId, + 'user_ip' => Net::pton(Net::IP()), + 'user_agent' => Utils::cleanString(isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'No user agent header.'), + 'session_key' => $session, + 'session_start' => time(), + 'session_expire' => time() + 604800, + 'session_remember' => $permanent ? '1' : '0', + ]); // Return the session key return $session; @@ -120,12 +118,10 @@ class Session public function validate() { // Get session from database - $session = DB::prepare('SELECT * FROM `{prefix}sessions` WHERE `user_id` = :user AND `session_key` = :key'); - $session->execute([ - 'user' => $this->userId, - 'key' => $this->sessionId, - ]); - $session = $session->fetch(); + $session = DB::table('sessions') + ->where('user_id', $this->userId) + ->where('session_key', $this->sessionId) + ->get(); // Check if we actually got something in return if (!$session) { @@ -133,7 +129,7 @@ class Session } // Check if the session expired - if ($session->session_expire < time()) { + if ($session[0]->session_expire < time()) { // ...and return false return 0; } @@ -144,7 +140,7 @@ class Session // Origin checking if ($ipCheck) { // Split both IPs up - $sessionIP = explode('.', $session['user_ip']); + $sessionIP = explode('.', $session[0]->user_ip); $userIP = explode('.', Net::IP()); // Take 1 off the ipCheck variable so it's equal to the array keys @@ -185,15 +181,13 @@ class Session } // If the remember flag is set extend the session time - if ($session->session_remember) { - DB::prepare('UPDATE `{prefix}sessions` SET `session_expire` = :expire WHERE `session_id` = :id') - ->execute([ - 'expire' => time() + 604800, - 'id' => $session->session_id, - ]); + if ($session[0]->session_remember) { + DB::table('sessions') + ->where('session_id', $session[0]->session_id) + ->update(['session_expire' => time() + 604800]); } // Return 2 if the remember flag is set and return 1 if not - return $session->session_remember ? 2 : 1; + return $session[0]->session_remember ? 2 : 1; } } diff --git a/libraries/User.php b/libraries/User.php index 13b39c7..c917c89 100644 --- a/libraries/User.php +++ b/libraries/User.php @@ -258,7 +258,7 @@ class User $password = Hashing::createHash($password); // Insert the user into the database - DB::prepare('INSERT INTO `{prefix}users` (`username`, `username_clean`, `password_hash`, `password_salt`, `password_algo`, `password_iter`, `email`, `rank_main`, `register_ip`, `last_ip`, `user_registered`, `user_last_online`, `user_country`) VALUES (:uname, :uname_clean, :pw_hash, :pw_salt, :pw_algo, :pw_iter, :email, :rank, :r_ip, :l_ip, :registered, :l_online, :country)') + DBv2::prepare('INSERT INTO `{prefix}users` (`username`, `username_clean`, `password_hash`, `password_salt`, `password_algo`, `password_iter`, `email`, `rank_main`, `register_ip`, `last_ip`, `user_registered`, `user_last_online`, `user_country`) VALUES (:uname, :uname_clean, :pw_hash, :pw_salt, :pw_algo, :pw_iter, :email, :rank, :r_ip, :l_ip, :registered, :l_online, :country)') ->execute([ 'uname' => $username, 'uname_clean' => $usernameClean, @@ -276,7 +276,7 @@ class User ]); // Get the last id - $userId = DB::lastID(); + $userId = DBv2::lastID(); // Create a user object $user = self::construct($userId); @@ -299,7 +299,7 @@ class User private function __construct($uid) { // Get the user database row - $userRow = DB::prepare('SELECT * FROM `{prefix}users` WHERE `user_id` = :id OR `username_clean` = :clean'); + $userRow = DBv2::prepare('SELECT * FROM `{prefix}users` WHERE `user_id` = :id OR `username_clean` = :clean'); $userRow->execute([ 'id' => $uid, 'clean' => Utils::cleanString($uid, true, true), @@ -334,7 +334,7 @@ class User } // Get all ranks - $ranks = DB::prepare('SELECT * FROM `{prefix}user_ranks` WHERE `user_id` = :id'); + $ranks = DBv2::prepare('SELECT * FROM `{prefix}user_ranks` WHERE `user_id` = :id'); $ranks->execute([ 'id' => $this->id, ]); @@ -426,7 +426,7 @@ class User public function isOnline() { // Get all sessions - $sessions = DB::prepare('SELECT `user_id` FROM `{prefix}sessions` WHERE `user_id` = :id'); + $sessions = DBv2::prepare('SELECT `user_id` FROM `{prefix}sessions` WHERE `user_id` = :id'); $sessions->execute([ 'id' => $this->id, ]); @@ -447,12 +447,12 @@ class User */ public function forumStats() { - $posts = DB::prepare('SELECT * FROM `{prefix}posts` WHERE `poster_id` = :id'); + $posts = DBv2::prepare('SELECT * FROM `{prefix}posts` WHERE `poster_id` = :id'); $posts->execute([ 'id' => $this->id, ]); - $threads = DB::prepare('SELECT DISTINCT * FROM `{prefix}posts` WHERE `poster_id` = :id GROUP BY `topic_id` ORDER BY `post_time`'); + $threads = DBv2::prepare('SELECT DISTINCT * FROM `{prefix}posts` WHERE `poster_id` = :id GROUP BY `topic_id` ORDER BY `post_time`'); $threads->execute([ 'id' => $this->id, ]); @@ -482,7 +482,7 @@ class User // Save to the database foreach ($ranks as $rank) { - DB::prepare('INSERT INTO `{prefix}ranks` (`rank_id`, `user_id`) VALUES (:rank, :user)') + DBv2::prepare('INSERT INTO `{prefix}ranks` (`rank_id`, `user_id`) VALUES (:rank, :user)') ->execute([ 'rank' => $rank, 'user' => $this->id, @@ -502,7 +502,7 @@ class User // Iterate over the ranks foreach ($remove as $rank) { - DB::prepare('DELETE FROM `{prefix}user_ranks` WHERE `user_id` = :user AND `rank_id` = :rank') + DBv2::prepare('DELETE FROM `{prefix}user_ranks` WHERE `user_id` = :user AND `rank_id` = :rank') ->execute([ 'user' => $this->id, 'rank' => $rank, @@ -520,7 +520,7 @@ class User public function setMainRank($rank) { // If it does exist update their row - DB::prepare('UPDATE `{prefix}users` SET `rank_main` = :rank WHERE `user_id` = :id') + DBv2::prepare('UPDATE `{prefix}users` SET `rank_main` = :rank WHERE `user_id` = :id') ->execute([ 'rank' => $rank, 'id' => $this->id, @@ -579,7 +579,7 @@ class User } // Add friend - DB::prepare('INSERT INTO `{prefix}friends` (`user_id`, `friend_id`, `friend_timestamp`) VALUES (:user, :friend, :time)') + DBv2::prepare('INSERT INTO `{prefix}friends` (`user_id`, `friend_id`, `friend_timestamp`) VALUES (:user, :friend, :time)') ->execute([ 'user' => $this->id, 'friend' => $uid, @@ -609,7 +609,7 @@ class User } // Prepare the statement - $rem = DB::prepare('DELETE FROM `{prefix}friends` WHERE `user_id` = :user AND `friend_id` = :friend'); + $rem = DBv2::prepare('DELETE FROM `{prefix}friends` WHERE `user_id` = :user AND `friend_id` = :friend'); // Remove friend $rem->execute([ @@ -639,7 +639,7 @@ class User public function isFriends($with) { // Accepted from this user - $get = DB::prepare('SELECT * FROM `{prefix}friends` WHERE `user_id` = :user AND `friend_id` = :friend'); + $get = DBv2::prepare('SELECT * FROM `{prefix}friends` WHERE `user_id` = :user AND `friend_id` = :friend'); $get->execute([ 'user' => $this->id, 'friend' => $with, @@ -681,14 +681,14 @@ class User // Mutual case 2: // Get all the current user's friends - $self = DB::prepare('SELECT `friend_id` FROM `{prefix}friends` WHERE `user_id` = :user'); + $self = DBv2::prepare('SELECT `friend_id` FROM `{prefix}friends` WHERE `user_id` = :user'); $self->execute([ 'user' => $this->id, ]); $self = array_column($self->fetchAll(\PDO::FETCH_ASSOC), 'friend_id'); // Get all the people that added this user as a friend - $others = DB::prepare('SELECT `user_id` FROM `{prefix}friends` WHERE `friend_id` = :user'); + $others = DBv2::prepare('SELECT `user_id` FROM `{prefix}friends` WHERE `friend_id` = :user'); $others->execute([ 'user' => $this->id, ]); @@ -700,7 +700,7 @@ class User // Non-mutual (from user perspective) case 1: - $users = DB::prepare('SELECT `friend_id` FROM `{prefix}friends` WHERE `user_id` = :user'); + $users = DBv2::prepare('SELECT `friend_id` FROM `{prefix}friends` WHERE `user_id` = :user'); $users->execute([ 'user' => $this->id, ]); @@ -711,14 +711,14 @@ class User case 0: default: // Get all the current user's friends - $self = DB::prepare('SELECT `friend_id` FROM `{prefix}friends` WHERE `user_id` = :user'); + $self = DBv2::prepare('SELECT `friend_id` FROM `{prefix}friends` WHERE `user_id` = :user'); $self->execute([ 'user' => $this->id, ]); $self = array_column($self->fetchAll(\PDO::FETCH_ASSOC), 'friend_id'); // Get all the people that added this user as a friend - $others = DB::prepare('SELECT `user_id` FROM `{prefix}friends` WHERE `friend_id` = :user'); + $others = DBv2::prepare('SELECT `user_id` FROM `{prefix}friends` WHERE `friend_id` = :user'); $others->execute([ 'user' => $this->id, ]); @@ -731,14 +731,14 @@ class User // Open requests case -1: // Get all the current user's friends - $self = DB::prepare('SELECT `friend_id` FROM `{prefix}friends` WHERE `user_id` = :user'); + $self = DBv2::prepare('SELECT `friend_id` FROM `{prefix}friends` WHERE `user_id` = :user'); $self->execute([ 'user' => $this->id, ]); $self = array_column($self->fetchAll(\PDO::FETCH_ASSOC), 'friend_id'); // Get all the people that added this user as a friend - $others = DB::prepare('SELECT `user_id` FROM `{prefix}friends` WHERE `friend_id` = :user'); + $others = DBv2::prepare('SELECT `user_id` FROM `{prefix}friends` WHERE `friend_id` = :user'); $others->execute([ 'user' => $this->id, ]); @@ -824,11 +824,11 @@ class User // Create array and get values $profile = []; - $profileFields = DB::prepare('SELECT * FROM `{prefix}profilefields`'); + $profileFields = DBv2::prepare('SELECT * FROM `{prefix}profilefields`'); $profileFields->execute(); $profileFields = $profileFields->fetchAll(\PDO::FETCH_ASSOC); - $profileValuesRaw = DB::prepare('SELECT * FROM `{prefix}user_profilefields` WHERE `user_id` = :user'); + $profileValuesRaw = DBv2::prepare('SELECT * FROM `{prefix}user_profilefields` WHERE `user_id` = :user'); $profileValuesRaw->execute([ 'user' => $this->id, ]); @@ -912,11 +912,11 @@ class User // Create array and get values $options = []; - $optionFields = DB::prepare('SELECT * FROM `{prefix}optionfields`'); + $optionFields = DBv2::prepare('SELECT * FROM `{prefix}optionfields`'); $optionFields->execute(); $optionFields = $optionFields->fetchAll(\PDO::FETCH_ASSOC); - $optionValuesRaw = DB::prepare('SELECT * FROM `{prefix}user_optionfields` WHERE `user_id` = :user'); + $optionValuesRaw = DBv2::prepare('SELECT * FROM `{prefix}user_optionfields` WHERE `user_id` = :user'); $optionValuesRaw->execute([ 'user' => $this->id, ]); @@ -972,7 +972,7 @@ class User } // Attempt to retrieve the premium record from the database - $getRecord = DB::prepare('SELECT * FROM `{prefix}premium` WHERE `user_id` = :user'); + $getRecord = DBv2::prepare('SELECT * FROM `{prefix}premium` WHERE `user_id` = :user'); $getRecord->execute([ 'user' => $this->id, ]); @@ -1000,7 +1000,7 @@ class User public function getWarnings() { // Do the database query - $getWarnings = DB::prepare('SELECT * FROM `{prefix}warnings` WHERE `user_id` = :user'); + $getWarnings = DBv2::prepare('SELECT * FROM `{prefix}warnings` WHERE `user_id` = :user'); $getWarnings->execute([ 'user' => $this->id, ]); @@ -1013,7 +1013,7 @@ class User foreach ($getWarnings as $warning) { // Check if it hasn't expired if ($warning['warning_expires'] < time()) { - DB::prepare('DELETE FROM `{prefix}warnings` WHERE `warning_id` = :warn') + DBv2::prepare('DELETE FROM `{prefix}warnings` WHERE `warning_id` = :warn') ->execute([ 'warn' => $warning['warning_id'], ]); @@ -1079,7 +1079,7 @@ class User public function getUsernameHistory() { // Do the database query - $changes = DB::prepare('SELECT * FROM `{prefix}username_history` WHERE `user_id` = :user ORDER BY `change_id` DESC'); + $changes = DBv2::prepare('SELECT * FROM `{prefix}username_history` WHERE `user_id` = :user ORDER BY `change_id` DESC'); $changes->execute([ 'user' => $this->id, ]); @@ -1111,7 +1111,7 @@ class User } // Check if this username hasn't been used in the last amount of days set in the config - $getOld = DB::prepare('SELECT * FROM `{prefix}username_history` WHERE `username_old_clean` = :clean AND `change_time` > :time ORDER BY `change_id` DESC'); + $getOld = DBv2::prepare('SELECT * FROM `{prefix}username_history` WHERE `username_old_clean` = :clean AND `change_time` > :time ORDER BY `change_id` DESC'); $getOld->execute([ 'clean' => $username_clean, 'time' => (Config::get('old_username_reserve') * 24 * 60 * 60), @@ -1124,7 +1124,7 @@ class User } // Check if the username is already in use - $getInUse = DB::prepare('SELECT * FROM `{prefix}users` WHERE `username_clean` = :clean'); + $getInUse = DBv2::prepare('SELECT * FROM `{prefix}users` WHERE `username_clean` = :clean'); $getInUse->execute([ 'clean' => $username_clean, ]); @@ -1136,7 +1136,7 @@ class User } // Insert into username_history table - DB::prepare('INSERT INTO `{prefix}username_history` (`change_time`, `user_id`, `username_new`, `username_new_clean`, `username_old`, `username_old_clean`) VALUES (:time, :user, :new, :new_clean, :old, :old_clean)') + DBv2::prepare('INSERT INTO `{prefix}username_history` (`change_time`, `user_id`, `username_new`, `username_new_clean`, `username_old`, `username_old_clean`) VALUES (:time, :user, :new, :new_clean, :old, :old_clean)') ->execute([ 'time' => time(), 'user' => $this->id, @@ -1147,7 +1147,7 @@ class User ]); // Update userrow - DB::prepare('UPDATE `{prefix}users` SET `username` = :username, `username_clean` = :clean WHERE `user_id` = :id') + DBv2::prepare('UPDATE `{prefix}users` SET `username` = :username, `username_clean` = :clean WHERE `user_id` = :id') ->execute([ 'username' => $username, 'clean' => $username_clean, @@ -1173,7 +1173,7 @@ class User } // Check if the username is already in use - $getInUse = DB::prepare('SELECT * FROM `{prefix}users` WHERE `email` = :email'); + $getInUse = DBv2::prepare('SELECT * FROM `{prefix}users` WHERE `email` = :email'); $getInUse->execute([ 'email' => $email, ]); @@ -1185,7 +1185,7 @@ class User } // Update userrow - DB::prepare('UPDATE `{prefix}users` SET `email` = :email WHERE `user_id` = :id') + DBv2::prepare('UPDATE `{prefix}users` SET `email` = :email WHERE `user_id` = :id') ->execute([ 'email' => $email, 'id' => $this->id, @@ -1239,7 +1239,7 @@ class User $password = Hashing::createHash($new); // Update userrow - DB::prepare('UPDATE `{prefix}users` SET `password_hash` = :hash, `password_salt` = :salt, `password_algo` = :algo, `password_iter` = :iter, `password_chan` = :chan WHERE `user_id` = :id') + DBv2::prepare('UPDATE `{prefix}users` SET `password_hash` = :hash, `password_salt` = :salt, `password_algo` = :algo, `password_iter` = :iter, `password_chan` = :chan WHERE `user_id` = :id') ->execute([ 'hash' => $password[3], 'salt' => $password[2], diff --git a/libraries/Users.php b/libraries/Users.php index 44b06a0..9edd8d1 100644 --- a/libraries/Users.php +++ b/libraries/Users.php @@ -85,7 +85,7 @@ class Users } // Update last online - DB::prepare('UPDATE `{prefix}users` SET `user_last_online` = :lo WHERE `user_id` = :id') + DBv2::prepare('UPDATE `{prefix}users` SET `user_last_online` = :lo WHERE `user_id` = :id') ->execute([ 'lo' => time(), 'id' => $uid, @@ -116,7 +116,7 @@ class Users } // Check if we haven't hit the rate limit - $rates = DB::prepare('SELECT * FROM `{prefix}login_attempts` WHERE `attempt_ip` = :ip AND `attempt_timestamp` > :time AND `attempt_success` = 0'); + $rates = DBv2::prepare('SELECT * FROM `{prefix}login_attempts` WHERE `attempt_ip` = :ip AND `attempt_timestamp` > :time AND `attempt_success` = 0'); $rates->execute([ 'ip' => Net::pton(Net::IP()), 'time' => time() - 1800, @@ -285,7 +285,7 @@ class Users } // Check if the e-mail has already been used - $emailCheck = DB::prepare('SELECT `user_id` FROM `{prefix}users` WHERE `email` = :email'); + $emailCheck = DBv2::prepare('SELECT `user_id` FROM `{prefix}users` WHERE `email` = :email'); $emailCheck->execute([ 'email' => $email, ]); @@ -340,7 +340,7 @@ class Users $emailClean = Utils::cleanString($email, true); // Do database request - $user = DB::prepare('SELECT * FROM `{prefix}users` WHERE `username_clean` = :clean AND `email` = :email'); + $user = DBv2::prepare('SELECT * FROM `{prefix}users` WHERE `username_clean` = :clean AND `email` = :email'); $user->execute([ 'clean' => $usernameClean, 'email' => $emailClean, @@ -423,7 +423,7 @@ class Users $password = Hashing::createHash($newpass); // Update the user - DB::prepare('UPDATE `{prefix}users` SET `password_hash` = :hash, `password_salt` = :salt, `password_algo` = :algo, `password_iter` = :iter, `password_chan` = :chan WHERE `user_id` = :id') + DBv2::prepare('UPDATE `{prefix}users` SET `password_hash` = :hash, `password_salt` = :salt, `password_algo` = :algo, `password_iter` = :iter, `password_chan` = :chan WHERE `user_id` = :id') ->execute([ 'hash' => $password[3], 'salt' => $password[2], @@ -457,7 +457,7 @@ class Users $emailClean = Utils::cleanString($email, true); // Do database request - $user = DB::prepare('SELECT * FROM `{prefix}users` WHERE `username_clean` = :clean AND `email` = :email'); + $user = DBv2::prepare('SELECT * FROM `{prefix}users` WHERE `username_clean` = :clean AND `email` = :email'); $user->execute([ 'clean' => $usernameClean, 'email' => $emailClean, @@ -590,7 +590,7 @@ class Users public static function userExists($id, $unused = null) { // Do database request - $user = DB::prepare('SELECT * FROM `{prefix}users` WHERE `user_id` = :id OR `username_clean` = :clean'); + $user = DBv2::prepare('SELECT * FROM `{prefix}users` WHERE `user_id` = :id OR `username_clean` = :clean'); $user->execute([ 'id' => $id, 'clean' => Utils::cleanString($id, true, true), @@ -609,7 +609,7 @@ class Users public static function getProfileFields() { // Get profile fields - $profileFields = DB::prepare('SELECT * FROM `{prefix}profilefields`'); + $profileFields = DBv2::prepare('SELECT * FROM `{prefix}profilefields`'); $profileFields->execute(); $profileFields = $profileFields->fetchAll(\PDO::FETCH_ASSOC); @@ -640,7 +640,7 @@ class Users public static function getOptionFields() { // Get option fields - $optionFields = DB::prepare('SELECT * FROM `{prefix}optionfields`'); + $optionFields = DBv2::prepare('SELECT * FROM `{prefix}optionfields`'); $optionFields->execute(); $optionFields = $optionFields->fetchAll(\PDO::FETCH_ASSOC); @@ -680,7 +680,7 @@ class Users $return = []; // Get all online users in the past 5 minutes - $getAll = DB::prepare('SELECT * FROM `{prefix}users` WHERE `user_last_online` > :lo'); + $getAll = DBv2::prepare('SELECT * FROM `{prefix}users` WHERE `user_last_online` > :lo'); $getAll->execute([ 'lo' => $time, ]); @@ -705,7 +705,7 @@ class Users public static function addUserPremium($id, $seconds) { // Check if there's already a record of premium for this user in the database - $getUser = DB::prepare('SELECT * FROM `{prefix}premium` WHERE `user_id` = :user'); + $getUser = DBv2::prepare('SELECT * FROM `{prefix}premium` WHERE `user_id` = :user'); $getUser->execute([ 'user' => $id, ]); @@ -717,14 +717,14 @@ class Users // If the user already exists do an update call, otherwise an insert call if (empty($getUser)) { - DB::prepare('INSERT INTO `{prefix}premium` (`user_id`, `premium_start`, `premium_expire`) VALUES (:user, :start, :expire)') + DBv2::prepare('INSERT INTO `{prefix}premium` (`user_id`, `premium_start`, `premium_expire`) VALUES (:user, :start, :expire)') ->execute([ 'user' => $id, 'start' => $start, 'expire' => $expire, ]); } else { - DB::prepare('UPDATE `{prefix}premium` SET `premium_expire` = :expire WHERE `user_id` = :id') + DBv2::prepare('UPDATE `{prefix}premium` SET `premium_expire` = :expire WHERE `user_id` = :id') ->execute([ 'expire' => $expire, 'user_id' => $id, @@ -763,7 +763,7 @@ class Users } } elseif (!$check[0]) { // Remove the expired entry - DB::prepare('DELETE FROM `{prefix}premium` WHERE `user_id` = :user') + DBv2::prepare('DELETE FROM `{prefix}premium` WHERE `user_id` = :user') ->execute([ 'user' => $user->id, ]); @@ -783,7 +783,7 @@ class Users public static function getUsersByIP($ip) { // Get the users - $users = DB::prepare('SELECT * FROM `{prefix}users` WHERE `register_ip` = :rip OR `last_ip` = :lip'); + $users = DBv2::prepare('SELECT * FROM `{prefix}users` WHERE `register_ip` = :rip OR `last_ip` = :lip'); $users->execute([ 'rip' => $ip, 'lip' => $ip, @@ -802,7 +802,7 @@ class Users public static function getAllRanks() { // Execute query - $getRanks = DB::prepare('SELECT * FROM `{prefix}ranks`'); + $getRanks = DBv2::prepare('SELECT * FROM `{prefix}ranks`'); $getRanks->execute(); $getRanks = $getRanks->fetchAll(); @@ -836,7 +836,7 @@ class Users $read = $excludeRead ? '0' : '%'; // Get notifications for the database - $notifications = DB::prepare('SELECT * FROM `{prefix}notifications` WHERE `user_id` = :user AND `alert_timestamp` > :time AND `alert_read` = :read'); + $notifications = DBv2::prepare('SELECT * FROM `{prefix}notifications` WHERE `user_id` = :user AND `alert_timestamp` > :time AND `alert_read` = :read'); $notifications->execute([ 'user' => $uid, 'time' => $time, @@ -871,7 +871,7 @@ class Users public static function markNotificationRead($id, $mode = true) { // Execute an update statement - DB::prepare('UPDATE `{prefix}notifications` SET `alert_read` = :read WHERE `alert_id` = :id') + DBv2::prepare('UPDATE `{prefix}notifications` SET `alert_read` = :read WHERE `alert_id` = :id') ->execute([ 'read' => ($mode ? 1 : 0), 'id' => $id, @@ -892,7 +892,7 @@ class Users public static function createNotification($user, $title, $text, $timeout = 60000, $img = 'FONT:fa-info-circle', $link = '', $sound = 0) { // Insert it into the database - DB::prepare('INSERT INTO `{prefix}notifications` (`user_id`, `alert_timestamp`, `alert_read`, `alert_sound`, `alert_title`, `alert_text`, `alert_link`, `alert_img`, `alert_timeout`) VALUES (:user, :time, :read, :sound, :title, :text, :link, :img, :timeout)') + DBv2::prepare('INSERT INTO `{prefix}notifications` (`user_id`, `alert_timestamp`, `alert_read`, `alert_sound`, `alert_title`, `alert_text`, `alert_link`, `alert_img`, `alert_timeout`) VALUES (:user, :time, :read, :sound, :title, :text, :link, :img, :timeout)') ->execute([ 'user' => $user, 'time' => time(), @@ -913,7 +913,7 @@ class Users */ public static function getNewestUserId() { - $get = DB::prepare('SELECT `user_id` FROM `{prefix}users` WHERE `rank_main` != :restricted ORDER BY `user_id` DESC LIMIT 1'); + $get = DBv2::prepare('SELECT `user_id` FROM `{prefix}users` WHERE `rank_main` != :restricted ORDER BY `user_id` DESC LIMIT 1'); $get->execute([ 'restricted' => Config::get('restricted_rank_id'), ]); diff --git a/libraries/Utils.php b/libraries/Utils.php index ed844b6..3d83420 100644 --- a/libraries/Utils.php +++ b/libraries/Utils.php @@ -61,12 +61,12 @@ class Utils $errfile = str_replace(ROOT, '', $errfile); // Attempt to log the error to the database - if (DB::$db !== null) { + if (DBv2::$db !== null) { // Encode backtrace data $backtrace = base64_encode(json_encode(debug_backtrace())); // Check if this error has already been logged in the past - $past = DB::prepare('SELECT * FROM `{prefix}error_log` WHERE `error_backtrace` = :bc OR (`error_string` = :str AND `error_line` = :li)'); + $past = DBv2::prepare('SELECT * FROM `{prefix}error_log` WHERE `error_backtrace` = :bc OR (`error_string` = :str AND `error_line` = :li)'); $past->execute([ 'bc' => $backtrace, 'str' => $errstr, @@ -82,7 +82,7 @@ class Utils $errid = substr(md5(microtime()), rand(0, 22), 10); // Log the error - DB::prepare('INSERT INTO `{prefix}error_log` (`error_id`, `error_timestamp`, `error_revision`, `error_type`, `error_line`, `error_string`, `error_file`, `error_backtrace`) VALUES (:id, :time, :rev, :type, :line, :string, :file, :bc)') + DBv2::prepare('INSERT INTO `{prefix}error_log` (`error_id`, `error_timestamp`, `error_revision`, `error_type`, `error_line`, `error_string`, `error_file`, `error_backtrace`) VALUES (:id, :time, :rev, :type, :line, :string, :file, :bc)') ->execute([ 'id' => $errid, 'time' => date("r"), @@ -431,7 +431,7 @@ class Utils $data = []; // Get database stuff - $table = DB::prepare('SELECT * FROM `{prefix}premium_log` ORDER BY `transaction_id` DESC'); + $table = DBv2::prepare('SELECT * FROM `{prefix}premium_log` ORDER BY `transaction_id` DESC'); $table->execute(); $table = $table->fetchAll(\PDO::FETCH_ASSOC); @@ -468,7 +468,7 @@ class Utils */ public static function updatePremiumTracker($id, $amount, $comment) { - DB::prepare('INSERT INTO `{prefix}premium_log` (`user_id`, `transaction_amount`, `transaction_date`, `transaction_comment`) VALUES (:user, :amount, :date, :comment)') + DBv2::prepare('INSERT INTO `{prefix}premium_log` (`user_id`, `transaction_amount`, `transaction_date`, `transaction_comment`) VALUES (:user, :amount, :date, :comment)') ->execute([ 'user' => $id, 'amount' => $amount, diff --git a/mahou b/mahou old mode 100755 new mode 100644 diff --git a/public/authenticate.php b/public/authenticate.php index 4732d57..ffc613a 100644 --- a/public/authenticate.php +++ b/public/authenticate.php @@ -184,7 +184,7 @@ if (isset($_REQUEST['mode'])) { // Check if we're not RATE_LIMIT if ($login[1] != 'RATE_LIMIT') { // Add to database - DB::prepare('INSERT INTO `{prefix}login_attempts` (`attempt_success`, `attempt_timestamp`, `attempt_ip`, `user_id`) VALUES (:succ, :time, :ip, :user)') + DBv2::prepare('INSERT INTO `{prefix}login_attempts` (`attempt_success`, `attempt_timestamp`, `attempt_ip`, `user_id`) VALUES (:succ, :time, :ip, :user)') ->execute([ 'succ' => $login[0], 'time' => time(), diff --git a/public/posting.php b/public/posting.php index f194fcd..e3cadc7 100644 --- a/public/posting.php +++ b/public/posting.php @@ -67,7 +67,7 @@ if (!isset($thread) && !$forum->permission(ForumPerms::CREATE_THREADS, $currentU $mode = isset($_GET['f']) ? 'f' : (isset($_GET['t']) ? 't' : (isset($_GET['p']) ? 'p' : null)); -$emotes = DB::prepare('SELECT * FROM `{prefix}emoticons`'); +$emotes = DBv2::prepare('SELECT * FROM `{prefix}emoticons`'); $emotes->execute(); // Include emotes and bbcodes @@ -201,7 +201,7 @@ if ($mode != 'f') { // Post deletion code if (isset($_POST['yes'])) { // Delete the post - DB::prepare('DELETE FROM `{prefix}posts` WHERE `post_id` = :post') + DBv2::prepare('DELETE FROM `{prefix}posts` WHERE `post_id` = :post') ->execute([ 'post' => $_POST['post_id'], ]); @@ -211,7 +211,7 @@ if ($mode != 'f') { // If there's no more posts left in the topic delete it as well if (!$thread->replyCount()) { - DB::prepare('DELETE FROM `{prefix}topics` WHERE `topic_id` = :thread') + DBv2::prepare('DELETE FROM `{prefix}topics` WHERE `topic_id` = :thread') ->execute([ 'thread' => $thread->id, ]); diff --git a/public/settings.php b/public/settings.php index 8ab6785..695220f 100644 --- a/public/settings.php +++ b/public/settings.php @@ -617,7 +617,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification } // Update table - DB::prepare($stmt) + DBv2::prepare($stmt) ->execute([ 'img' => $fileId, 'user' => $currentUser->id, @@ -640,12 +640,12 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification foreach ($fields as $field) { // Add to the store array if (isset($_POST['profile_' . $field['field_identity']]) && !empty($_POST['profile_' . $field['field_identity']])) { - DB::prepare('DELETE FROM `{prefix}user_profilefields` WHERE `user_id` = :user AND `field_name` = :id') + DBv2::prepare('DELETE FROM `{prefix}user_profilefields` WHERE `user_id` = :user AND `field_name` = :id') ->execute([ 'user' => $currentUser->id, 'id' => $field['field_identity'], ]); - DB::prepare('INSERT INTO `{prefix}user_profilefields` (`user_id`, `field_name`, `field_value`) VALUES (:user, :name, :value)') + DBv2::prepare('INSERT INTO `{prefix}user_profilefields` (`user_id`, `field_name`, `field_value`) VALUES (:user, :name, :value)') ->execute([ 'user' => $currentUser->id, 'name' => $field['field_identity'], @@ -659,12 +659,12 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification foreach ($field['field_additional'] as $addKey => $addVal) { // Add to the array $store = (isset($_POST['profile_additional_' . $addKey]) || !empty($_POST['profile_additional_' . $addKey])) ? $_POST['profile_additional_' . $addKey] : false; - DB::prepare('DELETE FROM `{prefix}user_profilefields` WHERE `user_id` = :user AND `field_name` = :id') + DBv2::prepare('DELETE FROM `{prefix}user_profilefields` WHERE `user_id` = :user AND `field_name` = :id') ->execute([ 'user' => $currentUser->id, 'id' => $addKey, ]); - DB::prepare('INSERT INTO `{prefix}user_profilefields` (`user_id`, `field_name`, `field_value`) VALUES (:user, :name, :value)') + DBv2::prepare('INSERT INTO `{prefix}user_profilefields` (`user_id`, `field_name`, `field_value`) VALUES (:user, :name, :value)') ->execute([ 'user' => $currentUser->id, 'name' => $addKey, @@ -731,7 +731,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification [$_POST['birthday_year'], $_POST['birthday_month'], $_POST['birthday_day']] ); - DB::prepare('UPDATE `{prefix}users` SET `user_birthday` = :bd WHERE `user_id` = :id') + DBv2::prepare('UPDATE `{prefix}users` SET `user_birthday` = :bd WHERE `user_id` = :id') ->execute([ 'bd' => $birthdate, 'id' => $currentUser->id, @@ -746,7 +746,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification // Go over each field foreach ($fields as $field) { - DB::prepare('DELETE FROM `{prefix}user_optionfields` WHERE `user_id` = :user AND `field_name` = :id') + DBv2::prepare('DELETE FROM `{prefix}user_optionfields` WHERE `user_id` = :user AND `field_name` = :id') ->execute([ 'user' => $currentUser->id, 'id' => $field['option_id'], @@ -759,7 +759,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification if (isset($_POST['option_' . $field['option_id']]) && !empty($_POST['option_' . $field['option_id']])) { - DB::prepare('INSERT INTO `{prefix}user_optionfields` (`user_id`, `field_name`, `field_value`) VALUES (:user, :name, :value)') + DBv2::prepare('INSERT INTO `{prefix}user_optionfields` (`user_id`, `field_name`, `field_value`) VALUES (:user, :name, :value)') ->execute([ 'user' => $currentUser->id, 'name' => $field['option_id'], @@ -801,7 +801,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification } // Update database - DB::prepare('UPDATE `{prefix}users` SET `user_title` = :title WHERE `user_id` = :id') + DBv2::prepare('UPDATE `{prefix}users` SET `user_title` = :title WHERE `user_id` = :id') ->execute([ 'title' => (isset($_POST['usertitle']) ? $_POST['usertitle'] : null), 'id' => $currentUser->id, @@ -938,7 +938,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification } // Update database - DB::prepare('UPDATE `{prefix}users` SET `user_page` = :up WHERE `user_id` = :id') + DBv2::prepare('UPDATE `{prefix}users` SET `user_page` = :up WHERE `user_id` = :id') ->execute([ 'up' => $_POST['userpage'], 'id' => $currentUser->id, @@ -964,7 +964,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification } // Update database - DB::prepare('UPDATE `{prefix}users` SET `user_signature` = :us WHERE `user_id` = :id') + DBv2::prepare('UPDATE `{prefix}users` SET `user_signature` = :us WHERE `user_id` = :id') ->execute([ 'us' => $_POST['signature'], 'id' => $currentUser->id, @@ -1049,7 +1049,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification // Check if sessionid is set to all if ($_POST['sessionid'] === 'all') { // Delete all sessions assigned to the current user - DB::prepare('DELETE FROM `{prefix}sessions` WHERE `user_id` = :user') + DBv2::prepare('DELETE FROM `{prefix}sessions` WHERE `user_id` = :user') ->execute([ 'user' => $currentUser->id, ]); @@ -1064,7 +1064,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification } // Check if the session is owned by the current user - $us = DB::prepare('SELECT * FROM `{prefix}sessions` WHERE `user_id` = :user AND `session_id` = :key'); + $us = DBv2::prepare('SELECT * FROM `{prefix}sessions` WHERE `user_id` = :user AND `session_id` = :key'); $us->execute([ 'user' => $currentUser->id, 'key' => $_POST['sessionid'], @@ -1079,7 +1079,7 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification } // Delete the session - DB::prepare('DELETE FROM `{prefix}sessions` WHERE `user_id` = :user AND `session_id` = :session') + DBv2::prepare('DELETE FROM `{prefix}sessions` WHERE `user_id` = :user AND `session_id` = :session') ->execute([ 'user' => $currentUser->id, 'session' => $_POST['sessionid'], @@ -1519,7 +1519,7 @@ if (Users::checkLogin()) { // Sessions case 'advanced.sessions': - $sessions = DB::prepare('SELECT * FROM `{prefix}sessions` WHERE `user_id` = :user'); + $sessions = DBv2::prepare('SELECT * FROM `{prefix}sessions` WHERE `user_id` = :user'); $sessions->execute([ 'user' => $currentUser->id, ]); diff --git a/sakura.php b/sakura.php index 0ce53e6..1c3a8f9 100644 --- a/sakura.php +++ b/sakura.php @@ -65,7 +65,7 @@ Config::init(ROOT . 'config/config.ini'); error_reporting(Config::local('dev', 'show_errors') ? -1 : 0); // Make the database connection -DB::open( +DBv2::open( Config::local('database', 'driver'), Config::local('dsn'), Config::local('database', 'username'), @@ -73,6 +73,15 @@ DB::open( Config::local('database', 'prefix') ); +// Create a new database capsule +$capsule = new \Illuminate\Database\Capsule\Manager; + +// Add the connection +$capsule->addConnection(Config::local('database')); + +// Make the capsule globally accessible +$capsule->setAsGlobal(); + // Check if we the system has a cron service if (Config::get('no_cron_service')) { // If not do an "asynchronous" call to the cron.php script