From 033611ff041b1d103c0b6d48f2b3630292e2da7e Mon Sep 17 00:00:00 2001 From: Michael Fairchild Date: Fri, 8 Nov 2013 09:09:35 -0600 Subject: [PATCH 01/17] Add a poster field to the media table --- data/add_media_poster.sql | 1 + src/UNL/MediaHub/Models/BaseMedia.php | 1 + upgrade.php | 2 ++ 3 files changed, 4 insertions(+) create mode 100644 data/add_media_poster.sql diff --git a/data/add_media_poster.sql b/data/add_media_poster.sql new file mode 100644 index 000000000..d9a4d6f6a --- /dev/null +++ b/data/add_media_poster.sql @@ -0,0 +1 @@ +ALTER TABLE `media` ADD `poster` VARCHAR(255) NULL AFTER `url`; diff --git a/src/UNL/MediaHub/Models/BaseMedia.php b/src/UNL/MediaHub/Models/BaseMedia.php index 9856fac67..dd578277b 100644 --- a/src/UNL/MediaHub/Models/BaseMedia.php +++ b/src/UNL/MediaHub/Models/BaseMedia.php @@ -9,6 +9,7 @@ public function setTableDefinition() $this->hasColumn('url', 'string', null, array('fixed' => false, 'primary' => false, 'notnull' => true, 'autoincrement' => false, 'regexp' => '/^(https?):\/\/([^\/])+unl\.edu\/.*/', 'notblank' => true)); + $this->hasColumn('poster', 'string', null, array('fixed' => false, 'primary' => false, 'notnull' => false, 'autoincrement' => false)); $this->hasColumn('length', 'integer', 4, array('unsigned' => 0, 'primary' => false, 'notnull' => false, 'autoincrement' => false)); $this->hasColumn('type', 'string', null, array('fixed' => false, 'primary' => false, 'notnull' => true, 'autoincrement' => false)); $this->hasColumn('title', 'string', null, array('fixed' => false, 'primary' => false, 'notnull' => true, 'autoincrement' => false)); diff --git a/upgrade.php b/upgrade.php index 0c9741fe7..2221da0b5 100644 --- a/upgrade.php +++ b/upgrade.php @@ -36,5 +36,7 @@ function exec_sql($db, $sql, $message, $fail_ok = false) exec_sql($db, file_get_contents(dirname(__FILE__).'/data/add_featured_feed_fields.sql'), 'Adding featured feeds support', true); exec_sql($db, file_get_contents(dirname(__FILE__).'/data/add_media_privacy.sql'), 'Adding media privacy settings', true); exec_sql($db, file_get_contents(dirname(__FILE__).'/data/add_media_play_count.sql'), 'Adding media play count', true); +exec_sql($db, file_get_contents(dirname(__FILE__).'/data/add_media_poster.sql'), 'Adding media poster', true); + echo 'Upgrade complete!'; From a1347481d42e588ce570ca0b76ab50671d11c663 Mon Sep 17 00:00:00 2001 From: Michael Fairchild Date: Fri, 8 Nov 2013 09:25:35 -0600 Subject: [PATCH 02/17] Add the poster field to the media form --- www/manager/templates/Feed/Media/Form.tpl.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/www/manager/templates/Feed/Media/Form.tpl.php b/www/manager/templates/Feed/Media/Form.tpl.php index 12dfa6e8f..0ea434328 100644 --- a/www/manager/templates/Feed/Media/Form.tpl.php +++ b/www/manager/templates/Feed/Media/Form.tpl.php @@ -69,6 +69,9 @@ ?> +
  • + +
  • From d547636180f374de0336feac68789c36417f5400 Mon Sep 17 00:00:00 2001 From: Michael Fairchild Date: Fri, 8 Nov 2013 09:26:40 -0600 Subject: [PATCH 03/17] use the custom poster image if it is not empty --- src/UNL/MediaHub/Media.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/UNL/MediaHub/Media.php b/src/UNL/MediaHub/Media.php index 9d7ff3dd6..98d6884c9 100644 --- a/src/UNL/MediaHub/Media.php +++ b/src/UNL/MediaHub/Media.php @@ -258,6 +258,10 @@ function addTag($newTag) */ function getThumbnailURL() { + if (!empty($this->poster)) { + return $this->poster; + } + return UNL_MediaHub_Controller::$thumbnail_generator.urlencode($this->url); } From 5a8f0f8d4659d8f91a093c944e3d2fb1bedb7ee1 Mon Sep 17 00:00:00 2001 From: Michael Fairchild Date: Fri, 8 Nov 2013 09:39:13 -0600 Subject: [PATCH 04/17] Make help text medium agnostic Could be for audio or video --- www/manager/templates/Feed/Media/Form.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/manager/templates/Feed/Media/Form.tpl.php b/www/manager/templates/Feed/Media/Form.tpl.php index 0ea434328..797057090 100644 --- a/www/manager/templates/Feed/Media/Form.tpl.php +++ b/www/manager/templates/Feed/Media/Form.tpl.php @@ -69,7 +69,7 @@ ?> -
  • +
  • From f793d37fc7a7c482c5c0cf389e3f5f5395c6e263 Mon Sep 17 00:00:00 2001 From: Michael Fairchild Date: Fri, 8 Nov 2013 09:43:01 -0600 Subject: [PATCH 05/17] Explain how the poster image will work It will override the custom one chosen --- www/manager/templates/Feed/Media/Form.tpl.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/www/manager/templates/Feed/Media/Form.tpl.php b/www/manager/templates/Feed/Media/Form.tpl.php index 797057090..84003ef0a 100644 --- a/www/manager/templates/Feed/Media/Form.tpl.php +++ b/www/manager/templates/Feed/Media/Form.tpl.php @@ -69,7 +69,13 @@ ?> -
  • + media) && $context->media->isVideo()) { + $text = 'This image will override the one chosen above.'; + } + ?> +
  • From c6cc00295b91f1110ca39f50e587bbeaaec429b9 Mon Sep 17 00:00:00 2001 From: Michael Fairchild Date: Fri, 8 Nov 2013 10:16:15 -0600 Subject: [PATCH 06/17] Add container divs This will make it easier to let JS manipulate --- .../templates/Media/Preview/Video.tpl.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/www/manager/templates/Media/Preview/Video.tpl.php b/www/manager/templates/Media/Preview/Video.tpl.php index 91e400ad9..2ddae3cd2 100644 --- a/www/manager/templates/Media/Preview/Video.tpl.php +++ b/www/manager/templates/Media/Preview/Video.tpl.php @@ -5,13 +5,21 @@
  • Click the "Set Image" button to save this as your image representation.
  • Continue with the form below.
  • -
    Your Image
    -
    -

    We're updating your image, this may take a few minutes depending on video length. Now is a good time to make sure the information below is up to snuff!

    +
    +
    Your Image
    +
    +

    We're updating your image, this may take a few minutes depending on video length. Now is a good time to make sure the information below is up to snuff!

    +
    + Thumbnail preview + Set Image +
    +
    +

    + The poster picker has been disabled. Enable it by removing the custom post image url. +

    - Thumbnail preview - Set Image
    +
    render($context, 'MediaPlayer.tpl.php'); ?>
    \ No newline at end of file From eeec257d6fc93bca3bb1d70e2badc2d671a99bb1 Mon Sep 17 00:00:00 2001 From: Michael Fairchild Date: Fri, 8 Nov 2013 10:16:39 -0600 Subject: [PATCH 07/17] Hide/show the poster picker --- www/templates/html/scripts/mediaDetails.js | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/www/templates/html/scripts/mediaDetails.js b/www/templates/html/scripts/mediaDetails.js index b539cfe4b..c6e308404 100644 --- a/www/templates/html/scripts/mediaDetails.js +++ b/www/templates/html/scripts/mediaDetails.js @@ -82,7 +82,17 @@ var mediaDetails = function() { WDN.jQuery('#thumbnail').attr('src', thumbnail.src); }; thumbnail.onerror = ''; - } + }, + + hidePosterPicker: function() { + WDN.jQuery('#poster_picker').hide(); + WDN.jQuery('#poster_picker_disabled').show(); + }, + + showPosterPicker: function() { + WDN.jQuery('#poster_picker').show(); + WDN.jQuery('#poster_picker_disabled').hide(); + } }; }(); @@ -99,6 +109,25 @@ WDN.jQuery(document).ready(function() { WDN.jQuery("#fileUpload").hide(); } + if (WDN.jQuery('#media_poster').val() !== '') { + WDN.jQuery('#poster_picker').hide(); + } else { + WDN.jQuery('#poster_picker_disabled').hide(); + } + + WDN.jQuery('#media_poster').on('keyup', function() { + if (this.value == '') { + mediaDetails.showPosterPicker(); + } else { + mediaDetails.hidePosterPicker(); + } + }); + + WDN.jQuery('#enable_poster_picker').click(function() { + WDN.jQuery('#media_poster').val(''); + mediaDetails.showPosterPicker(); + }); + WDN.jQuery("#mediaSubmit").click(function(event) { //called when a user adds video if (document.getElementById("file_upload").value == '') { From c55e46c6036a22441c75577f5973006bae3a001b Mon Sep 17 00:00:00 2001 From: Michael Fairchild Date: Fri, 8 Nov 2013 10:27:06 -0600 Subject: [PATCH 08/17] Don't auto play on the add media view --- www/templates/html/MediaPlayer/Video.tpl.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/www/templates/html/MediaPlayer/Video.tpl.php b/www/templates/html/MediaPlayer/Video.tpl.php index 782a0ed72..a2b73eccb 100644 --- a/www/templates/html/MediaPlayer/Video.tpl.php +++ b/www/templates/html/MediaPlayer/Video.tpl.php @@ -14,6 +14,11 @@ $autoplay = ''; } +//Don't auto play on the addmedia view +if ($controller->options['view'] == 'addmedia') { + $autoplay = ''; +} + if (isset($controller->options['autoplay']) && !$controller->options['autoplay']) { $autoplay = ''; } From fb0a5322934328e69334c5c2d53dbfa0ff47ea8a Mon Sep 17 00:00:00 2001 From: Michael Fairchild Date: Fri, 8 Nov 2013 10:28:07 -0600 Subject: [PATCH 09/17] Make sure that the key is set --- www/templates/html/MediaPlayer/Video.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/templates/html/MediaPlayer/Video.tpl.php b/www/templates/html/MediaPlayer/Video.tpl.php index a2b73eccb..b60d6d6b1 100644 --- a/www/templates/html/MediaPlayer/Video.tpl.php +++ b/www/templates/html/MediaPlayer/Video.tpl.php @@ -15,7 +15,7 @@ } //Don't auto play on the addmedia view -if ($controller->options['view'] == 'addmedia') { +if (isset($controller->options['view']) && $controller->options['view'] == 'addmedia') { $autoplay = ''; } From ab464825929ead85c5238bf633421e59eb0039ee Mon Sep 17 00:00:00 2001 From: Michael Fairchild Date: Fri, 8 Nov 2013 10:47:32 -0600 Subject: [PATCH 10/17] Still show the image, just hide the button --- www/manager/templates/Media/Preview/Video.tpl.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/www/manager/templates/Media/Preview/Video.tpl.php b/www/manager/templates/Media/Preview/Video.tpl.php index 2ddae3cd2..c4637dfda 100644 --- a/www/manager/templates/Media/Preview/Video.tpl.php +++ b/www/manager/templates/Media/Preview/Video.tpl.php @@ -5,12 +5,13 @@
  • Click the "Set Image" button to save this as your image representation.
  • Continue with the form below.
  • + +
    Your Image
    +
    +

    We're updating your image, this may take a few minutes depending on video length. Now is a good time to make sure the information below is up to snuff!

    +
    + Thumbnail preview
    -
    Your Image
    -
    -

    We're updating your image, this may take a few minutes depending on video length. Now is a good time to make sure the information below is up to snuff!

    -
    - Thumbnail preview Set Image
    From 645fd189f0045332a1c6402a009c98aef699b3af Mon Sep 17 00:00:00 2001 From: Michael Fairchild Date: Fri, 8 Nov 2013 10:49:15 -0600 Subject: [PATCH 11/17] Show the default poster when switching --- www/templates/html/scripts/mediaDetails.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/www/templates/html/scripts/mediaDetails.js b/www/templates/html/scripts/mediaDetails.js index c6e308404..1f671b9bc 100644 --- a/www/templates/html/scripts/mediaDetails.js +++ b/www/templates/html/scripts/mediaDetails.js @@ -92,6 +92,7 @@ var mediaDetails = function() { showPosterPicker: function() { WDN.jQuery('#poster_picker').show(); WDN.jQuery('#poster_picker_disabled').hide(); + mediaDetails.updateThumbnail(); } }; }(); @@ -119,6 +120,7 @@ WDN.jQuery(document).ready(function() { if (this.value == '') { mediaDetails.showPosterPicker(); } else { + WDN.jQuery('#thumbnail').attr('src', this.value); mediaDetails.hidePosterPicker(); } }); From b1cee1c26f8ea8729e5d0c440ddc4f37b6fd9099 Mon Sep 17 00:00:00 2001 From: Michael Fairchild Date: Fri, 8 Nov 2013 10:49:31 -0600 Subject: [PATCH 12/17] Add a script to remove 404 posters --- scripts/find404Posters.php | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 scripts/find404Posters.php diff --git a/scripts/find404Posters.php b/scripts/find404Posters.php new file mode 100644 index 000000000..cab5197bf --- /dev/null +++ b/scripts/find404Posters.php @@ -0,0 +1,42 @@ +options['limit'] = 3000; +$list->run(); + +if (count($list->items)) { + foreach ($list->items as $media) { + if (empty($media->poster)) { + continue; + } + + // Try and get the poster + if (substr($media->poster, 0, 5) == 'http:') { + $context = stream_context_create(array('http'=>array( + 'method' => 'GET', + 'user_agent' => 'UNL MediaHub/mediahub.unl.edu' + ))); + + if ($result = @file_get_contents($media->poster, null, $context, -1, 8)) { + // Assume OK, $result would === false if there was a 404 + continue; + } + + if (false === $http_response_header) { + echo 'DNS failure, did the server move?'.PHP_EOL; + } + + foreach ($http_response_header as $header) { + if (strpos($header, 'HTTP/1.1 404 Not Found') !== false) { + // This file is GONE! Better remove it + echo 'REMOVING POSTER-'.PHP_EOL.'ID: '.$media->id.PHP_EOL.'Title: '.$media->title.PHP_EOL.'POSTER URL: '.$media->poster.PHP_EOL.PHP_EOL; + $media->poster = ''; + $media->save(); + } + } + } + } +} From af53555baf4f7710217eb17e5d244fd09df6558b Mon Sep 17 00:00:00 2001 From: Michael Fairchild Date: Mon, 11 Nov 2013 15:56:33 -0600 Subject: [PATCH 13/17] also check for https --- scripts/find404Posters.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/find404Posters.php b/scripts/find404Posters.php index cab5197bf..fb1a40d3a 100644 --- a/scripts/find404Posters.php +++ b/scripts/find404Posters.php @@ -14,7 +14,8 @@ } // Try and get the poster - if (substr($media->poster, 0, 5) == 'http:') { + if (substr($media->poster, 0, 5) == 'http:' + || substr($media->poster, 0, 6) == 'https:') { $context = stream_context_create(array('http'=>array( 'method' => 'GET', 'user_agent' => 'UNL MediaHub/mediahub.unl.edu' From 526fd9ab4a18815f7edf4d4bf7334dc7e8fe236f Mon Sep 17 00:00:00 2001 From: Michael Fairchild Date: Mon, 11 Nov 2013 16:08:25 -0600 Subject: [PATCH 14/17] Add a filter for selecting media with posters --- .../MediaHub/MediaList/Filter/WithPoster.php | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/UNL/MediaHub/MediaList/Filter/WithPoster.php diff --git a/src/UNL/MediaHub/MediaList/Filter/WithPoster.php b/src/UNL/MediaHub/MediaList/Filter/WithPoster.php new file mode 100644 index 000000000..6102ff60e --- /dev/null +++ b/src/UNL/MediaHub/MediaList/Filter/WithPoster.php @@ -0,0 +1,38 @@ +where('m.poster IS NOT NULL AND m.poster != ""'); + } + + function getLabel() + { + return 'Media with posters'; + } + + function getType() + { + return ''; + } + + function getValue() + { + return ''; + } + + function __toString() + { + return ''; + } + + public static function getDescription() + { + return 'Find media with custom poster images defined'; + } +} From 23ccadc181bcbafbe556601afddcb9e9d18d5ea1 Mon Sep 17 00:00:00 2001 From: Michael Fairchild Date: Mon, 11 Nov 2013 16:08:50 -0600 Subject: [PATCH 15/17] Only select media with posters --- scripts/find404Posters.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/find404Posters.php b/scripts/find404Posters.php index fb1a40d3a..62f4f01a6 100644 --- a/scripts/find404Posters.php +++ b/scripts/find404Posters.php @@ -3,7 +3,10 @@ $mediahub = new UNL_MediaHub($dsn); -$list = new UNL_MediaHub_MediaList(); +$list = new UNL_MediaHub_MediaList(array( + 'filter' => new UNL_MediaHub_MediaList_Filter_WithPoster() +)); + $list->options['limit'] = 3000; $list->run(); From 4d975e8f147e9562b7232662ea519e830e559dba Mon Sep 17 00:00:00 2001 From: Michael Fairchild Date: Tue, 12 Nov 2013 08:39:42 -0600 Subject: [PATCH 16/17] Send a HEAD request --- scripts/find404Posters.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/find404Posters.php b/scripts/find404Posters.php index 62f4f01a6..0db12ef8a 100644 --- a/scripts/find404Posters.php +++ b/scripts/find404Posters.php @@ -20,7 +20,7 @@ if (substr($media->poster, 0, 5) == 'http:' || substr($media->poster, 0, 6) == 'https:') { $context = stream_context_create(array('http'=>array( - 'method' => 'GET', + 'method' => 'HEAD', 'user_agent' => 'UNL MediaHub/mediahub.unl.edu' ))); From bd1eadeb23fdab0755c8c703d53f3acf6758c6b1 Mon Sep 17 00:00:00 2001 From: Michael Fairchild Date: Tue, 12 Nov 2013 08:49:13 -0600 Subject: [PATCH 17/17] Use a better check for missing posters The status header will always be the first in the array (no need to check the others). Also, not all servers will respond with HTTP/1.1. Also, servers will not always use the string Not Found. Only the response code is guaranteed by the protocol. 404 is also not the only problematic response. --- scripts/find404Posters.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/find404Posters.php b/scripts/find404Posters.php index 0db12ef8a..c244919dc 100644 --- a/scripts/find404Posters.php +++ b/scripts/find404Posters.php @@ -29,17 +29,17 @@ continue; } - if (false === $http_response_header) { + if (!isset($http_response_header) || + false === $http_response_header) { echo 'DNS failure, did the server move?'.PHP_EOL; } - foreach ($http_response_header as $header) { - if (strpos($header, 'HTTP/1.1 404 Not Found') !== false) { - // This file is GONE! Better remove it - echo 'REMOVING POSTER-'.PHP_EOL.'ID: '.$media->id.PHP_EOL.'Title: '.$media->title.PHP_EOL.'POSTER URL: '.$media->poster.PHP_EOL.PHP_EOL; - $media->poster = ''; - $media->save(); - } + if (!isset($http_response_header[0]) + || strpos($http_response_header[0], '200') === false) { + // This file is GONE! Better remove it + echo 'REMOVING POSTER-'.PHP_EOL.'ID: '.$media->id.PHP_EOL.'Title: '.$media->title.PHP_EOL.'POSTER URL: '.$media->poster.PHP_EOL.PHP_EOL; + $media->poster = ''; + $media->save(); } } }