Jump to content

monollonom

Members
  • Posts

    426
  • Joined

  • Last visited

  • Days Won

    12

Everything posted by monollonom

  1. (once again I was surprised to see a work of mine pop up in the newsletter, this time without even listing the module on PW modules website. Thx @teppo !) FieldtypeQRCode Github: https://github.com/eprcstudio/FieldtypeQRCode Modules directory: https://processwire.com/modules/fieldtype-qrcode/ A simple fieldtype generating a QR Code from the public URL of the page, and more. Using the PHP library QR Code Generator by Kazuhiko Arase. Options In the field’s Details tab you can change between .gif or .svg formats. If you select .svg you will have the option to directly output the markup instead of a base64 image. SVG is the default. You can also change what is used to generate the QR code and even have several sources. The accepted sources (separated by a comma) are: httpUrl, editUrl, or the name of any text/URL/file/image field. If LanguageSupport is installed the compatible sources (httpUrl, text field, ...) will return as many QR codes as there are languages. Note however that when outputting on the front-end, only the languages visible to the user will be generated. Additionally you can set the error correction level which allows to better recover lost data in case of visual damage. This is also used when covering part of a QR code with a logo. There are four levels of correction: L, with 7% of potential data recovery M, with 15% of potential data recovery Q, with 25% of potential data recovery and H, with 30% of potential data recovery Formatting Unformatted value When using $page->getUnformatted("qrcode_field") it returns an array with the following structure: [ [ "label" => string, // label used in the admin "qr" => string, // the qrcode image "raw" => string, // the raw qrcode image (in base64, except if svg+markup) "source" => string, // the source, as defined in the configuration "text" => string // and the text used to generate the qrcode ], ... ] Formatted value The formatted value is an <img>/<svg> (or several right next to each other). There is no other markup. Should you need the same markup as in the admin you could use: $field = $fields->get("qrcode_field"); $field->type->markupValue($page, $field, $page->getUnformatted("qrcode_field")); But it’s a bit cumbersome, plus you need to import the FieldtypeQRCode's css/js. Best is to make your own markup using the unformatted value. Static QR code generator You can call FieldtypeQRCode::generateQRCode to generate any QR code you want. Its arguments are: string $text bool $svg Generate the QR code as svg instead of gif ? (default=true) bool $markup If svg, output its markup instead of a base64 ? (default=false) string $recoveryLevel Set error correction level (default="L") Hooks Please have a look at the source code for more details about the hookable functions. Examples $wire->addHookAfter("FieldtypeQRCode::getQRText", function($event) { $page = $event->arguments("page"); $event->return = $page->title; // or could be: $event->return = "Your custom text"; }); $wire->addHookAfter("FieldtypeQRCode::generateQRCodes", function($event) { $qrcodes = $event->return; // keep everything except the QR codes generated from editUrl foreach($qrcodes as $key => &$qrcode) { if($qrcode["source"] === "editUrl") { unset($qrcodes[$key]); } } unset($qrcode); $event->return = $qrcodes; }); Note Depending on the level of correction set and the type of characters encoded in the QR code, the maximum size allowed for a QR code can vary. It is adviced to set a maximum character count on textareas or any relevant Inputfields Recovery Level Numeric Alphanumeric Byte Kanji L (7%) 7089 4296 2953 1817 M (15%) 5596 3391 2331 1435 Q (25%) 3993 2420 1663 1024 H (30%) 3057 1852 1273 784
  2. I'm on MacOS using Firefox. I know Firefox has its way of doing when it comes to some cases with margin-bottom... Regarding colors: maybe a suggestion would be to set the blue for buttons / nav bar to a be a bit more blue-ish. Here I took the color from the (invisible) background of thumbnails (32, 115, 206) : Edit: wouldn't mind as well to have the left and right paddings to match the ones on the header (40px left/right). And sorry for throwing you css details !
  3. Tiny detail but the margin-bottom on the footer creates a white space I was surprised at first seeing the new colors but it looks good !
  4. In the end it seems to work if I specifically save the Page Reference field: $home->save("events"); I'm still not sure though why saving the page from a guest session would break the link between images and their field...
  5. After some more testing, it looks like it's not because of the hook or the LazyCron but because of the code being executed by a guest. Edit: it's actually just the fact that I save the homepage (from a guest session) that makes the images disappear. I have access control toggled on for the homepage template but I thought API calls would be respected, am I wrong ?
  6. Yes at first I did set the output formatting to "false" but wanted to try and see how it goes without it, with no luck. I'll edit my post though, thanks. (also for completeness, I'll try again with of(false) just to be 100% sure)
  7. (I edited the title to reflect my findings down below, I'm leaving the original post as is though) Hi, This is the first time I'm using LazyCron so maybe I did something wrong but basically when the hook function is triggered and does its thing to the homepage, all images within that page disappear from the database, while remaining in the file system. When I try to re-upload the same image it tells me "Refused file X because it is already on the file system and owned by a different field" (couldn't find that other field though). Has anybody encountered something like this before ? Here is my hook, from ready.php: $wire->addHook("LazyCron::everyHour", function() { $home = wire("pages")->get(1); $home->of(false); $nextMonth = strtotime("next month"); $newEvents = wire("pages")->find("template=event, end_date>=today, start_date<$nextMonth, limit=10, sort=start_date, sort=end_date, sort=title"); foreach($home->events as $event) { if (!$newEvents->has($event)) { $home->events->remove($event); } } foreach($newEvents as $new) { if (!$home->events->has($new)) { $home->events->add($new); } } $home->save(); }); $home->events is a Page Reference field. The idea is to update the field with the ten closest events and allow the editor to sort them in the admin. Thank you !
  8. Hi Ryan, as part of your rewritting of the WireDatabasePDO class, did you get a chance to have a look at this issue ?
  9. I've never worked with custom page classes but I assume you could add a hook on the "loaded" event of your custom page and execute your custom function, something like : $wire->addHookAfter("CustomPage::loaded", function($event) { $page = $event->object; $page->yourCustomPageFunction(); });
  10. Have you tried with Pages::added ?
  11. Great to read ! About your other request, I had a look at the code and there doesn't seem to be a hook available for what you're looking for (the closest being this non-hookable function). Maybe someone else can come up with another solution.
  12. I had a different setup where I wanted my files served from a sub-domain (even though in the end it was from /site/assets/files), but it's somehow related. What I did was to point the sub-domain to /site/assets/files, and then add this hook in ready.php : $wire->addHookAfter("Pagefile::url", function($event) { static $n = 0; if(++$n === 1) { $file = $event->object; $url = $file->httpUrl; $host = wire("config")->httpHost; $url = str_replace("$host/site/assets/files", "sub.domain.com", $url); $event->return = $url; } $n--; }); You could replace "sub.domain.com" to "domainB.com/site/assets/files" (or even clear the "site/assets/files" part in your case). Hope it helps !
  13. Are these website all on the same server ? Or on shared hosting ? Or do you also have the issue locally ? I have this issue with one of my websites where sometimes the TTBF drops down. Can't say for sure as I did not investigate much yet but I assume it's because there might be other websites on the shared hosting taking too much power. Sorry I'm not helping much so here's a screen of the timings I had for your website, looks pretty normal to me :
  14. If everything seems to point to emails being sent successfully but not received, shouldn't you have a look if the emails go to spam or are refused by the receiving address ? You can try this for example https://www.mail-tester.com/?lang=en
  15. Would showing the path instead of the title be okay ? I thought of a hook first but you could do the trick with a bit of CSS ul.pw-dropdown-menu-shorter li.ui-menu-item a::before { content: attr(title); margin-right: 3px; } ul.pw-dropdown-menu-shorter li.ui-menu-item a span { display: none; } (hopefully it doesn't target anything else, but from my quick testing it looks ok !) Before: After:
  16. Isn't your code missing a bit for $roles ? Right now, and if not, you could just do echo $page->insight_author("<a href='{url}'>{title}</a>, {staff_role}");
  17. Not sure if this is what you're looking for (or if you already know about it) but explaining the focus feature to your editors might come handy for you when generating variations for srcset. If cropped, the image returned will respect the focus point and try to keep it centered.
  18. Hm not really since in the end it's about PW outputting data, whether it's within HTML tags or as a json object. Here you only provide a very small sample of your setup so it's hard to tell, but there could a number of things that impacts the performance of PW. Hooks that take a long time to execute or something... Using TracyDebugger could help you narrow down what's going wrong.
  19. At least it's cleaner ? ?‍♂️ Re: perf difference, I can't say for sure but maybe having the file in the root made it so it's called outside of PW's context ? That may explain why it's faster as it would be raw php.
  20. It should work for your situation as well. Render your HTML markup and once you're done and want to stop PW output call $this->halt. Try and let me know if it works. Edit: That is, in your initial setup where you have _main.php included by default after your template
  21. I assume you're using the markup regions output strategy ? If so, when getting an ajax call, once you're done in your code and have echoed your response, you can call $this->halt(); to stop the template output (from https://processwire.com/blog/posts/processwire-2.6.8-brings-new-version-of-reno-admin-theme-and-more/#new-this-gt-halt-method-for-use-in-template-files) (I couldn't find it referenced in the doc though...) So for example in my case I have (in my page.php) if ($config->ajax) { http_response_code(200); header('Content-Type: application/json'); // code to populate $json echo json_encode($json); return $this->halt(); }
  22. Ok one issue though is that it's a global setting so I'm not sure how it will play out with the rest of your setup... so maybe you do need to use a hook in the end to be able to change this setting before ProcessPageAdd is started.
  23. What if you try to put all the template names except the one you want to be selected ? Re: "space-separated template names" $config->pageAdd("disableTemplates", "template1 template2 template4") Is "template3" then selected as you want ?
  24. Lol you're not alone, I struggle a bit sometimes too... To tell you the truth here was my train of thought: when trying to replicate your situation by adding several templates as authorized children, I came across the ProcessPageAdd module settings, and thought I might take a look at its code to see where it does the check to pull out the available templates. And then I finally stumbled upon this option I linked above... In your config.php file (in the /site/ folder), you can just add a line $config->pageAdd("noSuggestTemplates", true) So no need for a hook. Let me know how it goes.
  25. I've never had your situation so I wanted to be sure first. I quickly had a look at the code and I found this "Disable suggestions" option in $config->pageAdd, maybe try this ?
×
×
  • Create New...