2018-01-27 18:13:38 +01:00
|
|
|
<?php if(count(get_included_files()) ==1) exit("Direct access not permitted.");
|
|
|
|
|
|
|
|
require_once __DIR__ . '/base.php';
|
|
|
|
|
|
|
|
class Books
|
|
|
|
{
|
|
|
|
public static function readSingle($a)
|
|
|
|
{
|
2018-01-28 01:29:25 +01:00
|
|
|
$a['imgfront_url'] = '/data/images/book_img/' . $a['id'] . '_front.png';
|
|
|
|
$a['imgfront_path'] = __DIR__ . '/../data/images/book_img/' . $a['id'] . '_front.png';
|
2018-01-27 18:13:38 +01:00
|
|
|
|
2018-01-28 01:29:25 +01:00
|
|
|
$a['imgfull_url'] = '/data/images/book_img/' . $a['id'] . '_full.png';
|
|
|
|
$a['imgfull_path'] = __DIR__ . '/../data/images/book_img/' . $a['id'] . '_full.png';
|
2018-01-27 18:13:38 +01:00
|
|
|
|
2018-01-28 01:29:25 +01:00
|
|
|
$a['preview_url'] = '/data/dynamic/bookprev_' . $a['id'] . '.png';
|
|
|
|
$a['preview_path'] = __DIR__ . '/../data/dynamic/bookprev_' . $a['id'] . '.png';
|
2018-01-27 18:13:38 +01:00
|
|
|
|
2018-01-28 01:29:25 +01:00
|
|
|
$a['url'] = '/books/view/' . $a['id'] . '/' . destructiveUrlEncode($a['title']);
|
|
|
|
|
|
|
|
$a['extraimages_urls'] = [];
|
|
|
|
$a['extraimages_paths'] = [];
|
|
|
|
|
|
|
|
for ($i=1; $i <= $a['imagecount']; $i++)
|
|
|
|
{
|
|
|
|
$a['extraimages_urls'] []= '/data/images/book_img/' . $a['id'] . '_img' . $i . '.jpg';
|
|
|
|
$a['extraimages_paths'] []= __DIR__ . '/../data/images/book_img/' . $a['id'] . '_img' . $i . '.jpg';
|
|
|
|
}
|
2018-01-27 18:13:38 +01:00
|
|
|
|
|
|
|
return $a;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function listAll()
|
|
|
|
{
|
|
|
|
$all = require (__DIR__ . '/../statics/books/__all.php');
|
|
|
|
|
|
|
|
return array_map('self::readSingle', $all);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function listAllNewestFirst()
|
|
|
|
{
|
|
|
|
$data = self::listAll();
|
|
|
|
usort($data, function($a, $b) { return strcasecmp($b['date'], $a['date']); });
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function checkConsistency()
|
|
|
|
{
|
|
|
|
$warn = null;
|
|
|
|
|
|
|
|
$ids = [];
|
|
|
|
|
|
|
|
foreach (self::listAll() as $prog)
|
|
|
|
{
|
|
|
|
if (in_array($prog['id'], $ids)) return ['result'=>'err', 'message' => 'Duplicate id ' . $prog['id']];
|
|
|
|
$ids []= $prog['id'];
|
|
|
|
|
|
|
|
if (!file_exists($prog['imgfront_path'])) return ['result'=>'err', 'message' => 'Image not found ' . $prog['title_short']];
|
|
|
|
if (!file_exists($prog['imgfull_path'])) return ['result'=>'err', 'message' => 'Image not found ' . $prog['title_short']];
|
2018-02-09 22:59:02 +01:00
|
|
|
|
|
|
|
foreach ($prog['extraimages_paths'] as $eipath)
|
|
|
|
{
|
|
|
|
if (!file_exists($eipath)) return ['result'=>'err', 'message' => 'Extra-Image not found ' . $prog['title_short']];
|
|
|
|
}
|
2018-01-27 18:13:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($warn != null) return $warn;
|
|
|
|
return ['result'=>'ok', 'message' => ''];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function checkThumbnails()
|
|
|
|
{
|
|
|
|
foreach (self::listAll() as $book)
|
|
|
|
{
|
|
|
|
if (!file_exists($book['preview_path'])) return ['result'=>'err', 'message' => 'Preview not found ' . $book['title_short']];
|
|
|
|
}
|
|
|
|
|
|
|
|
return ['result'=>'ok', 'message' => ''];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function createPreview($prog)
|
|
|
|
{
|
2018-02-03 23:49:44 +01:00
|
|
|
global $CONFIG;
|
|
|
|
|
2018-01-27 18:13:38 +01:00
|
|
|
$src = $prog['imgfront_path'];
|
|
|
|
$dst = $prog['preview_path'];
|
|
|
|
|
2018-02-03 23:49:44 +01:00
|
|
|
if ($CONFIG['use_magick'])
|
|
|
|
magick_resize_image($src, 200, 0, $dst);
|
|
|
|
else
|
|
|
|
smart_resize_image($src, 200, 0, true, $dst);
|
|
|
|
|
2018-01-27 18:13:38 +01:00
|
|
|
}
|
2018-01-28 01:29:25 +01:00
|
|
|
|
|
|
|
public static function getBook($id)
|
|
|
|
{
|
|
|
|
foreach (self::listAll() as $book) {
|
|
|
|
if ($book['id'] == $id) return $book;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2018-03-24 02:55:01 +01:00
|
|
|
|
|
|
|
public static function getRepositoryHost($book)
|
|
|
|
{
|
|
|
|
$r = $book['repository'];
|
|
|
|
if (startsWith($r, "http://")) $r = substr($r, strlen("http://"));
|
|
|
|
if (startsWith($r, "https://")) $r = substr($r, strlen("https://"));
|
|
|
|
if (startsWith($r, "www.")) $r = substr($r, strlen("www."));
|
|
|
|
|
|
|
|
if (startsWith(strtolower($r), "gitlab")) return "Gitlab";
|
|
|
|
if (startsWith(strtolower($r), "github")) return "Github";
|
|
|
|
if (startsWith(strtolower($r), "bitbucket")) return "Bitbucket";
|
|
|
|
|
|
|
|
return "Online";
|
|
|
|
}
|
2018-01-27 18:13:38 +01:00
|
|
|
}
|