-
Posts
1,554 -
Joined
-
Last visited
-
Days Won
48
Everything posted by gebeer
-
Using config data for the module elsewhere
gebeer replied to gornycreative's topic in Module/Plugin Development
just to make sure, did you copy/paste this from your code? There is a typo "Imput", note the "m". It should read "getModuleConfigInputfields" To retrieve module config data from anywhere you can also use https://processwire.com/api/ref/modules/get-config/ -
Here you are referring to ProcessModules. These provide custom pages in the admin. For an example see https://processwire.com/modules/process-hello/ and I also can strongly recommend the excellent blog post about ProcessModules linked by @BillH This is correct. You can read all about module configuration at https://processwire.com/blog/posts/new-module-configuration-options/ with examples both for the "old" and "new" way to implement your custom configuration fields. There is no settings button on the module's detail page. Once you have implemented input fields for module configuration, they will appear underneat the module information. All configurable modules are also listed in the admin menu under Modules->Configure When you are new to module development, the available classes can be quite confusing. But once you try and build a module yourself everything will get clearer. If you want to build custom pages in the admin, use a process module (https://processwire.com/modules/process-hello/). If you want to add general functionality, use a "normal" module (https://processwire.com/modules/helloworld/). This is because the API docs are auto-generated from the PW code. Since ConfigurableModule is an interface and not a class, the documentation for it is not being picked up by the script that generates the docs. But you have the path to the file in the core that defines the interface and there you have extensive documentation https://github.com/processwire/processwire/blob/master/wire/core/ConfigurableModule.php
-
Great that this is working for you. Please share your additions to make it work with pageFileSecure. I never used that but would be interested in seeing how you implemented it.
-
DOn't think this will make a big difference. Browsers will still handle it inconsistently.
-
Support for config-localhost.php file (or similar)
gebeer replied to Lance O.'s topic in Wishlist & Roadmap
There is no built-in way ATM. But you can find some nice implementations here: -
To get more control over what happens in the user's browser, you can output your PDFs through a specific template file. Example implementation: Create a new template "pdf", in the URLs tab allow URL Segments Create a hidden page named "pdf" under home with that template. URL for that page will be: "/pdf/" Change text links for the PDFs to a format like "/pdf/{$pageId}/name-of-pdf-file.pdf" Sample code to create text links: /** @var Page $page page that the PDF file lives on */ /** @var Page $pdfPage page that ouputs the PDF file */ $pdfPage = $pages->get('template=pdf'); /** @var PageFile $pageFile object that holds the PDF */ $link = $pdfPage . $page->id . '/' . $pageFile->basename; // example result: /pdf/1234/name-of-pdf-file.pdf Now in site/templates/pdf.php you can use URL segments logic to retrieve and output the pdf if ($input->urlSegment1 && $input->urlSegment2) { $pageId = $sanitizer->int($input->urlSegment1); $baseName = $sanitizer->filename($input->urlSegment2); /** @var PageFile $pageFile object that holds the PDF */ $pageFile = $pages->get($pageId)->file_field->getFile($baseName); if ($pageFile) { $filePath = $pageFile->filename; // see https://processwire.com/api/ref/wire-file-tools/send/ for more options /** @var Files $files PW Files API */ if($filePath) $files->send($filePath, array('forceDownload' => false)); } } Instead of sending the file directly to the browser, in pdf.php you could implement https://pdfobject.com/ to embed it for every browser
-
What code are you using to display the PDF / send the PDF to the browser, are you using $files->send()? With that method you have control over the headers. Firefox uses Mozilla's PDF.js for PDF display. If you want to have a consistent display of PDFs across browsers you might want to consider implementing it on your site. This might of interest: And this: https://pdfobject.com/
-
You can use the User::changed hook to do what you want (see https://processwire.com/api/ref/wire/changed/). Put this in site/ready.php: $wire->addHookAfter('User::changed', function ($event) { if($event->arguments(0) === 'pass') { $user = $event->object; $this->wire->log->save('password-changes', "User $user->name has changed their password"); } }); Now everytime a user changes their password, it will be logged to Setup->logs->password-changes. You can do similar thing with roles if($event->arguments(0) === 'roles') { $user = $event->object; $oldRoles = $event->arguments(1); $newRoles = $event->arguments(2); // code to compare $oldRoles/$newRoles // write to log } If you want to have that information in the session log, just do $this->wire->log->save('session',...)
- 1 reply
-
- 7
-
-
I don't know where your input comes from. I would take care at the source that there is no broken HTML in the first place. I already provided some sample code how you can do this above
-
If you are building the formData object like you do it, you have to take care about url encoding yourself. Only if you pass in the form when building formData, encoding is taken care of. Have a look at https://processwire.com/api/ref/sanitizer/ and try different methods. But I'm afraid that the sanitizer methods that handle HTML tags will always run into problems when there is broken HTML. So you should take care in the first place that HTML is not broken if possible.
-
@fruid can you confirm that your data is urlencoded? You might want to have a read over at MDN https://developer.mozilla.org/en-US/docs/Learn/Forms/Sending_forms_through_JavaScript . Especially the part where they are using encodeURIComponent() to encode the data. What do you mean by broken HTML. Do you have an example? Passing an email, do you mean the HTML or text content of an email or an email address? In your code you are taking all form fields, putting them into an object, then converting that object into a JSON string and assign that string to a property 'content' of a formData object and send that object via XHR. To me it looks like what you actually want to do is send JSON data to the server. If this is the case, you could omit the step of assigning your JSON string to a formData object and use request header content-type 'application/json' instead. No need for url encoding the data then. Simplified example: // create an object const content = { formfield1: 'value', formfield2: 'value' } // open request xhr.open('POST', 'yourURL') // set Content-Type header xhr.setRequestHeader('Content-Type', 'application/json') // send rquest with JSON payload xhr.send(JSON.stringify(content)) On the PHP side where you receive the request, you can get the JSON data like this: // Takes raw data from the request $json = file_get_contents('php://input'); // Converts it into a PHP object $data = json_decode($json);
-
Module Concept for Error Reporting via Email
gebeer replied to gebeer's topic in Module/Plugin Development
Good find, thank you. By default PW only logs errors, exceptions, not warnings or notices. So the available types would be "error" and "exceptions". Is there a way of telling PW to also log warnings and notices? -
@kongondo I have a MM field "icons", allowed media types images. When adding an image via "Add Image", the MM modal pops up and shows all files of type image. I'd like to automatically apply a filter (profile) so that only images with tag 'icon' and extension svg are being listed. Otherwise editors have to manually choose a filter each time. "Add Image" issues a request which contains a property "filters". But in the field settings I don't see how I could configure which filters to apply. Is this scenario possible at all?
-
Hello all, I'm working on a concept for a module that sends error reports via email to different recipients based on different error levels (notice, warning, error) and I don't know yet how to best tackle this. It would be preferable if I could use PW internal classes, functions. I had a read through https://processwire.com/blog/posts/debugging-tools-built-in/ and especially the logging section. But looking at related classes like FileLog and WireException, it doen't seem like one can hook into them. I'm quite tempted to use NetteTracy, like TracyDebugger does. It seems like it can do what I want https://tracy.nette.org/en/guide#toc-production-mode-and-error-logging. PW is writing errors/exceptions to the log, I just wouldn't know how to tap into this, especially for different log levels. If anyone can point me in the right direction it would be much appreciated.
-
I changed my code to use wireInstanceOf(). Works like a charm. Today another problem surfaced. The MM Settings do not get saved when the core module PagePaths is installed. Located the cause in ProcessMediaManager.module L156 $mediaManagerSettings = $this->wire('pages')->get("template=media-manager-settings, parent={$path},include=hidden")->media_manager_settings; When PagePaths is not installed, the selector returns the page under Admin->Media Manager->Media Manger:Settings just fine. But with PagePaths installed it returns a NullPage. I found that with PagePaths installed page paths change to also include the language name, but not consistently. My install sets the home URL for the default language to "mydomain.com/en/". The paths that are returned look like $pages->get('template=media-manager-settings')->path // "/en/processwire/media-manager/media-manager--settings/" (note the '/en/' at the beginning). $pages->get('name=media-manager')->path // "/processwire/media-manager/" $config->urls->admin // "/processwire/" There is the inconsistency. Pages with template admin do not have the language prepended while pages with other templates do. Guess this implementation makes sense. When I remove "parent={$path}" from the selector, it works with PagePaths installed. I implemented a quickfix like this /******** - MEDIA MANAGER SETTINGS - *******/ $path = $config->urls->admin . 'media-manager/'; $selector = "template=media-manager-settings, status<" . Page::statusTrash; if(!$this->wire('modules')->isInstalled('PagePaths')) $selector .= ", parent={$path}"; $mediaManagerSettings = $this->wire('pages')->get($selector)->media_manager_settings; I left out the "include=hidden" since $pages->get() returns hidden pages by default. Is "parent={$path}" needed at all, can there be situations where multiple pages with template media-manager-settings are present in the system? Maybe in the Trash. So I handled that situation. Please let me know what you think. Thank you.
-
Sorry to say that this error still occurs in my multilang install using PW 3.0.200 on PHP 7.4 both outside and inside repeaters. Required option set either in field or template context yields the same result. Problem seems to be with the isEmpty() method in InputfieldMediaManager.module. Specifcally with get_class($value) == 'MediaManagerArray'. In my install get_class($value) returns 'ProcessWire\MediamanagerArray'. If I replace the check with if(is_object($value) && $value instanceof MediaManagerArray && count($value)) $empty = false; the error is gone.
-
@kongondo Referring to your post in Media Manager thread, do you think that JqueryFileupload will receive further updates? Just asking so I can decide whether I should fork it and potentially make PRs.
-
Hi @kongondo and many thanks for this great module. I just installed it on PW 3.0.200 / PHP 7.4 and encountered an issue with uploads of SVG, be it from the MM Upload section or the mm field that I created for type images. FileValidatorSvgSanitizer is also installed. There is a PHP Warning related to JqueryFileuploads module Problem is the getImagesize($imageFile) call which returns false for SVG images. I scanned the JqueryFileuploads thread for posts related to SVG and found none. Wondering if I'm the first one encounterng this. Maybe because it is "just" a Warning and not and Error. I have set Tracy Debugger to strict mode in all of my projects. On https://www.php.net/manual/en/function.getimagesize.php they explicitly say not to use getimagesize for detecting mime size and recommend https://www.php.net/manual/en/function.finfo-file.php instead. Is it possible to make the option allowedImageMimeTypes configurable through module settings or to hardcode image/svg+xml as allowed image mime type into the module? This would make it easier to do mime type validation for svg with finfo_file(). Something like // if (function_exists('exif_imagetype')) { ... } elseif (function_exists('finfo_file')) { $finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension if (in_array(finfo_file($finfo, $imageFile), $allowedImageMimeTypes)) $isValidImage = true; } // ... Or https://www.php.net/manual/en/function.mime-content-type.php is also an option. Feel free to move this to the JqueryFileuploads thread.
-
You could use it with your RockFrontend UIKit setup because that is based on LESS. But you would have to introduce npm based packages into RockFrontend Unfortunately, they don't provide a pure CSS version of RFS. So I can't integrate it with RockFrontendTailwind since that purposefully uses pure CSS in a PostCSS based build pipeline. Thank you for the links. How would a living Tailwind implementation look like, defining the calculated poly fluid sized font sizes in tailwind.config.js? I like that pure CSS approach. Well thought out. Personally, I also base font sizes, paddings and margins on rem in most cases.
-
I don't think there is a pure CSS solution for this. You might want to have a look at https://github.com/rikschennink/fitty. Used it in a project and is working great.
-
Hi there, I am looking for a module that can handle revision scenarios. Usecase: User role foo can edit content. After content changes user role bar needs to approve the edit before it goes live. It is important that changes to already published pages can be handled, too. For new, unpublished pages the PW permission system can do that. But other CMSs like TYPO3 or WordPress can handle multiple content versions and revisions. Hope that something like this exists for PW, too. I found @teppo's https://processwire.com/modules/version-control/ which likely will be needed as prerequisite to handle edits of existing pages that are already published. But couldn't find any revision related modules. EDIT: found a pro module that sounds like it can do what I need: https://processwire.com/talk/store/category/11-prodrafts/
-
@teppo can this module handle multilang fields? Couln't find anything in the module description or this thread.
-
Can't confirm that. But one more thing you could try is to extend Page and not RepeaterPage. Just a wild guess but maybe it helps.
-
The file name and class name are important here. Otherwise PW doesn't know which pages to apply the custom class to. The file name is derived from the template name. See here https://processwire.com/blog/posts/pw-3.0.152/#a-more-practical-example Now you need to find out what the name of the template is, that your repeater pages use behind the scenes. Usually the template name for repeater pages is "repeater_" + fieldname. So if your repeater field is named "my_repeater", the template name would be "repeater_my_repeater". You can look up the template name under Sytem->templates Filters->Show System Templates. Following all that logic in my example, the file name should be Repeater_my_repeaterPage.php and the class name Repeater_my_repeaterPage. I haven't tried this out and I'm not 100% sure about the naming because of the underscores. But in the documentation it isn't mentioned that underscores are converted to CamelCase. So theoretically it should work. Also make sure that custom page classes are enabled in config.php with $config->usePageClasses = true; EDIT: I just saw in https://github.com/processwire/processwire/blob/3acd7709c1cfc1817579db00c2f608235bdfb1e7/wire/core/Templates.php#L853 that underscores are converted to CamelCase, too. So in my example class name would be RepeaterMyRepeaterPage and file name RepeaterMyRepeaterPage.php
-
Hello all, I have released RockFrontendTailwind, an extension module for RockFrontend. It extends Bernhard's module and adds an installation profile for site development with Tailwind CSS. Obviously RockFrontend is a required dependency for my module to work. This module aims to give you a quick start with a Tailwind based project. What RockFrontendTailwind does: A folder "rockfrontendtailwind" will be installed in site/templates. That folder contains all the configuration files needed to get you started with a webpack-based build pipeline for JS and CSS with webpack tailwindcss postcss with postcss-preset-env (for autoprefixing) babel (for transpiling) So rather than just building the CSS with Tailwind, the build pipeline also takes care of transpiling your Javascript based on configuration in a .browserslist file. Of course, the setup is opinionated. But people who are comfortable working with webpack can easily adjust / extend the configuration to their liking. The default configuration watches your JS and CSS files and compiles them into site/templates/assets main.css and main.js by default. All paths are configurable through a .env file. Live reloading during development is not part of the webpack configuration since this is handled by RockFrontend already in a very efficient way. Also a _main.php file including a very basic boilerplate for a typical setup will be placed insite/templates. It includes examples on how to render your JS and CSS assets. More detailed instructions over at github. Adding new profiles to RockFrontend through your own modules is quite straight forward thanks to the clear structure in @bernhard's module. RockFrontendTailwind can serve as a boilerplate. The only important thing is that the "profiles" folder structure remains the same. The module is currently in beta but runs very stable. It will eventually be released as an official module in the directory soon. If you want to give it a shot, I shall be happy to hear your feedback. If you are looking for a standalone webpack build pipeline with webpack-dev-server, you might want to have a look at https://github.com/gebeer/tailwind-css-webpack-processwire-starter Happy Coding!
- 3 replies
-
- 11
-
-