Jump to content

netcarver

PW-Moderators
  • Posts

    2,233
  • Joined

  • Last visited

  • Days Won

    47

Everything posted by netcarver

  1. Hello, I'm starting to play catch-up with some of the recently (and not-so-recently) added features to PW. In particular, I'd like to ask about more complex uses of Page Classes. I have a site where the end users are actual PW Users with first and last name fields. I also have several other templates in the system that have the first and last name fields but they are not actually Users of the system, rather they are entities like Contacts or other personages that can be also be named. I thought I'd enable page classes and add a simple getName() method to the UserPage class to allow their name fields to be nicely concatenated. In itself, no problem, as long as I remember to extend from User. So here's exhibit A: UserPage.php... <?php namespace ProcessWire; class UserPage extends User { function getName() { return trim($this->first_name . ' ' . $this->last_name); } } This works fine, I can call getName() on my users, nice. Now, my other nameable entities need this function too. I can extend from UserPage to inherit the getName() function, which works well and is straightforward... <?php namespace ProcessWire; class ContactPage extends UserPage { } So I can now use $contact->getName() as well as $user->getName(). But, my contacts aren't really system users, so I'd prefer not to inherit from UserPage at all, but either inherit from some intermediate class representing some form of NameableEntity or else use traits to compose the functionality into the individual page classes which need it. However, I'm hitting snags with both approaches and would appreciate some feedback. Attempt at Traits So I add the following as site/classes/NameHandlingTrait.php... <?php namespace ProcessWire; trait NameHandlingTrait { public function getName() { return trim($this->first_name . ' ' . $this->last_name); } } And switch my ContactPage.php over to using it... <?php namespace ProcessWire; class ContactPage extends Page { use NameHandlingTrait; } And that works. I can access $contact->getName(); (I actually did it by setting up the wire autoloader in ready.php to look for a specific namespace in a traits/ subdirectory - but I'll skip showing that here, it did work for my page classes that extend from Page.) However, when I try switching UserPage.php over to the same trait code to keep it DRY... <?php namespace ProcessWire; class UserPage extends User { use NameHandlingTrait; } I immediately hit the following error: "Fatal Error: Trait 'NameHandlingTrait' not found (line 5 of /site/classes/UserPage.php)" either when visiting the site (front end or admin) or by bootstrapping from the CLI. I can overcome this by manually requiring/including the trait file at the start of UserPage.php - but I'd much rather autoload it if at all possible. No matter how early I try to declare the extension of the class loader to attempt to autoload the trait, it isn't soon enough and I always hit the fatal error shown above. Can anyone shed any light on this? How do you go about using the PageClasses, especially UserPage, when the structure might need to take more of a composition-rather-than-inheritance form? Also, if you have any suggestions as to other places to get autoloading set up in PW prior to init.php or ready.php I'm all ears. I tried setting up the autoloader mappings in both places and they work for classes derived from Page but not for UserPage - so I suspect PW is creating a User instance pretty early on in its bootstrap, well before it is loading in extensions to the autoloader. I'll try adding a PSR-4 clause to composer.json and dumping the composer autoloader next - but I'd rather stick with native PW autoloading if possible. Intermediate Base Class The other approach I've tried is to use an intermediate base class to house the getName() function and inherit from that. This is doable for the classes derived from Pages but again, I hit the snag that the UserPage seems to have to extend User, and not my base class. @ryan What would you recommend here? Could UserPage extend something other than User?
  2. @fruid Not 100% sure what's going on, but running grep in the site/modules/wireMailSmtp/ folder shows it's using mcrypt functions on lines 67, 68 and 79 of smtp_classes/ntlm_sasl_client.php - but mcrypt was removed from PHP7.2. It might be that @wbmnfktr isn't running into the issue if his setup is connecting to an smtp server without using ntlm_sasl. Is the SMTP server you are connecting to using Windows by any chance? (This might be a wild-hunch) Looks like that file was originally part of PHPMailer - and there are some posts about fixing it to work with NTLM that are more recent. Like this one: https://cheesefather.com/2017/06/phpmailer-ntlm-ms-exchange-smtp-authentication/ (though for a different hash() issue). You might be able to use that to patch your local copy - or otherwise look for a more recent version of the ntlm_sasl_client class.
  3. Hi Adrian, Is it possible to extend Tracy's definition of local host in some way? I'm running my sites out of docker containers on my local machine and can't get it to force guest users into development mode - probably because of the internal IP address assignments to the docker bridge networks. When I visit my site from the browser on my host, the visit has an IP address in the 172.16.x.y range. I'd like to be able to force guests into development mode for a specific visiting IP or block if that's possible. May be something in the settings for this already that I've missed. Regards, Steve
  4. Easy to hit a key combo to go to the end once in the editor. I'd axe the line number from the link.
  5. @teppo Maybe Soma's LogMaintenance module would be useful?
  6. Is your website built using ProcessWire?
  7. You're misquoting me, @bernhard :) Could you try this... <script> var evtSource = new EventSource("sse.php") evtSource.addEventListener('ping', function(event) { var data = JSON.parse(event.data) console.log(data) }, false) </script>
  8. Nice, are you using mermaid-js for the diagramming?
  9. Hi @3fingers Right, so the demo video I posted did this using a few separate parts. An event generator wrote messages into a Redis pubsub channel, and I had a long-running ReactPHP process subscribed to the channel which would then take those events from Redis and send them via SSE to any connected listeners. A little custom JS in the website's home page would connect via SSE to the server and would be asynchronously invoked when an SSE message came in. The JS was really simple, it parsed the incoming SSE message to grab an html id and the new content for that part of the DOM and then do the change (along with a little CSS styling to highlight the swap.) The most difficult part was running the ReactPHP process. In your case, you could replace the back end event generator with a hook and just publish a change when the PW admin control is changed. Anyone connected would then have their screen updated immediately. PM me if you want to discuss directly.
  10. @ryan As a possible alternative to having something polling for changes, have you considered some kind of server side push technology for signalling changes to the connected browsers as mentioned above by @Ivan Gretsky? I've been playing with using a thin ReactPHP layer that sends DOM mutation messages to clients using SSE (which has really good support in browsers) and have about 20 lines of vanilla JS in the browser that does the element replace in the DOM when it gets a message over SSE (though htmx could be used for this too). None of the connections in the video are polling. nifty-reactivedash-demo.mp4
  11. Anyone seeing issues with the generated thumbnail for vimeo-based embedded videos? Currently just getting a stripy image back from vimeo no matter what video is embedded. Pressing play works - the video is streamed and played without issue, it's just the thumbnail from vimeo that's the problem. Looks like this...
  12. Nice, thank you Robin. Seems to work well.
  13. @jds43 That would probably be indicative of your server side code running more than just your ajax section. It's probably not what you are outputting in the rendered htmx you just posted. In the example kongondo posted above, the ajax route ends by calling $this->halt() to finish off PWs processing after echoing out the html. Is your code doing this? NB it is only possible to use halt() in some situations (like template files, IIRC) so you'll need to do that or just call exit(); if in a different context.
  14. Any difference in PHP versions between these two setups?
  15. This requires a more recent version of PW than 3.0.165 - I'm currently using 3.0.182.
  16. Please do. And thank-you for what you've already shared. I just started using this today and it's looking good so far.
  17. Ok, like @rick said, please try to use the absolute path if possible. If that doesn't work I'd then want to check that the u9...9 user actually has access to PW's files. If that user is not the same user as the HTTP server user (like apache) then sometimes this can be an issue.
  18. Ok, so there are no errors in the apache/PHP Logs but what about in PWs log Error/Exception logs?
  19. @Manaus Take a look at Lakeland Trails from @Pete at Nifty Solutions. Almost 52 thousand users. Might be worth pinging him to ask more about the actual pros/cons of doing it that way.
  20. Hi @horst, thanks for the reply, but unfortunately not. I have found a work-around that I can use for now by hooking the login register pro login-form processing which happens before the session::login hook gets called, and removing it there does work.
  21. Hello wonderful PW-philes, I have a situation where I'd like to prevent system notifications from being stored when a self-registered user logs in or out (or fails to log in.) These events just clutter up the systemUser's notification list so I thought I'd add a hook early in the hook chain that works out if it's a self-registered user logging in and then just remove the System Notification module's hook by using removeHook(). Sure enough, I can find the target hook in the hooks returned by the system - and seemingly remove it from the hooks array - but the hook is still executed no matter how I call removeHook(). Here's the things I've tried in my hi-priority session::login hook that don't work... $id = $this->findSystemNotificationLoginHook(); $event->removeHook($id); $this->removeHook($id); parent::removeHook($id); $this->session->removeHook($id); wire()->session->removeHook($id); I've also tried targetting the actual instance by attaching to wire()->session->addHookAfter('login'...) as well - and tried doing addHookBefore(). I'm guessing that it's actually too late to remove the hook when I make the call as the hook array associated with this event is already being processed by PW and it's working its way through a local copy of the event's hooks. Does anyone have a way of removing a later hook from an event-in-progress? I can't just cancel the event as there may be other, lower priority hooks on the session::login event that I'm targetting.
  22. Never used it, but I know some folks use Wistia to host video content.
×
×
  • Create New...