public function MediaInternetSoundCloudHandler::parse in Media: SoundCloud 7
Same name and namespace in other branches
- 7.2 includes/MediaInternetSoundCloudHandler.inc \MediaInternetSoundCloudHandler::parse()
 
3 calls to MediaInternetSoundCloudHandler::parse()
- MediaInternetSoundCloudHandler::claim in includes/
MediaInternetSoundCloudHandler.inc  - MediaInternetSoundCloudHandler::getFileObject in includes/
MediaInternetSoundCloudHandler.inc  - MediaInternetSoundCloudHandler::getOEmbed in includes/
MediaInternetSoundCloudHandler.inc  - Returns information about the media. See http://www.oembed.com/.
 
File
- includes/
MediaInternetSoundCloudHandler.inc, line 9  
Class
- MediaInternetSoundCloudHandler
 - Implementation of MediaInternetBaseHandler.
 
Code
public function parse($embedCode) {
  $patterns = array(
    '@soundcloud\\.com/([0-9A-Za-z\\@\\&\\$_-]+)/([0-9A-Za-z\\@\\&\\$_-]+)/([0-9A-Za-z\\@\\&\\$_-]+)@i',
    '@soundcloud\\.com/([0-9A-Za-z\\@\\&\\$_-]+)/([0-9A-Za-z\\@\\&\\$_-]+)@i',
    '@soundcloud\\.com/([0-9A-Za-z\\@\\&\\$_-]+)@i',
  );
  foreach ($patterns as $pattern) {
    preg_match($pattern, $embedCode, $matches);
    if (isset($matches[1]) && !isset($matches[2])) {
      return file_stream_wrapper_uri_normalize('soundcloud://u/' . $matches[1]);
    }
    if (isset($matches[2]) && !isset($matches[3])) {
      if ($matches[1] == 'groups') {
        return file_stream_wrapper_uri_normalize('soundcloud://g/' . $matches[2]);
      }
      else {
        return file_stream_wrapper_uri_normalize('soundcloud://u/' . $matches[1] . '/a/' . $matches[2]);
      }
    }
    if (isset($matches[3])) {
      if ($matches[2] == 'sets') {
        return file_stream_wrapper_uri_normalize('soundcloud://u/' . $matches[1] . '/s/' . $matches[3]);
      }
    }
  }
}