cwsoft
Members-
Posts
163 -
Joined
-
Last visited
-
Days Won
3
cwsoft last won the day on November 12 2023
cwsoft had the most liked content!
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
cwsoft's Achievements
Sr. Member (5/6)
209
Reputation
-
@kongondoCool to know. So far used ddev exclusively from the bash shell, as I worked several years on Unix systems. However, I may check out this VS code Add-in with one of the next projects.
-
DDEV works great on Ubuntu in WSL2 on Windows 11. Installed VS Code in Windows with an extension to work remote on Linux too. So I do all my Web dev work in Ubuntu. Ubuntu file system shows up in Windows explorer too. This makes it easy to transfer files from Ubuntu to the WWW server using Filezilla on Windows by just using the local path to Ubuntu. Copying files from Windows to Ubuntu can easily be done via cp /mnt/c/Users/user/Downloads/file.ext . too. So WSL2 in comnination with DDEV and VS Code is really fun.
-
Hi Natalie, welcome to the PW forum. I would start setting up a local development env (like ddev) with a clean PW installation and a blank template. Then I would decide on a output strategy, like delayed output. Next I would create the HTML template using the look of your old site with some basic pages and the nav menu. Once that is done, I would try to implement one dynamic page (e.g. member login area) from your old site and see how for you get. If you hit a wall on your journey, come back in the forum and ask for guidance. The community here is very kind and can help you on your way. Thats how I started with PW. After the first implementation with just the PW API and basic concepts, I did a rewrite using some of the more advanced techniques like implementing the Latte template engine and PageClasses. But my first setup was just procedural PHP code organized in functions stored in helper files and basic PW PHP template files using the great PW API. That get‘s you started quickly, which I think is more important than trying to get the most sophisticated features implemented right from the beginning. I tend to go with release soon and iterate fast approach most of the times. Just my two cents. Cheers cwsoft
-
https://processwire.com/docs/security/admin/#preventing-dictionary-attacks For sites with simultaneous users coming from the same shared IP address, throttling by IP address may lock out legitimate users. Had this scenario with a project with about 1.000 frontend user accounts, which could sign in for courses. All get an E-Mail with their login credentials at about the same time. We had about 50-100 users from a big company using a shared IP address. Here some (5-10) of those users where blocked. So I allowed some IP ranges to not lock out legitimated users sharing the same IP address, simply to reduce the support request for my clients site operators. If this scenario doesn‘t matter for your sites, I would always turn on throttling by IP address.
-
Running latest ddev version on Windows 11 under wsl2. No slow down seen yet compared to previous versions.
-
Hi. Have you tried to add include=all or include=hidden as parameter or via the options array to the get or find API calls? See API overview for details: https://processwire.com/api/ref/pages/find/ From the API doc page: include (string): Optional inclusion mode of 'hidden', 'unpublished' or 'all'. (default=none). Typically you would specify this directly in the selector string, so the option is mainly useful if your first argument is not a string. Cheers cwsoft
-
Hook processInputFile and processInputDeleteFile
cwsoft replied to cwsoft's topic in API & Templates
@BrendonKozYes that is exactly the issue. The method processInputFile executes on both upload and deletion using the file input field. The processInputAddFile does not allow easy access to the pagefile and the other infos like page object etc. needed to unzip the files to the designated spots. Thought there might be a PW way of preventing trigger to kick in (e.g. by adding data to return value object) or to detect inside processInputFile if this was triggered from processInputDeleteFile etc. The easiest method I came up with is to set a PW session variable inside the delete hook and check for it in processInputFile to skip the extraction of the ZIP file. This works fine, but I doubt that this is the ideal way of doing it. -
Hook processInputFile and processInputDeleteFile
cwsoft replied to cwsoft's topic in API & Templates
@BrendonKozThanks for your suggestion. Basically an editor can upload a zip file with PDF participation certificates for courses from a page file field in the backend. Once the ZIP file was uploaded, the PDF files should be extracted to a folder inside site/assets/files/upload, which is protected via .htaccess from direct access. At the end of the year the extracted PDF files will be deleted by the course editor, by deleting the corresponding ZIP archive via pressing the trashcan icon of the page file field. The course attendees can download their PDF certificate after the course is finished from their course page available after frontend login. This is done by clicking a download button, which reads the binary contents of the corresponding PDF file and sends it as PDF file to the browser for download using PHP header functions. So the PDF files are not touched after upload until they get deleted at the end of the year. The PDF files should stay around until the end of the year or a predefined time period before getting deleted. So I do need two hooks. Upload of the ZIP file triggers the unzip task and the deletion of the ZIP archive should trigger the delete extracted PDF files task. Timing won‘t help, as the delete action should not trigger the unzip process again. -
Hook processInputFile and processInputDeleteFile
cwsoft replied to cwsoft's topic in API & Templates
Hi. Added a "workaround" to solve my issue by setting a session variable at the end of the processInputDelete Hook to indicate, that the ZIP file was deleted. Then I check in the processInputHook if this session variable exists and is true to skip the part to extract the content of the ZIP file again. That seems to work. However I doubt this is the best solution to deal with this issue. Is there a more PW like way achieving the same without the ugly session variable hack? Any hints or tips on this topic are welcome. -
Hi, I added the following hook into site/ready.php to extract the contents of an uploaded ZIP archive to a specific folder (site/assets/files/uploads). The first steps works just fine. // Hook into input file field to extract zip files into specific target folder. $wire->addHookAfter('InputfieldFile::processInputFile', function (HookEvent $event) { // Limit unzip handler to specific file fields on specific template pages. $pageFile = $event->arguments('pagefile'); $page = $pageFile?->page; if (!$page || $page->template->name !== 'XX' || $pageFile->field->name !== 'XX_zip') return $event->return; // Build path to specific target folder, where ZIP files gets extracted to. $files = $this->wire('files'); $extractPath = $this->wire('config')->paths->assets . "files/uploads"; // Ensure destination folder for files to extract exists. if (!$files->exists($extractPath, 'dir')) { $files->mkdir($extractPath, $recursive = true); } // Extract ZIP file into specific folder. if ($files->exists($extractPath, 'writeable dir')) { $items = $files->unzip($pageFile->filename, $extractPath); } return $event->return; }); Then I tried to remove the automatically extracted files from the specific folder, once the uploaded ZIP files gets deleted via the backend via the hook below (again in site/ready.php). The code below works standalone, but not in combination with the other hook above. Issue: Once the code in the delete hook (below) was executed, the code in the processInputFile hook (above) kicks in again, causing the unpacking of the files from the uploaded ZIP archive again. The ZIP file gets deleted during the process, but the unpacked files remain inside /site/assets/files/uploads. // Hook into file field to remove extracted files from specific folder once ZIP file gets deleted. $wire->addHookAfter('InputfieldFile::processInputDeleteFile', function (HookEvent $event) { // Limit unzip handler to specific file fields on specific template pages. $pageFile = $event->arguments('pagefile'); $page = $pageFile?->page; if (!$page || $page->template->name !== 'XX' || $pageFile->field->name !== 'XX_zip') return $event->return; // Build path to target folder. $files = $this->wire('files'); $extractPath = $this->wire('config')->paths->assets . "files/uploads"; // Delete zip folder when ZIP file gets deleted. $files->rmdir($extractPath, $recursive = true); return $event->return; }); Also tried to hook to processInputAddFile without success. Is there any way I can check inside processInputFile, if the hook was triggered by the delete or upload/add action? Thanks in advance for any hints or comments on this issue.
-
session variable randomly not set in multi instance context
cwsoft replied to elabx's topic in General Support
Had a similar issue with a local/live site where changing the session name to different names fixed the issues I had. However don‘t use special chars in the session name. Had issues with a - or . inside my session name, which caused weired issues, not easy to spot. Removing those chars and clearing session cache resolved the issues I had. Issue occured on last stable master and using PW $session API to check for logged in frontend users. -
@ryanThank you very much for the code examples you provided for possible hook options related to PageClasses. Personally like the idea of including a page related hook file following the naming convention concept of PageClasses like PageNameHook.php. Will try some of those concepts soon in a real world project I am working on right now.
-
@ryanCould you comment on this quote from @bernhard in this thread. Hope I haven‘t missed it in this long thread. Having init and ready methods for page classes is something which was asked or proposed quite often in this forum or discussed at PWs Github repo in the past. Would be great to hear your thoughts on that and if this is something you may consider for future PW versions. Thanks in advance.
-
The PW forum is a place of the most friendly and helpful people I ever interacted with in web based CMS/CMF forums so far. What I learned from other forums is, that showing as much code you already tried (e.g. I put this code xxx into /site/templates/myfile.php) and asking a single question closely related to your code example (e.g. I expected to get x, but instead I see y) would help all involved people to better grasp each others standpoint and to provide better replies to specific questions. Cheers cwsoft
-
Nice and clean writeup on your local development setup. Thanks for sharing.