Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/21/2023 in all areas

  1. I've just uploaded a video about RockPdf to processwire.rocks ? Until 30.11. you can get the module for 49€ @ https://www.baumrock.com/processwire/module/rockpdf/ Here are extensive docs for the module: https://www.baumrock.com/en/processwire/modules/rockpdf/docs/
    2 points
  2. Following on from an earlier tutorial for using $pagefile->uploadName... Tip 1 Suppose your website audience uses a non-latin alphabet and you have a file to upload with a filename like this: (I don't know any Chinese but Google Translate tells me that this is a translation for "my example filename") If this file is uploaded to a PW files field it ends up as shown below because none of the filename characters are allowed. This makes it hard to identify what the file relates to. Since PW 3.0.212 the original filename will be saved to the uploadName property of the Pagefile but it would be nice to improve the actual filename assigned to the file. The hooks below in /site/ready.php make use of the SanitizerEasySlugger module to transliterate the original filename to latin characters that are allowed in a PW files field. // When a file is added to InputfieldFile $wire->addHookAfter('InputfieldFile::fileAdded', function(HookEvent $event) { /** @var Pagefile $pagefile */ $pagefile = $event->arguments(0); // The uploadName property is not available at this point so just flag that the file is new $pagefile->isNewFile = true; }); // When InputfieldFile is processed in Page Edit $wire->addHookAfter('InputfieldFile::processInputFile', function(HookEvent $event) { /** @var Pagefile $pagefile */ $pagefile = $event->arguments(1); // Only for newly added files if(!$pagefile->isNewFile) return; // Only if the uploadName property is different to the basename if($pagefile->uploadName === $pagefile->basename) return; // Divide the upload name into parts $parts = pathinfo($pagefile->uploadName); // Transliterate non-latin characters in the filename using the SanitizerEasySlugger module // https://processwire.com/modules/sanitizer-easy-slugger/ $transliterated = $event->wire()->sanitizer->utf8Slugger($parts['filename']); // Rename the file (renamed file will be visible after the page is saved) $pagefile->rename($transliterated . '.' . $pagefile->ext); }); After saving the page the filename now at least has some connection to the original filename, and this is presumably more useful to a Chinese speaker: Tip 2 When using CKEditor or TinyMCE to link to a file, by default you can only see the sanitized name: But it would be helpful to also see the original filename that has been saved to $pagefile->uploadName. Add the hook below to /site/ready.php: // When the Add Link form is created $wire->addHookAfter('ProcessPageEditLink::buildForm', function(HookEvent $event) { /** @var InputfieldForm $form */ $form = $event->return; // Get the "Select File" select /** @var InputfieldSelect $select */ $select = $form->getChildByName('link_page_file'); // Get an instance of PagefilesManager via the Home page $fm = $event->wire()->pages->get('/')->filesManager(); // For each of the options in the select foreach($select->options as $filename => $label) { if(!$filename) continue; $pagefile = $fm->getFile($filename); if(!$pagefile) continue; // Only if the uploadName is different from the filename if($pagefile->uploadName === $pagefile->basename) continue; // Add the uploadName to the option label $select->replaceOption($filename, $filename, $label . " ($pagefile->uploadName)"); } }); Now the uploadName is appended to the select option label:
    2 points
  3. RockShell v2.0.0 is out. It's been in development for quite a long time and I use it on a daily basis. This module is a little special, as it has to be placed in the PW root folder (not in /site/modules). From there you can then call the shell interface via "php RockShell/rockshell" You can then use the "symlink" command to create a symlink in the root folder. After that you can call rockshell via "php rock" in the pw root folder. I've made it as easy as possible to create custom commands - you only need one config() and one handle() method! https://github.com/baumrock/RockShell/
    1 point
  4. This is a fun, simple project I built over the holidays and really goes back to what initially drew me to ProcessWire several years ago after being inspired by Ryan's Skyscrapers Demo. Backwards Compatible allows searching and browsing by various performance related tags and game pages display detailed data on each title. List of modules used: Import Pages by CSV - Essential for this kind of site, the vast majority of data was imported in one CSV upload Procache - Invaluable after an influx of 650k page views in 6 days(!) Form Builder - A simple implementation for monitored page updates and YT video submissions Soma's AjaxSearch Mike Rockett's Sitemap Additional styles/scripts: Bootstrap Grid only for CSS Fancybox.js Tippy.js Commento
    1 point
  5. Delayed Image Variations Delays the creation of image variations until their individual URLs are loaded. Image variations being generated one-by-one: Background Normally when you create new image variations in a template file using any of the ProcessWire image resizing methods, all the new variations that are needed on a page will be created from the original Pageimage the next time the page is loaded in a browser. If there are a lot of images on the page then this could take a while, and in some cases the page rendering might exceed your max_execution_time setting for PHP. So you might like to have image variations be generated individually when they are requested rather than all at once. That way the page will render more quickly and the risk of a timeout is all but eliminated. But there can be problems with some implementations of this approach, such as with the (in)famous TimThumb script: It's not ideal to have PHP be involved in serving every image as this is needlessly inefficient compared to serving static assets. It's not good to allow arbitrary image sizes to be generated by varying URL parameters because you might want to restrict the maximum resolution an image is available at (e.g. for copyrighted images). If images are generated from URL parameters a malicious user could potentially generate thousands of images of slightly different dimensions and fill up all your disk space. The Delayed Image Variations module avoids these problems - it creates variations when their URLs are loaded but only allows the specific dimensions you have defined in your code. It does this by saving the settings (width, height and ImageSizer options) of every new Pageimage::size() call to a queue. The module intercepts 404s and if the request is to an image variation that doesn't exist yet but is in the queue it generates the variation and returns the image data. This only happens the first time the image is requested - after that the image exists on disk and gets loaded statically without PHP. Usage In most cases usage is as simple as installing the module, and you don't need to change anything in your existing code. However, there might be some cases where you don't want the creation of a particular image variation to be delayed. For example, if you created a variation in your code and then immediately afterwards you wanted to get information about the variation such as dimensions or filesize. $resized = $page->image->width(600); echo $resized->height; echo $resized->filesize; This wouldn't work because the actual creation of the resized image hasn't happened yet and so that information won't be available. So in these cases you can set a noDelay option to true in your ImageSizer options and Delayed Image Variations will skip over that particular resizing operation. $resized = $page->image->width(600, ['noDelay' => true]); echo $resized->height; echo $resized->filesize; For advanced cases there is also a hookable method that you can return false for if you don't want a delayed variation for any particular resizing operation. Example: $wire->addHookAfter('DelayedImageVariations::allowDelayedVariation', function(HookEvent $event) { /** @var Pageimage $pageimage */ $pageimage = $event->arguments(0); // The Pageimage to be resized $width = $event->arguments(1); // The width supplied to Pageimage::size() $height = $event->arguments(2); // The height supplied to Pageimage::size() $options = $event->arguments(3); // The options supplied to Pageimage::size() // Don't delay variations if the Pageimage belongs to a page with the product template if($pageimage->page->template == 'product') $event->return = false; }); 404 handling For Delayed Image Variations to work your .htaccess file needs to be configured so that ProcessWire handles 404s. This is the default configuration so for most sites no change will be needed. # ----------------------------------------------------------------------------------------------- # 2. ErrorDocument settings: Have ProcessWire handle 404s # # For options and optimizations (O) see: # https://processwire.com/blog/posts/optimizing-404s-in-processwire/ # ----------------------------------------------------------------------------------------------- ErrorDocument 404 /index.php ProCache If you are using ProCache then make sure it is not configured to cache the 404 page or else PHP will not execute on 404s and queued image variations will not be generated. Generate queued variations Before launching a new website you might want to pre-generate all needed image variations, so no visitor will have to experience a delay while a variation is generated. To queue up the image variations needed for your site you will need to visit each page of the website one way or another. You could do this manually for a small site but for larger sites you'll probably want to use a site crawler tool such as Xenu's Link Sleuth. This may generate some image variations but it's likely that some other variations (e.g. within srcset attributes) will not be requested and so will remain queued. To generate all currently queued variations there is a button in the module config: This will search the /site/assets/files/ directory for queue files and render the variations. https://github.com/Toutouwai/DelayedImageVariations https://processwire.com/modules/delayed-image-variations/
    1 point
  6. Introduction to RectorPHP In the dynamic world of PHP development, code refactoring is an inevitable task, whether for code optimization or transitioning to newer PHP versions. RectorPHP stands as a vital tool, simplifying this often challenging process. So, what is RectorPHP? What is RectorPHP? RectorPHP, or Rector, is a revolutionary open-source tool created to automate the process of refactoring PHP code. Refactoring, in simple terms, refers to the modification of a software system's internal structure without changing its external behavior, ultimately leading to enhanced readability and maintainability. Built on the powerful PHP Parser library, Rector analyzes and manipulates PHP code at the abstract syntax tree (AST) level. This granular control allows for intricate adjustments, making refactoring a breeze. But Rector's capabilities don't end here. Its true strength lies in its role as an automatic code upgrade tool. RectorPHP as an Automatic Code Upgrade Tool RectorPHP's primary role is to transition PHP code from legacy standards to modern, efficient, and more secure versions. This transformation allows developers to maintain their codebase up to date, benefiting from the latest advancements in PHP development. How Can RectorPHP Upgrade Your PHP Code? RectorPHP provides a smooth and efficient roadmap to upgrade old PHP code to contemporary versions. Here's how: Installation The first step is to install Rector in your project. Given it's a composer-based project, installing is as simple as running composer require rector/rector --dev in your terminal. Configuration Next, Rector requires a configuration file (rector.php) to instruct it on what to refactor. This file, located at the root of your project, should specify the rule sets Rector should adhere to. For instance, the following configuration upgrades PHP code to PHP 8.1: <?php declare(strict_types=1); use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; use Rector\Config\RectorConfig; use Rector\Set\ValueObject\LevelSetList; return static function (RectorConfig $rectorConfig): void { $rectorConfig->paths([ __DIR__ . '/src' ]); // register a single rule $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); // define sets of rules $rectorConfig->sets([ LevelSetList::UP_TO_PHP_80 ]); }; Refactoring With Rector installed and configured, it's time to initiate the refactoring process. Execute vendor/bin/rector process in your terminal, and Rector will begin refactoring your code, illustrating the changes as it progresses. Review and Test While Rector often delivers flawless results, it's still a good practice to examine the modifications it makes. Ensuring that the changes conform to your project's requirements and haven't led to any unforeseen behaviors is a smart move. To further ascertain that your system's functionality remains unscathed, it's advisable to run your test suite. Remember, these steps aren't strictly necessary, but they add an extra layer of safety to your refactoring process. Rector also provides a "dry run" feature, where it displays the proposed changes without actually modifying the codebase. This feature is useful to preview what Rector will do before allowing it to alter your project. Conclusion RectorPHP is an essential tool for PHP developers looking to modernize their codebase efficiently. By simplifying the refactoring process and offering a seamless upgrade path for transitioning to more recent PHP versions, Rector empowers developers to focus on crafting high-quality software. Utilizing Rector means keeping your PHP code in sync with the rapidly evolving landscape of PHP development.
    1 point
  7. It isn't anymore. but the following code can be changed for ddev get ddev/ddev-phpmyadmin # Automatically add phpMyAdmin to .ddev/config.yaml echo "services:" >> .ddev/config.yaml echo " phpmyadmin:" >> .ddev/config.yaml echo " type: phpmyadmin" >> .ddev/config.yaml echo " port: 8036" >> .ddev/config.yaml When you have to choose Timezone you have to set an integer (god knows which), instead of for example Europe/Amsterdam I will try to look into the specifics
    1 point
  8. Yes, I have added rockshell alias, and a function to make it some less effort to get default setup. function setup_spinbox_project() { # Convert project name to lowercase local project_name=$(echo "$1" | tr '[:upper:]' '[:lower:]') # Check if project name is provided if [[ -z "$project_name" ]]; then echo "Please provide a project name." return 1 fi # Clone the repository and check for success git clone git@gitlab.com:#############################.git "$project_name" if [ $? -ne 0 ]; then echo "Failed to clone the repository. Check your access rights." return 1 fi # Change to the project directory cd "$project_name" || return # Run ddev config ddev config # Automatically add phpMyAdmin to .ddev/config.yaml echo "services:" >> .ddev/config.yaml echo " phpmyadmin:" >> .ddev/config.yaml echo " type: phpmyadmin" >> .ddev/config.yaml echo " port: 8036" >> .ddev/config.yaml # Start ddev ddev start # Run RockShell commands rockshell pw:download rockshell pw:install echo "Setup for $project_name complete." }
    1 point
  9. Great to hear that, thx for letting me know ? Did you create an alias? That's really great. Then you can simply type "rockshell" and it will execute "ddev php rock ..."
    1 point
  10. Awesome stuff @bernhard I have incorperated rockshell to my workflow (together with ddev, thanks for that video, just found it). Togerther with RockMigrations they are a great improvement. A thing I noticed it doesn't delete install file and folder (and also non-used site profile, though I'm not sure the default installation deletes these)
    1 point
  11. @Robin S Wow!! What can I say. How great is this community and how helpful everyone here is. Thanks Robin. I can wait longer until the final solution comes. Gideon
    1 point
  12. The problem I have is that the focus event isn't triggered for inline datepickers, which are especially handy if one wants to avoid invalid manual input. I've nevertheless thrown together a small POC module I've called DatePickerExclusions that works with focus and button click options. It still needs an option for time windows.
    1 point
  13. This is brilliant @Robin S - very clever solution ?? Should be merged into the core imho once it is more tested!
    1 point
  14. v2.1.0 is out ?? v2.1.0 Latest Bug Fixes command db:pull using old syntax (52f78e4) install command not working for dotnetic (2a68b11) rename rockshell to rock everywhere and update readme (2697bd6) Features add DbDownload command (2e91be7) add warning if PHP version is too low (a8caca8) We have a new db:download command and I created an alias for my laptop so that I can simply call "rockshell db:pull staging" instead of "ddev php rock db:pull staging" which is really nice if you use it often.
    1 point
  15. Sorry @bernhard that I wasn't very clear in my explanations. @Stefanowitsch did a better job! I will check, although I had surgery on my left hand yesterday(not fun) and I am still on painkillers(still not fun) and the blood bottle and tube is hindering everything ?(no fun at all)
    0 points
×
×
  • Create New...