Beispiel #1
0
 public static function cacheThumbnail($id, \OC_Image $image = null)
 {
     if (\OC_Cache::hasKey(self::THUMBNAIL_PREFIX . $id)) {
         return \OC_Cache::get(self::THUMBNAIL_PREFIX . $id);
     }
     if (is_null($image)) {
         $vcard = self::getContactVCard($id);
         // invalid vcard
         if (is_null($vcard)) {
             \OCP\Util::writeLog('contacts', __METHOD__ . ' The VCard for ID ' . $id . ' is not RFC compatible', \OCP\Util::ERROR);
             return false;
         }
         $image = new \OC_Image();
         if (!isset($vcard->PHOTO)) {
             return false;
         }
         if (!$image->loadFromBase64((string) $vcard->PHOTO)) {
             return false;
         }
     }
     if (!$image->centerCrop()) {
         \OCP\Util::writeLog('contacts', 'thumbnail.php. Couldn\'t crop thumbnail for ID ' . $id, \OCP\Util::ERROR);
         return false;
     }
     if (!$image->resize(self::THUMBNAIL_SIZE)) {
         \OCP\Util::writeLog('contacts', 'thumbnail.php. Couldn\'t resize thumbnail for ID ' . $id, \OCP\Util::ERROR);
         return false;
     }
     // Cache for around a month
     \OC_Cache::set(self::THUMBNAIL_PREFIX . $id, $image->data(), 3000000);
     \OCP\Util::writeLog('contacts', 'Caching ' . $id, \OCP\Util::DEBUG);
     return \OC_Cache::get(self::THUMBNAIL_PREFIX . $id);
 }
 public function cacheThumbnail(\OCP\Image $image = null, $remove = false, $update = false)
 {
     $key = self::THUMBNAIL_PREFIX . $this->combinedKey();
     //\OC_Cache::remove($key);
     if (\OC_Cache::hasKey($key) && $image === null && $remove === false && $update === false) {
         return \OC_Cache::get($key);
     }
     if ($remove) {
         \OC_Cache::remove($key);
         if (!$update) {
             return false;
         }
     }
     if (is_null($image)) {
         $this->retrieve();
         $image = new \OCP\Image();
         if (!isset($this->PHOTO) && !isset($this->LOGO)) {
             return false;
         }
         if (!$image->loadFromBase64((string) $this->PHOTO)) {
             if (!$image->loadFromBase64((string) $this->LOGO)) {
                 return false;
             }
         }
     }
     if (!$image->centerCrop()) {
         \OCP\Util::writeLog('contacts', __METHOD__ . '. Couldn\'t crop thumbnail for ID ' . $key, \OCP\Util::ERROR);
         return false;
     }
     if (!$image->resize(self::THUMBNAIL_SIZE)) {
         \OCP\Util::writeLog('contacts', __METHOD__ . '. Couldn\'t resize thumbnail for ID ' . $key, \OCP\Util::ERROR);
         return false;
     }
     // Cache as base64 for around a month
     \OC_Cache::set($key, strval($image), 3000000);
     \OCP\Util::writeLog('contacts', 'Caching ' . $key, \OCP\Util::DEBUG);
     return \OC_Cache::get($key);
 }
Beispiel #3
0
<?php

$id = $_['id'];
$tmpkey = $_['tmpkey'];
$requesttoken = $_['requesttoken'];
if (OC_Cache::hasKey($tmpkey)) {
    ?>
<img id="cropbox" src="<?php 
    print_unescaped(OCP\Util::linkToAbsolute('contacts', 'tmpphoto.php'));
    ?>
?tmpkey=<?php 
    p($tmpkey);
    ?>
" />
<form id="cropform"
	class="coords"
	method="post"
	enctype="multipart/form-data"
	target="crop_target"
	action="<?php 
    print_unescaped(OCP\Util::linkToAbsolute('contacts', 'ajax/savecrop.php'));
    ?>
">

	<input type="hidden" id="id" name="id" value="<?php 
    p($id);
    ?>
" />
	<input type="hidden" name="requesttoken" value="<?php 
    p($requesttoken);
    ?>