Jump to content
ryan

Module: Video embed for YouTube/Vimeo (TextformatterVideoEmbed)

Recommended Posts

If phpmotion.com supports oembed, then it is feasible for TextformatterVideoEmbed to support it in the same way as YouTube/Vimeo. 

Share this post


Link to post
Share on other sites

hi Adrian.
cool i got the img Thank you.

Now is there a way in module to get this youtube video id ? or do i have to do it with js ?

thanks :)

Share this post


Link to post
Share on other sites

It depends on what you want to do exactly. 

Because the module converts a Youtube link that is in an RTE texatarea field, you already know the id of the video because it is in the link. You could easily insert the image link using the url schema from that first link I posted.

Maybe if you can explain your usage scenario we can help more. Where you do want to display the image? How is it connected to the embedded link.

It is easy to grab the id of the video from the link in either PHP or JS using a regex, but the video module also stores the id in the PW database (in the textformatter_video_embed table), so this might also be an option depending on your needs.

EDIT: Here is the function in the module that parses the video url:

https://github.com/ryancramerdesign/TextformatterVideoEmbed/blob/master/TextformatterVideoEmbed.module#L127

Or you can use:

$url = "http://www.youtube.com/watch?v=C4kxS1ksqtw&feature=relate";
parse_str( parse_url( $url, PHP_URL_QUERY ), $my_array_of_vars );
echo $my_array_of_vars['v'];    
  // Output: C4kxS1ksqtw
  • Like 1

Share this post


Link to post
Share on other sites

Wow Ty Adrian.

Im just trying to open embeded video in the fancybox popup window after clicking on thumb. :)
Again thanks alot

Share this post


Link to post
Share on other sites

Ok, so it sounds like you are manually adding the thumbnail image to an RTE? Maybe you don't really need the video embed module, because you don't actually want the video to play inside the RTE field?

There are lots of ways to go about this. You could use a regex in your template. You could make your own module. You could maybe use the Hanna Code module (http://modules.processwire.com/modules/process-hanna-code/) and just enter the video ID and use that to output the thumbnail and link to open in fancybox.

You could even use JS to modify the link.

An example of your exact usage would really help to narrow down the best approach.

Share this post


Link to post
Share on other sites

i just did what u said, i dropped the module, now from admin panel i just enter the url for youtube movie and then i do this :

<?php
    $videoFolder = $pages->find('parent=1051, limit=3');
    $out ="";
        foreach($videoFolder as $videoItem){
            $vidUrl = $videoItem->video;
            parse_str( parse_url( $vidUrl, PHP_URL_QUERY ), $my_array_of_vars );
            $imgUrl = $my_array_of_vars['v'];
            $search     = '/youtube\.com\/watch\?v=([a-zA-Z0-9]+)/smi';
            $replace    = "youtube.com/embed/$1?autoplay=1";
            $vidUrl = preg_replace($search,$replace,$vidUrl);
            $out .= "<div>";
            $out .= "<a class='fancybox' data-fancybox-type='iframe' href='{$vidUrl}'><img src='http://img.youtube.com/vi/{$imgUrl}/0.jpg' alt='{$videoItem->title}' /></a>";
            $out .= "<div class='name'><a href='{$vidUrl}'>{$fotoItem->title}</a></div>";
            $out .= "</div> ";
        }
        echo $out;
 ?>

And thats it i got my video working :)
Ty alot Adrian u ware most helpful

  • Like 2

Share this post


Link to post
Share on other sites

Glad you got it working.

The $videoItem->video makes me think you are storing the URL for the video in a dedicated field? If that's the case, you shouldn't need to do that preg_replace. You already have the id from $my_array_of_vars['v'] so you should be able to just build the embed version directly from that.

  • Like 1

Share this post


Link to post
Share on other sites

Glad you got it working.

The $videoItem->video makes me think you are storing the URL for the video in a dedicated field? If that's the case, you shouldn't need to do that preg_replace. You already have the id from $my_array_of_vars['v'] so you should be able to just build the embed version directly from that.

HA! ... true  :D

<?php
	$videoFolder = $pages->find('parent=1051, limit=3');
	$out ="";
		foreach($videoFolder as $videoItem){
			$vidUrl = $videoItem->video;
			parse_str( parse_url( $vidUrl, PHP_URL_QUERY ), $my_array_of_vars );
			$vidID = $my_array_of_vars['v'];
			$out .= "<div>";
			$out .= "<a class='fancybox' data-fancybox-type='iframe' href='http://www.youtube.com/embed/{$vidID}?autoplay=1'><img src='http://img.youtube.com/vi/{$vidID}/0.jpg' alt='{$videoItem->title}' /></a>";
			$out .= "<div class='name'><a href='http://www.youtube.com/embed/{$vidID}?autoplay=1'>{$videoItem->title}</a></div>";
			$out .= "</div> ";
		}
		echo $out;
 ?>

Ty alot :)

Share this post


Link to post
Share on other sites

Just noticed that if you copypaste youtube url from Chrome (Win7) addressbar into CKeditor, it will be transformed into <a> tag and therefor embedding doesn't work. I don't know how CKeditor does that, since if you copypaste it from another source (like text editor), it will not be transformed into a link. 

Possible solution could be allowing links also transformed into a embed. What do you think?

  • Like 1

Share this post


Link to post
Share on other sites

It might just be a matter of the forum using an older version of CKEditor (3 vs 4). Does it work if you do an unformatted paste? i.e. shift+ctrl+v ? Though I'd have no problem making it support the videos as links, but it seems like that then creates a problem where you actually want to link to a video (as opposed to embedding it). If someone puts the link in it's own paragraph, maybe it's safe to assume they are trying to embed though. Especially if the anchor text matches the src attribute. 

Share this post


Link to post
Share on other sites

Hi all, 

I have an issue with the module.

It works fine for me under all browsers apart from Firefox(Win 7) - I've updated to version 26.0, from 24.*;

However I still get only a black box. I can see the code, exactly the same as under Chrome/Safari/Opera, but it doesn't work.

Any ideas what could be causing the problem ? 

p.s. I get no errors with Firebug. 

Share this post


Link to post
Share on other sites

Is it possible your browser doesn't have the necessary plugins to display videos (Flash, etc.) or has some kind of blocker installed? I know with my copy of Firefox, both are the case (no flash, and everything external blocked... but it was intentionally configured that way). 

Share this post


Link to post
Share on other sites

Is there any way I can call that youtube ID part from template using this module?

Youtube uses these urls:

http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg

to give us pre-generated thumbnails, so it would be great if I could use thumbnails on my front page as a preview, which leads to full page with properly embeded video.

Share this post


Link to post
Share on other sites

@Ryan: fantastic Module. I have used it the first time now on a site for a colleague.

There is one thing I want to ask if it could be possible:

With the param rel=0 added to the $embedCode  $queryString (e.g. ?feature=oembed&rel=0) the video gets reset to the first frame of it after playing, - instead of displaying a lot of thumbs to other videos.

On some pages / sites it looks much better this way.

Can this be added to the module? (maybe as option, or default?)

Share this post


Link to post
Share on other sites

Horst, it should already support the rel=0 option for video embedding (at least it used to). Try adding it to the YouTube URL you are embedding. If it doesn't work, go to the module settings and clear the video cache and try again. 

Share this post


Link to post
Share on other sites

Ryan, unfortunately it doesn't work. (have flushed the DB)
 
My url is


and the resulting code in DB is

video_id = oUdcc7fYlp8?rel=0

embed_code = <iframe width="640" height="360" src="http://www.youtube.com/embed/oUdcc7fYlp8?feature=oembed" frameborder="0" allowfullscreen></iframe>

The rel=0 doesn't make it into the embedded code. ??

Share this post


Link to post
Share on other sites

Fixed an issue with embedding in secure pages. YouTube's oembed service doesn't return https urls, even if the feed url is https.

Change line 86 to:

$embedCode = str_replace('http','https',$data['html']);

Share this post


Link to post
Share on other sites

Hi Guys!

A question for you gents...

Is it possible to modify the module such that it automatically adds  &rel=0  to all our YouTube video urls that we enter?

Been trying to plug it in into various parts of the module but I can't seem to get it to work.

It would save having to type in $rel=0 every single time I add a video.

Cheers guys!

Share this post


Link to post
Share on other sites

After you installed the Textformatter, go to /site/modules/TextformatterVideoEmbed.module

add a line in the methode embedYoutube:

// line number +/- 145
$queryString = isset($matches[3][$key]) ? $matches[3][$key] : '';
$queryString = $queryString . "&rel=0"; // this is the new line you should add

---

If you make modifications to this module, it's better to rename the module and the file and install it again. This to insures updates won't delete your modifications

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By eelkenet
      Hi! I've created a small Inputfield module called InputfieldFloatRange which allows you to use an HTML5 <input type="range" ../> slider as an InputField. I needed something like this for a project where the client needs to be able to tweak this value more based on 'a feeling' than just entering a boring old number. Maybe more people can use this so I'm hereby releasing it into the wild.  
       
      What is it?
      The missing range slider Inputfield for Processwire. 
      What does it do?
      This module extends InputfieldFloat and allows you to use HTML5 range sliders for number fields in your templates.
      It includes a visible and editable value field, to override/tweak the value if required.  
      Features
      Min/max values Precision (number of decimals) Steps (Read more) Manual override of the selected value (will still adhere to the rules above) Usage
      Clone / zip repo Install FieldtypeFloatRange, this automatically installs the Inputfield Create new field of type `Float (range)` or convert an existing `Float`, `Integer` or `Text` field. To render the field's value simply echo `$page->field` Demo
      A field with Min=0, Max=1, Step=0.2, Precision=2

      Field with settings Min=0, Max=200, Step=0.25, Precision=2

       
      Todo
      Make the display-field's size configurable (will use the Input Size field setting)  Hopefully become redundant If it's usable for others I'll add it to the Modules list  
      Changelog
      v002
      - Fix issue where setting the step value to an empty value created problem with validation
      - Make the display-field optional 
      v001
      - Initial release
       
      Thanks!
       
       
    • By Robin S
      Another little admin helper module...
      Template Field Widths
      Adds a "Field widths" field to Edit Template that allows you to quickly set the widths of inputfields in the template.

      Why?
      When setting up a new template or trying out different field layouts I find it a bit slow and tedious to have to open each field individually in a modal just to set the width. This module speeds up the process.
      Installation
      Install the Template Field Widths module.
      Config options
      You can set the default presentation of the "Field widths" field to collapsed or open. Field widths entered into the Template Field Widths inputfield are only applied if the Edit Template form is submitted with the Template Field Widths inputfield in an opened state. "Collapsed" is the recommended setting if you think you might also use core inputs for setting field widths in a template context. You can choose Name or Label as the primary identifier shown for the field. The unchosen alternative will become the title attribute shown on hover. You can choose to show the original field width next to the template context field width.  
      https://github.com/Toutouwai/TemplateFieldWidths
      https://modules.processwire.com/modules/template-field-widths/
    • By NehaPillai
      Hello Everyone, I was trying to update SEO meta title, description and meta keywords for my website in Process Wire CMS but it saving in the backend but it is not reflecting on my website, Please help me regarding this error. Please find below attached screen shot for your ref. TIA.


    • By adrian
      Tracy Debugger for ProcessWire
      The ultimate “swiss army knife” debugging and development tool for the ProcessWire CMF/CMS

       
      Integrates and extends Nette's Tracy debugging tool and adds 35+ custom tools designed for effective ProcessWire debugging and lightning fast development
      The most comprehensive set of instructions and examples is available at: https://adrianbj.github.io/TracyDebugger
      Modules Directory: http://modules.processwire.com/modules/tracy-debugger/
      Github: https://github.com/adrianbj/TracyDebugger
      A big thanks to @tpr for introducing me to Tracy and for the idea for this module and for significant feedback, testing, and feature suggestions.
×
×
  • Create New...