-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-feed-parser.php
96 lines (90 loc) · 2.91 KB
/
class-feed-parser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* Friends Feed Parser
*
* This contains the reference implementation for a parser.
*
* @package Friends
*/
namespace Friends;
/**
* This class describes a friends feed parser.
*/
abstract class Feed_Parser {
/**
* Determines if this is a supported feed and to what degree we feel it's supported.
*
* @param string $url The url.
* @param string $mime_type The mime type.
* @param string $title The title.
* @param string|null $content The content, it can't be assumed that it's always available.
*
* @return int Return 0 if unsupported, a positive value representing the confidence for the feed, use 10 if you're reasonably confident.
*/
public function feed_support_confidence( $url, $mime_type, $title, $content = null ) {
return 0;
}
/**
* Allow augmenting or modifying the details of a feed.
*
* The incoming $feed_details array looks like this:
*
* $feed_details = array(
* 'url' => 'https://url.of/the/feed',
* 'title' => 'Title from the <link> tag if any',
* 'mime-type' => 'mime-type from the <link> tag if any',
* // You can add these fields in the response:
* 'autoselect' => true|false,
* 'post-format' => 'standard', // or 'aside', etc. see get_post_format_strings() of WordPress core
* );
*
* @param array $feed_details The feed details.
*
* @return array The (potentially) modified feed details.
*/
public function update_feed_details( $feed_details ) {
return $feed_details;
}
/**
* Discover the feeds available at the URL specified.
*
* The content for the URL has already been fetched for you which can be analyzed.
*
* Return an array of supported feeds in the format of the $feed_details above:
*
* return array(
* array(
* 'url' => 'https://url.of/the/feed',
* 'title' => 'Title for the feed',
* 'mime-type' => 'mime-type for the feed',
* 'rel' => 'e.g. alternate',
* ),
* );
*
* @param string $content The content for the URL is already provided here.
* @param string $url The url to search.
*
* @return array A list of supported feeds at the URL.
*/
public function discover_available_feeds( $content, $url ) {
return array();
}
/**
* Convert relative URLs to absolute ones in incoming content.
*
* @param string $html The html.
* @param string $url The url of the feed.
*
* @return string The HTML with URLs replaced to their absolute represenation.
*/
public function convert_relative_urls_to_absolute_urls( $html, $url ) {
// For now this only converts links and image srcs.
return preg_replace_callback(
'~(src|href)=(?:"([^"]+)|\'([^\']+))~i',
function ( $m ) use ( $url ) {
return str_replace( $m[2], Mf2\resolveUrl( $url, $m[2] ), $m[0] );
},
$html
);
}
}