Recent Facebook Posts - Version 1.1

Version Description

  • Added: Shortcode to show a list of recent facebook updates in your posts: '[recent-facebook-posts]'
Download this release

Release Info

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

Code changes from version 1.0.5 to 1.1

classes/class-rfb-widget.php CHANGED
@@ -115,7 +115,7 @@ class RFB_Widget extends WP_Widget {
115
  <?php if($show_like_count) { ?><span class="like_count"><?php echo $post['like_count']; ?> <span>likes</span></span> <?php } ?>
116
  <?php if($show_comment_count) { ?><span class="comment_count"><?php echo $post['comment_count']; ?> <span>comments</span></span> <?php } ?>
117
  <?php if($show_like_count || $show_comment_count) { ?></span><?php } ?>
118
- <span class="timestamp" title="<?php echo date('l, F j, Y', $post['timestamp']) . ' at ' . date('G:i', $post['timestamp']); ?>" ><?php if($show_like_count || $show_comment_count) { ?> · <?php } ?><span><?php echo $this->time_ago($post['timestamp']); ?></span></span>
119
  </a></p>
120
  </li>
121
  <?php }
@@ -138,26 +138,6 @@ class RFB_Widget extends WP_Widget {
138
  echo $after_widget;
139
  }
140
 
141
- private function time_ago($timestamp) {
142
- $diff = time() - (int) $timestamp;
143
-
144
- if ($diff == 0)
145
- return 'just now';
146
-
147
- $intervals = array
148
- (
149
- 1 => array('year', 31556926),
150
- $diff < 31556926 => array('month', 2628000),
151
- $diff < 2629744 => array('week', 604800),
152
- $diff < 604800 => array('day', 86400),
153
- $diff < 86400 => array('hour', 3600),
154
- $diff < 3600 => array('minute', 60),
155
- $diff < 60 => array('second', 1)
156
- );
157
-
158
- $value = floor($diff/$intervals[1][1]);
159
- return $value.' '.$intervals[1][0].($value > 1 ? 's' : '').' ago';
160
-
161
- }
162
 
163
  }
115
  <?php if($show_like_count) { ?><span class="like_count"><?php echo $post['like_count']; ?> <span>likes</span></span> <?php } ?>
116
  <?php if($show_comment_count) { ?><span class="comment_count"><?php echo $post['comment_count']; ?> <span>comments</span></span> <?php } ?>
117
  <?php if($show_like_count || $show_comment_count) { ?></span><?php } ?>
118
+ <span class="timestamp" title="<?php echo date('l, F j, Y', $post['timestamp']) . ' at ' . date('G:i', $post['timestamp']); ?>" ><?php if($show_like_count || $show_comment_count) { ?> · <?php } ?><span><?php echo $RFB->time_ago($post['timestamp']); ?></span></span>
119
  </a></p>
120
  </li>
121
  <?php }
138
  echo $after_widget;
139
  }
140
 
141
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
 
143
  }
classes/class-rfb.php CHANGED
@@ -20,8 +20,11 @@ class RFB {
20
  }
21
 
22
  public function __construct() {
 
23
  add_action('wp_login', array($this, 'renew_access_token'));
24
- add_action('init', array(&$this, 'on_init'));
 
 
25
 
26
  // only on frontend
27
  if(!is_admin()) {
@@ -161,6 +164,84 @@ class RFB {
161
  file_put_contents($cache_file, $data);
162
 
163
  return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  }
165
 
166
  }
20
  }
21
 
22
  public function __construct() {
23
+
24
  add_action('wp_login', array($this, 'renew_access_token'));
25
+ add_action('init', array($this, 'on_init'));
26
+
27
+ add_shortcode('recent-facebook-posts', array($this, 'shortcode_output'));
28
 
29
  // only on frontend
30
  if(!is_admin()) {
164
  file_put_contents($cache_file, $data);
165
 
166
  return true;
167
+ }
168
+
169
+ public function shortcode_output($atts)
170
+ {
171
+ extract(shortcode_atts(array(
172
+ 'number' => '5',
173
+ 'likes' => 1,
174
+ 'comments' => 1,
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;
185
+
186
+ if(strlen($content) > $excerpt_length) {
187
+ $limit = strpos($post['content'], ' ',$excerpt_length);
188
+ if($limit) {
189
+ $content = substr($post['content'], 0, $limit);
190
+ $shortened = true;
191
+ }
192
+ }
193
+
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 .= ' · '; }
209
+ $output .= '<span>' . $this->time_ago($post['timestamp']) . '</span></span>';
210
+ $output .= '</a></p></div>' ;
211
+
212
+ }
213
+
214
+ if(empty($posts)) {
215
+ $output .= '<p>No recent Facebook status updates to show.</p>';
216
+ if(current_user_can('manage_options')) {
217
+ $output .= '<p><strong>Admins only notice:</strong> Did you <a href="' . get_admin_url(null,'options-general.php?page=rfb-settings') . '">configure the plugin</a> properly?</p>';
218
+ }
219
+ }
220
+
221
+ $output .= "</div>";
222
+ return $output;
223
+ }
224
+
225
+ public function time_ago($timestamp) {
226
+ $diff = time() - (int) $timestamp;
227
+
228
+ if ($diff == 0)
229
+ return 'just now';
230
+
231
+ $intervals = array
232
+ (
233
+ 1 => array('year', 31556926),
234
+ $diff < 31556926 => array('month', 2628000),
235
+ $diff < 2629744 => array('week', 604800),
236
+ $diff < 604800 => array('day', 86400),
237
+ $diff < 86400 => array('hour', 3600),
238
+ $diff < 3600 => array('minute', 60),
239
+ $diff < 60 => array('second', 1)
240
+ );
241
+
242
+ $value = floor($diff/$intervals[1][1]);
243
+ return $value.' '.$intervals[1][0].($value > 1 ? 's' : '').' ago';
244
+
245
  }
246
 
247
  }
css/rfb.css CHANGED
@@ -12,3 +12,8 @@
12
  .rfb_posts span.like_count span{ display:none; }
13
  .rfb_posts span.comment_count span{ display:none; }
14
 
 
 
 
 
 
12
  .rfb_posts span.like_count span{ display:none; }
13
  .rfb_posts span.comment_count span{ display:none; }
14
 
15
+ /* shortcode */
16
+ .rfb_posts.shortcode div.rfb-post{ border-bottom:1px solid #E9E9E9; padding-top:15px; margin-bottom:15px; margin-top:0; padding-bottom:0; }
17
+
18
+ /* widget */
19
+ .widget .rfb_posts { }
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.4.2
7
- Stable tag: 1.0.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -78,12 +78,23 @@ 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
  == Screenshots ==
82
 
83
  1. The black bordered circles are the fields you'll need to provide to Facebook, at a minimum. The green circled fields are the values you'll need to provide to Recent Facebook Posts.
84
  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).
85
 
86
  == Changelog ==
 
 
 
87
  = 1.0.5 =
88
  * Added: More user-friendly error message when cURL is not enabled on your server.
89
 
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
 
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
 
91
  1. The black bordered circles are the fields you'll need to provide to Facebook, at a minimum. The green circled fields are the values you'll need to provide to Recent Facebook Posts.
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
+
98
  = 1.0.5 =
99
  * Added: More user-friendly error message when cURL is not enabled on your server.
100
 
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.0.5
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.1
7
  Author: Danny van Kooten
8
  Author URI: http://dannyvankooten.com/
9
  License: GPL2