Admin
4 weeks ago
Builder
4 weeks ago
Integrations
4 weeks ago
SmashTwitter
4 weeks ago
UsageTracking
4 weeks ago
V2
4 weeks ago
blocks
4 weeks ago
CTF_Display_Elements.php
4 weeks ago
CTF_Feed.php
4 weeks ago
CTF_Feed_Locator.php
4 weeks ago
CTF_GDPR_Integrations.php
4 weeks ago
CTF_Parse.php
4 weeks ago
CTF_Settings.php
4 weeks ago
CtfAdmin.php
4 weeks ago
CtfCache.php
4 weeks ago
CtfFeed.php
4 weeks ago
CtfOauthConnect.php
4 weeks ago
SB_Twitter_Cron_Updater.php
4 weeks ago
admin-hooks.php
4 weeks ago
ctf-functions.php
4 weeks ago
notices.php
4 weeks ago
widget.php
4 weeks ago
CTF_Display_Elements.php
570 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class CTF_Display_Elements |
| 4 | * |
| 5 | * |
| 6 | * @since 2.0 |
| 7 | */ |
| 8 | namespace TwitterFeed; |
| 9 | use TwitterFeed\Builder\CTF_Feed_Builder; |
| 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | die( '-1' ); |
| 12 | } |
| 13 | |
| 14 | class CTF_Display_Elements { |
| 15 | |
| 16 | /** |
| 17 | * Get Feed Item CSS Classes |
| 18 | * |
| 19 | * @since 2.0 |
| 20 | */ |
| 21 | public static function get_item_classes( $data, $feed_options, $i ) { |
| 22 | $data = $data[$i]; |
| 23 | |
| 24 | $tweet_classes = 'ctf-item ctf-author-' . CTF_Parse::get_author_screen_name( $data ) .' ctf-new'; |
| 25 | $tweet_classes .= ( !ctf_show( 'avatar', $feed_options ) ) ? ' ctf-hide-avatar' : ''; |
| 26 | $tweet_classes = apply_filters( 'ctf_tweet_classes', $tweet_classes ); |
| 27 | |
| 28 | $tweet_classes .= isset( $data['retweeted_status'] ) ? ' ctf-retweet' : ''; |
| 29 | $tweet_classes .= isset( $data['quoted_status'] ) ? ' ctf-quoted' : ''; |
| 30 | $tweet_classes = ' class="' . $tweet_classes . '" '; |
| 31 | if( ctf_doing_customizer($feed_options) ){ |
| 32 | $tweet_classes .= ' :class="!$parent.valueIsEnabled($parent.customizerFeedData.settings.include_avatar) ? \'ctf-hide-avatar\' : \'\'" '; |
| 33 | } |
| 34 | return $tweet_classes; |
| 35 | } |
| 36 | |
| 37 | |
| 38 | /** |
| 39 | * Get Tweet Retweet Attribute |
| 40 | * |
| 41 | * @since 2.0 |
| 42 | */ |
| 43 | public static function get_retweet_attr( $post, $check_duplicates ) { |
| 44 | if( isset( $post['retweeted_status'] ) && $check_duplicates ) { |
| 45 | return ' data-ctfretweetid="'.$post['retweeted_status']['id_str'].'"'; |
| 46 | } |
| 47 | return ''; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Get Tweet Quoted Media Text |
| 52 | * |
| 53 | * @since 2.0 |
| 54 | */ |
| 55 | public static function get_quoted_media_text( $post, $feed_options ) { |
| 56 | $quoted_media_text = ''; |
| 57 | if(!$feed_options['is_legacy'] || ($feed_options['is_legacy'] && ctf_show( 'placeholder', $feed_options ))){ |
| 58 | if ( isset( $post['quoted_status'] ) ) { |
| 59 | $quoted = $post['quoted_status']; |
| 60 | |
| 61 | if ( ( isset( $quoted['extended_entities']['media'][0] ) || isset( $quoted['entities']['media'][0] ) ) && ctf_show( 'placeholder', $feed_options ) ) { |
| 62 | $quoted_media = isset( $quoted['extended_entities']['media'] ) ? $quoted['extended_entities']['media'] : $quoted['entities']['media']; |
| 63 | $quoted_media_count = count( $quoted_media ); |
| 64 | switch ( $quoted_media[0]['type'] ) { |
| 65 | case 'video': |
| 66 | case 'animated_gif': |
| 67 | $quoted_media_text .= '<span class="ctf-quoted-tweet-text-media-wrap">' . ctf_get_fa_el( 'fa-file-video-o' ) . '</span>'; |
| 68 | break; |
| 69 | default: |
| 70 | if ( $quoted_media_count > 1 ) { |
| 71 | $quoted_media_text .= '<span class="ctf-quoted-tweet-text-media-wrap ctf-multi-media-icon">' . $quoted_media_count . ctf_get_fa_el( 'fa-picture-o' ) . '</span>'; |
| 72 | } else { |
| 73 | $quoted_media_text .= '<span class="ctf-quoted-tweet-text-media-wrap">' . ctf_get_fa_el( 'fa-picture-o' ) . '</span>'; |
| 74 | } |
| 75 | break; |
| 76 | } |
| 77 | } else { |
| 78 | unset( $quoted_media ); |
| 79 | } |
| 80 | } |
| 81 | return $quoted_media_text; |
| 82 | } |
| 83 | |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Get Tweet Post media TExt |
| 88 | * |
| 89 | * @since 2.0 |
| 90 | */ |
| 91 | public static function get_post_media_text( $post, $feed_options, $type = 'text' ) { |
| 92 | $post_media_text = ''; |
| 93 | $post_media_count = 0; |
| 94 | if ( ( isset( $post['extended_entities']['media'][0] ) || isset( $post['entities']['media'][0] ) ) ) { |
| 95 | $post_media = isset( $post['extended_entities']['media'] ) ? $post['extended_entities']['media'] : $post['entities']['media']; |
| 96 | $post_media_count = count( $post_media ); |
| 97 | switch ( $post_media[0]['type'] ) { |
| 98 | case 'video': |
| 99 | case 'animated_gif': |
| 100 | $post_media_text .= ctf_get_fa_el( 'fa-file-video-o' ); |
| 101 | break; |
| 102 | default: |
| 103 | if ( $post_media_count > 1 ) { |
| 104 | $post_media_text .= $post_media_count . ctf_get_fa_el( 'fa-picture-o' ); |
| 105 | } else { |
| 106 | $post_media_text .= ctf_get_fa_el( 'fa-picture-o' ); |
| 107 | } |
| 108 | break; |
| 109 | } |
| 110 | } else { |
| 111 | unset( $post_media ); |
| 112 | return ''; |
| 113 | } |
| 114 | $html = ($type == 'text') ? $post_media_text : $post_media_count; |
| 115 | $multi_class = $post_media_count > 1 ? ' ctf-multi-media-icon' : ''; |
| 116 | |
| 117 | if ( $feed_options['linktexttotwitter'] ) { |
| 118 | return $html; |
| 119 | } elseif ( $feed_options['disablelinks'] ) { |
| 120 | $return = '<span class="ctf-tweet-text-media-wrap'.$multi_class.'">' . $html . '</span>'; |
| 121 | } else { |
| 122 | $return = '</p><a href="https://twitter.com/' . $post['user']['screen_name'] . '/status/' . $post['id_str'] . '" target="_blank" rel="noopener noreferrer" aria-label="' . esc_attr( sprintf( __( 'View @%s tweet media on Twitter', 'custom-twitter-feeds' ), $post['user']['screen_name'] ) ) . '" class="ctf-tweet-text-media-wrap'.$multi_class.'">' . $html . '</a>'; |
| 123 | } |
| 124 | |
| 125 | return $return; |
| 126 | } |
| 127 | /** |
| 128 | * Display Feed Header |
| 129 | * |
| 130 | * @param array $settings |
| 131 | * |
| 132 | * @return string |
| 133 | * |
| 134 | * @since 2.0 |
| 135 | */ |
| 136 | public static function display_header( $feed_options, $tweet_set ){ |
| 137 | if ( empty( $tweet_set ) || (isset( $tweet_set[0] ) && is_string( $tweet_set[0] ) && $tweet_set[0] === 'error') ) { |
| 138 | return; |
| 139 | } |
| 140 | if( ctf_doing_customizer( $feed_options ) ){ |
| 141 | $header_template = 'header-generic'; |
| 142 | if ( $feed_options['type'] === 'usertimeline' || $feed_options['type'] === 'mentionstimeline' || $feed_options['type'] === 'hometimeline' ) { |
| 143 | $header_template = 'header'; |
| 144 | } |
| 145 | include ctf_get_feed_template_part( $header_template, $feed_options ); |
| 146 | include ctf_get_feed_template_part( 'header-text', $feed_options ); |
| 147 | }else{ |
| 148 | include ctf_get_feed_template_part( CTF_Display_Elements::header_type( $feed_options ), $feed_options ); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | public static function header_type( $feed_options ) { |
| 153 | $header_template = 'header-generic'; |
| 154 | if ( $feed_options['type'] === 'usertimeline' || $feed_options['type'] === 'mentionstimeline' || $feed_options['type'] === 'hometimeline' ) { |
| 155 | $header_template = 'header'; |
| 156 | } |
| 157 | |
| 158 | if( isset( $feed_options['headerstyle'] ) && $feed_options['headerstyle'] == 'text'){ |
| 159 | $header_template = 'header-text'; |
| 160 | } |
| 161 | |
| 162 | return $header_template; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Should Show Element |
| 167 | * |
| 168 | * @param array $settings |
| 169 | * @param string $setting_name |
| 170 | * @param bool $custom_condition |
| 171 | * |
| 172 | * @return string |
| 173 | * |
| 174 | * @since 2.0 |
| 175 | */ |
| 176 | public static function should_show_element_vue( $settings, $setting_name, $custom_condition = false ) { |
| 177 | $customizer = ctf_doing_customizer( $settings ); |
| 178 | if ( $customizer ) { |
| 179 | return ' v-if="$parent.valueIsEnabled($parent.customizerFeedData.settings.' . $setting_name . ')' . ( $custom_condition != false ? $custom_condition : '' ) . '" '; |
| 180 | } |
| 181 | return ''; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Should Print HTML |
| 186 | * |
| 187 | * @param bool $customizer |
| 188 | * @param string $content |
| 189 | * |
| 190 | * @return string |
| 191 | * |
| 192 | * @since 2.0 |
| 193 | */ |
| 194 | public static function should_print_element_vue( $customizer, $content ) { |
| 195 | if ( $customizer ) { |
| 196 | return ' v-html="' . $content . '" '; |
| 197 | } |
| 198 | return ''; |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Should Print HTML |
| 203 | * |
| 204 | * @param bool $customizer |
| 205 | * @param string $condition |
| 206 | * |
| 207 | * @return string |
| 208 | * |
| 209 | * @since 2.0 |
| 210 | */ |
| 211 | public static function create_condition_vue( $customizer, $condition ) { |
| 212 | if ( $customizer ) { |
| 213 | return ' v-if="' . $condition . '" '; |
| 214 | } |
| 215 | return ''; |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * Should Show Print HTML |
| 220 | * |
| 221 | * @param bool $customizer |
| 222 | * @param string $condition |
| 223 | * |
| 224 | * @return string |
| 225 | * |
| 226 | * @since 2.0 |
| 227 | */ |
| 228 | public static function create_condition_show_vue( $customizer, $condition ) { |
| 229 | if ( $customizer ) { |
| 230 | return ' v-show="' . $condition . '" '; |
| 231 | } |
| 232 | return ''; |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Print Element HTML Attribute |
| 237 | * |
| 238 | * Output is echoed raw onto the #ctf div, so escaping here is what stops a |
| 239 | * settings value closing its attribute (SMASH-1770). vue_content is left |
| 240 | * unescaped: every call site passes a hardcoded expression. Keep it that way, |
| 241 | * a user-supplied one would be code in a compiled template. |
| 242 | * |
| 243 | * @param bool $customizer |
| 244 | * @param array $args |
| 245 | * |
| 246 | * @return string |
| 247 | * |
| 248 | * @since 2.0 |
| 249 | */ |
| 250 | public static function print_element_attribute( $customizer, $args ) { |
| 251 | if ( $customizer ) { |
| 252 | return ' :' . $args['attr'] . '="' . $args['vue_content'] . '"'; |
| 253 | } |
| 254 | if( ( isset( $args['php_condition'] ) && $args['php_condition'] ) || !isset( $args['php_condition'] ) ){ |
| 255 | return ' ' . sanitize_key( $args['attr'] ) . '="' . esc_attr( $args['php_content'] ) . '"'; |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * Print Element HTML Attribute |
| 261 | * |
| 262 | * @param bool $customizer |
| 263 | * @param array $args |
| 264 | * |
| 265 | * @return string |
| 266 | * |
| 267 | * @since 2.0 |
| 268 | */ |
| 269 | public static function get_element_attribute( $element, $settings ) { |
| 270 | $customizer = ctf_doing_customizer( $settings ); |
| 271 | if( $customizer ){ |
| 272 | switch ($element) { |
| 273 | case 'author': |
| 274 | return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_author)'); |
| 275 | break; |
| 276 | case 'avatar': |
| 277 | return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_author) && $parent.valueIsEnabled($parent.customizerFeedData.settings.include_avatar)'); |
| 278 | break; |
| 279 | case 'author_text': |
| 280 | return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_author) && $parent.valueIsEnabled($parent.customizerFeedData.settings.include_author_text)'); |
| 281 | break; |
| 282 | case 'date': |
| 283 | return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_date)'); |
| 284 | break; |
| 285 | case 'logo': |
| 286 | return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_logo)'); |
| 287 | break; |
| 288 | case 'text_and_link': |
| 289 | return CTF_Display_Elements::create_condition_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_text) && $parent.valueIsEnabled($parent.customizerFeedData.settings.linktexttotwitter)'); |
| 290 | break; |
| 291 | case 'text_no_link': |
| 292 | return CTF_Display_Elements::create_condition_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_text) && !$parent.valueIsEnabled($parent.customizerFeedData.settings.linktexttotwitter)'); |
| 293 | break; |
| 294 | case 'linkbox': |
| 295 | return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_linkbox)'); |
| 296 | break; |
| 297 | case 'media': |
| 298 | return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_media)'); |
| 299 | break; |
| 300 | case 'repliedto': |
| 301 | return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_replied_to)'); |
| 302 | break; |
| 303 | case 'retweeter': |
| 304 | return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_retweeter)'); |
| 305 | break; |
| 306 | case 'loadmore': |
| 307 | return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.showbutton) && $parent.customizerFeedData.settings.layout !== \'carousel\' ') . ' ' . CTF_Display_Elements::should_print_element_vue( $customizer, '$parent.customizerFeedData.settings.buttontext' ); |
| 308 | break; |
| 309 | case 'headerbio': |
| 310 | return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.showbio)'); |
| 311 | break; |
| 312 | case 'header': |
| 313 | return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.showheader) && $parent.customizerFeedData.settings.headerstyle === \'standard\' '); |
| 314 | break; |
| 315 | case 'header-text': |
| 316 | return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.showheader) && $parent.customizerFeedData.settings.headerstyle === \'text\' ') . ' ' . CTF_Display_Elements::should_print_element_vue( $customizer, '$parent.customizerFeedData.settings.customheadertext' ); |
| 317 | break; |
| 318 | case 'actions': |
| 319 | return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.include_actions)'); |
| 320 | break; |
| 321 | case 'viewtwitterlink': |
| 322 | return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.valueIsEnabled($parent.customizerFeedData.settings.viewtwitterlink)'); |
| 323 | break; |
| 324 | case 'viewtwitterlink_text': |
| 325 | return CTF_Display_Elements::should_print_element_vue( $customizer, '$parent.customizerFeedData.settings.twitterlinktext' ); |
| 326 | break; |
| 327 | case 'twitter_cards': |
| 328 | return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.customizerFeedData.settings.include_twittercards' ); |
| 329 | break; |
| 330 | case 'linkto': |
| 331 | return CTF_Display_Elements::create_condition_show_vue( $customizer, '$parent.customizerFeedData.settings.linktexttotwitter' ); |
| 332 | break; |
| 333 | |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | return ''; |
| 338 | } |
| 339 | |
| 340 | |
| 341 | /** |
| 342 | * Should Show Element |
| 343 | * |
| 344 | * @param array $settings |
| 345 | * @param string $setting_name |
| 346 | * @param bool $custom_condition |
| 347 | * |
| 348 | * @return string |
| 349 | * |
| 350 | * @since 2.0 |
| 351 | */ |
| 352 | public static function get_feed_container_data_attributes( $settings, $feed_id, $twitter_feed_id ) { |
| 353 | $customizer = ctf_doing_customizer( $settings ); |
| 354 | |
| 355 | $atts = CTF_Display_Elements::print_element_attribute( |
| 356 | $customizer, |
| 357 | array( |
| 358 | 'attr' => 'data-ctfdisablelinks', |
| 359 | 'vue_content' => '$parent.customizerFeedData.settings.disablelinks', |
| 360 | 'php_content' => self::cast_boolean($settings['disablelinks']) ? 'true' : 'false', |
| 361 | ) |
| 362 | ); |
| 363 | |
| 364 | $atts .= CTF_Display_Elements::print_element_attribute( |
| 365 | $customizer, |
| 366 | array( |
| 367 | 'attr' => 'data-ctflinktextcolor', |
| 368 | 'vue_content' => '$parent.customizerFeedData.settings.linktextcolor', |
| 369 | 'php_content' => $settings['linktextcolor'], |
| 370 | ) |
| 371 | ); |
| 372 | /* |
| 373 | |
| 374 | $atts .= CTF_Display_Elements::print_element_attribute( |
| 375 | $customizer, |
| 376 | array( |
| 377 | 'attr' => 'data-ctfscrolloffset', |
| 378 | 'vue_content' => '$parent.valueIsEnabled($parent.customizerFeedData.settings.autoscroll) ? $parent.customizerFeedData.settings.autoscrolldistance : false', |
| 379 | 'php_condition' => CTF_Feed_Builder::check_if_on( $settings['autoscroll'] ), |
| 380 | 'php_content' => $settings['autoscrolldistance'], |
| 381 | ) |
| 382 | ); |
| 383 | */ |
| 384 | /* |
| 385 | */ |
| 386 | |
| 387 | $atts .= CTF_Display_Elements::print_element_attribute( |
| 388 | $customizer, |
| 389 | array( |
| 390 | 'attr' => 'data-boxshadow', |
| 391 | 'vue_content' => ' $parent.customizerFeedData.settings.tweetpoststyle === \'boxed\' && $parent.valueIsEnabled($parent.customizerFeedData.settings.tweetboxshadow) ? \'true\' : \'false\' ', |
| 392 | 'php_condition' => $settings['tweetpoststyle'] === 'boxed' && CTF_Feed_Builder::check_if_on( $settings['tweetboxshadow'] ), |
| 393 | 'php_content' => "true", |
| 394 | ) |
| 395 | ); |
| 396 | $atts .= CTF_Display_Elements::print_element_attribute( |
| 397 | $customizer, |
| 398 | array( |
| 399 | 'attr' => 'data-header-size', |
| 400 | 'vue_content' => '$parent.customizerFeedData.settings.customheadersize', |
| 401 | 'php_content' => $settings['customheadersize'], |
| 402 | ) |
| 403 | ); |
| 404 | |
| 405 | //Global Feed Atts |
| 406 | $atts .= ' data-feedid="' . esc_attr($feed_id) . '" data-postid="' . esc_attr(get_the_ID()) . '" '; |
| 407 | if ( ! empty( $settings['feed'] ) ) { |
| 408 | $atts .= ' data-feed="' . esc_attr($settings['feed']) . '"'; |
| 409 | } |
| 410 | $flags = array(); |
| 411 | $dbsettings = ctf_get_database_settings(); |
| 412 | |
| 413 | if ( CTF_GDPR_Integrations::doing_gdpr( $dbsettings ) ) { |
| 414 | $flags[] = 'gdpr'; |
| 415 | } |
| 416 | if ( !is_admin() && CTF_Feed_Locator::should_do_ajax_locating( $twitter_feed_id , get_the_ID() ) ) { |
| 417 | $flags[] = 'locator'; |
| 418 | } |
| 419 | if (!empty($flags)) { |
| 420 | $atts .= ' data-ctf-flags="' . implode(',', $flags) . '"'; |
| 421 | } |
| 422 | |
| 423 | return $atts; |
| 424 | } |
| 425 | |
| 426 | |
| 427 | public static function cast_boolean( $value ) { |
| 428 | if ( $value === 'true' || $value === true || $value === 'on' ) { |
| 429 | return true; |
| 430 | } |
| 431 | return false; |
| 432 | } |
| 433 | |
| 434 | |
| 435 | /** |
| 436 | * Get Post Date TExt Attribure |
| 437 | * |
| 438 | * |
| 439 | * @return string |
| 440 | * |
| 441 | * @since 2.0 |
| 442 | */ |
| 443 | public static function get_post_date_attr($created_at, $settings ) { |
| 444 | $customizer = ctf_doing_customizer( $settings ); |
| 445 | return CTF_Display_Elements::should_print_element_vue( $customizer, '$parent.printDate(\''.$created_at.'\')' ); |
| 446 | } |
| 447 | /** |
| 448 | * Some characters in captions are breaking the customizer. |
| 449 | * |
| 450 | * @param $caption |
| 451 | * |
| 452 | * @return mixed |
| 453 | */ |
| 454 | public static function sanitize_caption( $caption ) { |
| 455 | // Decode the apostrophe entity (esc_html now produces it) before the quote |
| 456 | // replacement below so it degrades to a backtick like a literal apostrophe, |
| 457 | // instead of the historical "/" substitution (SMASH-1796). |
| 458 | $caption = str_replace( ''', "'", $caption ); |
| 459 | $caption = str_replace( array( "'" ), '`', $caption ); |
| 460 | $caption = str_replace( '&', '&', $caption ); |
| 461 | $caption = str_replace( '<', '<', $caption ); |
| 462 | $caption = str_replace( '>', '>', $caption ); |
| 463 | $caption = str_replace( '"', '"', $caption ); |
| 464 | $caption = str_replace( '\', '\/', $caption ); |
| 465 | |
| 466 | $caption = str_replace( array( "\r", "\n" ), '<br>', $caption ); |
| 467 | $caption = str_replace( '<br />', '<br>', nl2br( $caption ) ); |
| 468 | |
| 469 | return $caption; |
| 470 | } |
| 471 | /** |
| 472 | * Get Post Text Attributes |
| 473 | * |
| 474 | * |
| 475 | * @return string |
| 476 | * |
| 477 | * @since 2.0 |
| 478 | */ |
| 479 | public static function get_post_text_attr( $post_text, $settings, $post_id ) { |
| 480 | $customizer = ctf_doing_customizer( $settings ); |
| 481 | if( $customizer ){ |
| 482 | $post_text = self::sanitize_caption( $post_text ); |
| 483 | return ' v-html="$parent.getPostText(\'' . htmlspecialchars( $post_text ) . '\', ' . $post_id . ')"'; |
| 484 | } |
| 485 | return ''; |
| 486 | } |
| 487 | |
| 488 | public static function post_text( $post, $feed_options ) { |
| 489 | $text = isset($post['text']) ? $post['text'] : (isset($post['full_text']) ? $post['full_text'] : ''); |
| 490 | // Escaped here, ahead of the filter chain: ctf_maybe_shorten_text() is a |
| 491 | // ctf_tweet_text filter that INJECTS the read-more anchor into this value, so |
| 492 | // escaping at the sink instead would render the plugin's own markup as text |
| 493 | // and permanently satisfy the !$ctfText.find('a').length guard (SMASH-1796). |
| 494 | $text = esc_html( $text ); |
| 495 | $post_text = apply_filters( 'ctf_tweet_text', $text, $feed_options, $post ); |
| 496 | |
| 497 | return $post_text; |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * Get Post Text |
| 502 | * |
| 503 | * |
| 504 | * @return string |
| 505 | * |
| 506 | * @since 2.0 |
| 507 | */ |
| 508 | public static function get_post_text( $feed_options, $post_text, $post_id, $author_screen_name, $post_media_text ) { |
| 509 | $customizer = ctf_doing_customizer( $feed_options ); |
| 510 | $post_text_attr = CTF_Display_Elements::get_post_text_attr( $post_text, $feed_options, $post_id ); |
| 511 | $text_and_link_attr = CTF_Display_Elements::get_element_attribute( 'text_and_link', $feed_options ); |
| 512 | $text_no_link_attr = CTF_Display_Elements::get_element_attribute( 'text_no_link', $feed_options ); |
| 513 | if( !$customizer ){ |
| 514 | // a11y: ctf_maybe_shorten_text injects the read-more <button> + .ctf_remaining |
| 515 | // span into the tweet text; keep them out of the tweet-text anchor so no |
| 516 | // interactive control is nested inside a link (WCAG 4.1.2). |
| 517 | $read_more_markup = ''; |
| 518 | if ( $feed_options['linktexttotwitter'] ) { |
| 519 | $read_more_pos = strpos( $post_text, '<button type="button" class="ctf_more"' ); |
| 520 | if ( false !== $read_more_pos ) { |
| 521 | $read_more_markup = substr( $post_text, $read_more_pos ); |
| 522 | $post_text = substr( $post_text, 0, $read_more_pos ); |
| 523 | } |
| 524 | } |
| 525 | ?> |
| 526 | <p class="ctf-tweet-text"> |
| 527 | <?php if( $feed_options['linktexttotwitter'] ){ ?> |
| 528 | <a class="ctf-tweet-text-link" href="<?php echo esc_url( 'https://twitter.com/' . $author_screen_name . '/status/' .$post_id ) ?>" target = "_blank" rel = "noopener noreferrer"> |
| 529 | <?php } ?> |
| 530 | <?php echo wp_kses_post( nl2br( $post_text ) ) ?> |
| 531 | <?php |
| 532 | if(!$feed_options['is_legacy'] || ($feed_options['is_legacy'] && ctf_show( 'placeholder', $feed_options ))){ |
| 533 | echo $post_media_text; |
| 534 | } |
| 535 | ?> |
| 536 | <?php if( $feed_options['linktexttotwitter'] ){ ?> |
| 537 | </a><?php echo wp_kses_post( nl2br( $read_more_markup ) ); ?> |
| 538 | <?php } ?> |
| 539 | </p> |
| 540 | <?php |
| 541 | }else{ |
| 542 | ?> |
| 543 | <a class="ctf-tweet-text-link" <?php echo $text_and_link_attr; ?> href="<?php echo esc_url( 'https://twitter.com/' . $author_screen_name . '/status/' .$post_id ) ?>" target = "_blank" rel = "noopener noreferrer"> |
| 544 | <p class="ctf-tweet-text" <?php echo $post_text_attr; ?>></p> |
| 545 | </a> |
| 546 | <p class="ctf-tweet-text" <?php echo $text_no_link_attr; ?> <?php echo $post_text_attr; ?>><?php echo wp_kses_post( nl2br( $post_text ) ) ?></p> |
| 547 | <?php |
| 548 | if(!$feed_options['is_legacy'] || ($feed_options['is_legacy'] && ctf_show( 'placeholder', $feed_options ))){ |
| 549 | echo $post_media_text; |
| 550 | } |
| 551 | ?> |
| 552 | <?php |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | public static function get_ajax_code( $feed_options ) { |
| 557 | $json_array = array( |
| 558 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 559 | 'font_method' => 'svg', |
| 560 | 'placeholder' => trailingslashit( CTF_PLUGIN_URL ) . 'img/placeholder.png' |
| 561 | ); |
| 562 | return '<script> var ctfOptions = ' . ctf_json_encode( $json_array ) . '</script><script type="text/javascript" src="'. CTF_JS_URL .'"></script>'; |
| 563 | } |
| 564 | |
| 565 | public static function display_action_links( $feed_options ) { |
| 566 | return ctf_show( 'actions', $feed_options ) || (isset($feed_options['is_legacy']) && $feed_options['is_legacy'] == true); |
| 567 | } |
| 568 | |
| 569 | } |
| 570 |