Leaderboard
Popular Content
Showing content with the highest reputation on 08/06/2016 in all areas
-
Like mentioned in last week's post, this week was focused on covering remaining GitHub issue reports and pull requests in preparation for the 3.0 and 2.8 master version releases. In total we covered close to a dozen issues and around ten pull requests this week, so you'll find lots of updates in today's versions (3.0.29 and 2.8.29). In addition, we've also got a section in this post for those that have inquired about ProcessWire site development help. https://processwire.com/blog/posts/pw-3.0.29/7 points
-
Been in that position multiple times and I can highly recommend Ryan for any PW related work.7 points
-
Hi, I haven't followed to the end here, but saw something above what I want to mention: using <?php if($page->numChildren) { counts hidden / unpublished / protected pages too, per default. This is implemented in $page to give a quick "overview" of totals, but unrelated to their states. This is useful and was implemented for cases where you have lots (thousands!) of children, to give an raw overview. But in your case, with only a few or NO children, you want to query the exact visible / accessible children for guests. You need to use <?php if($page->numChildren(true)) { see: http://cheatsheet.processwire.com/page/built-in-methods-reference/page-numchildren-bool/ TLDR Before Ryan introduced numChildren(false|true), only $page->children()->count() was available, what needed to read / open all childpages and results into much memory and cpu usage and execution time. With numChildren(false|true) we have a much faster alternative. I think the fasted case is with the param set to false, the default. (Thats why it is the default . But this is only my guessing.)5 points
-
I gotta say, how awesome is that we're in a community where we can hire PW's main man to help with our projects?! Like, can you imagine a world where you can't decide on your Facebook cover image so you call in Zuckerberg for a consult?5 points
-
A couple of errors in your function... $output .="<h1><?php echo $page->title; ?></h1>"; The PHP tags shouldn't be here and you cannot echo inside a variable declaration. {$pages->about} ... {$pages->maincopy} These don't make sense - maybe you meant $page ? And totally a matter of preference, but I find... $output = " <div class='container'> <div class='row'> <div class='col-md-12'> <h1>{$page->title}</h1> </div> </div> </div> "; ...more readable than... $output = ""; $output .="<div class=\"container\">"; $output .="<div class=\"row\">"; $output .="<div class=\"col-md-12\">"; $output .="<h1>{$page->title}</h1>"; $output .="</div>"; $output .="</div>"; If you're considering switching to functions instead of includes because of performance concerns I wouldn't bother. It's true that you would avoid some file loads but you'd have to have a lot more includes before this would make a difference worth caring about. One thing to think about when considering a switch from includes to functions is variable scope. Basically, includes have access to variables defined outside of them but functions do not unless you pass the variable to the function as a parameter. This can be a help or a hindrance depending on your needs. Lastly, you could consider using $files->render() (aka wireRenderFile). A file rendered this way has access to all API variables and you can pass in an array of your own variables for use inside the file. I'm not 100% clear on the benefits of this over a normal include but I guess it has to do with the isolation of variable scope (to avoid the risk of overwriting variables of the same name in your template).4 points
-
Although you were experiencing this issue before enabling xdebug, xdebug itself really slows down PW. But that doesn't seem to be the issue in your case. Some things to try: try running the site on a production server and see if it's slow. if it's not, there's some issue with your local server. if you're using an old version of wamp-server (like v 2.4), try upgrading to a newer version. i hit an issue a couple years ago on an older version that was plaguing me. perhaps you're doing some crazy stuff with your code that you may not realize. keep trying to selectively remove various parts of your code and refreshing your site to see if you get a moment where everything clears up. then analyze the problematic code. Let us know how it works out.3 points
-
@flydev: only one suggestion: it should be $child->numChildren(true) instead of $child->numChildren // what is the shortcut to $child->numChildren(false) Read here why: https://processwire.com/talk/topic/13950-show-image-childrens-children/#comment-1254103 points
-
3 points
-
I think you should create a thumbnail on after saving the image with a hook. see https://processwire.com/api/hooks/captain-hook/?filter=image <?php // hook to this method protected function ___fileAdded(Pagefile $pagefile); $this->addHookAfter('InputFieldImage::fileAdded', $this, 'createThumbnail'); // create the thumbnail public function createThumbnail(HookEvent $event){ $file = $event->return; // new thumb $page->image->width(200); } with that you create the thumbnail right away on image uploading. I think that would work. But haven't tested that code.3 points
-
@Jason Huck I don't think this will sort out your problem - but you might want to do your realpath() call earlier - before you call file_put_contents() to save the image to tmp storage. You should also check the return value of that call and not try to store the image if it failed to write it to the tmp location. if(startsWith($image_data_raw, '0x')){ $image_data = hex2bin(ltrim($image_data_raw, '0x')); $image_path = realpath(wire('config')->paths->templates.'tmp/'.$line[18]); // Realpath here $has_image = file_put_contents($image_path, $image_data); // Use return value to signal need to add the image } else { $has_image = false; } ...and... // add image, save page again, and remove temporary image if($has_image){ if($product->image) { $product->image->deleteAll(); // get rid of anything that's already in there $product->save('image'); // try saving after delete to avoid 502's } $product->image->add($image_path); $product->save('image'); // save just the image field instead of the whole page unlink($image_path); // Now no need to realpath() here. } Also, have you tried saving the entire product page rather than just the 'image' field? // add image, save page again, and remove temporary image if($has_image){ if($product->image) { $product->image->deleteAll(); $product->save(); } $product->image->add($image_path); $product->save(); unlink($image_path); }2 points
-
Maybe this: https://processwire.com/blog/posts/upgrades-optimizations-pw-3.0.22/#major-optimizations-to-inputfield-forms2 points
-
Thanks @Horst for your comment. I'd replaced it! And @Blynx helped me trough PM. (Thanks!!) With the following line of code $projects = $pages->get("name=projects"); foreach ($projects->children as $cat) { foreach ($cat->children as $proj) { if ($proj->head_image) { echo $proj->head_image->url."<br>"; } } }2 points
-
Meanwhile we fixed it, there was some "}" missing somewhere, thanks for the addition @horst!2 points
-
Hi Troost, try something like this: foreach($page->children as $cat) { // maybe echo category stuff here? foreach ($cat->children as $project) { if ($project->head_image) { // echo project image stuff here } } } This loops through the categories first, and for each category looping through the projects. So it will loop through all projects one category after another. Also you could then echo some category stuff inbetween if you want ... cheers! Steffen2 points
-
Never been in the position but indeed it would be great to hire Ryan to do some cool stuff.2 points
-
Just wanted to add that if, as in the OP's case, you are going to foreach the children then there is no additional penalty to using $page->children()->count() because you will be loading the children into memory anyway.1 point
-
Ok, I made a huge progress after diving into the Inputfield class where I found those hidden features I needed to put the markup just where I needed. PW is great- it seems that Ryan (and others) have thought about all the things someone needs WAY before I added the field name to show on hover - it's animated from the left, with a small delay because it was frustrating moving the mouse around and they appeared here and there. I still need to finish a few things before I publish this but I think the majority of the work is done.1 point
-
@adrian Didn't realise it was that simple - thank you! Overlooked it as I'm using the Reno theme and it's sneakily hidden under "Helpers..."!1 point
-
1 point
-
@netcarver Actually it looks like that did sort the issue. I'll have to test some more, but I'm guessing that verifying the result of file_put_contents, which I should have been doing in the first place, is the key. Without that, the script was trying to add and remove nonexistent image files. Thanks for pointing that out!1 point
-
I started adding the field (and template?) edit links, similar to Soma's module HelperFieldLinks (but only links, without the all the field/template data). My first idea is to use ctrl+click (or long click?) on field label go to the edit page (on new tab, or perhaps modal/panel). I would like to avoid the clutter but let me know if you would prefer icon or other solution instead. Also, if you have an idea where to put the "Edit template" link, please share. My idea is ctrl+click on page title.1 point
-
@hansv - are you using the default images field, or have you added a third party cropping module or the imageextra module?1 point
-
Hej, just sent you a DM, maybe send me your site and I can have a look - maybe the error is somewhere else hidden!?!?1 point
-
Ok tested the approach here, works fine ... Ah, I meant the projects - has every project page an actual image inside head_image? (Well, might be a silly question but who know ^^)1 point
-
Yea, I have sorted the templates. The projects under Photography are with the photography.php, same for graphic etc etc. I will sort it out later with. If clicked on photography, the rest of the images wil disappear, and same for other categories. The category doenst have a head image, its just the projects underneath. The category just just a 'empty' template with only the title displayed. The code ill posted above is from the category template, the template structure is build up like this root -> Projects (category template) -> Photography, Graphic etc (category template) -> project (project template) This is the category page This is the projectpage (The image description and images are for an eventualy further page) --------------- Now I get an syntax error with this <?php if($page->numChildren) { echo "<ul class='project'>"; foreach($page->children as $cat) { foreach ($cat->children as $project) { if ($project->head_image) { echo "<li class='item'><img src='{$project->head_image->url}' class='image'></li>"; }} echo "</ul>";} ?> But the syntax error gives an error at the end of the document... When I put the other lines of code back to how it was, the error is gone. Thanks for your time, I hope im not confusing with the long sloppy posts1 point
-
Hej, you forgot to select the head_image in your image tag: <img src='{$project->head_image->url}' class='head-image'> This should work? Also it is better to use more specific classnames which describe the element in more detail - for example you would see at once in your css what kind of image that is - and other reasons ...1 point
-
Hi Steffen, Thanks for your comment and help. I've copied your code in, but still won't echo all the projects from the different categories. Got it like this now, or is this to easy thinking? <?php include("./header.inc"); ?> <div id="container" data-isotope='{ "itemSelector": ".grid-item", "layoutMode": "fitRows" }'> <div class="grid-sizer"></div> <?php if($page->numChildren) { echo "<ul class='project'>"; foreach($page->children as $cat) { foreach ($cat->children as $project) { if ($project->head_image) { echo "<li class='item' ><img src='{$project->url}' class='image'></li>"; }} echo "</ul>";} ?> </div> <!-- END CONTAINER --> </body> <?php include("./footer.inc"); ?>1 point
-
1 point
-
1 point
-
If you are using Processwire 3.x you could import PW namespace <?php namespace Processwire; and use the functions without the need for wire() method.1 point
-
@Marcel Epp You could add a new parameter to the function. Assuming you are using the code shown in the first post, the following code should work (not tested) : function renderChildrenOf($pa, $maxDepth = 1, $output = '', $level = 0) // MODIFIED_CODE { $output = ''; $level++; foreach ($pa as $child) { $atoggle = ''; $class = ''; if ($child->numChildren(true) && count($child->parents) == 1) { $class .= 'dropdown'; $atoggle .= ' class="dropdown-toggle" data-toggle="dropdown"'; } else if ($child->numChildren(true) && count($child->parents) > 1 ) { $class .= ($maxDepth > 0) ? 'dropdown-submenu' : ''; // MODIFIED_CODE $atoggle .= ($maxDepth > 0) ? ' class="dropdown-toggle"' : ' '; // MODIFIED_CODE } else if ($child->numChildren(true) && $child->id != 1) { $class .= 'dropdown-menu'; } // Makes the current page and it's top level parent add an active class $class .= ($child === wire("page") || $child === wire("page")->rootParent) ? " active" : ''; $class = strlen($class) ? " class='" . trim($class) . "'" : ''; if ($child->numChildren(true) && count($child->parents) == 1) { // Add Caret if have children $output .= "<li$class><a href='$child->url'$atoggle>$child->title <b class='caret'></b></a>"; } else if ($child->numChildren(true) && count($child->parents) > 1) { $output .= "<li$class><a tabindex='-1' href='$child->url'$atoggle>$child->title</a>"; } else { $output .= "<li$class><a href='$child->url'$atoggle>$child->title</a>"; } // If this child is itself a parent and not the root page, then render it's children in their own menu too... if ($child->numChildren(true) && $child->id != 1 && $maxDepth > 0) { // MODIFIED_CODE $maxDepth--; // MODIFIED_CODE $output .= renderChildrenOf($child->children, $maxDepth, $output, $level); // MODIFIED_CODE } $output .= '</li>'; } $outerclass = ($level == 1) ? "nav navbar-nav" : 'dropdown-menu'; return "<ul class='$outerclass'>$output</ul>"; } // bundle up the first level pages and prepend the root home page $homepage = $pages->get(1); $pa = $homepage->children; $pa = $pa->prepend($homepage); // Set the ball rolling... echo renderChildrenOf($pa); Search the comments MODIFIED_CODE to see whats going on in the function.1 point
-
I suspect that adding width and height is probably sufficient for non-SSL sites, but in this case, the entire site is served over SSL, which apparently made secure_url required as well, even though a secure URL was already provided for the base og:image value. I can't point to any documentation in that regard, it's just what finally worked for me.1 point
-
@mr-fan if you are still having the problem from with geocoding from your custom fields, maybe my modified InputfieldLeafletMapMarker.js gist can help. I have a custom button in the form that triggers the geocoding, defined on line 48 and a fucntion from line 135 that takes values from custom fields, concats them and does the geocoding.1 point
-
Hello, guys! I've prepared an extract of my latest work for public usage: Template for ProcessWire with Stylus and PostCSS. It simplifies the development of the stylesheet and JS files with CSS preprocessors, autoprefixes and browser reloading. I hope it can be a good kickstart for your next project! https://github.com/leonidlezner/pwtemplate Released under MIT, no credits or copyright notices are necessary, so feel free to do with it whatever you want Update: Template works with 3.x too! And now with German Tutorial http://leogo.es/qvxul1 point
-
Hey Mike - any thoughts of making is possible to add redirects via an API call. After the discussion this morning about imported Wordpress rewriting (https://processwire.com/talk/topic/8869-wordpress-url-rewrites/), I would like to add this functionality to MigratorWordpress so that rewrites are automatically added. Obviously I can do it through SQL inserts, but thought an API method would be nice.1 point
-
this is great...! i was trying to write this module about 2 months ago and couldn't figure out how to do it.. edit: brilliant, works perfectly, and even works using ../ to get out of the templates folder... this is going to be extremely useful for html5 video, selecting files to be used instead of uploading to processwire page.... and in other situations where we want to store large media assets somewhere else in the filesystem.. many thanks for this.1 point