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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/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;
$query = getenv('QUERY_STRING')??'';
if($query == 'q') {
    printf("10 Transpose into key /([0-9]+|[A-G][b#]?)/\r\n");return;
}
$id = substr(getenv('PATH_INFO')??'',1);
$song = $id ? Song::find($id) : 0;
if($song){
printf("20 text/gemini\r\n");
} else {
printf("30 " . Song::inRandomOrder()->first()->id . "\r\n");return;
}
?>
# <?= $song->title ?>

## <?= $song->verse ?>

<?= $song->author ?>

=> <?= $song->id ?>?q Transpose from <?= $song->plain_key ?>

<?= $song->audio ? "=> {$song->audio} Listen to this song" : "" ?>

```chord sheet
<?= $txt = $song->textTranspose(ucfirst(getenv('QUERY_STRING')??'')) ?>

```
<?php foreach($song->getChordsAttribute($txt) as $symbol => $tabs): ?>
=> /chord.svg/<?=$symbol?>?<?=$tabs[0]?> <?= $symbol ?> (<?=$tabs[0]?>)
<?php endforeach; ?>

=> mailto:zachdecook+songs@gmail.com?subject=<?=
    rawurlencode(json_encode([
        'id' => $song->id, 'title' => $song->title,
        'author' => $song->author,
        'key' => $song->key, 'verse' => $song->verse,
    ]))
    ?>&body=<?= rawurlencode($song->text) ?> Edit song

<?php foreach(Song::inRandomOrder()->limit(5)->pluck('title','id') as $id => $title): ?>
=> <?= $id ?> <?= $title ?>

<?php endforeach; ?>