-
Posts
680 -
Joined
-
Last visited
-
Days Won
18
Everything posted by Jan Romero
-
API, how do I dynamically add a segment url to a template?
Jan Romero replied to Alexey's topic in Getting Started
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. -
API, how do I dynamically add a segment url to a template?
Jan Romero replied to Alexey's topic in Getting Started
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/ -
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?
-
I imagine this may also be achieved without an additional database field using FieldtypeRuntimeMarkup: https://processwire.com/modules/fieldtype-runtime-markup/
-
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…
-
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?
-
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?
-
@@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.
-
Get previous template/field properties on saving
Jan Romero replied to MarkE's topic in API & Templates
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). -
Get previous template/field properties on saving
Jan Romero replied to MarkE's topic in API & Templates
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. -
How do I ADD a blog to my website without turning it into a blog?
Jan Romero replied to Boost's topic in Getting Started
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? -
Organising page tree in folders without changing paths
Jan Romero replied to JayGee's topic in General Support
I’m gonna say Virtual Parents? -
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?
-
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.
-
Can I return next 5 pages and previous 5 pages?
Jan Romero replied to double's topic in Getting Started
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/ -
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
-
Send mail to administrator if there is only 7 children?
Jan Romero replied to Roych's topic in API & Templates
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. -
Send mail to administrator if there is only 7 children?
Jan Romero replied to Roych's topic in API & Templates
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. -
PHP Session the PW way at its most basic
Jan Romero replied to modifiedcontent's topic in General Support
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. -
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
-
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).
- 8 replies
-
- 1
-
- images
- permission denied
-
(and 1 more)
Tagged with:
-
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.
-
This sounds like kind of a big project. I would advise you to make one or two smaller sites with ProcessWire first. You may find that you can add the multi-user stuff on later, but most likely you will have learned so much that you’ll want to start from scratch anyway ? Check this out regarding different user types: https://processwire.com/blog/posts/processwire-core-updates-2.5.14/#multiple-templates-or-parents-for-users Just using the built-in roles and permissions features may be more than sufficient, though. One important thing to consider is whether these users will all be trusted. Are they people you know or do you want to allow any rando off the internet to make an account? Do you want to let them into ProcessWire’s admin backend or do you want to build custom forms for everything?
-
The computer mostly did a good job, but I wouldn’t put it quite like this. One major thing to note about ImageMagick is that it is generally used without a graphical user interface and in fact without immediate user input. If the server on which you run ProcessWire has ImageMagick installed, ProcessWire can use it to create versions of your images in different sizes such as thumbnails. Shared hosting providers sometimes offer this (some don’t, but ProcessWire can also use a different library called “GD”). Basically you wouldn’t manually use ImageMagick before uploading images to your site. FileZilla can be used to install ProcessWire and transfer your own PHP code, but for uploading images and managing your webcomic, you would use ProcessWire’s admin area. That is, you would upload images over HTTP instead of FTP. ProcessWire then automatically creates thumbnails and puts everything where it needs to be (on the file system and in the database). To do this as a user you don’t need to know what any of these things mean. You just click upload, choose your images and hit save.