diff --git a/apps/contacts/css/jquery.Jcrop.css b/apps/contacts/css/jquery.Jcrop.css
index c9b24a5ebe9e0c6871a488aeda82a3ac9592c941..a9ba4746e0762e0b3457d1d71f8b636982f349a4 100644
--- a/apps/contacts/css/jquery.Jcrop.css
+++ b/apps/contacts/css/jquery.Jcrop.css
@@ -14,7 +14,7 @@
 }
 
 .jcrop-vline, .jcrop-hline {
-	background: white url('%webroot%/apps/contacts/img/Jcrop.gif') top left repeat;
+	background: white url('%appswebroot%/contacts/img/Jcrop.gif') top left repeat;
 	font-size: 0px;
 	position: absolute;
 }
diff --git a/apps/files_versions/appinfo/app.php b/apps/files_versions/appinfo/app.php
index ef2f54dd3f9b5e04cb48f105f93822a99b1a0f20..bd06dc0ced3c12b05a7e286039ffaa87d126e7cf 100644
--- a/apps/files_versions/appinfo/app.php
+++ b/apps/files_versions/appinfo/app.php
@@ -1,6 +1,6 @@
 <?php
 
-require_once('apps/files_versions/versions.php');
+require_once('files_versions/versions.php');
 
 OCP\App::registerAdmin('files_versions', 'settings');
 OCP\App::registerPersonal('files_versions','settings-personal');
@@ -8,4 +8,4 @@ OCP\App::registerPersonal('files_versions','settings-personal');
 OCP\Util::addscript('files_versions', 'versions');
 
 // Listen to write signals
-OCP\Util::connectHook('OC_Filesystem', 'post_write', "OCA_Versions\Storage", "write_hook");
\ No newline at end of file
+OCP\Util::connectHook('OC_Filesystem', 'post_write', "OCA_Versions\Storage", "write_hook");
diff --git a/apps/gallery/appinfo/app.php b/apps/gallery/appinfo/app.php
index e3a8dbd588b5875ca2ee3afd44858e959c01f97f..df3b68ef7368e2cfc9e24734f0c2abd53be5e4c4 100644
--- a/apps/gallery/appinfo/app.php
+++ b/apps/gallery/appinfo/app.php
@@ -21,13 +21,13 @@
 * 
 */
 
-OC::$CLASSPATH['OC_Gallery_Album'] = 'apps/gallery/lib/album.php';
-OC::$CLASSPATH['OC_Gallery_Photo'] = 'apps/gallery/lib/photo.php';
-OC::$CLASSPATH['OC_Gallery_Scanner'] = 'apps/gallery/lib/scanner.php';
-OC::$CLASSPATH['OC_Gallery_Sharing'] = 'apps/gallery/lib/sharing.php';
-OC::$CLASSPATH['OC_Gallery_Hooks_Handlers'] = 'apps/gallery/lib/hooks_handlers.php';
-OC::$CLASSPATH['Pictures_Managers'] = 'apps/gallery/lib/managers.php';
-OC::$CLASSPATH['Pictures_Tiles'] = 'apps/gallery/lib/tiles.php';
+OC::$CLASSPATH['OC_Gallery_Album'] = 'gallery/lib/album.php';
+OC::$CLASSPATH['OC_Gallery_Photo'] = 'gallery/lib/photo.php';
+OC::$CLASSPATH['OC_Gallery_Scanner'] = 'gallery/lib/scanner.php';
+OC::$CLASSPATH['OC_Gallery_Sharing'] = 'gallery/lib/sharing.php';
+OC::$CLASSPATH['OC_Gallery_Hooks_Handlers'] = 'gallery/lib/hooks_handlers.php';
+OC::$CLASSPATH['Pictures_Managers'] = 'gallery/lib/managers.php';
+OC::$CLASSPATH['Pictures_Tiles'] = 'gallery/lib/tiles.php';
 
 $l = OC_L10N::get('gallery');
 
@@ -52,4 +52,4 @@ class OC_GallerySearchProvider extends OC_Search_Provider{
 
 //OC_Search::registerProvider('OC_GallerySearchProvider');
 
-require_once('apps/gallery/lib/hooks_handlers.php');
+require_once('gallery/lib/hooks_handlers.php');
diff --git a/apps/gallery/index.php b/apps/gallery/index.php
index c08305bff9eb8ffcb637b2866fd2aa87fc936761..52a5b81a23a07e8f7e1f230fe622381c68f40704 100644
--- a/apps/gallery/index.php
+++ b/apps/gallery/index.php
@@ -31,7 +31,7 @@ OCP\Util::addStyle('files', 'files');
 OCP\Util::addStyle('gallery', 'styles');
 OCP\Util::addScript('gallery', 'pictures');
 
-include('apps/gallery/lib/tiles.php');
+include('gallery/lib/tiles.php');
 
 $root = !empty($_GET['root']) ? $_GET['root'] : '/';
 $images = \OC_FileCache::searchByMime('image', null, '/'.\OCP\USER::getUser().'/files'.$root);
diff --git a/apps/gallery/js/pictures.js b/apps/gallery/js/pictures.js
index 3a79788968856a7d3ff6ce7d81c1abfabadf972e..91fbf5be967344ce3a0da1687c4adec4da16a8f7 100644
--- a/apps/gallery/js/pictures.js
+++ b/apps/gallery/js/pictures.js
@@ -60,7 +60,7 @@ function deplode(element) {
 }
 
 function openNewGal(album_name) {
-	root = root + album_name + "/";
+	root = root + decodeURIComponent(album_name) + "/";
 	var url = window.location.toString().replace(window.location.search, '');
 	url = url + "?app=gallery&root="+encodeURIComponent(root);
 
diff --git a/apps/gallery/lib/tiles.php b/apps/gallery/lib/tiles.php
index 011168471f0f5f06818a4ebe7bb97f28c7f740c9..5efe0d7a299cd09b2fcbd9eff0676e780726dc45 100644
--- a/apps/gallery/lib/tiles.php
+++ b/apps/gallery/lib/tiles.php
@@ -168,7 +168,7 @@ class TileStack extends TileBase {
 	}
 	
 	public function getOnClickAction() {
-		return 'javascript:openNewGal(\''.\OCP\Util::sanitizeHTML($this->stack_name).'\');';
+		return 'javascript:openNewGal(\''.rawurlencode($this->stack_name).'\');';
 	}
 
 	private $tiles_array;
diff --git a/apps/media/appinfo/app.php b/apps/media/appinfo/app.php
index 869bc3440208f446d07d759aece82ccbbeb5145d..c5bfc3465428b21c064f7ab52bbd1137454e86f0 100644
--- a/apps/media/appinfo/app.php
+++ b/apps/media/appinfo/app.php
@@ -22,9 +22,9 @@
 
 $l=OC_L10N::get('media');
 
-require_once('apps/media/lib_media.php');
-require_once('apps/media/lib_collection.php');
-require_once('apps/media/lib_scanner.php');
+require_once('media/lib_media.php');
+require_once('media/lib_collection.php');
+require_once('media/lib_scanner.php');
 
 OCP\Util::addscript('media','loader');
 OCP\App::registerPersonal('media','settings');
diff --git a/apps/user_ldap/lib_ldap.php b/apps/user_ldap/lib_ldap.php
index aa104eb51265f7281a75dd11c36a441ca76c4721..c88b18b10d374df5830879acd6db8ef0ea76b6e6 100644
--- a/apps/user_ldap/lib_ldap.php
+++ b/apps/user_ldap/lib_ldap.php
@@ -471,11 +471,22 @@ class OC_LDAP {
 		if(!is_null($attr) && !is_array($attr)) {
 			$attr = array(strtolower($attr));
 		}
-		$sr = @ldap_search(self::getConnectionResource(), $base, $filter, $attr);
-		$findings = @ldap_get_entries(self::getConnectionResource(), $sr );
-		// if we're here, probably no connection ressource is returned.
-		// to make ownCloud behave nicely, we simply give back an empty array.
-		if(is_null($findings)) {
+
+		// See if we have a resource
+		$link_resource = self::getConnectionResource();
+		if($link_resource)
+		{
+			$sr = ldap_search($link_resource, $base, $filter, $attr);
+			$findings = ldap_get_entries($link_resource, $sr );
+			// if we're here, probably no connection resource is returned.
+			// to make ownCloud behave nicely, we simply give back an empty array.
+			if(is_null($findings)) {
+				return array();
+			}
+		} else
+		{
+			// Seems like we didn't find any resource.
+			// Return an empty array just like before.
 			return array();
 		}
 
diff --git a/lib/app.php b/lib/app.php
index 486704a2229454548009fb5a8152de7fd7ba6fac..84d17957def88132fae3c309f468866b759a04df 100755
--- a/lib/app.php
+++ b/lib/app.php
@@ -492,21 +492,21 @@ class OC_App{
 	 * register a settings form to be shown
 	 */
 	public static function registerSettings($app,$page){
-		self::$settingsForms[]='apps/'.$app.'/'.$page.'.php';
+		self::$settingsForms[]= $app.'/'.$page.'.php';
 	}
 
 	/**
 	 * register an admin form to be shown
 	 */
 	public static function registerAdmin($app,$page){
-		self::$adminForms[]='apps/'.$app.'/'.$page.'.php';
+		self::$adminForms[]= $app.'/'.$page.'.php';
 	}
 
 	/**
 	 * register a personal form to be shown
 	 */
 	public static function registerPersonal($app,$page){
-		self::$personalForms[]='apps/'.$app.'/'.$page.'.php';
+		self::$personalForms[]= $app.'/'.$page.'.php';
 	}
 
 	/**
diff --git a/lib/config.php b/lib/config.php
index 65f9fdc06baf13b74bfa55c2813cd0d0dfe58bde..266d559126ca86a38565d4b9f8fbd87d6d206085 100644
--- a/lib/config.php
+++ b/lib/config.php
@@ -157,7 +157,7 @@ class OC_Config{
 		// Create a php file ...
 		$content = "<?php\n\$CONFIG = ";
 		$content .= var_export(self::$cache, true);
-		$content .= ";\n?>\n";
+		$content .= ";\n";
 
 		$filename = OC::$SERVERROOT."/config/config.php";
 		// Write the file
diff --git a/lib/db.php b/lib/db.php
index bcc8657b4a4a638ef1e1486ebaf5fbedc086a362..dc9e3392d0a8733395a8d53a4f1fcf1fd630a7f2 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -526,7 +526,7 @@ class OC_DB {
 	 	self::removeDBStructure( OC::$SERVERROOT . '/db_structure.xml' );
 	 	
 	 	foreach($apps as $app){
-	 		$path = OC::$SERVERROOT.'/apps/'.$app.'/appinfo/database.xml';
+	 		$path = self::getAppPath($app).'/appinfo/database.xml';
 	 		if(file_exists($path)){
 	 			self::removeDBStructure( $path );	
 	 		}
diff --git a/lib/installer.php b/lib/installer.php
index c0903f93d519b7637ec16d651f21e91e3febd782..00feb6d470940c95a8943c8751ee583a0ffdd690 100644
--- a/lib/installer.php
+++ b/lib/installer.php
@@ -287,22 +287,23 @@ class OC_Installer{
 	 */
 	public static function installShippedApps(){
 		foreach(OC::$APPSROOTS as $app_dir) {
-			$dir = opendir( $app_dir['path'] );
-			while( false !== ( $filename = readdir( $dir ))){
-				if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ){
-					if( file_exists( $app_dir['path']."/$filename/appinfo/app.php" )){
-						if(!OC_Installer::isInstalled($filename)){
-							$info=OC_App::getAppInfo($filename);
-							$enabled = isset($info['default_enable']);
-							if( $enabled ){
-								OC_Installer::installShippedApp($filename);
-								OC_Appconfig::setValue($filename,'enabled','yes');
+			if($dir = opendir( $app_dir['path'] )){
+				while( false !== ( $filename = readdir( $dir ))){
+					if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ){
+						if( file_exists( $app_dir['path']."/$filename/appinfo/app.php" )){
+							if(!OC_Installer::isInstalled($filename)){
+								$info=OC_App::getAppInfo($filename);
+								$enabled = isset($info['default_enable']);
+								if( $enabled ){
+									OC_Installer::installShippedApp($filename);
+									OC_Appconfig::setValue($filename,'enabled','yes');
+								}
 							}
 						}
 					}
 				}
+				closedir( $dir );
 			}
-			closedir( $dir );
 		}
 	}
 
diff --git a/lib/migrate.php b/lib/migrate.php
index 5939ba32e50d76ba10827506059e381b5b090ef0..f26b4b256739d02f57cabbfdbdb6cc49e1b604b3 100644
--- a/lib/migrate.php
+++ b/lib/migrate.php
@@ -64,7 +64,7 @@ class OC_Migrate{
 		$apps = OC_App::getAllApps();
 
 		foreach($apps as $app){
-			$path = OC::$SERVERROOT . '/apps/' . $app . '/appinfo/migrate.php';
+			$path = self::getAppPath($app) . '/appinfo/migrate.php';
 			if( file_exists( $path ) ){
 				include( $path );
 			}
@@ -398,7 +398,7 @@ class OC_Migrate{
 			if( OC_App::isEnabled( $provider->getID() ) ){
 				$success = true;
 				// Does this app use the database?
-				if( file_exists( OC::$SERVERROOT.'/apps/'.$provider->getID().'/appinfo/database.xml' ) ){
+				if( file_exists( self::getAppPath($provider->getID()).'/appinfo/database.xml' ) ){
 					// Create some app tables
 					$tables = self::createAppTables( $provider->getID() );
 					if( is_array( $tables ) ){
@@ -539,7 +539,7 @@ class OC_Migrate{
 		}
 
 		// There is a database.xml file
-		$content = file_get_contents( OC::$SERVERROOT . '/apps/' . $appid . '/appinfo/database.xml' );
+		$content = file_get_contents(self::getAppPath($appid) . '/appinfo/database.xml' );
 
 		$file2 = 'static://db_scheme';
 		// TODO get the relative path to migration.db from the data dir
@@ -608,7 +608,7 @@ class OC_Migrate{
 	static public function getApps(){
 		$allapps = OC_App::getAllApps();
 		foreach($allapps as $app){
-			$path = OC::$SERVERROOT . '/apps/' . $app . '/lib/migrate.php';
+			$path = self::getAppPath($app) . '/lib/migrate.php';
 			if( file_exists( $path ) ){
 				$supportsmigration[] = $app;
 			}
diff --git a/search/js/result.js b/search/js/result.js
index 1087f9684b29663cb91973ad28a19a701cbdacdc..27a2383e2c34f64cb43c6b6b8c3c0e75a242141f 100644
--- a/search/js/result.js
+++ b/search/js/result.js
@@ -41,23 +41,13 @@ OC.search.showResults=function(results){
 		for(var name in types){
 			var type=types[name];
 			if(type.length>0){
-				var row=$('#searchresults tr.template').clone();
-				row.removeClass('template');
-				row.addClass('result');
-				row.children('td.type').text(name);
-				row.find('td.result a').attr('href',type[0].link);
-				row.find('td.result div.name').text(type[0].name);
-				row.find('td.result div.text').text(type[0].text);
-				row.data('index',index);
-				index++;
-				if(OC.search.customResults[name]){//give plugins the ability to customize the entries in here
-					OC.search.customResults[name](row,type[0]);
-				}
-				$('#searchresults tbody').append(row);
-				for(var i=1;i<type.length;i++){
+				for(var i=0;i<type.length;i++){
 					var row=$('#searchresults tr.template').clone();
 					row.removeClass('template');
 					row.addClass('result');
+					if (index == 0){
+						row.children('td.type').text(name);
+					}
 					row.find('td.result a').attr('href',type[i].link);
 					row.find('td.result div.name').text(type[i].name);
 					row.find('td.result div.text').text(type[i].text);