Calgarypuck Forums - The Unofficial Calgary Flames Fan Community
Old 12-20-2024, 10:21 PM   #21
KelVarnsen
Franchise Player
 
KelVarnsen's Avatar
 
Join Date: Jul 2010
Location: Apartment 5A
Exp:
Default

PHP Code:
 [TWEET]1866972053145870417[/TWEET
What exactly happens with that before the JS does anything? Create a div or something similar?
KelVarnsen is offline   Reply With Quote
Old 12-21-2024, 11:26 AM   #22
photon
The new goggles also do nothing.
 
photon's Avatar
 
Join Date: Oct 2001
Location: Calgary
Exp:
Default

Yeah exactly. The BBCode for that creates this:

Code:
<div class="tweet" tweetID="1866972053145870417"></div><a href="https://twitter.com/user/status/1866972053145870417" target="_blank">https://twitter.com/user/status/1866972053145870417</a>
And then there's this code at the end of each page which imports the Javascript script and then iterates over all the tweets on a page and does the replacement:

Code:
<script sync src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<script>
  window.onload = (function(){
    var tweets = document.querySelectorAll("div.tweet");
    tweets.forEach(
      function(tweet) {
        var id = tweet.getAttribute("tweetID");
        twttr.widgets.createTweet(
          id, tweet, 
          {
            conversation : 'none',    // or all
            cards        : 'visible',  // or visible 
          }
		);
      }
    );
  });
</script>
__________________
Uncertainty is an uncomfortable position.
But certainty is an absurd one.
photon is offline   Reply With Quote
Old 12-21-2024, 06:35 PM   #23
KelVarnsen
Franchise Player
 
KelVarnsen's Avatar
 
Join Date: Jul 2010
Location: Apartment 5A
Exp:
Default

Could we make?
PHP Code:
<div class=bluesky data-bluesky=urlofpost
KelVarnsen is offline   Reply With Quote
Old 12-22-2024, 06:48 PM   #24
photon
The new goggles also do nothing.
 
photon's Avatar
 
Join Date: Oct 2001
Location: Calgary
Exp:
Default

Yeah that would be easy to add as a BBCode.
__________________
Uncertainty is an uncomfortable position.
But certainty is an absurd one.
photon is offline   Reply With Quote
Old 12-22-2024, 11:23 PM   #25
KelVarnsen
Franchise Player
 
KelVarnsen's Avatar
 
Join Date: Jul 2010
Location: Apartment 5A
Exp:
Default

Cool, I’ll do some testing on my end
KelVarnsen is offline   Reply With Quote
The Following User Says Thank You to KelVarnsen For This Useful Post:
Old 01-21-2025, 02:24 PM   #26
KelVarnsen
Franchise Player
 
KelVarnsen's Avatar
 
Join Date: Jul 2010
Location: Apartment 5A
Exp:
Default

Forgot all about this. Will do it tonight.

Can we remove Twitter embeds after we get Bluesky embeds?
KelVarnsen is offline   Reply With Quote
The Following 2 Users Say Thank You to KelVarnsen For This Useful Post:
Old 02-02-2025, 04:55 PM   #27
Cheese
Franchise Player
 
Cheese's Avatar
 
Join Date: Mar 2002
Exp:
Default

How is this going gents? I'm nearly done with the X cesspool
Cheese is offline   Reply With Quote
Old 02-02-2025, 05:21 PM   #28
KelVarnsen
Franchise Player
 
KelVarnsen's Avatar
 
Join Date: Jul 2010
Location: Apartment 5A
Exp:
Default

I can’t it work consistently. Might be time me to upgrade the forum software
KelVarnsen is offline   Reply With Quote
The Following User Says Thank You to KelVarnsen For This Useful Post:
Old 02-28-2025, 10:04 AM   #29
psyang
Powerplay Quarterback
 
Join Date: Jan 2010
Exp:
Default

Just looked at this, and was wondering if we could do something like:

User enters:
PHP Code:
<bsky>3ldhirk3zcc2c</bsky
The BBCode transforms that to
PHP Code:
<div class=bsky bskyid="3ldhirk3zcc2c"/> 
Then at the bottom (along with the twitter code) you add:
PHP Code:
<script>
  var 
bskys document.querySelectorAll("div.bsky");
  
bskys.forEach (
    function(
bsky) {
      var 
id bsky.getAttribute("bskyid");
      var 
req = new XMLHttpRequest();
      
req.onreadystatechange=function() {
      if (
this.readyState==4&&this.status=200) {
          
document.querySelectorAll'[bskyid='+id+']').innerHTML=req.response.html
      
};
      
req.open("GET","https://embed.bsky.app/oembed?url=https://bsky.app/profile/aoc.bsky.social/post/3ldhirk3zcc2c",true);
      
req.send();
    }
 );

</script> 
That javascript code should loop through all div.bsky elements on the page, make the request for the json for each, then replace the contents of the div with the html that is returned in the json. That html includes the blockquote along with the javascript to convert to a bluesky post.

None of this is tested - just read through the thread and thought this might be a possible solution. It is basically the same as the twitter embed, but requires the extra step of first making a call to transforming the tag to the bluesky blockquote, which will then transform itself into the bluesky.

I am curious what the behaviour will be if the same bluesky post shows up multiple times on a page. The embedded javascript that comes with the blockquote will be repeated. Should be ok as long as those scripts don't run in parallel which can cause a race condition. If it causes an issue, we can look at extracting that javascript from the json response, and posting it once at the bottom of the page after all the bsky requests have completed.
psyang is offline   Reply With Quote
The Following User Says Thank You to psyang For This Useful Post:
Old 02-28-2025, 02:36 PM   #30
photon
The new goggles also do nothing.
 
photon's Avatar
 
Join Date: Oct 2001
Location: Calgary
Exp:
Default

Yeah that's basically what I had in mind just didn't really know how to do the Javascript well.

I did also find this: https://github.com/itteco/iframely

Which looks like it might work plus support a lot of different things all at once, was going to take a look at it.
__________________
Uncertainty is an uncomfortable position.
But certainty is an absurd one.
photon is offline   Reply With Quote
Old 03-02-2025, 01:40 AM   #31
psyang
Powerplay Quarterback
 
Join Date: Jan 2010
Exp:
Default

Quote:
Originally Posted by photon View Post
Yeah that's basically what I had in mind just didn't really know how to do the Javascript well.

I did also find this: https://github.com/itteco/iframely

Which looks like it might work plus support a lot of different things all at once, was going to take a look at it.
Ok, did some testing today. A couple errors in the code I posted above (I'll post fixed code below), however, there was a more fundamental issue, which is that bluesky's oembed does not support client-side integration. A call to their oembed endpoint using javascript/xmlhttprequest will return a cors error. The request needs to be made using a server-side call.

For some oembeds, you can use jsonp to get around the cors error. But that requires the oembed implementation to support jsonp, and bluesky's does not.

So there were only two alternatives:

1) Implement the oembed call server side. I'm unfamiliar with what vbulletin supports regarding customizing the output of posts server-side, so not sure what would be involved here.

2) Use a local server-side proxy that the page javascript will call. The proxy will take the bluesky oembed url, and return the json result. Since it's server-side, it won't run into the cors issue.

I tried to implement #2, and I think I have it working.

I slightly modified (simplified) a php proxy file I got from here and renamed it proxy.php
Spoiler!


I then created a test page that adds the following div:

PHP Code:
<div class=bsky url="https://bsky.app/profile/aoc.bsky.social/post/3lapo7x44ws2k"/> 
I'm placing the entire url instead of just the id since the profile also has to be passed in. It's probably easier to pass the entire url instead of cutting out the profile and id.

I then add 2 scripts at the end of the page. One is the script that calls oembed:
Spoiler!


The other is the script that is returned by bluesky's oembed. I'm adding the blockquote+script using innerHTML above, but using innerHTML does not execute the script. So I took the script and placed it in its own script tags, and made a call to the script directly after the innerHTML replacement.
Spoiler!


Finally, here is the full context of my test page.
Spoiler!

I was able to "embed" the bluesky post directly into my page using this method.

To add this to CP, you will have to:
1) add the proxy.php (maybe vbulletin already has its own method to do a proxy, in which case this isn't needed, and a small modification of the first script has to be done to call the built-in proxy properly).
2) Add the two scripts at the bottom of each page. First one converts the one-line bsky div into a blockquote. Second one converts the blockquote into a properly formatted bluesky iframe.
psyang is offline   Reply With Quote
The Following User Says Thank You to psyang For This Useful Post:
Old 03-02-2025, 04:42 PM   #32
photon
The new goggles also do nothing.
 
photon's Avatar
 
Join Date: Oct 2001
Location: Calgary
Exp:
Default

Ah yes CORS...

Cool thanks I'll take a look. I don't think vBulletin has a a simple proxy script, but that's a smart solution creating a separate php script to do that proxying.
__________________
Uncertainty is an uncomfortable position.
But certainty is an absurd one.
photon is offline   Reply With Quote
Old 03-02-2025, 10:38 PM   #33
psyang
Powerplay Quarterback
 
Join Date: Jan 2010
Exp:
Default

Quote:
Originally Posted by photon View Post
Ah yes CORS...

Cool thanks I'll take a look. I don't think vBulletin has a a simple proxy script, but that's a smart solution creating a separate php script to do that proxying.
The proxy script may need to be modified. The line

PHP Code:
curl_setopt($curlSessionCURLOPT_SSL_VERIFYHOST0); 
might need to be set to 2 instead of 0. I set it to 0 (and also added the previous line for VERIFYPEER) because I wasn't using https on my local environment, and adding these allowed the proxy to work properly - otherwise it was looking for a cert which I didn't have set up.

Wish I could be more specific, but I'm not a php guy, so was trying to cobble together what I could.

Good luck - I hope you get it working!
psyang is offline   Reply With Quote
Old 03-06-2025, 10:32 AM   #34
Cheese
Franchise Player
 
Cheese's Avatar
 
Join Date: Mar 2002
Exp:
Default

Not sure what language you guys are speaking but it sure is sexy LOL
Cheese is offline   Reply With Quote
The Following User Says Thank You to Cheese For This Useful Post:
Ped
Old 03-28-2025, 09:38 AM   #35
Fuzz
Franchise Player
 
Fuzz's Avatar
 
Join Date: Mar 2015
Location: Pickle Jar Lake
Exp:
Default

Just wondering if this got forgotten about or hit a dead end? I get it if you are just busy, too.
Fuzz is online now   Reply With Quote
The Following User Says Thank You to Fuzz For This Useful Post:
Old 03-28-2025, 03:24 PM   #36
photon
The new goggles also do nothing.
 
photon's Avatar
 
Join Date: Oct 2001
Location: Calgary
Exp:
Default

Yeah just been busy with some other stuff and/or didn't have energy to try the stuff that psyang worked out yet.

Kingdom Come Deliverance 2 isn't going to finish itself!
__________________
Uncertainty is an uncomfortable position.
But certainty is an absurd one.
photon is offline   Reply With Quote
The Following 2 Users Say Thank You to photon For This Useful Post:
Old 03-31-2025, 08:49 AM   #37
psyang
Powerplay Quarterback
 
Join Date: Jan 2010
Exp:
Default

Quote:
Originally Posted by photon View Post
Yeah just been busy with some other stuff and/or didn't have energy to try the stuff that psyang worked out yet.

Kingdom Come Deliverance 2 isn't going to finish itself!
Feel free to pm me if you want me to walk through anything with you
psyang is offline   Reply With Quote
The Following User Says Thank You to psyang For This Useful Post:
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 08:25 PM.

Calgary Flames
2024-25




Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright Calgarypuck 2021 | See Our Privacy Policy