File tree Expand file tree Collapse file tree 6 files changed +30
-10
lines changed Expand file tree Collapse file tree 6 files changed +30
-10
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ abstract class Adapter {
17
17
'getBiggerImage ' => false ,
18
18
'getBiggerIcon ' => false ,
19
19
'facebookAccessToken ' => null ,
20
- 'soundcloudClientId ' => null
20
+ 'soundcloudClientId ' => null ,
21
+ 'embedlyKey ' => null
21
22
);
22
23
23
24
abstract protected function initProviders (Url $ Url );
Original file line number Diff line number Diff line change 14
14
use Embed \Providers \TwitterCards ;
15
15
use Embed \Providers \Dcterms ;
16
16
use Embed \Providers \Facebook ;
17
+ use Embed \Providers \Embedly ;
17
18
18
19
class Webpage extends Adapter implements AdapterInterface {
19
20
static public function check (Url $ Url ) {
@@ -34,6 +35,8 @@ protected function initProviders (Url $Url) {
34
35
$ this ->providers ['OEmbed ' ] = new OEmbed (new Url ($ Url ->getAbsolute ($ this ->providers ['Html ' ]->get ('oembed ' ))));
35
36
} else if (($ OEmbed = OEmbedImplementations::create ($ Url ))) {
36
37
$ this ->providers ['OEmbed ' ] = $ OEmbed ;
38
+ } else if ($ this ->options ['embedlyKey ' ] && ($ OEmbed = Embedly::create ($ Url , $ this ->options ['embedlyKey ' ]))) {
39
+ $ this ->providers ['OEmbed ' ] = $ OEmbed ;
37
40
}
38
41
39
42
$ this ->providers = array_reverse ($ this ->providers );
Original file line number Diff line number Diff line change 4
4
use Embed \Url ;
5
5
6
6
class Embedly {
7
- static public $ api_key ;
8
7
static public $ patterns = array (
9
8
'http://*yfrog.*/* ' ,
10
9
'http://twitter.com/*/status/*/photo/* ' ,
@@ -640,12 +639,8 @@ class Embedly {
640
639
'http://www.gogoyoko.com/song/* '
641
640
);
642
641
643
- static public function setApiKey ($ key ) {
644
- static ::$ api_key = $ key ;
645
- }
646
-
647
- static public function create (Url $ Url ) {
648
- if (!static ::$ api_key ) {
642
+ static public function create (Url $ Url , $ api_key ) {
643
+ if (!$ api_key ) {
649
644
return false ;
650
645
}
651
646
@@ -655,7 +650,7 @@ static public function create (Url $Url) {
655
650
$ EndPoint ->setParameter (array (
656
651
'url ' => $ Url ->getUrl (),
657
652
'format ' => 'json ' ,
658
- 'key ' => static :: $ api_key
653
+ 'key ' => $ api_key
659
654
));
660
655
661
656
return new OEmbed ($ EndPoint );
Original file line number Diff line number Diff line change @@ -69,14 +69,21 @@ static protected function getRssItems (\SimpleXMLElement $Items) {
69
69
foreach ($ Items as $ Item ) {
70
70
$ item = array (
71
71
'url ' => null ,
72
+ 'originUrl ' => null ,
72
73
'pubdate ' => null
73
74
);
74
75
75
76
$ item ['url ' ] = (string )$ Item ->link ;
77
+ $ item ['originUrl ' ] = ((string )$ Item ->origLink ?: (string )$ Item ->comments );
78
+
76
79
$ item ['pubdate ' ] = ((string )$ Item ->pubdate ?: (string )$ Item ->pubDate );
77
80
78
81
if (!$ item ['pubdate ' ] && isset ($ namespaces ['dc ' ]) && ($ Children = $ Item ->children ($ namespaces ['dc ' ]))) {
79
- $ item ['pubdate ' ] = $ Children ->date ;
82
+ $ item ['pubdate ' ] = (string )$ Children ->date ;
83
+ }
84
+
85
+ if (!$ item ['originUrl ' ] && isset ($ namespaces ['feedburner ' ]) && ($ Children = $ Item ->children ($ namespaces ['feedburner ' ]))) {
86
+ $ item ['originUrl ' ] = (string )$ Children ->origLink ;
80
87
}
81
88
82
89
if ($ item ['url ' ]) {
@@ -118,6 +125,7 @@ static protected function getAtomEntries (\SimpleXMLElement $Entries) {
118
125
foreach ($ Entries as $ Entry ) {
119
126
$ item = array (
120
127
'url ' => null ,
128
+ 'originUrl ' => null ,
121
129
'pubdate ' => null
122
130
);
123
131
@@ -138,6 +146,15 @@ static protected function getAtomEntries (\SimpleXMLElement $Entries) {
138
146
}
139
147
}
140
148
149
+ foreach ($ Entry ->link as $ link ) {
150
+ $ attributes = $ link ->attributes ();
151
+
152
+ if (!empty ($ attributes ->href ) && ((string )$ attributes ->rel === 'comments ' )) {
153
+ $ item ['originUrl ' ] = (string )$ attributes ->href ;
154
+ break ;
155
+ }
156
+ }
157
+
141
158
if (!$ item ['url ' ]) {
142
159
if ($ Entry ->link ) {
143
160
$ attributes = $ link ->attributes ();
Original file line number Diff line number Diff line change 74
74
<?php foreach ($ Source ->items as $ url ): ?>
75
75
<li>
76
76
<a href="<?php echo $ url ['url ' ]; ?> "><?php echo $ url ['url ' ]; ?> </a> | <a href="test.php?url=<?php echo urlencode ($ url ['url ' ]); ?> " target="_blank">Test</a><br>
77
+ <?php if ($ url ['originUrl ' ]): ?>
78
+ <a href="<?php echo $ url ['originUrl ' ]; ?> "><?php echo $ url ['originUrl ' ]; ?> </a> | <a href="test.php?url=<?php echo urlencode ($ url ['originUrl ' ]); ?> " target="_blank">Test origin Url</a><br>
79
+ <?php endif ; ?>
77
80
<time><?php echo $ url ['pubdate ' ]; ?> </time>
78
81
</li>
79
82
<?php endforeach ?>
Original file line number Diff line number Diff line change @@ -71,6 +71,7 @@ function getOption ($name, $default = null) {
71
71
</p>
72
72
<p>
73
73
<label>Facebook access token: <input type="text" name="options[facebookAccessToken]" value="<?php echo getOption ('facebookAccessToken ' ); ?> "></label><br>
74
+ <label>Embedly key: <input type="text" name="options[embedlyKey]" value="<?php echo getOption ('embedlyKey ' ); ?> "></label><br>
74
75
<label>Soundcloud client id: <input type="text" name="options[soundcloudClientId]" value="<?php echo getOption ('soundcloudClientId ' , 'YOUR_CLIENT_ID ' ); ?> "></label>
75
76
</p>
76
77
</fieldset>
You can’t perform that action at this time.
0 commit comments