-
Notifications
You must be signed in to change notification settings - Fork 0
/
backtype.plugin.php
61 lines (57 loc) · 1.91 KB
/
backtype.plugin.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
<?php
/**
* Backtype Connect
*/
class BacktypePlugin extends Plugin
{
public function filter_post_comments(Comments $comments, Post $post) {
$url = Site::get_url('habari', true) . $post->slug;
foreach (self::fetch_backtype($url) as $new) {
$comments[] = $new;
}
return $comments;
}
protected static function fetch_backtype($url) {
$backtype = array();
$cacheName = "backtype-$url";
if ( Cache::has( $cacheName ) ) {
foreach (Cache::get( $cacheName ) as $cachedBacktype) {
$cachedBacktype->date = HabariDateTime::date_create($cachedBacktype->date);
$backtype[] = $cachedBacktype;
}
return $backtype;
}
$connectData = json_decode(file_get_contents("http://api.backtype.com/comments/connect.json?url={$url}&key=key&itemsperpage=10000"));
if (isset($connectData->comments)) {
foreach ($connectData->comments as $dat) {
$comment = new StdClass;
switch ($dat->entry_type) {
case 'tweet':
$comment->id = 'backtype-twitter-' . $dat->tweet_id;
$comment->url = 'http://twitter.com/' . $dat->tweet_from_user . '/status/' . $dat->tweet_id;
$comment->name = '@' . $dat->tweet_from_user . ' (via Backtype: Twitter)';
$comment->content_out = InputFilter::filter($dat->tweet_text);
$comment->date = $dat->tweet_created_at;
break;
case 'comment':
$comment->id = 'backtype-comment-' . $dat->comment->id;
$comment->url = $dat->comment->url;
$comment->name = $dat->author->name . ' (via Backtype: ' . InputFilter::filter($dat->blog->title) . ')';
$comment->content_out = InputFilter::filter($dat->comment->content);
$comment->date = $dat->comment->date;
break;
}
if (!$comment) {
continue;
}
$comment->status = Comment::STATUS_APPROVED;
$comment->type = Comment::TRACKBACK;
$comment->email = null;
$backtype[] = $comment;
}
}
Cache::set( $cacheName, $backtype );
return $backtype;
}
}
?>