Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/26/2024 in all areas

  1. I solved it myself by the following code. 1. Create a custom RepeaterPage class for my tracks and add a specific method to create a session-based URL for streaming. <?php namespace ProcessWire; /** * @property Pagefile $audio */ class TracksRepeaterPage extends RepeaterPage { /** * @param string $streamUrl Default stream URL when audio file does not exist * * @return string */ public function getStreamUrl(string $streamUrl = ''): string { // Check whether audio file exists and if it does create a session-based stream URL if ($this->audio) { // Create the file hash and add it to the session as key for the audio file path $audioPath = $this->audio->filename(); $fileHash = hash('sha1', $audioPath . session_id()); session()->setFor('stream', $fileHash, $audioPath); // Create the stream URL with the file hash $streamUrl = '/stream/' . $fileHash . '.mp3'; } return $streamUrl; } } 2. Create a custom hook to watch for the stream URL in the ready.php: <?php namespace ProcessWire; if (!defined("PROCESSWIRE")) { die(); } wire()->addHook('/stream/([\w\d]+).mp3', function ($event) { // Get the audio file path by file hash $fileHash = $event->arguments(1); $audioPath = session()->getFor('stream', $fileHash); // Check whether audio file exists and stream it when it does or throw 404 if (file_exists($audioPath)) { wireSendFile($audioPath, [], [ 'content-transfer-encoding' => 'chunked', 'accept-ranges' => 'bytes', 'cache-control' => 'no-cache' ]); } throw new Wire404Exception(); }); Ta da! 🙂 When the session expires, the session-based file hashes are destroyed and the stream URL no longer work. So every time the session is renewed with a new session ID, a new unique session-based stream URL is generated for each tracks. Have I missed anything or are there any security issues?
    2 points
  2. Awesome! That was one easy fix.
    1 point
  3. Cool! Thank you @Nicolas ! I did modify that code slightly. I put it into ready.php: wire()->addHookBefore("Pages::published(template=article)", function($hook) { $page = $hook->arguments(0); if($page->skipMyHook) { // if the page already has our temporary property, we skip further processing return; } $newUrl = date("Y-m-d-") . wire()->sanitizer->pageName($page->title) ; // give it a name used in the url for the page wire()->log->message($page->title); $page->skipMyHook = true; // add a temporary property to the page (it is only in memory) $page->setAndSave('name', $newUrl); });
    1 point
  4. Hi @Stefanowitsch, Have you tried <?php nl2br($item->description); I expect the IG caption uses newlines, this would convert them to <br> tags. The module passes the caption through $sanitizer->entities1() which shouldn't remove the newlines as far as I'm aware. Cheers, Chris
    1 point
  5. I don't know if that could be the reason, but I don't use the host at all any more in my config files. I always use the concept of including different files on my local development and on remote servers. See here: One of the reasons is that the hostname (or in your case the HTTP_HOST variable) might not be available. For example when bootstrapping or calling it from a cronjob. Or the variable might be empty for whatever reason. When including different config-local.php files on local dev and on production/staging you don't have these problems. That would at least be something that you can try.
    1 point
  6. We’re moving along with trying to cover as many small issue fixes as possible for the next main/master version. So that’s what all the commits this week are for. There’s not much more to report than that, making good progress! If you spot any new issues on the dev branch be sure to report them in the processwire-issues repository. Thanks and have a great weekend!
    1 point
  7. @Thomas -Allwinds Webstudio when creating your IntlDateFormatter, do you set the locale based on the user’s language or is hard-coded like in your code sample? It depends on how you named your languages or which one is your default but maybe it could be: $datum = $concert->date; $fmt = new \IntlDateFormatter($user->language->isDefault() ? "en_US" : "de-DE", \IntlDateFormatter::FULL ); $fmt->setPattern('E, d. LLLL yyyy, HH:mm'); echo $fmt->format($datum);
    1 point
×
×
  • Create New...