summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2013-08-02 19:53:04 +0200
committerRobin Appelman <icewind@owncloud.com>2013-08-02 19:53:04 +0200
commit2af27434a4e4fdfa01cbd0714b63f9c360d4a9d1 (patch)
tree5899f2c2f69fe7e08b8c09af8a2b378757284c32 /lib
parentd7916363e1efbc15a5dba51056fb8af93330e5eb (diff)
parent43b31f2161775c7db62b46b8e4044f328f774aae (diff)
downloadnextcloud-server-2af27434a4e4fdfa01cbd0714b63f9c360d4a9d1.tar.gz
nextcloud-server-2af27434a4e4fdfa01cbd0714b63f9c360d4a9d1.zip
merge master into doctrine-object
Diffstat (limited to 'lib')
-rw-r--r--lib/app.php4
-rw-r--r--lib/base.php13
-rw-r--r--lib/config.php10
-rw-r--r--lib/connector/sabre/directory.php1
-rw-r--r--lib/connector/sabre/file.php7
-rw-r--r--lib/connector/sabre/objecttree.php102
-rw-r--r--lib/connector/sabre/principal.php2
-rw-r--r--lib/db.php8
-rw-r--r--lib/db/adapter.php14
-rw-r--r--lib/db/connection.php30
-rw-r--r--lib/db/mdb2schemareader.php196
-rw-r--r--lib/db/schema.php20
-rw-r--r--lib/defaults.php14
-rw-r--r--lib/files.php34
-rw-r--r--lib/files/cache/cache.php40
-rw-r--r--lib/files/cache/scanner.php13
-rw-r--r--lib/files/utils/scanner.php13
-rw-r--r--lib/group.php225
-rw-r--r--lib/group/group.php238
-rw-r--r--lib/group/manager.php169
-rw-r--r--lib/helper.php3
-rw-r--r--lib/image.php2
-rw-r--r--lib/l10n.php6
-rw-r--r--lib/l10n/ca.php4
-rw-r--r--lib/l10n/cs_CZ.php4
-rw-r--r--lib/l10n/da.php4
-rw-r--r--lib/l10n/de.php4
-rw-r--r--lib/l10n/de_DE.php4
-rw-r--r--lib/l10n/es.php4
-rw-r--r--lib/l10n/es_AR.php4
-rw-r--r--lib/l10n/et_EE.php4
-rw-r--r--lib/l10n/eu.php4
-rw-r--r--lib/l10n/gl.php4
-rw-r--r--lib/l10n/hu_HU.php4
-rw-r--r--lib/l10n/it.php4
-rw-r--r--lib/l10n/ko.php7
-rw-r--r--lib/l10n/nl.php4
-rw-r--r--lib/l10n/pl.php4
-rw-r--r--lib/l10n/pt_BR.php4
-rw-r--r--lib/l10n/pt_PT.php4
-rw-r--r--lib/l10n/ru.php4
-rw-r--r--lib/l10n/sv.php4
-rw-r--r--lib/legacy/config.php4
-rw-r--r--lib/memcache/apcu.php28
-rw-r--r--lib/memcache/factory.php4
-rw-r--r--lib/public/files.php2
-rw-r--r--lib/public/image.php2
-rw-r--r--lib/public/share.php25
-rw-r--r--lib/public/util.php2
-rw-r--r--lib/setup.php4
-rw-r--r--lib/template.php356
-rw-r--r--lib/template/base.php134
-rw-r--r--lib/template/cssresourcelocator.php43
-rw-r--r--lib/template/functions.php120
-rw-r--r--lib/template/jsresourcelocator.php43
-rw-r--r--lib/template/resourcelocator.php70
-rw-r--r--lib/template/templatefilelocator.php44
-rw-r--r--lib/templatelayout.php114
-rw-r--r--lib/user.php4
-rw-r--r--lib/user/manager.php3
-rw-r--r--lib/user/user.php2
-rwxr-xr-xlib/util.php11
62 files changed, 1559 insertions, 699 deletions
diff --git a/lib/app.php b/lib/app.php
index baacf508d8e..2437896157a 100644
--- a/lib/app.php
+++ b/lib/app.php
@@ -839,9 +839,9 @@ class OC_App{
OC_Hook::emit('update', 'success', 'Updated '.$info['name'].' app');
}
catch (Exception $e) {
- echo 'Failed to upgrade "'.$app.'". Exception="'.$e->getMessage().'"';
OC_Hook::emit('update', 'failure', 'Failed to update '.$info['name'].' app: '.$e->getMessage());
- die;
+ $l = OC_L10N::get('lib');
+ throw new RuntimeException($l->t('Failed to upgrade "%s".', array($app)), 0, $e);
}
OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app));
}
diff --git a/lib/base.php b/lib/base.php
index 1ff462819db..eaee8424651 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -173,7 +173,7 @@ class OC {
and !is_writable(OC::$SERVERROOT . "/config/config.php")) {
$defaults = new OC_Defaults();
OC_Template::printErrorPage(
- "Can't write into config directory 'config'",
+ "Can't write into config directory!",
'This can usually be fixed by '
.'<a href="' . $defaults->getDocBaseUrl() . '/server/5.0/admin_manual/installation/installation_source.html#set-the-directory-permissions" target="_blank">giving the webserver write access to the config directory</a>.'
);
@@ -422,9 +422,13 @@ class OC {
}
}
- if (!defined('PHPUNIT_RUN') and !(defined('DEBUG') and DEBUG)) {
- OC\Log\ErrorHandler::register();
- OC\Log\ErrorHandler::setLogger(OC_Log::$object);
+ if (!defined('PHPUNIT_RUN')) {
+ if (defined('DEBUG') and DEBUG) {
+ set_exception_handler(array('OC_Template', 'printExceptionErrorPage'));
+ } else {
+ OC\Log\ErrorHandler::register();
+ OC\Log\ErrorHandler::setLogger(OC_Log::$object);
+ }
}
// register the stream wrappers
@@ -822,3 +826,4 @@ if (!function_exists('get_temp_dir')) {
}
OC::init();
+
diff --git a/lib/config.php b/lib/config.php
index a38ce19c74f..e773e6e2eb0 100644
--- a/lib/config.php
+++ b/lib/config.php
@@ -144,11 +144,8 @@ class Config {
continue;
}
unset($CONFIG);
- if((@include $file) === false)
- {
- throw new HintException("Can't read from config file '" . $file . "'. ".
- 'This is usually caused by the wrong file permission.');
- }
+ // ignore errors on include, this can happen when doing a fresh install
+ @include $file;
if (isset($CONFIG) && is_array($CONFIG)) {
$this->cache = array_merge($this->cache, $CONFIG);
}
@@ -177,7 +174,7 @@ class Config {
if (!$result) {
$url = $defaults->getDocBaseUrl() . '/server/5.0/admin_manual/installation/installation_source.html#set-the-directory-permissions';
throw new HintException(
- "Can't write into config directory 'config'",
+ "Can't write into config directory!",
'This can usually be fixed by '
.'<a href="' . $url . '" target="_blank">giving the webserver write access to the config directory</a>.');
}
@@ -186,3 +183,4 @@ class Config {
\OC_Util::clearOpcodeCache();
}
}
+
diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php
index 3d15a2a584d..ed8d085462d 100644
--- a/lib/connector/sabre/directory.php
+++ b/lib/connector/sabre/directory.php
@@ -222,7 +222,6 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
throw new \Sabre_DAV_Exception_Forbidden();
}
if ($this->path != "/Shared") {
- foreach($this->getChildren() as $child) $child->delete();
\OC\Files\Filesystem::rmdir($this->path);
}
diff --git a/lib/connector/sabre/file.php b/lib/connector/sabre/file.php
index 438d9871c22..06ab73e3e4d 100644
--- a/lib/connector/sabre/file.php
+++ b/lib/connector/sabre/file.php
@@ -115,8 +115,11 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
*/
public function getSize() {
$this->getFileinfoCache();
- return $this->fileinfo_cache['size'];
-
+ if ($this->fileinfo_cache['size'] > -1) {
+ return $this->fileinfo_cache['size'];
+ } else {
+ return null;
+ }
}
/**
diff --git a/lib/connector/sabre/objecttree.php b/lib/connector/sabre/objecttree.php
new file mode 100644
index 00000000000..c4ddcbecbb8
--- /dev/null
+++ b/lib/connector/sabre/objecttree.php
@@ -0,0 +1,102 @@
+<?php
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Connector\Sabre;
+
+use OC\Files\Filesystem;
+
+class ObjectTree extends \Sabre_DAV_ObjectTree {
+ /**
+ * Returns the INode object for the requested path
+ *
+ * @param string $path
+ * @throws \Sabre_DAV_Exception_NotFound
+ * @return \Sabre_DAV_INode
+ */
+ public function getNodeForPath($path) {
+
+ $path = trim($path, '/');
+ if (isset($this->cache[$path])) return $this->cache[$path];
+
+ // Is it the root node?
+ if (!strlen($path)) {
+ return $this->rootNode;
+ }
+
+ $info = Filesystem::getFileInfo($path);
+
+ if (!$info) {
+ throw new \Sabre_DAV_Exception_NotFound('File with name ' . $path . ' could not be located');
+ }
+
+ if ($info['mimetype'] === 'httpd/unix-directory') {
+ $node = new \OC_Connector_Sabre_Directory($path);
+ } else {
+ $node = new \OC_Connector_Sabre_File($path);
+ }
+
+ $node->setFileinfoCache($info);
+
+ $this->cache[$path] = $node;
+ return $node;
+
+ }
+
+ /**
+ * Moves a file from one location to another
+ *
+ * @param string $sourcePath The path to the file which should be moved
+ * @param string $destinationPath The full destination path, so not just the destination parent node
+ * @throws \Sabre_DAV_Exception_Forbidden
+ * @return int
+ */
+ public function move($sourcePath, $destinationPath) {
+
+ $sourceNode = $this->getNodeForPath($sourcePath);
+ if ($sourceNode instanceof \Sabre_DAV_ICollection and $this->nodeExists($destinationPath)) {
+ throw new \Sabre_DAV_Exception_Forbidden('Could not copy directory ' . $sourceNode . ', target exists');
+ }
+ list($sourceDir,) = \Sabre_DAV_URLUtil::splitPath($sourcePath);
+ list($destinationDir,) = \Sabre_DAV_URLUtil::splitPath($destinationPath);
+
+ Filesystem::rename($sourcePath, $destinationPath);
+
+ $this->markDirty($sourceDir);
+ $this->markDirty($destinationDir);
+
+ }
+
+ /**
+ * Copies a file or directory.
+ *
+ * This method must work recursively and delete the destination
+ * if it exists
+ *
+ * @param string $source
+ * @param string $destination
+ * @return void
+ */
+ public function copy($source, $destination) {
+
+ if (Filesystem::is_file($source)) {
+ Filesystem::copy($source, $destination);
+ } else {
+ Filesystem::mkdir($destination);
+ $dh = Filesystem::opendir($source);
+ while ($subnode = readdir($dh)) {
+
+ if ($subnode == '.' || $subnode == '..') continue;
+ $this->copy($source . '/' . $subnode, $destination . '/' . $subnode);
+
+ }
+ }
+
+ list($destinationDir,) = \Sabre_DAV_URLUtil::splitPath($destination);
+ $this->markDirty($destinationDir);
+ }
+}
diff --git a/lib/connector/sabre/principal.php b/lib/connector/sabre/principal.php
index 04be410ac85..16c88b96ea6 100644
--- a/lib/connector/sabre/principal.php
+++ b/lib/connector/sabre/principal.php
@@ -121,6 +121,6 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend {
}
function searchPrincipals($prefixPath, array $searchProperties) {
- return 0;
+ return array();
}
}
diff --git a/lib/db.php b/lib/db.php
index 102782ac6ba..fec4eaaf93f 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -42,10 +42,7 @@ class DatabaseException extends Exception {
*/
class OC_DB {
/**
- * @var \Doctrine\DBAL\Connection
- */
- /**
- * @var \Doctrine\DBAL\Connection
+ * @var \OC\DB\Connection $connection
*/
static private $connection; //the prefered connection to use, only Doctrine
@@ -164,6 +161,9 @@ class OC_DB {
return true;
}
+ /**
+ * @return \OC\DB\Connection
+ */
static public function getConnection() {
self::connect();
return self::$connection;
diff --git a/lib/db/adapter.php b/lib/db/adapter.php
index 2e4f230f366..6b31f37dd98 100644
--- a/lib/db/adapter.php
+++ b/lib/db/adapter.php
@@ -13,6 +13,10 @@ namespace OC\DB;
* handled by the database abstraction layer.
*/
class Adapter {
+
+ /**
+ * @var \OC\DB\Connection $conn
+ */
protected $conn;
public function __construct($conn) {
@@ -28,7 +32,7 @@ class Adapter {
}
/**
- * @param $statement that needs to be changed so the db can handle it
+ * @param string $statement that needs to be changed so the db can handle it
* @return string changed statement
*/
public function fixupStatement($statement) {
@@ -38,8 +42,8 @@ class Adapter {
/**
* @brief insert the @input values when they do not exist yet
* @param string $table name
- * @param array key->value pairs
- * @return count of inserted rows
+ * @param array $input key->value pairs
+ * @return int count of inserted rows
*/
public function insertIfNotExist($table, $input) {
$query = 'INSERT INTO `' .$table . '` (`'
@@ -56,7 +60,7 @@ class Adapter {
$inserts = array_merge($inserts, $inserts);
try {
- $result = $this->conn->executeUpdate($query, $inserts);
+ return $this->conn->executeUpdate($query, $inserts);
} catch(\Doctrine\DBAL\DBALException $e) {
$entry = 'DB Error: "'.$e->getMessage() . '"<br />';
$entry .= 'Offending command was: ' . $query.'<br />';
@@ -64,7 +68,5 @@ class Adapter {
error_log('DB error: ' . $entry);
\OC_Template::printErrorPage( $entry );
}
-
- return $result;
}
}
diff --git a/lib/db/connection.php b/lib/db/connection.php
index 1f01fae4f71..920fe144a8a 100644
--- a/lib/db/connection.php
+++ b/lib/db/connection.php
@@ -13,29 +13,40 @@ use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\Common\EventManager;
class Connection extends \Doctrine\DBAL\Connection {
+ /**
+ * @var string $table_prefix
+ */
protected $table_prefix;
+ /**
+ * @var \OC\DB\Adapter $adapter
+ */
protected $adapter;
+ /**
+ * @var \Doctrine\DBAL\Driver\Statement[] $preparedQueries
+ */
protected $preparedQueries = array();
+
protected $cachingQueryStatementEnabled = true;
/**
* Initializes a new instance of the Connection class.
*
* @param array $params The connection parameters.
- * @param Driver $driver
- * @param Configuration $config
- * @param EventManager $eventManager
+ * @param \Doctrine\DBAL\Driver $driver
+ * @param \Doctrine\DBAL\Configuration $config
+ * @param \Doctrine\Common\EventManager $eventManager
+ * @throws \Exception
*/
public function __construct(array $params, Driver $driver, Configuration $config = null,
EventManager $eventManager = null)
{
if (!isset($params['adapter'])) {
- throw new Exception('adapter not set');
+ throw new \Exception('adapter not set');
}
if (!isset($params['table_prefix'])) {
- throw new Exception('table_prefix not set');
+ throw new \Exception('table_prefix not set');
}
parent::__construct($params, $driver, $config, $eventManager);
$this->adapter = new $params['adapter']($this);
@@ -46,6 +57,8 @@ class Connection extends \Doctrine\DBAL\Connection {
* Prepares an SQL statement.
*
* @param string $statement The SQL statement to prepare.
+ * @param int $limit
+ * @param int $offset
* @return \Doctrine\DBAL\Driver\Statement The prepared statement.
*/
public function prepare( $statement, $limit=null, $offset=null ) {
@@ -142,7 +155,7 @@ class Connection extends \Doctrine\DBAL\Connection {
* @brief Insert a row if a matching row doesn't exists.
* @param string $table. The table to insert into in the form '*PREFIX*tableName'
* @param array $input. An array of fieldname/value pairs
- * @returns bool The return value from execute()
+ * @return bool The return value from execute()
*/
public function insertIfNotExist($table, $input) {
return $this->adapter->insertIfNotExist($table, $input);
@@ -151,7 +164,6 @@ class Connection extends \Doctrine\DBAL\Connection {
/**
* returns the error code and message as a string for logging
* works with DoctrineException
- * @param mixed $error
* @return string
*/
public function getError() {
@@ -166,6 +178,10 @@ class Connection extends \Doctrine\DBAL\Connection {
}
// internal use
+ /**
+ * @param string $statement
+ * @return string
+ */
protected function replaceTablePrefix($statement) {
return str_replace( '*PREFIX*', $this->table_prefix, $statement );
}
diff --git a/lib/db/mdb2schemareader.php b/lib/db/mdb2schemareader.php
index 0ead9528c93..b7128a2f176 100644
--- a/lib/db/mdb2schemareader.php
+++ b/lib/db/mdb2schemareader.php
@@ -6,35 +6,57 @@
* See the COPYING-README file.
*/
-class OC_DB_MDB2SchemaReader {
- static protected $DBNAME;
- static protected $DBTABLEPREFIX;
- static protected $platform;
+namespace OC\DB;
+class MDB2SchemaReader {
/**
- * @param $file
- * @param $platform
+ * @var string $DBNAME
+ */
+ protected $DBNAME;
+
+ /**
+ * @var string $DBTABLEPREFIX
+ */
+ protected $DBTABLEPREFIX;
+
+ /**
+ * @var \Doctrine\DBAL\Platforms\AbstractPlatform $platform
+ */
+ protected $platform;
+
+ /**
+ * @param \OC\Config $config
+ * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
+ */
+ public function __construct($config, $platform) {
+ $this->platform = $platform;
+ $this->DBNAME = $config->getValue('dbname', 'owncloud');
+ $this->DBTABLEPREFIX = $config->getValue('dbtableprefix', 'oc_');
+ }
+
+ /**
+ * @param string $file
* @return \Doctrine\DBAL\Schema\Schema
- * @throws DomainException
+ * @throws \DomainException
*/
- public static function loadSchemaFromFile($file, $platform) {
- self::$DBNAME = OC_Config::getValue( "dbname", "owncloud" );
- self::$DBTABLEPREFIX = OC_Config::getValue( "dbtableprefix", "oc_" );
- self::$platform = $platform;
+ public function loadSchemaFromFile($file) {
$schema = new \Doctrine\DBAL\Schema\Schema();
$xml = simplexml_load_file($file);
- foreach($xml->children() as $child) {
- switch($child->getName()) {
+ foreach ($xml->children() as $child) {
+ /**
+ * @var \SimpleXMLElement $child
+ */
+ switch ($child->getName()) {
case 'name':
case 'create':
case 'overwrite':
case 'charset':
break;
case 'table':
- self::loadTable($schema, $child);
+ $this->loadTable($schema, $child);
break;
default:
- throw new DomainException('Unknown element: '.$child->getName());
+ throw new \DomainException('Unknown element: ' . $child->getName());
}
}
@@ -43,16 +65,20 @@ class OC_DB_MDB2SchemaReader {
/**
* @param\Doctrine\DBAL\Schema\Schema $schema
- * @param $xml
- * @throws DomainException
+ * @param \SimpleXMLElement $xml
+ * @throws \DomainException
*/
- private static function loadTable($schema, $xml) {
- foreach($xml->children() as $child) {
- switch($child->getName()) {
+ private function loadTable($schema, $xml) {
+ $table = null;
+ foreach ($xml->children() as $child) {
+ /**
+ * @var \SimpleXMLElement $child
+ */
+ switch ($child->getName()) {
case 'name':
$name = (string)$child;
- $name = str_replace( '*dbprefix*', self::$DBTABLEPREFIX, $name );
- $name = self::$platform->quoteIdentifier($name);
+ $name = str_replace('*dbprefix*', $this->DBTABLEPREFIX, $name);
+ $name = $this->platform->quoteIdentifier($name);
$table = $schema->createTable($name);
break;
case 'create':
@@ -60,10 +86,13 @@ class OC_DB_MDB2SchemaReader {
case 'charset':
break;
case 'declaration':
- self::loadDeclaration($table, $child);
+ if (is_null($table)) {
+ throw new \DomainException('Table declaration before table name');
+ }
+ $this->loadDeclaration($table, $child);
break;
default:
- throw new DomainException('Unknown element: '.$child->getName());
+ throw new \DomainException('Unknown element: ' . $child->getName());
}
}
@@ -71,36 +100,47 @@ class OC_DB_MDB2SchemaReader {
/**
* @param \Doctrine\DBAL\Schema\Table $table
- * @param $xml
- * @throws DomainException
+ * @param \SimpleXMLElement $xml
+ * @throws \DomainException
*/
- private static function loadDeclaration($table, $xml) {
- foreach($xml->children() as $child) {
- switch($child->getName()) {
+ private function loadDeclaration($table, $xml) {
+ foreach ($xml->children() as $child) {
+ /**
+ * @var \SimpleXMLElement $child
+ */
+ switch ($child->getName()) {
case 'field':
- self::loadField($table, $child);
+ $this->loadField($table, $child);
break;
case 'index':
- self::loadIndex($table, $child);
+ $this->loadIndex($table, $child);
break;
default:
- throw new DomainException('Unknown element: '.$child->getName());
+ throw new \DomainException('Unknown element: ' . $child->getName());
}
}
}
- private static function loadField($table, $xml) {
+ /**
+ * @param \Doctrine\DBAL\Schema\Table $table
+ * @param \SimpleXMLElement $xml
+ * @throws \DomainException
+ */
+ private function loadField($table, $xml) {
$options = array();
- foreach($xml->children() as $child) {
- switch($child->getName()) {
+ foreach ($xml->children() as $child) {
+ /**
+ * @var \SimpleXMLElement $child
+ */
+ switch ($child->getName()) {
case 'name':
$name = (string)$child;
- $name = self::$platform->quoteIdentifier($name);
+ $name = $this->platform->quoteIdentifier($name);
break;
case 'type':
$type = (string)$child;
- switch($type) {
+ switch ($type) {
case 'text':
$type = 'string';
break;
@@ -110,8 +150,6 @@ class OC_DB_MDB2SchemaReader {
case 'timestamp':
$type = 'datetime';
break;
- // TODO
- return;
}
break;
case 'length':
@@ -119,15 +157,15 @@ class OC_DB_MDB2SchemaReader {
$options['length'] = $length;
break;
case 'unsigned':
- $unsigned = self::asBool($child);
+ $unsigned = $this->asBool($child);
$options['unsigned'] = $unsigned;
break;
case 'notnull':
- $notnull = self::asBool($child);
+ $notnull = $this->asBool($child);
$options['notnull'] = $notnull;
break;
case 'autoincrement':
- $autoincrement = self::asBool($child);
+ $autoincrement = $this->asBool($child);
$options['autoincrement'] = $autoincrement;
break;
case 'default':
@@ -138,8 +176,12 @@ class OC_DB_MDB2SchemaReader {
$comment = (string)$child;
$options['comment'] = $comment;
break;
+ case 'primary':
+ $primary = $this->asBool($child);
+ $options['primary'] = $primary;
+ break;
default:
- throw new DomainException('Unknown element: '.$child->getName());
+ throw new \DomainException('Unknown element: ' . $child->getName());
}
}
@@ -153,22 +195,30 @@ class OC_DB_MDB2SchemaReader {
}
if ($type == 'integer') {
$options['default'] = 0;
+ } elseif ($type == 'boolean') {
+ $options['default'] = false;
}
if (!empty($options['autoincrement']) && $options['autoincrement']) {
unset($options['default']);
}
}
- if ($type == 'integer' && isset($options['length'])) {
+ if ($type === 'integer' && isset($options['default'])) {
+ $options['default'] = (int)$options['default'];
+ }
+ if ($type === 'integer' && isset($options['length'])) {
$length = $options['length'];
if ($length < 4) {
$type = 'smallint';
- }
- else if ($length > 4) {
+ } else if ($length > 4) {
$type = 'bigint';
}
}
+ if ($type === 'boolean' && isset($options['default'])) {
+ $options['default'] = $this->asBool($options['default']);
+ }
if (!empty($options['autoincrement'])
- && !empty($options['notnull'])) {
+ && !empty($options['notnull'])
+ ) {
$options['primary'] = true;
}
$table->addColumn($name, $type, $options);
@@ -178,38 +228,49 @@ class OC_DB_MDB2SchemaReader {
}
}
- private static function loadIndex($table, $xml) {
+ /**
+ * @param \Doctrine\DBAL\Schema\Table $table
+ * @param \SimpleXMLElement $xml
+ * @throws \DomainException
+ */
+ private function loadIndex($table, $xml) {
$name = null;
$fields = array();
- foreach($xml->children() as $child) {
- switch($child->getName()) {
+ foreach ($xml->children() as $child) {
+ /**
+ * @var \SimpleXMLElement $child
+ */
+ switch ($child->getName()) {
case 'name':
$name = (string)$child;
break;
case 'primary':
- $primary = self::asBool($child);
+ $primary = $this->asBool($child);
break;
case 'unique':
- $unique = self::asBool($child);
+ $unique = $this->asBool($child);
break;
case 'field':
- foreach($child->children() as $field) {
- switch($field->getName()) {
+ foreach ($child->children() as $field) {
+ /**
+ * @var \SimpleXMLElement $field
+ */
+ switch ($field->getName()) {
case 'name':
$field_name = (string)$field;
- $field_name = self::$platform->quoteIdentifier($field_name);
+ $field_name = $this->platform->quoteIdentifier($field_name);
$fields[] = $field_name;
break;
case 'sorting':
break;
default:
- throw new DomainException('Unknown element: '.$field->getName());
+ throw new \DomainException('Unknown element: ' . $field->getName());
}
}
break;
default:
- throw new DomainException('Unknown element: '.$child->getName());
+ throw new \DomainException('Unknown element: ' . $child->getName());
}
}
@@ -217,22 +278,25 @@ class OC_DB_MDB2SchemaReader {
if (isset($primary) && $primary) {
$table->setPrimaryKey($fields, $name);
} else
- if (isset($unique) && $unique) {
- $table->addUniqueIndex($fields, $name);
- } else {
- $table->addIndex($fields, $name);
- }
+ if (isset($unique) && $unique) {
+ $table->addUniqueIndex($fields, $name);
+ } else {
+ $table->addIndex($fields, $name);
+ }
} else {
- throw new DomainException('Empty index definition: '.$name.' options:'. print_r($fields, true));
+ throw new \DomainException('Empty index definition: ' . $name . ' options:' . print_r($fields, true));
}
}
- private static function asBool($xml) {
+ /**
+ * @param \SimpleXMLElement | string $xml
+ * @return bool
+ */
+ private function asBool($xml) {
$result = (string)$xml;
if ($result == 'true') {
$result = true;
- } else
- if ($result == 'false') {
+ } elseif ($result == 'false') {
$result = false;
}
return (bool)$result;
diff --git a/lib/db/schema.php b/lib/db/schema.php
index fa053c64ef0..bc82249609d 100644
--- a/lib/db/schema.php
+++ b/lib/db/schema.php
@@ -24,18 +24,21 @@ class OC_DB_Schema {
/**
* @brief Creates tables from XML file
+ * @param \Doctrine\DBAL\Connection $conn
* @param string $file file to read structure from
* @return bool
*
* TODO: write more documentation
*/
public static function createDbFromStructure( $conn, $file ) {
- $toSchema = OC_DB_MDB2SchemaReader::loadSchemaFromFile($file, $conn->getDatabasePlatform());
+ $schemaReader = new \OC\DB\MDB2SchemaReader(\OC_Config::getObject(), $conn->getDatabasePlatform());
+ $toSchema = $schemaReader->loadSchemaFromFile($file);
return self::executeSchemaChange($conn, $toSchema);
}
/**
* @brief update the database scheme
+ * @param \Doctrine\DBAL\Connection $conn
* @param string $file file to read structure from
* @return bool
*/
@@ -43,7 +46,8 @@ class OC_DB_Schema {
$sm = $conn->getSchemaManager();
$fromSchema = $sm->createSchema();
- $toSchema = OC_DB_MDB2SchemaReader::loadSchemaFromFile($file, $conn->getDatabasePlatform());
+ $schemaReader = new \OC\DB\MDB2SchemaReader(\OC_Config::getObject(), $conn->getDatabasePlatform());
+ $toSchema = $schemaReader->loadSchemaFromFile($file);
// remove tables we don't know about
foreach($fromSchema->getTables() as $table) {
@@ -79,6 +83,7 @@ class OC_DB_Schema {
/**
* @brief drop a table
+ * @param \Doctrine\DBAL\Connection $conn
* @param string $tableName the table to drop
*/
public static function dropTable($conn, $tableName) {
@@ -92,10 +97,12 @@ class OC_DB_Schema {
/**
* remove all tables defined in a database structure xml file
+ * @param \Doctrine\DBAL\Connection $conn
* @param string $file the xml file describing the tables
*/
public static function removeDBStructure($conn, $file) {
- $fromSchema = OC_DB_MDB2SchemaReader::loadSchemaFromFile($file, $conn->getDatabasePlatform());
+ $schemaReader = new \OC\DB\MDB2SchemaReader(\OC_Config::getObject(), $conn->getDatabasePlatform());
+ $fromSchema = $schemaReader->loadSchemaFromFile($file);
$toSchema = clone $fromSchema;
foreach($toSchema->getTables() as $table) {
$toSchema->dropTable($table->getName());
@@ -107,6 +114,7 @@ class OC_DB_Schema {
/**
* @brief replaces the ownCloud tables with a new set
+ * @param \Doctrine\DBAL\Connection $conn
* @param $file string path to the MDB2 xml db export file
*/
public static function replaceDB( $conn, $file ) {
@@ -126,11 +134,17 @@ class OC_DB_Schema {
self::commit();
}
+ /**
+ * @param \Doctrine\DBAL\Connection $conn
+ * @param \Doctrine\DBAL\Schema\Schema $schema
+ * @return bool
+ */
private static function executeSchemaChange($conn, $schema) {
$conn->beginTransaction();
foreach($schema->toSql($conn->getDatabasePlatform()) as $sql) {
$conn->query($sql);
}
$conn->commit();
+ return true;
}
}
diff --git a/lib/defaults.php b/lib/defaults.php
index 196bb5cf14d..10813a3e8d8 100644
--- a/lib/defaults.php
+++ b/lib/defaults.php
@@ -16,6 +16,7 @@ class OC_Defaults {
private $defaultEntity;
private $defaultName;
+ private $defaultTitle;
private $defaultBaseUrl;
private $defaultSyncClientUrl;
private $defaultDocBaseUrl;
@@ -25,8 +26,9 @@ class OC_Defaults {
function __construct() {
$l = OC_L10N::get('core');
- $this->defaultEntity = "ownCloud";
- $this->defaultName = "ownCloud";
+ $this->defaultEntity = "ownCloud"; /* e.g. company name, used for footers and copyright notices */
+ $this->defaultName = "ownCloud"; /* short name, used when referring to the software */
+ $this->defaultTitle = "ownCloud"; /* can be a longer name, for titles */
$this->defaultBaseUrl = "http://owncloud.org";
$this->defaultSyncClientUrl = " http://owncloud.org/sync-clients/";
$this->defaultDocBaseUrl = "http://doc.owncloud.org";
@@ -69,6 +71,14 @@ class OC_Defaults {
}
}
+ public function getTitle() {
+ if ($this->themeExist('getTitle')) {
+ return $this->theme->getTitle();
+ } else {
+ return $this->defaultTitle;
+ }
+ }
+
public function getName() {
if ($this->themeExist('getName')) {
return $this->theme->getName();
diff --git a/lib/files.php b/lib/files.php
index f5dffd970d2..c705d2adb1a 100644
--- a/lib/files.php
+++ b/lib/files.php
@@ -62,7 +62,8 @@ class OC_Files {
$zip = new ZipArchive();
$filename = OC_Helper::tmpFile('.zip');
if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==true) {
- exit("cannot open <$filename>\n");
+ $l = OC_L10N::get('lib');
+ throw new Exception($l->t('cannot open "%s"', array($filename)));
}
foreach ($files as $file) {
$file = $dir . '/' . $file;
@@ -93,7 +94,8 @@ class OC_Files {
$zip = new ZipArchive();
$filename = OC_Helper::tmpFile('.zip');
if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==true) {
- exit("cannot open <$filename>\n");
+ $l = OC_L10N::get('lib');
+ throw new Exception($l->t('cannot open "%s"', array($filename)));
}
$file = $dir . '/' . $files;
self::zipAddDir($file, $zip);
@@ -220,16 +222,11 @@ class OC_Files {
if (!OC_Config::getValue('allowZipDownload', true)) {
$l = OC_L10N::get('lib');
header("HTTP/1.0 409 Conflict");
- $tmpl = new OC_Template('', 'error', 'user');
- $errors = array(
- array(
- 'error' => $l->t('ZIP download is turned off.'),
- 'hint' => $l->t('Files need to be downloaded one by one.')
- . '<br/><a href="javascript:history.back()">' . $l->t('Back to Files') . '</a>',
- )
+ OC_Template::printErrorPage(
+ $l->t('ZIP download is turned off.'),
+ $l->t('Files need to be downloaded one by one.')
+ . '<br/><a href="javascript:history.back()">' . $l->t('Back to Files') . '</a>'
);
- $tmpl->assign('errors', $errors);
- $tmpl->printPage();
exit;
}
@@ -252,17 +249,12 @@ class OC_Files {
if ($totalsize > $zipLimit) {
$l = OC_L10N::get('lib');
header("HTTP/1.0 409 Conflict");
- $tmpl = new OC_Template('', 'error', 'user');
- $errors = array(
- array(
- 'error' => $l->t('Selected files too large to generate zip file.'),
- 'hint' => 'Download the files in smaller chunks, seperately'
- .' or kindly ask your administrator.<br/><a href="javascript:history.back()">'
- . $l->t('Back to Files') . '</a>',
- )
+ OC_Template::printErrorPage(
+ $l->t('Selected files too large to generate zip file.'),
+ $l->t('Download the files in smaller chunks, seperately or kindly ask your administrator.')
+ .'<br/><a href="javascript:history.back()">'
+ . $l->t('Back to Files') . '</a>'
);
- $tmpl->assign('errors', $errors);
- $tmpl->printPage();
exit;
}
}
diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php
index 3818fdbd840..39e36684b7b 100644
--- a/lib/files/cache/cache.php
+++ b/lib/files/cache/cache.php
@@ -200,7 +200,7 @@ class Cache {
$data['path'] = $file;
$data['parent'] = $this->getParentId($file);
- $data['name'] = basename($file);
+ $data['name'] = \OC_Util::basename($file);
$data['encrypted'] = isset($data['encrypted']) ? ((int)$data['encrypted']) : 0;
list($queryParts, $params) = $this->buildParts($data);
@@ -485,28 +485,28 @@ class Cache {
* @return int
*/
public function calculateFolderSize($path) {
- $id = $this->getId($path);
- if ($id === -1) {
- return 0;
- }
- $sql = 'SELECT `size` FROM `*PREFIX*filecache` WHERE `parent` = ? AND `storage` = ?';
- $result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
$totalSize = 0;
- $hasChilds = 0;
- while ($row = $result->fetchRow()) {
- $hasChilds = true;
- $size = (int)$row['size'];
- if ($size === -1) {
- $totalSize = -1;
- break;
- } else {
- $totalSize += $size;
+ $entry = $this->get($path);
+ if ($entry && $entry['mimetype'] === 'httpd/unix-directory') {
+ $id = $entry['fileid'];
+ $sql = 'SELECT SUM(`size`), MIN(`size`) FROM `*PREFIX*filecache` '.
+ 'WHERE `parent` = ? AND `storage` = ?';
+ $result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
+ if ($row = $result->fetchRow()) {
+ list($sum, $min) = array_values($row);
+ $sum = (int)$sum;
+ $min = (int)$min;
+ if ($min === -1) {
+ $totalSize = $min;
+ } else {
+ $totalSize = $sum;
+ }
+ if ($entry['size'] !== $totalSize) {
+ $this->update($id, array('size' => $totalSize));
+ }
+
}
}
-
- if ($hasChilds) {
- $this->update($id, array('size' => $totalSize));
- }
return $totalSize;
}
diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php
index bcd6032fcac..dd212d84cc5 100644
--- a/lib/files/cache/scanner.php
+++ b/lib/files/cache/scanner.php
@@ -75,9 +75,10 @@ class Scanner extends BasicEmitter {
*
* @param string $file
* @param int $reuseExisting
+ * @param bool $parentExistsInCache
* @return array with metadata of the scanned file
*/
- public function scanFile($file, $reuseExisting = 0) {
+ public function scanFile($file, $reuseExisting = 0, $parentExistsInCache = false) {
if (!self::isPartialFile($file)
and !Filesystem::isFileBlacklisted($file)
) {
@@ -85,7 +86,7 @@ class Scanner extends BasicEmitter {
\OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_file', array('path' => $file, 'storage' => $this->storageId));
$data = $this->getData($file);
if ($data) {
- if ($file) {
+ if ($file and !$parentExistsInCache) {
$parent = dirname($file);
if ($parent === '.' or $parent === '/') {
$parent = '';
@@ -108,9 +109,9 @@ class Scanner extends BasicEmitter {
// Only update metadata that has changed
$newData = array_diff($data, $cacheData);
}
- }
- if (!empty($newData)) {
- $this->cache->put($file, $newData);
+ if (!empty($newData)) {
+ $this->cache->put($file, $newData);
+ }
}
return $data;
}
@@ -162,7 +163,7 @@ class Scanner extends BasicEmitter {
$child = ($path) ? $path . '/' . $file : $file;
if (!Filesystem::isIgnoredDir($file)) {
$newChildren[] = $file;
- $data = $this->scanFile($child, $reuse);
+ $data = $this->scanFile($child, $reuse, true);
if ($data) {
if ($data['size'] === -1) {
if ($recursive === self::SCAN_RECURSIVE) {
diff --git a/lib/files/utils/scanner.php b/lib/files/utils/scanner.php
index 800bb649934..f0dc41ffad3 100644
--- a/lib/files/utils/scanner.php
+++ b/lib/files/utils/scanner.php
@@ -8,8 +8,8 @@
namespace OC\Files\Utils;
-use OC\Hooks\BasicEmitter;
use OC\Files\Filesystem;
+use OC\Hooks\PublicEmitter;
/**
* Class Scanner
@@ -20,7 +20,7 @@ use OC\Files\Filesystem;
*
* @package OC\Files\Utils
*/
-class Scanner extends BasicEmitter {
+class Scanner extends PublicEmitter {
/**
* @var string $user
*/
@@ -60,11 +60,12 @@ class Scanner extends BasicEmitter {
*/
protected function attachListener($mount) {
$scanner = $mount->getStorage()->getScanner();
- $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($mount) {
- $this->emit('\OC\Files\Utils\Scanner', 'scanFile', array($mount->getMountPoint() . $path));
+ $emitter = $this;
+ $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($mount, $emitter) {
+ $emitter->emit('\OC\Files\Utils\Scanner', 'scanFile', array($mount->getMountPoint() . $path));
});
- $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($mount) {
- $this->emit('\OC\Files\Utils\Scanner', 'scanFolder', array($mount->getMountPoint() . $path));
+ $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($mount, $emitter) {
+ $emitter->emit('\OC\Files\Utils\Scanner', 'scanFolder', array($mount->getMountPoint() . $path));
});
}
diff --git a/lib/group.php b/lib/group.php
index d1a830730b7..8fbf5f86418 100644
--- a/lib/group.php
+++ b/lib/group.php
@@ -34,28 +34,43 @@
* post_removeFromGroup(uid, gid)
*/
class OC_Group {
- // The backend used for group management
/**
- * @var OC_Group_Interface[]
+ * @var \OC\Group\Manager $manager
*/
- private static $_usedBackends = array();
+ private static $manager;
+
+ /**
+ * @var \OC\User\Manager
+ */
+ private static $userManager;
+
+ /**
+ * @return \OC\Group\Manager
+ */
+ public static function getManager() {
+ if (self::$manager) {
+ return self::$manager;
+ }
+ self::$userManager = \OC_User::getManager();
+ self::$manager = new \OC\Group\Manager(self::$userManager);
+ return self::$manager;
+ }
/**
* @brief set the group backend
- * @param string $backend The backend to use for user managment
+ * @param \OC_Group_Backend $backend The backend to use for user managment
* @return bool
*/
- public static function useBackend( $backend ) {
- if($backend instanceof OC_Group_Interface) {
- self::$_usedBackends[]=$backend;
- }
+ public static function useBackend($backend) {
+ self::getManager()->addBackend($backend);
+ return true;
}
/**
* remove all used backends
*/
public static function clearBackends() {
- self::$_usedBackends=array();
+ self::getManager()->clearBackends();
}
/**
@@ -66,32 +81,13 @@ class OC_Group {
* Tries to create a new group. If the group name already exists, false will
* be returned. Basic checking of Group name
*/
- public static function createGroup( $gid ) {
- // No empty group names!
- if( !$gid ) {
- return false;
- }
- // No duplicate group names
- if( in_array( $gid, self::getGroups())) {
- return false;
- }
-
- $run = true;
- OC_Hook::emit( "OC_Group", "pre_createGroup", array( "run" => &$run, "gid" => $gid ));
-
- if($run) {
- //create the group in the first backend that supports creating groups
- foreach(self::$_usedBackends as $backend) {
- if(!$backend->implementsActions(OC_GROUP_BACKEND_CREATE_GROUP))
- continue;
+ public static function createGroup($gid) {
+ OC_Hook::emit("OC_Group", "pre_createGroup", array("run" => true, "gid" => $gid));
- $backend->createGroup($gid);
- OC_Hook::emit( "OC_User", "post_createGroup", array( "gid" => $gid ));
-
- return true;
- }
- return false;
- }else{
+ if (self::getManager()->createGroup($gid)) {
+ OC_Hook::emit("OC_User", "post_createGroup", array("gid" => $gid));
+ return true;
+ } else {
return false;
}
}
@@ -103,30 +99,22 @@ class OC_Group {
*
* Deletes a group and removes it from the group_user-table
*/
- public static function deleteGroup( $gid ) {
+ public static function deleteGroup($gid) {
// Prevent users from deleting group admin
- if( $gid == "admin" ) {
+ if ($gid == "admin") {
return false;
}
- $run = true;
- OC_Hook::emit( "OC_Group", "pre_deleteGroup", array( "run" => &$run, "gid" => $gid ));
-
- if($run) {
- //delete the group from all backends
- foreach(self::$_usedBackends as $backend) {
- if(!$backend->implementsActions(OC_GROUP_BACKEND_DELETE_GROUP))
- continue;
-
- $backend->deleteGroup($gid);
- OC_Hook::emit( "OC_User", "post_deleteGroup", array( "gid" => $gid ));
+ OC_Hook::emit("OC_Group", "pre_deleteGroup", array("run" => true, "gid" => $gid));
+ $group = self::getManager()->get($gid);
+ if ($group) {
+ if ($group->delete()) {
+ OC_Hook::emit("OC_User", "post_deleteGroup", array("gid" => $gid));
return true;
}
- return false;
- }else{
- return false;
}
+ return false;
}
/**
@@ -137,11 +125,11 @@ class OC_Group {
*
* Checks whether the user is member of a group or not.
*/
- public static function inGroup( $uid, $gid ) {
- foreach(self::$_usedBackends as $backend) {
- if($backend->inGroup($uid, $gid)) {
- return true;
- }
+ public static function inGroup($uid, $gid) {
+ $group = self::getManager()->get($gid);
+ $user = self::$userManager->get($uid);
+ if ($group and $user) {
+ return $group->inGroup($user);
}
return false;
}
@@ -154,33 +142,15 @@ class OC_Group {
*
* Adds a user to a group.
*/
- public static function addToGroup( $uid, $gid ) {
- // Does the group exist?
- if( !OC_Group::groupExists($gid)) {
- return false;
- }
-
- // Go go go
- $run = true;
- OC_Hook::emit( "OC_Group", "pre_addToGroup", array( "run" => &$run, "uid" => $uid, "gid" => $gid ));
-
- if($run) {
- $success=false;
-
- //add the user to the all backends that have the group
- foreach(self::$_usedBackends as $backend) {
- if(!$backend->implementsActions(OC_GROUP_BACKEND_ADD_TO_GROUP))
- continue;
-
- if($backend->groupExists($gid)) {
- $success|=$backend->addToGroup($uid, $gid);
- }
- }
- if($success) {
- OC_Hook::emit( "OC_User", "post_addToGroup", array( "uid" => $uid, "gid" => $gid ));
- }
- return $success;
- }else{
+ public static function addToGroup($uid, $gid) {
+ $group = self::getManager()->get($gid);
+ $user = self::$userManager->get($uid);
+ if ($group and $user) {
+ OC_Hook::emit("OC_Group", "pre_addToGroup", array("run" => true, "uid" => $uid, "gid" => $gid));
+ $group->addUser($user);
+ OC_Hook::emit("OC_User", "post_addToGroup", array("uid" => $uid, "gid" => $gid));
+ return true;
+ } else {
return false;
}
}
@@ -193,21 +163,15 @@ class OC_Group {
*
* removes the user from a group.
*/
- public static function removeFromGroup( $uid, $gid ) {
- $run = true;
- OC_Hook::emit( "OC_Group", "pre_removeFromGroup", array( "run" => &$run, "uid" => $uid, "gid" => $gid ));
-
- if($run) {
- //remove the user from the all backends that have the group
- foreach(self::$_usedBackends as $backend) {
- if(!$backend->implementsActions(OC_GROUP_BACKEND_REMOVE_FROM_GOUP))
- continue;
-
- $backend->removeFromGroup($uid, $gid);
- OC_Hook::emit( "OC_User", "post_removeFromGroup", array( "uid" => $uid, "gid" => $gid ));
- }
+ public static function removeFromGroup($uid, $gid) {
+ $group = self::getManager()->get($gid);
+ $user = self::$userManager->get($uid);
+ if ($group and $user) {
+ OC_Hook::emit("OC_Group", "pre_removeFromGroup", array("run" => true, "uid" => $uid, "gid" => $gid));
+ $group->removeUser($user);
+ OC_Hook::emit("OC_User", "post_removeFromGroup", array("uid" => $uid, "gid" => $gid));
return true;
- }else{
+ } else {
return false;
}
}
@@ -220,13 +184,18 @@ class OC_Group {
* This function fetches all groups a user belongs to. It does not check
* if the user exists at all.
*/
- public static function getUserGroups( $uid ) {
- $groups=array();
- foreach(self::$_usedBackends as $backend) {
- $groups=array_merge($backend->getUserGroups($uid), $groups);
+ public static function getUserGroups($uid) {
+ $user = self::$userManager->get($uid);
+ if ($user) {
+ $groups = self::getManager()->getUserGroups($user);
+ $groupIds = array();
+ foreach ($groups as $group) {
+ $groupIds[] = $group->getGID();
+ }
+ return $groupIds;
+ } else {
+ return array();
}
- asort($groups);
- return $groups;
}
/**
@@ -235,27 +204,23 @@ class OC_Group {
*
* Returns a list with all groups
*/
- public static function getGroups($search = '', $limit = -1, $offset = 0) {
- $groups = array();
- foreach (self::$_usedBackends as $backend) {
- $groups = array_merge($backend->getGroups($search, $limit, $offset), $groups);
+ public static function getGroups($search = '', $limit = null, $offset = null) {
+ $groups = self::getManager()->search($search, $limit, $offset);
+ $groupIds = array();
+ foreach ($groups as $group) {
+ $groupIds[] = $group->getGID();
}
- asort($groups);
- return $groups;
+ return $groupIds;
}
/**
* check if a group exists
+ *
* @param string $gid
* @return bool
*/
public static function groupExists($gid) {
- foreach(self::$_usedBackends as $backend) {
- if ($backend->groupExists($gid)) {
- return true;
- }
- }
- return false;
+ return self::getManager()->groupExists($gid);
}
/**
@@ -263,11 +228,17 @@ class OC_Group {
* @returns array with user ids
*/
public static function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
- $users=array();
- foreach(self::$_usedBackends as $backend) {
- $users = array_merge($backend->usersInGroup($gid, $search, $limit, $offset), $users);
+ $group = self::getManager()->get($gid);
+ if ($group) {
+ $users = $group->searchUsers($search . $limit, $offset);
+ $userIds = array();
+ foreach ($users as $user) {
+ $userIds[] = $user->getUID();
+ }
+ return $userIds;
+ } else {
+ return array();
}
- return $users;
}
/**
@@ -292,17 +263,17 @@ class OC_Group {
* @returns array with display names (value) and user ids(key)
*/
public static function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
- $displayNames=array();
- foreach(self::$_usedBackends as $backend) {
- if($backend->implementsActions(OC_GROUP_BACKEND_GET_DISPLAYNAME)) {
- $displayNames = array_merge($backend->displayNamesInGroup($gid, $search, $limit, $offset), $displayNames);
- } else {
- $users = $backend->usersInGroup($gid, $search, $limit, $offset);
- $names = array_combine($users, $users);
- $displayNames = array_merge($names, $displayNames);
+ $group = self::getManager()->get($gid);
+ if ($group) {
+ $users = $group->searchDisplayName($search . $limit, $offset);
+ $displayNames = array();
+ foreach ($users as $user) {
+ $displayNames[] = $user->getDisplayName();
}
+ return $displayNames;
+ } else {
+ return array();
}
- return $displayNames;
}
/**
diff --git a/lib/group/group.php b/lib/group/group.php
new file mode 100644
index 00000000000..a752c4311c1
--- /dev/null
+++ b/lib/group/group.php
@@ -0,0 +1,238 @@
+<?php
+
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Group;
+
+class Group {
+ /**
+ * @var string $id
+ */
+ private $gid;
+
+ /**
+ * @var \OC\User\User[] $users
+ */
+ private $users;
+
+ /**
+ * @var \OC_Group_Backend[] | \OC_Group_Database[] $backend
+ */
+ private $backends;
+
+ /**
+ * @var \OC\Hooks\PublicEmitter $emitter;
+ */
+ private $emitter;
+
+ /**
+ * @var \OC\User\Manager $userManager
+ */
+ private $userManager;
+
+ /**
+ * @param string $gid
+ * @param \OC_Group_Backend[] $backends
+ * @param \OC\User\Manager $userManager
+ * @param \OC\Hooks\PublicEmitter $emitter
+ */
+ public function __construct($gid, $backends, $userManager, $emitter = null) {
+ $this->gid = $gid;
+ $this->backends = $backends;
+ $this->userManager = $userManager;
+ $this->emitter = $emitter;
+ }
+
+ public function getGID() {
+ return $this->gid;
+ }
+
+ /**
+ * get all users in the group
+ *
+ * @return \OC\User\User[]
+ */
+ public function getUsers() {
+ if ($this->users) {
+ return $this->users;
+ }
+
+ $users = array();
+ $userIds = array();
+ foreach ($this->backends as $backend) {
+ $diff = array_diff(
+ $backend->usersInGroup($this->gid),
+ $userIds
+ );
+ if ($diff) {
+ $userIds = array_merge($userIds, $diff);
+ }
+ }
+
+ foreach ($userIds as $userId) {
+ $users[] = $this->userManager->get($userId);
+ }
+ $this->users = $users;
+ return $users;
+ }
+
+ /**
+ * check if a user is in the group
+ *
+ * @param \OC\User\User $user
+ * @return bool
+ */
+ public function inGroup($user) {
+ foreach ($this->backends as $backend) {
+ if ($backend->inGroup($user->getUID(), $this->gid)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * add a user to the group
+ *
+ * @param \OC\User\User $user
+ */
+ public function addUser($user) {
+ if ($this->inGroup($user)) {
+ return;
+ }
+
+ if ($this->emitter) {
+ $this->emitter->emit('\OC\Group', 'preAddUser', array($this, $user));
+ }
+ foreach ($this->backends as $backend) {
+ if ($backend->implementsActions(OC_GROUP_BACKEND_ADD_TO_GROUP)) {
+ $backend->addToGroup($user->getUID(), $this->gid);
+ if ($this->users) {
+ $this->users[] = $user;
+ }
+ if ($this->emitter) {
+ $this->emitter->emit('\OC\Group', 'postAddUser', array($this, $user));
+ }
+ return;
+ }
+ }
+ }
+
+ /**
+ * remove a user from the group
+ *
+ * @param \OC\User\User $user
+ */
+ public function removeUser($user) {
+ $result = false;
+ if ($this->emitter) {
+ $this->emitter->emit('\OC\Group', 'preRemoveUser', array($this, $user));
+ }
+ foreach ($this->backends as $backend) {
+ if ($backend->implementsActions(OC_GROUP_BACKEND_REMOVE_FROM_GOUP) and $backend->inGroup($user->getUID(), $this->gid)) {
+ $backend->removeFromGroup($user->getUID(), $this->gid);
+ $result = true;
+ }
+ }
+ if ($result) {
+ if ($this->emitter) {
+ $this->emitter->emit('\OC\Group', 'postRemoveUser', array($this, $user));
+ }
+ if ($this->users) {
+ foreach ($this->users as $index => $groupUser) {
+ if ($groupUser->getUID() === $user->getUID()) {
+ unset($this->users[$index]);
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * search for users in the group by userid
+ *
+ * @param string $search
+ * @param int $limit
+ * @param int $offset
+ * @return \OC\User\User[]
+ */
+ public function searchUsers($search, $limit = null, $offset = null) {
+ $users = array();
+ foreach ($this->backends as $backend) {
+ $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset);
+ if (!is_null($limit)) {
+ $limit -= count($userIds);
+ }
+ if (!is_null($offset)) {
+ $offset -= count($userIds);
+ }
+ foreach ($userIds as $userId) {
+ $users[$userId] = $this->userManager->get($userId);
+ }
+ if (!is_null($limit) and $limit <= 0) {
+ return array_values($users);
+ }
+ }
+ return array_values($users);
+ }
+
+ /**
+ * search for users in the group by displayname
+ *
+ * @param string $search
+ * @param int $limit
+ * @param int $offset
+ * @return \OC\User\User[]
+ */
+ public function searchDisplayName($search, $limit = null, $offset = null) {
+ $users = array();
+ foreach ($this->backends as $backend) {
+ if ($backend->implementsActions(OC_GROUP_BACKEND_GET_DISPLAYNAME)) {
+ $userIds = array_keys($backend->displayNamesInGroup($this->gid, $search, $limit, $offset));
+ } else {
+ $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset);
+ }
+ if (!is_null($limit)) {
+ $limit -= count($userIds);
+ }
+ if (!is_null($offset)) {
+ $offset -= count($userIds);
+ }
+ foreach ($userIds as $userId) {
+ $users[$userId] = $this->userManager->get($userId);
+ }
+ if (!is_null($limit) and $limit <= 0) {
+ return array_values($users);
+ }
+ }
+ return array_values($users);
+ }
+
+ /**
+ * delete the group
+ *
+ * @return bool
+ */
+ public function delete() {
+ $result = false;
+ if ($this->emitter) {
+ $this->emitter->emit('\OC\Group', 'preDelete', array($this));
+ }
+ foreach ($this->backends as $backend) {
+ if ($backend->implementsActions(OC_GROUP_BACKEND_DELETE_GROUP)) {
+ $result = true;
+ $backend->deleteGroup($this->gid);
+ }
+ }
+ if ($result and $this->emitter) {
+ $this->emitter->emit('\OC\Group', 'postDelete', array($this));
+ }
+ return $result;
+ }
+}
diff --git a/lib/group/manager.php b/lib/group/manager.php
new file mode 100644
index 00000000000..bf469d51d12
--- /dev/null
+++ b/lib/group/manager.php
@@ -0,0 +1,169 @@
+<?php
+
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Group;
+
+use OC\Hooks\PublicEmitter;
+
+/**
+ * Class Manager
+ *
+ * Hooks available in scope \OC\Group:
+ * - preAddUser(\OC\Group\Group $group, \OC\User\User $user)
+ * - postAddUser(\OC\Group\Group $group, \OC\User\User $user)
+ * - preRemoveUser(\OC\Group\Group $group, \OC\User\User $user)
+ * - postRemoveUser(\OC\Group\Group $group, \OC\User\User $user)
+ * - preDelete(\OC\Group\Group $group)
+ * - postDelete(\OC\Group\Group $group)
+ * - preCreate(string $groupId)
+ * - postCreate(\OC\Group\Group $group)
+ *
+ * @package OC\Group
+ */
+class Manager extends PublicEmitter {
+ /**
+ * @var \OC_Group_Backend[] | \OC_Group_Database[] $backends
+ */
+ private $backends = array();
+
+ /**
+ * @var \OC\User\Manager $userManager
+ */
+ private $userManager;
+
+ /**
+ * @var \OC\Group\Group[]
+ */
+ private $cachedGroups;
+
+ /**
+ * @param \OC\User\Manager $userManager
+ */
+ public function __construct($userManager) {
+ $this->userManager = $userManager;
+ $cache = & $this->cachedGroups;
+ $this->listen('\OC\Group', 'postDelete', function ($group) use (&$cache) {
+ /**
+ * @var \OC\Group\Group $group
+ */
+ unset($cache[$group->getGID()]);
+ });
+ }
+
+ /**
+ * @param \OC_Group_Backend $backend
+ */
+ public function addBackend($backend) {
+ $this->backends[] = $backend;
+ }
+
+ public function clearBackends() {
+ $this->backends = array();
+ $this->cachedGroups = array();
+ }
+
+ /**
+ * @param string $gid
+ * @return \OC\Group\Group
+ */
+ public function get($gid) {
+ if (isset($this->cachedGroups[$gid])) {
+ return $this->cachedGroups[$gid];
+ }
+ foreach ($this->backends as $backend) {
+ if ($backend->groupExists($gid)) {
+ return $this->getGroupObject($gid);
+ }
+ }
+ return null;
+ }
+
+ protected function getGroupObject($gid) {
+ $backends = array();
+ foreach ($this->backends as $backend) {
+ if ($backend->groupExists($gid)) {
+ $backends[] = $backend;
+ }
+ }
+ $this->cachedGroups[$gid] = new Group($gid, $backends, $this->userManager, $this);
+ return $this->cachedGroups[$gid];
+ }
+
+ /**
+ * @param string $gid
+ * @return bool
+ */
+ public function groupExists($gid) {
+ return !is_null($this->get($gid));
+ }
+
+ /**
+ * @param string $gid
+ * @return \OC\Group\Group
+ */
+ public function createGroup($gid) {
+ if (!$gid) {
+ return false;
+ } else if ($this->groupExists($gid)) {
+ return $this->get($gid);
+ } else {
+ $this->emit('\OC\Group', 'preCreate', array($gid));
+ foreach ($this->backends as $backend) {
+ if ($backend->implementsActions(OC_GROUP_BACKEND_CREATE_GROUP)) {
+ $backend->createGroup($gid);
+ $group = $this->getGroupObject($gid);
+ $this->emit('\OC\Group', 'postCreate', array($group));
+ return $group;
+ }
+ }
+ return null;
+ }
+ }
+
+ /**
+ * @param string $search
+ * @param int $limit
+ * @param int $offset
+ * @return \OC\Group\Group[]
+ */
+ public function search($search, $limit = null, $offset = null) {
+ $groups = array();
+ foreach ($this->backends as $backend) {
+ $groupIds = $backend->getGroups($search, $limit, $offset);
+ if (!is_null($limit)) {
+ $limit -= count($groupIds);
+ }
+ if (!is_null($offset)) {
+ $offset -= count($groupIds);
+ }
+ foreach ($groupIds as $groupId) {
+ $groups[$groupId] = $this->getGroupObject($groupId);
+ }
+ if (!is_null($limit) and $limit <= 0) {
+ return array_values($groups);
+ }
+ }
+ return array_values($groups);
+ }
+
+ /**
+ * @param \OC\User\User $user
+ * @return \OC\Group\Group[]
+ */
+ public function getUserGroups($user) {
+ $groups = array();
+ foreach ($this->backends as $backend) {
+ $groupIds = $backend->getUserGroups($user->getUID());
+ foreach ($groupIds as $groupId) {
+ $groups[$groupId] = $this->getGroupObject($groupId);
+ }
+ }
+ return array_values($groups);
+ }
+}
diff --git a/lib/helper.php b/lib/helper.php
index df0d120976d..ca508e1d933 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -176,8 +176,7 @@ class OC_Helper {
}elseif( file_exists( OC::$SERVERROOT."/core/img/$image" )) {
return OC::$WEBROOT."/core/img/$image";
}else{
- echo('image not found: image:'.$image.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
- die();
+ throw new RuntimeException('image not found: image:'.$image.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
}
}
diff --git a/lib/image.php b/lib/image.php
index c1b187608a6..4bc38e20e56 100644
--- a/lib/image.php
+++ b/lib/image.php
@@ -392,7 +392,7 @@ class OC_Image {
*/
public function loadFromFile($imagepath=false) {
// exif_imagetype throws "read error!" if file is less than 12 byte
- if(!is_file($imagepath) || !file_exists($imagepath) || filesize($imagepath) < 12 || !is_readable($imagepath)) {
+ if(!@is_file($imagepath) || !file_exists($imagepath) || filesize($imagepath) < 12 || !is_readable($imagepath)) {
// Debug output disabled because this method is tried before loadFromBase64?
OC_Log::write('core', 'OC_Image->loadFromFile, couldn\'t load: '.$imagepath, OC_Log::DEBUG);
return false;
diff --git a/lib/l10n.php b/lib/l10n.php
index d35ce5fed14..a28aa89c5f1 100644
--- a/lib/l10n.php
+++ b/lib/l10n.php
@@ -298,6 +298,12 @@ class OC_L10N{
}
}
+ $default_language = OC_Config::getValue('default_language', false);
+
+ if($default_language !== false) {
+ return $default_language;
+ }
+
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$accepted_languages = preg_split('/,\s*/', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']));
if(is_array($app)) {
diff --git a/lib/l10n/ca.php b/lib/l10n/ca.php
index 93f7fa5f7bc..14f9edfe34c 100644
--- a/lib/l10n/ca.php
+++ b/lib/l10n/ca.php
@@ -5,11 +5,14 @@
"Users" => "Usuaris",
"Apps" => "Aplicacions",
"Admin" => "Administració",
+"Failed to upgrade \"%s\"." => "Ha fallat l'actualització \"%s\".",
"web services under your control" => "controleu els vostres serveis web",
+"cannot open \"%s\"" => "no es pot obrir \"%s\"",
"ZIP download is turned off." => "La baixada en ZIP està desactivada.",
"Files need to be downloaded one by one." => "Els fitxers s'han de baixar d'un en un.",
"Back to Files" => "Torna a Fitxers",
"Selected files too large to generate zip file." => "Els fitxers seleccionats son massa grans per generar un fitxer zip.",
+"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Baixeu els fitxers en trossos petits, de forma separada, o pregunteu a l'administrador.",
"couldn't be determined" => "no s'ha pogut determinar",
"Application is not enabled" => "L'aplicació no està habilitada",
"Authentication error" => "Error d'autenticació",
@@ -49,5 +52,6 @@
"%d months ago" => "fa %d mesos",
"last year" => "l'any passat",
"years ago" => "anys enrere",
+"Caused by:" => "Provocat per:",
"Could not find category \"%s\"" => "No s'ha trobat la categoria \"%s\""
);
diff --git a/lib/l10n/cs_CZ.php b/lib/l10n/cs_CZ.php
index 917f383bb89..7390c5f432a 100644
--- a/lib/l10n/cs_CZ.php
+++ b/lib/l10n/cs_CZ.php
@@ -5,11 +5,14 @@
"Users" => "Uživatelé",
"Apps" => "Aplikace",
"Admin" => "Administrace",
+"Failed to upgrade \"%s\"." => "Selhalo povýšení verze \"%s\".",
"web services under your control" => "služby webu pod Vaší kontrolou",
+"cannot open \"%s\"" => "nelze otevřít \"%s\"",
"ZIP download is turned off." => "Stahování ZIPu je vypnuto.",
"Files need to be downloaded one by one." => "Soubory musí být stahovány jednotlivě.",
"Back to Files" => "Zpět k souborům",
"Selected files too large to generate zip file." => "Vybrané soubory jsou příliš velké pro vytvoření zip souboru.",
+"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Stáhněte soubory po menších částech, samostatně, nebo se obraťte na správce.",
"couldn't be determined" => "nelze zjistit",
"Application is not enabled" => "Aplikace není povolena",
"Authentication error" => "Chyba ověření",
@@ -49,5 +52,6 @@
"%d months ago" => "Před %d měsíci",
"last year" => "minulý rok",
"years ago" => "před lety",
+"Caused by:" => "Příčina:",
"Could not find category \"%s\"" => "Nelze nalézt kategorii \"%s\""
);
diff --git a/lib/l10n/da.php b/lib/l10n/da.php
index 5f11453bcdd..789328a3100 100644
--- a/lib/l10n/da.php
+++ b/lib/l10n/da.php
@@ -5,11 +5,14 @@
"Users" => "Brugere",
"Apps" => "Apps",
"Admin" => "Admin",
+"Failed to upgrade \"%s\"." => "Upgradering af \"%s\" fejlede",
"web services under your control" => "Webtjenester under din kontrol",
+"cannot open \"%s\"" => "Kan ikke åbne \"%s\"",
"ZIP download is turned off." => "ZIP-download er slået fra.",
"Files need to be downloaded one by one." => "Filer skal downloades en for en.",
"Back to Files" => "Tilbage til Filer",
"Selected files too large to generate zip file." => "De markerede filer er for store til at generere en ZIP-fil.",
+"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Download filerne i små bider, seperat, eller kontakt venligst din administrator.",
"couldn't be determined" => "kunne ikke fastslås",
"Application is not enabled" => "Programmet er ikke aktiveret",
"Authentication error" => "Adgangsfejl",
@@ -49,5 +52,6 @@
"%d months ago" => "%d måneder siden",
"last year" => "sidste år",
"years ago" => "år siden",
+"Caused by:" => "Forårsaget af:",
"Could not find category \"%s\"" => "Kunne ikke finde kategorien \"%s\""
);
diff --git a/lib/l10n/de.php b/lib/l10n/de.php
index 4ef02402b9b..f1c4a1171e2 100644
--- a/lib/l10n/de.php
+++ b/lib/l10n/de.php
@@ -5,11 +5,14 @@
"Users" => "Benutzer",
"Apps" => "Apps",
"Admin" => "Administration",
+"Failed to upgrade \"%s\"." => "Konnte \"%s\" nicht aktualisieren.",
"web services under your control" => "Web-Services unter Deiner Kontrolle",
+"cannot open \"%s\"" => "Öffnen von \"%s\" fehlgeschlagen",
"ZIP download is turned off." => "Der ZIP-Download ist deaktiviert.",
"Files need to be downloaded one by one." => "Die Dateien müssen einzeln heruntergeladen werden.",
"Back to Files" => "Zurück zu \"Dateien\"",
"Selected files too large to generate zip file." => "Die gewählten Dateien sind zu groß, um eine ZIP-Datei zu erstellen.",
+"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Lade die Dateien in kleineren, separaten, Stücken herunter oder bitte deinen Administrator.",
"couldn't be determined" => "konnte nicht festgestellt werden",
"Application is not enabled" => "Die Anwendung ist nicht aktiviert",
"Authentication error" => "Fehler bei der Anmeldung",
@@ -49,5 +52,6 @@
"%d months ago" => "Vor %d Monaten",
"last year" => "Letztes Jahr",
"years ago" => "Vor Jahren",
+"Caused by:" => "Verursacht durch:",
"Could not find category \"%s\"" => "Die Kategorie \"%s\" konnte nicht gefunden werden."
);
diff --git a/lib/l10n/de_DE.php b/lib/l10n/de_DE.php
index 823d423abcd..276e526e2ed 100644
--- a/lib/l10n/de_DE.php
+++ b/lib/l10n/de_DE.php
@@ -5,11 +5,14 @@
"Users" => "Benutzer",
"Apps" => "Apps",
"Admin" => "Administrator",
+"Failed to upgrade \"%s\"." => "Konnte \"%s\" nicht aktualisieren.",
"web services under your control" => "Web-Services unter Ihrer Kontrolle",
+"cannot open \"%s\"" => "Öffnen von \"%s\" fehlgeschlagen",
"ZIP download is turned off." => "Der ZIP-Download ist deaktiviert.",
"Files need to be downloaded one by one." => "Die Dateien müssen einzeln heruntergeladen werden.",
"Back to Files" => "Zurück zu \"Dateien\"",
"Selected files too large to generate zip file." => "Die gewählten Dateien sind zu groß, um eine ZIP-Datei zu erstellen.",
+"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Laden Sie die Dateien in kleineren, separaten, Stücken herunter oder bitten Sie Ihren Administrator.",
"couldn't be determined" => "konnte nicht ermittelt werden",
"Application is not enabled" => "Die Anwendung ist nicht aktiviert",
"Authentication error" => "Authentifizierungs-Fehler",
@@ -49,5 +52,6 @@
"%d months ago" => "Vor %d Monaten",
"last year" => "Letztes Jahr",
"years ago" => "Vor Jahren",
+"Caused by:" => "Verursacht durch:",
"Could not find category \"%s\"" => "Die Kategorie \"%s\" konnte nicht gefunden werden."
);
diff --git a/lib/l10n/es.php b/lib/l10n/es.php
index 1f243a224e4..66011e61a0d 100644
--- a/lib/l10n/es.php
+++ b/lib/l10n/es.php
@@ -5,11 +5,14 @@
"Users" => "Usuarios",
"Apps" => "Aplicaciones",
"Admin" => "Administración",
+"Failed to upgrade \"%s\"." => "Falló la actualización \"%s\".",
"web services under your control" => "Servicios web bajo su control",
+"cannot open \"%s\"" => "No se puede abrir \"%s\"",
"ZIP download is turned off." => "La descarga en ZIP está desactivada.",
"Files need to be downloaded one by one." => "Los archivos deben ser descargados uno por uno.",
"Back to Files" => "Volver a Archivos",
"Selected files too large to generate zip file." => "Los archivos seleccionados son demasiado grandes para generar el archivo zip.",
+"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Descargue los archivos en trozos más pequeños, por separado o solicítelos amablemente su administrador.",
"couldn't be determined" => "no pudo ser determinado",
"Application is not enabled" => "La aplicación no está habilitada",
"Authentication error" => "Error de autenticación",
@@ -49,5 +52,6 @@
"%d months ago" => "Hace %d meses",
"last year" => "año pasado",
"years ago" => "hace años",
+"Caused by:" => "Causado por:",
"Could not find category \"%s\"" => "No puede encontrar la categoria \"%s\""
);
diff --git a/lib/l10n/es_AR.php b/lib/l10n/es_AR.php
index cd1a0fbb530..da0f6fae84a 100644
--- a/lib/l10n/es_AR.php
+++ b/lib/l10n/es_AR.php
@@ -5,11 +5,14 @@
"Users" => "Usuarios",
"Apps" => "Apps",
"Admin" => "Administración",
+"Failed to upgrade \"%s\"." => "No se pudo actualizar \"%s\".",
"web services under your control" => "servicios web sobre los que tenés control",
+"cannot open \"%s\"" => "no se puede abrir \"%s\"",
"ZIP download is turned off." => "La descarga en ZIP está desactivada.",
"Files need to be downloaded one by one." => "Los archivos deben ser descargados de a uno.",
"Back to Files" => "Volver a Archivos",
"Selected files too large to generate zip file." => "Los archivos seleccionados son demasiado grandes para generar el archivo zip.",
+"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Descargá los archivos en partes más chicas, de forma separada, o pedíselos al administrador",
"couldn't be determined" => "no se pudo determinar",
"Application is not enabled" => "La aplicación no está habilitada",
"Authentication error" => "Error al autenticar",
@@ -49,5 +52,6 @@
"%d months ago" => "hace %d meses",
"last year" => "el año pasado",
"years ago" => "años atrás",
+"Caused by:" => "Provocado por:",
"Could not find category \"%s\"" => "No fue posible encontrar la categoría \"%s\""
);
diff --git a/lib/l10n/et_EE.php b/lib/l10n/et_EE.php
index 4da2c36d6ac..c2cd8ff0389 100644
--- a/lib/l10n/et_EE.php
+++ b/lib/l10n/et_EE.php
@@ -5,11 +5,14 @@
"Users" => "Kasutajad",
"Apps" => "Rakendused",
"Admin" => "Admin",
+"Failed to upgrade \"%s\"." => "Ebaõnnestunud uuendus \"%s\".",
"web services under your control" => "veebitenused sinu kontrolli all",
+"cannot open \"%s\"" => "ei suuda avada \"%s\"",
"ZIP download is turned off." => "ZIP-ina allalaadimine on välja lülitatud.",
"Files need to be downloaded one by one." => "Failid tuleb alla laadida ükshaaval.",
"Back to Files" => "Tagasi failide juurde",
"Selected files too large to generate zip file." => "Valitud failid on ZIP-faili loomiseks liiga suured.",
+"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Laadi failid alla eraldi väiksemate osadena või küsi nõu oma süsteemiadminstraatorilt.",
"couldn't be determined" => "ei suudetud tuvastada",
"Application is not enabled" => "Rakendus pole sisse lülitatud",
"Authentication error" => "Autentimise viga",
@@ -49,5 +52,6 @@
"%d months ago" => "%d kuud tagasi",
"last year" => "viimasel aastal",
"years ago" => "aastat tagasi",
+"Caused by:" => "Põhjustaja:",
"Could not find category \"%s\"" => "Ei leia kategooriat \"%s\""
);
diff --git a/lib/l10n/eu.php b/lib/l10n/eu.php
index 131ac6d7daa..94b4cfb902e 100644
--- a/lib/l10n/eu.php
+++ b/lib/l10n/eu.php
@@ -5,11 +5,14 @@
"Users" => "Erabiltzaileak",
"Apps" => "Aplikazioak",
"Admin" => "Admin",
+"Failed to upgrade \"%s\"." => "Ezin izan da \"%s\" eguneratu.",
"web services under your control" => "web zerbitzuak zure kontrolpean",
+"cannot open \"%s\"" => "ezin da \"%s\" ireki",
"ZIP download is turned off." => "ZIP deskarga ez dago gaituta.",
"Files need to be downloaded one by one." => "Fitxategiak banan-banan deskargatu behar dira.",
"Back to Files" => "Itzuli fitxategietara",
"Selected files too large to generate zip file." => "Hautatuko fitxategiak oso handiak dira zip fitxategia sortzeko.",
+"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Deskargatu fitzategiak zati txikiagoetan, banan-banan edo eskatu mesedez zure administradoreari",
"couldn't be determined" => "ezin izan da zehaztu",
"Application is not enabled" => "Aplikazioa ez dago gaituta",
"Authentication error" => "Autentifikazio errorea",
@@ -49,5 +52,6 @@
"%d months ago" => "orain dela %d hilabete",
"last year" => "joan den urtean",
"years ago" => "urte",
+"Caused by:" => "Honek eraginda:",
"Could not find category \"%s\"" => "Ezin da \"%s\" kategoria aurkitu"
);
diff --git a/lib/l10n/gl.php b/lib/l10n/gl.php
index 351f18c7155..f5309d95081 100644
--- a/lib/l10n/gl.php
+++ b/lib/l10n/gl.php
@@ -5,11 +5,14 @@
"Users" => "Usuarios",
"Apps" => "Aplicativos",
"Admin" => "Administración",
+"Failed to upgrade \"%s\"." => "Non foi posíbel anovar «%s».",
"web services under your control" => "servizos web baixo o seu control",
+"cannot open \"%s\"" => "non foi posíbel abrir «%s»",
"ZIP download is turned off." => "As descargas ZIP están desactivadas.",
"Files need to be downloaded one by one." => "Os ficheiros necesitan seren descargados dun en un.",
"Back to Files" => "Volver aos ficheiros",
"Selected files too large to generate zip file." => "Os ficheiros seleccionados son demasiado grandes como para xerar un ficheiro zip.",
+"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Descargue os ficheiros en cachos máis pequenos e por separado, ou pídallos amabelmente ao seu administrador.",
"couldn't be determined" => "non foi posíbel determinalo",
"Application is not enabled" => "O aplicativo non está activado",
"Authentication error" => "Produciuse un erro de autenticación",
@@ -49,5 +52,6 @@
"%d months ago" => "Vai %d meses",
"last year" => "último ano",
"years ago" => "anos atrás",
+"Caused by:" => "Causado por:",
"Could not find category \"%s\"" => "Non foi posíbel atopar a categoría «%s»"
);
diff --git a/lib/l10n/hu_HU.php b/lib/l10n/hu_HU.php
index 3aa04274fa3..7738dcc05c8 100644
--- a/lib/l10n/hu_HU.php
+++ b/lib/l10n/hu_HU.php
@@ -5,11 +5,14 @@
"Users" => "Felhasználók",
"Apps" => "Alkalmazások",
"Admin" => "Adminsztráció",
+"Failed to upgrade \"%s\"." => "Sikertelen Frissítés \"%s\".",
"web services under your control" => "webszolgáltatások saját kézben",
+"cannot open \"%s\"" => "nem sikerült megnyitni \"%s\"",
"ZIP download is turned off." => "A ZIP-letöltés nincs engedélyezve.",
"Files need to be downloaded one by one." => "A fájlokat egyenként kell letölteni.",
"Back to Files" => "Vissza a Fájlokhoz",
"Selected files too large to generate zip file." => "A kiválasztott fájlok túl nagyok a zip tömörítéshez.",
+"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Tölts le a fileokat kisebb chunkokban, kölün vagy kérj segitséget a rendszergazdádtól.",
"couldn't be determined" => "nem határozható meg",
"Application is not enabled" => "Az alkalmazás nincs engedélyezve",
"Authentication error" => "Azonosítási hiba",
@@ -49,5 +52,6 @@
"%d months ago" => "%d hónapja",
"last year" => "tavaly",
"years ago" => "több éve",
+"Caused by:" => "Okozta:",
"Could not find category \"%s\"" => "Ez a kategória nem található: \"%s\""
);
diff --git a/lib/l10n/it.php b/lib/l10n/it.php
index 74483315ca0..693f86b6b80 100644
--- a/lib/l10n/it.php
+++ b/lib/l10n/it.php
@@ -5,11 +5,14 @@
"Users" => "Utenti",
"Apps" => "Applicazioni",
"Admin" => "Admin",
+"Failed to upgrade \"%s\"." => "Aggiornamento non riuscito \"%s\".",
"web services under your control" => "servizi web nelle tue mani",
+"cannot open \"%s\"" => "impossibile aprire \"%s\"",
"ZIP download is turned off." => "Lo scaricamento in formato ZIP è stato disabilitato.",
"Files need to be downloaded one by one." => "I file devono essere scaricati uno alla volta.",
"Back to Files" => "Torna ai file",
"Selected files too large to generate zip file." => "I file selezionati sono troppo grandi per generare un file zip.",
+"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Scarica i file in blocchi più piccoli, separatamente o chiedi al tuo amministratore.",
"couldn't be determined" => "non può essere determinato",
"Application is not enabled" => "L'applicazione non è abilitata",
"Authentication error" => "Errore di autenticazione",
@@ -49,5 +52,6 @@
"%d months ago" => "%d mesi fa",
"last year" => "anno scorso",
"years ago" => "anni fa",
+"Caused by:" => "Causato da:",
"Could not find category \"%s\"" => "Impossibile trovare la categoria \"%s\""
);
diff --git a/lib/l10n/ko.php b/lib/l10n/ko.php
index 31245ea96f2..1f32ebe402a 100644
--- a/lib/l10n/ko.php
+++ b/lib/l10n/ko.php
@@ -17,6 +17,13 @@
"Files" => "파일",
"Text" => "텍스트",
"Images" => "그림",
+"%s enter the database username." => "데이터베이스 사용자 명을 %s 에 입력해주십시오",
+"%s enter the database name." => "데이터베이스 명을 %s 에 입력해주십시오",
+"%s you may not use dots in the database name" => "%s 에 적으신 데이터베이스 이름에는 점을 사용할수 없습니다",
+"DB Error: \"%s\"" => "DB 오류: \"%s\"",
+"PostgreSQL username and/or password not valid" => "PostgreSQL의 사용자 명 혹은 비밀번호가 잘못되었습니다",
+"Set an admin username." => "관리자 이름 설정",
+"Set an admin password." => "관리자 비밀번호 설정",
"Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken." => "WebDAV 인터페이스가 제대로 작동하지 않습니다. 웹 서버에서 파일 동기화를 사용할 수 있도록 설정이 제대로 되지 않은 것 같습니다.",
"Please double check the <a href='%s'>installation guides</a>." => "<a href='%s'>설치 가이드</a>를 다시 한 번 확인하십시오.",
"seconds ago" => "초 전",
diff --git a/lib/l10n/nl.php b/lib/l10n/nl.php
index de80d1b5d56..0a221b11f00 100644
--- a/lib/l10n/nl.php
+++ b/lib/l10n/nl.php
@@ -5,11 +5,14 @@
"Users" => "Gebruikers",
"Apps" => "Apps",
"Admin" => "Beheerder",
+"Failed to upgrade \"%s\"." => "Upgrade \"%s\" mislukt.",
"web services under your control" => "Webdiensten in eigen beheer",
+"cannot open \"%s\"" => "Kon \"%s\" niet openen",
"ZIP download is turned off." => "ZIP download is uitgeschakeld.",
"Files need to be downloaded one by one." => "Bestanden moeten één voor één worden gedownload.",
"Back to Files" => "Terug naar bestanden",
"Selected files too large to generate zip file." => "De geselecteerde bestanden zijn te groot om een zip bestand te maken.",
+"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Download de bestanden in kleinere brokken, appart of vraag uw administrator.",
"couldn't be determined" => "kon niet worden vastgesteld",
"Application is not enabled" => "De applicatie is niet actief",
"Authentication error" => "Authenticatie fout",
@@ -49,5 +52,6 @@
"%d months ago" => "%d maanden geleden",
"last year" => "vorig jaar",
"years ago" => "jaar geleden",
+"Caused by:" => "Gekomen door:",
"Could not find category \"%s\"" => "Kon categorie \"%s\" niet vinden"
);
diff --git a/lib/l10n/pl.php b/lib/l10n/pl.php
index bbca1913b70..d06d5ba8a3e 100644
--- a/lib/l10n/pl.php
+++ b/lib/l10n/pl.php
@@ -5,11 +5,14 @@
"Users" => "Użytkownicy",
"Apps" => "Aplikacje",
"Admin" => "Administrator",
+"Failed to upgrade \"%s\"." => "Błąd przy aktualizacji \"%s\".",
"web services under your control" => "Kontrolowane serwisy",
+"cannot open \"%s\"" => "Nie można otworzyć \"%s\"",
"ZIP download is turned off." => "Pobieranie ZIP jest wyłączone.",
"Files need to be downloaded one by one." => "Pliki muszą zostać pobrane pojedynczo.",
"Back to Files" => "Wróć do plików",
"Selected files too large to generate zip file." => "Wybrane pliki są zbyt duże, aby wygenerować plik zip.",
+"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Pobierz pliki w mniejszy kawałkach, oddzielnie lub poproś administratora o zwiększenie limitu.",
"couldn't be determined" => "nie może zostać znaleziony",
"Application is not enabled" => "Aplikacja nie jest włączona",
"Authentication error" => "Błąd uwierzytelniania",
@@ -49,5 +52,6 @@
"%d months ago" => "%d miesiecy temu",
"last year" => "w zeszłym roku",
"years ago" => "lat temu",
+"Caused by:" => "Spowodowane przez:",
"Could not find category \"%s\"" => "Nie można odnaleźć kategorii \"%s\""
);
diff --git a/lib/l10n/pt_BR.php b/lib/l10n/pt_BR.php
index 029331fdec8..23385e8c7d1 100644
--- a/lib/l10n/pt_BR.php
+++ b/lib/l10n/pt_BR.php
@@ -5,11 +5,14 @@
"Users" => "Usuários",
"Apps" => "Aplicações",
"Admin" => "Admin",
+"Failed to upgrade \"%s\"." => "Falha na atualização de \"%s\".",
"web services under your control" => "serviços web sob seu controle",
+"cannot open \"%s\"" => "não pode abrir \"%s\"",
"ZIP download is turned off." => "Download ZIP está desligado.",
"Files need to be downloaded one by one." => "Arquivos precisam ser baixados um de cada vez.",
"Back to Files" => "Voltar para Arquivos",
"Selected files too large to generate zip file." => "Arquivos selecionados são muito grandes para gerar arquivo zip.",
+"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Baixe os arquivos em pedaços menores, separadamente ou solicite educadamente ao seu administrador.",
"couldn't be determined" => "não pôde ser determinado",
"Application is not enabled" => "Aplicação não está habilitada",
"Authentication error" => "Erro de autenticação",
@@ -49,5 +52,6 @@
"%d months ago" => "%d meses atrás",
"last year" => "último ano",
"years ago" => "anos atrás",
+"Caused by:" => "Causados ​​por:",
"Could not find category \"%s\"" => "Impossível localizar categoria \"%s\""
);
diff --git a/lib/l10n/pt_PT.php b/lib/l10n/pt_PT.php
index 7480026e920..96cb5f65f56 100644
--- a/lib/l10n/pt_PT.php
+++ b/lib/l10n/pt_PT.php
@@ -5,11 +5,14 @@
"Users" => "Utilizadores",
"Apps" => "Aplicações",
"Admin" => "Admin",
+"Failed to upgrade \"%s\"." => "A actualização \"%s\" falhou.",
"web services under your control" => "serviços web sob o seu controlo",
+"cannot open \"%s\"" => "Não foi possível abrir \"%s\"",
"ZIP download is turned off." => "Descarregamento em ZIP está desligado.",
"Files need to be downloaded one by one." => "Os ficheiros precisam de ser descarregados um por um.",
"Back to Files" => "Voltar a Ficheiros",
"Selected files too large to generate zip file." => "Os ficheiros seleccionados são grandes demais para gerar um ficheiro zip.",
+"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Descarregue os ficheiros em partes menores, separados ou peça gentilmente ao seu administrador.",
"couldn't be determined" => "Não foi possível determinar",
"Application is not enabled" => "A aplicação não está activada",
"Authentication error" => "Erro na autenticação",
@@ -49,5 +52,6 @@
"%d months ago" => "Há %d meses atrás",
"last year" => "ano passado",
"years ago" => "anos atrás",
+"Caused by:" => "Causado por:",
"Could not find category \"%s\"" => "Não foi encontrado a categoria \"%s\""
);
diff --git a/lib/l10n/ru.php b/lib/l10n/ru.php
index 052b0487c6c..d9d1f5c53fe 100644
--- a/lib/l10n/ru.php
+++ b/lib/l10n/ru.php
@@ -5,11 +5,14 @@
"Users" => "Пользователи",
"Apps" => "Приложения",
"Admin" => "Admin",
+"Failed to upgrade \"%s\"." => "Не смог обновить \"%s\".",
"web services under your control" => "веб-сервисы под вашим управлением",
+"cannot open \"%s\"" => "не могу открыть \"%s\"",
"ZIP download is turned off." => "ZIP-скачивание отключено.",
"Files need to be downloaded one by one." => "Файлы должны быть загружены по одному.",
"Back to Files" => "Назад к файлам",
"Selected files too large to generate zip file." => "Выбранные файлы слишком велики, чтобы создать zip файл.",
+"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Загрузите файл маленьшими порциями, раздельно или вежливо попросите Вашего администратора.",
"couldn't be determined" => "Невозможно установить",
"Application is not enabled" => "Приложение не разрешено",
"Authentication error" => "Ошибка аутентификации",
@@ -49,5 +52,6 @@
"%d months ago" => "%d месяцев назад",
"last year" => "в прошлом году",
"years ago" => "несколько лет назад",
+"Caused by:" => "Вызвано:",
"Could not find category \"%s\"" => "Категория \"%s\" не найдена"
);
diff --git a/lib/l10n/sv.php b/lib/l10n/sv.php
index 56776e574aa..0e2e806b4f6 100644
--- a/lib/l10n/sv.php
+++ b/lib/l10n/sv.php
@@ -5,11 +5,14 @@
"Users" => "Användare",
"Apps" => "Program",
"Admin" => "Admin",
+"Failed to upgrade \"%s\"." => "Misslyckades med att uppgradera \"%s\".",
"web services under your control" => "webbtjänster under din kontroll",
+"cannot open \"%s\"" => "Kan inte öppna \"%s\"",
"ZIP download is turned off." => "Nerladdning av ZIP är avstängd.",
"Files need to be downloaded one by one." => "Filer laddas ner en åt gången.",
"Back to Files" => "Tillbaka till Filer",
"Selected files too large to generate zip file." => "Valda filer är för stora för att skapa zip-fil.",
+"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Ladda ner filerna i mindre bitar, separat eller fråga din administratör.",
"couldn't be determined" => "kunde inte bestämmas",
"Application is not enabled" => "Applikationen är inte aktiverad",
"Authentication error" => "Fel vid autentisering",
@@ -49,5 +52,6 @@
"%d months ago" => "%d månader sedan",
"last year" => "förra året",
"years ago" => "år sedan",
+"Caused by:" => "Orsakad av:",
"Could not find category \"%s\"" => "Kunde inte hitta kategorin \"%s\""
);
diff --git a/lib/legacy/config.php b/lib/legacy/config.php
index 5294a48ea44..7e498013737 100644
--- a/lib/legacy/config.php
+++ b/lib/legacy/config.php
@@ -46,6 +46,10 @@ class OC_Config {
*/
public static $object;
+ public static function getObject() {
+ return self::$object;
+ }
+
/**
* @brief Lists all available config keys
* @return array with key names
diff --git a/lib/memcache/apcu.php b/lib/memcache/apcu.php
new file mode 100644
index 00000000000..ccc1aa6e562
--- /dev/null
+++ b/lib/memcache/apcu.php
@@ -0,0 +1,28 @@
+<?php
+/**
+ * Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Memcache;
+
+class APCu extends APC {
+ public function clear($prefix = '') {
+ $ns = $this->getNamespace() . $prefix;
+ $ns = preg_quote($ns, '/');
+ $iter = new \APCIterator('/^'.$ns.'/');
+ return apc_delete($iter);
+ }
+
+ static public function isAvailable() {
+ if (!extension_loaded('apcu')) {
+ return false;
+ } elseif (!ini_get('apc.enable_cli') && \OC::$CLI) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+}
diff --git a/lib/memcache/factory.php b/lib/memcache/factory.php
index b1b49971031..4c1b1ab207f 100644
--- a/lib/memcache/factory.php
+++ b/lib/memcache/factory.php
@@ -18,6 +18,8 @@ class Factory {
function create($prefix = '') {
if (XCache::isAvailable()) {
return new XCache($prefix);
+ } elseif (APCu::isAvailable()) {
+ return new APCu($prefix);
} elseif (APC::isAvailable()) {
return new APC($prefix);
} elseif (Memcached::isAvailable()) {
@@ -33,6 +35,6 @@ class Factory {
* @return bool
*/
public function isAvailable() {
- return XCache::isAvailable() || APC::isAvailable() || Memcached::isAvailable();
+ return XCache::isAvailable() || APCu::isAvailable() || APC::isAvailable() || Memcached::isAvailable();
}
}
diff --git a/lib/public/files.php b/lib/public/files.php
index 4975bbb7dfa..852b041eefb 100644
--- a/lib/public/files.php
+++ b/lib/public/files.php
@@ -61,7 +61,7 @@ class Files {
* @param string $query
* @return array
*/
- public function searchByMime($mimetype) {
+ static public function searchByMime($mimetype) {
return(\OC\Files\Filesystem::searchByMime( $mimetype ));
}
diff --git a/lib/public/image.php b/lib/public/image.php
index dcecc077e2f..c6dd9a113ab 100644
--- a/lib/public/image.php
+++ b/lib/public/image.php
@@ -25,5 +25,5 @@ namespace OCP;
/**
* This class provides functions to handle images
*/
-class Image extends OC_Image {
+class Image extends \OC_Image {
}
diff --git a/lib/public/share.php b/lib/public/share.php
index 596a729a47d..63645e6fa34 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -454,6 +454,9 @@ class Share {
$forcePortable = (CRYPT_BLOWFISH != 1);
$hasher = new \PasswordHash(8, $forcePortable);
$shareWith = $hasher->HashPassword($shareWith.\OC_Config::getValue('passwordsalt', ''));
+ } else {
+ // reuse the already set password
+ $shareWith = $checkExists['share_with'];
}
// Generate token
@@ -1285,6 +1288,8 @@ class Share {
if ($shareType == self::SHARE_TYPE_GROUP) {
$groupItemTarget = self::generateTarget($itemType, $itemSource, $shareType, $shareWith['group'],
$uidOwner, $suggestedItemTarget);
+ $run = true;
+ $error = '';
\OC_Hook::emit('OCP\Share', 'pre_shared', array(
'itemType' => $itemType,
'itemSource' => $itemSource,
@@ -1294,8 +1299,15 @@ class Share {
'uidOwner' => $uidOwner,
'permissions' => $permissions,
'fileSource' => $fileSource,
- 'token' => $token
+ 'token' => $token,
+ 'run' => &$run,
+ 'error' => &$error
));
+
+ if ($run === false) {
+ throw new \Exception($error);
+ }
+
if (isset($fileSource)) {
if ($parentFolder) {
if ($parentFolder === true) {
@@ -1371,6 +1383,8 @@ class Share {
} else {
$itemTarget = self::generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner,
$suggestedItemTarget);
+ $run = true;
+ $error = '';
\OC_Hook::emit('OCP\Share', 'pre_shared', array(
'itemType' => $itemType,
'itemSource' => $itemSource,
@@ -1380,8 +1394,15 @@ class Share {
'uidOwner' => $uidOwner,
'permissions' => $permissions,
'fileSource' => $fileSource,
- 'token' => $token
+ 'token' => $token,
+ 'run' => &$run,
+ 'error' => &$error
));
+
+ if ($run === false) {
+ throw new \Exception($error);
+ }
+
if (isset($fileSource)) {
if ($parentFolder) {
if ($parentFolder === true) {
diff --git a/lib/public/util.php b/lib/public/util.php
index 7205950d149..693805946ea 100644
--- a/lib/public/util.php
+++ b/lib/public/util.php
@@ -83,7 +83,7 @@ class Util {
* @return OC_L10N
*/
public static function getL10N( $application ) {
- \OC_L10N::get( $application );
+ return \OC_L10N::get( $application );
}
/**
diff --git a/lib/setup.php b/lib/setup.php
index 59f4cab75de..05a49890976 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -185,9 +185,7 @@ class OC_Setup {
$hint = $l->t('Please double check the <a href=\'%s\'>installation guides</a>.',
'http://doc.owncloud.org/server/5.0/admin_manual/installation.html');
- $tmpl = new OC_Template('', 'error', 'guest');
- $tmpl->assign('errors', array(1 => array('error' => $error, 'hint' => $hint)));
- $tmpl->printPage();
+ OC_Template::printErrorPage($error, $hint);
exit();
}
}
diff --git a/lib/template.php b/lib/template.php
index d48e3b36821..9b2c1211e61 100644
--- a/lib/template.php
+++ b/lib/template.php
@@ -21,134 +21,20 @@
*
*/
-/**
- * Prints an XSS escaped string
- * @param string $string the string which will be escaped and printed
- */
-function p($string) {
- print(OC_Util::sanitizeHTML($string));
-}
-
-/**
- * Prints an unescaped string
- * @param string $string the string which will be printed as it is
- */
-function print_unescaped($string) {
- print($string);
-}
-
-/**
- * @brief make OC_Helper::linkTo available as a simple function
- * @param string $app app
- * @param string $file file
- * @param array $args array with param=>value, will be appended to the returned url
- * @return string link to the file
- *
- * For further information have a look at OC_Helper::linkTo
- */
-function link_to( $app, $file, $args = array() ) {
- return OC_Helper::linkTo( $app, $file, $args );
-}
-
-/**
- * @brief make OC_Helper::imagePath available as a simple function
- * @param string $app app
- * @param string $image image
- * @return string link to the image
- *
- * For further information have a look at OC_Helper::imagePath
- */
-function image_path( $app, $image ) {
- return OC_Helper::imagePath( $app, $image );
-}
-
-/**
- * @brief make OC_Helper::mimetypeIcon available as a simple function
- * @param string $mimetype mimetype
- * @return string link to the image
- *
- * For further information have a look at OC_Helper::mimetypeIcon
- */
-function mimetype_icon( $mimetype ) {
- return OC_Helper::mimetypeIcon( $mimetype );
-}
-
-/**
- * @brief make OC_Helper::humanFileSize available as a simple function
- * @param int $bytes size in bytes
- * @return string size as string
- *
- * For further information have a look at OC_Helper::humanFileSize
- */
-function human_file_size( $bytes ) {
- return OC_Helper::humanFileSize( $bytes );
-}
-
-function relative_modified_date($timestamp) {
- $l=OC_L10N::get('lib');
- $timediff = time() - $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 < 120) { return $l->t('1 minute ago'); }
- else if($timediff < 3600) { return $l->t('%d minutes ago', $diffminutes); }
- else if($timediff < 7200) { return $l->t('1 hour ago'); }
- else if($timediff < 86400) { return $l->t('%d hours ago', $diffhours); }
- else if((date('G')-$diffhours) > 0) { return $l->t('today'); }
- else if((date('G')-$diffhours) > -24) { return $l->t('yesterday'); }
- else if($timediff < 2678400) { return $l->t('%d days ago', $diffdays); }
- else if($timediff < 5184000) { return $l->t('last month'); }
- else if((date('n')-$diffmonths) > 0) { return $l->t('%d months ago', $diffmonths); }
- else if($timediff < 63113852) { return $l->t('last year'); }
- else { return $l->t('years ago'); }
-}
-
-function html_select_options($options, $selected, $params=array()) {
- if (!is_array($selected)) {
- $selected=array($selected);
- }
- if (isset($params['combine']) && $params['combine']) {
- $options = array_combine($options, $options);
- }
- $value_name = $label_name = false;
- if (isset($params['value'])) {
- $value_name = $params['value'];
- }
- if (isset($params['label'])) {
- $label_name = $params['label'];
- }
- $html = '';
- foreach($options as $value => $label) {
- if ($value_name && is_array($label)) {
- $value = $label[$value_name];
- }
- if ($label_name && is_array($label)) {
- $label = $label[$label_name];
- }
- $select = in_array($value, $selected) ? ' selected="selected"' : '';
- $html .= '<option value="' . OC_Util::sanitizeHTML($value) . '"' . $select . '>' . OC_Util::sanitizeHTML($label) . '</option>'."\n";
- }
- return $html;
-}
+require_once __DIR__.'/template/functions.php';
/**
- * This class provides the templates for owncloud.
+ * This class provides the templates for ownCloud.
*/
-class OC_Template{
+class OC_Template extends \OC\Template\Base {
private $renderas; // Create a full page?
- private $application; // template Application
- private $vars; // Vars
- private $template; // The path to the template
- private $l10n; // The l10n-Object
+ private $path; // The path to the template
private $headers=array(); //custom headers
/**
* @brief Constructor
* @param string $app app providing the template
- * @param string $file name of the template file (without suffix)
+ * @param string $name of the template file (without suffix)
* @param string $renderas = ""; produce a full page
* @return OC_Template object
*
@@ -159,13 +45,25 @@ class OC_Template{
* "admin".
*/
public function __construct( $app, $name, $renderas = "" ) {
+ // Read the selected theme from the config file
+ $theme = OC_Util::getTheme();
+
+ // Read the detected formfactor and use the right file name.
+ $fext = self::getFormFactorExtension();
+
+ $requesttoken = OC::$session ? OC_Util::callRegister() : '';
+
+ $parts = explode('/', $app); // fix translation when app is something like core/lostpassword
+ $l10n = OC_L10N::get($parts[0]);
+ $themeDefaults = new OC_Defaults();
+
+ list($path, $template) = $this->findTemplate($theme, $app, $name, $fext);
+
// Set the private data
$this->renderas = $renderas;
- $this->application = $app;
- $this->vars = array();
- $this->vars['requesttoken'] = OC::$session ? OC_Util::callRegister() : '';
- $parts = explode('/', $app); // fix translation when app is something like core/lostpassword
- $this->l10n = OC_L10N::get($parts[0]);
+ $this->path = $path;
+
+ parent::__construct($template, $requesttoken, $l10n, $themeDefaults);
// Some headers to enhance security
header('X-XSS-Protection: 1; mode=block'); // Enforce browser based XSS filters
@@ -189,7 +87,6 @@ class OC_Template{
.'media-src *');
header('Content-Security-Policy:'.$policy); // Standard
- $this->findTemplate($name);
}
/**
@@ -239,13 +136,13 @@ class OC_Template{
\OC::$session->set('formfactor', $_GET['formfactor']);
}
$formfactor = \OC::$session->get('formfactor');
- if($formfactor=='default') {
+ if($formfactor==='default') {
$fext='';
- }elseif($formfactor=='mobile') {
+ }elseif($formfactor==='mobile') {
$fext='.mobile';
- }elseif($formfactor=='tablet') {
+ }elseif($formfactor==='tablet') {
$fext='.tablet';
- }elseif($formfactor=='standalone') {
+ }elseif($formfactor==='standalone') {
$fext='.standalone';
}else{
$fext='';
@@ -260,112 +157,23 @@ class OC_Template{
* Will select the template file for the selected theme and formfactor.
* Checking all the possible locations.
*/
- protected function findTemplate($name)
- {
- // Read the selected theme from the config file
- $theme = OC_Util::getTheme();
-
- // Read the detected formfactor and use the right file name.
- $fext = self::getFormFactorExtension();
-
- $app = $this->application;
+ protected function findTemplate($theme, $app, $name, $fext) {
// Check if it is a app template or not.
- if( $app != "" ) {
- // Check if the app is in the app folder or in the root
- if( file_exists(OC_App::getAppPath($app)."/templates/" )) {
- // Check if the template is overwritten by the selected theme
- if ($this->checkPathForTemplate(OC::$SERVERROOT."/themes/$theme/apps/$app/templates/", $name, $fext)) {
- }elseif ($this->checkPathForTemplate(OC_App::getAppPath($app)."/templates/", $name, $fext)) {
- }
- }else{
- // Check if the template is overwritten by the selected theme
- if ($this->checkPathForTemplate(OC::$SERVERROOT."/themes/$theme/$app/templates/", $name, $fext)) {
- }elseif ($this->checkPathForTemplate(OC::$SERVERROOT."/$app/templates/", $name, $fext)) {
- }else{
- echo('template not found: template:'.$name.' formfactor:'.$fext
- .' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
- die();
- }
-
- }
- }else{
- // Check if the template is overwritten by the selected theme
- if ($this->checkPathForTemplate(OC::$SERVERROOT."/themes/$theme/core/templates/", $name, $fext)) {
- } elseif ($this->checkPathForTemplate(OC::$SERVERROOT."/core/templates/", $name, $fext)) {
- }else{
- echo('template not found: template:'.$name.' formfactor:'.$fext
- .' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
- die();
- }
- }
- }
-
- /**
- * @brief check Path For Template with and without $fext
- * @param string $path to check
- * @param string $name of the template file (without suffix)
- * @param string $fext formfactor extension
- * @return bool true when found
- *
- * Will set $this->template and $this->path if there is a template at
- * the specific $path
- */
- protected function checkPathForTemplate($path, $name, $fext)
- {
- if ($name =='') return false;
- $template = null;
- if( is_file( $path.$name.$fext.'.php' )) {
- $template = $path.$name.$fext.'.php';
- }elseif( is_file( $path.$name.'.php' )) {
- $template = $path.$name.'.php';
- }
- if ($template) {
- $this->template = $template;
- $this->path = $path;
- return true;
- }
- return false;
- }
-
- /**
- * @brief Assign variables
- * @param string $key key
- * @param string $value value
- * @return bool
- *
- * This function assigns a variable. It can be accessed via $_[$key] in
- * the template.
- *
- * If the key existed before, it will be overwritten
- */
- public function assign( $key, $value) {
- $this->vars[$key] = $value;
- return true;
- }
-
- /**
- * @brief Appends a variable
- * @param string $key key
- * @param string $value value
- * @return bool
- *
- * This function assigns a variable in an array context. If the key already
- * exists, the value will be appended. It can be accessed via
- * $_[$key][$position] in the template.
- */
- public function append( $key, $value ) {
- if( array_key_exists( $key, $this->vars )) {
- $this->vars[$key][] = $value;
- }
- else{
- $this->vars[$key] = array( $value );
+ if( $app !== '' ) {
+ $dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app));
+ } else {
+ $dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT);
}
+ $locator = new \OC\Template\TemplateFileLocator( $fext, $dirs );
+ $template = $locator->find($name);
+ $path = $locator->getPath();
+ return array($path, $template);
}
/**
* @brief Add a custom element to the header
* @param string $tag tag name of the element
- * @param array $attributes array of attrobutes for the element
+ * @param array $attributes array of attributes for the element
* @param string $text the text content for the element
*/
public function addHeader( $tag, $attributes, $text='') {
@@ -373,31 +181,14 @@ class OC_Template{
}
/**
- * @brief Prints the proceeded template
+ * @brief Process the template
* @return bool
*
- * This function proceeds the template and prints its output.
- */
- public function printPage() {
- $data = $this->fetchPage();
- if( $data === false ) {
- return false;
- }
- else{
- print $data;
- return true;
- }
- }
-
- /**
- * @brief Proceeds the template
- * @return bool
- *
- * This function proceeds the template. If $this->renderas is set, it
+ * This function process the template. If $this->renderas is set, it
* will produce a full page.
*/
public function fetchPage() {
- $data = $this->_fetch();
+ $data = parent::fetchPage();
if( $this->renderas ) {
$page = new OC_TemplateLayout($this->renderas);
@@ -417,27 +208,6 @@ class OC_Template{
}
/**
- * @brief doing the actual work
- * @return string content
- *
- * Includes the template file, fetches its output
- */
- private function _fetch() {
- // Register the variables
- $_ = $this->vars;
- $l = $this->l10n;
-
- // Execute the template
- ob_start();
- include $this->template; // <-- we have to use include because we pass $_!
- $data = ob_get_contents();
- @ob_end_clean();
-
- // return the data
- return $data;
- }
-
- /**
* @brief Include template
* @return string returns content of included template
*
@@ -445,21 +215,7 @@ class OC_Template{
* do this.
*/
public function inc( $file, $additionalparams = null ) {
- $_ = $this->vars;
- $l = $this->l10n;
-
- if( !is_null($additionalparams)) {
- $_ = array_merge( $additionalparams, $this->vars );
- }
-
- // Include
- ob_start();
- include $this->path.$file.'.php';
- $data = ob_get_contents();
- @ob_end_clean();
-
- // Return data
- return $data;
+ return $this->load($this->path.$file.'.php', $additionalparams);
}
/**
@@ -509,8 +265,8 @@ class OC_Template{
/**
* @brief Print a fatal error page and terminates the script
- * @param string $error The error message to show
- * @param string $hint An optional hint message
+ * @param string $error_msg The error message to show
+ * @param string $hint An optional hint message
* Warning: All data passed to $hint needs to get sanitized using OC_Util::sanitizeHTML
*/
public static function printErrorPage( $error_msg, $hint = '' ) {
@@ -531,17 +287,25 @@ class OC_Template{
if ($exception->getCode()) {
$error_msg = '['.$exception->getCode().'] '.$error_msg;
}
- $hint = $exception->getTraceAsString();
- if (!empty($hint)) {
- $hint = '<pre>'.$hint.'</pre>';
- }
- while (method_exists($exception,'previous') && $exception = $exception->previous()) {
- $error_msg .= '<br/>Caused by: ';
- if ($exception->getCode()) {
- $error_msg .= '['.$exception->getCode().'] ';
+ if (defined('DEBUG') and DEBUG) {
+ $hint = $exception->getTraceAsString();
+ if (!empty($hint)) {
+ $hint = '<pre>'.$hint.'</pre>';
}
- $error_msg .= $exception->getMessage();
- };
+ $l = OC_L10N::get('lib');
+ while (method_exists($exception, 'previous') && $exception = $exception->previous()) {
+ $error_msg .= '<br/>'.$l->t('Caused by:').' ';
+ if ($exception->getCode()) {
+ $error_msg .= '['.$exception->getCode().'] ';
+ }
+ $error_msg .= $exception->getMessage();
+ };
+ } else {
+ $hint = '';
+ if ($exception instanceof \OC\HintException) {
+ $hint = $exception->getHint();
+ }
+ }
self::printErrorPage($error_msg, $hint);
}
}
diff --git a/lib/template/base.php b/lib/template/base.php
new file mode 100644
index 00000000000..88941bc7132
--- /dev/null
+++ b/lib/template/base.php
@@ -0,0 +1,134 @@
+<?php
+/**
+ * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Template;
+
+class Base {
+ private $template; // The template
+ private $vars; // Vars
+ private $l10n; // The l10n-Object
+ private $theme; // theme defaults
+
+ public function __construct( $template, $requesttoken, $l10n, $theme ) {
+ $this->vars = array();
+ $this->vars['requesttoken'] = $requesttoken;
+ $this->l10n = $l10n;
+ $this->template = $template;
+ $this->theme = $theme;
+ }
+
+ protected function getAppTemplateDirs($theme, $app, $serverroot, $app_dir) {
+ // Check if the app is in the app folder or in the root
+ if( file_exists($app_dir.'/templates/' )) {
+ return array(
+ $serverroot.'/themes/'.$theme.'/apps/'.$app.'/templates/',
+ $app_dir.'/templates/',
+ );
+ }
+ return array(
+ $serverroot.'/themes/'.$theme.'/'.$app.'/templates/',
+ $serverroot.'/'.$app.'/templates/',
+ );
+ }
+
+ protected function getCoreTemplateDirs($theme, $serverroot) {
+ return array(
+ $serverroot.'/themes/'.$theme.'/core/templates/',
+ $serverroot.'/core/templates/',
+ );
+ }
+
+ /**
+ * @brief Assign variables
+ * @param string $key key
+ * @param string $value value
+ * @return bool
+ *
+ * This function assigns a variable. It can be accessed via $_[$key] in
+ * the template.
+ *
+ * If the key existed before, it will be overwritten
+ */
+ public function assign( $key, $value) {
+ $this->vars[$key] = $value;
+ return true;
+ }
+
+ /**
+ * @brief Appends a variable
+ * @param string $key key
+ * @param string $value value
+ * @return bool
+ *
+ * This function assigns a variable in an array context. If the key already
+ * exists, the value will be appended. It can be accessed via
+ * $_[$key][$position] in the template.
+ */
+ public function append( $key, $value ) {
+ if( array_key_exists( $key, $this->vars )) {
+ $this->vars[$key][] = $value;
+ }
+ else{
+ $this->vars[$key] = array( $value );
+ }
+ }
+
+ /**
+ * @brief Prints the proceeded template
+ * @return bool
+ *
+ * This function proceeds the template and prints its output.
+ */
+ public function printPage() {
+ $data = $this->fetchPage();
+ if( $data === false ) {
+ return false;
+ }
+ else{
+ print $data;
+ return true;
+ }
+ }
+
+ /**
+ * @brief Process the template
+ * @return bool
+ *
+ * This function processes the template.
+ */
+ public function fetchPage() {
+ return $this->load($this->template);
+ }
+
+ /**
+ * @brief doing the actual work
+ * @return string content
+ *
+ * Includes the template file, fetches its output
+ */
+ protected function load( $file, $additionalparams = null ) {
+ // Register the variables
+ $_ = $this->vars;
+ $l = $this->l10n;
+ $theme = $this->theme;
+
+ if( !is_null($additionalparams)) {
+ $_ = array_merge( $additionalparams, $this->vars );
+ }
+
+ // Include
+ ob_start();
+ include $file;
+ $data = ob_get_contents();
+ @ob_end_clean();
+
+ // Return data
+ return $data;
+ }
+
+}
diff --git a/lib/template/cssresourcelocator.php b/lib/template/cssresourcelocator.php
new file mode 100644
index 00000000000..8e7831ca549
--- /dev/null
+++ b/lib/template/cssresourcelocator.php
@@ -0,0 +1,43 @@
+<?php
+/**
+ * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Template;
+
+class CSSResourceLocator extends ResourceLocator {
+ public function doFind( $style ) {
+ if (strpos($style, '3rdparty') === 0
+ && $this->appendIfExist($this->thirdpartyroot, $style.'.css')
+ || $this->appendIfExist($this->serverroot, $style.$this->form_factor.'.css')
+ || $this->appendIfExist($this->serverroot, $style.'.css')
+ || $this->appendIfExist($this->serverroot, 'core/'.$style.$this->form_factor.'.css')
+ || $this->appendIfExist($this->serverroot, 'core/'.$style.'.css')
+ ) {
+ return;
+ }
+ $app = substr($style, 0, strpos($style, '/'));
+ $style = substr($style, strpos($style, '/')+1);
+ $app_path = \OC_App::getAppPath($app);
+ $app_url = $this->webroot . '/index.php/apps/' . $app;
+ if ($this->appendIfExist($app_path, $style.$this->form_factor.'.css', $app_url)
+ || $this->appendIfExist($app_path, $style.'.css', $app_url)
+ ) {
+ return;
+ }
+ throw new \Exception('css file not found: style:'.$style);
+ }
+
+ public function doFindTheme( $style ) {
+ $theme_dir = 'themes/'.$this->theme.'/';
+ $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$style.$this->form_factor.'.css')
+ || $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$style.'.css')
+ || $this->appendIfExist($this->serverroot, $theme_dir.$style.$this->form_factor.'.css')
+ || $this->appendIfExist($this->serverroot, $theme_dir.$style.'.css')
+ || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$style.$this->form_factor.'.css')
+ || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$style.'.css');
+ }
+}
diff --git a/lib/template/functions.php b/lib/template/functions.php
new file mode 100644
index 00000000000..2d43cae1c0c
--- /dev/null
+++ b/lib/template/functions.php
@@ -0,0 +1,120 @@
+<?php
+/**
+ * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+/**
+ * Prints an XSS escaped string
+ * @param string $string the string which will be escaped and printed
+ */
+function p($string) {
+ print(OC_Util::sanitizeHTML($string));
+}
+
+/**
+ * Prints an unescaped string
+ * @param string $string the string which will be printed as it is
+ */
+function print_unescaped($string) {
+ print($string);
+}
+
+/**
+ * @brief make OC_Helper::linkTo available as a simple function
+ * @param string $app app
+ * @param string $file file
+ * @param array $args array with param=>value, will be appended to the returned url
+ * @return string link to the file
+ *
+ * For further information have a look at OC_Helper::linkTo
+ */
+function link_to( $app, $file, $args = array() ) {
+ return OC_Helper::linkTo( $app, $file, $args );
+}
+
+/**
+ * @brief make OC_Helper::imagePath available as a simple function
+ * @param string $app app
+ * @param string $image image
+ * @return string link to the image
+ *
+ * For further information have a look at OC_Helper::imagePath
+ */
+function image_path( $app, $image ) {
+ return OC_Helper::imagePath( $app, $image );
+}
+
+/**
+ * @brief make OC_Helper::mimetypeIcon available as a simple function
+ * @param string $mimetype mimetype
+ * @return string link to the image
+ *
+ * For further information have a look at OC_Helper::mimetypeIcon
+ */
+function mimetype_icon( $mimetype ) {
+ return OC_Helper::mimetypeIcon( $mimetype );
+}
+
+/**
+ * @brief make OC_Helper::humanFileSize available as a simple function
+ * @param int $bytes size in bytes
+ * @return string size as string
+ *
+ * For further information have a look at OC_Helper::humanFileSize
+ */
+function human_file_size( $bytes ) {
+ return OC_Helper::humanFileSize( $bytes );
+}
+
+function relative_modified_date($timestamp) {
+ $l=OC_L10N::get('lib');
+ $timediff = time() - $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 < 120) { return $l->t('1 minute ago'); }
+ else if($timediff < 3600) { return $l->t('%d minutes ago', $diffminutes); }
+ else if($timediff < 7200) { return $l->t('1 hour ago'); }
+ else if($timediff < 86400) { return $l->t('%d hours ago', $diffhours); }
+ else if((date('G')-$diffhours) > 0) { return $l->t('today'); }
+ else if((date('G')-$diffhours) > -24) { return $l->t('yesterday'); }
+ else if($timediff < 2678400) { return $l->t('%d days ago', $diffdays); }
+ else if($timediff < 5184000) { return $l->t('last month'); }
+ else if((date('n')-$diffmonths) > 0) { return $l->t('%d months ago', $diffmonths); }
+ else if($timediff < 63113852) { return $l->t('last year'); }
+ else { return $l->t('years ago'); }
+}
+
+function html_select_options($options, $selected, $params=array()) {
+ if (!is_array($selected)) {
+ $selected=array($selected);
+ }
+ if (isset($params['combine']) && $params['combine']) {
+ $options = array_combine($options, $options);
+ }
+ $value_name = $label_name = false;
+ if (isset($params['value'])) {
+ $value_name = $params['value'];
+ }
+ if (isset($params['label'])) {
+ $label_name = $params['label'];
+ }
+ $html = '';
+ foreach($options as $value => $label) {
+ if ($value_name && is_array($label)) {
+ $value = $label[$value_name];
+ }
+ if ($label_name && is_array($label)) {
+ $label = $label[$label_name];
+ }
+ $select = in_array($value, $selected) ? ' selected="selected"' : '';
+ $html .= '<option value="' . OC_Util::sanitizeHTML($value) . '"' . $select . '>' . OC_Util::sanitizeHTML($label) . '</option>'."\n";
+ }
+ return $html;
+}
diff --git a/lib/template/jsresourcelocator.php b/lib/template/jsresourcelocator.php
new file mode 100644
index 00000000000..f8fe3817ce6
--- /dev/null
+++ b/lib/template/jsresourcelocator.php
@@ -0,0 +1,43 @@
+<?php
+/**
+ * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Template;
+
+class JSResourceLocator extends ResourceLocator {
+ public function doFind( $script ) {
+ $theme_dir = 'themes/'.$this->theme.'/';
+ if (strpos($script, '3rdparty') === 0
+ && $this->appendIfExist($this->thirdpartyroot, $script.'.js')
+ || $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.$this->form_factor.'.js')
+ || $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js')
+ || $this->appendIfExist($this->serverroot, $theme_dir.$script.$this->form_factor.'.js')
+ || $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js')
+ || $this->appendIfExist($this->serverroot, $script.$this->form_factor.'.js')
+ || $this->appendIfExist($this->serverroot, $script.'.js')
+ || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.$this->form_factor.'.js')
+ || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js')
+ || $this->appendIfExist($this->serverroot, 'core/'.$script.$this->form_factor.'.js')
+ || $this->appendIfExist($this->serverroot, 'core/'.$script.'.js')
+ ) {
+ return;
+ }
+ $app = substr($script, 0, strpos($script, '/'));
+ $script = substr($script, strpos($script, '/')+1);
+ $app_path = \OC_App::getAppPath($app);
+ $app_url = \OC_App::getAppWebPath($app);
+ if ($this->appendIfExist($app_path, $script.$this->form_factor.'.js', $app_url)
+ || $this->appendIfExist($app_path, $script.'.js', $app_url)
+ ) {
+ return;
+ }
+ throw new \Exception('js file not found: script:'.$script);
+ }
+
+ public function doFindTheme( $script ) {
+ }
+}
diff --git a/lib/template/resourcelocator.php b/lib/template/resourcelocator.php
new file mode 100644
index 00000000000..9f83673664d
--- /dev/null
+++ b/lib/template/resourcelocator.php
@@ -0,0 +1,70 @@
+<?php
+/**
+ * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Template;
+
+abstract class ResourceLocator {
+ protected $theme;
+ protected $form_factor;
+
+ protected $mapping;
+ protected $serverroot;
+ protected $thirdpartyroot;
+ protected $webroot;
+
+ protected $resources = array();
+
+ public function __construct( $theme, $form_factor, $core_map, $party_map ) {
+ $this->theme = $theme;
+ $this->form_factor = $form_factor;
+ $this->mapping = $core_map + $party_map;
+ $this->serverroot = key($core_map);
+ $this->thirdpartyroot = key($party_map);
+ $this->webroot = $this->mapping[$this->serverroot];
+ }
+
+ abstract public function doFind( $resource );
+ abstract public function doFindTheme( $resource );
+
+ public function find( $resources ) {
+ try {
+ foreach($resources as $resource) {
+ $this->doFind($resource);
+ }
+ if (!empty($this->theme)) {
+ foreach($resources as $resource) {
+ $this->doFindTheme($resource);
+ }
+ }
+ } catch (\Exception $e) {
+ throw new \Exception($e->getMessage().' formfactor:'.$this->form_factor
+ .' serverroot:'.$this->serverroot);
+ }
+ }
+
+ /*
+ * @brief append the $file resource if exist at $root
+ * @param $root path to check
+ * @param $file the filename
+ * @param $web base for path, default map $root to $webroot
+ */
+ protected function appendIfExist($root, $file, $webroot = null) {
+ if (is_file($root.'/'.$file)) {
+ if (!$webroot) {
+ $webroot = $this->mapping[$root];
+ }
+ $this->resources[] = array($root, $webroot, $file);
+ return true;
+ }
+ return false;
+ }
+
+ public function getResources() {
+ return $this->resources;
+ }
+}
diff --git a/lib/template/templatefilelocator.php b/lib/template/templatefilelocator.php
new file mode 100644
index 00000000000..d5a484b1a14
--- /dev/null
+++ b/lib/template/templatefilelocator.php
@@ -0,0 +1,44 @@
+<?php
+/**
+ * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Template;
+
+class TemplateFileLocator {
+ protected $form_factor;
+ protected $dirs;
+ private $path;
+
+ public function __construct( $form_factor, $dirs ) {
+ $this->form_factor = $form_factor;
+ $this->dirs = $dirs;
+ }
+
+ public function find( $template ) {
+ if ($template === '') {
+ throw new \InvalidArgumentException('Empty template name');
+ }
+
+ foreach($this->dirs as $dir) {
+ $file = $dir.$template.$this->form_factor.'.php';
+ if (is_file($file)) {
+ $this->path = $dir;
+ return $file;
+ }
+ $file = $dir.$template.'.php';
+ if (is_file($file)) {
+ $this->path = $dir;
+ return $file;
+ }
+ }
+ throw new \Exception('template file not found: template:'.$template.' formfactor:'.$this->form_factor);
+ }
+
+ public function getPath() {
+ return $this->path;
+ }
+}
diff --git a/lib/templatelayout.php b/lib/templatelayout.php
index 7115b8f0306..0024c9d4960 100644
--- a/lib/templatelayout.php
+++ b/lib/templatelayout.php
@@ -83,21 +83,6 @@ class OC_TemplateLayout extends OC_Template {
}
}
- /*
- * @brief append the $file-url if exist at $root
- * @param $files array to append file info to
- * @param $root path to check
- * @param $web base for path
- * @param $file the filename
- */
- static public function appendIfExist(&$files, $root, $webroot, $file) {
- if (is_file($root.'/'.$file)) {
- $files[] = array($root, $webroot, $file);
- return true;
- }
- return false;
- }
-
static public function findStylesheetFiles($styles) {
// Read the selected theme from the config file
$theme = OC_Util::getTheme();
@@ -105,51 +90,11 @@ class OC_TemplateLayout extends OC_Template {
// Read the detected formfactor and use the right file name.
$fext = self::getFormFactorExtension();
- $files = array();
- foreach($styles as $style) {
- // is it in 3rdparty?
- if(strpos($style, '3rdparty') === 0 &&
- self::appendIfExist($files, OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $style.'.css')) {
-
- // or in the owncloud root?
- }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$style$fext.css" )) {
- }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$style.css" )) {
-
- // or in core ?
- }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$style$fext.css" )) {
- }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$style.css" )) {
-
- }else{
- $app = substr($style, 0, strpos($style, '/'));
- $style = substr($style, strpos($style, '/')+1);
- $app_path = OC_App::getAppPath($app);
- $app_url = OC::$WEBROOT . '/index.php/apps/' . $app;
- if(self::appendIfExist($files, $app_path, $app_url, "$style$fext.css")) {
- }
- elseif(self::appendIfExist($files, $app_path, $app_url, "$style.css")) {
- }
- else {
- echo('css file not found: style:'.$style.' formfactor:'.$fext
- .' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
- die();
- }
- }
- }
- // Add the theme css files. you can override the default values here
- if(!empty($theme)) {
- foreach($styles as $style) {
- if(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style$fext.css" )) {
- }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style.css" )) {
-
- }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style$fext.css" )) {
- }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style.css" )) {
-
- }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style$fext.css" )) {
- }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style.css" )) {
- }
- }
- }
- return $files;
+ $locator = new \OC\Template\CSSResourceLocator( $theme, $fext,
+ array( OC::$SERVERROOT => OC::$WEBROOT ),
+ array( OC::$THIRDPARTYROOT => OC::$THIRDPARTYWEBROOT ));
+ $locator->find($styles);
+ return $locator->getResources();
}
static public function findJavascriptFiles($scripts) {
@@ -159,49 +104,10 @@ class OC_TemplateLayout extends OC_Template {
// Read the detected formfactor and use the right file name.
$fext = self::getFormFactorExtension();
- $files = array();
- foreach($scripts as $script) {
- // Is it in 3rd party?
- if(strpos($script, '3rdparty') === 0 &&
- self::appendIfExist($files, OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $script.'.js')) {
-
- // Is it in apps and overwritten by the theme?
- }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script$fext.js" )) {
- }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script.js" )) {
-
- // Is it in the owncloud root but overwritten by the theme?
- }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script$fext.js" )) {
- }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script.js" )) {
-
- // Is it in the owncloud root ?
- }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$script$fext.js" )) {
- }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$script.js" )) {
-
- // Is in core but overwritten by a theme?
- }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script$fext.js" )) {
- }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script.js" )) {
-
- // Is it in core?
- }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$script$fext.js" )) {
- }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$script.js" )) {
-
- }else{
- // Is it part of an app?
- $app = substr($script, 0, strpos($script, '/'));
- $script = substr($script, strpos($script, '/')+1);
- $app_path = OC_App::getAppPath($app);
- $app_url = OC_App::getAppWebPath($app);
- if(self::appendIfExist($files, $app_path, $app_url, "$script$fext.js")) {
- }
- elseif(self::appendIfExist($files, $app_path, $app_url, "$script.js")) {
- }
- else {
- echo('js file not found: script:'.$script.' formfactor:'.$fext
- .' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
- die();
- }
- }
- }
- return $files;
+ $locator = new \OC\Template\JSResourceLocator( $theme, $fext,
+ array( OC::$SERVERROOT => OC::$WEBROOT ),
+ array( OC::$THIRDPARTYROOT => OC::$THIRDPARTYWEBROOT ));
+ $locator->find($scripts);
+ return $locator->getResources();
}
}
diff --git a/lib/user.php b/lib/user.php
index d93ab1a5f73..ee20f2e0971 100644
--- a/lib/user.php
+++ b/lib/user.php
@@ -39,7 +39,7 @@
class OC_User {
public static $userSession = null;
- private static function getUserSession() {
+ public static function getUserSession() {
if (!self::$userSession) {
$manager = new \OC\User\Manager();
self::$userSession = new \OC\User\Session($manager, \OC::$session);
@@ -83,7 +83,7 @@ class OC_User {
/**
* @return \OC\User\Manager
*/
- private static function getManager() {
+ public static function getManager() {
return self::getUserSession()->getManager();
}
diff --git a/lib/user/manager.php b/lib/user/manager.php
index d17cdf1a200..8dc9bfe2729 100644
--- a/lib/user/manager.php
+++ b/lib/user/manager.php
@@ -30,6 +30,9 @@ class Manager extends PublicEmitter {
*/
private $backends = array();
+ /**
+ * @var \OC\User\User[] $cachedUsers
+ */
private $cachedUsers = array();
public function __construct() {
diff --git a/lib/user/user.php b/lib/user/user.php
index 55d7848a979..8115c43198c 100644
--- a/lib/user/user.php
+++ b/lib/user/user.php
@@ -44,7 +44,7 @@ class User {
*/
public function __construct($uid, $backend, $emitter = null) {
$this->uid = $uid;
- if ($backend->implementsActions(OC_USER_BACKEND_GET_DISPLAYNAME)) {
+ if ($backend and $backend->implementsActions(OC_USER_BACKEND_GET_DISPLAYNAME)) {
$this->displayName = $backend->getDisplayName($uid);
} else {
$this->displayName = $uid;
diff --git a/lib/util.php b/lib/util.php
index 2586ad28320..b7dc2207e6c 100755
--- a/lib/util.php
+++ b/lib/util.php
@@ -871,6 +871,10 @@ class OC_Util {
if (function_exists('xcache_clear_cache')) {
xcache_clear_cache(XC_TYPE_VAR, 0);
}
+ // Opcache (PHP >= 5.5)
+ if (function_exists('opcache_reset')) {
+ opcache_reset();
+ }
}
/**
@@ -890,4 +894,11 @@ class OC_Util {
return $value;
}
+
+ public static function basename($file)
+ {
+ $file = rtrim($file, '/');
+ $t = explode('/', $file);
+ return array_pop($t);
+ }
}