1 | <?php |
||
15 | class Parser extends ParserBase |
||
16 | { |
||
17 | /** |
||
18 | * @var \s9e\TextFormatter\Utils\Http\Client Client used to perform HTTP request |
||
19 | */ |
||
20 | protected static $client; |
||
21 | |||
22 | /** |
||
23 | * {@inheritdoc} |
||
24 | */ |
||
25 | 398 | public function parse($text, array $matches) |
|
38 | |||
39 | /** |
||
40 | * Filter a MEDIA tag |
||
41 | * |
||
42 | * This will always invalidate the original tag, and possibly replace it with the tag that |
||
43 | * corresponds to the media site |
||
44 | * |
||
45 | * @param Tag $tag The original tag |
||
46 | * @param TagStack $tagStack Parser instance, so that we can add the new tag to the stack |
||
47 | * @param array $hosts Map of [hostname => siteId] |
||
48 | * @param array $sites Map of [siteId => siteConfig] |
||
49 | * @param string|null $cacheDir Path to the cache directory |
||
50 | * @return void |
||
51 | */ |
||
52 | 400 | public static function filterTag(Tag $tag, TagStack $tagStack, array $hosts, array $sites, $cacheDir) |
|
71 | |||
72 | /** |
||
73 | * Add named captures from a set of regular expressions to a set of attributes |
||
74 | * |
||
75 | * @param array &$attributes Associative array of strings |
||
76 | * @param string $string Text to match |
||
77 | * @param array[] $regexps List of [regexp, map] pairs |
||
78 | * @return bool Whether any regexp matched |
||
79 | */ |
||
80 | 397 | protected static function addNamedCaptures(array &$attributes, $string, array $regexps) |
|
97 | |||
98 | /** |
||
99 | * Create a tag for a media embed |
||
100 | * |
||
101 | * @param string $tagName Tag's name |
||
102 | * @param TagStack $tagStack |
||
103 | * @param Tag $tag Reference tag |
||
104 | * @return Tag New tag |
||
105 | */ |
||
106 | 370 | protected static function createTag($tagName, TagStack $tagStack, Tag $tag) |
|
125 | |||
126 | /** |
||
127 | * Return a set of attributes for given URL based on a site's config |
||
128 | * |
||
129 | * @param string $url Original URL |
||
130 | * @param array $config Site config |
||
131 | * @param string|null $cacheDir Path to the cache directory |
||
132 | * @return array Associative array of attributes |
||
133 | */ |
||
134 | 397 | protected static function getAttributes($url, array $config, $cacheDir) |
|
145 | |||
146 | /** |
||
147 | * Return a cached instance of the HTTP client |
||
148 | * |
||
149 | * @param string|null $cacheDir |
||
150 | * @return \s9e\TextFormatter\Utils\Http\Client |
||
151 | */ |
||
152 | 61 | protected static function getHttpClient($cacheDir) |
|
161 | |||
162 | /** |
||
163 | * Return the siteId that corresponds to given URL |
||
164 | * |
||
165 | * @param string $url Original URL |
||
166 | * @param array $hosts Map of [hostname => siteId] |
||
167 | * @return string URL's siteId, or an empty string |
||
168 | */ |
||
169 | 400 | protected static function getSiteIdFromUrl($url, array $hosts) |
|
183 | |||
184 | /** |
||
185 | * Interpolate {@vars} in given string |
||
186 | * |
||
187 | * @param string $str Original string |
||
188 | * @param array $vars Associative array |
||
189 | * @return string Interpolated string |
||
190 | */ |
||
191 | 18 | protected static function interpolateVars($str, array $vars) |
|
202 | |||
203 | /** |
||
204 | * Scrape values and add them to current attributes |
||
205 | * |
||
206 | * @param array &$attributes Attributes |
||
207 | * @param string|null $cacheDir Path to the cache directory |
||
208 | * @param string $url Original URL |
||
209 | * @param array $config Scraping config |
||
210 | * @return void |
||
211 | */ |
||
212 | 135 | protected static function scrape(array &$attributes, $url, array $config, $cacheDir) |
|
227 | |||
228 | /** |
||
229 | * Retrieve external content |
||
230 | * |
||
231 | * @param string $url URL |
||
232 | * @param string|null $cacheDir Path to the cache directory |
||
233 | * @return string External content |
||
234 | */ |
||
235 | 61 | protected static function wget($url, $cacheDir) |
|
239 | } |