AIOSEOP_Opengraph_Public

Class aioseop_opengraph_public.

Defined (1)

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

/public/opengraph.php  
  1. class AIOSEOP_Opengraph_Public { 
  2.  
  3. /** 
  4. * Prepare twitter username for public display. 
  5. * We do things like strip out the URL, etc and return just (at)username. 
  6. * At the moment, we'll check for 1 of 3 things... (at)username, username, and https://twitter.com/username. 
  7. * In the future, we'll need to start validating the information on the way in, so we don't have to do it one the way out. 
  8. * @param $twitter_profile 
  9. * @return string 
  10. * @since 2.3.5 
  11. */ 
  12. public static function prepare_twitter_username( $twitter_profile ) { 
  13.  
  14. //$twitter_profile = 'https://twitter.com/sdfsdfsf'; //testing purposes only, remove for release 
  15.  
  16. //test for valid twitter username, with or without @ 
  17. if ( preg_match( '/^(\@)?[A-Za-z0-9_]+$/', $twitter_profile ) ) { 
  18.  
  19. $twitter_profile = self::prepend_at_symbol( $twitter_profile ); 
  20.  
  21. return $twitter_profile; 
  22.  
  23. //check if it has twitter.com 
  24. if ( strpos( $twitter_profile, 'twitter.com' ) ) { 
  25.  
  26. $twitter_profile = esc_url( $twitter_profile ); 
  27.  
  28. $new_profile = self::twitter_url_to_user( $twitter_profile ); 
  29.  
  30. if ( $new_profile ) { 
  31. $new_profile = self::prepend_at_symbol( $new_profile ); 
  32.  
  33. return $new_profile; 
  34.  
  35.  
  36. //if all else fails, just send it back 
  37. return $twitter_profile; 
  38.  
  39.  
  40.  
  41. /** 
  42. * @param $twitter_profile 
  43. * @return mixed 
  44. * @since 2.3.5 
  45. * @since 2.3.5.1 Bail if < WordPress 4.4 for now. 
  46. */ 
  47. public static function twitter_url_to_user( $twitter_profile ) { 
  48.  
  49. // If they're below 4.4 (no wp_parse_url) bail. We can improve this for <4.4 later or just hold out until we drop 4.4 support. 
  50. if ( ! function_exists( 'wp_parse_url' ) ) { 
  51. return $twitter_profile; 
  52.  
  53. //extract the twitter username from the url 
  54.  
  55. $parsed_twitter_profile = wp_parse_url( $twitter_profile ); 
  56.  
  57. $path = $parsed_twitter_profile['path']; 
  58. $path_parts = explode( '/', $path ); 
  59. $twitter_profile = $path_parts[1]; 
  60.  
  61. return $twitter_profile; 
  62.  
  63.  
  64.  
  65. /** 
  66. * @param $twitter_profile 
  67. * @return string 
  68. * @since 2.3.5 
  69. * TODO- this claims to just validate, but it's actually validating and adding the AT symbol as needed rather than returning true/false 
  70. */ 
  71. public static function validate_twitter_profile( $twitter_profile ) { 
  72. //test for valid twitter username, with or without @ 
  73. if ( preg_match( '/^(\@)?[A-Za-z0-9_]+$/', $twitter_profile ) ) { 
  74.  
  75. $twitter_profile = self::prepend_at_symbol( $twitter_profile ); 
  76.  
  77. return $twitter_profile; 
  78.  
  79.  
  80. /** 
  81. * @param $twitter_profile 
  82. * @return string 
  83. * @since 2.3.5 
  84. */ 
  85. public static function prepend_at_symbol( $twitter_profile ) { 
  86. //checks for @ in the beginning, if it's not there adds it 
  87. if ( '@' !== $twitter_profile[0] ) { 
  88. $twitter_profile = '@' . $twitter_profile; 
  89.  
  90. return $twitter_profile;