replace_aws_img_urls_from_activity

Replace aws url of image with the wordpress attachment url in buddypress activity.

Description

(string) replace_aws_img_urls_from_activity( (string) $html, (object) $rtmedia_media ); 

Returns (string)

Parameters (2)

0. $html (string)
The html.
1. $rtmedia_media (object)
The rtmedia media.

Usage

  1. if ( !function_exists( 'replace_aws_img_urls_from_activity' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'rtmedia-for-wordpress-buddypress-and-bbpress/app/main/controllers/template/rtmedia-filters.php'; 
  3.  
  4. // The html. 
  5. $html = ''; 
  6.  
  7. // The rtmedia media. 
  8. $rtmedia_media = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = replace_aws_img_urls_from_activity($html, $rtmedia_media); 
  12.  

Defined (1)

The function is defined in the following location(s).

/app/main/controllers/template/rtmedia-filters.php  
  1. function replace_aws_img_urls_from_activity( $html, $rtmedia_media ) { 
  2. if ( empty( $rtmedia_media ) ) { 
  3. return $html; 
  4. /** 
  5. * Allow users/plugins to prevent replacing of URL from activty 
  6. * @var boolean Boolean false is passed as a parameter. 
  7. * @var object $rtmedia_media Object ofrtmediacontaining media_id, media_type etc. 
  8. */ 
  9. if ( apply_filters( 'replace_aws_img_urls_from_activity', false, $rtmedia_media ) ) { 
  10. return $html; 
  11.  
  12. if ( empty( $rtmedia_media->media_id ) || empty( $rtmedia_media->media_type ) ) { 
  13. return $html; 
  14.  
  15. $media_type = $rtmedia_media->media_type; 
  16.  
  17. if ( 'image' === $media_type && ! empty( $rtmedia_media->guid ) ) { 
  18. /** 
  19. * Fix for rtAmazon S3 addon 
  20. * When rtAmazon S3 is disabled we need to restore/replace the attachment URLS with the 
  21. * original WordPress URL structure 
  22. */ 
  23. if ( ! class_exists( 'RTAWSS3_Class' ) && ! class_exists( 'AS3CF_Utils' ) ) { 
  24. /** for WordPress backward compatibility */ 
  25. if ( function_exists( 'wp_get_upload_dir' ) ) { 
  26. $uploads = wp_get_upload_dir(); 
  27. } else { 
  28. $uploads = wp_upload_dir(); 
  29.  
  30. $baseurl = $uploads['baseurl']; 
  31.  
  32. if ( 0 === strpos( $rtmedia_media->guid, $uploads['baseurl'] ) ) { 
  33. $thumbnail_url = $rtmedia_media->guid; 
  34. } else { 
  35.  
  36. $rtmedia_folder_name = apply_filters( 'rtmedia_upload_folder_name', rtMedia ); 
  37.  
  38. $thumbnail_url = explode( $rtmedia_folder_name , $rtmedia_media->guid ); 
  39.  
  40. if ( is_array( $thumbnail_url ) && ! empty( $thumbnail_url[1] ) ) { 
  41. $thumbnail_url = $baseurl . '/' . $rtmedia_folder_name . '/' . ltrim( $thumbnail_url[1], '/' ); 
  42. } else { 
  43. $thumbnail_url = $rtmedia_media->guid; 
  44.  
  45. if ( ! empty( $thumbnail_url ) ) { 
  46. $html = preg_replace( '/src=["]([^"]+)["]/', "src=\"$thumbnail_url\"", $html ); 
  47. }// End if(). 
  48. return $html;