Jump to content

Jan Romero

  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by Jan Romero

  1. HTMX will see the hx- attributes on your element and send a GET request to yourdomain.at/trigger_delay with the value of the input named “q” whenever it is triggered. Whatever the server sends as a response, HTMX will put in the div at the bottom (HTMX calls this “swapping“). Or something like that. I’m not familiar enough with HTMX’s defaults and the trigger syntax to be sure that your code will definitely work. Looks good though. The important parts happen in /trigger_delay, obviously. That is in keeping with HTMX’s whole raison d’être of mostly sticking to doing things on the server. What’s sticking out to me is the url of your endpoint “/trigger_delay”. It looks like this is supposed to be a page that returns search results or type-ahead suggestions, so I would expect something like “/search”.
  2. There is this setting, but I’m not sure whether it will redirect or 404 if the undesired option is requested.
  3. Okay, so, I didn’t think this should happen and indeed it usually doesn’t, but it definitely happens… sometimes??? This is the code I used to test it initially, just at the top of my home template. I visited the page, checked the UrlSegments in the admin and there they were: header('content-type: text/plain'); $page->template->urlSegments = array_merge($page->template->urlSegments, ['hello', 'world']); die(); I tried looking into core/Template.php but nothing seems suspicious… No idea what’s going on but I can reproduce the behaviour on two separate installations, one running 3.0.208 dev and one 3.0.191 dev. I’m not going to investigate this further and blame it on a module or a dumb hook I have set up, but I’m weirded out.
  4. You can use this to change the template settings’ valid UrlSegments: https://processwire.com/api/ref/template/url-segments/. Be aware this persists the change immediately, without having to call $template->save()! You can also use property syntax: //Add UrlSegments “login” and “logout” to whitelist of current page’s template: $page->template->urlSegments = array_merge($page->template->urlSegments, ['login', 'logout']); If you have this requirement, it’s probably worth checking out the relatively new URL hooks: https://processwire.com/blog/posts/pw-3.0.173/
  5. If I’m not mistaken that should be 47,672,401,706,823,533,450,263,330,816 combinations, so… seems sufficient? GUIDs are 128 bit tokens and they’re used for computer things, so for something like this that only needs to work on a human scale it shouldn’t be a problem to go a couple of billion times smaller. Especially if you rate limit against guessing. I wouldn’t ask for the phone number since anyone who intercepted the SMS would know that anyway. Shipment tracking things usually ask for my post code before showing my address, maybe that’s worth considering?
  6. I imagine this may also be achieved without an additional database field using FieldtypeRuntimeMarkup: https://processwire.com/modules/fieldtype-runtime-markup/
  7. Ah yes, my bad, you would have to make the groups mutually exclusive by adding the condition “does not have Type1” to the second one. Unfortunately I don’t think this is possible with FieldtypeMulti fields…
  8. Have you tried Or-Groups? https://processwire.com/docs/selectors/#or-groups $pages->get("template=store_template, (equipment_ref.title='Equipment2', type.title='Type1'), (equipment_ref.title='Equipment2')"); I think this should work for you?
  9. Maybe show those loops you already have, because I for one am unable to figure out what’s going on here in the first place? I suspect you mean Equipment2 here? So matching the equipment is kind of a fallback in case equipment AND type can’t both be matched?
  10. Double slashes used to “just work” but they redirect to the clean url since 3.0.212. Haven’t looked into the code, I suppose the query string gets lost along the way?
  11. @@byte the code you posted is vulnerable to SQL injections, because you're concatenating raw strings from the request into your SQL query (as @zoeck said). Even if it's just an example you're not using in production, I'd prefer if you didn't post it like that, because people might copy it.
  12. Yes, it’s not going to pick up changes to the Fields, because behind the scenes you’re actually adding the Field to the Template’s Fieldgroup. Can’t figure out how to get added fields, but getting removed fields seems to work reliably: foreach(wire('templates') as $template) { /** @var Template $template */ $template->setTrackChanges(Wire::trackChangesValues); $template->setTrackChanges(true); $template->fieldgroup->setTrackChanges(Wire::trackChangesValues); $template->fieldgroup->setTrackChanges(true); } wire()->addHookBefore('Templates::save', function (HookEvent $event) { /** @var Template $template */ $template = $event->arguments(0); bd($template->getChanges(true)); }); wire()->addHookBefore('Fieldgroups::save', function (HookEvent $event) { /** @var Fieldgroup $fieldgroup */ $fieldgroup = $event->arguments(0); bd($fieldgroup->getChanges(true)); //says NULL for added fields, because the previous value of the added field was no field, works well for removed fields bd($fieldgroup->getItemsAdded()); //gives all fields in the set for some reason bd($fieldgroup->removedFields); //this seems to work well }); If you have a use case for this there may be opportunities for PRs here. For example it doesn’t seem reasonable to me that removing a field tracks the change as "removed:<fieldname>" (plus the field itself as the old value) while adding one tracks as "add" without the field name (and no old value, because it was an add).
  13. I just tested this: //ready.php /* Turn on tracking of changed values for all Templates. * Couldn’t find a hook for this, so I’m just iterating * all templates on every request. Should be fine? * Both calls to setTrackChanges() are needed. */ foreach (wire('templates') as $template) { /** @var Template $template */ $template->setTrackChanges(Wire::trackChangesValues); $template->setTrackChanges(true); } /* Dump tracked changes when Templates are saved, or * do whatever with them */ wire()->addHookBefore('Templates::save', function (HookEvent $event) { /** @var Template $template */ $template = $event->arguments(0); bd($template->getChanges(true)); //var_dump($template->getChanges(true)); }); This doesn’t get changes to a template’s fields, but you can probably do something similar with Fieldgroups and Fields themselves.
  14. Hi, by “static pages” do you mean statically served HTML files generated outside of ProcessWire? Or do you want to add a blog to an existing ProcessWire site? I see you’ve been here for several months, so I’m assuming you’re somwhat familiar with PW. It should be a breeze to get a blog going. At its barest, it’s just a template with a title and a body field. For categories, there are different approaches you can go with, depending on how structured you want your data to be. Some blogs just have free-form textual tags, some have fixed categories that work like subdirectories, or anything in-between. Is there anything in particular you’re thinking about?
  15. Hi @e0f! Skimming the latest replies in this thread it sounds like that should be possible with @thausmann’s prototype version: https://github.com/timohausmann/IcsGenerator/tree/multievents You can keep the .ics files around as static files that you only update when something changes (say, by hooking Pages::savedPageOrField) or you can just build them live for each request as you would any other page. Where do you want these files to live exactly? If these calendars are supposed to be private to each user, you’ll need to figure out how to authenticate requests originating from your users’ calendar apps. That may or may not be the biggest hurdle in this endeavour, since they’re probably not going to send the session cookies ProcessWire normally uses. Do you struggle with anything in particular?
  16. IIRC this just takes you to the normal page finder, where you can click the column headers to sort. You can also add and remove columns if the one you’re looking for isn’t there by default.
  17. Haven’t tested but isn’t this just $page->prevAll('limit=5') and $page->nextAll('limit=5')? https://processwire.com/api/ref/page/prev-all/
  18. The way ProcessWire selectors work, this should be sort=-Date_2|Date_1, although I’m neither sure where the hyphens go nor whether sorting allows the pipe operator at all. Alternativey, it’s easy in SQL with coalesce(), or you could add a hidden third field that precomputes to Date_2 ?? Date_1. Edit: doesn’t seem to be supported judging by this open PR https://github.com/processwire/processwire-requests/issues/107
  19. whoops, sorry, I typed that straight into the forum textbox, pretty happy anything works at all 😅 I’ve changed the quotes above, so you should be able to copy it, @Roych PHP’s equality operators are == and ===. This is a classic foot gun, there’s probably even a name for it… Your idea should be fine unless there’s some sort of bulk-trash feature that I don’t know about where the number of children could go from 8 to 6 in one go.
  20. Hi, you can add a hook to execute code whenever a page is moved to the trash. You can use this to check how many children are left and send an e-mail using WireMail. Put this in your ready.php: $this->addHookAfter('Pages::trashed(template=calendar-post)', function(HookEvent $event) { $numberOfItems = wire('pages')->count('parent=/daily-menu/'); if ($numberOfItems <= 7) { $m = new WireMail(); $m->to('chefdecuisine@example.com'); // specify CSV string or array for multiple addresses $m->from('noreply@example.com'); $m->subject("Uh-oh, there are only {$numberOfItems} dishes left on the menu"); $m->bodyHTML("<html><marquee><blink><a href='" . wire('config')->urls->admin . "'>DO SOMETHING QUICK!!!</a></blink></marquee></html>"); $m->send(); } }); Obviously if you trash items one by one, you’ll get one e-mail for every item as long as the total is under 8. A more proper way to do this may be a cron job that only checks once a day. Alternatively you may not need to send an e-mail at all? Perhaps it will suffice to show a message to the user who did the trashing? wire()->message('Please remember to complete the daily menu! There are currently only {$numberOfItems} dishes.'); You could show this just after trashing or simply all the time whenever there are too few items.
  21. 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.
  22. 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
  23. I don’t think this is true. That’s the whole point of the secure files setting. It will only deliver the requested file if you’re logged in. So you can know the URL all you want, you also need a valid session cookie and potentially other fingerprinting stuff (eg. the correct IP).
  24. The way MarkupCache works simply does not allow for this nested use, IIRC. My advice is to just use the database cache (class WireCache, available as $cache or cache()), because it’s much easier to use and understand and probably just as fast. Obviously the speed depends on your setup, but if the database is on the same system and fits into memory it’s probably even faster than the filesystem. Also I would only cache the individual items, since renderResultList() doesn’t add anything interesting. It’s just going to complicate invalidation and bloat the cache table. With $cache you can preload all items in one roundtrip to the database, that should suffice. For more speed gainz you can always look into ProCache. As a sidenote, you’re overriding the WireCache $cache variable with MarkupCache, which may be a source of mistakes to watch out for.
  • Create New...