Jump to content

Jan Romero

Members
  • Posts

    550
  • Joined

  • Last visited

  • Days Won

    12

Jan Romero last won the day on November 16 2022

Jan Romero had the most liked content!

1 Follower

Profile Information

  • Gender
    Not Telling
  • Location
    Germany

Recent Profile Visitors

14,909 profile views

Jan Romero's Achievements

Hero Member

Hero Member (6/6)

806

Reputation

26

Community Answers

  1. 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.
  2. 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?
  3. 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.
  4. You can run both on the same stack. You just create two databases and one ProcessWire installation in the filesystem for each database.
  5. 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
  6. 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.
  7. 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
  8. 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?
  9. 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));
  10. 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:
  11. 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:
  12. Whoops, my bad! I always default to the functions api because of the benefits laid our here https://processwire.com/docs/start/api-access/
  13. 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.
  14. 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.
  15. 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)
×
×
  • Create New...