aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSem <sembrestels@riseup.net>2012-02-25 01:38:29 +0100
committerSem <sembrestels@riseup.net>2012-02-25 01:38:29 +0100
commit8ccd45aa77d290906fd42dcf5520a434303d4f68 (patch)
treef1cb3ccc39ce4e8a4ebafb68e414c0c963790dc6
parent3a948fa46583e2419388d0c04e910f5d69721d3e (diff)
downloadelgg-8ccd45aa77d290906fd42dcf5520a434303d4f68.tar.gz
elgg-8ccd45aa77d290906fd42dcf5520a434303d4f68.tar.bz2
Saving thumbnails in server and serving them secure.
-rw-r--r--actions/videolist/edit.php12
-rw-r--r--start.php2
-rw-r--r--thumbnail.php35
3 files changed, 48 insertions, 1 deletions
diff --git a/actions/videolist/edit.php b/actions/videolist/edit.php
index 6670ceadb..be566de7e 100644
--- a/actions/videolist/edit.php
+++ b/actions/videolist/edit.php
@@ -71,6 +71,18 @@ $video->container_guid = $container_guid;
if ($video->save()) {
elgg_clear_sticky_form('videolist');
+
+ // Let's save the thumbnail in the data folder
+ $thumbnail = file_get_contents($video->thumbnail);
+ if ($thumbnail) {
+ $prefix = "videolist/" . $video->guid;
+ $filehandler = new ElggFile();
+ $filehandler->owner_guid = $video->owner_guid;
+ $filehandler->setFilename($prefix . ".jpg");
+ $filehandler->open("write");
+ $filehandler->write($thumbnail);
+ $filehandler->close();
+ }
system_message(elgg_echo('videolist:saved'));
diff --git a/start.php b/start.php
index 4c29549eb..ff668f00c 100644
--- a/start.php
+++ b/start.php
@@ -255,7 +255,7 @@ function videolist_icon_url_override($hook, $type, $returnvalue, $params) {
// tiny thumbnails are too small to be useful, so give a generic video icon
if ($size != 'tiny' && isset($videolist_item->thumbnail)) {
- return $videolist_item->thumbnail;
+ return elgg_get_site_url() . "mod/videolist/thumbnail.php?guid=" . $videolist_item->guid;
}
if (in_array($size, array('tiny', 'small', 'medium'))){
diff --git a/thumbnail.php b/thumbnail.php
new file mode 100644
index 000000000..bd93f8e63
--- /dev/null
+++ b/thumbnail.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * Elgg file thumbnail
+ *
+ * @package ElggFile
+ */
+
+// Get engine
+require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
+
+// Get videolist item GUID
+$guid = (int) get_input('guid', 0);
+
+// Get file thumbnail size
+$size = get_input('size', 'small');
+
+$item = get_entity($guid);
+if (!$item || $item->getSubtype() != "videolist_item") {
+ exit;
+}
+
+$readfile = new ElggFile();
+$readfile->owner_guid = $item->owner_guid;
+$readfile->setFilename("videolist/{$item->guid}.jpg");
+$contents = $readfile->grabFile();
+
+// caching images for 10 days
+header("Content-type: image/jpeg");
+header('Expires: ' . date('r',time() + 864000));
+header("Pragma: public", true);
+header("Cache-Control: public", true);
+header("Content-Length: " . strlen($contents));
+
+echo $contents;
+exit;