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