type signatures a la 7.1
This commit is contained in:
parent
5607ef7c55
commit
3b60cf457e
76 changed files with 407 additions and 462 deletions
|
@ -19,7 +19,7 @@ class ActionCode
|
|||
* @param int $user
|
||||
* @return string
|
||||
*/
|
||||
public static function generate($action, $user = 0)
|
||||
public static function generate(string $action, int $user = 0): string
|
||||
{
|
||||
// Generate a code
|
||||
$code = uniqid();
|
||||
|
@ -44,7 +44,7 @@ class ActionCode
|
|||
* @param bool $invalidate
|
||||
* @return bool
|
||||
*/
|
||||
public static function validate($action, $code, $user = 0, $invalidate = true)
|
||||
public static function validate(string $action, string $code, int $user = 0, bool $invalidate = true): bool
|
||||
{
|
||||
// Fetch the code from the db
|
||||
$get = DB::table('actioncodes')
|
||||
|
@ -66,7 +66,7 @@ class ActionCode
|
|||
* Make a code invalid.
|
||||
* @param string $code
|
||||
*/
|
||||
public static function invalidate($code)
|
||||
public static function invalidate(string $code): void
|
||||
{
|
||||
DB::table('actioncodes')
|
||||
->where('action_code', $code)
|
||||
|
|
|
@ -58,15 +58,14 @@ class Parser
|
|||
/**
|
||||
* Parse the emoticons.
|
||||
* @param string $text
|
||||
* @param User $poster
|
||||
* @return string
|
||||
*/
|
||||
public static function parseEmoticons($text, User $poster = null)
|
||||
public static function parseEmoticons(string $text, User $poster = null): string
|
||||
{
|
||||
// Get emoticons from the database
|
||||
$emotes = DB::table('emoticons')
|
||||
->get();
|
||||
|
||||
// Parse all emoticons
|
||||
foreach ($emotes as $emote) {
|
||||
if ($poster === null) {
|
||||
// eventually check for hierarchies here
|
||||
|
@ -78,16 +77,16 @@ class Parser
|
|||
$text = preg_replace("#{$icon}#", $image, $text);
|
||||
}
|
||||
|
||||
// Return the parsed text
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the parsed text to HTML.
|
||||
* @param string $text
|
||||
* @param User $poster
|
||||
* @return string
|
||||
*/
|
||||
public static function toHTML($text, User $poster)
|
||||
public static function toHTML(string $text, User $poster): string
|
||||
{
|
||||
$text = self::parseEmoticons($text);
|
||||
|
||||
|
|
|
@ -30,9 +30,10 @@ class TagBase
|
|||
/**
|
||||
* Parses the bbcode.
|
||||
* @param string $text
|
||||
* @param User $poster
|
||||
* @return string
|
||||
*/
|
||||
public static function parse($text, User $poster)
|
||||
public static function parse(string $text, User $poster): string
|
||||
{
|
||||
return preg_replace(static::$pattern, static::$replace, $text);
|
||||
}
|
||||
|
|
|
@ -19,9 +19,10 @@ class Align extends TagBase
|
|||
/**
|
||||
* Parses the bbcode.
|
||||
* @param string $text
|
||||
* @param User $poster
|
||||
* @return string
|
||||
*/
|
||||
public static function parse($text, User $poster)
|
||||
public static function parse(string $text, User $poster): string
|
||||
{
|
||||
return preg_replace_callback(
|
||||
'/\[align\=(left|center|centre|right)\](.*?)\[\/align\]/s',
|
||||
|
|
|
@ -19,9 +19,10 @@ class Box extends TagBase
|
|||
/**
|
||||
* Parses the bbcode.
|
||||
* @param string $text
|
||||
* @param User $poster
|
||||
* @return string
|
||||
*/
|
||||
public static function parse($text, User $poster)
|
||||
public static function parse(string $text, User $poster): string
|
||||
{
|
||||
return preg_replace_callback(
|
||||
'/\[box(?:\=(.*?))?\](.*?)\[\/box\]/s',
|
||||
|
|
|
@ -19,9 +19,10 @@ class Code extends TagBase
|
|||
/**
|
||||
* Parses the bbcode.
|
||||
* @param string $text
|
||||
* @param User $poster
|
||||
* @return string
|
||||
*/
|
||||
public static function parse($text, User $poster)
|
||||
public static function parse(string $text, User $poster): string
|
||||
{
|
||||
return preg_replace_callback(
|
||||
'/\[code(?:\=([a-z]+))?\](.*?)\[\/code\]/s',
|
||||
|
|
|
@ -19,9 +19,10 @@ class ListTag extends TagBase
|
|||
/**
|
||||
* Parses the bbcode.
|
||||
* @param string $text
|
||||
* @param User $poster
|
||||
* @return string
|
||||
*/
|
||||
public static function parse($text, User $poster)
|
||||
public static function parse(string $text, User $poster): string
|
||||
{
|
||||
return preg_replace_callback(
|
||||
'/\[list(?:\=(1|A|a|I|i))?\](.*?)\[\/list\]/s',
|
||||
|
|
|
@ -26,9 +26,10 @@ class Markdown extends TagBase
|
|||
/**
|
||||
* Parses the bbcode.
|
||||
* @param string $text
|
||||
* @param User $poster
|
||||
* @return string
|
||||
*/
|
||||
public static function parse($text, User $poster)
|
||||
public static function parse(string $text, User $poster): string
|
||||
{
|
||||
return preg_replace_callback(
|
||||
'/\[md\](.*?)\[\/md\]/s',
|
||||
|
|
|
@ -21,9 +21,10 @@ class NamedQuote extends TagBase
|
|||
/**
|
||||
* Parses the bbcode.
|
||||
* @param string $text
|
||||
* @param User $poster
|
||||
* @return string
|
||||
*/
|
||||
public static function parse($text, User $poster)
|
||||
public static function parse(string $text, User $poster): string
|
||||
{
|
||||
return preg_replace_callback(
|
||||
'/\[quote\=(#?)(.*?)\](.*)\[\/quote\]/s',
|
||||
|
|
|
@ -43,9 +43,10 @@ class Size extends TagBase
|
|||
/**
|
||||
* Parses the bbcode.
|
||||
* @param string $text
|
||||
* @param User $poster
|
||||
* @return string
|
||||
*/
|
||||
public static function parse($text, User $poster)
|
||||
public static function parse(string $text, User $poster): string
|
||||
{
|
||||
return preg_replace_callback(
|
||||
'/\[size\=([a-z0-9]+)\](.*?)\[\/size\]/s',
|
||||
|
|
|
@ -19,9 +19,10 @@ class UserTag extends TagBase
|
|||
/**
|
||||
* Parses the bbcode.
|
||||
* @param string $text
|
||||
* @param User $poster
|
||||
* @return string
|
||||
*/
|
||||
public static function parse($text, User $poster)
|
||||
public static function parse(string $text, User $poster): string
|
||||
{
|
||||
return preg_replace_callback(
|
||||
'/\[user\]([0-9]+)\[\/user\]/s',
|
||||
|
|
|
@ -248,7 +248,7 @@ class Settings
|
|||
/**
|
||||
* Applies settings based on Sakura's configuration.
|
||||
*/
|
||||
public function loadStandard()
|
||||
public function loadStandard(): void
|
||||
{
|
||||
$this->protocol = config('chat.protocol');
|
||||
$this->server = config('chat.server');
|
||||
|
@ -278,7 +278,7 @@ class Settings
|
|||
* @param int $hierarchy
|
||||
* @param bool $relativePath
|
||||
*/
|
||||
public function addEmoticon($triggers, $image, $hierarchy = 0, $relativePath = false)
|
||||
public function addEmoticon(array $triggers, string $image, int $hierarchy = 0, bool $relativePath = false): void
|
||||
{
|
||||
$this->emoticons[] = [
|
||||
'Text' => $triggers,
|
||||
|
|
|
@ -25,7 +25,7 @@ class URLResolver
|
|||
* @param string $hash
|
||||
* @return LinkInfo
|
||||
*/
|
||||
public static function resolve($protocol, $slashes, $authority, $host, $port, $path, $query, $hash)
|
||||
public static function resolve(string $protocol, string $slashes, string $authority, string $host, string $port, string $path, string $query, string $hash): LinkInfo
|
||||
{
|
||||
$url = "{$protocol}:{$slashes}{$authority}{$host}{$port}{$path}{$query}{$hash}";
|
||||
$info = new LinkInfo;
|
||||
|
|
|
@ -77,7 +77,7 @@ class Comment
|
|||
* Constructor.
|
||||
* @var int $id
|
||||
*/
|
||||
public function __construct($id = 0)
|
||||
public function __construct(int $id = 0)
|
||||
{
|
||||
// Get comment data from the database
|
||||
$data = DB::table('comments')
|
||||
|
@ -100,7 +100,7 @@ class Comment
|
|||
/**
|
||||
* Saving changes made to this comment.
|
||||
*/
|
||||
public function save()
|
||||
public function save(): void
|
||||
{
|
||||
// Create submission data, insert and update take the same format
|
||||
$data = [
|
||||
|
@ -125,7 +125,7 @@ class Comment
|
|||
/**
|
||||
* Delete this comment.
|
||||
*/
|
||||
public function delete()
|
||||
public function delete(): void
|
||||
{
|
||||
foreach ($this->replies() as $reply) {
|
||||
$reply->delete();
|
||||
|
@ -141,7 +141,7 @@ class Comment
|
|||
/**
|
||||
* Gets and caches the upvotes.
|
||||
*/
|
||||
private function getVotes()
|
||||
private function getVotes(): void
|
||||
{
|
||||
$this->upvotes = intval(DB::table('comment_votes')
|
||||
->where('vote_comment', $this->id)
|
||||
|
@ -157,7 +157,7 @@ class Comment
|
|||
* Gets the parsed comment text
|
||||
* @return string
|
||||
*/
|
||||
public function parsed()
|
||||
public function parsed(): string
|
||||
{
|
||||
if (!$this->parsedCache) {
|
||||
$this->parsedCache = BBCode\Parser::parseEmoticons(clean_string($this->text));
|
||||
|
@ -170,7 +170,7 @@ class Comment
|
|||
* Get the replies to this comment.
|
||||
* @return array
|
||||
*/
|
||||
public function replies()
|
||||
public function replies(): array
|
||||
{
|
||||
if (!$this->replyCache) {
|
||||
$commentIds = DB::table('comments')
|
||||
|
@ -191,7 +191,7 @@ class Comment
|
|||
* Gets the user object of the poster.
|
||||
* @return User
|
||||
*/
|
||||
public function userData()
|
||||
public function userData(): User
|
||||
{
|
||||
return User::construct($this->user);
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ class Comment
|
|||
* @param int $user
|
||||
* @param bool $vote
|
||||
*/
|
||||
public function vote($user, $vote)
|
||||
public function vote(int $user, bool $vote): void
|
||||
{
|
||||
$vote = $vote ? '1' : '0';
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ class Config
|
|||
* @throws ConfigParseException
|
||||
* @param string $path
|
||||
*/
|
||||
public static function load($path)
|
||||
public static function load(string $path): void
|
||||
{
|
||||
// Check if the configuration file exists
|
||||
if (!file_exists($path)) {
|
||||
|
@ -53,7 +53,7 @@ class Config
|
|||
* @throws ConfigValueNotFoundException
|
||||
* @return array|string
|
||||
*/
|
||||
public static function get($section, $key = null)
|
||||
public static function get(string $section, string $key = null)
|
||||
{
|
||||
// Check if the key that we're looking for exists
|
||||
if (array_key_exists($section, self::$config)) {
|
||||
|
|
|
@ -6,22 +6,24 @@
|
|||
|
||||
namespace Sakura\Console;
|
||||
|
||||
use CLIFramework\Application as CLIApp;
|
||||
|
||||
/**
|
||||
* Command line interface main.
|
||||
* @package Sakura
|
||||
* @author Julian van de Groep <me@flash.moe>
|
||||
*/
|
||||
class Application extends \CLIFramework\Application
|
||||
class Application extends CLIApp
|
||||
{
|
||||
/**
|
||||
* CLI Application name.
|
||||
*/
|
||||
const NAME = 'Sakura';
|
||||
public const NAME = 'Sakura';
|
||||
|
||||
/**
|
||||
* CLI Application version.
|
||||
*/
|
||||
const VERSION = 9001;
|
||||
public const VERSION = 9001;
|
||||
|
||||
/**
|
||||
* Enable command autoloading.
|
||||
|
|
|
@ -22,7 +22,7 @@ class DatabaseInstallCommand extends Command
|
|||
* A quick description of this command.
|
||||
* @return string.
|
||||
*/
|
||||
public function brief()
|
||||
public function brief(): string
|
||||
{
|
||||
return 'Create the migration repository';
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class DatabaseInstallCommand extends Command
|
|||
/**
|
||||
* Does the repository installing.
|
||||
*/
|
||||
public function execute()
|
||||
public function execute(): void
|
||||
{
|
||||
$repository = DB::getMigrationRepository();
|
||||
$migrator = new Migrator($repository, $repository->getConnectionResolver(), new Filesystem);
|
||||
|
|
|
@ -21,13 +21,13 @@ class DatabaseMigrateCommand extends Command
|
|||
/**
|
||||
* The database migrations directory.
|
||||
*/
|
||||
const MIGRATIONS = "database/";
|
||||
private const MIGRATIONS = "database/";
|
||||
|
||||
/**
|
||||
* A quick description of this command.
|
||||
* @return string.
|
||||
*/
|
||||
public function brief()
|
||||
public function brief(): string
|
||||
{
|
||||
return 'Run the database migrations';
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class DatabaseMigrateCommand extends Command
|
|||
/**
|
||||
* Does the migrating.
|
||||
*/
|
||||
public function execute()
|
||||
public function execute(): void
|
||||
{
|
||||
$repository = DB::getMigrationRepository();
|
||||
$migrator = new Migrator($repository, $repository->getConnectionResolver(), new Filesystem);
|
||||
|
|
|
@ -22,7 +22,7 @@ class DatabaseResetCommand extends Command
|
|||
* A quick description of this command.
|
||||
* @return string.
|
||||
*/
|
||||
public function brief()
|
||||
public function brief(): string
|
||||
{
|
||||
return 'Rollback all database migrations';
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class DatabaseResetCommand extends Command
|
|||
/**
|
||||
* Does the resetting.
|
||||
*/
|
||||
public function execute()
|
||||
public function execute(): void
|
||||
{
|
||||
$repository = DB::getMigrationRepository();
|
||||
$migrator = new Migrator($repository, $repository->getConnectionResolver(), new Filesystem);
|
||||
|
|
|
@ -22,7 +22,7 @@ class DatabaseRollbackCommand extends Command
|
|||
* A quick description of this command.
|
||||
* @return string.
|
||||
*/
|
||||
public function brief()
|
||||
public function brief(): string
|
||||
{
|
||||
return 'Rollback the last database migration';
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class DatabaseRollbackCommand extends Command
|
|||
/**
|
||||
* Does the rolling back.
|
||||
*/
|
||||
public function execute()
|
||||
public function execute(): void
|
||||
{
|
||||
$repository = DB::getMigrationRepository();
|
||||
$migrator = new Migrator($repository, $repository->getConnectionResolver(), new Filesystem);
|
||||
|
|
|
@ -22,13 +22,13 @@ class DatabaseStatusCommand extends Command
|
|||
/**
|
||||
* The database migrations directory.
|
||||
*/
|
||||
const MIGRATIONS = "database/";
|
||||
private const MIGRATIONS = "database/";
|
||||
|
||||
/**
|
||||
* A quick description of this command.
|
||||
* @return string.
|
||||
*/
|
||||
public function brief()
|
||||
public function brief(): string
|
||||
{
|
||||
return 'Show the status of each migration';
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ class DatabaseStatusCommand extends Command
|
|||
/**
|
||||
* Fulfills the purpose of what is described above this class.
|
||||
*/
|
||||
public function execute()
|
||||
public function execute(): void
|
||||
{
|
||||
$repository = DB::getMigrationRepository();
|
||||
$migrator = new Migrator($repository, $repository->getConnectionResolver(), new Filesystem);
|
||||
|
|
|
@ -21,7 +21,7 @@ class PremiumPurgeCommand extends Command
|
|||
* A quick description of this command.
|
||||
* @return string.
|
||||
*/
|
||||
public function brief()
|
||||
public function brief(): string
|
||||
{
|
||||
return 'Purge expired premium.';
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ class PremiumPurgeCommand extends Command
|
|||
/**
|
||||
* Purge expired premium subs.
|
||||
*/
|
||||
public function execute()
|
||||
public function execute(): void
|
||||
{
|
||||
$expiredPremium = DB::table('premium')
|
||||
->where('premium_expire', '<', time())
|
||||
|
|
|
@ -21,7 +21,7 @@ class RebuildForumCacheCommand extends Command
|
|||
* A quick description of this command.
|
||||
* @return string.
|
||||
*/
|
||||
public function brief()
|
||||
public function brief(): string
|
||||
{
|
||||
return 'Rebuild the forum bbcode cache';
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ class RebuildForumCacheCommand extends Command
|
|||
/**
|
||||
* Does the repository installing.
|
||||
*/
|
||||
public function execute()
|
||||
public function execute(): void
|
||||
{
|
||||
$this->getLogger()->writeln("This might take a while...");
|
||||
$posts = DB::table('posts')->get(['post_id']);
|
||||
|
|
|
@ -19,7 +19,7 @@ class ServeCommand extends Command
|
|||
* A quick description of this command.
|
||||
* @return string.
|
||||
*/
|
||||
public function brief()
|
||||
public function brief(): string
|
||||
{
|
||||
return 'Sets up a local development server.';
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ class ServeCommand extends Command
|
|||
/**
|
||||
* Sends the php serve command via the exec command.
|
||||
*/
|
||||
public function execute()
|
||||
public function execute(): void
|
||||
{
|
||||
$document_root = addslashes(path('public'));
|
||||
$router_proxy = addslashes(path('server.php'));
|
||||
|
|
|
@ -20,7 +20,7 @@ class SessionPurgeCommand extends Command
|
|||
* A quick description of this command.
|
||||
* @return string.
|
||||
*/
|
||||
public function brief()
|
||||
public function brief(): string
|
||||
{
|
||||
return 'Purge expired sessions.';
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class SessionPurgeCommand extends Command
|
|||
/**
|
||||
* Purges sessions.
|
||||
*/
|
||||
public function execute()
|
||||
public function execute(): void
|
||||
{
|
||||
DB::table('sessions')
|
||||
->where('session_expire', '<', time())
|
||||
|
|
|
@ -22,7 +22,7 @@ class SetupCommand extends Command
|
|||
* A quick description of this command.
|
||||
* @return string.
|
||||
*/
|
||||
public function brief()
|
||||
public function brief(): string
|
||||
{
|
||||
return 'Adds the required data to the tables, only needed once after the initial migration.';
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class SetupCommand extends Command
|
|||
/**
|
||||
* Adds data to the database required to get everything running.
|
||||
*/
|
||||
public function execute()
|
||||
public function execute(): void
|
||||
{
|
||||
// Check if the users table has user with id 1
|
||||
$userCheck = DB::table('users')->where('user_id', 1)->count();
|
||||
|
|
|
@ -22,10 +22,10 @@ class AuthController extends Controller
|
|||
{
|
||||
/**
|
||||
* Touch the login rate limit.
|
||||
* @param $user int The ID of the user that attempted to log in.
|
||||
* @param $sucess bool Whether the login attempt was successful.
|
||||
* @param int $user The ID of the user that attempted to log in.
|
||||
* @param bool $success Whether the login attempt was successful.
|
||||
*/
|
||||
protected function touchRateLimit($user, $success = false)
|
||||
protected function touchRateLimit(int $user, bool $success = false): void
|
||||
{
|
||||
DB::table('login_attempts')
|
||||
->insert([
|
||||
|
@ -40,7 +40,7 @@ class AuthController extends Controller
|
|||
* End the current session.
|
||||
* @return string
|
||||
*/
|
||||
public function logout()
|
||||
public function logout(): string
|
||||
{
|
||||
if (!session_check()) {
|
||||
return view('auth/logout');
|
||||
|
@ -50,14 +50,14 @@ class AuthController extends Controller
|
|||
CurrentSession::stop();
|
||||
|
||||
// Return true indicating a successful logout
|
||||
redirect(route('auth.login'));
|
||||
return redirect(route('auth.login'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Login page.
|
||||
* @return string
|
||||
*/
|
||||
public function login()
|
||||
public function login(): string
|
||||
{
|
||||
if (!session_check()) {
|
||||
return view('auth/login');
|
||||
|
@ -151,7 +151,7 @@ class AuthController extends Controller
|
|||
* Do a registration attempt.
|
||||
* @return string
|
||||
*/
|
||||
public function register()
|
||||
public function register(): string
|
||||
{
|
||||
// Preliminarily set registration to failed
|
||||
$redirect = route('auth.register');
|
||||
|
@ -264,7 +264,7 @@ class AuthController extends Controller
|
|||
* Do a activation attempt.
|
||||
* @return string
|
||||
*/
|
||||
public function activate()
|
||||
public function activate(): string
|
||||
{
|
||||
// Preliminarily set activation to failed
|
||||
$redirect = route('main.index');
|
||||
|
@ -314,7 +314,7 @@ class AuthController extends Controller
|
|||
* Do a reactivation preparation attempt.
|
||||
* @return string
|
||||
*/
|
||||
public function reactivate()
|
||||
public function reactivate(): string
|
||||
{
|
||||
// Validate session
|
||||
if (!session_check()) {
|
||||
|
@ -361,7 +361,7 @@ class AuthController extends Controller
|
|||
* Do a password reset attempt.
|
||||
* @return string
|
||||
*/
|
||||
public function resetPassword()
|
||||
public function resetPassword(): string
|
||||
{
|
||||
// Validate session
|
||||
if (!session_check()) {
|
||||
|
@ -427,7 +427,7 @@ class AuthController extends Controller
|
|||
* Send the activation e-mail
|
||||
* @param User $user
|
||||
*/
|
||||
private function sendActivationMail($user)
|
||||
private function sendActivationMail(User $user): void
|
||||
{
|
||||
// Generate activation key
|
||||
$activate = ActionCode::generate('ACTIVATE', $user->id);
|
||||
|
@ -461,7 +461,7 @@ class AuthController extends Controller
|
|||
* Send the activation e-mail
|
||||
* @param User $user
|
||||
*/
|
||||
private function sendPasswordMail($user)
|
||||
private function sendPasswordMail(User $user): void
|
||||
{
|
||||
// Generate the verification key
|
||||
$verk = ActionCode::generate('LOST_PASS', $user->id);
|
||||
|
|
|
@ -31,16 +31,16 @@ class ChatController extends Controller
|
|||
/**
|
||||
* Redirects the user to the chat client.
|
||||
*/
|
||||
public function redirect()
|
||||
public function redirect(): string
|
||||
{
|
||||
redirect(config('chat.webclient'));
|
||||
return redirect(config('chat.webclient'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Serves the settings for a Sakurako chat.
|
||||
* @return string
|
||||
*/
|
||||
public function settings()
|
||||
public function settings(): string
|
||||
{
|
||||
$settings = new Settings;
|
||||
$settings->loadStandard();
|
||||
|
@ -59,7 +59,7 @@ class ChatController extends Controller
|
|||
* Resolves urls.
|
||||
* @return string
|
||||
*/
|
||||
public function resolve()
|
||||
public function resolve(): string
|
||||
{
|
||||
$data = json_decode(file_get_contents('php://input'));
|
||||
$info = new LinkInfo;
|
||||
|
@ -84,25 +84,25 @@ class ChatController extends Controller
|
|||
* Handles the authentication for a chat server.
|
||||
* @return string
|
||||
*/
|
||||
public function auth()
|
||||
public function auth(): ?string
|
||||
{
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* IRC page.
|
||||
* @return string
|
||||
*/
|
||||
public function irc()
|
||||
public function irc(): ?string
|
||||
{
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy auth, for SockLegacy. Remove when the old chat server finally dies.
|
||||
* @return string
|
||||
*/
|
||||
public function authLegacy()
|
||||
public function authLegacy(): string
|
||||
{
|
||||
$user = User::construct($_GET['arg1'] ?? null);
|
||||
$session = new Session($_GET['arg2'] ?? null);
|
||||
|
|
|
@ -23,7 +23,7 @@ class CommentsController extends Controller
|
|||
* @param int $reply
|
||||
* @return string
|
||||
*/
|
||||
public function post($category = '', $reply = 0)
|
||||
public function post(string $category = '', int $reply = 0): string
|
||||
{
|
||||
// Check if the user can comment
|
||||
if (session_check()) {
|
||||
|
@ -70,7 +70,7 @@ class CommentsController extends Controller
|
|||
* @param int $id
|
||||
* @return string
|
||||
*/
|
||||
public function delete($id = 0)
|
||||
public function delete(int $id = 0): string
|
||||
{
|
||||
// Check if the user can delete comments
|
||||
if (!CurrentSession::$user->perms->commentsDelete) {
|
||||
|
@ -102,7 +102,7 @@ class CommentsController extends Controller
|
|||
* @param int $id
|
||||
* @return string
|
||||
*/
|
||||
public function vote($id = 0)
|
||||
public function vote(int $id = 0): string
|
||||
{
|
||||
$vote = $_REQUEST['vote'] ?? 0;
|
||||
$vote = $vote != 0;
|
||||
|
|
|
@ -47,7 +47,7 @@ class Controller
|
|||
* @param int $operators
|
||||
* @return string
|
||||
*/
|
||||
public function json($object, $operators = null)
|
||||
public function json($object, int $operators = null): string
|
||||
{
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
return json_encode($object, $operators);
|
||||
|
|
|
@ -26,7 +26,7 @@ class FileController extends Controller
|
|||
/**
|
||||
* Possible modes.
|
||||
*/
|
||||
const MODES = [
|
||||
private const MODES = [
|
||||
'avatar',
|
||||
'background',
|
||||
'header',
|
||||
|
@ -39,7 +39,7 @@ class FileController extends Controller
|
|||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
private function serve($data, $mime, $name)
|
||||
private function serve(string $data, string $mime, string $name): string
|
||||
{
|
||||
header("Content-Disposition: inline; filename={$name}");
|
||||
header("Content-Type: {$mime}");
|
||||
|
@ -50,9 +50,10 @@ class FileController extends Controller
|
|||
* Handles file uploads.
|
||||
* @param string $mode
|
||||
* @param array $file
|
||||
* @return array
|
||||
* @param User $user
|
||||
* @throws FileException
|
||||
*/
|
||||
private function upload($mode, $file, $user)
|
||||
private function upload(string $mode, array $file, User $user): void
|
||||
{
|
||||
// Handle errors
|
||||
switch ($file['error']) {
|
||||
|
@ -135,8 +136,9 @@ class FileController extends Controller
|
|||
/**
|
||||
* Deletes a file.
|
||||
* @param string $mode
|
||||
* @param User $user
|
||||
*/
|
||||
public function delete($mode, $user)
|
||||
public function delete(string $mode, User $user): void
|
||||
{
|
||||
$fileId = $user->{$mode};
|
||||
|
||||
|
@ -151,7 +153,7 @@ class FileController extends Controller
|
|||
* @param array $params
|
||||
* @return string
|
||||
*/
|
||||
public function __call($method, $params)
|
||||
public function __call(string $method, array $params): ?string
|
||||
{
|
||||
if (!in_array($method, self::MODES)) {
|
||||
throw new HttpRouteNotFoundException;
|
||||
|
@ -183,7 +185,7 @@ class FileController extends Controller
|
|||
return $this->json(compact('error'));
|
||||
} elseif ($_SERVER['REQUEST_METHOD'] === 'DELETE') {
|
||||
$this->delete($method, $user);
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ class ForumController extends Controller
|
|||
* Renders the forum index
|
||||
* @return string
|
||||
*/
|
||||
public function index()
|
||||
public function index(): string
|
||||
{
|
||||
// Get the most active topics
|
||||
$activeTopicsIds = DB::table('posts')
|
||||
|
@ -109,28 +109,28 @@ class ForumController extends Controller
|
|||
|
||||
/**
|
||||
* Renders a forum.
|
||||
* @param int $id
|
||||
* @throws HttpRouteNotFoundException
|
||||
* @return string
|
||||
*/
|
||||
public function forum($id = 0)
|
||||
public function forum(int $id = 0): string
|
||||
{
|
||||
$forum = new Forum($id);
|
||||
|
||||
// Redirect forum id 0 to the main page
|
||||
if ($forum->id === 0) {
|
||||
redirect(route('forums.index'));
|
||||
return;
|
||||
return redirect(route('forums.index'));
|
||||
}
|
||||
|
||||
// Check if the forum exists
|
||||
if ($forum->id < 0
|
||||
|| !$forum->perms->view) {
|
||||
throw new HttpRouteNotFoundException();
|
||||
throw new HttpRouteNotFoundException;
|
||||
}
|
||||
|
||||
// Check if the forum isn't a link
|
||||
if ($forum->type === 2) {
|
||||
redirect($forum->link);
|
||||
return;
|
||||
return redirect($forum->link);
|
||||
}
|
||||
|
||||
return view('forum/forum', compact('forum'));
|
||||
|
@ -139,12 +139,14 @@ class ForumController extends Controller
|
|||
/**
|
||||
* Marks an entire forum as read.
|
||||
* @param int $id
|
||||
* @throws HttpRouteNotFoundException
|
||||
* @throws HttpMethodNotAllowedException
|
||||
* @return string
|
||||
*/
|
||||
public function markRead($id = 0)
|
||||
public function markRead(int $id = 0): string
|
||||
{
|
||||
if (!session_check('s')) {
|
||||
throw new HttpMethodNotAllowedException();
|
||||
throw new HttpMethodNotAllowedException;
|
||||
}
|
||||
|
||||
$forum = new Forum($id);
|
||||
|
@ -152,11 +154,11 @@ class ForumController extends Controller
|
|||
// Check if the forum exists
|
||||
if ($forum->id < 1
|
||||
|| !$forum->perms->view) {
|
||||
throw new HttpRouteNotFoundException();
|
||||
throw new HttpRouteNotFoundException;
|
||||
}
|
||||
|
||||
$forum->trackUpdateAll(CurrentSession::$user->id);
|
||||
|
||||
redirect(route('forums.forum', $forum->id));
|
||||
return redirect(route('forums.forum', $forum->id));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ class PostController extends Controller
|
|||
* @param int $id
|
||||
* @return string
|
||||
*/
|
||||
public function find($id = 0)
|
||||
public function find(int $id = 0): string
|
||||
{
|
||||
$post = new Post($id);
|
||||
$topic = new Topic($post->topic);
|
||||
|
@ -55,7 +55,7 @@ class PostController extends Controller
|
|||
$topicLink .= "?page={$postAt}";
|
||||
}
|
||||
|
||||
redirect("{$topicLink}#p{$post->id}");
|
||||
return redirect("{$topicLink}#p{$post->id}");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,7 +63,7 @@ class PostController extends Controller
|
|||
* @param int $id
|
||||
* @return string
|
||||
*/
|
||||
public function raw($id = 0)
|
||||
public function raw(int $id = 0): string
|
||||
{
|
||||
$post = new Post($id);
|
||||
$topic = new Topic($post->topic);
|
||||
|
@ -84,7 +84,7 @@ class PostController extends Controller
|
|||
* @param int $id
|
||||
* @return string
|
||||
*/
|
||||
public function edit($id = 0)
|
||||
public function edit(int $id = 0): string
|
||||
{
|
||||
$title = $_POST['title'] ?? null;
|
||||
$text = $_POST['text'] ?? null;
|
||||
|
@ -176,15 +176,15 @@ class PostController extends Controller
|
|||
|
||||
$postLink = route('forums.post', $post->id);
|
||||
|
||||
redirect($postLink);
|
||||
return redirect($postLink);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a post.
|
||||
* @param int $id
|
||||
* @return string
|
||||
* @throws HttpMethodNotAllowedException
|
||||
*/
|
||||
public function delete($id = 0)
|
||||
public function delete(int $id = 0): void
|
||||
{
|
||||
$post = new Post($id);
|
||||
$topic = new Topic($post->topic);
|
||||
|
@ -211,7 +211,7 @@ class PostController extends Controller
|
|||
|
||||
// Check if the forum exists
|
||||
if ($noAccess || $noDelete) {
|
||||
throw new HttpMethodNotAllowedException();
|
||||
throw new HttpMethodNotAllowedException;
|
||||
}
|
||||
|
||||
// Check if the topic only has 1 post
|
||||
|
|
|
@ -26,7 +26,7 @@ class TopicController extends Controller
|
|||
* @throws HttpRouteNotFoundException
|
||||
* @return string
|
||||
*/
|
||||
public function view($id = 0)
|
||||
public function view(int $id = 0): string
|
||||
{
|
||||
$topic = new Topic($id);
|
||||
$forum = new Forum($topic->forum);
|
||||
|
@ -49,7 +49,7 @@ class TopicController extends Controller
|
|||
* @throws HttpRouteNotFoundException
|
||||
* @return array
|
||||
*/
|
||||
private function modBase($id)
|
||||
private function modBase(int $id): array
|
||||
{
|
||||
$topic = new Topic($id);
|
||||
$forum = new Forum($topic->forum);
|
||||
|
@ -69,7 +69,7 @@ class TopicController extends Controller
|
|||
* @throws HttpMethodNotAllowedException
|
||||
* @return string
|
||||
*/
|
||||
public function sticky($id)
|
||||
public function sticky(int $id): string
|
||||
{
|
||||
extract($this->modBase($id));
|
||||
|
||||
|
@ -80,7 +80,7 @@ class TopicController extends Controller
|
|||
$topic->type = $topic->type !== 1 ? 1 : 0;
|
||||
$topic->update();
|
||||
|
||||
redirect(route('forums.topic', $topic->id));
|
||||
return redirect(route('forums.topic', $topic->id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,7 +89,7 @@ class TopicController extends Controller
|
|||
* @throws HttpMethodNotAllowedException
|
||||
* @return string
|
||||
*/
|
||||
public function announce($id)
|
||||
public function announce(int $id): string
|
||||
{
|
||||
extract($this->modBase($id));
|
||||
|
||||
|
@ -100,7 +100,7 @@ class TopicController extends Controller
|
|||
$topic->type = $topic->type !== 2 ? 2 : 0;
|
||||
$topic->update();
|
||||
|
||||
redirect(route('forums.topic', $topic->id));
|
||||
return redirect(route('forums.topic', $topic->id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -109,7 +109,7 @@ class TopicController extends Controller
|
|||
* @throws HttpMethodNotAllowedException
|
||||
* @return string
|
||||
*/
|
||||
public function lock($id)
|
||||
public function lock(int $id): string
|
||||
{
|
||||
extract($this->modBase($id));
|
||||
|
||||
|
@ -120,7 +120,7 @@ class TopicController extends Controller
|
|||
$topic->status = $topic->status !== 1 ? 1 : 0;
|
||||
$topic->update();
|
||||
|
||||
redirect(route('forums.topic', $topic->id));
|
||||
return redirect(route('forums.topic', $topic->id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,7 +129,7 @@ class TopicController extends Controller
|
|||
* @throws HttpMethodNotAllowedException
|
||||
* @return string
|
||||
*/
|
||||
public function delete($id)
|
||||
public function delete(int $id): string
|
||||
{
|
||||
extract($this->modBase($id));
|
||||
|
||||
|
@ -146,7 +146,7 @@ class TopicController extends Controller
|
|||
throw new HttpMethodNotAllowedException;
|
||||
}
|
||||
|
||||
redirect($redirect);
|
||||
return redirect($redirect);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -155,7 +155,7 @@ class TopicController extends Controller
|
|||
* @throws HttpMethodNotAllowedException
|
||||
* @return string
|
||||
*/
|
||||
public function restore($id)
|
||||
public function restore(int $id): string
|
||||
{
|
||||
extract($this->modBase($id));
|
||||
|
||||
|
@ -167,7 +167,7 @@ class TopicController extends Controller
|
|||
$topic->move($topic->oldForum, false);
|
||||
}
|
||||
|
||||
redirect(route('forums.topic', $topic->id));
|
||||
return redirect(route('forums.topic', $topic->id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -176,7 +176,7 @@ class TopicController extends Controller
|
|||
* @throws HttpMethodNotAllowedException
|
||||
* @return string
|
||||
*/
|
||||
public function move($id)
|
||||
public function move(int $id): string
|
||||
{
|
||||
extract($this->modBase($id));
|
||||
$dest_forum = new Forum($_REQUEST['forum_id'] ?? 0);
|
||||
|
@ -189,7 +189,7 @@ class TopicController extends Controller
|
|||
|
||||
$topic->move($dest_forum->id);
|
||||
|
||||
redirect(route('forums.topic', $topic->id));
|
||||
return redirect(route('forums.topic', $topic->id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -197,7 +197,7 @@ class TopicController extends Controller
|
|||
* @param int $id
|
||||
* @return string
|
||||
*/
|
||||
public function reply($id = 0)
|
||||
public function reply(int $id = 0): string
|
||||
{
|
||||
$text = $_POST['text'] ?? null;
|
||||
|
||||
|
@ -272,7 +272,7 @@ class TopicController extends Controller
|
|||
$postLink = route('forums.post', $post->id);
|
||||
|
||||
// Head to the post
|
||||
redirect($postLink);
|
||||
return redirect($postLink);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -280,7 +280,7 @@ class TopicController extends Controller
|
|||
* @param int $id
|
||||
* @return string
|
||||
*/
|
||||
public function create($id = 0)
|
||||
public function create(int $id = 0): string
|
||||
{
|
||||
$title = $_POST['title'] ?? null;
|
||||
$text = $_POST['text'] ?? null;
|
||||
|
@ -360,8 +360,7 @@ class TopicController extends Controller
|
|||
$postLink = route('forums.post', $post->id);
|
||||
|
||||
// Head to the post
|
||||
redirect($postLink);
|
||||
return;
|
||||
return redirect($postLink);
|
||||
}
|
||||
|
||||
return view('forum/topic', compact('forum'));
|
||||
|
|
|
@ -24,7 +24,7 @@ class FriendsController extends Controller
|
|||
* @param string $title
|
||||
* @param string $text
|
||||
*/
|
||||
private function addNotification($friend, $user, $title, $text = "")
|
||||
private function addNotification(User $friend, User $user, string $title, string $text = ""): void
|
||||
{
|
||||
$alert = new Notification;
|
||||
|
||||
|
@ -44,7 +44,7 @@ class FriendsController extends Controller
|
|||
* @param int $id
|
||||
* @return string
|
||||
*/
|
||||
public function add($id = 0)
|
||||
public function add(int $id = 0): string
|
||||
{
|
||||
$user = CurrentSession::$user;
|
||||
|
||||
|
@ -105,7 +105,7 @@ class FriendsController extends Controller
|
|||
* @param int $id
|
||||
* @return string
|
||||
*/
|
||||
public function remove($id = 0)
|
||||
public function remove(int $id = 0): string
|
||||
{
|
||||
$user = CurrentSession::$user;
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ class HelperController extends Controller
|
|||
* Parsed BBcode from a post request.
|
||||
* @return string
|
||||
*/
|
||||
public function bbcodeParse()
|
||||
public function bbcodeParse(): string
|
||||
{
|
||||
return BBParser::toHTML(htmlentities($_POST['text'] ?? ''), CurrentSession::$user);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ class InfoController extends Controller
|
|||
* Renders the terms of service.
|
||||
* @return string
|
||||
*/
|
||||
public function terms()
|
||||
public function terms(): string
|
||||
{
|
||||
return view('info/terms');
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ class InfoController extends Controller
|
|||
* Renders the privacy policy.
|
||||
* @return string
|
||||
*/
|
||||
public function privacy()
|
||||
public function privacy(): string
|
||||
{
|
||||
return view('info/privacy');
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class InfoController extends Controller
|
|||
* Renders the contact page.
|
||||
* @return string
|
||||
*/
|
||||
public function contact()
|
||||
public function contact(): string
|
||||
{
|
||||
$contact = config('contact');
|
||||
|
||||
|
@ -46,7 +46,7 @@ class InfoController extends Controller
|
|||
* Renders the rules page.
|
||||
* @return string
|
||||
*/
|
||||
public function rules()
|
||||
public function rules(): string
|
||||
{
|
||||
return view('info/rules');
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ class InfoController extends Controller
|
|||
* Renders the welcome page.
|
||||
* @return string
|
||||
*/
|
||||
public function welcome()
|
||||
public function welcome(): string
|
||||
{
|
||||
return view('info/welcome');
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class Controller extends BaseController
|
|||
* Generates the navigation.
|
||||
* @return array
|
||||
*/
|
||||
public function navigation()
|
||||
public function navigation(): array
|
||||
{
|
||||
$nav = [];
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class OverviewController extends Controller
|
|||
* Renders the base overview page.
|
||||
* @return string
|
||||
*/
|
||||
public function index()
|
||||
public function index(): string
|
||||
{
|
||||
return view('manage/overview/index');
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class OverviewController extends Controller
|
|||
* Gets the data for the overview page.
|
||||
* @return string
|
||||
*/
|
||||
public function data()
|
||||
public function data(): string
|
||||
{
|
||||
$data = new \stdClass;
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ class MetaController extends Controller
|
|||
* Serves the site index.
|
||||
* @return string
|
||||
*/
|
||||
public function index()
|
||||
public function index(): string
|
||||
{
|
||||
// Get the newest user
|
||||
$newestUserId = DB::table('users')
|
||||
|
@ -85,31 +85,22 @@ class MetaController extends Controller
|
|||
* Displays the FAQ.
|
||||
* @return string
|
||||
*/
|
||||
public function faq()
|
||||
public function faq(): string
|
||||
{
|
||||
// Get faq entries
|
||||
$faq = DB::table('faq')
|
||||
$questions = DB::table('faq')
|
||||
->orderBy('faq_id')
|
||||
->get();
|
||||
|
||||
// Set parse variables
|
||||
Template::vars([
|
||||
'page' => [
|
||||
'title' => 'Frequently Asked Questions',
|
||||
'questions' => $faq,
|
||||
],
|
||||
]);
|
||||
|
||||
// Print page contents
|
||||
return Template::render('meta/faq');
|
||||
return view('meta/faq', compact('questions'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Search page.
|
||||
* @return string
|
||||
*/
|
||||
public function search()
|
||||
public function search(): string
|
||||
{
|
||||
return Template::render('meta/search');
|
||||
return view('meta/search');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,10 @@ class NewsController extends Controller
|
|||
/**
|
||||
* Shows all posts in a specific category.
|
||||
* @param string $category
|
||||
* @throws HttpRouteNotFoundException
|
||||
* @return string
|
||||
*/
|
||||
public function category($category = '')
|
||||
public function category(string $category = ''): string
|
||||
{
|
||||
// Check if the category is set
|
||||
if ($category === '') {
|
||||
|
@ -35,7 +36,7 @@ class NewsController extends Controller
|
|||
$category = new Category($category);
|
||||
|
||||
if (!$category->posts()) {
|
||||
throw new HttpRouteNotFoundException();
|
||||
throw new HttpRouteNotFoundException;
|
||||
}
|
||||
|
||||
return view('news/category', compact('category'));
|
||||
|
@ -44,15 +45,16 @@ class NewsController extends Controller
|
|||
/**
|
||||
* Returns a news post.
|
||||
* @param int $id
|
||||
* @throws HttpRouteNotFoundException
|
||||
* @return string
|
||||
*/
|
||||
public function post($id = 0)
|
||||
public function post(int $id = 0): string
|
||||
{
|
||||
// Create the post object
|
||||
$post = new Post($id);
|
||||
|
||||
if (!$post->id) {
|
||||
throw new HttpRouteNotFoundException();
|
||||
throw new HttpRouteNotFoundException;
|
||||
}
|
||||
|
||||
return view('news/post', compact('post'));
|
||||
|
|
|
@ -20,7 +20,7 @@ class NotificationsController extends Controller
|
|||
* Get the notification JSON object for the currently authenticated user.
|
||||
* @return string
|
||||
*/
|
||||
public function notifications()
|
||||
public function notifications(): string
|
||||
{
|
||||
return $this->json(CurrentSession::$user->notifications());
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ class NotificationsController extends Controller
|
|||
* @param int
|
||||
* @return string
|
||||
*/
|
||||
public function mark($id = 0)
|
||||
public function mark(int $id = 0): string
|
||||
{
|
||||
if (!CurrentSession::$user->activated) {
|
||||
return '0';
|
||||
|
|
|
@ -22,7 +22,7 @@ class PremiumController extends Controller
|
|||
/**
|
||||
* The amount of premium a user received per period.
|
||||
*/
|
||||
const PERIOD_PER_PAYMENT = 2628000;
|
||||
private const PERIOD_PER_PAYMENT = 2628000;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -37,7 +37,7 @@ class PremiumController extends Controller
|
|||
* Returns the premium purchase index.
|
||||
* @return string
|
||||
*/
|
||||
public function index()
|
||||
public function index(): string
|
||||
{
|
||||
$price = config('premium.price_per_month');
|
||||
$amountLimit = config('premium.max_months_at_once');
|
||||
|
@ -48,10 +48,10 @@ class PremiumController extends Controller
|
|||
* Handles a purchase request.
|
||||
* @return string
|
||||
*/
|
||||
public function purchase()
|
||||
public function purchase(): string
|
||||
{
|
||||
// Get values from post
|
||||
$months = isset($_POST['months']) ? $_POST['months'] : 0;
|
||||
$months = $_POST['months'] ?? 0;
|
||||
|
||||
// Check if the session is valid
|
||||
if (!session_check()
|
||||
|
@ -67,8 +67,7 @@ class PremiumController extends Controller
|
|||
// Check months
|
||||
if ($months < 1
|
||||
|| $months > $amountLimit) {
|
||||
redirect(route('premium.error'));
|
||||
return;
|
||||
return redirect(route('premium.error'));
|
||||
}
|
||||
|
||||
$pricePerMonth = config('premium.price_per_month');
|
||||
|
@ -97,26 +96,25 @@ class PremiumController extends Controller
|
|||
|
||||
// Attempt to create a transaction
|
||||
if (!$transaction) {
|
||||
redirect(route('premium.error'));
|
||||
return;
|
||||
return redirect(route('premium.error'));
|
||||
}
|
||||
|
||||
// Store the amount of months in the global session array
|
||||
$_SESSION['premiumMonths'] = (int) $months;
|
||||
|
||||
redirect($transaction);
|
||||
return redirect($transaction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the data returned by PayPal.
|
||||
* @return string
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): string
|
||||
{
|
||||
$success = isset($_GET['success']);
|
||||
$payment = isset($_GET['paymentId']) ? $_GET['paymentId'] : null;
|
||||
$payer = isset($_GET['PayerID']) ? $_GET['PayerID'] : null;
|
||||
$months = isset($_SESSION['premiumMonths']) ? $_SESSION['premiumMonths'] : null;
|
||||
$payment = $_GET['paymentId'] ?? null;
|
||||
$payer = $_GET['PayerID'] ?? null;
|
||||
$months = $_SESSION['premiumMonths'] ?? null;
|
||||
|
||||
$successRoute = route('premium.complete');
|
||||
$failRoute = route('premium.error');
|
||||
|
@ -125,8 +123,7 @@ class PremiumController extends Controller
|
|||
|| !$payment
|
||||
|| !$payer
|
||||
|| !$months) {
|
||||
redirect($failRoute);
|
||||
return;
|
||||
return redirect($failRoute);
|
||||
}
|
||||
|
||||
// Attempt to complete the transaction
|
||||
|
@ -137,20 +134,19 @@ class PremiumController extends Controller
|
|||
}
|
||||
|
||||
if (!$finalise) {
|
||||
redirect($failRoute);
|
||||
return;
|
||||
return redirect($failRoute);
|
||||
}
|
||||
|
||||
CurrentSession::$user->addPremium(self::PERIOD_PER_PAYMENT * $months);
|
||||
|
||||
redirect($successRoute);
|
||||
return redirect($successRoute);
|
||||
}
|
||||
|
||||
/**
|
||||
* Presents the user with a thank you <3.
|
||||
* @return string
|
||||
*/
|
||||
public function complete()
|
||||
public function complete(): string
|
||||
{
|
||||
return view('premium/complete');
|
||||
}
|
||||
|
@ -159,7 +155,7 @@ class PremiumController extends Controller
|
|||
* Errors.
|
||||
* @return string
|
||||
*/
|
||||
public function error()
|
||||
public function error(): string
|
||||
{
|
||||
return view('premium/error');
|
||||
}
|
||||
|
|
|
@ -19,12 +19,13 @@ class AccountController extends Controller
|
|||
{
|
||||
/**
|
||||
* Renders the profile changing page.
|
||||
* @throws HttpMethodNotAllowedException
|
||||
* @return string
|
||||
*/
|
||||
public function profile()
|
||||
public function profile(): string
|
||||
{
|
||||
if (!CurrentSession::$user->perms->changeProfile) {
|
||||
throw new HttpMethodNotAllowedException();
|
||||
throw new HttpMethodNotAllowedException;
|
||||
}
|
||||
|
||||
if (session_check()) {
|
||||
|
@ -87,7 +88,7 @@ class AccountController extends Controller
|
|||
* Details such as email, username and password.
|
||||
* @return string
|
||||
*/
|
||||
public function details()
|
||||
public function details(): string
|
||||
{
|
||||
$user = CurrentSession::$user;
|
||||
$edit_usern = $user->perms->changeUsername;
|
||||
|
@ -225,12 +226,13 @@ class AccountController extends Controller
|
|||
|
||||
/**
|
||||
* Renders the rank management page.
|
||||
* @throws HttpMethodNotAllowedException
|
||||
* @return string
|
||||
*/
|
||||
public function ranks()
|
||||
public function ranks(): string
|
||||
{
|
||||
if (!CurrentSession::$user->perms->manageRanks) {
|
||||
throw new HttpMethodNotAllowedException();
|
||||
throw new HttpMethodNotAllowedException;
|
||||
}
|
||||
|
||||
$rank = $_POST['rank'] ?? null;
|
||||
|
@ -267,19 +269,20 @@ class AccountController extends Controller
|
|||
|
||||
CurrentSession::$user->setMainRank($rank);
|
||||
|
||||
redirect($redirect);
|
||||
return;
|
||||
return redirect($redirect);
|
||||
}
|
||||
|
||||
return view('settings/account/ranks', compact('locked'));
|
||||
}
|
||||
/**
|
||||
* Renders the userpage editing page.
|
||||
* @throws HttpMethodNotAllowedException
|
||||
* @return string
|
||||
*/
|
||||
public function userpage()
|
||||
public function userpage(): string
|
||||
{
|
||||
if (!CurrentSession::$user->perms->changeUserpage) {
|
||||
throw new HttpMethodNotAllowedException();
|
||||
throw new HttpMethodNotAllowedException;
|
||||
}
|
||||
|
||||
$userpage = $_POST['userpage'] ?? null;
|
||||
|
@ -308,12 +311,13 @@ class AccountController extends Controller
|
|||
|
||||
/**
|
||||
* Renders the signature changing page.
|
||||
* @throws HttpMethodNotAllowedException
|
||||
* @return string
|
||||
*/
|
||||
public function signature()
|
||||
public function signature(): string
|
||||
{
|
||||
if (!CurrentSession::$user->perms->changeSignature) {
|
||||
throw new HttpMethodNotAllowedException();
|
||||
throw new HttpMethodNotAllowedException;
|
||||
}
|
||||
|
||||
$signature = $_POST['signature'] ?? null;
|
||||
|
|
|
@ -21,7 +21,7 @@ class AdvancedController extends Controller
|
|||
* Renders the session management page.
|
||||
* @return string
|
||||
*/
|
||||
public function sessions()
|
||||
public function sessions(): string
|
||||
{
|
||||
$id = $_POST['id'] ?? null;
|
||||
$all = isset($_POST['all']);
|
||||
|
@ -45,11 +45,9 @@ class AdvancedController extends Controller
|
|||
return view('global/information', compact('message', 'redirect'));
|
||||
}
|
||||
|
||||
// Delete it
|
||||
$session->delete();
|
||||
|
||||
redirect($redirect);
|
||||
return;
|
||||
return redirect($redirect);
|
||||
}
|
||||
|
||||
$sessions = CurrentSession::$user->sessions();
|
||||
|
@ -62,7 +60,7 @@ class AdvancedController extends Controller
|
|||
* Renders the deactivation page.
|
||||
* @return string
|
||||
*/
|
||||
public function deactivate()
|
||||
public function deactivate(): string
|
||||
{
|
||||
if (!CurrentSession::$user->perms->deactivateAccount) {
|
||||
throw new HttpMethodNotAllowedException();
|
||||
|
|
|
@ -29,7 +29,7 @@ class Controller extends BaseController
|
|||
* Generates the navigation.
|
||||
* @return array
|
||||
*/
|
||||
public function navigation()
|
||||
public function navigation(): array
|
||||
{
|
||||
$nav = [];
|
||||
|
||||
|
|
|
@ -18,12 +18,13 @@ class FriendsController extends Controller
|
|||
{
|
||||
/**
|
||||
* Gets friends listing
|
||||
* @throws HttpMethodNotAllowedException
|
||||
* @return string
|
||||
*/
|
||||
public function listing()
|
||||
public function listing(): string
|
||||
{
|
||||
if (!CurrentSession::$user->perms->manageFriends) {
|
||||
throw new HttpMethodNotAllowedException();
|
||||
throw new HttpMethodNotAllowedException;
|
||||
}
|
||||
|
||||
return view('settings/friends/listing');
|
||||
|
@ -31,12 +32,13 @@ class FriendsController extends Controller
|
|||
|
||||
/**
|
||||
* Gets friend requests listing
|
||||
* @throws HttpMethodNotAllowedException
|
||||
* @return string
|
||||
*/
|
||||
public function requests()
|
||||
public function requests(): string
|
||||
{
|
||||
if (!CurrentSession::$user->perms->manageFriends) {
|
||||
throw new HttpMethodNotAllowedException();
|
||||
throw new HttpMethodNotAllowedException;
|
||||
}
|
||||
|
||||
return view('settings/friends/requests');
|
||||
|
|
|
@ -17,7 +17,7 @@ class StatusController extends Controller
|
|||
* Renders the base status page.
|
||||
* @return string
|
||||
*/
|
||||
public function index()
|
||||
public function index(): string
|
||||
{
|
||||
return view('status/index');
|
||||
}
|
||||
|
|
|
@ -23,10 +23,10 @@ class UserController extends Controller
|
|||
{
|
||||
/**
|
||||
* Display the profile of a user.
|
||||
* @param int $id
|
||||
* @param int|string $id
|
||||
* @return string
|
||||
*/
|
||||
public function profile($id = 0)
|
||||
public function profile($id = 0): string
|
||||
{
|
||||
// Get the user's context
|
||||
$profile = User::construct($id);
|
||||
|
@ -41,8 +41,7 @@ class UserController extends Controller
|
|||
|
||||
// Redirect if so
|
||||
if ($check) {
|
||||
redirect(route('user.profile', $check->user_id));
|
||||
return;
|
||||
return redirect(route('user.profile', $check->user_id));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,7 +54,7 @@ class UserController extends Controller
|
|||
* @throws HttpRouteNotFoundException
|
||||
* @return string
|
||||
*/
|
||||
public function nowPlaying($id)
|
||||
public function nowPlaying(int $id): string
|
||||
{
|
||||
$user = User::construct($id);
|
||||
|
||||
|
@ -83,7 +82,7 @@ class UserController extends Controller
|
|||
* @throws HttpMethodNotAllowedException
|
||||
* @return string
|
||||
*/
|
||||
public function members($rank = null)
|
||||
public function members(int $rank = null): string
|
||||
{
|
||||
if (!CurrentSession::$user->activated) {
|
||||
throw new HttpMethodNotAllowedException;
|
||||
|
@ -114,7 +113,7 @@ class UserController extends Controller
|
|||
* Report a user.
|
||||
* @param int $id
|
||||
*/
|
||||
public function report($id = 0)
|
||||
public function report(int $id = 0): string
|
||||
{
|
||||
return view('user/report');
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ class CurrentSession
|
|||
* @param string $session
|
||||
* @param string $ip
|
||||
*/
|
||||
public static function start($user, $session, $ip)
|
||||
public static function start(int $user, string $session, string $ip): void
|
||||
{
|
||||
// Check if a PHP session was already started and if not start one
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||
|
@ -57,7 +57,7 @@ class CurrentSession
|
|||
/**
|
||||
* Stop the current session
|
||||
*/
|
||||
public static function stop()
|
||||
public static function stop(): void
|
||||
{
|
||||
self::$session->delete();
|
||||
session_regenerate_id(true);
|
||||
|
@ -74,7 +74,7 @@ class CurrentSession
|
|||
* @param int $length
|
||||
* @return Session
|
||||
*/
|
||||
public static function create($user, $ip, $country, $agent = null, $remember = false, $length = 604800)
|
||||
public static function create(int $user, string $ip, string $country, string $agent = null, bool $remember = false, int $length = 604800)
|
||||
{
|
||||
return Session::create($user, $ip, $country, $agent, $remember, $length);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Sakura;
|
|||
use Illuminate\Database\Capsule\Manager;
|
||||
use Illuminate\Database\ConnectionResolver;
|
||||
use Illuminate\Database\Migrations\DatabaseMigrationRepository;
|
||||
use Illuminate\Database\Schema\Builder;
|
||||
|
||||
/**
|
||||
* The Illuminate (Laravel) database wrapper.
|
||||
|
@ -21,7 +22,7 @@ class DB extends Manager
|
|||
* Start the database module.
|
||||
* @param array $details
|
||||
*/
|
||||
public static function connect($details)
|
||||
public static function connect(array $details): void
|
||||
{
|
||||
$capsule = new static;
|
||||
$capsule->addConnection($details);
|
||||
|
@ -32,7 +33,7 @@ class DB extends Manager
|
|||
* Gets the migration repository (surprise surprise).
|
||||
* @return DatabaseMigrationRepository
|
||||
*/
|
||||
public static function getMigrationRepository()
|
||||
public static function getMigrationRepository(): DatabaseMigrationRepository
|
||||
{
|
||||
$resolver = new ConnectionResolver(['database' => self::connection()]);
|
||||
$repository = new DatabaseMigrationRepository($resolver, 'migrations');
|
||||
|
@ -42,9 +43,9 @@ class DB extends Manager
|
|||
|
||||
/**
|
||||
* Get the migration schema builder.
|
||||
* @return \Illuminate\Database\Schema\Builder
|
||||
* @return Builder
|
||||
*/
|
||||
public static function getSchemaBuilder()
|
||||
public static function getSchemaBuilder(): Builder
|
||||
{
|
||||
return self::connection()->getSchemaBuilder();
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ class ExceptionHandler
|
|||
/**
|
||||
* Register as the error and exception handler.
|
||||
*/
|
||||
public static function register()
|
||||
public static function register(): void
|
||||
{
|
||||
set_exception_handler([static::class, 'exception']);
|
||||
set_error_handler([static::class, 'error']);
|
||||
|
@ -36,7 +36,7 @@ class ExceptionHandler
|
|||
* The entry point for set_exception_handler.
|
||||
* @param Throwable $ex
|
||||
*/
|
||||
public static function exception(Throwable $ex)
|
||||
public static function exception(Throwable $ex): void
|
||||
{
|
||||
$report = strlen(config('dev.report_host')) > 0;
|
||||
|
||||
|
@ -53,8 +53,9 @@ class ExceptionHandler
|
|||
* @param string $message
|
||||
* @param string $file
|
||||
* @param int $line
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public static function error($severity, $message, $file, $line)
|
||||
public static function error(int $severity, string $message, string $file, int $line): void
|
||||
{
|
||||
throw new ErrorException($message, 0, $severity, $file, $line);
|
||||
}
|
||||
|
@ -64,7 +65,7 @@ class ExceptionHandler
|
|||
* @param Throwable $ex
|
||||
* @param bool $reported
|
||||
*/
|
||||
private static function view(Throwable $ex, $reported = false)
|
||||
private static function view(Throwable $ex, bool $reported = false): void
|
||||
{
|
||||
http_response_code(500);
|
||||
|
||||
|
@ -98,7 +99,7 @@ class ExceptionHandler
|
|||
* @param Throwable $ex
|
||||
* @param string $destination
|
||||
*/
|
||||
private static function report(Throwable $ex, $destination)
|
||||
private static function report(Throwable $ex, string $destination): void
|
||||
{
|
||||
$send = new stdClass;
|
||||
$send->Date = date('c');
|
||||
|
|
|
@ -65,7 +65,7 @@ class File
|
|||
* @param int $expire
|
||||
* @return File
|
||||
*/
|
||||
public static function create($data, $name, User $user, $expire = 0)
|
||||
public static function create(string $data, string $name, User $user, int $expire = 0): File
|
||||
{
|
||||
// Get the mimetype
|
||||
$mime = (new finfo(FILEINFO_MIME_TYPE))->buffer($data);
|
||||
|
@ -91,7 +91,7 @@ class File
|
|||
* Constructor.
|
||||
* @param int $fileId
|
||||
*/
|
||||
public function __construct($fileId)
|
||||
public function __construct(int $fileId)
|
||||
{
|
||||
// Attempt to get the database row
|
||||
$fileRow = DB::table('uploads')
|
||||
|
@ -113,7 +113,7 @@ class File
|
|||
/**
|
||||
* Delete this file from the database.
|
||||
*/
|
||||
public function delete()
|
||||
public function delete(): void
|
||||
{
|
||||
$filename = path(config('file.uploads_dir') . $this->id . ".bin");
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ class FileSystem
|
|||
* Resolves the root path.
|
||||
* @return string
|
||||
*/
|
||||
public static function getRootPath()
|
||||
public static function getRootPath(): string
|
||||
{
|
||||
if (self::$rootPath === null) {
|
||||
// assuming we're running from the 'app' subdirectory
|
||||
|
@ -35,18 +35,20 @@ class FileSystem
|
|||
|
||||
/**
|
||||
* Fixes a given path to the correct slashes and root.
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public static function getPath($path)
|
||||
public static function getPath(string $path): string
|
||||
{
|
||||
return self::getRootPath() . DIRECTORY_SEPARATOR . self::fixSlashes($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes slashes.
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
private static function fixSlashes($path)
|
||||
private static function fixSlashes(string $path): string
|
||||
{
|
||||
return str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path);
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ class Forum
|
|||
* Gets all subforums of this forum.
|
||||
* @return array
|
||||
*/
|
||||
public function forums()
|
||||
public function forums(): array
|
||||
{
|
||||
// Check if forumsCache is populated
|
||||
if (!count($this->forumsCache)) {
|
||||
|
@ -154,7 +154,7 @@ class Forum
|
|||
* Gets the topics in this forum.
|
||||
* @return array
|
||||
*/
|
||||
public function topics()
|
||||
public function topics(): array
|
||||
{
|
||||
// Check if topicsCache is populated
|
||||
if (!count($this->topicsCache)) {
|
||||
|
@ -186,7 +186,7 @@ class Forum
|
|||
* Gets the first post in this forum.
|
||||
* @return Post
|
||||
*/
|
||||
public function firstPost()
|
||||
public function firstPost(): Post
|
||||
{
|
||||
// Check if firstPostCache is set
|
||||
if ($this->firstPostCache === null) {
|
||||
|
@ -214,7 +214,7 @@ class Forum
|
|||
* Gets the last post in this forum.
|
||||
* @return Post
|
||||
*/
|
||||
public function lastPost()
|
||||
public function lastPost(): Post
|
||||
{
|
||||
// Check if lastPostCache is set
|
||||
if ($this->lastPostCache === null) {
|
||||
|
@ -242,7 +242,7 @@ class Forum
|
|||
* Counts the amount of topics in this forum.
|
||||
* @return int
|
||||
*/
|
||||
public function topicCount()
|
||||
public function topicCount(): int
|
||||
{
|
||||
return DB::table('topics')
|
||||
->where('forum_id', $this->id)
|
||||
|
@ -253,7 +253,7 @@ class Forum
|
|||
* Counts the amount of posts in this forum.
|
||||
* @return int
|
||||
*/
|
||||
public function postCount()
|
||||
public function postCount(): int
|
||||
{
|
||||
return DB::table('posts')
|
||||
->where('forum_id', $this->id)
|
||||
|
@ -265,7 +265,7 @@ class Forum
|
|||
* @param int $user
|
||||
* @return bool
|
||||
*/
|
||||
public function unread($user)
|
||||
public function unread(int $user): bool
|
||||
{
|
||||
// Return false if the user id is less than 1
|
||||
if ($user < 1) {
|
||||
|
@ -294,7 +294,7 @@ class Forum
|
|||
* Update the read status of all topics in this forum at once.
|
||||
* @param int $user
|
||||
*/
|
||||
public function trackUpdateAll($user)
|
||||
public function trackUpdateAll(int $user): void
|
||||
{
|
||||
// Iterate over every forum
|
||||
foreach ($this->forums() as $forum) {
|
||||
|
|
|
@ -30,17 +30,17 @@ class ForumPerms
|
|||
$this->ranks = array_keys($user->ranks);
|
||||
}
|
||||
|
||||
public function __get($name)
|
||||
public function __get(string $name): bool
|
||||
{
|
||||
return $this->check($name);
|
||||
}
|
||||
|
||||
public function __isset($name)
|
||||
public function __isset(string $name): bool
|
||||
{
|
||||
return $this->valid($name);
|
||||
}
|
||||
|
||||
public function valid($name)
|
||||
public function valid(string $name): bool
|
||||
{
|
||||
if (!array_key_exists($name, $this->validCache)) {
|
||||
$column = 'perm_' . camel_to_snake($name);
|
||||
|
@ -50,7 +50,7 @@ class ForumPerms
|
|||
return $this->validCache[$name];
|
||||
}
|
||||
|
||||
public function check($name)
|
||||
public function check(string $name): bool
|
||||
{
|
||||
if (!array_key_exists($name, $this->permCache)) {
|
||||
$column = 'perm_' . camel_to_snake($name);
|
||||
|
|
|
@ -101,7 +101,7 @@ class Post
|
|||
* Constructor.
|
||||
* @param int $postId
|
||||
*/
|
||||
public function __construct($postId)
|
||||
public function __construct(int $postId)
|
||||
{
|
||||
// Attempt to get the database row
|
||||
$postRow = DB::table('posts')
|
||||
|
@ -147,7 +147,7 @@ class Post
|
|||
* @param int $forum
|
||||
* @return Post
|
||||
*/
|
||||
public static function create($subject, $text, User $poster, $topic = 0, $forum = 0)
|
||||
public static function create(string $subject, string $text, User $poster, int $topic = 0, int $forum = 0): Post
|
||||
{
|
||||
// If no topic is specified create a new one
|
||||
if ($topic) {
|
||||
|
@ -186,7 +186,7 @@ class Post
|
|||
* @param bool $ignoreIp
|
||||
* @return Post
|
||||
*/
|
||||
public function update($ignoreIp = false)
|
||||
public function update(bool $ignoreIp = false): Post
|
||||
{
|
||||
// Create a topic object
|
||||
$topic = new Topic($this->topic);
|
||||
|
@ -215,7 +215,7 @@ class Post
|
|||
/**
|
||||
* Undo deletion.
|
||||
*/
|
||||
public function restore()
|
||||
public function restore(): void
|
||||
{
|
||||
DB::table('posts')
|
||||
->where('post_id', $this->id)
|
||||
|
@ -225,9 +225,9 @@ class Post
|
|||
}
|
||||
|
||||
/**
|
||||
* delete this.
|
||||
* delet this.
|
||||
*/
|
||||
public function delete()
|
||||
public function delete(): void
|
||||
{
|
||||
DB::table('posts')
|
||||
->where('post_id', $this->id)
|
||||
|
@ -237,9 +237,9 @@ class Post
|
|||
}
|
||||
|
||||
/**
|
||||
* DELETE THIS.
|
||||
* DELET THIS.
|
||||
*/
|
||||
public function purge()
|
||||
public function purge(): void
|
||||
{
|
||||
DB::table('posts')
|
||||
->where('post_id', $this->id)
|
||||
|
@ -248,26 +248,21 @@ class Post
|
|||
|
||||
/**
|
||||
* Check if a user has read this post before.
|
||||
* @param mixed $user
|
||||
* @param int $user
|
||||
* @return bool
|
||||
*/
|
||||
public function unread($user)
|
||||
public function unread(int $user): bool
|
||||
{
|
||||
// Return false if the user id is less than 1
|
||||
if ($user < 1) {
|
||||
return false;
|
||||
}
|
||||
// Only check if user id is positive
|
||||
if ($user >= 1) {
|
||||
// Get track row from the database
|
||||
$track = DB::table('topics_track')
|
||||
->where('user_id', $user)
|
||||
->where('topic_id', $this->topic)
|
||||
->where('mark_time', '>', $this->time)
|
||||
->count();
|
||||
|
||||
// Attempt to get track row from the database
|
||||
$track = DB::table('topics_track')
|
||||
->where('user_id', $user)
|
||||
->where('topic_id', $this->topic)
|
||||
->where('mark_time', '>', $this->time)
|
||||
->count();
|
||||
|
||||
// If nothing was returned it's obvious that the status is unread
|
||||
if (!$track) {
|
||||
return true;
|
||||
return !$track;
|
||||
}
|
||||
|
||||
// Else just return false meaning everything is read
|
||||
|
|
|
@ -108,7 +108,7 @@ class Topic
|
|||
* Constructor.
|
||||
* @param int $topicId
|
||||
*/
|
||||
public function __construct($topicId)
|
||||
public function __construct(int $topicId)
|
||||
{
|
||||
// Attempt to get the database row
|
||||
$topicRow = DB::table('topics')
|
||||
|
@ -139,7 +139,7 @@ class Topic
|
|||
* @param int $type
|
||||
* @return Topic
|
||||
*/
|
||||
public static function create($forum, $title, $status = 0, $type = 0)
|
||||
public static function create(int $forum, string $title, int $status = 0, int $type = 0)
|
||||
{
|
||||
// Create the database entry
|
||||
$id = DB::table('topics')
|
||||
|
@ -158,7 +158,7 @@ class Topic
|
|||
/**
|
||||
* Delete the current topic.
|
||||
*/
|
||||
public function delete()
|
||||
public function delete(): void
|
||||
{
|
||||
// Delete all posts
|
||||
DB::table('posts')
|
||||
|
@ -176,7 +176,7 @@ class Topic
|
|||
* @param int $forum
|
||||
* @param bool $setOld
|
||||
*/
|
||||
public function move($forum, $setOld = true)
|
||||
public function move(int $forum, bool $setOld = true): void
|
||||
{
|
||||
// Update all posts
|
||||
DB::table('posts')
|
||||
|
@ -196,7 +196,7 @@ class Topic
|
|||
* Update the topic data.
|
||||
* @return Topic
|
||||
*/
|
||||
public function update()
|
||||
public function update(): Topic
|
||||
{
|
||||
// Update row
|
||||
DB::table('topics')
|
||||
|
@ -219,7 +219,7 @@ class Topic
|
|||
* Get the replies to this topic.
|
||||
* @return array
|
||||
*/
|
||||
public function posts()
|
||||
public function posts(): array
|
||||
{
|
||||
// Check if postsCache is something
|
||||
if (!count($this->postsCache)) {
|
||||
|
@ -237,19 +237,16 @@ class Topic
|
|||
}
|
||||
|
||||
$this->postsCache = $posts;
|
||||
} else {
|
||||
$posts = $this->postsCache;
|
||||
}
|
||||
|
||||
// Return the post objects
|
||||
return $posts;
|
||||
return $this->postsCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the opening post.
|
||||
* @return Post
|
||||
*/
|
||||
public function firstPost()
|
||||
public function firstPost(): Post
|
||||
{
|
||||
// Check if the cache var is set
|
||||
if ($this->firstPostCache !== null) {
|
||||
|
@ -277,7 +274,7 @@ class Topic
|
|||
* Get the latest reply.
|
||||
* @return Post
|
||||
*/
|
||||
public function lastPost()
|
||||
public function lastPost(): Post
|
||||
{
|
||||
// Check if the cache var is set
|
||||
if ($this->lastPostCache !== null) {
|
||||
|
@ -305,7 +302,7 @@ class Topic
|
|||
* Get the amount of replies.
|
||||
* @return int
|
||||
*/
|
||||
public function replyCount()
|
||||
public function replyCount(): int
|
||||
{
|
||||
return DB::table('posts')
|
||||
->where('topic_id', $this->id)
|
||||
|
@ -317,23 +314,18 @@ class Topic
|
|||
* @param int $user
|
||||
* @return bool
|
||||
*/
|
||||
public function unread($user)
|
||||
public function unread(int $user): bool
|
||||
{
|
||||
// Return false if the user id is less than 1
|
||||
if ($user < 1) {
|
||||
return false;
|
||||
}
|
||||
// Only check if user id is positive
|
||||
if ($user >= 1) {
|
||||
// Get track row from the database
|
||||
$track = DB::table('topics_track')
|
||||
->where('user_id', $user)
|
||||
->where('topic_id', $this->id)
|
||||
->where('mark_time', '>', $this->lastPost()->time)
|
||||
->count();
|
||||
|
||||
// Attempt to get track row from the database
|
||||
$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) {
|
||||
return true;
|
||||
return !$track;
|
||||
}
|
||||
|
||||
// Else just return false meaning everything is read
|
||||
|
@ -344,7 +336,7 @@ class Topic
|
|||
* Update the read status.
|
||||
* @param int $user
|
||||
*/
|
||||
public function trackUpdate($user)
|
||||
public function trackUpdate(int $user): void
|
||||
{
|
||||
// Check if we already have a track record
|
||||
$track = DB::table('topics_track')
|
||||
|
@ -377,7 +369,7 @@ class Topic
|
|||
/**
|
||||
* Update the view count.
|
||||
*/
|
||||
public function viewsUpdate()
|
||||
public function viewsUpdate(): void
|
||||
{
|
||||
DB::table('topics')
|
||||
->where('topic_id', $this->id)
|
||||
|
@ -387,7 +379,7 @@ class Topic
|
|||
/**
|
||||
* Update the timestamp of when this topic was last replied to.
|
||||
*/
|
||||
public function lastUpdate()
|
||||
public function lastUpdate(): void
|
||||
{
|
||||
DB::table('topics')
|
||||
->where('topic_id', $this->id)
|
||||
|
|
|
@ -16,7 +16,7 @@ class EnableCORS implements MiddlewareInterface
|
|||
/**
|
||||
* Enables CORS.
|
||||
*/
|
||||
public function run()
|
||||
public function run(): void
|
||||
{
|
||||
if (isset($_SERVER['HTTP_ORIGIN'])) {
|
||||
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
|
||||
|
|
|
@ -18,7 +18,7 @@ class UpdateLastOnline implements MiddlewareInterface
|
|||
/**
|
||||
* Update the last online information for the active user.
|
||||
*/
|
||||
public function run()
|
||||
public function run(): void
|
||||
{
|
||||
if (CurrentSession::$user->id !== 0) {
|
||||
CurrentSession::$user->updateOnline();
|
||||
|
|
20
app/Net.php
20
app/Net.php
|
@ -20,7 +20,7 @@ class Net
|
|||
* Returns the connecting IP.
|
||||
* @return string
|
||||
*/
|
||||
public static function ip()
|
||||
public static function ip(): string
|
||||
{
|
||||
return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '::1';
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class Net
|
|||
* @param string $ipAddr
|
||||
* @return int
|
||||
*/
|
||||
public static function detectIPVersion($ipAddr)
|
||||
public static function detectIPVersion(string $ipAddr): int
|
||||
{
|
||||
// Check if var is IP
|
||||
if (filter_var($ipAddr, FILTER_VALIDATE_IP)) {
|
||||
|
@ -55,7 +55,7 @@ class Net
|
|||
* @throws NetInvalidAddressException
|
||||
* @return string
|
||||
*/
|
||||
public static function pton($ip)
|
||||
public static function pton(string $ip): string
|
||||
{
|
||||
// Detect the IP version
|
||||
$ipv = self::detectIPVersion($ip);
|
||||
|
@ -80,7 +80,7 @@ class Net
|
|||
* @throws NetAddressTypeException
|
||||
* @return string
|
||||
*/
|
||||
public static function ntop($bin)
|
||||
public static function ntop(string $bin): string
|
||||
{
|
||||
// Get the length of the binary string
|
||||
$len = strlen($bin);
|
||||
|
@ -100,7 +100,7 @@ class Net
|
|||
* @param string $range
|
||||
* @return bool
|
||||
*/
|
||||
public static function matchCIDR($ip, $range)
|
||||
public static function matchCIDR(string $ip, string $range): bool
|
||||
{
|
||||
// Break the range up in parts
|
||||
list($net, $mask) = explode('/', $range);
|
||||
|
@ -135,7 +135,7 @@ class Net
|
|||
* @param string $mask
|
||||
* @return bool
|
||||
*/
|
||||
private static function matchCIDRv4($ip, $net, $mask)
|
||||
private static function matchCIDRv4(string $ip, string $net, string $mask): bool
|
||||
{
|
||||
// Convert IP and Net address to long
|
||||
$ip = ip2long($ip);
|
||||
|
@ -153,7 +153,7 @@ class Net
|
|||
* @param int $mask
|
||||
* @return string
|
||||
*/
|
||||
private static function maskToByteArray($mask)
|
||||
private static function maskToByteArray(int $mask): string
|
||||
{
|
||||
// Generate an address from the mask
|
||||
$addr = str_repeat("f", $mask / 4);
|
||||
|
@ -190,7 +190,7 @@ class Net
|
|||
* @param int $mask
|
||||
* @return bool
|
||||
*/
|
||||
private static function matchCIDRv6($ip, $net, $mask)
|
||||
private static function matchCIDRv6(string $ip, string $net, int $mask): bool
|
||||
{
|
||||
// Pack the IP and Net addresses
|
||||
$ip = inet_pton($ip);
|
||||
|
@ -207,10 +207,10 @@ class Net
|
|||
* Make a web request.
|
||||
* @param string $url
|
||||
* @param string $method
|
||||
* @param mixed $params
|
||||
* @param mixed $params Can be either an array or a string.
|
||||
* @return string
|
||||
*/
|
||||
public static function request($url, $method = 'GET', $params = null)
|
||||
public static function request(string $url, string $method = 'GET', $params = null): string
|
||||
{
|
||||
$curl = curl_init();
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ class Category
|
|||
* Constructor.
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($name)
|
||||
public function __construct(string $name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
@ -33,8 +33,9 @@ class Category
|
|||
/**
|
||||
* Gets the news posts in this category.
|
||||
* @param int $limit
|
||||
* @return array
|
||||
*/
|
||||
public function posts($limit = 0)
|
||||
public function posts(int $limit = 0): array
|
||||
{
|
||||
$postIds = DB::table('news')
|
||||
->where('news_category', $this->name)
|
||||
|
|
|
@ -20,7 +20,7 @@ class Post
|
|||
/**
|
||||
* The format the comment categories should follow.
|
||||
*/
|
||||
const COMMENT_CATEGORY_FORMAT = "news-%s-%u";
|
||||
private const COMMENT_CATEGORY_FORMAT = "news-%s-%u";
|
||||
|
||||
/**
|
||||
* The id of this news post.
|
||||
|
@ -74,7 +74,7 @@ class Post
|
|||
* Constructor.
|
||||
* @param int $id
|
||||
*/
|
||||
public function __construct($id = 0)
|
||||
public function __construct(int $id = 0)
|
||||
{
|
||||
// Get comment data from the database
|
||||
$data = DB::table('news')
|
||||
|
@ -95,7 +95,7 @@ class Post
|
|||
/**
|
||||
* Saving changes to this news post.
|
||||
*/
|
||||
public function save()
|
||||
public function save(): void
|
||||
{
|
||||
// Create submission data, insert and update take the same format
|
||||
$data = [
|
||||
|
@ -120,7 +120,7 @@ class Post
|
|||
/**
|
||||
* Deleting this news post.
|
||||
*/
|
||||
public function delete()
|
||||
public function delete(): void
|
||||
{
|
||||
DB::table('news')
|
||||
->where('news_id', $this->id)
|
||||
|
@ -133,7 +133,7 @@ class Post
|
|||
* Get the user object of the poster.
|
||||
* @return User
|
||||
*/
|
||||
public function userData()
|
||||
public function userData(): User
|
||||
{
|
||||
return User::construct($this->user);
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ class Post
|
|||
* Count the amount of comments this post has.
|
||||
* @return int
|
||||
*/
|
||||
public function commentCount()
|
||||
public function commentCount(): int
|
||||
{
|
||||
if (!$this->commentCountCache) {
|
||||
$this->commentCountCache = DB::table('comments')
|
||||
|
@ -157,7 +157,7 @@ class Post
|
|||
* Get the comments on this post.
|
||||
* @return array
|
||||
*/
|
||||
public function comments()
|
||||
public function comments(): array
|
||||
{
|
||||
if (!$this->commentsCache) {
|
||||
$commentIds = DB::table('comments')
|
||||
|
|
|
@ -71,7 +71,7 @@ class Notification
|
|||
* The constructor.
|
||||
* @param int $id
|
||||
*/
|
||||
public function __construct($id = 0)
|
||||
public function __construct(int $id = 0)
|
||||
{
|
||||
// Get notification data from the database
|
||||
$data = DB::table('notifications')
|
||||
|
@ -95,7 +95,7 @@ class Notification
|
|||
/**
|
||||
* Saving changes to this notification.
|
||||
*/
|
||||
public function save()
|
||||
public function save(): void
|
||||
{
|
||||
// Create submission data, insert and update take the same format
|
||||
$data = [
|
||||
|
@ -123,7 +123,7 @@ class Notification
|
|||
/**
|
||||
* Toggle the read status
|
||||
*/
|
||||
public function toggleRead()
|
||||
public function toggleRead(): void
|
||||
{
|
||||
// Set read to the negative value of itself
|
||||
$this->read = !$this->read;
|
||||
|
@ -133,7 +133,7 @@ class Notification
|
|||
* Get the user object.
|
||||
* @return User
|
||||
*/
|
||||
public function userData()
|
||||
public function userData(): User
|
||||
{
|
||||
return User::construct($this->user);
|
||||
}
|
||||
|
|
|
@ -32,28 +32,21 @@ class Payments
|
|||
|
||||
/**
|
||||
* Initialise the wrapper.
|
||||
* @return bool
|
||||
*/
|
||||
public static function init()
|
||||
public static function init(): void
|
||||
{
|
||||
// Set PayPal object
|
||||
try {
|
||||
self::$paypal = new \PayPal\Rest\ApiContext(
|
||||
new \PayPal\Auth\OAuthTokenCredential(
|
||||
config("paypal.client_id"),
|
||||
config("paypal.secret_id")
|
||||
)
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
self::$paypal = new \PayPal\Rest\ApiContext(
|
||||
new \PayPal\Auth\OAuthTokenCredential(
|
||||
config("paypal.client_id"),
|
||||
config("paypal.secret_id")
|
||||
)
|
||||
);
|
||||
|
||||
// Set the configuration
|
||||
self::$paypal->setConfig([
|
||||
'mode' => config("paypal.mode"),
|
||||
]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,9 +55,9 @@ class Payments
|
|||
* @param string $itemName
|
||||
* @param string $transDescription
|
||||
* @param string $returnUrl
|
||||
* @return bool|null|string
|
||||
* @return string
|
||||
*/
|
||||
public static function createTransaction($total, $itemName, $transDescription, $returnUrl)
|
||||
public static function createTransaction(float $total, string $itemName, string $transDescription, string $returnUrl): string
|
||||
{
|
||||
// Create the payer object
|
||||
$payer = new Payer();
|
||||
|
@ -130,7 +123,7 @@ class Payments
|
|||
try {
|
||||
$payment->create(self::$paypal);
|
||||
} catch (\Exception $ex) {
|
||||
return false;
|
||||
return route('premium.error');
|
||||
}
|
||||
|
||||
// Return the approval link if everything is gucci
|
||||
|
@ -143,7 +136,7 @@ class Payments
|
|||
* @param string $payerId
|
||||
* @return bool
|
||||
*/
|
||||
public static function completeTransaction($paymentId, $payerId)
|
||||
public static function completeTransaction(string $paymentId, string $payerId): bool
|
||||
{
|
||||
// Attempt to get the payment
|
||||
$payment = Payment::get($paymentId, self::$paypal);
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
<?php
|
||||
/**
|
||||
* Holds the global permissions handler.
|
||||
* Holds the old permissions handler, only still here for reference while fixing the forum permission backend.
|
||||
* @package Sakura
|
||||
*/
|
||||
|
||||
namespace Sakura;
|
||||
|
||||
/**
|
||||
* Global permissions handler.
|
||||
* Old permissions handler.
|
||||
* @package Sakura
|
||||
* @author Julian van de Groep <me@flash.moe>
|
||||
*/
|
||||
|
|
19
app/Rank.php
19
app/Rank.php
|
@ -59,7 +59,7 @@ class Rank
|
|||
* Indicates if this rank should be hidden.
|
||||
* @var bool
|
||||
*/
|
||||
private $hidden = true;
|
||||
public $hidden = true;
|
||||
|
||||
/**
|
||||
* Instance cache container.
|
||||
|
@ -73,7 +73,7 @@ class Rank
|
|||
* @param bool $forceRefresh
|
||||
* @return Rank
|
||||
*/
|
||||
public static function construct($rid, $forceRefresh = false)
|
||||
public static function construct(int $rid, bool $forceRefresh = false): Rank
|
||||
{
|
||||
// Check if a rank object isn't present in cache
|
||||
if ($forceRefresh || !array_key_exists($rid, self::$rankCache)) {
|
||||
|
@ -89,7 +89,7 @@ class Rank
|
|||
* Constructor.
|
||||
* @param int $rankId
|
||||
*/
|
||||
private function __construct($rankId)
|
||||
private function __construct(int $rankId)
|
||||
{
|
||||
// Get the rank database row
|
||||
$rankRow = DB::table('ranks')
|
||||
|
@ -114,26 +114,17 @@ class Rank
|
|||
* @param bool $multi
|
||||
* @return string
|
||||
*/
|
||||
public function name($multi = false)
|
||||
public function name(bool $multi = false): string
|
||||
{
|
||||
return $this->name . ($multi ? $this->multiple : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the rank is hidden.
|
||||
* @return bool
|
||||
*/
|
||||
public function hidden()
|
||||
{
|
||||
return $this->hidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all users that are part of this rank.
|
||||
* @param bool $justIds
|
||||
* @return array
|
||||
*/
|
||||
public function users($justIds = false)
|
||||
public function users(bool $justIds = false): array
|
||||
{
|
||||
// Fetch all users part of this rank
|
||||
$get = DB::table('user_ranks')
|
||||
|
|
|
@ -10,6 +10,7 @@ use Phroute\Phroute\Dispatcher;
|
|||
use Phroute\Phroute\Exception\HttpMethodNotAllowedException;
|
||||
use Phroute\Phroute\Exception\HttpRouteNotFoundException;
|
||||
use Phroute\Phroute\RouteCollector;
|
||||
use Closure;
|
||||
|
||||
/**
|
||||
* Sakura Wrapper for Phroute.
|
||||
|
@ -24,12 +25,6 @@ class Router
|
|||
*/
|
||||
protected static $router = null;
|
||||
|
||||
/**
|
||||
* Base path of the router.
|
||||
* @var string
|
||||
*/
|
||||
protected static $basePath = null;
|
||||
|
||||
/**
|
||||
* Container for the Dispatcher.
|
||||
* @var Dispatcher
|
||||
|
@ -56,7 +51,7 @@ class Router
|
|||
* @param string $name
|
||||
* @param array $args
|
||||
*/
|
||||
public static function __callStatic($name, $args)
|
||||
public static function __callStatic(string $name, array $args): void
|
||||
{
|
||||
// Check if the method exists
|
||||
if (in_array($name = strtoupper($name), self::$methods)) {
|
||||
|
@ -82,32 +77,18 @@ class Router
|
|||
|
||||
/**
|
||||
* Initialisation.
|
||||
* @param string $basePath
|
||||
*/
|
||||
public static function init($basePath = '/')
|
||||
public static function init(): void
|
||||
{
|
||||
// Set base path
|
||||
self::setBasePath($basePath);
|
||||
|
||||
// Create router
|
||||
self::$router = new RouteCollector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the base path.
|
||||
* @param string $basePath
|
||||
*/
|
||||
public static function setBasePath($basePath)
|
||||
{
|
||||
self::$basePath = $basePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a URL.
|
||||
* @param string $url
|
||||
* @return string
|
||||
*/
|
||||
private static function parseUrl($url)
|
||||
private static function parseUrl(string $url): string
|
||||
{
|
||||
return parse_url($url, PHP_URL_PATH);
|
||||
}
|
||||
|
@ -118,7 +99,7 @@ class Router
|
|||
* @param string|array $args
|
||||
* @return string
|
||||
*/
|
||||
public static function route($name, $args = null)
|
||||
public static function route(string $name, $args = null): string
|
||||
{
|
||||
// Array-ify the arguments
|
||||
if ($args !== null && !is_array($args)) {
|
||||
|
@ -127,15 +108,15 @@ class Router
|
|||
$args[] = $temp;
|
||||
}
|
||||
|
||||
return self::$basePath . self::$router->route($name, $args);
|
||||
return '/' . self::$router->route($name, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create group.
|
||||
* @param array $filters
|
||||
* @param \Closure $callback
|
||||
* @param Closure $callback
|
||||
*/
|
||||
public static function group($filters, $callback)
|
||||
public static function group(array $filters, Closure $callback): void
|
||||
{
|
||||
// Execute the inner function
|
||||
self::$router->group($filters, $callback);
|
||||
|
@ -144,9 +125,9 @@ class Router
|
|||
/**
|
||||
* Create filter.
|
||||
* @param string $name
|
||||
* @param \Closure $method
|
||||
* @param Closure $method
|
||||
*/
|
||||
public static function filter($name, $method)
|
||||
public static function filter(string $name, Closure $method): void
|
||||
{
|
||||
self::$router->filter($name, $method);
|
||||
}
|
||||
|
@ -155,9 +136,9 @@ class Router
|
|||
* Handle requests.
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
* @return mixed
|
||||
* @return string
|
||||
*/
|
||||
public static function handle($method, $url)
|
||||
public static function handle(string $method, string $url): string
|
||||
{
|
||||
// Check if the dispatcher is defined
|
||||
if (self::$dispatcher === null) {
|
||||
|
|
|
@ -106,7 +106,7 @@ class Session
|
|||
* @param int $length
|
||||
* @return Session
|
||||
*/
|
||||
public static function create($user, $ip, $country, $agent = null, $remember = false, $length = 604800)
|
||||
public static function create(int $user, string $ip, string $country, string $agent = null, bool $remember = false, int $length = 604800)
|
||||
{
|
||||
$start = time();
|
||||
$key = bin2hex(random_bytes(64));
|
||||
|
@ -129,7 +129,7 @@ class Session
|
|||
/**
|
||||
* Delete this session.
|
||||
*/
|
||||
public function delete()
|
||||
public function delete(): void
|
||||
{
|
||||
DB::table('sessions')
|
||||
->where('session_id', $this->id)
|
||||
|
@ -142,7 +142,7 @@ class Session
|
|||
* @param string $ip
|
||||
* @return bool
|
||||
*/
|
||||
public function validate($user, $ip = null)
|
||||
public function validate(int $user, string $ip = null): bool
|
||||
{
|
||||
// Get session from database
|
||||
$session = DB::table('sessions')
|
||||
|
@ -184,7 +184,7 @@ class Session
|
|||
* @param bool $long
|
||||
* @return string
|
||||
*/
|
||||
public function country($long = false)
|
||||
public function country(bool $long = false): string
|
||||
{
|
||||
return $long ? get_country_name($this->country) : $this->country;
|
||||
}
|
||||
|
|
|
@ -22,12 +22,12 @@ class Template
|
|||
/**
|
||||
* The file extension used by template files.
|
||||
*/
|
||||
const FILE_EXT = '.twig';
|
||||
private const FILE_EXT = '.twig';
|
||||
|
||||
/**
|
||||
* The path relative to the root.
|
||||
*/
|
||||
const VIEWS_DIR = 'resources/views/';
|
||||
private const VIEWS_DIR = 'resources/views/';
|
||||
|
||||
/**
|
||||
* The template name.
|
||||
|
@ -82,7 +82,7 @@ class Template
|
|||
/**
|
||||
* Initialise the templating engine.
|
||||
*/
|
||||
public static function init()
|
||||
public static function init(): void
|
||||
{
|
||||
$views_dir = path(self::VIEWS_DIR);
|
||||
|
||||
|
@ -130,7 +130,7 @@ class Template
|
|||
* Checks if twig is available.
|
||||
* @return bool
|
||||
*/
|
||||
public static function available()
|
||||
public static function available(): bool
|
||||
{
|
||||
return self::$engine !== null && self::$name !== null;
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ class Template
|
|||
* Merge the parse variables.
|
||||
* @param array $vars
|
||||
*/
|
||||
public static function vars($vars)
|
||||
public static function vars(array $vars): void
|
||||
{
|
||||
self::$vars = array_merge(self::$vars, $vars);
|
||||
}
|
||||
|
@ -149,16 +149,17 @@ class Template
|
|||
* @param string $file
|
||||
* @return string
|
||||
*/
|
||||
public static function render($file)
|
||||
public static function render(string $file): string
|
||||
{
|
||||
return self::$engine->render($file . self::FILE_EXT, self::$vars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a template directory exists.
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public static function exists($name)
|
||||
public static function exists(string $name): bool
|
||||
{
|
||||
return ctype_alnum($name) && file_exists(path(self::VIEWS_DIR . $name . "/"));
|
||||
}
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Holds the extension manager.
|
||||
* @package Sakura
|
||||
*/
|
||||
|
||||
namespace Sakura;
|
||||
|
||||
/**
|
||||
* Extension manager.
|
||||
* @package Sakura
|
||||
* @author Julian van de Groep <me@flash.moe>
|
||||
*/
|
||||
class Trick
|
||||
{
|
||||
}
|
79
app/User.php
79
app/User.php
|
@ -278,7 +278,7 @@ class User
|
|||
* @param bool $forceRefresh
|
||||
* @return User
|
||||
*/
|
||||
public static function construct($uid, $forceRefresh = false)
|
||||
public static function construct($uid, bool $forceRefresh = false): User
|
||||
{
|
||||
// Check if a user object isn't present in cache
|
||||
if ($forceRefresh || !array_key_exists($uid, self::$userCache)) {
|
||||
|
@ -298,7 +298,7 @@ class User
|
|||
* @param array $ranks
|
||||
* @return User
|
||||
*/
|
||||
public static function create($username, $password, $email, $ranks = [2])
|
||||
public static function create(string $username, string $password, string $email, array $ranks = [2]): User
|
||||
{
|
||||
// Set a few variables
|
||||
$usernameClean = clean_string($username, true);
|
||||
|
@ -450,7 +450,7 @@ class User
|
|||
* Get a Carbon object of the registration date.
|
||||
* @return Carbon
|
||||
*/
|
||||
public function registerDate()
|
||||
public function registerDate(): Carbon
|
||||
{
|
||||
return Carbon::createFromTimestamp($this->registered);
|
||||
}
|
||||
|
@ -459,7 +459,7 @@ class User
|
|||
* Get a Carbon object of the last online date.
|
||||
* @return Carbon
|
||||
*/
|
||||
public function lastDate()
|
||||
public function lastDate(): Carbon
|
||||
{
|
||||
return Carbon::createFromTimestamp($this->lastOnline);
|
||||
}
|
||||
|
@ -469,7 +469,7 @@ class User
|
|||
* @param bool $age
|
||||
* @return int|string
|
||||
*/
|
||||
public function birthday($age = false)
|
||||
public function birthday(bool $age = false)
|
||||
{
|
||||
// If age is requested calculate it
|
||||
if ($age) {
|
||||
|
@ -493,7 +493,7 @@ class User
|
|||
* @param bool $long
|
||||
* @return string
|
||||
*/
|
||||
public function country($long = false)
|
||||
public function country(bool $long = false): string
|
||||
{
|
||||
return $long ? get_country_name($this->country) : $this->country;
|
||||
}
|
||||
|
@ -502,7 +502,7 @@ class User
|
|||
* Check if a user is online.
|
||||
* @return bool
|
||||
*/
|
||||
public function isOnline()
|
||||
public function isOnline(): bool
|
||||
{
|
||||
// Count sessions
|
||||
$sessions = DB::table('sessions')
|
||||
|
@ -521,7 +521,7 @@ class User
|
|||
/**
|
||||
* Updates the last IP and online time of the user.
|
||||
*/
|
||||
public function updateOnline()
|
||||
public function updateOnline(): void
|
||||
{
|
||||
$this->lastOnline = time();
|
||||
$this->lastIp = Net::ip();
|
||||
|
@ -538,7 +538,7 @@ class User
|
|||
* Runs some checks to see if this user is activated.
|
||||
* @return bool
|
||||
*/
|
||||
public function isActive()
|
||||
public function isActive(): bool
|
||||
{
|
||||
return $this->id !== 0 && $this->activated;
|
||||
}
|
||||
|
@ -547,7 +547,7 @@ class User
|
|||
* Get a few forum statistics.
|
||||
* @return array
|
||||
*/
|
||||
public function forumStats()
|
||||
public function forumStats(): array
|
||||
{
|
||||
$posts = DB::table('posts')
|
||||
->where('poster_id', $this->id)
|
||||
|
@ -559,17 +559,14 @@ class User
|
|||
->groupBy('topic_id')
|
||||
->count();
|
||||
|
||||
return [
|
||||
'posts' => $posts,
|
||||
'topics' => $topics,
|
||||
];
|
||||
return compact('posts', 'topics');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add ranks to a user.
|
||||
* @param array $ranks
|
||||
*/
|
||||
public function addRanks($ranks)
|
||||
public function addRanks(array $ranks): void
|
||||
{
|
||||
// Update the ranks array
|
||||
$ranks = array_diff(
|
||||
|
@ -598,7 +595,7 @@ class User
|
|||
* Remove a set of ranks from a user.
|
||||
* @param array $ranks
|
||||
*/
|
||||
public function removeRanks($ranks)
|
||||
public function removeRanks(array $ranks): void
|
||||
{
|
||||
// Current ranks
|
||||
$remove = array_intersect(array_keys($this->ranks), $ranks);
|
||||
|
@ -618,7 +615,7 @@ class User
|
|||
* Change the main rank of a user.
|
||||
* @param int $rank
|
||||
*/
|
||||
public function setMainRank($rank)
|
||||
public function setMainRank(int $rank): void
|
||||
{
|
||||
$this->mainRankId = $rank;
|
||||
$this->mainRank = $this->ranks[$rank];
|
||||
|
@ -635,7 +632,7 @@ class User
|
|||
* @param array $ranks
|
||||
* @return bool
|
||||
*/
|
||||
public function hasRanks($ranks)
|
||||
public function hasRanks(array $ranks): bool
|
||||
{
|
||||
// Check if the main rank is the specified rank
|
||||
if (in_array($this->mainRankId, $ranks)) {
|
||||
|
@ -658,7 +655,7 @@ class User
|
|||
* Add a new friend.
|
||||
* @param int $uid
|
||||
*/
|
||||
public function addFriend($uid)
|
||||
public function addFriend(int $uid): void
|
||||
{
|
||||
// Add friend
|
||||
DB::table('friends')
|
||||
|
@ -674,7 +671,7 @@ class User
|
|||
* @param int $uid
|
||||
* @param bool $deleteRequest
|
||||
*/
|
||||
public function removeFriend($uid, $deleteRequest = false)
|
||||
public function removeFriend(int $uid, bool $deleteRequest = false): void
|
||||
{
|
||||
// Remove friend
|
||||
DB::table('friends')
|
||||
|
@ -697,7 +694,7 @@ class User
|
|||
* @param int $with
|
||||
* @return int
|
||||
*/
|
||||
public function isFriends($with)
|
||||
public function isFriends(int $with): int
|
||||
{
|
||||
// Accepted from this user
|
||||
$user = DB::table('friends')
|
||||
|
@ -727,7 +724,7 @@ class User
|
|||
* @param bool $noObj
|
||||
* @return array
|
||||
*/
|
||||
public function friends($level = 0, $noObj = false)
|
||||
public function friends(int $level = 0, bool $noObj = false): array
|
||||
{
|
||||
// User ID container
|
||||
$users = [];
|
||||
|
@ -821,7 +818,7 @@ class User
|
|||
* Get the comments from the user's profile.
|
||||
* @return array
|
||||
*/
|
||||
public function profileComments()
|
||||
public function profileComments(): array
|
||||
{
|
||||
$commentIds = DB::table('comments')
|
||||
->where('comment_category', "profile-{$this->id}")
|
||||
|
@ -844,7 +841,7 @@ class User
|
|||
* @param int $seconds
|
||||
* @return int
|
||||
*/
|
||||
public function addPremium($seconds)
|
||||
public function addPremium(int $seconds): int
|
||||
{
|
||||
// Check if there's already a record of premium for this user in the database
|
||||
$getUser = DB::table('premium')
|
||||
|
@ -879,7 +876,7 @@ class User
|
|||
* Does this user have premium?
|
||||
* @return int
|
||||
*/
|
||||
public function isPremium()
|
||||
public function isPremium(): int
|
||||
{
|
||||
// Get rank IDs from the db
|
||||
$premiumRank = (int) config('rank.premium');
|
||||
|
@ -917,7 +914,7 @@ class User
|
|||
* Gets the start and end date of this user's premium tag.
|
||||
* @return stdClass
|
||||
*/
|
||||
public function premiumInfo()
|
||||
public function premiumInfo(): stdClass
|
||||
{
|
||||
// Attempt to retrieve the premium record from the database
|
||||
$check = DB::table('premium')
|
||||
|
@ -937,7 +934,7 @@ class User
|
|||
* Parse the user's userpage.
|
||||
* @return string
|
||||
*/
|
||||
public function userPage()
|
||||
public function userPage(): string
|
||||
{
|
||||
return BBCode\Parser::toHTML(htmlentities($this->page), $this);
|
||||
}
|
||||
|
@ -946,7 +943,7 @@ class User
|
|||
* Parse a user's signature.
|
||||
* @return string
|
||||
*/
|
||||
public function signature()
|
||||
public function signature(): string
|
||||
{
|
||||
return BBCode\Parser::toHTML(htmlentities($this->signature), $this);
|
||||
}
|
||||
|
@ -955,7 +952,7 @@ class User
|
|||
* Get a user's username history.
|
||||
* @return array
|
||||
*/
|
||||
public function getUsernameHistory()
|
||||
public function getUsernameHistory(): array
|
||||
{
|
||||
return DB::table('username_history')
|
||||
->where('user_id', $this->id)
|
||||
|
@ -967,7 +964,7 @@ class User
|
|||
* Alter the user's username.
|
||||
* @param string $username
|
||||
*/
|
||||
public function setUsername($username)
|
||||
public function setUsername(string $username): void
|
||||
{
|
||||
$username_clean = clean_string($username, true);
|
||||
|
||||
|
@ -996,7 +993,7 @@ class User
|
|||
* Alter a user's e-mail address.
|
||||
* @param string $email
|
||||
*/
|
||||
public function setMail($email)
|
||||
public function setMail(string $email): void
|
||||
{
|
||||
$this->email = $email;
|
||||
|
||||
|
@ -1011,7 +1008,7 @@ class User
|
|||
* Change the user's password.
|
||||
* @param string $password
|
||||
*/
|
||||
public function setPassword($password)
|
||||
public function setPassword(string $password): void
|
||||
{
|
||||
// Create hash
|
||||
$this->password = password_hash($password, PASSWORD_BCRYPT);
|
||||
|
@ -1030,7 +1027,7 @@ class User
|
|||
* Check if password expired.
|
||||
* @return bool
|
||||
*/
|
||||
public function passwordExpired()
|
||||
public function passwordExpired(): bool
|
||||
{
|
||||
return strlen($this->password) < 1;
|
||||
}
|
||||
|
@ -1040,7 +1037,7 @@ class User
|
|||
* @param string $password
|
||||
* @return bool
|
||||
*/
|
||||
public function verifyPassword($password)
|
||||
public function verifyPassword(string $password): bool
|
||||
{
|
||||
return password_verify($password, $this->password);
|
||||
}
|
||||
|
@ -1051,7 +1048,7 @@ class User
|
|||
* @param bool $excludeRead
|
||||
* @return array
|
||||
*/
|
||||
public function notifications($timeDifference = 0, $excludeRead = true)
|
||||
public function notifications(int $timeDifference = 0, bool $excludeRead = true): array
|
||||
{
|
||||
$alertIds = DB::table('notifications')
|
||||
->where('user_id', $this->id);
|
||||
|
@ -1077,7 +1074,7 @@ class User
|
|||
/**
|
||||
* Invalidate all sessions related to this user.
|
||||
*/
|
||||
public function purgeSessions()
|
||||
public function purgeSessions(): void
|
||||
{
|
||||
DB::table('sessions')
|
||||
->where('user_id', $this->id)
|
||||
|
@ -1088,7 +1085,7 @@ class User
|
|||
* Get all a user's sessions
|
||||
* @return array
|
||||
*/
|
||||
public function sessions()
|
||||
public function sessions(): array
|
||||
{
|
||||
$sessions = [];
|
||||
$ids = array_column(DB::table('sessions')
|
||||
|
@ -1106,16 +1103,16 @@ class User
|
|||
* Gets the user's selected design.
|
||||
* @return string
|
||||
*/
|
||||
public function design()
|
||||
public function design(): string
|
||||
{
|
||||
return Template::exists($this->design) ? $this->design : config('general.design');
|
||||
return isset($this->design) && Template::exists($this->design) ? $this->design : config('general.design');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the user's proper (highest) hierarchy.
|
||||
* @return int
|
||||
*/
|
||||
public function hierarchy()
|
||||
public function hierarchy(): int
|
||||
{
|
||||
return DB::table('ranks')
|
||||
->join('user_ranks', 'ranks.rank_id', '=', 'user_ranks.rank_id')
|
||||
|
@ -1126,7 +1123,7 @@ class User
|
|||
/**
|
||||
* Update last listened data.
|
||||
*/
|
||||
public function updateLastTrack()
|
||||
public function updateLastTrack(): void
|
||||
{
|
||||
if (strlen($this->lastfm) < 1
|
||||
|| $this->musicCheck + config('user.music_update') > time()) {
|
||||
|
|
|
@ -25,17 +25,17 @@ class UserPerms
|
|||
$this->ranks = array_keys($user->ranks);
|
||||
}
|
||||
|
||||
public function __get($name)
|
||||
public function __get(string $name): bool
|
||||
{
|
||||
return $this->check($name);
|
||||
}
|
||||
|
||||
public function __isset($name)
|
||||
public function __isset(string $name): bool
|
||||
{
|
||||
return $this->valid($name);
|
||||
}
|
||||
|
||||
public function valid($name)
|
||||
public function valid(string $name): bool
|
||||
{
|
||||
if (!array_key_exists($name, $this->validCache)) {
|
||||
$column = 'perm_' . camel_to_snake($name);
|
||||
|
@ -45,7 +45,7 @@ class UserPerms
|
|||
return $this->validCache[$name];
|
||||
}
|
||||
|
||||
public function check($name)
|
||||
public function check(string $name): bool
|
||||
{
|
||||
if (!array_key_exists($name, $this->permCache)) {
|
||||
$column = 'perm_' . camel_to_snake($name);
|
||||
|
|
|
@ -9,13 +9,13 @@
|
|||
Frequently Asked Questions
|
||||
</div>
|
||||
<div class="settings__navigation">
|
||||
{% for question in page.questions %}
|
||||
{% for question in questions %}
|
||||
<a href="#{{ question.faq_shorthand }}" class="settings__navigation-link">{{ question.faq_question }}</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="content--left">
|
||||
{% for question in page.questions %}
|
||||
{% for question in questions %}
|
||||
<div class="content__header" id="{{ question.faq_shorthand }}">
|
||||
{{ question.faq_question }}
|
||||
<a href="#{{ question.faq_shorthand }}" class="fa fa-quote-right news-rss default"></a>
|
||||
|
|
12
routes.php
12
routes.php
|
@ -194,13 +194,13 @@ Router::group(['before' => 'maintenance'], function () {
|
|||
// Settings
|
||||
Router::group(['prefix' => 'settings'], function () {
|
||||
Router::get('/', function () {
|
||||
redirect(route('settings.account.profile'));
|
||||
return redirect(route('settings.account.profile'));
|
||||
}, 'settings.index');
|
||||
|
||||
// Account section
|
||||
Router::group(['prefix' => 'account'], function () {
|
||||
Router::get('/', function () {
|
||||
redirect(route('settings.account.profile'));
|
||||
return redirect(route('settings.account.profile'));
|
||||
});
|
||||
|
||||
Router::get('/profile', 'Settings.AccountController@profile', 'settings.account.profile');
|
||||
|
@ -218,7 +218,7 @@ Router::group(['before' => 'maintenance'], function () {
|
|||
// Friends section
|
||||
Router::group(['prefix' => 'friends'], function () {
|
||||
Router::get('/', function () {
|
||||
redirect(route('settings.account.listing'));
|
||||
return redirect(route('settings.account.listing'));
|
||||
});
|
||||
|
||||
Router::get('/listing', 'Settings.FriendsController@listing', 'settings.friends.listing');
|
||||
|
@ -228,7 +228,7 @@ Router::group(['before' => 'maintenance'], function () {
|
|||
// Advanced section
|
||||
Router::group(['prefix' => 'advanced'], function () {
|
||||
Router::get('/', function () {
|
||||
redirect(route('settings.account.sessions'));
|
||||
return redirect(route('settings.account.sessions'));
|
||||
});
|
||||
|
||||
Router::get('/sessions', 'Settings.AdvancedController@sessions', 'settings.advanced.sessions');
|
||||
|
@ -241,13 +241,13 @@ Router::group(['before' => 'maintenance'], function () {
|
|||
// Settings
|
||||
Router::group(['prefix' => 'manage'], function () {
|
||||
Router::get('/', function () {
|
||||
redirect(route('manage.overview.index'));
|
||||
return redirect(route('manage.overview.index'));
|
||||
}, 'manage.index');
|
||||
|
||||
// Overview section
|
||||
Router::group(['prefix' => 'overview'], function () {
|
||||
Router::get('/', function () {
|
||||
redirect(route('manage.overview.index'));
|
||||
return redirect(route('manage.overview.index'));
|
||||
});
|
||||
|
||||
Router::get('/index', 'Manage.OverviewController@index', 'manage.overview.index');
|
||||
|
|
|
@ -91,6 +91,7 @@ function redirect($url)
|
|||
{
|
||||
header("Turbolinks-Location: {$url}");
|
||||
header("Location: {$url}");
|
||||
return $url;
|
||||
}
|
||||
|
||||
function check_mx_record($email)
|
||||
|
|
Reference in a new issue