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); }
<?php /** * Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de> * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ OCP\JSON::checkLoggedIn(); OCP\App::checkAppEnabled('calendar'); OCP\JSON::callCheck(); session_write_close(); if (isset($_POST['progresskey']) && isset($_POST['getprogress'])) { echo OCP\JSON::success(array('percent' => OC_Cache::get($_POST['progresskey']))); exit; } $file = \OC\Files\Filesystem::file_get_contents($_POST['path'] . '/' . $_POST['file']); if (!$file) { OCP\JSON::error(array('error' => '404')); } $file = Sabre\VObject\StringUtil::convertToUTF8($file); $import = new OC_Calendar_Import($file); $import->setUserID(OCP\User::getUser()); $import->setTimeZone(OC_Calendar_App::$tz); $import->enableProgressCache(); $import->setProgresskey($_POST['progresskey']); if (!$import->isValid()) { OCP\JSON::error(array('error' => 'notvalid')); exit; } $newcal = false;
/** * ownCloud - Image generator for contacts. * * @author Thomas Tanghus * @copyright 2012 Thomas Tanghus <*****@*****.**> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * License as published by the Free Software Foundation; either * version 3 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU Affero General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. * */ $tmpkey = $_GET['tmpkey']; $maxsize = isset($_GET['maxsize']) ? $_GET['maxsize'] : -1; header("Cache-Control: no-cache, no-store, must-revalidate"); OCP\Util::writeLog('contacts', 'tmpphoto.php: tmpkey: ' . $tmpkey, OCP\Util::DEBUG); $image = new OC_Image(); $image->loadFromData(OC_Cache::get($tmpkey)); if ($maxsize != -1) { $image->resize($maxsize); } $image();
/** * @NoAdminRequired */ public function status() { $request = $this->request; $response = new JSONResponse(); $progresskey = isset($request->get['progresskey']) ? $request->get['progresskey'] : null; if (is_null($progresskey)) { $response->bailOut(App::$l10n->t('Progress key missing from request.')); return $response; } $response->setParams(array('progress' => \OC_Cache::get($progresskey))); return $response; }
/** * Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de> * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ //check for addressbooks rights or create new one ob_start(); OCP\JSON::checkLoggedIn(); OCP\App::checkAppEnabled('contacts'); session_write_close(); $nl = "\n"; global $progresskey; $progresskey = 'contacts.import-' . (isset($_GET['progresskey']) ? $_GET['progresskey'] : ''); if (isset($_GET['progress']) && $_GET['progress']) { echo OC_Cache::get($progresskey); die; } function writeProgress($pct) { global $progresskey; OC_Cache::set($progresskey, $pct, 300); } writeProgress('10'); $view = $file = null; if (isset($_POST['fstype']) && $_POST['fstype'] == 'OC_FilesystemView') { $view = OCP\Files::getStorage('contacts'); $file = $view->file_get_contents('/imports/' . $_POST['file']); } else { $file = OC_Filesystem::file_get_contents($_POST['path'] . '/' . $_POST['file']); }
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); }
$x1 = isset($_POST['x1']) && $_POST['x1'] ? $_POST['x1'] : 0; //$x2 = isset($_POST['x2']) ? $_POST['x2'] : -1; $y1 = isset($_POST['y1']) && $_POST['y1'] ? $_POST['y1'] : 0; //$y2 = isset($_POST['y2']) ? $_POST['y2'] : -1; $w = isset($_POST['w']) && $_POST['w'] ? $_POST['w'] : -1; $h = isset($_POST['h']) && $_POST['h'] ? $_POST['h'] : -1; $tmpkey = isset($_POST['tmpkey']) ? $_POST['tmpkey'] : ''; $id = isset($_POST['id']) ? $_POST['id'] : ''; if ($tmpkey == '') { bailOut('Missing key to temporary file.'); } if ($id == '') { bailOut('Missing contact id.'); } OCP\Util::writeLog('contacts', 'savecrop.php: key: ' . $tmpkey, OCP\Util::DEBUG); $data = OC_Cache::get($tmpkey); if ($data) { $image = new OC_Image(); if ($image->loadFromdata($data)) { $w = $w != -1 ? $w : $image->width(); $h = $h != -1 ? $h : $image->height(); OCP\Util::writeLog('contacts', 'savecrop.php, x: ' . $x1 . ' y: ' . $y1 . ' w: ' . $w . ' h: ' . $h, OCP\Util::DEBUG); if ($image->crop($x1, $y1, $w, $h)) { if ($image->width() <= 200 && $image->height() <= 200 || $image->resize(200)) { $vcard = OCA\Contacts\App::getContactVCard($id); if (!$vcard) { OC_Cache::remove($tmpkey); bailOut(OCA\Contacts\App::$l10n->t('Error getting contact object.')); } if ($vcard->__isset('PHOTO')) { OCP\Util::writeLog('contacts', 'savecrop.php: PHOTO property exists.', OCP\Util::DEBUG);
public static function postCroppedAvatar($args) { \OC_JSON::checkLoggedIn(); \OC_JSON::callCheck(); $user = \OC_User::getUser(); if (isset($_POST['crop'])) { $crop = $_POST['crop']; } else { $l = new \OC_L10n('core'); \OC_JSON::error(array("data" => array("message" => $l->t("No crop data provided")))); return; } $tmpavatar = \OC_Cache::get('tmpavatar'); if (is_null($tmpavatar)) { $l = new \OC_L10n('core'); \OC_JSON::error(array("data" => array("message" => $l->t("No temporary profile picture available, try again")))); return; } $image = new \OC_Image($tmpavatar); $image->crop($crop['x'], $crop['y'], $crop['w'], $crop['h']); try { $avatar = new \OC_Avatar($user); $avatar->set($image->data()); // Clean up \OC_Cache::remove('tmpavatar'); \OC_JSON::success(); } catch (\Exception $e) { \OC_JSON::error(array("data" => array("message" => $e->getMessage()))); } }