thumbnail.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Elgg profile icon cache/bypass
  4. *
  5. *
  6. * @package ElggProfile
  7. */
  8. // Get DB settings
  9. require_once(dirname(dirname(dirname(__FILE__))). '/engine/settings.php');
  10. global $CONFIG;
  11. // won't be able to serve anything if no joindate or guid
  12. if (!isset($_GET['joindate']) || !isset($_GET['guid'])) {
  13. header("HTTP/1.1 404 Not Found");
  14. exit;
  15. }
  16. $join_date = (int)$_GET['joindate'];
  17. $owner_guid = (int)$_GET['owner_guid'];
  18. $guid = (int)$_GET['guid'];
  19. $mysql_dblink = @mysql_connect($CONFIG->dbhost, $CONFIG->dbuser, $CONFIG->dbpass, true);
  20. if ($mysql_dblink) {
  21. if (@mysql_select_db($CONFIG->dbname, $mysql_dblink)) {
  22. $result = mysql_query("select name, value from {$CONFIG->dbprefix}datalists where name='dataroot'", $mysql_dblink);
  23. if ($result) {
  24. $row = mysql_fetch_object($result);
  25. while ($row) {
  26. if ($row->name == 'dataroot') {
  27. $data_root = $row->value;
  28. }
  29. $row = mysql_fetch_object($result);
  30. }
  31. }
  32. @mysql_close($mysql_dblink);
  33. if (isset($data_root)) {
  34. // this depends on ElggDiskFilestore::makeFileMatrix()
  35. $user_path = date('Y/m/d/', $join_date) . $owner_guid;
  36. $filename = "$data_root$user_path/videolist/{$guid}.jpg";
  37. $size = @filesize($filename);
  38. if ($size) {
  39. header("Content-type: image/jpeg");
  40. header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+6 months")), true);
  41. header("Pragma: public");
  42. header("Cache-Control: public");
  43. header("Content-Length: $size");
  44. readfile($filename);
  45. exit;
  46. }
  47. }
  48. }
  49. }
  50. // something went wrong so load engine and try to forward to default icon
  51. require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
  52. elgg_log("Profile icon direct failed.", "WARNING");
  53. forward("mod/videolist/graphics/videolist_icon_{$size}.png");