mirror of
https://github.com/daledavies/jump.git
synced 2026-02-26 00:00:46 +01:00
Use config in site class
This commit is contained in:
@@ -23,7 +23,9 @@ class Config {
|
||||
*/
|
||||
private const BASE_APPLICATION_PATHS = [
|
||||
'backgroundsdir' => '/assets/backgrounds',
|
||||
'sitesfile' => '/sites/sites.json',
|
||||
'defaulticonpath' => '/assets/images/default-icon.png',
|
||||
'sitesdir' => '/sites',
|
||||
'sitesfile' => 'sites.json',
|
||||
'templatedir' => '/templates',
|
||||
];
|
||||
|
||||
|
||||
@@ -11,12 +11,14 @@ namespace Jump;
|
||||
*/
|
||||
class Site {
|
||||
|
||||
private Config $config;
|
||||
public string $name;
|
||||
public bool $nofollow;
|
||||
public string $icon;
|
||||
public string $url;
|
||||
|
||||
public function __construct(array $sitearray) {
|
||||
public function __construct(Config $config, array $sitearray) {
|
||||
$this->config = $config;
|
||||
if (!isset($sitearray['name'], $sitearray['url'])) {
|
||||
throw new \Exception('The array passed to Site() must contain the keys "name" and "url"!');
|
||||
}
|
||||
@@ -30,15 +32,15 @@ class Site {
|
||||
if ($icon === null) {
|
||||
$favicon = new \Favicon\Favicon();
|
||||
$favicon->cache([
|
||||
'dir' => '/var/www/cache/icons/',
|
||||
'dir' => $this->config->get('cachdir').'/icons/',
|
||||
'timeout' => 86400
|
||||
]);
|
||||
$rawimage = $favicon->get($this->url, \Favicon\FaviconDLType::RAW_IMAGE);
|
||||
if (!$rawimage) {
|
||||
$rawimage = file_get_contents(__DIR__ . '/../assets/images/default-icon.png');
|
||||
$rawimage = file_get_contents($this->config->get('defaulticonpath'));
|
||||
}
|
||||
} else {
|
||||
$rawimage = file_get_contents(__DIR__ . '/../sites/icons/'.$icon);
|
||||
$rawimage = file_get_contents($this->config->get('sitesdir').'/icons/'.$icon);
|
||||
}
|
||||
$mimetype = (new \finfo(FILEINFO_MIME_TYPE))->buffer($rawimage);
|
||||
return 'data:'.$mimetype.';base64,'.base64_encode($rawimage);
|
||||
|
||||
@@ -24,7 +24,7 @@ class Sites {
|
||||
public function __construct(Config $config, Cache $cache) {
|
||||
$this->config = $config;
|
||||
$this->loadedsites = [];
|
||||
$this->sitesfilelocation = $this->config->get('sitesfile');
|
||||
$this->sitesfilelocation = $this->config->get('sitesdir').'/'.$this->config->get('sitesfile');
|
||||
$this->cache = $cache;
|
||||
$this->load_sites_from_json();
|
||||
}
|
||||
@@ -53,7 +53,7 @@ class Sites {
|
||||
throw new Exception('Provided sites json does not contain a top-level array');
|
||||
}
|
||||
foreach ($decodedjson as $array) {
|
||||
$sites[] = new Site($array);
|
||||
$sites[] = new Site($this->config, $array);
|
||||
}
|
||||
return $sites;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user