Beispiel #1
0
 public function __construct(ICache $cache, $contact)
 {
     if (!$contact instanceof ContactObject) {
         throw new \Exception(__METHOD__ . ' Second argument must be an instance of OCA\\Contacts\\Contact');
     }
     parent::__construct($cache);
     $this->contact = $contact;
     $this->processImage();
 }
Beispiel #2
0
 public function __construct(ICache $cache, $userId)
 {
     parent::__construct($cache);
     // check if userId is a real ownCloud user
     if (!in_array($userId, \OCP\User::getUsers())) {
         throw new \Exception('Second argument must be an ownCloud user ID');
     }
     $this->userId = $userId;
     $this->processImage();
 }
 public function __construct(ICache $cache, IRequest $request)
 {
     \OCP\Util::writeLog('contacts', __METHOD__, \OCP\Util::DEBUG);
     if (!$request instanceof IRequest) {
         throw new \Exception(__METHOD__ . ' Second argument must be an instance of \\OCP\\IRequest');
     }
     parent::__construct($cache);
     $this->request = $request;
     $this->processImage();
 }
Beispiel #4
0
 public function __construct(ICache $cache, $path)
 {
     \OCP\Util::writeLog('contacts', __METHOD__ . ' path: ' . $path, \OCP\Util::DEBUG);
     if (!is_string($path)) {
         throw new \Exception(__METHOD__ . ' Second argument must a string');
     }
     parent::__construct($cache);
     $this->path = $path;
     $this->processImage();
 }
 /**
  * Get a photo from the oC and crops it with the suplied geometry.
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function cropPhoto()
 {
     $params = $this->request->urlParams;
     $x = $this->params('x', 0);
     $y = $this->params('y', 0);
     $w = $this->params('w', -1);
     $h = $this->params('h', -1);
     $tmpkey = $params['key'];
     $addressBook = $this->app->getAddressBook($params['backend'], $params['addressBookId']);
     $contact = $addressBook->getChild($params['contactId']);
     $response = new JSONResponse();
     $tmpPhoto = new TemporaryPhoto($this->cache, $tmpkey);
     $image = $tmpPhoto->getPhoto();
     if (!$image || !$image->valid()) {
         return $response->bailOut(App::$l10n->t('Error loading image from cache'));
     }
     $w = $w !== -1 ? $w : $image->width();
     $h = $h !== -1 ? $h : $image->height();
     $image->crop($x, $y, $w, $h);
     if (!$contact->setPhoto($image)) {
         $tmpPhoto->remove($tmpkey);
         return $response->bailOut(App::$l10n->t('Error getting PHOTO property.'));
     }
     if (!$contact->save()) {
         return $response->bailOut(App::$l10n->t('Error saving contact.'));
     }
     $thumbnail = Properties::cacheThumbnail($params['backend'], $params['addressBookId'], $params['contactId'], $image, $contact);
     $response->setData(array('status' => 'success', 'data' => array('id' => $params['contactId'], 'thumbnail' => $thumbnail)));
     $tmpPhoto->remove($tmpkey);
     return $response;
 }