| Current Path : /home/happyrenas/fun/public/api/ |
Linux webd005.cluster105.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 |
| Current File : /home/happyrenas/fun/public/api/activities.php |
<?php
/**
* GET /api/activities.php?query=...&limit=20&offset=0
* -> { ok:true, items:[{id,name}], total, nextOffset }
*/
require_once __DIR__ . '/_bootstrap.php';
rate_limit_or_429('get', $config);
$query = str_limit((string)q('query',''), 80);
$limit = (int)q('limit', 20);
$offset = (int)q('offset', 0);
$limit = max(1, min(100, $limit));
$offset = max(0, $offset);
$s = $config['sheets']['activities'];
$values = sheets_get_all($s['spreadsheet_id'], $s['sheet_name'], $config);
$t = table_from_values($values);
$items = [];
$qLower = mb_strtolower($query);
foreach ($t['rows'] as $r) {
$id = (string)($r['id'] ?? '');
$name = (string)($r['name'] ?? '');
if ($id === '' || $name === '') continue;
if ($qLower !== '') {
if (mb_strpos(mb_strtolower($name), $qLower) === false) continue;
}
$items[] = ['id'=>$id, 'name'=>$name];
}
$total = count($items);
$paged = array_slice($items, $offset, $limit);
$nextOffset = ($offset + $limit < $total) ? ($offset + $limit) : null;
json_out(['ok'=>true, 'items'=>$paged, 'total'=>$total, 'nextOffset'=>$nextOffset]);