PluginProbe ʕ •ᴥ•ʔ
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 1.2.4
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v1.2.4
4.8.1 trunk 1.0 1.1 1.12.1 1.2.3 1.2.4 1.2.5 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5 1.5.1 1.5.2 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.5.1 1.6.6 1.6.6.1 1.6.6.2 1.6.6.3 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.9.0 1.9.1 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.8.1 1.9.9 1.9.9.1 1.9.9.2 1.9.9.3 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.10 2.11 2.11.1 2.12 2.12.1 2.12.2 2.12.3 2.12.4 2.13 2.14 2.14.1 2.15 2.15.1 2.16 2.16.1 2.17 2.17.1 2.18 2.18.1 2.18.2 2.18.3 2.19 2.19.1 2.19.2 2.19.3 2.2 2.2.1 2.3 2.3.1 2.3.10 2.3.2 2.3.3 2.3.4 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.1.1 2.4.1.2 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5 2.5.1 2.5.2 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.7 2.7.1 2.7.2 2.8 2.9 2.9.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.7.5 4.7.6 4.7.7
custom-facebook-feed / custom-facebook-feed.php
custom-facebook-feed Last commit date
css 13 years ago img 13 years ago README.txt 13 years ago custom-facebook-feed-admin.php 13 years ago custom-facebook-feed.php 13 years ago gpl-2.0.txt 13 years ago
custom-facebook-feed.php
228 lines
1 <?php
2 /*
3 Plugin Name: Custom Facebook Feed
4 Plugin URI: http://smashballoon.com/custom-facebook-feed
5 Description: Add a completely customizable Facebook feed to your WordPress site
6 Version: 1.2.4
7 Author: Smash Balloon
8 Author URI: http://smashballoon.com/
9 License: GPLv2 or later
10 */
11
12 /*
13 Copyright 2013 Smash Balloon (email : hey@smashballoon.com)
14
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
29
30 //Include admin
31 include dirname( __FILE__ ) .'/custom-facebook-feed-admin.php';
32
33 error_reporting(0);
34
35 // Add shortcodes
36 add_shortcode('custom-facebook-feed', 'display_cff');
37 function display_cff($atts) {
38 //Pass in shortcode attrbutes
39 $atts = shortcode_atts(
40 array(
41 'id' => get_option('cff_page_id'),
42 'show' => get_option('cff_num_show'),
43 'titlelength' => get_option('cff_title_length'),
44 'bodylength' => get_option('cff_body_length')
45 ), $atts);
46
47 //Assign the Access Token and Page ID variables
48 $access_token = get_option('cff_access_token');
49 $page_id = $atts['id'];
50
51 //Check whether the Access Token is present and valid
52 if ($access_token == '') {
53 echo 'Please enter a valid Access Token. You can do this in the plugin settings (Settings > Custom Facebook Feed).<br /><br />';
54 return false;
55 }
56
57 //Check whether a Page ID has been defined
58 if ($page_id == '') {
59 echo "Please enter the Page ID of the Facebook feed you'd like to display. You can do this in either the plugin settings (Settings > Custom Facebook Feed) or in the shortcode itself. For example [custom_facebook_feed id=<b>YOUR_PAGE_ID</b>].<br /><br />";
60 return false;
61 }
62
63 //Get the contents of a Facebook page
64 $FBpage = @file_get_contents('https://graph.facebook.com/' . $page_id . '/posts?access_token=' . $access_token . '&limit=' . $atts['show']);
65
66 //Interpret data with JSON
67 $FBdata = json_decode($FBpage);
68
69 //Create HTML
70 $content = '<div id="cff">';
71 foreach ($FBdata->data as $news ) {
72
73 //Explode News and Page ID's into 2 values
74 $StatusID = explode("_", $news->id);
75
76 //Start the container
77 $content .= '<div class="cff-item">';
78
79 //Text/title/description/date
80 //Get text limits
81 $title_limit = $atts['titlelength'];
82 $body_limit = $atts['bodylength'];
83
84 if (!empty($news->story)) {
85 $story_text = $news->story;
86 if (isset($title_limit) && $title_limit !== '') {
87 if (strlen($story_text) > $title_limit) $story_text = substr($story_text, 0, $title_limit) . '...';
88 }
89 $content .= '<h4>' . $story_text . '</h4>';
90 }
91 if (!empty($news->message)) {
92 $message_text = $news->message;
93 if (isset($title_limit) && $title_limit !== '') {
94 if (strlen($message_text) > $title_limit) $message_text = substr($message_text, 0, $title_limit) . '...';
95 }
96 $content .= '<h4>' . $message_text . '</h4>';
97 }
98 if (!empty($news->description)) {
99 $description_text = $news->description;
100 if (isset($body_limit) && $body_limit !== '') {
101 if (strlen($description_text) > $body_limit) $description_text = substr($description_text, 0, $body_limit) . '...';
102 }
103 $content .= '<p>' . $description_text . '</p>';
104 }
105
106
107 //Posted on
108 $content .= '<p class="cff-date">Posted '. timeSince(strtotime($news->created_time)) . ' ago</p>';
109
110
111 //Check whether it's a shared link
112 if ($news->type == 'link') {
113 $content .= '<a href="'.$news->link.'"><img src="'. $picture_b .'" border="0" style="padding-right:10px;" /></a>';
114
115 //Display link name and description
116 if (!empty($news->description)) {
117 $content .= '<a href="'.$news->link.'">'. '<b>' . $news->name . '</b></a>';
118 }
119 }
120
121
122 //Show link
123 if (!empty($news->link)) {
124 $link = $news->link;
125
126 //Check whether it links to facebook or somewhere else
127 $facebook_str = 'facebook.com';
128
129 if(stripos($link, $facebook_str) !== false) {
130 $link_text = 'View on Facebook';
131 } else {
132 $link_text = 'View Link';
133 }
134 $content .= '<a class="cff-viewpost" href="' . $link . '" title="' . $link_text . '">' . $link_text . '</a>';
135 }
136
137
138 //End item
139 $content .= '</div> <!-- end .cff-item -->';
140
141 };
142
143
144 //Add the Like Box
145 $content .= '<div class="cff-likebox"><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like-box href="http://www.facebook.com/' . $page_id . '" width="200" show_faces="false" stream="false" header="true"></fb:like-box></div>';
146 $content .= '</div><div class="clear"></div> <!-- end .Custom Facebook Feed -->';
147
148 //Return our feed HTML to display
149 return $content;
150
151 }
152
153
154
155
156
157 //Time stamp function
158
159 function timeSince($original) {
160
161 // Array of time period
162 $chunks = array(
163 array(60 * 60 * 24 * 365 , 'year'),
164 array(60 * 60 * 24 * 30 , 'month'),
165 array(60 * 60 * 24 * 7, 'week'),
166 array(60 * 60 * 24 , 'day'),
167 array(60 * 60 , 'hour'),
168 array(60 , 'minute'),
169 );
170
171 // Current time
172 $today = time();
173 $since = $today - $original;
174
175 // $j saves performing the count function each time around the loop
176 for ($i = 0, $j = count($chunks); $i < $j; $i++) {
177 $seconds = $chunks[$i][0];
178 $name = $chunks[$i][1];
179
180 // finding the biggest chunk (if the chunk fits, break)
181 if (($count = floor($since / $seconds)) != 0) {
182 break;
183 }
184 }
185
186 $print = ($count == 1) ? '1 '.$name : "$count {$name}s";
187
188 if ($i + 1 < $j) {
189 // now getting the second item
190 $seconds2 = $chunks[$i + 1][0];
191 $name2 = $chunks[$i + 1][1];
192
193 // add second item if it's greater than 0
194 if (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0) {
195 $print .= ($count2 == 1) ? ', 1 '.$name2 : ", $count2 {$name2}s";
196 }
197 }
198 return $print;
199 }
200
201
202
203 //Enqueue stylesheet
204 add_action( 'wp_enqueue_scripts', 'cff_add_my_stylesheet' );
205 function cff_add_my_stylesheet() {
206 // Respects SSL, Style.css is relative to the current file
207 wp_register_style( 'cff', plugins_url('css/style.css', __FILE__) );
208 wp_enqueue_style( 'cff' );
209 }
210
211 //Allows shortcodes in sidebar of theme
212 add_filter('widget_text', 'do_shortcode');
213
214 //Uninstall
215 function cff_uninstall()
216 {
217 if ( ! current_user_can( 'activate_plugins' ) )
218 return;
219
220 delete_option( 'cff_access_token' );
221 delete_option( 'cff_page_id' );
222 delete_option( 'cff_num_show' );
223 delete_option( 'cff_title_length' );
224 delete_option( 'cff_body_length' );
225 }
226 register_uninstall_hook( __FILE__, 'cff_uninstall' );
227
228 ?>