How to encode video URLs in wordpress using base64? - php

<?php
$vid = get_post_meta($post->ID,'videourl', true);
$video = base64_encode($vid);
$embedvideo = get_post_meta($post->ID,'embedvideo', true);
$sefurL = get_bloginfo('template_url', true);
if($video != "") { ?>
<?php if ( !wp_is_mobile() ) {
echo'<object id="player" width="800" height="500" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0">
<param name="flashvars" value="file='.$video.' />
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="src" value="'.$sefurL.'/inc/tools/jwplayer/player.swf" />
<embed src="'.$sefurL.'/inc/tools/jwplayer/player.swf" autostart=false" wmode="opaque" allowscriptaccess="always" quality="high" FlashVars="file='.$video.'&width=800&height=500&skin='.$sefurL.'/inc/tools/jwplayer/blueratio.zip&repeat=false&autostart=false&image=big=true" quality="high" bgcolor="#000" width=800 height=500 name="jwplayer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer" allowfullscreen=true />
</embed>
</object>';
} else {
echo '<video src="'.$video.'" controls>
Your browser does not support the <code>video</code> element.
</video>';
}
?>
<?php } elseif($video == "" && $embedvideo != "") { ?>
<?php echo $embedvideo; ?>
<?php } else {
wpautop(the_content());
} ?>
As you see in the code I used $video = base64_encode($vid); but when I do it in this way video not working more, so I don't have any experience with the base64 encoding I just searched on the Google but I couldn't find the right way to do it.
Can anyone help me?

Maybe you should be using base_64_decode(), it's likely the 'videourl' is already base64 encoded. See how base64_encode() works in the
PHP Docs.
Try to echo the value of $vid to establish if it is already base64 encoded or not.

Related

replace a string in a youtube embed code using jquery

I have here an embed code from youtube and Im using a plugin to show that video
<object width="350" height="200">
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="movie" value="http://www.youtube.com/v/KVu3gS7iJu4&autoplay=0&loop=0&rel=0" />
<param name="wmode" value="transparent">
<embed src="http://www.youtube.com/v/KVu3gS7iJu4&autoplay=0&loop=0&rel=0" type="application/x-shockwave-flash" wmode="transparent" allowfullscreen="true" allowscriptaccess="always" width="350" height="200">
</embed>
</object>
My problem is I cannot edit those codes, I need to change the "&" sign to "&" for w3c validation, is this possible using jquery
here is My sample fiddle which is not working and dont know how http://jsfiddle.net/kfX9M/
Changing it with jQuery won't make your HTML valid. You could change it server-side with some PHP:
$dom = new DOMDocument();
$dom->loadHTML($your_embed_code_here);
$xpath = new DOMXPath($dom);
$items = $xpath->query("//*[contains(#href,'&')]");
$l = $item->length;
for($i=0; $i<$l; $i++) {
$items->item($i)->setAttribute("href",str_replace("&","&",$items->item($i)->getAttribute("href")));
}
$out = $dom->saveHTML();
But, as mentioned by elclanrs, it really makes no difference.
Hi dude i did with jQuery and Regular Expressions.,
<script type="text/javascript">
$(document).ready( function() {
var re=/&/g;
var value=$("param[name='movie']").val();
var modified_value=value.replace(re,'&');
$("param[name='movie']").val(modified_value);
var src = $("embed").attr('src');
var src_modified_value=src.replace(re,'&');
$("embed").attr('src',src_modified_value);
});
</script>
i think this may help you to resolve your problem.
To see it in action : http://jsfiddle.net/john_rock/7H2Hk/

Play audio file on website

I'm just wondering how, and which audio player I should use to allow my visitors to play audio files on my PHP-based website.
Thanks!
try this
<?php
$path = "PATH OF YOUR AUDIO FILE";
$image = "PATH OF YOUR IMAGEFILE";;?>
<div class="demomain">
<br>
<div style="margin: 0 0 0 30px;" id="mediaspace" name="mediaspace"><embed height="395" width="500" flashvars="javascriptid=JW&autostart=false&width=500&height=395&image=<?php echo $image; ?>&file=<?php echo $path; ?>" allowfullscreen="true" wmode="transparent" allowscriptaccess="always" quality="high" name="JW" id="JW" style="undefined" src="http://player.longtailvideo.com/player4.6.swf" type="application/x-shockwave-flash"> </div>
<?php
echo '<script type="text/javascript">
var s1 = new SWFObject("","JW","500","395","9");
s1.addParam("allowscriptaccess", "always");
s1.addParam("wmode","transparent");
s1.addParam("allowfullscreen","true");
s1.addVariable("javascriptid", "JW");
s1.addVariable("autostart","false");
s1.addVariable("image","' . $image . '"));
s1.addVariable("width","500");
s1.addVariable("height","395");';
echo 's1.addVariable("file","' . $path . '");';
echo 's1.write("mediaspace");';
echo '</script>';
?>
</div>
HTML 5 has an audio player tag,see this:
http://www.w3schools.com/html5/att_audio_src.asp
it is supported on major browsers, but it depends on the format of the audio file
you can see this: http://jplayer.org/ a jquery one,
The open source jPlayer works well and is very customisable - uses HTML/CSS for the interface. Will use HTML5 if it can, and fallback to Flash if not. Requires jQuery.
Website: http://jplayer.org/
You can try Flash Player. I think it will suite your requirement. Of course you should have the flash player installed, but practically almost all internet users have the flash player installed in their machines.
try this
<object height="81" width="100%">
<param name="movie" value="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F32222617&show_comments=true&auto_play=true">
</param>
<param name="allowscriptaccess" value="always"></param>
<embed allowscriptaccess="always" height="81" src="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F32222617&show_comments=true&auto_play=true&repeat=1" type="application/x-shockwave-flash" width="100%" loop="yes" autoresume="1" repeat="1">
</embed>
</object>
use this <audio controls><source src="<?php echo $pathtofile ?>" type="audio/mpeg">Error loading</audio> It works for me.

Get the Html Tag as string

I have a script that gets embed code for me.I am using php simple html dom parser.The code i am using is like this :
foreach ($html->find('object embed') as $embedCode)
{
echo $embedCode;
}
and the out put is :
<embed width="100%" height="320" flashvars="config=http://server0.stream2k.com/playerjw/vConfigCdn.php?vkey=c2053010dadfdd331145"
allowfullscreen="true" allowscriptaccess="always"
src="http://server0.stream2k.com/playerjw/player-licensed56.swf"
pluginspage="http://www.macromedia.com/go/getflashplayer"
type="application/x-shockwave-flash" wmode="transparent">
but it's showing in my browser as a flash screen.I want to print it as a single string.
Can anyone tell me how can i get it as a single string not the video screen.
Thanks in advance
The return of GetMovie() :
<embed wmode="transparent" type="application/x-shockwave- flash"
pluginspage="http://www.macromedia.com/go/getflashplayer"
src="http://server0.stream2k.com/playerjw/player- licensed56.swf"
width="100%" height="320" allowscriptaccess="always" allowfullscreen="true" flashvars="config=http://server0.stream2k.com/playerjw/vConfigCdn.php?vkey=f3513b19d1149102e116" />
use htmlspecialchars:
foreach ($html->find('object embed') as $embedCode)
{
echo htmlspecialchars($embedCode);
}
Try to put output string in htmlspecialchars: echo htmlspecialchars($embedCode);
You can try something like this :
<pre>
<embed width="100%" height="320" flashvars="config=http://server0.stream2k.com/playerjw/vConfigCdn.php?vkey=c2053010dadfdd331145"
allowfullscreen="true" allowscriptaccess="always"
src="http://server0.stream2k.com/playerjw/player-licensed56.swf"
pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent">
​</pre>
​​​​​​​​​​​​​​​​​​​​​
Try add this before your "for" loop:
echo '<xmp>';
this will echo all charactors but not display as html code.

Finding string between custom tags and doing something with it

On my new project, members are able to use my YouTube API and it will generate a tag like below for them to use it in whatever textarea they want:
<ymedia>http://www.youtube-nocookie.com/v/qQG0XfU-bFs</ymedia>
I want my PHP profile page to take the string between <ymedia></ymedia> and generate a similar code below using $ymstring for the string collected from the ymedia tag:
<?php
$u_agent = $_SERVER[''HTTP_USER_AGENT''];
if(preg_match(''/Opera/i'',$u_agent)){
<object width="320" height="240" data="".$ymstring."?fs=1&hl=en_US&rel=0"><param name="movie" value="".$ymstring."?fs=1&hl=en_US&rel=0" /><param name="allowFullScreen" value="true" /><param name="wmode" value="transparent" /><param name="bgColor" value="#ffffff" /><param name="flashvars" value="vu=".$ymstring."?fs=1&hl=en_US&rel=0" /></object>
} else {
<object width="320" height="240"><param name="movie" value="".$ymstring."?fs=1&hl=en_US&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="".$ymstring."?fs=1&hl=en_US&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="320" height="240"></embed></object>
}
?>
Basically, I'm trying to find all the ymedia tags in a $string and replace them with my youtube coding above aimed at either Opera or the rest of other browsers.
This should work:
    preg_match("/<ymedia>(.*?)<\/ymedia>/", $Input, $Matches);
Then, your result would be in $Matches[1] which you could pass as $ymstring.
You want to use preg_replace_callback for simplicity:
$html = preg_replace_callback('#<ymedia>(http://.*?)</ymedia>#',
"ymedia_cb", $html);
function ymedia_cb($matches) {
$url = $matches[1];
return "<object src=$url>";
}
Obviously you would use your if/else construct to return the appropriate and complete object tag.

Hyperlink Youtube to Embed Code

I've some troubles using Preg_replace and preg_match_all to convert a Youtube URL to embed code. Yes, I know that this topic has already touched in stackoverflow but not exactly like I want.
I can get the ID from a url, without html, with that:
http://(?:www\.)?youtu(?:be\.com/watch\?v=|\.be/)(\w*)(&(amp;)?[\w\?=]*)?
But I've the url formatted with like this:
http://www.youtube.com/watch?v=C9KAqhbIZ7o
And I want to convert it all to this:
<object width="640" height="505"><param name="movie" value="http://www.youtube.com/v/C9KAqhbIZ7o?fs=1&hl=es_ES&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/C9KAqhbIZ7o?fs=1&hl=es_ES&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"></embed></object>
Somebody can do some magic and tell me the correct expression to detect all the url, get the ID once and convert all to an embed code? Thank you so much in advance!
Update information:
In order to help and make it a more concise...
I've this:
<p>This is an example of comment</p><strong>Hi bold!</strong><p>Look a youtube url! http://www.youtube.com/watch?v=C9KAqhbIZ7o</p>
And I want to get this:
<p>This is an example of comment</p><strong>Hi bold!</strong><p>Look a youtube url! <object width="640" height="505"><param name="movie" value="http://www.youtube.com/v/C9KAqhbIZ7o?fs=1&hl=es_ES&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/C9KAqhbIZ7o?fs=1&hl=es_ES&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"></embed></object></p>
Thanks all for your help, I really appreciate it!
I use this code
// url of video
$url = $row['url'];
$id=0;
// we get the unique video id from the url by matching the pattern
preg_match("/v=([^&]+)/i", $url, $matches);
if(isset($matches[1])) $id = $matches[1];
if(!$id) {
$matches = explode('/', $url);
$id = $matches[count($matches)-1];
}
// this is your template for generating embed codes
$code = '<div id="img_wrapper"><object width="640" height="458"><param name="movie" value="http://www.youtube.com/v/{id}&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/{id}&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></div>';
// we replace each {id} with the actual ID of the video to get embed code for this particular video
$code = str_replace('{id}', $id, $code);
echo $code;
Replace $html with your html string which needs parsing.
$html=<<<HTML
<p>This is an example of comment</p><strong>Hi bold!</strong><p>Look a youtube url! http://www.youtube.com/watch?v=C9KAqhbIZ7o</p>
HTML;
$regex="/v\=([\-\w]+)/";
preg_match_all($regex,$html,$out);
$out[1]=array_unique($out[1]);
foreach($out[1] as $o){
$reg="/(<a).*(youtube.com).*($o).*(\/a>)/";
$embed= <<<HTML
<object width="640" height="505"><param name="movie" value="http://www.youtube.com/v/$o=1&hl=es_ES&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/$o?fs=1&hl=es_ES&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"></embed></object>
HTML;
$html=preg_replace($reg,$embed, $html);
}
echo $html;

Categories