Skip to content

Instantly share code, notes, and snippets.

@syntaqx
Last active December 9, 2015 05:36
Show Gist options
  • Save syntaqx/34c14ae8b2f4af026055 to your computer and use it in GitHub Desktop.
Save syntaqx/34c14ae8b2f4af026055 to your computer and use it in GitHub Desktop.
<?php
// Bootstrap bluethrust
require_once __DIR__ . '/../_setup.php';
// Required objects to perform the queries
$member = new Member($mysqli);
$rankObj = new Rank($mysqli);
$rankCatObj = new RankCategory($mysqli);
$gameObj = new Game($mysqli);
// Output object
$output = array(
'members' => array(),
);
// Fixes null values
function fix_null(&$value) {
if ($value === 0 || $value === "") {
$value = null;
}
}
// Retrieves all members
$result = $mysqli->query('SELECT * FROM ' . $dbprefix . 'members');
while ($row = $result->fetch_assoc()) {
// Properly reorganize the data
$data = array(
// Database relationships
'id' => (int) $row['member_id'],
'rank_id' => (int) $row['rank_id'],
'maingame_id' => (int) $row['maingame_id'],
'recruiter_id' => (int) $row['recruiter'],
// Row information
'username' => $row['username'],
'email' => $row['email'],
'ipaddress' => $row['ipaddress'],
'signature' => $row['forumsignature'],
'avatar' => $row['profilepic'],
'avatar' => $row['avatar'],
'date_birth' => (int) $row['birthday'],
'lastlogin' => (int) $row['lastlogin'],
'lastseen' => (int) $row['lastseen'],
'loggedin' => (bool) $row['loggedin'],
'date_promotion' => (int) $row['lastpromotion'],
'date_demotion' => (int) $row['lastdemotion'],
'timesloggedin' => (int) $row['timesloggedin'],
'profileviews' => (int) $row['profileviews'],
'defaultconsole' => (int) $row['defaultconsole'],
'disableddate' => (int) $row['disableddate'],
'notifications' => (int) $row['notifications'],
'topicsperpage' => (int) $row['topicsperpage'],
'postsperpage' => (int) $row['postsperpage'],
'freezerank' => (int) $row['freezerank'],
'promotepower' => (bool) $row['promotepower'],
'inactive' => (bool) $row['onia'],
'date_inactive' => (int) $row['inactivedate'],
'disabled' => (bool) $row['disabled'],
// Metadata
'date_created' => (int) $row['datejoined'],
'date_updated' => null,
);
// Sanitize data properly.
fix_null($data['signature']);
fix_null($data['avatar']);
fix_null($data['date_birth']);
fix_null($data['date_inactive']);
fix_null($data['date_promotion']);
fix_null($data['date_demotion']);
// Append the sanitized data to the output
$output['members'][] = $data;
}
// Display the output
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, HEAD');
header('Content-Type: application/json');
echo json_encode($output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment