Jump to content

Module: Video or Social Post Embed


LexSanchez

Recommended Posts

Video or Social Post Embed

Based on the TextformatterVideoEmbed module developed by Ryan Cramer, we have added the possibility to embed publications of the main social networks Facebook, Twitter and Instagram.

ProcessWire Textformatter module that enables translation of YouTube, Vimeo, Instagram, Facebook, Twitter or Issuu URLs to full embed codes, resulting in a viewable video or social post in textarea fields you apply it to.

How to install

  • Download or Clone from Github: https://github.com/lexsanchez/VideoOrSocialPostEmbed

  • Copy the VideoOrSocialPostEmbed.module file to your /site/modules/ directory (or place it in /site/modules/VideoOrSocialPostEmbed/).

  • Click check for new modules in ProcessWire Admin Modules screen. Click install for the module labeled: "Video or Social Post Embed".

  • Now you will be on the module config screen. Please make note of the config options and set as you see fit.

How to use

  • Edit your body field in Setup > Fields (or whatever field(s) you will be placing videos in). On the details tab, find the Text Formatters field and select "Video or Social Post Embed". Save.

  • Edit a page using the field you edited and paste in YouTube, Vimeo, Facebook, Twitter, Instagram and/or Issuu URLs each on their own paragraph.

Example

How it might look in your editor (like TinyMCE):

Here are two videos about ProcessWire

http://www.youtube.com/watch?v=Wl4XiYadV_k

http://www.youtube.com/watch?v=XKnG7sikE-U

And here is a great video I watched earlier this week:

http://vimeo.com/18280328

Embed social post and Issuu Presentation:

https://www.instagram.com/p/BeA8p9AhA3b/

https://twitter.com/rpc_radio/status/954315569838411776

https://www.facebook.com/TNTLA/videos/10155549598252758/

https://issuu.com/madsoundsmagazine/docs/mad_sounds_issue_no._17_issuu

How it works

This module uses YouTube, Vimeo, Instagram, Facebook, Twitter and Issuu oEmbed services to generate the embed codes populated in your content. After these services are queried the first time, the embed code is cached so that it doesn't need to be pulled again.

Configuration

You may want to update the max width and max height settings on the module's configuration screen. You should make these consistent with what is supported by your site design.

If you change these max width / max height settings you may also want to check the box to clear cache, so that YouTube/Vimeo/Facebook/Twitter/Instagram/Issuu oembed services will generate new embed codes for you.

Using with Markdown, Textile or other LML

This text formatter is looking for a YouTube, Vimeo, Instagram, Facebook, Twitter or Issuu video URL surrounded by paragraph tags. As a result, if you are using Markdown or Textile (or something else like it) you want that text formatter to run before this one. That ensures that the expected paragraph tags will be present when VideoOrSocialPostEmbed runs. You can control the order that text formatters are run in by drag/drop sorting in the field editor.


Copyright 2018 by Ryan Cramer / Updated by Lex Sanchez

  • Like 18
  • Haha 1
Link to comment
Share on other sites

Thank you.

There is a problem here with 

https://www.instagram.com/p/BeA8p9AhA3b/

 

Error: Exception: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'embed_code' at row 1 (in /home/theo/public_html/pwdev/site/modules/VideoOrSocialPostEmbed/TextformatterVideoOrSocialPostEmbed.module line 113)

#0 /home/theo/public_html/pwdev/site/modules/VideoOrSocialPostEmbed/TextformatterVideoOrSocialPostEmbed.module(113): PDOStatement->execute()
#1 /home/theo/public_html/pwdev/site/modules/VideoOrSocialPostEmbed/TextformatterVideoOrSocialPostEmbed.module(337): TextformatterVideoOrSocialPostEmbed->getEmbedCode('://api.instagra...', 'ig-BeA8p9AhA3b')
#2 /home/theo/public_html/pwdev/site/modules/VideoOrSocialPostEmbed/TextformatterVideoOrSocialPostEmbed.module(152): TextformatterVideoOrSocialPostEmbed->embedInstagram('<p>https://www....')
#3 /home/theo/public_html/pwdev/wire/core/Textformatter.php(60): TextformatterVideoOrSocialPostEmbed->format('<p>https://www....


 

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...
  • 1 month later...

Hello,

When I try to install Video or Social Post Embed in ProcessWire 3.0.102, I have an error page with:

Error

Class '\VideoOrSocialPostEmbed' not found

and

File: /home/********/public_html/wire/core/Modules.php:535

525:                    ProcessWire::setCurrentInstance($wire2);
526:                } else {
527:                    $wire1 = null;
528:                }
529:            } else {
530:                $wire1 = null;
531:                $wire2 = null;
532:            }
533:            
534:            try {
535:                $module = $this->wire(new $className());
536:            } catch(\Exception $e) {
537:                $this->error(sprintf($this->_('Failed to construct module: %s'), $className) . " - " . $e->getMessage());
538:                $module = null;
539:            }

In version 2.8.62, the class wasn't found as well.

If I disable Tracy Debugger, I see:

Fatal error: Uncaught Error: Class '\VideoOrSocialPostEmbed' not found in /home/********/public_html/wire/core/Modules.php:535 Stack trace: #0 /home/********/public_html/wire/core/Modules.php(1704): ProcessWire\Modules->newModule('\\VideoOrSocialP...') #1 /home/********/public_html/wire/core/Wire.php(386): ProcessWire\Modules->___install('VideoOrSocialPo...', Array) #2 /home/********/public_html/wire/core/WireHooks.php(723): ProcessWire\Wire->_callMethod('___install', Array) #3 /home/********/public_html/wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\Modules), 'install', Array) #4 /home/********/public_html/wire/modules/Process/ProcessModule/ProcessModule.module(262): ProcessWire\Wire->__call('install', Array) #5 /home/********/public_html/wire/core/Wire.php(380): ProcessWire\ProcessModule->___execute() #6 /home/********/public_html/wire/core/WireHooks.php(723): ProcessWire\Wire->_callMethod('___execute', Array) #7 /home/********/public_html/wire/core/Wire.php(442): ProcessWire\WireHooks->runH in /home/********/public_html/wire/core/Modules.php on line 535

and

Error: Uncaught Error: Class '\VideoOrSocialPostEmbed' not found in /home/********/public_html/wire/core/Modules.php:535
Stack trace:
#0 /home/********/public_html/wire/core/Modules.php(1704): ProcessWire\Modules->newModule('\\VideoOrSocialP...')
#1 /home/********/public_html/wire/core/Wire.php(386): ProcessWire\Modules->___install('VideoOrSocialPo...', Array)
#2 /home/********/public_html/wire/core/WireHooks.php(723): ProcessWire\Wire->_callMethod('___install', Array)
#3 /home/********/public_html/wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\Modules), 'install', Array)
#4 /home/********/public_html/wire/modules/Process/ProcessModule/ProcessModule.module(262): ProcessWire\Wire->__call('install', Array)
#5 /home/********/public_html/wire/core/Wire.php(380): ProcessWire\ProcessModule->___execute()
#6 /home/********/public_html/wire/core/WireHooks.php(723): ProcessWire\Wire->_callMethod('___execute', Array)
#7 /home/********/public_html/wire/core/Wire.php(442): ProcessWire\WireHooks->runH (line 535 of /home/********/public_html/wire/core/Modules.php) 

This error message was shown because: site is in debug mode. ($config->debug = true; => /site/config.php). Error has been logged.

EDIT: I've just been able to install it via the backend (via the .zip URL from GitHub).
I had done it manually before. I had renamed the folder and the .module file VideoOrSocialPostEmbed (like in the documentation(s)). I hadn't done it again without renaming anything (or had I? I don't remember. Perhaps both, or the folder or the file) so I don't know if it was the reason (or one of them).
I've changed the PHP version from 7.1 to 7.2. Not sure it had an effect.

Edited by Christophe
Solved
Link to comment
Share on other sites

  • 2 weeks later...

Hello again,

For YouTube videos, would it be possible to make it work with &rel=0 added at the end of the URL (like it is the case with Video Embed For YouTube/Vimeo).

It works with the Video embed for YouTube and Vimeo module.

Thanks in advance for considering it.

Or if anyone knows how to enable it properly.

Edited by Christophe
Link to comment
Share on other sites

  • 9 months later...

Nice module.

You should add this:

 $embedCode = utf8_encode($data['html']);


When fetching data from providers, and set the data tables to mb4. Otherwise the output gets chewed up and throws errors. 

Test with instagram embed where there is an emoji in the title, e.g. https://www.instagram.com/p/BjXM8mInfN-/

Thanks for the module. 

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...
  • 8 months later...
  • 4 months later...

tested with 3.0.155 all embed works after two changes:

1- Find textformatter_video_or_social_embed table change embed_code collation to utf8mb4 if not  // changed to utf8mb4_unicode_ci

2- https://github.com/lexsanchez/VideoOrSocialPostEmbed/blob/57c254e64ae3c03139e2bb5119ffc676d92af39c/TextformatterVideoOrSocialPostEmbed.module#L103

update this line 

$embedCode = utf8_encode($data['html']);

 

 

Untitled-1.jpg

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

I am having difficulty implementing the fix that fliwire suggests above. Can someone share with me the proper syntax for the first step "1- Find textformatter_video_or_social_embed table change embed_code collation to utf8mb4 if not  // changed to utf8mb4_unicode_ci" I understand the need to change the characterset but don't know how as I'm very new to processwire, php and this forum so thanks in advance to anyone who can help. 

Link to comment
Share on other sites

5 hours ago, Benjamin said:

I am having difficulty implementing the fix that fliwire suggests above. Can someone share with me the proper syntax for the first step "1- Find textformatter_video_or_social_embed table change embed_code collation to utf8mb4 if not  // changed to utf8mb4_unicode_ci" I understand the need to change the characterset but don't know how as I'm very new to processwire, php and this forum so thanks in advance to anyone who can help. 

Hi Benjamin:

I have made the update indicated by Fliwire, update the module, it is an excellent recommendation Fliwire thanks. 

Link to comment
Share on other sites

  • 2 months later...

Hi,

Just installed this amazing module. All works fine but I am not able to embed FB videos. I get this error on the page:

Video Unavailable
This video may no longer exist, or you don't have permission to view it.
 
Is there a solution for this?
 
Thanks.
 
Gideon
Link to comment
Share on other sites

  • 3 weeks later...

Hi,

I have a strange question. I embed twitter link without problem, but the rendering is in spanish (and I tried many links with the same result). Believe me, I have absolutely nothing set to this language on my computer (either PW, or twitter cookie or anything). Have an idea how to revert back this to my language?

image.png.748b3a2d020a010a377b735945e2f301.png

Thanks

Mel

Link to comment
Share on other sites

  • 1 month later...

I've just noticed from today that YouTube video urls don't appear to be working. Vimeo and Twitter examples worked fine but I can't seem to get any Youtube URL to work now.

Is anyone aware of what this could be. I've tried different urls in different fileds but am having no joy. Previous links that works have now just reverted to a line of text.

Any help or advice would be greatly appreciated.

Thanks

Link to comment
Share on other sites

Thank you for this module!

It was not working for me until I found out that the HTML created by CKEditor was something like

<p style="margin-left:0cm; margin-right:0cm">https://www.youtube.com/watch?v=Lh63JcccM7k</p>

So the <p> tag has a style attribute. The regex (line 180 in module php) does not cater for that.

$regex = '#<p>\s*(https?://(?:www\.)?youtu(?:.be|be.com)+/(?:watch/?\?v=|v/)?([^\s&<\'"]+))(&[-_,.=&;a-zA-Z0-9]*)?.*?</p>#';

I adjusted it, so that it also works  for paragraphs with attributes

$regex = '#<p.*>\s*(https?://(?:www\.)?youtu(?:.be|be.com)+/(?:watch/?\?v=|v/)?([^\s&<\'"]+))(&[-_,.=&;a-zA-Z0-9]*)?.*?</p>#';

@Lex Sanchez maybe you want to implement this in your module.

  • Like 1
Link to comment
Share on other sites

On 10/16/2020 at 5:36 AM, Gideon So said:

All works fine but I am not able to embed FB videos. I get this error on the page:

Video Unavailable
This video may no longer exist, or you don't have permission to view it.

@Gideon So Unfortunately Facebook doesn't allow embedding content anymore (started on 24th October 2020) unless the site is authenticated. More here: https://developers.facebook.com/docs/plugins/oembed
This includes Facebook and Instagram

Link to comment
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
×
×
  • Create New...