Leaderboard
Popular Content
Showing content with the highest reputation on 07/03/2023 in all areas
-
Made you a small screencast @bernhard to get an idea. This version works fine with php-8.1. Enregistrement #59.mp4 Enregistrement #60.mp45 points
-
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/3 points
-
I don’t know @wbmnfktr’s source, but it sure sounds like that’ll do the trick nicely! My suggestion otherwise, honestly, if you don’t have a lot of digital typography knowledge or relevant tools, would simply be to experiment with the CSS: specify only one font at a time and include font-variant-numeric: tabular-nums, remembering (of course) to dump (or not use) your browser cache with each new page load. I believe all the various Arial varieties support it, as do the Avenirs. So do (at least) the macOS Helveticas. DIsappointingly, the current macOS system font (variations on “SF” and “San Francisco”) appear not to support it, other than the mono-spaced SF Mono variant. It probably goes without saying, but you’ve asked for “basic,” so: all monospaced fonts will do exactly what you want, even without the font-variant-numeric: tabular-nums. Even if you don’t want to use a monospaced font in general, you might consider using it just for the date/time stamp. My favorite is Michael Everson’s shareware (€25) Everson Mono, which has beautiful glyphs for (I believe) every non-Han Unicode codepoint. Everson writes: I met Michael (nice guy!) a few years ago in the U.K., but otherwise I have no connection or vested interest — other than Everson Mono being my favorite monospaced font for the past 35 years....2 points
-
This ? « Just » make an offer on ddev.site and put the certificat on your setup ? Another solution is to make your own self signed certificate and add it to your OS certificates authority in order to trust it.2 points
-
I have seen this or maybe a very similar warning a few times - not with DDEV as I only use project abbreviations and not fully qualified domain names there. So your project would be running as something like brk.ddev.site here. Chrome is fine with that. Possible solutions: don't use full domain names use abbreviations instead write it domain-tld instead And always remember the ddev.site part is a fully qualified domain thats registered and everything. So technically yourproject.ddev.site is/could be a real subdomain and due to some security features Chrome tries to verify that this subdomain is secure and everything.2 points
-
2 points
-
This week, work continued on our next main/master version with 8 issue fixes (see dev branch commit log). In addition, the WireHttp class was updated with new delete(), patch() and put() methods which correspond to http methods of the same name, These might be used by web services in addition to the more common GET and POST methods. In prior versions of WireHttp, you could still use delete, patch and put methods, but had to use WireHttp::send() with the $method argument set to one of them. Now that there are separate class methods for these http methods, it makes them a little simpler to use and more clear in code. It may be that you never need these methods, or it may also be that you use a web service that uses them extensively. The more web services I work with, the more I come across them, and figured it would be good for WireHttp to have more clear support for them. I know things slow down in the summer, but we haven't had many submissions to the sites directory lately. If you have launched any sites using ProcessWire in the last year or so, and haven't submitted them to our sites directory, please submit your websites to the directory when you can. We really enjoy seeing what what people are building in ProcessWire. Thanks and have a great weekend!2 points
-
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
-
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!1 point
-
@orchardheightsdental do you want to solve the problem on your own? Otherwise it might be more efficient to find someone to help you: https://directory.processwire.com/ https://processwire.com/talk/forum/22-jobs/1 point
-
Thank you all for your input and help. Really a great forum with many helpful people around ? Unfortunately the developers of the panel do not seem to be interested in fixing that behaviour. They even moved the topic from the "issues" forum to the "feature requests" board. Not sure what they have against the wording "issue/bug" for that time based content shifts, and also I'm really confused where they see a "feature request" in that report, but that's another story ? At least I learned something new about fonts and I got reminded that it's not self-evident to have a place like the pw forum ?1 point
-
Thx, but that's not solving the problem. It's just preventing the line break, but then you'll break the responsiveness and you'll not see the time on mobile screens as it will not fit on the screen. Or it will create a horizontal scrollbar. No, I don't think that the font-size is the issue. The issue is that different numbers are of different width. A solution would be to use a monospace font for the time, but that looks ugly. That's why I suggested tabular-nums as solution but as I said he tried that and the problem still persists:1 point
-
Have you tried using the tabular-nums attribute of the font-variant-numeric CSS property? That’s how I’d approach this.1 point
-
I have never used ProDrafts, but the docs mention a drafts manager: https://processwire.com/store/pro-drafts/#drafts-manager Sounds like it's exactly what you're asking for. And even if that feature wouldn't exist: It would be quite easy to use ListerPro and write a custom Batch Action I guess...1 point
-
Anybody else experiencing this issue in chrome or having a solution for it? https://github.com/orgs/ddev/discussions/5051#discussioncomment-63438111 point
-
This is something that I'd also wish to have. But it's not easy to do properly. If that's the only thing missing have you thought of asking Ryan for adding that feature to ProDrafts?1 point
-
Yes. Current approach makes use of ProcessWire's database export feature and I'm not sure if it can do this (from what I can tell this is not really what it was meant to do; it was rather intended to store the dump "permanently"), so this might need to be a different command. Just like flydev mentioned above (native:restore). Personally I don't see much reason to use the ProcessWire db export method in this context, unless it does something special that mysqldump can't do (?). Various reasons for this. Resetting passwords is one, but I've also had to remove users matching specific conditions or temporarily disable their accounts, update categories for posts (e.g. a main category is removed and all posts that belonged to it need to be connected to a new one), automate some content modification for a number of pages matching specific criteria, etc. In WP it's not as easy to create "bootstrap scripts" as it is in PW, so WP-CLI is (in my opinion) often the easiest way to do any sort of bulk edit ? This is where differences between WP and PW matter. WP has a built-in cron task queue: the core maintains a list of registered tasks (some from core itself, others registered via hooks from theme(s) or plugins). Each task has a set recurrence (interval), a precalculated time for next run, and hook function to trigger when the task is due. WP-CLI can be used to trigger a specific task, run all tasks that are due now, etc. By default tasks are executed "lazily", similar to what ProcessWire does when using Lazy Cron, but typically you would not want to rely on that or slow down page views for regular users. Instead you'd set up a real cron job to run e.g. once per minute. That cron job then executes "wp cron event run --due-now --quiet". I don't say this often, but in this area WP is — in my opinion — ahead of PW. The cron setup makes a lot of sense, and it's really easy to keep track of active tasks ?1 point
-
Dear all, just released v0.0.2 of my No Cookies Without Consent module. I basically added my Typescript and SASS source files and config files so other users can modify the minified Javascript/CSS code more easily themselves. Using Windows 10 and VS Code as my PW dev environment. The NPM modules used (typescript, sass, esbuild) can easily be installed as dev-dependencies via npm run install inside the module folder. Apart from that some code refactoring to avoid flickering of cookie consent on page reloads and some code 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
-
In wire shell no, but wirechief contain them and more, like pw:restore native:restore (mysqldump), duplicator:restore (working with packages), etc. My screenshot do not reflect the current version. Almost all commands contains subcommands depending on the arguments given. Too much to be listed here without spamming the thread. I dont use migrations everywhere and the cli tool allow, for example, to create templates, fields and assiging them in seconds, or installing pw and a specific profile from the terminal without writing any code, its time saver, like artisan. Keep in mind that the tools is born 8 years ago and abandoned since 4y.1 point
-
Thanks for sharing! As always, your contribution to ProcessWire and its community rocks!1 point
-
Hi @snck, Thanks - I think I found the place where this is failing to generate the 1600x800 variation where it should. I've pushed the potential fix. Can you try it out? I would note that the example implementation I gave above (creating the variation before calling render()) is a better way to implement this as the markup is meant to be a template not a string with actual values, however if the fix I've pushed works, it should work for either implementation. Cheers, Chris1 point
-
I get this error all the time on my development server. 9 out of 10 times I had simply forgotten to change config.php, and my site would try to access the database using my local config! Could it be that you've accidentally overwritten that file with your local version? I ended up implementing a switch in config.php that checks what domain we're on, and sets the config variables according to the current domain. Should it be an upgrade issue, you can get into some trouble when upgrading through the ProcessUpdate module because the JS files for AdminThemeUikit are missing! I had this issue a while back with a bunch of sites that were suddenly running on PHP8 due to a decision of the hosting provider, and some friendly people on this forum helped me update ProcessWire manually to get around this issue. You can find the topic here.1 point
-
@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.1 point
-
Page::__construct() takes a Template object as an argument: /** * Create a new page in memory. * * @param Template $tpl Template object this page should use. * */ public function __construct(Template $tpl = null) { if(!is_null($tpl)) { $tpl->wire($this); $this->template = $tpl; } $this->useFuel(false); // prevent fuel from being in local scope $this->parentPrevious = null; $this->templatePrevious = null; $this->statusPrevious = null; } So I think the constructor in your child class should be: public function __construct(Template $tpl = null) { parent::__construct($tpl); $this->header = 'some text'; }1 point
-
When importing images to pages, make sure the page exists first. So if you are creating a new page, save it in your API code ($page->save()) before adding the image to it. Otherwise, PW won't know where to put the image(s) since the /site/assets/files/* directories are based on the page ID. If you are adding an image to a single-image field, you can just set the value of it to the URL, i.e. $page->image = 'http://www.something.com/some-image.png'; If you are adding an image to a mult-image field, you can add() it: $page->images->add('http://www.something.com/some-image.png'); Either of the above makes PW copy the image to it's assets and create the proper object. And then don't forget to: $page->save();1 point