Plugin Directory

Changeset 3287274


Ignore:
Timestamp:
05/04/2025 06:21:03 PM (7 months ago)
Author:
vapvarun
Message:

version update

Location:
activity-link-preview-for-buddypress
Files:
15 added
3 edited

Legend:

Unmodified
Added
Removed
  • activity-link-preview-for-buddypress/trunk/assets/js/bp-activity-link-preview.js

    r3215087 r3287274  
    66    // $(document).ready(function(){
    77
    8         jQuery(document).ajaxComplete(function(event, xhr, settings) {
    9             const params = new URLSearchParams(settings.data);
    10             const parsedData = Object.fromEntries(params.entries());
    11             if (parsedData.action.includes('activity_filter')) {
    12                 setTimeout(() => {
    13                     $(document).find( ".twitter-post" ).each(function( index, element ) {
     8    jQuery(document).ajaxComplete(function (event, xhr, settings) {
     9        const params = new URLSearchParams(settings.data);
     10        const parsedData = Object.fromEntries(params.entries());
     11        if (parsedData.action.includes('activity_filter')) {
     12            setTimeout(() => {
     13                $(document).find(".activity-link-preview-container").each(function (index, element) {
     14                    var url = $(element).data("url");
     15                    if (undefined != url) {
     16                        const tweetIdMatch = url.match(/status\/(\d+)/);
     17                        var tweetId = '';
     18                        if (tweetIdMatch && tweetIdMatch[1]) {
     19                            tweetId = tweetIdMatch[1]; // Return the matched tweet ID
     20                        }
     21                        twttr.widgets.createTweet(
     22                            tweetId,
     23                            element,
     24                            {
     25                                theme: 'light'
     26                            }
     27                        );
     28                    }
     29
     30                });
     31
     32                if (typeof FB !== 'undefined') {
     33                    FB.XFBML.parse();
     34                } else {
     35                    console.error('Facebook SDK not loaded.');
     36                }
     37            }, 200);
     38        } else if (parsedData.action.includes('post_update')) {
     39            setTimeout(() => {
     40                $(document).find(".activity-link-preview-container").each(function (index, element) {
     41                    if (0 === index) {
    1442                        var url = $(element).data("url");
    15                         if( undefined != url){
    16                         const tweetIdMatch = url.match(/status\/(\d+)/);
     43                        if (undefined != url) {
     44                            const tweetIdMatch = url.match(/status\/(\d+)/);
    1745                            var tweetId = '';
    1846                            if (tweetIdMatch && tweetIdMatch[1]) {
     
    2351                                element,
    2452                                {
    25                                   theme: 'light'
    26                                 }
    27                               );
    28                         }
    29                     });
    30 
    31                     if (typeof FB !== 'undefined') {
    32                         FB.XFBML.parse();
    33                         } else {
    34                             console.error('Facebook SDK not loaded.');
    35                         }
    36                 }, 200);
    37             }
    38         });
    39        
    40         $(document).ready(function(){
    41 
    42             var parentElement = $(document).find("whats-new-submit").find("input[type='submit']");
    43             $(document).on('click',parentElement,function(){
    44                 setTimeout(() => {
    45                     $(document).find( ".activity-link-preview-container" ).each(function( index, element ) {
    46                         var url = $(element).data("url");
    47                         if( undefined != url){
    48                         const tweetIdMatch = url.match(/status\/(\d+)/);
    49                             var tweetId = '';
    50                             if (tweetIdMatch && tweetIdMatch[1]) {
    51                                 tweetId = tweetIdMatch[1]; // Return the matched tweet ID
    52                             }
    53                             twttr.widgets.createTweet(
    54                                 tweetId,
    55                                 element,
    56                                 {
    57                                 theme: 'light'
     53                                    theme: 'light'
    5854                                }
    5955                            );
    6056                        }
    61                     });
    62 
    63                     if (typeof FB !== 'undefined') {
    64                         FB.XFBML.parse();
    65                     } else {
    66                         console.error('Facebook SDK not loaded.');
     57
    6758                    }
    68                 }, 200);
    69             })
    70 
    71         })
    72        
     59
     60                });
     61
     62                if (typeof FB !== 'undefined') {
     63                    FB.XFBML.parse();
     64                } else {
     65                    console.error('Facebook SDK not loaded.');
     66                }
     67            }, 200);
     68
     69        }
     70    });
     71
    7372    // })
    7473
     
    136135
    137136
    138            
     137
    139138            if (!urlResponse) {
    140139                loadURLAjax = jQuery.post(ajaxurl, {
     
    201200            image_nav = 'display:none;';
    202201        }
    203         var link_preview = '<div class="activity-url-scrapper-container error"><div class="activity-link-preview-container"><p class="activity-link-preview-title">' + title + '</p><div id="activity-url-scrapper-img-holder" style="' + image_nav + '"><div class="activity-link-preview-image"><img src="' + image + '"><a title="Cancel Preview Image" href="#" id="activity-link-preview-close-image"><i class="dashicons dashicons-no-alt"></i></a></div><div class="activity-url-thumb-nav"><button type="button" id="activity-url-prevPicButton"><span class="dashicons dashicons-arrow-left-alt2"></span></button><button type="button" id="activity-url-nextPicButton"><span class="dashicons dashicons-arrow-right-alt2"></span></button><div id="activity-url-scrapper-img-count">Image 1&nbsp;of&nbsp;' + image_count + '</div></div></div><div class="activity-link-preview-excerpt"><p>' + description + '</p></div><a title="Cancel Preview" href="#" id="activity-close-link-suggestion"><i class="dashicons dashicons-no-alt"></i></a></div><div class="bp-link-preview-hidden"><input type="hidden" name="link_url" value="' + url + '" /><input type="hidden" name="link_title" value="' + title + '" /><input type="hidden" name="link_description" value="' + escapeHtml(description) + '" /><input type="hidden" name="link_image" value="' + image + '" /></div></div>';
     202        var link_preview = '<div class="activity-url-scrapper-container"><div class="activity-link-preview-container"><p class="activity-link-preview-title">' + title + '</p><div id="activity-url-scrapper-img-holder" style="' + image_nav + '"><div class="activity-link-preview-image"><img src="' + image + '"><a title="Cancel Preview Image" href="#" id="activity-link-preview-close-image"><i class="dashicons dashicons-no-alt"></i></a></div><div class="activity-url-thumb-nav"><button type="button" id="activity-url-prevPicButton"><span class="dashicons dashicons-arrow-left-alt2"></span></button><button type="button" id="activity-url-nextPicButton"><span class="dashicons dashicons-arrow-right-alt2"></span></button><div id="activity-url-scrapper-img-count">Image 1&nbsp;of&nbsp;' + image_count + '</div></div></div><div class="activity-link-preview-excerpt"><p>' + description + '</p></div><a title="Cancel Preview" href="#" id="activity-close-link-suggestion"><i class="dashicons dashicons-no-alt"></i></a></div><div class="bp-link-preview-hidden"><input type="hidden" name="link_url" value="' + url + '" /><input type="hidden" name="link_title" value="' + title + '" /><input type="hidden" name="link_description" value="' + escapeHtml(description) + '" /><input type="hidden" name="link_image" value="' + image + '" /></div></div>';
    204203
    205204        $('#whats-new-attachments .activity-url-scrapper-container').remove();
    206205        $('#whats-new-attachments').append(link_preview);
    207         if(url.includes('x.com')){
     206        if (url.includes('x.com')) {
    208207            const tweetIdMatch = url.match(/status\/(\d+)/);
    209208            var tweetId = '';
     
    216215                $(document).find(".activity-link-preview-container")[0],
    217216                {
    218                   theme: 'light'
     217                    theme: 'light'
    219218                }
    220               );
    221         }
    222         if(url.includes('facebook.com')){
    223             $($(document).find(".activity-link-preview-container")[0]).html('<a title="Cancel Preview" href="#" id="activity-close-link-suggestion"><i class="dashicons dashicons-no-alt"></i></a><div class="fb-post" data-href="'+url+'" data-width="500" data-height="500"></div>');
    224               if (typeof FB !== 'undefined') {
     219            );
     220        }
     221        if (url.includes('facebook.com')) {
     222            $($(document).find(".activity-link-preview-container")[0]).html('<a title="Cancel Preview" href="#" id="activity-close-link-suggestion"><i class="dashicons dashicons-no-alt"></i></a><div class="fb-post" data-href="' + url + '" data-width="500" data-height="500"></div>');
     223            if (typeof FB !== 'undefined') {
    225224                FB.XFBML.parse();
    226                 } else {
    227                     console.error('Facebook SDK not loaded.');
    228                 }
     225            } else {
     226                console.error('Facebook SDK not loaded.');
     227            }
    229228        }
    230229    }
     
    232231
    233232    var escapeHtml = function (text) {
    234         if( ! text ){
     233        if (!text) {
    235234            return text;
    236235        }
    237             return text
     236        return text
    238237            .replace(/&/g, "&amp;")
    239238            .replace(/</g, "&lt;")
     
    293292
    294293
    295         var link_preview = '<div class="activity-url-scrapper-container error"><div class="activity-link-preview-container"><p class="activity-link-preview-title">' + title + '</p><div id="activity-url-scrapper-img-holder"><div class="activity-link-preview-image"><img src="' + image + '"><a title="Cancel Preview Image" href="#" id="activity-link-preview-close-image"><i class="dashicons dashicons-no-alt"></i></a></div><div class="activity-url-thumb-nav"><button type="button" id="activity-url-prevPicButton"><span class="dashicons dashicons-arrow-left-alt2"></span></button><button type="button" id="activity-url-nextPicButton"><span class="dashicons dashicons-arrow-right-alt2"></span></button><div id="activity-url-scrapper-img-count">Image ' + (link_image_index + 1) + '&nbsp;of&nbsp;' + image_count + '</div></div></div><div class="activity-link-preview-excerpt"><p>' + description + '</p></div><a title="Cancel Preview" href="#" id="activity-close-link-suggestion"><i class="dashicons dashicons-no-alt"></i></a></div><div class="bp-link-preview-hidden"><input type="hidden" name="link_url" value="' + url + '" /><input type="hidden" name="link_title" value="' + title + '" /><input type="hidden" name="link_description" value="' + escapeHtml(description) + '" /><input type="hidden" name="link_image" value="' + image + '" /></div></div>';
     294        var link_preview = '<div class="activity-url-scrapper-container"><div class="activity-link-preview-container"><p class="activity-link-preview-title">' + title + '</p><div id="activity-url-scrapper-img-holder"><div class="activity-link-preview-image"><img src="' + image + '"><a title="Cancel Preview Image" href="#" id="activity-link-preview-close-image"><i class="dashicons dashicons-no-alt"></i></a></div><div class="activity-url-thumb-nav"><button type="button" id="activity-url-prevPicButton"><span class="dashicons dashicons-arrow-left-alt2"></span></button><button type="button" id="activity-url-nextPicButton"><span class="dashicons dashicons-arrow-right-alt2"></span></button><div id="activity-url-scrapper-img-count">Image ' + (link_image_index + 1) + '&nbsp;of&nbsp;' + image_count + '</div></div></div><div class="activity-link-preview-excerpt"><p>' + description + '</p></div><a title="Cancel Preview" href="#" id="activity-close-link-suggestion"><i class="dashicons dashicons-no-alt"></i></a></div><div class="bp-link-preview-hidden"><input type="hidden" name="link_url" value="' + url + '" /><input type="hidden" name="link_title" value="' + title + '" /><input type="hidden" name="link_description" value="' + escapeHtml(description) + '" /><input type="hidden" name="link_image" value="' + image + '" /></div></div>';
    296295
    297296        $('#whats-new-attachments .activity-url-scrapper-container').remove();
  • activity-link-preview-for-buddypress/trunk/bp-activity-link-preview.php

    r3215087 r3287274  
    66 * Plugin URI:        https://wbcomdesigns.com/downloads/buddypress-activity-link-preview/
    77 * Description:       BuddyPress activity link preview display as image title and description from the site When links are used in activity posts.
    8  * Version:           1.4.4
     8 * Version:           1.6.0
    99 * Author:            wbcomdesigns
    1010 * Author URI:        https://wbcomdesigns.com/
     
    3131add_action( 'wp_enqueue_scripts', 'bp_activity_link_preview_enqueue_scripts' );
    3232
     33
    3334/** Bp_activity_parse_url_preview */
    3435function bp_activity_parse_url_preview() {
    3536
     37    // Check if user is logged in
     38    if ( ! is_user_logged_in() ) {
     39        wp_send_json( array( 'error' => __( 'You must be logged in to perform this action.', 'buddypress-activity-link-preview' ) ) );
     40    }
    3641    // Get URL.
    37     $url = ! empty( $_POST['url'] ) ? filter_var( $_POST['url'], FILTER_VALIDATE_URL ) : '';// phpcs:ignore
     42    $url = ! empty( $_POST['url'] ) ? filter_var( $_POST['url'], FILTER_VALIDATE_URL ) : '';// phpcs:ignore
    3843
    3944    // Check if URL is validated.
    4045    if ( ! filter_var( $url, FILTER_VALIDATE_URL ) ) {
    41         wp_send_json( array( 'error' => __( 'URL is not valid.', 'buddypress-activity-link-preview' ) ) );
    42     }
    43         $parse_url_data = bp_activity_link_parse_url( $url );
    44    
     46        wp_send_json( array( 'error' => __( 'The URL you entered is not valid.', 'buddypress-activity-link-preview' ) ) );
     47    }
     48
     49    // Parse URL to get host
     50    $parsed_url = parse_url( $url );
     51    $host       = isset( $parsed_url['host'] ) ? $parsed_url['host'] : '';
     52
     53    // Block requests to private/internal IP ranges and localhost
     54    if ( empty( $host ) ||
     55        ( filter_var( $host, FILTER_VALIDATE_IP ) &&
     56        ( filter_var( $host, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) === false ) ) ||
     57        $host === '127.0.0.1' ||
     58        $host === 'localhost' ||
     59        preg_match( '/^(10\.|172\.(1[6-9]|2[0-9]|3[0-1])\.|192\.168\.)/', $host )
     60    ) {
     61        wp_send_json( array( 'error' => __( 'This URL cannot be previewed for security reasons.', 'buddypress-activity-link-preview' ) ) );
     62    }
     63
     64    $parse_url_data = bp_activity_link_parse_url( $url );
     65
    4566    // If empty data then send error.
    4667    if ( empty( $parse_url_data ) ) {
    47         wp_send_json( array( 'error' => __( 'Sorry! preview is not available right now. Please try again later.', 'buddypress-activity-link-preview' ) ) );
    48     }
     68        wp_send_json( array( 'error' => __( 'Sorry! Preview is not available right now. Please try again later.', 'buddypress-activity-link-preview' ) ) );
     69    }
     70
     71    // Apply filter to allow modification of parsed data
     72    $parse_url_data = apply_filters( 'bp_activity_parse_url_preview', $parse_url_data, $url );
    4973
    5074    // send json success.
     
    6185 */
    6286function bp_activity_link_parse_url( $url ) {
    63     $cache_key = 'bp_activity_oembed_' . md5( serialize( $url ) );
     87
     88    $parse_url_data = wp_parse_url( $url, PHP_URL_HOST );
     89    $original_url   = $url;
     90
     91    if ( in_array( $parse_url_data, apply_filters( 'bp_activity_link_parse_url_shorten_url_provider', array( 'bit.ly', 'snip.ly', 'rb.gy', 'tinyurl.com', 'tiny.one', 'rotf.lol', 'b.link', '4ubr.short.gy', '' ) ), true ) ) {
     92        $response = wp_safe_remote_get(
     93            $url,
     94            array(
     95                'stream'  => true,
     96                'headers' => array(
     97                    'user-agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:71.0) Gecko/20100101 Firefox/71.0',
     98                ),
     99            ),
     100        );
     101
     102        if ( ! is_wp_error( $response ) && ! empty( $response['http_response']->get_response_object()->url ) && $response['http_response']->get_response_object()->url !== $url ) {
     103            $new_url = $response['http_response']->get_response_object()->url;
     104            if ( filter_var( $new_url, FILTER_VALIDATE_URL ) ) {
     105                $url = $new_url;
     106            }
     107        }
     108
     109        if ( $original_url === $url ) {
     110            $context = array(
     111                'http' => array(
     112                    'method'        => 'GET',
     113                    'max_redirects' => 1,
     114                ),
     115            );
     116
     117            @file_get_contents( $url, null, stream_context_create( $context ) );
     118            if ( isset( $http_response_header ) && isset( $http_response_header[6] ) ) {
     119                $new_url = str_replace( 'Location: ', '', $http_response_header[6] );
     120                if ( filter_var( $new_url, FILTER_VALIDATE_URL ) ) {
     121                    $url = $new_url;
     122                }
     123            }
     124        }
     125    }
     126
     127    $cache_key = 'bp_oembed_' . md5( maybe_serialize( $url ) );
     128
    64129    // get transient data for url.
    65130    $parsed_url_data = get_transient( $cache_key );
     
    67132        return $parsed_url_data;
    68133    }
     134
    69135    $parsed_url_data = array();
     136
     137    if ( strstr( $url, site_url() ) && ( strstr( $url, 'download_document_file' ) || strstr( $url, 'download_media_file' ) || strstr( $url, 'download_video_file' ) ) ) {
     138        return array();
     139    }
     140
     141    if ( ! function_exists( '_wp_oembed_get_object' ) ) {
     142        require ABSPATH . WPINC . '/class-oembed.php';
     143    }
     144
     145    $embed_code = '';
     146    $oembed_obj = _wp_oembed_get_object();
     147    $discover   = apply_filters( 'bp_oembed_discover_support', false, $url );
     148    $is_oembed  = $oembed_obj->get_data( $url, array( 'discover' => $discover ) );
     149
     150    if ( $is_oembed ) {
     151        $embed_code = wp_oembed_get( $url, array( 'discover' => $discover ) );
     152    }
     153
    70154    // Fetch the oembed code for URL.
    71     $embed_code = wp_oembed_get( $url, array( 'discover' => false ) );
    72 
    73     if ( ! empty( $embed_code ) || true === str_contains( $url , 'facebook') ) {
     155    if ( ! empty( $embed_code ) ) {
    74156        $parsed_url_data['title']       = ' ';
    75157        $parsed_url_data['description'] = $embed_code;
     
    78160        $parsed_url_data['wp_embed']    = true;
    79161    } else {
     162        $args = array( 'user-agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:71.0) Gecko/20100101 Firefox/71.0' );
     163
     164        if ( bp_is_same_site_url( $url ) ) {
     165            if ( ! bp_enable_private_network() ) {
     166                // Add the custom header with the JWT token.
     167                $args['headers'] = array(
     168                    'bb-preview-token' => bb_create_jwt(
     169                        array(
     170                            'url' => $url,
     171                            'iat' => time(),
     172                            'exp' => time() + 120, // Token validity 2 minutes.
     173                        )
     174                    ),
     175                );
     176            }
     177            $args['sslverify'] = false;
     178        }
    80179
    81180        // safely get URL and response body.
    82         $response = wp_safe_remote_get(
    83             $url,
    84             array(
    85                 'user-agent' => '', // Default value being blocked by Cloudflare.
    86             )
    87         );
     181        $response = wp_safe_remote_get( $url, $args );
    88182        $body     = wp_remote_retrieve_body( $response );
    89183
     
    93187            // Load HTML to DOM Object.
    94188            $dom = new DOMDocument();
    95             $dom->loadHTML( mb_convert_encoding( $body, 'HTML-ENTITIES', 'UTF-8' ) );
     189            @$dom->loadHTML( mb_convert_encoding( $body, 'HTML-ENTITIES', 'UTF-8' ) );
    96190
    97191            $meta_tags   = array();
     
    112206                foreach ( $meta_tags as $tag ) {
    113207                    if ( is_array( $tag ) && ! empty( $tag ) ) {
    114                         if ( 'og:title' === $tag[0] ) {
     208                        if ( $tag[0] == 'og:title' ) {
    115209                            $title = $tag[1];
    116210                        }
    117                         if ( 'og:description' === $tag[0] || 'description' === strtolower( $tag[0] ) ) {
     211                        if ( $tag[0] == 'og:description' || 'description' === strtolower( $tag[0] ) ) {
    118212                            $description = html_entity_decode( $tag[1], ENT_QUOTES, 'utf-8' );
    119213                        }
    120                         if ( 'og:image' === $tag[0] ) {
     214                        if ( $tag[0] == 'og:image' ) {
    121215                            $images[] = $tag[1];
    122216                        }
     
    128222            if ( empty( $title ) ) {
    129223                $nodes = $dom->getElementsByTagName( 'title' );
    130                 $title = $nodes->item( 0 )->nodeValue;
     224                $title = $nodes && $nodes->length > 0 ? $nodes->item( 0 )->nodeValue : '';
    131225            }
    132226
     
    134228            if ( empty( $description ) ) {
    135229                $metas = $dom->getElementsByTagName( 'meta' );
    136                 for ( $i = 0; $i < $metas->length; $i ++ ) {
     230                for ( $i = 0; $i < $metas->length; $i++ ) {
    137231                    $meta = $metas->item( $i );
    138232                    if ( 'description' === $meta->getAttribute( 'name' ) ) {
     
    142236                }
    143237            }
     238
    144239            // Parse DOM to get Images.
    145240            $image_elements = $dom->getElementsByTagName( 'img' );
    146             for ( $i = 0; $i < $image_elements->length; $i ++ ) {
     241            for ( $i = 0; $i < $image_elements->length; $i++ ) {
    147242                $image = $image_elements->item( $i );
    148243                $src   = $image->getAttribute( 'src' );
     
    178273        }
    179274    }
     275
    180276    if ( ! empty( $parsed_url_data ) ) {
    181277        // set the transient.
     
    186282     * Filters parsed URL data.
    187283     *
    188      * @since BuddyBoss 1.0.0
    189      * @param array $parsed_url_data Parse URL data.
     284     * @since 1.4.6
     285     *
     286     * * @param array $parsed_url_data Parse URL data.
    190287     */
    191288    return apply_filters( 'bp_activity_link_parse_url', $parsed_url_data );
     
    194291
    195292/**
     293 * Check if the requested URL is from same site.
     294 *
     295 * @since 1.4.6
     296 *
     297 * @param string $url URL to check.
     298 *
     299 * @return bool
     300 */
     301function bp_is_same_site_url( $url ) {
     302    $parsed_url = wp_parse_url( $url );
     303    $home_url   = wp_parse_url( home_url( '/' ) );
     304
     305    if ( ! empty( $parsed_url['host'] ) && ! empty( $parsed_url['scheme'] ) ) {
     306        return ( strtolower( $parsed_url['host'] ) === strtolower( $home_url['host'] ) ) && ( $parsed_url['scheme'] === $home_url['scheme'] );
     307    }
     308
     309    return false;
     310}
     311
     312/**
    196313 * Save link preview data into activity meta key "_bp_activity_link_preview_data"
    197314 *
     
    202319function bp_activity_link_preview_save_link_data( $activity ) {
    203320    $bp_activity_nonce = isset( $_POST['_wpnonce_post_update'] ) ? sanitize_text_field( wp_unslash( $_POST['_wpnonce_post_update'] ) ) : '';
    204     // Check for nonce security.   
    205     if ( $bp_activity_nonce != '' && ! wp_verify_nonce( $bp_activity_nonce, 'post_update' ) ) {
    206         die( 'Busted!' );
     321    // Check for nonce security.
     322    if ( empty( $bp_activity_nonce ) || ! wp_verify_nonce( $bp_activity_nonce, 'post_update' ) ) {
     323        die( 'Security check failed.' );
    207324    }
    208325    if ( isset( $_POST['link_url'] ) && isset( $_POST['link_title'] ) && isset( $_POST['link_description'] ) && isset( $_POST['link_image'] ) ) {
    209326
    210         $link_url         = ! empty( $_POST['link_url'] ) ? sanitize_text_field( wp_unslash( $_POST['link_url'] ) ) : '';
    211         $link_title       = ! empty( $_POST['link_title'] ) ? sanitize_text_field( wp_unslash( $_POST['link_title'] ) ) : '';
    212         $link_description = ! empty( $_POST['link_description'] ) ? sanitize_text_field( wp_unslash( $_POST['link_description'] ) ) : '';
    213         $link_image       = ! empty( $_POST['link_image'] ) ? sanitize_text_field( wp_unslash( $_POST['link_image'] ) ) : '';
    214 
     327        $link_url                 = ! empty( $_POST['link_url'] ) ? sanitize_text_field( wp_unslash( $_POST['link_url'] ) ) : '';
     328        $link_title               = ! empty( $_POST['link_title'] ) ? sanitize_text_field( wp_unslash( $_POST['link_title'] ) ) : '';
     329        $link_description         = ! empty( $_POST['link_description'] ) ? sanitize_text_field( wp_unslash( $_POST['link_description'] ) ) : '';
     330        $link_image               = ! empty( $_POST['link_image'] ) ? sanitize_text_field( wp_unslash( $_POST['link_image'] ) ) : '';
    215331        $link_preview_data['url'] = $link_url;
    216         if ( false !== strpos( $link_preview_data['url'] , 'www.reddit.com') ) {
    217             return ;
     332        if ( false !== strpos( $link_preview_data['url'], 'www.reddit.com' ) ) {
     333            return;
    218334        }
    219335        if ( ! empty( $link_image ) ) {
     
    259375        return $content;
    260376    }
    261     if( true === str_contains($preview_data['url'], 'x.com') ){
    262         $content = '<div class="twitter-post" data-url="'.$preview_data['url'].'"></div>';
    263     }elseif( true === str_contains($preview_data['url'], 'facebook.com') ){
    264         $content = '<div class="fb-post" data-href="'.$preview_data['url'].'" data-width="500" data-height="500"></div>';
    265     }else{
     377    if ( true === str_contains( $preview_data['url'], 'x.com' ) ) {
     378        $content .= '<div class="activity-link-preview-container" data-url="' . esc_attr( $preview_data['url'] ) . '"></div>';
     379    } elseif ( true === str_contains( $preview_data['url'], 'facebook.com' ) ) {
     380        $content .= '<div class="fb-post" data-href="' . esc_attr( $preview_data['url'] ) . '" data-width="500" data-height="500"></div>';
     381    } else {
    266382        $description = $preview_data['description'];
    267         $read_more   = ' &hellip; <a class="activity-link-preview-more" href="' . esc_url( $preview_data['url'] ) . '" target="_blank" rel="nofollow">' . __( 'Continue reading', 'buddypress-activity-link-preview' ) . '</a>';
     383        $read_more   = ' &hellip; <a class="activity-link-preview-more" href="' . esc_url( $preview_data['url'] ) . '" target="_blank" rel="nofollow">' . __( 'Read more', 'buddypress-activity-link-preview' ) . '</a>';
    268384        $description = wp_trim_words( $description, 40, $read_more );
    269    
     385
    270386        $content = make_clickable( $content );
    271    
     387
    272388        $content .= '<div class="activity-link-preview-container">';
    273389        $content .= '<p class="activity-link-preview-title"><a href="' . esc_url( $preview_data['url'] ) . '" target="_blank" rel="nofollow">' . esc_html( $preview_data['title'] ) . '</a></p>';
     
    280396        $content .= '</div>';
    281397    }
    282    
    283     return htmlspecialchars_decode($content);
     398
     399    return htmlspecialchars_decode( $content );
    284400}
    285401
     
    312428    echo '<div class="error"><p>';
    313429    /* translators: %s: */
    314     echo sprintf( esc_html__( '%1$s is ineffective as it requires %2$s to be installed and active.', 'buddypress-activity-link-preview' ), '<strong>' . esc_html( $bpquotes_plugin ) . '</strong>', '<strong>' . esc_html( $bp_plugin ) . '</strong>' );
     430    printf( esc_html__( '%1$s is ineffective because it requires %2$s to be installed and active.', 'buddypress-activity-link-preview' ), '<strong>' . esc_html( $bpquotes_plugin ) . '</strong>', '<strong>' . esc_html( $bp_plugin ) . '</strong>' );
    315431    echo '</p></div>';
    316432    if ( null !== filter_input( INPUT_GET, 'activate' ) ) {
     
    336452}
    337453
     454
     455/**
     456 * Outputs a Facebook root div element in specific BuddyPress contexts.
     457 *
     458 * This function checks if the current page is one of the following:
     459 * - The BuddyPress activity directory
     460 * - A BuddyPress group page
     461 * - A BuddyPress user activity page
     462 *
     463 * If any of these conditions are met, it echoes a `<div>` element with the ID `fb-root`.
     464 * This is typically required for Facebook SDK integration.
     465 *
     466 * @return void
     467 */
     468function bp_activity_link_preview_add_facebook_root_div() {
     469    if ( bp_is_activity_directory() || bp_is_group() || bp_is_user_activity() ) {
     470        echo '<div id="fb-root"></div>';
     471    }
     472}
    338473add_action( 'wp_head', 'bp_activity_link_preview_add_facebook_root_div' );
    339 function bp_activity_link_preview_add_facebook_root_div(){
    340     if( bp_is_activity_directory() || bp_is_group() || bp_is_user_activity() ){
    341         echo '<div id="fb-root"></div>';
    342     }
    343 }
  • activity-link-preview-for-buddypress/trunk/readme.txt

    r3215087 r3287274  
    44Tags: buddypress, Activity, Link Preview
    55Requires at least: 3.0.1
    6 Tested up to: 6.7.1
    7 Stable tag: 1.4.4
     6Tested up to: 6.8.0
     7Stable tag: 1.6.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3636
    3737== Changelog ==
     38
     39= 1.6.0 =
     40* Added: Filter and event hooks to extend the activity preview functionality.
     41* Fixed: Twitter card preview duplication issue in multiple activities.
     42* Fixed: Twitter preview incorrectly appended to the second activity.
     43* Fixed: Activity content not displaying when preview is enabled.
     44* Fixed: Iframe not rendering correctly in activity previews.
     45* Fixed: Preview not visible when sharing X (formerly Twitter) links.
     46* Fixed: Activity link preview index logic for accurate rendering.
     47* Improved: String labels and content clarity across the plugin.
     48* Security: Patched SSRF (Server Side Request Forgery) vulnerability in the URL parser.
     49* Security: Fixed XSS issues in link preview rendering to improve safety.
    3850
    3951= 1.4.4 =
Note: See TracChangeset for help on using the changeset viewer.