選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

photo.inc 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------+
  4. | program/steps/addressbook/photo.inc |
  5. | |
  6. | This file is part of the Roundcube Webmail client |
  7. | Copyright (C) 2005-2013, The Roundcube Dev Team |
  8. | |
  9. | Licensed under the GNU General Public License version 3 or |
  10. | any later version with exceptions for skins & plugins. |
  11. | See the README file for a full license statement. |
  12. | |
  13. | PURPOSE: |
  14. | Show contact photo |
  15. | |
  16. +-----------------------------------------------------------------------+
  17. | Author: Thomas Bruederli <roundcube@gmail.com> |
  18. | Author: Aleksander Machniak <alec@alec.pl> |
  19. +-----------------------------------------------------------------------+
  20. */
  21. // Get contact ID and source ID from request
  22. $cids = rcmail_get_cids();
  23. $source = key($cids);
  24. $cid = $cids ? array_shift($cids[$source]) : null;
  25. // read the referenced file
  26. if (($file_id = rcube_utils::get_input_value('_photo', rcube_utils::INPUT_GPC)) && ($tempfile = $_SESSION['contacts']['files'][$file_id])) {
  27. $tempfile = $RCMAIL->plugins->exec_hook('attachment_display', $tempfile);
  28. if ($tempfile['status']) {
  29. if ($tempfile['data'])
  30. $data = $tempfile['data'];
  31. else if ($tempfile['path'])
  32. $data = file_get_contents($tempfile['path']);
  33. }
  34. }
  35. else {
  36. // by email, search for contact first
  37. if ($email = rcube_utils::get_input_value('_email', rcube_utils::INPUT_GPC)) {
  38. foreach ($RCMAIL->get_address_sources() as $s) {
  39. $abook = $RCMAIL->get_address_book($s['id']);
  40. $result = $abook->search(array('email'), $email, 1, true, true, 'photo');
  41. while ($result && ($record = $result->iterate())) {
  42. if ($record['photo'])
  43. break 2;
  44. }
  45. }
  46. }
  47. // by contact id
  48. if (!$record && $cid) {
  49. // Initialize addressbook source
  50. $CONTACTS = rcmail_contact_source($source, true);
  51. $SOURCE_ID = $source;
  52. // read contact record
  53. $record = $CONTACTS->get_record($cid, true);
  54. }
  55. if ($record['photo']) {
  56. $data = is_array($record['photo']) ? $record['photo'][0] : $record['photo'];
  57. if (!preg_match('![^a-z0-9/=+-]!i', $data))
  58. $data = base64_decode($data, true);
  59. }
  60. }
  61. // let plugins do fancy things with contact photos
  62. $plugin = $RCMAIL->plugins->exec_hook('contact_photo',
  63. array('record' => $record, 'email' => $email, 'data' => $data));
  64. // redirect to url provided by a plugin
  65. if ($plugin['url']) {
  66. $RCMAIL->output->redirect($plugin['url']);
  67. }
  68. $data = $plugin['data'];
  69. // detect if photo data is an URL
  70. if (strlen($data) < 1024 && filter_var($data, FILTER_VALIDATE_URL)) {
  71. $RCMAIL->output->redirect($data);
  72. }
  73. // cache for one day if requested by email
  74. if (!$cid && $email) {
  75. $RCMAIL->output->future_expire_header(86400);
  76. }
  77. if ($data) {
  78. header('Content-Type: ' . rcube_mime::image_content_type($data));
  79. echo $data;
  80. }
  81. else if (!empty($_GET['_error'])) {
  82. header('HTTP/1.0 404 Photo not found');
  83. }
  84. else {
  85. header('Content-Type: image/gif');
  86. echo base64_decode(rcmail_output::BLANK_GIF);
  87. }
  88. exit;