Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by monollonom

  1. After doing a quick check I assume that was it (multilang issue). Here's a new version that will only output the QR Code in the user's language if it's a guest. Please note you'll still have the two QR Codes if you're logged in. I will think of something to help with the output, something like a ->get() to output a specific source and/or language.
  2. Hi, Sorry about this issue. Do you have multi-language activated on your website ? Also, which field(s) do you show with this qrcode ?
  3. I pushed a new release fixing an issue from the previous update: I forgot to update the name of the inputfield as well when switching from templates to allowedTemplates, resulting in an issue when trying to add/remove templates. You might need to uninstall / reinstall the module, though it shouldn't be an issue to do so.
  4. I published a new update with the following changes: changed filename of css/js files to PageMjmlToHtml (instead of debug) changed module configuration value name templates to allowedTemplates to avoid confusion modified the js so the copy to clipboard code works on all browser modified getCacheName method so it also checks for LanguageSupport and LanguageSupportPageNames Regarding point 2: please double-check the "Templates to convert (...)" field in the module settings properly catched up your previous value Thanks again @wbmnfktr for his thorough tests!
  5. Is it possible outputFormatting is set to false by the module ? If so your repeaters will return everything, including the disabled ones.
  6. Thinking out loud but I'd say there could be a module hooking into pwlink to add select actions in the Lister, something like [select] [>] [lang1] [lang2] [lang3] (or just be part of the core, if possible) Not that easy as there's a mix with dynamic JS stuff... too bad
  7. Fixed! And published! Keep the edge cases coming 💥
  8. I just published the new release! In the end I added a condition checking ProcessWire's version and calling the `getPage()` replacement, which uses a new `$pages->request()` method. Let me know if you notice anything else!
  9. The first part with the errors on initial save has been solved but I still need to find an alternative for the second part. In more recent dev versions Ryan removed a function I was relying on in my code (namely ProcessPageView::getPage) and I need to look for an alternative. I'll publish an update once it's all good.
  10. Oof doesn't sound good (thus the alpha state)... I'll have a look, thank you for bringing this up!
  11. Honestly I'm not that familiar with WireHttp, it was just a way for me to have a look at the source code and learn something as well 😅 Looking again at the code it seems you can get more information about the error by calling print_r($http->error). Maybe it's not the 404 triggering an error in the cURL call but something else ? Again no expert, just trying to help.
  12. When you look at the WireHTTP code you can see that when you're leaving the `use` options to `auto` (and no `fallback`) it will first try to send a cURL request and, should it fail, send another one using socket. In your case that's exactly what's happening since your tests return 404s.
  13. PageMjmlToHtml Github: https://github.com/romaincazier/PageMjmlToHtml Modules directory: https://processwire.com/modules/page-mjml-to-html/ A module allowing you to write your Processwire template using MJML and get a converted HTML output using MJML API. This is considered to be in alpha and as such needs some testing before being used in production! About Created by Mailjet, MJML is a markup language making it a breeze to create newsletters displayed consistently across all email clients. Write your template using MJML combined with Processwire’s API and this module will automatically convert your code into a working newsletter thanks to their free-to-use Rest API. Prerequisite For this module to work you will need to get an API key and paste it in the module’s configuration. Usage Once your credentials are validated, select the template(s) in which you’re using the MJML syntax, save and go visualize your page(s) to see if everything’s good. You will either get error/warning messages or your email properly formatted and ready-to-go. From there you can copy/paste the raw generated code in an external mailing service or distribute your newsletter using ProMailer. Features The MJML output is cached to avoid repetitive API calls Not cached if there are errors/warnings Cleared if the page is saved Cleared if the template file has been modified A simple (dumb?) code viewer highlights lines with errors/warnings A button is added to quickly copy the raw code of the generated newsletter Not added if the page is rendered outside of a PageView Only visible to users with the page’s edit permission A shortcut is also added under “View” in the edit page to open the raw code in a new tab Multi-languages support Notes The code viewer is only shown to superusers. If there’s an error the page will display: Only its title for guests Its title and a message inviting to contact the administrator for editors If you are using the markup regions output strategy, it might be best to not append files to preserve your MJML markup before calling the MJML API. This option is available in the module’s settings.
  14. Hmm, I think there's a few mistakes here. You should be hooking to InputfieldImage::fileAdded() instead of InputfieldFile::fileAdded() as you wouldn't want to resize files. Also in your first code you're trying to resize every images along with the current one uploaded, I don't think there's a need for that. Your hook could simply be: $this->addHookAfter('InputfieldImage::fileAdded', function(HookEvent $event) { if ($event->object->name === 'image_slider') return; $image = $event->arguments(0); // no need to save the page or the image as it is automatically generated / saved as a variation if($image->width > $image->height) { $image->width(1600, true); // from the doc: a boolean is assumed to be for "upscaling" } else { $image->height(1600, true); } }); And then afterwards you can call your image with: $image = $page->images->first(); $image = $image->width > $image->height ? $image->width(1600) : $image->height(1600); echo $image->url; However seeing how you check for a max-width/height why not just rely on the admin UI, in the image field settings ("Input" tab), to simply set a max size ?
  15. (re: this, I'm no master and just religiously use https://regex101.com/ or stackoverflow in desperate cases)
  16. It's not exactly the case. {variable} will return anything matching the route and will populate the value $e->variable accordingly, whereas (variable:value) will make sure `variable` is equal to `value` (which can be a regex) before making it accessible as $e->variable. There's an example where there is /route/(variable1|variable2|variable3) but in this case it will be accessible through $e->arguments(1) and will have to match either of the three values. At first this confused me as well but re-reading I think we misunderstood what Ryan meant: he's not talking about the regex part of (variable:regex) but rather making the whole hook a regex, as in: $wire->addHook("#/(event|person)/([[:alnum:]]{15})#", function($e) { $type = $e->arguments(1); $id = $e->arguments(2); return "Looking up data for ID $id of type $type"; }); That's why he mentioned that "...PW converts your match path to a regular expression (if it isn't one already)..."
  17. Your regex looks strangely complicated for what you're trying to achieve. I got it working using: <?php namespace ProcessWire; $wire->addHook('/api/v1/offline-events/(eventId:[[:alnum:]]{15})', function($e) { $e->return = "Hello $e->eventId"; }); As for the 404s, if you're not returning anything it will result in a pageNotFound() call you could hook after to check the url and execute code accordingly: $wire->addHookAfter('ProcessPageView::pageNotFound', function($e) { $url = $e->arguments(1); if(strpos($url, "/api") === 0) { $e->return = "API 404"; } });
  18. It's a very interesting setup @FireWire but I was wondering how you're dealing with API keys when used by modules. Usually, like in your (excellent) Fluency module, API keys are stored in the db through the module configuration, which is convenient since it's local to the module but in your setup ends up scattering around your credentials. It's an open question but should there be a $config object that would contain api keys that modules could check first and if empty rely on the administrator to input these in the module configuration ?
  19. And it seems to work perfectly using $event->cancelHooks! Thanks @Robin S for the pointer and for clarifying about replace, reading again from the doc it does say that it replaces the hookable function but it doesn't mean it will stop the functions hooked after.
  20. Hi @ryan, is it something that is still relevant ? I'm trying to use this for a module I'm writing but it doesn't seem to work as the after hook is still executed, even with `replace` set to true. Here's a boiled down sample of my setup: public function init() { $this->addHookBefore("PageRender::renderPage", $this, "beforeRenderPage"); $this->addHookAfter("PageRender::renderPage", $this, "afterRenderPage"); } protected function beforeRenderPage($event) { $parentEvent = $event->arguments(0); $page = $parentEvent->object; $markup = $this->wire()->cache->getFor($this, "cache-$page->id"); if($markup) { $parentEvent->return = $markup; $event->replace = true; } } protected function afterRenderPage($event) { $parentEvent = $event->arguments(0); $page = $parentEvent->object; $this->wire()->cache->saveFor($this, "cache-$page->id", $parentEvent->return); } Thank you in advance for your help.
  21. I just published another update. Following a pull request / suggestion from a friend I added support for any text and URL field. Multi-languages support is still there and the field will output as many (non-empty) texts as there are languages. I haven't tested with the textarea field but I assume it will generate the QR code from the raw markup, before any textformatter is applied. I believe this won't be a common use-case, but if need be you can always use hooks to adjust or generate your own QR code. I also fixed an issue where the template-contextual settings weren't applied. Please let me know if you run into any issue.
  22. I went ahead and pushed the latest release. I tested uninstalling LanguageSupportPageNames while still having LanguageSupport and it works as expected, outputting only the default language URL. I also namespaced the QR code php generator and it should help solve your issue with TOTP. Let me know if you notice anything else @adrian and otherwise thanks for your feedbacks!
  23. Do you mean like relying on urlSegment instead ? Implementing your feature I actually came across a situation where it would output the same URL twice because the page name of the root page wasn’t defined in the non-default language. So what I did is to add a check to make sure to not output the same QR code twice (plus the default language will just be labeled “URL”). Does it sound like it would help in your situation ? Even if not checking for LanguageSupportPageNames.
  24. Re: this, it seems to be because constants declared using define() do not respect namespace unless explicitely specified. One solution though seems to be to replace define() by const declarations. I'll try to do that tomorrow (also what you suggested is done but I want to also fix this first).
  • Create New...