Skip to content

v13.37.0

Choose a tag to compare

@ogorzalka ogorzalka released this 20 Oct 15:25
· 101 commits to main since this release
5ffbbb4

Added

  • Media, anchor of a cover: ImageSize::add('portrait')->cover(400, 500, Anchor::Top) keeps the top of the image instead of its centre (Pollora\Media\Domain\Enums\Anchor, the nine positions of add_image_size()). It never changes the dimensions of the size, changes the name of the files and the version of a service URL, becomes a gravity in the imgproxy preset, and is refused by Bunny, which pollora:media:thumbs:export and pollora:doctor report. It comes with pollora/media 0.8
  • Media, sizes made by a service: media.thumbnails.driver (MEDIA_THUMBNAILS_DRIVER) takes bunny (photo.jpg?class=card, an image class of Bunny Optimizer) or imgproxy (a URL signed with HMAC-SHA256 that names a preset, imgproxy 4.0.x in presets-only mode) besides pollora. No file is made and no fallback route is registered; a private media never goes to the service. php artisan pollora:media:thumbs:export --driver=bunny|imgproxy declares one class or preset per size and per extra width (Bunny: merged by name, a dry run unless --execute; imgproxy: the configuration to give it, without the key or the salt), and pollora:doctor reports a driver that cannot be used. See media.thumbnails.bunny and media.thumbnails.imgproxy in config/media.php
  • Media, sizes made on demand: a declared size that is not eager() is made the first time its URL is asked for, at the exact path of the URL, and served as a file afterwards (Cache-Control: public, max-age=31536000, immutable, never a redirect); the name, the signature and the extension are checked before anything is made, and media.thumbnails limits the cost per server (sizes at the same time, biggest original, wait before a size that exists is served instead). pollora:doctor reports a .htaccess in the uploads folder that stops the fallback
  • Media, image sizes: an ImageSize facade declares the sizes your design uses, ImageSize::add('card')->cover(600, 400)->webp(75), with cover(), scale(), contain(), webp(), avif(), original(), widths(), eager() and upscale(). The file of a size is named photo-card-600x400-{signature}.webp (an HMAC of the original and of the size, made with the application key), so changing a size changes its name, and the URL, width, height and srcset of a size are worked out from the metadata of the original, never from the disk. The sizes WordPress registers itself, including a theme's config/images.php, are left as they are. pollora:media:thumbs:warm makes the missing files for the images already uploaded, pollora:media:thumbs:prune deletes the files of a size that was changed or removed, and pollora:doctor reports a declaration that cannot make a size or a format the server cannot write
  • Media, private files: a media flagged private (the _pollora_media_private meta, or the pollora/media/is_private filter) is served through a signed URL that expires (media.private.expiry) on its URL, its sizes and its srcset; a public media keeps its plain URL and the disk is never asked to tell them apart. pollora:media:visibility {id} --private|--public changes every file of a media on the disk, pollora:media:files {id} lists them, and the module's actions reach Laravel as MediaStored, MediaDeleted and MediaVisibilityChanged events. The URL is signed by the Laravel disk (temporaryUrl()), and pollora:doctor warns of private media on a disk that cannot sign
  • Media, images: the sizes a media does not need at once can be generated after the upload (media.async_thumbnails): thumbnail and medium come with the upload, the rest in an asynchronous action that runs on the queue, Action Scheduler or WP-Cron, and WordPress serves the nearest size meanwhile. An upload of an image with nine sizes no longer reads the original back, nor asks the disk for the size of each file, and the personal data export works on any disk (its archive is built locally, copied to the disk and deleted from it when it expires). Both WordPress image editors, GD and Imagick, work as they are
  • The media library can live on any Laravel disk (local, S3, R2, Scaleway…) behind two settings, media.disk and media.url (config/media.php, MEDIA_DISK, MEDIA_URL). The storage is pollora/media; the framework keeps the connector: MediaServiceProvider (the Flysystem driver of the disk, the URL of the disk when media.url is empty), pollora:media:status, pollora:media:migrate (copy between disks, --replace-urls for the database, dry run unless --execute) and a check of pollora:doctor (the disk takes a file; no media left in the local uploads folder). WordPress's own file functions follow through a pollora:// stream wrapper and the upload_dir filter, so Gutenberg, ACF, Meta Box, WooCommerce and imports need no adaptation; a media URL is media.url and a relative path, never asked to the disk. With no media.disk, nothing changes: WordPress keeps public/content/uploads
  • A Role facade declares roles and capabilities the fluent way, besides #[Role] and #[ModifyRole]: Role::make('event_manager', 'Event manager')->inherits('author')->grantsPostType(Event::class, Access::Editor)->grants('export_attendees')->without('publish_posts'), Role::modify('editor') and Role::capabilitySet(EventCap::class). The names are those of the attributes and of their arguments, and the same code checks both, so a mistake is refused with the same reason, naming the call (Role::make('x') at file:line). There is nothing to register: the declarations are checked when WordPress builds its roles. It comes with pollora/roles 0.2

Fixed

  • Media, edited images: the eager() sizes of an image cropped, rotated, flipped or restored in the media library are made, as at upload. WordPress saves the metadata of an edited image without wp_generate_attachment_metadata, so on a disk served without fallback every size of an edited image was a broken image until thumbs warm. It comes with pollora/media 0.7.1

Changed

  • RoleServiceProvider binds RoleRegistry with its RoleDefinitionBuilder and adds RoleDeclarer, the service the facade forwards to