Skip to content

Commit dbadd5c

Browse files
committed
improv. rewrite some codes
1 parent 0d6bcc3 commit dbadd5c

25 files changed

Lines changed: 253 additions & 228 deletions

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.9.0
1+
1.14.0

app/Controller/AdminController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ function admin_index()
3434
$count_visits_before_yesterday = $this->Visit->getVisitsByDay(date('Y-m-d', strtotime('-2 day')))['count'];
3535
$count_visits_yesterday = $this->Visit->getVisitsByDay(date('Y-m-d', strtotime('-1 day')))['count'];
3636
$count_visits_today = $this->Visit->getVisitsByDay(date('Y-m-d'))['count'];
37-
37+
$purchase = [];
38+
$purchase_today = [];
39+
$items_solded = [];
3840
if ($this->EyPlugin->isInstalled('eywek.shop')) {
3941

4042
$this->loadModel('Shop.ItemsBuyHistory');
@@ -54,7 +56,6 @@ function admin_index()
5456
'group' => 'item_id',
5557
'limit' => 5
5658
]);
57-
$items_solded = [];
5859
$i = 0;
5960

6061
foreach ($find_items_solded as $key => $value) {

app/Controller/AppController.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,10 @@ public function __initNavbar()
431431
{
432432
$this->loadModel('Navbar');
433433
$nav = $this->Navbar->find('all', ['order' => 'order']);
434-
if (empty($nav))
435-
return $this->set('nav', false);
434+
if (empty($nav)) {
435+
$this->set('nav', false);
436+
return;
437+
}
436438
$this->loadModel('Page');
437439
$pages = $this->Page->find('all', ['fields' => ['id', 'slug']]);
438440
foreach ($pages as $key => $value)
@@ -468,10 +470,14 @@ public function __initServerInfos()
468470
$server_infos = $this->Server->banner_infos();
469471
else if (!empty($configuration))
470472
$server_infos = $this->Server->banner_infos(unserialize($configuration));
471-
else
472-
return $this->set(['banner_server' => false, 'server_infos' => false]);
473-
if (!isset($server_infos['GET_MAX_PLAYERS']) || !isset($server_infos['GET_PLAYER_COUNT']) || $server_infos['GET_MAX_PLAYERS'] === 0)
474-
return $this->set(['banner_server' => false, 'server_infos' => $server_infos]);
473+
else {
474+
$this->set(['banner_server' => false, 'server_infos' => false]);
475+
return ;
476+
}
477+
if (!isset($server_infos['GET_MAX_PLAYERS']) || !isset($server_infos['GET_PLAYER_COUNT']) || $server_infos['GET_MAX_PLAYERS'] === 0) {
478+
$this->set(['banner_server' => false, 'server_infos' => $server_infos]);
479+
return;
480+
}
475481

476482
$this->set([
477483
'banner_server' => $this->Lang->get('SERVER__STATUS_MESSAGE', [

app/Controller/AuthentificationController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public function validLogin()
4444
$this->response->body(json_encode(['statut' => true, 'msg' => $this->Lang->get('USER__REGISTER_LOGIN')]));
4545
}
4646

47+
/**
48+
* @throws Exception
49+
*/
4750
public function generateSecret()
4851
{
4952
$this->response->type('json');
@@ -110,7 +113,5 @@ public function disable()
110113
$this->Authentification->read(null, $infos['Authentification']['id']);
111114
$this->Authentification->set(['enabled' => false]);
112115
$this->Authentification->save();
113-
// send to user
114-
$this->response->body(json_encode(['qrcode_url' => $qrCodeUrl, 'secret' => $secret]));
115116
}
116117
}

app/Controller/Component/DataTableComponent.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function initialize(Controller $controller)
5454
* @param object $controller optional
5555
* @param object $model optional
5656
* @return array
57+
* @throws Exception
5758
*/
5859
public function getResponse($controller = null, $model = null)
5960
{
@@ -235,7 +236,7 @@ private function getWhereConditions()
235236

236237
$conditions = [];
237238

238-
239+
$fields = [];
239240
if ($this->mDataProp == true) {
240241
for ($i = 0; $i < $this->controller->request->query['iColumns']; $i++) {
241242
if (!isset($this->controller->request->query['bSearchable_' . $i]) || $this->controller->request->query['bSearchable_' . $i] == true) {
@@ -295,6 +296,7 @@ private function getWhereConditions()
295296
*/
296297
private function conditionByDataType($field)
297298
{
299+
$condition = [];
298300
foreach ($this->model->validate[$field] as $rule => $j) {
299301
switch ($rule) {
300302
case 'boolean':
@@ -334,8 +336,6 @@ private function getDataRecursively($data, $key = null)
334336
//echo "$key.$x = $index = $i \n";
335337
// index needs to be a string so array_merge handles it properly
336338
$fields[chr($index)] = "$i";
337-
} else {
338-
//echo "$key.$x (NOT FOUND) \n";
339339
}
340340
} // dimension is not multi-dimensionable so add to $fields
341341
else if (isset($this->controller->paginate['fields'])) {
@@ -356,14 +356,15 @@ private function getDataRecursively($data, $key = null)
356356

357357
/**
358358
* getTimes method - returns an array of the components benchmarks
359-
* @return type
359+
* @return array
360360
*/
361361
public function getTimes()
362362
{
363363
$times = [];
364364
$componentStart = 0;
365+
$end = 0;
365366
foreach ($this->times as $x => $i) {
366-
$start = $end = $desc = $startLine = $endLine = 0;
367+
$start = $desc = 0;
367368
foreach ($i as $j) {
368369
if ($j['action'] == 'start') {
369370
$start = $j['time'];

app/Controller/Component/EyPluginComponent.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -351,17 +351,17 @@ private function editDatabaseWithSchema($slug, $type, $update = false)
351351
$pluginSchema = $this->Schema->load($options);
352352
$compare = $this->Schema->compare($currentSchema, $pluginSchema);
353353
unlink($options['path'] . DS . $options['file']);
354-
354+
$pluginTables = [];
355355
if ($type === 'CREATE') {
356356
// Check edits
357357
$contents = [];
358358
foreach ($compare as $table => $changes) {
359-
if (isset($compare[$table]['create'])) continue; // not handle create here
359+
if (isset($changes['create'])) continue; // not handle create here
360360

361-
if (!isset($compare[$table]['add'])) continue; // no add
361+
if (!isset($changes['add'])) continue; // no add
362362

363363
if (explode('__', $table)[0] != strtolower($slug)) { // other plugin
364-
foreach ($compare[$table]['add'] as $column => $structure) {
364+
foreach ($changes['add'] as $column => $structure) {
365365
if (explode('-', $column)[0] != strtolower($slug)) // other plugin
366366
unset($compare[$table]['add'][$column]);
367367
}
@@ -380,9 +380,9 @@ private function editDatabaseWithSchema($slug, $type, $update = false)
380380
$contents[$table] = $db->alterSchema([$table => $compare[$table]], $table);
381381
}
382382
// add tables
383-
$pluginTables = [];
383+
384384
foreach ($compare as $table => $changes) {
385-
if (isset($compare[$table]['create'])) { // is create
385+
if (isset($changes['create'])) { // is create
386386
$contents[$table] = $db->createSchema($pluginSchema, $table);
387387
$pluginTables[] = $table; // save for delete
388388
}
@@ -537,7 +537,7 @@ private function refreshPermissions()
537537
$defaultPermissions = $this->controller->Permissions->permissions;
538538
$pluginsPermissions = [];
539539

540-
foreach ($this->loadPlugins() as $id => $data) {
540+
foreach ($this->loadPlugins() as $data) {
541541
if (!isset($data->permissions->available)) continue; // no permissions on this plugin
542542
foreach ($data->permissions->available as $key => $permission) {
543543
$pluginsPermissions[] = $permission; // add permission to plugins permissions
@@ -596,7 +596,7 @@ public function loadPlugins()
596596
$pluginList->$id->slugLower = strtolower($plugin['name']);
597597
$pluginList->$id->DBid = $plugin['id'];
598598
$pluginList->$id->DBinstall = $plugin['created'];
599-
$pluginList->$id->active = ($plugin['state']) ? true : false;
599+
$pluginList->$id->active = $plugin['state'];
600600
if ($pluginList->$id->active)
601601
$count++;
602602
$pluginList->$id->isValid = $this->isValid($pluginList->$id->slug); // plugin valid

app/Controller/Component/LangComponent.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ public function update($JSON, $file)
345345

346346
$newContent['INFORMATIONS']['VERSION'] = $updatedContent['INFORMATIONS']['VERSION']; // on change la version
347347

348-
$path = end(explode('/', $file));
348+
$array = explode('/', $file);
349+
$path = end($array);
349350
$path = explode('.', $path)[0];
350351

351352
foreach ($fileContent['MESSAGES'] as $key => $value) { // on parcours les messages pour éventuellement les mettre à jours

app/Controller/Component/ServerComponent.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public function getConfig($server_id = false)
169169
return $this->config[$server_id];
170170

171171
$this->Configuration = $this->configModel;
172-
$configuration = $this->Configuration->find('first');
172+
$configuration = $this->Configuration->find();
173173
if ($configuration['Configuration']['server_state'] != 1)
174174
return $this->config[$server_id] = false;
175175

@@ -310,7 +310,7 @@ private function request($url, $data, $timeout = false)
310310
private function decryptWithKey($data, $iv)
311311
{
312312
if (!isset($this->key))
313-
$this->key = $this->configModel->find('first')['Configuration']['server_secretkey'];
313+
$this->key = $this->configModel->find()['Configuration']['server_secretkey'];
314314
$iv = base64_decode($iv);
315315
$data = base64_decode($data);
316316
return openssl_decrypt($data, 'AES-128-CBC', substr($this->key, 0, 16), OPENSSL_RAW_DATA, $iv);
@@ -370,7 +370,7 @@ public function online($server_id = false, $debug = false)
370370
if (!$config) // server not found
371371
return $this->online[$server_id] = false;
372372
if ($config['type'] == 1 || $config['type'] == 2 || $config['type'] == 3) // ping only
373-
return $this->online[$server_id] = ($this->ping(['ip' => $config['ip'], 'port' => $config['port'], 'udp' => $config['type'] == 3])) ? true : false;
373+
return $this->online[$server_id] = $this->ping(['ip' => $config['ip'], 'port' => $config['port'], 'udp' => $config['type'] == 3]);
374374
list($return, $code, $error) = $this->request($this->getUrl($server_id), $this->encryptWithKey("[]"));
375375
if ($return && $code === 200)
376376
return $this->online[$server_id] = true;
@@ -414,7 +414,7 @@ public function check($info, $value)
414414

415415
public function getSecretKey()
416416
{
417-
$config = $this->configModel->find('first');
417+
$config = $this->configModel->find();
418418
$key = $config['Configuration']['server_secretkey'];
419419
if (isset($key) && !empty($key))
420420
return $key;

app/Controller/Component/StatisticsComponent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function startup($controller)
7676
$this->Visit->set(['ip' => $ip, 'referer' => $referer, 'lang' => $language, 'navigator' => $user_agent, 'page' => "http://" . htmlentities($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'])]);
7777
$this->Visit->save();
7878
}
79-
CakeSession::write('visit_check', true, true, '1 day');
79+
CakeSession::write('visit_check', true);
8080
}
8181
}
8282

app/Controller/Component/ThemeComponent.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function getThemesInstalled($api = true)
8181
$bypassedFiles = ['.', '..', '.DS_Store', '__MACOSX', '.gitkeep']; // not a theme
8282
// set themes on $this->themesAvailable
8383
if ($api)
84-
$this->getThemesOnAPI(true);
84+
$this->getThemesOnAPI();
8585
// each installed themes
8686
foreach ($themes as $slug) {
8787
if (in_array($slug, $bypassedFiles)) // not a valid theme
@@ -93,7 +93,7 @@ public function getThemesInstalled($api = true)
9393
$id = strtolower($config->author . '.' . $config->slug);
9494
$themesList->$id = $config;
9595
$checkSupported = $this->checkSupported($slug);
96-
$themesList->$id->supported = (empty($checkSupported)) ? true : false;
96+
$themesList->$id->supported = empty($checkSupported);
9797
$themesList->$id->supportedErrors = $checkSupported;
9898
if ($this->isValid($slug))
9999
$themesList->$id->valid = true;
@@ -502,7 +502,7 @@ public function processCustomData($slug, $request)
502502
// on détermine si le thème est installé
503503
$finded = false;
504504
$themesInstalled = $this->getThemesInstalled(false);
505-
foreach ($themesInstalled as $id => $data) {
505+
foreach ($themesInstalled as $data) {
506506
if ($data->slug == $slug) {
507507
$finded = true;
508508
$config = $data->configurations;

0 commit comments

Comments
 (0)