/
init.php
69 lines (54 loc) · 1.73 KB
/
init.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
<?php
require __DIR__.'/config.php';
require __DIR__.'/vendor/autoload.php';
session_start();
function getDb()
{
return new PDO('mysql:dbname='.Config::DB_NAME.';host='.Config::DB_HOST, Config::DB_USER, Config::DB_PASS);
}
function login()
{
if (!empty($_SESSION['login']) || php_sapi_name() == 'cli')
return true;
if (!isset($_SERVER['PHP_AUTH_USER'])
|| $_SERVER['PHP_AUTH_USER'] != \Config::ADMIN_USER
|| $_SERVER['PHP_AUTH_PW'] != \Config::ADMIN_PASS) {
header('WWW-Authenticate: Basic realm="Backend"');
header('HTTP/1.0 401 Unauthorized');
exit;
}
$_SESSION['login'] = true;
}
function getPersons()
{
$db = getDb();
$query = $db->prepare('SELECT DISTINCT person FROM photo2person ORDER BY person ASC');
$query->execute();
return $query->fetchAll();
}
function generateQRCode($hash)
{
$link = Config::HOST.Config::BASE_URI.'gallery/'.$hash;
$imageBlob = (new Endroid\QrCode\QrCode())
->setText($link)
->setPadding(7)
->setErrorCorrection('high')
->get();
$qrcode = new Imagick();
$qrcode->readImageBlob($imageBlob);
$qrcode->scaleImage(600, 600, true);
$camera = new Imagick(__DIR__.'/camera.png');
$qrcodeSize = $qrcode->getImageGeometry();
$cameraSize = $camera->getImageGeometry();
$qrcode->compositeImage($camera, Imagick::COMPOSITE_DEFAULT,
round(($qrcodeSize['width'] - $cameraSize['width']) / 2),
round(($qrcodeSize['height'] - $cameraSize['height']) / 2));
$qrcode->setImageFormat('png');
header('Content-Type: image/png');
echo $qrcode->getImageBlob();
$qrcode->clear();
$qrcode->destroy();
$camera->clear();
$camera->destroy();
exit;
}