cwsoft
Members-
Posts
167 -
Joined
-
Last visited
-
Days Won
3
Everything posted by cwsoft
-
Hi, I first went to the tutorials section, where I first read the different output strategies. After reading the three different main strategies, I decided to go with my first steps using the Delayed Output strategy. https://processwire.com/docs/tutorials/default-site-profile/ https://processwire.com/download/site-profiles/ Choosen: Default profile (standard/intermediate edition) Then I started to add some pages and started to add simple things in the template files using the great Processwire API and some plain PHP. After I created my first prototype and got the go from my customer, I reimplemented the site with some more structure using PageClasses and Latte template engine for the views, while sticking to the delayed output strategy. Some times later I added Markup regions to my sites frontend login template to alter the header and footer region for guest users. My advice is to start simple using the Default profile (standard/intermediate edition) and work on some tutorials and try to alter or add functionality in small steps. Cheers
-
If it‘s just one language and one or two spots you need to deal with month or weekday names, I tend to use an array with e.g. the month names defined in the Latter template in combination with a PHP date format string like „n“ used as array index pointing to the month name needed (or „N“ for the weekday number).
-
@YipperI struggled on this topic in my first project too. I used delayed output strategy for the first prototype. Then I did a rewrite over a weekend with all the stuff I‘ve learned in the meantime and restructured code into Page Classes and switched from PHP templates for the view part to Latte template engine where it made sense. Fun fact. To overwrite some template parts (e.g. navigation, footer) until guests logged into the frontend, I used Markup regions on the login page to overwrite the default template parts, which shouldn‘t be visible for guest or spam bots. Lessons learned. It‘s more important to get started then overthinking which strategy to use. You will learn a lot and some of the available strategies may come handy later, once you know, how and where you can make use of it.
-
Similar here. I init my PW Git repos inside the site folder and to exclude some stuff via .gitignore.
-
@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.
-
You need at least basic PHP skills and read through some ProcessWire tutorials before you could answer the question yourself. PW has a great community answering questions fast and trying to help and some great tutorials but less good out of the box frontend templates with a big wow effect for free. I would recommend to set up a local PW installation with a basic template first, read through the template, page, fields tutorials available and try to add some own templates e.g. showing some news extracted from child pages etc. PW has an easy API allowing to do amazing things, but you need some basic knowledge of PHP at least to have fun. Finally, you will never know if PW fits your needs unless you try to setup a small project with it and make your own mind out of it. No easy answer, sorry, but I would just try out myself and see what happens. Cheers cwsoft
-
Nice write up. Thanks for sharing.
-
As usual when I have a new idea and wonder how to implement it with PW core only, Bernhard has left a forum post pointing into the direction how to accomplish what I am looking for, even before I posted the question in the forum. I guess I own you a beer or two at least now.
-
Hi. I am using two site config files. The site/config-dev.php holds the DB settings and debug settings for my local site, the site/config.php holds all the settings for the live site. PW checks for presence of a config-dev.php and uses this file instead of default site/config.php if it exists. On my local dev setup, I do have a config-dev.php file next to my site/config.php file. On the live server I just upload the site/config.php or delete/rename the site/config-dev.php via FTP. Then I just ZIP my entire local setup once I am finished, upload the ZIP via FTP into the root of my live server together with an PHP unzip file and then visit the URL of the unzip script on my live server in the browser. The unzip scripts extracts all the files, sets right permissions if needed and deletes the ZIP folder and the unzip script itself once done. The local DB dump is done via DDEV DB export feature and then just loaded to the live server via phpMyAdmin or whatever DB tools the hosting company offers. This is done before I upload the ZIP file to my live server. For some extra safety, I create a dump of the live DB and rename the live site/ and wire/ folders to site.bak/ and wire.bak/ via Ftp before doing the update. This way I can easily revert back to the last working live state if needed - never needed for my PW sites so far, but happened in the past with some WP sites I tried to update.
-
@dan222You can get working a project in mind with PW quite easily by just using some basic features. I learn and discover new things every time I am using PW or read forum threads even after one year of using PW. Pretty sure I discovered only 30-50% of PWs goodies yet.
-
I created regular user accounts via the PW API with a specific role. Then I build a frontend login form using the PW API with the build in login throttle module and added a hidden honey pot field and a simple number captcha. Doing so allows to not expose the true admin login URL, which I keep for the side admin and two maintenance accounts. The admin template checks for the roles and throws a 404 PW error if a user with the role of the frontend-user would try to enter any backend page. So for those frontend users it seems the PW admin backend does not exist at all, while the site admin or the two other accounts can enter the PW backend parts which are accessible based on their roles and permissions granted.