-
Notifications
You must be signed in to change notification settings - Fork 0
/
fb.php
260 lines (222 loc) · 9.36 KB
/
fb.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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<?php
require('facebook-php-sdk/src/facebook.php'); // require your facebook php sdk
include("feed_generator/FeedWriter.php"); // include the feed generator feedwriter file
require_once( './config.php' );
$user_id = $fb_user_id;
$limit = 40;
$apiurl= 'https://graph.facebook.com/'.$user_id.'/feed/?limit='.$limit.'&locale=de&access_token='.$oauth_token;
$timeout = 15;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiurl);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout );
$output = curl_exec($ch);
curl_close($ch);
$rawData = trim($output);
// OK?
$response = json_decode($rawData, true);
//print_r($response);
// create the feedwriter object (we're using ATOM but there're other options like rss, etc)
$feed = new FeedWriter(ATOM);
$feed->setTitle($user_name.'s Facebook Stream'); // set your title
$feed->setLink('http://'.$_SERVER['SERVER_NAME'].$_SERVER["SCRIPT_NAME"]); // set the url to the feed page you're generating
$feed->setChannelElement('updated', date(DATE_ATOM , time()));
$feed->setChannelElement('author', array('name'=>$user_name)); // set the author name
// iterate through the facebook response to add items to the feed
foreach($response['data'] as $entry){
if(isset($entry["id"])){
if (
($entry['application']['name'] != "Twitter") // no tweets
AND ($entry['application']['namespace'] != "rssgraffiti") // no blog stuff
AND ($entry['application']['namespace'] != "ifthisthenthat") // no instagrams and ifttt
AND ($entry['status_type'] != "approved_friend") // no new friend anouncements
AND ( ($entry['privacy']['value'] == "") OR ($entry['privacy']['value'] == "EVERYONE") ) // privacy OK? is it public?
AND ($entry['from']['name'] == $user_name) // only own stuff $user_namestuff
) {
$item = $feed->createNewItem();
// is there a link? if not, link fb-post
if (isset($entry["link"])) {
$link = htmlentities($entry["link"]);
$item->setLink($link);
} else {
$id = substr(strstr($entry['id'], '_'),1);
$link = "https://www.facebook.com/$user_id/posts/".$id;
$item->setLink($link);
}
$id = substr($entry['id'], 10);
$facebooklink = "https://www.facebook.com/$user_id/posts/".$id;
$item->addElement('facebooklink', $facebooklink, '');
$image = $entry['picture'];
$parse_image_url = parse_url($image);
if (
($image!='')
AND ($parse_image_url['host'] != "s-platform.ak.fbcdn.net")
) {
// _s. und _q. -> _n. (normalgrosses bild)
$image = str_replace( '_s.', '_n.', $image );
$image = str_replace( '_q.', '_n.', $image );
// $image_html = '<div class="fbimage"><img src="'.$image.'" alt="'.$entry["caption"].'"></div>';
$image_html = '<div class="fbimage"><img src="'.$image.'"></div>';
} else {
$image_html = '';
}
// use date as title
// $item->setTitle(gmdate( 'd.m.Y H:i', strtotime($entry["created_time"])) );
$item->setDate($entry["created_time"]);
// defaults
$description = "";
// message?
if (isset($entry["message"])) {
// $description = '<blockquote class="fbmessage">'.$entry["message"].'</blockquote>';
$description = '<div class="fbmessage"><a href="'.$link.'">'.$entry["message"].'</a></div>';
}
$description .= $image_html
. '<div class="clearfix fbname"><a href="'.$link.'">'.$entry["name"].'</a></div>';
if (isset($entry["caption"])) {
$description .= '<blockquote class="clearfix fbcaption">'.$entry["caption"].'</blockquote>';
}
$title = $entry['message'];
// description?
if (isset($entry["description"])) {
$description .= '<blockquote>'.$entry["description"].'</blockquote>';
}
// story? rebuid description and title
if ($entry["story"] != "") {
$description = '<a href="'.$link.'">'.$entry["story"].'</a>';
if (isset($entry["message"])) {
$description .= '<blockquote>'.$entry["message"].'</blockquote>';
}
$description .= $image_html
. '<div class="clearfix fbname"><a href="'.$link.'">'.$entry["name"].'</a></div>';
if (isset($entry['properties'])) {
// $description .= '<a href="'.$entry['properties'][0]['href'].'">'.$entry['properties'][0]['name'].' '.$entry['properties'][0]['text'].'</a>:<br />';
$description .= '<a href="'.$entry['properties'][0]['href'].'">'.$entry['properties'][0]['text'].'</a><br />';
}
if (isset($entry["caption"])) {
$description .= '<div class="clearfix fbcaption">'.$entry["caption"].'</div>';
}
if (isset($entry["description"])) {
$description .= '<blockquote class="fbdescription">'.$entry["description"].'</blockquote>';
}
$title = $entry['story'];
}
if ($title=='') { $title='Aktivität auf Facebook';}
$item->setTitle(text_add_more(text_excerpt($title, 50, 0, 1, 0),' …', ''));
if ($entry['application']['name']=='Likes') {
// likes?
if ($entry['name']!="") {
$entry_name = $entry['name'];
} else {
$entry_name = "mehrere Dinge."; // manchmal liefert fb nix (nochmal id checken?)
}
$description = $user_name . ' mochte <a href="'.$link.'">'.$entry_name.'</a>';
$description .= $image_html
. '<div class="clearfix fbcaption">'.$entry["caption"].'</div>';
if (isset($entry["description"])) {
$description .= '<blockquote>'.$entry["description"].'</blockquote>';
}
$item->addElement('category', "likes");
}
elseif ($entry["type"]=='status') {
// no story?
if ($entry["story"] == "") {
$description = "";
if (isset($entry["message"])) {
// $description = '<blockquote>'.$entry["message"].'</blockquote>';
// $description = '<blockquote><a href="'.$link.'">'.$entry["message"].'</a></blockquote>';
$description = '<a href="'.$link.'">'.$entry["message"].'</a>';
}
$description .= $image_html
. '<div class="clearfix fbname"><a href="'.$link.'">'.$entry["name"].'</a></div>'
. '<div class="clearfix fbcaption">'.$entry["caption"].'</div>';
if (isset($entry["description"])) {
$description .= '<blockquote>'.$entry["description"].'</blockquote>';
}
} else {
// story?
$description = '<a href="'.$link.'">'.$entry["story"].'</a>';
if (isset($entry["message"])) {
$description = '<blockquote>'.$entry["message"].'</blockquote>';
}
$description .= $image_html
. '<div class="clearfix fbname"><a href="'.$link.'">'.$entry["name"].'</a></div>';
if (isset($entry["caption"])) {
$description .= '<blockquote class="clearfix fbcaption">'.$entry["caption"].'</blockquote>';
}
if (isset($entry["description"])) {
$description .= '<blockquote>'.$entry["description"].'</blockquote>';
}
$item->addElement('category', "links");
}
}
$item->setDescription($description);
$item->addElement('guid', $entry["id"]);
$feed->addItem($item);
}
}
}
// that's it... don't echo anything else, just call this method
$feed->genarateFeed();
function text_excerpt($text, $length, $use_words, $finish_word, $finish_sentence)
{
$tokens = array();
$out = '';
$w = 0;
// Divide the string into tokens; HTML tags, or words, followed by any whitespace
// (<[^>]+>|[^<>\s]+\s*)
preg_match_all('/(<[^>]+>|[^<>\s]+)\s*/u', $text, $tokens);
foreach ($tokens[0] as $t)
{ // Parse each token
if ($w >= $length && !$finish_sentence)
{ // Limit reached
break;
}
if ($t[0] != '<')
{ // Token is not a tag
if ($w >= $length && $finish_sentence && preg_match('/[\?\.\!]\s*$/uS', $t) == 1)
{ // Limit reached, continue until ? . or ! occur at the end
$out .= trim($t);
break;
}
if (1 == $use_words)
{ // Count words
$w++;
} else
{ // Count/trim characters
$chars = trim($t); // Remove surrounding space
$c = strlen($chars);
if ($c + $w > $length && !$finish_sentence)
{ // Token is too long
$c = ($finish_word) ? $c : $length - $w; // Keep token to finish word
$t = substr($t, 0, $c);
}
$w += $c;
}
}
// Append what's left of the token
$out .= $t;
}
return trim(strip_tags($out));
}
function text_add_more($text, $ellipsis, $read_more)
{
// New filter in WP2.9, seems unnecessary for now
//$ellipsis = apply_filters('excerpt_more', $ellipsis);
if ($read_more)
$ellipsis .= sprintf(' <a href="%s" class="read_more">%s</a>', get_permalink(), $read_more);
$pos = strrpos($text, '</');
if ($pos !== false)
// Inside last HTML tag
$text = substr_replace($text, $ellipsis, $pos, 0);
else
// After the content
$text .= $ellipsis;
return $text;
}
function SimpleRssFeedsWidget_Widget_desc_Register()
{
load_plugin_textdomain( 'simplerssfeedswidgetdesc', false, dirname( plugin_basename( __FILE__ ) ) );
return register_widget( "SimpleRssFeedsWidget_Widget_desc" );
}