forked from opentibiabr/myaac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem.php
66 lines (56 loc) · 1.49 KB
/
item.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
59
60
61
62
63
64
65
66
<?php
/**
* Item parser
*
* @package MyAAC
* @author Slawkens <slawkens@gmail.com>
* @author OpenTibiaBR
* @copyright 2023 MyAAC
* @link https://github.com/opentibiabr/myaac
*/
defined('MYAAC') or die('Direct access not allowed!');
require_once SYSTEM . 'libs/items_images.php';
Items_Images::$files = [
'otb' => SYSTEM . 'data/items.otb',
'spr' => SYSTEM . 'data/Tibia.spr',
'dat' => SYSTEM . 'data/Tibia.dat',
];
Items_Images::$outputDir = BASE . 'images/items/';
function generateItem($id = 100, $count = 1)
{
Items_Images::generate($id, $count);
}
function itemImageExists($id, $count = 1)
{
if (!isset($id)) {
throw new RuntimeException('ERROR - itemImageExists: id has been not set!');
}
$file_name = $id;
if ($count > 1) {
$file_name .= '-' . $count;
}
$file_name = Items_Images::$outputDir . $file_name . '.gif';
return file_exists($file_name);
}
function outputItem($id = 100, $count = 1)
{
if (!(int) $count) {
$count = 1;
}
if (!itemImageExists($id, $count)) {
//echo 'plik istnieje';
Items_Images::generate($id, $count);
}
$expires = 60 * 60 * 24 * 30; // 30 days
header('Content-type: image/gif');
header('Cache-Control: public');
header('Cache-Control: maxage=' . $expires);
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
$file_name = $id;
if ($count > 1) {
$file_name .= '-' . $count;
}
$file_name = Items_Images::$outputDir . $file_name . '.gif';
readfile($file_name);
}
?>