Skip to content

Commit 86e27fd

Browse files
committed
Add option to use full youtube url
1 parent b62c4fb commit 86e27fd

7 files changed

Lines changed: 19 additions & 15 deletions

File tree

admin/videos.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@
5353
$videoObject->setVar('uid_owner', Request::getVar('uid_owner', ''));
5454
$videoObject->setVar('video_title', Request::getVar('video_title', ''));
5555
$videoObject->setVar('video_desc', Request::getVar('video_desc', ''));
56-
$videoObject->setVar('youtube_code', Request::getVar('youtube_code', ''));
56+
$videourl=Request::getVar('youtube_code', '');
57+
//Get youtube video id
58+
preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $videourl, $match);
59+
$videocode = $match[1];
60+
$videoObject->setVar('youtube_code', $videocode);
5761
$videoObject->setVar('featured_video', Request::getVar('featured_video', ''));
5862
$dateTimeObj = \DateTime::createFromFormat(_SHORTDATESTRING, Request::getString('date_created', '', 'POST'));
5963
$videoObject->setVar('date_created', $dateTimeObj->getTimestamp());

assets/js/suico.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ $(document).ready(function () {
2929
$(document).ready(function () {
3030
$("form#form_videos").submit(function () {
3131

32-
if ($("form#form_videos input#codigo").val() === "") {
32+
if ($("form#form_videos input#videourl").val() === "") {
3333
window.alert("Please enter YouTube code");
34-
$("form#form_videos input#codigo").focus();
34+
$("form#form_videos input#videourl").focus();
3535
return false;
3636
}
3737
return true;

class/VideoHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public function renderFormSubmit(
312312
$xoopsTpl
313313
) {
314314
$form = new XoopsThemeForm(\_MD_SUICO_ADDFAVORITEVIDEOS, 'form_videos', 'submitVideo.php', 'post', true);
315-
$field_code = new XoopsFormText(\_MD_SUICO_YOUTUBECODE, 'codigo', 50, 250);
315+
$field_code = new XoopsFormText(\_MD_SUICO_YOUTUBECODE, 'videourl', 50, 250);
316316
$field_desc = new XoopsFormTextArea(\_MD_SUICO_CAPTION, 'caption');
317317
$form->setExtra('enctype="multipart/form-data"');
318318
$buttonSend = new XoopsFormButton('', 'submit_button', \_MD_SUICO_ADDVIDEO, 'submit');

docs/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<h5>3.5 Beta 2 [NOT RELEASED]</h5> Dev: XOOPS 2.5.11, PHP 7.4.5
22
<hr>
33
- Add youtube code help (liomj)
4+
- Add option to use full youtube url in code input (liomj)
45

56
<h5>3.5 Beta 1 [2020-05-07]</h5> Dev: XOOPS 2.5.11, PHP 7.4.5
67
<hr>

language/english/main.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,4 +529,4 @@
529529
define('_MD_SUICO_ONECOMMENT', '1 comment');
530530
define('_MD_SUICO_NO_COMMENTS', 'No comments');
531531
define('_MD_SUICO_COMMENTS', 'Comments');
532-
define('_MD_SUICO_YOUTUBE_CODEHELP', '<strong>Example:</strong> https://www.youtube.com/watch?v=<span style="color:red;font-weight:bold">jNQXAC9IVRw</span> :: Input the red part only</strong>');
532+
define('_MD_SUICO_YOUTUBE_CODEHELP', '<strong>Example:</strong> https://www.youtube.com/watch?v=jNQXAC9IVRw');

submitVideo.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* Factory of pictures created
2929
*/
3030
$videoFactory = new Suico\VideoHandler($xoopsDB);
31-
$url = Request::getUrl('codigo', '', 'POST');
31+
$url = Request::getUrl('videourl', '', 'POST');
3232
if (!$GLOBALS['xoopsSecurity']->check()) {
3333
redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 3, _MD_SUICO_TOKENEXPIRED);
3434
}
@@ -41,12 +41,11 @@
4141
$newvideo->setVar('uid_owner', (int)$xoopsUser->getVar('uid'));
4242
$newvideo->setVar('video_title', Request::getString('title', '', 'POST'));
4343
$newvideo->setVar('video_desc', Request::getString('caption', '', 'POST'));
44-
if (11 === mb_strlen($url)) {
45-
$code = $url;
46-
} else {
47-
$position_of_code = mb_strpos($url, 'v=');
48-
$code = mb_substr($url, $position_of_code + 2, 11);
49-
}
44+
45+
//Get youtube video id
46+
preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match);
47+
$code = $match[1];
48+
5049
$newvideo->setVar('youtube_code', $code);
5150
$newvideo->setVar('featured_video', Request::getInt('featured_video', 0, 'POST'));
5251
$newvideo->setVar('date_created', \time());

templates/suico_videos.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
<div class="form-group">
3535
<label for="video"><strong> <{$lang_youtubecodeLabel}></strong></label>
36-
<input type='text' name='codigo' id='codigo' class='form-control' value=''>
36+
<input type='text' name='videourl' id='videourl' class='form-control' value=''>
3737
` <label for="video"><small><{$smarty.const._MD_SUICO_YOUTUBE_CODEHELP}></small></label>
3838
</div>
3939

@@ -44,9 +44,9 @@
4444
<!--//
4545
function xoopsFormValidate_form_videos() {
4646
myform = window.document.form_videos;
47-
if (myform.codigo.value == "") {
47+
if (myform.videourl.value == "") {
4848
window.alert("Please enter YouTube code");
49-
myform.codigo.focus();
49+
myform.videourl.focus();
5050
return false;
5151
}
5252

0 commit comments

Comments
 (0)