Skip to content

Commit 83a563c

Browse files
committed
Merge branch 'feature/tags'
2 parents e4da107 + 71578dc commit 83a563c

File tree

14 files changed

+177
-9
lines changed

14 files changed

+177
-9
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ $info->title; //The page title
3939
$info->description; //The page description
4040
$info->url; //The canonical url
4141
$info->type; //The page type (link, video, image, rich)
42+
$info->tags; //The page keywords (tags)
4243

4344
$info->images; //List of all images found in the page
4445
$info->image; //The image choosen as main image

demo/index.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ function printCode($code, $asHtml = true)
8080
'description' => 'printText',
8181
'url' => 'printUrl',
8282
'type' => 'printText',
83+
'tags' => 'printArray',
8384
'imagesUrls' => 'printArray',
8485
'code' => 'printCode',
8586
'source' => 'printUrl',
@@ -98,6 +99,7 @@ function printCode($code, $asHtml = true)
9899
'description' => 'printText',
99100
'url' => 'printUrl',
100101
'type' => 'printText',
102+
'tags' => 'printArray',
101103
'image' => 'printImage',
102104
'imageWidth' => 'printText',
103105
'imageHeight' => 'printText',

src/Adapters/Adapter.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
* @property null|string $description
1616
* @property null|string $url
1717
* @property null|string $type
18+
* @property array $tags
1819
* @property array $images
1920
* @property null|string $image
20-
* @property null|int $imageWidth
21-
* @property null|int $imageHeight
21+
* @property null|int $imageWidth
22+
* @property null|int $imageHeight
2223
* @property null|string $code
23-
* @property null|int $width
24-
* @property null|int $height
24+
* @property null|int $width
25+
* @property null|int $height
2526
* @property null|float $aspectRatio
2627
* @property null|string $authorName
2728
* @property null|string $authorUrl
@@ -201,6 +202,14 @@ public function getType()
201202

202203
return 'link';
203204
}
205+
206+
/**
207+
* {@inheritdoc}
208+
*/
209+
public function getTags()
210+
{
211+
return Utils::getAllValues(Utils::getData($this->providers, 'tags'));
212+
}
204213

205214
/**
206215
* {@inheritdoc}

src/Adapters/AdapterInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function getImageHeight();
8181

8282
/**
8383
* Gets the aspect ratio of the embedded widget
84-
* (useful to make it flexible).
84+
* (useful to make it responsive).
8585
*
8686
* @return float|null
8787
*/

src/Adapters/N500px.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,7 @@ public function run()
5959
//order is important
6060
$this->addProvider('oembed', new Providers\OEmbed());
6161
$this->addProvider('opengraph', new Providers\OpenGraph());
62+
$this->addProvider('html', new Providers\Html());
63+
6264
}
6365
}

src/Bag.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,22 @@ public function getAll()
9090
*/
9191
public function has($name)
9292
{
93+
if (strpos($name, '[') !== false) {
94+
$names = explode('[', str_replace(']', '', $name));
95+
$key = array_shift($names);
96+
$item = isset($this->parameters[$key]) ? $this->parameters[$key] : [];
97+
98+
foreach ($names as $key) {
99+
if (!isset($item[$key])) {
100+
return false;
101+
}
102+
103+
$item = $item[$key];
104+
}
105+
106+
return isset($item);
107+
}
108+
93109
return isset($this->parameters[$name]);
94110
}
95111
}

src/DataInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ public function getDescription();
3030
*/
3131
public function getType();
3232

33+
/**
34+
* Gets the tags of the url
35+
*
36+
* @return array
37+
*/
38+
public function getTags();
39+
3340
/**
3441
* Gets the source url (feed, api, etc).
3542
*

src/Providers/Html.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,29 @@ public function getType()
6565
return $this->bag->has('video_src') ? 'video' : null;
6666
}
6767

68+
/**
69+
* {@inheritdoc}
70+
*/
71+
public function getTags()
72+
{
73+
$keywords = $this->bag->get('keywords');
74+
75+
if (!$keywords) {
76+
return [];
77+
}
78+
79+
//some sites, contains the keywords separated by commas
80+
if (strpos($keywords, ',')) {
81+
$keywords = explode(',', $keywords);
82+
//and others by spaces (ex: youtube)
83+
} else {
84+
$keywords = explode(' ', $keywords);
85+
}
86+
87+
return array_filter(array_map('trim', $keywords));
88+
}
89+
90+
6891
/**
6992
* {@inheritdoc}
7093
*/

src/Providers/OEmbed.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,21 @@ public function getType()
101101
}
102102
}
103103

104+
/**
105+
* {@inheritdoc}
106+
*/
107+
public function getTags()
108+
{
109+
if ($this->bag->has('meta[keywords]')) {
110+
//it means we are using iframe.ly api
111+
return array_map('trim', explode(',',$this->bag->get('meta[keywords]')));
112+
}
113+
114+
return [];
115+
116+
117+
}
118+
104119
/**
105120
* {@inheritdoc}
106121
*/

src/Providers/OpenGraph.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public function run()
3333

3434
if ($name === 'image') {
3535
$this->bag->add('images', $value);
36+
} else if (strpos($name, ':tag') !== false) {
37+
$this->bag->add('tags', $value);
3638
} else {
3739
$this->bag->set($name, $value);
3840
}
@@ -126,6 +128,14 @@ public function getUrl()
126128
return $this->bag->get('url');
127129
}
128130

131+
/**
132+
* {@inheritdoc}
133+
*/
134+
public function getTags()
135+
{
136+
return $this->bag->get('tags') ?: [];
137+
}
138+
129139
/**
130140
* {@inheritdoc}
131141
*/

0 commit comments

Comments
 (0)