Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/10/2022 in all areas

  1. I don't remember the last time I laughed so hard ?.
    5 points
  2. It's not only JavaScript, sometimes it's the design of our backend...
    4 points
  3. Yep, RockToken can help here ? https://github.com/baumrock/RockToken
    3 points
  4. 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 points
  5. No, the issue is not the JS, the issue is that the data received is not properly formatted, so the client thinks the request failed and it fires a new request which is the same as if it were ajax polling. If the received data is properly formatted the stream can be read and the connection keeps open. This is my JS: const evtSource = new EventSource(url, { withCredentials: true } ); evtSource.onmessage = function(event) { console.log(event); if(event.data==='DONE') { evtSource.close(); if(modal) modal.hide(); if($button.data('reload')) RockGrid2.getGrid($button).reload(); } else if($progress) { $progress.fadeIn(); $progress.html(event.data); } }
    2 points
  6. Thanks for the reply, @thetuningspoon I did try extending the autoloader in init.php instead of ready.php but it seemed to make no difference. The only thing that seemed to work for me was a direct include of the trait file from within site/classes/UserPage.php. Will try again though in case I did something wrong first attempt. No, still getting that error when it comes to autoloading for UserPage regardless of the location of the extension to the autoload mechanism. Actually, that might work fairly well in this case, though I'd really like to be able to get to the bottom of the autoloading.
    1 point
  7. Have you tried adding the namespace to the autoloader inside site/init.php instead of site/ready.php? wire('classLoader')->addNamespace('ProcessWire', wire('config')->paths->templates . "traits/"); If you have usePageClasses set to true in the config.php and are using the /site/classes/ folder then I would think this wouldn't even be necessary since that should already be included in the places for the autoloader to look. I haven't come across the need for traits yet, although I keep forgetting that they exist in php now. When I think of composition I usually think of moving certain functionality out into a separate class that would then be instantiated somewhere inside the other class. You can create classes that don't extend Page (perhaps that that extend Wire or WireData if you want easy API access) and then use those in your Page derived class. Your example is probably intentionally oversimplified, but sometimes I find that sometimes a bit of duplicated functionality is really just incidental and doesn't actually justify creating a new layer of inheritance or a separate class at all, especially as you might later discover that the two functions actually serve slightly different purposes and at that point are tied together and difficult to pull apart. You could also use a PW hook to add this function to both classes, although it wouldn't be as elegant.
    1 point
  8. @monollonom, you could do this with a hook in /site/ready.php: $wire->addHookAfter('InputfieldRepeater::renderReadyHook', function(HookEvent $event) { /** @var InputfieldRepeater $inputfield */ $inputfield = $event->object; // Disable RepeaterEasySort on all Repeater fields apart from those named "foo" if($inputfield->hasField && $inputfield->hasField->name !== 'foo') { $inputfield->removeClass('RepeaterEasySort', 'wrapClass'); } }, [ 'priority' => 101 ]);
    1 point
  9. Same here. The while loop is locking up everything. @bernhard, could you please provide more info regarding the endpoint of your url? I.e. ☝️ That url is pointing to some url in ProcessWire. Is it a page URL or a virtual URL that you handle using URL Hooks? Either way could you please show us how you handle requests to that URL in ProcessWire/PHP? I realise you have the thread below as well, but it doesn't show us how you handle 'pings' to your backend either. I am guessing this is where you have your while loop but it would be good to see the whole picture. Thanks.
    1 point
  10. That's how I got wind of it but on reddit: https://www.reddit.com/r/htmx/ ? 6K+ more views since I posted it here. Some of those are mine ?. I've watched it 5 times already and counting...?
    1 point
  11. 1 point
  12. Thank you Andreas. That is very slick and impressive! I hadn't thought of creating a hidden page for selections and time limiting the page. I think it could work for my images too. I'll have to explore Page References too as I never used them before. Paul Thanks for the heads up. I will take a look at this. Paul
    1 point
  13. @adrian @Claus fixes pushed - thanks you ?
    1 point
  14. I've had the same problem - the script seemed to work but sent several requests just like ajax polling: But I've managed to get it working correctly and the result is a nice stream of data and updating feedback for the user while bulk-editing of data in RockGrid. There's no reload, no ajax-polling: The key is to echo the correct message. I've built a method for this in my module: /** * Send SSE message to client * @return void */ public function sse($msg) { echo "data: $msg\n\n"; echo str_pad('',8186)."\n"; flush(); } If you do that, you can do something like this: <?php header("Cache-Control: no-cache"); header("Content-Type: text/event-stream"); $i = 0; while(true) { $this->sse("value of i = $i"); if($i>30) return; // manual break after 30s for testing while(ob_get_level() > 0) ob_end_flush(); if(connection_aborted()) break; sleep(1); } Not sure if the ob_get_level and ob_end_flush are necessary...
    1 point
  15. Aha / bingo from running <?php phpinfo(); ?> on PHP 8.0.16: disable_functions disk_total_space, diskfreespace, exec, system, popen, proc_open, proc_nice, shell_exec, passthru, dl
    1 point
  16. I have changed my PHP version from 7.x to 8.1. The changeover will take 10 mins, and I’ll report back if the output changes. (Please see my above post – I edited it.)
    1 point
  17. Alright, it worked, and it returns nothing. The hosting provider is One.com I found a way to enable PHP debug in the One.com interface, and now I get: Fatal error: Uncaught Error: Call to undefined function disk_total_space() in /customers/a/0/5/website.com/httpd.www/test_disk.php:1 Stack trace: #0 {main} thrown in /customers/a/0/5/website.com/httpd.www/test_disk.php on line 1
    1 point
  18. @flydev ?? - obviously not at all important, but - note the incorrect tooltip text.
    1 point
  19. Just installed this module on the DEV version. But my hosting didn’t like it: Fatal Error: Uncaught Error: Call to undefined function disk_total_space() in site/modules/Duplicator/Duplicator.module:1135 #0 site/modules/Duplicator/Duplicator.module (1230): Duplicator::getLocalFolderInfo() #1 [internal function]: Duplicator::getModuleConfigInputfields(Array) #2 wire/core/Modules.php (4110): call_user_func(Array, Array) #3 wire/core/Wire.php (420): Modules->___getModuleConfigInputfields('Duplicator', Object(InputfieldForm)) #4 wire/core/WireHooks.php (951): Wire->_callMethod('___getModuleCon...', Array) #5 wire/core/Wire.php (485): WireHooks->runHooks(Object(Modules), 'getModuleConfig...', Array) #6 wire/modules/Process/ProcessModule/ProcessModule.module (1665): Wire->__call('getModuleConfig...', Array) #7 wire/modules/Process/ProcessModule/ProcessModule.module (1399): ProcessModule->renderEdit('Duplicator', Array) #8 wire/core/Wire.php (414): ProcessModule->___executeEdit() #9 wire/core/WireHooks.php (951): Wire->_callMethod('___executeEdit', Array) #10 wire/core/Wire.php (485): WireHooks->runHooks(Object(ProcessModule), 'executeEdit', Array) #11 wire/core/ProcessController.php (337): Wire->__call('executeEdit', Array) #12 wire/core/Wire.php (414): ProcessController->___execute() #13 wire/core/WireHooks.php (951): Wire->_callMethod('___execute', Array) #14 wire/core/Wire.php (485): WireHooks->runHooks(Object(ProcessController), 'execute', Array) #15 wire/core/admin.php (160): Wire->__call('execute', Array) #16 wire/modules/AdminTheme/AdminThemeDefault/controller.php (13): require('/customers/a/0/...') #17 site/templates/admin.php (15): require('/customers/a/0/...') #18 wire/core/TemplateFile.php (327): require('/customers/a/0/...') #19 wire/core/Wire.php (414): TemplateFile->___render() #20 wire/core/WireHooks.php (951): Wire->_callMethod('___render', Array) #21 wire/core/Wire.php (485): WireHooks->runHooks(Object(TemplateFile), 'render', Array) #22 wire/modules/PageRender.module (575): Wire->__call('render', Array) #23 wire/core/Wire.php (417): PageRender->___renderPage(Object(HookEvent)) #24 wire/core/WireHooks.php (951): Wire->_callMethod('___renderPage', Array) #25 wire/core/Wire.php (485): WireHooks->runHooks(Object(PageRender), 'renderPage', Array) #26 wire/core/WireHooks.php (1059): Wire->__call('renderPage', Array) #27 wire/core/Wire.php (485): WireHooks->runHooks(Object(Page), 'render', Array) #28 wire/modules/Process/ProcessPageView.module (184): Wire->__call('render', Array) #29 wire/modules/Process/ProcessPageView.module (114): ProcessPageView->renderPage(Object(Page), Object(PagesRequest)) #30 wire/core/Wire.php (417): ProcessPageView->___execute(true) #31 wire/core/WireHooks.php (951): Wire->_callMethod('___execute', Array) #32 wire/core/Wire.php (485): WireHooks->runHooks(Object(ProcessPageView), 'execute', Array) #33 index.php (55): Wire->__call('execute', Array) #34 {main} thrown (line 1135 of site/modules/Duplicator/Duplicator.module) This error message was shown because: you are logged in as a Superuser. Error has been logged.
    1 point
  20. As we continue to work towards the next master version, this week I've been working on fixing reported issues. A new $sanitizer->words() method was also added which reduces a string to contain just words without punctuation and such. It was added in part to work on an issue reported with the tags feature in the field editor, but should be handy for other cases as well. As part of that update, the existing $sanitizer->word() (singular) method was re-written to support the features needed for the new words() plural method. This week I've also been working on a pull request from Bernhard that enables greater customization of AdminThemeUikit by way of custom render files and hooks. I'm bringing in that PR and it has a lot of good ideas that have inspired some related updates to it. I've got a bit more work and testing to do before committing, but that part should be ready early next week, along with more core updates. Thanks for reading and have a good weekend!
    1 point
  21. The term "hint" is a good here, but it's more than that. The purpose of any site profile (no matter how minimal) is to be a functional starting point. The blank profile is now the only core profile so most people will start with it. The /site/classes/ directory is important and is likely forgotten by all but the most experienced users, if it is not present. I think it belongs in the most minimal starting point. You have to have at least one file in a directory in order for it to remain through git, site profile and installation. Being the blank profile, the class itself is blank, a placeholder, like the directory itself. It exists to explain what the directory is for and the format files must use within it. It's a readme that exemplifies what it describes. Any site profile must be functional and it's worth noting that all site profiles, no matter how minimal, all have a "home" template (and an "admin" template). So a home.php template file and a HomePage.php class file are part of that minimal but functional starting point, even if blank.
    1 point
  22. I've been interested in sharing my setup since it's radically changed over the last year for the better. Wish I could open the repo for the code of my flagship project, but it's the site for the company I work for and isn't mine, www.renovaenergy.com Local Dev: Code editor is Sublime Text tuned for my preferences/workflow. OS is Ubuntu Linux, will probably distro-hop at some point like Linux users do. Environment is provided by Devilbox, which I can't recommend enough. It's a fast (mostly) pre-configured yet customizable Docker tool with outstanding documentation. A ProcessWire ready container is available. CSS/JS compiled by Gulp/Babel/Browserify for local dev and production builds. ES6 modules. Zero frameworks, no jQuery. Focus on lightweight JS and code splitting for better load times. CSS is compiled and split into separate files by media queries which are loaded by browsers on demand based on screen size. Currently building out website unit/integration tests using Codeception. This is becoming increasingly necessary as the site becomes more complex. Firefox Developer Edition Tilix terminal emulator, Quake mode is awesome Cacher stores code/scripts/configs in the cloud for easy sharing across machines. IDE integration is solid Meld for fast diffs WakaTime because who doesn't like programming metrics for yourself? DevDocs but locally in a Nativefier app. REQUEST: Star ProcessWire on Github. If a project has 7k+ stars it is a candidate to have it's documentation added to DevDocs. Production: Code editor is Vim on server Deployment is via Git. Local repositories have a secondary remote that pushes code to production via a bare GIT repo which updates assets on the server using hooks. Access to server via SSH only. Changes to files only made locally and pushed. Hosting by DigitalOcean with servers custom built from OS up for performance/security. Custom PageSpeed module implementation. Automatic image conversion to webp, file system asset caching, code inlining, delivery optimization, cache control, etc. Driven down TTFB <=500ms on most pages with load times around 2 seconds sometimes less if I'm lucky haha StatusCake monitors uptime, automated speed tests, server resources, and HTTPS cert checking. PagerDuty is integrated with StatusCake so issues like servers going down, server resources (ram/disk/memory) low, and whatever else get notifications on all your devices. 7G Firewall rules are added to the PW .htaccess file to block a ton of bots and malicious automated page visits. Highly recommended. Mailgun for transactional email ProcessWire Modules & Features: Modules (most used): CronjobDatabaseBackup, ProFields, Fluency, ImageBlurHash, MarkupSitemap, PageListShowPageId, ProDevTools, TracyDebugger, ListerPro, ProDrafts Template cache. We used ProCache initially but saw some redundancies/conflicts between it and PageSpeed tools on the server. Would absolutely recommend ProCache if your hosting environment isn't self-managed. All configurations are saved in .env files which are unique to local/staging/production environments with contents stored as secure notes in our password manager. This is achieved using the phpdotenv module loaded on boot in config.php where sensitive configurations and environment-dependent values are made securely available application-wide. Extensive use of ProcessWire image resizing and responsive srcset images in HTML for better performance across devices. URL Hooks - Use case- We rolled out a Web API so external platforms can make RESTful JSON requests to the site at dedicated endpoints. The syntax resembles application frameworks which made development really enjoyable and productive. The code is organized separately from the templates directory and allowed for clean separation of responsibilities without dummy pages or having to enable URL segments on the root page. Also allowed for easily building pure endpoints to receive form submissions. Page Classes - My usage -This was a gamechanger. Removing business logic from templates (only loops, variables, and if statements allowed) and using an OOP approach has been fantastic. Not sure if many people are using this but it's made the code much more DRY, predictable, and well organized. Implementing custom rendering methods in DefaultPage allowed for easily "componentizing" of common elements (video galleries, page previews, forms, etc) so that they are rendered from one source. Helped achieve no HTML in PHP and no PHP in HMTL (with the exceptions above). Also allows for using things like PHP Traits to share behavior between specific Page Classes. I completely fell in love all over again with PW over this and now I couldn't live without it. This literally restructured the entire site for the better. Probably other stuff but this post is too long anyway haha.
    1 point
  23. Hi all, new post instead of updating again and again the previous one... here we are, the translation is now complete, yes, i know i said yesterday "in a few days" but i forgot the kind of crazy guy i am ? no more abandoned/unused string/phase no more empty string/phrase no more files in the "no translation file exists" list which means some never translated files are now... translated ? and those that were translated but didn't exist anymore for completely revamped modules/filetypes are now translated again https://github.com/virtualgadjo/pw30184-lang-fr hope it will help, promise, i won't flood this post again before the next PW master release ?
    1 point
  24. Right — seems like it's an issue with formatting, i.e. single quote gets escaped (converted to HTML entity). Try $sanitizer->selectorValue($page->getUnformatted('title')) instead, that should work.
    1 point
×
×
  • Create New...