You are here

public function MediaInternetSoundCloudHandler::parse in Media: SoundCloud 7.2

Same name and namespace in other branches
  1. 7 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.

File

includes/MediaInternetSoundCloudHandler.inc, line 14
Extends the MediaInternetBaseHandler class to handle SoundCloud audio.

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) {
    $uri = FALSE;

    // @TODO: Parse is called often. Refactor so that valid ID is checked
    // when a song is added, but not every time the embedCode is parsed.
    preg_match($pattern, $embedCode, $matches);
    if (isset($matches[1]) && !isset($matches[2])) {
      $uri = 'soundcloud://u/' . $matches[1];
    }
    if (isset($matches[2]) && !isset($matches[3])) {
      if ($matches[1] == 'groups') {
        $uri = 'soundcloud://g/' . $matches[2];
      }
      else {
        $uri = 'soundcloud://u/' . $matches[1] . '/a/' . $matches[2];
      }
    }
    if (isset($matches[3])) {
      if ($matches[2] == 'sets') {
        $uri = 'soundcloud://u/' . $matches[1] . '/s/' . $matches[3];
      }
    }
    if ($uri && self::validId($uri)) {
      return file_stream_wrapper_uri_normalize($uri);
    }
  }
}