Backend for songs.zachdecook.com
* Gemini: Provide mechanism to edit songs over email
| -rw-r--r-- | laravel/applyedit.php | 26 | ||||
| -rwxr-xr-x | laravel/public/song.gmi.php | 2 |
2 files changed, 28 insertions, 0 deletions
diff --git a/laravel/applyedit.php b/laravel/applyedit.php new file mode 100644 index 0000000..034cca1 --- /dev/null +++ b/laravel/applyedit.php @@ -0,0 +1,26 @@ +<?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; + +$imap = imap_open($mailbox, $username, $password); +$check = imap_check($imap); $number = $check->Nmsgs; +// Just check the newest 10 messages. +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); + $body = quoted_printable_decode(imap_body($imap, $number - $i)); + $song->text = $body; + $song->save(); + imap_delete($imap, $number - $i); + printf("updated song $id"); + exit(0); + } +} +exit(0); diff --git a/laravel/public/song.gmi.php b/laravel/public/song.gmi.php index 4bf424d..8e3c43b 100755 --- a/laravel/public/song.gmi.php +++ b/laravel/public/song.gmi.php @@ -30,6 +30,8 @@ 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 + <?php foreach(Song::inRandomOrder()->limit(5)->pluck('title','id') as $id => $title): ?> => <?= $id ?> <?= $title ?> |