diff --git a/public/_flashii.php b/public/_flashii.php index 35a3936..5ae8827 100644 --- a/public/_flashii.php +++ b/public/_flashii.php @@ -1,39 +1,25 @@ PDO::CASE_NATURAL, - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, - PDO::ATTR_STRINGIFY_FETCHES => false, - PDO::ATTR_EMULATE_PREPARES => false, - PDO::MYSQL_ATTR_INIT_COMMAND => 'SET SESSION time_zone = \'+00:00\'' - . ', sql_mode = \'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION\'', - ]); -} catch(PDOException $ex) { - echo '{"error":103}'; + $db = \Index\Data\DbTools::create($config['dsn']); + $db->execute('SET SESSION time_zone = \'+00:00\', sql_mode = \'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION\';'); +} catch(Exception $ex) { + echo json_encode(['error' => 103, 'msg' => $ex->getMessage()]); exit; } diff --git a/public/charasort-shit.php b/public/charasort-shit.php deleted file mode 100644 index cdfd2b5..0000000 --- a/public/charasort-shit.php +++ /dev/null @@ -1,72 +0,0 @@ -prepare('SELECT `role_id`, `role_name` FROM `msz_roles` WHERE `role_hidden` = 0 ORDER BY `role_id` ASC'); -$getRoles->execute(); -while(($role = $getRoles->fetch()) !== false) - printf(' { name: "%s", key: "R%d" },%s', $role[1], $role[0], PHP_EOL); - -printf(' ],%s', PHP_EOL); -printf(' },%s', PHP_EOL); -printf(' {%s', PHP_EOL); -printf(' name: "Remove inactive members",%s', PHP_EOL); -printf(' key: "inactive",%s', PHP_EOL); -printf(' tooltip: "Limits the selection to people who have showed up within the last year.",%s', PHP_EOL); -printf(' },%s', PHP_EOL); -printf(' {%s', PHP_EOL); -printf(' name: "Remove members with no posts",%s', PHP_EOL); -printf(' key: "noposts",%s', PHP_EOL); -printf(' tooltip: "Removes members that have not made any forum posts yet.",%s', PHP_EOL); -printf(' },%s', PHP_EOL); -printf('];%s', PHP_EOL); - -echo PHP_EOL; - -printf('dataSet[dataSetVersion].characterData = [%s', PHP_EOL); - -$getUsers = $db->prepare('SELECT `user_id`, `username`, `user_active` > NOW() - INTERVAL 1 YEAR AS `user_active`, (SELECT COUNT(*) FROM `msz_forum_posts` WHERE `user_id` = u.`user_id` AND `post_deleted` IS NULL) AS `user_posts` FROM `msz_users` AS u WHERE `user_deleted` IS NULL ORDER BY `user_id` ASC'); -$getUsers->execute(); -while(($user = $getUsers->fetch()) !== false) { - printf(' {%s', PHP_EOL); - printf(' name: "%s",%s', $user[1], PHP_EOL); - printf(' img: "https://flashii.net/assets/avatar/%d?res=300",%s', $user[0], PHP_EOL); - printf(' opts: {%s', PHP_EOL); - printf(' role: [', PHP_EOL); - - $getRoles = $db->prepare('SELECT `role_id` FROM `msz_user_roles` WHERE `user_id` = :user'); - $getRoles->bindValue('user', $user[0]); - $getRoles->execute(); - while(($role = $getRoles->fetchColumn()) !== false) - printf(' "R%d", ', $role); - - printf('],%s', PHP_EOL); - - if(!$user[2]) - printf(' inactive: true,%s', PHP_EOL); - - if($user[3] < 1) - printf(' noposts: true,%s', PHP_EOL); - - printf(' },%s', PHP_EOL); - printf(' },%s', PHP_EOL); -} - -printf('];%s', PHP_EOL); diff --git a/public/exrate.php b/public/exrate.php index b49411e..b0a5d5f 100644 --- a/public/exrate.php +++ b/public/exrate.php @@ -1,20 +1,11 @@ PDO::CASE_NATURAL, - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, - PDO::ATTR_STRINGIFY_FETCHES => false, - PDO::ATTR_EMULATE_PREPARES => false, - PDO::MYSQL_ATTR_INIT_COMMAND => " - SET SESSION - sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION', - time_zone = '+00:00'; - ", - ]); -} catch(PDOException $ex) { + $db = \Index\Data\DbTools::create($config['exrate-dsn2']); + $db->execute('SET SESSION time_zone = \'+00:00\', sql_mode = \'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION\';'); +} catch(Exception $ex) { die((string)$ex); } @@ -23,8 +14,8 @@ define('EXRATE_COMMON', [ 'EUR', 'AUD', 'GBP', 'CAD', 'USD', 'JPY', 'PLN', 'SGD', 'RUB', 'ILS', ]); -$from = strtoupper((string)filter_input(INPUT_GET, 'from', FILTER_SANITIZE_STRING)); -$to = strtoupper((string)filter_input(INPUT_GET, 'to', FILTER_SANITIZE_STRING)); +$from = strtoupper((string)filter_input(INPUT_GET, 'from')); +$to = strtoupper((string)filter_input(INPUT_GET, 'to')); $amount = (string)(filter_input(INPUT_GET, 'amount', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION) ?? '1'); if((!empty($to) && strlen($to) !== 3) || strlen($from) !== 3) { @@ -32,17 +23,20 @@ if((!empty($to) && strlen($to) !== 3) || strlen($from) !== 3) { die('Invalid currency specified.'); } -$needsRefresh = $pdo->prepare('SELECT MAX(`rate_stored`) <= NOW() - INTERVAL 1 DAY FROM `exchange-rates` LIMIT 1'); -$needsRefresh = $needsRefresh->execute() ? $needsRefresh->fetchColumn() : 1; -if($needsRefresh !== 0) { +$needsRefresh = $db->query('SELECT MAX(rate_stored) > NOW() - INTERVAL 1 DAY FROM `exchange-rates` LIMIT 1'); +$needsRefresh->next(); +$needsRefresh = $needsRefresh->isNull(0) || $needsRefresh->getInteger(0) < 1; + +if($needsRefresh) { $data = json_decode(file_get_contents('https://api.exchangerate.host/latest?base=' . EXRATE_INTER), true); if($data !== null) { - $pdo->exec('TRUNCATE `exchange-rates`;'); - $insertCurrency = $pdo->prepare('REPLACE INTO `exchange-rates` (`rate_from`, `rate_to`, `rate_value`) VALUES (:from, :to, :value)'); - $insertCurrency->bindValue('from', $data['base']); + $db->execute('TRUNCATE `exchange-rates`'); + $insertCurrency = $db->prepare('INSERT INTO `exchange-rates` (rate_from, rate_to, rate_value) VALUES (?, ?, ?)'); foreach($data['rates'] as $currency => $rate) { - $insertCurrency->bindValue('to', $currency); - $insertCurrency->bindValue('value', $rate); + $insertCurrency->reset(); + $insertCurrency->addParameter(1, $data['base']); + $insertCurrency->addParameter(2, $currency); + $insertCurrency->addParameter(3, $rate); $insertCurrency->execute(); } } @@ -56,25 +50,41 @@ $result->amount = (float)$amount; if($from === $to) { $result->result = $result->amount; } else { - $convertCurrency = $pdo->prepare('SELECT (SELECT (:amount / `rate_value`) FROM `exchange-rates` WHERE `rate_from` = \'' . EXRATE_INTER . '\' AND `rate_to` = :from) * `rate_value` FROM `exchange-rates` WHERE `rate_from` = \'' . EXRATE_INTER . '\' AND `rate_to` = :to;'); - $convertCurrency->bindValue('from', $from); - $convertCurrency->bindValue('amount', $amount); + $convertCurrency = $db->prepare(sprintf( + 'SELECT (SELECT (? / rate_value) FROM `exchange-rates` WHERE rate_from = "%1$s" AND rate_to = ?) * rate_value FROM `exchange-rates` WHERE rate_from = "%1$s" AND rate_to = ?', + EXRATE_INTER + )); if(empty($to)) { $result->results = []; foreach(EXRATE_COMMON as $commonCurrency) { if($commonCurrency === $from) continue; + $result->results[] = $current = new stdClass; $current->to = $commonCurrency; - $convertCurrency->bindValue('to', $commonCurrency); + + $convertCurrency->reset(); + $convertCurrency->addParameter(1, $amount); + $convertCurrency->addParameter(2, $from); + $convertCurrency->addParameter(3, $commonCurrency); $convertCurrency->execute(); - $current->result = $convertCurrency->fetchColumn() ?? 0; + + $convertResult = $convertCurrency->getResult(); + $convertResult->next(); + + $current->result = $convertResult->getFloat(0); } } else { - $convertCurrency->bindValue('to', $to); + $convertCurrency->addParameter(1, $amount); + $convertCurrency->addParameter(2, $from); + $convertCurrency->addParameter(3, $to); $convertCurrency->execute(); - $result->result = $convertCurrency->fetchColumn() ?? 0; + + $convertResult = $convertCurrency->getResult(); + $convertResult->next(); + + $result->result = $convertResult->getFloat(0); } } diff --git a/public/get-profile-field.php b/public/get-profile-field.php index edca303..f9be8cc 100644 --- a/public/get-profile-field.php +++ b/public/get-profile-field.php @@ -5,16 +5,15 @@ $userId = (int)filter_input(INPUT_GET, 'user', FILTER_SANITIZE_NUMBER_INT); $fieldId = (int)filter_input(INPUT_GET, 'field', FILTER_SANITIZE_NUMBER_INT); try { - $fetch = $db->prepare('SELECT `field_value` FROM `msz_profile_fields_values` WHERE `field_id` = :field AND `user_id` = :user'); - $fetch->bindValue('user', $userId); - $fetch->bindValue('field', $fieldId); + $fetch = $db->prepare('SELECT `field_value` FROM `msz_profile_fields_values` WHERE `field_id` = ? AND `user_id` = ?'); + $fetch->addParameter(1, $fieldId); + $fetch->addParameter(2, $userId); $fetch->execute(); - $data = $fetch->fetchObject(); - if($data) - echo json_encode($data); - else { - echo '{"error":105}'; - } -} catch(PDOException $ex) { - echo '{"error":104}'; + $result = $fetch->getResult(); + + if($result->next()) + echo json_encode(['field_value' => $result->getString(0)]); + else echo '{"error":105}'; +} catch(Exception $ex) { + echo json_encode(['error' => 104, 'msg' => $ex->getMessage()]); } diff --git a/public/get-user-id.php b/public/get-user-id.php deleted file mode 100644 index 9447be5..0000000 --- a/public/get-user-id.php +++ /dev/null @@ -1,52 +0,0 @@ - PDO::CASE_NATURAL, - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, - PDO::ATTR_STRINGIFY_FETCHES => false, - PDO::ATTR_EMULATE_PREPARES => false, - PDO::MYSQL_ATTR_INIT_COMMAND => " - SET SESSION - sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION', - time_zone = '+00:00'; - " - ]); -} catch(PDOException $ex) { - die('-3'); -} - -$userId = $flashii->prepare('SELECT `user_id` FROM `msz_users` WHERE LOWER(`username`) = :username OR LOWER(`email`) = :email'); -$userId->bindValue('username', $name); -$userId->bindValue('email', $name); -$userId->execute(); - -echo (int)$userId->fetchColumn(); diff --git a/public/get-user-names.php b/public/get-user-names.php deleted file mode 100644 index ca93b90..0000000 --- a/public/get-user-names.php +++ /dev/null @@ -1,65 +0,0 @@ - 100) - die('-6:too many'); - -foreach($ids as $k => $id) { - $_id = intval($id); - if($id != $_id) - die('-4:format'); - $ids[$k] = $_id; -} - -$config = parse_ini_file($config['msz-config-path'], true, INI_SCANNER_TYPED); -if(empty($config)) - die('-1:config gone'); - -$info = $config['Database']; -if(empty($config)) - die('-2:config gone'); - -$dsn = 'mysql:'; - -if ($info['unix_socket'] ?? false) { - $dsn .= 'unix_socket=' . $info['unix_socket'] . ';'; -} else { - $dsn .= 'host=' . ($info['host'] ?? '127.0.0.1') . ';'; - $dsn .= 'port=' . intval($info['port'] ?? 3306) . ';'; -} - -$dsn .= 'charset=' . ($info['charset'] ?? 'utf8mb4') . ';'; -$dsn .= 'dbname=' . ($info['database'] ?? 'misuzu') . ';'; - -try { - $flashii = new PDO($dsn, ($info['username'] ?? null), ($info['password'] ?? null), [ - PDO::ATTR_CASE => PDO::CASE_NATURAL, - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, - PDO::ATTR_STRINGIFY_FETCHES => false, - PDO::ATTR_EMULATE_PREPARES => false, - PDO::MYSQL_ATTR_INIT_COMMAND => " - SET SESSION - sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION', - time_zone = '+00:00'; - " - ]); -} catch(PDOException $ex) { - die('-5:db gone'); -} - -$rows = $flashii->query('SELECT `user_id`, `username` FROM `msz_users` WHERE `user_id` IN (' . implode(',', $ids) . ')')->fetchAll(PDO::FETCH_ASSOC); -$out = ''; - -foreach($rows as $row) - $out .= "{$row['user_id']}:{$row['username']};"; - -echo substr($out, 0, -1); diff --git a/public/markov-shit.php b/public/markov-shit.php index 92e63d5..1818e57 100644 --- a/public/markov-shit.php +++ b/public/markov-shit.php @@ -9,429 +9,469 @@ $separator = "\r\n\r\nHOjGbeCdZHrVVFz3lBD0cIMGw2hPmkw4\r\n\r\n";

msz_changelog_changes -> change_log

msz_changelog_changes -> change_text

msz_changelog_tags -> tag_name

msz_changelog_tags -> tag_description

msz_comments_posts -> comment_text

msz_forum_categories -> forum_name

msz_forum_categories -> forum_description

msz_forum_posts -> post_text

msz_forum_topics -> topic_title

msz_news_categories -> category_name

msz_news_categories -> category_description

msz_news_posts -> post_title

msz_news_posts -> post_text

msz_roles -> role_name

msz_roles -> role_title

msz_roles -> role_description

msz_users -> username

msz_users -> user_about_content

msz_users -> user_signature_content

msz_users -> user_title

msz_profile_fields_values -> field_value -> 1

msz_profile_fields_values -> field_value -> 2

msz_profile_fields_values -> field_value -> 3

msz_profile_fields_values -> field_value -> 4

msz_profile_fields_values -> field_value -> 5

msz_profile_fields_values -> field_value -> 6

msz_profile_fields_values -> field_value -> 7

msz_profile_fields_values -> field_value -> 8

msz_profile_fields_values -> field_value -> 9

msz_profile_fields_values -> field_value -> 10

msz_profile_fields_values -> field_value -> 11

msz_profile_fields_values -> field_value -> 12

msz_profile_fields_values -> field_value -> 13

msz_profile_fields_values -> field_value -> 14

msz_profile_fields_values -> field_value -> 15

msz_profile_fields_values -> field_value -> 16

msz_profile_fields_values -> field_value -> 17

msz_profile_fields_values -> field_value -> 18

msz_profile_fields_values -> field_value -> 19

diff --git a/public/recent-forum-posts.php b/public/recent-forum-posts.php index 944062a..3a1baab 100644 --- a/public/recent-forum-posts.php +++ b/public/recent-forum-posts.php @@ -25,18 +25,32 @@ try { ON t.`topic_id` = p.`topic_id` LEFT JOIN `msz_forum_categories` AS f ON f.`forum_id` = p.`forum_id` - WHERE `post_id` > :post_id + WHERE `post_id` > ? AND `post_deleted` IS NULL AND `post_created` > NOW() - INTERVAL 7 DAY AND p.`forum_id` IN (2, 7, 24, 6, 5, 4, 16, 20, 8, 19, 10, 11, 13, 21, 15, 14, 27, 29, 28) ORDER BY `post_id` LIMIT 6 '); - $fetch->bindValue('post_id', $startId); - if($fetch->execute()) - echo json_encode($fetch->fetchAll(PDO::FETCH_ASSOC)); - else - echo '[]'; -} catch(PDOException $ex) { + $fetch->addParameter(1, $startId); + $fetch->execute(); + $result = $fetch->getResult(); + + $sets = []; + while($result->next()) + $sets[] = [ + 'post_id' => $result->getInteger(0), + 'topic_id' => $result->getInteger(1), + 'topic_title' => $result->getString(2), + 'forum_id' => $result->getInteger(3), + 'forum_name' => $result->getString(4), + 'user_id' => $result->getInteger(5), + 'username' => $result->getString(6), + 'user_colour' => $result->getInteger(7), + 'is_opening_post' => $result->getInteger(8), + ]; + + echo json_encode($sets); +} catch(Exception $ex) { echo '{"error":104}'; } diff --git a/public/recent-registrations.php b/public/recent-registrations.php index a3216bb..ccc8e07 100644 --- a/public/recent-registrations.php +++ b/public/recent-registrations.php @@ -7,16 +7,23 @@ try { $fetch = $db->prepare(' SELECT `user_id`, `username` FROM `msz_users` - WHERE `user_id` > :user_id + WHERE `user_id` > ? AND `user_created` > NOW() - INTERVAL 7 DAY ORDER BY `user_id` LIMIT 10 '); - $fetch->bindValue('user_id', $startId); - if($fetch->execute()) - echo json_encode($fetch->fetchAll(PDO::FETCH_ASSOC)); - else - echo '[]'; -} catch(PDOException $ex) { - echo '{"error":104}'; + $fetch->addParameter(1, $startId); + $fetch->execute(); + $result = $fetch->getResult(); + + $sets = []; + while($result->next()) + $sets[] = [ + 'user_id' => $result->getInteger(0), + 'username' => $result->getString(1), + ]; + + echo json_encode($sets); +} catch(Exception $ex) { + echo json_encode(['error' => 104, 'msg' => $ex->getMessage()]); }