Jump to content

gebeer

Members
  • Posts

    1,559
  • Joined

  • Last visited

  • Days Won

    49

Everything posted by gebeer

  1. Your textformatter seems like a valid solution. Although I am not sure whether the regex for getting the file URL is 100% reliable. I'm not a regex prof. But in general it is not a good idea to rely on regex for parsing HTML. You could use PHP's SimpleXML to parse and replace the href attributes. Adapt something like this: https://stackoverflow.com/questions/27326066/simplexml-php-change-value-from-any-node But I think you don't even need a textformatter for the task. A simple hook will intercept all URLs to PDF files and return the desired URL under /downloads/. Place this in site/init.php <?php namespace ProcessWire; // intercepts all file URLs and rturns URLs in desired format. wire()->addHookAfter('Pagefile::url', function(HookEvent $event) { /** @var PageFile $pageFile */ $pageFile = $event->object; if(strtolower($pageFile->ext) === 'pdf') { $pageId = $event->page->id; $event->return = '/download/' . $pageId . '/' . $pageFile->basename; } }); Now all URLs to PDF files will have the desired format. Even when you add a link to a file inside CKE editor, the desired URL will inserted.
  2. Hello and welcome to the forum! Please try to post in English if possible. Thank you. Is your code inside a function? If not, you need to echo json_encode($res) return json_encode ($res); // inside function echo json_encode ($res); // not inside function Do you see the output from var_dump() in the response in browser dev console?
  3. You are writing that you want to sort results by artist. But in your sort selector you try to sort by help_roles. Is it help_roles, you want to sort by? Or is it that you want to filter results by help_role "artist"? Please clarify.
  4. If I understand correctly, you want to publish all draft versions of pages with a single click? For drafts you are using ProDrafts module? You might want to ask Pro module related questions in the dedicated VIP support forum.
  5. Hello and welcome to the forum! In PW you can override core modules by copying them from wire/modules to site/modules. If you have multiple copies of a module installed, you can go to Modules->Configure->AdminThemeUikit and choose there which copy to use. If you don't have this choice in the Module Edit Screen, follow these instructions: Copy wire/modules/AdminTheme/AdminThemeUikit to site/modules/AdminThemeUikit and then in the backend main menu do a Modules->Refresh, you will get a notification that AdminThemeUikit has multiple files installed in different locations and it lets you choose which file location to load the module from. You can do this and choose the files in wire/modules/AdminTheme/AdminThemeUikit. After that you can delete the site/modules/AdminThemeUikit folder and the warning should be gone.
  6. 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/
  7. 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
  8. 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.
  9. DOn't think this will make a big difference. Browsers will still handle it inconsistently.
  10. There is no built-in way ATM. But you can find some nice implementations here:
  11. 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
  12. 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/
  13. 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',...)
  14. 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
  15. 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.
  16. @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);
  17. 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?
  18. @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?
  19. 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.
  20. 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.
  21. 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.
  22. @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.
  23. 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.
  24. 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.
  25. 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.
×
×
  • Create New...