thumbnail.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * ownCloud - Addressbook
  4. *
  5. * @author Thomas Tanghus
  6. * @copyright 2011-2012 Thomas Tanghus <thomas@tanghus.net>
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. // Init owncloud
  23. OCP\JSON::checkLoggedIn();
  24. //OCP\User::checkLoggedIn();
  25. OCP\App::checkAppEnabled('contacts');
  26. function getStandardImage(){
  27. //OCP\Response::setExpiresHeader('P10D');
  28. OCP\Response::enableCaching();
  29. OCP\Response::redirect(OCP\Util::imagePath('contacts', 'person.png'));
  30. }
  31. if(!extension_loaded('gd') || !function_exists('gd_info')) {
  32. OCP\Util::writeLog('contacts','thumbnail.php. GD module not installed',OCP\Util::DEBUG);
  33. getStandardImage();
  34. exit();
  35. }
  36. $id = $_GET['id'];
  37. $caching = isset($_GET['refresh']) ? 0 : null;
  38. $contact = OC_Contacts_App::getContactVCard($id);
  39. // invalid vcard
  40. if(is_null($contact)){
  41. OCP\Util::writeLog('contacts','thumbnail.php. The VCard for ID '.$id.' is not RFC compatible',OCP\Util::ERROR);
  42. getStandardImage();
  43. exit();
  44. }
  45. OCP\Response::enableCaching($caching);
  46. OC_Contacts_App::setLastModifiedHeader($contact);
  47. $thumbnail_size = 23;
  48. // Find the photo from VCard.
  49. $image = new OC_Image();
  50. $photo = $contact->getAsString('PHOTO');
  51. if($photo) {
  52. OCP\Response::setETagHeader(md5($photo));
  53. if($image->loadFromBase64($photo)) {
  54. if($image->centerCrop()) {
  55. if($image->resize($thumbnail_size)) {
  56. if($image->show()) {
  57. // done
  58. exit();
  59. } else {
  60. OCP\Util::writeLog('contacts','thumbnail.php. Couldn\'t display thumbnail for ID '.$id,OCP\Util::ERROR);
  61. }
  62. } else {
  63. OCP\Util::writeLog('contacts','thumbnail.php. Couldn\'t resize thumbnail for ID '.$id,OCP\Util::ERROR);
  64. }
  65. }else{
  66. OCP\Util::writeLog('contacts','thumbnail.php. Couldn\'t crop thumbnail for ID '.$id,OCP\Util::ERROR);
  67. }
  68. } else {
  69. OCP\Util::writeLog('contacts','thumbnail.php. Couldn\'t load image string for ID '.$id,OCP\Util::ERROR);
  70. }
  71. }
  72. getStandardImage();