Last active
August 29, 2015 14:04
-
-
Save mrpotatoes/b0c0c9c7176eaa878a14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Convert MP3 links from the body text into themed jplayer HTML | |
* @param string $text | |
* @return string new body text | |
*/ | |
function pi_river_filter_mp3_link($text) { | |
if (empty($text)) { | |
return $text; | |
} | |
module_load_include('php', 'pi_river', 'simple_html_dom'); | |
$html = str_get_html($text); | |
foreach ($html->find('a.asset-audio') as $element) { | |
preg_match("/(https|http):\/\/[A-Za-z\/_\-\.0-9]*?\.mp[34]/i", $element->href, $matches); | |
if (!$matches[0]) { | |
continue; | |
} | |
$post_body_audio = array(); | |
$post_body_audio[0]['url'] = $matches[0]; | |
$placeholder_nid = 0; | |
$attr['attributes']['class'] = 'jp-play'; | |
$settings = array( | |
'nid' => 'inline-audio', | |
'player_id' => rand(100, 200), | |
'audio_caption' => $element->innertext, | |
'audio_label' => 'Listen', | |
'player_attributes' => $attr, | |
'url' => $matches[0], | |
); | |
$element->outertext = theme('post_node_player_wrapper', $settings); | |
} | |
$str = $html->__toString(); | |
$html->clear(); | |
unset($html); | |
return $str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment