oEmbed onebox Support for Photobucket

We have a photography forum that dates to 2004, and Photobucket is used by many members… however the older posts with Photobucket, images are not showing up on the post… (Metrô de NYC - #3 de fotografosonline - Galeria de Fotos - Fotógrafos Online)

Is there a Photobucket support or a way to add this to the list of onebox allowed domains?

Photobucket doesn’t want you to embed those images:

BUT WAIT!! If you do this:

![](https://hosting.photobucket.com/images/af237/atpaula/tempImageuaxhM1.heic?width=1920&height=1080&fit=bounds
)

You can get this:

That won’t let Discourse download those images so you’ll have them when they are no longer available from photobucket, but it will display them.

So then you’d want to go into rails, get all the posts that have ^https://hosting.photobucket.com, and do a gsub to replace those bare URLs with ![](the url).

Wait. When I wrote this the first time, the top URL didn’t render, but then later it looks like Discourse did manage to pull it down! (And it worked on my test server too!)

Maybe you just need to rebake the posts?

But it’s not working on your site: Esta imagem do Photobucket será renderizada? - Atualizações do Fórum - Fotógrafos Online

Do you have download to local disabled?

Download to local - I would not know that :confused:

If you’re an admin you can see

https://forum.fotografos.online/admin/site_settings/category/all_results?filter=download%20remote%20images

If it’s disabled, enable it, go to the topic I created, click the :wrench: and then the thing that translates to “rebuild html”

I did enable in the admin just now… and went to the original post to rebuild… but it did not work…

It did work on your post though.

On the original post I just added the URL raw:

https://hosting.photobucket.com/images/af237/atpaula/tempImageRLm0iR.heic?width=1920&height=1080&fit=bounds

(discourse has it disabled I guess)

That’s becuase on the original post they are encoded as URLS: https://forum.fotografos.online/posts/1579128.json

like


1
[URL=https://hosting.photobucket.com/images/af237/atpaula/tempImage7XmEb0.heic?width=1920&height=1080&fit=bounds]
https://hosting.photobucket.com/images/af237/atpaula/tempImage7XmEb0.heic?width=1920&height=1080&fit=bounds
[/URL]

So you really wanted to fix those when you did the migration, but it’s still possible to run a task in rails that would fix them.

1 Like

I asked over at https://ask.discourse.com/ and after one false start, got this:

Replacing [URL] Tags in Discourse Posts AI

pfaffman:

I have a bunch of posts that look like this:

1
[URL=https://hosting.photobucket.com/images/af237/atpaula/tempImage7XmEb0.heic?width=1920&height=1080&fit=bounds]
https://hosting.photobucket.com/images/af237/atpaula/tempImage7XmEb0.heic?width=1920&height=1080&fit=bounds
[/URL]

I need to run a rails command to find all of those posts and then use gsub to replace the [URL…][/URL] with just the actual url so that it will render in a one-box

DiscourseHelper:

Searching

Searching for: How do I use a Rails command or console code to find all posts containing a specific string format like [URL] tags and then replace those tags with just the contained URL in Discourse?

To find all instances of [URL]...[/URL] and replace them with only the contained URL in your Discourse posts, you can accomplish this using Rails in the Discourse console. Here’s how you can do it:

Steps:

  1. Access the Rails Console:
    You need SSH access to your server. Run the following command to access the Discourse Rails console:

    cd /var/discourse
    ./launcher enter app
    rails c
    
  2. Run a Find and Replace Command:
    Use the following code snippet to locate posts containing [URL]...[/URL] and replace them.

    Post.where("cooked LIKE ?", "%[URL=%[/URL]%").find_each do |post|
      updated_cooked = post.cooked.gsub(/\[URL=.*?\](.*?)\[\/URL\]/, '\1')
      if updated_cooked != post.cooked
        post.update!(cooked: updated_cooked)
        PostRevisor.new(post, Discourse.system_user).revise!(
          post.user,
          { cooked: updated_cooked },
          revised_at: Time.now
        )
        puts "Updated post id: #{post.id}"
      end
    end
    
  3. Test the Script:
    Before replacing the content in bulk, run the gsub logic on a single post to ensure it behaves as expected.

    test_post = Post.first # Replace with an ID for better testing
    puts test_post.cooked.gsub(/\[URL=.*?\](.*?)\[\/URL\]/, '\1')
    
  4. Run the Script and Monitor:
    Execute the full script, monitor the output, and correct any errors if necessary.

Notes:

  • This script uses Regex (\[URL=.*?\](.*?)\[\/URL\]) to match and replace the specified pattern. Ensure the pattern matches your needs exactly.
  • It uses PostRevisor to ensure the changes are recorded in the post’s edit history.
  • Be sure to test thoroughly and back up your database before executing any bulk changes.

For additional guidance, check related documentation on meta.discourse.org. If you encounter issues, feel free to share details here!

pfaffman:

It needs to replace those in raw, not cooked

DiscourseHelper:

Thank you for clarifying! Since the changes need to be made to the raw (original post content), we can modify the script to work with the raw field instead. Here’s how you can achieve this:

Updated Rails Command for raw Field

  1. Modify and Run the Script:
    Below is the updated script to process and replace the [URL]...[/URL] tags in the raw field of posts:

    # Find all posts where the raw includes the [URL] tag
    Post.where("raw LIKE ?", "%[URL=%[/URL]%").find_each do |post|
      updated_raw = post.raw.gsub(/\[URL=.*?\](.*?)\[\/URL\]/, '\1')
      
      if updated_raw != post.raw
        # Update the raw content
        post.update!(raw: updated_raw, cooked: nil)
    
        # Trigger rebake to regenerate cooked content
        post.rebake!
    
        puts "Updated post id: #{post.id}"
      end
    end
    
  2. Explanation of Changes:

    • raw instead of cooked: The raw field contains the original post content, so the gsub operation is applied to the raw text.
    • Reset cooked: Setting cooked to nil ensures that the post will be rebaked (processed) correctly.
    • rebake!: This triggers the rebaking process, which regenerates the cooked (HTML-rendered) version of the post from the updated raw content.
  3. Test the Gsub for Raw Content:
    Test the regular expression substitution on a single post to ensure it behaves correctly:

    test_post = Post.first # Replace with an appropriate post ID for testing
    puts test_post.raw.gsub(/\[URL=.*?\](.*?)\[\/URL\]/, '\1')
    
  4. Run the Bulk Update:
    Once you confirm it works as intended, you can run the script to process all posts containing the [URL] tags.

  5. Monitor and Verify:
    Monitor the script’s output. For every updated post, its id will be printed to the console. After completion, check a few posts on the site to ensure the changes appear correctly.


Backup Reminder:
Before running the script, ensure you have a full database backup, especially when working with bulk updates.

If you have additional questions or encounter issues, feel free to ask!

And I like that it uses PostRevisor so that if something goes wrong, you’ll have a record of the edit.

1 Like

Ahhhh… I’ll take a look at this!!! thank you so much!!!

1 Like

You definitely want to test it on a few posts before turning it loose–and also see how many posts it’s going to fix and who’s going to get notifications on all of those (there is something like bypass_bump or similar that skips the notifications, I think).

1 Like