WordPress.org

Ready to get started?Download WordPress

Forums

FeedWordPress
Change image size from facebook feed (11 posts)

  1. Jappi
    Member
    Posted 3 months ago #

    Hi,

    I import posts from facebook via the rss feed. Unfortunately the small one is integrated:

    https://fbcdn-photos-b-a.akamaihd.net/hphotos-ak-prn2/t1.0-0/10250116_604574436304446_8532904596604394474_s.jpg

    Is it possible, to change the "_s.jpg" in "_n.jpg", via "str_replace" or like? Because, this is the large one (https://fbcdn-photos-b-a.akamaihd.net/hphotos-ak-prn2/t1.0-0/10250116_604574436304446_8532904596604394474_n.jpg).

    Regards,
    Jan

    https://wordpress.org/plugins/feedwordpress/

  2. Beer
    Member
    Posted 3 months ago #

    Yes. I was just working with this today actually. Try pasting this into your functions.php file. I'm working on a plugin add-on, but this was the snippet I used.

    function fwp_facebook_image( $content )
    {
        $content = preg_replace_callback(
            '|https://fbcdn-photos-f-a.akamaihd.net/.+_s\.jpg|',
            function ( $matches ) {
                return str_replace( '_s', '_o', $matches[0] );
            },
            $content
        );
    }
    add_filter( 'syndicated_post', 'fwp_facebook_image', 10, 2 );
  3. Beer
    Member
    Posted 3 months ago #

    I forgot the important last line inside the function!

    return $content;

  4. Jappi
    Member
    Posted 3 months ago #

    Hello Beer,

    thank you for the code. But unfortunately it doens´t work. When I use the code, the import don´t run. If I ad the return $content; for the last } there is a php error. What is wrong?

    Regards,
    Jan

  5. Beer
    Member
    Posted 3 months ago #

    Sorry. I was working on too many things at once and that snippet wasn't enough in this context to handle it for you. This should fix it.

    function fwp_facebook_image( $data )
    {
        $data['post_content'] = preg_replace_callback(
            '|https://fbcdn-photos-f-a.akamaihd.net/.+_s\.jpg|',
            function ( $matches ) {
                return str_replace( '_s', '_o', $matches[0] );
            },
            $data['post_content']
        );
        return $data;
    }
    add_filter( 'syndicated_post', 'fwp_facebook_image', 10, 2 );
  6. Jappi
    Member
    Posted 3 months ago #

    Hello Beer,

    thank you. I´m sorry, but it doens´t work :-(
    I paste your code, but the s.jpg is still there.
    http://neu.meinejobbox.de/
    https://www.facebook.com/feeds/page.php?id=400448853383673&format=rss20

    http://s14.directupload.net/images/140525/ryvmgu7m.png

    What is wrong?

    Regards,
    Jan

  7. Beer
    Member
    Posted 3 months ago #

    The regular expression I was using matched mine. I didn't realize the host name is changing. I took a look at yours for example and see the hostname to the image is different.

    Mine is fbcdn-photos-f-a.akamaihd.net/
    Yours is fbcdn-photos-d-a.akamaihd.net/

    So we need to adjust that.

    Change this
    '|https://fbcdn-photos-f-a.akamaihd.net/.+_s\.jpg|',
    to this
    '|https://fbcdn-photos-[a-z]-a.akamaihd.net/.+_s\.jpg|',

    and let me know if that works.

  8. Jappi
    Member
    Posted 3 months ago #

    Hello Beer,

    thank you very much! It works now. You just made my day!

    Jan

  9. Jappi
    Member
    Posted 3 months ago #

    Hello Beer,

    I hope, you could help me one more time:

    In the feed (https://www.facebook.com/feeds/page.php?id=136113746547580&format=rss20), the german "ü" (für) is wrong. How can I fix it? I played with your code

    function fwp_facebook_text( $data )
    {
        $data['post_content'] = preg_replace_callback(
    		'|für|',
            function ( $matches ) {
                return str_replace( 'für', 'ü', $matches[0] );
            },
            $data['post_content']
        );
        return $data;
    }
    add_filter( 'syndicated_post', 'fwp_facebook_text', 10, 2 );

    ... but it doens´t work.

    Regards,
    Jan

  10. Beer
    Member
    Posted 3 months ago #

    You have to look at the feed. It looks like it's using f& #xfc ; r as the text for that, so that's what you'd work with to replace. If you already were, then I'm not sure yet without digging into the html* mb* or iconv functions.

  11. hdepiano
    Member
    Posted 3 weeks ago #

Reply

You must log in to post.

About this Plugin

About this Topic