From 0e2b957dacb86c510c59721f63879f1c9d93d5d4 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind1991@gmail.com>
Date: Sat, 17 Sep 2011 02:30:58 +0200
Subject: add pdo backend to oc_db

---
 lib/db.php | 350 +++++++++++++++++++++++++++++++++++++------------------------
 1 file changed, 215 insertions(+), 135 deletions(-)

diff --git a/lib/db.php b/lib/db.php
index 414525ae207..3c0ab8544af 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -25,7 +25,13 @@
  * MDB2 with some adaptions.
  */
 class OC_DB {
-	static private $DBConnection=false;
+	const BACKEND_PDO=0;
+	const BACKEND_MDB2=1;
+	
+	static private $connection; //the prefered conenction to use, either PDO or MDB2
+	static private $backend=null;
+	static private $MDB2=false;
+	static private $PDO=false;
 	static private $schema=false;
 	static private $affected=0;
 	static private $result=false;
@@ -36,18 +42,77 @@ class OC_DB {
 	 *
 	 * Connects to the database as specified in config.php
 	 */
-	static public function connect(){
+	public static function connect(){
+		if(class_exists('PDO')){//check if we can use PDO, else use MDB2
+			self::connectPDO();
+			self::$connection=self::$PDO;
+			self::$backend=self::BACKEND_PDO;
+		}else{
+			self::connectMDB2();
+			die('bar');
+			self::$connection=self::$MDB2;
+			self::$backend=self::BACKEND_MDB2;
+		}
+	}
+
+	/**
+	 * connect to the database using pdo
+	 */
+	private static function connectPDO(){
 		// The global data we need
-		$CONFIG_DBNAME = OC_Config::getValue( "dbname", "owncloud" );;
-		$CONFIG_DBHOST = OC_Config::getValue( "dbhost", "" );;
-		$CONFIG_DBUSER = OC_Config::getValue( "dbuser", "" );;
-		$CONFIG_DBPASSWORD = OC_Config::getValue( "dbpassword", "" );;
-		$CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" );;
-		global $SERVERROOT;
+		$name = OC_Config::getValue( "dbname", "owncloud" );
+		$host = OC_Config::getValue( "dbhost", "" );
+		$user = OC_Config::getValue( "dbuser", "" );
+		$pass = OC_Config::getValue( "dbpassword", "" );
+		$type = OC_Config::getValue( "dbtype", "sqlite" );
+		$SERVERROOT=OC::$SERVERROOT;
+		$datadir=OC_Config::getValue( "datadirectory", "$SERVERROOT/data" );
+		
+		// do nothing if the connection already has been established
+		if(!self::$PDO){
+			// Add the dsn according to the database type
+			switch($type){
+				case 'sqlite':
+					$dsn='sqlite2:'.$datadir.'/'.$name.'.db';
+					break;
+				case 'sqlite3':
+					$dsn='sqlite:'.$datadir.'/'.$name.'.db';
+					break;
+				case 'mysql':
+					$dsn='mysql:dbname='.$name.';host='.$host;
+					break;
+				case 'pgsql':
+					$dsn='pgsql:dbname='.$name.';host='.$host;
+					break;
+			}
+			try{
+				self::$PDO=new PDO($dsn,$user,$pass);
+			}catch(PDOException $e){
+				echo( '<b>can not connect to database, using '.$type.'. ('.$e->getMessage().')</center>');
+				die();
+			}
+			// We always, really always want associative arrays
+			self::$PDO->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_ASSOC);
+			self::$PDO->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
+		}
+		return true;
+	}
+	
+	/**
+	 * connect to the database using mdb2
+	 */
+	static private function connectMDB2(){
+		// The global data we need
+		$name = OC_Config::getValue( "dbname", "owncloud" );
+		$host = OC_Config::getValue( "dbhost", "" );
+		$user = OC_Config::getValue( "dbuser", "" );
+		$pass = OC_Config::getValue( "dbpassword", "" );
+		$type = OC_Config::getValue( "dbtype", "sqlite" );
+		$SERVERROOT=OC::$SERVERROOT;
 		$datadir=OC_Config::getValue( "datadirectory", "$SERVERROOT/data" );
 
 		// do nothing if the connection already has been established
-		if(!self::$DBConnection){
+		if(!self::$MDB2){
 			// Require MDB2.php (not required in the head of the file so we only load it when needed)
 			require_once('MDB2.php');
 
@@ -60,83 +125,55 @@ class OC_DB {
 			  'quote_identifier' => true  );
 
 			// Add the dsn according to the database type
-			if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){
-				// sqlite
-				$dsn = array(
-				  'phptype'  => $CONFIG_DBTYPE,
-				  'database' => "$datadir/$CONFIG_DBNAME.db",
-				  'mode' => '0644' );
-			}
-			elseif( $CONFIG_DBTYPE == 'mysql' ){
-				// MySQL
-				$dsn = array(
-				  'phptype'  => 'mysql',
-				  'username' => $CONFIG_DBUSER,
-				  'password' => $CONFIG_DBPASSWORD,
-				  'hostspec' => $CONFIG_DBHOST,
-				  'database' => $CONFIG_DBNAME );
-			}
-			elseif( $CONFIG_DBTYPE == 'pgsql' ){
-				// PostgreSQL
-				$dsn = array(
-				  'phptype'  => 'pgsql',
-				  'username' => $CONFIG_DBUSER,
-				  'password' => $CONFIG_DBPASSWORD,
-				  'hostspec' => $CONFIG_DBHOST,
-				  'database' => $CONFIG_DBNAME );
+			switch($type){
+				case 'sqlite':
+				case 'sqlite3':
+					$dsn = array(
+						'phptype'  => $type,
+						'database' => "$datadir/$name.db",
+						'mode' => '0644'
+					);
+					break;
+				case 'mysql':
+					$dsn = array(
+						'phptype'  => 'mysql',
+						'username' => $user,
+						'password' => $pass,
+						'hostspec' => $host,
+						'database' => $name
+					);
+					break;
+				case 'pgsql':
+					$dsn = array(
+						'phptype'  => 'pgsql',
+						'username' => $user,
+						'password' => $pass,
+						'hostspec' => $host,
+						'database' => $name
+					);
+					break;
 			}
-
+			
 			// Try to establish connection
-			self::$DBConnection = MDB2::factory( $dsn, $options );
-
+			self::$MDB2 = MDB2::factory( $dsn, $options );
+			
 			// Die if we could not connect
-			if( PEAR::isError( self::$DBConnection )){
-				echo( '<b>can not connect to database, using '.$CONFIG_DBTYPE.'. ('.self::$DBConnection->getUserInfo().')</center>');
-				$error = self::$DBConnection->getMessage();
+			if( PEAR::isError( self::$MDB2 )){
+				echo( '<b>can not connect to database, using '.$type.'. ('.self::$MDB2->getUserInfo().')</center>');
+				$error = self::$MDB2->getMessage();
 				error_log( $error);
-				error_log( self::$DBConnection->getUserInfo());
+				error_log( self::$MDB2->getUserInfo());
 				die( $error );
 			}
-
+			
 			// We always, really always want associative arrays
-			self::$DBConnection->setFetchMode(MDB2_FETCHMODE_ASSOC);
-
-			//we need to function module for query pre-procesing
-			self::$DBConnection->loadModule('Function');
+			self::$MDB2->setFetchMode(MDB2_FETCHMODE_ASSOC);
 		}
-
+		
 		// we are done. great!
 		return true;
 	}
 
-	/**
-	 * @brief SQL query
-	 * @param $query Query string
-	 * @returns result as MDB2_Result
-	 *
-	 * SQL query via MDB2 query()
-	 */
-	static public function query( $query ){
-		// Optimize the query
-		$query = self::processQuery( $query );
-
-		self::connect();
-		//fix differences between sql versions
-
-		// return the result
-		$result = self::$DBConnection->exec( $query );
-
-		// Die if we have an error (error means: bad query, not 0 results!)
-		if( PEAR::isError($result)) {
-			$entry = 'DB Error: "'.$result->getMessage().'"<br />';
-			$entry .= 'Offending command was: '.$query.'<br />';
-			error_log( $entry );
-			die( $entry );
-		}
-
-		return $result;
-	}
-
 	/**
 	 * @brief Prepare a SQL query
 	 * @param $query Query string
@@ -150,16 +187,27 @@ class OC_DB {
 
 		self::connect();
 		// return the result
-		$result = self::$DBConnection->prepare( $query );
-
-		// Die if we have an error (error means: bad query, not 0 results!)
-		if( PEAR::isError($result)) {
-			$entry = 'DB Error: "'.$result->getMessage().'"<br />';
-			$entry .= 'Offending command was: '.$query.'<br />';
-			error_log( $entry );
-			die( $entry );
+		if(self::$backend==self::BACKEND_MDB2){
+			$result = self::$connection->prepare( $query );
+
+			// Die if we have an error (error means: bad query, not 0 results!)
+			if( PEAR::isError($result)) {
+				$entry = 'DB Error: "'.$result->getMessage().'"<br />';
+				$entry .= 'Offending command was: '.$query.'<br />';
+				error_log( $entry );
+				die( $entry );
+			}
+		}else{
+			try{
+				$result=self::$connection->prepare($query);
+			}catch(PDOException $e){
+				$entry = 'DB Error: "'.$e->getMessage().'"<br />';
+				$entry .= 'Offending command was: '.$query.'<br />';
+				error_log( $entry );
+				die( $entry );
+			}
+			$result=new PDOStatementWrapper($result);
 		}
-
 		return $result;
 	}
 
@@ -174,7 +222,7 @@ class OC_DB {
 	 */
 	public static function insertid(){
 		self::connect();
-		return self::$DBConnection->lastInsertID();
+		return self::$connection->lastInsertId();
 	}
 
 	/**
@@ -185,26 +233,18 @@ class OC_DB {
 	 */
 	public static function disconnect(){
 		// Cut connection if required
-		if(self::$DBConnection){
-			self::$DBConnection->disconnect();
-			self::$DBConnection=false;
+		if(self::$connection){
+			if(self::$backend==self::BACKEND_MDB2){
+				self::$connection->disconnect();
+			}
+			self::$connection=false;
+			self::$mdb2=false;
+			self::$pdo=false;
 		}
 
 		return true;
 	}
 
-	/**
-	 * @brief Escapes bad characters
-	 * @param $string string with dangerous characters
-	 * @returns escaped string
-	 *
-	 * MDB2 escape()
-	 */
-	public static function escape( $string ){
-		self::connect();
-		return self::$DBConnection->escape( $string );
-	}
-
 	/**
 	 * @brief saves database scheme to xml file
 	 * @param $file name of file
@@ -283,13 +323,13 @@ class OC_DB {
 	 * Connects to a MDB2 database scheme
 	 */
 	private static function connectScheme(){
-		// We need a database connection
-		self::connect();
+		// We need a mdb2 database connection
+		self::connectMDB2();
 
 		// Connect if this did not happen before
 		if(!self::$schema){
 			require_once('MDB2/Schema.php');
-			self::$schema=MDB2_Schema::factory(self::$DBConnection);
+			self::$schema=MDB2_Schema::factory(self::$MDB2);
 		}
 
 		return true;
@@ -306,24 +346,25 @@ class OC_DB {
 	private static function processQuery( $query ){
 		self::connect();
 		// We need Database type and table prefix
-		$CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" );
-		$CONFIG_DBTABLEPREFIX = OC_Config::getValue( "dbtableprefix", "oc_" );
-		
-		// differences is getting the current timestamp
-		$query = str_replace( 'NOW()', self::$DBConnection->now(), $query );
-		$query = str_replace( 'now()', self::$DBConnection->now(), $query );
+		$type = OC_Config::getValue( "dbtype", "sqlite" );
+		$prefix = OC_Config::getValue( "dbtableprefix", "oc_" );
 		
-		// differences in escaping of table names (` for mysql)
-		// Problem: what if there is a ` in the value we want to insert?
-		if( $CONFIG_DBTYPE == 'sqlite' ){
+		// differences in escaping of table names ('`' for mysql) and getting the current timestamp
+		if( $type == 'sqlite' ){
 			$query = str_replace( '`', '\'', $query );
-		}
-		elseif( $CONFIG_DBTYPE == 'pgsql' ){
+			$query = str_replace( 'NOW()', 'datetime(\'now\')', $query );
+			$query = str_replace( 'now()', 'datetime(\'now\')', $query );
+		}elseif( $type == 'mysql' ){
+			$query = str_replace( 'NOW()', 'CURRENT_TIMESTAMP', $query );
+			$query = str_replace( 'now()', 'CURRENT_TIMESTAMP', $query );
+		}elseif( $type == 'pgsql' ){
 			$query = str_replace( '`', '"', $query );
+			$query = str_replace( 'NOW()', 'CURRENT_TIMESTAMP', $query );
+			$query = str_replace( 'now()', 'CURRENT_TIMESTAMP', $query );
 		}
 
 		// replace table name prefix
-		$query = str_replace( '*PREFIX*', $CONFIG_DBTABLEPREFIX, $query );
+		$query = str_replace( '*PREFIX*', $prefix, $query );
 
 		return $query;
 	}
@@ -333,9 +374,9 @@ class OC_DB {
 	 * @param string $tableNamme the table to drop
 	 */
 	public static function dropTable($tableName){
-		self::connect();
-		self::$DBConnection->loadModule('Manager');
-		self::$DBConnection->dropTable($tableName);
+		self::connectMDB2();
+		self::$MDB2->loadModule('Manager');
+		self::$MDB2->dropTable($tableName);
 	}
 	
 	/**
@@ -367,37 +408,76 @@ class OC_DB {
 	}
 	
 	/**
-	 * Start a transaction or set a savepoint.
-	 * @param string $savePoint (optional) name of the savepoint to set
+	 * Start a transaction
 	 */
-	public static function beginTransaction($savePoint=''){
+	public static function beginTransaction(){
 		self::connect();
-		if (!self::$DBConnection->supports('transactions')) {
+		if (self::$backend=self::BACKEND_MDB2 && !self::$connection->supports('transactions')) {
 			return false;
 		}
-		if($savePoint && !self::$DBConnection->supports('savepoints')){
-			return false;
-		}
-		if($savePoint){
-			self::$DBConnection->beginTransaction($savePoint);
-		}else{
-			self::$DBConnection->beginTransaction();
-		}
+		self::$connection->beginTransaction();
 	}
 
 	/**
-	 * Commit the database changes done during a transaction that is in progress or release a savepoint.
-	 * @param string $savePoint (optional) name of the savepoint to commit
+	 * Commit the database changes done during a transaction that is in progress
 	 */
 	public static function commit($savePoint=''){
 		self::connect();
-		if(!self::$DBConnection->inTransaction()){
+		if(!self::$connection->inTransaction()){
 			return false;
 		}
-		if($savePoint){
-			self::$DBConnection->commit($savePoint);
+		self::$connection->commit();
+	}
+}
+
+/**
+ * small wrapper around PDOStatement to make it behave ,more like an MDB2 Statement
+ */
+class PDOStatementWrapper{
+	private $statement=null;
+	private $lastArguments=array();
+
+	public function __construct($statement){
+		$this->statement=$statement;
+	}
+	
+	/**
+	 * make exucute return the result instead of a bool
+	 */
+	public function execute($input=array()){
+		$this->lastArguments=$input;
+		if(count($input)>0){
+			$this->statement->execute($input);
+		}else{
+			$this->statement->execute();
+		}
+		return $this;
+	}
+	
+	/**
+	 * provide numRows
+	 */
+	public function numRows(){
+		$regex = '/^SELECT\s+(?:ALL\s+|DISTINCT\s+)?(?:.*?)\s+FROM\s+(.*)$/i';
+		if (preg_match($regex, $this->statement->queryString, $output) > 0) {
+			$query = OC_DB::prepare("SELECT COUNT(*) FROM {$output[1]}", PDO::FETCH_NUM);
+			return $query->execute($this->lastArguments)->fetchColumn();
 		}else{
-			self::$DBConnection->commit();
+			return $this->statement->rowCount();
 		}
 	}
+	
+	/**
+	 * provide an alias for fetch
+	 */
+	public function fetchRow(){
+		return $this->statement->fetch();
+	}
+	
+	/**
+	 * pass all other function directly to the PDOStatement
+	 */
+	public function __call($name,$arguments){
+		return call_user_func_array(array($this->statement,$name),$arguments);
+	}
 }
-- 
cgit v1.2.3


From 5e3ecbbf96ff0268220a85aaef3c99c84e13ab44 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind1991@gmail.com>
Date: Sat, 17 Sep 2011 02:36:04 +0200
Subject: dont use numRows when it's not needed since it can be expensive

---
 lib/appconfig.php      | 10 ++++------
 lib/group/database.php |  2 +-
 lib/preferences.php    | 11 +++++------
 lib/user/database.php  |  4 ++--
 4 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/lib/appconfig.php b/lib/appconfig.php
index c64a15b8938..392782b2586 100644
--- a/lib/appconfig.php
+++ b/lib/appconfig.php
@@ -93,14 +93,12 @@ class OC_Appconfig{
 		// At least some magic in here :-)
 		$query = OC_DB::prepare( 'SELECT configvalue FROM *PREFIX*appconfig WHERE appid = ? AND configkey = ?' );
 		$result = $query->execute( array( $app, $key ));
-
-		if( !$result->numRows()){
+		$row = $result->fetchRow();
+		if($row){
+			return $row["configvalue"];
+		}else{
 			return $default;
 		}
-
-		$row = $result->fetchRow();
-
-		return $row["configvalue"];
 	}
 
 	/**
diff --git a/lib/group/database.php b/lib/group/database.php
index 8a9fc53d39f..7bf9c8bb5ce 100644
--- a/lib/group/database.php
+++ b/lib/group/database.php
@@ -56,7 +56,7 @@ class OC_Group_Database extends OC_Group_Backend {
 		$query = OC_DB::prepare( "SELECT gid FROM `*PREFIX*groups` WHERE gid = ?" );
 		$result = $query->execute( array( $gid ));
 
-		if( $result->numRows() > 0 ){
+		if( !$result->fetchRow() ){
 			// Can not add an existing group
 			return false;
 		}
diff --git a/lib/preferences.php b/lib/preferences.php
index d53cdd538e0..5af007f0223 100644
--- a/lib/preferences.php
+++ b/lib/preferences.php
@@ -116,14 +116,13 @@ class OC_Preferences{
 		// Try to fetch the value, return default if not exists.
 		$query = OC_DB::prepare( 'SELECT configvalue FROM *PREFIX*preferences WHERE userid = ? AND appid = ? AND configkey = ?' );
 		$result = $query->execute( array( $user, $app, $key ));
-
-		if( !$result->numRows()){
+		
+		$row = $result->fetchRow();
+		if($row){
+			return $row["configvalue"];
+		}else{
 			return $default;
 		}
-
-		$row = $result->fetchRow();
-
-		return $row["configvalue"];
 	}
 
 	/**
diff --git a/lib/user/database.php b/lib/user/database.php
index f29aaf00f05..452709c1fb9 100644
--- a/lib/user/database.php
+++ b/lib/user/database.php
@@ -106,8 +106,8 @@ class OC_User_Database extends OC_User_Backend {
 		$query = OC_DB::prepare( "SELECT uid FROM *PREFIX*users WHERE uid LIKE ? AND password = ?" );
 		$result = $query->execute( array( $uid, sha1( $password )));
 
-		if( $result->numRows() > 0 ){
-			$row=$result->fetchRow();
+		$row=$result->fetchRow();
+		if($row){
 			return $row['uid'];
 		}else{
 			return false;
-- 
cgit v1.2.3


From 39fa5d1c7fe6b0e3c90396eb16a875b74d803894 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind1991@gmail.com>
Date: Sun, 18 Sep 2011 14:05:38 +0200
Subject: always use mdb2 for installation

---
 lib/db.php | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lib/db.php b/lib/db.php
index 3c0ab8544af..20adff30787 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -43,13 +43,12 @@ class OC_DB {
 	 * Connects to the database as specified in config.php
 	 */
 	public static function connect(){
-		if(class_exists('PDO')){//check if we can use PDO, else use MDB2
+		if(class_exists('PDO') && OC_Config::getValue('installed', false)){//check if we can use PDO, else use MDB2 (instalation always needs to be done my mdb2)
 			self::connectPDO();
 			self::$connection=self::$PDO;
 			self::$backend=self::BACKEND_PDO;
 		}else{
 			self::connectMDB2();
-			die('bar');
 			self::$connection=self::$MDB2;
 			self::$backend=self::BACKEND_MDB2;
 		}
-- 
cgit v1.2.3


From 949494ccfd89d7ff4af26d8da83475e2ee382f73 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind1991@gmail.com>
Date: Sat, 8 Oct 2011 21:18:47 +0200
Subject: mimetype icon improvements

---
 core/img/filetypes/code-script.png | Bin 0 -> 859 bytes
 core/img/filetypes/php.png         | Bin 538 -> 0 bytes
 core/img/filetypes/script.png      | Bin 859 -> 0 bytes
 core/img/filetypes/text-x-php.png  | Bin 0 -> 538 bytes
 files/ajax/mimeicon.php            |   8 ++++++++
 files/js/filelist.js               |  12 ++++++++----
 files/js/files.js                  |  15 +++++++++------
 lib/helper.php                     |   6 ++++++
 8 files changed, 31 insertions(+), 10 deletions(-)
 create mode 100644 core/img/filetypes/code-script.png
 delete mode 100644 core/img/filetypes/php.png
 delete mode 100644 core/img/filetypes/script.png
 create mode 100644 core/img/filetypes/text-x-php.png
 create mode 100644 files/ajax/mimeicon.php

diff --git a/core/img/filetypes/code-script.png b/core/img/filetypes/code-script.png
new file mode 100644
index 00000000000..63fe6ceff5b
Binary files /dev/null and b/core/img/filetypes/code-script.png differ
diff --git a/core/img/filetypes/php.png b/core/img/filetypes/php.png
deleted file mode 100644
index 7868a25945c..00000000000
Binary files a/core/img/filetypes/php.png and /dev/null differ
diff --git a/core/img/filetypes/script.png b/core/img/filetypes/script.png
deleted file mode 100644
index 63fe6ceff5b..00000000000
Binary files a/core/img/filetypes/script.png and /dev/null differ
diff --git a/core/img/filetypes/text-x-php.png b/core/img/filetypes/text-x-php.png
new file mode 100644
index 00000000000..7868a25945c
Binary files /dev/null and b/core/img/filetypes/text-x-php.png differ
diff --git a/files/ajax/mimeicon.php b/files/ajax/mimeicon.php
new file mode 100644
index 00000000000..8724016b3a1
--- /dev/null
+++ b/files/ajax/mimeicon.php
@@ -0,0 +1,8 @@
+<?php
+
+// Init owncloud
+require_once('../../lib/base.php');
+
+print OC_Helper::mimetypeIcon($_GET['mime']);
+
+?>
diff --git a/files/js/filelist.js b/files/js/filelist.js
index 84762bb561d..e6da922700d 100644
--- a/files/js/filelist.js
+++ b/files/js/filelist.js
@@ -101,10 +101,14 @@ FileList={
 		$('.file_upload_filename').removeClass('highlight');
 	},
 	loadingDone:function(name){
-		$('tr[data-file="'+name+'"]').data('loading',false);
-		var mime=$('tr[data-file="'+name+'"]').data('mime');
-		$('tr[data-file="'+name+'"] td.filename').attr('style','background-image:url('+getMimeIcon(mime)+')');
-		$('tr[data-file="'+name+'"] td.filename').draggable(dragOptions);
+		var tr=$('tr[data-file="'+name+'"]');
+		tr.data('loading',false);
+		var mime=tr.data('mime');
+		tr.attr('data-mime',mime);
+		getMimeIcon(mime,function(path){
+			tr.find('td.filename').attr('style','background-image:url('+path+')');
+		});
+		tr.find('td.filename').draggable(dragOptions);
 	},
 	isLoading:function(name){
 		return $('tr[data-file="'+name+'"]').data('loading');
diff --git a/files/js/files.js b/files/js/files.js
index 9342642b4ff..079646070d4 100644
--- a/files/js/files.js
+++ b/files/js/files.js
@@ -473,11 +473,14 @@ function relative_modified_date(timestamp) {
 	else { return diffyears+' '+t('files','years ago'); }
 }
 
-function getMimeIcon(mime){
-	mime=mime.substr(0,mime.indexOf('/'));
-	var knownMimes=['image','audio'];
-	if(knownMimes.indexOf(mime)==-1){
-		mime='file';
+function getMimeIcon(mime, ready){
+	if(getMimeIcon.cache[mime]){
+		ready(getMimeIcon.cache[mime]);
+	}else{
+		$.get( OC.filePath('files','ajax','mimeicon.php')+'?mime='+mime, function(path){
+			getMimeIcon.cache[mime]=path;
+			ready(getMimeIcon.cache[mime]);
+		});
 	}
-	return OC.imagePath('core','filetypes/'+mime);
 }
+getMimeIcon.cache={};
diff --git a/lib/helper.php b/lib/helper.php
index c2a81ba3306..5b3e394cafd 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -96,6 +96,12 @@ class OC_Helper {
 	 * Returns the path to the image of this file type.
 	 */
 	public static function mimetypeIcon( $mimetype ){
+		$alias=array('application/xml'=>'code/xml');
+// 		echo $mimetype;
+		if(isset($alias[$mimetype])){
+			$mimetype=$alias[$mimetype];
+// 			echo $mimetype;
+		}
 		// Replace slash with a minus
 		$mimetype = str_replace( "/", "-", $mimetype );
 
-- 
cgit v1.2.3


From ffb9a0475e046d2cf88bbc5801905358fe4ce1e0 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind1991@gmail.com>
Date: Thu, 13 Oct 2011 16:31:01 +0200
Subject: webdav workaround for apache+php-cgi

---
 .htaccess     | 4 ++++
 lib/base.php  | 8 ++++++++
 lib/setup.php | 4 ++++
 3 files changed, 16 insertions(+)

diff --git a/.htaccess b/.htaccess
index 8763a8bcde5..dd49442e371 100644
--- a/.htaccess
+++ b/.htaccess
@@ -5,4 +5,8 @@ php_value post_max_size 512M
 php_value memory_limit 128M
 SetEnv htaccessWorking true
 </IfModule>
+<IfModule !mod_php5.c>
+RewriteEngine on
+RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization},last]
+</IfModule>
 Options -Indexes
diff --git a/lib/base.php b/lib/base.php
index 0156febe231..57a3ae8669b 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -81,6 +81,14 @@ class OC{
 		date_default_timezone_set('Europe/Berlin');
 		ini_set('arg_separator.output','&amp;');
 
+		//set http auth headers for apache+php-cgi work around
+		if (preg_match('/Basic\s+(.*)$/i', $_SERVER['HTTP_AUTHORIZATION'], $matches))
+		{
+			list($name, $password) = explode(':', base64_decode($matches[1]));
+			$_SERVER['PHP_AUTH_USER'] = strip_tags($name);
+			$_SERVER['PHP_AUTH_PW'] = strip_tags($password);
+		}
+
 		// calculate the documentroot
 		OC::$DOCUMENTROOT=realpath($_SERVER['DOCUMENT_ROOT']);
 		OC::$SERVERROOT=str_replace("\\",'/',substr(__FILE__,0,-13));
diff --git a/lib/setup.php b/lib/setup.php
index 355d979dc65..252eaaeea18 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -273,6 +273,10 @@ class OC_Setup {
 		$content.= "php_value post_max_size 512M\n";
 		$content.= "SetEnv htaccessWorking true\n";
 		$content.= "</IfModule>\n";
+		$content.= "<IfModule !mod_php5.c>\n";
+		$content.= "RewriteEngine on\n";
+		$content.= "RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization},last]\n";
+		$content.= "</IfModule>\n";
 		$content.= "Options -Indexes\n";
 		@file_put_contents(OC::$SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it
 
-- 
cgit v1.2.3


From ea8461e83d83e17820518b844f7bb0d71685a88c Mon Sep 17 00:00:00 2001
From: Georg Ehrke <georg.stefan.germany@googlemail.com>
Date: Fri, 14 Oct 2011 13:46:28 +0200
Subject: scrolling in calendar

---
 apps/calendar/js/calendar.js | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/apps/calendar/js/calendar.js b/apps/calendar/js/calendar.js
index efddac40426..512946ad1be 100644
--- a/apps/calendar/js/calendar.js
+++ b/apps/calendar/js/calendar.js
@@ -454,6 +454,43 @@ Calendar={
 				  });
 			}
 		},
+		initscroll:function(){ 
+			if(window.addEventListener)
+				document.addEventListener('DOMMouseScroll', Calendar.UI.scrollcalendar);
+			//}else{
+				document.onmousewheel = Calendar.UI.scrollcalendar;
+			//}
+		},
+		scrollcalendar:function(event){
+			var direction;
+			if(event.detail){
+				if(event.detail < 0){
+					direction = "top";
+				}else{
+					direction = "down";
+				}
+			}
+			if (event.wheelDelta){
+				if(event.wheelDelta > 0){
+					direction = "top";
+				}else{
+					direction = "down";
+				}
+			}
+			if(Calendar.UI.currentview == "onemonthview"){
+				if(direction == "down"){
+					Calendar.UI.updateDate("forward");
+				}else{
+					Calendar.UI.updateDate("backward");
+				}
+			}else if(Calendar.UI.currentview == "oneweekview"){
+				if(direction == "down"){
+					Calendar.UI.updateDate("forward");
+				}else{
+					Calendar.UI.updateDate("backward");
+				}
+			}
+		},
 		Calendar:{
 			overview:function(){
 				if($('#choosecalendar_dialog').dialog('isOpen') == true){
@@ -935,6 +972,7 @@ Calendar={
 $(document).ready(function(){
 	$('#listview #more_before').click(Calendar.UI.List.renderMoreBefore);
 	$('#listview #more_after').click(Calendar.UI.List.renderMoreAfter);
+	Calendar.UI.initscroll();
 });
 //event vars
 Calendar.UI.loadEvents();
-- 
cgit v1.2.3


From 8d4039b678c2e35e3fd6834d56b8db6879beab89 Mon Sep 17 00:00:00 2001
From: Brice Maron <brice@bmaron.net>
Date: Fri, 14 Oct 2011 23:51:51 +0200
Subject: Add loading message to image lightbox and tweak events

---
 apps/files_imageviewer/css/lightbox.css |  11 ++++++++++-
 apps/files_imageviewer/js/lightbox.js   |  17 ++++++++++++-----
 core/img/loading-dark.gif               | Bin 0 -> 673 bytes
 3 files changed, 22 insertions(+), 6 deletions(-)
 create mode 100644 core/img/loading-dark.gif

diff --git a/apps/files_imageviewer/css/lightbox.css b/apps/files_imageviewer/css/lightbox.css
index a6e844a2e28..d96dd051b1e 100644
--- a/apps/files_imageviewer/css/lightbox.css
+++ b/apps/files_imageviewer/css/lightbox.css
@@ -20,4 +20,13 @@
 	margin-left:auto;
 	margin-right:auto;
 	z-index:9999;
-}
\ No newline at end of file
+}
+
+#lightbox_loader{
+  text-align:center;
+  position:fixed;
+  top: 40%;
+  left: 50%;
+  color:white;
+}
+#lightbox_loader img { margin-right: 1em;}
\ No newline at end of file
diff --git a/apps/files_imageviewer/js/lightbox.js b/apps/files_imageviewer/js/lightbox.js
index 847954d2f15..4f079b6d8af 100644
--- a/apps/files_imageviewer/js/lightbox.js
+++ b/apps/files_imageviewer/js/lightbox.js
@@ -2,11 +2,17 @@
 var lightBoxShown=false;
 $(document).ready(function() {
 	images={};//image cache
-	var overlay=$('<div id="lightbox_overlay"/>');
+	loading_str = t('files_imageviewer','Loading');
+	var overlay=$('<div id="lightbox_overlay"><div id="lightbox_loader"><img /></div></div>');
+	overlay.find('#lightbox_loader img')
+		.attr('src',OC.imagePath('core', 'loading-dark.gif'))
+		.attr('alt',loading_str)
+		.after(loading_str);
 	$( 'body' ).append(overlay);
 	var container=$('<div id="lightbox"/>');
 	$( 'body' ).append(container);
-	$( 'body' ).click(hideLightbox);
+	$( '#lightbox_overlay' ).click(hideLightbox);
+	$( '#lightbox' ).click(hideLightbox);
 	if(typeof FileActions!=='undefined'){
 		FileActions.register('image','View','',function(filename){
 			viewImage($('#dir').val(),filename);
@@ -35,7 +41,8 @@ function viewImage(dir,file){
 		var img = new Image();
 		img.onload = function(){
 			images[location]=img;
-			showLightbox(container,img);
+			if($('#lightbox_overlay').is(':visible'))
+				showLightbox(container,img);
 		}
 		img.src = location;
 	}else{
@@ -67,10 +74,10 @@ function showLightbox(container,img){
 }
 
 function hideLightbox(event){
-	if(lightBoxShown){
+	if(event){
 		event.stopPropagation();
 		$('#lightbox_overlay').hide();
 		$('#lightbox').hide();
 		lightBoxShown=false;
 	}
-}
+}
\ No newline at end of file
diff --git a/core/img/loading-dark.gif b/core/img/loading-dark.gif
new file mode 100644
index 00000000000..5fe86acabc4
Binary files /dev/null and b/core/img/loading-dark.gif differ
-- 
cgit v1.2.3


From 9cfae56df588c7ddb6e6199ab79afaa39cd7f94e Mon Sep 17 00:00:00 2001
From: Bart Visscher <bartv@thisnet.nl>
Date: Fri, 14 Oct 2011 14:56:18 +0200
Subject: Fix calendar colors with new calendar

---
 apps/calendar/ajax/editcalendar.php | 11 +----------
 apps/calendar/ajax/newcalendar.php  |  2 ++
 apps/calendar/js/calendar.js        |  3 ++-
 apps/calendar/lib/calendar.php      | 12 ++++++++++++
 4 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/apps/calendar/ajax/editcalendar.php b/apps/calendar/ajax/editcalendar.php
index 5f61cf50135..d23e5287868 100644
--- a/apps/calendar/ajax/editcalendar.php
+++ b/apps/calendar/ajax/editcalendar.php
@@ -11,17 +11,8 @@ $l10n = new OC_L10N('calendar');
 if(!OC_USER::isLoggedIn()) {
 	die("<script type=\"text/javascript\">document.location = oc_webroot;</script>");
 }
-$calendarcolor_options = array(
-	'ff0000', // "Red"
-	'00ff00', // "Green"
-	'ffff00', // "Yellow"
-	'808000', // "Olive"
-	'ffa500', // "Orange"
-	'ff7f50', // "Coral"
-	'ee82ee', // "Violet"
-	'ecc255', // dark yellow
-);
 OC_JSON::checkAppEnabled('calendar');
+$calendarcolor_options = OC_Calendar_Calendar::getCalendarColorOptions();
 $calendar = OC_Calendar_Calendar::findCalendar($_GET['calendarid']);
 $tmpl = new OC_Template("calendar", "part.editcalendar");
 $tmpl->assign('new', false);
diff --git a/apps/calendar/ajax/newcalendar.php b/apps/calendar/ajax/newcalendar.php
index f00dd0fb862..a7935c95672 100644
--- a/apps/calendar/ajax/newcalendar.php
+++ b/apps/calendar/ajax/newcalendar.php
@@ -12,6 +12,7 @@ if(!OC_USER::isLoggedIn()) {
 	die("<script type=\"text/javascript\">document.location = oc_webroot;</script>");
 }
 OC_JSON::checkAppEnabled('calendar');
+$calendarcolor_options = OC_Calendar_Calendar::getCalendarColorOptions();
 $calendar = array(
 	'id' => 'new',
 	'displayname' => '',
@@ -19,6 +20,7 @@ $calendar = array(
 );
 $tmpl = new OC_Template('calendar', 'part.editcalendar');
 $tmpl->assign('new', true);
+$tmpl->assign('calendarcolor_options', $calendarcolor_options);
 $tmpl->assign('calendar', $calendar);
 $tmpl->printPage();
 ?>
diff --git a/apps/calendar/js/calendar.js b/apps/calendar/js/calendar.js
index efddac40426..1582dcd67b3 100644
--- a/apps/calendar/js/calendar.js
+++ b/apps/calendar/js/calendar.js
@@ -479,7 +479,8 @@ Calendar={
 			},
 			newCalendar:function(object){
 				var tr = $(document.createElement('tr'))
-					.load(OC.filePath('calendar', 'ajax', 'newcalendar.php'));
+					.load(OC.filePath('calendar', 'ajax', 'newcalendar.php'),
+						function(){Calendar.UI.Calendar.colorPicker(this)});
 				$(object).closest('tr').after(tr).hide();
 			},
 			edit:function(object, calendarid){
diff --git a/apps/calendar/lib/calendar.php b/apps/calendar/lib/calendar.php
index 959cb14bf8f..c19c0e73c08 100644
--- a/apps/calendar/lib/calendar.php
+++ b/apps/calendar/lib/calendar.php
@@ -228,4 +228,16 @@ class OC_Calendar_Calendar{
 		list($prefix,$userid) = Sabre_DAV_URLUtil::splitPath($principaluri);
 		return $userid;
 	}
+	public static function getCalendarColorOptions(){
+		return array(
+			'ff0000', // "Red"
+			'00ff00', // "Green"
+			'ffff00', // "Yellow"
+			'808000', // "Olive"
+			'ffa500', // "Orange"
+			'ff7f50', // "Coral"
+			'ee82ee', // "Violet"
+			'ecc255', // dark yellow
+		);
+	}
 }
-- 
cgit v1.2.3


From c383543ec9d56db12fdf6d796ea95667dd3f1c45 Mon Sep 17 00:00:00 2001
From: Bart Visscher <bartv@thisnet.nl>
Date: Sat, 15 Oct 2011 11:45:50 +0200
Subject: Remove unused parameter

---
 apps/calendar/js/calendar.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/apps/calendar/js/calendar.js b/apps/calendar/js/calendar.js
index 1582dcd67b3..604f7d2668c 100644
--- a/apps/calendar/js/calendar.js
+++ b/apps/calendar/js/calendar.js
@@ -112,7 +112,7 @@ Calendar={
 		formatTime:function(date){
 			return date[3] + ':' + date[4];
 		},
-		updateView:function(task) {
+		updateView:function() {
 			this.current.removeEvents();
 			this.current.renderCal();
 			this.current.showEvents();
-- 
cgit v1.2.3


From 5d09a5e37e2afd7a54a022361d455c96758fd7a8 Mon Sep 17 00:00:00 2001
From: Brice Maron <brice@bmaron.net>
Date: Sun, 16 Oct 2011 13:12:11 +0200
Subject: Add some color in error messages + img for hints

---
 core/css/styles.css       |   5 ++-
 core/img/actions/info.png | Bin 0 -> 483 bytes
 core/img/actions/info.svg | 103 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 106 insertions(+), 2 deletions(-)
 create mode 100644 core/img/actions/info.png
 create mode 100644 core/img/actions/info.svg

diff --git a/core/css/styles.css b/core/css/styles.css
index 539ae580aa0..ea09a1f3636 100644
--- a/core/css/styles.css
+++ b/core/css/styles.css
@@ -121,5 +121,6 @@ div.jp-play-bar, div.jp-seek-bar { padding:0; }
 .pager { list-style:none; float:right; display:inline; margin:.7em 13em 0 0; }
 .pager li { display:inline-block; }
 
-li.error { width:640px; margin:4em auto; padding:1em 1em 1em 4em; background:#ffe .8em .8em no-repeat; border:1px solid #ccc; -moz-border-radius:10px; -webkit-border-radius:10px; border-radius:10px; }
-.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { overflow: hidden; text-overflow: ellipsis; }
\ No newline at end of file
+li.error { width:640px; margin:4em auto; padding:1em 1em 1em 4em; background:#ffe .8em .8em no-repeat; color: #FF3B3B; border:1px solid #ccc; -moz-border-radius:10px; -webkit-border-radius:10px; border-radius:10px; }
+.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { overflow: hidden; text-overflow: ellipsis; }
+.hint { background-image: url('/core/img/actions/info.png'); background-repeat:no-repeat; color: #777777; padding-left: 25px; background-position: 0 0.3em;}
\ No newline at end of file
diff --git a/core/img/actions/info.png b/core/img/actions/info.png
new file mode 100644
index 00000000000..f27c73d6d13
Binary files /dev/null and b/core/img/actions/info.png differ
diff --git a/core/img/actions/info.svg b/core/img/actions/info.svg
new file mode 100644
index 00000000000..4f5e644b25f
--- /dev/null
+++ b/core/img/actions/info.svg
@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:xlink="http://www.w3.org/1999/xlink"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="16px"
+   height="16px"
+   id="svg3281"
+   version="1.1"
+   inkscape:version="0.48.2 r9819"
+   sodipodi:docname="info.svg"
+   inkscape:export-filename="/home/emerzh/Documents/img/actions/info.png"
+   inkscape:export-xdpi="250.02"
+   inkscape:export-ydpi="250.02">
+  <defs
+     id="defs3283">
+    <linearGradient
+       id="linearGradient4567">
+      <stop
+         style="stop-color:#000000;stop-opacity:1;"
+         offset="0"
+         id="stop4569" />
+      <stop
+         id="stop4575"
+         offset="1"
+         style="stop-color:#363636;stop-opacity:1;" />
+    </linearGradient>
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient4567"
+       id="linearGradient4573"
+       x1="-0.2628715"
+       y1="6.7423267"
+       x2="14.00297"
+       y2="6.7423267"
+       gradientUnits="userSpaceOnUse" />
+  </defs>
+  <sodipodi:namedview
+     id="base"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageopacity="0.0"
+     inkscape:pageshadow="2"
+     inkscape:zoom="16.28125"
+     inkscape:cx="10.49929"
+     inkscape:cy="9.3022797"
+     inkscape:current-layer="layer1"
+     showgrid="true"
+     inkscape:grid-bbox="true"
+     inkscape:document-units="px"
+     inkscape:window-width="1920"
+     inkscape:window-height="1018"
+     inkscape:window-x="-5"
+     inkscape:window-y="-10"
+     inkscape:window-maximized="1" />
+  <metadata
+     id="metadata3286">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title></dc:title>
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     id="layer1"
+     inkscape:label="Layer 1"
+     inkscape:groupmode="layer">
+    <path
+       sodipodi:type="arc"
+       style="fill:url(#linearGradient4573);fill-opacity:1;stroke:none;opacity:0.7"
+       id="path4057"
+       sodipodi:cx="6.8700495"
+       sodipodi:cy="6.7423267"
+       sodipodi:rx="4.9329209"
+       sodipodi:ry="4.9329209"
+       d="m 11.80297,6.7423267 a 4.9329209,4.9329209 0 1 1 -9.8658415,0 4.9329209,4.9329209 0 1 1 9.8658415,0 z"
+       transform="matrix(1.5203974,0,0,1.5203974,-2.4452051,-2.2510159)" />
+    <text
+       xml:space="preserve"
+       style="font-size:15.25139999px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
+       x="5.9410372"
+       y="13.850288"
+       id="text4577"
+       sodipodi:linespacing="125%"><tspan
+         sodipodi:role="line"
+         id="tspan4579"
+         x="5.9410372"
+         y="13.850288"
+         style="font-size:15.25139999px;fill:#ffffff;fill-opacity:1">i</tspan></text>
+  </g>
+</svg>
-- 
cgit v1.2.3


From 543537ef29bb6f0d9b93a5329e7443e6742452ab Mon Sep 17 00:00:00 2001
From: Brice Maron <brice@bmaron.net>
Date: Sun, 16 Oct 2011 20:23:43 +0200
Subject: Fix installer for postgresql : correct table detection query

---
 lib/setup.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/setup.php b/lib/setup.php
index 252eaaeea18..d13502c4adf 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -135,7 +135,7 @@ class OC_Setup {
 				$dbpass = $options['dbpass'];
 				$dbname = $options['dbname'];
 				$dbhost = $options['dbhost'];
-				$dbtableprefix = $options['dbtableprefix'];
+				$dbtableprefix = 'oc_';
 				OC_CONFIG::setValue('dbname', $dbname);
 				OC_CONFIG::setValue('dbhost', $dbhost);
 				OC_CONFIG::setValue('dbtableprefix', $dbtableprefix);
@@ -178,7 +178,7 @@ class OC_Setup {
 					}
 
 					//fill the database if needed
-					$query="SELECT * FROM {$dbtableprefix}users";
+					$query = "SELECT relname FROM pg_class WHERE relname='{$dbtableprefix}users' limit 1";
 					$result = pg_query($connection, $query);
 					if(!$result) {
 						OC_DB::createDbFromStructure('db_structure.xml');
-- 
cgit v1.2.3


From c105268a1dc7e68bd9dc3ff3ebe65cffcce33568 Mon Sep 17 00:00:00 2001
From: Brice Maron <brice@bmaron.net>
Date: Sun, 16 Oct 2011 21:06:48 +0200
Subject: Fetch prefix from config at installation instead of a hardcoded value

---
 lib/setup.php | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/setup.php b/lib/setup.php
index d13502c4adf..92487c69162 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -82,10 +82,10 @@ class OC_Setup {
 				$dbpass = $options['dbpass'];
 				$dbname = $options['dbname'];
 				$dbhost = $options['dbhost'];
-				$dbtableprefix = 'oc_';
+				$dbtableprefix = OC_Config::gsetValue('dbtableprefix','oc_');
 				OC_Config::setValue('dbname', $dbname);
 				OC_Config::setValue('dbhost', $dbhost);
-				OC_Config::setValue('dbtableprefix', 'oc_');
+				OC_Config::setValue('dbtableprefix', $dbtableprefix);
 
 				//check if the database user has admin right
 				$connection = @mysql_connect($dbhost, $dbuser, $dbpass);
@@ -135,7 +135,7 @@ class OC_Setup {
 				$dbpass = $options['dbpass'];
 				$dbname = $options['dbname'];
 				$dbhost = $options['dbhost'];
-				$dbtableprefix = 'oc_';
+				$dbtableprefix = OC_Config::getValue('dbtableprefix','oc_');
 				OC_CONFIG::setValue('dbname', $dbname);
 				OC_CONFIG::setValue('dbhost', $dbhost);
 				OC_CONFIG::setValue('dbtableprefix', $dbtableprefix);
-- 
cgit v1.2.3


From 90c54ade673983d28d1eab810705fb6185632d2e Mon Sep 17 00:00:00 2001
From: Brice Maron <brice@bmaron.net>
Date: Sun, 16 Oct 2011 21:08:07 +0200
Subject: Fix typo in getting var from config

---
 lib/setup.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/setup.php b/lib/setup.php
index 92487c69162..2dcedb9b820 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -82,7 +82,7 @@ class OC_Setup {
 				$dbpass = $options['dbpass'];
 				$dbname = $options['dbname'];
 				$dbhost = $options['dbhost'];
-				$dbtableprefix = OC_Config::gsetValue('dbtableprefix','oc_');
+				$dbtableprefix = OC_Config::getValue('dbtableprefix','oc_');
 				OC_Config::setValue('dbname', $dbname);
 				OC_Config::setValue('dbhost', $dbhost);
 				OC_Config::setValue('dbtableprefix', $dbtableprefix);
-- 
cgit v1.2.3


From d11a8f4103c4de974f2f52c30defaeb7c1055819 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind1991@gmail.com>
Date: Sun, 16 Oct 2011 20:47:25 +0200
Subject: some minor tweaks to oc_db

---
 lib/db.php | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/db.php b/lib/db.php
index 20adff30787..ef6d1dcc8b7 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -43,6 +43,9 @@ class OC_DB {
 	 * Connects to the database as specified in config.php
 	 */
 	public static function connect(){
+		if(self::$connection){
+			return;
+		}
 		if(class_exists('PDO') && OC_Config::getValue('installed', false)){//check if we can use PDO, else use MDB2 (instalation always needs to be done my mdb2)
 			self::connectPDO();
 			self::$connection=self::$PDO;
@@ -64,8 +67,7 @@ class OC_DB {
 		$user = OC_Config::getValue( "dbuser", "" );
 		$pass = OC_Config::getValue( "dbpassword", "" );
 		$type = OC_Config::getValue( "dbtype", "sqlite" );
-		$SERVERROOT=OC::$SERVERROOT;
-		$datadir=OC_Config::getValue( "datadirectory", "$SERVERROOT/data" );
+		$datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT.'/data' );
 		
 		// do nothing if the connection already has been established
 		if(!self::$PDO){
-- 
cgit v1.2.3


From 820cd0fb75bac88b4debe8f3fb28c1118b8587fa Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind1991@gmail.com>
Date: Sun, 16 Oct 2011 20:49:14 +0200
Subject: provide a logging mechanism

---
 lib/app.php                |  2 ++
 lib/log.php                | 71 ++++++++++++++++++++++++++++++++++++++++++++++
 settings/log.php           | 41 ++++++++++++++++++++++++++
 settings/templates/log.php | 29 +++++++++++++++++++
 4 files changed, 143 insertions(+)
 create mode 100644 lib/log.php
 create mode 100644 settings/log.php
 create mode 100644 settings/templates/log.php

diff --git a/lib/app.php b/lib/app.php
index b9eea483a55..51dcb8d5732 100644
--- a/lib/app.php
+++ b/lib/app.php
@@ -222,6 +222,8 @@ class OC_App{
 				$settings[] = array( "id" => "core_users", "order" => 2, "href" => OC_Helper::linkTo( "settings", "users.php" ), "name" => $l->t("Users"), "icon" => OC_Helper::imagePath( "settings", "users.svg" ));
 				// admin apps menu
 				$settings[] = array( "id" => "core_apps", "order" => 3, "href" => OC_Helper::linkTo( "settings", "apps.php?installed" ), "name" => $l->t("Apps"), "icon" => OC_Helper::imagePath( "settings", "apps.svg" ));
+				// admin log menu
+				$settings[] = array( "id" => "core_log", "order" => 4, "href" => OC_Helper::linkTo( "settings", "log.php" ), "name" => $l->t("Log"), "icon" => OC_Helper::imagePath( "log", "apps.svg" ));
 
 				// if there're some admin forms
 				if(!empty(self::$adminForms))
diff --git a/lib/log.php b/lib/log.php
new file mode 100644
index 00000000000..a951b676037
--- /dev/null
+++ b/lib/log.php
@@ -0,0 +1,71 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Robin Appelman
+ * @copyright 2011 Robin Appelman icewind1991@gmail.com
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+/**
+ *logging utilities
+ *
+ * Log is saved at data/owncloud.log (on default)
+ */
+
+class OC_Log{
+	const DEBUG=0;
+	const INFO=1;
+	const WARN=2;
+	const ERROR=3;
+	const FATAL=4;
+
+	/**
+	 * write a message in the log
+	 * @param string $app
+	 * @param string $message
+	 * @param int level
+	 */
+	public static function write($app,$message,$level){
+		$minLevel=OC_Config::getValue( "loglevel", 2 );
+		if($level>$minLevel){
+			$datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT.'/data' );
+			$logFile=OC_Config::getValue( "logfile", $datadir.'/owncloud.log' );
+			$entry=array('app'=>$app,'message'=>$message,'level'=>$level,'time'=>time());
+			$fh=fopen($logFile,'a');
+			fwrite($fh,json_encode($entry)."\n");
+			fclose($fh);
+		}
+	}
+	
+	public static function getEntries(){
+		$datadir=OC_Config::getValue( "datadirectory", OC::$SERVERROOT.'/data' );
+		$logFile=OC_Config::getValue( "logfile", $datadir.'/owncloud.log' );
+		$entries=array();
+		if(!file_exists($logFile)){
+			return array();
+		}
+		$fh=fopen($logFile,'r');
+		while(!feof($fh)){
+			$line=fgets($fh);
+			if($line){
+				$entries[]=json_decode($line);
+			}
+		}
+		fclose($fh);
+		return $entries;
+	}
+}
diff --git a/settings/log.php b/settings/log.php
new file mode 100644
index 00000000000..e181a5a4967
--- /dev/null
+++ b/settings/log.php
@@ -0,0 +1,41 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Robin Appelman
+ * @copyright 2011 Robin Appelman icewind1991@gmail.com
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+require_once('../lib/base.php');
+OC_Util::checkAdminUser();
+
+// Load the files we need
+OC_Util::addStyle( "settings", "settings" );
+OC_Util::addScript( "settings", "apps" );
+OC_App::setActiveNavigationEntry( "core_log" );
+
+$entries=OC_Log::getEntries();
+
+function compareEntries($a,$b){
+	return $b->time-$a>time;
+}
+usort($entries, 'compareEntries');
+
+$tmpl = new OC_Template( "settings", "log", "user" );
+$tmpl->assign('entries',$entries);
+
+$tmpl->printPage();
diff --git a/settings/templates/log.php b/settings/templates/log.php
new file mode 100644
index 00000000000..467f594186c
--- /dev/null
+++ b/settings/templates/log.php
@@ -0,0 +1,29 @@
+<?php /**
+ * Copyright (c) 2011, Robin Appelman <icewind1991@gmail.com>
+ * This file is licensed under the Affero General Public License version 3 or later.
+ * See the COPYING-README file.
+ */
+$levels=array('DEBUG','INFO','WARN','ERROR','FATAL');
+?>
+
+<div id="controls">
+	
+</div>
+<table>
+	<?php foreach($_['entries'] as $entry):?>
+		<tr>
+			<td>
+				<?php echo $levels[$entry->level];?>
+			</td>
+			<td>
+				<?php echo $entry->app;?>
+			</td>
+			<td>
+				<?php echo $entry->message;?>
+			</td>
+			<td>
+				<?php echo $l->l('datetime',$entry->time);?>
+			</td>
+		</tr>
+	<?php endforeach;?>
+</table>
\ No newline at end of file
-- 
cgit v1.2.3


From d9372ac76606cd10e680852dde090171f04f5dee Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind1991@gmail.com>
Date: Sun, 16 Oct 2011 21:08:44 +0200
Subject: make log level configurable

---
 lib/app.php                   |  5 +----
 settings/admin.php            |  2 ++
 settings/ajax/setloglevel.php | 15 +++++++++++++++
 settings/js/admin.js          |  5 +++++
 settings/templates/admin.php  | 17 +++++++++++++++--
 settings/templates/log.php    |  2 +-
 6 files changed, 39 insertions(+), 7 deletions(-)
 create mode 100644 settings/ajax/setloglevel.php
 create mode 100644 settings/js/admin.js

diff --git a/lib/app.php b/lib/app.php
index 51dcb8d5732..30ebcf032b3 100644
--- a/lib/app.php
+++ b/lib/app.php
@@ -225,10 +225,7 @@ class OC_App{
 				// admin log menu
 				$settings[] = array( "id" => "core_log", "order" => 4, "href" => OC_Helper::linkTo( "settings", "log.php" ), "name" => $l->t("Log"), "icon" => OC_Helper::imagePath( "log", "apps.svg" ));
 
-				// if there're some admin forms
-				if(!empty(self::$adminForms))
-					// admins menu
-					$settings[]=array( "id" => "admin", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "admin.php" ), "name" => $l->t("Admin"), "icon" => OC_Helper::imagePath( "settings", "admin.svg" ));
+				$settings[]=array( "id" => "admin", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "admin.php" ), "name" => $l->t("Admin"), "icon" => OC_Helper::imagePath( "settings", "admin.svg" ));
 			}
  		}
 
diff --git a/settings/admin.php b/settings/admin.php
index 81ed6aa9516..9ee79002b5e 100644
--- a/settings/admin.php
+++ b/settings/admin.php
@@ -9,10 +9,12 @@ require_once('../lib/base.php');
 OC_Util::checkAdminUser();
 
 OC_Util::addStyle( "settings", "settings" );
+OC_Util::addScript( "settings", "admin" );
 OC_App::setActiveNavigationEntry( "admin" );
 
 $tmpl = new OC_Template( 'settings', 'admin', 'user');
 $forms=OC_App::getForms('admin');
+$tmpl->assign('loglevel',OC_Config::getValue( "loglevel", 2 ));
 $tmpl->assign('forms',array());
 foreach($forms as $form){
 	$tmpl->append('forms',$form);
diff --git a/settings/ajax/setloglevel.php b/settings/ajax/setloglevel.php
new file mode 100644
index 00000000000..298cbd64738
--- /dev/null
+++ b/settings/ajax/setloglevel.php
@@ -0,0 +1,15 @@
+<?php
+/**
+ * Copyright (c) 2011, Robin Appelman <icewind1991@gmail.com>
+ * This file is licensed under the Affero General Public License version 3 or later.
+ * See the COPYING-README file.
+ */
+
+require_once('../../lib/base.php');
+OC_Util::checkAdminUser();
+
+OC_Config::setValue( 'loglevel', $_POST['level'] );
+
+echo 'true';
+
+?>
\ No newline at end of file
diff --git a/settings/js/admin.js b/settings/js/admin.js
new file mode 100644
index 00000000000..a3585f7e1c2
--- /dev/null
+++ b/settings/js/admin.js
@@ -0,0 +1,5 @@
+$(document).ready(function(){
+	$('#loglevel').change(function(){
+		$.post(OC.filePath('settings','ajax','setloglevel.php'), { level: $(this).val() } );
+	})
+});
\ No newline at end of file
diff --git a/settings/templates/admin.php b/settings/templates/admin.php
index 98acd541e36..e3fd60fefce 100644
--- a/settings/templates/admin.php
+++ b/settings/templates/admin.php
@@ -2,8 +2,21 @@
  * Copyright (c) 2011, Robin Appelman <icewind1991@gmail.com>
  * This file is licensed under the Affero General Public License version 3 or later.
  * See the COPYING-README file.
- */?>
+ */
+$levels=array('Debug','Info','Warning','Error','Fatal');
+?>
 
 <?php foreach($_['forms'] as $form){
 	echo $form;
-};?>
\ No newline at end of file
+};?>
+<fieldset class="personalblock">
+	<legend><strong><?php echo $l->t('Log level');?></strong></legend>
+	<select name='loglevel' id='loglevel'>
+		<option value='<?php echo $_['loglevel']?>'><?php echo $levels[$_['loglevel']]?></option>
+		<?php for($i=0;$i<5;$i++):
+			if($i!=$_['loglevel']):?>
+				<option value='<?php echo $i?>'><?php echo $levels[$i]?></option>
+			<?php endif;
+		endfor;?>
+	</select>
+</fieldset>
diff --git a/settings/templates/log.php b/settings/templates/log.php
index 467f594186c..bcf5258f5f5 100644
--- a/settings/templates/log.php
+++ b/settings/templates/log.php
@@ -3,7 +3,7 @@
  * This file is licensed under the Affero General Public License version 3 or later.
  * See the COPYING-README file.
  */
-$levels=array('DEBUG','INFO','WARN','ERROR','FATAL');
+$levels=array('Debug','Info','Warning','Error','Fatal');
 ?>
 
 <div id="controls">
-- 
cgit v1.2.3


From b0127e39188f2268dbd74714e5d2f0e1a2b6ce7b Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind1991@gmail.com>
Date: Sun, 16 Oct 2011 21:42:24 +0200
Subject: use OC_Log instead of error_log

---
 apps/admin_export/settings.php           | 28 ++++++++++++++--------------
 apps/media/ajax/autoupdate.php           |  2 --
 apps/media/lib_ampache.php               |  1 -
 apps/media/lib_media.php                 |  2 --
 apps/media/lib_scanner.php               |  8 ++++----
 apps/media/server/xml.server.php         |  2 +-
 apps/remoteStorage/lib_remoteStorage.php |  8 ++++----
 apps/user_openid/appinfo/app.php         | 14 +++++++-------
 apps/user_openid/phpmyid.php             | 12 ------------
 apps/user_openid/user.php                |  2 +-
 files/ajax/newfolder.php                 |  2 +-
 index.php                                |  6 +++---
 lib/db.php                               |  9 ++++-----
 lib/filestorage/local.php                |  1 -
 lib/installer.php                        | 16 ++++++++--------
 lib/preferences.php                      |  1 -
 16 files changed, 47 insertions(+), 67 deletions(-)

diff --git a/apps/admin_export/settings.php b/apps/admin_export/settings.php
index 8308a2b89b5..1685e5c0ca1 100644
--- a/apps/admin_export/settings.php
+++ b/apps/admin_export/settings.php
@@ -26,14 +26,14 @@ if (isset($_POST['admin_export'])) {
     $root = OC::$SERVERROOT . "/";
     $zip = new ZipArchive();
     $filename = sys_get_temp_dir() . "/owncloud_export_" . date("y-m-d_H-i-s") . ".zip";
-    error_log("Creating export file at: " . $filename);
+    OC_Log::write('admin_export',"Creating export file at: " . $filename,OC_Log::INFO);
     if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
 	exit("Cannot open <$filename>\n");
     }
 
     if (isset($_POST['owncloud_system'])) {
 	// adding owncloud system files
-	error_log("Adding owncloud system files to export");
+	OC_Log::write('admin_export',"Adding owncloud system files to export",OC_Log::INFO);
 	zipAddDir($root, $zip, false);
 	foreach (array(".git", "3rdparty", "apps", "core", "files", "l10n", "lib", "ocs", "search", "settings", "tests") as $dirname) {
 	    zipAddDir($root . $dirname, $zip, true, basename($root) . "/");
@@ -43,7 +43,7 @@ if (isset($_POST['admin_export'])) {
     if (isset($_POST['owncloud_config'])) {
 	// adding owncloud config
 	// todo: add database export
-	error_log("Adding owncloud config to export");
+	OC_Log::write('admin_export',"Adding owncloud config to export",OC_Log::INFO);
 	zipAddDir($root . "config/", $zip, true, basename($root) . "/");
 	$zip->addFile($root . '/data/.htaccess', basename($root) . "/data/owncloud.db");
     }
@@ -53,7 +53,7 @@ if (isset($_POST['admin_export'])) {
 	$zip->addFile($root . '/data/.htaccess', basename($root) . "/data/.htaccess");
 	$zip->addFile($root . '/data/index.html', basename($root) . "/data/index.html");
 	foreach (OC_User::getUsers() as $i) {
-	    error_log("Adding owncloud user files of $i to export");
+		OC_Log::write('admin_export',"Adding owncloud user files of $i to export",OC_Log::INFO);
 	    zipAddDir($root . "data/" . $i, $zip, true, basename($root) . "/data/");
 	}
     }
@@ -78,19 +78,19 @@ function zipAddDir($dir, $zip, $recursive=true, $internalDir='') {
     $internalDir.=$dirname.='/';
 
     if ($dirhandle = opendir($dir)) {
-	while (false !== ( $file = readdir($dirhandle))) {
+		while (false !== ( $file = readdir($dirhandle))) {
 
-	    if (( $file != '.' ) && ( $file != '..' )) {
+			if (( $file != '.' ) && ( $file != '..' )) {
 
-		if (is_dir($dir . '/' . $file) && $recursive) {
-		    zipAddDir($dir . '/' . $file, $zip, $recursive, $internalDir);
-		} elseif (is_file($dir . '/' . $file)) {
-		    $zip->addFile($dir . '/' . $file, $internalDir . $file);
+			if (is_dir($dir . '/' . $file) && $recursive) {
+				zipAddDir($dir . '/' . $file, $zip, $recursive, $internalDir);
+			} elseif (is_file($dir . '/' . $file)) {
+				$zip->addFile($dir . '/' . $file, $internalDir . $file);
+			}
+			}
 		}
-	    }
-	}
-	closedir($dirhandle);
+		closedir($dirhandle);
     } else {
-	error_log("Was not able to open directory: " . $dir);
+		OC_Log::write('admin_export',"Was not able to open directory: " . $dir,OC_Log::ERROR);
     }
 }
diff --git a/apps/media/ajax/autoupdate.php b/apps/media/ajax/autoupdate.php
index ff0923ca032..a78b5e25dd1 100644
--- a/apps/media/ajax/autoupdate.php
+++ b/apps/media/ajax/autoupdate.php
@@ -30,9 +30,7 @@ $RUNTIME_NOSETUPFS=true;
 require_once('../../../lib/base.php');
 OC_JSON::checkAppEnabled('media');
 
-if(defined("DEBUG") && DEBUG) {error_log($_GET['autoupdate']);}
 $autoUpdate=(isset($_GET['autoupdate']) and $_GET['autoupdate']=='true');
-if(defined("DEBUG") && DEBUG) {error_log((integer)$autoUpdate);}
 
 OC_Preferences::setValue(OC_User::getUser(),'media','autoupdate',(integer)$autoUpdate);
 
diff --git a/apps/media/lib_ampache.php b/apps/media/lib_ampache.php
index 87291958af3..0ad84d66809 100644
--- a/apps/media/lib_ampache.php
+++ b/apps/media/lib_ampache.php
@@ -195,7 +195,6 @@ class OC_MEDIA_AMPACHE{
 		$filter=isset($params['filter'])?$params['filter']:'';
 		$exact=isset($params['exact'])?($params['exact']=='true'):false;
 		$artists=OC_MEDIA_COLLECTION::getArtists($filter,$exact);
-		if(defined("DEBUG") && DEBUG) {error_log('artists found: '.print_r($artists,true));}
 		echo('<root>');
 		foreach($artists as $artist){
 			self::printArtist($artist);
diff --git a/apps/media/lib_media.php b/apps/media/lib_media.php
index 7a666be8c27..485d616e1aa 100644
--- a/apps/media/lib_media.php
+++ b/apps/media/lib_media.php
@@ -40,7 +40,6 @@ class OC_MEDIA{
 	 */
 	public static function loginListener($params){
 		if(isset($_POST['user']) and $_POST['password']){
-			if(defined("DEBUG") && DEBUG) {error_log('postlogin');}
 			$name=$_POST['user'];
 			$query=OC_DB::prepare("SELECT user_id from *PREFIX*media_users WHERE user_id LIKE ?");
 			$uid=$query->execute(array($name))->fetchAll();
@@ -64,7 +63,6 @@ class OC_MEDIA{
 			$path=substr($path,1);
 		}
 		$path='/'.$path;
-		error_log("$path was updated");
 		OC_MEDIA_SCANNER::scanFile($path);
 	}
 
diff --git a/apps/media/lib_scanner.php b/apps/media/lib_scanner.php
index 9bf9397b19a..ef63cea45df 100644
--- a/apps/media/lib_scanner.php
+++ b/apps/media/lib_scanner.php
@@ -97,25 +97,25 @@ class OC_MEDIA_SCANNER{
 			$data=@self::$getID3->analyze($file);
 			getid3_lib::CopyTagsToComments($data);
 			if(!isset($data['comments'])){
-				if(defined("DEBUG") && DEBUG) {error_log("error reading id3 tags in '$file'");}
+				OC_Log::write('media',"error reading id3 tags in '$file'",OC_Log::WARN);
 				return;
 			}
 			if(!isset($data['comments']['artist'])){
-				if(defined("DEBUG") && DEBUG) {error_log("error reading artist tag in '$file'");}
+				OC_Log::write('media',"error reading artist tag in '$file'",OC_Log::WARN);
 				$artist='unknown';
 			}else{
 				$artist=stripslashes($data['comments']['artist'][0]);
 				$artist=utf8_encode($artist);
 			}
 			if(!isset($data['comments']['album'])){
-				if(defined("DEBUG") && DEBUG) {error_log("error reading album tag in '$file'");}
+				OC_Log::write('media',"error reading album tag in '$file'",OC_Log::WARN);
 				$album='unknown';
 			}else{
 				$album=stripslashes($data['comments']['album'][0]);
 				$album=utf8_encode($album);
 			}
 			if(!isset($data['comments']['title'])){
-				if(defined("DEBUG") && DEBUG) {error_log("error reading title tag in '$file'");}
+				OC_Log::write('media',"error reading title tag in '$file'",OC_Log::WARN);
 				$title='unknown';
 			}else{
 				$title=stripslashes($data['comments']['title'][0]);
diff --git a/apps/media/server/xml.server.php b/apps/media/server/xml.server.php
index 44a16793bf2..2d54c863c79 100644
--- a/apps/media/server/xml.server.php
+++ b/apps/media/server/xml.server.php
@@ -37,7 +37,7 @@ foreach($arguments as &$argument){
 }
 ob_clean();
 if(isset($arguments['action'])){
-	if(defined("DEBUG") && DEBUG) {error_log($arguments['action']);}
+	OC_Log::write('media','ampache '.$arguments['action'].' request', OC_Log::DEBUG);
 	switch($arguments['action']){
 		case 'url_to_song':
 			OC_MEDIA_AMPACHE::url_to_song($arguments);
diff --git a/apps/remoteStorage/lib_remoteStorage.php b/apps/remoteStorage/lib_remoteStorage.php
index 5677ab3c6e0..f10a72870a4 100644
--- a/apps/remoteStorage/lib_remoteStorage.php
+++ b/apps/remoteStorage/lib_remoteStorage.php
@@ -7,7 +7,7 @@ class OC_remoteStorage {
 		if( PEAR::isError($result)) {
 			$entry = 'DB Error: "'.$result->getMessage().'"<br />';
 			$entry .= 'Offending command was: '.$result->getDebugInfo().'<br />';
-			if(defined("DEBUG") && DEBUG) {error_log( $entry );}
+			OC_Log::write('removeStorage',$entry,OC_Log::ERROR);
 			die( $entry );
 		}
 		$ret = array();
@@ -24,7 +24,7 @@ class OC_remoteStorage {
 		if( PEAR::isError($result)) {
 			$entry = 'DB Error: "'.$result->getMessage().'"<br />';
 			$entry .= 'Offending command was: '.$result->getDebugInfo().'<br />';
-			if(defined("DEBUG") && DEBUG) {error_log( $entry );}
+			OC_Log::write('removeStorage',$entry,OC_Log::ERROR);
 			die( $entry );
 		}
 		$ret = array();
@@ -45,7 +45,7 @@ class OC_remoteStorage {
 		if( PEAR::isError($result)) {
 			$entry = 'DB Error: "'.$result->getMessage().'"<br />';
 			$entry .= 'Offending command was: '.$result->getDebugInfo().'<br />';
-			if(defined("DEBUG") && DEBUG) {error_log( $entry );}
+			OC_Log::write('removeStorage',$entry,OC_Log::ERROR);
 			die( $entry );
 		}
 	}
@@ -56,7 +56,7 @@ class OC_remoteStorage {
 		if( PEAR::isError($result)) {
 			$entry = 'DB Error: "'.$result->getMessage().'"<br />';
 			$entry .= 'Offending command was: '.$result->getDebugInfo().'<br />';
-			if(defined("DEBUG") && DEBUG) {error_log( $entry );}
+			OC_Log::write('removeStorage',$entry,OC_Log::ERROR);
 			die( $entry );
 		}
 	}
diff --git a/apps/user_openid/appinfo/app.php b/apps/user_openid/appinfo/app.php
index 546f9f4565a..912019a9700 100644
--- a/apps/user_openid/appinfo/app.php
+++ b/apps/user_openid/appinfo/app.php
@@ -26,14 +26,14 @@ OC_User::useBackend('openid');
 
 //check for results from openid requests
 if(isset($_GET['openid_mode']) and $_GET['openid_mode'] == 'id_res'){
-	if(defined("DEBUG") && DEBUG) {error_log('openid retured');}
+	OC_Log::write('user_openid','openid retured',OC_Log::DEBUG);
 	$openid = new SimpleOpenID;
 	$openid->SetIdentity($_GET['openid_identity']);
 	$openid_validation_result = $openid->ValidateWithServer();
 	if ($openid_validation_result == true){         // OK HERE KEY IS VALID
-		if(defined("DEBUG") && DEBUG) {error_log('auth sucessfull');}
+		OC_Log::write('user_openid','auth sucessfull',OC_Log::DEBUG);
 		$identity=$openid->GetIdentity();
-		if(defined("DEBUG") && DEBUG) {error_log("auth as $identity");}
+		OC_Log::write('user_openid','auth as '.$identity,OC_Log::DEBUG);
 		$user=OC_USER_OPENID::findUserForIdentity($identity);
 		if($user){
 			$_SESSION['user_id']=$user;
@@ -41,13 +41,13 @@ if(isset($_GET['openid_mode']) and $_GET['openid_mode'] == 'id_res'){
 		}
 	}else if($openid->IsError() == true){            // ON THE WAY, WE GOT SOME ERROR
 		$error = $openid->GetError();
-		if(defined("DEBUG") && DEBUG) {error_log("ERROR CODE: " . $error['code']);}
-		if(defined("DEBUG") && DEBUG) {error_log("ERROR DESCRIPTION: " . $error['description']);}
+		OC_Log::write('user_openid','ERROR CODE: '. $error['code'],OC_Log::ERROR);
+		OC_Log::write('user_openid','ERROR DESCRIPTION: '. $error['description'],OC_Log::ERROR);
 	}else{                                            // Signature Verification Failed
-		if(defined("DEBUG") && DEBUG) {error_log("INVALID AUTHORIZATION");}
+		OC_Log::write('user_openid','INVALID AUTHORIZATION',OC_Log::ERROR);
 	}
 }else if (isset($_GET['openid_mode']) and $_GET['openid_mode'] == 'cancel'){ // User Canceled your Request
-	if(defined("DEBUG") && DEBUG) {error_log("USER CANCELED REQUEST");}
+	OC_Log::write('user_openid','USER CANCELED REQUEST',OC_Log::DEBUG);
 	return false;
 }
 
diff --git a/apps/user_openid/phpmyid.php b/apps/user_openid/phpmyid.php
index 5009fa410aa..d8168c9a10d 100644
--- a/apps/user_openid/phpmyid.php
+++ b/apps/user_openid/phpmyid.php
@@ -1053,8 +1053,6 @@ function debug ($x, $m = null) {
 	} else {
 		$x .= "\n";
 	}
-
-	if(defined("DEBUG") && DEBUG) {error_log($x . "\n", 3, $profile['logfile']);}
 }
 
 
@@ -1513,7 +1511,6 @@ function wrap_html ( $message ) {
 </body>
 </html>
 ';
-	if(defined("DEBUG") && DEBUG) {error_log($html);}
 	echo $html;
 	exit(0);
 }
@@ -1658,15 +1655,6 @@ $profile['req_url'] = sprintf("%s://%s%s",
 // 		      $port,//host  already includes the path
 		      $_SERVER["REQUEST_URI"]);
 
-// $fullId='user.php/'.$USERNAME.'/';
-// $incompleteId='user.php/';
-
-// if(!strpos($profile['req_url'],$fullId)){
-// 	$profile['req_url']=str_replace($incompleteId,$fullId,$profile['req_url']);
-// }
-
-// if(defined("DEBUG") && DEBUG) {error_log('inc id: '.$fullId);}
-// if(defined("DEBUG") && DEBUG) {error_log('req url: '.$profile['req_url']);}
 
 // Set the default allowance for testing
 if (! array_key_exists('allow_test', $profile))
diff --git a/apps/user_openid/user.php b/apps/user_openid/user.php
index 3cbc38491ca..a267e020507 100644
--- a/apps/user_openid/user.php
+++ b/apps/user_openid/user.php
@@ -40,7 +40,7 @@ require_once '../../lib/base.php';
 OC_Util::checkAppEnabled('user_openid');
 
 if(!OC_User::userExists($USERNAME)){
-	if(defined("DEBUG") && DEBUG) {error_log($USERNAME.' doesn\'t exist');}
+	OC_Log::write('user_openid',$USERNAME.' doesn\'t exist',OC_Log::WARN);
 	$USERNAME='';
 }
 $IDENTITY=OC_Helper::linkTo( "user_openid", "user.php", null, true ).'/'.$USERNAME;
diff --git a/files/ajax/newfolder.php b/files/ajax/newfolder.php
index 43d87461fc7..6966e912c56 100644
--- a/files/ajax/newfolder.php
+++ b/files/ajax/newfolder.php
@@ -13,7 +13,7 @@ if($foldername == '') {
 	OC_JSON::error(array("data" => array( "message" => "Empty Foldername" )));
 	exit();
 }
-if(defined("DEBUG") && DEBUG) {error_log('try to create ' . $foldername . ' in ' . $dir);}
+
 if(OC_Files::newFile($dir, $foldername, 'dir')) {
 	OC_JSON::success(array("data" => array()));
 	exit();
diff --git a/index.php b/index.php
index 924e7394f7b..558733e1cda 100644
--- a/index.php
+++ b/index.php
@@ -31,7 +31,7 @@ if($not_installed) {
 	// Check for autosetup:
 	$autosetup_file = OC::$SERVERROOT."/config/autoconfig.php";
 	if( file_exists( $autosetup_file )){
-		error_log("Autoconfig file found, setting up owncloud...");
+		OC_Log::write('core','Autoconfig file found, setting up owncloud...',OC_Log::INFO);
 		include( $autosetup_file );
 		$_POST['install'] = 'true';
 		$_POST = array_merge ($_POST, $AUTOCONFIG);
@@ -68,7 +68,7 @@ else {
 	// remember was checked after last login
 	if(isset($_COOKIE["oc_remember_login"]) && isset($_COOKIE["oc_token"]) && isset($_COOKIE["oc_username"]) && $_COOKIE["oc_remember_login"]) {
 		if(defined("DEBUG") && DEBUG) {
-			error_log("Trying to login from cookie");
+			OC_Log::write('core','Trying to login from cookie',OC_Log::DEBUG);
 		}
 		// confirm credentials in cookie
 		if(isset($_COOKIE['oc_token']) && OC_User::userExists($_COOKIE['oc_username']) &&
@@ -86,7 +86,7 @@ else {
 		if(OC_User::login($_POST["user"], $_POST["password"])) {
 			if(!empty($_POST["remember_login"])){
 				if(defined("DEBUG") && DEBUG) {
-					error_log("Setting remember login to cookie");
+					OC_Log::write('core','Setting remember login to cookie',OC_Log::DEBUG);
 				}
 				$token = md5($_POST["user"].time());
 				OC_Preferences::setValue($_POST['user'], 'login', 'token', $token);
diff --git a/lib/db.php b/lib/db.php
index ef6d1dcc8b7..fa3995be125 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -161,9 +161,8 @@ class OC_DB {
 			// Die if we could not connect
 			if( PEAR::isError( self::$MDB2 )){
 				echo( '<b>can not connect to database, using '.$type.'. ('.self::$MDB2->getUserInfo().')</center>');
-				$error = self::$MDB2->getMessage();
-				error_log( $error);
-				error_log( self::$MDB2->getUserInfo());
+				OC_Log::write('core',self::$MDB2->getUserInfo(),OC_Log::FATAL);
+				OC_Log::write('core',self::$MDB2->getMessage(),OC_Log::FATAL);
 				die( $error );
 			}
 			
@@ -195,7 +194,7 @@ class OC_DB {
 			if( PEAR::isError($result)) {
 				$entry = 'DB Error: "'.$result->getMessage().'"<br />';
 				$entry .= 'Offending command was: '.$query.'<br />';
-				error_log( $entry );
+				OC_Log::write('core',$entry,OC_Log::FATAL);
 				die( $entry );
 			}
 		}else{
@@ -204,7 +203,7 @@ class OC_DB {
 			}catch(PDOException $e){
 				$entry = 'DB Error: "'.$e->getMessage().'"<br />';
 				$entry .= 'Offending command was: '.$query.'<br />';
-				error_log( $entry );
+				OC_Log::write('core',$entry,OC_Log::FATAL);
 				die( $entry );
 			}
 			$result=new PDOStatementWrapper($result);
diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php
index 180b056f344..8e0907f8d3b 100644
--- a/lib/filestorage/local.php
+++ b/lib/filestorage/local.php
@@ -195,7 +195,6 @@ class OC_Filestorage_Local extends OC_Filestorage{
 	}
 
 	private function delTree($dir) {
-		if(defined("DEBUG") && DEBUG) {error_log('del'.$dir);}
 		$dirRelative=$dir;
 		$dir=$this->datadir.$dir;
 		if (!file_exists($dir)) return true;
diff --git a/lib/installer.php b/lib/installer.php
index 0febb2cab46..242ca97934f 100644
--- a/lib/installer.php
+++ b/lib/installer.php
@@ -56,7 +56,7 @@ class OC_Installer{
 	 */
 	public static function installApp( $data = array()){
 		if(!isset($data['source'])){
-			if(defined("DEBUG") && DEBUG) {error_log("No source specified when installing app");}
+			OC_Log::write('core','No source specified when installing app',OC_Log::ERROR);
 			return false;
 		}
 		
@@ -64,13 +64,13 @@ class OC_Installer{
 		if($data['source']=='http'){
 			$path=tempnam(sys_get_temp_dir(),'oc_installer_');
 			if(!isset($data['href'])){
-				if(defined("DEBUG") && DEBUG) {error_log("No href specified when installing app from http");}
+				OC_Log::write('core','No href specified when installing app from http',OC_Log::ERROR);
 				return false;
 			}
 			copy($data['href'],$path);
 		}else{
 			if(!isset($data['path'])){
-				if(defined("DEBUG") && DEBUG) {error_log("No path specified when installing app from local file");}
+				OC_Log::write('core','No path specified when installing app from local file',OC_Log::ERROR);
 				return false;
 			}
 			$path=$data['path'];
@@ -85,7 +85,7 @@ class OC_Installer{
 			$zip->extractTo($extractDir);
 			$zip->close();
 		} else {
-			if(defined("DEBUG") && DEBUG) {error_log("Failed to open archive when installing app");}
+			OC_Log::write('core','Failed to open archive when installing app',OC_Log::ERROR);
 			OC_Helper::rmdirr($extractDir);
 			if($data['source']=='http'){
 				unlink($path);
@@ -95,7 +95,7 @@ class OC_Installer{
 		
 		//load the info.xml file of the app
 		if(!is_file($extractDir.'/appinfo/info.xml')){
-			if(defined("DEBUG") && DEBUG) {error_log("App does not provide an info.xml file");}
+			OC_Log::write('core','App does not provide an info.xml file',OC_Log::ERROR);
 			OC_Helper::rmdirr($extractDir);
 			if($data['source']=='http'){
 				unlink($path);
@@ -107,7 +107,7 @@ class OC_Installer{
 		
 		//check if an app with the same id is already installed
 		if(self::isInstalled( $info['id'] )){
-			if(defined("DEBUG") && DEBUG) {error_log("App already installed");}
+			OC_Log::write('core','App already installed',OC_Log::WARN);
 			OC_Helper::rmdirr($extractDir);
 			if($data['source']=='http'){
 				unlink($path);
@@ -117,7 +117,7 @@ class OC_Installer{
 
 		//check if the destination directory already exists
 		if(is_dir($basedir)){
-			if(defined("DEBUG") && DEBUG) {error_log("App's directory already exists");}
+			OC_Log::write('core','App directory already exists',OC_Log::WARN);
 			OC_Helper::rmdirr($extractDir);
 			if($data['source']=='http'){
 				unlink($path);
@@ -131,7 +131,7 @@ class OC_Installer{
 		
 		//copy the app to the correct place
 		if(!mkdir($basedir)){
-			if(defined("DEBUG") && DEBUG) {error_log('Can\'t create app folder ('.$basedir.')');}
+			OC_Log::write('core','Can\'t create app folder ('.$basedir.')',OC_Log::ERROR);
 			OC_Helper::rmdirr($extractDir);
 			if($data['source']=='http'){
 				unlink($path);
diff --git a/lib/preferences.php b/lib/preferences.php
index 6d8aa17afd5..75201f455ba 100644
--- a/lib/preferences.php
+++ b/lib/preferences.php
@@ -140,7 +140,6 @@ class OC_Preferences{
 		// Check if the key does exist
 		$query = OC_DB::prepare( 'SELECT configvalue FROM *PREFIX*preferences WHERE userid = ? AND appid = ? AND configkey = ?' );
 		$values=$query->execute(array($user,$app,$key))->fetchAll();
-		if(defined("DEBUG") && DEBUG) {error_log(print_r($values,true));}
 		$exists=(count($values)>0);
 
 		if( !$exists ){
-- 
cgit v1.2.3


From 1f6be857192bce5c6e33765bdebb424f74b3642d Mon Sep 17 00:00:00 2001
From: Brice Maron <brice@bmaron.net>
Date: Sun, 16 Oct 2011 23:03:03 +0200
Subject: Fix bookmarks app to work with postgresql.

Rework the bookmark app to manage postgresql.
Add a fetchOne function into the PdoStmtWrapper
Fix a tipo in comments.
---
 apps/bookmarks/ajax/addBookmark.php  | 12 +++++++-
 apps/bookmarks/ajax/editBookmark.php |  2 ++
 apps/bookmarks/ajax/updateList.php   | 55 +++++++++++++++++++++++-------------
 lib/db.php                           | 11 +++++++-
 4 files changed, 59 insertions(+), 21 deletions(-)

diff --git a/apps/bookmarks/ajax/addBookmark.php b/apps/bookmarks/ajax/addBookmark.php
index 0a7cdfc9be3..3975fd15f81 100644
--- a/apps/bookmarks/ajax/addBookmark.php
+++ b/apps/bookmarks/ajax/addBookmark.php
@@ -33,6 +33,8 @@ OC_JSON::checkAppEnabled('bookmarks');
 $CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" );
 if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){
 	$_ut = "strftime('%s','now')";
+} elseif($CONFIG_DBTYPE == 'pgsql') {
+	$_ut = 'date_part(\'epoch\',now())::integer';
 } else {
 	$_ut = "UNIX_TIMESTAMP()";
 }
@@ -51,7 +53,15 @@ $params=array(
 	OC_User::getUser()
 	);
 $query->execute($params);
-$b_id = OC_DB::insertid();
+
+if($CONFIG_DBTYPE == 'pgsql')
+{
+	$query = OC_DB::prepare("SELECT currval('*PREFIX*bookmarks_id_seq')");
+	$b_id = $query->execute()->fetchOne();
+} else {
+	$b_id = OC_DB::insertid();
+}
+
 
 if($b_id !== false) {
 	$query = OC_DB::prepare("
diff --git a/apps/bookmarks/ajax/editBookmark.php b/apps/bookmarks/ajax/editBookmark.php
index e205f69bf5a..35f30ebcb7a 100644
--- a/apps/bookmarks/ajax/editBookmark.php
+++ b/apps/bookmarks/ajax/editBookmark.php
@@ -33,6 +33,8 @@ OC_JSON::checkAppEnabled('bookmarks');
 $CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" );
 if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){
 	$_ut = "strftime('%s','now')";
+} elseif($CONFIG_DBTYPE == 'pgsql') {
+	$_ut = 'date_part(\'epoch\',now())::integer';
 } else {
 	$_ut = "UNIX_TIMESTAMP()";
 }
diff --git a/apps/bookmarks/ajax/updateList.php b/apps/bookmarks/ajax/updateList.php
index f2c81256bb6..7a5c0476b43 100644
--- a/apps/bookmarks/ajax/updateList.php
+++ b/apps/bookmarks/ajax/updateList.php
@@ -38,6 +38,9 @@ $filterTag = isset($_GET['tag']) ? '%' . htmlspecialchars_decode($_GET['tag']) .
 if($filterTag){
 	$sqlFilterTag = 'HAVING tags LIKE ?';
 	$params[] = $filterTag;
+	if($CONFIG_DBTYPE == 'pgsql' ) {
+		$sqlFilterTag = 'HAVING array_to_string(array_agg(tag), \' \')  LIKE ?';
+	}
 } else {
 	$sqlFilterTag = '';
 }
@@ -58,26 +61,40 @@ if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){
 	$_gc_separator = 'SEPARATOR \' \'';
 }
 
-$query = OC_DB::prepare('
-	SELECT id, url, title, 
-	CASE WHEN *PREFIX*bookmarks.id = *PREFIX*bookmarks_tags.bookmark_id
-			THEN GROUP_CONCAT( tag ' .$_gc_separator. ' )
-			ELSE \' \'
-		END
-		AS tags
-	FROM *PREFIX*bookmarks
-	LEFT JOIN *PREFIX*bookmarks_tags ON 1=1
-	WHERE (*PREFIX*bookmarks.id = *PREFIX*bookmarks_tags.bookmark_id 
-			OR *PREFIX*bookmarks.id NOT IN (
-				SELECT *PREFIX*bookmarks_tags.bookmark_id FROM *PREFIX*bookmarks_tags
+if($CONFIG_DBTYPE == 'pgsql' ){
+	$query = OC_DB::prepare('
+		SELECT id, url, title, array_to_string(array_agg(tag), \' \') as tags
+		FROM *PREFIX*bookmarks
+		LEFT JOIN *PREFIX*bookmarks_tags ON *PREFIX*bookmarks.id = *PREFIX*bookmarks_tags.bookmark_id 
+		WHERE 
+			*PREFIX*bookmarks.user_id = ?
+		GROUP BY id, url, title
+		'.$sqlFilterTag.'
+		ORDER BY *PREFIX*bookmarks.'.$sqlSort.' 
+		LIMIT 10
+		OFFSET ?');
+} else {
+	$query = OC_DB::prepare('
+		SELECT id, url, title, 
+		CASE WHEN *PREFIX*bookmarks.id = *PREFIX*bookmarks_tags.bookmark_id
+				THEN GROUP_CONCAT( tag ' .$_gc_separator. ' )
+				ELSE \' \'
+			END
+			AS tags
+		FROM *PREFIX*bookmarks
+		LEFT JOIN *PREFIX*bookmarks_tags ON 1=1
+		WHERE (*PREFIX*bookmarks.id = *PREFIX*bookmarks_tags.bookmark_id 
+				OR *PREFIX*bookmarks.id NOT IN (
+					SELECT *PREFIX*bookmarks_tags.bookmark_id FROM *PREFIX*bookmarks_tags
+				)
 			)
-		)
-		AND *PREFIX*bookmarks.user_id = ?
-	GROUP BY url
-	'.$sqlFilterTag.'
-	ORDER BY *PREFIX*bookmarks.'.$sqlSort.' 
-	LIMIT ?,  10');
-	
+			AND *PREFIX*bookmarks.user_id = ?
+		GROUP BY url
+		'.$sqlFilterTag.'
+		ORDER BY *PREFIX*bookmarks.'.$sqlSort.' 
+		LIMIT ?,  10');
+}
+
 $bookmarks = $query->execute($params)->fetchAll();
 
 OC_JSON::success(array('data' => $bookmarks));
diff --git a/lib/db.php b/lib/db.php
index fa3995be125..78a4da10ce8 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -28,7 +28,7 @@ class OC_DB {
 	const BACKEND_PDO=0;
 	const BACKEND_MDB2=1;
 	
-	static private $connection; //the prefered conenction to use, either PDO or MDB2
+	static private $connection; //the prefered connection to use, either PDO or MDB2
 	static private $backend=null;
 	static private $MDB2=false;
 	static private $PDO=false;
@@ -480,4 +480,13 @@ class PDOStatementWrapper{
 	public function __call($name,$arguments){
 		return call_user_func_array(array($this->statement,$name),$arguments);
 	}
+	
+	/**
+	 * Provide a simple fetchOne.
+	 * fetch single column from the next row
+	 * @param int $colnum the column number to fetch
+	 */
+	public function fetchOne($colnum = 0){
+		return $this->statement->fetchColumn($colnum);
+	}
 }
-- 
cgit v1.2.3


From 330c513015f835bc0f7f4cc19e3c49fd9053e735 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind1991@gmail.com>
Date: Mon, 17 Oct 2011 00:24:07 +0200
Subject: prevent error in media player ajax api

---
 apps/media/ajax/api.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/apps/media/ajax/api.php b/apps/media/ajax/api.php
index 29f61a2207f..93298c82c55 100644
--- a/apps/media/ajax/api.php
+++ b/apps/media/ajax/api.php
@@ -106,7 +106,7 @@ if($arguments['action']){
 			}
 			break;
 		case 'play':
-			ob_end_clean();
+			@ob_end_clean();
 			
 			$ftype=OC_Filesystem::getMimeType( $arguments['path'] );
 			
-- 
cgit v1.2.3


From 77378fa1893267bbdd6ee2f7805a34c1d5b0977b Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind1991@gmail.com>
Date: Mon, 17 Oct 2011 00:24:42 +0200
Subject: fix now() function for sqlite3

---
 lib/db.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/db.php b/lib/db.php
index 78a4da10ce8..bcfda4592f2 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -350,7 +350,7 @@ class OC_DB {
 		$prefix = OC_Config::getValue( "dbtableprefix", "oc_" );
 		
 		// differences in escaping of table names ('`' for mysql) and getting the current timestamp
-		if( $type == 'sqlite' ){
+		if( $type == 'sqlite' || $type == 'sqlite3' ){
 			$query = str_replace( '`', '\'', $query );
 			$query = str_replace( 'NOW()', 'datetime(\'now\')', $query );
 			$query = str_replace( 'now()', 'datetime(\'now\')', $query );
-- 
cgit v1.2.3


From 595b13f1e03a4300beee1396333a4b4337337df5 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind1991@gmail.com>
Date: Mon, 17 Oct 2011 01:18:02 +0200
Subject: prevent the remaining ob_clean related errors

---
 apps/admin_export/settings.php                   | 2 +-
 apps/media/getID3/getid3/extension.cache.dbm.php | 2 +-
 apps/media/getID3/getid3/module.graphic.jpg.php  | 2 +-
 apps/media/getID3/getid3/write.id3v2.php         | 8 ++++----
 apps/media/getID3/getid3/write.real.php          | 4 ++--
 apps/media/server/xml.server.php                 | 2 +-
 files/download.php                               | 2 +-
 lib/template.php                                 | 4 ++--
 ocs/v1.php                                       | 2 +-
 tests/index.php                                  | 2 +-
 tests/lib/filesystem.php                         | 2 +-
 11 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/apps/admin_export/settings.php b/apps/admin_export/settings.php
index 1685e5c0ca1..cf1daa250f7 100644
--- a/apps/admin_export/settings.php
+++ b/apps/admin_export/settings.php
@@ -63,7 +63,7 @@ if (isset($_POST['admin_export'])) {
     header("Content-Type: application/zip");
     header("Content-Disposition: attachment; filename=" . basename($filename));
     header("Content-Length: " . filesize($filename));
-    ob_end_clean();
+    @ob_end_clean();
     readfile($filename);
     unlink($filename);
 } else {
diff --git a/apps/media/getID3/getid3/extension.cache.dbm.php b/apps/media/getID3/getid3/extension.cache.dbm.php
index 051bb1f0d7a..c18b52d5dca 100644
--- a/apps/media/getID3/getid3/extension.cache.dbm.php
+++ b/apps/media/getID3/getid3/extension.cache.dbm.php
@@ -90,7 +90,7 @@ class getID3_cached_dbm extends getID3
 			ob_start(); // nasty, buy the only way to check...
 			phpinfo();
 			$contents = ob_get_contents();
-			ob_end_clean();
+			@ob_end_clean();
 			if (!strstr($contents, $cache_type)) {
 				die('PHP is not compiled --with '.$cache_type.' support, required to use DBM style cache.');
 			}
diff --git a/apps/media/getID3/getid3/module.graphic.jpg.php b/apps/media/getID3/getid3/module.graphic.jpg.php
index 0c2db92e636..cd5e986543c 100644
--- a/apps/media/getID3/getid3/module.graphic.jpg.php
+++ b/apps/media/getID3/getid3/module.graphic.jpg.php
@@ -62,7 +62,7 @@ class getid3_jpg
 							$ThisFileInfo['warning'][] = strip_tags($errors);
 							unset($ThisFileInfo['jpg']['exif']);
 						}
-						ob_end_clean();
+						@ob_end_clean();
 
 					} else {
 
diff --git a/apps/media/getID3/getid3/write.id3v2.php b/apps/media/getID3/getid3/write.id3v2.php
index 9447486e845..32546d18af9 100644
--- a/apps/media/getID3/getid3/write.id3v2.php
+++ b/apps/media/getID3/getid3/write.id3v2.php
@@ -68,7 +68,7 @@ class getid3_write_id3v2
 						} else {
 							$this->errors[] = 'Could not open '.$this->filename.' mode "r+b" - '.strip_tags(ob_get_contents());
 						}
-						ob_end_clean();
+						@ob_end_clean();
 
 					} else {
 
@@ -80,7 +80,7 @@ class getid3_write_id3v2
 						} else {
 							$this->errors[] = 'Could not open '.$this->filename.' mode "wb" - '.strip_tags(ob_get_contents());
 						}
-						ob_end_clean();
+						@ob_end_clean();
 
 					}
 
@@ -106,7 +106,7 @@ class getid3_write_id3v2
 								fclose($fp_source);
 								copy($tempfilename, $this->filename);
 								unlink($tempfilename);
-								ob_end_clean();
+								@ob_end_clean();
 								return true;
 
 							} else {
@@ -121,7 +121,7 @@ class getid3_write_id3v2
 							$this->errors[] = 'Could not open '.$this->filename.' mode "rb" - '.strip_tags(ob_get_contents());
 
 						}
-						ob_end_clean();
+						@ob_end_clean();
 					}
 					return false;
 
diff --git a/apps/media/getID3/getid3/write.real.php b/apps/media/getID3/getid3/write.real.php
index 1e0240ccf32..14e775812fc 100644
--- a/apps/media/getID3/getid3/write.real.php
+++ b/apps/media/getID3/getid3/write.real.php
@@ -118,7 +118,7 @@ class getid3_write_real
 							$this->errors[] = 'Could not open '.$tempfilename.' mode "wb" - '.strip_tags(ob_get_contents());
 
 						}
-						ob_end_clean();
+						@ob_end_clean();
 					}
 					fclose($fp_source);
 					return false;
@@ -275,7 +275,7 @@ class getid3_write_real
 						$this->errors[] = 'Could not open '.$tempfilename.' mode "wb" - '.strip_tags(ob_get_contents());
 
 					}
-					ob_end_clean();
+					@ob_end_clean();
 				}
 				fclose($fp_source);
 				return false;
diff --git a/apps/media/server/xml.server.php b/apps/media/server/xml.server.php
index 2d54c863c79..7e320a7f595 100644
--- a/apps/media/server/xml.server.php
+++ b/apps/media/server/xml.server.php
@@ -35,7 +35,7 @@ if(!isset($_POST['action']) and isset($_GET['action'])){
 foreach($arguments as &$argument){
 	$argument=stripslashes($argument);
 }
-ob_clean();
+@ob_clean();
 if(isset($arguments['action'])){
 	OC_Log::write('media','ampache '.$arguments['action'].' request', OC_Log::DEBUG);
 	switch($arguments['action']){
diff --git a/files/download.php b/files/download.php
index c8a2692d015..71f91d352f7 100644
--- a/files/download.php
+++ b/files/download.php
@@ -46,6 +46,6 @@ header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
 header('Pragma: public');
 header('Content-Length: '.OC_Filesystem::filesize($filename));
 
-ob_end_clean();
+@ob_end_clean();
 OC_Filesystem::readfile( $filename );
 ?>
diff --git a/lib/template.php b/lib/template.php
index a293e63b437..440b62003e7 100644
--- a/lib/template.php
+++ b/lib/template.php
@@ -293,7 +293,7 @@ class OC_Template{
 		ob_start();
 		include( $this->template ); // <-- we have to use include because we pass $_!
 		$data = ob_get_contents();
-		ob_end_clean();
+		@ob_end_clean();
 
 		// return the data
 		return $data;
@@ -319,7 +319,7 @@ class OC_Template{
 		ob_start();
 		include( $this->path.$file.'.php' );
 		$data = ob_get_contents();
-		ob_end_clean();
+		@ob_end_clean();
 
 		// Daten zurĂĽckgeben
 		return $data;
diff --git a/ocs/v1.php b/ocs/v1.php
index b5eb460664c..f5ff6cb6054 100644
--- a/ocs/v1.php
+++ b/ocs/v1.php
@@ -22,7 +22,7 @@
 */
 
 require_once('../lib/base.php');
-ob_clean();
+@ob_clean();
 OC_OCS::handle();
 
 ?>
diff --git a/tests/index.php b/tests/index.php
index 08e53f1a575..34e1d4166ce 100644
--- a/tests/index.php
+++ b/tests/index.php
@@ -29,7 +29,7 @@ require_once('../lib/base.php');
 OC_Util::checkAdminUser();
 
 $testCases=loadFiles(__DIR__,array('index.php','templates'));
-ob_end_clean();
+@ob_end_clean();
 $testResults=array();
 foreach($testCases as $testCaseClass){
 	$testCase=new $testCaseClass();
diff --git a/tests/lib/filesystem.php b/tests/lib/filesystem.php
index 4bfa23884f4..43cf2e53f3f 100644
--- a/tests/lib/filesystem.php
+++ b/tests/lib/filesystem.php
@@ -87,7 +87,7 @@ class OC_FILEYSYSTEM_Test extends OC_TestCase
 		ob_start();
 		OC_Filesystem::readfile('/dummy');
 		$this->assertEquals('foo', ob_get_contents(),'Unexpected output of readfile');
-		ob_end_clean();
+		@ob_end_clean();
 	}
 
 	public function isReadable(){
-- 
cgit v1.2.3


From 4d1776faf959c71ac81ea1724e0d270e5414e953 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind1991@gmail.com>
Date: Mon, 17 Oct 2011 01:25:11 +0200
Subject: catch some edge cases in media player

---
 apps/media/js/collection.js | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/apps/media/js/collection.js b/apps/media/js/collection.js
index 29ba45919cf..576f567faef 100644
--- a/apps/media/js/collection.js
+++ b/apps/media/js/collection.js
@@ -26,11 +26,17 @@ Collection={
 					}
 					for(var i=0;i<data.albums.length;i++){
 						var album=data.albums[i];
-						var artistName=Collection.artistsById[album.album_artist].name;
+						if(Collection.artistsById[album.album_artist]){
+							var artistName=Collection.artistsById[album.album_artist].name;
+						}else{
+							var artistName='unknown';
+						}
 						var albumData={name:album.album_name,artist:artistName,songs:[]};
 						Collection.albumsById[album.album_id]=albumData;
 						Collection.albums.push(albumData);
-						Collection.artistsById[album.album_artist].albums.push(albumData);
+						if(Collection.artistsById[album.album_artist]){
+							Collection.artistsById[album.album_artist].albums.push(albumData);
+						}
 					}
 					for(var i=0;i<data.songs.length;i++){
 						var song=data.songs[i];
@@ -51,6 +57,9 @@ Collection={
 					}
 					
 					Collection.artists.sort(function(a,b){
+						if(!a.name){
+							return -1;
+						}
 						return a.name.localeCompare(b.name);
 					});
 					
-- 
cgit v1.2.3


From 492931562fda62b1495af197b10e39f6c89a9949 Mon Sep 17 00:00:00 2001
From: Brice Maron <brice@bmaron.net>
Date: Mon, 17 Oct 2011 13:49:33 +0200
Subject: Fix bookmark listing with mysql: limit is binded as string.

---
 apps/bookmarks/ajax/updateList.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/apps/bookmarks/ajax/updateList.php b/apps/bookmarks/ajax/updateList.php
index 7a5c0476b43..d2a5397452f 100644
--- a/apps/bookmarks/ajax/updateList.php
+++ b/apps/bookmarks/ajax/updateList.php
@@ -46,7 +46,6 @@ if($filterTag){
 }
 
 $offset = isset($_GET['page']) ? intval($_GET['page']) * 10 : 0;
-$params[] = $offset;
 
 $sort = isset($_GET['sort']) ? ($_GET['sort']) : 'bookmarks_sorting_recent';
 if($sort == 'bookmarks_sorting_clicks') {
@@ -62,6 +61,7 @@ if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){
 }
 
 if($CONFIG_DBTYPE == 'pgsql' ){
+	$params[] = $offset;
 	$query = OC_DB::prepare('
 		SELECT id, url, title, array_to_string(array_agg(tag), \' \') as tags
 		FROM *PREFIX*bookmarks
@@ -92,7 +92,7 @@ if($CONFIG_DBTYPE == 'pgsql' ){
 		GROUP BY url
 		'.$sqlFilterTag.'
 		ORDER BY *PREFIX*bookmarks.'.$sqlSort.' 
-		LIMIT ?,  10');
+		LIMIT '.$offset.',  10');
 }
 
 $bookmarks = $query->execute($params)->fetchAll();
-- 
cgit v1.2.3


From 3c5a6a356a6d07df4111444620b578f22951f939 Mon Sep 17 00:00:00 2001
From: Brice Maron <brice@bmaron.net>
Date: Mon, 17 Oct 2011 20:39:01 +0200
Subject: Use notification to inform about errors in file list.

---
 files/js/filelist.js | 17 +++++++++++------
 files/js/files.js    | 20 ++++++++++++++------
 2 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/files/js/filelist.js b/files/js/filelist.js
index e6da922700d..3e85a35f6ef 100644
--- a/files/js/filelist.js
+++ b/files/js/filelist.js
@@ -173,6 +173,7 @@ FileList={
 		FileList.deleteCanceled=false;
 		FileList.deleteFiles=files;
 		$('#notification').text(t('files','undo deletion'));
+		$('#notification').data('deletefile',true);
 		$('#notification').fadeIn();
 	},
 	finishDelete:function(ready,sync){
@@ -204,14 +205,18 @@ FileList={
 $(document).ready(function(){
 	$('#notification').hide();
 	$('#notification').click(function(){
-		FileList.deleteCanceled=true;
-		$('#notification').fadeOut();
-		$.each(FileList.deleteFiles,function(index,file){
-			$('tr[data-file="'+file+'"]').show();
+		if($('#notification').data('deletefile'))
+		{
+			$.each(FileList.deleteFiles,function(index,file){
+				$('tr[data-file="'+file+'"]').show();
 // 			alert(file);
-		});
-		FileList.deleteFiles=null;
+			});
+			FileList.deleteCanceled=true;
+			FileList.deleteFiles=null;
+		}
+		$('#notification').fadeOut();
 	});
+	
 	$(window).bind('beforeunload', function (){
 		FileList.finishDelete(null,true);
 	});
diff --git a/files/js/files.js b/files/js/files.js
index 079646070d4..902c5e54934 100644
--- a/files/js/files.js
+++ b/files/js/files.js
@@ -182,13 +182,21 @@ $(document).ready(function() {
 				var response=jQuery.parseJSON(target.contents().find('body').text());
 				//set mimetype and if needed filesize
 				if(response){
-					for(var i=0;i<response.length;i++){
-						var file=response[i];
-						$('tr[data-file="'+file.name+'"]').data('mime',file.mime);
-						if(size=='Pending'){
-							$('tr[data-file='+file.name+'] td.filesize').text(file.size);
+					if(response[0] != undefined && response[0].status == 'success'){
+						for(var i=0;i<response.length;i++){
+							var file=response[i];
+							$('tr[data-file="'+file.name+'"]').data('mime',file.mime);
+							if(size=='Pending'){
+								$('tr[data-file='+file.name+'] td.filesize').text(file.size);
+							}
+							FileList.loadingDone(file.name);
 						}
-						FileList.loadingDone(file.name);
+					}
+					else{
+						$('#notification').text(t('files',response.data.message));
+						$('#notification').fadeIn();
+						$('#fileList > tr').not('[data-mime]').fadeOut();
+						$('#fileList > tr').not('[data-mime]').remove();
 					}
 				}
 			});
-- 
cgit v1.2.3


From 7358d9ebb47027340ce97192eb6c86592117d3f3 Mon Sep 17 00:00:00 2001
From: Brice Maron <brice@bmaron.net>
Date: Mon, 17 Oct 2011 20:50:41 +0200
Subject: Fix quota onBlur In Settings, Take from right attribute

---
 settings/js/users.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/settings/js/users.js b/settings/js/users.js
index 64a132b427e..684fee21c64 100644
--- a/settings/js/users.js
+++ b/settings/js/users.js
@@ -111,7 +111,7 @@ $(document).ready(function(){
 			}
 		});
 		input.blur(function(){
-			var quota=$(this).parent().data('quota');
+			var quota=$(this).parent().attr('data-quota');
 			$(this).replaceWith($('<span>'+quota+'</span>'));
 			img.css('display','');
 		});
-- 
cgit v1.2.3


From ebd36d56caec3f665f750ac934a533df57074112 Mon Sep 17 00:00:00 2001
From: Brice Maron <brice@bmaron.net>
Date: Mon, 17 Oct 2011 21:42:38 +0200
Subject: Remove unnecessary exec for getting timezone and fix spacings

---
 lib/util.php | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/util.php b/lib/util.php
index 0f8cc08fce6..6f3b7e3428a 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -153,7 +153,7 @@ class OC_Util {
          */
         public static function formatDate( $timestamp,$dateOnly=false){
 			if(isset($_SESSION['timezone'])){//adjust to clients timezone if we know it
-				$systemTimeZone = intval(exec('date +%z'));
+				$systemTimeZone = intval(date('O'));
 				$systemTimeZone=(round($systemTimeZone/100,0)*60)+($systemTimeZone%100);
 				$clientTimeZone=$_SESSION['timezone']*60;
 				$offset=$clientTimeZone-$systemTimeZone;
@@ -270,17 +270,17 @@ class OC_Util {
 	/**
 	* Try to get the username the httpd server runs on, used in hints
 	*/
-        public static function checkWebserverUser(){
+	public static function checkWebserverUser(){
 		if(is_callable('posix_getuid')){
 			$serverUser=posix_getpwuid(posix_getuid());
 			$serverUser='\''.$serverUser['name'].'\'';
 		}elseif(exec('whoami')){
-                	$serverUser=exec('whoami');
-                }else{
+			$serverUser=exec('whoami');
+		}else{
 			$serverUser='\'www-data\' for ubuntu/debian'; //TODO: try to detect the distro and give a guess based on that
 		}
-                return $serverUser;
-        }
+		return $serverUser;
+	}
 
 
 	/**
-- 
cgit v1.2.3


From 2ac00b378a536b67a85bf5972952663ca432d115 Mon Sep 17 00:00:00 2001
From: Brice Maron <brice@bmaron.net>
Date: Mon, 17 Oct 2011 23:39:23 +0200
Subject: Fix file sharing : Don't give a unused param to execute

---
 apps/files_sharing/lib_share.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php
index 978847f4a8f..0f1ddfee32f 100644
--- a/apps/files_sharing/lib_share.php
+++ b/apps/files_sharing/lib_share.php
@@ -60,7 +60,7 @@ class OC_Share {
 			foreach ($uid_shared_with as $uid) {
 				// Check if this item is already shared with the user
 				$checkSource = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE source = ? AND uid_shared_with ".self::getUsersAndGroups($uid));
-				$resultCheckSource = $checkSource->execute(array($source, $uid))->fetchAll();
+				$resultCheckSource = $checkSource->execute(array($source))->fetchAll();
 				// TODO Check if the source is inside a folder
 				if (count($resultCheckSource) > 0 && !isset($gid)) {
 					throw new Exception("This item is already shared with ".$uid);
-- 
cgit v1.2.3


From 59eac3bc29426b4871b03e9d173467e7b8059501 Mon Sep 17 00:00:00 2001
From: Brice Maron <brice@bmaron.net>
Date: Tue, 18 Oct 2011 20:10:17 +0200
Subject: Correct little typo/bug in log display and remove ending php tag

---
 apps/files_sharing/ajax/getitem.php | 2 --
 settings/log.php                    | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/apps/files_sharing/ajax/getitem.php b/apps/files_sharing/ajax/getitem.php
index 8d51c146523..075ec043eac 100644
--- a/apps/files_sharing/ajax/getitem.php
+++ b/apps/files_sharing/ajax/getitem.php
@@ -33,5 +33,3 @@ while ($source != "" && $source != "/" && $source != "." && $source != $userDire
 if (!empty($users)) {
 	OC_JSON::encodedPrint($users);
 }
-
-?>
diff --git a/settings/log.php b/settings/log.php
index e181a5a4967..21303c2170f 100644
--- a/settings/log.php
+++ b/settings/log.php
@@ -31,7 +31,7 @@ OC_App::setActiveNavigationEntry( "core_log" );
 $entries=OC_Log::getEntries();
 
 function compareEntries($a,$b){
-	return $b->time-$a>time;
+	return $b->time - $a->time;
 }
 usort($entries, 'compareEntries');
 
-- 
cgit v1.2.3


From 28ab39073a8ea942a7c299dc41ddf6023dd093de Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind1991@gmail.com>
Date: Tue, 18 Oct 2011 21:01:49 +0200
Subject: mount filesystems on demand

---
 lib/filesystem.php | 13 +++++++++----
 lib/util.php       | 31 +++----------------------------
 2 files changed, 12 insertions(+), 32 deletions(-)

diff --git a/lib/filesystem.php b/lib/filesystem.php
index f84cda20eac..60fd051f303 100644
--- a/lib/filesystem.php
+++ b/lib/filesystem.php
@@ -44,6 +44,7 @@
  */
 class OC_Filesystem{
 	static private $storages=array();
+	static private $mounts=array();
 	static private $fakeRoot='';
 	static private $storageTypes=array();
 	
@@ -91,7 +92,7 @@ class OC_Filesystem{
 	* @param  array  arguments
 	* @return OC_Filestorage
 	*/
-	static public function createStorage($type,$arguments){
+	static private function createStorage($type,$arguments){
 		if(!self::hasStorageType($type)){
 			return false;
 		}
@@ -163,11 +164,11 @@ class OC_Filesystem{
 	* @param OC_Filestorage storage
 	* @param string mountpoint
 	*/
-	static public function mount($storage,$mountpoint){
+	static public function mount($type,$arguments,$mountpoint){
 		if(substr($mountpoint,0,1)!=='/'){
 			$mountpoint='/'.$mountpoint;
 		}
-		self::$storages[self::$fakeRoot.$mountpoint]=$storage;
+		self::$mounts[self::$fakeRoot.$mountpoint]=array('type'=>$type,'arguments'=>$arguments);
 	}
 	
 	/**
@@ -178,6 +179,10 @@ class OC_Filesystem{
 	static public function getStorage($path){
 		$mountpoint=self::getMountPoint($path);
 		if($mountpoint){
+			if(!isset(self::$storages[$mountpoint])){
+				$mount=self::$mounts[$mountpoint];
+				self::$storages[$mountpoint]=self::createStorage($mount['type'],$mount['arguments']);
+			}
 			return self::$storages[$mountpoint];
 		}
 	}
@@ -201,7 +206,7 @@ class OC_Filesystem{
 		}
 		$path=self::$fakeRoot.$path;
 		$foundMountPoint='';
-		foreach(self::$storages as $mountpoint=>$storage){
+		foreach(self::$mounts as $mountpoint=>$storage){
 			if(substr($mountpoint,-1)!=='/'){
 				$mountpoint=$mountpoint.'/';
 			}
diff --git a/lib/util.php b/lib/util.php
index 6f3b7e3428a..ec92a986008 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -36,42 +36,17 @@ class OC_Util {
 		}
 
 		if( $user != "" ){ //if we aren't logged in, there is no use to set up the filesystem
-			//first set up the local "root" storage and the backupstorage if needed
-			$rootStorage=OC_Filesystem::createStorage('local',array('datadir'=>$CONFIG_DATADIRECTORY_ROOT));
-// 			if( OC_Config::getValue( "enablebackup", false )){
-// 				// This creates the Directorys recursively
-// 				if(!is_dir( "$CONFIG_BACKUPDIRECTORY/$user/$root" )){
-// 					mkdir( "$CONFIG_BACKUPDIRECTORY/$user/$root", 0755, true );
-// 				}
-// 				$backupStorage=OC_Filesystem::createStorage('local',array('datadir'=>$CONFIG_BACKUPDIRECTORY));
-// 				$backup=new OC_FILEOBSERVER_BACKUP(array('storage'=>$backupStorage));
-// 				$rootStorage->addObserver($backup);
-// 			}
-			OC_Filesystem::mount($rootStorage,'/');
+			//first set up the local "root" storage
+			OC_Filesystem::mount('local',array('datadir'=>$CONFIG_DATADIRECTORY_ROOT),'/');
 
 			// TODO add this storage provider in a proper way
-			$sharedStorage = OC_Filesystem::createStorage('shared',array('datadir'=>'/'.OC_User::getUser().'/files/Shared'));
-			OC_Filesystem::mount($sharedStorage,'/'.OC_User::getUser().'/files/Shared/');
+			OC_Filesystem::mount('shared',array('datadir'=>'/'.OC_User::getUser().'/files/Shared'),'/'.OC_User::getUser().'/files/Shared/');
 
 			OC::$CONFIG_DATADIRECTORY = $CONFIG_DATADIRECTORY_ROOT."/$user/$root";
 			if( !is_dir( OC::$CONFIG_DATADIRECTORY )){
 				mkdir( OC::$CONFIG_DATADIRECTORY, 0755, true );
 			}
 
-// TODO: find a cool way for doing this
-// 			//set up the other storages according to the system settings
-// 			foreach($CONFIG_FILESYSTEM as $storageConfig){
-// 				if(OC_Filesystem::hasStorageType($storageConfig['type'])){
-// 					$arguments=$storageConfig;
-// 					unset($arguments['type']);
-// 					unset($arguments['mountpoint']);
-// 					$storage=OC_Filesystem::createStorage($storageConfig['type'],$arguments);
-// 					if($storage){
-// 						OC_Filesystem::mount($storage,$storageConfig['mountpoint']);
-// 					}
-// 				}
-// 			}
-
 			//jail the user into his "home" directory
 			OC_Filesystem::chroot("/$user/$root");
 			$quotaProxy=new OC_FileProxy_Quota();
-- 
cgit v1.2.3


From b975f1151451785f8350a12bf63d8fd63f0d04b4 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind1991@gmail.com>
Date: Tue, 18 Oct 2011 21:19:13 +0200
Subject: make sharing work with the new mouting mechanism

---
 apps/files_sharing/sharedstorage.php | 12 +++++-------
 lib/base.php                         | 14 +++++++-------
 lib/filesystem.php                   |  2 +-
 lib/util.php                         |  3 ---
 4 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php
index 53f25b60e91..faf4e68d9b1 100644
--- a/apps/files_sharing/sharedstorage.php
+++ b/apps/files_sharing/sharedstorage.php
@@ -22,6 +22,11 @@
 
 require_once( 'lib_share.php' );
 
+if (!OC_Filesystem::is_dir('/Shared')) {
+	OC_Filesystem::mkdir('/Shared');
+}
+OC_Filesystem::mount('shared',array('datadir'=>'/'.OC_User::getUser().'/files/Shared'),'/'.OC_User::getUser().'/files/Shared/');
+
 /**
  * Convert target path to source path and pass the function call to the correct storage provider
  */
@@ -32,13 +37,6 @@ class OC_Filestorage_Shared extends OC_Filestorage {
 	
 	public function __construct($arguments) {
 		$this->datadir = $arguments['datadir'];
-		if (OC_Share::getItemsInFolder($this->datadir)) {
-			if (!OC_Filesystem::is_dir($this->datadir)) { 
-				OC_Filesystem::mkdir($this->datadir);
-			}
-		} else  if (OC_Filesystem::is_dir($this->datadir)) {
-			OC_Filesystem::rmdir($this->datadir);
-		}
 		$this->datadir .= "/";
 	}
 	
diff --git a/lib/base.php b/lib/base.php
index ade4d889631..8adb1cc9102 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -154,13 +154,6 @@ class OC{
 		OC_User::useBackend( OC_Config::getValue( "userbackend", "database" ));
 		OC_Group::setBackend( OC_Config::getValue( "groupbackend", "database" ));
 
-		// Load Apps
-		// This includes plugins for users and filesystems as well
-		global $RUNTIME_NOAPPS;
-		if(!$RUNTIME_NOAPPS ){
-			OC_App::loadApps();
-		}
-
 		// Was in required file ... put it here
 		OC_Filesystem::registerStorageType('local','OC_Filestorage_Local',array('datadir'=>'string'));
 
@@ -170,6 +163,13 @@ class OC{
 			OC_Util::setupFS();
 		}
 
+		// Load Apps
+		// This includes plugins for users and filesystems as well
+		global $RUNTIME_NOAPPS;
+		if(!$RUNTIME_NOAPPS ){
+			OC_App::loadApps();
+		}
+
 		// Last part: connect some hooks
 		OC_HOOK::connect('OC_User', 'post_createUser', 'OC_Connector_Sabre_Principal', 'addPrincipal');
 		OC_HOOK::connect('OC_User', 'post_deleteUser', 'OC_Connector_Sabre_Principal', 'deletePrincipal');
diff --git a/lib/filesystem.php b/lib/filesystem.php
index 60fd051f303..3497431f1ee 100644
--- a/lib/filesystem.php
+++ b/lib/filesystem.php
@@ -168,7 +168,7 @@ class OC_Filesystem{
 		if(substr($mountpoint,0,1)!=='/'){
 			$mountpoint='/'.$mountpoint;
 		}
-		self::$mounts[self::$fakeRoot.$mountpoint]=array('type'=>$type,'arguments'=>$arguments);
+		self::$mounts[$mountpoint]=array('type'=>$type,'arguments'=>$arguments);
 	}
 	
 	/**
diff --git a/lib/util.php b/lib/util.php
index ec92a986008..90cc1f6123a 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -39,9 +39,6 @@ class OC_Util {
 			//first set up the local "root" storage
 			OC_Filesystem::mount('local',array('datadir'=>$CONFIG_DATADIRECTORY_ROOT),'/');
 
-			// TODO add this storage provider in a proper way
-			OC_Filesystem::mount('shared',array('datadir'=>'/'.OC_User::getUser().'/files/Shared'),'/'.OC_User::getUser().'/files/Shared/');
-
 			OC::$CONFIG_DATADIRECTORY = $CONFIG_DATADIRECTORY_ROOT."/$user/$root";
 			if( !is_dir( OC::$CONFIG_DATADIRECTORY )){
 				mkdir( OC::$CONFIG_DATADIRECTORY, 0755, true );
-- 
cgit v1.2.3


From 29368d1c58d1c52420f46cf41a1b975a23751814 Mon Sep 17 00:00:00 2001
From: Brice Maron <brice@bmaron.net>
Date: Tue, 18 Oct 2011 21:29:48 +0200
Subject: Add 3 More log writing in files sharing app

---
 apps/files_sharing/ajax/share.php | 2 ++
 apps/files_sharing/lib_share.php  | 1 +
 2 files changed, 3 insertions(+)

diff --git a/apps/files_sharing/ajax/share.php b/apps/files_sharing/ajax/share.php
index 6a2b45b3a7d..d1f50994317 100644
--- a/apps/files_sharing/ajax/share.php
+++ b/apps/files_sharing/ajax/share.php
@@ -15,6 +15,7 @@ foreach ($sources as $source) {
 		$source = $userDirectory.$source;
 	// If the file doesn't exist, it may be shared with the current user
 	} else if (!$source = OC_Share::getSource($userDirectory.$source)) {
+		OC_Log::write('files_sharing',"Shared file doesn't exists :".$source,OC_Log::ERROR);
 		echo "false";
 	}
 	try {
@@ -23,6 +24,7 @@ foreach ($sources as $source) {
 			echo $shared->getToken();
 		}
 	} catch (Exception $exception) {
+		OC_Log::write('files_sharing',"Unexpected Error : ".$exception->getMessage(),OC_Log::ERROR);
 		echo "false";
 	}
 }
diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php
index 0f1ddfee32f..cde33fd1dc5 100644
--- a/apps/files_sharing/lib_share.php
+++ b/apps/files_sharing/lib_share.php
@@ -282,6 +282,7 @@ class OC_Share {
 					return $result[0]['permissions'];
 				}
 			} else {
+				OC_Log::write('files_sharing',"Not existing parent folder : ".$target,OC_Log::ERROR);
 				return false;
 			}
 		}
-- 
cgit v1.2.3


From b15d8878b7f2084dc5bc441911a86799379a6cbd Mon Sep 17 00:00:00 2001
From: Brice Maron <brice@bmaron.net>
Date: Tue, 18 Oct 2011 22:41:25 +0200
Subject: Correct use of null for not null columns in media scanner

---
 apps/media/lib_collection.php | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/apps/media/lib_collection.php b/apps/media/lib_collection.php
index 82c4afedd0a..54e317df930 100644
--- a/apps/media/lib_collection.php
+++ b/apps/media/lib_collection.php
@@ -43,7 +43,7 @@ class OC_MEDIA_COLLECTION{
 		if(isset(self::$artistIdCache[$name])){
 			return self::$artistIdCache[$name];
 		}else{
-			$query=OC_DB::prepare("SELECT artist_id FROM *PREFIX*media_artists WHERE artist_name LIKE ?");
+			$query=OC_DB::prepare("SELECT artist_id FROM *PREFIX*media_artists WHERE lower(artist_name) LIKE ?");
 			$artists=$query->execute(array($name))->fetchAll();
 			if(is_array($artists) and isset($artists[0])){
 				self::$artistIdCache[$name]=$artists[0]['artist_id'];
@@ -146,7 +146,7 @@ class OC_MEDIA_COLLECTION{
 		if($artistId!=0){
 			return $artistId;
 		}else{
-			$query=OC_DB::prepare("INSERT INTO `*PREFIX*media_artists` (`artist_id` ,`artist_name`) VALUES (NULL ,  ?)");
+			$query=OC_DB::prepare("INSERT INTO `*PREFIX*media_artists` (`artist_name`) VALUES (?)");
 			$result=$query->execute(array($name));
 			return self::getArtistId($name);;
 		}
@@ -193,7 +193,7 @@ class OC_MEDIA_COLLECTION{
 		if($albumId!=0){
 			return $albumId;
 		}else{
-			$query=OC_DB::prepare("INSERT INTO  `*PREFIX*media_albums` (`album_id` ,`album_name` ,`album_artist`) VALUES (NULL , ?, ?)");
+			$query=OC_DB::prepare("INSERT INTO  `*PREFIX*media_albums` (`album_name` ,`album_artist`) VALUES ( ?, ?)");
 			$query->execute(array($name,$artist));
 			return self::getAlbumId($name,$artist);
 		}
-- 
cgit v1.2.3


From 9ea34250a0d2e6c058d8869e0259026c083fa41e Mon Sep 17 00:00:00 2001
From: Brice Maron <brice@bmaron.net>
Date: Tue, 18 Oct 2011 23:15:47 +0200
Subject: Lower also the album name in media scanner...

---
 apps/media/lib_collection.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/apps/media/lib_collection.php b/apps/media/lib_collection.php
index 54e317df930..571cb7e6850 100644
--- a/apps/media/lib_collection.php
+++ b/apps/media/lib_collection.php
@@ -71,7 +71,7 @@ class OC_MEDIA_COLLECTION{
 		if(isset(self::$albumIdCache[$artistId][$name])){
 			return self::$albumIdCache[$artistId][$name];
 		}else{
-			$query=OC_DB::prepare("SELECT album_id FROM *PREFIX*media_albums WHERE album_name LIKE ? AND album_artist=?");
+			$query=OC_DB::prepare("SELECT album_id FROM *PREFIX*media_albums WHERE lower(album_name) LIKE ? AND album_artist=?");
 			$albums=$query->execute(array($name,$artistId))->fetchAll();
 			if(is_array($albums) and isset($albums[0])){
 				self::$albumIdCache[$artistId][$name]=$albums[0]['album_id'];
-- 
cgit v1.2.3


From da8d32ae38acdab576a30ca56b30579f427c780d Mon Sep 17 00:00:00 2001
From: Brice Maron <brice@bmaron.net>
Date: Tue, 18 Oct 2011 23:27:53 +0200
Subject: Tweak bookmarklet to not change the current page. Correct encoding
 when add bookmark

---
 apps/bookmarks/addBm.php              | 4 ++--
 apps/bookmarks/templates/settings.php | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/apps/bookmarks/addBm.php b/apps/bookmarks/addBm.php
index a7cdcee8faa..62ad5821dbf 100644
--- a/apps/bookmarks/addBm.php
+++ b/apps/bookmarks/addBm.php
@@ -39,7 +39,7 @@ $tmpl = new OC_Template( 'bookmarks', 'addBm', 'user' );
 $url = isset($_GET['url']) ? urldecode($_GET['url']) : '';
 $metadata = getURLMetadata($url);
 
-$tmpl->assign('URL', htmlentities($metadata['url']));
-$tmpl->assign('TITLE', htmlentities($metadata['title']));
+$tmpl->assign('URL', htmlentities($metadata['url'],ENT_COMPAT,'utf-8'));
+$tmpl->assign('TITLE', htmlentities($metadata['title'],ENT_COMPAT,'utf-8'));
 
 $tmpl->printPage();
diff --git a/apps/bookmarks/templates/settings.php b/apps/bookmarks/templates/settings.php
index b7da441c2f8..97b6b256c09 100644
--- a/apps/bookmarks/templates/settings.php
+++ b/apps/bookmarks/templates/settings.php
@@ -8,7 +8,7 @@
 ?>
 <form id="bookmarks">
 		<fieldset class="personalblock">
-			<span class="bold"><?php echo $l->t('Bookmarklet:');?></span>&nbsp;<a class="bookmarks_addBml" href="javascript:var url = encodeURIComponent(location.href);window.open('<?php echo OC_Helper::linkTo('bookmarks', 'addBm.php', null, true); ?>?url='+url, 'owncloud-bookmarks');"><?php echo $l->t('Add page to ownCloud'); ?></a>
+			<span class="bold"><?php echo $l->t('Bookmarklet:');?></span>&nbsp;<a class="bookmarks_addBml" href="javascript:(function(){url=encodeURIComponent(location.href);window.open('<?php echo OC_Helper::linkTo('bookmarks', 'addBm.php', null, true); ?>?url='+url, 'owncloud-bookmarks') })()"><?php echo $l->t('Add page to ownCloud'); ?></a>
 			<br/><em><?php echo $l->t('Drag this to your browser bookmarks and click it, when you want to bookmark a webpage.'); ?></em><br />
 		</fieldset>
 </form>
-- 
cgit v1.2.3


From 7e344527461194cc2cee9085648bfbd450ef1f7f Mon Sep 17 00:00:00 2001
From: Brice Maron <brice@bmaron.net>
Date: Wed, 19 Oct 2011 22:42:44 +0200
Subject: Little trick to avoid editor loading twice on double click

---
 apps/files_texteditor/js/editor.js | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/apps/files_texteditor/js/editor.js b/apps/files_texteditor/js/editor.js
index f7b924d494d..a0629aa8c4e 100644
--- a/apps/files_texteditor/js/editor.js
+++ b/apps/files_texteditor/js/editor.js
@@ -73,11 +73,7 @@ function bindControlEvents(){
 
 function editorIsShown(){
 	// Not working as intended. Always returns true.
-	if(window.aceEditor){
-		return true;
-	} else {
-		return false;	
-	}
+	return is_editor_shown;
 }
 
 function updateSessionFileHash(path){
@@ -174,6 +170,7 @@ function showFileEditor(dir,filename){
 				}
 				// End ajax
 				});
+		is_editor_shown = true;
 	}
 }
 
@@ -194,12 +191,13 @@ function hideFileEditor(){
 		$('.actions,#file_access_panel').fadeIn('slow');
 		$('table').fadeIn('slow');	
 	});
+	is_editor_shown = false;
 }
 
 $(window).resize(function() {
 	setEditorSize();
 });
-
+var is_editor_shown = false;
 $(document).ready(function(){
 	if(typeof FileActions!=='undefined'){
 		FileActions.register('text','Edit','',function(filename){
-- 
cgit v1.2.3


From 466b41c36bf7093cdde9d2856eb520503f52640c Mon Sep 17 00:00:00 2001
From: Hendrik Langer <hendrik.langer@gmx.de>
Date: Wed, 19 Oct 2011 23:38:35 +0200
Subject: Don't use sys_get_temp_dir(), as it reports the wrong path in
 restricted environments

---
 apps/admin_export/settings.php |  2 +-
 apps/user_openid/phpmyid.php   | 48 ++++++++++++++++++++++++------------------
 lib/base.php                   | 25 +++++++++++-----------
 lib/db.php                     |  4 ++--
 lib/files.php                  |  6 +++---
 lib/filestorage/local.php      |  2 +-
 lib/filestorage/remote.php     |  2 +-
 lib/installer.php              |  4 ++--
 lib/remote/cloud.php           |  8 +++----
 9 files changed, 55 insertions(+), 46 deletions(-)

diff --git a/apps/admin_export/settings.php b/apps/admin_export/settings.php
index cf1daa250f7..a33c872ccf4 100644
--- a/apps/admin_export/settings.php
+++ b/apps/admin_export/settings.php
@@ -25,7 +25,7 @@ OC_Util::checkAppEnabled('admin_export');
 if (isset($_POST['admin_export'])) {
     $root = OC::$SERVERROOT . "/";
     $zip = new ZipArchive();
-    $filename = sys_get_temp_dir() . "/owncloud_export_" . date("y-m-d_H-i-s") . ".zip";
+    $filename = get_temp_dir() . "/owncloud_export_" . date("y-m-d_H-i-s") . ".zip";
     OC_Log::write('admin_export',"Creating export file at: " . $filename,OC_Log::INFO);
     if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
 	exit("Cannot open <$filename>\n");
diff --git a/apps/user_openid/phpmyid.php b/apps/user_openid/phpmyid.php
index d8168c9a10d..c984dc8f5e6 100644
--- a/apps/user_openid/phpmyid.php
+++ b/apps/user_openid/phpmyid.php
@@ -603,7 +603,7 @@ function test_mode () {
 		$res['gmp'] = 'pass - n/a';
 	}
 
-	// sys_get_temp_dir
+	// get_temp_dir
 	$res['logfile'] = is_writable($profile['logfile'])
 		? 'pass' : "warn - log is not writable";
 
@@ -1374,30 +1374,38 @@ function str_diff_at ($a, $b) {
 }
 
 
-if (! function_exists('sys_get_temp_dir') && ini_get('open_basedir') == false) {
+if (! function_exists('get_temp_dir')) {
 /**
  * Create function if missing
  * @return string
  */
-function sys_get_temp_dir () {
-	$keys = array('TMP', 'TMPDIR', 'TEMP');
-	foreach ($keys as $key) {
-		if (isset($_ENV[$key]) && is_dir($_ENV[$key]) && is_writable($_ENV[$key]))
-			return realpath($_ENV[$key]);
-	}
+	if (ini_get('open_basedir') == false) {
+		function get_temp_dir () {
+			$keys = array('TMP', 'TMPDIR', 'TEMP');
+			foreach ($keys as $key) {
+				if (isset($_ENV[$key]) && is_dir($_ENV[$key]) && is_writable($_ENV[$key]))
+					return realpath($_ENV[$key]);
+			}
 
-	$tmp = tempnam(false, null);
-	if (file_exists($tmp)) {
-		$dir = realpath(dirname($tmp));
-		unlink($tmp);
-		return realpath($dir);
-	}
+			$tmp = tempnam(false, null);
+			if (file_exists($tmp)) {
+				$dir = realpath(dirname($tmp));
+				unlink($tmp);
+				return realpath($dir);
+			}
 
-	return realpath(dirname(__FILE__));
-}} elseif (! function_exists('sys_get_temp_dir')) {
-function sys_get_temp_dir () {
-	return realpath(dirname(__FILE__));
-}}
+			return realpath(dirname(__FILE__));
+		}
+	}
+	else {
+		function get_temp_dir () {
+			if (isset(ini_get('upload_tmp_dir')) && is_dir(ini_get('upload_tmp_dir')) && is_writable(ini_get('upload_tmp_dir')))
+				return ini_get('upload_tmp_dir');
+			else
+				return realpath(dirname(__FILE__));
+		}
+	}
+}
 
 
 /**
@@ -1694,7 +1702,7 @@ if (! array_key_exists('lifetime', $profile)) {
 
 // Set a default log file
 if (! array_key_exists('logfile', $profile))
-	$profile['logfile'] = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $profile['auth_realm'] . '.debug.log';
+	$profile['logfile'] = get_temp_dir() . DIRECTORY_SEPARATOR . $profile['auth_realm'] . '.debug.log';
 
 
 /*
diff --git a/lib/base.php b/lib/base.php
index 8adb1cc9102..d5fff1e0a74 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -186,18 +186,19 @@ if( !isset( $RUNTIME_NOAPPS )){
 
 OC::init();
 
-if(!function_exists('sys_get_temp_dir')) {
-    function sys_get_temp_dir() {
-        if( $temp=getenv('TMP') )        return $temp;
-        if( $temp=getenv('TEMP') )        return $temp;
-        if( $temp=getenv('TMPDIR') )    return $temp;
-        $temp=tempnam(__FILE__,'');
-        if (file_exists($temp)) {
-          unlink($temp);
-          return dirname($temp);
-        }
-        return null;
-    }
+if(!function_exists('get_temp_dir')) {
+	function get_temp_dir() {
+		if( $temp=ini_get('upload_tmp_dir') )        return $temp;
+		if( $temp=getenv('TMP') )        return $temp;
+		if( $temp=getenv('TEMP') )        return $temp;
+		if( $temp=getenv('TMPDIR') )    return $temp;
+		$temp=tempnam(__FILE__,'');
+		if (file_exists($temp)) {
+			unlink($temp);
+			return dirname($temp);
+		}
+		return null;
+	}
 }
 
 require_once('fakedirstream.php');
diff --git a/lib/db.php b/lib/db.php
index bcfda4592f2..44be619fde1 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -285,7 +285,7 @@ class OC_DB {
 		$content = file_get_contents( $file );
 		
 		// Make changes and save them to a temporary file
-		$file2 = tempnam( sys_get_temp_dir(), 'oc_db_scheme_' );
+		$file2 = tempnam( get_temp_dir(), 'oc_db_scheme_' );
 		$content = str_replace( '*dbname*', $CONFIG_DBNAME, $content );
 		$content = str_replace( '*dbprefix*', $CONFIG_DBTABLEPREFIX, $content );
 		if( $CONFIG_DBTYPE == 'pgsql' ){ //mysql support it too but sqlite don't
@@ -392,7 +392,7 @@ class OC_DB {
 		$content = file_get_contents( $file );
 
 		// Make changes and save them to a temporary file
-		$file2 = tempnam( sys_get_temp_dir(), 'oc_db_scheme_' );
+		$file2 = tempnam( get_temp_dir(), 'oc_db_scheme_' );
 		$content = str_replace( '*dbname*', $CONFIG_DBNAME, $content );
 		$content = str_replace( '*dbprefix*', $CONFIG_DBTABLEPREFIX, $content );
 		file_put_contents( $file2, $content );
diff --git a/lib/files.php b/lib/files.php
index 631726bf9b5..88b559059f0 100644
--- a/lib/files.php
+++ b/lib/files.php
@@ -91,7 +91,7 @@ class OC_Files {
 
 		if(is_array($files)){
 			$zip = new ZipArchive();
-			$filename = sys_get_temp_dir()."/ownCloud.zip";
+			$filename = get_temp_dir()."/ownCloud.zip";
 			if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
 				exit("cannot open <$filename>\n");
 			}
@@ -108,7 +108,7 @@ class OC_Files {
 			$zip->close();
 		}elseif(OC_Filesystem::is_dir($dir.'/'.$files)){
 			$zip = new ZipArchive();
-			$filename = sys_get_temp_dir()."/ownCloud.zip";
+			$filename = get_temp_dir()."/ownCloud.zip";
 			if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
 				exit("cannot open <$filename>\n");
 			}
@@ -271,7 +271,7 @@ class OC_Files {
 	* @return string  guessed mime type
 	*/
 	static function pull($source,$token,$dir,$file){
-		$tmpfile=tempnam(sys_get_temp_dir(),'remoteCloudFile');
+		$tmpfile=tempnam(get_temp_dir(),'remoteCloudFile');
 		$fp=fopen($tmpfile,'w+');
 		$url=$source.="/files/pull.php?token=$token";
 		$ch=curl_init();
diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php
index 8e0907f8d3b..8db0ffead4e 100644
--- a/lib/filestorage/local.php
+++ b/lib/filestorage/local.php
@@ -161,7 +161,7 @@ class OC_Filestorage_Local extends OC_Filestorage{
 	}
 
 	public function toTmpFile($path){
-		$tmpFolder=sys_get_temp_dir();
+		$tmpFolder=get_temp_dir();
 		$filename=tempnam($tmpFolder,'OC_TEMP_FILE_'.substr($path,strrpos($path,'.')));
 		$fileStats = stat($this->datadir.$path);
 		if(copy($this->datadir.$path,$filename)){
diff --git a/lib/filestorage/remote.php b/lib/filestorage/remote.php
index fb14c4121a2..88bdbca481c 100644
--- a/lib/filestorage/remote.php
+++ b/lib/filestorage/remote.php
@@ -211,7 +211,7 @@ class OC_Filestorage_Remote extends OC_Filestorage{
 		$parent=dirname($path);
 		$name=substr($path,strlen($parent)+1);
 		$file=$this->remote->getFile($parent,$name);
-		$file=tempnam(sys_get_temp_dir(),'oc_');
+		$file=tempnam(get_temp_dir(),'oc_');
 		file_put_contents($file,$data);
 		if($return=$this->remote->sendTmpFile($file,$parent,$name)){
 			$this->notifyObservers($path,OC_FILEACTION_WRITE);
diff --git a/lib/installer.php b/lib/installer.php
index 242ca97934f..9248f68e011 100644
--- a/lib/installer.php
+++ b/lib/installer.php
@@ -62,7 +62,7 @@ class OC_Installer{
 		
 		//download the file if necesary
 		if($data['source']=='http'){
-			$path=tempnam(sys_get_temp_dir(),'oc_installer_');
+			$path=tempnam(get_temp_dir(),'oc_installer_');
 			if(!isset($data['href'])){
 				OC_Log::write('core','No href specified when installing app from http',OC_Log::ERROR);
 				return false;
@@ -77,7 +77,7 @@ class OC_Installer{
 		}
 		
 		//extract the archive in a temporary folder
-		$extractDir=tempnam(sys_get_temp_dir(),'oc_installer_uncompressed_');
+		$extractDir=tempnam(get_temp_dir(),'oc_installer_uncompressed_');
 		unlink($extractDir);
 		mkdir($extractDir);
 		$zip = new ZipArchive;
diff --git a/lib/remote/cloud.php b/lib/remote/cloud.php
index 75d60155d06..a9c74e8bf5f 100644
--- a/lib/remote/cloud.php
+++ b/lib/remote/cloud.php
@@ -17,7 +17,7 @@ class OC_REMOTE_CLOUD{
 	*/
 	private function apiCall($action,$parameters=false,$assoc=false){
 		if(!$this->cookiefile){
-			$this->cookiefile=sys_get_temp_dir().'/remoteCloudCookie'.uniqid();
+			$this->cookiefile=get_temp_dir().'/remoteCloudCookie'.uniqid();
 		}
 		$url=$this->path.='/files/api.php';
 		$fields_string="action=$action&";
@@ -168,9 +168,9 @@ class OC_REMOTE_CLOUD{
 		}
 		$ch=curl_init();
 		if(!$this->cookiefile){
-			$this->cookiefile=sys_get_temp_dir().'/remoteCloudCookie'.uniqid();
+			$this->cookiefile=get_temp_dir().'/remoteCloudCookie'.uniqid();
 		}
-		$tmpfile=tempnam(sys_get_temp_dir(),'remoteCloudFile');
+		$tmpfile=tempnam(get_temp_dir(),'remoteCloudFile');
 		$fp=fopen($tmpfile,'w+');
 		$url=$this->path.="/files/api.php?action=get&dir=$dir&file=$file";
 		curl_setopt($ch,CURLOPT_URL,$url);
@@ -191,7 +191,7 @@ class OC_REMOTE_CLOUD{
 
 	public function sendTmpFile($tmp,$targetDir,$targetFile){
 		$token=sha1(uniqid().$tmp);
-		$file=sys_get_temp_dir().'/'.'remoteCloudFile'.$token;
+		$file=get_temp_dir().'/'.'remoteCloudFile'.$token;
 		rename($tmp,$file);
 		if( OC_Config::getValue( "forcessl", false ) or isset($_SERVER['HTTPS']) and $_SERVER['HTTPS'] == 'on') {
 			$url = "https://". $_SERVER['SERVER_NAME'] . OC::$WEBROOT;
-- 
cgit v1.2.3


From 273972b75af17b228a57c7cf8258ea31f2e2e3bc Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind1991@gmail.com>
Date: Thu, 20 Oct 2011 01:16:48 +0200
Subject: prevent sql error while initializing apps on sqlite2

---
 lib/appconfig.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/appconfig.php b/lib/appconfig.php
index f43ef141732..2b5cef59adc 100644
--- a/lib/appconfig.php
+++ b/lib/appconfig.php
@@ -47,7 +47,7 @@ class OC_Appconfig{
 	 */
 	public static function getApps(){
 		// No magic in here!
-		$query = OC_DB::prepare( 'SELECT DISTINCT( appid ) FROM *PREFIX*appconfig' );
+		$query = OC_DB::prepare( 'SELECT DISTINCT appid FROM *PREFIX*appconfig' );
 		$result = $query->execute();
 
 		$apps = array();
-- 
cgit v1.2.3


From e9b6a1018db89fb23d6e52e529f80ce11da09bd0 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind1991@gmail.com>
Date: Thu, 20 Oct 2011 01:27:04 +0200
Subject: remove unneeded definiton of get_temp_dir

---
 apps/user_openid/phpmyid.php | 35 -----------------------------------
 1 file changed, 35 deletions(-)

diff --git a/apps/user_openid/phpmyid.php b/apps/user_openid/phpmyid.php
index c984dc8f5e6..ef01e7a046d 100644
--- a/apps/user_openid/phpmyid.php
+++ b/apps/user_openid/phpmyid.php
@@ -1373,41 +1373,6 @@ function str_diff_at ($a, $b) {
 	return $n;
 }
 
-
-if (! function_exists('get_temp_dir')) {
-/**
- * Create function if missing
- * @return string
- */
-	if (ini_get('open_basedir') == false) {
-		function get_temp_dir () {
-			$keys = array('TMP', 'TMPDIR', 'TEMP');
-			foreach ($keys as $key) {
-				if (isset($_ENV[$key]) && is_dir($_ENV[$key]) && is_writable($_ENV[$key]))
-					return realpath($_ENV[$key]);
-			}
-
-			$tmp = tempnam(false, null);
-			if (file_exists($tmp)) {
-				$dir = realpath(dirname($tmp));
-				unlink($tmp);
-				return realpath($dir);
-			}
-
-			return realpath(dirname(__FILE__));
-		}
-	}
-	else {
-		function get_temp_dir () {
-			if (isset(ini_get('upload_tmp_dir')) && is_dir(ini_get('upload_tmp_dir')) && is_writable(ini_get('upload_tmp_dir')))
-				return ini_get('upload_tmp_dir');
-			else
-				return realpath(dirname(__FILE__));
-		}
-	}
-}
-
-
 /**
  * Determine if a child URL actually decends from the parent, and that the
  * parent is a good URL.
-- 
cgit v1.2.3


From 3a937f79f72117be16d905d1fa421d93130a48a3 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind1991@gmail.com>
Date: Thu, 20 Oct 2011 22:55:27 +0200
Subject: escape filenames for getMimeType

---
 lib/filestorage/local.php | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php
index 8db0ffead4e..58c34e972de 100644
--- a/lib/filestorage/local.php
+++ b/lib/filestorage/local.php
@@ -140,6 +140,7 @@ class OC_Filestorage_Local extends OC_Filestorage{
 			} else if (OC_Helper::canExecute("file")) {
 				// it looks like we have a 'file' command,
 				// lets see it it does have mime support
+				$fspath=str_replace("'","\'",$fspath);
 				$fp = popen("file -i -b '{$this->datadir}$fspath' 2>/dev/null", "r");
 				$reply = fgets($fp);
 				pclose($fp);
-- 
cgit v1.2.3


From 2906ea3d78d2ff8ebfa3ceebe1c8cb5afa43225a Mon Sep 17 00:00:00 2001
From: Brice Maron <brice@bmaron.net>
Date: Thu, 20 Oct 2011 23:02:38 +0200
Subject: Add caching for filelist sharing icon status to avoid many http req.

---
 apps/files_sharing/js/share.js | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js
index aaffc3824ea..c0fc91e92ad 100644
--- a/apps/files_sharing/js/share.js
+++ b/apps/files_sharing/js/share.js
@@ -1,8 +1,11 @@
 $(document).ready(function() {
+	var shared_status = {};
 	if (typeof FileActions !== 'undefined') {
 		FileActions.register('all', 'Share', function(filename) {
 			var icon;
 			var file = $('#dir').val()+'/'+filename;
+			if(shared_status[file])
+				return shared_status[file].icon;
 			$.ajax({
 				type: 'GET',
 				url: OC.linkTo('files_sharing', 'ajax/getitem.php'),
@@ -20,6 +23,7 @@ $(document).ready(function() {
 					} else {
 						icon = OC.imagePath('core', 'actions/share');
 					}
+					shared_status[file]= { timestamp: new Date().getTime(), icon: icon };
 				}
 			});
 			return icon;
@@ -54,6 +58,7 @@ $(document).ready(function() {
 	$(this).click(function(event) {
 		if (!($(event.target).hasClass('drop')) && $(event.target).parents().index($('#dropdown')) == -1) {
 			if ($('#dropdown').is(':visible')) {
+				delete shared_status[$('#dropdown').data('file')]; //Remove File from icon cache
 				$('#dropdown').hide('blind', function() {
 					$('#dropdown').remove();
 					$('tr').removeClass('mouseOver');
-- 
cgit v1.2.3


From f0565de900e3abd80557e2912d577a2002809d38 Mon Sep 17 00:00:00 2001
From: Florian Pritz <bluewind@xinu.at>
Date: Sun, 16 Oct 2011 23:16:32 +0200
Subject: use fancybox instead of lightbox

Signed-off-by: Florian Pritz <bluewind@xinu.at>
---
 apps/files_imageviewer/appinfo/app.php             |   4 +-
 .../css/jquery.fancybox-1.3.4.css                  | 359 +++++++++++++++++++++
 apps/files_imageviewer/css/lightbox.css            |  32 --
 apps/files_imageviewer/img/blank.gif               | Bin 0 -> 43 bytes
 apps/files_imageviewer/img/fancy_close.png         | Bin 0 -> 1517 bytes
 apps/files_imageviewer/img/fancy_loading.png       | Bin 0 -> 10195 bytes
 apps/files_imageviewer/img/fancy_nav_left.png      | Bin 0 -> 1446 bytes
 apps/files_imageviewer/img/fancy_nav_right.png     | Bin 0 -> 1454 bytes
 apps/files_imageviewer/img/fancy_shadow_e.png      | Bin 0 -> 107 bytes
 apps/files_imageviewer/img/fancy_shadow_n.png      | Bin 0 -> 106 bytes
 apps/files_imageviewer/img/fancy_shadow_ne.png     | Bin 0 -> 347 bytes
 apps/files_imageviewer/img/fancy_shadow_nw.png     | Bin 0 -> 324 bytes
 apps/files_imageviewer/img/fancy_shadow_s.png      | Bin 0 -> 111 bytes
 apps/files_imageviewer/img/fancy_shadow_se.png     | Bin 0 -> 352 bytes
 apps/files_imageviewer/img/fancy_shadow_sw.png     | Bin 0 -> 340 bytes
 apps/files_imageviewer/img/fancy_shadow_w.png      | Bin 0 -> 103 bytes
 apps/files_imageviewer/img/fancy_title_left.png    | Bin 0 -> 503 bytes
 apps/files_imageviewer/img/fancy_title_main.png    | Bin 0 -> 96 bytes
 apps/files_imageviewer/img/fancy_title_over.png    | Bin 0 -> 70 bytes
 apps/files_imageviewer/img/fancy_title_right.png   | Bin 0 -> 506 bytes
 apps/files_imageviewer/img/fancybox-x.png          | Bin 0 -> 203 bytes
 apps/files_imageviewer/img/fancybox-y.png          | Bin 0 -> 176 bytes
 apps/files_imageviewer/img/fancybox.png            | Bin 0 -> 15287 bytes
 .../js/jquery.fancybox-1.3.4.pack.js               |  46 +++
 .../js/jquery.mousewheel-3.0.4.pack.js             |  14 +
 apps/files_imageviewer/js/lightbox.js              |  68 +---
 apps/gallery/templates/view_album.php              |  14 +-
 27 files changed, 439 insertions(+), 98 deletions(-)
 create mode 100644 apps/files_imageviewer/css/jquery.fancybox-1.3.4.css
 delete mode 100644 apps/files_imageviewer/css/lightbox.css
 create mode 100644 apps/files_imageviewer/img/blank.gif
 create mode 100644 apps/files_imageviewer/img/fancy_close.png
 create mode 100644 apps/files_imageviewer/img/fancy_loading.png
 create mode 100644 apps/files_imageviewer/img/fancy_nav_left.png
 create mode 100644 apps/files_imageviewer/img/fancy_nav_right.png
 create mode 100644 apps/files_imageviewer/img/fancy_shadow_e.png
 create mode 100644 apps/files_imageviewer/img/fancy_shadow_n.png
 create mode 100644 apps/files_imageviewer/img/fancy_shadow_ne.png
 create mode 100644 apps/files_imageviewer/img/fancy_shadow_nw.png
 create mode 100644 apps/files_imageviewer/img/fancy_shadow_s.png
 create mode 100644 apps/files_imageviewer/img/fancy_shadow_se.png
 create mode 100644 apps/files_imageviewer/img/fancy_shadow_sw.png
 create mode 100644 apps/files_imageviewer/img/fancy_shadow_w.png
 create mode 100644 apps/files_imageviewer/img/fancy_title_left.png
 create mode 100644 apps/files_imageviewer/img/fancy_title_main.png
 create mode 100644 apps/files_imageviewer/img/fancy_title_over.png
 create mode 100644 apps/files_imageviewer/img/fancy_title_right.png
 create mode 100644 apps/files_imageviewer/img/fancybox-x.png
 create mode 100644 apps/files_imageviewer/img/fancybox-y.png
 create mode 100644 apps/files_imageviewer/img/fancybox.png
 create mode 100644 apps/files_imageviewer/js/jquery.fancybox-1.3.4.pack.js
 create mode 100644 apps/files_imageviewer/js/jquery.mousewheel-3.0.4.pack.js

diff --git a/apps/files_imageviewer/appinfo/app.php b/apps/files_imageviewer/appinfo/app.php
index 3dfbb76ceb0..0f77076b79b 100644
--- a/apps/files_imageviewer/appinfo/app.php
+++ b/apps/files_imageviewer/appinfo/app.php
@@ -1,6 +1,8 @@
 <?php
 
 OC_Util::addScript( 'files_imageviewer', 'lightbox' );
-OC_Util::addStyle( 'files_imageviewer', 'lightbox' );
+OC_Util::addScript('files_imageviewer', 'jquery.mousewheel-3.0.4.pack');
+OC_Util::addScript('files_imageviewer', 'jquery.fancybox-1.3.4.pack');
+OC_Util::addStyle( 'files_imageviewer', 'jquery.fancybox-1.3.4' );
 
 ?>
diff --git a/apps/files_imageviewer/css/jquery.fancybox-1.3.4.css b/apps/files_imageviewer/css/jquery.fancybox-1.3.4.css
new file mode 100644
index 00000000000..030497750b2
--- /dev/null
+++ b/apps/files_imageviewer/css/jquery.fancybox-1.3.4.css
@@ -0,0 +1,359 @@
+/*
+ * FancyBox - jQuery Plugin
+ * Simple and fancy lightbox alternative
+ *
+ * Examples and documentation at: http://fancybox.net
+ * 
+ * Copyright (c) 2008 - 2010 Janis Skarnelis
+ * That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated.
+ * 
+ * Version: 1.3.4 (11/11/2010)
+ * Requires: jQuery v1.3+
+ *
+ * Dual licensed under the MIT and GPL licenses:
+ *   http://www.opensource.org/licenses/mit-license.php
+ *   http://www.gnu.org/licenses/gpl.html
+ */
+
+#fancybox-loading {
+	position: fixed;
+	top: 50%;
+	left: 50%;
+	width: 40px;
+	height: 40px;
+	margin-top: -20px;
+	margin-left: -20px;
+	cursor: pointer;
+	overflow: hidden;
+	z-index: 1104;
+	display: none;
+}
+
+#fancybox-loading div {
+	position: absolute;
+	top: 0;
+	left: 0;
+	width: 40px;
+	height: 480px;
+	background-image: url('../img/fancybox/fancybox.png');
+}
+
+#fancybox-overlay {
+	position: absolute;
+	top: 0;
+	left: 0;
+	width: 100%;
+	z-index: 1100;
+	display: none;
+}
+
+#fancybox-tmp {
+	padding: 0;
+	margin: 0;
+	border: 0;
+	overflow: auto;
+	display: none;
+}
+
+#fancybox-wrap {
+	position: absolute;
+	top: 0;
+	left: 0;
+	padding: 20px;
+	z-index: 1101;
+	outline: none;
+	display: none;
+}
+
+#fancybox-outer {
+	position: relative;
+	width: 100%;
+	height: 100%;
+	background: #fff;
+}
+
+#fancybox-content {
+	width: 0;
+	height: 0;
+	padding: 0;
+	outline: none;
+	position: relative;
+	overflow: hidden;
+	z-index: 1102;
+	border: 0px solid #fff;
+}
+
+#fancybox-hide-sel-frame {
+	position: absolute;
+	top: 0;
+	left: 0;
+	width: 100%;
+	height: 100%;
+	background: transparent;
+	z-index: 1101;
+}
+
+#fancybox-close {
+	position: absolute;
+	top: -15px;
+	right: -15px;
+	width: 30px;
+	height: 30px;
+	background: transparent url('../img/fancybox.png') -40px 0px;
+	cursor: pointer;
+	z-index: 1103;
+	display: none;
+}
+
+#fancybox-error {
+	color: #444;
+	font: normal 12px/20px Arial;
+	padding: 14px;
+	margin: 0;
+}
+
+#fancybox-img {
+	width: 100%;
+	height: 100%;
+	padding: 0;
+	margin: 0;
+	border: none;
+	outline: none;
+	line-height: 0;
+	vertical-align: top;
+}
+
+#fancybox-frame {
+	width: 100%;
+	height: 100%;
+	border: none;
+	display: block;
+}
+
+#fancybox-left, #fancybox-right {
+	position: absolute;
+	bottom: 0px;
+	height: 100%;
+	width: 35%;
+	cursor: pointer;
+	outline: none;
+	background: transparent url('../img/blank.gif');
+	z-index: 1102;
+	display: none;
+}
+
+#fancybox-left {
+	left: 0px;
+}
+
+#fancybox-right {
+	right: 0px;
+}
+
+#fancybox-left-ico, #fancybox-right-ico {
+	position: absolute;
+	top: 50%;
+	left: -9999px;
+	width: 30px;
+	height: 30px;
+	margin-top: -15px;
+	cursor: pointer;
+	z-index: 1102;
+	display: block;
+}
+
+#fancybox-left-ico {
+	background-image: url('../img/fancybox.png');
+	background-position: -40px -30px;
+}
+
+#fancybox-right-ico {
+	background-image: url('../img/fancybox.png');
+	background-position: -40px -60px;
+}
+
+#fancybox-left:hover, #fancybox-right:hover {
+	visibility: visible; /* IE6 */
+}
+
+#fancybox-left:hover span {
+	left: 20px;
+}
+
+#fancybox-right:hover span {
+	left: auto;
+	right: 20px;
+}
+
+.fancybox-bg {
+	position: absolute;
+	padding: 0;
+	margin: 0;
+	border: 0;
+	width: 20px;
+	height: 20px;
+	z-index: 1001;
+}
+
+#fancybox-bg-n {
+	top: -20px;
+	left: 0;
+	width: 100%;
+	background-image: url('../img/fancybox-x.png');
+}
+
+#fancybox-bg-ne {
+	top: -20px;
+	right: -20px;
+	background-image: url('../img/fancybox.png');
+	background-position: -40px -162px;
+}
+
+#fancybox-bg-e {
+	top: 0;
+	right: -20px;
+	height: 100%;
+	background-image: url('../img/fancybox-y.png');
+	background-position: -20px 0px;
+}
+
+#fancybox-bg-se {
+	bottom: -20px;
+	right: -20px;
+	background-image: url('../img/fancybox.png');
+	background-position: -40px -182px; 
+}
+
+#fancybox-bg-s {
+	bottom: -20px;
+	left: 0;
+	width: 100%;
+	background-image: url('../img/fancybox-x.png');
+	background-position: 0px -20px;
+}
+
+#fancybox-bg-sw {
+	bottom: -20px;
+	left: -20px;
+	background-image: url('../img/fancybox.png');
+	background-position: -40px -142px;
+}
+
+#fancybox-bg-w {
+	top: 0;
+	left: -20px;
+	height: 100%;
+	background-image: url('../img/fancybox-y.png');
+}
+
+#fancybox-bg-nw {
+	top: -20px;
+	left: -20px;
+	background-image: url('../img/fancybox.png');
+	background-position: -40px -122px;
+}
+
+#fancybox-title {
+	font-family: Helvetica;
+	font-size: 12px;
+	z-index: 1102;
+}
+
+.fancybox-title-inside {
+	padding-bottom: 10px;
+	text-align: center;
+	color: #333;
+	background: #fff;
+	position: relative;
+}
+
+.fancybox-title-outside {
+	padding-top: 10px;
+	color: #fff;
+}
+
+.fancybox-title-over {
+	position: absolute;
+	bottom: 0;
+	left: 0;
+	color: #FFF;
+	text-align: left;
+}
+
+#fancybox-title-over {
+	padding: 10px;
+	background-image: url('../img/fancybox/fancy_title_over.png');
+	display: block;
+}
+
+.fancybox-title-float {
+	position: absolute;
+	left: 0;
+	bottom: -20px;
+	height: 32px;
+}
+
+#fancybox-title-float-wrap {
+	border: none;
+	border-collapse: collapse;
+	width: auto;
+}
+
+#fancybox-title-float-wrap td {
+	border: none;
+	white-space: nowrap;
+}
+
+#fancybox-title-float-left {
+	padding: 0 0 0 15px;
+	background: url('../img/fancybox/fancybox.png') -40px -90px no-repeat;
+}
+
+#fancybox-title-float-main {
+	color: #FFF;
+	line-height: 29px;
+	font-weight: bold;
+	padding: 0 0 3px 0;
+	background: url('../img/fancybox/fancybox-x.png') 0px -40px;
+}
+
+#fancybox-title-float-right {
+	padding: 0 0 0 15px;
+	background: url('../img/fancybox/fancybox.png') -55px -90px no-repeat;
+}
+
+/* IE6 */
+
+.fancybox-ie6 #fancybox-close { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_close.png', sizingMethod='scale'); }
+
+.fancybox-ie6 #fancybox-left-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_nav_left.png', sizingMethod='scale'); }
+.fancybox-ie6 #fancybox-right-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_nav_right.png', sizingMethod='scale'); }
+
+.fancybox-ie6 #fancybox-title-over { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_over.png', sizingMethod='scale'); zoom: 1; }
+.fancybox-ie6 #fancybox-title-float-left { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_left.png', sizingMethod='scale'); }
+.fancybox-ie6 #fancybox-title-float-main { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_main.png', sizingMethod='scale'); }
+.fancybox-ie6 #fancybox-title-float-right { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_title_right.png', sizingMethod='scale'); }
+
+.fancybox-ie6 #fancybox-bg-w, .fancybox-ie6 #fancybox-bg-e, .fancybox-ie6 #fancybox-left, .fancybox-ie6 #fancybox-right, #fancybox-hide-sel-frame {
+	height: expression(this.parentNode.clientHeight + "px");
+}
+
+#fancybox-loading.fancybox-ie6 {
+	position: absolute; margin-top: 0;
+	top: expression( (-20 + (document.documentElement.clientHeight ? document.documentElement.clientHeight/2 : document.body.clientHeight/2 ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop )) + 'px');
+}
+
+#fancybox-loading.fancybox-ie6 div	{ background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_loading.png', sizingMethod='scale'); }
+
+/* IE6, IE7, IE8 */
+
+.fancybox-ie .fancybox-bg { background: transparent !important; }
+
+.fancybox-ie #fancybox-bg-n { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_n.png', sizingMethod='scale'); }
+.fancybox-ie #fancybox-bg-ne { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_ne.png', sizingMethod='scale'); }
+.fancybox-ie #fancybox-bg-e { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_e.png', sizingMethod='scale'); }
+.fancybox-ie #fancybox-bg-se { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_se.png', sizingMethod='scale'); }
+.fancybox-ie #fancybox-bg-s { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_s.png', sizingMethod='scale'); }
+.fancybox-ie #fancybox-bg-sw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_sw.png', sizingMethod='scale'); }
+.fancybox-ie #fancybox-bg-w { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_w.png', sizingMethod='scale'); }
+.fancybox-ie #fancybox-bg-nw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fancybox/fancy_shadow_nw.png', sizingMethod='scale'); }
diff --git a/apps/files_imageviewer/css/lightbox.css b/apps/files_imageviewer/css/lightbox.css
deleted file mode 100644
index d96dd051b1e..00000000000
--- a/apps/files_imageviewer/css/lightbox.css
+++ /dev/null
@@ -1,32 +0,0 @@
-#lightbox_overlay{
-	position:fixed;
-	display:none;
-	height:100%;
-	width:100%;
-	top:0px;
-	left:0px;
-	opacity:0.5;
-	filter: alpha(opacity = 50);
-	background-color:black;
-	z-index:9999;
-}
-
-#lightbox{
-	position:fixed;
-	display:none;
-	max-height:90%;
-	max-width:90%;
-	top:10px;
-	margin-left:auto;
-	margin-right:auto;
-	z-index:9999;
-}
-
-#lightbox_loader{
-  text-align:center;
-  position:fixed;
-  top: 40%;
-  left: 50%;
-  color:white;
-}
-#lightbox_loader img { margin-right: 1em;}
\ No newline at end of file
diff --git a/apps/files_imageviewer/img/blank.gif b/apps/files_imageviewer/img/blank.gif
new file mode 100644
index 00000000000..35d42e808f0
Binary files /dev/null and b/apps/files_imageviewer/img/blank.gif differ
diff --git a/apps/files_imageviewer/img/fancy_close.png b/apps/files_imageviewer/img/fancy_close.png
new file mode 100644
index 00000000000..07035307ad4
Binary files /dev/null and b/apps/files_imageviewer/img/fancy_close.png differ
diff --git a/apps/files_imageviewer/img/fancy_loading.png b/apps/files_imageviewer/img/fancy_loading.png
new file mode 100644
index 00000000000..2503017960b
Binary files /dev/null and b/apps/files_imageviewer/img/fancy_loading.png differ
diff --git a/apps/files_imageviewer/img/fancy_nav_left.png b/apps/files_imageviewer/img/fancy_nav_left.png
new file mode 100644
index 00000000000..ebaa6a4fd34
Binary files /dev/null and b/apps/files_imageviewer/img/fancy_nav_left.png differ
diff --git a/apps/files_imageviewer/img/fancy_nav_right.png b/apps/files_imageviewer/img/fancy_nav_right.png
new file mode 100644
index 00000000000..873294e969d
Binary files /dev/null and b/apps/files_imageviewer/img/fancy_nav_right.png differ
diff --git a/apps/files_imageviewer/img/fancy_shadow_e.png b/apps/files_imageviewer/img/fancy_shadow_e.png
new file mode 100644
index 00000000000..2eda0893649
Binary files /dev/null and b/apps/files_imageviewer/img/fancy_shadow_e.png differ
diff --git a/apps/files_imageviewer/img/fancy_shadow_n.png b/apps/files_imageviewer/img/fancy_shadow_n.png
new file mode 100644
index 00000000000..69aa10e233b
Binary files /dev/null and b/apps/files_imageviewer/img/fancy_shadow_n.png differ
diff --git a/apps/files_imageviewer/img/fancy_shadow_ne.png b/apps/files_imageviewer/img/fancy_shadow_ne.png
new file mode 100644
index 00000000000..79f6980a3ba
Binary files /dev/null and b/apps/files_imageviewer/img/fancy_shadow_ne.png differ
diff --git a/apps/files_imageviewer/img/fancy_shadow_nw.png b/apps/files_imageviewer/img/fancy_shadow_nw.png
new file mode 100644
index 00000000000..7182cd938ae
Binary files /dev/null and b/apps/files_imageviewer/img/fancy_shadow_nw.png differ
diff --git a/apps/files_imageviewer/img/fancy_shadow_s.png b/apps/files_imageviewer/img/fancy_shadow_s.png
new file mode 100644
index 00000000000..d8858bfb78e
Binary files /dev/null and b/apps/files_imageviewer/img/fancy_shadow_s.png differ
diff --git a/apps/files_imageviewer/img/fancy_shadow_se.png b/apps/files_imageviewer/img/fancy_shadow_se.png
new file mode 100644
index 00000000000..541e3ffd3e8
Binary files /dev/null and b/apps/files_imageviewer/img/fancy_shadow_se.png differ
diff --git a/apps/files_imageviewer/img/fancy_shadow_sw.png b/apps/files_imageviewer/img/fancy_shadow_sw.png
new file mode 100644
index 00000000000..b451689fa7b
Binary files /dev/null and b/apps/files_imageviewer/img/fancy_shadow_sw.png differ
diff --git a/apps/files_imageviewer/img/fancy_shadow_w.png b/apps/files_imageviewer/img/fancy_shadow_w.png
new file mode 100644
index 00000000000..8a4e4a887f1
Binary files /dev/null and b/apps/files_imageviewer/img/fancy_shadow_w.png differ
diff --git a/apps/files_imageviewer/img/fancy_title_left.png b/apps/files_imageviewer/img/fancy_title_left.png
new file mode 100644
index 00000000000..6049223d1ec
Binary files /dev/null and b/apps/files_imageviewer/img/fancy_title_left.png differ
diff --git a/apps/files_imageviewer/img/fancy_title_main.png b/apps/files_imageviewer/img/fancy_title_main.png
new file mode 100644
index 00000000000..8044271f29b
Binary files /dev/null and b/apps/files_imageviewer/img/fancy_title_main.png differ
diff --git a/apps/files_imageviewer/img/fancy_title_over.png b/apps/files_imageviewer/img/fancy_title_over.png
new file mode 100644
index 00000000000..d9f458f4bb8
Binary files /dev/null and b/apps/files_imageviewer/img/fancy_title_over.png differ
diff --git a/apps/files_imageviewer/img/fancy_title_right.png b/apps/files_imageviewer/img/fancy_title_right.png
new file mode 100644
index 00000000000..e36d9db2a7c
Binary files /dev/null and b/apps/files_imageviewer/img/fancy_title_right.png differ
diff --git a/apps/files_imageviewer/img/fancybox-x.png b/apps/files_imageviewer/img/fancybox-x.png
new file mode 100644
index 00000000000..c2130f8698f
Binary files /dev/null and b/apps/files_imageviewer/img/fancybox-x.png differ
diff --git a/apps/files_imageviewer/img/fancybox-y.png b/apps/files_imageviewer/img/fancybox-y.png
new file mode 100644
index 00000000000..7ef399b9908
Binary files /dev/null and b/apps/files_imageviewer/img/fancybox-y.png differ
diff --git a/apps/files_imageviewer/img/fancybox.png b/apps/files_imageviewer/img/fancybox.png
new file mode 100644
index 00000000000..65e14f68fd8
Binary files /dev/null and b/apps/files_imageviewer/img/fancybox.png differ
diff --git a/apps/files_imageviewer/js/jquery.fancybox-1.3.4.pack.js b/apps/files_imageviewer/js/jquery.fancybox-1.3.4.pack.js
new file mode 100644
index 00000000000..1373ed0838b
--- /dev/null
+++ b/apps/files_imageviewer/js/jquery.fancybox-1.3.4.pack.js
@@ -0,0 +1,46 @@
+/*
+ * FancyBox - jQuery Plugin
+ * Simple and fancy lightbox alternative
+ *
+ * Examples and documentation at: http://fancybox.net
+ * 
+ * Copyright (c) 2008 - 2010 Janis Skarnelis
+ * That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated.
+ * 
+ * Version: 1.3.4 (11/11/2010)
+ * Requires: jQuery v1.3+
+ *
+ * Dual licensed under the MIT and GPL licenses:
+ *   http://www.opensource.org/licenses/mit-license.php
+ *   http://www.gnu.org/licenses/gpl.html
+ */
+
+;(function(b){var m,t,u,f,D,j,E,n,z,A,q=0,e={},o=[],p=0,d={},l=[],G=null,v=new Image,J=/\.(jpg|gif|png|bmp|jpeg)(.*)?$/i,W=/[^\.]\.(swf)\s*$/i,K,L=1,y=0,s="",r,i,h=false,B=b.extend(b("<div/>")[0],{prop:0}),M=b.browser.msie&&b.browser.version<7&&!window.XMLHttpRequest,N=function(){t.hide();v.onerror=v.onload=null;G&&G.abort();m.empty()},O=function(){if(false===e.onError(o,q,e)){t.hide();h=false}else{e.titleShow=false;e.width="auto";e.height="auto";m.html('<p id="fancybox-error">The requested content cannot be loaded.<br />Please try again later.</p>');
+F()}},I=function(){var a=o[q],c,g,k,C,P,w;N();e=b.extend({},b.fn.fancybox.defaults,typeof b(a).data("fancybox")=="undefined"?e:b(a).data("fancybox"));w=e.onStart(o,q,e);if(w===false)h=false;else{if(typeof w=="object")e=b.extend(e,w);k=e.title||(a.nodeName?b(a).attr("title"):a.title)||"";if(a.nodeName&&!e.orig)e.orig=b(a).children("img:first").length?b(a).children("img:first"):b(a);if(k===""&&e.orig&&e.titleFromAlt)k=e.orig.attr("alt");c=e.href||(a.nodeName?b(a).attr("href"):a.href)||null;if(/^(?:javascript)/i.test(c)||
+c=="#")c=null;if(e.type){g=e.type;if(!c)c=e.content}else if(e.content)g="html";else if(c)g=c.match(J)?"image":c.match(W)?"swf":b(a).hasClass("iframe")?"iframe":c.indexOf("#")===0?"inline":"ajax";if(g){if(g=="inline"){a=c.substr(c.indexOf("#"));g=b(a).length>0?"inline":"ajax"}e.type=g;e.href=c;e.title=k;if(e.autoDimensions)if(e.type=="html"||e.type=="inline"||e.type=="ajax"){e.width="auto";e.height="auto"}else e.autoDimensions=false;if(e.modal){e.overlayShow=true;e.hideOnOverlayClick=false;e.hideOnContentClick=
+false;e.enableEscapeButton=false;e.showCloseButton=false}e.padding=parseInt(e.padding,10);e.margin=parseInt(e.margin,10);m.css("padding",e.padding+e.margin);b(".fancybox-inline-tmp").unbind("fancybox-cancel").bind("fancybox-change",function(){b(this).replaceWith(j.children())});switch(g){case "html":m.html(e.content);F();break;case "inline":if(b(a).parent().is("#fancybox-content")===true){h=false;break}b('<div class="fancybox-inline-tmp" />').hide().insertBefore(b(a)).bind("fancybox-cleanup",function(){b(this).replaceWith(j.children())}).bind("fancybox-cancel",
+function(){b(this).replaceWith(m.children())});b(a).appendTo(m);F();break;case "image":h=false;b.fancybox.showActivity();v=new Image;v.onerror=function(){O()};v.onload=function(){h=true;v.onerror=v.onload=null;e.width=v.width;e.height=v.height;b("<img />").attr({id:"fancybox-img",src:v.src,alt:e.title}).appendTo(m);Q()};v.src=c;break;case "swf":e.scrolling="no";C='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+e.width+'" height="'+e.height+'"><param name="movie" value="'+c+
+'"></param>';P="";b.each(e.swf,function(x,H){C+='<param name="'+x+'" value="'+H+'"></param>';P+=" "+x+'="'+H+'"'});C+='<embed src="'+c+'" type="application/x-shockwave-flash" width="'+e.width+'" height="'+e.height+'"'+P+"></embed></object>";m.html(C);F();break;case "ajax":h=false;b.fancybox.showActivity();e.ajax.win=e.ajax.success;G=b.ajax(b.extend({},e.ajax,{url:c,data:e.ajax.data||{},error:function(x){x.status>0&&O()},success:function(x,H,R){if((typeof R=="object"?R:G).status==200){if(typeof e.ajax.win==
+"function"){w=e.ajax.win(c,x,H,R);if(w===false){t.hide();return}else if(typeof w=="string"||typeof w=="object")x=w}m.html(x);F()}}}));break;case "iframe":Q()}}else O()}},F=function(){var a=e.width,c=e.height;a=a.toString().indexOf("%")>-1?parseInt((b(window).width()-e.margin*2)*parseFloat(a)/100,10)+"px":a=="auto"?"auto":a+"px";c=c.toString().indexOf("%")>-1?parseInt((b(window).height()-e.margin*2)*parseFloat(c)/100,10)+"px":c=="auto"?"auto":c+"px";m.wrapInner('<div style="width:'+a+";height:"+c+
+";overflow: "+(e.scrolling=="auto"?"auto":e.scrolling=="yes"?"scroll":"hidden")+';position:relative;"></div>');e.width=m.width();e.height=m.height();Q()},Q=function(){var a,c;t.hide();if(f.is(":visible")&&false===d.onCleanup(l,p,d)){b.event.trigger("fancybox-cancel");h=false}else{h=true;b(j.add(u)).unbind();b(window).unbind("resize.fb scroll.fb");b(document).unbind("keydown.fb");f.is(":visible")&&d.titlePosition!=="outside"&&f.css("height",f.height());l=o;p=q;d=e;if(d.overlayShow){u.css({"background-color":d.overlayColor,
+opacity:d.overlayOpacity,cursor:d.hideOnOverlayClick?"pointer":"auto",height:b(document).height()});if(!u.is(":visible")){M&&b("select:not(#fancybox-tmp select)").filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one("fancybox-cleanup",function(){this.style.visibility="inherit"});u.show()}}else u.hide();i=X();s=d.title||"";y=0;n.empty().removeAttr("style").removeClass();if(d.titleShow!==false){if(b.isFunction(d.titleFormat))a=d.titleFormat(s,l,p,d);else a=s&&s.length?
+d.titlePosition=="float"?'<table id="fancybox-title-float-wrap" cellpadding="0" cellspacing="0"><tr><td id="fancybox-title-float-left"></td><td id="fancybox-title-float-main">'+s+'</td><td id="fancybox-title-float-right"></td></tr></table>':'<div id="fancybox-title-'+d.titlePosition+'">'+s+"</div>":false;s=a;if(!(!s||s==="")){n.addClass("fancybox-title-"+d.titlePosition).html(s).appendTo("body").show();switch(d.titlePosition){case "inside":n.css({width:i.width-d.padding*2,marginLeft:d.padding,marginRight:d.padding});
+y=n.outerHeight(true);n.appendTo(D);i.height+=y;break;case "over":n.css({marginLeft:d.padding,width:i.width-d.padding*2,bottom:d.padding}).appendTo(D);break;case "float":n.css("left",parseInt((n.width()-i.width-40)/2,10)*-1).appendTo(f);break;default:n.css({width:i.width-d.padding*2,paddingLeft:d.padding,paddingRight:d.padding}).appendTo(f)}}}n.hide();if(f.is(":visible")){b(E.add(z).add(A)).hide();a=f.position();r={top:a.top,left:a.left,width:f.width(),height:f.height()};c=r.width==i.width&&r.height==
+i.height;j.fadeTo(d.changeFade,0.3,function(){var g=function(){j.html(m.contents()).fadeTo(d.changeFade,1,S)};b.event.trigger("fancybox-change");j.empty().removeAttr("filter").css({"border-width":d.padding,width:i.width-d.padding*2,height:e.autoDimensions?"auto":i.height-y-d.padding*2});if(c)g();else{B.prop=0;b(B).animate({prop:1},{duration:d.changeSpeed,easing:d.easingChange,step:T,complete:g})}})}else{f.removeAttr("style");j.css("border-width",d.padding);if(d.transitionIn=="elastic"){r=V();j.html(m.contents());
+f.show();if(d.opacity)i.opacity=0;B.prop=0;b(B).animate({prop:1},{duration:d.speedIn,easing:d.easingIn,step:T,complete:S})}else{d.titlePosition=="inside"&&y>0&&n.show();j.css({width:i.width-d.padding*2,height:e.autoDimensions?"auto":i.height-y-d.padding*2}).html(m.contents());f.css(i).fadeIn(d.transitionIn=="none"?0:d.speedIn,S)}}}},Y=function(){if(d.enableEscapeButton||d.enableKeyboardNav)b(document).bind("keydown.fb",function(a){if(a.keyCode==27&&d.enableEscapeButton){a.preventDefault();b.fancybox.close()}else if((a.keyCode==
+37||a.keyCode==39)&&d.enableKeyboardNav&&a.target.tagName!=="INPUT"&&a.target.tagName!=="TEXTAREA"&&a.target.tagName!=="SELECT"){a.preventDefault();b.fancybox[a.keyCode==37?"prev":"next"]()}});if(d.showNavArrows){if(d.cyclic&&l.length>1||p!==0)z.show();if(d.cyclic&&l.length>1||p!=l.length-1)A.show()}else{z.hide();A.hide()}},S=function(){if(!b.support.opacity){j.get(0).style.removeAttribute("filter");f.get(0).style.removeAttribute("filter")}e.autoDimensions&&j.css("height","auto");f.css("height","auto");
+s&&s.length&&n.show();d.showCloseButton&&E.show();Y();d.hideOnContentClick&&j.bind("click",b.fancybox.close);d.hideOnOverlayClick&&u.bind("click",b.fancybox.close);b(window).bind("resize.fb",b.fancybox.resize);d.centerOnScroll&&b(window).bind("scroll.fb",b.fancybox.center);if(d.type=="iframe")b('<iframe id="fancybox-frame" name="fancybox-frame'+(new Date).getTime()+'" frameborder="0" hspace="0" '+(b.browser.msie?'allowtransparency="true""':"")+' scrolling="'+e.scrolling+'" src="'+d.href+'"></iframe>').appendTo(j);
+f.show();h=false;b.fancybox.center();d.onComplete(l,p,d);var a,c;if(l.length-1>p){a=l[p+1].href;if(typeof a!=="undefined"&&a.match(J)){c=new Image;c.src=a}}if(p>0){a=l[p-1].href;if(typeof a!=="undefined"&&a.match(J)){c=new Image;c.src=a}}},T=function(a){var c={width:parseInt(r.width+(i.width-r.width)*a,10),height:parseInt(r.height+(i.height-r.height)*a,10),top:parseInt(r.top+(i.top-r.top)*a,10),left:parseInt(r.left+(i.left-r.left)*a,10)};if(typeof i.opacity!=="undefined")c.opacity=a<0.5?0.5:a;f.css(c);
+j.css({width:c.width-d.padding*2,height:c.height-y*a-d.padding*2})},U=function(){return[b(window).width()-d.margin*2,b(window).height()-d.margin*2,b(document).scrollLeft()+d.margin,b(document).scrollTop()+d.margin]},X=function(){var a=U(),c={},g=d.autoScale,k=d.padding*2;c.width=d.width.toString().indexOf("%")>-1?parseInt(a[0]*parseFloat(d.width)/100,10):d.width+k;c.height=d.height.toString().indexOf("%")>-1?parseInt(a[1]*parseFloat(d.height)/100,10):d.height+k;if(g&&(c.width>a[0]||c.height>a[1]))if(e.type==
+"image"||e.type=="swf"){g=d.width/d.height;if(c.width>a[0]){c.width=a[0];c.height=parseInt((c.width-k)/g+k,10)}if(c.height>a[1]){c.height=a[1];c.width=parseInt((c.height-k)*g+k,10)}}else{c.width=Math.min(c.width,a[0]);c.height=Math.min(c.height,a[1])}c.top=parseInt(Math.max(a[3]-20,a[3]+(a[1]-c.height-40)*0.5),10);c.left=parseInt(Math.max(a[2]-20,a[2]+(a[0]-c.width-40)*0.5),10);return c},V=function(){var a=e.orig?b(e.orig):false,c={};if(a&&a.length){c=a.offset();c.top+=parseInt(a.css("paddingTop"),
+10)||0;c.left+=parseInt(a.css("paddingLeft"),10)||0;c.top+=parseInt(a.css("border-top-width"),10)||0;c.left+=parseInt(a.css("border-left-width"),10)||0;c.width=a.width();c.height=a.height();c={width:c.width+d.padding*2,height:c.height+d.padding*2,top:c.top-d.padding-20,left:c.left-d.padding-20}}else{a=U();c={width:d.padding*2,height:d.padding*2,top:parseInt(a[3]+a[1]*0.5,10),left:parseInt(a[2]+a[0]*0.5,10)}}return c},Z=function(){if(t.is(":visible")){b("div",t).css("top",L*-40+"px");L=(L+1)%12}else clearInterval(K)};
+b.fn.fancybox=function(a){if(!b(this).length)return this;b(this).data("fancybox",b.extend({},a,b.metadata?b(this).metadata():{})).unbind("click.fb").bind("click.fb",function(c){c.preventDefault();if(!h){h=true;b(this).blur();o=[];q=0;c=b(this).attr("rel")||"";if(!c||c==""||c==="nofollow")o.push(this);else{o=b("a[rel="+c+"], area[rel="+c+"]");q=o.index(this)}I()}});return this};b.fancybox=function(a,c){var g;if(!h){h=true;g=typeof c!=="undefined"?c:{};o=[];q=parseInt(g.index,10)||0;if(b.isArray(a)){for(var k=
+0,C=a.length;k<C;k++)if(typeof a[k]=="object")b(a[k]).data("fancybox",b.extend({},g,a[k]));else a[k]=b({}).data("fancybox",b.extend({content:a[k]},g));o=jQuery.merge(o,a)}else{if(typeof a=="object")b(a).data("fancybox",b.extend({},g,a));else a=b({}).data("fancybox",b.extend({content:a},g));o.push(a)}if(q>o.length||q<0)q=0;I()}};b.fancybox.showActivity=function(){clearInterval(K);t.show();K=setInterval(Z,66)};b.fancybox.hideActivity=function(){t.hide()};b.fancybox.next=function(){return b.fancybox.pos(p+
+1)};b.fancybox.prev=function(){return b.fancybox.pos(p-1)};b.fancybox.pos=function(a){if(!h){a=parseInt(a);o=l;if(a>-1&&a<l.length){q=a;I()}else if(d.cyclic&&l.length>1){q=a>=l.length?0:l.length-1;I()}}};b.fancybox.cancel=function(){if(!h){h=true;b.event.trigger("fancybox-cancel");N();e.onCancel(o,q,e);h=false}};b.fancybox.close=function(){function a(){u.fadeOut("fast");n.empty().hide();f.hide();b.event.trigger("fancybox-cleanup");j.empty();d.onClosed(l,p,d);l=e=[];p=q=0;d=e={};h=false}if(!(h||f.is(":hidden"))){h=
+true;if(d&&false===d.onCleanup(l,p,d))h=false;else{N();b(E.add(z).add(A)).hide();b(j.add(u)).unbind();b(window).unbind("resize.fb scroll.fb");b(document).unbind("keydown.fb");j.find("iframe").attr("src",M&&/^https/i.test(window.location.href||"")?"javascript:void(false)":"about:blank");d.titlePosition!=="inside"&&n.empty();f.stop();if(d.transitionOut=="elastic"){r=V();var c=f.position();i={top:c.top,left:c.left,width:f.width(),height:f.height()};if(d.opacity)i.opacity=1;n.empty().hide();B.prop=1;
+b(B).animate({prop:0},{duration:d.speedOut,easing:d.easingOut,step:T,complete:a})}else f.fadeOut(d.transitionOut=="none"?0:d.speedOut,a)}}};b.fancybox.resize=function(){u.is(":visible")&&u.css("height",b(document).height());b.fancybox.center(true)};b.fancybox.center=function(a){var c,g;if(!h){g=a===true?1:0;c=U();!g&&(f.width()>c[0]||f.height()>c[1])||f.stop().animate({top:parseInt(Math.max(c[3]-20,c[3]+(c[1]-j.height()-40)*0.5-d.padding)),left:parseInt(Math.max(c[2]-20,c[2]+(c[0]-j.width()-40)*0.5-
+d.padding))},typeof a=="number"?a:200)}};b.fancybox.init=function(){if(!b("#fancybox-wrap").length){b("body").append(m=b('<div id="fancybox-tmp"></div>'),t=b('<div id="fancybox-loading"><div></div></div>'),u=b('<div id="fancybox-overlay"></div>'),f=b('<div id="fancybox-wrap"></div>'));D=b('<div id="fancybox-outer"></div>').append('<div class="fancybox-bg" id="fancybox-bg-n"></div><div class="fancybox-bg" id="fancybox-bg-ne"></div><div class="fancybox-bg" id="fancybox-bg-e"></div><div class="fancybox-bg" id="fancybox-bg-se"></div><div class="fancybox-bg" id="fancybox-bg-s"></div><div class="fancybox-bg" id="fancybox-bg-sw"></div><div class="fancybox-bg" id="fancybox-bg-w"></div><div class="fancybox-bg" id="fancybox-bg-nw"></div>').appendTo(f);
+D.append(j=b('<div id="fancybox-content"></div>'),E=b('<a id="fancybox-close"></a>'),n=b('<div id="fancybox-title"></div>'),z=b('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'),A=b('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>'));E.click(b.fancybox.close);t.click(b.fancybox.cancel);z.click(function(a){a.preventDefault();b.fancybox.prev()});A.click(function(a){a.preventDefault();b.fancybox.next()});
+b.fn.mousewheel&&f.bind("mousewheel.fb",function(a,c){if(h)a.preventDefault();else if(b(a.target).get(0).clientHeight==0||b(a.target).get(0).scrollHeight===b(a.target).get(0).clientHeight){a.preventDefault();b.fancybox[c>0?"prev":"next"]()}});b.support.opacity||f.addClass("fancybox-ie");if(M){t.addClass("fancybox-ie6");f.addClass("fancybox-ie6");b('<iframe id="fancybox-hide-sel-frame" src="'+(/^https/i.test(window.location.href||"")?"javascript:void(false)":"about:blank")+'" scrolling="no" border="0" frameborder="0" tabindex="-1"></iframe>').prependTo(D)}}};
+b.fn.fancybox.defaults={padding:10,margin:40,opacity:false,modal:false,cyclic:false,scrolling:"auto",width:560,height:340,autoScale:true,autoDimensions:true,centerOnScroll:false,ajax:{},swf:{wmode:"transparent"},hideOnOverlayClick:true,hideOnContentClick:false,overlayShow:true,overlayOpacity:0.7,overlayColor:"#777",titleShow:true,titlePosition:"float",titleFormat:null,titleFromAlt:false,transitionIn:"fade",transitionOut:"fade",speedIn:300,speedOut:300,changeSpeed:300,changeFade:"fast",easingIn:"swing",
+easingOut:"swing",showCloseButton:true,showNavArrows:true,enableEscapeButton:true,enableKeyboardNav:true,onStart:function(){},onCancel:function(){},onComplete:function(){},onCleanup:function(){},onClosed:function(){},onError:function(){}};b(document).ready(function(){b.fancybox.init()})})(jQuery);
\ No newline at end of file
diff --git a/apps/files_imageviewer/js/jquery.mousewheel-3.0.4.pack.js b/apps/files_imageviewer/js/jquery.mousewheel-3.0.4.pack.js
new file mode 100644
index 00000000000..cb66588e29c
--- /dev/null
+++ b/apps/files_imageviewer/js/jquery.mousewheel-3.0.4.pack.js
@@ -0,0 +1,14 @@
+/*! Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net)
+* Licensed under the MIT License (LICENSE.txt).
+*
+* Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
+* Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
+* Thanks to: Seamus Leahy for adding deltaX and deltaY
+*
+* Version: 3.0.4
+*
+* Requires: 1.2.2+
+*/
+
+(function(d){function g(a){var b=a||window.event,i=[].slice.call(arguments,1),c=0,h=0,e=0;a=d.event.fix(b);a.type="mousewheel";if(a.wheelDelta)c=a.wheelDelta/120;if(a.detail)c=-a.detail/3;e=c;if(b.axis!==undefined&&b.axis===b.HORIZONTAL_AXIS){e=0;h=-1*c}if(b.wheelDeltaY!==undefined)e=b.wheelDeltaY/120;if(b.wheelDeltaX!==undefined)h=-1*b.wheelDeltaX/120;i.unshift(a,c,h,e);return d.event.handle.apply(this,i)}var f=["DOMMouseScroll","mousewheel"];d.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var a=
+f.length;a;)this.addEventListener(f[--a],g,false);else this.onmousewheel=g},teardown:function(){if(this.removeEventListener)for(var a=f.length;a;)this.removeEventListener(f[--a],g,false);else this.onmousewheel=null}};d.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})})(jQuery);
\ No newline at end of file
diff --git a/apps/files_imageviewer/js/lightbox.js b/apps/files_imageviewer/js/lightbox.js
index 4f079b6d8af..94743aa85e0 100644
--- a/apps/files_imageviewer/js/lightbox.js
+++ b/apps/files_imageviewer/js/lightbox.js
@@ -1,18 +1,4 @@
-
-var lightBoxShown=false;
 $(document).ready(function() {
-	images={};//image cache
-	loading_str = t('files_imageviewer','Loading');
-	var overlay=$('<div id="lightbox_overlay"><div id="lightbox_loader"><img /></div></div>');
-	overlay.find('#lightbox_loader img')
-		.attr('src',OC.imagePath('core', 'loading-dark.gif'))
-		.attr('alt',loading_str)
-		.after(loading_str);
-	$( 'body' ).append(overlay);
-	var container=$('<div id="lightbox"/>');
-	$( 'body' ).append(container);
-	$( '#lightbox_overlay' ).click(hideLightbox);
-	$( '#lightbox' ).click(hideLightbox);
 	if(typeof FileActions!=='undefined'){
 		FileActions.register('image','View','',function(filename){
 			viewImage($('#dir').val(),filename);
@@ -22,7 +8,6 @@ $(document).ready(function() {
 	OC.search.customResults.Images=function(row,item){
 		var image=item.link.substr(item.link.indexOf('file=')+5);
 		var a=row.find('a');
-		var container=$('<div id="lightbox"/>');
 		a.attr('href','#');
 		a.click(function(){
 			var file=image.split('/').pop();
@@ -32,52 +17,11 @@ $(document).ready(function() {
 	}
 });
 
-function viewImage(dir,file){
+function viewImage(dir, file) {
 	var location=OC.filePath('files','ajax','download.php')+'?files='+file+'&dir='+dir;
-	var overlay=$('#lightbox_overlay');
-	var container=$('#lightbox');
-	overlay.show();
-	if(!images[location]){
-		var img = new Image();
-		img.onload = function(){
-			images[location]=img;
-			if($('#lightbox_overlay').is(':visible'))
-				showLightbox(container,img);
-		}
-		img.src = location;
-	}else{
-		showLightbox(container,images[location]);
-	}
+	$.fancybox({
+		"href": location,
+		"title": file,
+		"titlePosition": "inside"
+	});
 }
-
-function showLightbox(container,img){
-	var maxWidth = $( window ).width() - 50;
-	var maxHeight = $( window ).height() - 50;
-	if( img.width > maxWidth || img.height > maxHeight ) { // One of these is larger than the window
-		var ratio = img.width / img.height;
-		if( img.height >= maxHeight ) {
-			img.height = maxHeight;
-			img.width = maxHeight * ratio;
-		} else {
-			img.width = maxWidth;
-			img.height = maxWidth / ratio;
-		}
-	}
-	container.empty();
-	container.append(img);
-	container.css('top',Math.round( ($( window ).height() - img.height)/2));
-	container.css('left',Math.round( ($( window ).width() - img.width)/2));
-	$('#lightbox').show();
-	setTimeout(function(){
-		lightBoxShown=true;
-	},100);
-}
-
-function hideLightbox(event){
-	if(event){
-		event.stopPropagation();
-		$('#lightbox_overlay').hide();
-		$('#lightbox').hide();
-		lightBoxShown=false;
-	}
-}
\ No newline at end of file
diff --git a/apps/gallery/templates/view_album.php b/apps/gallery/templates/view_album.php
index ea2969e0110..230e2a5c21d 100644
--- a/apps/gallery/templates/view_album.php
+++ b/apps/gallery/templates/view_album.php
@@ -1,9 +1,17 @@
 <?php
 OC_Util::addStyle('gallery', 'styles');
 OC_Util::addScript('gallery', 'album_cover');
-OC_Util::addScript( 'files_imageviewer', 'lightbox' );
-OC_Util::addStyle( 'files_imageviewer', 'lightbox' );
+OC_Util::addScript('files_imageviewer', 'jquery.mousewheel-3.0.4.pack');
+OC_Util::addScript('files_imageviewer', 'jquery.fancybox-1.3.4.pack');
+OC_Util::addStyle( 'files_imageviewer', 'jquery.fancybox-1.3.4' );
 ?>
+<script type="text/javascript">
+  $(document).ready(function() {
+    $("a[rel=images]").fancybox({
+    'titlePosition': 'inside'
+    });
+  });
+</script>
 
 <div id="controls">
   <a href="?"><input type="button" value="Back" /></a><br/>
@@ -12,7 +20,7 @@ OC_Util::addStyle( 'files_imageviewer', 'lightbox' );
 <?php
 foreach ($_['photos'] as $a) {
 ?>
-<a onclick="javascript:viewImage('/','<?php echo $a; ?>');"><img src="ajax/thumbnail.php?img=<?php echo $a ?>"></a>
+<a rel="images" href="../../files/ajax/download.php?files=<?php echo $a; ?>"><img src="ajax/thumbnail.php?img=<?php echo $a ?>"></a>
 <?php
   }
 ?>
-- 
cgit v1.2.3


From 43c28b941b6ddb9c74056749066d2707d56d3332 Mon Sep 17 00:00:00 2001
From: Jan-Christoph Borchardt <jan@unhosted.org>
Date: Fri, 21 Oct 2011 18:12:47 +0200
Subject: hopefully finally fixed the initial breadcrumb arrow

---
 .gitignore          | 4 ++++
 files/css/files.css | 9 +++++----
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/.gitignore b/.gitignore
index 312dc0433aa..cc4d3bf03b0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -35,4 +35,8 @@ nbproject
 # geany
 *.geany
 
+# Cloud9IDE
+.settings.xml
+
+# Mac OS
 .DS_Store
diff --git a/files/css/files.css b/files/css/files.css
index a8419e972ef..1007554cdd6 100644
--- a/files/css/files.css
+++ b/files/css/files.css
@@ -7,10 +7,10 @@
 .actions input { margin:0; }
 #file_menu { right:0; position:absolute; top:0; }
 #file_menu a { display:block; float:left; background-image:none; text-decoration:none; }
-.file_upload_form, #file_newfolder_form { display:inline; float: left;}
+.file_upload_form, #file_newfolder_form { display:inline; float: left; margin-left:.5em; }
 #fileSelector, #file_upload_submit, #file_newfolder_submit { display:none; }
 .file_upload_wrapper, #file_newfolder_name { background-repeat:no-repeat; background-position:.5em .5em; padding-left:2em; }
-.file_upload_wrapper { font-weight:bold; display:-moz-inline-box; /* fallback for older firefox versions*/ display:inline-block; padding-left:0; overflow:hidden; position:relative; margin:.1em 1em .1em 0em;}
+.file_upload_wrapper { font-weight:bold; display:-moz-inline-box; /* fallback for older firefox versions*/ display:inline-block; padding-left:0; overflow:hidden; position:relative; margin:.1em .1em .1em 0em;}
 .file_upload_wrapper .file_upload_button_wrapper { position:absolute; top:0; left:0; width:100%; height:100%; cursor:pointer; z-index:1000; }
 
 #file_newfolder_name { background-image:url('../../core/img/places/folder.svg'); font-weight:normal; width:7em; }
@@ -33,7 +33,7 @@ span.extention, td.date { color:#999; }
 span.extention { opacity:0; -webkit-transition:opacity 500ms; -moz-transition:opacity 500ms; -o-transition:opacity 500ms; transition:opacity 500ms; }
 tr:hover span.extention { opacity:1; }
 div.crumb { float:left; display:block; background:no-repeat right 0; padding:.75em 1.5em 0 1em; height:2.9em; }
-div.crumb:first-child { padding-left:1.5em; }
+div.crumb:first-child { padding-left:1em; }
 div.crumb:last-child { font-weight:bold; }
 table tr.mouseOver td { background-color:#eee; }
 table th { height:2em; padding:0 .5em; color:#999; }
@@ -63,4 +63,5 @@ table thead.fixed { height:2em; }
 .selectedActions { display:none; }
 
 /* add breadcrumb divider to the File item in navigation panel */
-#navigation>ul>li:first-child { background:url('../../core/img/breadcrumb-start.svg') no-repeat 12.5em 0px; width:12.5em; padding-right:1em; }
+#navigation>ul>li:first-child { background:url('../../core/img/breadcrumb-start.svg') no-repeat 12.5em 0px; width:12.5em; padding-right:1em; position:fixed; }
+#navigation>ul>li:first-child+li { padding-top:2.9em; }
\ No newline at end of file
-- 
cgit v1.2.3


From 92ba000f09882224526373dc04ac8926dc9ca27d Mon Sep 17 00:00:00 2001
From: Jan-Christoph Borchardt <jan@unhosted.org>
Date: Fri, 21 Oct 2011 18:24:56 +0200
Subject: only show checkbox on hovering filetype icon

---
 files/css/files.css | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/files/css/files.css b/files/css/files.css
index 1007554cdd6..c7d39d114b3 100644
--- a/files/css/files.css
+++ b/files/css/files.css
@@ -54,7 +54,7 @@ table td.filename form { float:left; font-size:.85em; }
 table thead.fixed tr{ position:fixed; top:6.5em; z-index:49; -moz-box-shadow:0 -3px 7px #ddd; -webkit-box-shadow:0 -3px 7px #ddd; box-shadow:0 -3px 7px #ddd; }
 table thead.fixed { height:2em; }
 #fileList tr td.filename>input[type=checkbox]:first-child { opacity:0; float:left; margin:.7em 0 0 1em; /* bigger clickable area doesn’t work in FF width:2.8em; height:2.4em;*/ -webkit-transition:opacity 500ms; -moz-transition:opacity 500ms; -o-transition:opacity 500ms; transition:opacity 500ms; }
-#fileList tr:hover td.filename>input[type="checkbox"]:first-child { opacity:.8; }
+#fileList tr td.filename>input[type="checkbox"]:hover:first-child { opacity:.8; }
 #fileList tr td.filename>input[type="checkbox"]:checked:first-child { opacity:1; }
 #fileList tr td.filename { -webkit-transition:background-image 500ms; -moz-transition:background-image 500ms; -o-transition:background-image 500ms; transition:background-image 500ms; }
 #select_all { float:left; margin:.3em 0.6em 0 .5em; }
-- 
cgit v1.2.3


From c420001f2b28a619fe844d7366ae3984b38021e9 Mon Sep 17 00:00:00 2001
From: Jan-Christoph Borchardt <jan@unhosted.org>
Date: Fri, 21 Oct 2011 19:09:41 +0200
Subject: bold current folder in breadcrumbs

---
 files/css/files.css                 |  2 +-
 files/templates/part.breadcrumb.php | 11 ++++++++---
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/files/css/files.css b/files/css/files.css
index c7d39d114b3..ac1f523f862 100644
--- a/files/css/files.css
+++ b/files/css/files.css
@@ -34,7 +34,7 @@ span.extention { opacity:0; -webkit-transition:opacity 500ms; -moz-transition:op
 tr:hover span.extention { opacity:1; }
 div.crumb { float:left; display:block; background:no-repeat right 0; padding:.75em 1.5em 0 1em; height:2.9em; }
 div.crumb:first-child { padding-left:1em; }
-div.crumb:last-child { font-weight:bold; }
+div.crumb.last { font-weight:bold; }
 table tr.mouseOver td { background-color:#eee; }
 table th { height:2em; padding:0 .5em; color:#999; }
 table th .name { float:left; margin-left:.5em; }
diff --git a/files/templates/part.breadcrumb.php b/files/templates/part.breadcrumb.php
index 63242dd326c..b26f6097153 100644
--- a/files/templates/part.breadcrumb.php
+++ b/files/templates/part.breadcrumb.php
@@ -1,5 +1,10 @@
-	<?php foreach($_["breadcrumb"] as $crumb): ?>
+	<?php for($i=0; $i<count($_["breadcrumb"])-1; $i++):
+        $crumb = $_["breadcrumb"][$i]; ?>
 		<div class="crumb svg" data-dir='<?php echo $crumb["dir"];?>' style='background-image:url("<?php echo image_path('core','breadcrumb.png');?>")'>
-			<a href="<?php echo $_['baseURL'].$crumb["dir"]; ?>"><?php echo htmlspecialchars($crumb["name"]); ?></a>
+    		<a href="<?php echo $_['baseURL'].$crumb["dir"]; ?>"><?php echo htmlspecialchars($crumb["name"]); ?></a>
 		</div>
-	<?php endforeach; ?>
\ No newline at end of file
+	<?php endfor;
+    $crumb = $_["breadcrumb"][count($_["breadcrumb"])-1] ?>
+    <div class="crumb last svg" data-dir='<?php echo $crumb["dir"];?>' style='background-image:url("<?php echo image_path('core','breadcrumb.png');?>")'>
+    	<a href="<?php echo $_['baseURL'].$crumb["dir"]; ?>"><?php echo htmlspecialchars($crumb["name"]); ?></a>
+	</div>
\ No newline at end of file
-- 
cgit v1.2.3