Skip to content

Commit

Permalink
Added support for embedding Facebook posts
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshyPHP committed May 18, 2014
1 parent fce86dd commit 83b21f6
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Media BB Codes for XenForo, imported from [s9e\TextFormatter](https://github.com
<tr>
<td><code>facebook</code></td>
<td>Facebook</td>
<td>https://www.facebook.com/photo.php?v=10100658170103643&amp;set=vb.20531316728&amp;type=3&amp;theater<br/>https://www.facebook.com/video/video.php?v=10150451523596807</td>
<td>https://www.facebook.com/photo.php?v=10100658170103643&amp;set=vb.20531316728&amp;type=3&amp;theater<br/>https://www.facebook.com/video/video.php?v=10150451523596807<br/>https://www.facebook.com/FacebookDevelopers/posts/10151471074398553</td>
</tr>
<tr>
<td><code>funnyordie</code></td>
Expand Down
9 changes: 5 additions & 4 deletions build/addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<addon addon_id="s9e" title="s9e Media Pack" url="https://github.com/s9e/XenForoMediaBBCodes" version_id="20140517b" version_string="201405171" install_callback_class="s9e_MediaBBCodes" install_callback_method="install">
<addon addon_id="s9e" title="s9e Media Pack" url="https://github.com/s9e/XenForoMediaBBCodes" version_id="20140518" version_string="201405180" install_callback_class="s9e_MediaBBCodes" install_callback_method="install">
<bb_code_media_sites>
<site media_site_id="abcnews" site_title="ABC News" site_url="http://abcnews.go.com/" match_is_regex="1" supported="1">
<match_urls>!abcnews\.go\.com/[^/]+/video/[^/]+-(?'id'\d+)!</match_urls>
Expand Down Expand Up @@ -64,9 +64,10 @@
#(?'id')(?=.*?espn\.go\.com).*?(?'cms'deportes|espn(?!d))#</match_urls>
<embed_html><![CDATA[<iframe width="560" height="315" src="https://espn.go.com/video/iframe/twitter/?cms={$cms}&amp;id={$id}" allowfullscreen="" frameborder="0" scrolling="no"></iframe>]]></embed_html>
</site>
<site media_site_id="facebook" site_title="Facebook" site_url="http://www.facebook.com/" match_is_regex="1" supported="1">
<match_urls>!facebook\.com/(?:photo|video/video)\.php\?v=(?'id'[0-9]+)!</match_urls>
<embed_html><![CDATA[<iframe width="560" height="315" src="https://www.facebook.com/video/embed?video_id={$id}" allowfullscreen="" frameborder="0" scrolling="no"></iframe>]]></embed_html>
<site media_site_id="facebook" site_title="Facebook" site_url="http://www.facebook.com/" match_is_regex="1" supported="1" embed_html_callback_class="s9e_MediaBBCodes" embed_html_callback_method="embed" match_callback_class="s9e_MediaBBCodes" match_callback_method="matchFacebook">
<match_urls>!facebook\.com/(?'mode'photo|video)(?:/video)?\.php\?v=(?'id'\d+)!
!facebook\.com/[\w.]+/(?'mode'post)s/(?'id'\d+)!</match_urls>
<embed_html><![CDATA[<!-- s9e_MediaBBCodes::renderFacebook() -->]]></embed_html>
</site>
<site media_site_id="funnyordie" site_title="Funny or Die" site_url="http://www.funnyordie.com/" match_is_regex="1" supported="1">
<match_urls>!funnyordie\.com/videos/(?'id'[0-9a-f]+)!</match_urls>
Expand Down
17 changes: 17 additions & 0 deletions build/upload/library/s9e/MediaBBCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,23 @@ public static function matchEspn($url)
return self::match($url, $regexps, $scrapes);
}

public static function renderFacebook($vars)
{
$vars += array('id' => null, 'mode' => null);

$html='<iframe width="560" height="315" allowfullscreen="" frameborder="0" scrolling="no" src="';if($vars['mode']==='post')$html.='//s9e.github.io/iframe/facebook.min.html?';else$html.='https://www.facebook.com/video/embed?video_id=';$html.=htmlspecialchars($vars['id'],2).'"';if($vars['mode']==='post')$html.=' onload="var b=this;window.addEventListener(\'message\',function(a){/^https?:\\/\\/s9e\\.github\\.io$/.test(a.origin)&amp;&amp;a.data.url&amp;&amp;a.data.height&amp;&amp;b.src==a.data.url&amp;&amp;(b.style.height=a.data.height+\'px\')});b.contentWindow.postMessage(\'s9e:init\',\'*\')"';$html.='></iframe>';

return $html;
}

public static function matchFacebook($url)
{
$regexps = array('!facebook\\.com/(?\'mode\'photo|video)(?:/video)?\\.php\\?v=(?\'id\'\\d+)!', '!facebook\\.com/[\\w.]+/(?\'mode\'post)s/(?\'id\'\\d+)!');
$scrapes = array();

return self::match($url, $regexps, $scrapes);
}

public static function matchGametrailers($url)
{
$regexps = array();
Expand Down
35 changes: 35 additions & 0 deletions tests/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,21 @@ public function getMatchCallbackTests()
'http://espndeportes.espn.go.com/videohub/video/clipDeportes?id=2088955&amp;cc=7586',
'cms=deportes;id=2088955'
),
array(
'facebook',
'https://www.facebook.com/photo.php?v=10100658170103643',
'id=10100658170103643;mode=photo'
),
array(
'facebook',
'https://www.facebook.com/video/video.php?v=10150451523596807',
'id=10150451523596807;mode=video'
),
array(
'facebook',
'https://www.facebook.com/FacebookDevelopers/posts/10151471074398553',
'id=10151471074398553;mode=post'
),
array(
'gametrailers',
'http://www.gametrailers.com/videos/jz8rt1/tom-clancy-s-the-division-vgx-2013--world-premiere-featurette',
Expand Down Expand Up @@ -472,6 +487,26 @@ public function getEmbedCallbackTests()
'<!-- s9e_MediaBBCodes::renderEbay() -->',
'<object type="application/x-shockwave-flash" typemustmatch="" width="355" height="300" data="http://togo.ebay.com/togo/togo.swf?2008013100"><param name="allowfullscreen" value="true"><param name="flashvars" value="base=http://togo.ebay.com/togo/&amp;mode=normal&amp;query=server&amp;itemid=251053262701&amp;lang=en-GB"><embed type="application/x-shockwave-flash" src="http://togo.ebay.com/togo/togo.swf?2008013100" width="355" height="300" allowfullscreen="" flashvars="base=http://togo.ebay.com/togo/&amp;mode=normal&amp;query=server&amp;itemid=251053262701&amp;lang=en-GB"></object>'
),
array(
'id=10100658170103643;mode=photo',
'<!-- s9e_MediaBBCodes::renderFacebook() -->',
'<iframe width="560" height="315" allowfullscreen="" frameborder="0" scrolling="no" src="https://www.facebook.com/video/embed?video_id=10100658170103643"></iframe>'
),
array(
'id=10150451523596807;mode=video',
'<!-- s9e_MediaBBCodes::renderFacebook() -->',
'<iframe width="560" height="315" allowfullscreen="" frameborder="0" scrolling="no" src="https://www.facebook.com/video/embed?video_id=10150451523596807"></iframe>'
),
array(
'10150451523596807',
'<!-- s9e_MediaBBCodes::renderFacebook() -->',
'<iframe width="560" height="315" allowfullscreen="" frameborder="0" scrolling="no" src="https://www.facebook.com/video/embed?video_id=10150451523596807"></iframe>'
),
array(
'id=10151471074398553;mode=post',
'<!-- s9e_MediaBBCodes::renderFacebook() -->',
'<iframe width="560" height="315" allowfullscreen="" frameborder="0" scrolling="no" src="//s9e.github.io/iframe/facebook.min.html?10151471074398553" onload="var b=this;window.addEventListener(\'message\',function(a){/^https?:\/\/s9e\.github\.io$/.test(a.origin)&amp;&amp;a.data.url&amp;&amp;a.data.height&amp;&amp;b.src==a.data.url&amp;&amp;(b.style.height=a.data.height+\'px\')});b.contentWindow.postMessage(\'s9e:init\',\'*\')"></iframe>'
),
array(
'height=338;id=SereneIllfatedCapybara;width=600',
'<iframe width="{$width}" height="{$height}" src="http://gfycat.com/iframe/{$id}" allowfullscreen="" frameborder="0" scrolling="no"></iframe>',
Expand Down
4 changes: 2 additions & 2 deletions www/configure.html

Large diffs are not rendered by default.

0 comments on commit 83b21f6

Please sign in to comment.