Recent Facebook Posts - Version 1.2.2

Version Description

Download this release

Release Info

Developer DvanKooten
Plugin Icon wp plugin Recent Facebook Posts
Version 1.2.2
Comparing to
See all releases

Code changes from version 1.1 to 1.2.2

classes/class-rfb-admin.php CHANGED
@@ -51,35 +51,44 @@ class RFB_Admin {
51
 
52
  $opts = $this->RFB->get_options();
53
  $curl = extension_loaded('curl');
54
- $fb = $this->RFB->get_fb_instance();
55
  //update_option('rfb_access_token', '');
56
  $access_token = get_option('rfb_access_token');
57
  $connected = false;
58
 
59
- // try to fetch a test post
60
- if($curl && $access_token) {
61
- $fb->setAccessToken($access_token);
62
-
63
- $connected = $fb->getUser();
64
-
65
- if($connected) {
66
- try {
67
- $try = $fb->api('/' . $opts['fb_id'] . '/posts?limit=1');
68
- } catch(Exception $e) {
69
- $connected = false;
70
- $error = $e;
 
 
 
 
 
71
  }
72
  }
 
73
  }
74
 
 
75
  // check if cache directory is writable
76
  $cache_dir = dirname(__FILE__) . '/../cache/';
77
  $cache_file = dirname(__FILE__) . '/../cache/posts.cache';
78
 
79
- if(!is_writable($cache_dir)) {
 
 
80
  $cache_error = 'The cache directory (<i>'. ABSPATH . 'wp-content/plugins/recent-facebook-posts/cache/</i>) is not writable.';
81
  } elseif(file_exists($cache_file) && !is_writable($cache_file)) {
82
- $cache_error = 'The cache directory (<i>'. ABSPATH . 'wp-content/plugins/recent-facebook-posts/cache/posts.cache</i>) exists but is not writable.';
83
  }
84
 
85
 
51
 
52
  $opts = $this->RFB->get_options();
53
  $curl = extension_loaded('curl');
54
+
55
  //update_option('rfb_access_token', '');
56
  $access_token = get_option('rfb_access_token');
57
  $connected = false;
58
 
59
+ if($curl) {
60
+
61
+ $fb = $this->RFB->get_fb_instance();
62
+
63
+ if($access_token) {
64
+
65
+ $fb->setAccessToken($access_token);
66
+ $connected = $fb->getUser();
67
+
68
+ if($connected) {
69
+ // try to fetch a test pos
70
+ try {
71
+ $try = $fb->api('/' . $opts['fb_id'] . '/posts?limit=1');
72
+ } catch(Exception $e) {
73
+ $connected = false;
74
+ $error = $e;
75
+ }
76
  }
77
  }
78
+
79
  }
80
 
81
+
82
  // check if cache directory is writable
83
  $cache_dir = dirname(__FILE__) . '/../cache/';
84
  $cache_file = dirname(__FILE__) . '/../cache/posts.cache';
85
 
86
+ if(!file_exists($cache_dir)) {
87
+ $cache_error = 'The cache directory (<i>'. ABSPATH . 'wp-content/plugins/recent-facebook-posts/cache/</i>) does not exist.';
88
+ } elseif(!is_writable($cache_dir)) {
89
  $cache_error = 'The cache directory (<i>'. ABSPATH . 'wp-content/plugins/recent-facebook-posts/cache/</i>) is not writable.';
90
  } elseif(file_exists($cache_file) && !is_writable($cache_file)) {
91
+ $cache_error = 'The cache file (<i>'. ABSPATH . 'wp-content/plugins/recent-facebook-posts/cache/posts.cache</i>) exists but is not writable.';
92
  }
93
 
94
 
classes/class-rfb-widget.php CHANGED
@@ -109,7 +109,24 @@ class RFB_Widget extends WP_Widget {
109
  ?>
110
  <li>
111
  <p class="rfb_text"><?php echo nl2br(make_clickable($content)); if($shortened) echo '..'; ?></p>
112
- <?php if(isset($post['image']) && $post['image']) { ?><p class="rfb_image"><a target="_blank" href="<?php echo $post['link']; ?>" rel="nofollow"><img src="<?php echo $post['image']; ?>" alt="" /></a></p><?php } ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  <p><a target="_blank" class="rfb_link" href="<?php echo $post['link']; ?>" rel="nofollow">
114
  <?php if($show_like_count || $show_comment_count) { ?><span class="like_count_and_comment_count"><?php } ?>
115
  <?php if($show_like_count) { ?><span class="like_count"><?php echo $post['like_count']; ?> <span>likes</span></span> <?php } ?>
@@ -130,7 +147,7 @@ class RFB_Widget extends WP_Widget {
130
  </ul>
131
 
132
  <?php if($show_link) { ?>
133
- <p><a href="http://www.facebook.com/<?php echo $opts['fb_id']; ?>/" rel="external nofollow"><?php echo strip_tags($opts['link_text']); ?></a>.</p>
134
  <?php } ?>
135
 
136
  <?php
109
  ?>
110
  <li>
111
  <p class="rfb_text"><?php echo nl2br(make_clickable($content)); if($shortened) echo '..'; ?></p>
112
+ <?php
113
+ if($opts['img_size'] != 'dont_show' && isset($post['image']) && $post['image']) {
114
+
115
+ if(isset($post['type']) && $post['type'] == 'photo') {
116
+ $img_atts = "src=\"{$post['image']}?type={$opts['img_size']}\" style=\"max-height: {$opts['img_height']}px;\"";
117
+ } else {
118
+ $img_atts = "src=\"{$post['image']}\" style=\"\"";
119
+ }
120
+ ?>
121
+ <p class="rfb_image">
122
+ <a target="_blank" href="<?php echo $post['link']; ?>" rel="nofollow">
123
+
124
+ <img <?php echo $img_atts; ?> alt="" />
125
+ </a>
126
+ </p>
127
+ <?php } ?>
128
+
129
+
130
  <p><a target="_blank" class="rfb_link" href="<?php echo $post['link']; ?>" rel="nofollow">
131
  <?php if($show_like_count || $show_comment_count) { ?><span class="like_count_and_comment_count"><?php } ?>
132
  <?php if($show_like_count) { ?><span class="like_count"><?php echo $post['like_count']; ?> <span>likes</span></span> <?php } ?>
147
  </ul>
148
 
149
  <?php if($show_link) { ?>
150
+ <p><a href="http://www.facebook.com/<?php echo $opts['fb_id']; ?>/" rel="external nofollow" <?php if($opts['link_new_window']) { ?>target="_blank"<?php } ?>><?php echo strip_tags($opts['link_text']); ?></a>.</p>
151
  <?php } ?>
152
 
153
  <?php
classes/class-rfb.php CHANGED
@@ -10,7 +10,11 @@ class RFB {
10
  'fb_id' => 'DannyvanKootenCOM',
11
  'cache_time' => 1800,
12
  'load_css' => 0,
13
- 'link_text' => 'Find us on Facebook'
 
 
 
 
14
  );
15
  private $options;
16
 
@@ -54,38 +58,44 @@ class RFB {
54
  return $this->options;
55
  }
56
 
57
- public function renew_access_token() {
58
- // only run if this is an administrator.
 
59
  $user = wp_get_current_user();
60
-
61
  if(!user_can($user, 'manage_options')) return false;
62
 
 
 
 
 
63
  $fb = $this->get_fb_instance();
64
 
65
  // Get Facebook User ID
66
  $fb_user = $fb->getUser();
67
 
68
- if(!$fb_user) {
69
 
70
- if(!headers_sent()) {
71
- header("Location: ".$fb->getLoginUrl(array('redirect_uri' => get_admin_url() . '?rfb_renew_access_token')));
72
- exit;
73
- } else {
74
- echo '<script type="text/javascript">window.location = \''. $fb->getLoginUrl(array('redirect_uri' => get_admin_url() . '?rfb_renew_access_token')) .'\';</script>';
75
- exit;
76
- }
77
  }
78
 
79
- return;
80
  }
81
 
82
  public function get_fb_instance() {
83
  if(!self::$fb_instance) {
 
84
  require dirname(__FILE__) . '/facebook-php-sdk/facebook.php';
 
85
  $opts = $this->get_options();
 
86
  self::$fb_instance = new Facebook(array(
87
- 'appId' => $opts['app_id'],
88
- 'secret' => $opts['app_secret'],
89
  ));
90
  }
91
  return self::$fb_instance;
@@ -96,8 +106,8 @@ class RFB {
96
  $opts = $this->get_options();
97
 
98
  // check if cache file exists
99
- // check if cache file is exists for longer then the given expiration time
100
- if(!file_exists($cache_file) || (filemtime($cache_file) < (time() - $opts['cache_time']))) {
101
  $this->renew_cache_file();
102
 
103
  if(!file_exists($cache_file)) return array();
@@ -112,8 +122,8 @@ class RFB {
112
  if(empty($opts['app_id']) || empty($opts['fb_id'])) return false;
113
 
114
  $access_token = get_option('rfb_access_token');
115
- if(!$access_token) {
116
 
 
117
  $access_token = $this->renew_access_token();
118
  if(!$access_token) return false;
119
  }
@@ -123,43 +133,84 @@ class RFB {
123
 
124
  if(!$fb->getUser()) return false;
125
 
126
- $apiResult = $fb->api($opts['fb_id'].'/posts', "GET", array(
127
- 'limit' => 250
128
- )
129
- );
130
 
131
  if(!$apiResult or !is_array($apiResult) or !isset($apiResult['data']) or !is_array($apiResult['data'])) { return false; }
132
 
133
  $data = array();
134
  foreach($apiResult['data'] as $p) {
135
- if(!isset($p['message']) || empty($p['message'])) continue;
 
 
 
 
 
 
 
136
 
137
  //split user and post ID (userID_postID)
138
  $idArray = explode("_", $p['id']);
139
 
140
  $post = array();
 
141
  $post['author'] = $p['from'];
142
- $post['content'] = $p['message'];
143
 
144
 
 
145
  if($p['type'] == 'photo') {
146
- $post['image'] = $p['picture'];
 
 
 
 
147
  } else {
148
  $post['image'] = null;
149
  }
150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  $post['timestamp'] = strtotime($p['created_time']);
152
- $post['like_count'] = (isset($p['likes'])) ? $p['likes']['count'] : 0;
153
- $post['comment_count'] = (isset($p['comments'])) ? $p['comments']['count'] : 0;
154
  $post['link'] = "http://www.facebook.com/".$opts['fb_id']."/posts/".$idArray[1];
155
  $data[] = $post;
156
 
157
  }
158
 
159
  $data = json_encode($data);
 
160
  $cache_file = dirname(__FILE__) . '/../cache/posts.cache';
161
 
162
- if(!is_writable(dirname(__FILE__) . '/../cache/')) return false;
 
 
 
 
 
 
 
 
163
 
164
  file_put_contents($cache_file, $data);
165
 
@@ -175,10 +226,12 @@ class RFB {
175
  'excerpt_length' => 140
176
  ), $atts));
177
 
 
178
  $posts = $this->get_posts();
179
  $posts = array_slice($posts, 0, $number);
180
 
181
  $output = '<div class="recent-facebook-posts rfb_posts shortcode">';
 
182
  foreach($posts as $post) {
183
  $content = $post['content'];
184
  $shortened = false;
@@ -194,15 +247,23 @@ class RFB {
194
 
195
  $output .= '<div class="rfb-post">';
196
  $output .= '<p class="rfb_text">'. nl2br(make_clickable($content));
197
- if ($shortened) $output .= '..';
198
  $output .= '</p>';
199
- if(isset($post['image']) && $post['image']) {
200
- $output .= '<p class="rfb_image"><a target="_blank" href="'. $post['link'] . '" rel="nofollow"><img src="'. $post['image'] . '" alt="" /></a></p>';
 
 
 
 
 
 
 
201
  }
 
202
  $output .= '<p><a target="_blank" class="rfb_link" href="'. $post['link'] .'" rel="nofollow">';
203
  if($likes || $comments) { $output .= '<span class="like_count_and_comment_count">'; }
204
- if($likes) { $output .= '<span class="like_count">'. $post['like_count'] . ' <span>likes</span></span>'; }
205
- if($comments) { $output .= '<span class="comment_count">' . $post['comment_count'] . ' <span>comments</span></span>'; }
206
  if($likes || $comments) { $output .= '</span>'; }
207
  $output .= '<span class="timestamp" title="'. date('l, F j, Y', $post['timestamp']) . ' at ' . date('G:i', $post['timestamp']) . '" >';
208
  if($likes || $comments) { $output .= ' · '; }
@@ -241,7 +302,28 @@ class RFB {
241
 
242
  $value = floor($diff/$intervals[1][1]);
243
  return $value.' '.$intervals[1][0].($value > 1 ? 's' : '').' ago';
244
-
245
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
 
247
  }
10
  'fb_id' => 'DannyvanKootenCOM',
11
  'cache_time' => 1800,
12
  'load_css' => 0,
13
+ 'link_text' => 'Find us on Facebook',
14
+ 'link_new_window' => 0,
15
+ 'img_size' => 'thumbnail',
16
+ 'img_width' => 100,
17
+ 'img_height' => 100
18
  );
19
  private $options;
20
 
58
  return $this->options;
59
  }
60
 
61
+ public function renew_access_token($redirect_uri = null) {
62
+
63
+ // only renew when the visitor is an administrator
64
  $user = wp_get_current_user();
 
65
  if(!user_can($user, 'manage_options')) return false;
66
 
67
+ if(!$redirect_uri) {
68
+ $redirect_uri = get_admin_url() . '?rfb_renew_access_token';
69
+ }
70
+
71
  $fb = $this->get_fb_instance();
72
 
73
  // Get Facebook User ID
74
  $fb_user = $fb->getUser();
75
 
76
+ $location = $fb->getLoginUrl(array('redirect_uri' => $redirect_uri));
77
 
78
+ if(!headers_sent()) {
79
+ header("Location: $location");
80
+ exit;
81
+ } else {
82
+ echo '<script type="text/javascript">window.location = \''. $location .'\';</script>';
83
+ exit;
 
84
  }
85
 
86
+ return ;
87
  }
88
 
89
  public function get_fb_instance() {
90
  if(!self::$fb_instance) {
91
+
92
  require dirname(__FILE__) . '/facebook-php-sdk/facebook.php';
93
+
94
  $opts = $this->get_options();
95
+
96
  self::$fb_instance = new Facebook(array(
97
+ 'appId' => trim($opts['app_id']),
98
+ 'secret' => trim($opts['app_secret']),
99
  ));
100
  }
101
  return self::$fb_instance;
106
  $opts = $this->get_options();
107
 
108
  // check if cache file exists
109
+ // check if cache file exists for longer then the given expiration time
110
+ if(!file_exists($cache_file) || ($this->get_time_of_last_file_change($cache_file) < (time() - $opts['cache_time']))) {
111
  $this->renew_cache_file();
112
 
113
  if(!file_exists($cache_file)) return array();
122
  if(empty($opts['app_id']) || empty($opts['fb_id'])) return false;
123
 
124
  $access_token = get_option('rfb_access_token');
 
125
 
126
+ if(!$access_token) {
127
  $access_token = $this->renew_access_token();
128
  if(!$access_token) return false;
129
  }
133
 
134
  if(!$fb->getUser()) return false;
135
 
136
+ $apiResult = $fb->api(trim($opts['fb_id']) . '/posts?with=message&limit=250');
 
 
 
137
 
138
  if(!$apiResult or !is_array($apiResult) or !isset($apiResult['data']) or !is_array($apiResult['data'])) { return false; }
139
 
140
  $data = array();
141
  foreach($apiResult['data'] as $p) {
142
+
143
+ // skip this "post" if it is not of one of the following types
144
+ if(!in_array($p['type'], array('status', 'photo', 'video', 'link'))) {
145
+ continue;
146
+ }
147
+
148
+ // skip empty status updates
149
+ if($p['type'] == 'status' && empty($p['message'])) { continue; }
150
 
151
  //split user and post ID (userID_postID)
152
  $idArray = explode("_", $p['id']);
153
 
154
  $post = array();
155
+ $post['type'] = $p['type'];
156
  $post['author'] = $p['from'];
157
+ $post['content'] = isset($p['message']) ? $p['message'] : '';
158
 
159
 
160
+ // set post content and image
161
  if($p['type'] == 'photo') {
162
+ $post['image'] = "http://graph.facebook.com/".$p['object_id']."/picture";
163
+ } elseif($p['type'] == 'video') {
164
+ //$post['image'] = $p['picture'];
165
+ $post['image'] = "http://graph.facebook.com/".$p['object_id']."/picture";
166
+ $post['content'] .= "\n\n {$p['link']}";
167
  } else {
168
  $post['image'] = null;
169
  }
170
 
171
+
172
+ // calculate post like and comment counts
173
+ if(isset($p['likes'])) {
174
+ if(isset($p['likes']['count'])) {
175
+ $like_count = $p['likes']['count'];
176
+ } elseif(isset($p['likes']['data']) && is_array($p['likes']['data'])) {
177
+ $like_count = count($p['likes']['data']);
178
+ }
179
+ } else {
180
+ $like_count = 0;
181
+ }
182
+
183
+ if(isset($p['comments'])) {
184
+ if(isset($p['comments']['count'])) {
185
+ $comment_count = $p['comments']['count'];
186
+ } elseif(isset($p['comments']['data']) && is_array($p['comments']['data'])) {
187
+ $comment_count = count($p['comments']['data']);
188
+ }
189
+ } else {
190
+ $comment_count = 0;
191
+ }
192
+
193
  $post['timestamp'] = strtotime($p['created_time']);
194
+ $post['like_count'] = $like_count;
195
+ $post['comment_count'] = $comment_count;
196
  $post['link'] = "http://www.facebook.com/".$opts['fb_id']."/posts/".$idArray[1];
197
  $data[] = $post;
198
 
199
  }
200
 
201
  $data = json_encode($data);
202
+ $cache_dir = dirname(__FILE__) . '/../cache/';
203
  $cache_file = dirname(__FILE__) . '/../cache/posts.cache';
204
 
205
+ // create cache directory if not exists
206
+ if(!file_exists($cache_dir)) {
207
+ @mkdir($cache_dir, 0777);
208
+ }
209
+
210
+ // abandon if cache folder is not writable
211
+ if(!is_writable(dirname(__FILE__) . '/../cache/')) {
212
+ return false;
213
+ }
214
 
215
  file_put_contents($cache_file, $data);
216
 
226
  'excerpt_length' => 140
227
  ), $atts));
228
 
229
+ $opts = $this->get_options();
230
  $posts = $this->get_posts();
231
  $posts = array_slice($posts, 0, $number);
232
 
233
  $output = '<div class="recent-facebook-posts rfb_posts shortcode">';
234
+
235
  foreach($posts as $post) {
236
  $content = $post['content'];
237
  $shortened = false;
247
 
248
  $output .= '<div class="rfb-post">';
249
  $output .= '<p class="rfb_text">'. nl2br(make_clickable($content));
250
+ if ($shortened) $output .= '..';
251
  $output .= '</p>';
252
+
253
+ if($opts['img_size'] != 'dont_show' && isset($post['image']) && $post['image']) {
254
+ if(isset($post['type']) && $post['type'] == 'photo') {
255
+ $img_atts = 'src="'. $post['image'] .'?type='. $opts['img_size'] .'" style="max-width: '. $opts['img_width'] .'px; max-height: '. $opts['img_width'] .'px;"';
256
+ } else {
257
+ $img_atts = 'src="'. $post['image'] .'" style="max-width: '. $opts['img_width'] .'px; max-height: '. $opts['img_width'] .'px;"';
258
+ }
259
+
260
+ $output .= '<p class="rfb_image"><a target="_blank" href="'. $post['link'] . '" rel="nofollow"><img '. $img_atts .' alt="" /></a></p>';
261
  }
262
+
263
  $output .= '<p><a target="_blank" class="rfb_link" href="'. $post['link'] .'" rel="nofollow">';
264
  if($likes || $comments) { $output .= '<span class="like_count_and_comment_count">'; }
265
+ if($likes) { $output .= '<span class="like_count">'. $post['like_count'] . ' <span>likes</span></span> '; }
266
+ if($comments) { $output .= '<span class="comment_count">' . $post['comment_count'] . ' <span>comments</span></span> '; }
267
  if($likes || $comments) { $output .= '</span>'; }
268
  $output .= '<span class="timestamp" title="'. date('l, F j, Y', $post['timestamp']) . ' at ' . date('G:i', $post['timestamp']) . '" >';
269
  if($likes || $comments) { $output .= ' · '; }
302
 
303
  $value = floor($diff/$intervals[1][1]);
304
  return $value.' '.$intervals[1][0].($value > 1 ? 's' : '').' ago';
 
305
  }
306
+
307
+ private function get_time_of_last_file_change($filePath)
308
+ {
309
+ clearstatcache();
310
+ $time = filemtime($filePath);
311
+
312
+ $isDST = (date('I', $time) == 1);
313
+ $systemDST = (date('I') == 1);
314
+
315
+ $adjustment = 0;
316
+
317
+ if($isDST == false && $systemDST == true)
318
+ $adjustment = 3600;
319
+
320
+ else if($isDST == true && $systemDST == false)
321
+ $adjustment = -3600;
322
+
323
+ else
324
+ $adjustment = 0;
325
+
326
+ return ($time + $adjustment);
327
+ }
328
 
329
  }
css/rfb.css CHANGED
@@ -1,7 +1,9 @@
1
  .rfb_posts a.rfb_link{ display:block; clear:both; float:none; font-weight:normal; background:none; border:0; padding:1px 0; margin:0; cursor:pointer; text-decoration:none; font-size:11px; line-height:15px; height:15px; }
2
  .rfb_posts a.rfb_link:hover{ text-decoration:none; }
3
  .rfb_posts .rfb_text a{ word-break:break-all; }
4
- .rfb_posts .rfb_image img{ max-width:100%; }
 
 
5
 
6
  .rfb_posts span.like_count, .rfb_posts span.comment_count{ margin-right:3px; background:url("../img/fb-sprite.png") no-repeat 0 0; padding-left:18px; color: #3B5998 !important; display:inline-block; }
7
  .rfb_posts span.like_count_and_comment_count:hover{ background-color: #ECEFF5; }
1
  .rfb_posts a.rfb_link{ display:block; clear:both; float:none; font-weight:normal; background:none; border:0; padding:1px 0; margin:0; cursor:pointer; text-decoration:none; font-size:11px; line-height:15px; height:15px; }
2
  .rfb_posts a.rfb_link:hover{ text-decoration:none; }
3
  .rfb_posts .rfb_text a{ word-break:break-all; }
4
+ .rfb_posts .rfb_image a{ border:1px solid #ccc; display:inline-block; margin:0; padding:3px; line-height:0; }
5
+ .rfb_posts .rfb_image a:hover{ border-color:#3b5998; }
6
+ .rfb_posts .rfb_image img{ max-width:100%; margin:0; padding:0; }
7
 
8
  .rfb_posts span.like_count, .rfb_posts span.comment_count{ margin-right:3px; background:url("../img/fb-sprite.png") no-repeat 0 0; padding-left:18px; color: #3B5998 !important; display:inline-block; }
9
  .rfb_posts span.like_count_and_comment_count:hover{ background-color: #ECEFF5; }
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: DvanKooten
3
  Donate link: http://dannyvankooten.com/donate/
4
  Tags: facebook,posts,fanpage,recent posts,fb,like box alternative,widget,facebook widget,widgets,facebook updates,like button,fb posts
5
  Requires at least: 3.0.1
6
- Tested up to: 3.5
7
- Stable tag: 1.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -12,7 +12,7 @@ Widget that lists your recent Facebook page or profile updates / posts. A faster
12
 
13
  == Description ==
14
 
15
- This plugin adds a widget to your WordPress installation which you can use to list your recent Facebook posts / updates. This can be either posts from your personal profile or posts from your fanpage.
16
 
17
  **Benefits of using Recent Facebook Posts**
18
 
@@ -28,7 +28,6 @@ This plugin adds a widget to your WordPress installation which you can use to li
28
  **Coming up**
29
 
30
  * Option to show a Like button
31
- * Option to show "photo" updates
32
  * Suggestions, anyone? Drop me a line if you do.
33
 
34
  **More info:**
@@ -42,11 +41,14 @@ This plugin adds a widget to your WordPress installation which you can use to li
42
  1. Upload the contents of the .zip-file to the `/wp-content/plugins/` directory
43
  1. Activate the plugin through the 'Plugins' menu in WordPress
44
  1. [Create a new Facebook application here](http://developers.facebook.com/apps). Fill in ANY name you'd like (it won't be visible to the public), leave the namespace field blank and the hosting checkbox unchecked.
45
- 1. Select "Website with Facebook login" and set your `Site URL`
46
  1. Copy your `App ID` and `App Secret` (see screenshot 1)
47
  1. Go to your WordPress Admin panel and open the Recent Facebook Posts options screen. (Settings > Recent Facebook Posts)
48
- 1. Paste your Facebook `App id` and `App Secret`.
 
 
49
  1. Test your configuration by clicking the button "Renew access token".
 
50
  1. Drag the 'Recent FB Posts Widget' to one of your widget areas.
51
  1. (optional) Apply some custom CSS rules to style your recent FB posts widget. Just add them to your theme's CSS file.
52
 
@@ -78,13 +80,17 @@ Please check if the page you are trying to fetch posts from has **publicly** ava
78
  = Where to add custom CSS =
79
  IMO, appearance should be handled by the theme you are using. This is why your custom CSS rules should be added to your theme's stylesheet file. You can find this file by browsing (over FTP) to `/wp-content/themes/your-theme-name/style.css`, or you can just use the WP Editor under Appearance > Editor.
80
 
 
 
 
81
  = Can I show a list of recent facebook updates in my posts or pages? =
82
- Yes, you can use the `[recent-facebook-posts]` shortcode. Optionally, add the following attributes: `likes`, `comments`, `excerpt_length`. Example: `[recent-facebook-posts likes=0 comments=0 excerpt_length=250]`
83
 
84
  Valid attribute values are as follows:
85
  `likes` : 0 (don't show like count), 1 (show like count)
86
  `comments` : 0 (don't show comment count), 1 (show comment count)
87
  `excerpt_length` : 1 - 9999 (sets the length of the excerpt)
 
88
 
89
  == Screenshots ==
90
 
@@ -92,6 +98,33 @@ Valid attribute values are as follows:
92
  2. The green circled fields are the fields where you'll need to provide your Facebook app id and app secret (as shown in screenshot 1).
93
 
94
  == Changelog ==
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  = 1.1 =
96
  * Added: Shortcode to show a list of recent facebook updates in your posts: '[recent-facebook-posts]'
97
 
3
  Donate link: http://dannyvankooten.com/donate/
4
  Tags: facebook,posts,fanpage,recent posts,fb,like box alternative,widget,facebook widget,widgets,facebook updates,like button,fb posts
5
  Requires at least: 3.0.1
6
+ Tested up to: 3.5.2
7
+ Stable tag: 1.2.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
12
 
13
  == Description ==
14
 
15
+ This plugin adds a widget (and a shortcode `[recent-facebook-posts]`) to your WordPress installation which you can use to list your recent Facebook posts / updates. This can be either posts from your personal profile or posts from your fanpage.
16
 
17
  **Benefits of using Recent Facebook Posts**
18
 
28
  **Coming up**
29
 
30
  * Option to show a Like button
 
31
  * Suggestions, anyone? Drop me a line if you do.
32
 
33
  **More info:**
41
  1. Upload the contents of the .zip-file to the `/wp-content/plugins/` directory
42
  1. Activate the plugin through the 'Plugins' menu in WordPress
43
  1. [Create a new Facebook application here](http://developers.facebook.com/apps). Fill in ANY name you'd like (it won't be visible to the public), leave the namespace field blank and the hosting checkbox unchecked.
44
+ 1. In the Basic Application settings screen, scroll down a bit and select "Website with Facebook login" and set your `Site URL` to the URL of your WordPress installation.
45
  1. Copy your `App ID` and `App Secret` (see screenshot 1)
46
  1. Go to your WordPress Admin panel and open the Recent Facebook Posts options screen. (Settings > Recent Facebook Posts)
47
+ 1. Paste your Facebook `App id` and `App Secret`. [screenshot 1](http://wordpress.org/extend/plugins/recent-facebook-posts/screenshots/)
48
+ 1. Find the numeric Facebook ID of your public Facebook page with [this website](http://findmyfacebookid.com/).
49
+ 1. Fill in your Facebook ID in the RFB options screen.
50
  1. Test your configuration by clicking the button "Renew access token".
51
+ 1. Test if caching works by clicking the "Renew cache" button.
52
  1. Drag the 'Recent FB Posts Widget' to one of your widget areas.
53
  1. (optional) Apply some custom CSS rules to style your recent FB posts widget. Just add them to your theme's CSS file.
54
 
80
  = Where to add custom CSS =
81
  IMO, appearance should be handled by the theme you are using. This is why your custom CSS rules should be added to your theme's stylesheet file. You can find this file by browsing (over FTP) to `/wp-content/themes/your-theme-name/style.css`, or you can just use the WP Editor under Appearance > Editor.
82
 
83
+ = Does this plugin work with group posts? =
84
+ Currently, no. This plugin currently only works with pages and personal profiles.
85
+
86
  = Can I show a list of recent facebook updates in my posts or pages? =
87
+ Yes, you can use the `[recent-facebook-posts]` shortcode. Optionally, add the following attributes: `likes`, `comments`, `excerpt_length`, `number`. Example: `[recent-facebook-posts number=10 likes=0 comments=0 excerpt_length=250]`
88
 
89
  Valid attribute values are as follows:
90
  `likes` : 0 (don't show like count), 1 (show like count)
91
  `comments` : 0 (don't show comment count), 1 (show comment count)
92
  `excerpt_length` : 1 - 9999 (sets the length of the excerpt)
93
+ `number` : 1 - 99 (set the number of posts to show)
94
 
95
  == Screenshots ==
96
 
98
  2. The green circled fields are the fields where you'll need to provide your Facebook app id and app secret (as shown in screenshot 1).
99
 
100
  == Changelog ==
101
+
102
+ = 1.2.1 =
103
+ * Added option to hide images
104
+ * Added option to load either thumbnail or normal size images from Facebook's CDN
105
+ * Added border to image links
106
+
107
+ = 1.2.1 =
108
+ * Fixed parameter app_id is required notice before being able to enter it.
109
+
110
+ = 1.2 =
111
+ * Fixed: Reverted back to 'posts' instead of 'feed', to exclude posts from others.
112
+ * Fixed: undefined index 'count' when renewing cache file
113
+ * Fixed: wrong comment or like count for some posts
114
+ * Improved: calculation of cache file modification time to prevent unnecessary cache renewal
115
+ * Improved: error message when cURL is not enabled
116
+ * Improved: access token and cache configuration options are now only available when connected
117
+
118
+ = 1.1.2 =
119
+ * Fixed: Added spaces after the like and comment counts in the shortcode output
120
+
121
+ = 1.1.1 =
122
+ * Updated: Expanded installation instructions.
123
+ * Changed: Some code improvements
124
+ * Added: Link to Facebook numeric ID helper website.
125
+ * Added: Check if cache directory exists. If not the plugin will now automatically try to create it with the right permissions.
126
+ * Added: option to open link to Facebook Page in a new window.
127
+
128
  = 1.1 =
129
  * Added: Shortcode to show a list of recent facebook updates in your posts: '[recent-facebook-posts]'
130
 
recent-facebook-posts.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Recent Facebook Posts
4
  Plugin URI: http://dannyvankooten.com/wordpress-plugins/recent-facebook-posts/
5
  Description: Widget that lists your X most recent Facebook posts.
6
- Version: 1.1
7
  Author: Danny van Kooten
8
  Author URI: http://dannyvankooten.com/
9
  License: GPL2
3
  Plugin Name: Recent Facebook Posts
4
  Plugin URI: http://dannyvankooten.com/wordpress-plugins/recent-facebook-posts/
5
  Description: Widget that lists your X most recent Facebook posts.
6
+ Version: 1.2.2
7
  Author: Danny van Kooten
8
  Author URI: http://dannyvankooten.com/
9
  License: GPL2
views/settings_page.html.php CHANGED
@@ -3,7 +3,7 @@
3
  <div id="rfb" class="wrap">
4
  <div class="column" style="width:70%;">
5
 
6
- <?php if($fb->getUser() && !$access_token) { ?>
7
  <div id="setting-error-settings_updated" class="updated settings-error">
8
  <p>
9
  <strong>Your API settings seem fine but there is no valid access token available. </strong>
@@ -58,7 +58,7 @@
58
  </tr>
59
 
60
  <tr valign="top">
61
- <th scope="row"><label for="rfb_fb_id" <?php if(empty($opts['fb_id'])) echo 'class="error"'; ?>>Facebook user id, page id or slug</label></th>
62
  <td><input type="text" size="50" id="rfb_fb_id" name="rfb_settings[fb_id]" value="<?php echo $opts['fb_id']; ?>" /></td>
63
  </tr>
64
 
@@ -67,11 +67,36 @@
67
  <td><input type="text" size="50" id="rfb_cache_time" name="rfb_settings[cache_time]" value="<?php echo $opts['cache_time']; ?>" /></td>
68
  </tr>
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  <tr valign="top">
71
  <th scope="row"><label for="rfb_link_text">Link text</label></th>
72
  <td><input type="text" size="50" id="rfb_link_text" name="rfb_settings[link_text]" value="<?php echo $opts['link_text']; ?>" /></td>
73
  </tr>
74
 
 
 
 
 
 
75
  <tr valign="top">
76
  <th scope="row"><label for="rfb_load_css">Load some default CSS?</label></th>
77
  <td><input type="checkbox" id="rfb_load_css" name="rfb_settings[load_css]" value="1" <?php if(isset($opts['load_css']) && $opts['load_css']) { ?>checked="1" <?php } ?>/></td>
@@ -87,27 +112,34 @@
87
 
88
  </form>
89
 
90
- <h3 title="<?php echo get_option('rfb_access_token'); ?>">Access Token</h3>
91
- <p>Use this button to test your configuration. It also won't hurt to hit this button once in a month or so to renew your access token, although this should be taken care of automatically everytime you log into WordPress.</p>
92
- <a class="button-primary" href="<?php echo $fb->getLoginUrl(array('redirect_uri' => get_admin_url() . 'options-general.php?page=rfb-settings&rfb_renew_access_token')); ?>">Test / Renew Access Token</a>
93
-
94
- <h3>Cache</h3>
95
- <p>Because fetching posts from Facebook is "expensive", this will only happen every <?php echo $opts['cache_time']; ?> seconds (as configured above). You can manually renew the cache using the button below.</p>
96
- <form action="" method="post"><input type="submit" name="renew_cache" class="button-primary" value="<?php _e('Renew Cache'); ?>" /></form>
 
 
 
97
  </div>
98
 
99
  <div class="column clearfix" style="width:26%; margin-left:3%;">
100
 
101
  <div id="rfb-donatebox" class="box">
102
  <h3>Donate $10, $20 or $50</h3>
103
- <p>I spent countless hours developing this plugin for <b>FREE</b>. If you like it, consider donating a token of your appreciation.</p>
104
 
105
- <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
106
- <input type="hidden" name="cmd" value="_s-xclick">
107
- <input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIHVwYJKoZIhvcNAQcEoIIHSDCCB0QCAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwDQYJKoZIhvcNAQEBBQAEgYCT0Lls0OHcadQPQYia2dXZvq5rcZoIJYFsQ+hi7hkeIfew8hVWTmXNm0Ozm4+QsmPge4dQB0kxne5sPYthMNi+Z2H7Jh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ORBY=-----END PKCS7-----
108
- ">
109
- <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
110
- <img alt="" border="0" src="https://www.paypalobjects.com/nl_NL/i/scr/pixel.gif" width="1" height="1">
 
 
 
 
111
  </form>
112
 
113
  <p>Or you can: </p>
3
  <div id="rfb" class="wrap">
4
  <div class="column" style="width:70%;">
5
 
6
+ <?php if(isset($fb) && $fb->getUser() && !$access_token) { ?>
7
  <div id="setting-error-settings_updated" class="updated settings-error">
8
  <p>
9
  <strong>Your API settings seem fine but there is no valid access token available. </strong>
58
  </tr>
59
 
60
  <tr valign="top">
61
+ <th scope="row"><label for="rfb_fb_id" <?php if(empty($opts['fb_id'])) echo 'class="error"'; ?>>Facebook numeric ID <small><a target="_blank" href="http://findmyfacebookid.com/">(?)</a></small></label></th>
62
  <td><input type="text" size="50" id="rfb_fb_id" name="rfb_settings[fb_id]" value="<?php echo $opts['fb_id']; ?>" /></td>
63
  </tr>
64
 
67
  <td><input type="text" size="50" id="rfb_cache_time" name="rfb_settings[cache_time]" value="<?php echo $opts['cache_time']; ?>" /></td>
68
  </tr>
69
 
70
+ <tr valign="top">
71
+ <th scope="row"><label for="rfb_img_size">Image source size</label></th>
72
+ <td>
73
+ <select id="rfb_img_size" name="rfb_settings[img_size]">
74
+ <option value="dont_show" <?php if($opts['img_size'] == 'dont_show') { echo 'selected'; } ?>>Don't show images</option>
75
+ <option value="thumbnail" <?php if($opts['img_size'] == 'thumbnail') { echo 'selected'; } ?>>Thumbnail</option>
76
+ <option value="normal" <?php if($opts['img_size'] == 'normal') { echo 'selected'; } ?>>Normal</option>
77
+ </select>
78
+ </tr>
79
+
80
+ <tr valign="top">
81
+ <th scope="row"><label for="rfb_img_width">Image width <small>(in px)</small></label></th>
82
+ <td><input type="text" size="50" id="rfb_img_width" name="rfb_settings[img_width]" value="<?php echo $opts['img_width']; ?>" /></td>
83
+ </tr>
84
+
85
+ <tr valign="top">
86
+ <th scope="row"><label for="rfb_img_width">Image height <small>(in px)</small></label></th>
87
+ <td><input type="text" size="50" id="rfb_img_height" name="rfb_settings[img_height]" value="<?php echo $opts['img_height']; ?>" /></td>
88
+ </tr>
89
+
90
  <tr valign="top">
91
  <th scope="row"><label for="rfb_link_text">Link text</label></th>
92
  <td><input type="text" size="50" id="rfb_link_text" name="rfb_settings[link_text]" value="<?php echo $opts['link_text']; ?>" /></td>
93
  </tr>
94
 
95
+ <tr valign="top">
96
+ <th scope="row"><label for="rfb_link_new_window">Open link in new window?</label></th>
97
+ <td><input type="checkbox" id="rfb_link_new_window" name="rfb_settings[link_new_window]" value="1" <?php if(isset($opts['link_new_window']) && $opts['link_new_window']) { ?>checked="1" <?php } ?>/></td>
98
+ </tr>
99
+
100
  <tr valign="top">
101
  <th scope="row"><label for="rfb_load_css">Load some default CSS?</label></th>
102
  <td><input type="checkbox" id="rfb_load_css" name="rfb_settings[load_css]" value="1" <?php if(isset($opts['load_css']) && $opts['load_css']) { ?>checked="1" <?php } ?>/></td>
112
 
113
  </form>
114
 
115
+ <?php if($curl && !empty($opts['app_id']) && !empty($opts['app_secret'])) { ?>
116
+ <h3 title="<?php echo get_option('rfb_access_token'); ?>">Access Token</h3>
117
+ <p>Use this button to test your configuration. It also won't hurt to hit this button once in a month or so to renew your access token, although this should be taken care of automatically everytime you log into WordPress.</p>
118
+ <a class="button-primary" href="<?php echo $fb->getLoginUrl(array('redirect_uri' => get_admin_url() . 'options-general.php?page=rfb-settings&rfb_renew_access_token')); ?>">Test / Renew Access Token</a>
119
+ <?php } ?>
120
+ <?php if($connected) { ?>
121
+ <h3>Cache</h3>
122
+ <p>Because fetching posts from Facebook is "expensive", this will only happen every <?php echo $opts['cache_time']; ?> seconds (as configured above). You can manually renew the cache using the button below.</p>
123
+ <form action="" method="post"><input type="submit" name="renew_cache" class="button-primary" value="<?php _e('Renew Cache'); ?>" /></form>
124
+ <?php } ?>
125
  </div>
126
 
127
  <div class="column clearfix" style="width:26%; margin-left:3%;">
128
 
129
  <div id="rfb-donatebox" class="box">
130
  <h3>Donate $10, $20 or $50</h3>
131
+ <p>I spent countless hours developing this plugin for <b>FREE</b>. If you use it and like it, consider buying me a beer as a small token of your appreciation.</p>
132
 
133
+ <form class="donate" action="https://www.paypal.com/cgi-bin/webscr" method="post">
134
+ <input type="hidden" name="cmd" value="_donations">
135
+ <input type="hidden" name="business" value="AP87UHXWPNBBU">
136
+ <input type="hidden" name="lc" value="US">
137
+ <input type="hidden" name="item_name" value="Danny van Kooten">
138
+ <input type="hidden" name="item_number" value="Recent Facebook Posts">
139
+ <input type="hidden" name="currency_code" value="USD">
140
+ <input type="hidden" name="bn" value="PP-DonationsBF:btn_donateCC_LG.gif:NonHosted">
141
+ <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
142
+ <img alt="" border="0" src="https://www.paypalobjects.com/nl_NL/i/scr/pixel.gif" width="1" height="1">
143
  </form>
144
 
145
  <p>Or you can: </p>