Backend for songs.zachdecook.com
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
#!/usr/bin/php
<?php

define('LARAVEL_START', microtime(true));
require __DIR__.'/../vendor/autoload.php';
require __DIR__.'/../load-eloquent.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
use App\Song;

$q = getenv('QUERY_STRING');
if (!$q) {
	printf("10 Enter a verse to search.\r\n");
	exit(0);
}

try {
	$results = Song::whereVerse($q)->get(['id', 'verse', 'title']);
} catch (Throwable $e) {
	printf("51 ".$e->getMessage()."\r\n");
	exit(0);
}

if (!count($results)) {
	printf("51 No songs found for '$q'.\r\n");
	exit(0);
}

printf("20 text/gemini\r\n");
?>
<?php foreach($results as $song): ?>
=> gemini://<?=getenv('HOSTNAME')?>/song.gmi.php/<?=$song->id?> <?= $song->verse ?>: <?= $song->title ?>

<?php endforeach; ?>