Skip to content

Commit

Permalink
- Added support for imgur gifv format
Browse files Browse the repository at this point in the history
- Move the css and js calls to integrate_load_theme hook.

Signed-off-by: Suki <suki@missallsunday.com>
  • Loading branch information
MissAllSunday committed Feb 18, 2016
1 parent 01a695b commit 54e8f28
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 41 deletions.
4 changes: 2 additions & 2 deletions OharaYTEmbed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<modification xmlns="http://www.simplemachines.org/xml/modification" xmlns:smf="http://www.simplemachines.org/">
<id>Suki:ohara_youtube_embed</id>
<version>1.2.4</version>
<version>1.2.5</version>

<file name="$sourcedir/Post.php">
<operation>
Expand All @@ -12,7 +12,7 @@
</operation>
<operation>
<search position="replace"><![CDATA[<img>]]></search>
<add><![CDATA[<img><iframe><div>]]></add>
<add><![CDATA[<img><iframe><video><div>]]></add>
</operation>
</file>
<file name="$sourcedir/Subs.php">
Expand Down
99 changes: 85 additions & 14 deletions Sources/OharaYTEmbed.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

/*
* @package Ohara Youtube Embed mod
* @version 1.2.4
* @version 1.2.5
* @author Jessica González <missallsunday@simplemachines.org>
* @copyright Copyright (C) 2015 Jessica González
* @copyright Copyright (C) 2016 Jessica González
* @license http://www.mozilla.org/MPL/ MPL 2.0
*/

Expand Down Expand Up @@ -77,11 +77,30 @@ function OYTE_bbc_add_code(&$codes)
},
'disabled_content' => '$1',
'block_level' => true,
),
array(
'tag' => 'gifv',
'type' => 'unparsed_content',
'content' => '$1',
'validate' => function (&$tag, &$data, $disabled) use ($txt)
{
// This tag was disabled.
if (!empty($disabled['gifv']))
return;

if (empty($data))
$data = $txt['OYTE_unvalid_link'];

else
$data = OYTE_Gifv(trim(strtr($data, array('<br />' => ''))));
},
'disabled_content' => '$1',
'block_level' => true,
)
);
}

/* The bbc button */
// The bbc button.
function OYTE_bbc_add_button(&$buttons)
{
global $txt, $modSettings;
Expand All @@ -107,9 +126,16 @@ function OYTE_bbc_add_button(&$buttons)
'description' => $txt['OYTE_vimeo_desc'],
);

$buttons[count($buttons) - 1][] =array(
'image' => 'gifv',
'code' => 'gifv',
'before' => '[gifv]',
'after' => '[/gifv]',
'description' => $txt['OYTE_gifv_desc'],
);
}

/* Don't bother on create a whole new page for this, let's use integrate_general_mod_settings ^o^ */
// Don't bother on create a whole new page for this, let's use integrate_general_mod_settings ^o^.
function OYTE_settings(&$config_vars)
{
global $txt;
Expand All @@ -124,7 +150,7 @@ function OYTE_settings(&$config_vars)
$config_vars[] = '';
}

/* Take the url, take the video ID and return the embed code */
// Take the url, take the video ID and return the embed code.
function OYTE_Main($data)
{
global $modSettings, $txt;
Expand All @@ -135,34 +161,34 @@ function OYTE_Main($data)
if (empty($data) || empty($modSettings['OYTE_master']))
return sprintf($txt['OYTE_unvalid_link'], 'youtube');

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

// Check if the user provided the youtube ID
if (preg_match('/^[a-zA-z0-9_-]{11}$/', $data) > 0)
$videoID = $data;

/* We all love Regex */
// We all love Regex.
$pattern = '#^(?:https?://)?(?:www\.)?(?:youtu\.be/|youtube\.com(?:/embed/|/v/|/watch\?v=|/watch\?.+&v=))([\w-]{11})(?:.+)?$#x';

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

/* Give another regex a chance */
// Give another regex a chance.
elseif (empty($videoID) && preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $data, $match))
$videoID = isset($match[1]) ? $match[1] : false;

/* No?, then one last chance, let PHPs native parse_url() function do the dirty work */
// No?, then one last chance, let PHPs native parse_url() function do the dirty work.
elseif (empty($videoID))
{
/* This relies on the url having ? and =, this is only an emergency check */
// This relies on the url having ? and =, this is only an emergency check.
parse_str(parse_url($data, PHP_URL_QUERY), $videoID);
$videoID = isset($videoID['v']) ? $videoID['v'] : false;
}

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

Expand Down Expand Up @@ -194,11 +220,45 @@ function OYTE_Vimeo($data)
if (!empty($jsonArray) && is_array($jsonArray) && !empty($jsonArray['html']))
return '<div class="oharaEmbed vimeo">'. str_replace('<iframe', '<iframe width="'. (empty($modSettings['OYTE_video_width']) ? '480' : $modSettings['OYTE_video_width']) .'px" height="'. (empty($modSettings['OYTE_video_height']) ? '270' : $modSettings['OYTE_video_height']) .'px"', $jsonArray['html']) .'</div>';


else
return sprintf($txt['OYTE_unvalid_link'], 'vimeo');
}

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'], 'youtube');

// 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 preload="auto" autoplay="autoplay" loop="loop" style="max-width: '. (empty($modSettings['OYTE_video_width']) ? '480' : $modSettings['OYTE_video_width']) .'px; min-height: '. (empty($modSettings['OYTE_video_height']) ? '270' : $modSettings['OYTE_video_height']) .'px;" src="//i.imgur.com/'. $videoID .'.webm">
<source src="//i.imgur.com/'. $videoID .'.webm" type="video/webm"></source>
</video>';

return $result;
}

function OYTE_Preparse($message)
{
global $context, $modSettings;
Expand All @@ -215,6 +275,8 @@ function OYTE_Preparse($message)
$vimeo = '~(?<=[\s>\.(;\'"]|^)(?:https?\:\/\/)?(?:www\.)?vimeo.com\/(?:album\/|groups\/(.*?)\/|channels\/(.*?)\/)?[0-9]+\??[/\w\-_\~%@\?;=#}\\\\]?~';
$youtube = '~(?<=[\s>\.(;\'"]|^)(?:http|https):\/\/[\w\-_%@:|]?(?:www\.)?(?:youtu\.be/|youtube\.com(?:/embed/|/v/|/watch\?v=|/watch\?.+&v=))([\w-]{11})(?=[^\w-]|$)(?![?=&+%\w.-]*(?:[\'"][^<>]*> | </a> ))[?=&+%\w.-]*[/\w\-_\~%@\?;=#}\\\\]?~ix';

$gifv = '~(?<=[\s>\.(;\'"]|^)(?:http|https):\/\/[\w\-_%@:|]?(?:www\.)?i\.imgur\.com\/([a-z0-9]+)\.gifv(?=[^\w-]|$)(?![?=&+%\w.-]*(?:[\'"][^<>]*> | <\/a> ))[?=&+%\w.-]*[\/\w\-_\~%@\?;=#}\\\\]?~ix';

// Is this a YouTube video url?
$message = preg_replace_callback(
$youtube,
Expand All @@ -233,10 +295,19 @@ function ($matches) {
$message
);

// imgur gifv format.
$message = preg_replace_callback(
$gifv,
function ($matches) {
return '[gifv]'. $matches[0] .'[/gifv]';
},
$message
);

return $message;
}

/* DUH! WINNING! */
// DUH! WINNING!.
function OYTE_care(&$dummy)
{
global $context, $settings, $modSettings;
Expand Down
5 changes: 3 additions & 2 deletions Themes/default/languages/OharaYTEmbed.english-utf8.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

/*
* @package Ohara Youtube Embed mod
* @version 1.2.4
* @version 1.2.5
* @author Jessica González <missallsunday@simplemachines.org>
* @copyright Copyright (C) 2015 Jessica González
* @copyright Copyright (C) 2016 Jessica González
* @license http://www.mozilla.org/MPL/ MPL 2.0
*/

Expand All @@ -20,5 +20,6 @@
$txt['OYTE_video_height_sub'] = 'If empty it will take the default value: 270';
$txt['OYTE_desc'] = 'Embed a youtube video url';
$txt['OYTE_vimeo_desc'] = 'Embed a vimeo video url';
$txt['OYTE_gifv_desc'] = 'Embed an imgur gifv url';
$txt['OYTE_unvalid_link'] = 'Not a valid %s URL';
$txt['OYTE_title'] = 'Ohara Youtube|Vimeo Embed mod';
5 changes: 3 additions & 2 deletions Themes/default/languages/OharaYTEmbed.english.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

/*
* @package Ohara Youtube Embed mod
* @version 1.2.4
* @version 1.2.5
* @author Jessica Gonzalez <missallsunday@simplemachines.org>
* @copyright Copyright (C) 2015 Jessica Gonzalez
* @copyright Copyright (C) 2016 Jessica Gonzalez
* @license http://www.mozilla.org/MPL/ MPL 2.0
*/

Expand All @@ -20,5 +20,6 @@
$txt['OYTE_video_height_sub'] = 'If empty it will take the default value: 270';
$txt['OYTE_desc'] = 'Embed a youtube video url';
$txt['OYTE_vimeo_desc'] = 'Embed a vimeo video url';
$txt['OYTE_gifv_desc'] = 'Embed an imgur gifv url';
$txt['OYTE_unvalid_link'] = 'Not a valid %s URL';
$txt['OYTE_title'] = 'Ohara Youtube|Vimeo Embed mod';
5 changes: 3 additions & 2 deletions Themes/default/languages/OharaYTEmbed.spanish_es-utf8.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

/*
* @package Ohara Youtube Embed mod
* @version 1.2.4
* @version 1.2.5
* @author Jessica González <missallsunday@simplemachines.org>
* @copyright Copyright (C) 2015 Jessica González
* @copyright Copyright (C) 2016 Jessica González
* @license http://www.mozilla.org/MPL/ MPL 2.0
*/

Expand All @@ -20,5 +20,6 @@
$txt['OYTE_video_height_sub'] = 'Si se deja vacio se usará el valor por defecto: 270';
$txt['OYTE_desc'] = 'Inserta un video desde youtube';
$txt['OYTE_vimeo_desc'] = 'Inserta un video desde vimeo';
$txt['OYTE_gifv_desc'] = 'Inserta un gifv de imgur';
$txt['OYTE_unvalid_link'] = 'No es una dirección de %s válida';
$txt['OYTE_title'] = 'Ohara Youtube|Vimeo Embed mod';
5 changes: 3 additions & 2 deletions Themes/default/languages/OharaYTEmbed.spanish_es.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

/*
* @package Ohara Youtube Embed mod
* @version 1.2.4
* @version 1.2.5
* @author Jessica Gonzalez <missallsunday@simplemachines.org>
* @copyright Copyright (C) 2015 Jessica Gonzalez
* @copyright Copyright (C) 2016 Jessica Gonzalez
* @license http://www.mozilla.org/MPL/ MPL 2.0
*/

Expand All @@ -20,5 +20,6 @@
$txt['OYTE_video_height_sub'] = 'Si se deja vacio se usar&aacute; el valor por defecto: 270';
$txt['OYTE_desc'] = 'Inserta un video desde youtube';
$txt['OYTE_vimeo_desc'] = 'Inserta un video desde vimeo';
$txt['OYTE_gifv_desc'] = 'Inserta un gifv de imgur';
$txt['OYTE_unvalid_link'] = 'No es una direcci&oacute;n de %s v&aacute;lida';
$txt['OYTE_title'] = 'Ohara Youtube|Vimeo Embed mod';
5 changes: 3 additions & 2 deletions Themes/default/languages/OharaYTEmbed.spanish_latin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

/*
* @package Ohara Youtube Embed mod
* @version 1.2.4
* @version 1.2.5
* @author Jessica Gonz&aacute;lez <missallsunday@simplemachines.org>
* @copyright Copyright (C) 2015 Jessica Gonz&aacute;lez
* @copyright Copyright (C) 2016 Jessica Gonz&aacute;lez
* @license http://www.mozilla.org/MPL/ MPL 2.0
*/

Expand All @@ -20,5 +20,6 @@
$txt['OYTE_video_height_sub'] = 'Si se deja vacio se usar&aacute; el valor por defecto: 270';
$txt['OYTE_desc'] = 'Inserta un video desde youtube';
$txt['OYTE_vimeo_desc'] = 'Inserta un video desde vimeo';
$txt['OYTE_gifv_desc'] = 'Inserta un gifv de imgur';
$txt['OYTE_unvalid_link'] = 'No es una direcci&oacute;n de %s v&aacute;lida';
$txt['OYTE_title'] = 'Ohara Youtube|Vimeo Embed mod';
5 changes: 3 additions & 2 deletions Themes/default/languages/OharaYTEmbed.spanish_latin_utf8.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

/*
* @package Ohara Youtube Embed mod
* @version 1.2.4
* @version 1.2.5
* @author Jessica González <missallsunday@simplemachines.org>
* @copyright Copyright (C) 2015 Jessica González
* @copyright Copyright (C) 2016 Jessica González
* @license http://www.mozilla.org/MPL/ MPL 2.0
*/

Expand All @@ -20,5 +20,6 @@
$txt['OYTE_video_height_sub'] = 'Si se deja vacio se usará el valor por defecto: 270';
$txt['OYTE_desc'] = 'Inserta un video desde youtube';
$txt['OYTE_vimeo_desc'] = 'Inserta un video desde vimeo';
$txt['OYTE_gifv_desc'] = 'Inserta un gifv de imgur';
$txt['OYTE_unvalid_link'] = 'No es una dirección de %s válida';
$txt['OYTE_title'] = 'Ohara Youtube|Vimeo Embed mod';
4 changes: 2 additions & 2 deletions Themes/default/scripts/ohyoutube.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright (c) 2015 Jessica González
Copyright (C) 2016 Jessica González
@license http://www.mozilla.org/MPL/ MPL 2.0
@version 1.2.4
@version 1.2.5
*/

var _oh = function(){
Expand Down
4 changes: 2 additions & 2 deletions Themes/default/scripts/ohyoutube.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions addHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

/*
* @package Ohara Youtube Embed mod
* @version 1.2.4
* @version 1.2.5
* @author Jessica González <missallsunday@simplemachines.org>
* @copyright Copyright (C) 2015 Jessica González
* @copyright Copyright (C) 2016 Jessica González
* @license http://www.mozilla.org/MPL/ MPL 2.0
*/

Expand All @@ -21,7 +21,7 @@
'integrate_bbc_codes' => 'OYTE_bbc_add_code',
'integrate_bbc_buttons' => 'OYTE_bbc_add_button',
'integrate_general_mod_settings' => 'OYTE_settings',
'integrate_menu_buttons' => 'OYTE_care', // Yes, a whole hook function for a copyright...
'integrate_load_theme' => 'OYTE_care', // Yes, a whole hook function for a copyright...
);

foreach ($hooks as $hook => $function)
Expand Down
Binary file added gifv.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion package-info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<name>Ohara YouTube Embed</name>
<id>Suki:ohara_youtube_embed</id>
<version>1.2.4</version>
<version>1.2.5</version>
<type>modification</type>

<install for="2.0 - 2.0.99">
Expand All @@ -16,6 +16,7 @@
<require-file name="Sources/OharaYTEmbed.php" destination="$sourcedir">The main file</require-file>
<require-file name="youtube.gif" destination="$imagesdir/bbc" />
<require-file name="vimeo.gif" destination="$imagesdir/bbc" />
<require-file name="gifv.gif" destination="$imagesdir/bbc" />
<redirect url="index.php?action=admin;area=modsettings;sa=general" timeout="1000"></redirect>
</install>

Expand All @@ -31,6 +32,7 @@
<remove-file name="$languagedir/OharaYTEmbed.spanish_latin" />
<remove-file name="$imagesdir/bbc/youtube.gif" />
<remove-file name="$imagesdir/bbc/vimeo.gif" />
<remove-file name="$imagesdir/bbc/gifv.gif" />
<remove-file name="$themedir/scripts/ohyoutube.js" />
<remove-file name="$themedir/scripts/ohyoutube.min.js" />
<remove-file name="$themedir/css/oharaEmbed.css" />
Expand Down
Loading

0 comments on commit 54e8f28

Please sign in to comment.