Ejemplo n.º 1
0
 /**
  * Save image data to cache and return the key
  *
  * @return string
  */
 private function cachePhoto()
 {
     if ($this->cached) {
         return;
     }
     if (!$this->image instanceof Image) {
         $this->processImage();
     }
     $this->normalizePhoto();
     $data = $this->image->data();
     $this->key = uniqid('photo-');
     $this->cache->set($this->key, $data, 600);
 }
Ejemplo n.º 2
0
 /**
  * Set the contact photo.
  *
  * @param \OCP\Image $photo
  */
 public function setPhoto(\OCP\Image $photo)
 {
     // For vCard 3.0 the type must be e.g. JPEG or PNG
     // For version 4.0 the full mimetype should be used.
     // https://tools.ietf.org/html/rfc2426#section-3.1.4
     if (strval($this->VERSION) === '4.0') {
         $type = $photo->mimeType();
     } else {
         $type = explode('/', $photo->mimeType());
         $type = strtoupper(array_pop($type));
     }
     if (isset($this->PHOTO)) {
         $this->remove('PHOTO');
     }
     $this->add('PHOTO', $photo->data(), ['ENCODING' => 'b', 'TYPE' => $type]);
     $this->setSaved(false);
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Fixes the preview cache by replacing the broken thumbnail with ours
  *
  * WARNING: Will break if the thumbnail folder ever moves or if encryption is turned on for
  * thumbnails
  *
  * @param resource $fixedPreview
  *
  * @return \OC_Image
  */
 private function fixPreviewCache($fixedPreview)
 {
     $owner = $this->userId;
     $file = $this->file;
     $preview = $this->preview;
     $fixedPreviewObject = new Image($fixedPreview);
     $previewData = $preview->getPreview();
     // Get the location where the broken thumbnail is stored
     $thumbnailFolder = $this->dataDir . '/' . $owner . '/';
     $thumbnail = $thumbnailFolder . $preview->isCached($file->getId());
     // Caching it for next time
     if ($fixedPreviewObject->save($thumbnail)) {
         $previewData = $fixedPreviewObject->data();
     }
     return $previewData;
 }
Ejemplo n.º 4
0
 /**
  * Get and set facebook profile picture
  */
 public function setPhoto()
 {
     if (isset($this->vcard->FBID)) {
         $img = file_get_contents("https://graph.facebook.com/" . $this->getFBID() . "/picture?height=1000");
         $image = new Image(base64_encode($img));
         // Center auto crop!!
         $image->centerCrop();
         if ($image->height() < 100 || $image->width() < 100) {
             // Maybe the graph API is disabled ?
             // Let's try to get the pic anyway
             $imgAltUrl = $this->fbController->getPicture_alt($this->getFBID());
             if (!$imgAltUrl) {
                 return array("error" => "Image unreachable", "id" => $this->id, "name" => $this->getName(), "addressbook" => $this->addressbook, "img" => $imgAltUrl, "photo" => isset($this->vcard->PHOTO), "photourl" => $this->getPhoto(100));
             } else {
                 if ($imgAltUrl == "notfound") {
                     return array("error" => "Wrong FBID, User not found", "id" => $this->id, "name" => $this->getName(), "addressbook" => $this->addressbook, "img" => $imgAltUrl, "photo" => isset($this->vcard->PHOTO), "photourl" => $this->getPhoto(100));
                 } else {
                     $imgAlt = file_get_contents($imgAltUrl);
                     $image = new Image(base64_encode($imgAlt));
                     // Center auto crop!!
                     $image->centerCrop();
                     if ($image->height() < 100 || $image->width() < 100) {
                         return array("error" => "Image too small", "id" => $this->id, "name" => $this->getName(), "addressbook" => $this->addressbook, "img" => $imgAltUrl, "photo" => isset($this->vcard->PHOTO), "photourl" => $this->getPhoto(100));
                     }
                 }
             }
         }
         // Image too big
         if ($image->width() > App::MAXPICTURESIZE || $image->height() > App::MAXPICTURESIZE) {
             $image->resize(App::MAXPICTURESIZE);
             // Prettier resizing than with browser and saves bandwidth.
         }
         // Image big enough or get without the graph API
         if (isset($this->vcard->PHOTO)) {
             unset($this->vcard->PHOTO);
         }
         // Add and save!
         $this->vcard->add('PHOTO', $image->data(), array('ENCODING' => 'b', 'TYPE' => $image->mimeType()));
         $this->save();
         return array("error" => false, "id" => $this->id, "name" => $this->getName(), "name" => $this->getName(), "addressbook" => $this->addressbook, "photo" => isset($this->vcard->PHOTO), "photourl" => $this->getPhoto(100), "alt_method" => isset($imgAltUrl) ? $imgAltUrl : false);
     }
 }