Uncaught TypeError

Return value of User::getDisplayname() must be of the type string, null returned

(File: /var/www/cubedcraft/core/classes/Core/User.php)

https://cubedcraft.com/profile/Partydragen/&p=13


File: /var/www/cubedcraft/core/classes/Core/User.php
     * Handle StaffCP logins.
     *
     * @param string|null $username Their username (or email, depending on $method).
     * @param string|null $password Their password.
     * @param string $method What column to check for their details in. Can be either `username` or `email`.
     *
     * @return bool True/false on success or failure respectfully.
     */
    public function adminLogin(?string $username = null, ?string $password = null, string $method = 'email'): bool {
        return $this->_commonLogin($username, $password, true, $method, true);
    }

    /**
     * Get user's display name.
     *
     * @param bool $username If true, will use their username. If false, will use their nickname.
     * @return string Their display name.
     */
    public function getDisplayname(bool $username = false): string {
        if ($username) {
            return Output::getClean($this->data()->username);
        }

        return Output::getClean($this->data()->nickname);
    }

    /**
     * Build this user's profile link.
     *
     * @return string Compiled profile URL.
     */
    public function getProfileURL(): string {
        return URL::build('/profile/' . urlencode($this->data()->username));
    }

    /**
     * Get all of a user's groups id. Logged out/non-existent users will return just `0`.
     *
     * @return array Array of all their group IDs.
     */
    public function getAllGroupIds(): array {
File: /var/www/cubedcraft/modules/Core/pages/profile.php
                if (count($reactions_query) == 1) {
                    $reactions['count'] = $language->get('user', '1_reaction');
                } else {
                    $reactions['count'] = $language->get('user', 'x_reactions', ['count' => count($reactions_query)]);
                }

                foreach ($reactions_query as $reaction) {
                    // Get reaction name and icon
                    // TODO
                    /*
                    $reaction_name = DB::getInstance()->get('reactions', array('id', $reaction->reaction_id))->results();

                    if (!count($reaction_name) || $reaction_name[0]->enabled == 0) continue;
                    $reaction_html = $reaction_name[0]->html;
                    $reaction_name = Output::getClean($reaction_name[0]->name);
                    */

                    $target_user = new User($reaction->user_id);
                    $reactions['reactions'][] = [
                        'user_id' => Output::getClean($reaction->user_id),
                        'username' => $target_user->getDisplayname(true),
                        'nickname' => $target_user->getDisplayname(),
                        'style' => $target_user->getGroupStyle(),
                        'profile' => $target_user->getProfileURL(),
                        'avatar' => $target_user->getAvatar(500),
                        //'reaction_name' => $reaction_name,
                        //'reaction_html' => $reaction_html
                    ];
                }
            } else {
                $reactions['count'] = $language->get('user', 'x_reactions', ['count' => 0]);
            }
            $reactions_query = null;

            $replies_query = DB::getInstance()->orderWhere('user_profile_wall_posts_replies', 'post_id = ' . $nValue->id, 'time', 'ASC')->results();
            if (count($replies_query)) {
                if (count($replies_query) == 1) {
                    $replies['count'] = $language->get('user', '1_reply');
                } else {
                    $replies['count'] = $language->get('user', 'x_replies', ['count' => count($replies_query)]);
                }
File: /var/www/cubedcraft/index.php
        die();
    }
} else {
    // Use recursion to check - might have URL parameters in path
    $path_array = explode('/', $route);

    for ($i = count($path_array) - 2; $i > 0; $i--) {

        $new_path = '/';
        for ($n = 1; $n <= $i; $n++) {
            $new_path .= $path_array[$n] . '/';
        }

        $new_path = rtrim($new_path, '/');

        if (array_key_exists($new_path, $all_pages)) {
            $path = implode(DIRECTORY_SEPARATOR, [ROOT_PATH, 'modules', $all_pages[$new_path]['module'], $all_pages[$new_path]['file']]);

            if (file_exists($path)) {
                $pages->setActivePage($all_pages[$new_path]);
                require($path);
                die();
            }
        }
    }
}

require(ROOT_PATH . '/404.php');
SQL query:
SELECT * FROM nl2_users WHERE `id` = '482';
File: /var/www/cubedcraft/core/classes/Core/User.php
    }

    /**
     * Find a user by unique identifier (username, ID, email, etc).
     * Loads instance variables for this class.
     *
     * @param string|null $value Unique identifier.
     * @param string $field What column to check for their unique identifier in.
     *
     * @return bool True/false on success or failure respectfully.
     */
    public function find(string $value = null, string $field = 'id'): bool {
        if ($value) {
            if (isset(self::$_user_cache["$value.$field"])) {
                $cache = self::$_user_cache["$value.$field"];
                $this->_data = $cache['data'];
                $this->_groups = $cache['groups'];
                return true;
            }

            $data = $this->_db->get('users', [$field, $value]);

            if ($data->count()) {
                $this->_data = new UserData($data->first());

                // Get user groups
                $groups_query = $this->_db->query('SELECT nl2_groups.* FROM nl2_users_groups INNER JOIN nl2_groups ON group_id = nl2_groups.id WHERE user_id = ? AND deleted = 0 ORDER BY `order`;', [$this->data()->id]);

                if ($groups_query->count()) {

                    $groups_query = $groups_query->results();
                    foreach ($groups_query as $item) {
                        $this->_groups[$item->id] = new Group($item);
                    }

                    self::$_user_cache["$value.$field"] = [
                        'data' => $this->_data,
                        'groups' => $this->_groups,
                    ];

                } else {
SQL query:
SELECT nl2_users_integrations.*, nl2_integrations.name as integration_name FROM nl2_users_integrations LEFT JOIN nl2_integrations ON integration_id=nl2_integrations.id WHERE user_id = '454';
File: /var/www/cubedcraft/core/classes/Core/User.php
    }

    /**
     * Get the user's groups.
     *
     * @return array Their groups.
     */
    public function getGroups(): array {
        return $this->_groups;
    }

    /**
     * Get the user's integrations.
     *
     * @return IntegrationUser[] Their integrations.
     */
    public function getIntegrations(): array {
        return $this->_integrations ??= (function (): array {
            $integrations = Integrations::getInstance();

            $integrations_query = $this->_db->query('SELECT nl2_users_integrations.*, nl2_integrations.name as integration_name FROM nl2_users_integrations LEFT JOIN nl2_integrations ON integration_id=nl2_integrations.id WHERE user_id = ?', [$this->data()->id]);
            if ($integrations_query->count()) {
                $integrations_query = $integrations_query->results();

                $integrations_list = [];
                foreach ($integrations_query as $item) {
                    $integration = $integrations->getIntegration($item->integration_name);
                    if ($integration != null) {
                        $integrationUser = new IntegrationUser($integration, $this->data()->id, 'user_id', $item);

                        $integrations_list[$item->integration_name] = $integrationUser;
                    }
                }

                return $integrations_list;
            }

            return [];
        })();
    }

SQL query:
SELECT nl2_groups.* FROM nl2_users_groups INNER JOIN nl2_groups ON group_id = nl2_groups.id WHERE user_id = '454' AND deleted = 0 ORDER BY `order`;
File: /var/www/cubedcraft/core/classes/Core/User.php
     * @param string|null $value Unique identifier.
     * @param string $field What column to check for their unique identifier in.
     *
     * @return bool True/false on success or failure respectfully.
     */
    public function find(string $value = null, string $field = 'id'): bool {
        if ($value) {
            if (isset(self::$_user_cache["$value.$field"])) {
                $cache = self::$_user_cache["$value.$field"];
                $this->_data = $cache['data'];
                $this->_groups = $cache['groups'];
                return true;
            }

            $data = $this->_db->get('users', [$field, $value]);

            if ($data->count()) {
                $this->_data = new UserData($data->first());

                // Get user groups
                $groups_query = $this->_db->query('SELECT nl2_groups.* FROM nl2_users_groups INNER JOIN nl2_groups ON group_id = nl2_groups.id WHERE user_id = ? AND deleted = 0 ORDER BY `order`;', [$this->data()->id]);

                if ($groups_query->count()) {

                    $groups_query = $groups_query->results();
                    foreach ($groups_query as $item) {
                        $this->_groups[$item->id] = new Group($item);
                    }

                    self::$_user_cache["$value.$field"] = [
                        'data' => $this->_data,
                        'groups' => $this->_groups,
                    ];

                } else {
                    // Get default group
                    // TODO: Use PRE_VALIDATED_DEFAULT ?
                    $default_group = $this->_db->query('SELECT * FROM nl2_groups WHERE default_group = 1', [])->first();
                    if ($default_group) {
                        $default_group_id = $default_group->id;
                    } else {
SQL query:
SELECT * FROM nl2_users WHERE `id` = '454';
File: /var/www/cubedcraft/core/classes/Core/User.php
    }

    /**
     * Find a user by unique identifier (username, ID, email, etc).
     * Loads instance variables for this class.
     *
     * @param string|null $value Unique identifier.
     * @param string $field What column to check for their unique identifier in.
     *
     * @return bool True/false on success or failure respectfully.
     */
    public function find(string $value = null, string $field = 'id'): bool {
        if ($value) {
            if (isset(self::$_user_cache["$value.$field"])) {
                $cache = self::$_user_cache["$value.$field"];
                $this->_data = $cache['data'];
                $this->_groups = $cache['groups'];
                return true;
            }

            $data = $this->_db->get('users', [$field, $value]);

            if ($data->count()) {
                $this->_data = new UserData($data->first());

                // Get user groups
                $groups_query = $this->_db->query('SELECT nl2_groups.* FROM nl2_users_groups INNER JOIN nl2_groups ON group_id = nl2_groups.id WHERE user_id = ? AND deleted = 0 ORDER BY `order`;', [$this->data()->id]);

                if ($groups_query->count()) {

                    $groups_query = $groups_query->results();
                    foreach ($groups_query as $item) {
                        $this->_groups[$item->id] = new Group($item);
                    }

                    self::$_user_cache["$value.$field"] = [
                        'data' => $this->_data,
                        'groups' => $this->_groups,
                    ];

                } else {
SQL query:
SELECT * FROM nl2_user_profile_wall_posts_reactions WHERE `post_id` = '18';
File: /var/www/cubedcraft/modules/Core/pages/profile.php
            $template_pagination_left ?? null,
            $template_pagination_right ?? null
        );
        $results = $paginator->getLimited($wall_posts_query, 10, $p, count($wall_posts_query));
        $pagination = $paginator->generate(7, URL::build('/profile/' . urlencode($query->username) . '/'));

        $smarty->assign('PAGINATION', $pagination);

        // Display the correct number of posts
        foreach ($results->data as $nValue) {
            $post_user = DB::getInstance()->get('users', ['id', $nValue->author_id])->results();

            if (!count($post_user)) {
                continue;
            }

            // Get reactions/replies
            $reactions = [];
            $replies = [];

            $reactions_query = DB::getInstance()->get('user_profile_wall_posts_reactions', ['post_id', $nValue->id])->results();
            if (count($reactions_query)) {
                if (count($reactions_query) == 1) {
                    $reactions['count'] = $language->get('user', '1_reaction');
                } else {
                    $reactions['count'] = $language->get('user', 'x_reactions', ['count' => count($reactions_query)]);
                }

                foreach ($reactions_query as $reaction) {
                    // Get reaction name and icon
                    // TODO
                    /*
                    $reaction_name = DB::getInstance()->get('reactions', array('id', $reaction->reaction_id))->results();

                    if (!count($reaction_name) || $reaction_name[0]->enabled == 0) continue;
                    $reaction_html = $reaction_name[0]->html;
                    $reaction_name = Output::getClean($reaction_name[0]->name);
                    */

                    $target_user = new User($reaction->user_id);
                    $reactions['reactions'][] = [
SQL query:
SELECT * FROM nl2_users WHERE `id` = '454';
File: /var/www/cubedcraft/modules/Core/pages/profile.php
    ]);

    // Wall posts
    $wall_posts = [];
    $wall_posts_query = DB::getInstance()->orderWhere('user_profile_wall_posts', 'user_id = ' . $query->id, 'time', 'DESC')->results();

    if (count($wall_posts_query)) {
        // Pagination
        $paginator = new Paginator(
            $template_pagination ?? null,
            $template_pagination_left ?? null,
            $template_pagination_right ?? null
        );
        $results = $paginator->getLimited($wall_posts_query, 10, $p, count($wall_posts_query));
        $pagination = $paginator->generate(7, URL::build('/profile/' . urlencode($query->username) . '/'));

        $smarty->assign('PAGINATION', $pagination);

        // Display the correct number of posts
        foreach ($results->data as $nValue) {
            $post_user = DB::getInstance()->get('users', ['id', $nValue->author_id])->results();

            if (!count($post_user)) {
                continue;
            }

            // Get reactions/replies
            $reactions = [];
            $replies = [];

            $reactions_query = DB::getInstance()->get('user_profile_wall_posts_reactions', ['post_id', $nValue->id])->results();
            if (count($reactions_query)) {
                if (count($reactions_query) == 1) {
                    $reactions['count'] = $language->get('user', '1_reaction');
                } else {
                    $reactions['count'] = $language->get('user', 'x_reactions', ['count' => count($reactions_query)]);
                }

                foreach ($reactions_query as $reaction) {
                    // Get reaction name and icon
                    // TODO
SQL query:
SELECT nl2_users_integrations.*, nl2_integrations.name as integration_name FROM nl2_users_integrations LEFT JOIN nl2_integrations ON integration_id=nl2_integrations.id WHERE user_id = '523';
File: /var/www/cubedcraft/core/classes/Core/User.php
    }

    /**
     * Get the user's groups.
     *
     * @return array Their groups.
     */
    public function getGroups(): array {
        return $this->_groups;
    }

    /**
     * Get the user's integrations.
     *
     * @return IntegrationUser[] Their integrations.
     */
    public function getIntegrations(): array {
        return $this->_integrations ??= (function (): array {
            $integrations = Integrations::getInstance();

            $integrations_query = $this->_db->query('SELECT nl2_users_integrations.*, nl2_integrations.name as integration_name FROM nl2_users_integrations LEFT JOIN nl2_integrations ON integration_id=nl2_integrations.id WHERE user_id = ?', [$this->data()->id]);
            if ($integrations_query->count()) {
                $integrations_query = $integrations_query->results();

                $integrations_list = [];
                foreach ($integrations_query as $item) {
                    $integration = $integrations->getIntegration($item->integration_name);
                    if ($integration != null) {
                        $integrationUser = new IntegrationUser($integration, $this->data()->id, 'user_id', $item);

                        $integrations_list[$item->integration_name] = $integrationUser;
                    }
                }

                return $integrations_list;
            }

            return [];
        })();
    }

SQL query:
SELECT nl2_groups.* FROM nl2_users_groups INNER JOIN nl2_groups ON group_id = nl2_groups.id WHERE user_id = '523' AND deleted = 0 ORDER BY `order`;
File: /var/www/cubedcraft/core/classes/Core/User.php
     * @param string|null $value Unique identifier.
     * @param string $field What column to check for their unique identifier in.
     *
     * @return bool True/false on success or failure respectfully.
     */
    public function find(string $value = null, string $field = 'id'): bool {
        if ($value) {
            if (isset(self::$_user_cache["$value.$field"])) {
                $cache = self::$_user_cache["$value.$field"];
                $this->_data = $cache['data'];
                $this->_groups = $cache['groups'];
                return true;
            }

            $data = $this->_db->get('users', [$field, $value]);

            if ($data->count()) {
                $this->_data = new UserData($data->first());

                // Get user groups
                $groups_query = $this->_db->query('SELECT nl2_groups.* FROM nl2_users_groups INNER JOIN nl2_groups ON group_id = nl2_groups.id WHERE user_id = ? AND deleted = 0 ORDER BY `order`;', [$this->data()->id]);

                if ($groups_query->count()) {

                    $groups_query = $groups_query->results();
                    foreach ($groups_query as $item) {
                        $this->_groups[$item->id] = new Group($item);
                    }

                    self::$_user_cache["$value.$field"] = [
                        'data' => $this->_data,
                        'groups' => $this->_groups,
                    ];

                } else {
                    // Get default group
                    // TODO: Use PRE_VALIDATED_DEFAULT ?
                    $default_group = $this->_db->query('SELECT * FROM nl2_groups WHERE default_group = 1', [])->first();
                    if ($default_group) {
                        $default_group_id = $default_group->id;
                    } else {
SQL query:
SELECT * FROM nl2_users WHERE `id` = '523';
File: /var/www/cubedcraft/core/classes/Core/User.php
    }

    /**
     * Find a user by unique identifier (username, ID, email, etc).
     * Loads instance variables for this class.
     *
     * @param string|null $value Unique identifier.
     * @param string $field What column to check for their unique identifier in.
     *
     * @return bool True/false on success or failure respectfully.
     */
    public function find(string $value = null, string $field = 'id'): bool {
        if ($value) {
            if (isset(self::$_user_cache["$value.$field"])) {
                $cache = self::$_user_cache["$value.$field"];
                $this->_data = $cache['data'];
                $this->_groups = $cache['groups'];
                return true;
            }

            $data = $this->_db->get('users', [$field, $value]);

            if ($data->count()) {
                $this->_data = new UserData($data->first());

                // Get user groups
                $groups_query = $this->_db->query('SELECT nl2_groups.* FROM nl2_users_groups INNER JOIN nl2_groups ON group_id = nl2_groups.id WHERE user_id = ? AND deleted = 0 ORDER BY `order`;', [$this->data()->id]);

                if ($groups_query->count()) {

                    $groups_query = $groups_query->results();
                    foreach ($groups_query as $item) {
                        $this->_groups[$item->id] = new Group($item);
                    }

                    self::$_user_cache["$value.$field"] = [
                        'data' => $this->_data,
                        'groups' => $this->_groups,
                    ];

                } else {
SQL query:
SELECT * FROM nl2_user_profile_wall_posts_replies WHERE post_id = 92 ORDER BY time ASC;
File: /var/www/cubedcraft/modules/Core/pages/profile.php
                    $reaction_name = Output::getClean($reaction_name[0]->name);
                    */

                    $target_user = new User($reaction->user_id);
                    $reactions['reactions'][] = [
                        'user_id' => Output::getClean($reaction->user_id),
                        'username' => $target_user->getDisplayname(true),
                        'nickname' => $target_user->getDisplayname(),
                        'style' => $target_user->getGroupStyle(),
                        'profile' => $target_user->getProfileURL(),
                        'avatar' => $target_user->getAvatar(500),
                        //'reaction_name' => $reaction_name,
                        //'reaction_html' => $reaction_html
                    ];
                }
            } else {
                $reactions['count'] = $language->get('user', 'x_reactions', ['count' => 0]);
            }
            $reactions_query = null;

            $replies_query = DB::getInstance()->orderWhere('user_profile_wall_posts_replies', 'post_id = ' . $nValue->id, 'time', 'ASC')->results();
            if (count($replies_query)) {
                if (count($replies_query) == 1) {
                    $replies['count'] = $language->get('user', '1_reply');
                } else {
                    $replies['count'] = $language->get('user', 'x_replies', ['count' => count($replies_query)]);
                }

                foreach ($replies_query as $reply) {
                    $target_user = new User($reply->author_id);
                    $replies['replies'][] = [
                        'user_id' => Output::getClean($reply->author_id),
                        'username' => $target_user->getDisplayname(true),
                        'nickname' => $target_user->getDisplayname(),
                        'style' => $target_user->getGroupStyle(),
                        'profile' => $target_user->getProfileURL(),
                        'avatar' => $target_user->getAvatar(500),
                        'time_friendly' => $timeago->inWords($reply->time, $language),
                        'time_full' => date(DATE_FORMAT, $reply->time),
                        'content' => Output::getPurified(Output::getDecoded($reply->content)),
                        'self' => (($user->isLoggedIn() && $user->data()->id == $reply->author_id) ? 1 : 0),
SQL query:
SELECT * FROM nl2_user_profile_wall_posts_reactions WHERE `post_id` = '92';
File: /var/www/cubedcraft/modules/Core/pages/profile.php
            $template_pagination_left ?? null,
            $template_pagination_right ?? null
        );
        $results = $paginator->getLimited($wall_posts_query, 10, $p, count($wall_posts_query));
        $pagination = $paginator->generate(7, URL::build('/profile/' . urlencode($query->username) . '/'));

        $smarty->assign('PAGINATION', $pagination);

        // Display the correct number of posts
        foreach ($results->data as $nValue) {
            $post_user = DB::getInstance()->get('users', ['id', $nValue->author_id])->results();

            if (!count($post_user)) {
                continue;
            }

            // Get reactions/replies
            $reactions = [];
            $replies = [];

            $reactions_query = DB::getInstance()->get('user_profile_wall_posts_reactions', ['post_id', $nValue->id])->results();
            if (count($reactions_query)) {
                if (count($reactions_query) == 1) {
                    $reactions['count'] = $language->get('user', '1_reaction');
                } else {
                    $reactions['count'] = $language->get('user', 'x_reactions', ['count' => count($reactions_query)]);
                }

                foreach ($reactions_query as $reaction) {
                    // Get reaction name and icon
                    // TODO
                    /*
                    $reaction_name = DB::getInstance()->get('reactions', array('id', $reaction->reaction_id))->results();

                    if (!count($reaction_name) || $reaction_name[0]->enabled == 0) continue;
                    $reaction_html = $reaction_name[0]->html;
                    $reaction_name = Output::getClean($reaction_name[0]->name);
                    */

                    $target_user = new User($reaction->user_id);
                    $reactions['reactions'][] = [
SQL query:
SELECT * FROM nl2_users WHERE `id` = '523';
File: /var/www/cubedcraft/modules/Core/pages/profile.php
    ]);

    // Wall posts
    $wall_posts = [];
    $wall_posts_query = DB::getInstance()->orderWhere('user_profile_wall_posts', 'user_id = ' . $query->id, 'time', 'DESC')->results();

    if (count($wall_posts_query)) {
        // Pagination
        $paginator = new Paginator(
            $template_pagination ?? null,
            $template_pagination_left ?? null,
            $template_pagination_right ?? null
        );
        $results = $paginator->getLimited($wall_posts_query, 10, $p, count($wall_posts_query));
        $pagination = $paginator->generate(7, URL::build('/profile/' . urlencode($query->username) . '/'));

        $smarty->assign('PAGINATION', $pagination);

        // Display the correct number of posts
        foreach ($results->data as $nValue) {
            $post_user = DB::getInstance()->get('users', ['id', $nValue->author_id])->results();

            if (!count($post_user)) {
                continue;
            }

            // Get reactions/replies
            $reactions = [];
            $replies = [];

            $reactions_query = DB::getInstance()->get('user_profile_wall_posts_reactions', ['post_id', $nValue->id])->results();
            if (count($reactions_query)) {
                if (count($reactions_query) == 1) {
                    $reactions['count'] = $language->get('user', '1_reaction');
                } else {
                    $reactions['count'] = $language->get('user', 'x_reactions', ['count' => count($reactions_query)]);
                }

                foreach ($reactions_query as $reaction) {
                    // Get reaction name and icon
                    // TODO
SQL query:
SELECT * FROM nl2_user_profile_wall_posts WHERE user_id = 1 ORDER BY time DESC;
File: /var/www/cubedcraft/modules/Core/pages/profile.php
        'FEED' => $language->get('user', 'feed'),
        'ABOUT' => $language->get('user', 'about'),
        'REACTIONS_TITLE' => $language->get('user', 'likes'),
        //'REACTIONS' => $reactions,
        'CLOSE' => $language->get('general', 'close'),
        'REPLIES_TITLE' => $language->get('user', 'replies'),
        'NO_REPLIES' => $language->get('user', 'no_replies_yet'),
        'NEW_REPLY' => $language->get('user', 'new_reply'),
        'DELETE' => $language->get('general', 'delete'),
        'CONFIRM_DELETE' => $language->get('general', 'confirm_deletion'),
        'EDIT' => $language->get('general', 'edit'),
        'SUCCESS_TITLE' => $language->get('general', 'success'),
        'ERROR_TITLE' => $language->get('general', 'error'),
        'REPLY' => $language->get('user', 'reply'),
        'EDIT_POST' => $language->get('general', 'edit'),
        'VIEWER_ID' => $user->isLoggedIn() ? $user->data()->id : 0,
    ]);

    // Wall posts
    $wall_posts = [];
    $wall_posts_query = DB::getInstance()->orderWhere('user_profile_wall_posts', 'user_id = ' . $query->id, 'time', 'DESC')->results();

    if (count($wall_posts_query)) {
        // Pagination
        $paginator = new Paginator(
            $template_pagination ?? null,
            $template_pagination_left ?? null,
            $template_pagination_right ?? null
        );
        $results = $paginator->getLimited($wall_posts_query, 10, $p, count($wall_posts_query));
        $pagination = $paginator->generate(7, URL::build('/profile/' . urlencode($query->username) . '/'));

        $smarty->assign('PAGINATION', $pagination);

        // Display the correct number of posts
        foreach ($results->data as $nValue) {
            $post_user = DB::getInstance()->get('users', ['id', $nValue->author_id])->results();

            if (!count($post_user)) {
                continue;
            }
SQL query:
SELECT nl2_users_integrations.*, nl2_integrations.name as integration_name FROM nl2_users_integrations LEFT JOIN nl2_integrations ON integration_id=nl2_integrations.id WHERE user_id = '1';
File: /var/www/cubedcraft/core/classes/Core/User.php
    }

    /**
     * Get the user's groups.
     *
     * @return array Their groups.
     */
    public function getGroups(): array {
        return $this->_groups;
    }

    /**
     * Get the user's integrations.
     *
     * @return IntegrationUser[] Their integrations.
     */
    public function getIntegrations(): array {
        return $this->_integrations ??= (function (): array {
            $integrations = Integrations::getInstance();

            $integrations_query = $this->_db->query('SELECT nl2_users_integrations.*, nl2_integrations.name as integration_name FROM nl2_users_integrations LEFT JOIN nl2_integrations ON integration_id=nl2_integrations.id WHERE user_id = ?', [$this->data()->id]);
            if ($integrations_query->count()) {
                $integrations_query = $integrations_query->results();

                $integrations_list = [];
                foreach ($integrations_query as $item) {
                    $integration = $integrations->getIntegration($item->integration_name);
                    if ($integration != null) {
                        $integrationUser = new IntegrationUser($integration, $this->data()->id, 'user_id', $item);

                        $integrations_list[$item->integration_name] = $integrationUser;
                    }
                }

                return $integrations_list;
            }

            return [];
        })();
    }

SQL query:
UPDATE nl2_users SET profile_views = profile_views + 1 WHERE id = '1';
File: /var/www/cubedcraft/modules/Core/pages/profile.php
            // Avoid bug in pagination class
            Redirect::to($profile_user->getProfileURL());
        }
        $p = $_GET['p'];
    } else {
        $p = 1;
    }

    // View count
    // Check if user is logged in and the viewer is not the owner of this profile.
    if (($user->isLoggedIn() && $user->data()->id != $query->id)
        // If no one is logged in check if they have accepted the cookies.
        || (!$user->isLoggedIn() && (defined('COOKIE_CHECK') && COOKIES_ALLOWED))
    ) {
        if (!Cookie::exists('nl-profile-' . $query->id)) {
            DB::getInstance()->increment('users', $query->id, 'profile_views');
            Cookie::put('nl-profile-' . $query->id, 'true', 3600);
        }
    } else {
        if (!Session::exists('nl-profile-' . $query->id)) {
            DB::getInstance()->increment('users', $query->id, 'profile_views');
            Session::put('nl-profile-' . $query->id, 'true');
        }
    }

    // Set Can view
    if ($profile_user->isPrivateProfile() && $user->canPrivateProfile()) {
        $smarty->assign([
            'PRIVATE_PROFILE' => $language->get('user', 'private_profile_page'),
            'CAN_VIEW' => false
        ]);
    } else {
        $smarty->assign([
            'CAN_VIEW' => true
        ]);
    }

    // Generate Smarty variables to pass to template
    if ($user->isLoggedIn()) {
        // Form token
        $smarty->assign([
SQL query:
SELECT nl2_groups.* FROM nl2_users_groups INNER JOIN nl2_groups ON group_id = nl2_groups.id WHERE user_id = '1' AND deleted = 0 ORDER BY `order`;
File: /var/www/cubedcraft/core/classes/Core/User.php
     * @param string|null $value Unique identifier.
     * @param string $field What column to check for their unique identifier in.
     *
     * @return bool True/false on success or failure respectfully.
     */
    public function find(string $value = null, string $field = 'id'): bool {
        if ($value) {
            if (isset(self::$_user_cache["$value.$field"])) {
                $cache = self::$_user_cache["$value.$field"];
                $this->_data = $cache['data'];
                $this->_groups = $cache['groups'];
                return true;
            }

            $data = $this->_db->get('users', [$field, $value]);

            if ($data->count()) {
                $this->_data = new UserData($data->first());

                // Get user groups
                $groups_query = $this->_db->query('SELECT nl2_groups.* FROM nl2_users_groups INNER JOIN nl2_groups ON group_id = nl2_groups.id WHERE user_id = ? AND deleted = 0 ORDER BY `order`;', [$this->data()->id]);

                if ($groups_query->count()) {

                    $groups_query = $groups_query->results();
                    foreach ($groups_query as $item) {
                        $this->_groups[$item->id] = new Group($item);
                    }

                    self::$_user_cache["$value.$field"] = [
                        'data' => $this->_data,
                        'groups' => $this->_groups,
                    ];

                } else {
                    // Get default group
                    // TODO: Use PRE_VALIDATED_DEFAULT ?
                    $default_group = $this->_db->query('SELECT * FROM nl2_groups WHERE default_group = 1', [])->first();
                    if ($default_group) {
                        $default_group_id = $default_group->id;
                    } else {
SQL query:
SELECT * FROM nl2_users WHERE `username` = 'Partydragen';
File: /var/www/cubedcraft/core/classes/Core/User.php
    }

    /**
     * Find a user by unique identifier (username, ID, email, etc).
     * Loads instance variables for this class.
     *
     * @param string|null $value Unique identifier.
     * @param string $field What column to check for their unique identifier in.
     *
     * @return bool True/false on success or failure respectfully.
     */
    public function find(string $value = null, string $field = 'id'): bool {
        if ($value) {
            if (isset(self::$_user_cache["$value.$field"])) {
                $cache = self::$_user_cache["$value.$field"];
                $this->_data = $cache['data'];
                $this->_groups = $cache['groups'];
                return true;
            }

            $data = $this->_db->get('users', [$field, $value]);

            if ($data->count()) {
                $this->_data = new UserData($data->first());

                // Get user groups
                $groups_query = $this->_db->query('SELECT nl2_groups.* FROM nl2_users_groups INNER JOIN nl2_groups ON group_id = nl2_groups.id WHERE user_id = ? AND deleted = 0 ORDER BY `order`;', [$this->data()->id]);

                if ($groups_query->count()) {

                    $groups_query = $groups_query->results();
                    foreach ($groups_query as $item) {
                        $this->_groups[$item->id] = new Group($item);
                    }

                    self::$_user_cache["$value.$field"] = [
                        'data' => $this->_data,
                        'groups' => $this->_groups,
                    ];

                } else {
SQL query:
SELECT * FROM nl2_page_descriptions WHERE `page` = '/profile/Partydragen';
File: /var/www/cubedcraft/core/templates/frontend_init.php
        $default_group = $cache->retrieve('default_group');
    } else {
        try {
            $default_group = Group::find(1, 'default_group')->id;
        } catch (Exception $e) {
            $default_group = 1;
        }

        $cache->store('default_group', $default_group);
    }
}

// Page metadata
if (isset($_GET['route']) && $_GET['route'] != '/') {
    $route = rtrim($_GET['route'], '/');
} else {
    $route = '/';
}

if (!defined('PAGE_DESCRIPTION')) {
    $page_metadata = DB::getInstance()->get('page_descriptions', ['page', $route])->results();
    if (count($page_metadata)) {
        $smarty->assign([
            'PAGE_DESCRIPTION' => str_replace('{site}', Output::getClean(SITE_NAME), $page_metadata[0]->description),
            'PAGE_KEYWORDS' => $page_metadata[0]->tags
        ]);
    }
} else {
    $smarty->assign([
        'PAGE_DESCRIPTION' => str_replace('{site}', Output::getClean(SITE_NAME), PAGE_DESCRIPTION),
        'PAGE_KEYWORDS' => (defined('PAGE_KEYWORDS') ? PAGE_KEYWORDS : '')
    ]);
}

$smarty->assign('TITLE', $page_title);

$cache->setCache('backgroundcache');

$banner_image = $cache->retrieve('banner_image');

if (!empty($banner_image)) {
SQL query:
SELECT * FROM nl2_page_descriptions WHERE `page` = '/profile';
File: /var/www/cubedcraft/modules/Core/pages/profile.php
/*
 *	Made by Samerton
 *  https://github.com/NamelessMC/Nameless/
 *  NamelessMC version 2.0.0-pr13
 *
 *  License: MIT
 *
 *  User profile page
 */

// Always define page name
const PAGE = 'profile';

$timeago = new TimeAgo(TIMEZONE);

$profile = explode('/', rtrim($_GET['route'], '/'));
if (count($profile) >= 3 && ($profile[count($profile) - 1] != 'profile' || $profile[count($profile) - 2] == 'profile') && !isset($_GET['error'])) {
    // User specified
    $md_profile = $profile[count($profile) - 1];

    $page_metadata = DB::getInstance()->get('page_descriptions', ['page', '/profile'])->results();
    if (count($page_metadata)) {
        define('PAGE_DESCRIPTION', str_replace(['{site}', '{profile}'], [Output::getClean(SITE_NAME), Output::getClean($md_profile)], $page_metadata[0]->description));
        define('PAGE_KEYWORDS', $page_metadata[0]->tags);
    }

    $page_title = $language->get('user', 'profile') . ' - ' . Output::getClean($md_profile);
} else {
    $page_title = $language->get('user', 'profile');
}

require_once(ROOT_PATH . '/core/templates/frontend_init.php');

$template->assets()->include([
    DARK_MODE
        ? AssetTree::PRISM_DARK
        : AssetTree::PRISM_LIGHT,
    AssetTree::TINYMCE_SPOILER,
]);

$template->addCSSStyle(
SQL query:
UPDATE nl2_online_guests SET `last_seen` = '113512' WHERE `id` =;
File: /var/www/cubedcraft/core/init.php
            'user_title' => Output::getClean($user->data()->user_title),
            'avatar' => $user->getAvatar(),
            'integrations' => $user_integrations
        ]);

        // Panel access?
        if ($user->canViewStaffCP()) {
            $smarty->assign([
                'PANEL_LINK' => URL::build('/panel'),
                'PANEL' => $language->get('moderator', 'staff_cp')
            ]);
        }
    } else {
        // Perform tasks for guests
        if (!$_SESSION['checked'] || (isset($_SESSION['checked']) && $_SESSION['checked'] <= strtotime('-5 minutes'))) {
            $already_online = DB::getInstance()->get('online_guests', ['ip', $ip])->results();

            $date = date('U');

            if (count($already_online)) {
                DB::getInstance()->update('online_guests', $already_online[0]->id, ['last_seen' => $date]);
            } else {
                DB::getInstance()->insert('online_guests', ['ip' => $ip, 'last_seen' => $date]);
            }

            $_SESSION['checked'] = $date;
        }
    }

    // Dark mode
    $cache->setCache('template_settings');
    $darkMode = $cache->isCached('darkMode') ? $cache->retrieve('darkMode') : '0';
    if ($user->isLoggedIn()) {
        $darkMode = $user->data()->night_mode !== null ? $user->data()->night_mode : $darkMode;
    } else {
        if (Cookie::exists('night_mode')) {
            $darkMode = Cookie::get('night_mode');
        }
    }

    define('DARK_MODE', $darkMode);
SQL query:
SELECT * FROM nl2_online_guests WHERE `ip` = '3.233.217.106';
File: /var/www/cubedcraft/core/init.php
            'username' => $user->getDisplayname(true),
            'nickname' => $user->getDisplayname(),
            'profile' => $user->getProfileURL(),
            'panel_profile' => URL::build('/panel/user/' . urlencode($user->data()->id) . '-' . urlencode($user->data()->username)),
            'username_style' => $user->getGroupStyle(),
            'user_title' => Output::getClean($user->data()->user_title),
            'avatar' => $user->getAvatar(),
            'integrations' => $user_integrations
        ]);

        // Panel access?
        if ($user->canViewStaffCP()) {
            $smarty->assign([
                'PANEL_LINK' => URL::build('/panel'),
                'PANEL' => $language->get('moderator', 'staff_cp')
            ]);
        }
    } else {
        // Perform tasks for guests
        if (!$_SESSION['checked'] || (isset($_SESSION['checked']) && $_SESSION['checked'] <= strtotime('-5 minutes'))) {
            $already_online = DB::getInstance()->get('online_guests', ['ip', $ip])->results();

            $date = date('U');

            if (count($already_online)) {
                DB::getInstance()->update('online_guests', $already_online[0]->id, ['last_seen' => $date]);
            } else {
                DB::getInstance()->insert('online_guests', ['ip' => $ip, 'last_seen' => $date]);
            }

            $_SESSION['checked'] = $date;
        }
    }

    // Dark mode
    $cache->setCache('template_settings');
    $darkMode = $cache->isCached('darkMode') ? $cache->retrieve('darkMode') : '0';
    if ($user->isLoggedIn()) {
        $darkMode = $user->data()->night_mode !== null ? $user->data()->night_mode : $darkMode;
    } else {
        if (Cookie::exists('night_mode')) {
SQL query:
SELECT * FROM nl2_integrations WHERE name = 'Discord';
File: /var/www/cubedcraft/core/classes/Integrations/IntegrationBase.php
 * @package NamelessMC\Integrations
 * @author Partydragen
 * @version 2.0.0-pr13
 * @license MIT
 */

abstract class IntegrationBase {

    private DB $_db;
    private IntegrationData $_data;
    protected string $_icon;
    private array $_errors = [];
    protected Language $_language;

    protected string $_name;
    protected ?int $_order;

    public function __construct() {
        $this->_db = DB::getInstance();

        $integration = $this->_db->query('SELECT * FROM nl2_integrations WHERE name = ?', [$this->_name]);
        if ($integration->count()) {
            $integration = $integration->first();

            $this->_data = new IntegrationData($integration);
            $this->_order = $integration->order;
        } else {
            // Register integration to database
            $this->_db->query('INSERT INTO nl2_integrations (name) VALUES (?)', [
                $this->_name
            ]);

            $integration = $this->_db->query('SELECT * FROM nl2_integrations WHERE name = ?', [$this->_name])->first();

            $this->_data = new IntegrationData($integration);
            $this->_order = $integration->order;
        }
    }

    /**
     * Get the name of this integration.
SQL query:
SELECT form_id FROM nl2_forms_permissions WHERE form_id = '5' AND post = 1 AND group_id IN(0);
File: /var/www/cubedcraft/modules/Forms/module.php

        try {
            $forms = $this->_db->query('SELECT id, link_location, url, icon, title, guest FROM nl2_forms')->results();
            if (count($forms)) {
                if ($user->isLoggedIn()) {
                    $group_ids = implode(',', $user->getAllGroupIds());
                } else {
                    $group_ids = implode(',', array(0));
                }

                foreach ($forms as $form) {
                    // Register form page
                    $pages->add('Forms', $form->url, 'pages/form.php', 'form-' . $form->id, true);

                    $perm = false;
                    if (!$user->isLoggedIn() && $form->guest == 1) {
                        $perm = true;
                    }

                    if (!$perm) {
                        $hasperm = $this->_db->query('SELECT form_id FROM nl2_forms_permissions WHERE form_id = ? AND post = 1 AND group_id IN('.$group_ids.')', array($form->id));
                        if ($hasperm->count()) {
                            $perm = true;
                        }
                    }

                    // Add link location to navigation if user have permission
                    if ($perm) {
                        switch ($form->link_location) {
                            case 1:
                                // Navbar
                                // Check cache first
                                $cache->setCache('navbar_order');
                                if (!$cache->isCached('form-' . $form->id . '_order')) {
                                    // Create cache entry now
                                    $form_order = 5;
                                    $cache->store('form-' . $form->id . '_order', 5);
                                } else {
                                    $form_order = $cache->retrieve('form-' . $form->id . '_order');
                                }
                                $navigation->add('form-' . $form->id, Output::getClean($form->title), URL::build(Output::getClean($form->url)), 'top', null, $form_order, $form->icon);
SQL query:
SELECT form_id FROM nl2_forms_permissions WHERE form_id = '4' AND post = 1 AND group_id IN(0);
File: /var/www/cubedcraft/modules/Forms/module.php

        try {
            $forms = $this->_db->query('SELECT id, link_location, url, icon, title, guest FROM nl2_forms')->results();
            if (count($forms)) {
                if ($user->isLoggedIn()) {
                    $group_ids = implode(',', $user->getAllGroupIds());
                } else {
                    $group_ids = implode(',', array(0));
                }

                foreach ($forms as $form) {
                    // Register form page
                    $pages->add('Forms', $form->url, 'pages/form.php', 'form-' . $form->id, true);

                    $perm = false;
                    if (!$user->isLoggedIn() && $form->guest == 1) {
                        $perm = true;
                    }

                    if (!$perm) {
                        $hasperm = $this->_db->query('SELECT form_id FROM nl2_forms_permissions WHERE form_id = ? AND post = 1 AND group_id IN('.$group_ids.')', array($form->id));
                        if ($hasperm->count()) {
                            $perm = true;
                        }
                    }

                    // Add link location to navigation if user have permission
                    if ($perm) {
                        switch ($form->link_location) {
                            case 1:
                                // Navbar
                                // Check cache first
                                $cache->setCache('navbar_order');
                                if (!$cache->isCached('form-' . $form->id . '_order')) {
                                    // Create cache entry now
                                    $form_order = 5;
                                    $cache->store('form-' . $form->id . '_order', 5);
                                } else {
                                    $form_order = $cache->retrieve('form-' . $form->id . '_order');
                                }
                                $navigation->add('form-' . $form->id, Output::getClean($form->title), URL::build(Output::getClean($form->url)), 'top', null, $form_order, $form->icon);
SQL query:
SELECT id, link_location, url, icon, title, guest FROM nl2_forms;
File: /var/www/cubedcraft/modules/Forms/module.php
        $pages->add('Forms', '/user/submissions', 'pages/user/submissions.php');

        // Check if module version changed
        $cache->setCache('forms_module_cache');
        if (!$cache->isCached('module_version')) {
            $cache->store('module_version', $module_version);
        } else {
            if ($module_version != $cache->retrieve('module_version')) {
                // Version have changed, Perform actions
                $this->initialiseUpdate($cache->retrieve('module_version'));

                $cache->store('module_version', $module_version);

                if ($cache->isCached('update_check')) {
                    $cache->erase('update_check');
                }
            }
        }

        try {
            $forms = $this->_db->query('SELECT id, link_location, url, icon, title, guest FROM nl2_forms')->results();
            if (count($forms)) {
                if ($user->isLoggedIn()) {
                    $group_ids = implode(',', $user->getAllGroupIds());
                } else {
                    $group_ids = implode(',', array(0));
                }

                foreach ($forms as $form) {
                    // Register form page
                    $pages->add('Forms', $form->url, 'pages/form.php', 'form-' . $form->id, true);

                    $perm = false;
                    if (!$user->isLoggedIn() && $form->guest == 1) {
                        $perm = true;
                    }

                    if (!$perm) {
                        $hasperm = $this->_db->query('SELECT form_id FROM nl2_forms_permissions WHERE form_id = ? AND post = 1 AND group_id IN('.$group_ids.')', array($form->id));
                        if ($hasperm->count()) {
                            $perm = true;
SQL query:
SELECT * FROM nl2_integrations WHERE name = 'Minecraft';
File: /var/www/cubedcraft/core/classes/Integrations/IntegrationBase.php
 * @package NamelessMC\Integrations
 * @author Partydragen
 * @version 2.0.0-pr13
 * @license MIT
 */

abstract class IntegrationBase {

    private DB $_db;
    private IntegrationData $_data;
    protected string $_icon;
    private array $_errors = [];
    protected Language $_language;

    protected string $_name;
    protected ?int $_order;

    public function __construct() {
        $this->_db = DB::getInstance();

        $integration = $this->_db->query('SELECT * FROM nl2_integrations WHERE name = ?', [$this->_name]);
        if ($integration->count()) {
            $integration = $integration->first();

            $this->_data = new IntegrationData($integration);
            $this->_order = $integration->order;
        } else {
            // Register integration to database
            $this->_db->query('INSERT INTO nl2_integrations (name) VALUES (?)', [
                $this->_name
            ]);

            $integration = $this->_db->query('SELECT * FROM nl2_integrations WHERE name = ?', [$this->_name])->first();

            $this->_data = new IntegrationData($integration);
            $this->_order = $integration->order;
        }
    }

    /**
     * Get the name of this integration.
SQL query:
SELECT * FROM nl2_custom_pages_permissions WHERE `group_id` = '0';
File: /var/www/cubedcraft/modules/Core/module.php
                                                $navigation->add(
                                                    $custom_page->id,
                                                    Output::getClean($custom_page->title),
                                                    (is_null($redirect)) ? URL::build(Output::urlEncodeAllowSlashes($custom_page->url)) : $redirect,
                                                    'footer', $custom_page->target ? '_blank' : null,
                                                    2000,
                                                    $custom_page->icon
                                                );
                                                break;
                                        }
                                        break 2;
                                    }

                                    break;
                                }
                            }
                        }
                    }
                }
            } else {
                $custom_page_permissions = DB::getInstance()->get('custom_pages_permissions', ['group_id', 0])->results();
                if (count($custom_page_permissions)) {
                    foreach ($custom_pages as $custom_page) {
                        $redirect = null;

                        if ($custom_page->redirect == 1) {
                            $redirect = Output::getClean($custom_page->link);
                        }

                        $pages->addCustom(Output::urlEncodeAllowSlashes($custom_page->url), Output::getClean($custom_page->title), !$custom_page->basic);

                        foreach ($custom_page_permissions as $permission) {
                            if ($permission->page_id == $custom_page->id) {
                                if ($permission->view == 1) {
                                    // Check cache for order
                                    if (!$cache->isCached($custom_page->id . '_order')) {
                                        // Create cache entry now
                                        $page_order = 200;
                                        $cache->store($custom_page->id . '_order', 200);
                                    } else {
                                        $page_order = $cache->retrieve($custom_page->id . '_order');
SQL query:
SELECT * FROM nl2_custom_pages WHERE `id` <> '0';
File: /var/www/cubedcraft/modules/Core/module.php
        $pages->addAjaxScript(URL::build('/queries/servers'));

        // "More" dropdown
        $cache->setCache('navbar_icons');
        if ($cache->isCached('more_dropdown_icon')) {
            $icon = $cache->retrieve('more_dropdown_icon');
        } else {
            $icon = '';
        }

        $cache->setCache('navbar_order');
        if ($cache->isCached('more_dropdown_order')) {
            $order = $cache->retrieve('more_dropdown_order');
        } else {
            $order = 2500;
        }

        $navigation->addDropdown('more_dropdown', $language->get('general', 'more'), 'top', $order, $icon);

        // Custom pages
        $custom_pages = DB::getInstance()->get('custom_pages', ['id', '<>', 0])->results();
        if (count($custom_pages)) {
            $more = [];
            $cache->setCache('navbar_order');

            if ($user->isLoggedIn()) {
                // Check all groups
                $user_groups = $user->getAllGroupIds();

                foreach ($custom_pages as $custom_page) {
                    $redirect = null;

                    // Get redirect URL if enabled
                    if ($custom_page->redirect == 1) {
                        $redirect = $custom_page->link;
                    }

                    $pages->addCustom(Output::urlEncodeAllowSlashes($custom_page->url), Output::getClean($custom_page->title), !$custom_page->basic);

                    foreach ($user_groups as $user_group) {
                        $custom_page_permissions = DB::getInstance()->get('custom_pages_permissions', ['group_id', $user_group])->results();
SQL query:
SELECT `name`, `value` FROM `nl2_settings`;
File: /var/www/cubedcraft/core/classes/Core/Util.php
            }

            return '<a href="' . $m[1] . '" target="_blank">' . $m[2] . '</a>';
        }, $data);
    }

    /**
     * Get a setting from the database table `nl2_settings`.
     *
     * @param string $setting Setting to check.
     * @param ?string $fallback Fallback to return if $setting is not set in DB.
     * @param ?string $module Alphanumeric (no spaces!) module name to use as a settings table prefix. For example,
     *                        specify 'store' to use the 'nl2_store_settings' table. Null to use the standard
     *                        nl2_settings table.
     * @return ?string Setting from DB or $fallback.
     */
    public static function getSetting(string $setting, ?string $fallback = null, ?string $module = null): ?string {
        $table_name = $module == null ? 'nl2_settings' : "nl2_${module}_settings";

        if (self::$_cached_settings == null) {
            $result = DB::getInstance()->query('SELECT `name`, `value` FROM `' . $table_name. '`')->results();
            // Store settings in dictionary format
            self::$_cached_settings = [];
            foreach ($result as $row) {
                self::$_cached_settings[$row->name] = $row->value;
            }
        }

        if (isset(self::$_cached_settings[$setting])) {
            return self::$_cached_settings[$setting];
        } else {
            return null;
        }
    }

    /**
     * Modify a setting in the database table `nl2_settings`.
     *
     * @param string $setting Setting name.
     * @param string $new_value New setting value, or null to delete
     * @param ?string $module Alphanumeric (no spaces!) module name to use as a settings table prefix. For example,
SQL query:
SELECT COUNT(*) AS count FROM nl2_phinxlog;
File: /var/www/cubedcraft/core/classes/Database/PhinxAdapter.php
<?php

class PhinxAdapter {

    /**
     * Checks the number of existing migration files compared to executed migrations in the database.
     * Alternatively we could check the output of a Phinx command, but that takes ~8x as long to execute.
     *
     * @throws RuntimeException If these numbers don't match.
     */
    public static function ensureUpToDate(): void {
        $migration_files = count(scandir(__DIR__ . '/../../migrations')) - 3; // -3 because of . and .. and phinx.php
        $migration_database_entries = DB::getInstance()->query('SELECT COUNT(*) AS count FROM nl2_phinxlog')->first()->count;

        if ($migration_files == $migration_database_entries) {
            return;
        }

        // Likely a pull from the repo dev branch or migrations
        // weren't run during an upgrade script.
        if (($diff = abs($migration_files - $migration_database_entries)) > 0) {
            throw new RuntimeException("There are {$diff} database migrations pending.");
        }

        // Something went wonky, either they've deleted migration files,
        // or they've added stuff to the nl2_phinxlog table.
        throw new RuntimeException("Inconsistent number of migration database entries ({$migration_database_entries}) and migration files ({$migration_files}).");
    }

    /**
     * Runs any pending migrations. Used for installation and upgrades. Resource heavy, only call when needed.
     *
     * @return string Output of the migration command from Phinx as if it was executed in the console.