loadphoto.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * ownCloud - Addressbook
  4. *
  5. * @author Thomas Tanghus
  6. * @copyright 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. // Check if we are a user
  24. OCP\JSON::checkLoggedIn();
  25. OCP\JSON::checkAppEnabled('contacts');
  26. // foreach ($_POST as $key=>$element) {
  27. // OCP\Util::writeLog('contacts','ajax/savecrop.php: '.$key.'=>'.$element, OCP\Util::DEBUG);
  28. // }
  29. function bailOut($msg) {
  30. OCP\JSON::error(array('data' => array('message' => $msg)));
  31. OCP\Util::writeLog('contacts','ajax/loadphoto.php: '.$msg, OCP\Util::DEBUG);
  32. exit();
  33. }
  34. $image = null;
  35. $id = isset($_GET['id']) ? $_GET['id'] : '';
  36. $refresh = isset($_GET['refresh']) ? true : false;
  37. if($id == '') {
  38. bailOut(OC_Contacts_App::$l10n->t('Missing contact id.'));
  39. }
  40. $checksum = '';
  41. $vcard = OC_Contacts_App::getContactVCard( $id );
  42. foreach($vcard->children as $property){
  43. if($property->name == 'PHOTO') {
  44. $checksum = md5($property->serialize());
  45. break;
  46. }
  47. }
  48. $tmpl = new OCP\Template("contacts", "part.contactphoto");
  49. $tmpl->assign('id', $id);
  50. if($refresh) {
  51. $tmpl->assign('refresh', 1);
  52. }
  53. $page = $tmpl->fetchPage();
  54. OCP\JSON::success(array('data' => array('page'=>$page, 'checksum'=>$checksum)));
  55. ?>