Changeset 3287274
- Timestamp:
- 05/04/2025 06:21:03 PM (7 months ago)
- Location:
- activity-link-preview-for-buddypress
- Files:
-
- 15 added
- 3 edited
-
tags/1.6.0 (added)
-
tags/1.6.0/.gitignore (added)
-
tags/1.6.0/assets (added)
-
tags/1.6.0/assets/css (added)
-
tags/1.6.0/assets/css/bp-activity-link-preview.css (added)
-
tags/1.6.0/assets/js (added)
-
tags/1.6.0/assets/js/bp-activity-link-preview.js (added)
-
tags/1.6.0/bp-activity-link-preview.php (added)
-
tags/1.6.0/gruntfile.js (added)
-
tags/1.6.0/languages (added)
-
tags/1.6.0/languages/bp-fav-notification.pot (added)
-
tags/1.6.0/package-lock.json (added)
-
tags/1.6.0/package.json (added)
-
tags/1.6.0/readme.txt (added)
-
tags/1.6.0/screenshot-1.png (added)
-
trunk/assets/js/bp-activity-link-preview.js (modified) (7 diffs)
-
trunk/bp-activity-link-preview.php (modified) (18 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
activity-link-preview-for-buddypress/trunk/assets/js/bp-activity-link-preview.js
r3215087 r3287274 6 6 // $(document).ready(function(){ 7 7 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) { 14 42 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+)/); 17 45 var tweetId = ''; 18 46 if (tweetIdMatch && tweetIdMatch[1]) { … … 23 51 element, 24 52 { 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' 58 54 } 59 55 ); 60 56 } 61 }); 62 63 if (typeof FB !== 'undefined') { 64 FB.XFBML.parse(); 65 } else { 66 console.error('Facebook SDK not loaded.'); 57 67 58 } 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 73 72 // }) 74 73 … … 136 135 137 136 138 137 139 138 if (!urlResponse) { 140 139 loadURLAjax = jQuery.post(ajaxurl, { … … 201 200 image_nav = 'display:none;'; 202 201 } 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 of ' + 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 of ' + 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>'; 204 203 205 204 $('#whats-new-attachments .activity-url-scrapper-container').remove(); 206 205 $('#whats-new-attachments').append(link_preview); 207 if (url.includes('x.com')){206 if (url.includes('x.com')) { 208 207 const tweetIdMatch = url.match(/status\/(\d+)/); 209 208 var tweetId = ''; … … 216 215 $(document).find(".activity-link-preview-container")[0], 217 216 { 218 theme: 'light'217 theme: 'light' 219 218 } 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') { 225 224 FB.XFBML.parse(); 226 } else {227 console.error('Facebook SDK not loaded.');228 }225 } else { 226 console.error('Facebook SDK not loaded.'); 227 } 229 228 } 230 229 } … … 232 231 233 232 var escapeHtml = function (text) { 234 if ( ! text ){233 if (!text) { 235 234 return text; 236 235 } 237 return text236 return text 238 237 .replace(/&/g, "&") 239 238 .replace(/</g, "<") … … 293 292 294 293 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) + ' of ' + 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) + ' of ' + 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>'; 296 295 297 296 $('#whats-new-attachments .activity-url-scrapper-container').remove(); -
activity-link-preview-for-buddypress/trunk/bp-activity-link-preview.php
r3215087 r3287274 6 6 * Plugin URI: https://wbcomdesigns.com/downloads/buddypress-activity-link-preview/ 7 7 * 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.48 * Version: 1.6.0 9 9 * Author: wbcomdesigns 10 10 * Author URI: https://wbcomdesigns.com/ … … 31 31 add_action( 'wp_enqueue_scripts', 'bp_activity_link_preview_enqueue_scripts' ); 32 32 33 33 34 /** Bp_activity_parse_url_preview */ 34 35 function bp_activity_parse_url_preview() { 35 36 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 } 36 41 // Get URL. 37 $url = ! empty( $_POST['url'] ) ? filter_var( $_POST['url'], FILTER_VALIDATE_URL ) : '';// phpcs:ignore42 $url = ! empty( $_POST['url'] ) ? filter_var( $_POST['url'], FILTER_VALIDATE_URL ) : '';// phpcs:ignore 38 43 39 44 // Check if URL is validated. 40 45 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 45 66 // If empty data then send error. 46 67 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 ); 49 73 50 74 // send json success. … … 61 85 */ 62 86 function 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 64 129 // get transient data for url. 65 130 $parsed_url_data = get_transient( $cache_key ); … … 67 132 return $parsed_url_data; 68 133 } 134 69 135 $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 70 154 // 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 ) ) { 74 156 $parsed_url_data['title'] = ' '; 75 157 $parsed_url_data['description'] = $embed_code; … … 78 160 $parsed_url_data['wp_embed'] = true; 79 161 } 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 } 80 179 81 180 // 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 ); 88 182 $body = wp_remote_retrieve_body( $response ); 89 183 … … 93 187 // Load HTML to DOM Object. 94 188 $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' ) ); 96 190 97 191 $meta_tags = array(); … … 112 206 foreach ( $meta_tags as $tag ) { 113 207 if ( is_array( $tag ) && ! empty( $tag ) ) { 114 if ( 'og:title' === $tag[0]) {208 if ( $tag[0] == 'og:title' ) { 115 209 $title = $tag[1]; 116 210 } 117 if ( 'og:description' === $tag[0]|| 'description' === strtolower( $tag[0] ) ) {211 if ( $tag[0] == 'og:description' || 'description' === strtolower( $tag[0] ) ) { 118 212 $description = html_entity_decode( $tag[1], ENT_QUOTES, 'utf-8' ); 119 213 } 120 if ( 'og:image' === $tag[0]) {214 if ( $tag[0] == 'og:image' ) { 121 215 $images[] = $tag[1]; 122 216 } … … 128 222 if ( empty( $title ) ) { 129 223 $nodes = $dom->getElementsByTagName( 'title' ); 130 $title = $nodes ->item( 0 )->nodeValue;224 $title = $nodes && $nodes->length > 0 ? $nodes->item( 0 )->nodeValue : ''; 131 225 } 132 226 … … 134 228 if ( empty( $description ) ) { 135 229 $metas = $dom->getElementsByTagName( 'meta' ); 136 for ( $i = 0; $i < $metas->length; $i ++ ) {230 for ( $i = 0; $i < $metas->length; $i++ ) { 137 231 $meta = $metas->item( $i ); 138 232 if ( 'description' === $meta->getAttribute( 'name' ) ) { … … 142 236 } 143 237 } 238 144 239 // Parse DOM to get Images. 145 240 $image_elements = $dom->getElementsByTagName( 'img' ); 146 for ( $i = 0; $i < $image_elements->length; $i ++ ) {241 for ( $i = 0; $i < $image_elements->length; $i++ ) { 147 242 $image = $image_elements->item( $i ); 148 243 $src = $image->getAttribute( 'src' ); … … 178 273 } 179 274 } 275 180 276 if ( ! empty( $parsed_url_data ) ) { 181 277 // set the transient. … … 186 282 * Filters parsed URL data. 187 283 * 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. 190 287 */ 191 288 return apply_filters( 'bp_activity_link_parse_url', $parsed_url_data ); … … 194 291 195 292 /** 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 */ 301 function 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 /** 196 313 * Save link preview data into activity meta key "_bp_activity_link_preview_data" 197 314 * … … 202 319 function bp_activity_link_preview_save_link_data( $activity ) { 203 320 $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.' ); 207 324 } 208 325 if ( isset( $_POST['link_url'] ) && isset( $_POST['link_title'] ) && isset( $_POST['link_description'] ) && isset( $_POST['link_image'] ) ) { 209 326 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'] ) ) : ''; 215 331 $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; 218 334 } 219 335 if ( ! empty( $link_image ) ) { … … 259 375 return $content; 260 376 } 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 { 266 382 $description = $preview_data['description']; 267 $read_more = ' … <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 = ' … <a class="activity-link-preview-more" href="' . esc_url( $preview_data['url'] ) . '" target="_blank" rel="nofollow">' . __( 'Read more', 'buddypress-activity-link-preview' ) . '</a>'; 268 384 $description = wp_trim_words( $description, 40, $read_more ); 269 385 270 386 $content = make_clickable( $content ); 271 387 272 388 $content .= '<div class="activity-link-preview-container">'; 273 389 $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>'; … … 280 396 $content .= '</div>'; 281 397 } 282 283 return htmlspecialchars_decode( $content);398 399 return htmlspecialchars_decode( $content ); 284 400 } 285 401 … … 312 428 echo '<div class="error"><p>'; 313 429 /* translators: %s: */ 314 echo sprintf( esc_html__( '%1$s is ineffective asit 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>' ); 315 431 echo '</p></div>'; 316 432 if ( null !== filter_input( INPUT_GET, 'activate' ) ) { … … 336 452 } 337 453 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 */ 468 function 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 } 338 473 add_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 4 4 Tags: buddypress, Activity, Link Preview 5 5 Requires at least: 3.0.1 6 Tested up to: 6. 7.17 Stable tag: 1. 4.46 Tested up to: 6.8.0 7 Stable tag: 1.6.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 36 36 37 37 == 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. 38 50 39 51 = 1.4.4 =
Note: See TracChangeset
for help on using the changeset viewer.