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,

Is there a way to get a thumb img of a video ?

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

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By MoritzLost
      This is a new module that provides a simple solution to clearing all your cache layers at once, and an extensible interface to perform various cache-related actions.
      The simple motivation behind this module was that I was tired of manually clearing caches in several places after deploying a change on a live site. The basic purpose of this module is a simple Clear all caches link in the Setup menu which clears out all caches, no matter where they hide. You can customize what exactly the module does through it's configuration menu:
      Expire or delete all cache entries in the database, or selectively clear caches by namespace ($cache API) Clear the the template render cache. Clear out specific folders inside your site's cache directory (/site/assets/cache) Refresh version strings for static assets to bust client-side browser caches (this requires some setup, see the full documentation for details). This is the basic function of the module. However, you can also add different cache management action through the API and execute them through the module's interface. For this advanced usage, the module provides:
      An interface to see all available cache actions and execute them. A system log and logging output on the module page to see verify what the module is doing. A CacheControlTools class with utility functions to clear out different caches. An API to add cache actions, execute them programmatically and even modify the default action. Permission management, allowing you granular control over which user roles can execute which actions. The complete documentation can be found in the module's README.
      Beta release
      Note that I consider this a Beta release. Since the module is relatively aggressive in deleting some caches, I would advise you to install in on a test environment before using it on a live site.
      Let me know if you're getting any errors, have trouble using the module or if you have suggestions for improvement!
      In particular, can someone let me know if this module causes any problems with the ProCache module? I don't own or use it, so I can't check. As far as I can tell, ProCache uses a folder inside the cache directory to cache static pages, so my module should be able to clear the ProCache site cache as well, I'd appreciate it if someone can test that for me.
      Future plans
      If there is some interest in this, I plan to expand this to a more general cache management solution. I particular, I would like to add additional cache actions. Some ideas that came to mind:
      Warming up the template render cache for publicly accessible pages. Removing all active user sessions. Let me know if you have more suggestions!
      Links
      https://github.com/MoritzLost/ProcessCacheControl ProcessCacheControl in the Module directory

    • By joshua
      This module is (yet another) way for implementing a cookie management solution.
      Of course there are several other possibilities:
      - https://processwire.com/talk/topic/22920-klaro-cookie-consent-manager/
      - https://github.com/webmanufaktur/CookieManagementBanner
      - https://github.com/johannesdachsel/cookiemonster
      - https://www.oiljs.org/
      - ... and so on ...
      In this module you can configure which kind of cookie categories you want to manage:

      You can also enable the support for respecting the Do-Not-Track (DNT) header to don't annoy users, who already decided for all their browsing experience.
      Currently there are four possible cookie groups:
      - Necessary (always enabled)
      - Statistics
      - Marketing
      - External Media
      All groups can be renamed, so feel free to use other cookie group names. I just haven't found a way to implement a "repeater like" field as configurable module field ...
      When you want to load specific scripts ( like Google Analytics, Google Maps, ...) only after the user's content to this specific category of cookies, just use the following script syntax:
      <script type="optin" data-type="text/javascript" data-category="statistics" data-src="/path/to/your/statistic/script.js"></script> <script type="optin" data-type="text/javascript" data-category="marketing" data-src="/path/to/your/mareketing/script.js"></script> <script type="optin" data-type="text/javascript" data-category="external_media" data-src="/path/to/your/external-media/script.js"></script> <script type="optin" data-type="text/javascript" data-category="marketing">console.log("Inline scripts are also working!");</script> The type has to be "optin" to get recognized by PrivacyWire, the data-attributes are giving hints, how the script shall be loaded, if the data-category is within the cookie consents of the user. These scripts are loaded asynchronously after the user made the decision.
      If you want to give the users the possibility to change their consent, you can use the following Textformatter:
      [[privacywire-choose-cookies]] It's planned to add also other Textformatters to opt-out of specific cookie groups or delete the whole consent cookie.
      You can also add a custom link to output the banner again with a link / button with following class:
      <a href="#" class="privacywire-show-options">Show Cookie Options</a> <button class="privacywire-show-options">Show Cookie Options</button> This module is still in development, but we already use it on several production websites.
      You find it here: https://github.com/blaueQuelle/privacywire/tree/master
      Download: https://github.com/blaueQuelle/privacywire/archive/master.zip
      I would love to hear your feedback 🙂
      Edit: Updated URLs to master tree of git repo
       
    • By David Karich
      Admin Page Tree Multiple Sorting
      ClassName: ProcessPageListMultipleSorting
      Extend the ordinary sort of children of a template in the admin page tree with multiple properties. For each template, you can define your own rule. Write each template (template-name) in a row, followed by a colon and then the additional field names for sorting.
      Example: All children of the template "blog" to be sorted in descending order according to the date of creation, then descending by modification date, and then by title. Type:
      blog: -created, -modified, title  Installation
      Copy the files for this module to /site/modules/ProcessPageListMultipleSorting/ In admin: Modules > Check for new modules. Install Module "Admin Page Tree Multible Sorting". Alternative in ProcessWire 2.4+
      Login to ProcessWire backend and go to Modules Click tab "New" and enter Module Class Name: "ProcessPageListMultipleSorting" Click "Download and Install"   Compatibility   I have currently tested the module only under PW 2.6+, but think that it works on older versions too. Maybe someone can give a feedback.     Download   PW-Repo: http://modules.processwire.com/modules/process-page-list-multiple-sorting/ GitHub: https://github.com/FlipZoomMedia/Processwire-ProcessPageListMultipleSorting     I hope someone can use the module. Have fun and best regards, David
    • By dimitrios
      Hello,
      this module can publish content of a Processwire page on a Facebook page, triggered by saving the Processwire page.
      To set it up, configure the module with a Facebook app ID, secret and a Page ID. Following is additional configuration on Facebook for developers:
      Minimum Required Facebook App configuration:
      on Settings -> Basics, provide the App Domains, provide the Site URL, on Settings -> Advanced, set the API version (has been tested up to v3.3), add Product: Facebook Login, on Facebook Login -> Settings, set Client OAuth Login: Yes, set Web OAuth Login: Yes, set Enforce HTTPS: Yes, add "https://www.example.com/processwire/page/" to field Valid OAuth Redirect URIs. This module is configurable as follows:
      Templates: posts can take place only for pages with the defined templates. On/Off switch: specify a checkbox field that will not allow the post if checked. Specify a message and/or an image for the post.
      Usage
      edit the desired PW page and save; it will post right after the initial Facebook log in and permission granting. After that, an access token is kept.
       
      Download
      PW module directory: http://modules.processwire.com/modules/auto-fb-post/ Github: https://github.com/kastrind/AutoFbPost   Note: Facebook SDK for PHP is utilized.


×
×
  • Create New...