Leaderboard
Popular Content
Showing content with the highest reputation on 02/02/2016 in all areas
-
Update 2017-10: this feature is bult-in to AdminOnSteroids module, with more features (eg. ctrl-down/up for expand/collapse lang tabs) and bug fixes. This is a small snippet I put together to make easier to navigate between language tabs, using ctrl + right/left arrows. I know there is a button to toggle the visibility of all lang tabs but I find this method easier. It's far from perfect, doesn't work with ajax-loaded CKEditors and and the code itself could be polished more. But it does the job quite well. To use, put this in ready.php:5 points
-
It doesn't. Whether a template file matching the name of the template (or the alternative name in the template config) is in fact present in the file system isn't stored in the database. You could assemble a list of all templates without file and put that into a selector though: $missing = array(); foreach($templates->find("flags!={template::flagSystem}") as $tpl) { if(! $tpl->filenameExists()) $missing[] = $tpl->name; } // Now you can get all pages with missing template file: $pages->find("template=" . implode("|", $missing)); // Or just children $page->children("template=" . implode("|", $missing));3 points
-
3 points
-
Peter, it can be done. There's nothing to prevent it from being done . Something is goofing your script somewhere. Either you are overwriting your output in the foreach loops or there is something else we can't see, given we are only seeing part of the code. I am finding it difficult to understand how the <div> are related to the <ul> (if at all). How should the end result look like on a single page? One list of <ul>,</ul> and several <div> one for each image on that page? May I also suggest that if you can, try not to echo stuff within code but save them to a variable, usually $out, concatenating stuff to that variable and finally when you are done with the code, to echo $out. It's just easier to follow what's going on that way. Back to your qn, if we can get a clearer picture of the end result, this can be resolved quickly, maybe even put up an example online on some PHP Fiddle..2 points
-
Hi all, Not sure if this has been asked already but... Recently came across an agency with a build script for PW! I was amazed and also bemused, as alot of the script was used to create the right fields and templates in the DB from other local copies, and they'd done this by separating out tens of JSON files with individual field / template export data and sticking it back together on deploy creating new id's adhocly. (a far as i could see as id's were ommited) Anyway, in my experience I've always felt that export profile and profile installing has worked well for buiding for live as you get a stable install with your site template, fields and pages. If anyone has any scripting experience with PW I would love to know: Anyone else use build tools? What do you use them for with PW? and what languages/environment you use to create them?1 point
-
A very simple tip, but that might be useful for someone that didn't think of it... This is what I usually do if I want to change something on a live site. if($user->name!='diogo'){ // live code }else{ // my new code } Like this I'm the only one that sees the changes. More examples: // test new javascript. do the same for styles <?php if ($user->name!='diogo'){?> <script src="<?php echo $config->urls->templates?>scripts/main.js"></script> <?php }else{?> <script src="<?php echo $config->urls->templates?>scripts/main-dev.js"></script> <?php }?> // test new head file if($user->name!='diogo'){ include(head.inc); }else{ include(head-dev.inc): } and so on... edit: corrected the first block by Nik's suggestion1 point
-
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!1 point
-
I'll contribute too. ($100). Would love to see an integrated image optimisation module if there's agreement on the fundamentals. I know there are some upcoming improvements with the image UI on the horizon. I wonder are there plans for this type of service as a native or paid module. I also think that both support and maintenance need consideration. Some good approaches here http://www.mobiloud.com/blog/2015/02/10-best-image-optimization-plugins-speed-wordpress-site/1 point
-
Just to qualify my question above, I'm just trying to think through the whole idea of 'crowd-funded' modules, since, IIRC, it is uncharted territory for us (although quite interesting). Just wondering if it is something we need to think through a bit more.?..or am just being too fussy. OK, back to my hiding place...1 point
-
Just wanted to say that this sounds very interesting. Been meaning to build a module like this, though was thinking of limiting it to PNGs since that seems to be the only case where optimization doesn't necessarily mean sacrificing quality. I'm also aware of the minimize.pw service, but a) it's not free (as in beer or as in freedom), b) it doesn't seem to be well maintained and c) I don't want to rely on external services unless I really trust them (especially when it means sending client data over to an external server). As a reply to Horst, kind of, I'd like to point out that whether or not the host allows exec(), if there's a similar solution that doesn't require it, that's in my opinion always the better route. Even when you're taking every step to make sure that it's safe, exec() is still potentially dangerous. Any and all mistakes have the potential to compromise your entire server (or, at the very least, your personal account). There's a reason why exec() and other code execution methods tend to trigger warnings from security scanners. That being said, I won't deny that executing external apps via PHP can solve some situations where nothing else helps. I've had to use it many times over myself. Edit: just took a closer look at Tinify. Somehow I managed to miss earlier the point that it is also an API, i.e. requires sending the data to their servers for processing. Can't say that I would be exactly happy with that, but will give this a while; perhaps it's a compromise worth making. In the meantime I'll be looking into some alternative approaches.1 point
-
@matjazp: Thanks for clarifying. I didn't know that there is no further maintainance of the minimize service. I also know that we would need CLI processing via PHPs exec(), and that this isn't supported on (some) shared hosts. But also the bullet proofed method would be to process variations and minifying locally. A less bullet proofed method would be to use "a sort of" remote service via http on the own host, if possible, because you also have full control and the http protocoll overhead is small and results in appropriate fast speed. The last one in the hirarchy is to use a foreign remote service, as you have no control and a lot of overhead. I'm interested in how many shared hosts have the ability to choose php fastcgi handler for subdirectories (via htaccess), where you than have support for exec(). I'm on this sort of shared servers myself and use PHP as apache_module with disabled exec() as the (main) PHP handler for the whole site. But I can define fastcgi handler(s) for A) a specific subdirectory or B) for a specific defined file extension. This way I'm able to run my PW site within a fast apache_module PHP handler and pass the final step of optimization via http to a cgihandler script. This is really fast, as I do not have to sent and retrieve files, I also do not need to resolve a DNS for the connection, as it is on the same (local) host. If there is the possibilty for others too, I'm happy to share my solution.1 point
-
@OllieMackJames: I would love to have that module. I can help with testing/debugging as I'm not that good at programming. @Horst: I know ProcessImageMinimize.pw, but it is not free (although they have free plan). ProcessImageMinimize is not supported on PW3 (I asked Marvin Scharle at Conclurer). I tested it and couldn't make it work (running on Windows with IIS - maybe this is the culprit). And probably there will be no more support for it. Module JpegOptimImage is using exec, some sites do not allow that. Most of my users doesn't know anything about images so they upload just what they have, even if those are big images (like 5-10 Mb) and large sizes. I just go after them, resize if needed (yes, I have max/min width set in ImageField) and then optimize with jpegmini.1 point
-
Head over here and run the following code (pasting between the <?php ?> tags). Have a look at the output (underlying html) Is that what you are after? Note: this is pseudo-code. No image tags here. $tags here are equivalent to your $page->images. $tags = array('Bathroom', 'Gym Basement Loft', 'Home-Office Kitchen', 'Kitchen', 'Car', 'Gym'); $tagsArray = array(); $uniqueTags = array(); $out =''; $out .= "<ul>"; foreach ($tags as $tag) { $tagsArray = explode(' ', $tag); foreach ($tagsArray as $t) { if(in_array($t, $uniqueTags)) continue;// skip duplicate tags $out .= "<li data-uk-filter='{$t}'><a href='#'>{$t}</a></li>"; $uniqueTags[] = $t; } } $out .= "</ul>"; foreach ($tags as $tag) { $t = str_replace(' ', ', ', $tag);// our comma separated tags $out .= "<div data-uk-filter='{$t}'>" . "<a class='fancybox-portfolio port-item' href='url' rel='gallery1'>" . $tag . "</a>" . "</div>"; } echo $out; Alternative shorter code...looping 'once' $tags = array('Bathroom', 'Gym Basement Loft', 'Home-Office Kitchen', 'Kitchen', 'Car', 'Gym'); $tagsArray = array(); $uniqueTags = array(); $divs ='';// will hold the <div> $out =''; $out .= "<ul>"; foreach ($tags as $tag) { $tagsArray = explode(' ', $tag); $t = str_replace(' ', ', ', $tag); $divs .= "<div data-uk-filter='{$t}'>" . "<a class='fancybox-portfolio port-item' href='url' rel='gallery1'>" . $tag . "</a>" . "</div>"; foreach ($tagsArray as $t) { if(in_array($t, $uniqueTags)) continue;// skip duplicate tags $out .= "<li data-uk-filter='{$t}'><a href='#'>{$t}</a></li>"; $uniqueTags[] = $t; } } $out .= "</ul>" . $divs;1 point
-
1 point
-
Thanks Martijn My understanding of the images API is that I can set just a width and the height will be proportional so I'm not sure why thats throwing an error. At least I'm happy it's not causing my issue. Can anyone actually try on their own install to output a list of comma separated image tags from a page? I've never seen it done before and there's not much evidence on the forums that it's been tried.1 point
-
Thank you for sharing! It would be nice to have this feature built in.1 point
-
I haven't done it in a project yet, but I've found 2 reliable sources of information: https://sites.google.com/site/webmasterhelpforum/en/faq-internationalisation https://moz.com/learn/seo/international-seo I think you're covered.1 point
-
That's just the thing with PW: there's rarely a "right way" to do something. When it comes to things like templating, I still think that for a beginner it's best to start with the simplest possible scenario, which would be direct output. Once you grasp that, it's much easier to understand how delayed output or some of the more advanced output strategies work. For an example my own favorite output pattern is loosely based on model-view-controller. It's entirely based on template files, and comprised of a shared front controller, template-specific controllers and view scripts, partials, and layouts. The result is a structure that in my opinion can be easily adapted to all kinds of sites, applications, and so on. Would I recommend this as the first thing a complete beginner should learn? Probably not1 point
-
Yeah just read it. Since I came across the delayed output (and using leading underscore for view files) I fell in love with it. Set variables (or placeholders as some call it) with init values, output them in _main.php, give them overrides as needed in a template file. Use wireRenderFile() for view files. You can in fact stack your site with any layers you want, outputted in _main.php1 point
-
Thanks for this Ben! I was about to hit the comments but I see Ryan has already mentioned what I had in mind1 point
-
This line is executed regardless of whether $item has children: $out .= "<li$class><a href='{$item->url}'><i class='fa fa-file-text-o'></i> {$item->title}</a>\n"; You’re going to want to attach it to the condition if($numChildren) { below, so the link is only appended to your output if it doesn’t have children. Perhaps like so: if(!$numChildren) { //No children, so append the standard top-tier link $out .= "<li$class><a href='{$item->url}'><i class='fa fa-file-text-o'></i> {$item->title}</a>\n"; } else { //We have children here, so append the parent-style link and do the recursion //... }1 point
-
Two uses for this solution -- part of a book back matter (indexing) and newspaper/magazine column layouts. In a responsive design, you can have a single-column for mobile, two-column for tablet, and three-column for desktop -- similar to iNoize's attached image.1 point
-
I've looked at the module, and I'd like it to be more passive than that. Plus, instead of confronting visitors with a login screen, I'd rather give them some information. In fact, this code in head.inc seems to work nicely - $allowed = array('192.168.1.0','192.168.1.1'); $ip = $_SERVER['REMOTE_ADDR']; if (!in_array($ip, $allowed)) { header("Location: http://example.com/maintenance.html"); exit(); }1 point
-
No problem. Also, as a somewhat cleaner alternative to what I posted above, you can grab the POSTed version of the username directly to avoid the need to replace "-" with "@". With this version, it doesn't have to do anything if there is no "@" in the entered username. public function init() { if (strpos(wire('input')->post->login_name, '@') !== FALSE) { $this->addHookBefore('Session::login', $this, 'beforeSessionLogin'); } } public function beforeSessionLogin(HookEvent $event) { $name = wire('sanitizer')->email(wire('input')->post->login_name); $u = wire('users')->get("email=$name"); if($u->id) $event->setArgument('name', $u->name); } This way you can choose to sanitize it as an email address before it has been sanitized as a pageName which doesn't allow "@". The disadvantage to this version though is that for the front-end, you need to make sure your custom login form also uses "login_name" as the name of the input field. Not a big deal, but not as versatile I guess.1 point
-
Thank you for your help, ryan! I hadn´t realized that I would have to rename the module tor run in /site/modules/, that´s why it didn´t work from there. Great work the whole CMS, I like it a lot!1 point
-
The prefered, simpler way is to make the user when created via API unpublished: $user->addStatus(Page::statusUnpublished); See cheatsheet addStatus Then the user can't login yet. And the admin can just go and publish the user (same as with pages) in the admin. Users are pages so the page API applies here same way as it is for pages. Or using API to publish $user->removeStatus(Page::statusUnpublished); See cheatsheet removeStatus The different system flags are also on the cheatsheet.1 point