Jump to content

monollonom

Members
  • Posts

    328
  • Joined

  • Last visited

  • Days Won

    8

Everything posted by monollonom

  1. Fixed! And published! Keep the edge cases coming ?
  2. 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!
  3. 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.
  4. Oof doesn't sound good (thus the alpha state)... I'll have a look, thank you for bringing this up!
  5. 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.
  6. 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.
  7. PageMjmlToHtml Github: https://github.com/eprcstudio/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. 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. If your layout looks weird somehow, try disabling the minification in the options.
  8. 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 ?
  9. (re: this, I'm no master and just religiously use https://regex101.com/ or stackoverflow in desperate cases)
  10. 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)..."
  11. 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"; } });
  12. 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 ?
  13. 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.
  14. 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.
  15. 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.
  16. 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!
  17. 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.
  18. 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).
  19. Is this still the case ? I changed the way I import the library by putting it in the __construct rather than outside the class. Also it's weird because in Ryan's case its class is namespaced "Processwire\TfaTotp" so there shouldn't be conflicts ? Or maybe I should use a namespace as well ? Thanks for your suggestion. I don't see any issue to adding this, I'll let you know once it's done. Maybe it's something to keep in mind to allow to say which language to output from the "source" config input, something like "httpUrl.default" (opening the way to other ways to narrow down what to output for files/images but I'm already getting too far ahead...)
  20. Annnnd I found a tiny bug where there was no output if a source was empty... new release published!
  21. I just published a new release of the Fieldtype and updated the original post with a copy of the README. I think it's pretty complete at this point: you can output several QR codes by specifying the sources in the field's config (limited to httpUrl, editUrl and PageFiles/PageImages fields), it supports multi-languages by outputting as many QR codes for httpUrl as there are languages (only those visible to the user when output in the front-end), there is now a static function to generate any QR code you want and there are several functions you can hook at to adjust according to your needs. Let me know if you notice anything strange or a bug!
  22. That's a good point, but I'll let @Robin S decide on that one. Thanks for pointing this out anyway, I wasn't sure but you're right the example might be confusing.
  23. It’s already the case. The reason I set off the output formatting in the example is in the case your image field is set to accepting only one file and thus returning the image or null if empty. Setting output formatting makes sure we get the Pageimages object to call the method from. (but it could be mentioned then I guess)
  24. Hi @Robin S, I made a pull request to add a new method `addFromUrl` to Pagefiles. In a project I'm working on I needed this function from the API. Coming across your module I extracted the bit I was interested in but then I thought it might be a good addition to your module. Hope it helps!
  25. I think there's no way around this issue except for the developers to adapt their code a bit, have their page working without javascript, or a full page reload. I tried to check if there was a way to somehow "reset" the javascript but it seems there's none. What I like about this is how it's somehow reminiscent of front-end editing's method D. Maybe it could be something to rely on for the live preview as well ?
×
×
  • Create New...