PluginProbe
Friends / 2.8.7
Friends v2.8.7
4.3.2 4.3.1 4.3.0 4.2.2 4.2.1 4.2.0 4.1.0 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.0 2.9.1 All 88 releases
friends / feed-parsers / class-feed-parser.php

class-feed-parser.php in Friends 2.8.7, at feed-parsers/class-feed-parser.php

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