diff options
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/backgroundjob/joblist.php | 5 | ||||
-rw-r--r-- | lib/private/contacts/localaddressbook.php | 104 | ||||
-rw-r--r-- | lib/private/db/mdb2schemamanager.php | 3 | ||||
-rw-r--r-- | lib/private/db/migrator.php | 4 | ||||
-rw-r--r-- | lib/private/db/mysqlmigrator.php | 4 | ||||
-rw-r--r-- | lib/private/db/sqlitemigrator.php | 39 | ||||
-rw-r--r-- | lib/private/image.php | 8 | ||||
-rwxr-xr-x | lib/private/preview.php | 10 | ||||
-rw-r--r-- | lib/private/preview/mp3.php | 2 | ||||
-rw-r--r-- | lib/private/server.php | 6 | ||||
-rw-r--r-- | lib/private/share/share.php | 64 | ||||
-rw-r--r-- | lib/private/updater.php | 5 | ||||
-rw-r--r-- | lib/private/user/user.php | 2 | ||||
-rwxr-xr-x | lib/private/util.php | 24 |
14 files changed, 259 insertions, 21 deletions
diff --git a/lib/private/backgroundjob/joblist.php b/lib/private/backgroundjob/joblist.php index 211d7e9abfc..9d15cd1663a 100644 --- a/lib/private/backgroundjob/joblist.php +++ b/lib/private/backgroundjob/joblist.php @@ -96,7 +96,10 @@ class JobList implements IJobList { $query->execute(); $jobs = array(); while ($row = $query->fetch()) { - $jobs[] = $this->buildJob($row); + $job = $this->buildJob($row); + if ($job) { + $jobs[] = $job; + } } return $jobs; } diff --git a/lib/private/contacts/localaddressbook.php b/lib/private/contacts/localaddressbook.php new file mode 100644 index 00000000000..483bbee83f8 --- /dev/null +++ b/lib/private/contacts/localaddressbook.php @@ -0,0 +1,104 @@ +<?php + /** + * ownCloud + * + * @author Thomas Müller + * @copyright 2014 Thomas Müller >deepdiver@owncloud.com> + * + */ + +namespace OC\Contacts; + +class LocalAddressBook implements \OCP\IAddressBook { + + /** + * @var \OCP\IUserManager + */ + private $userManager; + + /** + * @param $userManager + */ + public function __construct($userManager) { + $this->userManager = $userManager; + } + + /** + * @return string defining the technical unique key + */ + public function getKey() { + return 'local'; + } + + /** + * In comparison to getKey() this function returns a human readable (maybe translated) name + * + * @return mixed + */ + public function getDisplayName() { + return "Local users"; + } + + /** + * @param string $pattern which should match within the $searchProperties + * @param array $searchProperties defines the properties within the query pattern should match + * @param array $options - for future use. One should always have options! + * @return array an array of contacts which are arrays of key-value-pairs + */ + public function search($pattern, $searchProperties, $options) { + $users = array(); + if($pattern == '') { + // Fetch all contacts + $users = $this->userManager->search(''); + } else { + foreach($searchProperties as $property) { + $result = array(); + if($property === 'FN') { + $result = $this->userManager->searchDisplayName($pattern); + } else if ($property === 'id') { + $result = $this->userManager->search($pattern); + } + if (is_array($result)) { + $users = array_merge($users, $result); + } + } + } + + $contacts = array(); + foreach($users as $user){ + $contact = array( + "id" => $user->getUID(), + "FN" => $user->getDisplayname(), + "EMAIL" => array(), + "IMPP" => array( + "x-owncloud-handle:" . $user->getUID() + ) + ); + $contacts[] = $contact; + } + return $contacts; + } + + /** + * @param array $properties this array if key-value-pairs defines a contact + * @return array an array representing the contact just created or updated + */ + public function createOrUpdate($properties) { + return array(); + } + + /** + * @return int + */ + public function getPermissions() { + return \OCP\PERMISSION_READ; + } + + /** + * @param object $id the unique identifier to a contact + * @return bool successful or not + */ + public function delete($id) { + return false; + } +} diff --git a/lib/private/db/mdb2schemamanager.php b/lib/private/db/mdb2schemamanager.php index d3e379c9417..91e590a901a 100644 --- a/lib/private/db/mdb2schemamanager.php +++ b/lib/private/db/mdb2schemamanager.php @@ -59,7 +59,8 @@ class MDB2SchemaManager { public function getMigrator() { $platform = $this->conn->getDatabasePlatform(); if ($platform instanceof SqlitePlatform) { - return new SQLiteMigrator($this->conn); + $config = \OC::$server->getConfig(); + return new SQLiteMigrator($this->conn, $config); } else if ($platform instanceof OraclePlatform) { return new OracleMigrator($this->conn); } else if ($platform instanceof MySqlPlatform) { diff --git a/lib/private/db/migrator.php b/lib/private/db/migrator.php index 6443cf4ed48..d05f8455551 100644 --- a/lib/private/db/migrator.php +++ b/lib/private/db/migrator.php @@ -110,7 +110,9 @@ class Migrator { $this->dropTable($tmpName); } catch (DBALException $e) { // pgsql needs to commit it's failed transaction before doing anything else - $this->connection->commit(); + if ($this->connection->isTransactionActive()) { + $this->connection->commit(); + } $this->dropTable($tmpName); throw new MigrationException($table->getName(), $e->getMessage()); } diff --git a/lib/private/db/mysqlmigrator.php b/lib/private/db/mysqlmigrator.php index 97495f52032..c0adcdf5df3 100644 --- a/lib/private/db/mysqlmigrator.php +++ b/lib/private/db/mysqlmigrator.php @@ -17,6 +17,10 @@ class MySQLMigrator extends Migrator { * @return \Doctrine\DBAL\Schema\SchemaDiff */ protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { + $platform = $connection->getDatabasePlatform(); + $platform->registerDoctrineTypeMapping('enum', 'string'); + $platform->registerDoctrineTypeMapping('bit', 'string'); + $schemaDiff = parent::getDiff($targetSchema, $connection); // identifiers need to be quoted for mysql diff --git a/lib/private/db/sqlitemigrator.php b/lib/private/db/sqlitemigrator.php index f5f78986771..94b421c5562 100644 --- a/lib/private/db/sqlitemigrator.php +++ b/lib/private/db/sqlitemigrator.php @@ -9,8 +9,24 @@ namespace OC\DB; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Schema\Schema; class SQLiteMigrator extends Migrator { + + /** + * @var \OCP\IConfig + */ + private $config; + + /** + * @param \Doctrine\DBAL\Connection $connection + * @param \OCP\IConfig $config + */ + public function __construct(\Doctrine\DBAL\Connection $connection, \OCP\IConfig $config) { + parent::__construct($connection); + $this->config = $config; + } + /** * @param \Doctrine\DBAL\Schema\Schema $targetSchema * @throws \OC\DB\MigrationException @@ -19,7 +35,7 @@ class SQLiteMigrator extends Migrator { */ public function checkMigrate(\Doctrine\DBAL\Schema\Schema $targetSchema) { $dbFile = $this->connection->getDatabase(); - $tmpFile = \OC_Helper::tmpFile('.db'); + $tmpFile = $this->buildTempDatabase(); copy($dbFile, $tmpFile); $connectionParams = array( @@ -37,4 +53,25 @@ class SQLiteMigrator extends Migrator { throw new MigrationException('', $e->getMessage()); } } + + /** + * @return string + */ + private function buildTempDatabase() { + $dataDir = $this->config->getSystemValue("datadirectory", \OC::$SERVERROOT . '/data'); + $tmpFile = uniqid("oc_"); + return "$dataDir/$tmpFile.db"; + } + + /** + * @param Schema $targetSchema + * @param \Doctrine\DBAL\Connection $connection + * @return \Doctrine\DBAL\Schema\SchemaDiff + */ + protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { + $platform = $connection->getDatabasePlatform(); + $platform->registerDoctrineTypeMapping('tinyint unsigned', 'integer'); + + return parent::getDiff($targetSchema, $connection); + } } diff --git a/lib/private/image.php b/lib/private/image.php index 5331c399159..0dff8c5a9da 100644 --- a/lib/private/image.php +++ b/lib/private/image.php @@ -870,6 +870,14 @@ class OC_Image { imagedestroy($process); return false; } + + // preserve transparency + if($this->imageType == IMAGETYPE_GIF or $this->imageType == IMAGETYPE_PNG) { + imagecolortransparent($process, imagecolorallocatealpha($process, 0, 0, 0, 127)); + imagealphablending($process, false); + imagesavealpha($process, true); + } + imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $w, $h, $w, $h); if ($process == false) { OC_Log::write('core', __METHOD__.'(): Error resampling process image '.$w.'x'.$h, OC_Log::ERROR); diff --git a/lib/private/preview.php b/lib/private/preview.php index 8089379bde5..6172519c7d1 100755 --- a/lib/private/preview.php +++ b/lib/private/preview.php @@ -561,9 +561,15 @@ class Preview { $realX = (int)$image->width(); $realY = (int)$image->height(); - // compute $maxY using the aspect of the generated preview + // compute $maxY and $maxX using the aspect of the generated preview if ($this->keepAspect) { - $y = $x / ($realX / $realY); + $ratio = $realX / $realY; + if($x / $ratio < $y) { + // width restricted + $y = $x / $ratio; + } else { + $x = $y * $ratio; + } } if ($x === $realX && $y === $realY) { diff --git a/lib/private/preview/mp3.php b/lib/private/preview/mp3.php index 21f160fd50f..bb4d3dfce86 100644 --- a/lib/private/preview/mp3.php +++ b/lib/private/preview/mp3.php @@ -14,8 +14,6 @@ class MP3 extends Provider { } public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { - require_once('getid3/getid3.php'); - $getID3 = new \getID3(); $tmpPath = $fileview->toTmpFile($path); diff --git a/lib/private/server.php b/lib/private/server.php index da705863078..3299792e20d 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -255,7 +255,11 @@ class Server extends SimpleContainer implements IServerContainer { * @return \OCP\Files\Folder */ function getUserFolder() { - $dir = '/' . \OCP\User::getUser(); + $user = $this->getUserSession()->getUser(); + if (!$user) { + return null; + } + $dir = '/' . $user->getUID(); $root = $this->getRootFolder(); $folder = null; diff --git a/lib/private/share/share.php b/lib/private/share/share.php index 673c0dc383a..7fd5cd70e1d 100644 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@ -595,6 +595,7 @@ class Share extends \OC\Share\Constants { $shareWith['group'] = $group; $shareWith['users'] = array_diff(\OC_Group::usersInGroup($group), array($uidOwner)); } else if ($shareType === self::SHARE_TYPE_LINK) { + $updateExistingShare = false; if (\OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes') == 'yes') { // when updating a link share @@ -629,7 +630,7 @@ class Share extends \OC\Share\Constants { throw new \Exception($message_t); } - if (!empty($updateExistingShare) && + if ($updateExistingShare === false && self::isDefaultExpireDateEnabled() && empty($expirationDate)) { $expirationDate = Helper::calcExpireDate(); @@ -925,19 +926,69 @@ class Share extends \OC\Share\Constants { } /** + * validate expire date if it meets all constraints + * + * @param string $expireDate well formate date string, e.g. "DD-MM-YYYY" + * @param string $shareTime timestamp when the file was shared + * @param string $itemType + * @param string $itemSource + * @return DateTime validated date + * @throws \Exception + */ + private static function validateExpireDate($expireDate, $shareTime, $itemType, $itemSource) { + $l = \OC_L10N::get('lib'); + $date = new \DateTime($expireDate); + $today = new \DateTime('now'); + + // if the user doesn't provide a share time we need to get it from the database + // fall-back mode to keep API stable, because the $shareTime parameter was added later + $defaultExpireDateEnforced = \OCP\Util::isDefaultExpireDateEnforced(); + if ($defaultExpireDateEnforced && $shareTime === null) { + $items = self::getItemShared($itemType, $itemSource); + $firstItem = reset($items); + $shareTime = (int)$firstItem['stime']; + } + + if ($defaultExpireDateEnforced) { + // initialize max date with share time + $maxDate = new \DateTime(); + $maxDate->setTimestamp($shareTime); + $maxDays = \OCP\Config::getAppValue('core', 'shareapi_expire_after_n_days', '7'); + $maxDate->add(new \DateInterval('P' . $maxDays . 'D')); + if ($date > $maxDate) { + $warning = 'Can not set expire date. Shares can not expire later then ' . $maxDays . ' after they where shared'; + $warning_t = $l->t('Can not set expire date. Shares can not expire later then %s after they where shared', array($maxDays)); + \OCP\Util::writeLog('OCP\Share', $warning, \OCP\Util::WARN); + throw new \Exception($warning_t); + } + } + + if ($date < $today) { + $message = 'Can not set expire date. Expire date is in the past'; + $message_t = $l->t('Can not set expire date. Expire date is in the past'); + \OCP\Util::writeLog('OCP\Share', $message, \OCP\Util::WARN); + throw new \Exception($message_t); + } + + return $date; + } + + /** * Set expiration date for a share * @param string $itemType * @param string $itemSource * @param string $date expiration date + * @param int $shareTime timestamp from when the file was shared + * @throws \Exception * @return boolean */ - public static function setExpirationDate($itemType, $itemSource, $date) { + public static function setExpirationDate($itemType, $itemSource, $date, $shareTime = null) { $user = \OC_User::getUser(); if ($date == '') { $date = null; } else { - $date = new \DateTime($date); + $date = self::validateExpireDate($date, $shareTime, $itemType, $itemSource); } $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `item_type` = ? AND `item_source` = ? AND `uid_owner` = ? AND `share_type` = ?'); $query->bindValue(1, $date, 'datetime'); @@ -954,11 +1005,10 @@ class Share extends \OC\Share\Constants { 'date' => $date, 'uidOwner' => $user )); - + return true; + } - } - /** * Checks whether a share has expired, calls unshareItem() if yes. * @param array $item Share data (usually database row) @@ -1348,7 +1398,7 @@ class Share extends \OC\Share\Constants { } } // Check if resharing is allowed, if not remove share permission - if (isset($row['permissions']) && !self::isResharingAllowed()) { + if (isset($row['permissions']) && (!self::isResharingAllowed() | \OC_Util::isSharingDisabledForUser())) { $row['permissions'] &= ~\OCP\PERMISSION_SHARE; } // Add display names to result diff --git a/lib/private/updater.php b/lib/private/updater.php index d50c2554c75..7acd6446ec4 100644 --- a/lib/private/updater.php +++ b/lib/private/updater.php @@ -212,8 +212,6 @@ class Updater extends BasicEmitter { \OC_DB::updateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml'); $this->emit('\OC\Updater', 'dbUpgrade'); - // TODO: why not do this at the end ? - \OC_Config::setValue('version', implode('.', \OC_Util::getVersion())); $disabledApps = \OC_App::checkAppsRequirements(); if (!empty($disabledApps)) { $this->emit('\OC\Updater', 'disabledApps', array($disabledApps)); @@ -227,6 +225,9 @@ class Updater extends BasicEmitter { //Invalidate update feed \OC_Appconfig::setValue('core', 'lastupdatedat', 0); + + // only set the final version if everything went well + \OC_Config::setValue('version', implode('.', \OC_Util::getVersion())); } } } diff --git a/lib/private/user/user.php b/lib/private/user/user.php index f9c2cb4d130..993fb4c0c64 100644 --- a/lib/private/user/user.php +++ b/lib/private/user/user.php @@ -156,7 +156,7 @@ class User implements IUser { * @param string $recoveryPassword for the encryption app to reset encryption keys * @return bool */ - public function setPassword($password, $recoveryPassword) { + public function setPassword($password, $recoveryPassword = null) { if ($this->emitter) { $this->emitter->emit('\OC\User', 'preSetPassword', array($this, $password, $recoveryPassword)); } diff --git a/lib/private/util.php b/lib/private/util.php index eea194288f9..896b076afa6 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -22,7 +22,7 @@ class OC_Util { self::$rootMounted = true; } } - + /** * mounting an object storage as the root fs will in essence remove the * necessity of a data folder being present. @@ -50,7 +50,7 @@ class OC_Util { self::$rootMounted = true; } } - + /** * Can be set up * @param string $user @@ -171,6 +171,21 @@ class OC_Util { } /** + * check if share API enforces a default expire date + * @return boolean + */ + public static function isDefaultExpireDateEnforced() { + $isDefaultExpireDateEnabled = \OCP\Config::getAppValue('core', 'shareapi_default_expire_date', 'no'); + $enforceDefaultExpireDate = false; + if ($isDefaultExpireDateEnabled === 'yes') { + $value = \OCP\Config::getAppValue('core', 'shareapi_enforce_expire_date', 'no'); + $enforceDefaultExpireDate = ($value === 'yes') ? true : false; + } + + return $enforceDefaultExpireDate; + } + + /** * Get the quota of a user * @param string $user * @return int Quota bytes @@ -1217,11 +1232,16 @@ class OC_Util { /** * @Brief Get file content via curl. * @param string $url Url to get content + * @throws Exception If the URL does not start with http:// or https:// * @return string of the response or false on error * This function get the content of a page via curl, if curl is enabled. * If not, file_get_contents is used. */ public static function getUrlContent($url) { + if (strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) { + throw new Exception('$url must start with https:// or http://', 1); + } + if (function_exists('curl_init')) { $curl = curl_init(); $max_redirects = 10; |