forked from gjedeer/ttrss-af_nofacebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.php
80 lines (64 loc) · 1.65 KB
/
init.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
<?php
class Af_Nofacebook extends Plugin {
private $host;
function about() {
return array(1.0,
"Remove facebook redirects",
"GDR!",
false);
}
function init($host) {
$this->host = $host;
$host->add_hook($host::HOOK_RENDER_ARTICLE, $this);
}
function hook_render_article($article) {
$article["content"] = $this->replace_facebook_redirects($article["content"]);
$article["link"] = $this->replace_facebook_redirects($article["link"]);
return $article;
}
function api_version() {
return 2;
}
function decode_facebook_url($url_str)
{
$url = parse_url($url_str);
if($url['host'] == 'www.facebook.com' || $url['host'] == 'facebook.com' || $url['host'] == 'l.facebook.com')
{
if($url['path'] == '/l.php')
{
$query = array();
parse_str($url['query'], $query);
if(isset($query['u']))
{
return $query['u'];
}
}
}
return false;
}
function replace_facebook_redirects($html)
{
preg_match_all('#http(s?)://((www|l)\.?)facebook\.com/l\.php[^\s"\']+#', $html, $matches);
foreach($matches[0] as $url_str)
{
$html_mode = false;
if(strpos($url_str, '&') !== false)
{
$html_mode = true;
$fb_url = htmlspecialchars_decode($url_str);
}
else
{
$fb_url = $url_str;
}
$url = $this->decode_facebook_url($fb_url);
if($html_mode)
{
$url = htmlspecialchars($url);
}
$html = str_replace($url_str, $url, $html);
}
return $html;
}
}
?>