Skip to content

Commit

Permalink
Updated compatibility of arrays with PHP 5.x.
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
praveenscience committed Oct 29, 2015
1 parent e83a60b commit 3f6ded3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 37 deletions.
8 changes: 4 additions & 4 deletions api/boardRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
R::trashAll($board->xownCategory);
R::trashAll($board->xownAutoaction);
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 . '.');
$actor = getUser();
logAction($actor->username . ' removed board ' . $board->name, $before, null);
Expand Down Expand Up @@ -139,7 +139,7 @@
if (validateToken()) {
$user = getUser();
$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) {
R::trash($collapsed);
Expand All @@ -155,7 +155,7 @@
$jsonResponse->addBeans(getBoards());
}
$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) {
if (validateToken()) {
Expand All @@ -175,4 +175,4 @@
}
}
$app->response->setBody($jsonResponse->asJson());
})->conditions(['boardId' => '\d+']); // Numbers only.
})->conditions(array('boardId' => '\d+')); // Numbers only.
35 changes: 19 additions & 16 deletions api/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function setUserToken($user, $expires) {
$dbToken->token = $token;

if (null == $user->ownToken) {
$user->ownToken = [];
$user->ownToken = array();
}
$user->ownToken[] = $dbToken;

Expand All @@ -50,9 +50,9 @@ function setUserToken($user, $expires) {
// Get the user making the current request.
function getUser() {
global $jsonResponse;

if (isset(getallheaders()['Authorization'])) {
$hash = getallheaders()['Authorization'];
$gah = getallheaders();
if (isset($gah['Authorization'])) {
$hash = $gah['Authorization'];
try {
$payload = JWT::decode($hash, getJwtKey());
$user = R::load('user', $payload->uid);
Expand Down Expand Up @@ -94,7 +94,8 @@ function getLaneByID($id) {
// Get all users.
function getUsers($sanitize = true) {
try {
$hash = getallheaders()['Authorization'];
$gah = getallheaders();
$hash = $gah['Authorization'];
$payload = JWT::decode($hash, getJwtKey());

$users = R::findAll('user');
Expand Down Expand Up @@ -153,7 +154,7 @@ function getBoards() {
if ($user->isAdmin) {
return $boards;
} else {
$filteredBoards = [];
$filteredBoards = array();
foreach($boards as $board) {
foreach($board->sharedUser as $boardUser) {
if ($user->username == $boardUser->username) {
Expand All @@ -167,7 +168,7 @@ function getBoards() {

// Finds the removed IDs for updating a board.
function getIdsToRemove($boardList, $dataList) {
$retVal = [];
$retVal = array();
foreach($boardList as $item) {
$remove = true;
foreach($dataList as $newItem) {
Expand Down Expand Up @@ -199,7 +200,7 @@ function loadBoardData($board, $data) {
$lane->position = intval($item->position);

if (null == $lane->ownItems) {
$lane->ownItems = [];
$lane->ownItems = array();
}
// New lane, add it to the board
if (!$lane->id) {
Expand Down Expand Up @@ -246,14 +247,14 @@ function loadBoardData($board, $data) {
// Clean a user bean for return to front-end.
function sanitize($user) {
$user['salt'] = null;
$user->ownToken = [];
$user->ownToken = array();
$user['password'] = null;
}

// Change username if available.
function updateUsername($user, $data) {
global $jsonResponse;
$nameTaken = R::findOne('user', ' username = ?', [$data->newUsername]);
$nameTaken = R::findOne('user', ' username = ?', array($data->newUsername));

if (null != $user && null == $nameTaken) {
$user->username = $data->newUsername;
Expand All @@ -268,7 +269,7 @@ function updateUsername($user, $data) {
// Change email if available.
function updateEmail($user, $data) {
global $jsonResponse;
$emailTaken = R::findOne('user', ' username = ?', [$data->newEmail]);
$emailTaken = R::findOne('user', ' username = ?', array($data->newEmail));

if (null != $user && null == $emailTaken) {
$user->email = $data->newEmail;
Expand Down Expand Up @@ -311,8 +312,9 @@ function checkDbToken() {
$isValid = false;

if (null != $user) {
if (isset(getallheaders()['Authorization'])) {
$hash = getallheaders()['Authorization'];
$gah = getallheaders();
if (isset($gah['Authorization'])) {
$hash = $gah['Authorization'];

foreach ($user->ownToken as $token) {
if ($hash == $token->token) {
Expand All @@ -328,15 +330,16 @@ function checkDbToken() {
// Clear a user's token from the DB.
function clearDbToken() {
$payload = null;

$gah = getallheaders();
try {
$payload = JWT::decode(getallheaders()['Authorization'], getJwtKey());

$payload = JWT::decode($gah['Authorization'], getJwtKey());
} catch (Exception $e) {}

if (null != $payload) {
$user = R::load('user', $payload->uid);
if (0 != $user->id) {
$hash = getallheaders()['Authorization'];
$hash = $gah['Authorization'];

foreach ($user->ownToken as $token) {
if ($hash == $token->token) {
Expand Down
16 changes: 8 additions & 8 deletions api/itemRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
}
}
$app->response->setBody($jsonResponse->asJson());
})->conditions(['id' => '\d+']); // Numbers only.
})->conditions(array('id' => '\d+')); // Numbers only.

//Update existing item
$app->post('/items/:itemId', function($itemId) use ($app, $jsonResponse) {
Expand Down Expand Up @@ -121,7 +121,7 @@
}
}
$app->response->setBody($jsonResponse->asJson());
})->conditions(['itemId' => '\d+']);
})->conditions(array('itemId' => '\d+'));

// Update item positions
$app->post('/items/positions', function() use ($app, $jsonResponse) {
Expand Down Expand Up @@ -200,7 +200,7 @@
}
}
$app->response->setBody($jsonResponse->asJson());
})->conditions(['itemId' => '\d+']);
})->conditions(array('itemId' => '\d+'));

// Update an existing comment
$app->post('/comments/:commentId', function($commentId) use ($app, $jsonResponse) {
Expand Down Expand Up @@ -241,7 +241,7 @@
}
}
$app->response->setBody($jsonResponse->asJson());
})->conditions(['commentId' => '\d+']);
})->conditions(array('commentId' => '\d+'));

// Remove a comment from an item.
$app->post('/items/:itemId/comment/remove', function($itemId) use ($app, $jsonResponse) {
Expand All @@ -261,7 +261,7 @@
}
}
$app->response->setBody($jsonResponse->asJson());
})->conditions(['itemId' => '\d+']);
})->conditions(array('itemId' => '\d+'));

// Add an attachment to an item.
$app->post('/items/:itemId/upload', function($itemId) use ($app, $jsonResponse) {
Expand Down Expand Up @@ -293,7 +293,7 @@
$jsonResponse->addBeans($item);
}
$app->response->setBody($jsonResponse->asJson());
})->conditions(['itemId' => '\d+']);
})->conditions(array('itemId' => '\d+'));

// Get an item attachment's information.
$app->get('/items/:itemId/upload/:attachmentId', function($itemId, $attachmentId) use ($app, $jsonResponse) {
Expand All @@ -310,7 +310,7 @@
}
}
$app->response->setBody($jsonResponse->asJson());
})->conditions(['itemId' => '\d+', 'attachmentId' => '\d+']);
})->conditions(array('itemId' => '\d+', 'attachmentId' => '\d+'));

// Remove an attachment from an item.
$app->post('/items/:itemId/upload/remove', function($itemId) use ($app, $jsonResponse) {
Expand All @@ -336,7 +336,7 @@
}
}
$app->response->setBody($jsonResponse->asJson());
})->conditions(['itemId' => '\d+']);
})->conditions(array('itemId' => '\d+'));

// Remove an item.
$app->post('/items/remove', function() use ($app, $jsonResponse) {
Expand Down
2 changes: 1 addition & 1 deletion api/jsonResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ function addBeans($beans) {
}

function addAlert($type, $text) {
$this->alerts[] = ['type' => $type, 'text' => $text];
$this->alerts[] = array('type' => $type, 'text' => $text);
}
}
16 changes: 8 additions & 8 deletions api/userRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
? (2 * 7 * 24 * 60 * 60) /* Two weeks */
: (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.';
$app->response->setStatus(401);
Expand All @@ -27,7 +27,7 @@

logAction($lookup->username . ' logged in.', null, null);
$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);
}
}
Expand Down Expand Up @@ -139,19 +139,19 @@
$user = getUser();
if (null != $user) {
$userOptions = R::exportAll($user->ownOption);
$options = [
$options = array(
'tasksOrder' => $userOptions[0]['tasks_order'],
'showAssignee' => $userOptions[0]['show_assignee'] == 1,
'showAnimations' => $userOptions[0]['show_animations'] == 1
];
$jsonResponse->data = [
);
$jsonResponse->data = array(
'userId' => $user->id,
'username' => $user->username,
'isAdmin' => $user->isAdmin,
'email' => $user->email,
'defaultBoard' => $user->defaultBoard,
'options' => $options
];
);
}
}
$app->response->setBody($jsonResponse->asJson());
Expand Down Expand Up @@ -186,7 +186,7 @@
$data = json_decode($app->environment['slim.input']);

if (validateToken(true)) {
$nameTaken = R::findOne('user', ' username = ?', [$data->username]);
$nameTaken = R::findOne('user', ' username = ?', array($data->username));

if (null != $nameTaken) {
$jsonResponse->addAlert('error', 'Username already in use.');
Expand Down Expand Up @@ -263,7 +263,7 @@
if ($user->id == $data->userId && $actor->isAdmin) {
$before = $user->export();
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);
$jsonResponse->addAlert('success', 'Removed user ' . $user->username . '.');
Expand Down

0 comments on commit 3f6ded3

Please sign in to comment.