Commit 64c8163e authored by Lisa Seeto's avatar Lisa Seeto Committed by Robert Lyon
Browse files

Bug 1806169: starting youtubevideo at special timestamp does not work



Updated url to replace ?t= with ?start=

behatnotneeded

Change-Id: Icc047ef0d8866dfbe7d7a21773ebfa7d440102ae
Signed-off-by: default avatarLisa Seeto <lisaseeto@catalyst.net.nz>
parent 6627ff82
......@@ -19,20 +19,20 @@ class Media_youtube implements MediaBase {
self::$iframe_sources = array(
array(
'match' => '#^https?://(www\.)?youtube\.com/watch\?v=([a-zA-Z0-9_=-]+).*#',
'url' => $this->httpstr . '://www.youtube.com/embed/$2'
'match' => '#^https?://(www\.)?youtube\.com/watch\?v=([a-zA-Z0-9_=-]+).*?\&?(t|start)?=?([0-9]+)?#',
'url' => $this->httpstr . '://www.youtube.com/embed/$2?start=$4'
),
array(
'match' => '#^https?://(www\.)?youtube\.com/embed/([a-zA-Z0-9\-_+]*).*#',
'url' => $this->httpstr . '://www.youtube.com/embed/$2',
'match' => '#^https?://(www\.)?youtube\.com/embed/([a-zA-Z0-9\-_+]*)\??(t|start)?=?([0-9]+)?#',
'url' => $this->httpstr . '://www.youtube.com/embed/$2?start=$4',
),
array(
'match' => '#^https?://(www\.)?youtu\.be/([a-zA-Z0-9\-_+]*)#',
'url' => $this->httpstr . '://www.youtube.com/embed/$2',
'match' => '#^https?://(www\.)?youtu\.be/([a-zA-Z0-9\-_+]*)\??(t|start)=?([0-9]+)?#',
'url' => $this->httpstr . '://www.youtube.com/embed/$2?start=$4',
),
array(
'match' => '#^https?://(www\.)?youtube\-nocookie\.com/embed/([a-zA-Z0-9\-_+]*)#',
'url' => $this->httpstr . '://www.youtube-nocookie.com/embed/$2',
'match' => '#^https?://(www\.)?youtube\-nocookie\.com/embed/([a-zA-Z0-9\-_+]*)\??(t|start)?=?([0-9]+)?#',
'url' => $this->httpstr . '://www.youtube-nocookie.com/embed/$2?start=$4',
),
);
}
......
......@@ -1196,5 +1196,36 @@ function xmldb_core_upgrade($oldversion=0) {
log_debug('Clearing cache for new people menu structure');
}
if ($oldversion < 2019040400) {
log_debug('Adding timestamps to youtube videos');
$sql = "SELECT id FROM {block_instance} WHERE blocktype = 'externalvideo' AND configdata LIKE '%youtube%'";
$records = get_records_sql_array($sql, array());
if ($records) {
$key = 'youtube';
$count = 0;
$limit = 1000;
$total = count($records);
require_once(get_config('docroot').'blocktype/lib.php');
foreach ($records as $record) {
$bi = new BlockInstance($record->id);
$configdata = $bi->get('configdata');
if (isset($configdata['videoid']) && strpos($configdata['videoid'], $key) !== false ) {
$configdata['videoid'] = preg_replace('/(\?|\&)(t=)/', '$1start=', $configdata['videoid']);
}
if (isset($configdata['html']) && strpos($configdata['html'], $key) !== false ) {
$configdata['html'] = preg_replace('/(\?|\&)(t=)/', '$1start=', $configdata['html']);
}
$bi->set('configdata', $configdata);
$bi->commit();
$count++;
if (($count % $limit) == 0 || $count == $total) {
log_debug("$count/$total");
set_time_limit(30);
}
}
}
}
return $status;
}
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2019040200;
$config->version = 2019040400;
$config->series = '19.10';
$config->release = '19.10dev';
$config->minupgradefrom = 2017031605;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment