Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Merged
merged 2 commits into from

2 participants

@evansims

Updates video embeds to use protocol relative urls when services support it.

evansims added some commits
@evansims evansims Fix broken video embeds in reports when viewed over HTTPS
Updates video embeds to use protocol relative urls when services support it.
0fee1b5
@evansims evansims Improve error handling when generating thumbnails for reports with at…
…tached videos.

Fixes some issues we've seen on Crowdmap when used in conjunction with a CDN.
b36414a
@evansims evansims merged commit f73eb7e into ushahidi:develop
@srutto srutto added this to the v2.7.3 milestone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 27, 2014
  1. @evansims

    Fix broken video embeds in reports when viewed over HTTPS

    evansims authored
    Updates video embeds to use protocol relative urls when services support it.
  2. @evansims

    Improve error handling when generating thumbnails for reports with at…

    evansims authored
    …tached videos.
    
    Fixes some issues we've seen on Crowdmap when used in conjunction with a CDN.
This page is out of date. Refresh to see the latest.
View
56 application/helpers/reports.php
@@ -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;
@@ -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
@@ -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());
View
6 application/libraries/VideoEmbed.php
@@ -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;
@@ -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;
@@ -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;
}
Something went wrong with that request. Please try again.