/data/core/classes/Core/User.php
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`;
]);
Session::delete($this->_admSessionName);
Cookie::delete($this->_cookieName . '_adm');
}
/**
* Get the user's groups.
*
* @return array<int, Group> Their groups.
*/
public function getGroups(): array
{
if (isset($this->_groups)) {
return $this->_groups;
}
if (isset(self::$_group_cache[$this->data()->id])) {
$this->_groups = self::$_group_cache[$this->data()->id];
} else {
$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()) {
foreach ($groups_query->results() as $item) {
$this->_groups[$item->id] = new Group($item);
}
} else {
$this->_groups = [];
}
self::$_group_cache[$this->data()->id] = $this->_groups;
}
if (!count($this->_groups)) {
// Get default group
// TODO: Use PRE_VALIDATED_DEFAULT ?
$default_group = Group::find(1, 'default_group');
$default_group_id = $default_group->id ?? 1;
$this->addGroup($default_group_id);
}
/data/core/classes/Core/User.php
SELECT * FROM nl2_users WHERE `username` = 'AirJerr';
}
/**
* Find a user by unique identifier (username, ID, email, etc).
* Loads instance variables for this class.
*
* @param string $value Unique identifier.
* @param string $field What column to check for their unique identifier in.
*
* @return bool True/false on success or failure respectfully.
*/
private function find(string $value, string $field = 'id'): bool
{
if (isset(self::$_user_cache["$value.$field"])) {
$this->_data = self::$_user_cache["$value.$field"];
return true;
}
if ($field !== 'hash') {
$data = $this->_db->get('users', [$field, $value]);
} else {
$data = $this->_db->query(
<<<'SQL'
SELECT
nl2_users.*
FROM nl2_users
LEFT JOIN nl2_users_session
ON nl2_users.id = nl2_users_session.user_id
WHERE
nl2_users_session.hash = ?
AND nl2_users_session.active = 1
AND (
nl2_users_session.expires_at IS NULL
OR nl2_users_session.expires_at > ?
)
SQL,
[
$value,
time(),
]
/data/core/classes/Core/User.php
SELECT * FROM nl2_users WHERE `username` = 'capnelson';
}
/**
* Find a user by unique identifier (username, ID, email, etc).
* Loads instance variables for this class.
*
* @param string $value Unique identifier.
* @param string $field What column to check for their unique identifier in.
*
* @return bool True/false on success or failure respectfully.
*/
private function find(string $value, string $field = 'id'): bool
{
if (isset(self::$_user_cache["$value.$field"])) {
$this->_data = self::$_user_cache["$value.$field"];
return true;
}
if ($field !== 'hash') {
$data = $this->_db->get('users', [$field, $value]);
} else {
$data = $this->_db->query(
<<<'SQL'
SELECT
nl2_users.*
FROM nl2_users
LEFT JOIN nl2_users_session
ON nl2_users.id = nl2_users_session.user_id
WHERE
nl2_users_session.hash = ?
AND nl2_users_session.active = 1
AND (
nl2_users_session.expires_at IS NULL
OR nl2_users_session.expires_at > ?
)
SQL,
[
$value,
time(),
]
/data/core/classes/Core/User.php
SELECT * FROM nl2_users WHERE `username` = 'typhoon';
}
/**
* Find a user by unique identifier (username, ID, email, etc).
* Loads instance variables for this class.
*
* @param string $value Unique identifier.
* @param string $field What column to check for their unique identifier in.
*
* @return bool True/false on success or failure respectfully.
*/
private function find(string $value, string $field = 'id'): bool
{
if (isset(self::$_user_cache["$value.$field"])) {
$this->_data = self::$_user_cache["$value.$field"];
return true;
}
if ($field !== 'hash') {
$data = $this->_db->get('users', [$field, $value]);
} else {
$data = $this->_db->query(
<<<'SQL'
SELECT
nl2_users.*
FROM nl2_users
LEFT JOIN nl2_users_session
ON nl2_users.id = nl2_users_session.user_id
WHERE
nl2_users_session.hash = ?
AND nl2_users_session.active = 1
AND (
nl2_users_session.expires_at IS NULL
OR nl2_users_session.expires_at > ?
)
SQL,
[
$value,
time(),
]
/data/core/classes/Core/User.php
SELECT * FROM nl2_users WHERE `username` = 'Skidmark#95';
}
/**
* Find a user by unique identifier (username, ID, email, etc).
* Loads instance variables for this class.
*
* @param string $value Unique identifier.
* @param string $field What column to check for their unique identifier in.
*
* @return bool True/false on success or failure respectfully.
*/
private function find(string $value, string $field = 'id'): bool
{
if (isset(self::$_user_cache["$value.$field"])) {
$this->_data = self::$_user_cache["$value.$field"];
return true;
}
if ($field !== 'hash') {
$data = $this->_db->get('users', [$field, $value]);
} else {
$data = $this->_db->query(
<<<'SQL'
SELECT
nl2_users.*
FROM nl2_users
LEFT JOIN nl2_users_session
ON nl2_users.id = nl2_users_session.user_id
WHERE
nl2_users_session.hash = ?
AND nl2_users_session.active = 1
AND (
nl2_users_session.expires_at IS NULL
OR nl2_users_session.expires_at > ?
)
SQL,
[
$value,
time(),
]
/data/core/classes/Core/User.php
SELECT * FROM nl2_users WHERE `username` = 'PAL';
}
/**
* Find a user by unique identifier (username, ID, email, etc).
* Loads instance variables for this class.
*
* @param string $value Unique identifier.
* @param string $field What column to check for their unique identifier in.
*
* @return bool True/false on success or failure respectfully.
*/
private function find(string $value, string $field = 'id'): bool
{
if (isset(self::$_user_cache["$value.$field"])) {
$this->_data = self::$_user_cache["$value.$field"];
return true;
}
if ($field !== 'hash') {
$data = $this->_db->get('users', [$field, $value]);
} else {
$data = $this->_db->query(
<<<'SQL'
SELECT
nl2_users.*
FROM nl2_users
LEFT JOIN nl2_users_session
ON nl2_users.id = nl2_users_session.user_id
WHERE
nl2_users_session.hash = ?
AND nl2_users_session.active = 1
AND (
nl2_users_session.expires_at IS NULL
OR nl2_users_session.expires_at > ?
)
SQL,
[
$value,
time(),
]
/data/core/classes/Core/User.php
SELECT nl2_groups.* FROM nl2_users_groups INNER JOIN nl2_groups ON group_id = nl2_groups.id WHERE user_id = '3541' AND deleted = 0 ORDER BY `order`;
]);
Session::delete($this->_admSessionName);
Cookie::delete($this->_cookieName . '_adm');
}
/**
* Get the user's groups.
*
* @return array<int, Group> Their groups.
*/
public function getGroups(): array
{
if (isset($this->_groups)) {
return $this->_groups;
}
if (isset(self::$_group_cache[$this->data()->id])) {
$this->_groups = self::$_group_cache[$this->data()->id];
} else {
$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()) {
foreach ($groups_query->results() as $item) {
$this->_groups[$item->id] = new Group($item);
}
} else {
$this->_groups = [];
}
self::$_group_cache[$this->data()->id] = $this->_groups;
}
if (!count($this->_groups)) {
// Get default group
// TODO: Use PRE_VALIDATED_DEFAULT ?
$default_group = Group::find(1, 'default_group');
$default_group_id = $default_group->id ?? 1;
$this->addGroup($default_group_id);
}
/data/core/classes/Core/User.php
SELECT * FROM nl2_users WHERE `username` = 'Shadoe14';
}
/**
* Find a user by unique identifier (username, ID, email, etc).
* Loads instance variables for this class.
*
* @param string $value Unique identifier.
* @param string $field What column to check for their unique identifier in.
*
* @return bool True/false on success or failure respectfully.
*/
private function find(string $value, string $field = 'id'): bool
{
if (isset(self::$_user_cache["$value.$field"])) {
$this->_data = self::$_user_cache["$value.$field"];
return true;
}
if ($field !== 'hash') {
$data = $this->_db->get('users', [$field, $value]);
} else {
$data = $this->_db->query(
<<<'SQL'
SELECT
nl2_users.*
FROM nl2_users
LEFT JOIN nl2_users_session
ON nl2_users.id = nl2_users_session.user_id
WHERE
nl2_users_session.hash = ?
AND nl2_users_session.active = 1
AND (
nl2_users_session.expires_at IS NULL
OR nl2_users_session.expires_at > ?
)
SQL,
[
$value,
time(),
]
/data/core/classes/Core/User.php
SELECT * FROM nl2_users WHERE `username` = 'GhostSmoke';
}
/**
* Find a user by unique identifier (username, ID, email, etc).
* Loads instance variables for this class.
*
* @param string $value Unique identifier.
* @param string $field What column to check for their unique identifier in.
*
* @return bool True/false on success or failure respectfully.
*/
private function find(string $value, string $field = 'id'): bool
{
if (isset(self::$_user_cache["$value.$field"])) {
$this->_data = self::$_user_cache["$value.$field"];
return true;
}
if ($field !== 'hash') {
$data = $this->_db->get('users', [$field, $value]);
} else {
$data = $this->_db->query(
<<<'SQL'
SELECT
nl2_users.*
FROM nl2_users
LEFT JOIN nl2_users_session
ON nl2_users.id = nl2_users_session.user_id
WHERE
nl2_users_session.hash = ?
AND nl2_users_session.active = 1
AND (
nl2_users_session.expires_at IS NULL
OR nl2_users_session.expires_at > ?
)
SQL,
[
$value,
time(),
]
/data/core/classes/Core/User.php
SELECT * FROM nl2_users WHERE `username` = 'Wonderpants';
}
/**
* Find a user by unique identifier (username, ID, email, etc).
* Loads instance variables for this class.
*
* @param string $value Unique identifier.
* @param string $field What column to check for their unique identifier in.
*
* @return bool True/false on success or failure respectfully.
*/
private function find(string $value, string $field = 'id'): bool
{
if (isset(self::$_user_cache["$value.$field"])) {
$this->_data = self::$_user_cache["$value.$field"];
return true;
}
if ($field !== 'hash') {
$data = $this->_db->get('users', [$field, $value]);
} else {
$data = $this->_db->query(
<<<'SQL'
SELECT
nl2_users.*
FROM nl2_users
LEFT JOIN nl2_users_session
ON nl2_users.id = nl2_users_session.user_id
WHERE
nl2_users_session.hash = ?
AND nl2_users_session.active = 1
AND (
nl2_users_session.expires_at IS NULL
OR nl2_users_session.expires_at > ?
)
SQL,
[
$value,
time(),
]
/data/core/classes/Core/User.php
SELECT * FROM nl2_users WHERE `username` = 'Cobalt60-JaGr';
}
/**
* Find a user by unique identifier (username, ID, email, etc).
* Loads instance variables for this class.
*
* @param string $value Unique identifier.
* @param string $field What column to check for their unique identifier in.
*
* @return bool True/false on success or failure respectfully.
*/
private function find(string $value, string $field = 'id'): bool
{
if (isset(self::$_user_cache["$value.$field"])) {
$this->_data = self::$_user_cache["$value.$field"];
return true;
}
if ($field !== 'hash') {
$data = $this->_db->get('users', [$field, $value]);
} else {
$data = $this->_db->query(
<<<'SQL'
SELECT
nl2_users.*
FROM nl2_users
LEFT JOIN nl2_users_session
ON nl2_users.id = nl2_users_session.user_id
WHERE
nl2_users_session.hash = ?
AND nl2_users_session.active = 1
AND (
nl2_users_session.expires_at IS NULL
OR nl2_users_session.expires_at > ?
)
SQL,
[
$value,
time(),
]
/data/core/classes/Core/User.php
SELECT * FROM nl2_users WHERE `username` = 'B0k0';
}
/**
* Find a user by unique identifier (username, ID, email, etc).
* Loads instance variables for this class.
*
* @param string $value Unique identifier.
* @param string $field What column to check for their unique identifier in.
*
* @return bool True/false on success or failure respectfully.
*/
private function find(string $value, string $field = 'id'): bool
{
if (isset(self::$_user_cache["$value.$field"])) {
$this->_data = self::$_user_cache["$value.$field"];
return true;
}
if ($field !== 'hash') {
$data = $this->_db->get('users', [$field, $value]);
} else {
$data = $this->_db->query(
<<<'SQL'
SELECT
nl2_users.*
FROM nl2_users
LEFT JOIN nl2_users_session
ON nl2_users.id = nl2_users_session.user_id
WHERE
nl2_users_session.hash = ?
AND nl2_users_session.active = 1
AND (
nl2_users_session.expires_at IS NULL
OR nl2_users_session.expires_at > ?
)
SQL,
[
$value,
time(),
]
/data/core/classes/Core/User.php
SELECT * FROM nl2_users WHERE `username` = 'TheWolf';
}
/**
* Find a user by unique identifier (username, ID, email, etc).
* Loads instance variables for this class.
*
* @param string $value Unique identifier.
* @param string $field What column to check for their unique identifier in.
*
* @return bool True/false on success or failure respectfully.
*/
private function find(string $value, string $field = 'id'): bool
{
if (isset(self::$_user_cache["$value.$field"])) {
$this->_data = self::$_user_cache["$value.$field"];
return true;
}
if ($field !== 'hash') {
$data = $this->_db->get('users', [$field, $value]);
} else {
$data = $this->_db->query(
<<<'SQL'
SELECT
nl2_users.*
FROM nl2_users
LEFT JOIN nl2_users_session
ON nl2_users.id = nl2_users_session.user_id
WHERE
nl2_users_session.hash = ?
AND nl2_users_session.active = 1
AND (
nl2_users_session.expires_at IS NULL
OR nl2_users_session.expires_at > ?
)
SQL,
[
$value,
time(),
]
/data/core/classes/Core/User.php
SELECT * FROM nl2_users WHERE `username` = 'Juggernaut';
}
/**
* Find a user by unique identifier (username, ID, email, etc).
* Loads instance variables for this class.
*
* @param string $value Unique identifier.
* @param string $field What column to check for their unique identifier in.
*
* @return bool True/false on success or failure respectfully.
*/
private function find(string $value, string $field = 'id'): bool
{
if (isset(self::$_user_cache["$value.$field"])) {
$this->_data = self::$_user_cache["$value.$field"];
return true;
}
if ($field !== 'hash') {
$data = $this->_db->get('users', [$field, $value]);
} else {
$data = $this->_db->query(
<<<'SQL'
SELECT
nl2_users.*
FROM nl2_users
LEFT JOIN nl2_users_session
ON nl2_users.id = nl2_users_session.user_id
WHERE
nl2_users_session.hash = ?
AND nl2_users_session.active = 1
AND (
nl2_users_session.expires_at IS NULL
OR nl2_users_session.expires_at > ?
)
SQL,
[
$value,
time(),
]
/data/core/classes/Core/User.php
SELECT nl2_groups.* FROM nl2_users_groups INNER JOIN nl2_groups ON group_id = nl2_groups.id WHERE user_id = '5436' AND deleted = 0 ORDER BY `order`;
]);
Session::delete($this->_admSessionName);
Cookie::delete($this->_cookieName . '_adm');
}
/**
* Get the user's groups.
*
* @return array<int, Group> Their groups.
*/
public function getGroups(): array
{
if (isset($this->_groups)) {
return $this->_groups;
}
if (isset(self::$_group_cache[$this->data()->id])) {
$this->_groups = self::$_group_cache[$this->data()->id];
} else {
$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()) {
foreach ($groups_query->results() as $item) {
$this->_groups[$item->id] = new Group($item);
}
} else {
$this->_groups = [];
}
self::$_group_cache[$this->data()->id] = $this->_groups;
}
if (!count($this->_groups)) {
// Get default group
// TODO: Use PRE_VALIDATED_DEFAULT ?
$default_group = Group::find(1, 'default_group');
$default_group_id = $default_group->id ?? 1;
$this->addGroup($default_group_id);
}
/data/core/classes/Core/User.php
SELECT * FROM nl2_users WHERE `username` = 'dzifti';
}
/**
* Find a user by unique identifier (username, ID, email, etc).
* Loads instance variables for this class.
*
* @param string $value Unique identifier.
* @param string $field What column to check for their unique identifier in.
*
* @return bool True/false on success or failure respectfully.
*/
private function find(string $value, string $field = 'id'): bool
{
if (isset(self::$_user_cache["$value.$field"])) {
$this->_data = self::$_user_cache["$value.$field"];
return true;
}
if ($field !== 'hash') {
$data = $this->_db->get('users', [$field, $value]);
} else {
$data = $this->_db->query(
<<<'SQL'
SELECT
nl2_users.*
FROM nl2_users
LEFT JOIN nl2_users_session
ON nl2_users.id = nl2_users_session.user_id
WHERE
nl2_users_session.hash = ?
AND nl2_users_session.active = 1
AND (
nl2_users_session.expires_at IS NULL
OR nl2_users_session.expires_at > ?
)
SQL,
[
$value,
time(),
]
/data/modules/Reclamation/pages/round.php
SELECT players_rounds.*, username, playerprogress.crpt AS total_score FROM players_rounds LEFT JOIN playerprogress ON players_rounds.pid=playerprogress.pid WHERE round_id = '35412';
if (isset($directories[1]) && !empty($directories[1])){
$game_id = $directories[1];
}else {
require_once(ROOT_PATH . '/404.php');
die();
}
$query = Reclamation::getDB()->get('rounds', array('id', '=', $game_id));
if(!$query->count()) {
require_once(ROOT_PATH . '/404.php');
die();
}
$query = $query->first();
$server = new Server($query->hostname, 'prefix');
$i = 0;
$r = 0;
$players = array();
$game_results = Reclamation::getDB()->query('SELECT players_rounds.*, username, playerprogress.crpt AS total_score FROM players_rounds LEFT JOIN playerprogress ON players_rounds.pid=playerprogress.pid WHERE round_id = ?', [$query->id])->results();
foreach ($game_results as $item){
$target_user = new User($item->username, 'username');
if ($target_user->exists()) {
$style = $target_user->getGroupStyle();
$user_id = $target_user->data()->id;
} else {
$style = 'color: #6AA5D7;';
$user_id = null;
}
$players[] = array(
'rank' => $r++,
'player' => Output::getClean($item->username),
'avatar' => '',
'profile' => URL::build('/soldier/' . Output::getClean($item->username)),
'style' => $style,
'user_id' => $user_id,
'kills' => $item->klls,
'score' => $item->gsco,
'deaths' => $item->dths,
/data/modules/Reclamation/classes/Server.php
SELECT * FROM servers WHERE `prefix` = 'recl_es_1';
<?php
class Server {
private DB $_db;
private $_data;
// Construct server class
public function __construct($value = null, $field = 'id') {
$this->_db = Reclamation::getDB();
$data = $this->_db->get('servers', array($field, '=', $value));
if ($data->count()) {
$this->_data = $data->first();
}
}
/**
* Update a server data in the database.
*
* @param array $fields Column names and values to update.
*/
public function update($fields = []): void {
if (!$this->_db->update('servers', ['id', '=', $this->data()->id], $fields)) {
throw new Exception('There was a problem updating server');
}
}
/*
* Does this server exist?
*
* @return bool Whether the server exists (has data) or not.
/data/modules/Reclamation/pages/round.php
SELECT * FROM rounds WHERE `id` = '35412';
* NamelessMC version 2.0.0-pr9
*
* License: MIT
*
* Servers page
*/
// Always define page name
define('PAGE', 'servers');
$page_title = 'Servers';
require_once(ROOT_PATH . '/core/templates/frontend_init.php');
$timeago = new TimeAgo(TIMEZONE);
if (isset($directories[1]) && !empty($directories[1])){
$game_id = $directories[1];
}else {
require_once(ROOT_PATH . '/404.php');
die();
}
$query = Reclamation::getDB()->get('rounds', array('id', '=', $game_id));
if(!$query->count()) {
require_once(ROOT_PATH . '/404.php');
die();
}
$query = $query->first();
$server = new Server($query->hostname, 'prefix');
$i = 0;
$r = 0;
$players = array();
$game_results = Reclamation::getDB()->query('SELECT players_rounds.*, username, playerprogress.crpt AS total_score FROM players_rounds LEFT JOIN playerprogress ON players_rounds.pid=playerprogress.pid WHERE round_id = ?', [$query->id])->results();
foreach ($game_results as $item){
$target_user = new User($item->username, 'username');
if ($target_user->exists()) {
$style = $target_user->getGroupStyle();
$user_id = $target_user->data()->id;
} else {
$style = 'color: #6AA5D7;';
/data/core/templates/frontend_init.php
SELECT * FROM nl2_page_descriptions WHERE `page` = '/round/35412';
$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]);
if ($page_metadata->count()) {
$page_metadata = $page_metadata->first();
$template->getEngine()->addVariables([
'PAGE_DESCRIPTION' => str_replace('{site}', Output::getClean(SITE_NAME), addslashes(strip_tags($page_metadata->description))),
'PAGE_KEYWORDS' => addslashes(strip_tags($page_metadata->tags)),
]);
$og_image = $page_metadata->image;
if ($og_image) {
$template->getEngine()->addVariable('OG_IMAGE', rtrim(URL::getSelfURL(), '/') . $og_image);
}
} else {
$template->getEngine()->addVariables([
'PAGE_DESCRIPTION' => str_replace('{site}', Output::getClean(SITE_NAME), addslashes(strip_tags(Settings::get('default_meta_description', '')))),
'PAGE_KEYWORDS' => addslashes(strip_tags(Settings::get('default_meta_keywords', ''))),
]);
}
} else {
$template->getEngine()->addVariables([
'PAGE_DESCRIPTION' => str_replace('{site}', Output::getClean(SITE_NAME), addslashes(strip_tags(PAGE_DESCRIPTION))),
/data/core/init.php
SELECT * FROM nl2_groups WHERE `default_group` = '1';
: [DiscordHook::class, 'execute'],
'events' => json_decode($hook->events, true),
];
}
$cache->store('hooks', $hook_array);
}
}
}
EventHandler::registerWebhooks($hook_array);
// Get IP
$ip = HttpUtils::getRemoteAddress();
// Define default group pre validation
$cache->setCache('pre_validation_default');
$group_id = null;
if ($cache->isCached('pre_validation_default')) {
$group_id = $cache->retrieve('pre_validation_default');
} else {
$group_id = DB::getInstance()->get('groups', ['default_group', '1'])->results();
$group_id = $group_id[0]->id;
}
define('PRE_VALIDATED_DEFAULT', $group_id);
// Perform tasks if the user is logged in
if ($user->isLoggedIn()) {
Debugging::setCanViewDetailedError($user->hasPermission('admincp.errors'));
Debugging::setCanGenerateDebugLink($user->hasPermission('admincp.core.debugging'));
// Ensure a user is not banned
if ($user->data()->isbanned == 1) {
$user->logout();
Session::flash('home_error', $language->get('user', 'you_have_been_banned'));
Redirect::to(URL::build('/'));
}
// Is the IP address banned?
$ip_bans = DB::getInstance()->get('ip_bans', ['ip', $ip])->results();
if (count($ip_bans)) {
/data/core/classes/Integrations/IntegrationBase.php
SELECT * FROM nl2_integrations WHERE name = 'Discord';
* @author Partydragen
* @version 2.1.0
* @license MIT
*/
abstract class IntegrationBase
{
private DB $_db;
private IntegrationData $_data;
protected string $_icon;
private array $_errors = [];
protected Language $_language;
protected ?string $_settings = null;
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.
/data/core/classes/Integrations/IntegrationBase.php
SELECT * FROM nl2_integrations WHERE name = 'Patreon';
* @author Partydragen
* @version 2.1.0
* @license MIT
*/
abstract class IntegrationBase
{
private DB $_db;
private IntegrationData $_data;
protected string $_icon;
private array $_errors = [];
protected Language $_language;
protected ?string $_settings = null;
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.
/data/core/classes/Integrations/IntegrationBase.php
SELECT * FROM nl2_integrations WHERE name = 'BF2142';
* @author Partydragen
* @version 2.1.0
* @license MIT
*/
abstract class IntegrationBase
{
private DB $_db;
private IntegrationData $_data;
protected string $_icon;
private array $_errors = [];
protected Language $_language;
protected ?string $_settings = null;
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.
/data/core/classes/Core/Module.php
SELECT * FROM nl2_modules WHERE `name` = 'Core';
/**
* Get this module's ID.
*
* @return int The ID for the module
*/
public function getId(): int
{
return DB::getInstance()->query('SELECT `id` FROM nl2_modules WHERE `name` = ?', [$this->_name])->first()->id;
}
/**
* Get a module ID from name.
*
* @param string $name Module name
*
* @return ?int Module ID
*/
public static function getIdFromName(string $name): ?int
{
$query = DB::getInstance()->get('modules', ['name', $name]);
if ($query->count()) {
return $query->first()->id;
}
return null;
}
/**
* Get a module name from ID.
*
* @param int $id Module ID
*
* @return ?string Module name
*/
public static function getNameFromId(int $id): ?string
{
$query = DB::getInstance()->get('modules', ['id', $id]);
if ($query->count()) {
/data/core/classes/Integrations/IntegrationBase.php
SELECT * FROM nl2_integrations WHERE name = 'Google';
* @author Partydragen
* @version 2.1.0
* @license MIT
*/
abstract class IntegrationBase
{
private DB $_db;
private IntegrationData $_data;
protected string $_icon;
private array $_errors = [];
protected Language $_language;
protected ?string $_settings = null;
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.
/data/modules/Core/module.php
SELECT * FROM nl2_custom_pages_permissions WHERE `group_id` = '0';
$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');
/data/modules/Core/module.php
SELECT * FROM nl2_custom_pages WHERE `id` <> '0';
}
// "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', 'Support', '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();
/data/core/classes/Core/Settings.php
SELECT `name`, `value` FROM `nl2_settings` WHERE `module` IS NULL;
private static function setSettingsCache(?string $module, array $cache): void
{
$cache_name = $module !== null ? $module : 'core';
self::$_cached_settings[$cache_name] = $cache;
}
/**
* 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. Defaults to null.
* @param string $module Module name to keep settings separate from other modules. Set module
* to 'Core' for global settings.
* @return ?string Setting from DB or $fallback.
*/
public static function get(string $setting, ?string $fallback = null, string $module = 'core'): ?string
{
if (!self::hasSettingsCache($module)) {
// Load all settings for this module and store it as a dictionary
if ($module === 'core') {
$result = DB::getInstance()->query('SELECT `name`, `value` FROM `nl2_settings` WHERE `module` IS NULL')->results();
} else {
$result = DB::getInstance()->query('SELECT `name`, `value` FROM `nl2_settings` WHERE `module` = ?', [$module])->results();
}
$cache = [];
foreach ($result as $row) {
$cache[$row->name] = $row->value;
}
self::setSettingsCache($module, $cache);
}
$cache = &self::getSettingsCache($module);
return $cache[$setting] ?? $fallback;
}
/**
* Modify a setting in the database table `nl2_settings`.
*
* @param string $setting Setting name.
/data/core/classes/Database/PhinxAdapter.php
SELECT version, migration_name FROM nl2_phinxlog;
if (!$migrationDir) {
$migrationDir = __DIR__ . '/../../migrations';
}
$migration_files = array_map(
static function ($file_name) {
[$version, $migration_name] = explode('_', $file_name, 2);
$migration_name = str_replace(['.php', '_'], '', ucwords($migration_name, '_'));
return $version . '_' . $migration_name;
},
array_filter(scandir($migrationDir), static function ($file_name) {
// Pattern that matches Phinx migration file names (eg: 20230403000000_create_stroopwafel_table.php)
return preg_match('/^\d{14}_\w+\.php$/', $file_name);
}),
);
$migration_database_entries = array_map(static function ($row) {
return $row->version . '_' . $row->migration_name;
}, DB::getInstance()->query("SELECT version, migration_name FROM $table")->results());
$missing = array_diff($migration_files, $migration_database_entries);
$extra = array_diff($migration_database_entries, $migration_files);
if ($returnResults) {
return [
'missing' => count($missing),
'extra' => count($extra),
];
}
// Likely a pull from the repo dev branch or migrations
// weren't run during an upgrade script.
if (($missing_count = count($missing)) > 0) {
echo "There are $missing_count migrations files which have not been executed:" . '<br>';
foreach ($missing as $missing_migration) {
echo " - $missing_migration" . '<br>';
}
}