Leaderboard
Popular Content
Showing content with the highest reputation on 09/11/2017 in all areas
-
Hey Pete, thanks for doing the upgrade. I guess not much has changed from an appearance point-of-view. My only gripe is the reactions bar - I now I have to click Like twice, and the chances of me using other reactions is very slim (this isn't a social network, after all). Any chance it can be disabled? Unless anyone has any objections... Also, this issue is still present (really long initial tag): Thanks!5 points
-
I've just upgraded the forums due to an important security patch being released. There was a bit of a dilemma in that the forum upgrade was guaranteed to break the theme that blended the forum software into the rest of the site design as it was a fairly major release that contained the fix. I chose to upgrade the forums anyway as the security issue was big enough to warrant a little discomfort in the short-term. Please bear with me over the next 24 hours as I get things looking back to normal again.4 points
-
hi @Martin Muzatko i would recommend you read the docs about hooks carefully: https://processwire.com/api/hooks (especially here: https://processwire.com/api/hooks/#add_new_method ) to your problem: try this: public function getMessagesBySender($event) { $user = $event->object; $sender = $event->arguments[0]; $event->return = $user->getMessages()->find('sender='.$sender); } you could also modify your getMessages method to take an argument as selector and then use it like this: $user->getMessages("sender=$user"); // additional tip: double quotes makes it easier to read sometimes ;) regarding the "event system": $event in the hooks is the hookevent object. you could call it whatever you want, but as it's called $event everywhere in PW it's good to stay with this naming. the object is needed by PW and it's hook system so you cannot just "return" from inside the method. or to be more clear: you can just return but then it will not change anything. thats the way how you can do early exits: $wire->addHookAfter('Pages::added', function($myHookEvent) { $page = $myHookEvent->arguments(0); if($page->template != 'mytemplate') return; // example of early exit [...] } here i named $event differently just as a showcase. the $event->return property holds the "value" of the hooked method. this can be different things, for example a PageArray if you hook a page find operation or a simple string if you hook a field's value. This value is only one thing that is needed by processwire to fully execute the request. For example there is also the $event->replace property that would tell PW to completely replace the hooked method if it was set to TRUE - so pw would not call the original method after the hook was executed (this only works on before-hooks, of course). https://processwire.com/api/hooks/#replace_method hope this makes sense for you. i would also recommend using tracy debugger - it's a lot more powerful and easier to read than var_dump3 points
-
Here are my generic versions WireArray::map wire()->addHookMethod('WireArray::map', function (HookEvent $e) { $func = $e->arguments(0); if (!is_callable($func)) throw new WireException('first argument must be a callable function'); $mapped = array_map($func, $e->object->getArray()); $e->return = $mapped; }); WireArray::reduce wire()->addHookMethod('WireArray::reduce', function (HookEvent $e) { $func = $e->arguments(0); $initial = $e->arguments(1) ?? []; if (!is_callable($func)) throw new WireException('first argument must be a callable function'); $reduced = array_reduce($e->object->getArray(), $func, $initial); $e->return = $reduced; }); WireArray::forEach wire()->addHookMethod('WireArray::forEach', function (HookEvent $e) { $func = $e->arguments(0); if (!is_callable($func)) throw new WireException('first argument must be a callable function'); $foreached = []; foreach ($e->object as $i => $item) $foreached[] = $func($item, $i); $e->return = $foreached; }); Tests $mapped = $pages->find('id>0, parent=2')->map(function($page) { return [ 'title' => $page->title, 'id' => $page->id ]; }); $reduced = $pages->find('template=post')->reduce(function($carry, $item){ $carry[] = $item->id; return $carry; }, []); $foreached = $pages->find('template=post')->forEach(function($item){ echo $item->id . '<br>'; }); dump($mapped); dump($reduced); dump($foreached); Which outputs array (4) 0 => array (2) title => "Pages" (5) id => 3 1 => array (2) title => "Setup" (5) id => 22 2 => array (2) title => "Modules" (7) id => 21 3 => array (2) title => "Access" (6) id => 28 array (8) 0 => 1024 1 => 1026 2 => 1028 3 => 1031 4 => 1033 5 => 1058 6 => 1062 7 => 1065 1024 1026 1028 1031 1033 1058 1062 1065 array (8) 0 => null 1 => null 2 => null 3 => null 4 => null 5 => null 6 => null 7 => null 29.59ms, 0.06 MB3 points
-
Ah, I see. Doesn't do that for me. Well, it does the first time, but quickly disappears and then I have to click on it to open it.2 points
-
I would only create the page if the user answers the first step of the quiz (to avoid empty pages). And yes, I would pass the ID of the page to each successive step of the quiz.2 points
-
2 points
-
If outputformatting is off it will always return an array.2 points
-
what about this? <?php $allTitles = $yourPageArray->each('title'); // or if it was more complex $allTitles = $yourPageArray->each(function($page) { return "{$page->forename} {$page->surname}"; } you can also add your own methods via hooks: $wire->addHookMethod('WireArray::test', function($event) { $arr = $event->object; $out = []; foreach($arr as $item) $out[] = 'testing page ' . $item->id; $event->return = $out; });2 points
-
Small update to the ProcessWire Info panel which adds a new redirecting "Login" button. Obviously this is only relevant if you have checked the "Force Guest Users into Development Mode on Localhost" option in the config settings. I always do this because I like the Tracy debug bar enabled whether I am logged in or not when developing. The nice thing about this login button is that it redirects to the page you were on when you clicked it, so you can be viewing a page on the frontend of your site, click this button, enter your credentials and you will be automatically redirected back to the page you were viewing. Showing the login button: And if you are already logged in, then you'll get a logout button instead (which also returns you to the current page after logout):2 points
-
Hello there! I'd love to see more array operation functions such as map/reduce. There are already a few helpful functions there like pop, shift, etc. I find myself turning pageArrays into arrays, do array_map or similar and create pageArrays again from that data. For Processwire, it would be really helpful to perform forEach operations more comfortably. E.g. <?php $allTitles = $pages->map(function($page){return $page->title}); // vs traditionally: $allTitles = []; foreach($pages as $page) { array_push($allTitles, $page->title); } $pages->reduce would be really helpful too. This would avoid many in-between variables when calculating sums of fields stored in individual pages. Thank you in advance Best, Martin1 point
-
By the way, the new way of previewing post is rather misleading, at least most of the time, eg: Here, I wanted to recommend @LostKobrakai's post which is about API variable access and was written as a side note, not as the actual reply to the topic. Including – even worse highlighting! – the topic makes the false impression that my intention was to link to the topic "Custom PHP code selector" but it is not the case. And this situation will not be rare. This new feature will not be helpful in a lot of cases, rather it will add confusion1 point
-
Here is a related very good post I keep recommending from time to time.1 point
-
sent you a private message to hunt this down.1 point
-
1 point
-
Interesting... Still not for me. One click to open the reactions bar (unlike Facebook's hover) and then another click to Like (as in, select from the reactions bar). They do appear to be shown initially for me.1 point
-
You're running into PHP scope issues. You will need to use: $this->wire('user')->name; Same goes for $pages - use: $this->wire('pages')->findOne .......1 point
-
For me too but I hate that fact that user names are no longer displayed initially. We need to lick and wait to see even the first users who have already reacted. Is it possible to get back the previous behavior? I also vote for "like" only1 point
-
1 point
-
1 point
-
It doesn't really matter, but high quality source gives you higher quality thumbnails. However, in both cases, unless _web is an very low quality version of _flat, the difference between the results wouldn't even be noticable. One thing to note, however, lower resolution images take less time & cpu to work on, so I guess you should go with _web version.1 point
-
Check out Pageimage::size() method https://processwire.com/api/ref/page-image/size/ <?php namespace ProcessWire; $img = $page->images->first; $img1x = $img->size(300, 400)->url; $img2x = $img->size(600, 800, ['quality' => 70])->url; $img3x = $img->size(1200, 1600, ['quality' => 60])->url; ?> <img src="<?= $img1x ?>" srcset="<?= $img1x ?> 1x, <?= $img2x ?> 2x, <?= $img3x ?> 3x" alt="">1 point
-
The basic functionality of the module is great, but I wanted the capacity to add paths, and potentially geometric areas, and the easiest way I found to generate them was using something like Google Earth, or various mobile GPS apps which export KML files. KML files can contain map markers as well, but the module already handles these fine. The Google Maps API allows adding KML layers, and of course Processwire already has a files fieldtype, so it's easy to create a files field that only allows files of type kml. I had to make a few modifications to the FieldTypeMapMarker as well. MarkupGoogleMap.js //Add support for KML overlays, eg exported from Google Earth, or various GPS apps. this.addKml = function (url) { var zIndex = 99999 + this.numMarkers + 1; var layerOptions = { url: url, map: this.map, zIndex: zIndex } var kml = new google.maps.KmlLayer(layerOptions); } MarkupGoogleMap.module I added a 'postinit' property that is output after the map has been rendered. I found that the overlays can only be added after the map has been initialised, so the existing 'init' property didn't work. Here's how I used it in a template: $map = $modules->get('MarkupGoogleMap'); foreach ($page->kml as $kmlFile) { $overlays .= "mgmap1.addKml('$kmlFile->httpUrl'); "; } $content .= $map->render($page, 'location', array('type' => 'ROADMAP', 'postinit' => $overlays)); The code could probably be improved to have the foreach loop inside MarkupGoogleMap.module, and just pass the name of the overlay field if any, but it needs to be optional, as not all maps will have an associated field with kml files.1 point
-
@bernhard, I've found a way. Hooking ProcessPageEdit::buildForm works wire()->addHookAfter('ProcessPageEdit::buildForm', function (HookEvent $e) { /** @var ProcessPageEdit $edit */ $templates = ['post', 'basic']; $edit = $e->object; $page = $edit->getPage(); if (!in_array($page->template->name, $templates)) return; /** @var InputfieldForm $form */ $form = $e->return; /** @var InputfieldImage $imageField */ $imageField = $form->children->findOne('name=images'); if (!$imageField) return; $imageField->maxFiles = 1; }); When I try to add more images, field just replaces the first one, not allowing more than one. If there were multiple images before, they disappear after page save, only the first one remains.1 point
-
Hey @bernhard - I took another look at the $wire variable not being available in ready.php (and init.php / finished.php) and this has been fixed in the latest version. Please confirm it all works at your end please.1 point
-
Code snippets are very hard to read on small screens due to lack of white-space: pre CSS property on <pre> tags. This causes very weird text wrapping. Adding this allows code to scroll sideways, which also preserves the whitespace properly. Here's the problem and proposed change in action Readable on large screens, overflow works ✓ Unreadable on small screens, text should not wrap ✘ Proposal: add white-space: pre on <pre> elements. See it in action 2017-04-05_20-18-03.mp4 (770KB) or GIPHY link1 point
-
I'm not 100 % sure right now, but I think if you don't set a name, Pw takes already care of this problem. Edit: Yep it does, found the code in Pages::___setupNew() protected function ___setupNew(Page $page) { if(!$page->name && $page->title) { $n = 0; $pageName = $this->fuel('sanitizer')->pageName($page->title, Sanitizer::translate); do { $name = $pageName . ($n ? "-$n" : ''); $child = $page->parent->child("name=$name"); // see if another page already has the same name $n++; } while($child->id); $page->name = $name; } //... So just set the title. If the same title appears multiple times, the API generates a name with -1,-2,-3...1 point