Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 07/04/2023 in all areas

  1. Page List Auto Expand Automatically expands the next adjacent page when moving a page in Page List. Usage As you are moving a page in Page List, if you position the yellow move placeholder above a Page List item for a configurable period of time (default is 1000 milliseconds) then that item will expand, allowing the moving page to be dropped as child page. Configuration In the module config you can set the delay before the Page List item adjacent to the move placeholder will be automatically expanded. Restricting the module to certain roles If you want to restrict the module functionality to only certain roles then create a new permission named page-list-auto-expand. If that permission exists then a user's role must have that permission or the module will not have an effect in Page List. https://github.com/Toutouwai/PageListAutoExpand https://processwire.com/modules/page-list-auto-expand/
    9 points
  2. Hi, `$this->addHook()` give you the ability to define a custom method that can be available in the class object given as a parameter. $this->addHook('Page::summarize', $this, 'summarize'); | | | |- (name of the method defined in the current object (module, class..) | | | | | |- current object where the method is defined (module, class) | | | |- the name is mandatory, | you will call the method given as third param from the Page $page object ($page->summarize()). | |- the object where the new method will be added to In the example of the `summarize()` method you are talking about, it expect a method `summarize()` to be defined in an autoload module. But you are not required to write a module just to define a new method to an existing class. You can write it outside a class, for example, in the file `init.php` by writing the following: $this->addHook('Page::summarize', function ($event) { // the $event->object represents the object hooked (Page) $page = $event->object; // first argument is the optional max length $maxlen = $event->arguments(0); // if no $maxlen was present, we'll use a default of 200 if(!$maxlen) $maxlen = 200; // use sanitizer truncate method to create a summary $summary = $this->sanitizer->truncate($page->body, $maxlen); // populate $summary to $event->return, the return value $event->return = $summary; }); // or by defining the function... function summarize_2($event) { // the $event->object represents the object hooked (Page) $page = $event->object; // first argument is the optional max length $maxlen = $event->arguments(0); // if no $maxlen was present, we'll use a default of 200 if(!$maxlen) $maxlen = 200; // use sanitizer truncate method to create a summary $summary = wire()->sanitizer->truncate($page->body, $maxlen); // populate $summary to $event->return, the return value $event->return = $summary; }; // ... and giving the name of the function to the hook. // note the `null` parameter used to tell the hook we are not using it from a class object $this->addHook('Page::summarize_2', null, 'summarize_2'); You will be using a hook where `after` or `before` doesn't matter, to define a new method `summarize()` to the existing class `Page`. So in your template, eg. `home.php` or `basic-page.php`, you can then call both methods from the `$page` api variable. <?php namespace ProcessWire; // Template home.php // if the `body` field content is: "The body field of this page summarized in less than 200 characters, or it will be truncated." // calls of the new defined methods `summarize()` and `summarize_2()` will print the content of the `body` field. echo $page->summarize(); echo $page->summarize_2(); If you want to test it from a module, then is quite simple (note we replace the `null` param by `$this` to tell the hook we are using it from the current object class (themodule): class ExampleSummarize extends WireData implements Module { public static function getModuleInfo() { return [ 'title' => 'Example Summarize module', 'version' => 1, 'summary' => 'Add a new method `summarize()` to page object.', 'autoload' => true, ]; } function summarize($event) { // the $event->object represents the object hooked (Page) $page = $event->object; // first argument is the optional max length $maxlen = $event->arguments(0); // if no $maxlen was present, we'll use a default of 200 if(!$maxlen) $maxlen = 200; // use sanitizer truncate method to create a summary $summary = wire()->sanitizer->truncate($page->body, $maxlen); // populate $summary to $event->return, the return value $event->return = $summary; }; public function init() { $this->addHook('Page::summarize', $this, 'summarize'); } } If you write this code in a file `ExampleSummarize.module` and from the backend you refresh modules and install this module, the method `summarize()` will be available by calling `$page->summarize()` from where you want. You can also find more informations and lot of details there: https://processwire.com/docs/modules/hooks/
    4 points
  3. Hi everyone, Got a new feature for you today (at the request of @eydun). First some background - some of you might not even be aware that Tracy saves .html files of it's bluescreen stacktrace when an exception is thrown. The cool part about this is that these happen when Tracy is in production mode on a live site, so if you get a notification (via email or slack) that an exception was thrown, you can navigate to /site/assets/logs/tracy and load these html files in your browser and inspect the code (including values passed to functions etc). This can make debugging much easier because you don't need to try to replicate the error again. The new feature today makes viewing these much easier with a dedicated panel listing all available exception files. Simply click on one to have it display as it would if the exception was thrown while you were interacting with the site. The icon turns red when there are new exception files since your last visit and it shows which ones are new. The clear button will remove the bluescreen so you can return to your site without needing to reload the page. The Validator panel also had a revamp. It now uses https://validator.w3.org/nu/ because https://html5.validator.nu/ was no longer working and I have updated the CSS to support their new output DOM. For those of you who don't know, the key value to the Validator panel is for local dev sites where you don't have a publicly accessible URL to use - this sends the HTML of the page directly. Also included are some PHP 8.2 deprecation fixes.
    3 points
  4. Peace-of-Mind Setup: ProcessWire 3.0.210, PHP 7.4 Future-Proof Setup: ProcessWire 3.0.210 (or latest stable), PHP 8.1 All-In Setup: ProcessWire DEV (always latest), PHP 8.2 If it was my own project to play around with ProcessWire - 3rd option. If it's a small client project that once it's built never sees an update again - 1st option. If it's a long term project with lots of functionality, lots of content, nice budget - 2nd option.
    3 points
  5. But not the backend which give a 500 error. Anyway, you just have to throw a lot of confettis on @ryan . Read below. This piece of software look solid, love this quote so much ?
    3 points
  6. Hi folks, I'm looking for some general advice on where things stand with PHP 8.X and ProcessWire versions. Having recently migrated to a new webhost, I now have the option of using any PHP version (from 5.3 right up to 8.2) and I'm trying to decide on which version to go for. At the moment, things seem to point towards PHP 8.1, but I'd be happy to go for 8.2 if it has been confirmed as stable with the latest ProcessWire DEV (3.0.221). Most of the sites I develop run a few modules (including Formbuilder with custom Stripe payment actions). So, in a nutshell, my question is this: If you had the choice of a clean install, which version of PHP and ProcessWire would you choose? Thanks in advance for the insight! Douglas.
    2 points
  7. I was in New Orleans at the gymnastics Nationals most of this week. In her age group and level, my 10-year old daughter won 4th overall and 3rd on bars and beam. After a long drive, we're now back home in Atlanta and it's been a very short work week, but there's still a new dev branch version to write about. ProcessWire 3.0.221 continues primarily with minor issue fixes, working towards our next main/master version. Included are 11 resolved issues, 2 PRs, and code contributions from @matjazp and @dotnetic. In terms of new features, this version updates the language translating _n() function to support languages that consider 0 quantities as singular rather than plural in calls like _n('%d item', '%d items', $quantity); Previously this call has always used the plural "items" version for 0 quantities (i.e. "0 items"), which is correct in English, but may not be in other languages like French (as I've learned from issue #1757, though I think it has come up once before too). To define whether a language should consider 0 quantities plural or singular, use ProcessWire's language translation tool: Setup > Languages > [any language] > Find files to translate > wire/modules/LanguageSupport/LanguageTranslator.php ... when translating that file, you'll see the setting at the top labeled "Is zero (0) plural or singular?": That screenshot above also shows another new feature that was added, which is the ability to use Select and Radios fields when defining translatable text. Previously you could only use text, textarea and number fields. Let's say you wanted to have the person translating choose a color name for the language as part of the translation: $color = __('Red'); // What color? type=radios options=[Red, Green, Blue] As before, the "What color?" part is an optional description for the translatable text. Also as before, the "type=..." defines what Inputfield type to use. The supported values are any Inputfield name (minus the "Inputfield" part). Known to work values for this include: text, textarea, integer, float, radios and select. The "options=[...]" is the newly added part, and this enables you to define the selectable options for select or radios inputs. If you wanted to use separate value and label, you can also do that. In the example below, city abbreviations are used for the values and full city names as the labels: $city = __('ATL'); // What city? type=radios options=[ATL:Atlanta, CHI=Chicago, NYC:New York City] Another example is the one we used in the core for plural vs. singular here. By the way, if any of your values or labels need a literal comma, you can optionally use a pipe "|" as the separator rather than a comma. This ability to use Select and Radios is a fairly minor addition, but does open up better support for having certain language settings (rather than just translatable text) be part of language translation packs going forward. The plural vs singular setting for 0 seemed like a good first one to support with this. Next week we'll continue preparing our next main/master version. Thanks for reading and have a great weekend!
    2 points
  8. I guess @wbmnfktr you know that, but I want to mention that PHP7.4 is end of life since 2022 and we have PHP8.1 since 2021, so while I agree on the basic concept of using newer versions for less critical projects and older ones for others I'd vote for using 8.1 for the "peace-of-mind" setup. I know being up to date with the PHP version not the only thing that counts, but I think it's good to stay at least with the latest supported version and we should encourage everybody to do so. It's really not a big deal in my opinion and if someone finds an issue in a 3rd party module that does not work with PHP8 than it's for sure better to inform the module author about that or to provide a PR than to use an outdated version of PHP. I'm on 8.1 with most of my projects and I've not had any issues for a long time. There has been a lot of deprecation warnings, but they have all been addressed and tracy debugger now also has nice color options for making those warnings/errors more comfortable for the eyes ?
    2 points
  9. @wbmnfktr this makes a lot of sense. In your experience, PHP 8.2 with the latest DEV is pretty reliable? Any stand-out features from the DEV which you couldn't live without? @da² yes, I guess that's the thing I'm slightly concerned about, that I'll suddenly be faced with all these little niggly bugs. Even if easy fixes, when there are a few across multiple sites it could be a pain to debug.
    2 points
  10. Hi, I'm using PHP 8.2 and 8.1. No issue with Processwire 3.0.210 but you may find issues with third-party modules. For example I recently installed Twig module and it has this minor issue easy to fix.
    2 points
  11. That’s a shame, @bernhard — not the way I like my app developers to behave. ? But I’ve learned so much for your own helpful comments and answers and modules that it would never occur to me to withhold a helpful hand when there’s something I know a little bit about. I’ve been privileged to belong to several forums with very high signal-to-noise ratios, but this one is truly la crème de la crème. Tschüß, und Viel Glück!
    2 points
  12. @orchardheightsdental Netcarver is right that you need to get a look at the /site/assets/logs/errors.txt log and see what the last entries are in it. If you don't have SSH access you can also grab it through FTP. My best guess is that your web host upgraded to PHP 8.1 or 8.2 and that you are running a much older version of ProcessWire. PHP 8.1/8.2 upgrades can sometimes break old versions and old sites. I can tell that you are running a pretty old version because it is missing the JS files for AdminThemeUikit, which was added more than 6 years ago. The good news is that the front-end of your site seems to be working. A major PHP upgrade on an old site would be more likely to break both the front and back end. Most likely an upgrade to a more recent PW version (like 3.0.210) would resolve the issue. Though it's also possible that the issue is coming from a 3rd party module that's installed, or something else, and that's what the errors.txt log would tell us.
    2 points
  13. Sometimes you need to execute a slow task after some event occurs in the PW admin, and normally you have to wait for this task to finish before you can continue using the admin. This is because PHP is "blocking", meaning that while one thing is executing nothing else can execute. There are potentially lots of different kinds of tasks that could be slow, but just as an example suppose you want to generate resized variations of images on a page, and there are a lot of images. You might have a hook like this so that any non-existing variations are created when the page is saved: $pages->addHookAfter('saveReady', function(HookEvent $event) { /** @var Page $page */ $page = $event->arguments(0); // When a gallery page is saved if($page->template == 'gallery') { // Create an image variation for each image foreach($page->images as $image) { $image->size(1200, 1200); } } }); When you save a gallery page in the PW admin, the admin will be unresponsive and will only load again after all the variations have been created. I wanted to find a way for slow tasks to be triggered by events in the PW admin and for the website editor not to have to wait for the task to finish before continuing with other work in the admin. Inspired by this StackOverflow answer I came up with the following solution that seems to work well. Using the image variations task above as an example... First we make use of the URL hooks feature to set up a URL that can trigger tasks to run when it is loaded: // A URL that will trigger tasks when loaded $wire->addHook('/run-task/', function($event) { $input = $event->wire()->input; // A simple check to avoid unauthorised access // You could implement more advanced checks if needed if($input->post('key') !== 'cTdPMBQ7x8b7') return false; // Allow the script to keep running even though we have set a short WireHttp timeout ignore_user_abort(true); // The "create variations" task if($input->post('task') === 'create-variations') { $page_id = (int) $input->post('page'); $p = $event->wire()->pages->get($page_id); // Create an image variation for each image foreach($p->images as $image) { $image->size(1200, 1200); } return true; } return false; }); Then in the Pages::saveReady hook we use WireHttp to load that URL and post parameters that define what task to run and anything else needed for the task (in this case the ID of the page that has been saved). $pages->addHookAfter('saveReady', function(HookEvent $event) { /** @var Page $page */ $page = $event->arguments(0); // When a gallery page is saved if($page->template == 'gallery') { // Load the /run-task/ URL using WireHttp $http = new WireHttp(); // Set a short timeout so we don't have to wait until the script finishes // Timeout values shorter than 1 second can be tried once a core issue is fixed // https://github.com/processwire/processwire-issues/issues/1773 $http->setTimeout(1); $url = $event->wire()->config->urls->httpRoot . 'run-task/'; $data = [ 'key' => 'cTdPMBQ7x8b7', 'task' => 'create-variations', 'page' => $page->id, ]; $http->post($url, $data, ['use' => 'curl']); } }); By doing it this way the task runs in a separate request and the website editor doesn't have to wait for it to finish before they can continue working in the PW admin.
    1 point
  14. I am still getting a deprecation warning with that combo. I think it is caused by the cookie module MarkupCookieConsent passing an explicitly null param, but it should be caught by the cookie() method in WireInput. Easily fixed by changing line 371 to if($key === null || !strlen($key)) return $this->cookieVars; Worth a PR?
    1 point
  15. I am totally aware of this. Yet, the combo of PW 3.0.210 and PHP 8.1 wouldn't be my first choice right now. But... this will change with the upcoming new stable version of ProcessWire. That would be a totally different story. It is, still it's nothing I'd recommend right now as the foundation of a project. Not because it's not working, but because I don't know if the person I recommend this to can handle a few warnings and issues once in a while or would then just trash talk about ProcessWire because of it. That's the main reason I never recommend any All-in setups. To be totally clear: if I knew you or the person better - for example someone like @bernhard - I'd probably suggest using PW DEV on PHP 8.2 actually.
    1 point
  16. Thanks @gornycreative, I don't use TracyDebugger (*hangs head in shame*) but I do wonder whether that is why $this->wire()->page isn't available in the init(). The test I ran was on a new install of the dev branch so it does suggest something additional altering things. Regardless, for the purposes of this module the fix I put in place to use $this->wire()->process should work. I would normally have put this logic in ready() but didn't and can't remember why, so I'd prefer to keep it where it is for now at least. Cheers, Chris
    1 point
  17. As it happens, I looked into this with the latest version just a couple of days ago on a PW 3.0.208 install with Repeater Matrix and nested Repeaters inside Matrix items. Unfortunately there seems to be no support for Repeater Matrix.
    1 point
  18. Ah, my bad. But that does mean this solution should work. The second-last post in that topic tells you exactly what to do. As other people pointed out, it's probably a good idea to make a backup of the files and the database before you do. I do agree though, PW is a fantastic piece of software that rarely runs into these kind of issues, especially if you keep upgrading your website like... once a year. This is also a reason why I vastly prefer it over Wordpress, which is likely to whine about one of it's many plugins needing an upgrade every few weeks. PW has most of that "plugin" stuff in the core already. I can serve most of my clients without using any custom modules: I only install the ProcessUpgrade module for my own convenience. The AdminThemeUikit issue on some old sites is the only instance of PW ever making me manually update anything on the backend. I regularly say no thanks to well-paying development jobs on LinkedIn because I want to keep using ProcessWire. That says something.
    1 point
  19. @Olaf looks like there are a few issues with your code. Could you try this instead? // Get page to be copied $sourcePage = $pages->findOne(...); // Init new page $page_add = new Page(); // Set some basics $page_add->template = '<template-name>'; $page_add->parent = '</path/to/parent/>'; // Add some fields to copy $page_add->field = $sourcePage->field; ... // Save page to i get an ID $page_add->save(); // Although not neccessary, make sure we are working with array format $page_add->of(false); // Trying to add/copy the images to the new page $page_add->field->add($sourcePage->field); // For the sake of it, save page again $page_add->save();
    1 point
  20. Thank you - this will be very useful!
    1 point
  21. Heyyyy https://www.orchardheightsdental.com/ is back up! I dunno what you did, but it worked! Nice! ?
    1 point
  22. This post might also help you better understand hooks: https://processwire.com/talk/topic/18037-2-date-fields-how-to-ensure-the-second-date-is-higher/#comment-158164
    1 point
  23. Dear all, just released v0.0.4 of my EmailToEncryptedMailto module. I basically added the Typescript source files and config files so other users can modify the minified Javascript code more easily themselves. Using Windows 10 and VS Code as my PW dev environment. The NPM modules used (typescript, esbuild) can easily be installed as dev-dependencies via npm run install inside the module folder. Apart from that some code refactoring and clean up. I set the target of the transpiled JS file to es6 for better browser support (before it was set to ESNext). Have fun P.S.: The Github release section contains a ZIP-file containing just the ProcessWire module files without the DEV stuff included. The attached ZIP-file is the preferred installation option for end users, while cloning the git repo is the preferred option for devs wanting to adapt/modify the module code.
    1 point
  24. Hi Daun, Thank you - the template file method is working.
    1 point
  25. This repository doesn't include third party module translations, core and core modules only. We've got a relatively up-to-date FormBuilder translation package floating around. I'll give it a quick read-through, see if it needs updating, and post it somewhere (most likely the FB support forum).
    1 point
  26. Congrats to your daughter and thanks for letting us participate in that!
    1 point
  27. Congrats to your daughter! And looking forward for the next master.
    1 point
  28. I have one more small suggestion to improve the function a bit ? Just replace the complete if inside the execute-endpoints.php file: if ($action === 'action-get-openapi') { [...] } With this: if ($action === 'action-get-openapi') { header('Content-Type: application/json; charset=utf-8'); echo json_encode($openApiOutput, JSON_PRETTY_PRINT + JSON_UNESCAPED_SLASHES + JSON_UNESCAPED_UNICODE + JSON_UNESCAPED_LINE_TERMINATORS); die(); } So Tracy is disabled on output and via the browser you can save the file directly as json. And Thanks for this nice update ? @Sebi
    1 point
  29. Please note: I changed my initial forum name zx80 to my Github name cwsoft. Never thought I will release two PW modules within a month after my initial registration to the ProcessWire community forum ?. Hope this makes it more transparent for possible future contributions to the PW eco system.
    1 point
  30. Log in to your server via SSH and navigate to the site/assets/logs/ directory and look at the end of the errors.txt and exceptions.txt files. You should see information there about what could be happening on the server.
    1 point
  31. From my understanding is_nan(null) === false (in prior PHP versions). To fix lines 247 and 248 something like the following should do the trick: if($c2 !== null && is_nan($c2)) $e3 = $e4 = 64; else if($c3 !== null && is_nan($c3)) $e4 = 64; At least for me this stops the deprecation warning from appearing and keeps the functionality.
    1 point
  32. Hello @Roope, first of all thank you for your module. I am a long time user of your module and so far it has been working really fine. ? With PHP 8.2 I get following warning: Other than that the module is working normal. If you please could fix this warning that would be great. There is already a pull request for this warning, but I have not tested it. Regards, Andreas
    1 point
×
×
  • Create New...