@ -72,7 +72,7 @@ function get_words($date, $limit, $include) {
if(pg_num_rows($res) == 0) {
return [
'status' => 'ERROR',
'message' => 'Date too l ate'
'message' => 'Already up to d ate'
];
}
@ -110,7 +110,7 @@ function add_words($datestamp) {
// Add word to database
$query = 'INSERT INTO words (id, solution, print_date, days_since_launch, editor) ' .
'VALUES ($1, $2, $3, $4, $5)';
'VALUES ($1, UPPER( $2) , $3, $4, $5)';
$params = [
$word['id'],
$word['solution'],
@ -135,34 +135,6 @@ function add_words($datestamp) {
$dbc = pg_connect("host=$DB_HOST dbname=$DB_NAME user=$DB_USER password=$DB_PASSWORD")
or die('Could not connect: ' . pg_last_error());
// Check get vars
$date = $_GET['date'];
$limit = isset($_GET['limit']) ? intval($_GET['limit']) : 100;
$include = isset($_GET['include']) ? $_GET['include'] : 'id,solution,print_date,days_since_launch,editor';
if(!preg_match('/^\d{4}-\d{2}-\d{2}$/', $date)) {
die(json_encode([
'status' => 'ERROR',
'message' => 'Invalid date format (YYYY-MM-DD)'
]));
} else if($date < '2021-06-19') {
die(json_encode([
'status' => 'ERROR',
'message' => 'Date too early'
]));
} else if($limit < = 0) {
die(json_encode([
'status' => 'ERROR',
'message' => 'Invalid limit'
]));
} else if(!preg_match('/^[a-z,_]+$/', $include)) {
die(json_encode([
'status' => 'ERROR',
'message' => 'Invalid include'
]));
}
// Check for words once a day
$res = pg_query('SELECT EXTRACT(EPOCH FROM time) AS time FROM update') or die('Query failed: ' . pg_last_error());
$cur_time = time();
@ -175,6 +147,42 @@ if($cur_time > $last_time + (60 * 60 * 24)) {
}
// Get words
echo json_encode(get_words($date, $limit, $include));
if($_GET['mode'] == 'mod.json') {
header('Content-Disposition: attachment; filename="mod.json"');
echo json_encode([
'words' => [
'order' => get_words('2021-06-19', 100000, 'id')
]
]);
} else {
// Check get vars
$date = $_GET['date'];
$limit = isset($_GET['limit']) ? intval($_GET['limit']) : 100;
$include = isset($_GET['include']) ? $_GET['include'] : 'id,solution,print_date,days_since_launch,editor';
if(!preg_match('/^\d{4}-\d{2}-\d{2}$/', $date)) {
die(json_encode([
'status' => 'ERROR',
'message' => 'Invalid date format (YYYY-MM-DD)'
]));
} else if($date < '2021-06-19') {
die(json_encode([
'status' => 'ERROR',
'message' => 'Date too early'
]));
} else if($limit < = 0) {
die(json_encode([
'status' => 'ERROR',
'message' => 'Invalid limit'
]));
} else if(!preg_match('/^[a-z,_]+$/', $include)) {
die(json_encode([
'status' => 'ERROR',
'message' => 'Invalid include'
]));
}
echo json_encode(get_words($date, $limit, $include));
}
pg_close($dbc);