Commit 9a2cfb06 authored by Eugene Venter's avatar Eugene Venter
Browse files

Embed external videos and Google Apps over https



Bug #809058

If the site is running https, embed external videos and google apps
over https where possible.

Change-Id: Id1d4b66c1f04587d4864126c2e58d2167e45fe70
Signed-off-by: default avatarEugene Venter <eugene@catalyst.net.nz>
parent 5b9569fb
......@@ -4,25 +4,34 @@ require_once(dirname(__FILE__) . '/../Media_base.php');
class Media_prezi implements MediaBase {
private static $base_url = 'http://www.prezi.com/';
private $httpstr;
private static $base_url;
private static $default_width = 550;
private static $default_height = 400;
private static $embed_sources = array(
array(
'match' => '#.*https?://(www\.)?prezi\.com/bin/preziloader\.swf\?prezi_id=([a-zA-Z0-9\-_]+).*#',
'url' => 'http://prezi.com/bin/preziloader.swf?prezi_id=$2',
),
array(
'match' => '#.*?"preziEmbed_([a-zA-Z0-9\-_]+)".*#',
'url' => 'http://prezi.com/bin/preziloader.swf?prezi_id=$1',
),
array(
'match' => '#.*?prezi.com/([a-zA-Z0-9\-_]+)/.*#',
'url' => 'http://prezi.com/bin/preziloader.swf?prezi_id=$1',
),
);
private static $embed_sources;
function __construct() {
$this->httpstr = is_https() ? 'https' : 'http';
self::$base_url = $this->httpstr . '://www.prezi.com/';
self::$embed_sources = array(
array(
'match' => '#.*https?://(www\.)?prezi\.com/bin/preziloader\.swf\?prezi_id=([a-zA-Z0-9\-_]+).*#',
'url' => $this->httpstr . '://prezi.com/bin/preziloader.swf?prezi_id=$2',
),
array(
'match' => '#.*?"preziEmbed_([a-zA-Z0-9\-_]+)".*#',
'url' => $this->httpstr . '://prezi.com/bin/preziloader.swf?prezi_id=$1',
),
array(
'match' => '#.*?prezi.com/([a-zA-Z0-9\-_]+)/.*#',
'url' => $this->httpstr . '://prezi.com/bin/preziloader.swf?prezi_id=$1',
),
);
}
public function process_url($input, $width=0, $height=0) {
$width = $width ? (int)$width : self::$default_width;
......
......@@ -4,25 +4,33 @@ require_once(dirname(__FILE__) . '/../Media_base.php');
class Media_vimeo implements MediaBase {
private static $base_url = 'http://vimeo.com/';
private $httpstr;
private static $base_url;
private static $default_width = 400;
private static $default_height = 225;
private static $iframe_sources = array(
array(
'match' => '#.*http://vimeo\.com/moogaloop\.swf\?clip_id=([0-9]+).*#',
'url' => 'http://player.vimeo.com/video/$1'
),
array(
'match' => '#.*http://player\.vimeo\.com/video/([0-9]+).*#',
'url' => 'http://player.vimeo.com/video/$1'
),
array(
'match' => '#https?://(www\.|secure\.)?vimeo\.com/([0-9]+)#',
'url' => 'http://player.vimeo.com/video/$2'
),
);
private static $iframe_sources;
function __construct() {
$this->httpstr = is_https() ? 'https' : 'http';
self::$base_url = $this->httpstr . '://vimeo.com/';
self::$iframe_sources = array(
array(
'match' => '#.*http://vimeo\.com/moogaloop\.swf\?clip_id=([0-9]+).*#',
'url' => $this->httpstr . '://player.vimeo.com/video/$1'
),
array(
'match' => '#.*http://player\.vimeo\.com/video/([0-9]+).*#',
'url' => $this->httpstr . '://player.vimeo.com/video/$1'
),
array(
'match' => '#https?://(www\.|secure\.)?vimeo\.com/([0-9]+)#',
'url' => $this->httpstr . '://player.vimeo.com/video/$2'
),
);
}
public function process_url($input, $width=0, $height=0) {
$width = $width ? (int)$width : self::$default_width;
......
......@@ -4,25 +4,34 @@ require_once(dirname(__FILE__) . '/../Media_base.php');
class Media_voicethread implements MediaBase {
private static $base_url = 'http://www.voicethread.com/';
private $httpstr;
private static $base_url;
private static $default_width = 480;
private static $default_height = 360;
private static $embed_sources = array(
array(
'match' => '#.*https?://(www\.)?voicethread\.com/book\.swf\?b=([0-9]+).*#',
'url' => 'http://voicethread.com/book.swf?b=$2',
),
array(
'match' => '#.*https?://(www\.)?voicethread\.com/share/([0-9]+).*#',
'url' => 'http://voicethread.com/book.swf?b=$2',
),
array(
'match' => '@.*https?://(www\.)?voicethread\.com/\??#q\.b([0-9]+).*@',
'url' => 'http://voicethread.com/book.swf?b=$2',
),
);
private static $embed_sources;
function __construct() {
$this->httpstr = is_https() ? 'https' : 'http';
self::$base_url = $this->httpstr . '://www.voicethread.com/';
self::$embed_sources = array(
array(
'match' => '#.*https?://(www\.)?voicethread\.com/book\.swf\?b=([0-9]+).*#',
'url' => $this->httpstr . '://voicethread.com/book.swf?b=$2',
),
array(
'match' => '#.*https?://(www\.)?voicethread\.com/share/([0-9]+).*#',
'url' => $this->httpstr . '://voicethread.com/book.swf?b=$2',
),
array(
'match' => '@.*https?://(www\.)?voicethread\.com/\??#q\.b([0-9]+).*@',
'url' => $this->httpstr . '://voicethread.com/book.swf?b=$2',
),
);
}
public function process_url($input, $width=0, $height=0) {
$width = $width ? (int)$width : self::$default_width;
......
......@@ -4,25 +4,34 @@ require_once(dirname(__FILE__) . '/../Media_base.php');
class Media_youtube implements MediaBase {
private static $base_url = 'http://youtube.com/';
private $httpstr;
private static $base_url;
private static $default_width = 560;
private static $default_height = 349;
private static $iframe_sources = array(
array(
'match' => '#.*youtube\.com.*(v|(cp))(=|\/)([a-zA-Z0-9_=-]+).*#',
'url' => 'http://www.youtube.com/embed/$4'
),
array(
'match' => '#.*https?://(www\.)?youtube\.com/embed/([a-zA-Z0-9\-_+]*).*#',
'url' => 'http://www.youtube.com/embed/$2',
),
array(
'match' => '#https?://(www\.)?youtu\.be/([a-zA-Z0-9\-_+]*)#',
'url' => 'http://www.youtube.com/embed/$2',
),
);
private static $iframe_sources;
function __construct() {
$this->httpstr = is_https() ? 'https' : 'http';
self::$base_url = $this->httpstr . '://youtube.com/';
self::$iframe_sources = array(
array(
'match' => '#.*youtube\.com.*(v|(cp))(=|\/)([a-zA-Z0-9_=-]+).*#',
'url' => $this->httpstr . '://www.youtube.com/embed/$4'
),
array(
'match' => '#.*https?://(www\.)?youtube\.com/embed/([a-zA-Z0-9\-_+]*).*#',
'url' => $this->httpstr . '://www.youtube.com/embed/$2',
),
array(
'match' => '#https?://(www\.)?youtu\.be/([a-zA-Z0-9\-_+]*)#',
'url' => $this->httpstr . '://www.youtube.com/embed/$2',
),
);
}
public function process_url($input, $width=0, $height=0) {
$width = $width ? (int)$width : self::$default_width;
......
......@@ -109,13 +109,15 @@ class PluginBlocktypeGoogleApps extends SystemBlocktype {
}
private static function make_apps_url($url) {
static $embedsources = array(
$httpstr = is_https() ? 'https' : 'http';
$embedsources = array(
// docs.google.com/leaf - Google collections
// $1 - domain, e.g. /a/domainname/
// $2 - id, key, etc. of the collection
array(
'match' => '#.*docs.google.com/([a-zA-Z0-9\_\-\.\/]*)leaf\?id=([a-zA-Z0-9]+).*#',
'url' => 'http://docs.google.com/$1leaf?id=$2',
'url' => $httpstr . '://docs.google.com/$1leaf?id=$2',
'type' => 'spanicon',
),
// docs.google.com/present - Google presentation incl. custom domain presentation
......@@ -124,7 +126,7 @@ class PluginBlocktypeGoogleApps extends SystemBlocktype {
// $3 - id, key, etc. of the presentation
array(
'match' => '#.*docs.google.com/([a-zA-Z0-9\_\-\.\/]*)present/([a-z]+).*id=([a-zA-Z0-9\_\-\&\=]+).*#',
'url' => 'http://docs.google.com/$1present/embed?id=$3',
'url' => $httpstr . '://docs.google.com/$1present/embed?id=$3',
'type' => 'iframe',
),
// docs.google.com/drawings - Google drawing incl. custom domain drawing
......@@ -132,7 +134,7 @@ class PluginBlocktypeGoogleApps extends SystemBlocktype {
// $2 - id, key, etc. of the drawing
array(
'match' => '#.*docs.google.com/([a-zA-Z0-9\_\-\.\/]*)drawings.*id=([a-zA-Z0-9\_\-\&\=]+).*#',
'url' => 'http://docs.google.com/$1drawings/pub?id=$2',
'url' => $httpstr . '://docs.google.com/$1drawings/pub?id=$2',
'type' => 'image',
),
// docs.google.com - Google document (before July 2010) incl. custom domain document
......@@ -140,7 +142,7 @@ class PluginBlocktypeGoogleApps extends SystemBlocktype {
// $2 - id, key, etc. of the document
array(
'match' => '#.*docs.google.com/([a-zA-Z0-9\_\-\.\/]*)View.*id=([a-zA-Z0-9\_\-]+).*#',
'url' => 'http://docs.google.com/$1View?id=$2',
'url' => $httpstr . '://docs.google.com/$1View?id=$2',
'type' => 'iframe',
),
// docs.google.com - Google document (after July 2010) incl. custom domain document
......@@ -148,7 +150,7 @@ class PluginBlocktypeGoogleApps extends SystemBlocktype {
// $2 - id, key, etc. of the document
array(
'match' => '#.*docs.google.com/([a-zA-Z0-9\_\-\.\/]*)document/pub.*id=([a-zA-Z0-9\_\-]+).*#',
'url' => 'http://docs.google.com/$1document/pub?id=$2',
'url' => $httpstr . '://docs.google.com/$1document/pub?id=$2',
'type' => 'iframe',
),
// spreadsheets.google.com/viewform - Google form incl. custom domain form
......@@ -156,7 +158,7 @@ class PluginBlocktypeGoogleApps extends SystemBlocktype {
// $2 - id, key, etc. of the form
array(
'match' => '#.*spreadsheets[0-9]?.google.com/([a-zA-Z0-9\_\-\.\/]*)viewform.*formkey=([a-zA-Z0-9\_\-]+).*#',
'url' => 'https://spreadsheets.google.com/$1embeddedform?formkey=$2',
'url' => $httpstr . '://spreadsheets.google.com/$1embeddedform?formkey=$2',
'type' => 'iframe',
),
// spreadsheets.google.com/embeddedform - Google form incl. custom domain form
......@@ -164,7 +166,7 @@ class PluginBlocktypeGoogleApps extends SystemBlocktype {
// $2 - id, key, etc. of the form
array(
'match' => '#.*spreadsheets[0-9]?.google.com/([a-zA-Z0-9\_\-\.\/]*)embeddedform.*formkey=([a-zA-Z0-9\_\-]+).*#',
'url' => 'https://spreadsheets.google.com/$1embeddedform?formkey=$2',
'url' => $httpstr . '://spreadsheets.google.com/$1embeddedform?formkey=$2',
'type' => 'iframe',
),
// spreadsheets.google.com - Google spreadsheet incl. custom domain spreadsheet
......@@ -172,25 +174,25 @@ class PluginBlocktypeGoogleApps extends SystemBlocktype {
// $2 - id, key, etc. of the spreadsheet
array(
'match' => '#.*spreadsheets[0-9]?.google.com/([a-zA-Z0-9\_\-\.\/]*)pub.*key=([a-zA-Z0-9\_\-]+).*#',
'url' => 'http://spreadsheets.google.com/$1pub?key=$2',
'url' => $httpstr . '://spreadsheets.google.com/$1pub?key=$2',
'type' => 'iframe',
),
// www.google.com/calendar - Google calendar
array(
'match' => '#.*www.google.com/calendar.*src=([a-zA-Z0-9\.\_\-\&\%\=/]+).*#',
'url' => 'http://www.google.com/calendar/embed?src=$1',
'url' => $httpstr . '://www.google.com/calendar/embed?src=$1',
'type' => 'iframe',
),
// maps.google.com - Google My Maps (IMPORTANT: this is ONLY for My Maps)
array(
'match' => '#.*maps.google.[^/]*/maps/ms\?([a-zA-Z0-9\.\,\;\_\-\&\%\=\+/]+).*#',
'url' => 'http://maps.google.com/maps/ms?$1',
'url' => $httpstr . '://maps.google.com/maps/ms?$1',
'type' => 'iframe',
),
// maps.google.com - Google Maps (IMPORTANT: this is for ANY Maps EXCEPT My Maps)
array(
'match' => '#.*maps.google.[^/]*/(maps)?\?([a-zA-Z0-9\.\,\;\_\-\&\%\=\+/]+).*#',
'url' => 'http://maps.google.com/maps?$2',
'url' => $httpstr . '://maps.google.com/maps?$2',
'type' => 'iframe',
),
// books.google.com - Google Books
......@@ -203,7 +205,7 @@ class PluginBlocktypeGoogleApps extends SystemBlocktype {
// Google Docs Viewer supported files: PDF, TIFF, PPT, DOC, DOCX
array(
'match' => '#http([a-zA-Z0-9\.\,\;\_\-\&\%\=\+/\:]+)\.(pdf|tif|tiff|ppt|doc|docx)#',
'url' => 'http://docs.google.com/gview?url=http$1.$2&embedded=true',
'url' => $httpstr . '://docs.google.com/gview?url=http$1.$2&embedded=true',
'type' => 'iframe',
),
);
......
......@@ -2776,3 +2776,12 @@ function is_html_editor_enabled () {
return (!get_config('wysiwyg') && ($USER->get_account_preference('wysiwyg') || defined('PUBLIC'))) ||
get_config('wysiwyg') == 'enable';
}
/**
* Determine if site is running with https
*
* @return bool
*/
function is_https() {
return stripos(get_config('wwwroot'), 'https://') !== false;
}
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