Jump to content

Jan Romero

Members
  • Posts

    680
  • Joined

  • Last visited

  • Days Won

    18

Everything posted by Jan Romero

  1. You can run both on the same stack. You just create two databases and one ProcessWire installation in the filesystem for each database.
  2. If you actually want to upload an image using curl, you can do this: curl "https://example.com/my/page/upload" -F mypic=@"C:\temp\guy.brush" -F tells curl to make a multipart/form-data request (the full switch is --form). “mypic” is the name of the POST parameter, so that’s what we’ll be looking for on our server. ProcessWire code: <?php namespace ProcessWire; //return a bad status if anything weird happens http_response_code(500); //let’s pretend the POST request goes to the page to which we want to add the image //here you would check if the request is allowed etc. $page->of(false); //use ProcessWire’s tempDir feature to generate a temporary directory which will receive the image //the temporary directory will be destroyed after one hour $upload_dir = files()->tempDir('', 3600); //here’s the name “mypic” from the curl command again. $u = new WireUpload('mypic'); //here you could put some more settings for WireUpload, such as setMaxFileSize() or setOverwrite() $u->setMaxFiles(1); $u->setDestinationPath($upload_dir); $u->setValidExtensions([ 'jpg', 'jpeg', 'png', 'gif', 'webp', 'brush' ]); //read the file from the request into $upload_dir and receive an array of filenames $uploadedFiles = $u->execute(); //handle errors $uploadErrors = $u->getErrors(); if ($uploadErrors) die(var_dump($uploadErrors)); //the image is still in the temp dir. If everything went well, //we now need to move it to our page and save the page. $path = $upload_dir . $uploadedFiles[0]; $pageimage = $page->images->add($path)->last(); //delete the file from the temporary directory unlink($path); $page->save(); http_response_code(200); die('wow thanks for the pic, it’s very nice'); //this will show up in the curl command line
  3. Nice. I’m all for one-liners (at least for something like formatting…), but I find the whole IntlDateFormatter business a bit verbose. I like to keep pre-configured instances of the things around, for example on $config, and just call something like $config->dateFormatter->format($page->cooldate) Not sure if $config is a good place for this, and I have no experience doing this on multilanguage sites, but I imagine you’d be able to prepare the instances according to the user’s language and never have to worry about it again.
  4. The new thing in PHP for this is the IntlDateFormatter class: $giornoDellaSettimanaFormatter = new \IntlDateFormatter('it_IT', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, null, null, 'eeee'); echo $giornoDellaSettimanaFormatter->format($page->getUnformatted('data')); //Domenica https://www.php.net/manual/en/class.intldateformatter.php
  5. Before changes are saved to the database, you can load the previous values from there. Here is a snippet that does this: It’s a bit old, maybe there are better ways of doing it now?
  6. No, it will create a single database table. If you use the table field on multiple pages, all records will go into the same database table, just with a foreign key connecting each record to its page. So perhaps you will make a Track template and add the Hotlaps field (Profields Table) to it. That way you don’t need a custom trackID column because that will just be the page’s ID. Because it’s a single database table you will still be able to figure out, for example, the car with the most hotlaps across all tracks, by just doing very simple custom SQL: $sql = <<<SQL select car, count(id) as hotlaps from field_hotlaps group by car order by count(id) desc SQL $query = wire('database')->prepare($sql); $query->execute(); $queryResults = $query->fetchAll(\PDO::FETCH_KEY_PAIR); A car will probably be a page, so you would use a Page Reference column in your table. The query above thus gives you a bunch of page ids you can convert to page objects like this: wire('pages')->getByIds(array_keys($queryResults));
  7. You can set breakpoints in your javascript using Firefox’s Debugger tab. You can also look at the response bodies in both places you screenshotted, to see if they are what you expect. Likely something in your javascript is going wrong and this happens:
  8. Zoeck just told you: See if this makes a difference. Post the console output again if you have problems, but make sure to activate requests:
  9. Whoops, my bad! I always default to the functions api because of the benefits laid our here https://processwire.com/docs/start/api-access/
  10. As it turns out, I don’t get a notification when you change your reaction to one of my posts, only when you add a new reaction, but I noticed anyway ? You have to get an understanding of how to debug what’s happening. Are you familiar with your browser’s web development tools? There will be a place that shows all requests it sends to your site and their results. You can use this to figure out what is going wrong. This line will initiate a POST request to auction-longpolling.php. Check your browser console to see the response status and its contents. It might be 404 or 403 or something, in which case you’re probably hitting the wrong URL or the server doesn’t allow the PHP file to be accessed that way. If it’s in the 500s there’s probably an issue with the PHP code.
  11. This is roughly what your directory tree looks like: Your file auction-longpolling.php should be in the same directory as index.php and favicon.ico. Then it should be accessible as example.com/auction-longpolling.php. You can test if the file is accessible by just typing the URL into your browser. This isn’t a very processwirey way of doing things per se. You might want to make a special Template and Page for this polling or use a Path Hook or a UrlSegment.
  12. Mh? Doesn’t fetch("/auction-longpolling.php" work? Starting with a slash is always relative to the “origin”. You could also put the full address: fetch("<?=config()->urls->httpRoot?>auction-longpolling.php" etc. (note httpRoot already comes with a trailing slash)
  13. If you look at that file, you see that in line 35 it calls the count() function and passes it the variable $architects. From the error message we know that $architects is NULL. Before PHP 8.0 I believe this would have been fine, but now it’s a fatal error. Further up in the same file, the $architects variable is assigned: $architects = $page->get('architect'); $page is the skyscraper you’re trying to view, so it’s trying to get the value of that skyscraper’s field called “architect”. It’s a page reference field for multiple pages. That fieldtype always gives you a PageArray, so even if the skyscraper has no architects you should still get an empty PageArray and not NULL. The fatal error would not occur. So how could $page->get('architect') end up being NULL? The most likely possibility is that the template doesn’t have a field called “architect”. Now if you check out install.sql, it looks like there is only a field called “architects”, which makes sense because it’s a multiple page reference field. So I’d say you’ve found a bug in the site profile. The line I quoted above should say architects instead of architect.
  14. It used to be on TV in Germany every night, so maybe that? ?
  15. Sorry for unearthing this thread, but I can’t figure this out… https://github.com/processwire/processwire/blob/master/.gitattributes What does "$ cat .gitattributes" do here? I know what cat is, but why is this line in this file?
  16. I feel like it would make more sense to call focus() first and size() afterwards, but I haven’t tested or read up on anything.
  17. Hm, does this still work for you? I just installed it and the download link appears, but it doesn’t seem to accept clicks: Tested it in Default, Reno and UIKit themes, in Firefox and Edge. Maybe something else I’ve done to this install is messing with it, though ?
  18. Sorry for the delay, I’ve posted the PR here: https://github.com/processwire/processwire/pull/251 Since it simply uses an anchor tag with a download attribute, it also allows you to open the full-size image in a new tab using a middle click or “open in new tab”, which is just the behaviour I would expect and seems pretty useful. Your SCSS module is amazing! Unfortunately SCSSPHP doesn’t seem to do exactly what Ryan’s setup does, and I suppose the “self” thing is a bug in SCSSPHP, but a great help nonetheless!
  19. Note that you’re hooking the save() method of “Fields” object. This line makes no sense. I assume you mean “$event->object”, but because you’re hooking a method of the Fields class, I would imagine that will give you the same as wire()->fields(), not the field that was saved. The saved field is the first and only argument of the save() method, so I expect this should work: $field = $event->arguments(0); Apparently, towards the end, Fields::save() also calls Fieldtype::savedField() , so you may want to hook that instead: $this->addHookAfter('FieldtypePassword::savedField', $this, 'updateBlacklist'); protected function updateBlacklist(HookEvent $event): void { $field = $events->arguments(0); if ($field->name == 'pass') { $this->wire('session')->message('works'); } }
  20. Well, for what it’s worth, it’s just a Warning, so it’s not going to crash your site, although it probably will when you upgrade your PHP to version 9 in a couple of years. Since I’m still not seeing the problem in the code you posted, I assume it’s somewhere else. The Warning should tell you a line number to investigate, but also I would advise you to install a PHP language server such as Intelephense for VSCode. It will show you such problems while you write your code.
  21. Is the line that throws the warning within the function you just showed?! Clearly the variable is defined right here: $pageparentdate = $page->parent->auction_end_date; I’m not seeing the problem right now, sorry!
  22. Sorry, I somehow overlooked this line. You can’t compare $page->template to this string because it is not a valid template name. The line will always return because the condition can never be true. I think you probably want this: if (!$page->matches("template=auction-bid, auction_bid_date>={$parentdateminusstart}, auction_bid_date<={$parentdateminusend}")) return; //only continue if the added bid’s auction_bid_date is less than 3 minutes before the parent’s auction_end_date. See https://processwire.com/api/ref/page/matches/.
  23. Now do bd($page->parent->auction_end_date) from inside the hook
  24. @Frank Schneider Did you get it fixed? I fear there may not be enough information here to diagnose it. You should look at the POST request in your browser console and maybe post the (presumably javascript) code that makes the request in this thread.
  25. How are you uploading from the client? Does your form element have the attribute enctype="multipart/form-data"?
×
×
  • Create New...