-
Notifications
You must be signed in to change notification settings - Fork 55
/
class.scene.php
128 lines (117 loc) · 4.73 KB
/
class.scene.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/*
SceneGames
Copyright (C) 2018 GoodOldDownloads
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace GoodOldDownloads;
require __DIR__ . '/db.php';
class Config
{
public function __construct()
{
require __DIR__ . '/config.php';
$this->CONFIG = $CONFIG;
}
public function get($settingName)
{
global $Memcached;
$settingVal = $Memcached->get("setting_$settingName");
if ($settingVal === false) {
global $dbh;
$get = $dbh->prepare("SELECT `value` FROM `site` WHERE `name` = :name");
$get->bindParam(':name', $settingName, \PDO::PARAM_STR);
$get->execute();
$settingVal = $get->fetchColumn();
$Memcached->add("setting_$settingName", $settingVal, 0);
}
return $settingVal;
}
public function set($settingName, $value)
{
global $Memcached;
global $dbh;
$set = $dbh->prepare("REPLACE INTO `site` (`name`, `value`) VALUES (:name, :value)");
$set->bindParam(':name', $settingName, \PDO::PARAM_STR);
$set->bindParam(':value', $value, \PDO::PARAM_STR);
$Memcached->set("setting_$settingName", $value, 0);
return $set->execute();
}
}
class Images
{
public function __construct()
{
require __DIR__ . '/config.php';
$this->CONFIG = $CONFIG;
}
public function getCoverImagePath($gameId)
{
global $dbh;
$get = $dbh->prepare("SELECT `id`, `image_cover`, `cover_id`, `steam_id` FROM `games` WHERE `id` = :id");
$get->bindParam(':id', $gameId, \PDO::PARAM_INT);
$get->execute();
$game = $get->fetch(\PDO::FETCH_ASSOC);
if ($game['image_cover'] == 1){
$time = '';
$file = $this->CONFIG['BASEDIR']."/web/static/img/game_assets/custom/".$game['id']."_cover.jpg";
if (file_exists($file)) {
$time = "?".filemtime($file);
}
return "/static/img/game_assets/custom/".$game['id']."_cover.jpg$time";
} elseif ($game['cover_id'] !== null){
return "/static/img/game_assets/cover_big/".$game['cover_id'].".jpg";
} elseif ($game['cover_id'] == null && $game['steam_id'] !== null){
return "/static/img/game_assets/steam_covers/".$game['steam_id'].".jpg";
} else {
return "/static/img/nocover.png";
}
}
public function getBackgroundImagePath($gameId, $size)
{
global $dbh;
$get = $dbh->prepare("SELECT `id`, `image_background`, `screen_id`, `steam_id` FROM `games` WHERE `id` = :id");
$get->bindParam(':id', $gameId, \PDO::PARAM_INT);
$get->execute();
$game = $get->fetch(\PDO::FETCH_ASSOC);
switch ($size) {
case '720p':
if ($game['image_background'] == 1){
$time = '';
$file = $this->CONFIG['BASEDIR']."/static/img/game_assets/custom/".$game['id']."_bg_720p.jpg";
if (file_exists($file)) {
$time = "?".filemtime($file);
}
return "/static/img/game_assets/custom/".$game['id']."_bg_720p.jpg$time";
} elseif ($game['screen_id'] !== null){
return "/static/img/game_assets/bg_720p/".$game['screen_id'].".jpg";
} else {
return "/static/img/nobg.png";
}
break;
case '1080p':
if ($game['image_background'] == 1){
$time = '';
$file = $this->CONFIG['BASEDIR']."/static/img/game_assets/custom/".$game['id']."_bg_1080p.jpg";
if (file_exists($file)) {
$time = "?".filemtime($file);
}
return "/static/img/game_assets/custom/".$game['id']."_bg_1080p.jpg$time";
} elseif ($game['screen_id'] !== null){
return "/static/img/game_assets/bg_1080p/".$game['screen_id'].".jpg";
} else {
return "/static/img/nobg.png";
}
break;
}
}
}