Jump to content

da²

Members
  • Posts

    341
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by da²

  1. OK, I don't know if this is possible in PW. I searched in source code for "ORDER BY FIELD" but found nothing. Maybe that could be a PW feature request to add selector for ORDER BY FIELD. You can also do the MySQL request using $database API variable, but then you must do yourself values sanitization, and resolving pages references if any. SELECT * FROM table ORDER BY FIELD(id, 5,3,6,1,4,2);
  2. Could you explain the conditions that justify this sorting? Is it static or dynamic? If static maybe you can solve this by manual sorting in PW admin. Then you use "sort=sort" in your selector. If dynamic the only solution I see actually would be like: $sortedIds = [5872, 5869, 5870, 5871]; // List created dynamically $results = $pages->find('id=' . implode('|', $sortedIds)); $sortedResults = []; foreach ($results as $result) { // echo $result->id . "\n"; $nextId = array_shift($sortedIds); if(!$nextId) break; $sortedResults[] = $results->getPageByID($nextId); } var_dump($sortedResults);
  3. So, except if there's a magic trick I'm not aware of, you have to get the pages in correct order from the resulting PageArray, with your own code.
  4. Sorting is managed with "sort" selector. If you want to sort by reverse id: $pages->find('id=4|2|1', sort='-id');
  5. Hello, Probably a mistake when configuring host. Edit C:\Windows\System32\drivers\etc\hosts and add line: 127.0.0.1 my-project.local.fr Edit xampp\apache\conf\extra\httpd-vhosts.conf and add: <VirtualHost *:80> # Directory that contains index.php DocumentRoot "E:\src-processwire" ServerName my-project.local.fr <Directory "E:\src-processwire"> Options FollowSymLinks Indexes Order allow,deny Allow from all AllowOverride All Require all granted </Directory> </VirtualHost> Restart XAMPP Apache server and go to http://my-project.local.fr/
  6. Is it possible that your provider changed the network configuration? It happened to me few months ago, provider migrated my server to another server rack and then I wasn't able to reach external URLs, a single file_get_contents() to a remote URL wasn't working anymore. Reason was: new network config used IPv6 but it wasn't available. Dunno if your symptoms are compatible with this scenario, but something must have been modified. ?
  7. I don't know if that can help you, but on my project, backend side, I hide all pages that a user can't edit, with this hook: /** * In PW admin, hide pages that user can't edit. */ $wire->addHookAfter('Page::listable', function (HookEvent $event) { /* @var Page $page */ $page = $event->object; if ($page->path == "/") $event->return = true; else $event->return = wire()->user->hasPermission("page-edit", $page); }); There is no impact on the frontend side.
  8. Hello, Documentation of this module is here: https://processwire.com/api/ref/textformatter-markdown-extra/ You can do something like: modules('TextformatterMarkdownExtra')->format($text);
  9. Hi, There's not enough information to talk about the issue. It seems the provider changed its API, asking for a cookie that you don't provide. You should check if the API works outside of the form and ProcessWire.
  10. I also can't login in Developer Directory too. Red popup too.
  11. 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.
  12. Hello, I suppose this is due to text domain. You are asking for a translation that has been defined in another file, so to get it you need to specify the text domain of this file. echo __($string, '/site/templates/file_containing_translation.php'); If you want to automatically export translations, I think you should put all translations in a single file, let say it's named _commonTranslations.php: __('translation 1'); __('translation 2'); // And so on... Then when you insert this translations in the template that needs it, you need to specify text domain (you can put it in a constant or create a global function that inserts it automatically): __('translation 1', '/site/templates/_commonTranslations.php'); Note that in PW, you translate this sentences ONLY in _commonTranslations.php. Finally your function looks like that: function echoSnippet($string, $lang) { // Echo the string in english wire('user')->setLanguage(wire('languages')->get('name=en')); echo __($string, '/site/templates/_commonTranslations.php'); // Echo the string in german wire('user')->setLanguage($lang); echo __($string, '/site/templates/_commonTranslations.php'); }
  13. Hello @Craig I don't know if you get notifications from Github issues, so I notice you here that your module has a huge bug, it just doesn't manage cookie expiration date. Greetings, and thanks for your work.
  14. Hello, @ryan I tried to use in PW 3.0.210 and 3.0.218 a class I wrote in PW 3.0.200 for managing forms, and it's not working anymore. When I manually set an error on a field, $form->getErrors() returns no error cause it's returning an empty cached array generated with $form->process(). A simple example: <?php use ProcessWire\InputfieldForm; use function ProcessWire\modules; /** @var InputfieldForm $form */ $form = modules('InputfieldForm'); $form->add($form->InputfieldText->attr('id+name', 'foobar')); $form->add($form->InputfieldSubmit->attr('name', 'submit_subscribe')->val('Subscribe')); if ($form->isSubmitted('submit_subscribe')) { if ($form->process()) { // Simulating a callback method doing extra form validation (for example requesting a URL to verify data). $fieldInError = $form->getChildByName('foobar'); $fieldInError->error("test error"); echo "<u>form->getErrors():</u> " . count($form->getErrors()) . "<br>"; // BUG: getErrors() == 0 echo "fieldInError->getErrors(): " . count($fieldInError->getErrors()) . "<br>"; // this is correct, == 1 echo "form->getErrorInputfields(): " . count($form->getErrorInputfields()) . "<br>"; // this is correct, == 1 echo $form->render(); } else { echo "<h3>There were errors, please fix</h3>"; echo $form->render(); } } else { echo $form->render(); } ?> $form->getErrors() returns 0 cause it's returning the cache. But even if you call $form->getErrors(clear: true) you are stuck with cache forever, look at InputfieldForm.getErrors(): public function getErrors($clear = false) { if($this->errorCache !== null) return $this->errorCache; $errors = parent::getErrors($clear); $this->errorCache = $clear ? null : $errors; return $errors; } Cache cleaning is at line 3, but if we have cache we always stop at line 1. Maybe we could fix it like this, but I don't get the purpose of this error cache so this code may be problematic in some cases: public function getErrors($clear = false) { if($this->errorCache !== null && !$clear) return $this->errorCache; $errors = parent::getErrors($clear); $this->errorCache = $clear ? null : $errors; return $errors; } Actually the easiest fix is to use getErrorInputfields() from InputfieldWrapper, because it doesn't implement error cache. ------------------------------------------- I also randomly found 2 things about errors being stored somewhere in PW. This cases should not happen but maybe it's worth reporting them. If we don't call $form->render(); after setting the field in error, the error is stored and will be displayed on next page load. Demonstration: $form = modules('InputfieldForm'); $form->add($form->InputfieldText->attr('id+name', 'foobar')); $form->add($form->InputfieldSubmit->attr('name', 'submit_subscribe')->val('Subscribe')); if ($form->isSubmitted('submit_subscribe')) { $form->getChildByName('foobar')->error("test error"); } else echo $form->render(); Click Subscribe, select url bar and hit enter, or open same url in another tab => you see the field in error. If we do a redirection after setting the field in error, the error will also appear in PW admin: $form = modules('InputfieldForm'); $form->add($form->InputfieldText->attr('id+name', 'foobar')); $form->add($form->InputfieldSubmit->attr('name', 'submit_subscribe')->val('Subscribe')); if ($form->isSubmitted('submit_subscribe')) { $form->getChildByName('foobar')->error("test error"); $session->redirect($page->url); } else echo $form->render(); Click Subscribe, navigate to admin => you see the red error notice: ------------------------------------------- And the last thing, getErrors() have different behavior depending if we use $form->process(); or $form->processInput($input->post);. Here with process(), getErrors() returns 0. This is caused by process() calling getErrors(clear:false), and getErrors() creating this forever cache. $form = modules('InputfieldForm'); $form->add($form->InputfieldText->attr('id+name', 'foobar')); $form->add($form->InputfieldSubmit->attr('name', 'submit_subscribe')->val('Subscribe')); if ($form->isSubmitted('submit_subscribe')) { $form->process(); $form->getChildByName('foobar')->error("test error"); echo "<u>form->getErrors():</u> " . count($form->getErrors()) . "<br>"; // ZERO echo $form->render(); } else { echo $form->render(); } And with processInput() it returns 1. $form = modules('InputfieldForm'); $form->add($form->InputfieldText->attr('id+name', 'foobar')); $form->add($form->InputfieldSubmit->attr('name', 'submit_subscribe')->val('Subscribe')); if ($form->isSubmitted('submit_subscribe')) { $form->processInput($input->post); $form->getChildByName('foobar')->error("test error"); // ONE echo "<u>form->getErrors():</u> " . count($form->getErrors()) . "<br>"; echo $form->render(); } else { echo $form->render(); } Thanks for reading, I hope it will be useful, I've lost my night on that trying to figure why my code wasn't working even if I used it tens of times on a PW 3.0.200 project. ?
  15. Where is the "mark as solution" button that the email I just received is talking about? ?
  16. Check in your template > Advanced tab > List of fields to display in the admin Page List
  17. Hello, I'm using the W3C validator to check my pages and find that Textarea CKEditor outputs line breaks as <br /> instead of <br>. Is there a way to make it HTML5 compliant? I used no text formatter and checked Markup/HTML content type. EDIT : Same issue with InputfieldForm, <input /> should be <input> Thanks.
  18. Thank you for your answers @bernhard and @Jan Romero . The ProFields Table looks like a good solution. ? So I can use PageReference fields for users, cars and tracks, and display the standings in each hotlap page (same for races and other events). Also I prefer to use PW solutions instead of developing my own modules. I already used PW for some projects, but never at this scale, I'm quite excited to start development but I'm also a bit blind about how to do this or that. ?
  19. Hello, I'm planning to use Processwire for a sim-racing project where we will create events like championships, races and hotlaps. I'm wondering how to manage results and standings for each event. You can see here an example of a hotlap standings : https://online.racingfr.net/hotlaps/assetto.corsa/roc.2022.bmw.e30.dtm.hotlap/okayama/hotlap-2192.html Standings need to be editable, for example to add penalty points to a player result. Usually, without using a CMS, I would create a table "hotlaps" with columns [hotlapID, username, trackID, carID, globalTime, sector1Time, sector2Time, ..., optimalTime] and all of our hotlap results would go in this table. Then I can make SQL queries to find times for a particular hotlapID, track, car... In Processwire I don't know what is the best choice. We will have a single PW page for each hotlap, race or championship. I first thought to create a child page per event result with a template "hotlap_result" corresponding to a single row (a single player result), but we will end with more than 200 000 result pages after years, this is not optimal from an ergonomics point of view in PW admin. And we also have standings for races and championships, so I need a good overall solution. I see that ProFields Table would make the trick, but will it create a separate database table for each hotlap page? That could be an issue cause actually we have 2000 hotlaps, to add to future hotlaps in next years. I hope I'm clear, thank you for your advice. ?
  20. Yes yes I know. ? Main question is: is it safe to use LoginRegister module today ? (sorry to post this here but I didn't find this module topic)
  21. I was afraid to read this. ? I use a CMS to avoid having to develop things like this, I just want to focus on my site content, coding a login/register module is reinventing the wheel, this has be done thousands of time by developers with a better knowledge than me in security.
  22. Hello, Some months ago I've created a PW site using LoginRegister module. Today if I search "register" in PW free modules shop I just find FrontendUser, so I assume this is the "new" officially supported login module, but then I read here that it's not maintained anymore. I'm kind of confused, is there still an officially supported and free module to register/login in PW ? Is LoginRegister still good in term of security ? (last commit 5 years ago) I like PW a lot for its simplicity, but I'm afraid that a CMS without an official register/login module is kind of dying, and that I should find another CMS for my next site. Am I missing something ? Thanks for any help.
  23. It looks like there's a compatibility issue between modules TemplateEngineFactory and TemplateEngineTwig in current PW master and dev versions. I use the "Add Module From Directory" form: * With TemplateEngineFactory and it installs version 1.1.3 (no update available) * With TemplateEngineTwig, it chooses version 1.1.0 and reports a compatibility issue: So I can't install it. I'll try to install it from the sources but I did want to report that issue.
×
×
  • Create New...