-
Posts
192 -
Joined
-
Last visited
Everything posted by Torsten Baldes
-
Send email with changes when user profile is changed
Torsten Baldes replied to Torsten Baldes's topic in API & Templates
Thanks for your help! For now I ended up with something like this: wire('user')->setTrackChanges(Wire::trackChangesOn | Wire::trackChangesValues); wire()->addHookAfter("Pages::saved", null, function($event){ $user = $event->arguments(0); if($user->template->name == 'user'){ $userfields = $user->template->fieldgroup; $excludeFields = ['pass', 'roles', 'language', 'admin_theme', 'schedulerSkip', 'cpf_added']; $changes = $event->arguments(1); // check if there are any changes, if it's not an InputfieldFileAjax (also triggers the hook), the user changed his own profile, if the changed user is not a superuser (could be any other role to exclude) if(count($changes) && !wire('input')->get->InputfieldFileAjax && wire('user')->id == $user->id && !$user->hasRole('superuser')){ $userfieldsArray = array(); foreach($userfields as $userfield){ $userfieldsArray[] = $userfield->name; } //remove unwanted fields $changes = array_diff($changes, $excludeFields); // order changed fields like template $changesSorted = array(); foreach ($userfieldsArray as $item) { if(in_array($item, $changes)){ $changesSorted[] = $changes[$item]; } } $changes = $changesSorted; unset($changesSorted); // probably not necessary // get the changes in a string $changedFields = ''; foreach($changes as $change){ $changedFields .= $userfields->get($change)->label . "\r\n"; } // compose the mail $subject = "Änderung im Nutzerprofil von »".$user->u_fullname."«"; $message = "Hallo,\r\n\r\n das Nutzerprofil von ".$user->u_fullname." wurde aktualisiert.\r\nFolgende Felder haben sich geändert:\r\n\r\n" ; $message .= $changedFields; $message .= "\r\n\r\n" ; $message .= "Klicken Sie hier, um das Profil zu bearbeiten: ".trim(wire('urls')->httpRoot, '/').$user->editUrl ; $message .= "\r\n\r\n\r\n"; $mailmessage = wire('mail')->new(); $mailmessage->to('mail@domain.tld')->from($user->email); $mailmessage->subject($subject)->body($message); $sent = $mailmessage->send(); } } }); I decided that it's not necessary to send the before and after values within the email. This could even be a privacy and/or security issue. Thanks again for your ideas and help! -
Hi, I'm building a site with user profiles, where the users can change and update their profile. For different reasons it's important that the person who oversees these users get's an email, when a user updates his profile. At best with all the values that changed and their value before. I tried to hook into User::changed and this kind of works, but it get's triggered for every field, that's changed. With each trigger the list of fields also get's longer, so that only the last run contains all the changed fields. This would mean, i would send multiple emails for one profile change. Is there a way to prevent this and get all changes at once in only one hook run? This is my code so far (in ready.php): wire('user')->setTrackChanges(Wire::trackChangesOn | Wire::trackChangesValues); wire()->addHookAfter("User::changed", null, function($event){ $user = $event->object; $changes = $user->getChanges(true); // output changes as log entry wire('log')->save('testchangelog', print_r($changes, true) ); // TODO: send mail }); Thanks!
-
Most of the time other users/editors use this Field to "generate" a selection of posts/pages which are applicable for the topic of the current post. Something like "If you liked this post, then these posts could also be interesting to you".
-
Hi, I'm using the core module FieldTypeSelector (like Lister) to be able to create custom lists of pages on my pages. e.g. show me pages with template=foo, somevalue=bar and someothervalue=foobar. Is there a way to use OR groups (https://processwire.com/docs/selectors/#or-groups) with FieldTypeSelector? This way I could build a list of pages which have somevalue=bar OR someothervalue=foobar As a selector this would look like this: template=foo, (somevalue=bar), (someothervalue=foobar) Is this possible? I know I could insert this as a _custom selector, but this would kind of defeat the purpose of FieldTypeSelector. Thanks!
-
Set InputField unrequired via hook
Torsten Baldes replied to Torsten Baldes's topic in API & Templates
Hi bernhart ;-), thanks, that did the trick! Here's my code, if someone also needs to do this: wire()->addHookAfter('ProcessPageEdit::buildForm', function (HookEvent $e) { // skip the whole thing and return, if the user has not the proper role if (!wire('user')->hasRole('superuser') && !wire('user')->hasRole('useradmin')) return; $form = $e->return; $boxes = ['privacy', 'consent']; foreach ($boxes as $box) { $boxfield = $form->getChildByName($box); if($boxfield){ $boxfield->required = false; } } }); -
Hi, I have a website with some users and admins who create and administrate these users. In their user profile is a checkbox which is set to required. When the admins create or edit an user they have to check this checkbox to be able to publish this user. But this checkbox should only be checked by the user itself. So I want to set this checkbox to "unrequired" when a user with a certain role is editing this profile. I tried to do this with the following hook (check for role not yet included), but I can't get it to work. wire()->addHookBefore('InputfieldCheckbox::render', function (HookEvent $event) { if ($event->object->name != 'consent') return; $field = $event->object; $field->required = false; $field->set('required', 0); }); It catches the right field but it doesn't set the field to unrequired. Is this hook too late in the chain or do I have to do this with another property or method? Thanks!
-
Use Processwire (ImageSizer) as image resizing service
Torsten Baldes replied to Torsten Baldes's topic in General Support
Whooohaaa! Thanks! That was more then I expected! I will give it a try. -
Use Processwire (ImageSizer) as image resizing service
Torsten Baldes replied to Torsten Baldes's topic in General Support
Thanks, but I don't want to / can't use an external service and PW can already do all the resizing and cropping stuff. I just want access to these features outside from the template context. -
Hi, I'm building a small REST-API for my ProcessWire website to use the content outside in other apps. There are a lot of images and the apps will run on many different systems (mobile phones, tablets with iOS and android). To have the ability to always request the optimal image for each device width and screen density, I don't want to generate a fixed set of image sizes. Instead, it would be nice to request the resized image on the fly by sending the URL of the image with some parameters (width, height, crop) to the server and get my resized and cached image back. Similar to scripts like Timthumb or phpThumb, but with all the nice additions (e.g. focus point) from ProcessWire. The URL could look like this: https://mydomain.tld/resize/?url=/site/assets/files/1125/profile-image.jpg&width=1200&height=1200&crop=1 The response of this would be the image itself, resized to a square image, 1200x1200px How would I approach this? Is there something like this already available? Thanks!
-
@thomasaull Thanks for this module! It seems to be a great starting point for building an API. I have 2 questions: 1. How would you approach a multilanguage API? My idea would be to add a query param to the api call (e.g. /api/posts/?lang=fr ) and switch the user language before getting the field values. Is there another/better solution? 2. I don't need it right now, but how would I implement a session authentification when accessing the api? Thanks!
-
Thanks for all your suggestions! I thought it would be possible with just one query. Connect Page Fields seems like a good choice here (because I have no idea, how I would use RockFinder with the GraphQL module ? ) Thanks!
-
Hi, I'm new to GraphQl, try to wrap my head around it and I couldn't find it in the docs or here in the forum. So here's my question: Is there a way to "reverse" find and list pages which reference a page? For example, I want to get a list of speakers with all the needed fields (name etc.) and their talks at conferences. The problem is, that I don't link the conferences on the speaker template, but reference the speakers on the conference template. { speaker { list { u_name u_forename u_vita } } } How can I output the conferences for every speaker, when I'm querying the speakers? Is this possible? Thanks!
-
Hi, I'm building a site where users can edit and update their user profile in the admin area but are not allowed to see/edit any other part of the admin (e.g. pages). (Note: These profiles have a different template and a different parent than the normal users. see: https://processwire.com/blog/posts/processwire-core-updates-2.5.14/#multiple-templates-or-parents-for-users) In these profiles, I want to use multilanguage fields. But if a user only has profile-edit permission, he can't save these fields. To do this, he needs page-edit and page-edit-lang permissions. These permissions also let him see the page tree, which he shouldn't see. Is there any way to have multilanguage fields in a profile without page-edit-permissions? Single language fields work fine and without issues. Thanks!
-
sorry, my mistake …
-
Hi, I have a multilanguage (en, de) ProcessWire 3.0.111 installation and when I copy a page, only the second language in text fields (text & textarea) gets copied. The default language is always blank on the new page and in all repeaters on this page. I tried to recreate this issue on a fresh installation, but with no luck. There it worked like it should. What can I do to track down this error and fix it? Thanks!
-
@renobird Is there a way to purge the activity log? I tried removing and readding templates, but the older log entries were still there. Thanks!
-
repost of my comment from the blogpost: Great additions! Thank you! One question for $page->references(): If a page is referenced from a repeater or similar fields, does it return the repeater page or the the „for page“ (the page where the repeater is used)? Thanks!
-
Module: ImageMarker Fieldtype & Inputfield
Torsten Baldes replied to kongondo's topic in Modules/Plugins
Thanks! I did just that. I changed the col types for x & y in the DB from int(11) to decimal(5,2) and replaced the (int) with (float) for x & y in the module files. I also modified the js to output float values. Seems to work! -
Module: ImageMarker Fieldtype & Inputfield
Torsten Baldes replied to kongondo's topic in Modules/Plugins
Thanks for this module! I plan to use it for a map with quite a bunch of pins. For some pins the limitation to only have integer percentage values is too strict and they get placed slightly shifted from the original position? Is there a way to have float/decimal values for the coordinates? e.g. 35.75 Thanks! -
PW 3.0.12: Support for extended (UTF8) page names/URLs
Torsten Baldes replied to ryan's topic in News & Announcements
Is there any new development regarding the chinese characters? Thanks! -
@adrian Sorry I just saw this. If it breaks something revert it. Seems to work for me.
-
Hi, I'm using LoginRegister and SessionLoginThrottle (core module). If a user tries to login with wrong credentials SessionLoginThrottle steps in and prevents a brute force attack. This works fine for the backend login. When someone tries this on the frontend, it produces an exception with an "Internal server error" message. Is there a way to output the same messages from the backend also on the frontend or catch this error and show some other hint to the user? Thanks!
-
thanks for your suggestion. unfortunately "admin_city1" has also no access to users with "admin_city2". so it doesn't matter if I change the order.
-
Hi, I'm using IftRunner (https://github.com/ryancramerdesign/IftRunner) to update/change the roles of a user based on a selection in the user profile. Example: The field "location" has multiple cities (city1,city2,city3) and when the user changes this field from "city1" to "city2", he should get the role "admin_city2", which can access and edit users with the role "usergroup_city2". Unfortunately the api call "addRole" seems to check, if the current user has the permissions to assign this role. Since he has only the role "admin_city1", he can't change his role to "admin_city2". Is there a way to "force" the api to do this, even when the current user doesn't have the permissions? Thanks!