Skip to content

Commit 808b507

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

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

admin/videos.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,16 @@
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+
5657
$videourl=Request::getVar('youtube_code', '');
5758
//Get youtube video id
58-
preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $videourl, $match);
59-
$videocode = $match[1];
59+
if (11 === mb_strlen($videourl)) {
60+
$videocode = $videourl;
61+
} else {
62+
//Get youtube video id
63+
preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $videourl, $match);
64+
$videocode = $match[1];
65+
}
6066
$videoObject->setVar('youtube_code', $videocode);
6167
$videoObject->setVar('featured_video', Request::getVar('featured_video', ''));
6268
$dateTimeObj = \DateTime::createFromFormat(_SHORTDATESTRING, Request::getString('date_created', '', 'POST'));

submitVideo.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@
4242
$newvideo->setVar('video_title', Request::getString('title', '', 'POST'));
4343
$newvideo->setVar('video_desc', Request::getString('caption', '', 'POST'));
4444

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];
45+
if (11 === mb_strlen($url)) {
46+
$code = $url;
47+
} else {
48+
//Get youtube video id
49+
preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match);
50+
$code = $match[1];
51+
}
4852

4953
$newvideo->setVar('youtube_code', $code);
5054
$newvideo->setVar('featured_video', Request::getInt('featured_video', 0, 'POST'));

0 commit comments

Comments
 (0)