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