Skip to content

Commit 7d7a5d9

Browse files
authored
Merge pull request #33 from jurgenbosch/feature/verify-image-url
Handling non valid image urls
2 parents f04ab78 + d88f5ae commit 7d7a5d9

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

src/OpenGraph.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ protected function curl_get_contents($url, $lang)
8181

8282
protected function verify_image_url($url)
8383
{
84+
if (!filter_var($url, FILTER_VALIDATE_URL)) {
85+
return false;
86+
}
87+
8488
$headers = get_headers($url);
8589

8690
return stripos($headers[0], '200 OK') ? true : false;

tests/OpenGraphTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,17 @@ public function testFetchReturnsEmptyArrayForWebsiteWithNoMetadata()
4646

4747
$this->assertEmpty($data);
4848
}
49+
50+
/** @test */
51+
public function testFetchMustacheMetasData()
52+
{
53+
$opengraph = new OpenGraph();
54+
$data = $opengraph->fetch(
55+
'https://raw.githubusercontent.com/jurgenbosch/OpenGraph/master/tests/__mocks__/angular-headers.html', true
56+
);
57+
$this->assertArrayHasKey('title', $data);
58+
$this->assertArrayHasKey('description', $data);
59+
$this->assertArrayHasKey('image', $data);
60+
$this->assertEmpty($data['image']);
61+
}
4962
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!doctype html>
2+
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
3+
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
4+
<!--[if IE 8]> <html xmlns:ng="https://angularjs.org" class="no-js lt-ie9" id="ng-app" data-ng-app="skeletonApp"> <![endif]-->
5+
<!--[if gt IE 8]><!--> <html class="no-js" style="height: 100%; background-color: #ffffff;" data-ng-app="skeletonApp"> <!--<![endif]-->
6+
<head>
7+
<meta charset="utf-8">
8+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
9+
<title>Example</title>
10+
<meta name="description" content="{{ pageDescription }}" />
11+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
12+
13+
<meta property="og:title" content="{{ pageTitle }}" />
14+
<meta property="og:description" content="{{ pageDescription }}" />
15+
<meta property="og:image" content="{{ picturePath }}" />
16+
17+
<meta name="theme-color" content="{{ themeColor }}">
18+
<meta name="msapplication-navbutton-color" content="{{ themeColor }}">
19+
<meta name="apple-mobile-web-app-status-bar-style" content="{{ themeColor }}" />
20+
<meta name="{{ indexName }}" content="{{ indexContent }}">
21+
<link rel="canonical" href="{{ canonicalUrl }}" />
22+
</head>
23+
<body>
24+
Body here
25+
</body>
26+
</html>

0 commit comments

Comments
 (0)