Backend for songs.zachdecook.com
* Gemini Editing: use json subject line
| -rw-r--r-- | laravel/applyedit.php | 10 | ||||
| -rwxr-xr-x | laravel/public/song.gmi.php | 8 |
2 files changed, 14 insertions, 4 deletions
diff --git a/laravel/applyedit.php b/laravel/applyedit.php index 034cca1..993203c 100644 --- a/laravel/applyedit.php +++ b/laravel/applyedit.php @@ -13,13 +13,17 @@ for($i = 0; $i < 10; $i++) { // TODO: Process these in order? $header = imap_header($imap, $number - $i); if (strpos($header->to[0]->mailbox, "+songs")){ - $id = explode(" ", $header->subject)[2]; - $song = Song::findOrFail($id); + $json = json_decode($header->subject); + $song = Song::findOrFail($json->id); $body = quoted_printable_decode(imap_body($imap, $number - $i)); $song->text = $body; + $song->title = $json->title; + $song->author = $json->author; + $song->key = $json->key; + $song->verse = $json->verse; $song->save(); imap_delete($imap, $number - $i); - printf("updated song $id"); + printf("updated song {$song->id}"); exit(0); } } diff --git a/laravel/public/song.gmi.php b/laravel/public/song.gmi.php index 8e3c43b..e4a84d6 100755 --- a/laravel/public/song.gmi.php +++ b/laravel/public/song.gmi.php @@ -30,7 +30,13 @@ printf("30 " . Song::inRandomOrder()->first()->id . "\r\n");return; ``` -=> mailto:zachdecook+songs@gmail.com?subject=Edit%20Song%20<?= $song->id ?>&body=<?= rawurlencode($song->text) ?> Edit song +=> 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 ?> |