aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSem <sembrestels@riseup.net>2013-11-07 06:01:06 +0100
committerSem <sembrestels@riseup.net>2013-11-07 06:01:06 +0100
commit3ea9610796770bb2ba54d3c8c0f465a22eb9e3c8 (patch)
tree127226272974af37f9e49f3702ed74891c091881
parentb02119c597a1d806e7910e63ba20139234249fa0 (diff)
downloadelgg-3ea9610796770bb2ba54d3c8c0f465a22eb9e3c8.tar.gz
elgg-3ea9610796770bb2ba54d3c8c0f465a22eb9e3c8.tar.bz2
Making video thumbnails faster (thanks to ura soul).
-rw-r--r--start.php37
-rw-r--r--thumbnail.php77
2 files changed, 78 insertions, 36 deletions
diff --git a/start.php b/start.php
index 2094ffacc..6f94b97d0 100644
--- a/start.php
+++ b/start.php
@@ -270,22 +270,35 @@ function videolist_embed_get_items($hook, $type, $value, $params) {
* @return string Relative URL
*/
function videolist_icon_url_override($hook, $type, $returnvalue, $params) {
- $videolist_item = $params['entity'];
- /* @var ElggObject $videolist_item */
- $size = $params['size'];
- if($videolist_item->getSubtype() != 'videolist_item'){
- return $returnvalue;
- }
-
- // tiny thumbnails are too small to be useful, so give a generic video icon
- if ($size != 'tiny' && isset($videolist_item->thumbnail)) {
- return elgg_get_site_url() . "mod/videolist/thumbnail.php?guid=" . $videolist_item->guid;
+ // if someone already set this, quit
+ if ($return_value) {
+ return null;
}
- if (in_array($size, array('tiny', 'small', 'medium'))){
- return "mod/videolist/graphics/videolist_icon_{$size}.png";
+ $videolist_item = $params['entity'];
+ $size = $params['size'];
+
+ if (!elgg_instanceof($videolist_item, 'object', 'videolist_item')) {
+ return null;
}
+
+ // tiny thumbnails are too small to be useful, so give a generic video icon
+ try {
+ if ($size != 'tiny' && isset($videolist_item->thumbnail)) {
+ $owner = $videolist_item->getOwnerEntity();
+ $owner_guid = $owner->getGUID();
+ $join_date = $owner->getTimeCreated();
+ return "mod/videolist/thumbnail.php?joindate=$join_date&guid={$videolist_item->guid}&owner_guid=$owner_guid&size=$size";
+ }
+ } catch (InvalidParameterException $e) {
+ elgg_log("Unable to get videolist icon for video with GUID {$videolist_item->guid}", 'ERROR');
+ return "mod/videolist/graphics/videolist_icon_{$size}.png";
+ }
+ if (in_array($size, array('tiny', 'small', 'medium'))){
+ return "mod/videolist/graphics/videolist_icon_{$size}.png";
+ }
+ return null;
}
/**
diff --git a/thumbnail.php b/thumbnail.php
index bd93f8e63..7a4ca8b6c 100644
--- a/thumbnail.php
+++ b/thumbnail.php
@@ -1,35 +1,64 @@
<?php
/**
- * Elgg file thumbnail
- *
- * @package ElggFile
+ * Elgg profile icon cache/bypass
+ *
+ *
+ * @package ElggProfile
*/
-// Get engine
-require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
-
-// Get videolist item GUID
-$guid = (int) get_input('guid', 0);
+// Get DB settings
+require_once(dirname(dirname(dirname(__FILE__))). '/engine/settings.php');
-// Get file thumbnail size
-$size = get_input('size', 'small');
+global $CONFIG;
-$item = get_entity($guid);
-if (!$item || $item->getSubtype() != "videolist_item") {
+// won't be able to serve anything if no joindate or guid
+if (!isset($_GET['joindate']) || !isset($_GET['guid'])) {
+ header("HTTP/1.1 404 Not Found");
exit;
}
-$readfile = new ElggFile();
-$readfile->owner_guid = $item->owner_guid;
-$readfile->setFilename("videolist/{$item->guid}.jpg");
-$contents = $readfile->grabFile();
+$join_date = (int)$_GET['joindate'];
+$owner_guid = (int)$_GET['owner_guid'];
+$guid = (int)$_GET['guid'];
+
+$mysql_dblink = @mysql_connect($CONFIG->dbhost, $CONFIG->dbuser, $CONFIG->dbpass, true);
+if ($mysql_dblink) {
+ if (@mysql_select_db($CONFIG->dbname, $mysql_dblink)) {
+ $result = mysql_query("select name, value from {$CONFIG->dbprefix}datalists where name='dataroot'", $mysql_dblink);
+ if ($result) {
+ $row = mysql_fetch_object($result);
+ while ($row) {
+ if ($row->name == 'dataroot') {
+ $data_root = $row->value;
+ }
+ $row = mysql_fetch_object($result);
+ }
+ }
+
+ @mysql_close($mysql_dblink);
+
+ if (isset($data_root)) {
-// 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));
+ // this depends on ElggDiskFilestore::makeFileMatrix()
+ $user_path = date('Y/m/d/', $join_date) . $owner_guid;
-echo $contents;
-exit;
+ $filename = "$data_root$user_path/videolist/{$guid}.jpg";
+ $size = @filesize($filename);
+ if ($size) {
+ header("Content-type: image/jpeg");
+ header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+6 months")), true);
+ header("Pragma: public");
+ header("Cache-Control: public");
+ header("Content-Length: $size");
+ readfile($filename);
+ exit;
+ }
+ }
+ }
+
+}
+
+// something went wrong so load engine and try to forward to default icon
+require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
+elgg_log("Profile icon direct failed.", "WARNING");
+forward("mod/videolist/graphics/videolist_icon_{$size}.png");