Ejemplo n.º 1
0
 public function __construct($configID = 'user_ldap')
 {
     $this->configID = $configID;
     $this->cache = \OC_Cache::getGlobalCache();
     $this->config['hasPagedResultSupport'] = function_exists('ldap_control_paged_result') && function_exists('ldap_control_paged_result_response');
     \OCP\Util::writeLog('user_ldap', 'PHP supports paged results? ' . print_r($this->config['hasPagedResultSupport'], true), \OCP\Util::INFO);
 }
Ejemplo n.º 2
0
 /**
  * @brief Constructor
  * @param $configPrefix a string with the prefix for the configkey column (appconfig table)
  * @param $configID a string with the value for the appid column (appconfig table) or null for on-the-fly connections
  */
 public function __construct($configPrefix = '', $configID = 'user_ldap')
 {
     $this->configPrefix = $configPrefix;
     $this->configID = $configID;
     $this->cache = \OC_Cache::getGlobalCache();
     $this->config['hasPagedResultSupport'] = function_exists('ldap_control_paged_result') && function_exists('ldap_control_paged_result_response');
 }
Ejemplo n.º 3
0
 public function getCacheKey()
 {
     if (!isset($this->cache_key)) {
         $files = $this->getRoutingFiles();
         $files[] = 'settings/routes.php';
         $files[] = 'core/routes.php';
         $this->cache_key = OC_Cache::generateCacheKeyFromFiles($files);
     }
     return $this->cache_key;
 }
Ejemplo n.º 4
0
 /**
  * @brief Constructor
  * @param $configPrefix a string with the prefix for the configkey column (appconfig table)
  * @param $configID a string with the value for the appid column (appconfig table) or null for on-the-fly connections
  */
 public function __construct(ILDAPWrapper $ldap, $configPrefix = '', $configID = 'user_ldap')
 {
     parent::__construct($ldap);
     $this->configPrefix = $configPrefix;
     $this->configID = $configID;
     $this->configuration = new Configuration($configPrefix);
     $memcache = new \OC\Memcache\Factory();
     if ($memcache->isAvailable()) {
         $this->cache = $memcache->create();
     } else {
         $this->cache = \OC_Cache::getGlobalCache();
     }
     $this->hasPagedResultSupport = $this->ldap->hasPagedResultSupport();
     $this->doNotValidate = !in_array($this->configPrefix, Helper::getServerConfigurationPrefixes());
 }
Ejemplo n.º 5
0
function writeProgress($pct)
{
    global $progresskey;
    OC_Cache::set($progresskey, $pct, 300);
}
Ejemplo n.º 6
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);
 }
Ejemplo n.º 7
0
 /**
  * get the file id as used in the cache
  * @param string path
  * @param string root (optional)
  * @return int
  */
 public static function getId($path, $root = false)
 {
     if ($root === false) {
         $root = OC_Filesystem::getRoot();
     }
     $fullPath = $root . $path;
     if (($cache = OC_Cache::getUserCache(true)) && $cache->hasKey('fileid/' . $fullPath)) {
         return $cache->get('fileid/' . $fullPath);
     }
     $query = OC_DB::prepare('SELECT `id` FROM `*PREFIX*fscache` WHERE `path_hash`=?');
     $result = $query->execute(array(md5($fullPath)));
     if (OC_DB::isError($result)) {
         OC_Log::write('files', 'error while getting file id of ' . $path, OC_Log::ERROR);
         return -1;
     }
     $result = $result->fetchRow();
     if (is_array($result)) {
         $id = $result['id'];
     } else {
         $id = -1;
     }
     if ($cache = OC_Cache::getUserCache(true)) {
         $cache->set('fileid/' . $fullPath, $id);
     }
     return $id;
 }
Ejemplo n.º 8
0
/**
 * 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();
Ejemplo n.º 9
0
 public function __construct(ILDAPWrapper $ldap)
 {
     $this->ldap = $ldap;
     $this->cache = \OC_Cache::getGlobalCache();
 }
Ejemplo n.º 10
0
    bailOut(OC_Contacts_App::$l10n->t('No contact ID was submitted.'));
}
if (!isset($_GET['path'])) {
    bailOut(OC_Contacts_App::$l10n->t('No photo path was submitted.'));
}
$localpath = OC_Filesystem::getLocalFile($_GET['path']);
$tmpkey = 'contact-photo-' . $_GET['id'];
if (!file_exists($localpath)) {
    bailOut(OC_Contacts_App::$l10n->t('File doesn\'t exist:') . $localpath);
}
$image = new OC_Image();
if (!$image) {
    bailOut(OC_Contacts_App::$l10n->t('Error loading image.'));
}
if (!$image->loadFromFile($localpath)) {
    bailOut(OC_Contacts_App::$l10n->t('Error loading image.'));
}
if ($image->width() > 400 || $image->height() > 400) {
    $image->resize(400);
    // Prettier resizing than with browser and saves bandwidth.
}
if (!$image->fixOrientation()) {
    // No fatal error so we don't bail out.
    OCP\Util::writeLog('contacts', 'ajax/oc_photo.php: Couldn\'t save correct image orientation: ' . $localpath, OCP\Util::DEBUG);
}
if (OC_Cache::set($tmpkey, $image->data(), 600)) {
    OCP\JSON::success(array('data' => array('id' => $_GET['id'], 'tmp' => $tmpkey)));
    exit;
} else {
    bailOut('Couldn\'t save temporary image: ' . $tmpkey);
}
Ejemplo n.º 11
0
$l10n = OCA\Contacts\App::$l10n;
$multi_properties = array('EMAIL', 'TEL', 'IMPP', 'ADR', 'URL');
if (!$id) {
    bailOut(OCA\Contacts\App::$l10n->t('id is not set.'));
}
if (!$name) {
    bailOut(OCA\Contacts\App::$l10n->t('element name is not set.'));
}
if (!$checksum && in_array($name, $multi_properties)) {
    bailOut(OCA\Contacts\App::$l10n->t('checksum is not set.'));
}
$vcard = OCA\Contacts\App::getContactVCard($id);
if (!is_null($checksum)) {
    $line = OCA\Contacts\App::getPropertyLineByChecksum($vcard, $checksum);
    if (is_null($line)) {
        bailOut($l10n->t('Information about vCard is incorrect. Please reload the page.'));
        exit;
    }
    unset($vcard->children[$line]);
} else {
    unset($vcard->{$name});
    if ($name === 'PHOTO') {
        \OC_Cache::remove(OCA\Contacts\App::THUMBNAIL_PREFIX . $id);
    }
}
try {
    OCA\Contacts\VCard::edit($id, $vcard);
} catch (Exception $e) {
    bailOut($e->getMessage());
}
OCP\JSON::success(array('data' => array('id' => $id, 'lastmodified' => OCA\Contacts\App::lastModified($vcard)->format('U'))));
Ejemplo n.º 12
0
set_time_limit(0);
//scanning can take ages
$force = isset($_GET['force']) and $_GET['force'] == 'true';
$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
$checkOnly = isset($_GET['checkonly']) and $_GET['checkonly'] == 'true';
if (!$checkOnly) {
    $eventSource = new OC_EventSource();
}
session_write_close();
//create the file cache if necesary
if ($force or !OC_FileCache::inCache('')) {
    if (!$checkOnly) {
        OCP\DB::beginTransaction();
        if (OC_Cache::isFast()) {
            OC_Cache::clear('fileid/');
            //make sure the old fileid's don't mess things up
        }
        OC_FileCache::scan($dir, $eventSource);
        OC_FileCache::clean();
        OCP\DB::commit();
        $eventSource->send('success', true);
    } else {
        OCP\JSON::success(array('data' => array('done' => true)));
        exit;
    }
} else {
    if ($checkOnly) {
        OCP\JSON::success(array('data' => array('done' => false)));
        exit;
    }
Ejemplo n.º 13
0
 private function updateProgress($percentage)
 {
     $this->progress = $percentage;
     if ($this->cacheprogress) {
         OC_Cache::set($this->progresskey, $this->progress, 300);
     }
     return true;
 }
Ejemplo n.º 14
0
 public function clearCache()
 {
     $cache = OC_Cache::getGlobalCache();
     $cache->clear('core.css');
     $cache->clear('core.js');
 }
Ejemplo n.º 15
0
 /**
  * check if a fast memory based cache is available
  * @return true
  */
 public static function isFast()
 {
     if (is_null(self::$isFast)) {
         self::$isFast = function_exists('xcache_set') || function_exists('apc_store');
     }
     return self::$isFast;
 }
Ejemplo n.º 16
0
 public function __construct($configID = 'user_ldap')
 {
     $this->configID = $configID;
     $this->cache = \OC_Cache::getGlobalCache();
 }
Ejemplo n.º 17
0
 public function import()
 {
     if (!$this->isValid()) {
         return false;
     }
     $numofcomponents = count($this->calobject->getComponents());
     if ($this->overwrite) {
         foreach (OC_Calendar_Object::all($this->id) as $obj) {
             OC_Calendar_Object::delete($obj['id']);
         }
     }
     foreach ($this->calobject->getComponents() as $object) {
         if (!$object instanceof Sabre\VObject\Component\VEvent && !$object instanceof Sabre\VObject\Component\VJournal && !$object instanceof Sabre\VObject\Component\VTodo) {
             continue;
         }
         if (!is_null($object->DTSTART)) {
             $dtend = OC_Calendar_Object::getDTEndFromVEvent($object);
             if ($object->DTEND) {
                 $object->DTEND->setDateTime($dtend->getDateTime(), $object->DTSTART->getDateType());
             }
         }
         $vcalendar = $this->createVCalendar($object->serialize());
         $insertid = OC_Calendar_Object::add($this->id, $vcalendar);
         $this->abscount++;
         if ($this->isDuplicate($insertid)) {
             OC_Calendar_Object::delete($insertid);
         } else {
             $this->count++;
         }
         $this->updateProgress(intval($this->abscount / $numofcomponents * 100));
     }
     OC_Cache::remove($this->progresskey);
     return true;
 }
Ejemplo n.º 18
0
 public function __construct()
 {
     $this->cache = \OC_Cache::getGlobalCache();
 }
Ejemplo n.º 19
0
 /**
  * @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;
 }
Ejemplo n.º 20
0
 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())));
     }
 }
Ejemplo n.º 21
0
<?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;
Ejemplo n.º 22
0
                    $property->parameters[] = new Sabre\VObject\Parameter('TYPE', $image->mimeType());
                    $vcard->__set('PHOTO', $property);
                } else {
                    OCP\Util::writeLog('contacts', 'savecrop.php: files: Adding PHOTO property.', OCP\Util::DEBUG);
                    // 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
                    $type = $vcard->VERSION == '4.0' ? $image->mimeType() : strtoupper(array_pop(explode('/', $image->mimeType())));
                    $vcard->add('PHOTO', $image->__toString(), array('ENCODING' => 'b', 'TYPE' => $type));
                }
                $now = new DateTime();
                $vcard->{'REV'} = $now->format(DateTime::W3C);
                if (!OCA\Contacts\VCard::edit($id, $vcard)) {
                    bailOut(OCA\Contacts\App::$l10n->t('Error saving contact.'));
                }
                OCA\Contacts\App::cacheThumbnail($id, $image);
                OCP\JSON::success(array('data' => array('id' => $id, 'width' => $image->width(), 'height' => $image->height(), 'lastmodified' => OCA\Contacts\App::lastModified($vcard)->format('U'))));
            } else {
                bailOut(OCA\Contacts\App::$l10n->t('Error resizing image'));
            }
        } else {
            bailOut(OCA\Contacts\App::$l10n->t('Error cropping image'));
        }
    } else {
        bailOut(OCA\Contacts\App::$l10n->t('Error creating temporary image'));
    }
} else {
    bailOut(OCA\Contacts\App::$l10n->t('Error finding image: ') . $tmpkey);
}
OC_Cache::remove($tmpkey);
Ejemplo n.º 23
0
 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);
 }
Ejemplo n.º 24
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);
    ?>