-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
142 lines (128 loc) · 3.95 KB
/
index.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
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
<?php
require_once('vendor/autoload.php');
if(isset($_POST['blog'])){
$blog = $_POST['blog'];
if ($blog) {
$client = new Tumblr\API\Client('XXXXXXXXX', 'XXXXXXXXX');
}
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Blog Loader</title>
<script>
document.onkeydown=function(evt){
var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
if(keyCode == 13)
{
document.bloginput.submit();
}
}
</script>
<script src="lib/sorttable.js"></script>
<link rel="stylesheet" type="text/css" href="lib/style.css">
</head>
<body class="blog-loader">
<?php include_once("../analyticstracking.php") ?>
<script>ga('send', 'pageview');</script>
<form name="bloginput" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
<input type="text" name="blog" <?php if ($blog) {?>value="<?php echo $blog; ?>" <?php } ?> />.tumblr.com
<input type="submit" value="Load" />
</form>
<?php if ($blog) { ?>
<table class="sortable">
<thead>
<th>Date</th>
<th>Post</th>
<th>Tags</th>
<th>Likes</th>
<th>Reblogs</th>
<th>Link</th>
</thead>
<tbody>
<?php
$index = 0;
$total_posts = $client->getBlogPosts($blog.'.tumblr.com', array('limit' => 1))->total_posts;
do {
try {
$posts = $client->getBlogPosts($blog.'.tumblr.com', array('offset' => $index, 'notes_info' => true))->posts;
$index += count($posts);
foreach($posts as $post) {
$likes = 0;
$reblogs = 0;
if (!empty($post->notes)) {
foreach ($post->notes as $note) {
switch ($note->type) {
case "reblog":
$reblogs++;
break;
case "like":
$likes++;
break;
}
}
}
?>
<tr>
<td><?php echo date('d/m/y', strtotime($post->date)); ?></td>
<td><?php
echo '<h2>'.$post->title.'</h2>';
switch ($post->type) {
case "quote":
echo $post->text;
break;
case "link":
echo '<a href="'.$post->url.'" target="_blank">'.$post->excerpt.'</a><br />';
echo $post->description.'<br />';
if ($post->photos) {
foreach ($post->photos as $photo) {
echo '<img src="'.$photo->alt_sizes[3]->url.'" width="'.$photo->alt_sizes[3]->width.'" height="'.$photo->alt_sizes[3]->height.'" />';
echo $photo->caption;
//print_r($photo->alt_sizes);
}
}
break;
case "answer":
echo '<a href="'.$post->asking_url.'" target="_blank">'.$post->asking_name.'</a><br />';
echo $post->question.'<br />';
echo $post->answer;
break;
case "video":
case "audio":
echo $post->caption.'<br />';
echo end($post->player)->embed_code;
break;
case "photo":
echo $post->caption.'<br />';
foreach ($post->photos as $photo) {
echo '<img src="'.$photo->alt_sizes[3]->url.'" width="'.$photo->alt_sizes[3]->width.'" height="'.$photo->alt_sizes[3]->height.'" />';
echo $photo->caption;
//print_r($photo->alt_sizes);
}
break;
case "text":
case "chat":
echo $post->body;
break;
}
?></td>
<td><?php
foreach ($post->tags as $tag) {
echo '<a href="http://www.tumblr.com/tagged/'.$tag.'" target="_blank">'.$tag.'</a> ';
}?></td>
<td><?php echo $reblogs; ?></td>
<td><?php echo $likes; ?></td>
<td><a href="<?php echo $post->post_url; ?>" target="_blank">link</a></td>
</tr>
<?php }
} catch (Exception $e) { ?>
<p>Is the blog name correct?</p>
<?php }
} while ($index < $total_posts);?>
</tbody>
</table>
<?php } ?>
</body>
</html>