forked from iGBAEmu/iGBA-DR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repo.php
58 lines (42 loc) · 1.85 KB
/
repo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/*
iGBA Dynamic Repository (iGBA-DR)
Unofficial.
SETUP:
1. Create a MySQL user, database, and table. Add the details in the 'database information' section.
2. Add the following columns to your newly created table: id (auto increment enabled), name (text), boxart (text), url (text).
3. Edit the repository information to something other than the example.
4. Add a rewrite rule that rewrites (not redirect) json to php for this specific file and web server it's going to be hosted on.
If you don't know how to do that, search for something like "{your web server} rewrite url from json to php".
Either add your ROMs manually into the table with each column filled in or use a script (like a custom-made control panel) to manage the ROM entries.
*/
// Database information
define('DBHOST', 'localhost');
define('DBUSER', 'user');
define('DBPASS', 'pass');
define('DB', 'igbarepo');
define('DBTABLE', 'romlist');
// Information about the repository
define('REPO_NAME', 'GBA archive');
define('REPO_LOGO', 'https://example.com/path/to/icon.png');
define('REPO_AUTHOR', 'Bob');
header('Content-Type: application/json; charset=utf-8');
$con = new mysqli(DBHOST, DBUSER, DBPASS, DB);
if (!$con) exit('{"err":"error connecting"}');
$romstore = [];
$romstore['reponame'] = REPO_NAME;
$romstore['repologo'] = REPO_LOGO;
$romstore['author'] = REPO_AUTHOR;
$romstorecount = 0;
$query = 'SELECT `id`,`name`,`boxart`,`url` FROM `'.DBTABLE.'`';
$romlist = $con->query($query);
if (!$romlist) exit('{"err":"failed to obtain rom data"}');
while ($romlistdat = $romlist->fetch_assoc()) {
$romstore['games'][$romstorecount]['name'] = $romlistdat['name'];
$romstore['games'][$romstorecount]['boxart'] = $romlistdat['boxart'];
$romstore['games'][$romstorecount]['url'] = $romlistdat['url'];
++$romstorecount;
}
$romlist->free();
$con->close();
echo json_encode($romstore);