diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/autoloader.php | 7 | ||||
-rw-r--r-- | lib/private/connector/sabre/node.php | 9 | ||||
-rw-r--r-- | lib/private/defaults.php | 5 | ||||
-rw-r--r-- | lib/private/files/cache/upgrade.php | 10 | ||||
-rw-r--r-- | lib/private/template/functions.php | 45 | ||||
-rwxr-xr-x | lib/private/util.php | 34 | ||||
-rw-r--r-- | lib/public/share.php | 90 | ||||
-rw-r--r-- | lib/public/template.php | 4 |
8 files changed, 178 insertions, 26 deletions
diff --git a/lib/autoloader.php b/lib/autoloader.php index 72041200116..b5b58918372 100644 --- a/lib/autoloader.php +++ b/lib/autoloader.php @@ -77,6 +77,7 @@ class Autoloader { $paths[] = 'private/' . strtolower(str_replace('_', '/', substr($class, 3)) . '.php'); } elseif (strpos($class, 'OC\\') === 0) { $paths[] = 'private/' . strtolower(str_replace('\\', '/', substr($class, 3)) . '.php'); + $paths[] = strtolower(str_replace('\\', '/', substr($class, 3)) . '.php'); } elseif (strpos($class, 'OCP\\') === 0) { $paths[] = 'public/' . strtolower(str_replace('\\', '/', substr($class, 4)) . '.php'); } elseif (strpos($class, 'OCA\\') === 0) { @@ -117,7 +118,11 @@ class Autoloader { // Does this PHP have an in-memory cache? We cache the paths there if ($this->constructingMemoryCache && !$this->memoryCache) { $this->constructingMemoryCache = false; - $this->memoryCache = \OC\Memcache\Factory::createLowLatency('Autoloader'); + try { + $this->memoryCache = \OC\Memcache\Factory::createLowLatency('Autoloader'); + } catch(\Exception $ex) { + // no caching then - fine with me + } } if ($this->memoryCache) { $pathsToRequire = $this->memoryCache->get($class); diff --git a/lib/private/connector/sabre/node.php b/lib/private/connector/sabre/node.php index 29b7f9e53a5..e65ad7b8bef 100644 --- a/lib/private/connector/sabre/node.php +++ b/lib/private/connector/sabre/node.php @@ -207,7 +207,14 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr while( $row = $result->fetchRow()) { $this->property_cache[$row['propertyname']] = $row['propertyvalue']; } - $this->property_cache[self::GETETAG_PROPERTYNAME] = $this->getETagPropertyForPath($this->path); + + // Don't call the static getETagPropertyForPath, its result is not cached + $this->getFileinfoCache(); + if ($this->fileinfo_cache['etag']) { + $this->property_cache[self::GETETAG_PROPERTYNAME] = '"'.$this->fileinfo_cache['etag'].'"'; + } else { + $this->property_cache[self::GETETAG_PROPERTYNAME] = null; + } } // if the array was empty, we need to return everything diff --git a/lib/private/defaults.php b/lib/private/defaults.php index 10813a3e8d8..4951c6f50ae 100644 --- a/lib/private/defaults.php +++ b/lib/private/defaults.php @@ -13,6 +13,7 @@ if (file_exists(OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults. class OC_Defaults { private $theme; + private $l; private $defaultEntity; private $defaultName; @@ -24,7 +25,7 @@ class OC_Defaults { private $defaultLogoClaim; function __construct() { - $l = OC_L10N::get('core'); + $this->l = OC_L10N::get('core'); $this->defaultEntity = "ownCloud"; /* e.g. company name, used for footers and copyright notices */ $this->defaultName = "ownCloud"; /* short name, used when referring to the software */ @@ -32,7 +33,7 @@ class OC_Defaults { $this->defaultBaseUrl = "http://owncloud.org"; $this->defaultSyncClientUrl = " http://owncloud.org/sync-clients/"; $this->defaultDocBaseUrl = "http://doc.owncloud.org"; - $this->defaultSlogan = $l->t("web services under your control"); + $this->defaultSlogan = $this->l->t("web services under your control"); $this->defaultLogoClaim = ""; if (class_exists("OC_Theme")) { diff --git a/lib/private/files/cache/upgrade.php b/lib/private/files/cache/upgrade.php index cfb9a117311..e3a46896cbf 100644 --- a/lib/private/files/cache/upgrade.php +++ b/lib/private/files/cache/upgrade.php @@ -192,7 +192,15 @@ class Upgrade { */ static function needUpgrade($user) { $cacheVersion = (int)\OCP\Config::getUserValue($user, 'files', 'cache_version', 4); - return $cacheVersion < 5; + if ($cacheVersion < 5) { + $legacy = new \OC\Files\Cache\Legacy($user); + if ($legacy->hasItems()) { + return true; + } + self::upgradeDone($user); + } + + return false; } /** diff --git a/lib/private/template/functions.php b/lib/private/template/functions.php index 501f8081bff..0aa2b27b96b 100644 --- a/lib/private/template/functions.php +++ b/lib/private/template/functions.php @@ -85,22 +85,51 @@ function human_file_size( $bytes ) { return OC_Helper::humanFileSize( $bytes ); } -function relative_modified_date($timestamp) { +/** + * @brief Strips the timestamp of its time value + * @param int $timestamp UNIX timestamp to strip + * @return $timestamp without time value + */ +function strip_time($timestamp){ + $date = new \DateTime("@{$timestamp}"); + $date->setTime(0, 0, 0); + return intval($date->format('U')); +} + +/** + * @brief Formats timestamp relatively to the current time using + * a human-friendly format like "x minutes ago" or "yesterday" + * @param int $timestamp timestamp to format + * @param int $fromTime timestamp to compare from, defaults to current time + * @param bool $dateOnly whether to strip time information + * @return formatted timestamp + */ +function relative_modified_date($timestamp, $fromTime = null, $dateOnly = false) { $l=OC_L10N::get('lib'); - $timediff = time() - $timestamp; + if (!isset($fromTime) || $fromTime === null){ + $fromTime = time(); + } + if ($dateOnly){ + $fromTime = strip_time($fromTime); + $timestamp = strip_time($timestamp); + } + $timediff = $fromTime - $timestamp; $diffminutes = round($timediff/60); $diffhours = round($diffminutes/60); $diffdays = round($diffhours/24); $diffmonths = round($diffdays/31); - if($timediff < 60) { return $l->t('seconds ago'); } - else if($timediff < 3600) { return $l->n('%n minute ago', '%n minutes ago', $diffminutes); } - else if($timediff < 86400) { return $l->n('%n hour ago', '%n hours ago', $diffhours); } - else if((date('G')-$diffhours) > 0) { return $l->t('today'); } - else if((date('G')-$diffhours) > -24) { return $l->t('yesterday'); } + if(!$dateOnly && $timediff < 60) { return $l->t('seconds ago'); } + else if(!$dateOnly && $timediff < 3600) { return $l->n('%n minute ago', '%n minutes ago', $diffminutes); } + else if(!$dateOnly && $timediff < 86400) { return $l->n('%n hour ago', '%n hours ago', $diffhours); } + else if((date('G', $fromTime)-$diffhours) >= 0) { return $l->t('today'); } + else if((date('G', $fromTime)-$diffhours) >= -24) { return $l->t('yesterday'); } + // 86400 * 31 days = 2678400 else if($timediff < 2678400) { return $l->n('%n day go', '%n days ago', $diffdays); } + // 86400 * 60 days = 518400 else if($timediff < 5184000) { return $l->t('last month'); } - else if((date('n')-$diffmonths) > 0) { return $l->n('%n month ago', '%n months ago', $diffmonths); } + else if((date('n', $fromTime)-$diffmonths) > 0) { return $l->n('%n month ago', '%n months ago', $diffmonths); } + // 86400 * 365.25 days * 2 = 63113852 else if($timediff < 63113852) { return $l->t('last year'); } else { return $l->t('years ago'); } } diff --git a/lib/private/util.php b/lib/private/util.php index ea2eb98d23c..ae9aef69b4c 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -68,6 +68,7 @@ class OC_Util { $userDirectory = $userRoot . '/files'; if( !is_dir( $userDirectory )) { mkdir( $userDirectory, 0755, true ); + OC_Util::copySkeleton($userDirectory); } //jail the user into his "home" directory \OC\Files\Filesystem::init($user, $userDir); @@ -93,6 +94,35 @@ class OC_Util { } /** + * @brief copies the user skeleton files into the fresh user home files + * @param string $userDirectory + */ + public static function copySkeleton($userDirectory) { + OC_Util::copyr(\OC::$SERVERROOT.'/core/skeleton' , $userDirectory); + } + + /** + * @brief copies a directory recursively + * @param string $source + * @param string $target + * @return void + */ + public static function copyr($source,$target) { + $dir = opendir($source); + @mkdir($target); + while(false !== ( $file = readdir($dir)) ) { + if ( !\OC\Files\Filesystem::isIgnoredDir($file) ) { + if ( is_dir($source . '/' . $file) ) { + OC_Util::copyr($source . '/' . $file , $target . '/' . $file); + } else { + copy($source . '/' . $file,$target . '/' . $file); + } + } + } + closedir($dir); + } + + /** * @return void */ public static function tearDownFS() { @@ -138,7 +168,7 @@ class OC_Util { OC_Util::loadVersion(); return \OC::$server->getSession()->get('OC_Channel'); } - + /** * @description get the build number of the current installed of ownCloud. * @return string @@ -617,7 +647,7 @@ class OC_Util { if(is_null($id)) { // We need to guarantee at least one letter in instanceid so it can be used as the session_name $id = 'oc' . self::generateRandomBytes(10); - OC_Config::setValue('instanceid', $id); + OC_Config::$object->setValue('instanceid', $id); } return $id; } diff --git a/lib/public/share.php b/lib/public/share.php index 6c5783f1179..e6a74117aa2 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -246,9 +246,9 @@ class Share { /** * @brief Get the item of item type shared with the current user - * @param string Item type - * @param string Item target - * @param int Format (optional) Format type must be defined by the backend + * @param string $itemType + * @param string $ItemTarget + * @param int $format (optional) Format type must be defined by the backend * @return Return depends on format */ public static function getItemSharedWith($itemType, $itemTarget, $format = self::FORMAT_NONE, @@ -258,6 +258,55 @@ class Share { } /** + * @brief Get the item of item type shared with a given user by source + * @param string $ItemType + * @param string $ItemSource + * @param string $user User user to whom the item was shared + * @return array Return list of items with file_target, permissions and expiration + */ + public static function getItemSharedWithUser($itemType, $itemSource, $user) { + + $shares = array(); + + // first check if there is a db entry for the specific user + $query = \OC_DB::prepare( + 'SELECT `file_target`, `permissions`, `expiration` + FROM + `*PREFIX*share` + WHERE + `item_source` = ? AND `item_type` = ? AND `share_with` = ?' + ); + + $result = \OC_DB::executeAudited($query, array($itemSource, $itemType, $user)); + + while ($row = $result->fetchRow()) { + $shares[] = $row; + } + + //if didn't found a result than let's look for a group share. + if(empty($shares)) { + $groups = \OC_Group::getUserGroups($user); + + $query = \OC_DB::prepare( + 'SELECT `file_target`, `permissions`, `expiration` + FROM + `*PREFIX*share` + WHERE + `item_source` = ? AND `item_type` = ? AND `share_with` in (?)' + ); + + $result = \OC_DB::executeAudited($query, array($itemSource, $itemType, implode(',', $groups))); + + while ($row = $result->fetchRow()) { + $shares[] = $row; + } + } + + return $shares; + + } + + /** * @brief Get the item of item type shared with the current user by source * @param string Item type * @param string Item source @@ -653,6 +702,29 @@ class Share { } return false; } + /** + * @brief sent status if users got informed by mail about share + * @param string $itemType + * @param string $itemSource + * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK + * @param bool $status + */ + public static function setSendMailStatus($itemType, $itemSource, $shareType, $status) { + $status = $status ? 1 : 0; + + $query = \OC_DB::prepare( + 'UPDATE `*PREFIX*share` + SET `mail_send` = ? + WHERE `item_type` = ? AND `item_source` = ? AND `share_type` = ?'); + + $result = $query->execute(array($status, $itemType, $itemSource, $shareType)); + + if($result === false) { + \OC_Log::write('OCP\Share', 'Couldn\'t set send mail status', \OC_Log::ERROR); + } + + + } /** * @brief Set the permissions of an item for a specific user or group @@ -983,19 +1055,19 @@ class Share { if ($format == self::FORMAT_STATUSES) { if ($itemType == 'file' || $itemType == 'folder') { $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`,' - .' `share_type`, `file_source`, `path`, `expiration`, `storage`'; + .' `share_type`, `file_source`, `path`, `expiration`, `storage`, `mail_send`'; } else { - $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `expiration`'; + $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `expiration`, `mail_send`'; } } else { if (isset($uidOwner)) { if ($itemType == 'file' || $itemType == 'folder') { $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`,' .' `share_type`, `share_with`, `file_source`, `path`, `permissions`, `stime`,' - .' `expiration`, `token`, `storage`'; + .' `expiration`, `token`, `storage`, `mail_send`'; } else { $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `share_with`, `permissions`,' - .' `stime`, `file_source`, `expiration`, `token`'; + .' `stime`, `file_source`, `expiration`, `token`, `mail_send`'; } } else { if ($fileDependent) { @@ -1006,11 +1078,11 @@ class Share { $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `uid_owner`, ' .'`share_type`, `share_with`, `file_source`, `path`, `file_target`, ' .'`permissions`, `expiration`, `storage`, `*PREFIX*filecache`.`parent` as `file_parent`, ' - .'`name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`, `etag`'; + .'`name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`, `etag`, `mail_send`'; } else { $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `item_target`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `uid_owner`, - `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`, `storage`'; + `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`, `storage`, `mail_send`'; } } else { $select = '*'; diff --git a/lib/public/template.php b/lib/public/template.php index 3b1a4ed4906..a5c500b0e25 100644 --- a/lib/public/template.php +++ b/lib/public/template.php @@ -90,8 +90,8 @@ function human_file_size( $bytes ) { * @param $timestamp unix timestamp * @returns human readable interpretation of the timestamp */ -function relative_modified_date($timestamp) { - return(\relative_modified_date($timestamp)); +function relative_modified_date($timestamp, $dateOnly = false) { + return(\relative_modified_date($timestamp, null, $dateOnly)); } |