-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmb.php
More file actions
172 lines (137 loc) · 5.52 KB
/
tmb.php
File metadata and controls
172 lines (137 loc) · 5.52 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
spl_autoload_register(function($c) { @include_once strtr($c, '\\_', '//').'.php'; });
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__);
use \RSSWriter\Feed;
use \RSSWriter\Channel;
use \RSSWriter\Item;
error_reporting(E_WARNING);
$username = isset($_GET['username']) ? $_GET['username'] : NULL;
$count = isset($_GET['count']) ? $_GET['count'] : 25;
$offset = isset($_GET['offset']) ? $_GET['offset'] : 0;
if (!$username)
return;
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
do
{
curl_setopt($ch, CURLOPT_URL, "https://${username}.tumblr.com/api/read/json/?start=${offset}&num=${count}");
$page = curl_exec($ch);
if ($page == FALSE)
return;
//remove JS declaration
$len = strlen($page);
$page = substr($page, 22, $len-24);
$blog = json_decode($page, true);
$posts = (object)array_merge((array)$posts, (array)$blog['posts']);
if ($count > $blog['posts-total'])
$count = $blog['posts-total'];
$offset += 50;
$count -= 50;
} while ($count >= 50);
date_default_timezone_set($blog['tumblelog']['timezone']);
$feed = new Feed();
$channel = new Channel();
$channel
->title("{$blog['tumblelog']['title']}")
->description("<img src=\"{$blog['posts'][0]['tumblelog']['avatar_url_512']}\" />" . "{$blog['tumblelog']['description']}")
->url($blog['tumblelog']['cname'] ? "https://{$blog['tumblelog']['cname']}/"
: "https://{$username}.tumblr.com")
->pubdate($blog['posts'][0]['unix-timestamp'])
->lastBuildDate(time())
->ttl(30)
->appendTo($feed);
foreach($posts as $post)
{
switch ($post['type'])
{
case 'photo':
if ($post["photo-caption"] != "")
$item_title = strip_tags($post["photo-caption"]);
else
$item_title = $post["date"];
unset($image);
if (empty($post['photos']))
$image = "<img src=\"{$post['photo-url-1280']}\" />";
else foreach($post['photos'] as $photo)
$image .= "<img src=\"{$photo['photo-url-1280']}\" />";
$item_body = $image . $post["photo-caption"];
break;
case 'audio':
if ($post['id3-title'] != "")
$item_title = $post['id3-title'];
else if ($post['audio-caption'] != "")
$item_title = $post['audio-caption'];
else
$item_title = $post["date"];
$item_body = $post['audio-player'] . $post['audio-caption'];
break;
case 'video':
if ($post["video-caption"] != "")
$item_title = strip_tags($post["video-caption"]);
else
$item_title = $post["date"];
if (strpos($post["video-player"], 'hdUrl":"'))
{
$st = strpos($post["video-player"], 'hdUrl":"') + 8;
$ed = strpos($post["video-player"], '"', $st+1);
$video = substr($post["video-player"], $st, $ed-$st);
$item_body = "<p><video width=\"100%\" controls=\"true\">
<source src=\"{$video}\"/>
</video></p>"
. $post["video-caption"];
}
else if (strpos($post["video-player"], 'src="'))
{
$st = strpos($post["video-player"], 'src="') + 5;
$ed = strpos($post["video-player"], '"', $st+1);
$video = substr($post["video-player"], $st, $ed-$st);
$item_body = "<p><video width=\"100%\" controls=\"true\">
<source src=\"{$video}\"/>
</video></p>"
. $post["video-caption"];
}
else
$item_body = $post["video-player"] . $post["video-caption"];
break;
case 'answer':
$item_title = $post['question'];
$item_body = "<blockquote>{$post['question']}</blockquote>" . $post['answer'];
break;
case 'quote':
$item_title = strip_tags($post['quote-source']);
$item_body = "<p>{$post['quote-source']}</p><blockquote>{$post['quote-text']}</blockquote>";
break;
case 'link':
$item_title = "<p>{$post['link-text']}</p>";
$item_body = "<a href=\"{$post['link-url']}\">{$post['link-text']}</a>" . $post['link-description'];
break;
case 'regular':
$item_title = $post['regular-title'] ? $post['regular-title']
: $post["date"];
$item_body = $post['regular-body'];
break;
default:
$item_title = "FIXME: {$post['type']}";
$item_body = "<b>Unknown post type: {$post['type']}</b>";
break;
}
if (strlen($item_title) > 120)
$item_title = mb_substr($item_title, 0, 120) . '…';
$item = new Item();
$item
->title($item_title)
->description("$item_body")
->author($post['reblogged-root-title'] ? $post['reblogged-root-title']
: $post['tumblelog']['title'])
->url($post['url-with-slug'])
->pubDate($post['unix-timestamp'])
->guid("{$username}/{$post['id']}", false)
->appendTo($channel);
if (isset($post['tags']))
foreach($post['tags'] as $tag)
$item->category($tag);
}
echo $feed;
?>