| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Blip.tv embed code: |
| 5 |
* <embed src="http://blip.tv/play/g8sVgpfaCgI%2Em4v" type="application/x-shockwave-flash" width="480" height="255" allowscriptaccess="always" allowfullscreen="true"></embed> |
| 6 |
* Blip.tv shortcode is: [blip.tv url-or-something-else] |
| 7 |
* */ |
| 8 |
|
| 9 |
function blip_embed_to_shortcode( $content ) { |
| 10 |
if ( false === stripos( $content, '/blip.tv/play/' ) ) |
| 11 |
return $content; |
| 12 |
|
| 13 |
$regexp = '!<embed((?:\s+\w+="[^"]*")*)\s+src="http(?:\:|�*58;)//(blip\.tv/play/[^"]*)"((?:\s+\w+="[^"]*")*)\s*(?:/>|>\s*</embed>)!'; |
| 14 |
$regexp_ent = str_replace( '&#0*58;', '&#0*58;|�*58;', htmlspecialchars( $regexp, ENT_NOQUOTES ) ); |
| 15 |
|
| 16 |
foreach ( array( 'regexp', 'regexp_ent' ) as $reg ) { |
| 17 |
if ( !preg_match_all( $$reg, $content, $matches, PREG_SET_ORDER ) ) |
| 18 |
continue; |
| 19 |
|
| 20 |
foreach ( $matches as $match ) { |
| 21 |
$src = 'http://' . html_entity_decode( $match[2] ); |
| 22 |
$params = $match[1] . $match[3]; |
| 23 |
if ( 'regexp_ent' == $reg ) { |
| 24 |
$src = html_entity_decode( $src ); |
| 25 |
$params = html_entity_decode( $params ); |
| 26 |
} |
| 27 |
$params = wp_kses_hair( $params, array( 'http' ) ); |
| 28 |
if ( ! isset( $params['type'] ) || 'application/x-shockwave-flash' != $params['type']['value'] ) |
| 29 |
continue; |
| 30 |
|
| 31 |
$content = str_replace( $match[0], "[blip.tv $src]", $content ); |
| 32 |
} |
| 33 |
} |
| 34 |
return $content; |
| 35 |
} |
| 36 |
add_filter( 'pre_kses', 'blip_embed_to_shortcode' ); |
| 37 |
|
| 38 |
// [blip.tv ?posts_id=4060324&dest=-1] |
| 39 |
// [blip.tv http://blip.tv/play/hpZTgffqCAI%2Em4v] // WLS |
| 40 |
|
| 41 |
function blip_shortcode( $atts ) { |
| 42 |
if ( ! isset( $atts[0] ) ) |
| 43 |
return ''; |
| 44 |
$src = $atts[0]; |
| 45 |
|
| 46 |
if ( preg_match( '/^\?posts_id=(\d+)&[^d]*dest=(-?\d+)$/', $src, $matches ) ) |
| 47 |
return "<script type='text/javascript' src='http://blip.tv/syndication/write_player?skin=js&posts_id={$matches[1]}&cross_post_destination={$matches[2]}&view=full_js'></script>"; |
| 48 |
elseif ( preg_match( '|^http://blip.tv/play/[.\w]+$|', urldecode( $src ) ) ) // WLS |
| 49 |
return "<embed src='$src' type='application/x-shockwave-flash' width='480' height='300' allowscriptaccess='never' allowfullscreen='true'></embed>"; |
| 50 |
|
| 51 |
|
| 52 |
return "<!--blip.tv pattern not matched -->"; |
| 53 |
} |
| 54 |
|
| 55 |
add_shortcode( 'blip.tv', 'blip_shortcode' ); |
| 56 |
|