Browse Source

Fix Youtube video ID

pull/189/head
Danang Probo Sayekti 10 years ago
parent
commit
676ebc3746
2 changed files with 15 additions and 3 deletions
  1. +2
    -2
      system/htmly.php
  2. +13
    -1
      system/includes/functions.php

+ 2
- 2
system/htmly.php View File

@ -1853,8 +1853,8 @@ get('/:year/:month/:name/edit', function ($year, $month, $name) {
} elseif (isset($current->audio)) {
$var = 'edit-audio';
} elseif (isset($current->video)) {
$var = 'edit-video'; }
else {
$var = 'edit-video';
} else {
$var = 'edit-post';
}


+ 13
- 1
system/includes/functions.php View File

@ -267,7 +267,7 @@ function get_posts($posts, $page = 1, $perpage = 0)
// Extract the title and body
$post->title = get_content_tag('t', $content, 'Untitled: ' . date('l jS \of F Y', $post->date));
$post->image = get_content_tag('image', $content);
$post->video = str_replace(array("http://", "https://", "www.", "youtube", ".com", "/watch?v=", "/embed/"), "", get_content_tag('video', $content));
$post->video = get_youtube_id(get_content_tag('video', $content));
$post->link = get_content_tag('link', $content);
$post->quote = get_content_tag('quote', $content);
$post->audio = get_content_tag('audio', $content);
@ -2011,3 +2011,15 @@ function isCaptcha($reCaptchaResponse)
}
return ($json['success']);
}
// Get YouTube video ID
function get_youtube_id($url)
{
if(empty($url)) {
return;
}
preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $url, $matches);
return $matches[1];
}

Loading…
Cancel
Save