custom-facebook-feed
Last commit date
css
12 years ago
img
12 years ago
js
12 years ago
README.txt
12 years ago
custom-facebook-feed-admin.php
12 years ago
custom-facebook-feed.php
12 years ago
gpl-2.0.txt
13 years ago
custom-facebook-feed.php
1438 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.8.2 |
| 7 | Author: Smash Balloon |
| 8 | Author URI: http://smashballoon.com/ |
| 9 | License: GPLv2 or later |
| 10 | */ |
| 11 | /* |
| 12 | Copyright 2013 Smash Balloon LLC (email : hey@smashballoon.com) |
| 13 | This program is free software; you can redistribute it and/or modify |
| 14 | it under the terms of the GNU General Public License as published by |
| 15 | the Free Software Foundation; either version 2 of the License, or |
| 16 | (at your option) any later version. |
| 17 | This program is distributed in the hope that it will be useful, |
| 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | GNU General Public License for more details. |
| 21 | You should have received a copy of the GNU General Public License |
| 22 | along with this program; if not, write to the Free Software |
| 23 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 24 | */ |
| 25 | //Include admin |
| 26 | include dirname( __FILE__ ) .'/custom-facebook-feed-admin.php'; |
| 27 | include dirname( __FILE__ ) .'/cff_autolink.php'; |
| 28 | |
| 29 | // Add shortcodes |
| 30 | add_shortcode('custom-facebook-feed', 'display_cff'); |
| 31 | function display_cff($atts) { |
| 32 | |
| 33 | //Style options |
| 34 | $options = get_option('cff_style_settings'); |
| 35 | //Create the types string to set as shortcode default |
| 36 | $include_string = ''; |
| 37 | if($options[ 'cff_show_author' ]) $include_string .= 'author,'; |
| 38 | if($options[ 'cff_show_text' ]) $include_string .= 'text,'; |
| 39 | if($options[ 'cff_show_desc' ]) $include_string .= 'desc,'; |
| 40 | if($options[ 'cff_show_shared_links' ]) $include_string .= 'sharedlinks,'; |
| 41 | if($options[ 'cff_show_date' ]) $include_string .= 'date,'; |
| 42 | if($options[ 'cff_show_media' ]) $include_string .= 'media,'; |
| 43 | if($options[ 'cff_show_event_title' ]) $include_string .= 'eventtitle,'; |
| 44 | if($options[ 'cff_show_event_details' ]) $include_string .= 'eventdetails,'; |
| 45 | if($options[ 'cff_show_meta' ]) $include_string .= 'social,'; |
| 46 | if($options[ 'cff_show_link' ]) $include_string .= 'link,'; |
| 47 | if($options[ 'cff_show_like_box' ]) $include_string .= 'likebox,'; |
| 48 | //Pass in shortcode attrbutes |
| 49 | $atts = shortcode_atts( |
| 50 | array( |
| 51 | 'accesstoken' => trim( get_option('cff_access_token') ), |
| 52 | 'id' => get_option('cff_page_id'), |
| 53 | 'pagetype' => get_option('cff_page_type'), |
| 54 | 'num' => get_option('cff_num_show'), |
| 55 | 'limit' => get_option('cff_post_limit'), |
| 56 | 'others' => '', |
| 57 | 'showpostsby' => get_option('cff_show_others'), |
| 58 | 'cachetime' => get_option('cff_cache_time'), |
| 59 | 'cacheunit' => get_option('cff_cache_time_unit'), |
| 60 | 'locale' => get_option('cff_locale'), |
| 61 | 'ajax' => get_option('cff_ajax'), |
| 62 | 'width' => isset($options[ 'cff_feed_width' ]) ? $options[ 'cff_feed_width' ] : '', |
| 63 | 'height' => isset($options[ 'cff_feed_height' ]) ? $options[ 'cff_feed_height' ] : '', |
| 64 | 'padding' => isset($options[ 'cff_feed_padding' ]) ? $options[ 'cff_feed_padding' ] : '', |
| 65 | 'bgcolor' => isset($options[ 'cff_bg_color' ]) ? $options[ 'cff_bg_color' ] : '', |
| 66 | 'showauthor' => '', |
| 67 | 'showauthornew' => isset($options[ 'cff_show_author' ]) ? $options[ 'cff_show_author' ] : '', |
| 68 | 'class' => isset($options[ 'cff_class' ]) ? $options[ 'cff_class' ] : '', |
| 69 | 'layout' => isset($options[ 'cff_preset_layout' ]) ? $options[ 'cff_preset_layout' ] : '', |
| 70 | 'include' => $include_string, |
| 71 | 'exclude' => '', |
| 72 | //Typography |
| 73 | 'textformat' => isset($options[ 'cff_title_format' ]) ? $options[ 'cff_title_format' ] : '', |
| 74 | 'textsize' => isset($options[ 'cff_title_size' ]) ? $options[ 'cff_title_size' ] : '', |
| 75 | 'textweight' => isset($options[ 'cff_title_weight' ]) ? $options[ 'cff_title_weight' ] : '', |
| 76 | 'textcolor' => isset($options[ 'cff_title_color' ]) ? $options[ 'cff_title_color' ] : '', |
| 77 | 'textlink' => isset($options[ 'cff_title_link' ]) ? $options[ 'cff_title_link' ] : '', |
| 78 | 'posttags' => isset($options[ 'cff_post_tags' ]) ? $options[ 'cff_post_tags' ] : '', |
| 79 | 'descsize' => isset($options[ 'cff_body_size' ]) ? $options[ 'cff_body_size' ] : '', |
| 80 | 'descweight' => isset($options[ 'cff_body_weight' ]) ? $options[ 'cff_body_weight' ] : '', |
| 81 | 'desccolor' => isset($options[ 'cff_body_color' ]) ? $options[ 'cff_body_color' ] : '', |
| 82 | //Event title |
| 83 | 'eventtitleformat' => isset($options[ 'cff_event_title_format' ]) ? $options[ 'cff_event_title_format' ] : '', |
| 84 | 'eventtitlesize' => isset($options[ 'cff_event_title_size' ]) ? $options[ 'cff_event_title_size' ] : '', |
| 85 | 'eventtitleweight' => isset($options[ 'cff_event_title_weight' ]) ? $options[ 'cff_event_title_weight' ] : '', |
| 86 | 'eventtitlecolor' => isset($options[ 'cff_event_title_color' ]) ? $options[ 'cff_event_title_color' ] : '', |
| 87 | 'eventtitlelink' => isset($options[ 'cff_event_title_link' ]) ? $options[ 'cff_event_title_link' ] : '', |
| 88 | //Event date |
| 89 | 'eventdatesize' => isset($options[ 'cff_event_date_size' ]) ? $options[ 'cff_event_date_size' ] : '', |
| 90 | 'eventdateweight' => isset($options[ 'cff_event_date_weight' ]) ? $options[ 'cff_event_date_weight' ] : '', |
| 91 | 'eventdatecolor' => isset($options[ 'cff_event_date_color' ]) ? $options[ 'cff_event_date_color' ] : '', |
| 92 | 'eventdatepos' => isset($options[ 'cff_event_date_position' ]) ? $options[ 'cff_event_date_position' ] : '', |
| 93 | 'eventdateformat' => isset($options[ 'cff_event_date_formatting' ]) ? $options[ 'cff_event_date_formatting' ] : '', |
| 94 | 'eventdatecustom' => isset($options[ 'cff_event_date_custom' ]) ? $options[ 'cff_event_date_custom' ] : '', |
| 95 | //Event details |
| 96 | 'eventdetailssize' => isset($options[ 'cff_event_details_size' ]) ? $options[ 'cff_event_details_size' ] : '', |
| 97 | 'eventdetailsweight' => isset($options[ 'cff_event_details_weight' ]) ? $options[ 'cff_event_details_weight' ] : '', |
| 98 | 'eventdetailscolor' => isset($options[ 'cff_event_details_color' ]) ? $options[ 'cff_event_details_color' ] : '', |
| 99 | //Date |
| 100 | 'datepos' => isset($options[ 'cff_date_position' ]) ? $options[ 'cff_date_position' ] : '', |
| 101 | 'datesize' => isset($options[ 'cff_date_size' ]) ? $options[ 'cff_date_size' ] : '', |
| 102 | 'dateweight' => isset($options[ 'cff_date_weight' ]) ? $options[ 'cff_date_weight' ] : '', |
| 103 | 'datecolor' => isset($options[ 'cff_date_color' ]) ? $options[ 'cff_date_color' ] : '', |
| 104 | 'dateformat' => isset($options[ 'cff_date_formatting' ]) ? $options[ 'cff_date_formatting' ] : '', |
| 105 | 'datecustom' => isset($options[ 'cff_date_custom' ]) ? $options[ 'cff_date_custom' ] : '', |
| 106 | 'timezone' => isset($options[ 'cff_timezone' ]) ? $options[ 'cff_timezone' ] : 'America/Chicago', |
| 107 | |
| 108 | //Link to Facebook |
| 109 | 'linksize' => isset($options[ 'cff_link_size' ]) ? $options[ 'cff_link_size' ] : '', |
| 110 | 'linkweight' => isset($options[ 'cff_link_weight' ]) ? $options[ 'cff_link_weight' ] : '', |
| 111 | 'linkcolor' => isset($options[ 'cff_link_color' ]) ? $options[ 'cff_link_color' ] : '', |
| 112 | 'viewlinktext' => isset($options[ 'cff_view_link_text' ]) ? $options[ 'cff_view_link_text' ] : '', |
| 113 | 'linktotimeline' => isset($options[ 'cff_link_to_timeline' ]) ? $options[ 'cff_link_to_timeline' ] : '', |
| 114 | //Social |
| 115 | 'iconstyle' => isset($options[ 'cff_icon_style' ]) ? $options[ 'cff_icon_style' ] : '', |
| 116 | 'socialtextcolor' => isset($options[ 'cff_meta_text_color' ]) ? $options[ 'cff_meta_text_color' ] : '', |
| 117 | 'socialbgcolor' => isset($options[ 'cff_meta_bg_color' ]) ? $options[ 'cff_meta_bg_color' ] : '', |
| 118 | //Misc |
| 119 | 'textlength' => get_option('cff_title_length'), |
| 120 | 'desclength' => get_option('cff_body_length'), |
| 121 | 'likeboxpos' => isset($options[ 'cff_like_box_position' ]) ? $options[ 'cff_like_box_position' ] : '', |
| 122 | 'likeboxoutside' => isset($options[ 'cff_like_box_outside' ]) ? $options[ 'cff_like_box_outside' ] : '', |
| 123 | 'likeboxcolor' => isset($options[ 'cff_likebox_bg_color' ]) ? $options[ 'cff_likebox_bg_color' ] : '', |
| 124 | 'likeboxtextcolor' => isset($options[ 'cff_like_box_text_color' ]) ? $options[ 'cff_like_box_text_color' ] : '', |
| 125 | 'likeboxwidth' => isset($options[ 'cff_likebox_width' ]) ? $options[ 'cff_likebox_width' ] : '', |
| 126 | 'likeboxfaces' => isset($options[ 'cff_like_box_faces' ]) ? $options[ 'cff_like_box_faces' ] : '', |
| 127 | 'likeboxborder' => isset($options[ 'cff_like_box_border' ]) ? $options[ 'cff_like_box_border' ] : '', |
| 128 | |
| 129 | //Page Header |
| 130 | 'showheader' => isset($options[ 'cff_show_header' ]) ? $options[ 'cff_show_header' ] : '', |
| 131 | 'headeroutside' => isset($options[ 'cff_header_outside' ]) ? $options[ 'cff_header_outside' ] : '', |
| 132 | 'headertext' => isset($options[ 'cff_header_text' ]) ? $options[ 'cff_header_text' ] : '', |
| 133 | 'headerbg' => isset($options[ 'cff_header_bg_color' ]) ? $options[ 'cff_header_bg_color' ] : '', |
| 134 | 'headerpadding' => isset($options[ 'cff_header_padding' ]) ? $options[ 'cff_header_padding' ] : '', |
| 135 | 'headertextsize' => isset($options[ 'cff_header_text_size' ]) ? $options[ 'cff_header_text_size' ] : '', |
| 136 | 'headertextweight' => isset($options[ 'cff_header_text_weight' ]) ? $options[ 'cff_header_text_weight' ] : '', |
| 137 | 'headertextcolor' => isset($options[ 'cff_header_text_color' ]) ? $options[ 'cff_header_text_color' ] : '', |
| 138 | 'headericon' => isset($options[ 'cff_header_icon' ]) ? $options[ 'cff_header_icon' ] : '', |
| 139 | 'headericoncolor' => isset($options[ 'cff_header_icon_color' ]) ? $options[ 'cff_header_icon_color' ] : '', |
| 140 | 'headericonsize' => isset($options[ 'cff_header_icon_size' ]) ? $options[ 'cff_header_icon_size' ] : '', |
| 141 | |
| 142 | 'videoheight' => isset($options[ 'cff_video_height' ]) ? $options[ 'cff_video_height' ] : '', |
| 143 | 'videoaction' => isset($options[ 'cff_video_action' ]) ? $options[ 'cff_video_action' ] : '', |
| 144 | 'sepcolor' => isset($options[ 'cff_sep_color' ]) ? $options[ 'cff_sep_color' ] : '', |
| 145 | 'sepsize' => isset($options[ 'cff_sep_size' ]) ? $options[ 'cff_sep_size' ] : '', |
| 146 | |
| 147 | //Translate |
| 148 | 'seemoretext' => isset($options[ 'cff_see_more_text' ]) ? $options[ 'cff_see_more_text' ] : '', |
| 149 | 'seelesstext' => isset($options[ 'cff_see_less_text' ]) ? $options[ 'cff_see_less_text' ] : '', |
| 150 | 'facebooklinktext' => isset($options[ 'cff_facebook_link_text' ]) ? $options[ 'cff_facebook_link_text' ] : '', |
| 151 | 'photostext' => isset($options[ 'cff_translate_photos_text' ]) ? $options[ 'cff_translate_photos_text' ] : '' |
| 152 | ), $atts); |
| 153 | /********** GENERAL **********/ |
| 154 | $cff_page_type = $atts[ 'pagetype' ]; |
| 155 | ($cff_page_type == 'group') ? $cff_is_group = true : $cff_is_group = false; |
| 156 | |
| 157 | $cff_feed_width = $atts['width']; |
| 158 | $cff_feed_height = $atts[ 'height' ]; |
| 159 | $cff_feed_padding = $atts[ 'padding' ]; |
| 160 | $cff_bg_color = $atts[ 'bgcolor' ]; |
| 161 | $cff_show_author = $atts[ 'showauthornew' ]; |
| 162 | $cff_cache_time = $atts[ 'cachetime' ]; |
| 163 | $cff_locale = $atts[ 'locale' ]; |
| 164 | if ( empty($cff_locale) || !isset($cff_locale) || $cff_locale == '' ) $cff_locale = 'en_US'; |
| 165 | if (!isset($cff_cache_time)) $cff_cache_time = 0; |
| 166 | $cff_cache_time_unit = $atts[ 'cacheunit' ]; |
| 167 | $cff_class = $atts['class']; |
| 168 | //Compile feed styles |
| 169 | $cff_feed_styles = 'style="'; |
| 170 | if ( !empty($cff_feed_width) ) $cff_feed_styles .= 'width:' . $cff_feed_width . '; '; |
| 171 | if ( !empty($cff_feed_height) ) $cff_feed_styles .= 'height:' . $cff_feed_height . '; '; |
| 172 | if ( !empty($cff_feed_padding) ) $cff_feed_styles .= 'padding:' . $cff_feed_padding . '; '; |
| 173 | if ( !empty($cff_bg_color) ) $cff_feed_styles .= 'background-color:#' . str_replace('#', '', $cff_bg_color) . '; '; |
| 174 | $cff_feed_styles .= '"'; |
| 175 | //Like box |
| 176 | $cff_like_box_position = $atts[ 'likeboxpos' ]; |
| 177 | $cff_like_box_outside = $atts[ 'likeboxoutside' ]; |
| 178 | //Open links in new window? |
| 179 | $target = 'target="_blank"'; |
| 180 | /********** POST TYPES **********/ |
| 181 | $cff_show_links_type = true; |
| 182 | $cff_show_event_type = true; |
| 183 | $cff_show_video_type = true; |
| 184 | $cff_show_photos_type = true; |
| 185 | $cff_show_status_type = true; |
| 186 | $cff_events_only = false; |
| 187 | //Are we showing ONLY events? |
| 188 | if ($cff_show_event_type && !$cff_show_links_type && !$cff_show_video_type && !$cff_show_photos_type && !$cff_show_status_type) $cff_events_only = true; |
| 189 | /********** LAYOUT **********/ |
| 190 | $cff_includes = $atts[ 'include' ]; |
| 191 | //Look for non-plural version of string in the types string in case user specifies singular in shortcode |
| 192 | $cff_show_author = false; |
| 193 | $cff_show_text = false; |
| 194 | $cff_show_desc = false; |
| 195 | $cff_show_shared_links = false; |
| 196 | $cff_show_date = false; |
| 197 | $cff_show_media = false; |
| 198 | $cff_show_event_title = false; |
| 199 | $cff_show_event_details = false; |
| 200 | $cff_show_meta = false; |
| 201 | $cff_show_link = false; |
| 202 | $cff_show_like_box = false; |
| 203 | if ( stripos($cff_includes, 'author') !== false ) $cff_show_author = true; |
| 204 | if ( stripos($cff_includes, 'text') !== false ) $cff_show_text = true; |
| 205 | if ( stripos($cff_includes, 'desc') !== false ) $cff_show_desc = true; |
| 206 | if ( stripos($cff_includes, 'sharedlink') !== false ) $cff_show_shared_links = true; |
| 207 | if ( stripos($cff_includes, 'date') !== false ) $cff_show_date = true; |
| 208 | if ( stripos($cff_includes, 'media') !== false ) $cff_show_media = true; |
| 209 | if ( stripos($cff_includes, 'eventtitle') !== false ) $cff_show_event_title = true; |
| 210 | if ( stripos($cff_includes, 'eventdetail') !== false ) $cff_show_event_details = true; |
| 211 | if ( stripos($cff_includes, 'social') !== false ) $cff_show_meta = true; |
| 212 | if ( stripos($cff_includes, ',link') !== false ) $cff_show_link = true; //comma used to separate it from 'sharedlinks' - which also contains 'link' string |
| 213 | if ( stripos($cff_includes, 'like') !== false ) $cff_show_like_box = true; |
| 214 | |
| 215 | |
| 216 | //Exclude string |
| 217 | $cff_excludes = $atts[ 'exclude' ]; |
| 218 | //Look for non-plural version of string in the types string in case user specifies singular in shortcode |
| 219 | if ( stripos($cff_excludes, 'author') !== false ) $cff_show_author = false; |
| 220 | if ( stripos($cff_excludes, 'text') !== false ) $cff_show_text = false; |
| 221 | if ( stripos($cff_excludes, 'desc') !== false ) $cff_show_desc = false; |
| 222 | if ( stripos($cff_excludes, 'sharedlink') !== false ) $cff_show_shared_links = false; |
| 223 | if ( stripos($cff_excludes, 'date') !== false ) $cff_show_date = false; |
| 224 | if ( stripos($cff_excludes, 'media') !== false ) $cff_show_media = false; |
| 225 | if ( stripos($cff_excludes, 'eventtitle') !== false ) $cff_show_event_title = false; |
| 226 | if ( stripos($cff_excludes, 'eventdetail') !== false ) $cff_show_event_details = false; |
| 227 | if ( stripos($cff_excludes, 'social') !== false ) $cff_show_meta = false; |
| 228 | if ( stripos($cff_excludes, ',link') !== false ) $cff_show_link = false; //comma used to separate it from 'sharedlinks' - which also contains 'link' string |
| 229 | if ( stripos($cff_excludes, 'like') !== false ) $cff_show_like_box = false; |
| 230 | |
| 231 | |
| 232 | //Set free version to thumb layout by default as layout option not available on settings page |
| 233 | $cff_preset_layout = 'thumb'; |
| 234 | |
| 235 | //If the old shortcode option 'showauthor' is being used then apply it |
| 236 | $cff_show_author_old = $atts[ 'showauthor' ]; |
| 237 | if( $cff_show_author_old == 'false' ) $cff_show_author = false; |
| 238 | if( $cff_show_author_old == 'true' ) $cff_show_author = true; |
| 239 | |
| 240 | |
| 241 | /********** META **********/ |
| 242 | $cff_icon_style = $atts[ 'iconstyle' ]; |
| 243 | $cff_meta_text_color = $atts[ 'socialtextcolor' ]; |
| 244 | $cff_meta_bg_color = $atts[ 'socialbgcolor' ]; |
| 245 | $cff_meta_styles = 'style="'; |
| 246 | if ( !empty($cff_meta_text_color) ) $cff_meta_styles .= 'color:#' . str_replace('#', '', $cff_meta_text_color) . ';'; |
| 247 | if ( !empty($cff_meta_bg_color) ) $cff_meta_styles .= 'background-color:#' . str_replace('#', '', $cff_meta_bg_color) . ';'; |
| 248 | $cff_meta_styles .= '"'; |
| 249 | $cff_nocomments_text = isset($options[ 'cff_nocomments_text' ]) ? $options[ 'cff_nocomments_text' ] : ''; |
| 250 | $cff_hide_comments = isset($options[ 'cff_hide_comments' ]) ? $options[ 'cff_hide_comments' ] : ''; |
| 251 | if (!isset($cff_nocomments_text) || empty($cff_nocomments_text)) $cff_hide_comments = true; |
| 252 | /********** TYPOGRAPHY **********/ |
| 253 | //See More text |
| 254 | $cff_see_more_text = $atts[ 'seemoretext' ]; |
| 255 | $cff_see_less_text = $atts[ 'seelesstext' ]; |
| 256 | //See Less text |
| 257 | //Title |
| 258 | $cff_title_format = $atts[ 'textformat' ]; |
| 259 | if (empty($cff_title_format)) $cff_title_format = 'p'; |
| 260 | $cff_title_size = $atts[ 'textsize' ]; |
| 261 | $cff_title_weight = $atts[ 'textweight' ]; |
| 262 | $cff_title_color = $atts[ 'textcolor' ]; |
| 263 | $cff_title_styles = 'style="'; |
| 264 | if ( !empty($cff_title_size) && $cff_title_size != 'inherit' ) $cff_title_styles .= 'font-size:' . $cff_title_size . 'px; '; |
| 265 | if ( !empty($cff_title_weight) && $cff_title_weight != 'inherit' ) $cff_title_styles .= 'font-weight:' . $cff_title_weight . '; '; |
| 266 | if ( !empty($cff_title_color) ) $cff_title_styles .= 'color:#' . str_replace('#', '', $cff_title_color) . ';'; |
| 267 | $cff_title_styles .= '"'; |
| 268 | $cff_title_link = $atts[ 'textlink' ]; |
| 269 | //Description |
| 270 | $cff_body_size = $atts[ 'descsize' ]; |
| 271 | $cff_body_weight = $atts[ 'descweight' ]; |
| 272 | $cff_body_color = $atts[ 'desccolor' ]; |
| 273 | $cff_body_styles = 'style="'; |
| 274 | if ( !empty($cff_body_size) && $cff_body_size != 'inherit' ) $cff_body_styles .= 'font-size:' . $cff_body_size . 'px; '; |
| 275 | if ( !empty($cff_body_weight) && $cff_body_weight != 'inherit' ) $cff_body_styles .= 'font-weight:' . $cff_body_weight . '; '; |
| 276 | if ( !empty($cff_body_color) ) $cff_body_styles .= 'color:#' . str_replace('#', '', $cff_body_color) . ';'; |
| 277 | $cff_body_styles .= '"'; |
| 278 | //Event Title |
| 279 | $cff_event_title_format = $atts[ 'eventtitleformat' ]; |
| 280 | if (empty($cff_event_title_format)) $cff_event_title_format = 'p'; |
| 281 | $cff_event_title_size = $atts[ 'eventtitlesize' ]; |
| 282 | $cff_event_title_weight = $atts[ 'eventtitleweight' ]; |
| 283 | $cff_event_title_color = $atts[ 'eventtitlecolor' ]; |
| 284 | $cff_event_title_styles = 'style="'; |
| 285 | if ( !empty($cff_event_title_size) && $cff_event_title_size != 'inherit' ) $cff_event_title_styles .= 'font-size:' . $cff_event_title_size . 'px; '; |
| 286 | if ( !empty($cff_event_title_weight) && $cff_event_title_weight != 'inherit' ) $cff_event_title_styles .= 'font-weight:' . $cff_event_title_weight . '; '; |
| 287 | if ( !empty($cff_event_title_color) ) $cff_event_title_styles .= 'color:#' . str_replace('#', '', $cff_event_title_color) . ';'; |
| 288 | $cff_event_title_styles .= '"'; |
| 289 | $cff_event_title_link = $atts[ 'eventtitlelink' ]; |
| 290 | //Event Date |
| 291 | $cff_event_date_size = $atts[ 'eventdatesize' ]; |
| 292 | $cff_event_date_weight = $atts[ 'eventdateweight' ]; |
| 293 | $cff_event_date_color = $atts[ 'eventdatecolor' ]; |
| 294 | $cff_event_date_position = $atts[ 'eventdatepos' ]; |
| 295 | $cff_event_date_formatting = $atts[ 'eventdateformat' ]; |
| 296 | $cff_event_date_custom = $atts[ 'eventdatecustom' ]; |
| 297 | $cff_event_date_styles = 'style="'; |
| 298 | if ( !empty($cff_event_date_size) && $cff_event_date_size != 'inherit' ) $cff_event_date_styles .= 'font-size:' . $cff_event_date_size . 'px; '; |
| 299 | if ( !empty($cff_event_date_weight) && $cff_event_date_weight != 'inherit' ) $cff_event_date_styles .= 'font-weight:' . $cff_event_date_weight . '; '; |
| 300 | if ( !empty($cff_event_date_color) ) $cff_event_date_styles .= 'color:#' . str_replace('#', '', $cff_event_date_color) . ';'; |
| 301 | $cff_event_date_styles .= '"'; |
| 302 | //Event Details |
| 303 | $cff_event_details_size = $atts[ 'eventdetailssize' ]; |
| 304 | $cff_event_details_weight = $atts[ 'eventdetailsweight' ]; |
| 305 | $cff_event_details_color = $atts[ 'eventdetailscolor' ]; |
| 306 | $cff_event_details_styles = 'style="'; |
| 307 | if ( !empty($cff_event_details_size) && $cff_event_details_size != 'inherit' ) $cff_event_details_styles .= 'font-size:' . $cff_event_details_size . 'px; '; |
| 308 | if ( !empty($cff_event_details_weight) && $cff_event_details_weight != 'inherit' ) $cff_event_details_styles .= 'font-weight:' . $cff_event_details_weight . '; '; |
| 309 | if ( !empty($cff_event_details_color) ) $cff_event_details_styles .= 'color:#' . str_replace('#', '', $cff_event_details_color) . ';'; |
| 310 | $cff_event_details_styles .= '"'; |
| 311 | //Date |
| 312 | $cff_date_position = $atts[ 'datepos' ]; |
| 313 | if (!isset($cff_date_position)) $cff_date_position = 'below'; |
| 314 | $cff_date_size = $atts[ 'datesize' ]; |
| 315 | $cff_date_weight = $atts[ 'dateweight' ]; |
| 316 | $cff_date_color = $atts[ 'datecolor' ]; |
| 317 | $cff_date_styles = 'style="'; |
| 318 | if ( !empty($cff_date_size) && $cff_date_size != 'inherit' ) $cff_date_styles .= 'font-size:' . $cff_date_size . 'px; '; |
| 319 | if ( !empty($cff_date_weight) && $cff_date_weight != 'inherit' ) $cff_date_styles .= 'font-weight:' . $cff_date_weight . '; '; |
| 320 | if ( !empty($cff_date_color) ) $cff_date_styles .= 'color:#' . str_replace('#', '', $cff_date_color) . ';'; |
| 321 | $cff_date_styles .= '"'; |
| 322 | $cff_date_before = isset($options[ 'cff_date_before' ]) ? $options[ 'cff_date_before' ] : ''; |
| 323 | $cff_date_after = isset($options[ 'cff_date_after' ]) ? $options[ 'cff_date_after' ] : ''; |
| 324 | //Set user's timezone based on setting |
| 325 | $cff_timezone = $atts['timezone']; |
| 326 | $cff_orig_timezone = date_default_timezone_get(); |
| 327 | date_default_timezone_set($cff_timezone); |
| 328 | //Link to Facebook |
| 329 | $cff_link_size = $atts[ 'linksize' ]; |
| 330 | $cff_link_weight = $atts[ 'linkweight' ]; |
| 331 | $cff_link_color = $atts[ 'linkcolor' ]; |
| 332 | $cff_link_styles = 'style="'; |
| 333 | if ( !empty($cff_link_size) && $cff_link_size != 'inherit' ) $cff_link_styles .= 'font-size:' . $cff_link_size . 'px; '; |
| 334 | if ( !empty($cff_link_weight) && $cff_link_weight != 'inherit' ) $cff_link_styles .= 'font-weight:' . $cff_link_weight . '; '; |
| 335 | if ( !empty($cff_link_color) ) $cff_link_styles .= 'color:#' . str_replace('#', '', $cff_link_color) . ';'; |
| 336 | $cff_link_styles .= '"'; |
| 337 | $cff_facebook_link_text = $atts[ 'facebooklinktext' ]; |
| 338 | $cff_view_link_text = $atts[ 'viewlinktext' ]; |
| 339 | $cff_link_to_timeline = $atts[ 'linktotimeline' ]; |
| 340 | /********** MISC **********/ |
| 341 | //Like Box styles |
| 342 | $cff_likebox_bg_color = $atts[ 'likeboxcolor' ]; |
| 343 | |
| 344 | $cff_like_box_text_color = $atts[ 'likeboxtextcolor' ]; |
| 345 | $cff_like_box_colorscheme = 'light'; |
| 346 | if ($cff_like_box_text_color == 'white') $cff_like_box_colorscheme = 'dark'; |
| 347 | |
| 348 | $cff_likebox_styles = 'style="'; |
| 349 | if ( !empty($cff_likebox_bg_color) ) $cff_likebox_styles .= 'background-color:#' . str_replace('#', '', $cff_likebox_bg_color) . '; margin-left: 0; '; |
| 350 | |
| 351 | $cff_likebox_width = $atts[ 'likeboxwidth' ]; |
| 352 | if ( !isset($cff_likebox_width) || empty($cff_likebox_width) || $cff_likebox_width == '' ) $cff_likebox_width = '100%'; |
| 353 | $cff_like_box_faces = $atts[ 'likeboxfaces' ]; |
| 354 | if ( !isset($cff_like_box_faces) || empty($cff_like_box_faces) ) $cff_like_box_faces = 'false'; |
| 355 | $cff_like_box_border = $atts[ 'likeboxborder' ]; |
| 356 | if ($cff_like_box_border) { |
| 357 | $cff_like_box_border = 'true'; |
| 358 | } else { |
| 359 | $cff_like_box_border = 'false'; |
| 360 | } |
| 361 | |
| 362 | //Compile Like box styles |
| 363 | $cff_likebox_styles = 'style="width: ' . $cff_likebox_width . ';'; |
| 364 | if ( !empty($cff_likebox_bg_color) ) $cff_likebox_styles .= 'background-color: #' . str_replace('#', '', $cff_likebox_bg_color) . ';'; |
| 365 | if ( empty($cff_likebox_bg_color) && $cff_like_box_faces == 'false' ) $cff_likebox_styles .= ' margin-left: -10px;'; |
| 366 | $cff_likebox_styles .= '"'; |
| 367 | |
| 368 | //Get feed header settings |
| 369 | $cff_header_bg_color = $atts['headerbg']; |
| 370 | $cff_header_padding = $atts['headerpadding']; |
| 371 | $cff_header_text_size = $atts['headertextsize']; |
| 372 | $cff_header_text_weight = $atts['headertextweight']; |
| 373 | $cff_header_text_color = $atts['headertextcolor']; |
| 374 | |
| 375 | //Compile feed header styles |
| 376 | $cff_header_styles = 'style="'; |
| 377 | if ( !empty($cff_header_bg_color) ) $cff_header_styles .= 'background-color: #' . str_replace('#', '', $cff_header_bg_color) . ';'; |
| 378 | if ( !empty($cff_header_padding) ) $cff_header_styles .= ' padding: ' . $cff_header_padding . ';'; |
| 379 | if ( !empty($cff_header_text_size) ) $cff_header_styles .= ' font-size: ' . $cff_header_text_size . 'px;'; |
| 380 | if ( !empty($cff_header_text_weight) ) $cff_header_styles .= ' font-weight: ' . $cff_header_text_weight . ';'; |
| 381 | if ( !empty($cff_header_text_color) ) $cff_header_styles .= ' color: #' . str_replace('#', '', $cff_header_text_color) . ';'; |
| 382 | $cff_header_styles .= '"'; |
| 383 | |
| 384 | //Video |
| 385 | //Dimensions |
| 386 | $cff_video_width = 640; |
| 387 | $cff_video_height = $atts[ 'videoheight' ]; |
| 388 | |
| 389 | //Action |
| 390 | $cff_video_action = $atts[ 'videoaction' ]; |
| 391 | //Separating Line |
| 392 | $cff_sep_color = $atts[ 'sepcolor' ]; |
| 393 | if (empty($cff_sep_color)) $cff_sep_color = 'ddd'; |
| 394 | $cff_sep_size = $atts[ 'sepsize' ]; |
| 395 | if (empty($cff_sep_size)) $cff_sep_size = 0; |
| 396 | //CFF item styles |
| 397 | $cff_item_styles = 'style="'; |
| 398 | $cff_item_styles .= 'border-bottom: ' . $cff_sep_size . 'px solid #' . str_replace('#', '', $cff_sep_color) . '; '; |
| 399 | $cff_item_styles .= '"'; |
| 400 | |
| 401 | //Text limits |
| 402 | $title_limit = $atts['textlength']; |
| 403 | if (!isset($title_limit)) $title_limit = 9999; |
| 404 | $body_limit = $atts['desclength']; |
| 405 | //Assign the Access Token and Page ID variables |
| 406 | $access_token = $atts['accesstoken']; |
| 407 | $page_id = trim( $atts['id'] ); |
| 408 | |
| 409 | //If user pastes their full URL into the Page ID field then strip it out |
| 410 | $cff_facebook_string = 'facebook.com'; |
| 411 | $cff_page_id_url_check = stripos($page_id, $cff_facebook_string); |
| 412 | |
| 413 | if ( $cff_page_id_url_check ) { |
| 414 | //Remove trailing slash if exists |
| 415 | $page_id = preg_replace('{/$}', '', $page_id); |
| 416 | //Get last part of url |
| 417 | $page_id = substr( $page_id, strrpos( $page_id, '/' )+1 ); |
| 418 | } |
| 419 | |
| 420 | //Get show posts attribute. If not set then default to 25 |
| 421 | $show_posts = $atts['num']; |
| 422 | if (empty($show_posts)) $show_posts = 25; |
| 423 | if ( $show_posts == 0 || $show_posts == 'undefined' ) $show_posts = 25; |
| 424 | //Check whether the Access Token is present and valid |
| 425 | if ($access_token == '') { |
| 426 | echo 'Please enter a valid Access Token. You can do this in the Custom Facebook Feed plugin settings.<br /><br />'; |
| 427 | return false; |
| 428 | } |
| 429 | //Check whether a Page ID has been defined |
| 430 | if ($page_id == '') { |
| 431 | echo "Please enter the Page ID of the Facebook feed you'd like to display. You can do this in either the Custom Facebook Feed plugin settings or in the shortcode itself. For example [custom_facebook_feed id=<b>YOUR_PAGE_ID</b>].<br /><br />"; |
| 432 | return false; |
| 433 | } |
| 434 | |
| 435 | |
| 436 | //Is it SSL? |
| 437 | $cff_ssl = ''; |
| 438 | if (is_ssl()) $cff_ssl = '&return_ssl_resources=true'; |
| 439 | |
| 440 | //Use posts? or feed? |
| 441 | $old_others_option = get_option('cff_show_others'); //Use this to help depreciate the old option |
| 442 | $show_others = $atts['others']; |
| 443 | $show_posts_by = $atts['showpostsby']; |
| 444 | $graph_query = 'posts'; |
| 445 | $cff_show_only_others = false; |
| 446 | |
| 447 | //If 'others' shortcode option is used then it overrides any other option |
| 448 | if ($show_others || $old_others_option == 'on') { |
| 449 | //Show posts by everyone |
| 450 | if ( $old_others_option == 'on' || $show_others == 'on' || $show_others == 'true' || $show_others == true || $cff_is_group ) $graph_query = 'feed'; |
| 451 | |
| 452 | //Only show posts by me |
| 453 | if ( $show_others == 'false' ) $graph_query = 'posts'; |
| 454 | |
| 455 | } else { |
| 456 | //Else use the settings page option or the 'showpostsby' shortcode option |
| 457 | |
| 458 | //Only show posts by me |
| 459 | if ( $show_posts_by == 'me' ) $graph_query = 'posts'; |
| 460 | |
| 461 | //Show posts by everyone |
| 462 | if ( $show_posts_by == 'others' || $cff_is_group ) $graph_query = 'feed'; |
| 463 | |
| 464 | //Show posts ONLY by others |
| 465 | if ( $show_posts_by == 'onlyothers' && !$cff_is_group ) { |
| 466 | $graph_query = 'feed'; |
| 467 | $cff_show_only_others = true; |
| 468 | } |
| 469 | |
| 470 | } |
| 471 | |
| 472 | |
| 473 | //If the limit isn't set then set it to be 5 more than the number of posts defined |
| 474 | if ( isset($atts['limit']) && $atts['limit'] !== '' ) { |
| 475 | $cff_post_limit = $atts['limit']; |
| 476 | } else { |
| 477 | $cff_post_limit = intval(intval($show_posts) + 7); |
| 478 | } |
| 479 | |
| 480 | |
| 481 | //Calculate the cache time in seconds |
| 482 | if($cff_cache_time_unit == 'minutes') $cff_cache_time_unit = 60; |
| 483 | if($cff_cache_time_unit == 'hours') $cff_cache_time_unit = 60*60; |
| 484 | if($cff_cache_time_unit == 'days') $cff_cache_time_unit = 60*60*24; |
| 485 | $cache_seconds = $cff_cache_time * $cff_cache_time_unit; |
| 486 | |
| 487 | //Get like box vars |
| 488 | $cff_likebox_width = $atts[ 'likeboxwidth' ]; |
| 489 | if ( !isset($cff_likebox_width) || empty($cff_likebox_width) || $cff_likebox_width == '' ) $cff_likebox_width = 300; |
| 490 | $cff_like_box_faces = $atts[ 'likeboxfaces' ]; |
| 491 | if ( !isset($cff_like_box_faces) || empty($cff_like_box_faces) ) $cff_like_box_faces = 'false'; |
| 492 | |
| 493 | //Set like box variable |
| 494 | $like_box = '<div class="cff-likebox'; |
| 495 | if ($cff_like_box_outside) $like_box .= ' cff-outside'; |
| 496 | $like_box .= ($cff_like_box_position == 'top') ? ' top' : ' bottom'; |
| 497 | $like_box .= '" ' . $cff_likebox_styles . '><script src="https://connect.facebook.net/' . $cff_locale . '/all.js#xfbml=1"></script><fb:like-box href="http://www.facebook.com/' . $page_id . '" show_faces="'.$cff_like_box_faces.'" stream="false" header="false" colorscheme="'. $cff_like_box_colorscheme .'" show_border="'. $cff_like_box_border .'"></fb:like-box></div>'; |
| 498 | //Don't show like box if it's a group |
| 499 | if($cff_is_group) $like_box = ''; |
| 500 | |
| 501 | |
| 502 | //Feed header |
| 503 | $cff_show_header = $atts['showheader']; |
| 504 | ($cff_show_header == 'true' || $cff_show_header == 'on') ? $cff_show_header = true : $cff_show_header = false; |
| 505 | |
| 506 | $cff_header_outside = $atts['headeroutside']; |
| 507 | ($cff_header_outside == 'true' || $cff_header_outside == 'on') ? $cff_header_outside = true : $cff_header_outside = false; |
| 508 | |
| 509 | $cff_header_text = $atts['headertext']; |
| 510 | $cff_header_icon = $atts['headericon']; |
| 511 | $cff_header_icon_color = $atts['headericoncolor']; |
| 512 | $cff_header_icon_size = $atts['headericonsize']; |
| 513 | |
| 514 | $cff_header = '<h3 class="cff-header'; |
| 515 | if ($cff_header_outside) $cff_header .= ' cff-outside'; |
| 516 | $cff_header .= '"' . $cff_header_styles . '>'; |
| 517 | $cff_header .= '<i class="fa fa-' . $cff_header_icon . '"'; |
| 518 | if(!empty($cff_header_icon_color) || !empty($cff_header_icon_size)) $cff_header .= ' style="'; |
| 519 | if(!empty($cff_header_icon_color)) $cff_header .= 'color: #' . $cff_header_icon_color . ';'; |
| 520 | if(!empty($cff_header_icon_size)) $cff_header .= ' font-size: ' . $cff_header_icon_size . 'px;'; |
| 521 | if(!empty($cff_header_icon_color) || !empty($cff_header_icon_size))$cff_header .= '"'; |
| 522 | $cff_header .= '></i>'; |
| 523 | $cff_header .= $cff_header_text; |
| 524 | $cff_header .= '</h3>'; |
| 525 | |
| 526 | |
| 527 | //***START FEED*** |
| 528 | $cff_content = ''; |
| 529 | |
| 530 | //Add the page header to the outside of the top of feed |
| 531 | if ($cff_show_header && $cff_header_outside) $cff_content .= $cff_header; |
| 532 | |
| 533 | //Add like box to the outside of the top of feed |
| 534 | if ($cff_like_box_position == 'top' && $cff_show_like_box && $cff_like_box_outside) $cff_content .= $like_box; |
| 535 | |
| 536 | //Create CFF container HTML |
| 537 | $cff_content .= '<div id="cff" rel="'.$title_limit.'" class="'; |
| 538 | if( !empty($cff_class) ) $cff_content .= $cff_class . ' '; |
| 539 | if ( !empty($cff_feed_height) ) $cff_content .= 'cff-fixed-height '; |
| 540 | $cff_content .= '" ' . $cff_feed_styles . '>'; |
| 541 | |
| 542 | //Add the page header to the inside of the top of feed |
| 543 | if ($cff_show_header && !$cff_header_outside) $cff_content .= $cff_header; |
| 544 | |
| 545 | //Add like box to the inside of the top of feed |
| 546 | if ($cff_like_box_position == 'top' && $cff_show_like_box && !$cff_like_box_outside) $cff_content .= $like_box; |
| 547 | //Limit var |
| 548 | $i = 0; |
| 549 | |
| 550 | //Define array for post items |
| 551 | $cff_posts_array = array(); |
| 552 | |
| 553 | //ALL POSTS |
| 554 | if (!$cff_events_only){ |
| 555 | |
| 556 | $cff_posts_json_url = 'https://graph.facebook.com/' . $page_id . '/' . $graph_query . '?access_token=' . $access_token . '&limit=' . $cff_post_limit . '&locale=' . $cff_locale . $cff_ssl; |
| 557 | |
| 558 | //Don't use caching if the cache time is set to zero |
| 559 | if ($cff_cache_time != 0){ |
| 560 | // Get any existing copy of our transient data |
| 561 | $transient_name = 'cff_'. $graph_query .'_json_' . $page_id; |
| 562 | if ( false === ( $posts_json = get_transient( $transient_name ) ) || $posts_json === null ) { |
| 563 | //Get the contents of the Facebook page |
| 564 | $posts_json = cff_fetchUrl($cff_posts_json_url); |
| 565 | //Cache the JSON |
| 566 | set_transient( $transient_name, $posts_json, $cache_seconds ); |
| 567 | } else { |
| 568 | $posts_json = get_transient( $transient_name ); |
| 569 | //If we can't find the transient then fall back to just getting the json from the api |
| 570 | if ($posts_json == false) $posts_json = cff_fetchUrl($cff_posts_json_url); |
| 571 | } |
| 572 | } else { |
| 573 | $posts_json = cff_fetchUrl($cff_posts_json_url); |
| 574 | } |
| 575 | |
| 576 | |
| 577 | |
| 578 | //Interpret data with JSON |
| 579 | $FBdata = json_decode($posts_json); |
| 580 | //***STARTS POSTS LOOP*** |
| 581 | foreach ($FBdata->data as $news ) |
| 582 | { |
| 583 | //Explode News and Page ID's into 2 values |
| 584 | $PostID = explode("_", $news->id); |
| 585 | //Check the post type |
| 586 | $cff_post_type = $news->type; |
| 587 | if ($cff_post_type == 'link') { |
| 588 | isset($news->story) ? $story = $news->story : $story = ''; |
| 589 | //Check whether it's an event |
| 590 | $event_link_check = "facebook.com/events/"; |
| 591 | $event_link_check = stripos($news->link, $event_link_check); |
| 592 | if ( $event_link_check ) $cff_post_type = 'event'; |
| 593 | } |
| 594 | //Should we show this post or not? |
| 595 | $cff_show_post = false; |
| 596 | switch ($cff_post_type) { |
| 597 | case 'link': |
| 598 | if ( $cff_show_links_type ) $cff_show_post = true; |
| 599 | break; |
| 600 | case 'event': |
| 601 | if ( $cff_show_event_type ) $cff_show_post = true; |
| 602 | break; |
| 603 | case 'video': |
| 604 | if ( $cff_show_video_type ) $cff_show_post = true; |
| 605 | break; |
| 606 | case 'swf': |
| 607 | if ( $cff_show_video_type ) $cff_show_post = true; |
| 608 | break; |
| 609 | case 'photo': |
| 610 | if ( $cff_show_photos_type ) $cff_show_post = true; |
| 611 | break; |
| 612 | case 'offer': |
| 613 | $cff_show_post = true; |
| 614 | break; |
| 615 | case 'status': |
| 616 | //Check whether it's a status (author comment or like) |
| 617 | if ( $cff_show_status_type && !empty($news->message) ) $cff_show_post = true; |
| 618 | break; |
| 619 | } |
| 620 | |
| 621 | |
| 622 | //ONLY show posts by others |
| 623 | if ( $cff_show_only_others ) { |
| 624 | //Get the numeric ID of the page |
| 625 | $page_object = cff_fetchUrl('https://graph.facebook.com/' . $page_id); |
| 626 | $page_object = json_decode($page_object); |
| 627 | $numeric_page_id = $page_object->id; |
| 628 | |
| 629 | //If the post author's ID is the same as the page ID then don't show the post |
| 630 | if ( $numeric_page_id == $news->from->id ) $cff_show_post = false; |
| 631 | } |
| 632 | |
| 633 | |
| 634 | //Is it a duplicate post? |
| 635 | if (!isset($prev_post_message)) $prev_post_message = ''; |
| 636 | if (!isset($prev_post_link)) $prev_post_link = ''; |
| 637 | if (!isset($prev_post_description)) $prev_post_description = ''; |
| 638 | isset($news->message) ? $pm = $news->message : $pm = ''; |
| 639 | isset($news->link) ? $pl = $news->link : $pl = ''; |
| 640 | isset($news->description) ? $pd = $news->description : $pd = ''; |
| 641 | |
| 642 | if ( ($prev_post_message == $pm) && ($prev_post_link == $pl) && ($prev_post_description == $pd) ) $cff_show_post = false; |
| 643 | |
| 644 | //Check post type and display post if selected |
| 645 | if ( $cff_show_post ) { |
| 646 | //If it isn't then create the post |
| 647 | //Only create posts for the amount of posts specified |
| 648 | if ( $i == $show_posts ) break; |
| 649 | $i++; |
| 650 | //********************************// |
| 651 | //***COMPILE SECTION VARIABLES***// |
| 652 | //********************************// |
| 653 | //Set the post link |
| 654 | isset($news->link) ? $link = htmlspecialchars($news->link) : $link = ''; |
| 655 | //Is it a shared album? |
| 656 | $shared_album_string = 'shared an album:'; |
| 657 | isset($news->story) ? $story = $news->story : $story = ''; |
| 658 | $shared_album = stripos($story, $shared_album_string); |
| 659 | if ( $shared_album ) { |
| 660 | $link = str_replace('photo.php?','media/set/?',$link); |
| 661 | } |
| 662 | |
| 663 | //Is it an album? |
| 664 | $cff_album = false; |
| 665 | $album_string = 'relevant_count='; |
| 666 | $relevant_count = stripos($link, $album_string); |
| 667 | |
| 668 | if ( $relevant_count ) { |
| 669 | //If relevant_count is larger than 1 then there are multiple photos |
| 670 | $relevant_count = explode('relevant_count=', $link); |
| 671 | $num_photos = intval($relevant_count[1]); |
| 672 | if ( $num_photos > 1 ) { |
| 673 | $cff_album = true; |
| 674 | |
| 675 | //Link to the album instead of the photo |
| 676 | $album_link = str_replace('photo.php?','media/set/?',$link); |
| 677 | $link = "https://www.facebook.com/" . $page_id . "/posts/" . $PostID[1]; |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | //If there's no link provided then link to either the Facebook page or the individual status |
| 682 | if (empty($news->link)) { |
| 683 | if ($cff_link_to_timeline == true){ |
| 684 | //Link to page |
| 685 | $link = 'http://facebook.com/' . $page_id; |
| 686 | } else { |
| 687 | //Link to status |
| 688 | $link = "https://www.facebook.com/" . $page_id . "/posts/" . $PostID[1]; |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | //POST AUTHOR |
| 693 | $cff_author = '<a class="cff-author" href="https://facebook.com/' . $news->from->id . '" '.$target.' title="'.$news->from->name.' on Facebook">'; |
| 694 | |
| 695 | //Set the author image as a variable. If it already exists then don't query the api for it again. |
| 696 | $cff_author_img_var = '$cff_author_img_' . $news->from->id; |
| 697 | if ( !isset($$cff_author_img_var) ) $$cff_author_img_var = 'https://graph.facebook.com/' . $news->from->id . '/picture?type=square'; |
| 698 | |
| 699 | $cff_author .= '<img src="'.$$cff_author_img_var.'" width=50 height=50>'; |
| 700 | $cff_author .= '<span class="cff-page-name">'.$news->from->name.'</span>'; |
| 701 | $cff_author .= '</a>'; |
| 702 | |
| 703 | //POST TEXT |
| 704 | $cff_translate_photos_text = $atts['photostext']; |
| 705 | if (!isset($cff_translate_photos_text) || empty($cff_translate_photos_text)) $cff_translate_photos_text = 'photos'; |
| 706 | $cff_post_text = '<' . $cff_title_format . ' class="cff-post-text" ' . $cff_title_styles . '>'; |
| 707 | $cff_post_text .= '<span class="cff-text">'; |
| 708 | if ($cff_title_link == 'true') $cff_post_text .= '<a class="cff-post-text-link" href="'.$link.'" '.$target.'>'; |
| 709 | //Which content should we use? |
| 710 | $cff_post_text_type = ''; |
| 711 | //Use the story |
| 712 | if (!empty($news->story)) { |
| 713 | $post_text = htmlspecialchars($news->story); |
| 714 | $cff_post_text_type = 'story'; |
| 715 | } |
| 716 | //Use the message |
| 717 | if (!empty($news->message)) { |
| 718 | $post_text = htmlspecialchars($news->message); |
| 719 | $cff_post_text_type = 'message'; |
| 720 | } |
| 721 | //Use the name |
| 722 | if (!empty($news->name) && empty($news->story) && empty($news->message)) { |
| 723 | $post_text = htmlspecialchars($news->name); |
| 724 | $cff_post_text_type = 'name'; |
| 725 | } |
| 726 | if ($cff_album) { |
| 727 | if (!empty($news->name)) { |
| 728 | $post_text = htmlspecialchars($news->name); |
| 729 | $cff_post_text_type = 'name'; |
| 730 | } |
| 731 | if (!empty($news->message) && empty($news->name)) { |
| 732 | $post_text = htmlspecialchars($news->message); |
| 733 | $cff_post_text_type = 'message'; |
| 734 | } |
| 735 | $post_text .= ' (' . $num_photos . ' '.$cff_translate_photos_text.')'; |
| 736 | } |
| 737 | |
| 738 | |
| 739 | //MESSAGE TAGS |
| 740 | $cff_post_tags = $atts[ 'posttags' ]; |
| 741 | //If the post tags option doesn't exist yet (ie. on plugin update) then set them as true |
| 742 | if ( !array_key_exists( 'cff_post_tags', $options ) ) $cff_post_tags = true; |
| 743 | //Add message and story tags if there are any and the post text is the message or the story |
| 744 | if( $cff_post_tags && ( isset($news->message_tags) || isset($news->story_tags) ) && ($cff_post_text_type == 'message' || $cff_post_text_type == 'story') && $cff_title_link != 'true' ){ |
| 745 | //Use message_tags or story_tags? |
| 746 | ( $cff_post_text_type == 'message' )? $text_tags = $news->message_tags : $text_tags = $news->story_tags; |
| 747 | |
| 748 | //Does the Post Text contain any html tags? - the & symbol is the best indicator of this |
| 749 | $html_check = stripos($post_text, '&'); |
| 750 | |
| 751 | //If it contains HTML tags then use the name replace method |
| 752 | if( $html_check ) { |
| 753 | //Loop through the tags |
| 754 | foreach($text_tags as $message_tag ) { |
| 755 | $tag_name = $message_tag[0]->name; |
| 756 | $tag_link = '<a href="http://facebook.com/' . $message_tag[0]->id . '" target="_blank">' . $message_tag[0]->name . '</a>'; |
| 757 | |
| 758 | $post_text = str_replace($tag_name, $tag_link, $post_text); |
| 759 | } |
| 760 | |
| 761 | } else { |
| 762 | //If it doesn't contain HTMl tags then use the offset to replace message tags |
| 763 | $message_tags_arr = array(); |
| 764 | |
| 765 | $i = 0; |
| 766 | foreach($text_tags as $message_tag ) { |
| 767 | $i++; |
| 768 | $message_tags_arr = array_push_assoc( |
| 769 | $message_tags_arr, |
| 770 | $i, |
| 771 | array( |
| 772 | 'id' => $message_tag[0]->id, |
| 773 | 'name' => $message_tag[0]->name, |
| 774 | 'type' => $message_tag[0]->type, |
| 775 | 'offset' => $message_tag[0]->offset, |
| 776 | 'length' => $message_tag[0]->length |
| 777 | ) |
| 778 | ); |
| 779 | } |
| 780 | |
| 781 | for($i = count($message_tags_arr); $i >= 1; $i--) { |
| 782 | |
| 783 | $b = '<a href="http://facebook.com/' . $message_tags_arr[$i]['id'] . '" target="_blank">' . $message_tags_arr[$i]['name'] . '</a>'; |
| 784 | $c = $message_tags_arr[$i]['offset']; |
| 785 | $d = $message_tags_arr[$i]['length']; |
| 786 | |
| 787 | $post_text = substr_replace( $post_text, $b, $c, $d); |
| 788 | |
| 789 | } |
| 790 | |
| 791 | } |
| 792 | |
| 793 | } //END MESSAGE TAGS |
| 794 | |
| 795 | |
| 796 | //If the text is wrapped in a link then don't hyperlink any text within |
| 797 | if ($cff_title_link) { |
| 798 | //Wrap links in a span so we can break the text if it's too long |
| 799 | $cff_post_text .= cff_autolink( htmlspecialchars($post_text), true ) . ' '; |
| 800 | } else { |
| 801 | //Don't use htmlspecialchars for post_text as it's added above so that it doesn't mess up the message_tag offsets |
| 802 | $cff_post_text .= cff_autolink( $post_text ) . ' '; |
| 803 | } |
| 804 | |
| 805 | if ($cff_title_link) $cff_post_text .= '</a>'; |
| 806 | $cff_post_text .= '</span>'; |
| 807 | //'See More' link |
| 808 | $cff_post_text .= '<span class="cff-expand">... <a href="#"><span class="cff-more">' . $cff_see_more_text . '</span><span class="cff-less">' . $cff_see_less_text . '</span></a></span>'; |
| 809 | $cff_post_text .= '</' . $cff_title_format . '>'; |
| 810 | |
| 811 | //DESCRIPTION |
| 812 | $cff_description = ''; |
| 813 | //Use the description if it's available and the post type isn't set to offer (offer description isn't useful) |
| 814 | if ( ( !empty($news->description) || !empty($news->caption) ) && $cff_post_type != 'offer') { |
| 815 | |
| 816 | $description_text = ''; |
| 817 | if ( !empty($news->description) ) { |
| 818 | $description_text = $news->description; |
| 819 | } else { |
| 820 | $description_text = $news->caption; |
| 821 | } |
| 822 | |
| 823 | if (!empty($body_limit)) { |
| 824 | if (strlen($description_text) > $body_limit) $description_text = substr($description_text, 0, $body_limit) . '...'; |
| 825 | } |
| 826 | $cff_description .= '<p class="cff-post-desc" '.$cff_body_styles.'><span>' . cff_autolink( htmlspecialchars($description_text) ) . '</span></p>'; |
| 827 | |
| 828 | //If the post text and description/caption are the same then don't show the description |
| 829 | if($post_text == $description_text) $cff_description = ''; |
| 830 | |
| 831 | } |
| 832 | |
| 833 | //LINK |
| 834 | $cff_shared_link = ''; |
| 835 | //Display shared link |
| 836 | if ($news->type == 'link') { |
| 837 | $cff_shared_link .= '<div class="cff-shared-link">'; |
| 838 | |
| 839 | //Display link name and description |
| 840 | if (!empty($news->description)) { |
| 841 | $cff_shared_link .= '<div class="cff-text-link '; |
| 842 | $cff_shared_link .= 'cff-no-image'; |
| 843 | $cff_shared_link .= '"><a class="cff-link-title" href="'.$link.'" '.$target.'>'. '<b>' . $news->name . '</b></a>'; |
| 844 | if(!empty($news->caption)) $cff_shared_link .= '<p class="cff-link-caption">'.$news->caption.'</p>'; |
| 845 | if ($cff_show_desc) { |
| 846 | $cff_shared_link .= $cff_description; |
| 847 | } |
| 848 | $cff_shared_link .= '</div>'; |
| 849 | } |
| 850 | |
| 851 | $cff_shared_link .= '</div>'; |
| 852 | } |
| 853 | |
| 854 | //DATE |
| 855 | $cff_date_formatting = $atts[ 'dateformat' ]; |
| 856 | $cff_date_custom = $atts[ 'datecustom' ]; |
| 857 | |
| 858 | $post_time = $news->created_time; |
| 859 | $cff_date = '<p class="cff-date" '.$cff_date_styles.'>'. $cff_date_before . ' ' . cff_getdate(strtotime($post_time), $cff_date_formatting, $cff_date_custom) . ' ' . $cff_date_after . '</p>'; |
| 860 | //EVENT |
| 861 | $cff_event = ''; |
| 862 | if ($cff_show_event_title || $cff_show_event_details) { |
| 863 | //Check for media |
| 864 | if ($cff_post_type == 'event') { |
| 865 | |
| 866 | //Get the event id from the event URL. eg: http://www.facebook.com/events/123451234512345/ |
| 867 | $event_url = parse_url($link); |
| 868 | $url_parts = explode('/', $event_url['path']); |
| 869 | //Get the id from the parts |
| 870 | $eventID = $url_parts[count($url_parts)-2]; |
| 871 | |
| 872 | //Get the contents of the event using the WP HTTP API |
| 873 | $event_json_url = 'https://graph.facebook.com/'.$eventID.'?access_token=' . $access_token . $cff_ssl; |
| 874 | |
| 875 | //Don't use caching if the cache time is set to zero |
| 876 | if ($cff_cache_time != 0){ |
| 877 | // Get any existing copy of our transient data |
| 878 | $transient_name = 'cff_timeline_event_json_' . $eventID; |
| 879 | if ( false === ( $event_json = get_transient( $transient_name ) ) || $event_json === null ) { |
| 880 | //Get the contents of the Facebook page |
| 881 | $event_json = cff_fetchUrl($event_json_url); |
| 882 | //Cache the JSON |
| 883 | set_transient( $transient_name, $event_json, $cache_seconds ); |
| 884 | } else { |
| 885 | $event_json = get_transient( $transient_name ); |
| 886 | //If we can't find the transient then fall back to just getting the json from the api |
| 887 | if ($event_json == false) $event_json = cff_fetchUrl($event_json_url); |
| 888 | } |
| 889 | } else { |
| 890 | $event_json = cff_fetchUrl($event_json_url); |
| 891 | } |
| 892 | |
| 893 | //Interpret data with JSON |
| 894 | $event_object = json_decode($event_json); |
| 895 | //Event date |
| 896 | isset( $event_object->start_time ) ? $event_time = $event_object->start_time : $event_time = ''; |
| 897 | //If timezone migration is enabled then remove last 5 characters |
| 898 | if ( strlen($event_time) == 24 ) $event_time = substr($event_time, 0, -5); |
| 899 | if (!empty($event_time)) $cff_event_date = '<p class="cff-date" '.$cff_event_date_styles.'>' . cff_eventdate(strtotime($event_time), $cff_event_date_formatting, $cff_event_date_custom) . '</p>'; |
| 900 | //EVENT |
| 901 | //Display the event details |
| 902 | $cff_event .= '<div class="cff-details">'; |
| 903 | //show event date above title |
| 904 | if ($cff_event_date_position == 'above') $cff_event .= $cff_event_date; |
| 905 | //Show event title |
| 906 | if ($cff_show_event_title && !empty($event_object->name)) { |
| 907 | if ($cff_event_title_link) $cff_event .= '<a href="'.$link.'">'; |
| 908 | $cff_event .= '<' . $cff_event_title_format . ' ' . $cff_event_title_styles . '>' . $event_object->name . '</' . $cff_event_title_format . '>'; |
| 909 | if ($cff_event_title_link) $cff_event .= '</a>'; |
| 910 | } |
| 911 | //show event date below title |
| 912 | if ($cff_event_date_position !== 'above') $cff_event .= $cff_event_date; |
| 913 | //Show event details |
| 914 | if ($cff_show_event_details){ |
| 915 | //Location |
| 916 | if (!empty($event_object->location)) $cff_event .= '<p class="cff-where" ' . $cff_event_details_styles . '>' . $event_object->location . '</p>'; |
| 917 | //Description |
| 918 | if (!empty($event_object->description)){ |
| 919 | $description = $event_object->description; |
| 920 | if (!empty($body_limit)) { |
| 921 | if (strlen($description) > $body_limit) $description = substr($description, 0, $body_limit) . '...'; |
| 922 | } |
| 923 | $cff_event .= '<p class="cff-info" ' . $cff_event_details_styles . '>' . cff_autolink($description) . '</p>'; |
| 924 | } |
| 925 | } |
| 926 | $cff_event .= '</div>'; |
| 927 | |
| 928 | } |
| 929 | } |
| 930 | |
| 931 | /* VIDEO */ |
| 932 | $cff_is_video_embed = false; |
| 933 | $cff_media = ''; |
| 934 | if ($news->type == 'video') { |
| 935 | $cff_is_video_embed = true; |
| 936 | //Add the name to the description if it's a video embed |
| 937 | if($cff_is_video_embed) { |
| 938 | isset($news->name) ? $video_name = $news->name : $video_name = $link; |
| 939 | isset($news->description) ? $description_text = $news->description : $description_text = ''; |
| 940 | $cff_description = '<div class="cff-desc-wrap '; |
| 941 | if (empty($picture)) $cff_description .= 'cff-no-image'; |
| 942 | $cff_description .= '"><a class="cff-link-title" href="'.$link.'" '.$target.'>'. '<b>' . $video_name . '</b></a>'; |
| 943 | $cff_description .= '<p class="cff-post-desc" '.$cff_body_styles.'><span>' . cff_autolink( htmlspecialchars($description_text) ) . '</span></p></div>'; |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | |
| 948 | //Display the link to the Facebook post or external link |
| 949 | $cff_link = ''; |
| 950 | //Default link |
| 951 | $cff_viewpost_class = 'cff-viewpost-facebook'; |
| 952 | if ($cff_facebook_link_text == '') $cff_facebook_link_text = 'View on Facebook'; |
| 953 | $link_text = $cff_facebook_link_text; |
| 954 | |
| 955 | //Link to the Facebook post if it's a link or a video |
| 956 | if($cff_post_type == 'link' || $cff_post_type == 'video') $link = "https://www.facebook.com/" . $page_id . "/posts/" . $PostID[1]; |
| 957 | |
| 958 | if ($cff_post_type == 'offer') $link_text = 'View Offer'; |
| 959 | $cff_link = '<a class="' . $cff_viewpost_class . '" href="' . $link . '" title="' . $link_text . '" ' . $target . ' ' . $cff_link_styles . '>' . $link_text . '</a>'; |
| 960 | |
| 961 | |
| 962 | //**************************// |
| 963 | //***CREATE THE POST HTML***// |
| 964 | //**************************// |
| 965 | //Start the container |
| 966 | $cff_post_item = '<div class="cff-item '; |
| 967 | if ($cff_post_type == 'link') $cff_post_item .= 'cff-link-item'; |
| 968 | if ($cff_post_type == 'event') $cff_post_item .= 'cff-timeline-event'; |
| 969 | if ($cff_post_type == 'photo') $cff_post_item .= 'cff-photo-post'; |
| 970 | if ($cff_post_type == 'video') $cff_post_item .= 'cff-video-post'; |
| 971 | if ($cff_post_type == 'swf') $cff_post_item .= 'cff-swf-post'; |
| 972 | if ($cff_post_type == 'status') $cff_post_item .= 'cff-status-post'; |
| 973 | if ($cff_post_type == 'offer') $cff_post_item .= 'cff-offer-post'; |
| 974 | if ($cff_album) $cff_post_item .= ' cff-album'; |
| 975 | $cff_post_item .= ' author-'. to_slug($news->from->name) .'" id="'. $news->id .'" ' . $cff_item_styles . '>'; |
| 976 | |
| 977 | //POST AUTHOR |
| 978 | if($cff_show_author) $cff_post_item .= $cff_author; |
| 979 | //DATE ABOVE |
| 980 | if ($cff_show_date && $cff_date_position == 'above') $cff_post_item .= $cff_date; |
| 981 | //POST TEXT |
| 982 | if($cff_show_text) $cff_post_item .= $cff_post_text; |
| 983 | //DESCRIPTION |
| 984 | if($cff_show_desc && $cff_post_type != 'offer' && $cff_post_type != 'link') $cff_post_item .= $cff_description; |
| 985 | //LINK |
| 986 | if($cff_show_shared_links) $cff_post_item .= $cff_shared_link; |
| 987 | //DATE BELOW |
| 988 | if ($cff_show_date && $cff_date_position == 'below') $cff_post_item .= $cff_date; |
| 989 | //EVENT |
| 990 | if($cff_show_event_title || $cff_show_event_details) $cff_post_item .= $cff_event; |
| 991 | //VIEW ON FACEBOOK LINK |
| 992 | if($cff_show_link) $cff_post_item .= $cff_link; |
| 993 | |
| 994 | //End the post item |
| 995 | $cff_post_item .= '</div><div class="cff-clear"></div>'; |
| 996 | |
| 997 | //PUSH TO ARRAY |
| 998 | $cff_posts_array = array_push_assoc($cff_posts_array, strtotime($post_time), $cff_post_item); |
| 999 | |
| 1000 | } // End post type check |
| 1001 | |
| 1002 | if (isset($news->message)) $prev_post_message = $news->message; |
| 1003 | if (isset($news->link)) $prev_post_link = $news->link; |
| 1004 | if (isset($news->description)) $prev_post_description = $news->description; |
| 1005 | |
| 1006 | } // End the loop |
| 1007 | |
| 1008 | //Sort the array in reverse order (newest first) |
| 1009 | krsort($cff_posts_array); |
| 1010 | |
| 1011 | } // End ALL POSTS |
| 1012 | |
| 1013 | |
| 1014 | //Output the posts array |
| 1015 | $p = 0; |
| 1016 | foreach ($cff_posts_array as $post ) { |
| 1017 | if ( $p == $show_posts ) break; |
| 1018 | $cff_content .= $post; |
| 1019 | $p++; |
| 1020 | } |
| 1021 | |
| 1022 | //Reset the timezone |
| 1023 | date_default_timezone_set( $cff_orig_timezone ); |
| 1024 | //Add the Like Box inside |
| 1025 | if ($cff_like_box_position == 'bottom' && $cff_show_like_box && !$cff_like_box_outside) $cff_content .= $like_box; |
| 1026 | //End the feed |
| 1027 | $cff_content .= '</div><div class="cff-clear"></div>'; |
| 1028 | //Add the Like Box outside |
| 1029 | if ($cff_like_box_position == 'bottom' && $cff_show_like_box && $cff_like_box_outside) $cff_content .= $like_box; |
| 1030 | |
| 1031 | //If the feed is loaded via Ajax then put the scripts into the shortcode itself |
| 1032 | $ajax_theme = $atts['ajax']; |
| 1033 | ( $ajax_theme == 'on' || $ajax_theme == 'true' || $ajax_theme == true ) ? $ajax_theme = true : $ajax_theme = false; |
| 1034 | if( $atts[ 'ajax' ] == 'false' ) $ajax_theme = false; |
| 1035 | if ($ajax_theme) $cff_content .= '<script type="text/javascript" src="' . plugins_url( '/js/cff-scripts.js?8' , __FILE__ ) . '"></script>'; |
| 1036 | |
| 1037 | //Return our feed HTML to display |
| 1038 | return $cff_content; |
| 1039 | } |
| 1040 | |
| 1041 | //***FUNCTIONS*** |
| 1042 | |
| 1043 | //Get JSON object of feed data |
| 1044 | function cff_fetchUrl($url){ |
| 1045 | //Can we use cURL? |
| 1046 | if(is_callable('curl_init')){ |
| 1047 | $ch = curl_init(); |
| 1048 | curl_setopt($ch, CURLOPT_URL, $url); |
| 1049 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 1050 | curl_setopt($ch, CURLOPT_TIMEOUT, 20); |
| 1051 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
| 1052 | $feedData = curl_exec($ch); |
| 1053 | curl_close($ch); |
| 1054 | //If not then use file_get_contents |
| 1055 | } elseif ( ini_get('allow_url_fopen') == 1 || ini_get('allow_url_fopen') === TRUE ) { |
| 1056 | $feedData = @file_get_contents($url); |
| 1057 | //Or else use the WP HTTP API |
| 1058 | } else { |
| 1059 | if( !class_exists( 'WP_Http' ) ) include_once( ABSPATH . WPINC. '/class-http.php' ); |
| 1060 | $request = new WP_Http; |
| 1061 | $result = $request->request($url); |
| 1062 | $feedData = $result['body']; |
| 1063 | } |
| 1064 | |
| 1065 | return $feedData; |
| 1066 | } |
| 1067 | |
| 1068 | //2013-04-28T21:06:56+0000 |
| 1069 | //Time stamp function - used for posts |
| 1070 | function cff_getdate($original, $date_format, $custom_date) { |
| 1071 | switch ($date_format) { |
| 1072 | |
| 1073 | case '2': |
| 1074 | $print = date_i18n('F jS, g:i a', $original); |
| 1075 | break; |
| 1076 | case '3': |
| 1077 | $print = date_i18n('F jS', $original); |
| 1078 | break; |
| 1079 | case '4': |
| 1080 | $print = date_i18n('D F jS', $original); |
| 1081 | break; |
| 1082 | case '5': |
| 1083 | $print = date_i18n('l F jS', $original); |
| 1084 | break; |
| 1085 | case '6': |
| 1086 | $print = date_i18n('D M jS, Y', $original); |
| 1087 | break; |
| 1088 | case '7': |
| 1089 | $print = date_i18n('l F jS, Y', $original); |
| 1090 | break; |
| 1091 | case '8': |
| 1092 | $print = date_i18n('l F jS, Y - g:i a', $original); |
| 1093 | break; |
| 1094 | case '9': |
| 1095 | $print = date_i18n("l M jS, 'y", $original); |
| 1096 | break; |
| 1097 | case '10': |
| 1098 | $print = date_i18n('m.d.y', $original); |
| 1099 | break; |
| 1100 | case '11': |
| 1101 | $print = date_i18n('m/d/y', $original); |
| 1102 | break; |
| 1103 | case '12': |
| 1104 | $print = date_i18n('d.m.y', $original); |
| 1105 | break; |
| 1106 | case '13': |
| 1107 | $print = date_i18n('d/m/y', $original); |
| 1108 | break; |
| 1109 | default: |
| 1110 | |
| 1111 | $options = get_option('cff_style_settings'); |
| 1112 | |
| 1113 | $cff_second = isset($options['cff_translate_second']) ? $options['cff_translate_second'] : ''; |
| 1114 | if ( empty($cff_second) ) $cff_second = 'second'; |
| 1115 | |
| 1116 | $cff_seconds = isset($options['cff_translate_seconds']) ? $options['cff_translate_seconds'] : ''; |
| 1117 | if ( empty($cff_seconds) ) $cff_seconds = 'seconds'; |
| 1118 | |
| 1119 | $cff_minute = isset($options['cff_translate_minute']) ? $options['cff_translate_minute'] : ''; |
| 1120 | if ( empty($cff_minute) ) $cff_minute = 'minute'; |
| 1121 | |
| 1122 | $cff_minutes = isset($options['cff_translate_minutes']) ? $options['cff_translate_minutes'] : ''; |
| 1123 | if ( empty($cff_minutes) ) $cff_minutes = 'minutes'; |
| 1124 | |
| 1125 | $cff_hour = isset($options['cff_translate_hour']) ? $options['cff_translate_hour'] : ''; |
| 1126 | if ( empty($cff_hour) ) $cff_hour = 'hour'; |
| 1127 | |
| 1128 | $cff_hours = isset($options['cff_translate_hours']) ? $options['cff_translate_hours'] : ''; |
| 1129 | if ( empty($cff_hours) ) $cff_hours = 'hours'; |
| 1130 | |
| 1131 | $cff_day = isset($options['cff_translate_day']) ? $options['cff_translate_day'] : ''; |
| 1132 | if ( empty($cff_day) ) $cff_day = 'day'; |
| 1133 | |
| 1134 | $cff_days = isset($options['cff_translate_days']) ? $options['cff_translate_days'] : ''; |
| 1135 | if ( empty($cff_days) ) $cff_days = 'days'; |
| 1136 | |
| 1137 | $cff_week = isset($options['cff_translate_week']) ? $options['cff_translate_week'] : ''; |
| 1138 | if ( empty($cff_week) ) $cff_week = 'week'; |
| 1139 | |
| 1140 | $cff_weeks = isset($options['cff_translate_weeks']) ? $options['cff_translate_weeks'] : ''; |
| 1141 | if ( empty($cff_weeks) ) $cff_weeks = 'weeks'; |
| 1142 | |
| 1143 | $cff_month = isset($options['cff_translate_month']) ? $options['cff_translate_month'] : ''; |
| 1144 | if ( empty($cff_month) ) $cff_month = 'month'; |
| 1145 | |
| 1146 | $cff_months = isset($options['cff_translate_months']) ? $options['cff_translate_months'] : ''; |
| 1147 | if ( empty($cff_months) ) $cff_months = 'months'; |
| 1148 | |
| 1149 | $cff_year = isset($options['cff_translate_year']) ? $options['cff_translate_year'] : ''; |
| 1150 | if ( empty($cff_year) ) $cff_year = 'year'; |
| 1151 | |
| 1152 | $cff_years = isset($options['cff_translate_years']) ? $options['cff_translate_years'] : ''; |
| 1153 | if ( empty($cff_years) ) $cff_years = 'years'; |
| 1154 | |
| 1155 | $cff_ago = isset($options['cff_translate_ago']) ? $options['cff_translate_ago'] : ''; |
| 1156 | if ( empty($cff_ago) ) $cff_ago = 'ago'; |
| 1157 | |
| 1158 | |
| 1159 | $periods = array($cff_second, $cff_minute, $cff_hour, $cff_day, $cff_week, $cff_month, $cff_year, "decade"); |
| 1160 | $periods_plural = array($cff_seconds, $cff_minutes, $cff_hours, $cff_days, $cff_weeks, $cff_months, $cff_years, "decade"); |
| 1161 | |
| 1162 | $lengths = array("60","60","24","7","4.35","12","10"); |
| 1163 | $now = time(); |
| 1164 | |
| 1165 | // is it future date or past date |
| 1166 | if($now > $original) { |
| 1167 | $difference = $now - $original; |
| 1168 | $tense = $cff_ago; |
| 1169 | } else { |
| 1170 | $difference = $original - $now; |
| 1171 | $tense = $cff_ago; |
| 1172 | } |
| 1173 | for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) { |
| 1174 | $difference /= $lengths[$j]; |
| 1175 | } |
| 1176 | |
| 1177 | $difference = round($difference); |
| 1178 | |
| 1179 | if($difference != 1) { |
| 1180 | $periods[$j] = $periods_plural[$j]; |
| 1181 | } |
| 1182 | $print = "$difference $periods[$j] {$tense}"; |
| 1183 | |
| 1184 | break; |
| 1185 | |
| 1186 | } |
| 1187 | if ( !empty($custom_date) ){ |
| 1188 | $print = date_i18n($custom_date, $original); |
| 1189 | } |
| 1190 | |
| 1191 | return $print; |
| 1192 | } |
| 1193 | function cff_eventdate($original, $date_format, $custom_date) { |
| 1194 | switch ($date_format) { |
| 1195 | |
| 1196 | case '2': |
| 1197 | $print = date_i18n('F jS, g:ia', $original); |
| 1198 | break; |
| 1199 | case '3': |
| 1200 | $print = date_i18n('g:ia - F jS', $original); |
| 1201 | break; |
| 1202 | case '4': |
| 1203 | $print = date_i18n('g:ia, F jS', $original); |
| 1204 | break; |
| 1205 | case '5': |
| 1206 | $print = date_i18n('l F jS - g:ia', $original); |
| 1207 | break; |
| 1208 | case '6': |
| 1209 | $print = date_i18n('D M jS, Y, g:iA', $original); |
| 1210 | break; |
| 1211 | case '7': |
| 1212 | $print = date_i18n('l F jS, Y, g:iA', $original); |
| 1213 | break; |
| 1214 | case '8': |
| 1215 | $print = date_i18n('l F jS, Y - g:ia', $original); |
| 1216 | break; |
| 1217 | case '9': |
| 1218 | $print = date_i18n("l M jS, 'y", $original); |
| 1219 | break; |
| 1220 | case '10': |
| 1221 | $print = date_i18n('m.d.y - g:iA', $original); |
| 1222 | break; |
| 1223 | case '11': |
| 1224 | $print = date_i18n('m/d/y, g:ia', $original); |
| 1225 | break; |
| 1226 | case '12': |
| 1227 | $print = date_i18n('d.m.y - g:iA', $original); |
| 1228 | break; |
| 1229 | case '13': |
| 1230 | $print = date_i18n('d/m/y, g:ia', $original); |
| 1231 | break; |
| 1232 | default: |
| 1233 | $print = date_i18n('F j, Y, g:ia', $original); |
| 1234 | break; |
| 1235 | } |
| 1236 | if ( !empty($custom_date) ){ |
| 1237 | $print = date_i18n($custom_date, $original); |
| 1238 | } |
| 1239 | return $print; |
| 1240 | } |
| 1241 | //Time stamp function - used for comments |
| 1242 | function cff_timesince($original) { |
| 1243 | |
| 1244 | $options = get_option('cff_style_settings'); |
| 1245 | |
| 1246 | $cff_second = isset($options['cff_translate_second']) ? $options['cff_translate_second'] : ''; |
| 1247 | if ( empty($cff_second) ) $cff_second = 'second'; |
| 1248 | |
| 1249 | $cff_seconds = isset($options['cff_translate_seconds']) ? $options['cff_translate_seconds'] : ''; |
| 1250 | if ( empty($cff_seconds) ) $cff_seconds = 'seconds'; |
| 1251 | |
| 1252 | $cff_minute = isset($options['cff_translate_minute']) ? $options['cff_translate_minute'] : ''; |
| 1253 | if ( empty($cff_minute) ) $cff_minute = 'minute'; |
| 1254 | |
| 1255 | $cff_minutes = isset($options['cff_translate_minutes']) ? $options['cff_translate_minutes'] : ''; |
| 1256 | if ( empty($cff_minutes) ) $cff_minutes = 'minutes'; |
| 1257 | |
| 1258 | $cff_hour = isset($options['cff_translate_hour']) ? $options['cff_translate_hour'] : ''; |
| 1259 | if ( empty($cff_hour) ) $cff_hour = 'hour'; |
| 1260 | |
| 1261 | $cff_hours = isset($options['cff_translate_hours']) ? $options['cff_translate_hours'] : ''; |
| 1262 | if ( empty($cff_hours) ) $cff_hours = 'hours'; |
| 1263 | |
| 1264 | $cff_day = isset($options['cff_translate_day']) ? $options['cff_translate_day'] : ''; |
| 1265 | if ( empty($cff_day) ) $cff_day = 'day'; |
| 1266 | |
| 1267 | $cff_days = isset($options['cff_translate_days']) ? $options['cff_translate_days'] : ''; |
| 1268 | if ( empty($cff_days) ) $cff_days = 'days'; |
| 1269 | |
| 1270 | $cff_week = isset($options['cff_translate_week']) ? $options['cff_translate_week'] : ''; |
| 1271 | if ( empty($cff_week) ) $cff_week = 'week'; |
| 1272 | |
| 1273 | $cff_weeks = isset($options['cff_translate_weeks']) ? $options['cff_translate_weeks'] : ''; |
| 1274 | if ( empty($cff_weeks) ) $cff_weeks = 'weeks'; |
| 1275 | |
| 1276 | $cff_month = isset($options['cff_translate_month']) ? $options['cff_translate_month'] : ''; |
| 1277 | if ( empty($cff_month) ) $cff_month = 'month'; |
| 1278 | |
| 1279 | $cff_months = isset($options['cff_translate_months']) ? $options['cff_translate_months'] : ''; |
| 1280 | if ( empty($cff_months) ) $cff_months = 'months'; |
| 1281 | |
| 1282 | $cff_year = isset($options['cff_translate_year']) ? $options['cff_translate_year'] : ''; |
| 1283 | if ( empty($cff_year) ) $cff_year = 'year'; |
| 1284 | |
| 1285 | $cff_years = isset($options['cff_translate_years']) ? $options['cff_translate_years'] : ''; |
| 1286 | if ( empty($cff_years) ) $cff_years = 'years'; |
| 1287 | |
| 1288 | $cff_ago = isset($options['cff_translate_ago']) ? $options['cff_translate_ago'] : ''; |
| 1289 | if ( empty($cff_ago) ) $cff_ago = 'ago'; |
| 1290 | |
| 1291 | |
| 1292 | $periods = array($cff_second, $cff_minute, $cff_hour, $cff_day, $cff_week, $cff_month, $cff_year, "decade"); |
| 1293 | $periods_plural = array($cff_seconds, $cff_minutes, $cff_hours, $cff_days, $cff_weeks, $cff_months, $cff_years, "decade"); |
| 1294 | |
| 1295 | $lengths = array("60","60","24","7","4.35","12","10"); |
| 1296 | $now = time(); |
| 1297 | |
| 1298 | // is it future date or past date |
| 1299 | if($now > $original) { |
| 1300 | $difference = $now - $original; |
| 1301 | $tense = $cff_ago; |
| 1302 | } else { |
| 1303 | $difference = $original - $now; |
| 1304 | $tense = $cff_ago; |
| 1305 | } |
| 1306 | for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) { |
| 1307 | $difference /= $lengths[$j]; |
| 1308 | } |
| 1309 | |
| 1310 | $difference = round($difference); |
| 1311 | |
| 1312 | if($difference != 1) { |
| 1313 | $periods[$j] = $periods_plural[$j]; |
| 1314 | } |
| 1315 | return "$difference $periods[$j] {$tense}"; |
| 1316 | |
| 1317 | } |
| 1318 | //Use custom stripos function if it's not available (only available in PHP 5+) |
| 1319 | if(!is_callable('stripos')){ |
| 1320 | function stripos($haystack, $needle){ |
| 1321 | return strpos($haystack, stristr( $haystack, $needle )); |
| 1322 | } |
| 1323 | } |
| 1324 | |
| 1325 | //Push to assoc array |
| 1326 | function array_push_assoc($array, $key, $value){ |
| 1327 | $array[$key] = $value; |
| 1328 | return $array; |
| 1329 | } |
| 1330 | //Convert string to slug |
| 1331 | function to_slug($string){ |
| 1332 | return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string))); |
| 1333 | } |
| 1334 | |
| 1335 | // remove_filter( 'the_content', 'wpautop' ); |
| 1336 | // add_filter( 'the_content', 'wpautop', 99 ); |
| 1337 | |
| 1338 | |
| 1339 | //Allows shortcodes in theme |
| 1340 | add_filter('widget_text', 'do_shortcode'); |
| 1341 | |
| 1342 | //Enqueue stylesheet |
| 1343 | add_action( 'wp_enqueue_scripts', 'cff_add_my_stylesheet' ); |
| 1344 | function cff_add_my_stylesheet() { |
| 1345 | // Respects SSL, Style.css is relative to the current file |
| 1346 | wp_register_style( 'cff', plugins_url('css/cff-style.css?5', __FILE__) ); |
| 1347 | wp_enqueue_style( 'cff' ); |
| 1348 | wp_enqueue_style( 'cff-font-awesome', '//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css', array(), '4.0.3' ); |
| 1349 | } |
| 1350 | //Enqueue scripts |
| 1351 | add_action( 'wp_enqueue_scripts', 'cff_scripts_method' ); |
| 1352 | function cff_scripts_method() { |
| 1353 | //Register the script to make it available |
| 1354 | wp_register_script( 'cffscripts', plugins_url( '/js/cff-scripts.js?5' , __FILE__ ), array('jquery'), '1.8', true ); |
| 1355 | //Enqueue it to load it onto the page |
| 1356 | wp_enqueue_script('cffscripts'); |
| 1357 | } |
| 1358 | |
| 1359 | function cff_activate() { |
| 1360 | $options = get_option('cff_style_settings'); |
| 1361 | $options[ 'cff_show_links_type' ] = true; |
| 1362 | $options[ 'cff_show_event_type' ] = true; |
| 1363 | $options[ 'cff_show_video_type' ] = true; |
| 1364 | $options[ 'cff_show_photos_type' ] = true; |
| 1365 | $options[ 'cff_show_status_type' ] = true; |
| 1366 | // Show all parts of the feed by default on activation |
| 1367 | $options[ 'cff_show_author' ] = true; |
| 1368 | $options[ 'cff_show_text' ] = true; |
| 1369 | $options[ 'cff_show_desc' ] = true; |
| 1370 | $options[ 'cff_show_shared_links' ] = true; |
| 1371 | $options[ 'cff_show_date' ] = true; |
| 1372 | $options[ 'cff_show_media' ] = true; |
| 1373 | $options[ 'cff_show_event_title' ] = true; |
| 1374 | $options[ 'cff_show_event_details' ] = true; |
| 1375 | $options[ 'cff_show_meta' ] = true; |
| 1376 | $options[ 'cff_show_link' ] = true; |
| 1377 | $options[ 'cff_show_like_box' ] = true; |
| 1378 | update_option( 'cff_style_settings', $options ); |
| 1379 | } |
| 1380 | register_activation_hook( __FILE__, 'cff_activate' ); |
| 1381 | //Uninstall |
| 1382 | function cff_uninstall() |
| 1383 | { |
| 1384 | if ( ! current_user_can( 'activate_plugins' ) ) |
| 1385 | return; |
| 1386 | //Settings |
| 1387 | delete_option( 'cff_access_token' ); |
| 1388 | delete_option( 'cff_page_id' ); |
| 1389 | delete_option( 'cff_num_show' ); |
| 1390 | delete_option( 'cff_post_limit' ); |
| 1391 | delete_option( 'cff_show_others' ); |
| 1392 | delete_option('cff_cache_time'); |
| 1393 | delete_option('cff_cache_time_unit'); |
| 1394 | delete_option( 'cff_locale' ); |
| 1395 | //Style & Layout |
| 1396 | delete_option( 'cff_title_length' ); |
| 1397 | delete_option( 'cff_body_length' ); |
| 1398 | delete_option('cff_style_settings'); |
| 1399 | } |
| 1400 | register_uninstall_hook( __FILE__, 'cff_uninstall' ); |
| 1401 | add_action( 'wp_head', 'cff_custom_css' ); |
| 1402 | function cff_custom_css() { |
| 1403 | $options = get_option('cff_style_settings'); |
| 1404 | isset($options[ 'cff_custom_css' ]) ? $cff_custom_css = $options[ 'cff_custom_css' ] : $cff_custom_css = ''; |
| 1405 | |
| 1406 | if( !empty($cff_custom_css) ) echo "\r\n"; |
| 1407 | if( !empty($cff_custom_css) ) echo '<!-- Custom Facebook Feed Custom CSS -->'; |
| 1408 | if( !empty($cff_custom_css) ) echo "\r\n"; |
| 1409 | if( !empty($cff_custom_css) ) echo '<style type="text/css">'; |
| 1410 | if( !empty($cff_custom_css) ) echo "\r\n"; |
| 1411 | if( !empty($cff_custom_css) ) echo stripslashes($cff_custom_css); |
| 1412 | if( !empty($cff_custom_css) ) echo "\r\n"; |
| 1413 | if( !empty($cff_custom_css) ) echo '</style>'; |
| 1414 | if( !empty($cff_custom_css) ) echo "\r\n"; |
| 1415 | } |
| 1416 | add_action( 'wp_footer', 'cff_js' ); |
| 1417 | function cff_js() { |
| 1418 | $options = get_option('cff_style_settings'); |
| 1419 | $cff_custom_js = isset($options[ 'cff_custom_js' ]) ? $options[ 'cff_custom_js' ] : ''; |
| 1420 | |
| 1421 | if( !empty($cff_custom_js) ) echo "\r\n"; |
| 1422 | if( !empty($cff_custom_js) ) echo '<!-- Custom Facebook Feed JS -->'; |
| 1423 | if( !empty($cff_custom_js) ) echo "\r\n"; |
| 1424 | if( !empty($cff_custom_js) ) echo '<script type="text/javascript">'; |
| 1425 | if( !empty($cff_custom_js) ) echo "\r\n"; |
| 1426 | if( !empty($cff_custom_js) ) echo "jQuery( document ).ready(function($) {"; |
| 1427 | if( !empty($cff_custom_js) ) echo "\r\n"; |
| 1428 | if( !empty($cff_custom_js) ) echo stripslashes($cff_custom_js); |
| 1429 | if( !empty($cff_custom_js) ) echo "\r\n"; |
| 1430 | if( !empty($cff_custom_js) ) echo "});"; |
| 1431 | if( !empty($cff_custom_js) ) echo "\r\n"; |
| 1432 | if( !empty($cff_custom_js) ) echo '</script>'; |
| 1433 | if( !empty($cff_custom_js) ) echo "\r\n"; |
| 1434 | } |
| 1435 | |
| 1436 | //Comment out the line below to view errors |
| 1437 | error_reporting(0); |
| 1438 | ?> |