Jump to content

SoundCloud textformatter


Recommended Posts

I've written a textformatter module for transforming SoundCloud URLs into SoundCloud widgets. It is customizable, so the user is able to select color, auto-play and comment visibility options. 

Being based on the YouTube/Vimeo textformatter by Ryan, it is working in the same way.

I hope you like it.

bildschirmfoto2013-09mzsmw.png

bildschirmfoto2013-09v5sr2.png

TextformatterSoundcloudEmbed.module

  • Like 12
Link to comment
Share on other sites

  • 1 month later...

I gonna try your module & love what you build !

but I get a Fatal error: Call-time pass-by-reference has been removed in /Path/To/modules/TextformatterSoundcloudEmbed.module on line 117

I've changed the format() methode, now it seems to works.

public function format(&$str) {
    $str = $this->embedSoundcloud($str);
}

ps, can't get it working. 

Edited by Martijn Geerts
  • Like 1
Link to comment
Share on other sites

Hi Martijn,

thanks for your feedback and your interest in my SoundCloud module. Can you please change line 116-137 in the module file to the following and tell me, whether it works or not?

public function format(&$str) {
		$str = $this->embedSoundcloud($str);
	}
	
	protected function embedSoundcloud($str) {
		if (strpos($str, '://soundcloud.com/') === false) return;

		
		$regex = '/.*?((?:http|https)(?::\\/{2}[\\w]+)(?:[\\/|\\.]?)(?:[^\\s"]*))/is';	//Url
		preg_match_all($regex, $str, $matches);		
		//echo var_dump($matches);
		foreach ($matches[1] as $match) {
			if (strpos($match, '://soundcloud.com/') === false) continue;
			$match = str_replace("</p>", "", $match);
			$soundcloudId = str_replace("https", "http", $match);
			$oembedURL = "http://soundcloud.com/oembed?".$this->getOembedParameters()."format=json&url=".urlencode($match);
			$embedCode = $this->getEmbedCode($oembedURL, $soundcloudId);
			
			if ($embedCode) $str = str_replace($match, $embedCode, $str);
		}
		//exit;
		return $str;
	} 
Link to comment
Share on other sites

I had a problem with this module before I discovered this thread, getting the same error Martijn Geerts noted above.

After taking a look at Ryan's original Vimeo/YouTube module, I changed line 117 from:

$this->embedSoundcloud(&$str);

to:

$this->embedSoundcloud($str);

removing the "&" in red before "$str" in the first example above. 

Now it works as expected, including multiple embeds on a single page.

However, there is one anomaly: unlike the Vimeo/YouTube module, this Soundcloud module is sensitive to its order among other TextFormatters (in Edit Field --> Field Type Details --> Text Formatters).

The SoundCloud module won't embed when Markdown Extra module follows it, but embeds OK when Markdown precedes it.

I hope that makes sense, thanks for your work on this, Marvin!

  • Like 2
Link to comment
Share on other sites

  • 2 years later...
  • 1 month later...

Anyone using this module successfully with PW 2.7.x? I've had no luck so far getting PW to even recognize that it's available to install.

Edit: Installed a completely different module, and afterwards, this one magically appeared as available to install.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...