photo.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
  4. * Copyright (c) 2011, 2012 Bart Visscher <bartv@thisnet.nl>
  5. * Copyright (c) 2011 Jakob Sack mail@jakobsack.de
  6. * This file is licensed under the Affero General Public License version 3 or
  7. * later.
  8. * See the COPYING-README file.
  9. */
  10. // Init owncloud
  11. OCP\User::checkLoggedIn();
  12. OCP\App::checkAppEnabled('contacts');
  13. function getStandardImage(){
  14. //OCP\Response::setExpiresHeader('P10D');
  15. OCP\Response::enableCaching();
  16. OCP\Response::redirect(OCP\Util::imagePath('contacts', 'person_large.png'));
  17. }
  18. $id = isset($_GET['id']) ? $_GET['id'] : null;
  19. $caching = isset($_GET['refresh']) ? 0 : null;
  20. if(is_null($id)) {
  21. getStandardImage();
  22. }
  23. if(!extension_loaded('gd') || !function_exists('gd_info')) {
  24. OCP\Util::writeLog('contacts','photo.php. GD module not installed',OCP\Util::DEBUG);
  25. getStandardImage();
  26. }
  27. $contact = OC_Contacts_App::getContactVCard($id);
  28. $image = new OC_Image();
  29. if(!$image) {
  30. getStandardImage();
  31. }
  32. // invalid vcard
  33. if( is_null($contact)) {
  34. OCP\Util::writeLog('contacts','photo.php. The VCard for ID '.$id.' is not RFC compatible',OCP\Util::ERROR);
  35. } else {
  36. OCP\Response::enableCaching($caching);
  37. OC_Contacts_App::setLastModifiedHeader($contact);
  38. // Photo :-)
  39. if($image->loadFromBase64($contact->getAsString('PHOTO'))) {
  40. // OK
  41. OCP\Response::setETagHeader(md5($contact->getAsString('PHOTO')));
  42. }
  43. else
  44. // Logo :-/
  45. if($image->loadFromBase64($contact->getAsString('LOGO'))) {
  46. // OK
  47. OCP\Response::setETagHeader(md5($contact->getAsString('LOGO')));
  48. }
  49. if ($image->valid()) {
  50. $max_size = 200;
  51. if($image->width() > $max_size ||
  52. $image->height() > $max_size) {
  53. $image->resize($max_size);
  54. }
  55. }
  56. }
  57. if (!$image->valid()) {
  58. // Not found :-(
  59. getStandardImage();
  60. //$image->loadFromFile('img/person_large.png');
  61. }
  62. header('Content-Type: '.$image->mimeType());
  63. $image->show();
  64. //echo OC_Contacts_App::$l10n->t('This card does not contain a photo.');