Skip to content

Commit

Permalink
merge dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Eywek committed Dec 28, 2020
2 parents 0870378 + 9a497a3 commit 52f4cb5
Show file tree
Hide file tree
Showing 39 changed files with 8,138 additions and 5,168 deletions.
1 change: 0 additions & 1 deletion .htaccess
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Expand Down
29 changes: 24 additions & 5 deletions app/Config/Schema/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public function after($event = array(), $install = false, $updateContent = array
'cape_free' => 0,
'cape_width' => '64',
'cape_height' => '32',
'get_premium_skins' => 1,
'use_skin_restorer' => 0,
'skin_restorer_server_id' => 0,
));
$api->save();

Expand Down Expand Up @@ -89,8 +92,8 @@ public function after($event = array(), $install = false, $updateContent = array
'end_layout_code' => null,
'check_uuid' => 0,
'captcha_type' => 1,
'captcha_google_sitekey' => null,
'captcha_google_secret' => null,
'captcha_sitekey' => null,
'captcha_secret' => null,
'confirm_mail_signup' => 0,
'confirm_mail_signup_block' => 0,
'member_page_type' => 0,
Expand Down Expand Up @@ -170,6 +173,9 @@ public function after($event = array(), $install = false, $updateContent = array
'cape_free' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 1, 'unsigned' => false),
'cape_width' => array('type' => 'integer', 'null' => true, 'default' => '64', 'unsigned' => false),
'cape_height' => array('type' => 'integer', 'null' => true, 'default' => '32', 'unsigned' => false),
'get_premium_skins' => array('type' => 'integer', 'null' => false, 'default' => '1', 'length' => 1, 'unsigned' => false),
'use_skin_restorer' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 1, 'unsigned' => false),
'skin_restorer_server_id' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 8, 'unsigned' => false),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => 1)
),
Expand Down Expand Up @@ -223,9 +229,9 @@ public function after($event = array(), $install = false, $updateContent = array
'google_analytics' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 15, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
'end_layout_code' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
'check_uuid' => array('type' => 'integer', 'null' => true, 'default' => '0', 'length' => 1, 'unsigned' => false),
'captcha_type' => array('type' => 'integer', 'null' => true, 'default' => '1', 'length' => 1, 'unsigned' => false, 'comment' => '1 = default, 2 = google'),
'captcha_google_sitekey' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 60, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
'captcha_google_secret' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 60, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
'captcha_type' => array('type' => 'integer', 'null' => true, 'default' => '1', 'length' => 1, 'unsigned' => false, 'comment' => '1 = default, 2 = google, 3 = h-captcha'),
'captcha_sitekey' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 60, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
'captcha_secret' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 60, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
'confirm_mail_signup' => array('type' => 'integer', 'null' => false, 'default' => 0, 'length' => 1, 'unsigned' => false),
'confirm_mail_signup_block' => array('type' => 'integer', 'null' => false, 'default' => 0, 'length' => 1, 'unsigned' => false),
'member_page_type' => array('type' => 'integer', 'null' => false, 'default' => 0, 'length' => 1, 'unsigned' => false),
Expand Down Expand Up @@ -378,6 +384,19 @@ public function after($event = array(), $install = false, $updateContent = array
'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB')
);

public $seo = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 20, 'unsigned' => false, 'key' => 'primary'),
'title' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 255, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
'description' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
'favicon_url' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 255, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
'img_url' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 255, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
'page' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 255, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => 1)
),
'tableParameters' => array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'InnoDB')
);

public $servers = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => true, 'key' => 'primary'),
'name' => array('type' => 'string', 'null' => false, 'length' => 20, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
Expand Down
113 changes: 60 additions & 53 deletions app/Controller/APIController.php
Original file line number Diff line number Diff line change
@@ -1,57 +1,64 @@
<?php

class APIController extends AppController {

public $components = array('Session', 'API');

public function launcher($username, $password, $args = null) {
$this->autoRender = false;
$this->response->type('json');
$args = explode(',', $args);
$this->response->body(json_encode($this->API->get($username, $password, $args)));
}

public function admin_index() {
if($this->isConnected AND $this->Permissions->can('MANAGE_API')) {
$this->set('title_for_layout',$this->Lang->get('API__LABEL'));
$this->layout = 'admin';

$this->loadModel('ApiConfiguration');
$config = $this->ApiConfiguration->find('first')['ApiConfiguration'];

if($this->request->is('post')) {
if(isset($this->request->data['skins']) AND isset($this->request->data['skin_free']) AND !empty($this->request->data['skin_filename']) AND isset($this->request->data['capes']) AND isset($this->request->data['cape_free']) AND !empty($this->request->data['cape_filename'])) {

$this->loadModel('ApiConfiguration');
$this->ApiConfiguration->read(null, 1);
$this->ApiConfiguration->set($this->request->data);
$this->ApiConfiguration->save();

$config = $this->request->data;

$this->History->set('EDIT_CONFIGURATION', 'api');
$this->Session->setFlash($this->Lang->get('CONFIG__EDIT_SUCCESS'), 'default.success');
} else {
$this->Session->setFlash($this->Lang->get('ERROR__FILL_ALL_FIELDS'), 'default.error');
}
}

$this->set('config', $config);
} else {
$this->redirect('/');
}
}

public function get_skin($name) {
header('Content-Type: image/png');
$this->autoRender = false;
echo $this->API->get_skin($name);
}

public function get_head_skin($name, $size = 50) {
header('Content-Type: image/png');
$this->autoRender = false;
echo $this->API->get_head_skin($name, $size);
}
class APIController extends AppController
{

public $components = array('Session', 'API');

public function launcher($username, $password, $args = null)
{
$this->autoRender = false;
$this->response->type('json');
$args = explode(',', $args);
$this->response->body(json_encode($this->API->get($username, $password, $args)));
}

public function admin_index()
{
if ($this->isConnected and $this->Permissions->can('MANAGE_API')) {
$this->set('title_for_layout', $this->Lang->get('API__LABEL'));
$this->layout = 'admin';

$this->loadModel('ApiConfiguration');
$config = $this->ApiConfiguration->find('first')['ApiConfiguration'];
$this->loadModel('Server');
$get_all_servers = $this->Server->findSelectableServers(false);

if ($this->request->is('post')) {
if (isset($this->request->data['skins']) and isset($this->request->data['skin_free']) and !empty($this->request->data['skin_filename']) and isset($this->request->data['capes']) and isset($this->request->data['cape_free']) and !empty($this->request->data['cape_filename'])) {

$this->loadModel('ApiConfiguration');
$this->ApiConfiguration->read(null, 1);
$this->ApiConfiguration->set($this->request->data);
$this->ApiConfiguration->save();

$config = $this->request->data;

$this->History->set('EDIT_CONFIGURATION', 'api');
$this->Session->setFlash($this->Lang->get('CONFIG__EDIT_SUCCESS'), 'default.success');
} else {
$this->Session->setFlash($this->Lang->get('ERROR__FILL_ALL_FIELDS'), 'default.error');
}
}
$this->set('get_all_servers', $get_all_servers);
$this->set('config', $config);
} else {
$this->redirect('/');
}
}

public function get_skin($name)
{
header('Content-Type: image/png');
$this->autoRender = false;
echo $this->API->get_skin($name);
}

public function get_head_skin($name, $size = 50)
{
header('Content-Type: image/png');
$this->autoRender = false;
echo $this->API->get_head_skin($name, $size);
}

}
11 changes: 11 additions & 0 deletions app/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,15 @@ function admin_index() {
}
}

public function admin_switchAdminDarkMode()
{
$this->autoRender = false;
if ($this->isConnected) {
$admin_dark_mode = $this->Cookie->read('use_admin_dark_mode');
$this->Cookie->write('use_admin_dark_mode', !$admin_dark_mode);
} else {
throw new ForbiddenException();
}
}

}
94 changes: 68 additions & 26 deletions app/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,16 @@ public function beforeFilter()
if ($event->isStopped())
return $event->result;
}
$LoginCondition = ($this->here != "/login") || !$this->EyPlugin->isInstalled('phpierre.signinup');
$LoginCondition = ($this->here != "/login") || !$this->EyPlugin->isInstalled('phpierre.signinup');
// Maintenance / Bans
if ($this->isConnected AND $this->User->getKey('rank') == 5 AND $this->params['controller'] != "maintenance" AND $this->params['action'] != "logout" AND $this->params['controller'] != "api")
// lowercase to avoid errors when the controller is called with uppercase
$this->params['controller'] = strtolower($this->params['controller']);
$this->params['action'] = strtolower($this->params['action']);
if ($this->isConnected and $this->User->getKey('rank') == 5 and $this->params['controller'] != "maintenance" and $this->params['action'] != "logout" and $this->params['controller'] != "api")
$this->redirect(array('controller' => 'maintenance', 'action' => 'index/banned', 'plugin' => false, 'admin' => false));
else if ($this->params['controller'] != "user" && $this->params['controller'] != "maintenance" && $this->Configuration->getKey('maintenance') != '0' && !$this->Permissions->can('BYPASS_MAINTENANCE') && $LoginCondition)
$this->redirect(array('controller' => 'maintenance', 'action' => 'index', 'plugin' => false, 'admin' => false));

}

public function __initConfiguration()
Expand Down Expand Up @@ -125,17 +129,30 @@ public function __initConfiguration()
// Variables
$google_analytics = $this->Configuration->getKey('google_analytics');
$configuration_end_code = $this->Configuration->getKey('end_layout_code');
$condition = $this->Configuration->getKey('condition');
$condition = $this->Configuration->getKey('condition');

$this->loadModel('SocialButton');
$findSocialButtons = $this->SocialButton->find('all');
$type = "";
switch ($this->Configuration->getKey('captcha_type')) {
case "1":
$type = "default";
break;
case "2":
$type = "google";
break;
case "3":
$type = "hcaptcha";
break;
}

$reCaptcha['type'] = ($this->Configuration->getKey('captcha_type') == '2') ? 'google' : 'default';
$reCaptcha['siteKey'] = $this->Configuration->getKey('captcha_google_sitekey');

$captcha['type'] = $type;
$captcha['siteKey'] = $this->Configuration->getKey('captcha_sitekey');
$reCaptcha = $captcha;
$this->set(compact(
'reCaptcha',
'condition',
'captcha',
'condition',
'website_name',
'theme_config',
'facebook_link',
Expand Down Expand Up @@ -213,16 +230,16 @@ public function __initAdminNavbar()
'permission' => 'MANAGE_CONFIGURATION',
'route' => ['controller' => 'configuration', 'action' => 'index', 'admin' => true, 'plugin' => false]
],
'STATS__TITLE' => [
'icon' => 'far fa-chart-bar',
'permission' => 'VIEW_STATISTICS',
'route' => ['controller' => 'statistics', 'action' => 'index', 'admin' => true, 'plugin' => false]
],
'MAINTENANCE__TITLE' => [
'icon' => 'fas fa-hand-paper',
'permission' => 'MANAGE_MAINTENANCE',
'route' => ['controller' => 'maintenance', 'action' => 'index', 'admin' => true, 'plugin' => false]
],
'STATS__TITLE' => [
'icon' => 'far fa-chart-bar',
'permission' => 'VIEW_STATISTICS',
'route' => ['controller' => 'statistics', 'action' => 'index', 'admin' => true, 'plugin' => false]
],
'MAINTENANCE__TITLE' => [
'icon' => 'fas fa-hand-paper',
'permission' => 'MANAGE_MAINTENANCE',
'route' => ['controller' => 'maintenance', 'action' => 'index', 'admin' => true, 'plugin' => false]
],
]
],
'GLOBAL__CUSTOMIZE' => [
Expand All @@ -243,6 +260,11 @@ public function __initAdminNavbar()
'permission' => 'MANAGE_NAV',
'route' => ['controller' => 'navbar', 'action' => 'index', 'admin' => true, 'plugin' => false]
],
'SEO__TITLE' => [
'icon' => 'fab fa-google',
'permission' => 'MANAGE_SEO',
'route' => ['controller' => 'seo', 'action' => 'index', 'admin' => true, 'plugin' => false]
],
'MOTD__TITLE' => [
'icon' => 'fas fa-sort-amount-up-alt',
'permission' => 'MANAGE_MOTD',
Expand Down Expand Up @@ -318,7 +340,8 @@ public function __initAdminNavbar()

// Functions
if (!function_exists('addToNav')) {
function addToArrayAt($where, $index, $array) {
function addToArrayAt($where, $index, $array)
{
return array_slice($where, 0, $index, true) +
$array +
array_slice($where, $index, count($where) - $index, true);
Expand Down Expand Up @@ -357,7 +380,7 @@ function addToNav($menus, $nav, $index = 0)
// Handle plugins
$plugins = $this->EyPlugin->pluginsLoaded;
foreach ($plugins as $plugin) {
if (!isset($plugin->admin_menus))
if (!isset($plugin->admin_menus) || !$plugin->active)
continue;
$menus = json_decode(json_encode($plugin->admin_menus), true);
$nav = addToNav($menus, $nav);
Expand Down Expand Up @@ -418,25 +441,27 @@ public function __initServerInfos()
'{ONLINE}' => @$server_infos['GET_PLAYER_COUNT'],
'{ONLINE_LIMIT}' => @$server_infos['GET_MAX_PLAYERS']
)), 'server_infos' => $server_infos]);

}

public function __initWebsiteInfos()
{
$this->loadModel('User');
$this->loadModel('Visit');
$users_count = $this->User->find('count');
$users_last = $this->User->find('first', array('order' =>'created DESC'));
$users_last = $this->User->find('first', array('order' => 'created DESC'));
$users_last = $users_last['User'];
$users_count_today = $this->User->find('count', array('conditions' => array('created LIKE' => date('Y-m-d').'%')));
$users_count_today = $this->User->find('count', array('conditions' => array('created LIKE' => date('Y-m-d') . '%')));
$visits_count = $this->Visit->getVisitsCount();
$visits_count_today = $this->Visit->getVisitsByDay(date('Y-m-d'))['count'];
$this->set(compact('users_count', 'users_last', 'users_count_today', 'visits_count', 'visits_count_today'));

$admin_dark_mode = $this->Cookie->read('use_admin_dark_mode');
$this->set(compact('users_count', 'users_last', 'users_count_today', 'visits_count', 'visits_count_today', 'admin_dark_mode'));

}

public function beforeRender()
{
$this->__initSeoConfiguration();
$event = new CakeEvent('onLoadPage', $this, $this->request->data);
$this->getEventManager()->dispatch($event);
if ($event->isStopped()) {
Expand All @@ -455,6 +480,22 @@ public function beforeRender()
$this->__setTheme();
}

public function __initSeoConfiguration()
{
$this->loadModel('Seo');
$default = $this->Seo->find('first', ["conditions" => ['page' => null]])['Seo'];
$current_url = $this->here;
$get_page = $this->Seo->find('first', ["conditions" => ['page' => $current_url]])['Seo'];
$seo_config['title'] = (!empty($get_page['title'])) ? $get_page['title'] : $default['title'];
$seo_config['description'] = (!empty($get_page['description'])) ? $get_page['description'] : $default['description'];
$seo_config['img_url'] = (!empty($get_page['img_url'])) ? $get_page['img_url'] : $default['img_url'];
$seo_config['favicon_url'] = (!empty($get_page['favicon_url'])) ? $get_page['favicon_url'] : $default['favicon_url'];
$seo_config['img_url'] = (empty($seo_config['img_url'])) ? $seo_config['favicon_url'] : $seo_config['img_url'];
$seo_config['title'] = str_replace(["{TITLE}", "{WEBSITE_NAME}"], [$this->viewVars['title_for_layout'], $this->viewVars['website_name']], $seo_config['title']);

$this->set(compact('seo_config'));
}

public function afterFilter()
{
$event = new CakeEvent('beforePageDisplay', $this, $this->request->data);
Expand All @@ -463,11 +504,12 @@ public function afterFilter()
$this->__setTheme();
return $event->result;
}

}

protected function __setTheme()
{
if (!isset($this->params['prefix']) OR $this->params['prefix'] !== "admin")
if (!isset($this->params['prefix']) or $this->params['prefix'] !== "admin")
$this->theme = Configure::read('theme');
}

Expand Down
Loading

0 comments on commit 52f4cb5

Please sign in to comment.