Commit 3e2a0d40 authored by Henning Leutz's avatar Henning Leutz 🥋

refactor: code performance and code style

parent e1c70d07
......@@ -13,7 +13,7 @@ QUI::$Ajax->registerFunction(
function ($control, $params = false) {
try {
$Control = new $control();
$params = json_decode($params, true);
$params = \json_decode($params, true);
/* @var $Control QUI\Control */
if ($params) {
......@@ -26,7 +26,7 @@ QUI::$Ajax->registerFunction(
);
}
if (!is_subclass_of($Control, '\QUI\Control')) {
if (!\is_subclass_of($Control, '\QUI\Control')) {
throw new QUI\Exception(
QUI::getLocale()->get('quiqqer/system', 'control.not.found'),
404
......@@ -35,5 +35,5 @@ QUI::$Ajax->registerFunction(
return $Control->create();
},
array('control', 'params')
['control', 'params']
);
......@@ -9,7 +9,7 @@ QUI::$Ajax->registerFunction(
'ajax_desktop_workspace_add',
function ($data) {
$User = QUI::getUserBySession();
$data = json_decode($data, true);
$data = \json_decode($data, true);
QUI\Workspace\Manager::addWorkspace(
$User,
......@@ -19,6 +19,6 @@ QUI::$Ajax->registerFunction(
$data['minWidth']
);
},
array('data'),
['data'],
'Permission::checkUser'
);
......@@ -9,12 +9,12 @@ QUI::$Ajax->registerFunction(
'ajax_desktop_workspace_delete',
function ($ids) {
$User = QUI::getUserBySession();
$ids = json_decode($ids, true);
$ids = \json_decode($ids, true);
foreach ($ids as $id) {
QUI\Workspace\Manager::deleteWorkspace($id, $User);
}
},
array('ids'),
['ids'],
'Permission::checkUser'
);
......@@ -10,10 +10,10 @@ QUI::$Ajax->registerFunction(
'ajax_desktop_workspace_edit',
function ($id, $data) {
$User = QUI::getUserBySession();
$data = json_decode($data, true);
$data = \json_decode($data, true);
QUI\Workspace\Manager::saveWorkspace($User, $id, $data);
},
array('id', 'data'),
['id', 'data'],
'Permission::checkUser'
);
......@@ -10,14 +10,14 @@
QUI::$Ajax->registerFunction(
'ajax_editor_get_toolbar_xml',
function ($toolbar) {
$file = QUI\Editor\Manager::getToolbarsPath() . $toolbar;
$file = QUI\Editor\Manager::getToolbarsPath().$toolbar;
$file = QUI\Utils\Security\Orthos::clearPath($file);
if (file_exists($file)) {
return file_get_contents($file);
if (\file_exists($file)) {
return \file_get_contents($file);
}
return '';
},
array('toolbar')
['toolbar']
);
......@@ -9,14 +9,14 @@
QUI::$Ajax->registerFunction(
'ajax_groups_activate',
function ($gid) {
$gid = json_decode($gid, true);
$gid = \json_decode($gid, true);
if (!is_array($gid)) {
$gid = array($gid);
if (!\is_array($gid)) {
$gid = [$gid];
}
$Groups = QUI::getGroups();
$result = array();
$result = [];
foreach ($gid as $_gid) {
try {
......@@ -35,6 +35,6 @@ QUI::$Ajax->registerFunction(
return $result;
},
array('gid'),
['gid'],
'Permission::checkSU'
);
......@@ -10,7 +10,7 @@
QUI::$Ajax->registerFunction(
'ajax_groups_addUsers',
function ($gid, $userIds) {
$userIds = json_decode($userIds, true);
$userIds = \json_decode($userIds, true);
$Group = QUI::getGroups()->get((int)$gid);
foreach ($userIds as $userId) {
......@@ -19,6 +19,6 @@ QUI::$Ajax->registerFunction(
$User->save();
}
},
array('gid', 'userIds'),
['gid', 'userIds'],
'Permission::checkSU'
);
......@@ -9,14 +9,14 @@
QUI::$Ajax->registerFunction(
'ajax_groups_deactivate',
function ($gid) {
$gid = json_decode($gid, true);
$gid = \json_decode($gid, true);
if (!is_array($gid)) {
$gid = array($gid);
if (!\is_array($gid)) {
$gid = [$gid];
}
$Groups = QUI::getGroups();
$result = array();
$result = [];
foreach ($gid as $_gid) {
try {
......@@ -35,6 +35,6 @@ QUI::$Ajax->registerFunction(
return $result;
},
array('gid'),
['gid'],
'Permission::checkSU'
);
......@@ -9,10 +9,10 @@
QUI::$Ajax->registerFunction(
'ajax_groups_delete',
function ($gids) {
$gids = json_decode($gids, true);
$gids = \json_decode($gids, true);
$Groups = QUI::getGroups();
if (!is_array($gids)) {
if (!\is_array($gids)) {
$gids = [$gids];
}
......@@ -36,7 +36,7 @@ QUI::$Ajax->registerFunction(
}
if (!empty($result)) {
if (count($result) === 1) {
if (\count($result) === 1) {
QUI::getMessagesHandler()->addSuccess(
QUI::getLocale()->get('quiqqer/quiqqer', 'message.group.deleted', [
'groupname' => $names[0],
......@@ -46,20 +46,20 @@ QUI::$Ajax->registerFunction(
} else {
QUI::getMessagesHandler()->addSuccess(
QUI::getLocale()->get('quiqqer/quiqqer', 'message.groups.deleted', [
'groups' => implode(', ', $result)
'groups' => \implode(', ', $result)
])
);
}
}
if (!$ExceptionStack->isEmpty()) {
$message = array_map(function ($Exception) {
$message = \array_map(function ($Exception) {
/* @var $Exception QUI\Exception */
return $Exception->getMessage();
}, $ExceptionStack->getExceptionList());
QUI::getMessagesHandler()->addAttention(
implode("<br>", $message)
\implode("<br>", $message)
);
}
......
......@@ -11,7 +11,7 @@ QUI::$Ajax->registerFunction(
'ajax_groups_list',
function ($params) {
$Groups = QUI::getGroups();
$params = json_decode($params, true);
$params = \json_decode($params, true);
$page = 1;
$limit = 10;
......@@ -42,12 +42,12 @@ QUI::$Ajax->registerFunction(
}
}
return array(
return [
'total' => $Groups->count($params),
'page' => $page,
'data' => $search
);
];
},
array('params'),
['params'],
'Permission::checkAdminUser'
);
......@@ -10,7 +10,7 @@
QUI::$Ajax->registerFunction(
'ajax_groups_removeUsers',
function ($gid, $userIds) {
$userIds = json_decode($userIds, true);
$userIds = \json_decode($userIds, true);
$Group = QUI::getGroups()->get((int)$gid);
foreach ($userIds as $userId) {
......@@ -19,6 +19,6 @@ QUI::$Ajax->registerFunction(
$User->save();
}
},
array('gid', 'userIds'),
['gid', 'userIds'],
'Permission::checkSU'
);
......@@ -13,8 +13,8 @@ QUI::$Ajax->registerFunction(
$Groups = QUI::getGroups();
$Group = $Groups->get((int)$gid);
$attributes = json_decode($attributes, true);
$rights = json_decode($rights, true);
$attributes = \json_decode($attributes, true);
$rights = \json_decode($rights, true);
$Group->setRights($rights);
$Group->setAttributes($attributes);
......@@ -33,12 +33,12 @@ QUI::$Ajax->registerFunction(
}
QUI::getMessagesHandler()->addSuccess(
QUI::getLocale()->get('quiqqer/quiqqer', 'message.group.saved', array(
QUI::getLocale()->get('quiqqer/quiqqer', 'message.group.saved', [
'groupname' => $Group->getName(),
'id' => $Group->getId()
))
])
);
},
array('gid', 'attributes', 'rights'),
['gid', 'attributes', 'rights'],
'Permission::checkSU'
);
......@@ -10,13 +10,13 @@ QUI::$Ajax->registerFunction(
'ajax_groups_search',
function ($fields, $params) {
$Groups = QUI::getGroups();
$params = json_decode($params, true);
$fields = json_decode($fields, true);
$query = array();
$params = \json_decode($params, true);
$fields = \json_decode($fields, true);
$query = [];
$page = 1;
if (!is_array($fields)) {
$fields = array();
if (!\is_array($fields)) {
$fields = [];
}
if (isset($params['order'])) {
......@@ -28,10 +28,10 @@ QUI::$Ajax->registerFunction(
}
foreach ($fields as $field => $value) {
$query['where_or'][$field] = array(
$query['where_or'][$field] = [
'type' => '%LIKE%',
'value' => $value
);
];
}
$Grid = new QUI\Utils\Grid();
......@@ -39,6 +39,6 @@ QUI::$Ajax->registerFunction(
return $Grid->parseResult($Groups->search($query), $Groups->count($params));
},
array('fields', 'params'),
['fields', 'params'],
'Permission::checkAdminUser'
);
......@@ -9,14 +9,14 @@
QUI::$Ajax->registerFunction(
'ajax_groups_switchstatus',
function ($gid) {
$gid = json_decode($gid, true);
$gid = \json_decode($gid, true);
if (!is_array($gid)) {
$gid = array($gid);
if (!\is_array($gid)) {
$gid = [$gid];
}
$Groups = QUI::getGroups();
$result = array();
$result = [];
foreach ($gid as $_gid) {
try {
......@@ -40,6 +40,6 @@ QUI::$Ajax->registerFunction(
return $result;
},
array('gid'),
['gid'],
'Permission::checkSU'
);
......@@ -10,7 +10,7 @@
QUI::$Ajax->registerFunction(
'ajax_groups_users',
function ($gid, $params) {
$params = json_decode($params, true);
$params = \json_decode($params, true);
$start = 0;
$page = 1;
......@@ -36,7 +36,7 @@ QUI::$Ajax->registerFunction(
$start = (int)$params['start'];
}
$params['limit'] = $start . ', ' . $limit;
$params['limit'] = $start.', '.$limit;
}
// order
......@@ -48,11 +48,11 @@ QUI::$Ajax->registerFunction(
case 'lasttname':
case 'email':
case 'regdate':
$params['order'] = $params['field'] . ' ' . $params['order'];
$params['order'] = $params['field'].' '.$params['order'];
break;
default:
$params['order'] = 'username ' . $params['order'];
$params['order'] = 'username '.$params['order'];
break;
}
}
......@@ -63,10 +63,10 @@ QUI::$Ajax->registerFunction(
// search users
$users = QUI::getGroups()->get($gid)->getUsers($params);
$result = array();
$result = [];
foreach ($users as $user) {
$result[] = array(
$result[] = [
'id' => $user['id'],
'active' => $user['active'],
'username' => $user['username'],
......@@ -74,7 +74,7 @@ QUI::$Ajax->registerFunction(
'firstname' => $user['firstname'],
'lastname' => $user['lastname'],
'regdate' => $user['regdate']
);
];
}
// count users
......@@ -83,12 +83,12 @@ QUI::$Ajax->registerFunction(
$count = QUI::getGroups()->get($gid)->getUsers($params);
return array(
return [
'total' => isset($count[0]['cu']) ? $count[0]['cu'] : 0,
'page' => $page,
'data' => $result
);
];
},
array('gid', 'params'),
['gid', 'params'],
'Permission::checkSU'
);
......@@ -8,9 +8,9 @@
QUI::$Ajax->registerFunction(
'ajax_licenseKey_delete',
function () {
$licenseConfigFile = CMS_DIR . 'etc/license.ini.php';
$licenseConfigFile = CMS_DIR.'etc/license.ini.php';
if (!file_exists($licenseConfigFile)) {
if (!\file_exists($licenseConfigFile)) {
QUI::getMessagesHandler()->addError(
QUI::getLocale()->get(
'quiqqer/system',
......@@ -21,7 +21,7 @@ QUI::$Ajax->registerFunction(
return false;
}
unlink($licenseConfigFile);
\unlink($licenseConfigFile);
// re-create composer.json
QUI::getPackageManager()->refreshServerList();
......@@ -35,6 +35,6 @@ QUI::$Ajax->registerFunction(
return true;
},
array(),
[],
'Permission::checkAdminUser'
);
......@@ -12,30 +12,30 @@ use QUI\Config;
QUI::$Ajax->registerFunction(
'ajax_licenseKey_get',
function () {
$licenseConfigFile = CMS_DIR . 'etc/license.ini.php';
$default = array(
$licenseConfigFile = CMS_DIR.'etc/license.ini.php';
$default = [
'id' => '-',
'created' => '-',
'validUntil' => '-',
'name' => '-',
);
];
if (!file_exists($licenseConfigFile)) {
if (!\file_exists($licenseConfigFile)) {
return $default;
}
$LicenseConfig = new Config($licenseConfigFile);
$data = array_merge($default, $LicenseConfig->getSection('license'));
$data = \array_merge($default, $LicenseConfig->getSection('license'));
if (isset($data['created'])) {
$data['created'] = date('Y-m-d', (int)$data['created']);
$data['created'] = \date('Y-m-d', (int)$data['created']);
}
if (isset($data['validUntil'])) {
if ($data['validUntil'] === 'forever') {
$data['validUntil'] = QUI::getLocale()->get('quiqqer/system', 'quiqqer.licenseKey.unlimited');
} else {
$data['validUntil'] = date('Y-m-d', (int)$data['validUntil']);
$data['validUntil'] = \date('Y-m-d', (int)$data['validUntil']);
}
}
......@@ -43,6 +43,6 @@ QUI::$Ajax->registerFunction(
return $data;
},
array(),
[],
'Permission::checkAdminUser'
);
......@@ -12,9 +12,9 @@ use QUI\Config;
QUI::$Ajax->registerFunction(
'ajax_licenseKey_getAuthData',
function () {
$licenseConfigFile = CMS_DIR . 'etc/license.ini.php';
$licenseConfigFile = CMS_DIR.'etc/license.ini.php';
if (!file_exists($licenseConfigFile)) {
if (!\file_exists($licenseConfigFile)) {
return false;
}
......@@ -28,14 +28,14 @@ QUI::$Ajax->registerFunction(
}
$hash = $data['licenseHash'];
$hash = hex2bin($hash);
$hash = bin2hex(Encryption::decrypt($hash));
$hash = \hex2bin($hash);
$hash = \bin2hex(Encryption::decrypt($hash));
return array(
return [
'licenseId' => $data['id'],
'licenseHash' => $hash
);
];
},
array(),
[],
'Permission::checkAdminUser'
);
......@@ -15,42 +15,42 @@ QUI::$Ajax->registerFunction(
'ajax_licenseKey_upload',
function ($File) {
try {
$content = file_get_contents($File->getAttribute('filepath'));
$content = json_decode(hex2bin($content), true);
$content = \file_get_contents($File->getAttribute('filepath'));
$content = \json_decode(hex2bin($content), true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new QUI\Exception('JSON Error in license data: ' . json_last_error_msg());
if (\json_last_error() !== JSON_ERROR_NONE) {
throw new QUI\Exception('JSON Error in license data: '.\json_last_error_msg());
}
$keys = array(
$keys = [
'id',
'created',
'licenseHash',
'licenseServer',
'validUntil',
'name'
);
];
foreach ($keys as $key) {
if (!isset($content[$key])) {
throw new QUI\Exception('Missing key "' . $key . '" in license data.');
throw new QUI\Exception('Missing key "'.$key.'" in license data.');
}
if (empty($content[$key])) {
throw new QUI\Exception('Empty key "' . $key . '" in license data.');
throw new QUI\Exception('Empty key "'.$key.'" in license data.');
}
if (!is_string($content[$key])) {
throw new QUI\Exception('Non-string key "' . $key . '" in license data.');
throw new QUI\Exception('Non-string key "'.$key.'" in license data.');
}
}
// put license data in config
$licenseConfigFile = CMS_DIR . 'etc/license.ini.php';
$licenseConfigFile = CMS_DIR.'etc/license.ini.php';
File::mkfile($licenseConfigFile);
if (!file_exists($licenseConfigFile)) {
throw new QUI\Exception('Could not create license config file "' . $licenseConfigFile . '"');
if (!\file_exists($licenseConfigFile)) {
throw new QUI\Exception('Could not create license config file "'.$licenseConfigFile.'"');
}
$LicenseConfig = new Config($licenseConfigFile);
......@@ -62,13 +62,13 @@ QUI::$Ajax->registerFunction(
$LicenseConfig->set(
'license',
'licenseHash',
bin2hex(Encryption::encrypt(hex2bin($content['licenseHash'])))
\bin2hex(Encryption::encrypt(\hex2bin($content['licenseHash'])))
);
$LicenseConfig->save($licenseConfigFile);
// set license server
$Config = new QUI\Config(ETC_DIR . 'conf.ini.php');
$Config = new QUI\Config(ETC_DIR.'conf.ini.php');
$Config->set('license', 'url', $content['licenseServer']);
$Config->save();
......@@ -95,6 +95,6 @@ QUI::$Ajax->registerFunction(
)
);
},
array('File'),
['File'],
'Permission::checkAdminUser'
);
......@@ -12,13 +12,13 @@
QUI::$Ajax->registerFunction(
'ajax_media_activate',
function ($project, $fileid) {
$fileid = json_decode($fileid, true);
$fileid = \json_decode($fileid, true);
$Project = QUI\Projects\Manager::getProject($project);
$Media = $Project->getMedia();
if (is_array($fileid)) {
$result = array();
if (\is_array($fileid)) {
$result = [];
foreach ($fileid as $id) {
try {
......@@ -39,6 +39,6 @@ QUI::$Ajax->registerFunction(
return $File->isActive();
},
array('project', 'fileid'),
['project', 'fileid'],
'Permission::checkAdminUser'
);
......@@ -16,7 +16,7 @@ QUI::$Ajax->registerFunction(
$Media = $Project->getMedia();
$Folder = $Media->get($to);
$ids = json_decode($ids, true);
$ids = \json_decode($ids, true);
if (!QUI\Projects\Media\Utils::isFolder($Folder)) {
throw new QUI\Exception(
......@@ -36,6 +36,6 @@ QUI::$Ajax->registerFunction(
}
}
},
array('project', 'to', 'ids'),
['project', 'to', 'ids'],
'Permission::checkAdminUser'
);
......@@ -12,13 +12,13 @@
QUI::$Ajax->registerFunction(
'ajax_media_deactivate',
function ($project, $fileid) {
$fileid = json_decode($fileid, true);
$fileid = \json_decode($fileid, true);
$Project = QUI\Projects\Manager::getProject($project);
$Media = $Project->getMedia();
if (is_array($fileid)) {
$result = array();
if (\is_array($fileid)) {
$result = [];
foreach ($fileid as $id) {
try {
......@@ -39,6 +39,6 @@ QUI::$Ajax->registerFunction(
return $File->isActive();
},
array('project', 'fileid'),
['project', 'fileid'],
'Permission::checkAdminUser'
);
......@@ -11,11 +11,11 @@
QUI::$Ajax->registerFunction(
'ajax_media_delete',
function ($project, $fileid) {
$fileid = json_decode($fileid, true);
$fileid = \json_decode($fileid, true);
$Project = QUI\Projects\Manager::getProject($project);
$Media = $Project->getMedia();
if (is_array($fileid)) {
if (\is_array($fileid)) {
foreach ($fileid as $id) {