File tree Expand file tree Collapse file tree 3 files changed +32
-14
lines changed
Expand file tree Collapse file tree 3 files changed +32
-14
lines changed Original file line number Diff line number Diff line change @@ -195,27 +195,30 @@ public function getHeight()
195195
196196 /**
197197 * Extract oembed information from the <link rel="alternate"> elements
198+ * Note: Some sites use <meta rel="alternate"> instead
198199 *
199200 * @param \DOMDocument $html
200201 *
201202 * @return string|null
202203 */
203204 protected static function getEndPointFromDom (\DOMDocument $ html )
204205 {
205- foreach (Utils::getLinks ($ html ) as $ link ) {
206- list ($ rel , $ href , $ element ) = $ link ;
206+ foreach (['link ' , 'meta ' ] as $ tagName ) {
207+ foreach (Utils::getLinks ($ html , $ tagName ) as $ link ) {
208+ list ($ rel , $ href , $ element ) = $ link ;
207209
208- if (empty ($ href )) {
209- continue ;
210- }
210+ if (empty ($ href )) {
211+ continue ;
212+ }
211213
212- if ($ rel === 'alternate ' ) {
213- switch (strtolower ($ element ->getAttribute ('type ' ))) {
214- case 'application/json+oembed ' :
215- case 'application/xml+oembed ' :
216- case 'text/json+oembed ' :
217- case 'text/xml+oembed ' :
218- return $ href ;
214+ if ($ rel === 'alternate ' ) {
215+ switch (strtolower ($ element ->getAttribute ('type ' ))) {
216+ case 'application/json+oembed ' :
217+ case 'application/xml+oembed ' :
218+ case 'text/json+oembed ' :
219+ case 'text/xml+oembed ' :
220+ return $ href ;
221+ }
219222 }
220223 }
221224 }
Original file line number Diff line number Diff line change @@ -31,14 +31,15 @@ public static function getMetas(\DOMDocument $html)
3131 * Extract all link elements from html
3232 *
3333 * @param \DOMDocument $html
34+ * @param string $tagName
3435 *
3536 * @return array with subarrays [rel, href, element]
3637 */
37- public static function getLinks (\DOMDocument $ html )
38+ public static function getLinks (\DOMDocument $ html, $ tagName = ' link ' )
3839 {
3940 $ links = [];
4041
41- foreach ($ html ->getElementsByTagName (' link ' ) as $ link ) {
42+ foreach ($ html ->getElementsByTagName ($ tagName ) as $ link ) {
4243 if ($ link ->hasAttribute ('rel ' ) && $ link ->hasAttribute ('href ' )) {
4344 $ rel = trim (strtolower ($ link ->getAttribute ('rel ' )));
4445 $ href = $ link ->getAttribute ('href ' );
Original file line number Diff line number Diff line change 1+ <?php
2+ class ViddlerTest extends PHPUnit_Framework_TestCase
3+ {
4+ public function testOne ()
5+ {
6+ $ info = Embed \Embed::create ('http://www.viddler.com/v/bdce8c7 ' );
7+
8+ $ this ->assertEquals ($ info ->title , 'Viddler Platform Overview ' );
9+ $ this ->assertEquals ($ info ->type , 'video ' );
10+ $ this ->assertEquals ($ info ->code , '<iframe width="620" height="349" src="http://viddler.com/embed/bdce8c7" frameborder="0" allowfullscreen></iframe> ' );
11+ $ this ->assertEquals ($ info ->providerName , 'Viddler ' );
12+ $ this ->assertEquals ($ info ->providerUrl , 'http://viddler.com/ ' );
13+ }
14+ }
You can’t perform that action at this time.
0 commit comments