shweshi / OpenGraph

A Laravel package to fetch Open Graph data of a website.
https://opengraph.shashi.dev
MIT License
154 stars 29 forks source link

Twitter post images not generating inside image tag due to verify_image_url function #83

Closed ItsSkynet closed 2 years ago

ItsSkynet commented 2 years ago

Describe the bug verify_image_url Function is assuming twitter post images with ":orig", ":large" ":medium" or ":small" as invalid images and thus is sending empty image value on the fetch return array.

Generated example:

Array
(
    [0] => Array
        (
            [robots] => NOODP
            [msapplication-TileImage] => //abs.twimg.com/favicons/win8-tile-144.png
            [msapplication-TileColor] => #00aced
            [facebook-domain-verification] => moho2ug7zs57jijiywrewd8wb5a08h
            [swift-page-name] => permalink
            [swift-page-section] => permalink
            [al:ios:url] => twitter://status?id=1524828581536440320
            [al:ios:app_store_id] => 333903271
            [al:ios:app_name] => Twitter
            [al:android:url] => twitter://status?status_id=1524828581536440320
            [al:android:package] => com.twitter.android
            [al:android:app_name] => Twitter
            [type] => article
            [url] => https://twitter.com/MexicanSkynet/status/1524828581536440320
            [title] => SKYNΞT | 🔴 twitch.tv/mexicanskynet on Twitter
            [image] =>  
            [image:user_generated] => true
            [description] => “Hoy tenemos el mas pintoresco y tradicional torneo M7GP a las 9:00 pm CUU / 10:00 pm CDMX

Recuerda unirte al chat de voz: https://t.co/GGyxQJteMB
y recuerda sintonizarnos por: https://t.co/L0KmK5iRHt

#MarioKart8Deluxe #mariokart #nintendoswitch #twitchaffiliate”
            [site_name] => Twitter
            [fb:app_id] => 2231777543
        )

)

After commenting line 56 trough line 51 in src/OpenGraph.php it successfully generated the image url on this example:

Array
(
    [0] => Array
        (
            [robots] => NOODP
            [msapplication-TileImage] => //abs.twimg.com/favicons/win8-tile-144.png
            [msapplication-TileColor] => #00aced
            [facebook-domain-verification] => moho2ug7zs57jijiywrewd8wb5a08h
            [swift-page-name] => permalink
            [swift-page-section] => permalink
            [al:ios:url] => twitter://status?id=1524828581536440320
            [al:ios:app_store_id] => 333903271
            [al:ios:app_name] => Twitter
            [al:android:url] => twitter://status?status_id=1524828581536440320
            [al:android:package] => com.twitter.android
            [al:android:app_name] => Twitter
            [type] => article
            [url] => https://twitter.com/MexicanSkynet/status/1524828581536440320
            [title] => SKYNΞT | 🔴 twitch.tv/mexicanskynet on Twitter
            [image] => https://pbs.twimg.com/media/FSlHM2bWIAAQn-8.jpg:large
            [image:user_generated] => true
            [description] => “Hoy tenemos el mas pintoresco y tradicional torneo M7GP a las 9:00 pm CUU / 10:00 pm CDMX

Recuerda unirte al chat de voz: https://t.co/GGyxQJteMB
y recuerda sintonizarnos por: https://t.co/L0KmK5iRHt

#MarioKart8Deluxe #mariokart #nintendoswitch #twitchaffiliate”
            [site_name] => Twitter
            [fb:app_id] => 2231777543
        )

)

Expected behavior Url array key should be populated if a twitter post has an image.

System Laravel 8 PHP 7.4

Side note anyone having problems getting metadata from socialmedia please use the following user agent set on this example: $opg_array = OpenGraph::fetch('URL', true, null, null, 'facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)');

shweshi commented 2 years ago

@ItsSkynet Thanks for pointing this out. Let me know if you would like to open a PR to fix this issue?

ItsSkynet commented 2 years ago

i did a little bit of research and it seems that the php constant "FILTER_VALIDATE_URL" is too strict when it comes to validate url with this kind of characteristics.

On php 5.5 it was deemed buggy and in today php versions it's deemed too strict by the community.

Removal of this constant would do no good, but instead it would be best advised to find a way to better sanitize the url before reaching this point. i will try to come up with a way to solve this. in the meantime if anyone has an idea, by all means PR it.

shweshi commented 2 years ago

Closed by PR #84