-
Notifications
You must be signed in to change notification settings - Fork 1
/
extension.php
40 lines (31 loc) · 949 Bytes
/
extension.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
<?php
class RedditSubExtension extends Minz_Extension
{
public function init()
{
Minz_View::appendStyle($this->getFileUrl('style.css', 'css'));
$this->registerHook('entry_before_display', array($this, 'renderEntry'));
}
protected function isRedditLink($entry)
{
return (bool) strpos($entry->link(), 'reddit.com');
}
protected function extractSubreddit($content)
{
$match_url = '#<a href="https://www.reddit.com/r/.*"> (.*) </a>#';
if ( preg_match($match_url, $content, $matches) )
{
return $matches[1];
}
}
public function renderEntry($entry)
{
if (false === $this->isRedditLink($entry))
{
return $entry;
}
$sub = $this->extractSubreddit( $entry->content() );
$entry->_title( "<span class='subreddit_name'>$sub</span> " . $entry->title() );
return $entry;
}
}