This PR attempts to bypass code that (unsuccessfully) tries to download an image if the src attribute is a base64-encoded string. Current behaviour:
The importer tries to download the image using fetchAndSaveUniqueImage.
This fails because $src_old is not a URL.
fetchAndSaveUniqueImage adds #fixme to the end of the image src attribute, indicating that it couldn't download the image.
The base64 value no longer works as an image src.
Proposed behaviour:
If $src_old is a base64 string, nothing is downloaded and the image src is not modified.
In both cases, the entirety of the base64 string is stored in the database after the import— the only difference in the new behaviour is that #fixme is not appended to it.
This PR lacks a unit test. Ned suggests that a check be added to ensure that this process specifically looks for base64 images, e.g. "data:image/png;base64" or "data:image/jpeg;base64". As the check is written right now it isn't checking specifically for images. Furthermore, the current PR uses str_contains() a function that's only available in PHP8. Since Pressbooks requires PHP7.3, we should prefer a compatible method, like https://www.php.net/manual/en/function.str-contains.php#125977
An open source user has opened a simple PR in Pressbooks: https://github.com/pressbooks/pressbooks/pull/2107
This PR attempts to bypass code that (unsuccessfully) tries to download an image if the src attribute is a base64-encoded string. Current behaviour:
Proposed behaviour:
In both cases, the entirety of the base64 string is stored in the database after the import— the only difference in the new behaviour is that #fixme is not appended to it.
This PR lacks a unit test. Ned suggests that a check be added to ensure that this process specifically looks for base64 images, e.g. "data:image/png;base64" or "data:image/jpeg;base64". As the check is written right now it isn't checking specifically for images. Furthermore, the current PR uses
str_contains()
a function that's only available in PHP8. Since Pressbooks requires PHP7.3, we should prefer a compatible method, like https://www.php.net/manual/en/function.str-contains.php#125977