-
Posts
1,554 -
Joined
-
Last visited
-
Days Won
48
Everything posted by gebeer
-
Released: Street Address Fieldtype + Inputfield
gebeer replied to netcarver's topic in Modules/Plugins
Sorry @netcarver to be bothering again. When I try to search in ListerPro for a subfield (e.g. locality) with "Contains Text", I get following error: Operator '%=' is not implemented in FieldtypeStreetAddress Guess this has something to do with how the module is setup. I had this once in my own custom address fieldtype (that has never been published as an official module). But unfortunately I don't know the exact solution to this problem. But I just found a pointer towards a solution in Ryan's post here. Hope you can sort it out. Would be nice to be able to search for partial strings within the subfields. -
Released: Street Address Fieldtype + Inputfield
gebeer replied to netcarver's topic in Modules/Plugins
Hello @netcarver and thank you for that great module. I just installed v1.0.6 on a brand new PW 3.0.98. Did not get any warnings during install that it requires jQuerySelectize. It is listed in the dependencies of the InputfieldStreetAddress module, though. Then, of course, I got a JS error because selectize is not available. When I click on the JquerySelectize module link in the InputfieldStreetAddress module info section it says 'Session: unknown module' So maybe that module was part of the core before? Anyways, after installing the JquerySelectize module from the modules directory, everything is working fine. However, it would be nice to get a warning on install and on the module page if the selectize module is not yet installed. -
Mask page edit URL to custom profile edit page
gebeer replied to gebeer's topic in Module/Plugin Development
Great idea, thank you @bernhard I tried your solution, added a new child page under Admin with name 'my-profile' and assigned the ProcessUser process. When I go to that URL, I get a list of users. When I click on one of the users' name, I get to an URL like .../my-profile/edit/?id=1020 and am on the user edit screen. I need to avoid the first step and go right to the second while still having only '.../my-profile' in the address bar, without the edit/?id=xxx. But your hook is a great way of securing my current setup! Another thing I tried some time ago: In my custom user dashboard which is a process module, I have a method public function ___executeMyprofile() { $processUser = $this->modules->get('ProcessUser'); return $processUser->executeEdit(); } But this never worked because there are some wired in redirects in place, that always redirect to the .../access/users/edit/?id=xxx URL. At that time I even opened a thread on this topic which was never resolved. -
Mask page edit URL to custom profile edit page
gebeer replied to gebeer's topic in Module/Plugin Development
Thank you @Robin S for looking into this. My question was: how can I make a user edit screen under a URL like '/adminurl/access/users/edit/?id=1377' available under a URL like '/adminurl/myprofile/'. So that all user edit URLs with different user ids are routed to that 'myprofile' URL and the users that edit their user pages (which are their profiles in my case) never sees the actual user id and cannot try to mess with it. Thus I chose the term 'mask' in the thread title. Maybe the way I explained it was confusing or not clear. I am not using the default user template but my own user template. User pages live under their own parent (https://processwire.com/blog/posts/processwire-core-updates-2.5.14/#multiple-templates-or-parents-for-users) Users can edit their pages via the page edit process. This is working fine. I just need to change (mask) the URL for that process. The 2 ways that I can think of for approaching this: make the user edit process available under a custom process module which resolves to '/adminurl/myprofile/' have some htaccess rewrite magic in place I'd prefer number 1, as I cannot easily adjust the htaccess rules so that they only kick in for the custom user type and not for all ''/adminurl/access/users/edit/?id=1377' type of URLs. Hope this clears things up a bit ? -
Hello @apeisa, thank you for this module. I use it on many sites. Now I have a client site where the homepage in the default language has a url segment 'de'. In the LanguageSupportPageNames module I have the setting active to redirect the default language pages to that url segment. So the homepage URL in the default language reads 'mydomain.de/de/'. In my opinion this setup does not make a lot of sense but the client insisted, so what can I do.... Now when I add a redirect like '/wer-wir-sind' (which is an old URL from the pre-PW site), the module does not kick in because the LanguageSupportPageNames module adds the 'de' to the URL. Now I end up with a URL like ''mydomain.de/de/wer-wir-sind'. The redirects module cannot find that URL and won't redirect. As a workaround, the administrator could enter redirects for the default language in the format '/de/wer-wir-sind'. Now redirects work but from a logical point of view this doesn't make sense. Because we want to redirect from' mydomain.de/wer-wir-sind' to a chosen URL and not from 'mydomain.de/de/wer-wir-sind'. To make a long story short: I added some code to the checkRedirects method of the module right after line 247, which caters for this special use case: // if homepage in default language has a language segment and the root URL is redirecting to that language segment, // remove the segment from the url so it can be found in the DB if( $this->wire('modules')->isInstalled('LanguageSupportPageNames') && $this->wire('modules')->getModule('LanguageSupportPageNames')->useHomeSegment && $this->wire('user')->get('language')->isDefault() ) { $homeSegment = '/' . $this->wire('pages')->get(1)->name; if (substr($url, 0, strlen($homeSegment)) == $homeSegment) { // remove the language segment from $url so it can be found in the DB $url = substr($url, strlen($homeSegment)); } } If you think it should be implemented into your module, let me know and I'll make a PR on github. Cheers
-
Hello, I have a user page template with many fields that are organised in tabs. Tabs do not work on the profile edit screen. So I had to find a way how to let users edit their page with tabs in place. The way I solved this is having users edit their user page in the backend instead of their profile page. So basically they are on a page edit screen and not on their profile edit screen which is a different process. The drawback of this method is that the users edit their profile on a URL like .../youradminurl/access/users/edit/?id=1377. So I needed to make sure that users cannot edit other users' profiles by just switching out the id. I did this through hooks that redirect them to their own profile. This is far from a perfect solution. Ideally I would like to mask the page edit url to something like /myprofile but haven't found a way on how to do this, yet. How would you go about this? redirect rules in .htaccess hooking into the profile edit process? Either way I couldn't figure out how to accomplish it. Any pointers towards a solution would be very much appreciated.
-
Building a reusable function to generate responsive images
gebeer replied to MoritzLost's topic in Tutorials
Very nice writeup. Thank you for sharing! There are so many different approaches to handling responsive images and it is great to see how others do it. Would love to see more approaches from others here, too. To get the concept of responsive images, I read the anatomy of responsive images which explains them very well. Then I used to implement a quite similar approach to @MoritzLost for some time utilizing the MarkupSrcset module and also my own functions. Until I stumbled upon an article about creating responsive images which shows an approach that I now prefer. In this approach you go through all your different images in the finished layout and determine their exact respective size at your breakpoints. Then you build srcset and sizes attributes for those exact values. So there is no more approximation using scaling factors. You get exactly the amount of images at the sizes you need them. I pass an array with the breakpoints and the required sizes for that breakpoint and build srcset and sizes from that array. Here's the code: /** * Builds responsive img tag with srcset and sizes attributes * @param \Processwire\Pageimage $img * @param array $breakpointsizes array of associative arrays that describe media min breakpoints and width/height of images from the respective * breakpoint to the next * Example: * $breakpointSizes = [ * ['bp' => 320, 'sz' => [500, 0]], * ['bp' => 576, 'sz' => [992, 0]], * ['bp' => 992, 'sz' => [690, 0]] * ['bp' => 1200, 'sz' => [835, 0]] * ]; * @return string */ function renderImageResponsive($img, $breakpointSizes) { $imgSrc = $img->url; // use original image as fallback src $alt = ($img->description) ? $img->description : $img->page->title; // if no description use page title // construct sizes attribute $sizes = array(); foreach(array_reverse($breakpointSizes) as $bs) { $sizes[] = "(min-width:{$bs['bp']}px) {$bs['sz'][0]}px"; } $sizes = implode(', ', $sizes) . ', 100vw'; // construct srcset attribute $srcSet = array(); foreach($breakpointSizes as $bs) { $srcSet[] = $img->size($bs['sz'][0], $bs['sz'][1])->url . " {$bs['sz'][0]}w"; } $srcSet = implode(', ', $srcSet); return "<img class='img-fluid' src='{$imgSrc}' srcset='{$srcSet}' sizes='{$sizes}' alt='{$alt}'>"; } Obviously it does not account for Retina which needs to be added. I will also extend my function to add support for other attributes like you showed it. That is a great idea. -
@thomasaull Great that you are converting this into a module. It would be a muc better fit. That way we can add api funtionality to any site easily. Actually, I was thinking about converting your site profile to a module, too ?
-
Hallo, I wanted to test this site profile and cloned PW 3.0.98 from git. Then cloned the site profile repo and installed PW without any issues. I issued the 2 composer commands to install dependencies. Environment: Apache with PHP 7.0.29 FPM/FastCGI. When I try to access api/test, I get the following error Looks like a namespace issue. I didn't change namespaces on any of the files included in the profile. My config.php is not namespaced. Does anyone have an idea how I can overcome this? EDIT: apache_request headers became available under FastCGI since 5.4.0 according to http://php.net/manual/en/function.apache-request-headers.php EDIT2: After some more investigation I found https://bugs.php.net/bug.php?id=70025. So it seems apache_request_headers is still not supported in PHP 7.0 FPM/CGI environment. I added templates/inc/functions.php with contents of https://gist.github.com/rmpel/11583cfddfcc9705578428e3a2ee3dc1 and added require "{$config->paths->templates}inc/functions.php"; to api.php This solved the problem :)-
-
I ran into a similar issue with v1.1.0. using Javascript Loading method: Load file to $config->scripts emo.min.js is included on the page before the <!-- emo --> script block which defines var emo_addr. The function emo_replace() never gets called because at the point of script inclusion emo_addr === undefined. In v1.5 of emo.js window.onload was removed. So the script never executes when emo.min.js is included before the <!-- emo --> script block. I have refactored emo.js as an object literal and modified the module Code so that the script block calls emo.init(emo_addr) after defining the addresses. Tested without problems. Modified module can be found at https://github.com/gebeer/EmailObfuscation/tree/dev @Roope do you want a PR for that?
-
I've been following the discussion about language translation for this module. It is convenient to edit the language specific texts on the module settings page. But if they were implemented as i18n language translation strings, I guess all those problems would be solved. I personally wouldn't mind to edit those under Settings->Languages as long as there is a hint on the module settings page.
-
Hello, I just installed this module on PW 2.7.2. On the module settings page I get an error "Call to a member function render() on a non-object" from line 78 of CookieManagementBanner.module. $this->wire('files') is null. If I replace line 78 with the following, everything works ok. $cookieBanner = wireRenderFile($this->wire('config')->paths->$this.'wrapper.tpl.php', array('module' => $this, 'lang' => $lang)); Seems like wire('files') is not available in 2.7.2 which is strange. Can anyone confirm this?
-
Anyone interested in the module with added region option and with added o:deliverytime option can use my fork at https://github.com/gebeer/WireMailMailgun
-
@cb2004 attached is an amended version of the module and module config. I added a setting for the region and the API URL will adjust accordingly. WireMailMailgunConfig.php WireMailMailgun.module
-
Could you please share a link to the mailgun docs where this is mentioned. Thank you. EDIT: Never mind. I found it: https://documentation.mailgun.com/en/latest/api-intro.html#mailgun-regions
-
From the API side it is still valid and working code. I don't think there is one best way to go. This tutorial shows one possible approach. There are many different other approaches possible. But at least it shows the basics of implementing a REST API. You can also have a look at https://modules.processwire.com/modules/rest-api-profile/ which is the most recent approach I'm aware of.
-
@Peter Knight What do you want to do with products that do not have images? In your foreach you define the $image variable only when there are images. Then you echo the images even if there are none. This will give you a PHP notice for $image is undefined. You'd need another if condition within your echo to check for isset($image) and only output the image if there is one. The way you setup your images field it should definitely return an empty array if there are no images so the if (count($prod->images)) should work as expected.
-
This is an option only for visitors with JS enabled. I decided to copy the module to site/modules and extend it there. Though it would be really nice if we could extend the comments form with hooks.
-
Hello, I need to add a checkbox to the comments form to make it GDPR compliant and I guess I'm not the only one... Doing a search and looking at the FieldTypeComments module file it seems that the only way to add custom fields to the form is by copying the module to site/modules and apply the changes there. I am just wondering why the comment form is not driven by the PW form API and also why none of the methods in that module are hookable? Would be much appreciated if you could share your approaches on handling this.
-
Is it possible to hook into message render function
gebeer replied to Juergen's topic in General Support
don't think so since the error method is not hookable nor is any other method in that class that would give you access to what you need. -
Is it possible to hook into message render function
gebeer replied to Juergen's topic in General Support
If you don't want to change the core Inputfield.php that @PWaddict points to, you can copy the whole Inputfield module folder to site/modules and apply your changes there. When you then refresh the modules in the backend PW will ask you from which location the module should be loaded. -
Have you tried <?php // get all pages in page field sorted by manual sort order $resultsAllSorted = $page->my_page_field->sort('sort'); // filter $resultsCategory = $resultsAllSorted->filter('category=1474'); // loop foreach($resultsCategory as $result) { // ... } ?
-
@Fantomas Thank you for letting me know. I had tried the second notation that you mentioned with exactly the same code I put in Rest.php. But on my server environment this wouldn't work. Because HTTP_AUTHORIZATION was always empty. I never tried REDIRECT_HTTP_AUTHORIZATION. It did not occur to me since in the .htaccess rewrite rule it defines HTTP_AUTHORIZATION. So you pointed me to the final piece of the puzzle. Thanks again for that. I now can implement this in a way that it will properly work in most server environments.
-
@uliverse You can still use the Leaflet module and read through this thread from the link I recommended in my last post. Then have a look at how BrendonKoz and patman solved it in their forks. Seems like they have a readily available solution.
-
This module is meant to give a lt/lng position of an address so we can display a marker on a map. It is not an address field type. When you set the marker on the page that you edit, it will get the address for the lat/lng that you have set in the GUI by reverse geocoding it through the Google geocoding API. This returns the long address string that you can get in your template with $page->mylocationfieldname->address. To answer your question, there are ways to get a properly formatted address but all of them involve some work: 1. extend the module yourself to store address parts. Or read posts in this thread from here on and than use @BrendonKoz or @patman forks: 2. add fields to your template for postcode, street address, city, country. Fill them manually when you edit the page. Then you can render them in your templates. This should be the easiest way. 3. switch to the Map Marker Module which uses Google Maps and read from this post on where @adrian has extended the functionality to give you exactly what you want: