Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken video embeds in reports when viewed over HTTPS #1328

Merged
merged 2 commits into from
Feb 27, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 39 additions & 17 deletions application/helpers/reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,13 +447,14 @@ public static function save_media($post, $incident)
if (isset($post->incident_video))
{
$videoembed = new VideoEmbed();
foreach ($post->incident_video as $k => $item)
foreach ($post->incident_video as $k => $video_link)
{
if ( ! empty($item))
if ( ! empty($video_link))
{
$video_thumb = $videoembed->thumbnail($item);
$video_thumb = $videoembed->thumbnail($video_link);
$new_filename = $incident->id.'_v'.$k.'_'.time();
$file_type = substr($video_thumb,-4);
$file_type = substr($video_thumb, strrpos($video_thumb, '.'));

$media_thumb = NULL;
$media_medium = NULL;

Expand All @@ -465,7 +466,16 @@ public static function save_media($post, $incident)
$media_medium = $new_filename.'_m'.$file_type;
$media_thumb = $new_filename.'_t'.$file_type;

file_put_contents($upload_dir.$media_link, @file_get_contents($video_thumb));
try {
if ($data = file_get_contents($video_thumb))
{
file_put_contents($upload_dir.$media_link, $data);
}
}
catch (Exception $e)
{

}

// IMAGE SIZES: 800X600, 400X300, 89X59
// Catch any errors from corrupt image files
Expand Down Expand Up @@ -507,28 +517,40 @@ public static function save_media($post, $incident)

// Okay, now we have these three different files on the server, now check to see
// if we should be dropping them on the CDN
if (Kohana::config("cdn.cdn_store_dynamic_content"))

if ($media_medium AND $media_thumb AND Kohana::config("cdn.cdn_store_dynamic_content"))
{
//$media_link = cdn::upload($media_link);
$media_medium = cdn::upload($media_medium);
$media_thumb = cdn::upload($media_thumb);

$cdn_media_medium = cdn::upload($media_medium);
$cdn_media_thumb = cdn::upload($media_thumb);

// We no longer need the files we created on the server. Remove them.
$local_directory = rtrim($upload_dir, '/').'/';
//unlink($local_directory.$media_link);
unlink($local_directory.$media_medium);
unlink($local_directory.$media_thumb);

if (file_exists($local_directory.$media_medium))
{
unlink($local_directory.$media_medium);
}

if (file_exists($local_directory.$media_thumb))
{
unlink($local_directory.$media_thumb);
}

$media_medium = $cdn_media_medium;
$media_thumb = $cdn_media_thumb;
}

if (file_exists($local_directory.$media_link)) {
// Remove original image
unlink($upload_dir.$media_link);
}
// Remove original image
unlink($upload_dir.$media_link);
}

$video = new Media_Model();
$video->location_id = $incident->location_id;
$video->incident_id = $incident->id;
$video->media_type = 2; // Video
$video->media_link = $item;
$video->media_link = $video_link;
$video->media_thumb = $media_thumb;
$video->media_medium = $media_medium;
$video->media_date = date("Y-m-d H:i:s",time());
Expand Down
6 changes: 3 additions & 3 deletions application/libraries/VideoEmbed.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function embed($raw, $auto = FALSE, $echo = TRUE)
$you_auto = ($auto) ? "&autoplay=1" : "";

$output = '<iframe id="ytplayer" type="text/html" width="320" height="265" '
. 'src="http://www.youtube.com/embed/'.html::escape($code).'?origin='.urlencode(url::base()).html::escape($you_auto).'" '
. 'src="//www.youtube.com/embed/'.html::escape($code).'?origin='.urlencode(url::base()).html::escape($you_auto).'" '
. 'frameborder="0"></iframe>';
break;

Expand All @@ -175,7 +175,7 @@ public function embed($raw, $auto = FALSE, $echo = TRUE)
$google_auto = ($auto) ? "&autoPlay=true" : "";

$output = "<embed style='width:320px; height:265px;' id='VideoPlayback' type='application/x-shockwave-flash'"
. " src='http://video.google.com/googleplayer.swf?docId=-".html::escape($code.$google_auto)."&hl=en' flashvars=''>"
. " src='//video.google.com/googleplayer.swf?docId=-".html::escape($code.$google_auto)."&hl=en' flashvars=''>"
. "</embed>";
break;

Expand All @@ -197,7 +197,7 @@ public function embed($raw, $auto = FALSE, $echo = TRUE)
case "vimeo":
$vimeo_auto = ($auto) ? "?autoplay=1" : "";

$output = '<iframe src="http://player.vimeo.com/video/'.html::escape($code.$vimeo_auto).'" width="320" height="265" frameborder="0">'
$output = '<iframe src="//player.vimeo.com/video/'.html::escape($code.$vimeo_auto).'" width="320" height="265" frameborder="0">'
. '</iframe>';
break;
}
Expand Down