Updated compatibility of arrays with PHP 5.x.
* Added array() instead of just []. * Created a new variable for function_call()[] type of array calling. * The both forms are not supported in PHP 5.x.
This commit is contained in:
parent
e83a60b06d
commit
3f6ded3fe8
@ -78,7 +78,7 @@ $app->post('/boards/remove', function() use($app, $jsonResponse) {
|
|||||||
R::trashAll($board->xownCategory);
|
R::trashAll($board->xownCategory);
|
||||||
R::trashAll($board->xownAutoaction);
|
R::trashAll($board->xownAutoaction);
|
||||||
R::trash($board);
|
R::trash($board);
|
||||||
R::exec('DELETE from board_user WHERE board_id = ?', [$data->boardId]);
|
R::exec('DELETE from board_user WHERE board_id = ?', array($data->boardId));
|
||||||
$jsonResponse->addAlert('success', 'Removed board ' . $board->name . '.');
|
$jsonResponse->addAlert('success', 'Removed board ' . $board->name . '.');
|
||||||
$actor = getUser();
|
$actor = getUser();
|
||||||
logAction($actor->username . ' removed board ' . $board->name, $before, null);
|
logAction($actor->username . ' removed board ' . $board->name, $before, null);
|
||||||
@ -139,7 +139,7 @@ $app->post('/lanes/:laneId/toggle', function($laneId) use($app, $jsonResponse) {
|
|||||||
if (validateToken()) {
|
if (validateToken()) {
|
||||||
$user = getUser();
|
$user = getUser();
|
||||||
$lane = R::load('lane', $laneId);
|
$lane = R::load('lane', $laneId);
|
||||||
$collapsed = R::findOne('collapsed', ' user_id = ? AND lane_id = ? ', [$user->id, $laneId]);
|
$collapsed = R::findOne('collapsed', ' user_id = ? AND lane_id = ? ', array($user->id, $laneId));
|
||||||
|
|
||||||
if (null != $collapsed) {
|
if (null != $collapsed) {
|
||||||
R::trash($collapsed);
|
R::trash($collapsed);
|
||||||
@ -155,7 +155,7 @@ $app->post('/lanes/:laneId/toggle', function($laneId) use($app, $jsonResponse) {
|
|||||||
$jsonResponse->addBeans(getBoards());
|
$jsonResponse->addBeans(getBoards());
|
||||||
}
|
}
|
||||||
$app->response->setBody($jsonResponse->asJson());
|
$app->response->setBody($jsonResponse->asJson());
|
||||||
})->conditions(['laneId' => '\d+']); // Numbers only.
|
})->conditions(array('laneId' => '\d+')); // Numbers only.
|
||||||
|
|
||||||
$app->post('/boards/:boardId/toggleActive', function($boardId) use($app, $jsonResponse) {
|
$app->post('/boards/:boardId/toggleActive', function($boardId) use($app, $jsonResponse) {
|
||||||
if (validateToken()) {
|
if (validateToken()) {
|
||||||
@ -175,4 +175,4 @@ $app->post('/boards/:boardId/toggleActive', function($boardId) use($app, $jsonRe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$app->response->setBody($jsonResponse->asJson());
|
$app->response->setBody($jsonResponse->asJson());
|
||||||
})->conditions(['boardId' => '\d+']); // Numbers only.
|
})->conditions(array('boardId' => '\d+')); // Numbers only.
|
||||||
|
@ -40,7 +40,7 @@ function setUserToken($user, $expires) {
|
|||||||
$dbToken->token = $token;
|
$dbToken->token = $token;
|
||||||
|
|
||||||
if (null == $user->ownToken) {
|
if (null == $user->ownToken) {
|
||||||
$user->ownToken = [];
|
$user->ownToken = array();
|
||||||
}
|
}
|
||||||
$user->ownToken[] = $dbToken;
|
$user->ownToken[] = $dbToken;
|
||||||
|
|
||||||
@ -50,9 +50,9 @@ function setUserToken($user, $expires) {
|
|||||||
// Get the user making the current request.
|
// Get the user making the current request.
|
||||||
function getUser() {
|
function getUser() {
|
||||||
global $jsonResponse;
|
global $jsonResponse;
|
||||||
|
$gah = getallheaders();
|
||||||
if (isset(getallheaders()['Authorization'])) {
|
if (isset($gah['Authorization'])) {
|
||||||
$hash = getallheaders()['Authorization'];
|
$hash = $gah['Authorization'];
|
||||||
try {
|
try {
|
||||||
$payload = JWT::decode($hash, getJwtKey());
|
$payload = JWT::decode($hash, getJwtKey());
|
||||||
$user = R::load('user', $payload->uid);
|
$user = R::load('user', $payload->uid);
|
||||||
@ -94,7 +94,8 @@ function getLaneByID($id) {
|
|||||||
// Get all users.
|
// Get all users.
|
||||||
function getUsers($sanitize = true) {
|
function getUsers($sanitize = true) {
|
||||||
try {
|
try {
|
||||||
$hash = getallheaders()['Authorization'];
|
$gah = getallheaders();
|
||||||
|
$hash = $gah['Authorization'];
|
||||||
$payload = JWT::decode($hash, getJwtKey());
|
$payload = JWT::decode($hash, getJwtKey());
|
||||||
|
|
||||||
$users = R::findAll('user');
|
$users = R::findAll('user');
|
||||||
@ -153,7 +154,7 @@ function getBoards() {
|
|||||||
if ($user->isAdmin) {
|
if ($user->isAdmin) {
|
||||||
return $boards;
|
return $boards;
|
||||||
} else {
|
} else {
|
||||||
$filteredBoards = [];
|
$filteredBoards = array();
|
||||||
foreach($boards as $board) {
|
foreach($boards as $board) {
|
||||||
foreach($board->sharedUser as $boardUser) {
|
foreach($board->sharedUser as $boardUser) {
|
||||||
if ($user->username == $boardUser->username) {
|
if ($user->username == $boardUser->username) {
|
||||||
@ -167,7 +168,7 @@ function getBoards() {
|
|||||||
|
|
||||||
// Finds the removed IDs for updating a board.
|
// Finds the removed IDs for updating a board.
|
||||||
function getIdsToRemove($boardList, $dataList) {
|
function getIdsToRemove($boardList, $dataList) {
|
||||||
$retVal = [];
|
$retVal = array();
|
||||||
foreach($boardList as $item) {
|
foreach($boardList as $item) {
|
||||||
$remove = true;
|
$remove = true;
|
||||||
foreach($dataList as $newItem) {
|
foreach($dataList as $newItem) {
|
||||||
@ -199,7 +200,7 @@ function loadBoardData($board, $data) {
|
|||||||
$lane->position = intval($item->position);
|
$lane->position = intval($item->position);
|
||||||
|
|
||||||
if (null == $lane->ownItems) {
|
if (null == $lane->ownItems) {
|
||||||
$lane->ownItems = [];
|
$lane->ownItems = array();
|
||||||
}
|
}
|
||||||
// New lane, add it to the board
|
// New lane, add it to the board
|
||||||
if (!$lane->id) {
|
if (!$lane->id) {
|
||||||
@ -246,14 +247,14 @@ function loadBoardData($board, $data) {
|
|||||||
// Clean a user bean for return to front-end.
|
// Clean a user bean for return to front-end.
|
||||||
function sanitize($user) {
|
function sanitize($user) {
|
||||||
$user['salt'] = null;
|
$user['salt'] = null;
|
||||||
$user->ownToken = [];
|
$user->ownToken = array();
|
||||||
$user['password'] = null;
|
$user['password'] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change username if available.
|
// Change username if available.
|
||||||
function updateUsername($user, $data) {
|
function updateUsername($user, $data) {
|
||||||
global $jsonResponse;
|
global $jsonResponse;
|
||||||
$nameTaken = R::findOne('user', ' username = ?', [$data->newUsername]);
|
$nameTaken = R::findOne('user', ' username = ?', array($data->newUsername));
|
||||||
|
|
||||||
if (null != $user && null == $nameTaken) {
|
if (null != $user && null == $nameTaken) {
|
||||||
$user->username = $data->newUsername;
|
$user->username = $data->newUsername;
|
||||||
@ -268,7 +269,7 @@ function updateUsername($user, $data) {
|
|||||||
// Change email if available.
|
// Change email if available.
|
||||||
function updateEmail($user, $data) {
|
function updateEmail($user, $data) {
|
||||||
global $jsonResponse;
|
global $jsonResponse;
|
||||||
$emailTaken = R::findOne('user', ' username = ?', [$data->newEmail]);
|
$emailTaken = R::findOne('user', ' username = ?', array($data->newEmail));
|
||||||
|
|
||||||
if (null != $user && null == $emailTaken) {
|
if (null != $user && null == $emailTaken) {
|
||||||
$user->email = $data->newEmail;
|
$user->email = $data->newEmail;
|
||||||
@ -311,8 +312,9 @@ function checkDbToken() {
|
|||||||
$isValid = false;
|
$isValid = false;
|
||||||
|
|
||||||
if (null != $user) {
|
if (null != $user) {
|
||||||
if (isset(getallheaders()['Authorization'])) {
|
$gah = getallheaders();
|
||||||
$hash = getallheaders()['Authorization'];
|
if (isset($gah['Authorization'])) {
|
||||||
|
$hash = $gah['Authorization'];
|
||||||
|
|
||||||
foreach ($user->ownToken as $token) {
|
foreach ($user->ownToken as $token) {
|
||||||
if ($hash == $token->token) {
|
if ($hash == $token->token) {
|
||||||
@ -328,15 +330,16 @@ function checkDbToken() {
|
|||||||
// Clear a user's token from the DB.
|
// Clear a user's token from the DB.
|
||||||
function clearDbToken() {
|
function clearDbToken() {
|
||||||
$payload = null;
|
$payload = null;
|
||||||
|
$gah = getallheaders();
|
||||||
try {
|
try {
|
||||||
$payload = JWT::decode(getallheaders()['Authorization'], getJwtKey());
|
|
||||||
|
$payload = JWT::decode($gah['Authorization'], getJwtKey());
|
||||||
} catch (Exception $e) {}
|
} catch (Exception $e) {}
|
||||||
|
|
||||||
if (null != $payload) {
|
if (null != $payload) {
|
||||||
$user = R::load('user', $payload->uid);
|
$user = R::load('user', $payload->uid);
|
||||||
if (0 != $user->id) {
|
if (0 != $user->id) {
|
||||||
$hash = getallheaders()['Authorization'];
|
$hash = $gah['Authorization'];
|
||||||
|
|
||||||
foreach ($user->ownToken as $token) {
|
foreach ($user->ownToken as $token) {
|
||||||
if ($hash == $token->token) {
|
if ($hash == $token->token) {
|
||||||
|
@ -59,7 +59,7 @@ $app->post('/boards/:id/items', function($id) use($app, $jsonResponse) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$app->response->setBody($jsonResponse->asJson());
|
$app->response->setBody($jsonResponse->asJson());
|
||||||
})->conditions(['id' => '\d+']); // Numbers only.
|
})->conditions(array('id' => '\d+')); // Numbers only.
|
||||||
|
|
||||||
//Update existing item
|
//Update existing item
|
||||||
$app->post('/items/:itemId', function($itemId) use ($app, $jsonResponse) {
|
$app->post('/items/:itemId', function($itemId) use ($app, $jsonResponse) {
|
||||||
@ -121,7 +121,7 @@ $app->post('/items/:itemId', function($itemId) use ($app, $jsonResponse) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$app->response->setBody($jsonResponse->asJson());
|
$app->response->setBody($jsonResponse->asJson());
|
||||||
})->conditions(['itemId' => '\d+']);
|
})->conditions(array('itemId' => '\d+'));
|
||||||
|
|
||||||
// Update item positions
|
// Update item positions
|
||||||
$app->post('/items/positions', function() use ($app, $jsonResponse) {
|
$app->post('/items/positions', function() use ($app, $jsonResponse) {
|
||||||
@ -200,7 +200,7 @@ $app->post('/items/:itemId/comment', function($itemId) use ($app, $jsonResponse)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$app->response->setBody($jsonResponse->asJson());
|
$app->response->setBody($jsonResponse->asJson());
|
||||||
})->conditions(['itemId' => '\d+']);
|
})->conditions(array('itemId' => '\d+'));
|
||||||
|
|
||||||
// Update an existing comment
|
// Update an existing comment
|
||||||
$app->post('/comments/:commentId', function($commentId) use ($app, $jsonResponse) {
|
$app->post('/comments/:commentId', function($commentId) use ($app, $jsonResponse) {
|
||||||
@ -241,7 +241,7 @@ $app->post('/comments/:commentId', function($commentId) use ($app, $jsonResponse
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$app->response->setBody($jsonResponse->asJson());
|
$app->response->setBody($jsonResponse->asJson());
|
||||||
})->conditions(['commentId' => '\d+']);
|
})->conditions(array('commentId' => '\d+'));
|
||||||
|
|
||||||
// Remove a comment from an item.
|
// Remove a comment from an item.
|
||||||
$app->post('/items/:itemId/comment/remove', function($itemId) use ($app, $jsonResponse) {
|
$app->post('/items/:itemId/comment/remove', function($itemId) use ($app, $jsonResponse) {
|
||||||
@ -261,7 +261,7 @@ $app->post('/items/:itemId/comment/remove', function($itemId) use ($app, $jsonRe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$app->response->setBody($jsonResponse->asJson());
|
$app->response->setBody($jsonResponse->asJson());
|
||||||
})->conditions(['itemId' => '\d+']);
|
})->conditions(array('itemId' => '\d+'));
|
||||||
|
|
||||||
// Add an attachment to an item.
|
// Add an attachment to an item.
|
||||||
$app->post('/items/:itemId/upload', function($itemId) use ($app, $jsonResponse) {
|
$app->post('/items/:itemId/upload', function($itemId) use ($app, $jsonResponse) {
|
||||||
@ -293,7 +293,7 @@ $app->post('/items/:itemId/upload', function($itemId) use ($app, $jsonResponse)
|
|||||||
$jsonResponse->addBeans($item);
|
$jsonResponse->addBeans($item);
|
||||||
}
|
}
|
||||||
$app->response->setBody($jsonResponse->asJson());
|
$app->response->setBody($jsonResponse->asJson());
|
||||||
})->conditions(['itemId' => '\d+']);
|
})->conditions(array('itemId' => '\d+'));
|
||||||
|
|
||||||
// Get an item attachment's information.
|
// Get an item attachment's information.
|
||||||
$app->get('/items/:itemId/upload/:attachmentId', function($itemId, $attachmentId) use ($app, $jsonResponse) {
|
$app->get('/items/:itemId/upload/:attachmentId', function($itemId, $attachmentId) use ($app, $jsonResponse) {
|
||||||
@ -310,7 +310,7 @@ $app->get('/items/:itemId/upload/:attachmentId', function($itemId, $attachmentId
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$app->response->setBody($jsonResponse->asJson());
|
$app->response->setBody($jsonResponse->asJson());
|
||||||
})->conditions(['itemId' => '\d+', 'attachmentId' => '\d+']);
|
})->conditions(array('itemId' => '\d+', 'attachmentId' => '\d+'));
|
||||||
|
|
||||||
// Remove an attachment from an item.
|
// Remove an attachment from an item.
|
||||||
$app->post('/items/:itemId/upload/remove', function($itemId) use ($app, $jsonResponse) {
|
$app->post('/items/:itemId/upload/remove', function($itemId) use ($app, $jsonResponse) {
|
||||||
@ -336,7 +336,7 @@ $app->post('/items/:itemId/upload/remove', function($itemId) use ($app, $jsonRes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$app->response->setBody($jsonResponse->asJson());
|
$app->response->setBody($jsonResponse->asJson());
|
||||||
})->conditions(['itemId' => '\d+']);
|
})->conditions(array('itemId' => '\d+'));
|
||||||
|
|
||||||
// Remove an item.
|
// Remove an item.
|
||||||
$app->post('/items/remove', function() use ($app, $jsonResponse) {
|
$app->post('/items/remove', function() use ($app, $jsonResponse) {
|
||||||
|
@ -17,6 +17,6 @@ class JsonResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addAlert($type, $text) {
|
function addAlert($type, $text) {
|
||||||
$this->alerts[] = ['type' => $type, 'text' => $text];
|
$this->alerts[] = array('type' => $type, 'text' => $text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ $app->post('/login', function() use ($app, $jsonResponse) {
|
|||||||
? (2 * 7 * 24 * 60 * 60) /* Two weeks */
|
? (2 * 7 * 24 * 60 * 60) /* Two weeks */
|
||||||
: (1.5 * 60 * 60) /* One and a half hours */;
|
: (1.5 * 60 * 60) /* One and a half hours */;
|
||||||
|
|
||||||
$lookup = R::findOne('user', ' username = ? ', [$data->username]);
|
$lookup = R::findOne('user', ' username = ? ', array($data->username));
|
||||||
|
|
||||||
$jsonResponse->message = 'Invalid username or password.';
|
$jsonResponse->message = 'Invalid username or password.';
|
||||||
$app->response->setStatus(401);
|
$app->response->setStatus(401);
|
||||||
@ -27,7 +27,7 @@ $app->post('/login', function() use ($app, $jsonResponse) {
|
|||||||
|
|
||||||
logAction($lookup->username . ' logged in.', null, null);
|
logAction($lookup->username . ' logged in.', null, null);
|
||||||
$jsonResponse->message = 'Login successful.';
|
$jsonResponse->message = 'Login successful.';
|
||||||
$jsonResponse->data = R::findOne('token', ' user_id = ? ORDER BY id DESC ', [$lookup->id])->token;
|
$jsonResponse->data = R::findOne('token', ' user_id = ? ORDER BY id DESC ', array($lookup->id))->token;
|
||||||
$app->response->setStatus(200);
|
$app->response->setStatus(200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -139,19 +139,19 @@ $app->get('/users/current', function() use($app, $jsonResponse) {
|
|||||||
$user = getUser();
|
$user = getUser();
|
||||||
if (null != $user) {
|
if (null != $user) {
|
||||||
$userOptions = R::exportAll($user->ownOption);
|
$userOptions = R::exportAll($user->ownOption);
|
||||||
$options = [
|
$options = array(
|
||||||
'tasksOrder' => $userOptions[0]['tasks_order'],
|
'tasksOrder' => $userOptions[0]['tasks_order'],
|
||||||
'showAssignee' => $userOptions[0]['show_assignee'] == 1,
|
'showAssignee' => $userOptions[0]['show_assignee'] == 1,
|
||||||
'showAnimations' => $userOptions[0]['show_animations'] == 1
|
'showAnimations' => $userOptions[0]['show_animations'] == 1
|
||||||
];
|
);
|
||||||
$jsonResponse->data = [
|
$jsonResponse->data = array(
|
||||||
'userId' => $user->id,
|
'userId' => $user->id,
|
||||||
'username' => $user->username,
|
'username' => $user->username,
|
||||||
'isAdmin' => $user->isAdmin,
|
'isAdmin' => $user->isAdmin,
|
||||||
'email' => $user->email,
|
'email' => $user->email,
|
||||||
'defaultBoard' => $user->defaultBoard,
|
'defaultBoard' => $user->defaultBoard,
|
||||||
'options' => $options
|
'options' => $options
|
||||||
];
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$app->response->setBody($jsonResponse->asJson());
|
$app->response->setBody($jsonResponse->asJson());
|
||||||
@ -186,7 +186,7 @@ $app->post('/users', function() use($app, $jsonResponse) {
|
|||||||
$data = json_decode($app->environment['slim.input']);
|
$data = json_decode($app->environment['slim.input']);
|
||||||
|
|
||||||
if (validateToken(true)) {
|
if (validateToken(true)) {
|
||||||
$nameTaken = R::findOne('user', ' username = ?', [$data->username]);
|
$nameTaken = R::findOne('user', ' username = ?', array($data->username));
|
||||||
|
|
||||||
if (null != $nameTaken) {
|
if (null != $nameTaken) {
|
||||||
$jsonResponse->addAlert('error', 'Username already in use.');
|
$jsonResponse->addAlert('error', 'Username already in use.');
|
||||||
@ -263,7 +263,7 @@ $app->post('/users/remove', function() use($app, $jsonResponse) {
|
|||||||
if ($user->id == $data->userId && $actor->isAdmin) {
|
if ($user->id == $data->userId && $actor->isAdmin) {
|
||||||
$before = $user->export();
|
$before = $user->export();
|
||||||
R::trash($user);
|
R::trash($user);
|
||||||
R::exec('DELETE from board_user WHERE user_id = ?', [$data->userId]);
|
R::exec('DELETE from board_user WHERE user_id = ?', array($data->userId));
|
||||||
|
|
||||||
logAction($actor->username . ' removed user ' . $before['username'], $before, null);
|
logAction($actor->username . ' removed user ' . $before['username'], $before, null);
|
||||||
$jsonResponse->addAlert('success', 'Removed user ' . $user->username . '.');
|
$jsonResponse->addAlert('success', 'Removed user ' . $user->username . '.');
|
||||||
|
Reference in New Issue
Block a user