Jump to content

DaveP

Members
  • Posts

    868
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by DaveP

  1. @horst Because everything is done through established API methods, that's what I think happens.
  2. Background - I came across http://www.responsivebreakpoints.com/ the other day and thought it was a nice idea, but that could be done in PW using the API. In a nutshell, what it does is create an image width breakpoint at roughly every 20kb of file size between a minimum and maximum pixel size. According to this article on CSS-Tricks, "If you’re just changing resolutions, use srcset", so the markup is as suggested there. There is already the excellent Srcset Image Textformatter which works on images in RTE fields, but if you want responsive images elsewhere in your templates, you need to do the markup and decide on breakpoint sizes yourself. However, Field Templates have got you covered! Just save this as a field template file in /site/templates/fields/my_image.php as described above. <?php $maxWidth = 1000; //largest breakpoint $minWidth = 200; //smallest breakpoint $srcQuality = 40; //jpeg quality of the 'src' image $srcsetQuality = 80; //jpeg quality of the 'srcset' images $breakpointStepFileSize = 20; //i.e. 20kb $class = ""; //change this if you want to add eg "class='responsive'" $horizAspect = $value->width / $value->height; $minSizeArea = round($minWidth * ($minWidth / $horizAspect)); $maxSizeArea = round($maxWidth * ($maxWidth / $horizAspect)); $areaDiff = $maxSizeArea - $minSizeArea; $minFile = $value->width($minWidth, array('quality' => $srcsetQuality)); $maxFile = $value->width($maxWidth, array('quality' => $srcsetQuality)); $minFileSize = $minFile->filesize; $maxFileSize = $maxFile->filesize; $fileSizeDiff = $maxFileSize - $minFileSize; if($fileSizeDiff > ($breakpointStepFileSize * 1024)){ $numBreakpoints = round($fileSizeDiff / ($breakpointStepFileSize * 1024)); for($s = 1; $s < $numBreakpoints; $s++){ $breakpointStepArea = $minSizeArea + (($areaDiff / $numBreakpoints) * $s); $breakpointWidth = round(sqrt($breakpointStepArea * $horizAspect)); $breakpoints[] = $breakpointWidth; } } $src = $value->width($maxWidth, array('quality' => $srcQuality))->url; $min = "$minFile->url {$minWidth}w, "; $out = "<img src='$src' srcset='$min"; foreach($breakpoints as $breakpoint){ $bp = $value->width($breakpoint, array('quality' => $srcsetQuality))->url; $out .= "$bp {$breakpoint}w, "; } $out .= "$maxFile->url {$maxWidth}w"; $out .= "' alt='$value->description' $class>"; echo $out; Then use something like echo $page->render->my_image; in your page template and you'll get something like <img src='/site/assets/files/1/photo.1000x0.jpg' srcset='/site/assets/files/1/photo.200x0.jpg 200w, /site/assets/files/1/photo.482x0.jpg 482w, /site/assets/files/1/photo.651x0.jpg 651w, /site/assets/files/1/photo.785x0.jpg 785w, /site/assets/files/1/photo.899x0.jpg 899w, /site/assets/files/1/photo.1000x0.jpg 1000w' alt='pic' > (Bear in mind that PW has to create all these image variations on first page load, so it will take a moment.) Give it a try and see what you think!
  3. I might be missing something here, but do you not need json_encode($json) in there somewhere?
  4. So, 48 hours or so after a question that initially got the standard "PW != WP" answer, there's been a reasoned discussion, people have come round to seeing some merit in the initial premise, and BitPoet has a couple of alpha modules on GitHub. That is an extraordinary testament to the quality of PW and this community.
  5. Hi petejones, and welcome. What LostKobrakai said, plus... PW really is a different beast to WP (and Joomla, or Mambo as it was when I first got involved with it). PW has had no known security issues, as ProcessWire or in its earlier incarnations. Background here. Unless you want the extra functionality that updates bring, there is no need to update an existing installation. Ryan explains one significant contributor here. I know this sounds strange, but PW doesn't need maintenance. It just works and carries on working and doesn't become broken for arbitrary reasons. Alright, on shared hosting (for example) there is the possibility that something could happen, but that would be because of poor security practices by the hoster, not PW.
  6. It hasn't been updated for a while, but the author, felix, is still around. <edit> And just thinking out loud, it wouldn't be hard to make a text formatter to cURL a link and parse for Open Graph tags or Twitter Cards, which a lot of sites include.</edit>
  7. Also take a look at http://oembed.com/ and http://modules.processwire.com/modules/textformatter-oembed/
  8. Ok, so there's a problem with the selector. Standard kind of debugging process - try this: $vorstand = $page->children(); then $vorstand = $page->children("vorstand=1"); (You might not need sort=sort) Hang on, just thought of something! Take the space out of your selector. $vorstand = $page->children("vorstand=1,sort=sort"); You never know.
  9. Firstly, try adding echo $vorstand->count(); after your first line. That will tell you if there is anything to loop through with your foreach().
  10. I think $comments = wire(modules)->get("Comments"); should work. Probably.
  11. I have my own blog hosted with vidahost.com. Their shared cloud hosting(?!?) is very affordable - https://www.vidahost.com/cloud-web-hosting/overview and I've had no problems in the first 12 months with them.
  12. I bet @Joss can remember this kind of setup.
  13. This kind of error is usually because your code is overwriting the PW $user object. Try making your own user and password variable something like $u and $p, then there is no chance of that happening.
  14. One easy addition to your original code is to add the descriptions, which would be something like $page->summary (per the default PW site profile). That said, you might want different descriptions (perhaps in tone, at least) across different social platforms. It gets even trickier with images as IIRC Twitter & FB don't agree on dimensions or aspect ratios. (Or at least they change them often.) FB's recommendations are here.
  15. @benbyf ..or use both if character limit allows?
  16. Freudian?
  17. Haven't used Padloper or Litespeed, but PW certainly works with MariaDB. I have tried it and there is this post as well.
  18. Looks great on mobile. Very sweet.
  19. I just looked at expired domains until my name came up.
  20. Yeh, what @kongondo said.
  21. One way (and there are always many) is to have a field specifying the body class for the child in the child. So you can Echo <class="$child->class> (On mobile so this is tricky!)
  22. Just ran this site through YSlow and you could help the images (and html & js) with a bit of .htaccess wizardry - see this post.
  23. (Answering one tiny bit of the original post.) The 'delete' checkbox you see occasionally is usually hidden by CSS and is to enable the 'trashcan' functionality in the repeater head. This suggests that your site sometimes doesn't load all the backend CSS.
  24. If I understand your question correctly something like this should work. $foo = $pages->get("name=rates")->children("checkbox=1"); I see Tom got there before me, and we are heading along similar lines.
×
×
  • Create New...