Ohara YouTube Embed

Started by Suki, December 21, 2011, 03:04:59 PM

Previous topic - Next topic

themavesite

Quote from: Suki on November 09, 2016, 04:26:17 PM
There's no real way to fix the imgur gifv,  some of them simply do not play at all,  I don't know if there's a setting to avoid embed on external sites.

I'll look at the height and width

Yet I managed to fix it months ago. Here's the solution for OharaYTEmbed: gifv part:

function OYTE_Gifv($data)
{
global $modSettings, $txt;

loadLanguage('OharaYTEmbed');

// Gotta respect the master setting...
if (empty($data) || empty($modSettings['OYTE_master']))
return sprintf($txt['OYTE_unvalid_link'], 'gifv');

// Set a local var for laziness.
$videoID = '';
$result = '';

// We all love Regex.
$pattern = '/^(?:https?:\/\/)?(?:www\.)?i\.imgur\.com\/([a-z0-9]+)\.gifv/i';

// First attempt, pure regex.
if (empty($videoID) && preg_match($pattern, $data, $matches))
$videoID = isset($matches[1]) ? $matches[1] : false;


// At this point, all tests had miserably failed.
if (empty($videoID))
return sprintf($txt['OYTE_unvalid_link'], 'gifv');

// Got something!
else
$result = '<video style="max-width: 945px;" autoplay="" loop="" muted="" preload="" class="imgurgifvVid">
<source src="//i.imgur.com/'. $videoID .'.webm" type="video/webm">
<source src="//i.imgur.com/'. $videoID .'.mp4" type="video/mp4">
</video>';

return $result;
}


I believe you only checked for mp4 or webm, but you need to check for both  :)
TMS Forums
Since 2008 and still going strong! Join today! http://forums.themavesite.com/index.php

Snek Dankmemes

I can verify that that code works. Thanks again!

Snek Dankmemes

And this works for both Imgur and Gfycat and makes them click to play:

/* 2016/11/10
Pulseczar/puzzlecars/Alex O. did this ****** */
function OYTE_Gifv($data)
{
global $modSettings, $txt;

loadLanguage('OharaYTEmbed');

// Gotta respect the master setting...
if (empty($data) || empty($modSettings['OYTE_master']))
return sprintf($txt['OYTE_unvalid_link'], 'gifv');

// Set a local var for laziness.
$videoID = '';
$result = '';
$identifier = '';

// We all love Regex.
$imgurPattern = '/^(?:https?:\/\/)?(?:www\.)?i\.imgur\.com\/([a-z0-9]+)\.gifv/i';
$gfycatPattern = '/^(?:https?:\/\/)?(?:.+)?(?:gfycat\.com)\/(.+?)(?:\.[^.]*$|$)/i';

// First attempt, pure regex. Imgur
if (empty($videoID) && preg_match($imgurPattern, $data, $matches))
$videoID = isset($matches[1]) ? $matches[1] : false;


if(!empty($videoID))
{

$result = '
<div class="video-container">
<video style="max-width: 945px;" loop="" muted="" preload="" class="imgurgifvVid"
onmousedown="if (!this.controls && event.button == 0) { if (this.paused) { this.play(); } else { this.pause(); }}">
<source src="//i.imgur.com/'. $videoID .'.webm" type="video/webm">
<source src="//i.imgur.com/'. $videoID .'.mp4" type="video/mp4">
</video>
    <div style="font-size: 75%; font-style: italic; padding: 0px; margin: -2px 0px 2px 0px;">Click to Play</div>
</div> ';

return $result;
}

// gfycat
if (empty($identifier) && preg_match($gfycatPattern, $data, $matches))
{
$identifier = isset($matches[1]) ? $matches[1] : false;
}

if(!empty($identifier))
{
$result = '
<div class="video-container">
  <video preload="auto" muted="muted" loop="loop" poster="http://thumbs.gfycat.com/'.$identifier.'-poster.jpg" style="height: auto; max-width: 100%;" onmousedown="if (!this.controls && event.button == 0) { if (this.paused) { this.play(); } else { this.pause(); }}">
<source src="http://zippy.gfycat.com/'.$identifier.'.webm" type="video/webm" />
<source src="http://zippy.gfycat.com/'.$identifier.'.mp4" type="video/mp4" />
<source src="http://fat.gfycat.com/'.$identifier.'.webm" type="video/webm" />
<source src="http://fat.gfycat.com/'.$identifier.'.mp4" type="video/mp4" />
<source src="http://giant.gfycat.com/'.$identifier.'.webm" type="video/webm" />
<source src="http://giant.gfycat.com/'.$identifier.'.mp4" type="video/mp4" />
<a href="http://gfycat.com/'.$identifier.'">[ View Video ]</a>
  </video>
  <div style="font-size: 75%; font-style: italic; padding: 0px; margin: -2px 0px 2px 0px;">Click to Play</div>
</div> ';

return $result;
}


// At this point, all tests had miserably failed.
return sprintf($txt['OYTE_unvalid_link'], 'gifv');

}



It at least works with the [gifv] tag. I haven't tried auto-embed.

lahmfan

Quote from: Snek Dankmemes on November 10, 2016, 06:40:15 PM
And this works for both Imgur and Gfycat and makes them click to play:

/* 2016/11/10
Pulseczar/puzzlecars/Alex O. did this ****** */
function OYTE_Gifv($data)
{
global $modSettings, $txt;

loadLanguage('OharaYTEmbed');

// Gotta respect the master setting...
if (empty($data) || empty($modSettings['OYTE_master']))
return sprintf($txt['OYTE_unvalid_link'], 'gifv');

// Set a local var for laziness.
$videoID = '';
$result = '';
$identifier = '';

// We all love Regex.
$imgurPattern = '/^(?:https?:\/\/)?(?:www\.)?i\.imgur\.com\/([a-z0-9]+)\.gifv/i';
$gfycatPattern = '/^(?:https?:\/\/)?(?:.+)?(?:gfycat\.com)\/(.+?)(?:\.[^.]*$|$)/i';

// First attempt, pure regex. Imgur
if (empty($videoID) && preg_match($imgurPattern, $data, $matches))
$videoID = isset($matches[1]) ? $matches[1] : false;


if(!empty($videoID))
{

$result = '
<div class="video-container">
<video style="max-width: 945px;" loop="" muted="" preload="" class="imgurgifvVid"
onmousedown="if (!this.controls && event.button == 0) { if (this.paused) { this.play(); } else { this.pause(); }}">
<source src="//i.imgur.com/'. $videoID .'.webm" type="video/webm">
<source src="//i.imgur.com/'. $videoID .'.mp4" type="video/mp4">
</video>
    <div style="font-size: 75%; font-style: italic; padding: 0px; margin: -2px 0px 2px 0px;">Click to Play</div>
</div> ';

return $result;
}

// gfycat
if (empty($identifier) && preg_match($gfycatPattern, $data, $matches))
{
$identifier = isset($matches[1]) ? $matches[1] : false;
}

if(!empty($identifier))
{
$result = '
<div class="video-container">
  <video preload="auto" muted="muted" loop="loop" poster="http://thumbs.gfycat.com/'.$identifier.'-poster.jpg" style="height: auto; max-width: 100%;" onmousedown="if (!this.controls && event.button == 0) { if (this.paused) { this.play(); } else { this.pause(); }}">
<source src="http://zippy.gfycat.com/'.$identifier.'.webm" type="video/webm" />
<source src="http://zippy.gfycat.com/'.$identifier.'.mp4" type="video/mp4" />
<source src="http://fat.gfycat.com/'.$identifier.'.webm" type="video/webm" />
<source src="http://fat.gfycat.com/'.$identifier.'.mp4" type="video/mp4" />
<source src="http://giant.gfycat.com/'.$identifier.'.webm" type="video/webm" />
<source src="http://giant.gfycat.com/'.$identifier.'.mp4" type="video/mp4" />
<a href="http://gfycat.com/'.$identifier.'">[ View Video ]</a>
  </video>
  <div style="font-size: 75%; font-style: italic; padding: 0px; margin: -2px 0px 2px 0px;">Click to Play</div>
</div> ';

return $result;
}


// At this point, all tests had miserably failed.
return sprintf($txt['OYTE_unvalid_link'], 'gifv');

}



It at least works with the [gifv] tag. I haven't tried auto-embed.

this works for me as well. Thanks!

FragaCampos

Hello there.

The youtube videos in my forum stopped working. It only appears a black square (where the video was supposed to appear) and nothing happens.
Vimeo is working fine.

I've version 1.2.3 but version 1.2.8 seems to show the same behaviour.
Any help, please?

FragaCampos

Ok, I managed to solve the problem with this suggestion.

Quote from: Suki on June 28, 2015, 10:53:38 AM
You are using another mod which uses jquery with "jQuery" as the variable name, this mod (and SMF 2.1 too) uses "$".

You need to either change the other mod to use $ or replace all instance of $ with jQuery on the Themes/default/scripts/ohyoutube.min.js file file.

SirLouen

Found a little Issue in the error log
Not sure how is affecting to the forum but here is:
8: Undefined index: youtube
File: /var/www/site/Sources/Subs-Editor.php
Line: 1574

Line 1574 is:
'description' => $txt['youtube']

In context:
$context['bbc_tags'][] = array(
                        array(
                                'image' => 'youtube',
                                'code' => 'youtube',
                                'before' => '[youtube]',
                                'after' => '[/youtube]',
                                'description' => $txt['youtube']
                        ),
                        array(
                                'image' => 'jwp',
                                'code' => 'jwp',
                                'before' => '[jwp=425,344,image]',
                                'after' => '[/jwp]',
                                'description' => $txt['jwplayer']
                        ),


Any idea?

Kindred

$txt['youtube'] is not properly defined in your modifications.YOURLANGUAGE.php file
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Suki

This mod does not use that $txt string and it doesn't make any edit to that file. It seems you are using another youtube mod.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

SirLouen

Quote from: Suki on February 03, 2017, 09:24:37 AM
This mod does not use that $txt string and it doesn't make any edit to that file. It seems you are using another youtube mod.

Yep, seems so. Thanks for the response, i was able to solve it

OCJ

I felt like reporting this mod as unsafe....

Just moved host and did not know the php version was set lower than this mod requires. Perhaps on the package install page there should be a warning that installing on lower php version will crash the SMF installation. And maybe it is possible to show the current php version on the test page and warn (?).

White page.....
Parse error: syntax error, unexpected T_FUNCTION in /xxxxx/xxxx/public_html/Sources/OharaYTEmbed.php on line 28

This happened twice (moved site files and new installation - package manager backups failed to restore the site).
This happened when I first copied my installation over. I thought perhaps the files were corrupted so started over installing again  from the beginning. It takes time setting themes preferences, mod upload and install.
Then the site broke again after installing this mod.

Simple I thought, just put the mod backup files back and no  problem, Not so. Changed files were replaced with backups but still the same error message and no access to the site.
Only after  changing the htaccess file php version I could get on the site again.

Using package manager backup files - how come when the changed files are replaced with previous versions it still does not work?


Kindred

Why would that require an unsafe report?  And how is it this mod's fault?  If you are not checking the host for the proper version support before moving, of course it is not going to work...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

OCJ

#632
Most of all - using Backup files in Packages it does not even remove the problem - that is the main point.
After supposedly replacing all changed files with the backups, it still gives errors and a blank page. That is not supposed to happen.
It would be good practice to give a warning during install on the test page that displays if the php version is not new enough and warns that it will render the website unusable and would need server file manager or ftp access to repair it.

br360

The minimum PHP version requirements are listed on the main page of the mod-

QuoteDescription

For SMF 2.0.x only

Version 1.2.x and above requires PHP 5.3 or greater

Suki

If you are still unable to access your site, open your DB table using phpmyadmin or a similar tool, go the the settings table and look for the following rows:

integrate_pre_include
integrate_bbc_codes
integrate_bbc_buttons
integrate_general_mod_settings
integrate_load_theme

And remove any string that starts with the prefix: OYTE_

This will completely uninstall the mod.

Please at least try and check the mod's content before filling a report.  The mod does give a warning regarding PHP compatibility:

Quote
if (version_compare(PHP_VERSION, '5.3.0', '<'))
   exit('This mod needs PHP 5.3 or greater. You will not be able to install/use this mod, contact your host and ask for a php upgrade.');


These lines are taken straight from the mod's addHooks.php file. The mod is open source and its content is freely available for everyone to see at: https://github.com/MissAllSunday/OharaYouTubeEmbed/tree/1.2

The minimum required PHP version is visible listed on this mod's readme file too. The readme file is displayed every time you install this mod and it is the user's responsibility to fully read it before installing any mod.

If you have doubts about the mod's version and/or if it will be compatible with X PHP versions you should seek the mod's author for assistant before proceeding with the installation or the PHP version change.

The reason why this check failed during your installation is simple, your PHP version cannot parsed the PHP file because this mod uses new functionality that your PHP version cannot handle. Unfortunately, using closures on PHP versions lower than 5.3 will make PHP crash, theres no solution for this except not using closures.

Your PHP version cannot handle closures, closures are a PHP > 5.3 thing and there is no fallback for previous versions meaning there is absolutely nothing I can do to prevent this beyond adding a minimum required PHP version in the readme as well as a fallback PHP check and I already did those things.

BTW, any mod or any PHP script will have the same problem, even SMF itself. To check for the PHP version requires PHP itself, if PHP crashes, the check cannot be performed.


I did my fair share to tell the users about the minimum requirements and I'm sorry but it is out of the scope of this mod to prevent user related errors. By user related errors I mean users neglecting to read the mod's readme file on install.

Lastly, no. Replacing the files with a backup isn't enough to solve this particular problem, this mod uses hooks which means most of the core functionality of this mod is completely separated from SMF's files. To completely remove the mod, besides replacing your files, the hooks this mod uses needs to be removed from your DB. You can do so by calling the file removeHooks.php via your browser but since you are unable to use PHP you need to do so manually following the instructions I gave previously.

Again, if you require assistant on how to completely remove a mod you should seek the mod's author for help.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

OCJ

Thank you for all the information - I know you do a lot of work on mods here. I was annoyed at Kindreds attitude (as usual). My site is working fine so that not a problem, but I was worried that lurking below the surface was a problem in waiting. With the php version higher it is working but I would guess that if, for whatever reason, it reverted to an older version, The site would go down again.

I assumed mods were all designed so that the  package manager would remove them and leave the forum as it was beforehand. It was quite a shock wen I lost it twice and thought I had followed proper 'proceedures' to revert changes.

In the package manager when installing this mod there is only a 1 line message saying what the minimum php version is (I'm sure people assume that is for the mod to work).
There is no warning that it will make the site inaccesable - even after the files are replaced using backups.



I'm used to fiddling with mods and files and cpanel so its ok. For other people it could cause a lot of trouble - better warning about uninstalling and php version.

Anyway, as you can see from my link the site is fine - thanks again for all the detailed info. I will make the database changes in the near future. It would be worth mentioning this on the install test page of package manager.

Andy

Ninja ZX-10RR

Quote from: igirisjin on February 22, 2017, 06:21:23 PM
Thank you for all the information - I know you do a lot of work on mods here. I was annoyed at Kindreds attitude (as usual).
;D

Btw, in a very polite way, I think what igirisjin wants to say is that the warning should be:
"This mod requires php 5.3 version or greater, otherwise it may not only fail, but also make your forum unusable."
Or something similar :)

I'm pretty sure you realize that the meaning of the sentence as it is can be easily interpreted as "The mod will fail with php<5.3", which is different from "It will break everything if php<5.3" ;)

Not criticizing the code, that one seems to be fine (and you detailed it pretty well), but the warning could really use an improvement for clarity.
Quote from: BeastMode topic=525177.msg3720020#msg3720020
It's so powerful that on this post and even in the two PMs you sent me,you still answered my question very quickly and you're apologizing for the delay. You're the #1 support I've probably ever encountered man, so much respect for that. Thank you, and get better soon.

I'll keep this in my siggy for a while just to remind me that someone appreciated what I did while others didn't.

♥ Jess ♥

STOP EDITING MY PROFILE

Suki

Sorry but no. It is an statement, not a warning, as such, it requires no further improvements.

Why are you guys making such a fuss out of this?  this whole thing could have been easily avoided by ASKING first. As simple as that. Something like: "Hey, I didn't understood your minimum PHP version statement, can I install this mod on PHP x.x?"

Or how about this one: "I'm changing my PHP version to x, can this mod will work on it?".

Thats it. Thats all you guys needed to do. ASK.

You made a mistake. Plain and simple. What you guys need to do is learn from it to avoid doing it again instead of trying to blame the mod or try to find loopholes in the description.

Lastly, you guys should really, really read the mod's license, specially this bit:  https://github.com/MissAllSunday/OharaYouTubeEmbed/blob/1.2/License#L263
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Arantor

Considering that PHP 5.3 came out in 2009 and stopped receiving any kind of support from the PHP dev team in 2014, the only unsafe thing around here is the hosting company.

shawnb61

I don't think anyone knew in advance what would happen under these exact circumstances.  I would never have guessed the site might come down if you ignored the warning.

I'm not sure it's reasonable to expect every mod developer to test vs every ancient version to know all potential impacts.   
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

Advertisement: