1
0
This commit is contained in:
Mike Schwörer 2020-01-15 00:37:08 +01:00
parent e5dc57e2b5
commit 099f5b368e
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
2 changed files with 44 additions and 32 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
require_once __DIR__ . '/base.php'; require_once 'website.php';
class Programs class Programs
{ {
@ -33,7 +33,22 @@ class Programs
'Mozilla-2.0' => 'https://choosealicense.com/licenses/mpl-2.0/', 'Mozilla-2.0' => 'https://choosealicense.com/licenses/mpl-2.0/',
]; ];
public static function readSingle($a) /** @var array */
private $staticData;
public function __construct()
{
$this->load();
}
private function load()
{
$all = require (__DIR__ . '/../statics/blog/__all.php');
$this->staticData = array_map(function($a){return self::readSingle($a);}, $all);
}
private static function readSingle($a)
{ {
$a['mainimage_url'] = '/data/images/program_img/' . $a['internal_name'] . '.png'; $a['mainimage_url'] = '/data/images/program_img/' . $a['internal_name'] . '.png';
$a['mainimage_path'] = __DIR__ . '/../data/images/program_img/' . $a['internal_name'] . '.png'; $a['mainimage_path'] = __DIR__ . '/../data/images/program_img/' . $a['internal_name'] . '.png';
@ -62,42 +77,34 @@ class Programs
return $a; return $a;
} }
public static function listAll() public function listAll()
{ {
$all = require (__DIR__ . '/../statics/programs/__all.php'); return $this->staticData;
return array_map('self::readSingle', $all);
} }
public static function listAllNewestFirst($filter = '') public function listAllNewestFirst($filter = '')
{ {
$data = self::listAll(); $data = $this->staticData;
usort($data, function($a, $b) { return strcasecmp($b['add_date'], $a['add_date']); }); usort($data, function($a, $b) { return strcasecmp($b['add_date'], $a['add_date']); });
if ($filter !== '') $data = array_filter($data, function($a) use($filter) { return strtolower($a['category']) === strtolower($filter); }); if ($filter !== '') $data = array_filter($data, function($a) use($filter) { return strtolower($a['category']) === strtolower($filter); });
return $data; return $data;
} }
public static function listUpdateData() public function getProgramByInternalName($id)
{ {
$a = require (__DIR__ . '/../statics/updates/_all.php'); foreach ($this->staticData as $prog) {
return $a;
}
public static function getProgramByInternalName($id)
{
foreach (self::listAll() as $prog) {
if (strcasecmp($prog['internal_name'], $id) === 0) return $prog; if (strcasecmp($prog['internal_name'], $id) === 0) return $prog;
if ($prog['internal_name_alt'] !== null && strcasecmp($prog['internal_name_alt'], $id) === 0) return $prog; if ($prog['internal_name_alt'] !== null && strcasecmp($prog['internal_name_alt'], $id) === 0) return $prog;
} }
return null; return null;
} }
public static function getProgramDescription($prog) public function getProgramDescription($prog)
{ {
return file_get_contents($prog['file_longdescription']); return file_get_contents($prog['file_longdescription']);
} }
public static function urlComparator($a, $b) private static function urlComparator($a, $b)
{ {
$na = 0; $na = 0;
$nb = 0; $nb = 0;
@ -118,10 +125,10 @@ class Programs
} }
public static function getURLs($prog) public function getURLs($prog)
{ {
$urls = $prog['urls']; $urls = $prog['urls'];
uksort($urls, 'self::urlComparator'); uksort($urls, function($a,$b){return self::urlComparator($a,$b);});
$result = []; $result = [];
foreach ($urls as $fulltype => $urldata) foreach ($urls as $fulltype => $urldata)
@ -178,29 +185,31 @@ class Programs
return $result; return $result;
} }
public static function getLicenseUrl($license) public function getLicenseUrl($license)
{ {
return self::LICENSES[$license]; return self::LICENSES[$license];
} }
public static function getDirectDownloadURL($prog) public function getDirectDownloadURL($prog)
{ {
return '/data/binaries/'.$prog['internal_name'].'.zip'; return '/data/binaries/'.$prog['internal_name'].'.zip';
} }
public static function getDirectDownloadPath($prog) public function getDirectDownloadPath($prog)
{ {
return (__DIR__ . '/../data/binaries/'.$prog['internal_name'].'.zip'); return (__DIR__ . '/../data/binaries/'.$prog['internal_name'].'.zip');
} }
public static function checkConsistency() public function checkConsistency()
{ {
$warn = null; $warn = null;
$this->load();
$intname = []; $intname = [];
$realname = []; $realname = [];
foreach (self::listAll() as $prog) foreach ($this->staticData as $prog)
{ {
if (in_array($prog['internal_name'], $intname)) return ['result'=>'err', 'message' => 'Duplicate internal_name ' . $prog['name']]; if (in_array($prog['internal_name'], $intname)) return ['result'=>'err', 'message' => 'Duplicate internal_name ' . $prog['name']];
$intname []= $prog['internal_name']; $intname []= $prog['internal_name'];
@ -250,9 +259,9 @@ class Programs
return ['result'=>'ok', 'message' => '']; return ['result'=>'ok', 'message' => ''];
} }
public static function checkThumbnails() public function checkThumbnails()
{ {
foreach (self::listAll() as $prog) foreach ($this->staticData as $prog)
{ {
if (!file_exists($prog['preview_path'])) return ['result'=>'err', 'message' => 'Preview not found ' . $prog['name']]; if (!file_exists($prog['preview_path'])) return ['result'=>'err', 'message' => 'Preview not found ' . $prog['name']];
} }
@ -260,14 +269,12 @@ class Programs
return ['result'=>'ok', 'message' => '']; return ['result'=>'ok', 'message' => ''];
} }
public static function createPreview($prog) public function createPreview($prog)
{ {
global $CONFIG;
$src = $prog['mainimage_path']; $src = $prog['mainimage_path'];
$dst = $prog['preview_path']; $dst = $prog['preview_path'];
if ($CONFIG['use_magick']) if (Website::inst()->config['use_magick'])
magick_resize_image($src, 250, 0, $dst); magick_resize_image($src, 250, 0, $dst);
else else
smart_resize_image($src, 250, 0, true, $dst); smart_resize_image($src, 250, 0, true, $dst);

View File

@ -22,6 +22,7 @@ class Website
/** @var Blog|null */ private $blog = null; /** @var Blog|null */ private $blog = null;
/** @var Books|null */ private $books = null; /** @var Books|null */ private $books = null;
/** @var Euler|null */ private $euler = null; /** @var Euler|null */ private $euler = null;
/** @var Programs|null */ private $programs = null;
public function init() public function init()
{ {
@ -189,7 +190,11 @@ class Website
return $this->euler; return $this->euler;
} }
public function Programs()
{
if ($this->programs === null) { require_once 'programs.php'; $this->programs = new Programs(); }
return $this->programs;
}
/** /**
* @return bool * @return bool