Jump to content

Jan Romero

Members
  • Posts

    612
  • Joined

  • Last visited

  • Days Won

    15

Everything posted by Jan Romero

  1. IIRC this just takes you to the normal page finder, where you can click the column headers to sort. You can also add and remove columns if the one you’re looking for isn’t there by default.
  2. Haven’t tested but isn’t this just $page->prevAll('limit=5') and $page->nextAll('limit=5')? https://processwire.com/api/ref/page/prev-all/
  3. The way ProcessWire selectors work, this should be sort=-Date_2|Date_1, although I’m neither sure where the hyphens go nor whether sorting allows the pipe operator at all. Alternativey, it’s easy in SQL with coalesce(), or you could add a hidden third field that precomputes to Date_2 ?? Date_1. Edit: doesn’t seem to be supported judging by this open PR https://github.com/processwire/processwire-requests/issues/107
  4. whoops, sorry, I typed that straight into the forum textbox, pretty happy anything works at all 😅 I’ve changed the quotes above, so you should be able to copy it, @Roych PHP’s equality operators are == and ===. This is a classic foot gun, there’s probably even a name for it… Your idea should be fine unless there’s some sort of bulk-trash feature that I don’t know about where the number of children could go from 8 to 6 in one go.
  5. Hi, you can add a hook to execute code whenever a page is moved to the trash. You can use this to check how many children are left and send an e-mail using WireMail. Put this in your ready.php: $this->addHookAfter('Pages::trashed(template=calendar-post)', function(HookEvent $event) { $numberOfItems = wire('pages')->count('parent=/daily-menu/'); if ($numberOfItems <= 7) { $m = new WireMail(); $m->to('chefdecuisine@example.com'); // specify CSV string or array for multiple addresses $m->from('noreply@example.com'); $m->subject("Uh-oh, there are only {$numberOfItems} dishes left on the menu"); $m->bodyHTML("<html><marquee><blink><a href='" . wire('config')->urls->admin . "'>DO SOMETHING QUICK!!!</a></blink></marquee></html>"); $m->send(); } }); Obviously if you trash items one by one, you’ll get one e-mail for every item as long as the total is under 8. A more proper way to do this may be a cron job that only checks once a day. Alternatively you may not need to send an e-mail at all? Perhaps it will suffice to show a message to the user who did the trashing? wire()->message('Please remember to complete the daily menu! There are currently only {$numberOfItems} dishes.'); You could show this just after trashing or simply all the time whenever there are too few items.
  6. Check the actual session storage in /site/assets/sessions/ or, if you’re using the module “Session Handler Database”, in the database table called “sessions”. Sounds like you already know where to find the session ID but for the record it’s in the cookie called “wires” (this is customisable), available in your browser’s dev tools. You can also check if maybe you’re overwriting the value before reading it on the second page? With a generic term like “session” there’s also always some danger of overriding ProcessWire’s $session variable. Using the Functions API can guard against this.
  7. https://obsproject.com/ this is open source and dope https://vento.so/ this was on hackernews the other day and promises some editing capabilities during recording
  8. I don’t think this is true. That’s the whole point of the secure files setting. It will only deliver the requested file if you’re logged in. So you can know the URL all you want, you also need a valid session cookie and potentially other fingerprinting stuff (eg. the correct IP).
  9. The way MarkupCache works simply does not allow for this nested use, IIRC. My advice is to just use the database cache (class WireCache, available as $cache or cache()), because it’s much easier to use and understand and probably just as fast. Obviously the speed depends on your setup, but if the database is on the same system and fits into memory it’s probably even faster than the filesystem. Also I would only cache the individual items, since renderResultList() doesn’t add anything interesting. It’s just going to complicate invalidation and bloat the cache table. With $cache you can preload all items in one roundtrip to the database, that should suffice. For more speed gainz you can always look into ProCache. As a sidenote, you’re overriding the WireCache $cache variable with MarkupCache, which may be a source of mistakes to watch out for.
  10. This sounds like kind of a big project. I would advise you to make one or two smaller sites with ProcessWire first. You may find that you can add the multi-user stuff on later, but most likely you will have learned so much that you’ll want to start from scratch anyway 😉 Check this out regarding different user types: https://processwire.com/blog/posts/processwire-core-updates-2.5.14/#multiple-templates-or-parents-for-users Just using the built-in roles and permissions features may be more than sufficient, though. One important thing to consider is whether these users will all be trusted. Are they people you know or do you want to allow any rando off the internet to make an account? Do you want to let them into ProcessWire’s admin backend or do you want to build custom forms for everything?
  11. The computer mostly did a good job, but I wouldn’t put it quite like this. One major thing to note about ImageMagick is that it is generally used without a graphical user interface and in fact without immediate user input. If the server on which you run ProcessWire has ImageMagick installed, ProcessWire can use it to create versions of your images in different sizes such as thumbnails. Shared hosting providers sometimes offer this (some don’t, but ProcessWire can also use a different library called “GD”). Basically you wouldn’t manually use ImageMagick before uploading images to your site. FileZilla can be used to install ProcessWire and transfer your own PHP code, but for uploading images and managing your webcomic, you would use ProcessWire’s admin area. That is, you would upload images over HTTP instead of FTP. ProcessWire then automatically creates thumbnails and puts everything where it needs to be (on the file system and in the database). To do this as a user you don’t need to know what any of these things mean. You just click upload, choose your images and hit save.
  12. You can run both on the same stack. You just create two databases and one ProcessWire installation in the filesystem for each database.
  13. 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
  14. 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.
  15. 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
  16. 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?
  17. 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));
  18. 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:
  19. 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:
  20. Whoops, my bad! I always default to the functions api because of the benefits laid our here https://processwire.com/docs/start/api-access/
  21. 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.
  22. 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.
  23. 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)
  24. 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.
  25. It used to be on TV in Germany every night, so maybe that? 😄
×
×
  • Create New...