Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/30/2023 in all areas

  1. This week we've got a few minor issue fixes and a couple of pull request additions on the dev branch. Pull request #251 thanks to @Jan Romero added a download button to the thumbnail images in InputfieldImage. I wasn't sure we really needed that, but really liked his thinking behind it, which was envisioning the ability to add more custom buttons/actions for images. So while I didn't specifically add the download button, I added the proposed system for adding any custom buttons, and then applied that same thinking to some other parts of InputfieldImage. And we'll talk about how to add that Download button here. 🙂 First, let's look at how you might add your own download button, and note we're using this as just an example, as you might add any kind of button this way. A new hookable getImageThumbnailActions() method was added for this purpose. So here's how you might hook it (in /site/ready.php) to add a download button: $wire->addHookAfter('InputfieldImage::getImageThumbnailActions', function(HookEvent $event) { $image = $event->arguments(0); // Pageimage $class = $event->arguments(3); // class to use on all returned actions $a = $event->return; // array $icon = wireIconMarkup('download'); $a['download'] = "<a class='$class' href='$image->url' download>$icon</a>"; $event->return = $a; }); With that hook in place, here's what it looks like when you hover a thumbnail image. And if you click that Download icon, it downloads the file to your computer: or in list mode (download icon appears in right corner next to trash): I was thinking it would be useful to also be able to add custom actions after you click the thumbnail, and it shows the image edit features. So let's add a Download button there instead, by hooking the new getImageEditButtons() method: $wire->addHookAfter('InputfieldImage::getImageEditButtons', function(HookEvent $event) { $image = $event->arguments(0); // Pageimage $class = $event->arguments(3); // class(es) to use on all returned actions $buttons = $event->return; // array, indexed by action name $icon = wireIconMarkup('download'); $buttons['download'] = "<button class='$class'><a download href='$image->url'>$icon Download</a></button>"; $event->return = $buttons; }); And the result looks like this (see new Download button after Variations button): We also have that Actions dropdown that you see in the screenshot above. This is already hookable but we've not had any good examples of it. In this case, you need two hooks: one to add the action to the <select> and another to handle the processing of the action when the page is saved. So in our next example, we'll demonstrate how to display verbose EXIF information about whatever image(s) the action was selected for. In this first hook, we'll add the action to the Actions <select>: // Example of adding an “Get EXIF data” action to the <select> $wire->addHookAfter('InputfieldImage::getFileActions', function(HookEvent $event) { $image = $event->arguments(0); // Pageimage if($image->ext == 'jpg' || $image->ext == 'jpeg') { $actions = $event->return; // array $actions['exif'] = 'Get EXIF data'; $event->return = $actions; } }); And in this next hook, we'll handle the action, which gets called when the page editor form is submitted: // Example of handling an “Get EXIF data” action $wire->addHookAfter('InputfieldImage::processUnknownFileAction', function(HookEvent $event) { $image = $event->arguments(0); $action = $event->arguments(1); if($action === 'exif' && file_exists($image->filename)) { $exif = exif_read_data($image->filename); $event->warning([ "EXIF data for $image->name" => $exif ], 'icon-photo nogroup'); $event->return = true; } }); And here's what it shows after you hit save (for any images that had the action selected): The screenshot above is truncated because it was about twice is big as what's above. All the above code examples are also included in the phpdoc for each of the relevant hookable methods in the InputfieldImage module. For another recent useful addition, be sure to check out ProcessWire Weekly #454 (last week) which covered some new options available for the language translation functions like __text('hello'); where you can now tell it what kind of input type (and how many rows) to use in the admin translation interface, via inline PHP comments. Thanks for reading and I hope you have a great weekend!
    2 points
  2. Hey @ryan thx for the additions! And thx @Jan Romero for the PR! I think a download button is a must have on image fields, so for my taste it should be default, but until then I've added a tweak to RockMigrations (v2.15.0) so the download buttons are just a checkbox away 🙂
    1 point
  3. How about adding a meaningful log output everywhere you read or assign your session variable? The log lets verify in which order those are executed, which page calls they come from, and if there's maybe an execution step you didn't think of. In the more complex developments, I like to make such log output conditional on $config->debug. <?php namespace ProcessWire; $session->set( 'event_number', $n ); if($config->debug) $log->save('eventnum', "Wrote event number $n to session"); //....... $evtnum = $session->event_number; if($config->debug) $log->save('eventnum', "Read event number from session: $evtnum");
    1 point
  4. It does appear as though it's related. In my instance I'm using PageListSelect which was mentioned as also being affected by this. I'll give the available solutions a try tomorrow. Thank you!
    1 point
  5. Check the actual session storage in /site/assets/sessions/ or, if you’re using the module “Session Handler Database”, in the database table called “sessions”. Sounds like you already know where to find the session ID but for the record it’s in the cookie called “wires” (this is customisable), available in your browser’s dev tools. You can also check if maybe you’re overwriting the value before reading it on the second page? With a generic term like “session” there’s also always some danger of overriding ProcessWire’s $session variable. Using the Functions API can guard against this.
    1 point
  6. If you're on Mac, you can try/buy https://www.araelium.com/screenflick-mac-screen-recorder. I'm just using it for basic screen recording but it seems it could do what you need (except for "append videos" maybe), plus it can be simple enough.
    1 point
  7. https://obsproject.com/ this is open source and dope https://vento.so/ this was on hackernews the other day and promises some editing capabilities during recording
    1 point
  8. Your problem might be related to Autocomplete and PageListSelect inputfields not allowing for custom selector strings. See Just a guess
    1 point
  9. Yeah it's a pity, but I still haven't found a good replacement for it 😞 tabulator.info has similar features but it's overkill for a simple tabular input..
    1 point
  10. You can use the User::changed hook to do what you want (see https://processwire.com/api/ref/wire/changed/). Put this in site/ready.php: $wire->addHookAfter('User::changed', function ($event) { if($event->arguments(0) === 'pass') { $user = $event->object; $this->wire->log->save('password-changes', "User $user->name has changed their password"); } }); Now everytime a user changes their password, it will be logged to Setup->logs->password-changes. You can do similar thing with roles if($event->arguments(0) === 'roles') { $user = $event->object; $oldRoles = $event->arguments(1); $newRoles = $event->arguments(2); // code to compare $oldRoles/$newRoles // write to log } If you want to have that information in the session log, just do $this->wire->log->save('session',...)
    1 point
  11. I know this is a year old, but having just run into a similar issue, I wanted to point out that just adding check_access=0 should solve this particular problem without including any unwanted pages as a side effect.
    1 point
×
×
  • Create New...