revolution icon indicating copy to clipboard operation
revolution copied to clipboard

Thumbnails not working in the media browser in PHP 7.4

Open DmitryFX opened this issue 1 year ago • 8 comments

Bug report

Summary

Thumbnails not working in the media browser. image

Step to reproduce

Upload any image (jpg, png) in the media browser, no thumbnails.

Observed behavior

Trying to navigate the url given in the 'not found' <img src='/site/connectors/system/phpthumb.php?src=assets%252Fvideo-iframe.png&w=100&h=0&HTTP_MODAUTH=modx64e51c266752a2.30117216_164f338950c1714.28557021&f=png&q=90&wctx=mgr&source=1&t=1693977472&ar=x'> I get:

Fatal error: Uncaught TypeError: Argument 2 passed to phpthumb::__set() must be an instance of mixed, bool given in 

D:\site\site_www\core\vendor\james-heinrich\phpthumb\phpthumb.class.php:321 Stack trace: #0 

D:\site\site_www\core\vendor\james-heinrich\phpthumb\phpthumb.class.php(405): phpthumb->__set('cache_source_en...', false) #1 

D:\site\site_www\core\src\Revolution\modPhpThumb.php(100): phpthumb->setParameter('cache_source_en...', false) #2 

D:\site\site_www\core\src\Revolution\Processors\System\PhpThumb.php(140): MODX\Revolution\modPhpThumb->initialize() #3 

D:\site\site_www\core\src\Revolution\Processors\System\PhpThumb.php(84): MODX\Revolution\Processors\System\PhpThumb->loadPhpThumb() #4 

D:\site\site_www\core\src\Revolution\Processors\Processor.php(189): MODX\Revolution\Processors\System\PhpThumb->process() #5 

D:\site\site_www\core\src\Revolution\modX.php(1761): MOD in 

D:\site\site_www\core\vendor\james-heinrich\phpthumb\phpthumb.class.php on line 321

Error Log, set to Debug mode:

[2023-09-06 08:32:31] (DEBUG @ D:\site\site_www\core\src\Revolution\modLexicon.php : 526) Language string not found: "prop_file.skipExtensions_desc"
[2023-09-06 08:32:31] (DEBUG @ D:\site\site_www\core\src\Revolution\modLexicon.php : 526) Language string not found: "fred"
[2023-09-06 08:32:31] (DEBUG @ D:\site\site_www\core\src\Revolution\modLexicon.php : 526) Language string not found: "fredReadOnly"
[2023-09-06 08:32:31] (DEBUG @ D:\site\site_www\core\src\Revolution\modLexicon.php : 526) Language string not found: "prop_file.skipExtensions_desc"
[2023-09-06 08:32:31] (DEBUG @ D:\site\site_www\core\src\Revolution\modLexicon.php : 526) Language string not found: "fred"
[2023-09-06 08:32:31] (DEBUG @ D:\site\site_www\core\src\Revolution\modLexicon.php : 526) Language string not found: "fredReadOnly"
[2023-09-06 08:32:31] (DEBUG @ D:\site\site_www\core\src\Revolution\modLexicon.php : 526) Language string not found: "prop_file.skipExtensions_desc"
[2023-09-06 08:32:31] (DEBUG @ D:\site\site_www\core\src\Revolution\modLexicon.php : 526) Language string not found: "fred"
[2023-09-06 08:32:31] (DEBUG @ D:\site\site_www\core\src\Revolution\modLexicon.php : 526) Language string not found: "fredReadOnly"
[2023-09-06 08:32:31] (DEBUG @ D:\site\site_www\core\src\Revolution\modLexicon.php : 526) Language string not found: "prop_file.skipExtensions_desc"
[2023-09-06 08:32:31] (DEBUG @ D:\site\site_www\core\src\Revolution\modLexicon.php : 526) Language string not found: "fred"
[2023-09-06 08:32:31] (DEBUG @ D:\site\site_www\core\src\Revolution\modLexicon.php : 526) Language string not found: "fredReadOnly"
[2023-09-06 08:32:31] (WARN @ D:\site\site_www\core\vendor\james-heinrich\phpthumb\phpthumb.class.php : 314) PHP notice: Undefined variable: value
[2023-09-06 08:32:31] (WARN @ D:\site\site_www\core\vendor\james-heinrich\phpthumb\phpthumb.class.php : 314) PHP notice: Undefined variable: value

Expected behavior

Thumbnails should work.

Environment

3.1.0-dev PHP 7.4.30 Apache 2.4 Mysql 5.7.17

ModX 2.8.4 works in the same environment as expected.

DmitryFX avatar Sep 06 '23 07:09 DmitryFX

It seems that there has been an update to the phpThumb library (that is used by MODX to create thumbnails) that is not compatible with PHP 7.4. But I believe this issue has to be fixed in phpThumb and not in MODX.

The problem is this pull request: https://github.com/JamesHeinrich/phpThumb/pull/216/files

For a quick fix, you could either change the PHP version to at least 8.0, or delete the word mixed from the line here: https://github.com/JamesHeinrich/phpThumb/blob/7ee966b38ddd7eb4d8091389aa514604710711c8/phpthumb.class.php#L317

halftrainedharry avatar Sep 06 '23 13:09 halftrainedharry

halftrainedharry's solution worked. Many thanks! SVG previews still not working, but it is another story.

DmitryFX avatar Sep 06 '23 15:09 DmitryFX

SVGs maybe shouldn't try generating thumbnails and just be passed through w/o a thumbnail?

rthrash avatar Sep 06 '23 15:09 rthrash

SVGs maybe shouldn't try generating thumbnails and just be passed through w/o a thumbnail?

Agree, but it looks, that phpthumb tries to make the preview and gives the following errors:

[2023-09-06 15:54:08] (DEBUG @ D:\site\site_www\core\src\Revolution\Sources\modMediaSource.php : 2376) assets/settings.svg has a mime type of: image/svg
[2023-09-06 15:54:08] (WARN @ D:\site\site_www\core\src\Revolution\Sources\modMediaSource.php : 2300) PHP notice: Undefined variable: image
[2023-09-06 15:54:08] (WARN @ D:\site\site_www\core\src\Revolution\Sources\modMediaSource.php : 2300) PHP notice: Undefined variable: image
[2023-09-06 15:54:08] (WARN @ D:\site\site_www\core\src\Revolution\Sources\modMediaSource.php : 1961) PHP notice: Trying to access array offset on value of type bool
[2023-09-06 15:54:08] (WARN @ D:\site\site_www\core\src\Revolution\Sources\modMediaSource.php : 1962) PHP notice: Trying to access array offset on value of type bool

Interesting: Accessing .svg file directly via phpthumb connector gives the proper svg document in the browser.

http://localhost/site/connectors/system/phpthumb.php?src=assets%252Fsettings.svg&w=100&h=0&HTTP_MODAUTH=modx64e51c266752a2.30117216_164f338950c1714.28557021&f=png&q=90&wctx=mgr&source=1&t=1693977472&ar=x

But in the media browser svg preview looks as follows:

<img src="" data-src="" loading="lazy" width="100" height="80" alt="settings.svg" title="settings.svg">

DmitryFX avatar Sep 06 '23 15:09 DmitryFX

SVGs maybe shouldn't try generating thumbnails and just be passed through w/o a thumbnail?

This should already be implemented. There are exceptions in the code for SVGs: https://github.com/modxcms/revolution/blob/8feb62f69a0a1b3b557528c5ffdd1c6d311e8682/core/src/Revolution/Sources/modMediaSource.php#L2238-L2246

When I test it, it seems to work correctly (at least in MODX 3.0.3-pl).

halftrainedharry avatar Sep 06 '23 16:09 halftrainedharry

This issue has been mentioned on MODX Community. There might be relevant details there:

https://community.modx.com/t/modx-2-8-6-php-7-4-breaks-thumbnails-in-the-manager/7100/1

modxcommunity avatar Oct 01 '23 15:10 modxcommunity

PR submitted to the upstream repo: https://github.com/JamesHeinrich/phpThumb/pull/218

rthrash avatar Oct 04 '23 16:10 rthrash

This issue has been mentioned on MODX Community. There might be relevant details there:

https://community.modx.com/t/no-image-thumbnails-after-modx-3-upgrade/7353/2

modxcommunity avatar Dec 20 '23 08:12 modxcommunity

Hi @opengeek sorry to bug you on this one but it'd be epic to get a release out with this fix.

People (like me and many other) stiil get updates websites and catches thumbnail bugs! Community chat warming with reports, manual codefixes coming to the wild...

But v2.8.7 milestone is only 58% complete, may be we can flush it faster?

dimasites avatar Mar 26 '24 14:03 dimasites

Work is definitely happening @dimasites … some of the issues/PRs may not make the 2.8.7 release depending on testing and feedback, but the important phpThumb one definitely will.

rthrash avatar Mar 26 '24 14:03 rthrash

Hi @opengeek sorry to bug you on this one but it'd be epic to get a release out with this fix.

People (like me and many other) stiil get updates websites and catches thumbnail bugs! Community chat warming with reports, manual codefixes coming to the wild...

But v2.8.7 milestone is only 58% complete, may be we can flush it faster?

We will be releasing it very soon. I would not pay much attention to the milestones—issues and PRs tend to get assigned to them with little regard for reality.

opengeek avatar Mar 26 '24 14:03 opengeek

Thanks @opengeek and @rthrash for answers!

But for critical bugs please (it is only my point) lets make immidiate solutions! May be even hotfix-release with revert bad commit, because problems like this, make damage to friendliness and popularity of MODX.

I know about PHP 7.4 lifetime (yes, it is over), but we all knows: many and many MODX sites use PHP 7.4, much more then PHP8...

And I'll show you confirmation that it's critical.

See screenshots with stat, based on ~4.2k MODX Apps (components) install/upgrade/uninstall over last ~15 months (with only about 50% of Russian because its from MODX RSC data-source: image

All additional screen for representation: image

Based on this stats, we see over 95% MODX website's affected the bug, and even this stats not 100% accurate, even half of MODX users is overmuch

I think, we need (or must) to be more responsible with critical bug fixing! it is not security issue, but strog Developer UX issue...

P.S. I cant and dont want to make any pressure, but want stronly highlight problem!

Also i hope my examples and arguments were at least informative for you, thank you for your attention! And very thanks for working on such a wonderful project as MODX!

dimasites avatar Mar 26 '24 16:03 dimasites

+1 for bump fixed version faster!

denius-dev avatar Mar 26 '24 17:03 denius-dev

+2 for bump fixed version faster! HELP! I also faced this problem

wintik1 avatar Mar 26 '24 17:03 wintik1

+1 for bump fixed version faster!

ShevArtV avatar Mar 26 '24 17:03 ShevArtV

Long time have this problem...

Arahort avatar Apr 09 '24 14:04 Arahort

+1 for bump fixed version faster!

Oksana-png avatar Apr 09 '24 15:04 Oksana-png

+1 for bump fixed version faster!

biz87 avatar Apr 09 '24 17:04 biz87

This issue is resolved with the vendor fix for phpthumb in both 2.8.7 and 3.0.5.

smg6511 avatar Apr 22 '24 14:04 smg6511