itemlistparser.php

main 49 lines · 937 bytes Raw
Alex Alex Commit Initial commit 01/10/2026 09:20
1<?php
2
3function getItemList(): array {
4 return parseItems();
5}
6
7function getItemById(int $id): string|false {
8 static $items = null;
9
10 if ($items === null) {
11 $items = parseItems();
12 }
13
14 return $items[$id] ?? false;
15}
16
17function parseItems(): array {
18 // ZnoteAAC compatible
19 $serverPath = function_exists('Config')
20 ? Config('server_path')
21 : ($GLOBALS['config']['server_path'] ?? null);
22
23 if (!$serverPath) {
24 return [];
25 }
26
27 $file = $serverPath . '/data/items/items.xml';
28
29 if (!file_exists($file)) {
30 return [];
31 }
32
33 libxml_use_internal_errors(true);
34 $xml = simplexml_load_file($file);
35
36 if ($xml === false) {
37 return [];
38 }
39
40 $itemList = [];
41
42 foreach ($xml->children() as $item) {
43 if (isset($item['id'], $item['name'])) {
44 $itemList[(int)$item['id']] = (string)$item['name'];
45 }
46 }
47
48 return $itemList;
49}
Top