custom-facebook-feed
Last commit date
css
9 years ago
fonts
11 years ago
img
9 years ago
js
10 years ago
README.txt
9 years ago
custom-facebook-feed-admin.php
9 years ago
custom-facebook-feed.php
9 years ago
gpl-2.0.txt
13 years ago
custom-facebook-feed.php
2406 lines
| 1 | <?php |
| 2 | /* |
| 3 | Plugin Name: Custom Facebook Feed |
| 4 | Plugin URI: http://smashballoon.com/custom-facebook-feed |
| 5 | Description: Add completely customizable Facebook feeds to your WordPress site |
| 6 | Version: 2.4.2 |
| 7 | Author: Smash Balloon |
| 8 | Author URI: http://smashballoon.com/ |
| 9 | License: GPLv2 or later |
| 10 | Text Domain: custom-facebook-feed |
| 11 | */ |
| 12 | /* |
| 13 | Copyright 2016 Smash Balloon LLC (email : hey@smashballoon.com) |
| 14 | This program is free software; you can redistribute it and/or modify |
| 15 | it under the terms of the GNU General Public License as published by |
| 16 | the Free Software Foundation; either version 2 of the License, or |
| 17 | (at your option) any later version. |
| 18 | This program is distributed in the hope that it will be useful, |
| 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | GNU General Public License for more details. |
| 22 | You should have received a copy of the GNU General Public License |
| 23 | along with this program; if not, write to the Free Software |
| 24 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 | */ |
| 26 | //Include admin |
| 27 | include dirname( __FILE__ ) .'/custom-facebook-feed-admin.php'; |
| 28 | |
| 29 | define('CFFVER', '2.4.2'); |
| 30 | |
| 31 | // Add shortcodes |
| 32 | add_shortcode('custom-facebook-feed', 'display_cff'); |
| 33 | function display_cff($atts) { |
| 34 | |
| 35 | //Style options |
| 36 | $options = get_option('cff_style_settings'); |
| 37 | //Create the types string to set as shortcode default |
| 38 | $include_string = ''; |
| 39 | if($options[ 'cff_show_author' ]) $include_string .= 'author,'; |
| 40 | if($options[ 'cff_show_text' ]) $include_string .= 'text,'; |
| 41 | if($options[ 'cff_show_desc' ]) $include_string .= 'desc,'; |
| 42 | if($options[ 'cff_show_shared_links' ]) $include_string .= 'sharedlinks,'; |
| 43 | if($options[ 'cff_show_date' ]) $include_string .= 'date,'; |
| 44 | if($options[ 'cff_show_media' ]) $include_string .= 'media,'; |
| 45 | if( isset($options[ 'cff_show_media_link' ]) ){ //If not set yet then show link by default |
| 46 | if($options[ 'cff_show_media_link' ]) $include_string .= 'medialink,'; |
| 47 | } else { |
| 48 | $include_string .= 'medialink,'; |
| 49 | } |
| 50 | if($options[ 'cff_show_event_title' ]) $include_string .= 'eventtitle,'; |
| 51 | if($options[ 'cff_show_event_details' ]) $include_string .= 'eventdetails,'; |
| 52 | if($options[ 'cff_show_meta' ]) $include_string .= 'social,'; |
| 53 | if($options[ 'cff_show_link' ]) $include_string .= 'link,'; |
| 54 | if($options[ 'cff_show_like_box' ]) $include_string .= 'likebox,'; |
| 55 | //Pass in shortcode attrbutes |
| 56 | $atts = shortcode_atts( |
| 57 | array( |
| 58 | 'accesstoken' => trim( get_option('cff_access_token') ), |
| 59 | 'id' => get_option('cff_page_id'), |
| 60 | 'pagetype' => get_option('cff_page_type'), |
| 61 | 'num' => get_option('cff_num_show'), |
| 62 | 'limit' => get_option('cff_post_limit'), |
| 63 | 'others' => '', |
| 64 | 'showpostsby' => get_option('cff_show_others'), |
| 65 | 'cachetime' => get_option('cff_cache_time'), |
| 66 | 'cacheunit' => get_option('cff_cache_time_unit'), |
| 67 | 'locale' => get_option('cff_locale'), |
| 68 | 'ajax' => get_option('cff_ajax'), |
| 69 | 'offset' => '', |
| 70 | |
| 71 | //General |
| 72 | 'width' => isset($options[ 'cff_feed_width' ]) ? $options[ 'cff_feed_width' ] : '', |
| 73 | 'widthresp' => isset($options[ 'cff_feed_width_resp' ]) ? $options[ 'cff_feed_width_resp' ] : '', |
| 74 | 'height' => isset($options[ 'cff_feed_height' ]) ? $options[ 'cff_feed_height' ] : '', |
| 75 | 'padding' => isset($options[ 'cff_feed_padding' ]) ? $options[ 'cff_feed_padding' ] : '', |
| 76 | 'bgcolor' => isset($options[ 'cff_bg_color' ]) ? $options[ 'cff_bg_color' ] : '', |
| 77 | 'showauthor' => '', |
| 78 | 'showauthornew' => isset($options[ 'cff_show_author' ]) ? $options[ 'cff_show_author' ] : '', |
| 79 | 'class' => isset($options[ 'cff_class' ]) ? $options[ 'cff_class' ] : '', |
| 80 | 'layout' => isset($options[ 'cff_preset_layout' ]) ? $options[ 'cff_preset_layout' ] : '', |
| 81 | 'include' => $include_string, |
| 82 | 'exclude' => '', |
| 83 | //Post Style |
| 84 | 'postbgcolor' => isset($options[ 'cff_post_bg_color' ]) ? $options[ 'cff_post_bg_color' ] : '', |
| 85 | 'postcorners' => isset($options[ 'cff_post_rounded' ]) ? $options[ 'cff_post_rounded' ] : '', |
| 86 | |
| 87 | //Typography |
| 88 | 'textformat' => isset($options[ 'cff_title_format' ]) ? $options[ 'cff_title_format' ] : '', |
| 89 | 'textsize' => isset($options[ 'cff_title_size' ]) ? $options[ 'cff_title_size' ] : '', |
| 90 | 'textweight' => isset($options[ 'cff_title_weight' ]) ? $options[ 'cff_title_weight' ] : '', |
| 91 | 'textcolor' => isset($options[ 'cff_title_color' ]) ? $options[ 'cff_title_color' ] : '', |
| 92 | 'textlinkcolor' => isset($options[ 'cff_posttext_link_color' ]) ? $options[ 'cff_posttext_link_color' ] : '', |
| 93 | 'textlink' => isset($options[ 'cff_title_link' ]) ? $options[ 'cff_title_link' ] : '', |
| 94 | 'posttags' => isset($options[ 'cff_post_tags' ]) ? $options[ 'cff_post_tags' ] : '', |
| 95 | 'linkhashtags' => isset($options[ 'cff_link_hashtags' ]) ? $options[ 'cff_link_hashtags' ] : '', |
| 96 | |
| 97 | //Description |
| 98 | 'descsize' => isset($options[ 'cff_body_size' ]) ? $options[ 'cff_body_size' ] : '', |
| 99 | 'descweight' => isset($options[ 'cff_body_weight' ]) ? $options[ 'cff_body_weight' ] : '', |
| 100 | 'desccolor' => isset($options[ 'cff_body_color' ]) ? $options[ 'cff_body_color' ] : '', |
| 101 | 'linktitleformat' => isset($options[ 'cff_link_title_format' ]) ? $options[ 'cff_link_title_format' ] : '', |
| 102 | 'linktitlesize' => isset($options[ 'cff_link_title_size' ]) ? $options[ 'cff_link_title_size' ] : '', |
| 103 | 'linktitlecolor' => isset($options[ 'cff_link_title_color' ]) ? $options[ 'cff_link_title_color' ] : '', |
| 104 | 'linkurlcolor' => isset($options[ 'cff_link_url_color' ]) ? $options[ 'cff_link_url_color' ] : '', |
| 105 | 'linkbgcolor' => isset($options[ 'cff_link_bg_color' ]) ? $options[ 'cff_link_bg_color' ] : '', |
| 106 | 'linkbordercolor' => isset($options[ 'cff_link_border_color' ]) ? $options[ 'cff_link_border_color' ] : '', |
| 107 | 'disablelinkbox' => isset($options[ 'cff_disable_link_box' ]) ? $options[ 'cff_disable_link_box' ] : '', |
| 108 | |
| 109 | //Author |
| 110 | 'authorsize' => isset($options[ 'cff_author_size' ]) ? $options[ 'cff_author_size' ] : '', |
| 111 | 'authorcolor' => isset($options[ 'cff_author_color' ]) ? $options[ 'cff_author_color' ] : '', |
| 112 | |
| 113 | //Event title |
| 114 | 'eventtitleformat' => isset($options[ 'cff_event_title_format' ]) ? $options[ 'cff_event_title_format' ] : '', |
| 115 | 'eventtitlesize' => isset($options[ 'cff_event_title_size' ]) ? $options[ 'cff_event_title_size' ] : '', |
| 116 | 'eventtitleweight' => isset($options[ 'cff_event_title_weight' ]) ? $options[ 'cff_event_title_weight' ] : '', |
| 117 | 'eventtitlecolor' => isset($options[ 'cff_event_title_color' ]) ? $options[ 'cff_event_title_color' ] : '', |
| 118 | 'eventtitlelink' => isset($options[ 'cff_event_title_link' ]) ? $options[ 'cff_event_title_link' ] : '', |
| 119 | //Event date |
| 120 | 'eventdatesize' => isset($options[ 'cff_event_date_size' ]) ? $options[ 'cff_event_date_size' ] : '', |
| 121 | 'eventdateweight' => isset($options[ 'cff_event_date_weight' ]) ? $options[ 'cff_event_date_weight' ] : '', |
| 122 | 'eventdatecolor' => isset($options[ 'cff_event_date_color' ]) ? $options[ 'cff_event_date_color' ] : '', |
| 123 | 'eventdatepos' => isset($options[ 'cff_event_date_position' ]) ? $options[ 'cff_event_date_position' ] : '', |
| 124 | 'eventdateformat' => isset($options[ 'cff_event_date_formatting' ]) ? $options[ 'cff_event_date_formatting' ] : '', |
| 125 | 'eventdatecustom' => isset($options[ 'cff_event_date_custom' ]) ? $options[ 'cff_event_date_custom' ] : '', |
| 126 | //Event details |
| 127 | 'eventdetailssize' => isset($options[ 'cff_event_details_size' ]) ? $options[ 'cff_event_details_size' ] : '', |
| 128 | 'eventdetailsweight' => isset($options[ 'cff_event_details_weight' ]) ? $options[ 'cff_event_details_weight' ] : '', |
| 129 | 'eventdetailscolor' => isset($options[ 'cff_event_details_color' ]) ? $options[ 'cff_event_details_color' ] : '', |
| 130 | 'eventlinkcolor' => isset($options[ 'cff_event_link_color' ]) ? $options[ 'cff_event_link_color' ] : '', |
| 131 | //Date |
| 132 | 'datepos' => isset($options[ 'cff_date_position' ]) ? $options[ 'cff_date_position' ] : '', |
| 133 | 'datesize' => isset($options[ 'cff_date_size' ]) ? $options[ 'cff_date_size' ] : '', |
| 134 | 'dateweight' => isset($options[ 'cff_date_weight' ]) ? $options[ 'cff_date_weight' ] : '', |
| 135 | 'datecolor' => isset($options[ 'cff_date_color' ]) ? $options[ 'cff_date_color' ] : '', |
| 136 | 'dateformat' => isset($options[ 'cff_date_formatting' ]) ? $options[ 'cff_date_formatting' ] : '', |
| 137 | 'datecustom' => isset($options[ 'cff_date_custom' ]) ? $options[ 'cff_date_custom' ] : '', |
| 138 | 'timezone' => isset($options[ 'cff_timezone' ]) ? $options[ 'cff_timezone' ] : 'America/Chicago', |
| 139 | |
| 140 | //Link to Facebook |
| 141 | 'linksize' => isset($options[ 'cff_link_size' ]) ? $options[ 'cff_link_size' ] : '', |
| 142 | 'linkweight' => isset($options[ 'cff_link_weight' ]) ? $options[ 'cff_link_weight' ] : '', |
| 143 | 'linkcolor' => isset($options[ 'cff_link_color' ]) ? $options[ 'cff_link_color' ] : '', |
| 144 | 'viewlinktext' => isset($options[ 'cff_view_link_text' ]) ? $options[ 'cff_view_link_text' ] : '', |
| 145 | 'linktotimeline' => isset($options[ 'cff_link_to_timeline' ]) ? $options[ 'cff_link_to_timeline' ] : '', |
| 146 | //Social |
| 147 | 'iconstyle' => isset($options[ 'cff_icon_style' ]) ? $options[ 'cff_icon_style' ] : '', |
| 148 | 'socialtextcolor' => isset($options[ 'cff_meta_text_color' ]) ? $options[ 'cff_meta_text_color' ] : '', |
| 149 | 'socialbgcolor' => isset($options[ 'cff_meta_bg_color' ]) ? $options[ 'cff_meta_bg_color' ] : '', |
| 150 | //Misc |
| 151 | 'textlength' => get_option('cff_title_length'), |
| 152 | 'desclength' => get_option('cff_body_length'), |
| 153 | 'likeboxpos' => isset($options[ 'cff_like_box_position' ]) ? $options[ 'cff_like_box_position' ] : '', |
| 154 | 'likeboxoutside' => isset($options[ 'cff_like_box_outside' ]) ? $options[ 'cff_like_box_outside' ] : '', |
| 155 | 'likeboxcolor' => isset($options[ 'cff_likebox_bg_color' ]) ? $options[ 'cff_likebox_bg_color' ] : '', |
| 156 | 'likeboxtextcolor' => isset($options[ 'cff_like_box_text_color' ]) ? $options[ 'cff_like_box_text_color' ] : '', |
| 157 | 'likeboxwidth' => isset($options[ 'cff_likebox_width' ]) ? $options[ 'cff_likebox_width' ] : '', |
| 158 | 'likeboxheight' => isset($options[ 'cff_likebox_height' ]) ? $options[ 'cff_likebox_height' ] : '', |
| 159 | 'likeboxfaces' => isset($options[ 'cff_like_box_faces' ]) ? $options[ 'cff_like_box_faces' ] : '', |
| 160 | 'likeboxborder' => isset($options[ 'cff_like_box_border' ]) ? $options[ 'cff_like_box_border' ] : '', |
| 161 | 'likeboxcover' => isset($options[ 'cff_like_box_cover' ]) ? $options[ 'cff_like_box_cover' ] : '', |
| 162 | 'likeboxsmallheader' => isset($options[ 'cff_like_box_small_header' ]) ? $options[ 'cff_like_box_small_header' ] : '', |
| 163 | 'likeboxhidebtn' => isset($options[ 'cff_like_box_hide_cta' ]) ? $options[ 'cff_like_box_hide_cta' ] : '', |
| 164 | |
| 165 | 'credit' => isset($options[ 'cff_show_credit' ]) ? $options[ 'cff_show_credit' ] : '', |
| 166 | 'nofollow' => 'true', |
| 167 | 'disablestyles' => isset($options[ 'cff_disable_styles' ]) ? $options[ 'cff_disable_styles' ] : '', |
| 168 | |
| 169 | //Page Header |
| 170 | 'showheader' => isset($options[ 'cff_show_header' ]) ? $options[ 'cff_show_header' ] : '', |
| 171 | 'headeroutside' => isset($options[ 'cff_header_outside' ]) ? $options[ 'cff_header_outside' ] : '', |
| 172 | 'headertext' => isset($options[ 'cff_header_text' ]) ? $options[ 'cff_header_text' ] : '', |
| 173 | 'headerbg' => isset($options[ 'cff_header_bg_color' ]) ? $options[ 'cff_header_bg_color' ] : '', |
| 174 | 'headerpadding' => isset($options[ 'cff_header_padding' ]) ? $options[ 'cff_header_padding' ] : '', |
| 175 | 'headertextsize' => isset($options[ 'cff_header_text_size' ]) ? $options[ 'cff_header_text_size' ] : '', |
| 176 | 'headertextweight' => isset($options[ 'cff_header_text_weight' ]) ? $options[ 'cff_header_text_weight' ] : '', |
| 177 | 'headertextcolor' => isset($options[ 'cff_header_text_color' ]) ? $options[ 'cff_header_text_color' ] : '', |
| 178 | 'headericon' => isset($options[ 'cff_header_icon' ]) ? $options[ 'cff_header_icon' ] : '', |
| 179 | 'headericoncolor' => isset($options[ 'cff_header_icon_color' ]) ? $options[ 'cff_header_icon_color' ] : '', |
| 180 | 'headericonsize' => isset($options[ 'cff_header_icon_size' ]) ? $options[ 'cff_header_icon_size' ] : '', |
| 181 | |
| 182 | 'videoheight' => isset($options[ 'cff_video_height' ]) ? $options[ 'cff_video_height' ] : '', |
| 183 | 'videoaction' => isset($options[ 'cff_video_action' ]) ? $options[ 'cff_video_action' ] : '', |
| 184 | 'sepcolor' => isset($options[ 'cff_sep_color' ]) ? $options[ 'cff_sep_color' ] : '', |
| 185 | 'sepsize' => isset($options[ 'cff_sep_size' ]) ? $options[ 'cff_sep_size' ] : '', |
| 186 | |
| 187 | //Translate |
| 188 | 'seemoretext' => isset( $options[ 'cff_see_more_text' ] ) ? stripslashes( esc_attr( $options[ 'cff_see_more_text' ] ) ) : '', |
| 189 | 'seelesstext' => isset( $options[ 'cff_see_less_text' ] ) ? stripslashes( esc_attr( $options[ 'cff_see_less_text' ] ) ) : '', |
| 190 | 'photostext' => isset( $options[ 'cff_translate_photos_text' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_photos_text' ] ) ) : '', |
| 191 | 'phototext' => isset( $options[ 'cff_translate_photo_text' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_photo_text' ] ) ) : '', |
| 192 | 'videotext' => isset( $options[ 'cff_translate_video_text' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_video_text' ] ) ) : '', |
| 193 | |
| 194 | 'facebooklinktext' => isset( $options[ 'cff_facebook_link_text' ] ) ? stripslashes( esc_attr( $options[ 'cff_facebook_link_text' ] ) ) : '', |
| 195 | 'sharelinktext' => isset( $options[ 'cff_facebook_share_text' ] ) ? stripslashes( esc_attr( $options[ 'cff_facebook_share_text' ] ) ) : '', |
| 196 | 'showfacebooklink' => isset($options[ 'cff_show_facebook_link' ]) ? $options[ 'cff_show_facebook_link' ] : '', |
| 197 | 'showsharelink' => isset($options[ 'cff_show_facebook_share' ]) ? $options[ 'cff_show_facebook_share' ] : '', |
| 198 | |
| 199 | 'secondtext' => isset( $options[ 'cff_translate_second' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_second' ] ) ) : 'second', |
| 200 | 'secondstext' => isset( $options[ 'cff_translate_seconds' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_seconds' ] ) ) : 'seconds', |
| 201 | 'minutetext' => isset( $options[ 'cff_translate_minute' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_minute' ] ) ) : 'minute', |
| 202 | 'minutestext' => isset( $options[ 'cff_translate_minutes' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_minutes' ] ) ) : 'minutes', |
| 203 | 'hourtext' => isset( $options[ 'cff_translate_hour' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_hour' ] ) ) : 'hour', |
| 204 | 'hourstext' => isset( $options[ 'cff_translate_hours' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_hours' ] ) ) : 'hours', |
| 205 | 'daytext' => isset( $options[ 'cff_translate_day' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_day' ] ) ) : 'day', |
| 206 | 'daystext' => isset( $options[ 'cff_translate_days' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_days' ] ) ) : 'days', |
| 207 | 'weektext' => isset( $options[ 'cff_translate_week' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_week' ] ) ) : 'week', |
| 208 | 'weekstext' => isset( $options[ 'cff_translate_weeks' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_weeks' ] ) ) : 'weeks', |
| 209 | 'monthtext' => isset( $options[ 'cff_translate_month' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_month' ] ) ) : 'month', |
| 210 | 'monthstext' => isset( $options[ 'cff_translate_months' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_months' ] ) ) : 'months', |
| 211 | 'yeartext' => isset( $options[ 'cff_translate_year' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_year' ] ) ) : 'year', |
| 212 | 'yearstext' => isset( $options[ 'cff_translate_years' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_years' ] ) ) : 'years', |
| 213 | 'agotext' => isset( $options[ 'cff_translate_ago' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_ago' ] ) ) : 'ago' |
| 214 | |
| 215 | ), $atts); |
| 216 | |
| 217 | /********** GENERAL **********/ |
| 218 | $cff_page_type = $atts[ 'pagetype' ]; |
| 219 | ($cff_page_type == 'group') ? $cff_is_group = true : $cff_is_group = false; |
| 220 | |
| 221 | $cff_feed_width = $atts[ 'width' ]; |
| 222 | if ( is_numeric(substr($cff_feed_width, -1, 1)) ) $cff_feed_width = $cff_feed_width . 'px'; |
| 223 | |
| 224 | //Set to be 100% width on mobile? |
| 225 | $cff_feed_width_resp = $atts[ 'widthresp' ]; |
| 226 | ( $cff_feed_width_resp == 'on' || $cff_feed_width_resp == 'true' || $cff_feed_width_resp == true ) ? $cff_feed_width_resp = true : $cff_feed_width_resp = false; |
| 227 | if( $atts[ 'widthresp' ] == 'false' ) $cff_feed_width_resp = false; |
| 228 | |
| 229 | $cff_feed_height = $atts[ 'height' ]; |
| 230 | if ( is_numeric(substr($cff_feed_height, -1, 1)) ) $cff_feed_height = $cff_feed_height . 'px'; |
| 231 | |
| 232 | $cff_feed_padding = $atts[ 'padding' ]; |
| 233 | if ( is_numeric(substr($cff_feed_padding, -1, 1)) ) $cff_feed_padding = $cff_feed_padding . 'px'; |
| 234 | |
| 235 | $cff_bg_color = $atts[ 'bgcolor' ]; |
| 236 | $cff_show_author = $atts[ 'showauthornew' ]; |
| 237 | $cff_cache_time = $atts[ 'cachetime' ]; |
| 238 | $cff_locale = $atts[ 'locale' ]; |
| 239 | if ( empty($cff_locale) || !isset($cff_locale) || $cff_locale == '' ) $cff_locale = 'en_US'; |
| 240 | if (!isset($cff_cache_time)) $cff_cache_time = 0; |
| 241 | $cff_cache_time_unit = $atts[ 'cacheunit' ]; |
| 242 | |
| 243 | //Don't allow cache time to be zero - set to 1 minute instead to minimize API requests |
| 244 | if(!isset($cff_cache_time) || $cff_cache_time == '0'){ |
| 245 | $cff_cache_time = 1; |
| 246 | $cff_cache_time_unit = 'minutes'; |
| 247 | } |
| 248 | if($cff_cache_time == 'none') $cff_cache_time = 0; |
| 249 | |
| 250 | $cff_class = $atts['class']; |
| 251 | //Compile feed styles |
| 252 | $cff_feed_styles = ''; |
| 253 | if( !empty($cff_feed_width) || !empty($cff_feed_height) || !empty($cff_feed_padding) || (!empty($cff_bg_color) && $cff_bg_color !== '#') ) $cff_feed_styles = 'style="'; |
| 254 | if ( !empty($cff_feed_width) ) $cff_feed_styles .= 'width:' . $cff_feed_width . '; '; |
| 255 | if ( !empty($cff_feed_height) ) $cff_feed_styles .= 'height:' . $cff_feed_height . '; '; |
| 256 | if ( !empty($cff_feed_padding) ) $cff_feed_styles .= 'padding:' . $cff_feed_padding . '; '; |
| 257 | if ( !empty($cff_bg_color) && $cff_bg_color !== '#' ) $cff_feed_styles .= 'background-color:#' . str_replace('#', '', $cff_bg_color) . '; '; |
| 258 | if( !empty($cff_feed_width) || !empty($cff_feed_height) || !empty($cff_feed_padding) || (!empty($cff_bg_color) && $cff_bg_color !== '#') ) $cff_feed_styles .= '"'; |
| 259 | //Like box |
| 260 | $cff_like_box_position = $atts[ 'likeboxpos' ]; |
| 261 | $cff_like_box_outside = $atts[ 'likeboxoutside' ]; |
| 262 | //Open links in new window? |
| 263 | $target = 'target="_blank"'; |
| 264 | /********** POST TYPES **********/ |
| 265 | $cff_show_links_type = true; |
| 266 | $cff_show_event_type = true; |
| 267 | $cff_show_video_type = true; |
| 268 | $cff_show_photos_type = true; |
| 269 | $cff_show_status_type = true; |
| 270 | $cff_events_only = false; |
| 271 | //Are we showing ONLY events? |
| 272 | 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; |
| 273 | /********** LAYOUT **********/ |
| 274 | $cff_includes = $atts[ 'include' ]; |
| 275 | //Look for non-plural version of string in the types string in case user specifies singular in shortcode |
| 276 | $cff_show_author = false; |
| 277 | $cff_show_text = false; |
| 278 | $cff_show_desc = false; |
| 279 | $cff_show_shared_links = false; |
| 280 | $cff_show_date = false; |
| 281 | $cff_show_media = false; |
| 282 | $cff_show_media_link = false; |
| 283 | $cff_show_event_title = false; |
| 284 | $cff_show_event_details = false; |
| 285 | $cff_show_meta = false; |
| 286 | $cff_show_link = false; |
| 287 | $cff_show_like_box = false; |
| 288 | if ( stripos($cff_includes, 'author') !== false ) $cff_show_author = true; |
| 289 | if ( stripos($cff_includes, 'text') !== false ) $cff_show_text = true; |
| 290 | if ( stripos($cff_includes, 'desc') !== false ) $cff_show_desc = true; |
| 291 | if ( stripos($cff_includes, 'sharedlink') !== false ) $cff_show_shared_links = true; |
| 292 | if ( stripos($cff_includes, 'date') !== false ) $cff_show_date = true; |
| 293 | if ( stripos($cff_includes, 'media') !== false ) $cff_show_media = true; |
| 294 | if ( stripos($cff_includes, 'medialink') !== false ) $cff_show_media_link = true; |
| 295 | if ( stripos($cff_includes, 'eventtitle') !== false ) $cff_show_event_title = true; |
| 296 | if ( stripos($cff_includes, 'eventdetail') !== false ) $cff_show_event_details = true; |
| 297 | if ( stripos($cff_includes, 'social') !== false ) $cff_show_meta = true; |
| 298 | if ( stripos($cff_includes, ',link') !== false ) $cff_show_link = true; //comma used to separate it from 'sharedlinks' - which also contains 'link' string |
| 299 | if ( stripos($cff_includes, 'like') !== false ) $cff_show_like_box = true; |
| 300 | |
| 301 | |
| 302 | //Exclude string |
| 303 | $cff_excludes = $atts[ 'exclude' ]; |
| 304 | //Look for non-plural version of string in the types string in case user specifies singular in shortcode |
| 305 | if ( stripos($cff_excludes, 'author') !== false ) $cff_show_author = false; |
| 306 | if ( stripos($cff_excludes, 'text') !== false ) $cff_show_text = false; |
| 307 | if ( stripos($cff_excludes, 'desc') !== false ) $cff_show_desc = false; |
| 308 | if ( stripos($cff_excludes, 'sharedlink') !== false ) $cff_show_shared_links = false; |
| 309 | if ( stripos($cff_excludes, 'date') !== false ) $cff_show_date = false; |
| 310 | if ( stripos($cff_excludes, 'media') !== false ) $cff_show_media = false; |
| 311 | if ( stripos($cff_excludes, 'medialink') !== false ) $cff_show_media_link = false; |
| 312 | if ( stripos($cff_excludes, 'eventtitle') !== false ) $cff_show_event_title = false; |
| 313 | if ( stripos($cff_excludes, 'eventdetail') !== false ) $cff_show_event_details = false; |
| 314 | if ( stripos($cff_excludes, 'social') !== false ) $cff_show_meta = false; |
| 315 | if ( stripos($cff_excludes, ',link') !== false ) $cff_show_link = false; //comma used to separate it from 'sharedlinks' - which also contains 'link' string |
| 316 | if ( stripos($cff_excludes, 'like') !== false ) $cff_show_like_box = false; |
| 317 | |
| 318 | |
| 319 | //Set free version to thumb layout by default as layout option not available on settings page |
| 320 | $cff_preset_layout = 'thumb'; |
| 321 | |
| 322 | //If the old shortcode option 'showauthor' is being used then apply it |
| 323 | $cff_show_author_old = $atts[ 'showauthor' ]; |
| 324 | if( $cff_show_author_old == 'false' ) $cff_show_author = false; |
| 325 | if( $cff_show_author_old == 'true' ) $cff_show_author = true; |
| 326 | |
| 327 | |
| 328 | /********** META **********/ |
| 329 | $cff_icon_style = $atts[ 'iconstyle' ]; |
| 330 | $cff_meta_text_color = $atts[ 'socialtextcolor' ]; |
| 331 | $cff_meta_bg_color = $atts[ 'socialbgcolor' ]; |
| 332 | $cff_meta_styles = ''; |
| 333 | if ( !empty($cff_meta_text_color) || ( !empty($cff_meta_bg_color) && $cff_meta_bg_color !== '#' ) ) $cff_meta_styles = 'style="'; |
| 334 | if ( !empty($cff_meta_text_color) ) $cff_meta_styles .= 'color:#' . str_replace('#', '', $cff_meta_text_color) . ';'; |
| 335 | if ( !empty($cff_meta_bg_color) && $cff_meta_bg_color !== '#' ) $cff_meta_styles .= 'background-color:#' . str_replace('#', '', $cff_meta_bg_color) . ';'; |
| 336 | if ( !empty($cff_meta_text_color) || ( !empty($cff_meta_bg_color) && $cff_meta_bg_color !== '#' ) ) $cff_meta_styles .= '"'; |
| 337 | $cff_nocomments_text = isset($options[ 'cff_nocomments_text' ]) ? $options[ 'cff_nocomments_text' ] : ''; |
| 338 | $cff_hide_comments = isset($options[ 'cff_hide_comments' ]) ? $options[ 'cff_hide_comments' ] : ''; |
| 339 | if (!isset($cff_nocomments_text) || empty($cff_nocomments_text)) $cff_hide_comments = true; |
| 340 | /********** TYPOGRAPHY **********/ |
| 341 | //See More text |
| 342 | $cff_see_more_text = $atts[ 'seemoretext' ]; |
| 343 | $cff_see_less_text = $atts[ 'seelesstext' ]; |
| 344 | //See Less text |
| 345 | //Title |
| 346 | $cff_title_format = $atts[ 'textformat' ]; |
| 347 | if (empty($cff_title_format)) $cff_title_format = 'p'; |
| 348 | $cff_title_size = $atts[ 'textsize' ]; |
| 349 | $cff_title_weight = $atts[ 'textweight' ]; |
| 350 | $cff_title_color = $atts[ 'textcolor' ]; |
| 351 | |
| 352 | $cff_title_styles = ''; |
| 353 | if( ( !empty($cff_title_size) && $cff_title_size != 'inherit' ) || ( !empty($cff_title_weight) && $cff_title_weight != 'inherit' ) || ( !empty($cff_title_color) && $cff_title_color !== '#' ) ) $cff_title_styles = 'style="'; |
| 354 | if ( !empty($cff_title_size) && $cff_title_size != 'inherit' ) $cff_title_styles .= 'font-size:' . $cff_title_size . 'px; '; |
| 355 | if ( !empty($cff_title_weight) && $cff_title_weight != 'inherit' ) $cff_title_styles .= 'font-weight:' . $cff_title_weight . '; '; |
| 356 | if ( !empty($cff_title_color) && $cff_title_color !== '#' ) $cff_title_styles .= 'color:#' . str_replace('#', '', $cff_title_color) . ';'; |
| 357 | if( ( !empty($cff_title_size) && $cff_title_size != 'inherit' ) || ( !empty($cff_title_weight) && $cff_title_weight != 'inherit' ) || ( !empty($cff_title_color) && $cff_title_color !== '#' ) ) $cff_title_styles .= '"'; |
| 358 | |
| 359 | $cff_title_link = $atts[ 'textlink' ]; |
| 360 | |
| 361 | $cff_posttext_link_color = str_replace('#', '', $atts['textlinkcolor']); |
| 362 | |
| 363 | ( $cff_title_link == 'on' || $cff_title_link == 'true' || $cff_title_link == true ) ? $cff_title_link = true : $cff_title_link = false; |
| 364 | if( $atts[ 'textlink' ] == 'false' ) $cff_title_link = false; |
| 365 | |
| 366 | //Author |
| 367 | $cff_author_size = $atts[ 'authorsize' ]; |
| 368 | $cff_author_color = $atts[ 'authorcolor' ]; |
| 369 | |
| 370 | $cff_author_styles = ''; |
| 371 | if( ( !empty($cff_author_size) && $cff_author_size != 'inherit' ) || ( !empty($cff_author_color) && $cff_author_color !== '#' ) ) $cff_author_styles = 'style="'; |
| 372 | if ( !empty($cff_author_size) && $cff_author_size != 'inherit' ) $cff_author_styles .= 'font-size:' . $cff_author_size . 'px; '; |
| 373 | if ( !empty($cff_author_color) && $cff_author_color !== '#' ) $cff_author_styles .= 'color:#' . str_replace('#', '', $cff_author_color) . ';'; |
| 374 | if( ( !empty($cff_author_size) && $cff_author_size != 'inherit' ) || ( !empty($cff_author_color) && $cff_author_color !== '#' ) ) $cff_author_styles .= '"'; |
| 375 | |
| 376 | //Description |
| 377 | $cff_body_size = $atts[ 'descsize' ]; |
| 378 | $cff_body_weight = $atts[ 'descweight' ]; |
| 379 | $cff_body_color = $atts[ 'desccolor' ]; |
| 380 | |
| 381 | $cff_body_styles = ''; |
| 382 | if( ( !empty($cff_body_size) && $cff_body_size != 'inherit' ) || ( !empty($cff_body_weight) && $cff_body_weight != 'inherit' ) || ( !empty($cff_body_color) && $cff_body_color !== '#' ) ) $cff_body_styles = 'style="'; |
| 383 | if ( !empty($cff_body_size) && $cff_body_size != 'inherit' ) $cff_body_styles .= 'font-size:' . $cff_body_size . 'px; '; |
| 384 | if ( !empty($cff_body_weight) && $cff_body_weight != 'inherit' ) $cff_body_styles .= 'font-weight:' . $cff_body_weight . '; '; |
| 385 | if ( !empty($cff_body_color) && $cff_body_color !== '#' ) $cff_body_styles .= 'color:#' . str_replace('#', '', $cff_body_color) . ';'; |
| 386 | if( ( !empty($cff_body_size) && $cff_body_size != 'inherit' ) || ( !empty($cff_body_weight) && $cff_body_weight != 'inherit' ) || ( !empty($cff_body_color) && $cff_body_color !== '#' ) ) $cff_body_styles .= '"'; |
| 387 | |
| 388 | //Shared link title |
| 389 | $cff_link_title_format = $atts[ 'linktitleformat' ]; |
| 390 | if (empty($cff_link_title_format)) $cff_link_title_format = 'p'; |
| 391 | $cff_link_title_size = $atts[ 'linktitlesize' ]; |
| 392 | $cff_link_title_color = str_replace('#', '', $atts[ 'linktitlecolor' ]); |
| 393 | $cff_link_url_color = $atts[ 'linkurlcolor' ]; |
| 394 | |
| 395 | $cff_link_title_styles = ''; |
| 396 | if ( !empty($cff_link_title_size) && $cff_link_title_size != 'inherit' ) $cff_link_title_styles = 'style="font-size:' . $cff_link_title_size . 'px;"'; |
| 397 | |
| 398 | //Shared link box |
| 399 | $cff_link_bg_color = $atts[ 'linkbgcolor' ]; |
| 400 | $cff_link_border_color = $atts[ 'linkbordercolor' ]; |
| 401 | $cff_disable_link_box = $atts['disablelinkbox']; |
| 402 | ($cff_disable_link_box == 'true' || $cff_disable_link_box == 'on') ? $cff_disable_link_box = true : $cff_disable_link_box = false; |
| 403 | |
| 404 | $cff_link_box_styles = ''; |
| 405 | if( !empty($cff_link_border_color) || (!empty($cff_link_bg_color) && $cff_link_bg_color !== '#') ) $cff_link_box_styles = 'style="'; |
| 406 | if ( !empty($cff_link_border_color) ) $cff_link_box_styles .= 'border: 1px solid #' . str_replace('#', '', $cff_link_border_color) . '; '; |
| 407 | if ( !empty($cff_link_bg_color) && $cff_link_bg_color !== '#' ) $cff_link_box_styles .= 'background-color: #' . str_replace('#', '', $cff_link_bg_color) . ';'; |
| 408 | if( !empty($cff_link_border_color) || (!empty($cff_link_bg_color) && $cff_link_bg_color !== '#') ) $cff_link_box_styles .= '"'; |
| 409 | |
| 410 | //Event Title |
| 411 | $cff_event_title_format = $atts[ 'eventtitleformat' ]; |
| 412 | if (empty($cff_event_title_format)) $cff_event_title_format = 'p'; |
| 413 | $cff_event_title_size = $atts[ 'eventtitlesize' ]; |
| 414 | $cff_event_title_weight = $atts[ 'eventtitleweight' ]; |
| 415 | $cff_event_title_color = $atts[ 'eventtitlecolor' ]; |
| 416 | |
| 417 | $cff_event_title_styles = ''; |
| 418 | if( ( !empty($cff_event_title_size) && $cff_event_title_size != 'inherit' ) || ( !empty($cff_event_title_weight) && $cff_event_title_weight != 'inherit' ) || ( !empty($cff_event_title_color) && $cff_event_title_color !== '#' ) ) $cff_event_title_styles = 'style="'; |
| 419 | if ( !empty($cff_event_title_size) && $cff_event_title_size != 'inherit' ) $cff_event_title_styles .= 'font-size:' . $cff_event_title_size . 'px; '; |
| 420 | if ( !empty($cff_event_title_weight) && $cff_event_title_weight != 'inherit' ) $cff_event_title_styles .= 'font-weight:' . $cff_event_title_weight . '; '; |
| 421 | if ( !empty($cff_event_title_color) && $cff_event_title_color !== '#' ) $cff_event_title_styles .= 'color:#' . str_replace('#', '', $cff_event_title_color) . ';'; |
| 422 | if( ( !empty($cff_event_title_size) && $cff_event_title_size != 'inherit' ) || ( !empty($cff_event_title_weight) && $cff_event_title_weight != 'inherit' ) || ( !empty($cff_event_title_color) && $cff_event_title_color !== '#' ) ) $cff_event_title_styles .= '"'; |
| 423 | |
| 424 | $cff_event_title_link = $atts[ 'eventtitlelink' ]; |
| 425 | ( $cff_event_title_link == 'on' || $cff_event_title_link == 'true' || $cff_event_title_link == true ) ? $cff_event_title_link = true : $cff_event_title_link = false; |
| 426 | if( $atts[ 'eventtitlelink' ] == 'false' ) $cff_event_title_link = false; |
| 427 | |
| 428 | //Event Date |
| 429 | $cff_event_date_size = $atts[ 'eventdatesize' ]; |
| 430 | $cff_event_date_weight = $atts[ 'eventdateweight' ]; |
| 431 | $cff_event_date_color = $atts[ 'eventdatecolor' ]; |
| 432 | $cff_event_date_position = $atts[ 'eventdatepos' ]; |
| 433 | $cff_event_date_formatting = $atts[ 'eventdateformat' ]; |
| 434 | $cff_event_date_custom = $atts[ 'eventdatecustom' ]; |
| 435 | |
| 436 | $cff_event_date_styles = ''; |
| 437 | if( ( !empty($cff_event_date_size) && $cff_event_date_size != 'inherit' ) || ( !empty($cff_event_date_weight) && $cff_event_date_weight != 'inherit' ) || ( !empty($cff_event_date_color) && $cff_event_date_color !== '#' ) ) $cff_event_date_styles = 'style="'; |
| 438 | if ( !empty($cff_event_date_size) && $cff_event_date_size != 'inherit' ) $cff_event_date_styles .= 'font-size:' . $cff_event_date_size . 'px; '; |
| 439 | if ( !empty($cff_event_date_weight) && $cff_event_date_weight != 'inherit' ) $cff_event_date_styles .= 'font-weight:' . $cff_event_date_weight . '; '; |
| 440 | if ( !empty($cff_event_date_color) && $cff_event_date_color !== '#' ) $cff_event_date_styles .= 'color:#' . str_replace('#', '', $cff_event_date_color) . ';'; |
| 441 | if( ( !empty($cff_event_date_size) && $cff_event_date_size != 'inherit' ) || ( !empty($cff_event_date_weight) && $cff_event_date_weight != 'inherit' ) || ( !empty($cff_event_date_color) && $cff_event_date_color !== '#' ) ) $cff_event_date_styles .= '"'; |
| 442 | |
| 443 | //Event Details |
| 444 | $cff_event_details_size = $atts[ 'eventdetailssize' ]; |
| 445 | $cff_event_details_weight = $atts[ 'eventdetailsweight' ]; |
| 446 | $cff_event_details_color = $atts[ 'eventdetailscolor' ]; |
| 447 | $cff_event_link_color = $atts[ 'eventlinkcolor' ]; |
| 448 | |
| 449 | $cff_event_details_styles = ''; |
| 450 | if( ( !empty($cff_event_details_size) && $cff_event_details_size != 'inherit' ) || ( !empty($cff_event_details_weight) && $cff_event_details_weight != 'inherit' ) || ( !empty($cff_event_details_color) && $cff_event_details_color !== '#' ) ) $cff_event_details_styles = 'style="'; |
| 451 | if ( !empty($cff_event_details_size) && $cff_event_details_size != 'inherit' ) $cff_event_details_styles .= 'font-size:' . $cff_event_details_size . 'px; '; |
| 452 | if ( !empty($cff_event_details_weight) && $cff_event_details_weight != 'inherit' ) $cff_event_details_styles .= 'font-weight:' . $cff_event_details_weight . '; '; |
| 453 | if ( !empty($cff_event_details_color) && $cff_event_details_color !== '#' ) $cff_event_details_styles .= 'color:#' . str_replace('#', '', $cff_event_details_color) . ';'; |
| 454 | if( ( !empty($cff_event_details_size) && $cff_event_details_size != 'inherit' ) || ( !empty($cff_event_details_weight) && $cff_event_details_weight != 'inherit' ) || ( !empty($cff_event_details_color) && $cff_event_details_color !== '#' ) ) $cff_event_details_styles .= '"'; |
| 455 | |
| 456 | //Date |
| 457 | $cff_date_position = $atts[ 'datepos' ]; |
| 458 | if (!isset($cff_date_position)) $cff_date_position = 'below'; |
| 459 | $cff_date_size = $atts[ 'datesize' ]; |
| 460 | $cff_date_weight = $atts[ 'dateweight' ]; |
| 461 | $cff_date_color = $atts[ 'datecolor' ]; |
| 462 | |
| 463 | $cff_date_styles = ''; |
| 464 | if( ( !empty($cff_date_size) && $cff_date_size != 'inherit' ) || ( !empty($cff_date_weight) && $cff_date_weight != 'inherit' ) || ( !empty($cff_date_color) && $cff_date_color !== '#' ) ) $cff_date_styles = 'style="'; |
| 465 | if ( !empty($cff_date_size) && $cff_date_size != 'inherit' ) $cff_date_styles .= 'font-size:' . $cff_date_size . 'px; '; |
| 466 | if ( !empty($cff_date_weight) && $cff_date_weight != 'inherit' ) $cff_date_styles .= 'font-weight:' . $cff_date_weight . '; '; |
| 467 | if ( !empty($cff_date_color) && $cff_date_color !== '#' ) $cff_date_styles .= 'color:#' . str_replace('#', '', $cff_date_color) . ';'; |
| 468 | if( ( !empty($cff_date_size) && $cff_date_size != 'inherit' ) || ( !empty($cff_date_weight) && $cff_date_weight != 'inherit' ) || ( !empty($cff_date_color) && $cff_date_color !== '#' ) ) $cff_date_styles .= '"'; |
| 469 | |
| 470 | $cff_date_before = isset($options[ 'cff_date_before' ]) ? $options[ 'cff_date_before' ] : ''; |
| 471 | $cff_date_after = isset($options[ 'cff_date_after' ]) ? $options[ 'cff_date_after' ] : ''; |
| 472 | //Set user's timezone based on setting |
| 473 | $cff_timezone = $atts['timezone']; |
| 474 | $cff_orig_timezone = date_default_timezone_get(); |
| 475 | date_default_timezone_set($cff_timezone); |
| 476 | |
| 477 | //Posted ago strings |
| 478 | $cff_date_translate_strings = array( |
| 479 | 'cff_translate_second' => $atts['secondtext'], |
| 480 | 'cff_translate_seconds' => $atts['secondstext'], |
| 481 | 'cff_translate_minute' => $atts['minutetext'], |
| 482 | 'cff_translate_minutes' => $atts['minutestext'], |
| 483 | 'cff_translate_hour' => $atts['hourtext'], |
| 484 | 'cff_translate_hours' => $atts['hourstext'], |
| 485 | 'cff_translate_day' => $atts['daytext'], |
| 486 | 'cff_translate_days' => $atts['daystext'], |
| 487 | 'cff_translate_week' => $atts['weektext'], |
| 488 | 'cff_translate_weeks' => $atts['weekstext'], |
| 489 | 'cff_translate_month' => $atts['monthtext'], |
| 490 | 'cff_translate_months' => $atts['monthstext'], |
| 491 | 'cff_translate_year' => $atts['yeartext'], |
| 492 | 'cff_translate_years' => $atts['yearstext'], |
| 493 | 'cff_translate_ago' => $atts['agotext'] |
| 494 | ); |
| 495 | |
| 496 | //Link to Facebook |
| 497 | $cff_link_size = $atts[ 'linksize' ]; |
| 498 | $cff_link_weight = $atts[ 'linkweight' ]; |
| 499 | $cff_link_color = $atts[ 'linkcolor' ]; |
| 500 | |
| 501 | $cff_link_styles = ''; |
| 502 | if( ( !empty($cff_link_size) && $cff_link_size != 'inherit' ) || ( !empty($cff_link_weight) && $cff_link_weight != 'inherit' ) || ( !empty($cff_link_color) && $cff_link_color !== '#' ) ) $cff_link_styles = 'style="'; |
| 503 | if ( !empty($cff_link_size) && $cff_link_size != 'inherit' ) $cff_link_styles .= 'font-size:' . $cff_link_size . 'px; '; |
| 504 | if ( !empty($cff_link_weight) && $cff_link_weight != 'inherit' ) $cff_link_styles .= 'font-weight:' . $cff_link_weight . '; '; |
| 505 | if ( !empty($cff_link_color) && $cff_link_color !== '#' ) $cff_link_styles .= 'color:#' . str_replace('#', '', $cff_link_color) . ';'; |
| 506 | if( ( !empty($cff_link_size) && $cff_link_size != 'inherit' ) || ( !empty($cff_link_weight) && $cff_link_weight != 'inherit' ) || ( !empty($cff_link_color) && $cff_link_color !== '#' ) ) $cff_link_styles .= '"'; |
| 507 | |
| 508 | //Link custom text |
| 509 | $cff_facebook_link_text = $atts[ 'facebooklinktext' ]; |
| 510 | $cff_facebook_share_text = $atts[ 'sharelinktext' ]; |
| 511 | if ($cff_facebook_share_text == '') $cff_facebook_share_text = 'Share'; |
| 512 | |
| 513 | |
| 514 | //Show Facebook link |
| 515 | $cff_show_facebook_link = $atts[ 'showfacebooklink' ]; |
| 516 | ( $cff_show_facebook_link == 'on' || $cff_show_facebook_link == 'true' || $cff_show_facebook_link == true ) ? $cff_show_facebook_link = true : $cff_show_facebook_link = false; |
| 517 | if( $atts[ 'showfacebooklink' ] === 'false' ) $cff_show_facebook_link = false; |
| 518 | |
| 519 | |
| 520 | //Show Share link |
| 521 | $cff_show_facebook_share = $atts[ 'showsharelink' ]; |
| 522 | ( $cff_show_facebook_share == 'on' || $cff_show_facebook_share == 'true' || $cff_show_facebook_share == true ) ? $cff_show_facebook_share = true : $cff_show_facebook_share = false; |
| 523 | if( $atts[ 'showsharelink' ] === 'false' ) $cff_show_facebook_share = false; |
| 524 | |
| 525 | $cff_view_link_text = $atts[ 'viewlinktext' ]; |
| 526 | $cff_link_to_timeline = $atts[ 'linktotimeline' ]; |
| 527 | /********** MISC **********/ |
| 528 | //Like Box styles |
| 529 | $cff_likebox_bg_color = $atts[ 'likeboxcolor' ]; |
| 530 | |
| 531 | $cff_like_box_text_color = $atts[ 'likeboxtextcolor' ]; |
| 532 | $cff_like_box_colorscheme = 'light'; |
| 533 | if ($cff_like_box_text_color == 'white') $cff_like_box_colorscheme = 'dark'; |
| 534 | |
| 535 | $cff_likebox_width = $atts[ 'likeboxwidth' ]; |
| 536 | if ( is_numeric(substr($cff_likebox_width, -1, 1)) ) $cff_likebox_width = $cff_likebox_width . 'px'; |
| 537 | |
| 538 | $cff_likebox_height = $atts[ 'likeboxheight' ]; |
| 539 | $cff_likebox_height = preg_replace('/px$/', '', $cff_likebox_height); |
| 540 | |
| 541 | if ( !isset($cff_likebox_width) || empty($cff_likebox_width) || $cff_likebox_width == '' ) $cff_likebox_width = '100%'; |
| 542 | $cff_like_box_faces = $atts[ 'likeboxfaces' ]; |
| 543 | if ( !isset($cff_like_box_faces) || empty($cff_like_box_faces) ){ |
| 544 | $cff_like_box_faces = 'false'; |
| 545 | } else { |
| 546 | $cff_like_box_faces = 'true'; |
| 547 | } |
| 548 | |
| 549 | $cff_like_box_border = $atts[ 'likeboxborder' ]; |
| 550 | if ($cff_like_box_border) { |
| 551 | $cff_like_box_border = 'true'; |
| 552 | } else { |
| 553 | $cff_like_box_border = 'false'; |
| 554 | } |
| 555 | |
| 556 | $cff_like_box_cover = $atts[ 'likeboxcover' ]; |
| 557 | if ($cff_like_box_cover) { |
| 558 | $cff_like_box_cover = 'false'; |
| 559 | } else { |
| 560 | $cff_like_box_cover = 'true'; |
| 561 | } |
| 562 | |
| 563 | $cff_like_box_small_header = $atts[ 'likeboxsmallheader' ]; |
| 564 | if ($cff_like_box_small_header) { |
| 565 | $cff_like_box_small_header = 'true'; |
| 566 | } else { |
| 567 | $cff_like_box_small_header = 'false'; |
| 568 | } |
| 569 | |
| 570 | $cff_like_box_hide_cta = $atts[ 'likeboxhidebtn' ]; |
| 571 | if ($cff_like_box_hide_cta) { |
| 572 | $cff_like_box_hide_cta = 'true'; |
| 573 | } else { |
| 574 | $cff_like_box_hide_cta = 'false'; |
| 575 | } |
| 576 | |
| 577 | //Compile Like box styles |
| 578 | $cff_likebox_styles = 'style="width: ' . $cff_likebox_width . ';'; |
| 579 | if ( !empty($cff_likebox_bg_color) ) $cff_likebox_styles .= ' background-color: #' . str_replace('#', '', $cff_likebox_bg_color) . ';'; |
| 580 | |
| 581 | //Set the left margin on the like box based on how it's being displayed |
| 582 | if ( (!empty($cff_likebox_bg_color) && $cff_likebox_bg_color != '#') || ($cff_like_box_faces == 'true' || $cff_like_box_faces == 'on') ) $cff_likebox_styles .= ' margin-left: 0px;'; |
| 583 | |
| 584 | $cff_likebox_styles .= '"'; |
| 585 | |
| 586 | //Get feed header settings |
| 587 | $cff_header_bg_color = $atts['headerbg']; |
| 588 | $cff_header_padding = $atts['headerpadding']; |
| 589 | if ( is_numeric(substr($cff_header_padding, -1, 1)) ) $cff_header_padding = $cff_header_padding . 'px'; |
| 590 | |
| 591 | $cff_header_text_size = $atts['headertextsize']; |
| 592 | $cff_header_text_weight = $atts['headertextweight']; |
| 593 | $cff_header_text_color = $atts['headertextcolor']; |
| 594 | |
| 595 | //Compile feed header styles |
| 596 | $cff_header_styles = ''; |
| 597 | if( ( !empty($cff_header_bg_color) && $cff_header_bg_color !== '#' ) || !empty($cff_header_padding) || ( !empty($cff_header_text_size) && $cff_header_text_size != 'inherit' ) || ( !empty($cff_header_text_weight) && $cff_header_text_weight != 'inherit' ) || (!empty($cff_header_text_color) && $cff_header_text_color !== '#') ) $cff_header_styles = 'style="'; |
| 598 | if ( !empty($cff_header_bg_color) && $cff_header_bg_color !== '#' ) $cff_header_styles .= 'background-color: #' . str_replace('#', '', $cff_header_bg_color) . '; '; |
| 599 | if ( !empty($cff_header_padding) ) $cff_header_styles .= 'padding: ' . $cff_header_padding . '; '; |
| 600 | if ( !empty($cff_header_text_size) && $cff_header_text_size != 'inherit' ) $cff_header_styles .= 'font-size: ' . $cff_header_text_size . 'px; '; |
| 601 | if ( !empty($cff_header_text_weight) && $cff_header_text_weight != 'inherit' ) $cff_header_styles .= 'font-weight: ' . $cff_header_text_weight . '; '; |
| 602 | if ( !empty($cff_header_text_color) && $cff_header_text_color !== '#' ) $cff_header_styles .= 'color: #' . str_replace('#', '', $cff_header_text_color) . '; '; |
| 603 | if( ( !empty($cff_header_bg_color) && $cff_header_bg_color !== '#' ) || !empty($cff_header_padding) || ( !empty($cff_header_text_size) && $cff_header_text_size != 'inherit' ) || ( !empty($cff_header_text_weight) && $cff_header_text_weight != 'inherit' ) || (!empty($cff_header_text_color) && $cff_header_text_color !== '#') ) $cff_header_styles .= '"'; |
| 604 | |
| 605 | //Video |
| 606 | //Dimensions |
| 607 | $cff_video_width = 640; |
| 608 | $cff_video_height = $atts[ 'videoheight' ]; |
| 609 | |
| 610 | //Action |
| 611 | $cff_video_action = $atts[ 'videoaction' ]; |
| 612 | //Separating Line |
| 613 | $cff_sep_color = $atts[ 'sepcolor' ]; |
| 614 | if (empty($cff_sep_color)) $cff_sep_color = 'ddd'; |
| 615 | $cff_sep_size = $atts[ 'sepsize' ]; |
| 616 | //If empty then set a 0px border |
| 617 | if ( empty($cff_sep_size) || $cff_sep_size == '' ) { |
| 618 | $cff_sep_size = 0; |
| 619 | //Need to set a color otherwise the CSS is invalid |
| 620 | $cff_sep_color = 'fff'; |
| 621 | } |
| 622 | |
| 623 | $cff_post_bg_color = str_replace('#', '', $atts['postbgcolor']); |
| 624 | $cff_post_rounded = $atts['postcorners']; |
| 625 | |
| 626 | ($cff_post_bg_color !== '#' && $cff_post_bg_color !== '') ? $cff_post_bg_color_check = true : $cff_post_bg_color_check = false; |
| 627 | ($cff_sep_color !== '#' && $cff_sep_color !== '') ? $cff_sep_color_check = true : $cff_sep_color_check = false; |
| 628 | |
| 629 | $cff_item_styles = ''; |
| 630 | //CFF item styles |
| 631 | if( $cff_sep_color_check || $cff_post_bg_color_check ){ |
| 632 | $cff_item_styles = 'style="'; |
| 633 | if($cff_sep_color_check && !$cff_post_bg_color_check) $cff_item_styles .= 'border-bottom: ' . $cff_sep_size . 'px solid #' . str_replace('#', '', $cff_sep_color) . '; '; |
| 634 | if($cff_post_bg_color_check) $cff_item_styles .= 'background-color: #' . $cff_post_bg_color . '; '; |
| 635 | if(isset($cff_post_rounded) && $cff_post_rounded !== '0') $cff_item_styles .= '-webkit-border-radius: ' . $cff_post_rounded . 'px; -moz-border-radius: ' . $cff_post_rounded . 'px; border-radius: ' . $cff_post_rounded . 'px; '; |
| 636 | $cff_item_styles .= '"'; |
| 637 | } |
| 638 | |
| 639 | //Text limits |
| 640 | $title_limit = $atts['textlength']; |
| 641 | if (!isset($title_limit)) $title_limit = 9999; |
| 642 | $body_limit = $atts['desclength']; |
| 643 | //Assign the Access Token and Page ID variables |
| 644 | $access_token = $atts['accesstoken']; |
| 645 | $page_id = trim( $atts['id'] ); |
| 646 | |
| 647 | //If user pastes their full URL into the Page ID field then strip it out |
| 648 | $cff_facebook_string = 'facebook.com'; |
| 649 | $cff_page_id_url_check = stripos($page_id, $cff_facebook_string); |
| 650 | |
| 651 | if ( $cff_page_id_url_check ) { |
| 652 | //Remove trailing slash if exists |
| 653 | $page_id = preg_replace('{/$}', '', $page_id); |
| 654 | //Get last part of url |
| 655 | $page_id = substr( $page_id, strrpos( $page_id, '/' )+1 ); |
| 656 | } |
| 657 | |
| 658 | //If the Page ID contains a query string at the end then remove it |
| 659 | if ( stripos( $page_id, '?') !== false ) $page_id = substr($page_id, 0, strrpos($page_id, '?')); |
| 660 | |
| 661 | //Get show posts attribute. If not set then default to 25 |
| 662 | $show_posts = $atts['num']; |
| 663 | if (empty($show_posts)) $show_posts = 25; |
| 664 | if ( $show_posts == 'undefined' ) $show_posts = 25; |
| 665 | |
| 666 | //If the 'Enter my own Access Token' box is unchecked then don't use the user's access token, even if there's one in the field |
| 667 | get_option('cff_show_access_token') ? $cff_show_access_token = true : $cff_show_access_token = false; |
| 668 | |
| 669 | //If there's no Access Token then use a default |
| 670 | $access_token_array = array( |
| 671 | '772762049525257|UksMy-gYmk78WNHVEsimaf8uar4', |
| 672 | '1611234219197161|PenH1iYmf3CShpuWiLMrP6_0mro', |
| 673 | '842457575860455|MA2WQAK6MO22mYlD1vAfQmY-jNQ', |
| 674 | '1598576770461963|t3KRNHf1490G8qEopdGoUiMPJ7I', |
| 675 | '1774415812787078|3yGpMpgbH-Nte9YHCfVIQ59RIt8', |
| 676 | '762305090538008|KmVsImjHmaJIPTpII9HyOif3yD0', |
| 677 | '1741187749472232|b1ZfgQ2OSQZzsQN1lqLn4vjrQV4', |
| 678 | '1748310315388907|AMSWRHgAoChtXepfsWU0OxKfVbQ', |
| 679 | '1721409114785415|4dIAXp4_utfqkAJS-9X4OXB6GR4', |
| 680 | '1609030662756868|nCKsZPN4cI-GsIJsi0DESGGtSgw', |
| 681 | '1590773627916704|EbgBWG45AVQZdNrwsAnTl_-CW_A', |
| 682 | '227652200958404|AzHtmm3B080elswwLKJrRCKYpGg', |
| 683 | '1176842909001332|YIQehZhGPWxqkvmiFn4Klt1PA4U', |
| 684 | '217933725249790|h4YSEYX71EO_2el93hiT47uyf5g', |
| 685 | '823681761071502|0oAyJYz-MO-jgr8rI3ftrEcBRiQ' |
| 686 | ); |
| 687 | if ($access_token == '' || !$cff_show_access_token) $access_token = $access_token_array[rand(0, 14)]; |
| 688 | |
| 689 | //Check whether a Page ID has been defined |
| 690 | if ($page_id == '') { |
| 691 | 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=YOUR_PAGE_ID_HERE].<br /><br />"; |
| 692 | return false; |
| 693 | } |
| 694 | |
| 695 | |
| 696 | //Is it SSL? |
| 697 | $cff_ssl = ''; |
| 698 | if (is_ssl()) $cff_ssl = '&return_ssl_resources=true'; |
| 699 | |
| 700 | //Use posts? or feed? |
| 701 | $old_others_option = get_option('cff_show_others'); //Use this to help depreciate the old option |
| 702 | $show_others = $atts['others']; |
| 703 | $show_posts_by = $atts['showpostsby']; |
| 704 | $graph_query = 'posts'; |
| 705 | $cff_show_only_others = false; |
| 706 | |
| 707 | //If 'others' shortcode option is used then it overrides any other option |
| 708 | if ($show_others || $old_others_option == 'on') { |
| 709 | //Show posts by everyone |
| 710 | if ( $old_others_option == 'on' || $show_others == 'on' || $show_others == 'true' || $show_others == true || $cff_is_group ) $graph_query = 'feed'; |
| 711 | |
| 712 | //Only show posts by me |
| 713 | if ( $show_others == 'false' ) $graph_query = 'posts'; |
| 714 | |
| 715 | } else { |
| 716 | //Else use the settings page option or the 'showpostsby' shortcode option |
| 717 | |
| 718 | //Only show posts by me |
| 719 | if ( $show_posts_by == 'me' ) $graph_query = 'posts'; |
| 720 | |
| 721 | //Show posts by everyone |
| 722 | if ( $show_posts_by == 'others' || $cff_is_group ) $graph_query = 'feed'; |
| 723 | |
| 724 | //Show posts ONLY by others |
| 725 | if ( $show_posts_by == 'onlyothers' && !$cff_is_group ) { |
| 726 | $graph_query = 'feed'; |
| 727 | $cff_show_only_others = true; |
| 728 | } |
| 729 | |
| 730 | } |
| 731 | |
| 732 | |
| 733 | //If the limit isn't set then set it to be 5 more than the number of posts defined |
| 734 | if ( isset($atts['limit']) && $atts['limit'] !== '' ) { |
| 735 | $cff_post_limit = $atts['limit']; |
| 736 | } else { |
| 737 | $cff_post_limit = intval(intval($show_posts) + 7); |
| 738 | } |
| 739 | if( $cff_post_limit >= 100 ) $cff_post_limit = 100; |
| 740 | |
| 741 | |
| 742 | //Calculate the cache time in seconds |
| 743 | if($cff_cache_time_unit == 'minutes') $cff_cache_time_unit = 60; |
| 744 | if($cff_cache_time_unit == 'hours') $cff_cache_time_unit = 60*60; |
| 745 | if($cff_cache_time_unit == 'days') $cff_cache_time_unit = 60*60*24; |
| 746 | $cache_seconds = $cff_cache_time * $cff_cache_time_unit; |
| 747 | |
| 748 | //Get like box vars |
| 749 | $cff_likebox_width = $atts[ 'likeboxwidth' ]; |
| 750 | if ( !isset($cff_likebox_width) || empty($cff_likebox_width) || $cff_likebox_width == '' ) $cff_likebox_width = 300; |
| 751 | |
| 752 | //Set like box variable |
| 753 | isset( $options[ 'cff_app_id' ] ) && !empty( $options[ 'cff_app_id' ] ) ? $cff_app_id = $options[ 'cff_app_id' ] : $cff_app_id = '712681982206086'; |
| 754 | $cff_like_box_params = '&appId=' .$cff_app_id; |
| 755 | $like_box = '<div class="cff-likebox'; |
| 756 | if ($cff_like_box_outside) $like_box .= ' cff-outside'; |
| 757 | $like_box .= ($cff_like_box_position == 'top') ? ' cff-top' : ' cff-bottom'; |
| 758 | |
| 759 | $like_box_page_id = explode(",", str_replace(' ', '', $page_id) ); |
| 760 | |
| 761 | $like_box .= '" ><script src="https://connect.facebook.net/' . $cff_locale . '/all.js#xfbml=1'.$cff_like_box_params.'"></script><div class="fb-page" data-href="https://www.facebook.com/'.$like_box_page_id[0].'" data-width="'.$cff_likebox_width.'" data-hide-cover="'.$cff_like_box_cover.'" data-show-facepile="'.$cff_like_box_faces.'" data-small-header="'.$cff_like_box_small_header.'" data-hide-cta="'.$cff_like_box_hide_cta.'" data-show-posts="false" data-adapt-container-width="true"><div class="fb-xfbml-parse-ignore"><blockquote cite="https://www.facebook.com/'.$like_box_page_id[0].'"><a href="https://www.facebook.com/'.$like_box_page_id[0].'">'.$cff_facebook_link_text.'</a></blockquote></div></div><div id="fb-root"></div></div>'; |
| 762 | |
| 763 | //Don't show like box if it's a group |
| 764 | if($cff_is_group) $like_box = ''; |
| 765 | |
| 766 | |
| 767 | //Feed header |
| 768 | $cff_show_header = $atts['showheader']; |
| 769 | ($cff_show_header == 'true' || $cff_show_header == 'on') ? $cff_show_header = true : $cff_show_header = false; |
| 770 | |
| 771 | $cff_header_outside = $atts['headeroutside']; |
| 772 | ($cff_header_outside == 'true' || $cff_header_outside == 'on') ? $cff_header_outside = true : $cff_header_outside = false; |
| 773 | |
| 774 | $cff_header_text = $atts['headertext']; |
| 775 | $cff_header_icon = $atts['headericon']; |
| 776 | $cff_header_icon_color = $atts['headericoncolor']; |
| 777 | $cff_header_icon_size = $atts['headericonsize']; |
| 778 | |
| 779 | $cff_header = '<h3 class="cff-header'; |
| 780 | if ($cff_header_outside) $cff_header .= ' cff-outside'; |
| 781 | $cff_header .= '" ' . $cff_header_styles . '>'; |
| 782 | $cff_header .= '<i class="fa fa-' . $cff_header_icon . '"'; |
| 783 | if(!empty($cff_header_icon_color) || !empty($cff_header_icon_size)) $cff_header .= ' style="'; |
| 784 | if(!empty($cff_header_icon_color)) $cff_header .= 'color: #' . str_replace('#', '', $cff_header_icon_color) . ';'; |
| 785 | if(!empty($cff_header_icon_size)) $cff_header .= ' font-size: ' . $cff_header_icon_size . 'px;'; |
| 786 | if(!empty($cff_header_icon_color) || !empty($cff_header_icon_size))$cff_header .= '"'; |
| 787 | $cff_header .= '></i>'; |
| 788 | $cff_header .= '<span class="header-text" style="height: '.$cff_header_icon_size.'px;">' . $cff_header_text . '</span>'; |
| 789 | $cff_header .= '</h3>'; |
| 790 | |
| 791 | //Misc Settings |
| 792 | $cff_nofollow = $atts['nofollow']; |
| 793 | ( $cff_nofollow == 'on' || $cff_nofollow == 'true' || $cff_nofollow == true ) ? $cff_nofollow = true : $cff_nofollow = false; |
| 794 | if( $atts[ 'nofollow' ] == 'false' ) $cff_nofollow = false; |
| 795 | ( $cff_nofollow ) ? $cff_nofollow = ' rel="nofollow"' : $cff_nofollow = ''; |
| 796 | |
| 797 | //If the number of posts is set to zero then don't show any and set limit to one |
| 798 | if ( ($atts['num'] == '0' || $atts['num'] == 0) && $atts['num'] !== ''){ |
| 799 | $show_posts = 0; |
| 800 | $cff_post_limit = 1; |
| 801 | } |
| 802 | |
| 803 | //***START FEED*** |
| 804 | $cff_content = ''; |
| 805 | |
| 806 | //Add the page header to the outside of the top of feed |
| 807 | if ($cff_show_header && $cff_header_outside) $cff_content .= $cff_header; |
| 808 | |
| 809 | //Add like box to the outside of the top of feed |
| 810 | if ($cff_like_box_position == 'top' && $cff_show_like_box && $cff_like_box_outside) $cff_content .= $like_box; |
| 811 | |
| 812 | //Create CFF container HTML |
| 813 | $cff_content .= '<div class="cff-wrapper">'; |
| 814 | $cff_content .= '<div id="cff" data-char="'.$title_limit.'"'; |
| 815 | |
| 816 | //Disable default CSS styles? |
| 817 | $cff_disable_styles = $atts['disablestyles']; |
| 818 | ( $cff_disable_styles == 'on' || $cff_disable_styles == 'true' || $cff_disable_styles == true ) ? $cff_disable_styles = true : $cff_disable_styles = false; |
| 819 | if( $atts[ 'disablestyles' ] === 'false' ) $cff_disable_styles = false; |
| 820 | |
| 821 | //If there's a class then add it here |
| 822 | if( !empty($cff_class) || !empty($cff_feed_height) || !$cff_disable_styles || $cff_feed_width_resp ) $cff_content .= ' class="'; |
| 823 | if( !empty($cff_class) ) $cff_content .= $cff_class . ' '; |
| 824 | if ( !empty($cff_feed_height) ) $cff_content .= 'cff-fixed-height '; |
| 825 | if ( $cff_feed_width_resp ) $cff_content .= 'cff-width-resp '; |
| 826 | if ( !$cff_disable_styles ) $cff_content .= 'cff-default-styles'; |
| 827 | if( !empty($cff_class) || !empty($cff_feed_height) || !$cff_disable_styles || $cff_feed_width_resp ) $cff_content .= '"'; |
| 828 | |
| 829 | $cff_content .= ' ' . $cff_feed_styles . '>'; |
| 830 | |
| 831 | //Add the page header to the inside of the top of feed |
| 832 | if ($cff_show_header && !$cff_header_outside) $cff_content .= $cff_header; |
| 833 | |
| 834 | //Add like box to the inside of the top of feed |
| 835 | if ($cff_like_box_position == 'top' && $cff_show_like_box && !$cff_like_box_outside) $cff_content .= $like_box; |
| 836 | //Limit var |
| 837 | $i = 0; |
| 838 | |
| 839 | //Define array for post items |
| 840 | $cff_posts_array = array(); |
| 841 | |
| 842 | //ALL POSTS |
| 843 | if (!$cff_events_only){ |
| 844 | |
| 845 | $cff_posts_json_url = 'https://graph.facebook.com/' . $page_id . '/' . $graph_query . '?fields=id,from,message,message_tags,story,story_tags,link,source,name,caption,description,type,status_type,object_id,created_time&access_token=' . $access_token . '&limit=' . $cff_post_limit . '&locale=' . $cff_locale . $cff_ssl; |
| 846 | |
| 847 | //Don't use caching if the cache time is set to zero |
| 848 | if ($cff_cache_time != 0){ |
| 849 | |
| 850 | //Create the transient name |
| 851 | //Split the Page ID in half and stick it together so we definitely have the beginning and end of it |
| 852 | $trans_page_id = substr($page_id, 0, 17) . substr($page_id, -16); |
| 853 | $transient_name = 'cff_' . substr($graph_query, 0, 1) . '_' . $trans_page_id . substr($cff_post_limit, 0, 3) . substr($show_posts_by, 0, 2); |
| 854 | //Limit to 45 chars max |
| 855 | $transient_name = substr($transient_name, 0, 45); |
| 856 | |
| 857 | //Get any existing copy of our transient data |
| 858 | if ( false === ( $posts_json = get_transient( $transient_name ) ) || $posts_json === null ) { |
| 859 | //Get the contents of the Facebook page |
| 860 | $posts_json = cff_fetchUrl($cff_posts_json_url); |
| 861 | |
| 862 | //Check whether any data is returned from the API. If it isn't then don't cache the error response and instead keep checking the API on every page load until data is returned. |
| 863 | $FBdata = json_decode($posts_json); |
| 864 | if( !empty($FBdata->data) ) { |
| 865 | //Cache the JSON |
| 866 | set_transient( $transient_name, $posts_json, $cache_seconds ); |
| 867 | } |
| 868 | } else { |
| 869 | $posts_json = get_transient( $transient_name ); |
| 870 | //If we can't find the transient then fall back to just getting the json from the api |
| 871 | if ($posts_json == false) $posts_json = cff_fetchUrl($cff_posts_json_url); |
| 872 | } |
| 873 | } else { |
| 874 | $posts_json = cff_fetchUrl($cff_posts_json_url); |
| 875 | } |
| 876 | |
| 877 | |
| 878 | //Interpret data with JSON |
| 879 | $FBdata = json_decode($posts_json); |
| 880 | |
| 881 | //If there's no data then show a pretty error message |
| 882 | if( empty($FBdata->data) ) { |
| 883 | $cff_content .= '<div class="cff-error-msg"><p>Unable to display Facebook posts.<br/><a href="javascript:void(0);" id="cff-show-error" onclick="cffShowError()">Show error</a>'; |
| 884 | $cff_content .= '<script type="text/javascript">function cffShowError() { document.getElementById("cff-error-reason").style.display = "block"; document.getElementById("cff-show-error").style.display = "none"; }</script>'; |
| 885 | $cff_content .= '</p><div id="cff-error-reason">'; |
| 886 | |
| 887 | if( isset($FBdata->error->message) ) $cff_content .= 'Error: ' . $FBdata->error->message; |
| 888 | if( isset($FBdata->error->type) ) $cff_content .= '<br />Type: ' . $FBdata->error->type; |
| 889 | if( isset($FBdata->error->code) ) $cff_content .= '<br />Code: ' . $FBdata->error->code; |
| 890 | if( isset($FBdata->error->error_subcode) ) $cff_content .= '<br />Subcode: ' . $FBdata->error->error_subcode; |
| 891 | |
| 892 | if( isset($FBdata->error_msg) ) $cff_content .= 'Error: ' . $FBdata->error_msg; |
| 893 | if( isset($FBdata->error_code) ) $cff_content .= '<br />Code: ' . $FBdata->error_code; |
| 894 | |
| 895 | if($FBdata == null) $cff_content .= 'Error: Server configuration issue'; |
| 896 | |
| 897 | if( empty($FBdata->error) && empty($FBdata->error_msg) && $FBdata !== null ) $cff_content .= 'Error: No posts available for this Facebook ID'; |
| 898 | |
| 899 | $cff_content .= '<br />Please refer to our <a href="http://smashballoon.com/custom-facebook-feed/docs/errors/" target="_blank">Error Message Reference</a>.'; |
| 900 | $cff_content .= '</div></div>'; //End .cff-error-msg and #cff-error-reason |
| 901 | $cff_content .= '</div></div>'; //End #cff and .cff-wrapper |
| 902 | |
| 903 | return $cff_content; |
| 904 | } |
| 905 | |
| 906 | //***STARTS POSTS LOOP*** |
| 907 | foreach ($FBdata->data as $news ) |
| 908 | { |
| 909 | //Explode News and Page ID's into 2 values |
| 910 | $PostID = ''; |
| 911 | $cff_post_id = ''; |
| 912 | if( isset($news->id) ){ |
| 913 | $cff_post_id = $news->id; |
| 914 | $PostID = explode("_", $cff_post_id); |
| 915 | } |
| 916 | |
| 917 | //Check the post type |
| 918 | $cff_post_type = $news->type; |
| 919 | if ($cff_post_type == 'link') { |
| 920 | isset($news->story) ? $story = $news->story : $story = ''; |
| 921 | //Check whether it's an event |
| 922 | $event_link_check = "facebook.com/events/"; |
| 923 | $event_link_check = stripos($news->link, $event_link_check); |
| 924 | if ( $event_link_check ) $cff_post_type = 'event'; |
| 925 | } |
| 926 | |
| 927 | //Should we show this post or not? |
| 928 | $cff_show_post = false; |
| 929 | switch ($cff_post_type) { |
| 930 | case 'link': |
| 931 | if ( $cff_show_links_type ) $cff_show_post = true; |
| 932 | break; |
| 933 | case 'event': |
| 934 | if ( $cff_show_event_type ) $cff_show_post = true; |
| 935 | break; |
| 936 | case 'video': |
| 937 | if ( $cff_show_video_type ) $cff_show_post = true; |
| 938 | break; |
| 939 | case 'swf': |
| 940 | if ( $cff_show_video_type ) $cff_show_post = true; |
| 941 | break; |
| 942 | case 'photo': |
| 943 | if ( $cff_show_photos_type ) $cff_show_post = true; |
| 944 | break; |
| 945 | case 'offer': |
| 946 | $cff_show_post = true; |
| 947 | break; |
| 948 | case 'status': |
| 949 | //Check whether it's a status (author comment or like) |
| 950 | if ( $cff_show_status_type && !empty($news->message) ) $cff_show_post = true; |
| 951 | break; |
| 952 | } |
| 953 | |
| 954 | |
| 955 | //ONLY show posts by others |
| 956 | if ( $cff_show_only_others ) { |
| 957 | //Get the numeric ID of the page |
| 958 | $page_object = cff_fetchUrl('https://graph.facebook.com/' . $page_id . '?fields=name,id&access_token=' . $access_token); |
| 959 | $page_object = json_decode($page_object); |
| 960 | $numeric_page_id = $page_object->id; |
| 961 | |
| 962 | //If the post author's ID is the same as the page ID then don't show the post |
| 963 | if ( $numeric_page_id == $news->from->id ) $cff_show_post = false; |
| 964 | } |
| 965 | |
| 966 | |
| 967 | //Is it a duplicate post? |
| 968 | if (!isset($prev_post_message)) $prev_post_message = ''; |
| 969 | if (!isset($prev_post_link)) $prev_post_link = ''; |
| 970 | if (!isset($prev_post_description)) $prev_post_description = ''; |
| 971 | isset($news->message) ? $pm = $news->message : $pm = ''; |
| 972 | isset($news->link) ? $pl = $news->link : $pl = ''; |
| 973 | isset($news->description) ? $pd = $news->description : $pd = ''; |
| 974 | |
| 975 | if ( ($prev_post_message == $pm) && ($prev_post_link == $pl) && ($prev_post_description == $pd) ) $cff_show_post = false; |
| 976 | |
| 977 | //Offset. If the post index ($i) is less than the offset then don't show the post |
| 978 | if( intval($i) < intval($atts['offset']) ){ |
| 979 | $cff_show_post = false; |
| 980 | $i++; |
| 981 | } |
| 982 | |
| 983 | //Check post type and display post if selected |
| 984 | if ( $cff_show_post ) { |
| 985 | //If it isn't then create the post |
| 986 | //Only create posts for the amount of posts specified |
| 987 | if( intval($atts['offset']) > 0 ){ |
| 988 | //If offset is being used then stop after showing the number of posts + the offset |
| 989 | if ( $i == (intval($show_posts) + intval($atts['offset'])) ) break; |
| 990 | } else { |
| 991 | //Else just stop after the number of posts to be displayed is reached |
| 992 | if ( $i == $show_posts ) break; |
| 993 | } |
| 994 | $i++; |
| 995 | //********************************// |
| 996 | //***COMPILE SECTION VARIABLES***// |
| 997 | //********************************// |
| 998 | //Set the post link |
| 999 | isset($news->link) ? $link = htmlspecialchars($news->link) : $link = ''; |
| 1000 | //Is it a shared album? |
| 1001 | $shared_album_string = 'shared an album:'; |
| 1002 | isset($news->story) ? $story = $news->story : $story = ''; |
| 1003 | $shared_album = stripos($story, $shared_album_string); |
| 1004 | if ( $shared_album ) { |
| 1005 | $link = str_replace('photo.php?','media/set/?',$link); |
| 1006 | } |
| 1007 | |
| 1008 | //Check the post type |
| 1009 | isset($news->type) ? $cff_post_type = $news->type : $cff_post_type = ''; |
| 1010 | if ($cff_post_type == 'link') { |
| 1011 | isset($news->story) ? $story = $news->story : $story = ''; |
| 1012 | //Check whether it's an event |
| 1013 | $event_link_check = "facebook.com/events/"; |
| 1014 | //Make sure URL doesn't include 'permalink' as that indicates someone else sharing a post from within an event (eg: https://www.facebook.com/events/617323338414282/permalink/617324268414189/) and the event ID is then not retrieved properly from the event URL as it's formatted like so: facebook.com/events/EVENT_ID/permalink/POST_ID |
| 1015 | $event_link_check = stripos($news->link, $event_link_check); |
| 1016 | $event_link_check_2 = stripos($news->link, "permalink/"); |
| 1017 | if ( $event_link_check && !$event_link_check_2 ) $cff_post_type = 'event'; |
| 1018 | } |
| 1019 | |
| 1020 | //If it's an event then check whether the URL contains facebook.com |
| 1021 | if(isset($news->link)){ |
| 1022 | if( stripos($news->link, "events/") && $cff_post_type == 'event' ){ |
| 1023 | //Facebook changed the event link from absolute to relative, and so if the link isn't absolute then add facebook.com to front |
| 1024 | ( stripos($link, 'facebook.com') ) ? $link = $link : $link = 'https://facebook.com' . $link; |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | //Is it an album? |
| 1029 | $cff_album = false; |
| 1030 | $num_photos = 0; |
| 1031 | |
| 1032 | if( isset($news->status_type) ){ |
| 1033 | if( $news->status_type == 'added_photos' ){ |
| 1034 | //Check 'story' to see whether it contains a number |
| 1035 | (isset($news->story)) ? $str = $news->story : $str = ''; |
| 1036 | |
| 1037 | //Only matches number with a space after them |
| 1038 | preg_match('!\d+ !', $str, $matches); |
| 1039 | |
| 1040 | |
| 1041 | (isset($matches[0])) ? $num_photos = $matches[0] : $num_photos = 0; |
| 1042 | |
| 1043 | //If the story contains a number... |
| 1044 | if ( $num_photos > 1 ) { |
| 1045 | |
| 1046 | //... and the link is to an album then it most likely has photo attachments |
| 1047 | $albumLinkArr1 = explode('photos/a.', $link); |
| 1048 | if( isset($albumLinkArr1[1]) ) $albumLinkArr2 = explode('.', $albumLinkArr1[1]); |
| 1049 | |
| 1050 | //If it has an album link then set the post type to be album |
| 1051 | if( isset($albumLinkArr1[1]) ){ |
| 1052 | |
| 1053 | $cff_album = true; |
| 1054 | |
| 1055 | //Change the Post ID to be to the post about adding photos to the album |
| 1056 | $cff_post_id = $PostID[0] . '_' . $albumLinkArr2[0]; |
| 1057 | |
| 1058 | //Link to the album instead of the photo |
| 1059 | $album_link = str_replace('photo.php?','media/set/?',$link); |
| 1060 | $link = "https://www.facebook.com/" . $page_id . "/posts/" . $PostID[1]; |
| 1061 | |
| 1062 | //If the album link is a new format then link it to the post |
| 1063 | $album_link_check = 'media/set/?'; |
| 1064 | if( stripos($album_link, $album_link_check) !== true ) $album_link = $link; |
| 1065 | |
| 1066 | } |
| 1067 | |
| 1068 | } |
| 1069 | } |
| 1070 | } |
| 1071 | |
| 1072 | //If there's no link provided then link to either the Facebook page or the individual status |
| 1073 | if (empty($news->link)) { |
| 1074 | if ($cff_link_to_timeline == true){ |
| 1075 | //Link to page |
| 1076 | $link = 'http://facebook.com/' . $page_id; |
| 1077 | } else { |
| 1078 | //Link to status |
| 1079 | $link = "https://www.facebook.com/" . $page_id . "/posts/" . $PostID[1]; |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | //DATE |
| 1084 | $cff_date_formatting = $atts[ 'dateformat' ]; |
| 1085 | $cff_date_custom = $atts[ 'datecustom' ]; |
| 1086 | |
| 1087 | $post_time = $news->created_time; |
| 1088 | $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_translate_strings) . ' ' . $cff_date_after; |
| 1089 | if($cff_date_position == 'below' || (!$cff_show_author && $cff_date_position == 'author') ) $cff_date .= '<span class="cff-date-dot"> · </span>'; |
| 1090 | $cff_date .= '</p>'; |
| 1091 | |
| 1092 | //POST AUTHOR |
| 1093 | $cff_author = '<div class="cff-author">'; |
| 1094 | |
| 1095 | //Author text |
| 1096 | $cff_author .= '<a href="https://facebook.com/' . $news->from->id . '" '.$target.$cff_nofollow.' title="'.$news->from->name.' on Facebook" '.$cff_author_styles.'><div class="cff-author-text">'; |
| 1097 | |
| 1098 | if($cff_show_date && $cff_date_position !== 'above' && $cff_date_position !== 'below'){ |
| 1099 | $cff_author .= '<p class="cff-page-name cff-author-date" '.$cff_author_styles.'>'.$news->from->name.'</p>'; |
| 1100 | $cff_author .= $cff_date; |
| 1101 | } else { |
| 1102 | $cff_author .= '<span class="cff-page-name">'.$news->from->name.'</span>'; |
| 1103 | } |
| 1104 | |
| 1105 | $cff_author .= '</div>'; |
| 1106 | |
| 1107 | //Author image |
| 1108 | //Set the author image as a variable. If it already exists then don't query the api for it again. |
| 1109 | $cff_author_img_var = '$cff_author_img_' . $news->from->id; |
| 1110 | if ( !isset($$cff_author_img_var) ) $$cff_author_img_var = 'https://graph.facebook.com/' . $news->from->id . '/picture?type=square'; |
| 1111 | $cff_author .= '<div class="cff-author-img"><img src="'.$$cff_author_img_var.'" title="'.$news->from->name.'" alt="'.$news->from->name.'" width=40 height=40></div>'; |
| 1112 | |
| 1113 | $cff_author .= '</a></div>'; //End .cff-author |
| 1114 | |
| 1115 | |
| 1116 | //POST TEXT |
| 1117 | $cff_translate_photos_text = $atts['photostext']; |
| 1118 | if (!isset($cff_translate_photos_text) || empty($cff_translate_photos_text)) $cff_translate_photos_text = 'photos'; |
| 1119 | $cff_post_text = '<' . $cff_title_format . ' class="cff-post-text" ' . $cff_title_styles . '>'; |
| 1120 | |
| 1121 | //Start HTML for post text |
| 1122 | $cff_post_text .= '<span class="cff-text" data-color="'.$cff_posttext_link_color.'">'; |
| 1123 | if ($cff_title_link){ |
| 1124 | //Link to the Facebook post if it's a link or a video |
| 1125 | ($cff_post_type == 'link' || $cff_post_type == 'video') ? $text_link = "https://www.facebook.com/" . $page_id . "/posts/" . $PostID[1] : $text_link = $link; |
| 1126 | |
| 1127 | $cff_post_text .= '<a class="cff-post-text-link" '.$cff_title_styles.' href="'.$text_link.'" '.$target.$cff_nofollow.'>'; |
| 1128 | } |
| 1129 | |
| 1130 | //Which content should we use? |
| 1131 | $cff_post_text_type = ''; |
| 1132 | $post_text = ''; |
| 1133 | //Use the story |
| 1134 | if (!empty($news->story)) { |
| 1135 | $post_text = htmlspecialchars($news->story); |
| 1136 | $cff_post_text_type = 'story'; |
| 1137 | } |
| 1138 | //Use the message |
| 1139 | if (!empty($news->message)) { |
| 1140 | $post_text = htmlspecialchars($news->message); |
| 1141 | $cff_post_text_type = 'message'; |
| 1142 | } |
| 1143 | //Use the name |
| 1144 | if (!empty($news->name) && empty($news->story) && empty($news->message)) { |
| 1145 | $post_text = htmlspecialchars($news->name); |
| 1146 | $cff_post_text_type = 'name'; |
| 1147 | } |
| 1148 | |
| 1149 | |
| 1150 | //MESSAGE TAGS |
| 1151 | $cff_post_tags = $atts[ 'posttags' ]; |
| 1152 | //If the post tags option doesn't exist yet (ie. on plugin update) then set them as true |
| 1153 | if ( !array_key_exists( 'cff_post_tags', $options ) ) $cff_post_tags = true; |
| 1154 | |
| 1155 | //Add message and story tags if there are any and the post text is the message or the story |
| 1156 | 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){ |
| 1157 | //Use message_tags or story_tags? |
| 1158 | ( isset($news->message_tags) )? $text_tags = $news->message_tags : $text_tags = $news->story_tags; |
| 1159 | |
| 1160 | //If message tags and message is being used as the post text, or same with story. This stops story tags being used to replace the message inadvertently. |
| 1161 | if( ( $cff_post_text_type == 'message' && isset($news->message_tags) ) || ( $cff_post_text_type == 'story' && !isset($news->message_tags) ) ) { |
| 1162 | |
| 1163 | //Does the Post Text contain any html tags? - the & symbol is the best indicator of this |
| 1164 | $cff_html_check_array = array('<', '’', '“', '"', '&', '>>', '>'); |
| 1165 | |
| 1166 | //always use the text replace method |
| 1167 | if( cff_stripos_arr($post_text, $cff_html_check_array) !== false ) { |
| 1168 | //Loop through the tags |
| 1169 | foreach($text_tags as $message_tag ) { |
| 1170 | |
| 1171 | ( isset($message_tag->id) ) ? $message_tag = $message_tag : $message_tag = $message_tag[0]; |
| 1172 | |
| 1173 | $tag_name = $message_tag->name; |
| 1174 | $tag_link = '<a href="http://facebook.com/' . $message_tag->id . '" style="color: #'.$cff_posttext_link_color.';" target="_blank">' . $message_tag->name . '</a>'; |
| 1175 | |
| 1176 | $post_text = str_replace($tag_name, $tag_link, $post_text); |
| 1177 | } |
| 1178 | |
| 1179 | } else { |
| 1180 | //If it doesn't contain HTMl tags then use the offset to replace message tags |
| 1181 | $message_tags_arr = array(); |
| 1182 | |
| 1183 | $i = 0; |
| 1184 | foreach($text_tags as $message_tag ) { |
| 1185 | $i++; |
| 1186 | |
| 1187 | ( isset($message_tag->id) ) ? $message_tag = $message_tag : $message_tag = $message_tag[0]; |
| 1188 | |
| 1189 | $message_tags_arr = cff_array_push_assoc( |
| 1190 | $message_tags_arr, |
| 1191 | $i, |
| 1192 | array( |
| 1193 | 'id' => $message_tag->id, |
| 1194 | 'name' => $message_tag->name, |
| 1195 | 'type' => isset($message_tag->type) ? $message_tag->type : '', |
| 1196 | 'offset' => $message_tag->offset, |
| 1197 | 'length' => $message_tag->length |
| 1198 | ) |
| 1199 | ); |
| 1200 | } |
| 1201 | |
| 1202 | for($i = count($message_tags_arr); $i >= 1; $i--) { |
| 1203 | |
| 1204 | //If the name is blank (aka the story tag doesn't work properly) then don't use it |
| 1205 | if( $message_tags_arr[$i]['name'] !== '' ) { |
| 1206 | |
| 1207 | if( $cff_post_text_type == 'story' && $message_tags_arr[$i]['type'] == 'event' ){ |
| 1208 | //Don't use the story tag in this case otherwise it changes '__ created an event' to '__ created an Name Of Event' |
| 1209 | } else { |
| 1210 | $b = '<a href="http://facebook.com/' . $message_tags_arr[$i]['id'] . '">' . $message_tags_arr[$i]['name'] . '</a>'; |
| 1211 | $c = $message_tags_arr[$i]['offset']; |
| 1212 | $d = $message_tags_arr[$i]['length']; |
| 1213 | |
| 1214 | $post_text = cff_mb_substr_replace( $post_text, $b, $c, $d); |
| 1215 | } |
| 1216 | |
| 1217 | } |
| 1218 | |
| 1219 | } |
| 1220 | |
| 1221 | } // end if/else |
| 1222 | |
| 1223 | } // end message check |
| 1224 | |
| 1225 | } //END MESSAGE TAGS |
| 1226 | |
| 1227 | //Replace line breaks in text (needed for IE8) |
| 1228 | $post_text = preg_replace("/\r\n|\r|\n/",'<br/>', $post_text); |
| 1229 | |
| 1230 | //If the text is wrapped in a link then don't hyperlink any text within |
| 1231 | if ($cff_title_link) { |
| 1232 | //Wrap links in a span so we can break the text if it's too long |
| 1233 | $cff_post_text .= cff_wrap_span( $post_text ) . ' '; |
| 1234 | } else { |
| 1235 | //Don't use htmlspecialchars for post_text as it's added above so that it doesn't mess up the message_tag offsets |
| 1236 | $cff_post_text .= cff_autolink( $post_text ) . ' '; |
| 1237 | } |
| 1238 | |
| 1239 | if ($cff_title_link) $cff_post_text .= '</a>'; |
| 1240 | $cff_post_text .= '</span>'; |
| 1241 | //'See More' link |
| 1242 | $cff_post_text .= '<span class="cff-expand">... <a href="#" style="color: #'.$cff_posttext_link_color.'"><span class="cff-more">' . $cff_see_more_text . '</span><span class="cff-less">' . $cff_see_less_text . '</span></a></span>'; |
| 1243 | $cff_post_text .= '</' . $cff_title_format . '>'; |
| 1244 | |
| 1245 | //DESCRIPTION |
| 1246 | $cff_description = ''; |
| 1247 | //Use the description if it's available and the post type isn't set to offer (offer description isn't useful) |
| 1248 | if ( ( !empty($news->description) || !empty($news->caption) ) && $cff_post_type != 'offer') { |
| 1249 | |
| 1250 | $description_text = ''; |
| 1251 | if ( !empty($news->description) ) { |
| 1252 | $description_text = $news->description; |
| 1253 | } else { |
| 1254 | $description_text = $news->caption; |
| 1255 | } |
| 1256 | |
| 1257 | if (!empty($body_limit)) { |
| 1258 | if (strlen($description_text) > $body_limit) $description_text = substr($description_text, 0, $body_limit) . '...'; |
| 1259 | } |
| 1260 | $cff_description .= '<p class="cff-post-desc" '.$cff_body_styles.'><span>' . cff_autolink( htmlspecialchars($description_text), $link_color=$cff_posttext_link_color) . ' </span></p>'; |
| 1261 | |
| 1262 | //If the post text and description/caption are the same then don't show the description |
| 1263 | if($post_text == $description_text) $cff_description = ''; |
| 1264 | |
| 1265 | if( $cff_post_type == 'event' ) $cff_description = ''; |
| 1266 | } |
| 1267 | |
| 1268 | //LINK |
| 1269 | $cff_shared_link = ''; |
| 1270 | //Display shared link |
| 1271 | if ($cff_post_type == 'link') { |
| 1272 | $cff_shared_link .= '<div class="cff-shared-link'; |
| 1273 | if($cff_disable_link_box) $cff_shared_link .= ' cff-no-styles"'; |
| 1274 | if(!$cff_disable_link_box) $cff_shared_link .= '" ' . $cff_link_box_styles; |
| 1275 | $cff_shared_link .= '>'; |
| 1276 | |
| 1277 | //Display link name and description |
| 1278 | if (!empty($news->description)) { |
| 1279 | $cff_shared_link .= '<div class="cff-text-link '; |
| 1280 | $cff_shared_link .= 'cff-no-image'; |
| 1281 | $cff_shared_link .= '">'; |
| 1282 | //The link title: |
| 1283 | $cff_shared_link .= '<'.$cff_link_title_format.' class="cff-link-title" '.$cff_link_title_styles.'><a href="'.$link.'" '.$target.$cff_nofollow.' style="color:#' . $cff_link_title_color . ';">'. $news->name . '</a></'.$cff_link_title_format.'>'; |
| 1284 | //The link source: |
| 1285 | (!empty($news->caption)) ? $cff_link_caption = $news->caption : $cff_link_caption = ''; |
| 1286 | if(!empty($cff_link_caption)) $cff_shared_link .= '<p class="cff-link-caption" style="color:#' . str_replace('#', '', $cff_link_url_color) . ';">'.$cff_link_caption.'</p>'; |
| 1287 | if ($cff_show_desc) { |
| 1288 | if( $description_text != $cff_link_caption ) $cff_shared_link .= $cff_description; |
| 1289 | } |
| 1290 | $cff_shared_link .= '</div>'; |
| 1291 | } |
| 1292 | |
| 1293 | $cff_shared_link .= '</div>'; |
| 1294 | } |
| 1295 | |
| 1296 | //EVENT |
| 1297 | $cff_event = ''; |
| 1298 | if ($cff_show_event_title || $cff_show_event_details) { |
| 1299 | //Check for media |
| 1300 | if ($cff_post_type == 'event') { |
| 1301 | |
| 1302 | //Get the event id from the event URL. eg: http://www.facebook.com/events/123451234512345/ |
| 1303 | $event_url = parse_url($link); |
| 1304 | $url_parts = explode('/', $event_url['path']); |
| 1305 | //Get the id from the parts |
| 1306 | $eventID = $url_parts[count($url_parts)-2]; |
| 1307 | |
| 1308 | //Facebook changed the event link from absolute to relative, and so if the link isn't absolute then add facebook.com to front |
| 1309 | ( stripos($link, 'facebook.com') ) ? $link = $link : $link = 'https://facebook.com' . $link; |
| 1310 | |
| 1311 | //Get the contents of the event using the WP HTTP API |
| 1312 | $event_json_url = 'https://graph.facebook.com/'.$eventID.'?access_token=' . $access_token . $cff_ssl; |
| 1313 | |
| 1314 | //Don't use caching if the cache time is set to zero |
| 1315 | if ($cff_cache_time != 0){ |
| 1316 | // Get any existing copy of our transient data |
| 1317 | $transient_name = 'cff_tle_' . $eventID; |
| 1318 | $transient_name = substr($transient_name, 0, 45); |
| 1319 | |
| 1320 | if ( false === ( $event_json = get_transient( $transient_name ) ) || $event_json === null ) { |
| 1321 | //Get the contents of the Facebook page |
| 1322 | $event_json = cff_fetchUrl($event_json_url); |
| 1323 | //Cache the JSON |
| 1324 | set_transient( $transient_name, $event_json, $cache_seconds ); |
| 1325 | } else { |
| 1326 | $event_json = get_transient( $transient_name ); |
| 1327 | //If we can't find the transient then fall back to just getting the json from the api |
| 1328 | if ($event_json == false) $event_json = cff_fetchUrl($event_json_url); |
| 1329 | } |
| 1330 | } else { |
| 1331 | $event_json = cff_fetchUrl($event_json_url); |
| 1332 | } |
| 1333 | |
| 1334 | //Interpret data with JSON |
| 1335 | $event_object = json_decode($event_json); |
| 1336 | |
| 1337 | //Event date |
| 1338 | $event_time = $event_object->start_time; |
| 1339 | isset($event_object->end_time) ? $event_end_time = ' - ' . cff_eventdate(strtotime($event_object->end_time), $cff_event_date_formatting, $cff_event_date_custom) : $event_end_time = ''; |
| 1340 | //If timezone migration is enabled then remove last 5 characters |
| 1341 | if ( strlen($event_time) == 24 ) $event_time = substr($event_time, 0, -5); |
| 1342 | 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) . $event_end_time.'</p>'; |
| 1343 | |
| 1344 | |
| 1345 | //EVENT |
| 1346 | //Display the event details |
| 1347 | $cff_event .= '<div class="cff-details">'; |
| 1348 | //show event date above title |
| 1349 | if ($cff_event_date_position == 'above') $cff_event .= $cff_event_date; |
| 1350 | //Show event title |
| 1351 | if ($cff_show_event_title && !empty($event_object->name)) { |
| 1352 | if ($cff_event_title_link) $cff_event .= '<a href="'.$link.'" '.$target.$cff_nofollow.'>'; |
| 1353 | $cff_event .= '<' . $cff_event_title_format . ' ' . $cff_event_title_styles . '>' . $event_object->name . '</' . $cff_event_title_format . '>'; |
| 1354 | if ($cff_event_title_link) $cff_event .= '</a>'; |
| 1355 | } |
| 1356 | //show event date below title |
| 1357 | if ($cff_event_date_position !== 'above') $cff_event .= $cff_event_date; |
| 1358 | //Show event details |
| 1359 | if ($cff_show_event_details){ |
| 1360 | //Location |
| 1361 | if (!empty($event_object->location)) $cff_event .= '<p class="cff-where" ' . $cff_event_details_styles . '>' . $event_object->location . '</p>'; |
| 1362 | //Description |
| 1363 | if (!empty($event_object->description)){ |
| 1364 | $description = $event_object->description; |
| 1365 | if (!empty($body_limit)) { |
| 1366 | if (strlen($description) > $body_limit) $description = substr($description, 0, $body_limit) . '...'; |
| 1367 | } |
| 1368 | $cff_event .= '<p class="cff-info" ' . $cff_event_details_styles . '>' . cff_autolink($description, $link_color=str_replace('#', '', $cff_event_link_color) ) . '</p>'; |
| 1369 | } |
| 1370 | } |
| 1371 | $cff_event .= '</div>'; |
| 1372 | |
| 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | /* VIDEO */ |
| 1377 | |
| 1378 | //Check to see whether it's an embedded video so that we can show the name above the post text if necessary |
| 1379 | $cff_is_video_embed = false; |
| 1380 | if ($news->type == 'video'){ |
| 1381 | $url = $news->source; |
| 1382 | //Embeddable video strings |
| 1383 | $youtube = 'youtube'; |
| 1384 | $youtu = 'youtu'; |
| 1385 | $vimeo = 'vimeo'; |
| 1386 | $youtubeembed = 'youtube.com/embed'; |
| 1387 | //Check whether it's a youtube video |
| 1388 | $youtube = stripos($url, $youtube); |
| 1389 | $youtu = stripos($url, $youtu); |
| 1390 | $youtubeembed = stripos($url, $youtubeembed); |
| 1391 | //Check whether it's a youtube video |
| 1392 | if($youtube || $youtu || $youtubeembed || (stripos($url, $vimeo) !== false)) { |
| 1393 | $cff_is_video_embed = true; |
| 1394 | } |
| 1395 | } |
| 1396 | |
| 1397 | |
| 1398 | $cff_media = ''; |
| 1399 | if ($news->type == 'video') { |
| 1400 | //Add the name to the description if it's a video embed |
| 1401 | if($cff_is_video_embed) { |
| 1402 | isset($news->name) ? $video_name = $news->name : $video_name = $link; |
| 1403 | isset($news->description) ? $description_text = $news->description : $description_text = ''; |
| 1404 | //Add the 'cff-shared-link' class so that embedded videos display in a box |
| 1405 | $cff_description = '<div class="cff-desc-wrap cff-shared-link '; |
| 1406 | if (empty($picture)) $cff_description .= 'cff-no-image'; |
| 1407 | if($cff_disable_link_box) $cff_description .= ' cff-no-styles"'; |
| 1408 | if(!$cff_disable_link_box) $cff_description .= '" ' . $cff_link_box_styles; |
| 1409 | $cff_description .= '>'; |
| 1410 | |
| 1411 | if( isset($news->name) ) $cff_description .= '<'.$cff_link_title_format.' class="cff-link-title" '.$cff_link_title_styles.'><a href="'.$link.'" '.$target.$cff_nofollow.' style="color:#' . $cff_link_title_color . ';">'. $news->name . '</a></'.$cff_link_title_format.'>'; |
| 1412 | |
| 1413 | if (!empty($body_limit)) { |
| 1414 | if (strlen($description_text) > $body_limit) $description_text = substr($description_text, 0, $body_limit) . '...'; |
| 1415 | } |
| 1416 | |
| 1417 | $cff_description .= '<p class="cff-post-desc" '.$cff_body_styles.'><span>' . cff_autolink( htmlspecialchars($description_text) ) . '</span></p></div>'; |
| 1418 | } else { |
| 1419 | isset($news->name) ? $video_name = $news->name : $video_name = $link; |
| 1420 | if( isset($news->name) ) $cff_description .= '<'.$cff_link_title_format.' class="cff-link-title" '.$cff_link_title_styles.'><a href="'.$link.'" '.$target.$cff_nofollow.' style="color:#' . $cff_link_title_color . ';">'. $news->name . '</a></'.$cff_link_title_format.'>'; |
| 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | |
| 1425 | //Display the link to the Facebook post or external link |
| 1426 | $cff_link = ''; |
| 1427 | //Default link |
| 1428 | $cff_viewpost_class = 'cff-viewpost-facebook'; |
| 1429 | if ($cff_facebook_link_text == '') $cff_facebook_link_text = 'View on Facebook'; |
| 1430 | $link_text = $cff_facebook_link_text; |
| 1431 | |
| 1432 | //Link to the Facebook post if it's a link or a video |
| 1433 | if($cff_post_type == 'link' || $cff_post_type == 'video') $link = "https://www.facebook.com/" . $page_id . "/posts/" . $PostID[1]; |
| 1434 | |
| 1435 | //Social media sharing URLs |
| 1436 | $cff_share_facebook = 'https://www.facebook.com/sharer/sharer.php?u=' . urlencode($link); |
| 1437 | $cff_share_twitter = 'https://twitter.com/intent/tweet?text=' . urlencode($link); |
| 1438 | $cff_share_google = 'https://plus.google.com/share?url=' . urlencode($link); |
| 1439 | $cff_share_linkedin = 'https://www.linkedin.com/shareArticle?mini=true&url=' . urlencode($link) . '&title=' . rawurlencode( strip_tags($cff_post_text) ); |
| 1440 | $cff_share_email = 'mailto:?subject=Facebook&body=' . urlencode($link) . '%20-%20' . rawurlencode( strip_tags($cff_post_text) ); |
| 1441 | |
| 1442 | //If it's a shared post then change the link to use the Post ID so that it links to the shared post and not the original post that's being shared |
| 1443 | if( isset($news->status_type) ){ |
| 1444 | if( $news->status_type == 'shared_story' ) $link = "https://www.facebook.com/" . $cff_post_id; |
| 1445 | } |
| 1446 | |
| 1447 | //If it's an offer post then change the text |
| 1448 | if ($cff_post_type == 'offer') $link_text = 'View Offer'; |
| 1449 | |
| 1450 | //Create post action links HTML |
| 1451 | $cff_link = ''; |
| 1452 | if($cff_show_facebook_link || $cff_show_facebook_share){ |
| 1453 | $cff_link .= '<div class="cff-post-links">'; |
| 1454 | |
| 1455 | //View on Facebook link |
| 1456 | if($cff_show_facebook_link) $cff_link .= '<a class="' . $cff_viewpost_class . '" href="' . $link . '" title="' . $link_text . '" ' . $target . $cff_nofollow . ' ' . $cff_link_styles . '>' . $link_text . '</a>'; |
| 1457 | |
| 1458 | //Share link |
| 1459 | if($cff_show_facebook_share){ |
| 1460 | $cff_link .= '<div class="cff-share-container">'; |
| 1461 | //Only show separating dot if both links are enabled |
| 1462 | if($cff_show_facebook_link) $cff_link .= '<span class="cff-dot" ' . $cff_link_styles . '>·</span>'; |
| 1463 | $cff_link .= '<a class="cff-share-link" href="javascript:void(0);" title="' . $cff_facebook_share_text . '" ' . $cff_link_styles . '>' . $cff_facebook_share_text . '</a>'; |
| 1464 | $cff_link .= "<p class='cff-share-tooltip'><a href='".$cff_share_facebook."' target='_blank' class='cff-facebook-icon'><i class='fa fa-facebook-square'></i></a><a href='".$cff_share_twitter."' target='_blank' class='cff-twitter-icon'><i class='fa fa-twitter'></i></a><a href='".$cff_share_google."' target='_blank' class='cff-google-icon'><i class='fa fa-google-plus'></i></a><a href='".$cff_share_linkedin."' target='_blank' class='cff-linkedin-icon'><i class='fa fa-linkedin'></i></a><a href='".$cff_share_email."' target='_blank' class='cff-email-icon'><i class='fa fa-envelope'></i></a><i class='fa fa-play fa-rotate-90'></i></p></div>"; |
| 1465 | } |
| 1466 | |
| 1467 | $cff_link .= '</div>'; |
| 1468 | } |
| 1469 | |
| 1470 | |
| 1471 | /* MEDIA LINK */ |
| 1472 | $cff_translate_photo_text = $atts['phototext']; |
| 1473 | if (!isset($cff_translate_photo_text) || empty($cff_translate_photo_text)) $cff_translate_photo_text = 'Photo'; |
| 1474 | $cff_translate_video_text = $atts['videotext']; |
| 1475 | if (!isset($cff_translate_video_text) || empty($cff_translate_video_text)) $cff_translate_video_text = 'Video'; |
| 1476 | |
| 1477 | $cff_media_link = ''; |
| 1478 | if( $cff_show_media_link && ($cff_post_type == 'photo' || $cff_post_type == 'video') ){ |
| 1479 | $cff_media_link .= '<p class="cff-media-link"><a href="'.$link.'" '.$target.' style="color: #'.$cff_posttext_link_color.';"><i style="padding-right: 5px;" class="fa fa-'; |
| 1480 | if($cff_post_type == 'photo') $cff_media_link .= 'picture-o"></i>'. $cff_translate_photo_text; |
| 1481 | // if($cff_post_type == 'video') $cff_media_link .= 'file-video-o'; |
| 1482 | if($cff_post_type == 'video') $cff_media_link .= 'video-camera"></i>'. $cff_translate_video_text; |
| 1483 | $cff_media_link .= '</a></p>'; |
| 1484 | } |
| 1485 | |
| 1486 | |
| 1487 | //**************************// |
| 1488 | //***CREATE THE POST HTML***// |
| 1489 | //**************************// |
| 1490 | //Start the container |
| 1491 | $cff_post_item = '<div class="cff-item '; |
| 1492 | if ($cff_post_type == 'link') $cff_post_item .= 'cff-link-item'; |
| 1493 | if ($cff_post_type == 'event') $cff_post_item .= 'cff-timeline-event'; |
| 1494 | if ($cff_post_type == 'photo') $cff_post_item .= 'cff-photo-post'; |
| 1495 | if ($cff_post_type == 'video') $cff_post_item .= 'cff-video-post'; |
| 1496 | if ($cff_post_type == 'swf') $cff_post_item .= 'cff-swf-post'; |
| 1497 | if ($cff_post_type == 'status') $cff_post_item .= 'cff-status-post'; |
| 1498 | if ($cff_post_type == 'offer') $cff_post_item .= 'cff-offer-post'; |
| 1499 | if ($cff_album) $cff_post_item .= ' cff-album'; |
| 1500 | if ($cff_post_bg_color_check) $cff_post_item .= ' cff-box'; |
| 1501 | $cff_post_item .= ' author-'. cff_to_slug($news->from->name) .'" id="cff_'. $cff_post_id .'" ' . $cff_item_styles . '>'; |
| 1502 | |
| 1503 | //POST AUTHOR |
| 1504 | if($cff_show_author) $cff_post_item .= $cff_author; |
| 1505 | //DATE ABOVE |
| 1506 | if ($cff_show_date && $cff_date_position == 'above') $cff_post_item .= $cff_date; |
| 1507 | //POST TEXT |
| 1508 | if($cff_show_text) $cff_post_item .= $cff_post_text; |
| 1509 | |
| 1510 | //DESCRIPTION |
| 1511 | if($cff_show_desc && $cff_post_type != 'offer' && $cff_post_type != 'link') $cff_post_item .= $cff_description; |
| 1512 | //LINK |
| 1513 | if($cff_show_shared_links) $cff_post_item .= $cff_shared_link; |
| 1514 | //DATE BELOW |
| 1515 | if ( (!$cff_show_author && $cff_date_position == 'author') || $cff_show_date && $cff_date_position == 'below') { |
| 1516 | if($cff_show_date && $cff_post_type !== 'event') $cff_post_item .= $cff_date; |
| 1517 | } |
| 1518 | //EVENT |
| 1519 | if($cff_show_event_title || $cff_show_event_details) $cff_post_item .= $cff_event; |
| 1520 | //DATE BELOW (only for Event posts) |
| 1521 | if ( (!$cff_show_author && $cff_date_position == 'author') || $cff_show_date && $cff_date_position == 'below') { |
| 1522 | if($cff_show_date && $cff_post_type == 'event') $cff_post_item .= $cff_date; |
| 1523 | } |
| 1524 | |
| 1525 | //MEDIA LINK |
| 1526 | if($cff_show_media_link) $cff_post_item .= $cff_media_link; |
| 1527 | //VIEW ON FACEBOOK LINK |
| 1528 | if($cff_show_link) $cff_post_item .= $cff_link; |
| 1529 | |
| 1530 | //End the post item |
| 1531 | $cff_post_item .= '</div>'; |
| 1532 | |
| 1533 | //PUSH TO ARRAY |
| 1534 | if(!$cff_is_group){ |
| 1535 | $cff_posts_array = cff_array_push_assoc($cff_posts_array, strtotime($post_time), $cff_post_item); |
| 1536 | } else { |
| 1537 | $cff_posts_array = cff_array_push_assoc($cff_posts_array, $i, $cff_post_item); |
| 1538 | } |
| 1539 | |
| 1540 | } // End post type check |
| 1541 | |
| 1542 | if (isset($news->message)) $prev_post_message = $news->message; |
| 1543 | if (isset($news->link)) $prev_post_link = $news->link; |
| 1544 | if (isset($news->description)) $prev_post_description = $news->description; |
| 1545 | |
| 1546 | } // End the loop |
| 1547 | |
| 1548 | //Sort the array in reverse order (newest first) |
| 1549 | if(!$cff_is_group) krsort($cff_posts_array); |
| 1550 | |
| 1551 | } // End ALL POSTS |
| 1552 | |
| 1553 | |
| 1554 | //Output the posts array |
| 1555 | $p = 0; |
| 1556 | foreach ($cff_posts_array as $post ) { |
| 1557 | if ( $p == $show_posts ) break; |
| 1558 | $cff_content .= $post; |
| 1559 | $p++; |
| 1560 | } |
| 1561 | |
| 1562 | //Reset the timezone |
| 1563 | date_default_timezone_set( $cff_orig_timezone ); |
| 1564 | //Add the Like Box inside |
| 1565 | if ($cff_like_box_position == 'bottom' && $cff_show_like_box && !$cff_like_box_outside) $cff_content .= $like_box; |
| 1566 | /* Credit link */ |
| 1567 | $cff_show_credit = $atts['credit']; |
| 1568 | ($cff_show_credit == 'true' || $cff_show_credit == 'on') ? $cff_show_credit = true : $cff_show_credit = false; |
| 1569 | |
| 1570 | if($cff_show_credit) $cff_content .= '<p class="cff-credit"><a href="https://smashballoon.com/custom-facebook-feed/" target="_blank" style="color: #'.$link_color=$cff_posttext_link_color.'" title="Smash Balloon Custom Facebook Feed WordPress Plugin"><img src="'.plugins_url( '/img/smashballoon-tiny.png' , __FILE__ ).'" alt="Smash Balloon Custom Facebook Feed WordPress Plugin" />The Custom Facebook Feed plugin</a></p>'; |
| 1571 | //End the feed |
| 1572 | $cff_content .= '</div><div class="cff-clear"></div>'; |
| 1573 | //Add the Like Box outside |
| 1574 | if ($cff_like_box_position == 'bottom' && $cff_show_like_box && $cff_like_box_outside) $cff_content .= $like_box; |
| 1575 | |
| 1576 | //If the feed is loaded via Ajax then put the scripts into the shortcode itself |
| 1577 | $ajax_theme = $atts['ajax']; |
| 1578 | ( $ajax_theme == 'on' || $ajax_theme == 'true' || $ajax_theme == true ) ? $ajax_theme = true : $ajax_theme = false; |
| 1579 | if( $atts[ 'ajax' ] == 'false' ) $ajax_theme = false; |
| 1580 | if ($ajax_theme) { |
| 1581 | $cff_link_hashtags = $atts['linkhashtags']; |
| 1582 | ($cff_link_hashtags == 'true' || $cff_link_hashtags == 'on') ? $cff_link_hashtags = 'true' : $cff_link_hashtags = 'false'; |
| 1583 | if($cff_title_link == 'true' || $cff_title_link == 'on') $cff_link_hashtags = 'false'; |
| 1584 | $cff_content .= '<script type="text/javascript">var cfflinkhashtags = "' . $cff_link_hashtags . '";</script>'; |
| 1585 | $cff_content .= '<script type="text/javascript" src="' . plugins_url( '/js/cff-scripts.js?ver='.CFFVER , __FILE__ ) . '"></script>'; |
| 1586 | } |
| 1587 | |
| 1588 | $cff_content .= '</div>'; |
| 1589 | |
| 1590 | if( isset( $cff_posttext_link_color ) && !empty( $cff_posttext_link_color ) ) $cff_content .= '<style>#cff .cff-post-text a{ color: #'.$cff_posttext_link_color.'; }</style>'; |
| 1591 | |
| 1592 | //Return our feed HTML to display |
| 1593 | return $cff_content; |
| 1594 | } |
| 1595 | |
| 1596 | //***FUNCTIONS*** |
| 1597 | |
| 1598 | //Get JSON object of feed data |
| 1599 | function cff_fetchUrl($url){ |
| 1600 | |
| 1601 | //Style options |
| 1602 | $options = get_option('cff_style_settings'); |
| 1603 | isset( $options['cff_request_method'] ) ? $cff_request_method = $options['cff_request_method'] : $cff_request_method = 'auto'; |
| 1604 | |
| 1605 | if($cff_request_method == '1'){ |
| 1606 | //Use cURL |
| 1607 | if(is_callable('curl_init')){ |
| 1608 | $ch = curl_init(); |
| 1609 | // Use global proxy settings |
| 1610 | if (defined('WP_PROXY_HOST')) { |
| 1611 | curl_setopt($ch, CURLOPT_PROXY, WP_PROXY_HOST); |
| 1612 | } |
| 1613 | if (defined('WP_PROXY_PORT')) { |
| 1614 | curl_setopt($ch, CURLOPT_PROXYPORT, WP_PROXY_PORT); |
| 1615 | } |
| 1616 | if (defined('WP_PROXY_USERNAME')){ |
| 1617 | $auth = WP_PROXY_USERNAME; |
| 1618 | if (defined('WP_PROXY_PASSWORD')){ |
| 1619 | $auth .= ':' . WP_PROXY_PASSWORD; |
| 1620 | } |
| 1621 | curl_setopt($ch, CURLOPT_PROXYUSERPWD, $auth); |
| 1622 | } |
| 1623 | curl_setopt($ch, CURLOPT_URL, $url); |
| 1624 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 1625 | curl_setopt($ch, CURLOPT_TIMEOUT, 20); |
| 1626 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
| 1627 | curl_setopt($ch, CURLOPT_ENCODING, ''); |
| 1628 | $feedData = curl_exec($ch); |
| 1629 | curl_close($ch); |
| 1630 | } |
| 1631 | } else if($cff_request_method == '2') { |
| 1632 | //Use file_get_contents |
| 1633 | if ( (ini_get('allow_url_fopen') == 1 || ini_get('allow_url_fopen') === TRUE ) && in_array('https', stream_get_wrappers()) ){ |
| 1634 | $feedData = @file_get_contents($url); |
| 1635 | } |
| 1636 | } else if($cff_request_method == '3'){ |
| 1637 | //Use the WP HTTP API |
| 1638 | $request = new WP_Http; |
| 1639 | $response = $request->request($url, array('timeout' => 60, 'sslverify' => false)); |
| 1640 | if( is_wp_error( $response ) ) { |
| 1641 | //Don't display an error, just use the Server config Error Reference message |
| 1642 | $FBdata = null; |
| 1643 | } else { |
| 1644 | $feedData = wp_remote_retrieve_body($response); |
| 1645 | } |
| 1646 | } else { |
| 1647 | //Auto detect |
| 1648 | if(is_callable('curl_init')){ |
| 1649 | $ch = curl_init(); |
| 1650 | // Use global proxy settings |
| 1651 | if (defined('WP_PROXY_HOST')) { |
| 1652 | curl_setopt($ch, CURLOPT_PROXY, WP_PROXY_HOST); |
| 1653 | } |
| 1654 | if (defined('WP_PROXY_PORT')) { |
| 1655 | curl_setopt($ch, CURLOPT_PROXYPORT, WP_PROXY_PORT); |
| 1656 | } |
| 1657 | if (defined('WP_PROXY_USERNAME')){ |
| 1658 | $auth = WP_PROXY_USERNAME; |
| 1659 | if (defined('WP_PROXY_PASSWORD')){ |
| 1660 | $auth .= ':' . WP_PROXY_PASSWORD; |
| 1661 | } |
| 1662 | curl_setopt($ch, CURLOPT_PROXYUSERPWD, $auth); |
| 1663 | } |
| 1664 | curl_setopt($ch, CURLOPT_URL, $url); |
| 1665 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 1666 | curl_setopt($ch, CURLOPT_TIMEOUT, 20); |
| 1667 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
| 1668 | curl_setopt($ch, CURLOPT_ENCODING, ''); |
| 1669 | $feedData = curl_exec($ch); |
| 1670 | curl_close($ch); |
| 1671 | } elseif ( (ini_get('allow_url_fopen') == 1 || ini_get('allow_url_fopen') === TRUE ) && in_array('https', stream_get_wrappers()) ) { |
| 1672 | $feedData = @file_get_contents($url); |
| 1673 | } else { |
| 1674 | $request = new WP_Http; |
| 1675 | $response = $request->request($url, array('timeout' => 60, 'sslverify' => false)); |
| 1676 | if( is_wp_error( $response ) ) { |
| 1677 | $FBdata = null; |
| 1678 | } else { |
| 1679 | $feedData = wp_remote_retrieve_body($response); |
| 1680 | } |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | return $feedData; |
| 1685 | } |
| 1686 | |
| 1687 | //Make links into span instead when the post text is made clickable |
| 1688 | function cff_wrap_span($text) { |
| 1689 | $pattern = '#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#'; |
| 1690 | return preg_replace_callback($pattern, 'cff_wrap_span_callback', $text); |
| 1691 | } |
| 1692 | function cff_wrap_span_callback($matches) { |
| 1693 | $max_url_length = 100; |
| 1694 | $max_depth_if_over_length = 2; |
| 1695 | $ellipsis = '…'; |
| 1696 | $target = 'target="_blank"'; |
| 1697 | $url_full = $matches[0]; |
| 1698 | $url_short = ''; |
| 1699 | if (strlen($url_full) > $max_url_length) { |
| 1700 | $parts = parse_url($url_full); |
| 1701 | $url_short = $parts['scheme'] . '://' . preg_replace('/^www\./', '', $parts['host']) . '/'; |
| 1702 | $path_components = explode('/', trim($parts['path'], '/')); |
| 1703 | foreach ($path_components as $dir) { |
| 1704 | $url_string_components[] = $dir . '/'; |
| 1705 | } |
| 1706 | if (!empty($parts['query'])) { |
| 1707 | $url_string_components[] = '?' . $parts['query']; |
| 1708 | } |
| 1709 | if (!empty($parts['fragment'])) { |
| 1710 | $url_string_components[] = '#' . $parts['fragment']; |
| 1711 | } |
| 1712 | for ($k = 0; $k < count($url_string_components); $k++) { |
| 1713 | $curr_component = $url_string_components[$k]; |
| 1714 | if ($k >= $max_depth_if_over_length || strlen($url_short) + strlen($curr_component) > $max_url_length) { |
| 1715 | if ($k == 0 && strlen($url_short) < $max_url_length) { |
| 1716 | // Always show a portion of first directory |
| 1717 | $url_short .= substr($curr_component, 0, $max_url_length - strlen($url_short)); |
| 1718 | } |
| 1719 | $url_short .= $ellipsis; |
| 1720 | break; |
| 1721 | } |
| 1722 | $url_short .= $curr_component; |
| 1723 | } |
| 1724 | } else { |
| 1725 | $url_short = $url_full; |
| 1726 | } |
| 1727 | return "<span class='cff-break-word'>$url_short</span>"; |
| 1728 | } |
| 1729 | |
| 1730 | //2013-04-28T21:06:56+0000 |
| 1731 | //Time stamp function - used for posts |
| 1732 | function cff_getdate($original, $date_format, $custom_date, $cff_date_translate_strings) { |
| 1733 | switch ($date_format) { |
| 1734 | |
| 1735 | case '2': |
| 1736 | $print = date_i18n('F jS, g:i a', $original); |
| 1737 | break; |
| 1738 | case '3': |
| 1739 | $print = date_i18n('F jS', $original); |
| 1740 | break; |
| 1741 | case '4': |
| 1742 | $print = date_i18n('D F jS', $original); |
| 1743 | break; |
| 1744 | case '5': |
| 1745 | $print = date_i18n('l F jS', $original); |
| 1746 | break; |
| 1747 | case '6': |
| 1748 | $print = date_i18n('D M jS, Y', $original); |
| 1749 | break; |
| 1750 | case '7': |
| 1751 | $print = date_i18n('l F jS, Y', $original); |
| 1752 | break; |
| 1753 | case '8': |
| 1754 | $print = date_i18n('l F jS, Y - g:i a', $original); |
| 1755 | break; |
| 1756 | case '9': |
| 1757 | $print = date_i18n("l M jS, 'y", $original); |
| 1758 | break; |
| 1759 | case '10': |
| 1760 | $print = date_i18n('m.d.y', $original); |
| 1761 | break; |
| 1762 | case '11': |
| 1763 | $print = date_i18n('m/d/y', $original); |
| 1764 | break; |
| 1765 | case '12': |
| 1766 | $print = date_i18n('d.m.y', $original); |
| 1767 | break; |
| 1768 | case '13': |
| 1769 | $print = date_i18n('d/m/y', $original); |
| 1770 | break; |
| 1771 | default: |
| 1772 | |
| 1773 | $cff_second = $cff_date_translate_strings['cff_translate_second']; |
| 1774 | $cff_seconds = $cff_date_translate_strings['cff_translate_seconds']; |
| 1775 | $cff_minute = $cff_date_translate_strings['cff_translate_minute']; |
| 1776 | $cff_minutes = $cff_date_translate_strings['cff_translate_minutes']; |
| 1777 | $cff_hour = $cff_date_translate_strings['cff_translate_hour']; |
| 1778 | $cff_hours = $cff_date_translate_strings['cff_translate_hours']; |
| 1779 | $cff_day = $cff_date_translate_strings['cff_translate_day']; |
| 1780 | $cff_days = $cff_date_translate_strings['cff_translate_days']; |
| 1781 | $cff_week = $cff_date_translate_strings['cff_translate_week']; |
| 1782 | $cff_weeks = $cff_date_translate_strings['cff_translate_weeks']; |
| 1783 | $cff_month = $cff_date_translate_strings['cff_translate_month']; |
| 1784 | $cff_months = $cff_date_translate_strings['cff_translate_months']; |
| 1785 | $cff_year = $cff_date_translate_strings['cff_translate_years']; |
| 1786 | $cff_years = $cff_date_translate_strings['cff_translate_years']; |
| 1787 | $cff_ago = $cff_date_translate_strings['cff_translate_ago']; |
| 1788 | |
| 1789 | |
| 1790 | $periods = array($cff_second, $cff_minute, $cff_hour, $cff_day, $cff_week, $cff_month, $cff_year, "decade"); |
| 1791 | $periods_plural = array($cff_seconds, $cff_minutes, $cff_hours, $cff_days, $cff_weeks, $cff_months, $cff_years, "decade"); |
| 1792 | |
| 1793 | $lengths = array("60","60","24","7","4.35","12","10"); |
| 1794 | $now = time(); |
| 1795 | |
| 1796 | // is it future date or past date |
| 1797 | if($now > $original) { |
| 1798 | $difference = $now - $original; |
| 1799 | $tense = $cff_ago; |
| 1800 | } else { |
| 1801 | $difference = $original - $now; |
| 1802 | $tense = $cff_ago; |
| 1803 | } |
| 1804 | for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) { |
| 1805 | $difference /= $lengths[$j]; |
| 1806 | } |
| 1807 | |
| 1808 | $difference = round($difference); |
| 1809 | |
| 1810 | if($difference != 1) { |
| 1811 | $periods[$j] = $periods_plural[$j]; |
| 1812 | } |
| 1813 | $print = "$difference $periods[$j] {$tense}"; |
| 1814 | |
| 1815 | break; |
| 1816 | |
| 1817 | } |
| 1818 | if ( !empty($custom_date) ){ |
| 1819 | $print = date_i18n($custom_date, $original); |
| 1820 | } |
| 1821 | |
| 1822 | return $print; |
| 1823 | } |
| 1824 | function cff_eventdate($original, $date_format, $custom_date) { |
| 1825 | switch ($date_format) { |
| 1826 | |
| 1827 | case '2': |
| 1828 | $print = date_i18n('F jS, g:ia', $original); |
| 1829 | break; |
| 1830 | case '3': |
| 1831 | $print = date_i18n('g:ia - F jS', $original); |
| 1832 | break; |
| 1833 | case '4': |
| 1834 | $print = date_i18n('g:ia, F jS', $original); |
| 1835 | break; |
| 1836 | case '5': |
| 1837 | $print = date_i18n('l F jS - g:ia', $original); |
| 1838 | break; |
| 1839 | case '6': |
| 1840 | $print = date_i18n('D M jS, Y, g:iA', $original); |
| 1841 | break; |
| 1842 | case '7': |
| 1843 | $print = date_i18n('l F jS, Y, g:iA', $original); |
| 1844 | break; |
| 1845 | case '8': |
| 1846 | $print = date_i18n('l F jS, Y - g:ia', $original); |
| 1847 | break; |
| 1848 | case '9': |
| 1849 | $print = date_i18n("l M jS, 'y", $original); |
| 1850 | break; |
| 1851 | case '10': |
| 1852 | $print = date_i18n('m.d.y - g:iA', $original); |
| 1853 | break; |
| 1854 | case '11': |
| 1855 | $print = date_i18n('m/d/y, g:ia', $original); |
| 1856 | break; |
| 1857 | case '12': |
| 1858 | $print = date_i18n('d.m.y - g:iA', $original); |
| 1859 | break; |
| 1860 | case '13': |
| 1861 | $print = date_i18n('d/m/y, g:ia', $original); |
| 1862 | break; |
| 1863 | default: |
| 1864 | $print = date_i18n('F j, Y, g:ia', $original); |
| 1865 | break; |
| 1866 | } |
| 1867 | if ( !empty($custom_date) ){ |
| 1868 | $print = date_i18n($custom_date, $original); |
| 1869 | } |
| 1870 | return $print; |
| 1871 | } |
| 1872 | //Use custom stripos function if it's not available (only available in PHP 5+) |
| 1873 | if(!is_callable('stripos')){ |
| 1874 | function stripos($haystack, $needle){ |
| 1875 | return strpos($haystack, stristr( $haystack, $needle )); |
| 1876 | } |
| 1877 | } |
| 1878 | function cff_stripos_arr($haystack, $needle) { |
| 1879 | if(!is_array($needle)) $needle = array($needle); |
| 1880 | foreach($needle as $what) { |
| 1881 | if(($pos = stripos($haystack, ltrim($what) ))!==false) return $pos; |
| 1882 | } |
| 1883 | return false; |
| 1884 | } |
| 1885 | function cff_mb_substr_replace($string, $replacement, $start, $length=NULL) { |
| 1886 | if (is_array($string)) { |
| 1887 | $num = count($string); |
| 1888 | // $replacement |
| 1889 | $replacement = is_array($replacement) ? array_slice($replacement, 0, $num) : array_pad(array($replacement), $num, $replacement); |
| 1890 | // $start |
| 1891 | if (is_array($start)) { |
| 1892 | $start = array_slice($start, 0, $num); |
| 1893 | foreach ($start as $key => $value) |
| 1894 | $start[$key] = is_int($value) ? $value : 0; |
| 1895 | } |
| 1896 | else { |
| 1897 | $start = array_pad(array($start), $num, $start); |
| 1898 | } |
| 1899 | // $length |
| 1900 | if (!isset($length)) { |
| 1901 | $length = array_fill(0, $num, 0); |
| 1902 | } |
| 1903 | elseif (is_array($length)) { |
| 1904 | $length = array_slice($length, 0, $num); |
| 1905 | foreach ($length as $key => $value) |
| 1906 | $length[$key] = isset($value) ? (is_int($value) ? $value : $num) : 0; |
| 1907 | } |
| 1908 | else { |
| 1909 | $length = array_pad(array($length), $num, $length); |
| 1910 | } |
| 1911 | // Recursive call |
| 1912 | return array_map(__FUNCTION__, $string, $replacement, $start, $length); |
| 1913 | } |
| 1914 | preg_match_all('/./us', (string)$string, $smatches); |
| 1915 | preg_match_all('/./us', (string)$replacement, $rmatches); |
| 1916 | if ($length === NULL) $length = mb_strlen($string); |
| 1917 | array_splice($smatches[0], $start, $length, $rmatches[0]); |
| 1918 | return join($smatches[0]); |
| 1919 | } |
| 1920 | |
| 1921 | //Push to assoc array |
| 1922 | function cff_array_push_assoc($array, $key, $value){ |
| 1923 | $array[$key] = $value; |
| 1924 | return $array; |
| 1925 | } |
| 1926 | //Convert string to slug |
| 1927 | function cff_to_slug($string){ |
| 1928 | return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string))); |
| 1929 | } |
| 1930 | |
| 1931 | // remove_filter( 'the_content', 'wpautop' ); |
| 1932 | // add_filter( 'the_content', 'wpautop', 99 ); |
| 1933 | |
| 1934 | |
| 1935 | //Allows shortcodes in theme |
| 1936 | add_filter('widget_text', 'do_shortcode'); |
| 1937 | |
| 1938 | //Enqueue stylesheet |
| 1939 | add_action( 'wp_enqueue_scripts', 'cff_add_my_stylesheet' ); |
| 1940 | function cff_add_my_stylesheet() { |
| 1941 | // Respects SSL, Style.css is relative to the current file |
| 1942 | wp_register_style( 'cff', plugins_url('css/cff-style.css', __FILE__), array(), CFFVER ); //Update to plugin version |
| 1943 | wp_enqueue_style( 'cff' ); |
| 1944 | |
| 1945 | $options = get_option('cff_style_settings'); |
| 1946 | |
| 1947 | if( !isset( $options[ 'cff_font_source' ] ) ){ |
| 1948 | wp_enqueue_style( 'cff-font-awesome', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css', array(), '4.5.0' ); |
| 1949 | } else { |
| 1950 | |
| 1951 | if( $options[ 'cff_font_source' ] == 'none' ){ |
| 1952 | //Do nothing |
| 1953 | } else if( $options[ 'cff_font_source' ] == 'local' ){ |
| 1954 | wp_enqueue_style( 'cff-font-awesome', plugins_url('css/font-awesome.min.css', __FILE__), array(), '4.5.0' ); |
| 1955 | } else { |
| 1956 | wp_enqueue_style( 'cff-font-awesome', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css', array(), '4.5.0' ); |
| 1957 | } |
| 1958 | |
| 1959 | } |
| 1960 | |
| 1961 | |
| 1962 | } |
| 1963 | //Enqueue scripts |
| 1964 | add_action( 'wp_enqueue_scripts', 'cff_scripts_method' ); |
| 1965 | function cff_scripts_method() { |
| 1966 | //Register the script to make it available |
| 1967 | wp_register_script( 'cffscripts', plugins_url( '/js/cff-scripts.js' , __FILE__ ), array('jquery'), CFFVER, true ); |
| 1968 | //Enqueue it to load it onto the page |
| 1969 | wp_enqueue_script('cffscripts'); |
| 1970 | } |
| 1971 | |
| 1972 | function cff_activate() { |
| 1973 | $options = get_option('cff_style_settings'); |
| 1974 | $options[ 'cff_show_links_type' ] = true; |
| 1975 | $options[ 'cff_show_event_type' ] = true; |
| 1976 | $options[ 'cff_show_video_type' ] = true; |
| 1977 | $options[ 'cff_show_photos_type' ] = true; |
| 1978 | $options[ 'cff_show_status_type' ] = true; |
| 1979 | $options[ 'cff_show_author' ] = true; |
| 1980 | $options[ 'cff_show_text' ] = true; |
| 1981 | $options[ 'cff_show_desc' ] = true; |
| 1982 | $options[ 'cff_show_shared_links' ] = true; |
| 1983 | $options[ 'cff_show_date' ] = true; |
| 1984 | $options[ 'cff_show_media' ] = true; |
| 1985 | $options[ 'cff_show_media_link' ] = true; |
| 1986 | $options[ 'cff_show_event_title' ] = true; |
| 1987 | $options[ 'cff_show_event_details' ] = true; |
| 1988 | $options[ 'cff_show_meta' ] = true; |
| 1989 | $options[ 'cff_show_link' ] = true; |
| 1990 | $options[ 'cff_show_like_box' ] = true; |
| 1991 | $options[ 'cff_show_facebook_link' ] = true; |
| 1992 | $options[ 'cff_show_facebook_share' ] = true; |
| 1993 | $options[ 'cff_event_title_link' ] = true; |
| 1994 | update_option( 'cff_style_settings', $options ); |
| 1995 | |
| 1996 | get_option('cff_show_access_token'); |
| 1997 | update_option( 'cff_show_access_token', false ); |
| 1998 | |
| 1999 | //Run cron twice daily when plugin is first activated for new users |
| 2000 | wp_schedule_event(time(), 'twicedaily', 'cff_cron_job'); |
| 2001 | } |
| 2002 | register_activation_hook( __FILE__, 'cff_activate' ); |
| 2003 | |
| 2004 | function cff_deactivate() { |
| 2005 | wp_clear_scheduled_hook('cff_cron_job'); |
| 2006 | } |
| 2007 | register_deactivation_hook(__FILE__, 'cff_deactivate'); |
| 2008 | |
| 2009 | //Uninstall |
| 2010 | function cff_uninstall() |
| 2011 | { |
| 2012 | if ( ! current_user_can( 'activate_plugins' ) ) |
| 2013 | return; |
| 2014 | |
| 2015 | //If the user is preserving the settings then don't delete them |
| 2016 | $cff_preserve_settings = get_option('cff_preserve_settings'); |
| 2017 | if($cff_preserve_settings) return; |
| 2018 | |
| 2019 | //Settings |
| 2020 | delete_option( 'cff_show_access_token' ); |
| 2021 | delete_option( 'cff_access_token' ); |
| 2022 | delete_option( 'cff_page_id' ); |
| 2023 | delete_option( 'cff_num_show' ); |
| 2024 | delete_option( 'cff_post_limit' ); |
| 2025 | delete_option( 'cff_show_others' ); |
| 2026 | delete_option( 'cff_cache_time' ); |
| 2027 | delete_option( 'cff_cache_time_unit' ); |
| 2028 | delete_option( 'cff_locale' ); |
| 2029 | delete_option( 'cff_ajax' ); |
| 2030 | delete_option( 'cff_preserve_settings' ); |
| 2031 | //Style & Layout |
| 2032 | delete_option( 'cff_title_length' ); |
| 2033 | delete_option( 'cff_body_length' ); |
| 2034 | delete_option('cff_style_settings'); |
| 2035 | } |
| 2036 | register_uninstall_hook( __FILE__, 'cff_uninstall' ); |
| 2037 | add_action( 'wp_head', 'cff_custom_css' ); |
| 2038 | function cff_custom_css() { |
| 2039 | $options = get_option('cff_style_settings'); |
| 2040 | isset($options[ 'cff_custom_css' ]) ? $cff_custom_css = $options[ 'cff_custom_css' ] : $cff_custom_css = ''; |
| 2041 | |
| 2042 | if( !empty($cff_custom_css) ) echo "\r\n"; |
| 2043 | if( !empty($cff_custom_css) ) echo '<!-- Custom Facebook Feed Custom CSS -->'; |
| 2044 | if( !empty($cff_custom_css) ) echo "\r\n"; |
| 2045 | if( !empty($cff_custom_css) ) echo '<style type="text/css">'; |
| 2046 | if( !empty($cff_custom_css) ) echo "\r\n"; |
| 2047 | if( !empty($cff_custom_css) ) echo stripslashes($cff_custom_css); |
| 2048 | if( !empty($cff_custom_css) ) echo "\r\n"; |
| 2049 | if( !empty($cff_custom_css) ) echo '</style>'; |
| 2050 | if( !empty($cff_custom_css) ) echo "\r\n"; |
| 2051 | } |
| 2052 | add_action( 'wp_footer', 'cff_js' ); |
| 2053 | function cff_js() { |
| 2054 | $options = get_option('cff_style_settings'); |
| 2055 | $cff_custom_js = isset($options[ 'cff_custom_js' ]) ? $options[ 'cff_custom_js' ] : ''; |
| 2056 | |
| 2057 | //Link hashtags? |
| 2058 | isset($options[ 'cff_link_hashtags' ]) ? $cff_link_hashtags = $options[ 'cff_link_hashtags' ] : $cff_link_hashtags = 'true'; |
| 2059 | ($cff_link_hashtags == 'true' || $cff_link_hashtags == 'on') ? $cff_link_hashtags = 'true' : $cff_link_hashtags = 'false'; |
| 2060 | |
| 2061 | //If linking the post text then don't link the hashtags |
| 2062 | isset($options[ 'cff_title_link' ]) ? $cff_title_link = $options[ 'cff_title_link' ] : $cff_title_link = false; |
| 2063 | ($cff_title_link == 'true' || $cff_title_link == 'on') ? $cff_title_link = true : $cff_title_link = false; |
| 2064 | if ($cff_title_link) $cff_link_hashtags = 'false'; |
| 2065 | |
| 2066 | |
| 2067 | echo '<!-- Custom Facebook Feed JS -->'; |
| 2068 | echo "\r\n"; |
| 2069 | echo '<script type="text/javascript">'; |
| 2070 | echo "\r\n"; |
| 2071 | echo 'var cfflinkhashtags = "' . $cff_link_hashtags . '";'; |
| 2072 | echo "\r\n"; |
| 2073 | if( !empty($cff_custom_js) ) echo "jQuery( document ).ready(function($) {"; |
| 2074 | if( !empty($cff_custom_js) ) echo "\r\n"; |
| 2075 | if( !empty($cff_custom_js) ) echo stripslashes($cff_custom_js); |
| 2076 | if( !empty($cff_custom_js) ) echo "\r\n"; |
| 2077 | if( !empty($cff_custom_js) ) echo "});"; |
| 2078 | if( !empty($cff_custom_js) ) echo "\r\n"; |
| 2079 | echo '</script>'; |
| 2080 | echo "\r\n"; |
| 2081 | } |
| 2082 | |
| 2083 | |
| 2084 | |
| 2085 | //AUTOLINK |
| 2086 | $GLOBALS['autolink_options'] = array( |
| 2087 | |
| 2088 | # Should http:// be visibly stripped from the front |
| 2089 | # of URLs? |
| 2090 | 'strip_protocols' => true, |
| 2091 | |
| 2092 | ); |
| 2093 | |
| 2094 | #################################################################### |
| 2095 | |
| 2096 | function cff_autolink($text, $link_color='', $span_tag = false, $limit=100, $tagfill='class="cff-break-word"', $auto_title = true){ |
| 2097 | |
| 2098 | $text = cff_autolink_do($text, $link_color, '![a-z][a-z-]+://!i', $limit, $tagfill, $auto_title, $span_tag); |
| 2099 | $text = cff_autolink_do($text, $link_color, '!(mailto|skype):!i', $limit, $tagfill, $auto_title, $span_tag); |
| 2100 | $text = cff_autolink_do($text, $link_color, '!www\\.!i', $limit, $tagfill, $auto_title, 'http://', $span_tag); |
| 2101 | return $text; |
| 2102 | } |
| 2103 | |
| 2104 | #################################################################### |
| 2105 | |
| 2106 | function cff_autolink_do($text, $link_color, $sub, $limit, $tagfill, $auto_title, $span_tag, $force_prefix=null){ |
| 2107 | |
| 2108 | $text_l = StrToLower($text); |
| 2109 | $cursor = 0; |
| 2110 | $loop = 1; |
| 2111 | $buffer = ''; |
| 2112 | |
| 2113 | while (($cursor < strlen($text)) && $loop){ |
| 2114 | |
| 2115 | $ok = 1; |
| 2116 | $matched = preg_match($sub, $text_l, $m, PREG_OFFSET_CAPTURE, $cursor); |
| 2117 | |
| 2118 | if (!$matched){ |
| 2119 | |
| 2120 | $loop = 0; |
| 2121 | $ok = 0; |
| 2122 | |
| 2123 | }else{ |
| 2124 | |
| 2125 | $pos = $m[0][1]; |
| 2126 | $sub_len = strlen($m[0][0]); |
| 2127 | |
| 2128 | $pre_hit = substr($text, $cursor, $pos-$cursor); |
| 2129 | $hit = substr($text, $pos, $sub_len); |
| 2130 | $pre = substr($text, 0, $pos); |
| 2131 | $post = substr($text, $pos + $sub_len); |
| 2132 | |
| 2133 | $fail_text = $pre_hit.$hit; |
| 2134 | $fail_len = strlen($fail_text); |
| 2135 | |
| 2136 | # |
| 2137 | # substring found - first check to see if we're inside a link tag already... |
| 2138 | # |
| 2139 | |
| 2140 | $bits = preg_split("!</a>!i", $pre); |
| 2141 | $last_bit = array_pop($bits); |
| 2142 | if (preg_match("!<a\s!i", $last_bit)){ |
| 2143 | |
| 2144 | #echo "fail 1 at $cursor<br />\n"; |
| 2145 | |
| 2146 | $ok = 0; |
| 2147 | $cursor += $fail_len; |
| 2148 | $buffer .= $fail_text; |
| 2149 | } |
| 2150 | } |
| 2151 | |
| 2152 | # |
| 2153 | # looks like a nice spot to autolink from - check the pre |
| 2154 | # to see if there was whitespace before this match |
| 2155 | # |
| 2156 | |
| 2157 | if ($ok){ |
| 2158 | |
| 2159 | if ($pre){ |
| 2160 | if (!preg_match('![\s\(\[\{>]$!s', $pre)){ |
| 2161 | |
| 2162 | #echo "fail 2 at $cursor ($pre)<br />\n"; |
| 2163 | |
| 2164 | $ok = 0; |
| 2165 | $cursor += $fail_len; |
| 2166 | $buffer .= $fail_text; |
| 2167 | } |
| 2168 | } |
| 2169 | } |
| 2170 | |
| 2171 | # |
| 2172 | # we want to autolink here - find the extent of the url |
| 2173 | # |
| 2174 | |
| 2175 | if ($ok){ |
| 2176 | if (preg_match('/^([a-z0-9\-\.\/\-_%~!?=,:;&+*#@\(\)\$]+)/i', $post, $matches)){ |
| 2177 | |
| 2178 | $url = $hit.$matches[1]; |
| 2179 | |
| 2180 | $cursor += strlen($url) + strlen($pre_hit); |
| 2181 | $buffer .= $pre_hit; |
| 2182 | |
| 2183 | $url = html_entity_decode($url); |
| 2184 | |
| 2185 | |
| 2186 | # |
| 2187 | # remove trailing punctuation from url |
| 2188 | # |
| 2189 | |
| 2190 | while (preg_match('|[.,!;:?]$|', $url)){ |
| 2191 | $url = substr($url, 0, strlen($url)-1); |
| 2192 | $cursor--; |
| 2193 | } |
| 2194 | foreach (array('()', '[]', '{}') as $pair){ |
| 2195 | $o = substr($pair, 0, 1); |
| 2196 | $c = substr($pair, 1, 1); |
| 2197 | if (preg_match("!^(\\$c|^)[^\\$o]+\\$c$!", $url)){ |
| 2198 | $url = substr($url, 0, strlen($url)-1); |
| 2199 | $cursor--; |
| 2200 | } |
| 2201 | } |
| 2202 | |
| 2203 | |
| 2204 | # |
| 2205 | # nice-i-fy url here |
| 2206 | # |
| 2207 | |
| 2208 | $link_url = $url; |
| 2209 | $display_url = $url; |
| 2210 | |
| 2211 | if ($force_prefix) $link_url = $force_prefix.$link_url; |
| 2212 | |
| 2213 | if ($GLOBALS['autolink_options']['strip_protocols']){ |
| 2214 | if (preg_match('!^(http|https)://!i', $display_url, $m)){ |
| 2215 | |
| 2216 | $display_url = substr($display_url, strlen($m[1])+3); |
| 2217 | } |
| 2218 | } |
| 2219 | |
| 2220 | $display_url = cff_autolink_label($display_url, $limit); |
| 2221 | |
| 2222 | |
| 2223 | # |
| 2224 | # add the url |
| 2225 | # |
| 2226 | |
| 2227 | if ($display_url != $link_url && !preg_match('@title=@msi',$tagfill) && $auto_title) { |
| 2228 | |
| 2229 | $display_quoted = preg_quote($display_url, '!'); |
| 2230 | |
| 2231 | if (!preg_match("!^(http|https)://{$display_quoted}$!i", $link_url)){ |
| 2232 | |
| 2233 | $tagfill .= ' title="'.$link_url.'"'; |
| 2234 | } |
| 2235 | } |
| 2236 | |
| 2237 | $link_url_enc = HtmlSpecialChars($link_url); |
| 2238 | $display_url_enc = HtmlSpecialChars($display_url); |
| 2239 | |
| 2240 | |
| 2241 | if( substr( $link_url_enc, 0, 4 ) !== "http" ) $link_url_enc = 'http://' . $link_url_enc; |
| 2242 | $buffer .= "<a href=\"{$link_url_enc}\">{$display_url_enc}</a>"; |
| 2243 | |
| 2244 | |
| 2245 | }else{ |
| 2246 | #echo "fail 3 at $cursor<br />\n"; |
| 2247 | |
| 2248 | $ok = 0; |
| 2249 | $cursor += $fail_len; |
| 2250 | $buffer .= $fail_text; |
| 2251 | } |
| 2252 | } |
| 2253 | |
| 2254 | } |
| 2255 | |
| 2256 | # |
| 2257 | # add everything from the cursor to the end onto the buffer. |
| 2258 | # |
| 2259 | |
| 2260 | $buffer .= substr($text, $cursor); |
| 2261 | |
| 2262 | return $buffer; |
| 2263 | } |
| 2264 | |
| 2265 | #################################################################### |
| 2266 | |
| 2267 | function cff_autolink_label($text, $limit){ |
| 2268 | |
| 2269 | if (!$limit){ return $text; } |
| 2270 | |
| 2271 | if (strlen($text) > $limit){ |
| 2272 | return substr($text, 0, $limit-3).'...'; |
| 2273 | } |
| 2274 | |
| 2275 | return $text; |
| 2276 | } |
| 2277 | |
| 2278 | #################################################################### |
| 2279 | |
| 2280 | function cff_autolink_email($text, $tagfill=''){ |
| 2281 | |
| 2282 | $atom = '[^()<>@,;:\\\\".\\[\\]\\x00-\\x20\\x7f]+'; # from RFC822 |
| 2283 | |
| 2284 | #die($atom); |
| 2285 | |
| 2286 | $text_l = StrToLower($text); |
| 2287 | $cursor = 0; |
| 2288 | $loop = 1; |
| 2289 | $buffer = ''; |
| 2290 | |
| 2291 | while(($cursor < strlen($text)) && $loop){ |
| 2292 | |
| 2293 | # |
| 2294 | # find an '@' symbol |
| 2295 | # |
| 2296 | |
| 2297 | $ok = 1; |
| 2298 | $pos = strpos($text_l, '@', $cursor); |
| 2299 | |
| 2300 | if ($pos === false){ |
| 2301 | |
| 2302 | $loop = 0; |
| 2303 | $ok = 0; |
| 2304 | |
| 2305 | }else{ |
| 2306 | |
| 2307 | $pre = substr($text, $cursor, $pos-$cursor); |
| 2308 | $hit = substr($text, $pos, 1); |
| 2309 | $post = substr($text, $pos + 1); |
| 2310 | |
| 2311 | $fail_text = $pre.$hit; |
| 2312 | $fail_len = strlen($fail_text); |
| 2313 | |
| 2314 | #die("$pre::$hit::$post::$fail_text"); |
| 2315 | |
| 2316 | # |
| 2317 | # substring found - first check to see if we're inside a link tag already... |
| 2318 | # |
| 2319 | |
| 2320 | $bits = preg_split("!</a>!i", $pre); |
| 2321 | $last_bit = array_pop($bits); |
| 2322 | if (preg_match("!<a\s!i", $last_bit)){ |
| 2323 | |
| 2324 | #echo "fail 1 at $cursor<br />\n"; |
| 2325 | |
| 2326 | $ok = 0; |
| 2327 | $cursor += $fail_len; |
| 2328 | $buffer .= $fail_text; |
| 2329 | } |
| 2330 | } |
| 2331 | |
| 2332 | # |
| 2333 | # check backwards |
| 2334 | # |
| 2335 | |
| 2336 | if ($ok){ |
| 2337 | if (preg_match("!($atom(\.$atom)*)\$!", $pre, $matches)){ |
| 2338 | |
| 2339 | # move matched part of address into $hit |
| 2340 | |
| 2341 | $len = strlen($matches[1]); |
| 2342 | $plen = strlen($pre); |
| 2343 | |
| 2344 | $hit = substr($pre, $plen-$len).$hit; |
| 2345 | $pre = substr($pre, 0, $plen-$len); |
| 2346 | |
| 2347 | }else{ |
| 2348 | |
| 2349 | #echo "fail 2 at $cursor ($pre)<br />\n"; |
| 2350 | |
| 2351 | $ok = 0; |
| 2352 | $cursor += $fail_len; |
| 2353 | $buffer .= $fail_text; |
| 2354 | } |
| 2355 | } |
| 2356 | |
| 2357 | # |
| 2358 | # check forwards |
| 2359 | # |
| 2360 | |
| 2361 | if ($ok){ |
| 2362 | if (preg_match("!^($atom(\.$atom)*)!", $post, $matches)){ |
| 2363 | |
| 2364 | # move matched part of address into $hit |
| 2365 | |
| 2366 | $len = strlen($matches[1]); |
| 2367 | |
| 2368 | $hit .= substr($post, 0, $len); |
| 2369 | $post = substr($post, $len); |
| 2370 | |
| 2371 | }else{ |
| 2372 | #echo "fail 3 at $cursor ($post)<br />\n"; |
| 2373 | |
| 2374 | $ok = 0; |
| 2375 | $cursor += $fail_len; |
| 2376 | $buffer .= $fail_text; |
| 2377 | } |
| 2378 | } |
| 2379 | |
| 2380 | # |
| 2381 | # commit |
| 2382 | # |
| 2383 | |
| 2384 | if ($ok) { |
| 2385 | |
| 2386 | $cursor += strlen($pre) + strlen($hit); |
| 2387 | $buffer .= $pre; |
| 2388 | $buffer .= "<a href=\"mailto:$hit\"$tagfill>$hit</a>"; |
| 2389 | |
| 2390 | } |
| 2391 | |
| 2392 | } |
| 2393 | |
| 2394 | # |
| 2395 | # add everything from the cursor to the end onto the buffer. |
| 2396 | # |
| 2397 | |
| 2398 | $buffer .= substr($text, $cursor); |
| 2399 | |
| 2400 | return $buffer; |
| 2401 | } |
| 2402 | |
| 2403 | #################################################################### |
| 2404 | |
| 2405 | |
| 2406 | ?> |