Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify link detection, discovers links in RDF feeds too. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions src/p3k/WebSub/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,13 @@ public function discover($url, $headfirst=true, $verbose=false) {
$type = $body['type'] = 'rss';
} elseif($xpath->query('/atom:feed')->length) {
$type = $body['type'] = 'atom';
} elseif($xpath->query('/rdf:RDF')->length) {
$type = $body['type'] = 'rdf';
}

// Look for atom link elements in the feed
foreach($xpath->query('/atom:feed/atom:link[@href]') as $link) {
$rel = $link->getAttribute('rel');
$url = $link->getAttribute('href');
if($rel == 'hub') {
$body['hub'][] = $url;
} else if($rel == 'self') {
$body['self'][] = $url;
}
}

// Some RSS feeds include the link element as an atom attribute
foreach($xpath->query('/rss/channel/atom:link[@href]') as $link) {
// Find all link elements in the feed.
$links = $dom->getElementsByTagName('link');
foreach ($links as $link) {
$rel = $link->getAttribute('rel');
$url = $link->getAttribute('href');
if($rel == 'hub') {
Expand Down Expand Up @@ -213,7 +205,7 @@ public function unsubscribe($hub, $topic, $callback) {
}

public static function verify_signature($body, $signature_header, $secret) {
if($signature_header && is_string($signature_header)
if($signature_header && is_string($signature_header)
&& preg_match('/(sha(?:1|256|384|512))=(.+)/', $signature_header, $match)) {
$alg = $match[1];
$sig = $match[2];
Expand Down