PDA

View Full Version : Automatically embed tweet when user posts link (PHP)


greigeh
04-23-2015, 03:58 PM
I already have this plugin for youtube videos/vines/instagram etc but i'm struggling to get it to work with tweets.

$embed_player = '
<table widht="300" align="center" class="tborder" >
<tr><td class="alt1">
<iframe src="http://instagram.com/p/\\4/embed/" frameborder="0" width="280" height="330" scrolling="no"></iframe>
</td>
</tr>
</table>
';

$post['message'] = preg_replace('#(<a href="http://instagram.com)?/(embed/([-|~_0-9A-Za-z]+)|p\/([-|~_0-9A-Za-z]+)&?.*?)">(http://instagram.com)?/(embed/([-|~_0-9A-Za-z]+)|p\/([-|~_0-9A-Za-z]+)&?.*?)<\/a>#i', $embed_player, $post['message']);

I only need help with lines (src="http://instagram.com/p/\\4/embed/")

and

(preg_replace('#(<a href="http://instagram.com)?/(embed/([-|~_0-9A-Za-z]+)|p\/([-|~_0-9A-Za-z]+)&?.*?)">(http://instagram.com)?/(embed/([-|~_0-9A-Za-z]+)|p\/([-|~_0-9A-Za-z]+)&?.*?)<\/a>#i')


below is an example of a link a user would post

https://twitter.com/greigeh/status/590850852161740801

but the script will run with the following html/javascript

<div>
<script type="text/javascript">
function loadx(data) {
document.write(data.html);
}
</script>
<script type="text/javascript" src="https://api.twitter.com/1/statuses/oembed.json?id=TWEET NUMBER HERE&callback=loadx"></script>
<div class="twitter" onLoad="loadx().html"/>
</div>
</div>
<div style="clear:both;"></div>


So all I really need to know is how to ignore the underlined part of a posted link and place it into this plugin, does that make sense?

sorry if this is so confusing im just a tad baffled at the mo! :eek:

dany_danay
05-20-2018, 06:56 AM
Did you get it?

lacidious
07-11-2019, 01:18 AM
Did you figure this out? And also, how do I set this up for Vine and Instagram? Thanks!