Skip to content
Open
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Add skipPhotonDomain to the typed Jetpack script data flags.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ declare module '@automattic/jetpack-script-data' {
jetpack?: {
flags: {
showJetpackBranding: boolean;
skipPhotonDomain: boolean;
};
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: bugfix

Tiled Gallery: fix images being routed through the external Photon domain on VIP sites, keep existing galleries valid when that changes, and add a `jetpack_skip_photon_domain` filter to control it.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import * as deprecatedV5 from './v5';
import * as deprecatedV6 from './v6';
import * as deprecatedV7 from './v7';
import * as deprecatedV8 from './v8';
import * as deprecatedV9 from './v9';

export default [
deprecatedV9,
deprecatedV8,
deprecatedV7,
deprecatedV6,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ export function photonizedImgProps( img, galleryAtts = {} ) {
const { height, width } = img;
const { layoutStyle } = galleryAtts;

const photonImplementation =
isWpcomFilesUrl( url ) || true === isVIP() ? photonWpcomImage : photon;
// Deprecated versions have to keep producing the URLs they originally saved, or content saved
// under them stops validating, so they always use the external Photon domain — regardless of what
// the site's Photon-domain setting says. Only the current version follows that setting.
const photonImplementation = isWpcomFilesUrl( url ) ? photonWpcomImage : photon;

/**
* Build the `src`
Expand Down Expand Up @@ -97,12 +99,6 @@ export function photonizedImgProps( img, galleryAtts = {} ) {

return Object.assign( { src }, srcSet && { srcSet } );
}
function isVIP() {
/*global jetpack_plan*/
if ( typeof jetpack_plan !== 'undefined' && jetpack_plan.data === 'vip' ) {
return true;
}
}
function isWpcomFilesUrl( url ) {
const { host } = new URL( url, window.location.href );
return /\.files\.wordpress\.com$/.test( host );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ export function photonizedImgProps( img, galleryAtts = {} ) {
const { height, width } = img;
const { layoutStyle } = galleryAtts;

const photonImplementation =
isWpcomFilesUrl( url ) || true === isVIP() ? photonWpcomImage : photon;
// Deprecated versions have to keep producing the URLs they originally saved, or content saved
// under them stops validating, so they always use the external Photon domain — regardless of what
// the site's Photon-domain setting says. Only the current version follows that setting.
const photonImplementation = isWpcomFilesUrl( url ) ? photonWpcomImage : photon;

/**
* Build the `src`
Expand Down Expand Up @@ -98,12 +100,6 @@ export function photonizedImgProps( img, galleryAtts = {} ) {

return Object.assign( { src }, srcSet && { srcSet } );
}
function isVIP() {
/*global jetpack_plan*/
if ( typeof jetpack_plan !== 'undefined' && jetpack_plan.data === 'vip' ) {
return true;
}
}
function isWpcomFilesUrl( url ) {
const { host } = new URL( url, window.location.href );
return /\.files\.wordpress\.com$/.test( host );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ export function photonizedImgProps( img, galleryAtts = {} ) {
const { height, width } = img;
const { layoutStyle } = galleryAtts;

const photonImplementation =
isWpcomFilesUrl( url ) || true === isVIP() ? photonWpcomImage : photon;
// Deprecated versions have to keep producing the URLs they originally saved, or content saved
// under them stops validating, so they always use the external Photon domain — regardless of what
// the site's Photon-domain setting says. Only the current version follows that setting.
const photonImplementation = isWpcomFilesUrl( url ) ? photonWpcomImage : photon;

/**
* Build the `src`
Expand Down Expand Up @@ -106,12 +108,6 @@ export function photonizedImgProps( img, galleryAtts = {} ) {

return Object.assign( { src }, srcSet && { srcSet } );
}
function isVIP() {
/*global jetpack_plan*/
if ( typeof jetpack_plan !== 'undefined' && jetpack_plan.data === 'vip' ) {
return true;
}
}
function isWpcomFilesUrl( url ) {
const { host } = new URL( url, window.location.href );
return /\.files\.wordpress\.com$/.test( host );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ export function photonizedImgProps( img, galleryAtts = {} ) {
const { height, width } = img;
const { layoutStyle } = galleryAtts;

const photonImplementation =
isWpcomFilesUrl( url ) || true === isVIP() ? photonWpcomImage : photon;
// Deprecated versions have to keep producing the URLs they originally saved, or content saved
// under them stops validating, so they always use the external Photon domain — regardless of what
// the site's Photon-domain setting says. Only the current version follows that setting.
const photonImplementation = isWpcomFilesUrl( url ) ? photonWpcomImage : photon;

/**
* Build the `src`
Expand Down Expand Up @@ -106,12 +108,6 @@ export function photonizedImgProps( img, galleryAtts = {} ) {

return Object.assign( { src }, srcSet && { srcSet } );
}
function isVIP() {
/*global jetpack_plan*/
if ( typeof jetpack_plan !== 'undefined' && jetpack_plan.data === 'vip' ) {
return true;
}
}
function isWpcomFilesUrl( url ) {
const { host } = new URL( url, window.location.href );
return /\.files\.wordpress\.com$/.test( host );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export default class Layout extends Component {
);
const Image = GalleryImageSave;

const { src, srcSet } = photonizedImgProps( img, { layoutStyle } );
// This deprecated version has to keep producing the URLs it originally saved, so it always
// uses the external Photon domain. Only the current version follows the site's setting.
const { src, srcSet } = photonizedImgProps( img, { layoutStyle }, { skipPhotonDomain: false } );

return (
<Image
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Frozen snapshot of the attributes at the time this markup was current. Never update it: the
// deprecation exists to parse content already saved in that shape.
export default {
align: {
type: 'string',
default: 'center',
},
className: {
type: 'string',
default: 'is-style-rectangular',
},
columns: {
type: 'number',
},
columnWidths: {
type: 'array',
default: [],
},
ids: {
type: 'array',
default: [],
},
imageFilter: {
type: 'string',
},
images: {
type: 'array',
default: [],
source: 'query',
selector: '.tiled-gallery__item',
query: {
alt: {
attribute: 'alt',
default: '',
selector: 'img',
source: 'attribute',
},
height: {
attribute: 'data-height',
type: 'number',
selector: 'img',
source: 'attribute',
},
id: {
attribute: 'data-id',
selector: 'img',
source: 'attribute',
},
link: {
attribute: 'data-link',
selector: 'img',
source: 'attribute',
},
customLink: {
attribute: 'href',
selector: 'a',
source: 'attribute',
},
url: {
attribute: 'data-url',
selector: 'img',
source: 'attribute',
},
width: {
attribute: 'data-width',
selector: 'img',
source: 'attribute',
type: 'number',
},
},
},
imageCrop: {
type: 'boolean',
default: true,
},
linkTo: {
default: 'none',
type: 'string',
},
roundedCorners: {
type: 'integer',
default: 0,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default as attributes } from './attributes';
export { default as supports } from './supports';
export { default as save } from './save';
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { useBlockProps } from '@wordpress/block-editor';
import clsx from 'clsx';
import { getActiveStyleName } from '../../../../shared/block-styles';
import { LAYOUT_STYLES } from '../../constants';
import { defaultColumnsNumber } from '../../edit';
import Layout from '../../layout';

/**
* Same markup as the current version, but always building external Photon (i0.wp.com) image URLs.
*
* Galleries saved before the site's Photon-domain setting was honoured have those URLs in their
* markup — on VIP sites in particular, where images are now kept on the site's own host. Without
* this deprecation the current save() regenerates different URLs while the post is parsed and every
* one of those galleries is flagged as invalid on load.
*
* Attributes are unchanged, so there is nothing to migrate: matching here keeps the block valid, and
* the next save re-serializes it with the URLs the site asks for.
*
* This is the only deprecation that reproduces the current markup. The much older v6 happens to match
* it too for plain galleries — its wrapper differs only by whitespace, which validation forgives —
* but v6 knows nothing about custom links, so galleries using `linkTo: 'custom'` match here and
* nowhere else. Removing this file invalidates exactly those.
*
* Never edit this file to follow ../../save.jsx. It has to keep emitting the markup that is already
* in the database; when the current markup changes, add a new deprecation instead.
*
* @param {object} props - Block props.
* @param {object} props.attributes - Block attributes.
* @return {import('react').ReactElement} The saved markup.
*/
export default function TiledGallerySave( { attributes } ) {
const { imageFilter, images } = attributes;

if ( ! images.length ) {
return null;
}

const {
align,
className,
columns = defaultColumnsNumber( attributes ),
linkTo,
roundedCorners,
columnWidths,
} = attributes;
const blockProps = useBlockProps.save();

return (
<div { ...blockProps } className={ clsx( blockProps.className, className ) }>
<Layout
align={ align }
columns={ columns }
imageFilter={ imageFilter }
images={ images }
isSave
layoutStyle={ getActiveStyleName( LAYOUT_STYLES, className ) }
linkTo={ linkTo }
roundedCorners={ roundedCorners }
columnWidths={ columnWidths }
skipPhotonDomain={ false }
/>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Frozen snapshot of the supports at the time this markup was current. See ./attributes.js.
export default {
align: [ 'center', 'wide', 'full' ],
color: {
gradients: true,
text: false,
},
customClassName: false,
html: false,
spacing: {
margin: true,
padding: true,
},
__experimentalHideChildBlockControls: true,
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default class Layout extends Component {
onSelectImage,
selectedImage,
setImageAttributes,
skipPhotonDomain,
} = this.props;

const ariaLabel = sprintf(
Expand All @@ -38,7 +39,9 @@ export default class Layout extends Component {
);
const Image = isSave ? GalleryImageSave : GalleryImageEdit;

const { src, srcSet } = photonizedImgProps( img, { layoutStyle } );
// Only the deprecated version that has to keep emitting the external Photon domain passes this;
// left undefined, the images follow whatever this site asks for.
const { src, srcSet } = photonizedImgProps( img, { layoutStyle }, { skipPhotonDomain } );

return (
<Image
Expand Down
Loading
Loading