diff --git a/apps/bookmarks/addBm.php b/apps/bookmarks/addBm.php
index 861b677222d2232f5ba7d4f12f49d11363c4b2b1..27e01bb3baf6a625b3e90ccd1833a7040e2e6d9e 100644
--- a/apps/bookmarks/addBm.php
+++ b/apps/bookmarks/addBm.php
@@ -21,7 +21,7 @@
 * 
 */
 
-require_once('../../lib/base.php');
+
 
 // Check if we are a user
 OC_Util::checkLoggedIn();
diff --git a/apps/bookmarks/ajax/addBookmark.php b/apps/bookmarks/ajax/addBookmark.php
index 8cda7f0f060dc4d03495cfe5fe89af405ef646e4..ceeb034ec9de728be900d959d309183f63bad847 100644
--- a/apps/bookmarks/ajax/addBookmark.php
+++ b/apps/bookmarks/ajax/addBookmark.php
@@ -24,12 +24,12 @@
 //no apps or filesystem
 $RUNTIME_NOSETUPFS=true;
 
-require_once('../../../lib/base.php');
+ 
 
 // Check if we are a user
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('bookmarks');
 
-require_once('../bookmarksHelper.php');
+require_once(OC::$APPSROOT . '/apps/bookmarks/bookmarksHelper.php');
 $id = addBookmark($_GET['url'], $_GET['title'], $_GET['tags']);
 OC_JSON::success(array('data' => $id));
\ No newline at end of file
diff --git a/apps/bookmarks/ajax/delBookmark.php b/apps/bookmarks/ajax/delBookmark.php
index 4aef86e771b4b125b71fe56bc3bc1ef7fe1fc7fd..655d9f825d9605110bfab9c386aa58549887af53 100644
--- a/apps/bookmarks/ajax/delBookmark.php
+++ b/apps/bookmarks/ajax/delBookmark.php
@@ -24,7 +24,7 @@
 //no apps or filesystem
 $RUNTIME_NOSETUPFS=true;
 
-require_once('../../../lib/base.php');
+ 
 
 // Check if we are a user
 OC_JSON::checkLoggedIn();
diff --git a/apps/bookmarks/ajax/editBookmark.php b/apps/bookmarks/ajax/editBookmark.php
index 35f30ebcb7a9e7b8fb3d7e8b1d9b413e0271d225..a834cd216e6e435879ee261410a07b766f15f63b 100644
--- a/apps/bookmarks/ajax/editBookmark.php
+++ b/apps/bookmarks/ajax/editBookmark.php
@@ -24,7 +24,7 @@
 //no apps or filesystem
 $RUNTIME_NOSETUPFS=true;
 
-require_once('../../../lib/base.php');
+ 
 
 // Check if we are a user
 OC_JSON::checkLoggedIn();
diff --git a/apps/bookmarks/ajax/recordClick.php b/apps/bookmarks/ajax/recordClick.php
index e6fdfe043e1dcd6691e4c55f87da376dbc2f6933..a542f636d8c4feed1137b97af10750c882eeab11 100644
--- a/apps/bookmarks/ajax/recordClick.php
+++ b/apps/bookmarks/ajax/recordClick.php
@@ -24,7 +24,7 @@
 //no apps or filesystem
 $RUNTIME_NOSETUPFS=true;
 
-require_once('../../../lib/base.php');
+ 
 
 // Check if we are a user
 OC_JSON::checkLoggedIn();
diff --git a/apps/bookmarks/ajax/updateList.php b/apps/bookmarks/ajax/updateList.php
index 487e0d290e3d664097d018fd86c90644e6e84285..6aa951bbb65479186be32ddeb6136c70881fea99 100644
--- a/apps/bookmarks/ajax/updateList.php
+++ b/apps/bookmarks/ajax/updateList.php
@@ -25,7 +25,7 @@
 //no apps or filesystem
 $RUNTIME_NOSETUPFS=true;
 
-require_once('../../../lib/base.php');
+ 
 
 // Check if we are a user
 OC_JSON::checkLoggedIn();
diff --git a/apps/bookmarks/index.php b/apps/bookmarks/index.php
index 50fea3fddbd68b4966838690799a434c730530b9..4d604a4fd559e1c4e9416d246028d992466497d3 100644
--- a/apps/bookmarks/index.php
+++ b/apps/bookmarks/index.php
@@ -21,7 +21,7 @@
 * 
 */
 
-require_once('../../lib/base.php');
+
 
 // Check if we are a user
 OC_Util::checkLoggedIn();
diff --git a/apps/bookmarks/js/bookmarks.js b/apps/bookmarks/js/bookmarks.js
index 16ed14c89b29cb71962b6609eaaeb2885f1e71fb..38b8c43eb7dcaec80457eb95e328af72aceb78a5 100644
--- a/apps/bookmarks/js/bookmarks.js
+++ b/apps/bookmarks/js/bookmarks.js
@@ -20,7 +20,7 @@ function getBookmarks() {
 	}
 
 	$.ajax({
-		url: 'ajax/updateList.php',
+		url: OC.filePath('bookmarks', 'ajax', 'updateList.php'),
 		data: 'tag=' + encodeURIComponent($('#bookmarkFilterTag').val()) + '&page=' + bookmarks_page + '&sort=' + bookmarks_sorting,
 		success: function(bookmarks){
 			if (bookmarks.data.length) {
@@ -63,7 +63,7 @@ function addOrEditBookmark(event) {
 
 	if (id == 0) {
 		$.ajax({
-			url: 'ajax/addBookmark.php',
+			url: OC.filePath('bookmarks', 'ajax', 'addBookmark.php'),
 			data: 'url=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title) + '&tags=' + encodeURIComponent(tags),
 			success: function(response){
 				$('.bookmarks_input').val('');
@@ -75,7 +75,7 @@ function addOrEditBookmark(event) {
 	}
 	else {
 		$.ajax({
-			url: 'ajax/editBookmark.php',
+			url: OC.filePath('bookmarks', 'ajax', 'editBookmark.php'),
 			data: 'id=' + id + '&url=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title) + '&tags=' + encodeURIComponent(tags),
 			success: function(){
 				$('.bookmarks_input').val('');
@@ -92,7 +92,7 @@ function addOrEditBookmark(event) {
 function delBookmark(event) {
 	var record = $(this).parent().parent();
 	$.ajax({
-		url: 'ajax/delBookmark.php',
+		url: OC.filePath('bookmarks', 'ajax', 'delBookmark.php'),
 		data: 'url=' + encodeURIComponent($(this).parent().parent().children('.bookmark_url:first').text()),
 		success: function(data){
 			record.remove();
@@ -164,7 +164,7 @@ function updateOnBottom() {
 
 function recordClick(event) {
 	$.ajax({
-		url: 'ajax/recordClick.php',
+		url: OC.filePath('bookmarks', 'ajax', 'recordClick.php'),
 		data: 'url=' + encodeURIComponent($(this).attr('href')),
 	});
 }
diff --git a/apps/bookmarks/templates/list.php b/apps/bookmarks/templates/list.php
index 1abdbb7f838af48d94d062e395f3463a58eca76d..9fe9ee7a9a9bfdc81e7a770441e35d0543f2d6c6 100644
--- a/apps/bookmarks/templates/list.php
+++ b/apps/bookmarks/templates/list.php
@@ -20,7 +20,7 @@
 <div id="firstrun" style="display: none;">
 	<?php
 		echo $l->t('You have no bookmarks');
-		require_once('bookmarklet.php');
+		require_once(OC::$APPSROOT . '/apps/bookmarks/templates/bookmarklet.php');
 		createBookmarklet(); 
 	?>
 </div>
diff --git a/apps/calendar/ajax/calendar/activation.php b/apps/calendar/ajax/calendar/activation.php
index 7677d85aff30d67c1318aee177f4fbb4c83cbfa1..c93a0495717c1c4da9d7903d817a139dd25e070c 100644
--- a/apps/calendar/ajax/calendar/activation.php
+++ b/apps/calendar/ajax/calendar/activation.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
 $calendarid = $_POST['calendarid'];
diff --git a/apps/calendar/ajax/calendar/delete.php b/apps/calendar/ajax/calendar/delete.php
index a2f5311731c5edb0b137a8e0876639109dca3fd9..4bef912333c5b83a305a5149b61fadde27a3480a 100644
--- a/apps/calendar/ajax/calendar/delete.php
+++ b/apps/calendar/ajax/calendar/delete.php
@@ -5,7 +5,7 @@
  * later.
  * See the COPYING-README file.
  */
-require_once('../../../../lib/base.php');
+ 
 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
diff --git a/apps/calendar/ajax/calendar/edit.form.php b/apps/calendar/ajax/calendar/edit.form.php
index 8922b3eba4ed5e05ae174d95ff357c3b6bb71806..d3f9629f1aea9a824b4b28fa45c02b3dc2ba70d0 100644
--- a/apps/calendar/ajax/calendar/edit.form.php
+++ b/apps/calendar/ajax/calendar/edit.form.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
 
diff --git a/apps/calendar/ajax/calendar/edit.php b/apps/calendar/ajax/calendar/edit.php
index 8922b3eba4ed5e05ae174d95ff357c3b6bb71806..d3f9629f1aea9a824b4b28fa45c02b3dc2ba70d0 100644
--- a/apps/calendar/ajax/calendar/edit.php
+++ b/apps/calendar/ajax/calendar/edit.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
 
diff --git a/apps/calendar/ajax/calendar/new.form.php b/apps/calendar/ajax/calendar/new.form.php
index fa014351f7735b2f662104c594374abdb2aeb797..3de56460c2d65007e59f75b1a9a3612151720158 100644
--- a/apps/calendar/ajax/calendar/new.form.php
+++ b/apps/calendar/ajax/calendar/new.form.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
 $calendarcolor_options = OC_Calendar_Calendar::getCalendarColorOptions();
diff --git a/apps/calendar/ajax/calendar/new.php b/apps/calendar/ajax/calendar/new.php
index 228e6247724dfbf0dcfc32235ca2294b86c6a5a4..ada28a9fc07c099fc41bf4b679cba4fce98f980b 100644
--- a/apps/calendar/ajax/calendar/new.php
+++ b/apps/calendar/ajax/calendar/new.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../../lib/base.php');
+ 
 
 // Check if we are a user
 OC_JSON::checkLoggedIn();
diff --git a/apps/calendar/ajax/calendar/overview.php b/apps/calendar/ajax/calendar/overview.php
index dd55f3e018f8ba1555e85993f45a1b4dc5d2bd8f..f66d1eae8f80df8243a81e4ba6e73a1f333152c5 100644
--- a/apps/calendar/ajax/calendar/overview.php
+++ b/apps/calendar/ajax/calendar/overview.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../../lib/base.php');
+ 
 $l10n = OC_L10N::get('calendar');
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
diff --git a/apps/calendar/ajax/calendar/update.php b/apps/calendar/ajax/calendar/update.php
index f400c8c14b43018fdf12efb541b9f422430d5ba0..9bb1307a8458b5ee0cb881e125928f729030d249 100644
--- a/apps/calendar/ajax/calendar/update.php
+++ b/apps/calendar/ajax/calendar/update.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../../lib/base.php');
+ 
 
 // Check if we are a user
 OC_JSON::checkLoggedIn();
diff --git a/apps/calendar/ajax/categories/rescan.php b/apps/calendar/ajax/categories/rescan.php
index 0fd878ed8f93cbc9a6497449be80c57f9a24a54b..9273986cad4816db90c5ea98793eba19ba822ba5 100644
--- a/apps/calendar/ajax/categories/rescan.php
+++ b/apps/calendar/ajax/categories/rescan.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
 
diff --git a/apps/calendar/ajax/changeview.php b/apps/calendar/ajax/changeview.php
index 76e29cbe2659a9206d9a4526407fb52b5ab763ca..736a5625530da0de445eadf9bb61090e64eb818b 100644
--- a/apps/calendar/ajax/changeview.php
+++ b/apps/calendar/ajax/changeview.php
@@ -5,8 +5,6 @@
  * later.
  * See the COPYING-README file.
  */
-
-require_once ('../../../lib/base.php');
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
 $view = $_GET['v'];
diff --git a/apps/calendar/ajax/event/delete.php b/apps/calendar/ajax/event/delete.php
index fd7b709393a374dddbef2b3f5307d58d04570770..3b726651641151008d24a2f0c8813c08a6455599 100644
--- a/apps/calendar/ajax/event/delete.php
+++ b/apps/calendar/ajax/event/delete.php
@@ -5,7 +5,7 @@
  * later.
  * See the COPYING-README file.
  */
-require_once('../../../../lib/base.php');
+ 
 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
diff --git a/apps/calendar/ajax/event/edit.form.php b/apps/calendar/ajax/event/edit.form.php
index 97b0907c8398d9718654716d25b170cf31615f12..e963da32958b9be327909fa6f1713daa4926fe07 100644
--- a/apps/calendar/ajax/event/edit.form.php
+++ b/apps/calendar/ajax/event/edit.form.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../../lib/base.php');
+ 
 
 if(!OC_USER::isLoggedIn()) {
 	die('<script type="text/javascript">document.location = oc_webroot;</script>');
diff --git a/apps/calendar/ajax/event/edit.php b/apps/calendar/ajax/event/edit.php
index f65b67b84ac0bcc0fa890163a286d188c7127a26..172488f6241ed34e165b03c3bbb7959b7d19e824 100644
--- a/apps/calendar/ajax/event/edit.php
+++ b/apps/calendar/ajax/event/edit.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
 
diff --git a/apps/calendar/ajax/event/move.php b/apps/calendar/ajax/event/move.php
index 63995602de253cc976e893950ed7bf256933da64..75d174c13e1df42fc45b318de6740733e4c5f50b 100644
--- a/apps/calendar/ajax/event/move.php
+++ b/apps/calendar/ajax/event/move.php
@@ -5,7 +5,7 @@
  * later.
  * See the COPYING-README file.
  */
-require_once('../../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 
 $id = $_POST['id'];
diff --git a/apps/calendar/ajax/event/new.form.php b/apps/calendar/ajax/event/new.form.php
index 91b955465697fce80ce676b661d68781ef440dc4..62087e9a8175a3d381eb66537b5135425ebf877b 100644
--- a/apps/calendar/ajax/event/new.form.php
+++ b/apps/calendar/ajax/event/new.form.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../../lib/base.php');
+ 
 
 if(!OC_USER::isLoggedIn()) {
 	die('<script type="text/javascript">document.location = oc_webroot;</script>');
diff --git a/apps/calendar/ajax/event/new.php b/apps/calendar/ajax/event/new.php
index 7070bbf05d7959eb3ac65cf54dcf42120e9dec9a..5e8c305e97a408631994d1682d7ee1b7cd6fd758 100644
--- a/apps/calendar/ajax/event/new.php
+++ b/apps/calendar/ajax/event/new.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../../lib/base.php');
+ 
 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
diff --git a/apps/calendar/ajax/event/resize.php b/apps/calendar/ajax/event/resize.php
index 75d6e0b254729c588a762e50b754c75cc037506a..260b69144268ccf0c6173588cea1a7cf2488d056 100644
--- a/apps/calendar/ajax/event/resize.php
+++ b/apps/calendar/ajax/event/resize.php
@@ -5,7 +5,7 @@
  * later.
  * See the COPYING-README file.
  */
-require_once('../../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 
 $id = $_POST['id'];
diff --git a/apps/calendar/ajax/events.php b/apps/calendar/ajax/events.php
index 5b3d26b53b7e8f842d05b6e93cb82ccc5af74ac3..8adaa4c98f395a6e8f26a8f05db624818d582a1c 100755
--- a/apps/calendar/ajax/events.php
+++ b/apps/calendar/ajax/events.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once ('../../../lib/base.php');
+ 
 require_once('when/When.php');
 
 OC_JSON::checkLoggedIn();
diff --git a/apps/calendar/ajax/import/dialog.php b/apps/calendar/ajax/import/dialog.php
index 16ec54d14a2d6d5a77b350dc0400898bf6c73063..0c1a8f94943bd9c8602d5386bf446238ea743730 100644
--- a/apps/calendar/ajax/import/dialog.php
+++ b/apps/calendar/ajax/import/dialog.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_Util::checkAppEnabled('calendar');
 $tmpl = new OC_Template('calendar', 'part.import');
diff --git a/apps/calendar/ajax/import/import.php b/apps/calendar/ajax/import/import.php
index 4d5e7340aefd4821043793469224b69767f8d46c..5848cac448d102d64ebffab38bd7ca976d2e11cd 100644
--- a/apps/calendar/ajax/import/import.php
+++ b/apps/calendar/ajax/import/import.php
@@ -7,7 +7,6 @@
  */
 //check for calendar rights or create new one
 ob_start();
-require_once ('../../../../lib/base.php');
 OC_JSON::checkLoggedIn();
 OC_Util::checkAppEnabled('calendar');
 $nl="\r\n";
@@ -127,4 +126,4 @@ sleep(3);
 if(is_writable('import_tmp/')){
 	unlink($progressfile);
 }
-OC_JSON::success();
\ No newline at end of file
+OC_JSON::success();
diff --git a/apps/calendar/ajax/settings/getfirstday.php b/apps/calendar/ajax/settings/getfirstday.php
index cab5870509a3718c598beee612987dfc7a8665c1..63218dcd0285b4d582d04b8076fcd73855fb61b8 100644
--- a/apps/calendar/ajax/settings/getfirstday.php
+++ b/apps/calendar/ajax/settings/getfirstday.php
@@ -5,7 +5,7 @@
  * later.
  * See the COPYING-README file.
  */
-require_once('../../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 $firstday = OC_Preferences::getValue( OC_User::getUser(), 'calendar', 'firstday', 'mo');
 OC_JSON::encodedPrint(array('firstday' => $firstday));
diff --git a/apps/calendar/ajax/settings/gettimezonedetection.php b/apps/calendar/ajax/settings/gettimezonedetection.php
index 11255fe8ef386739105d36fe99838ba729032bfe..b9555900a0ec04f26396e451c327f7a5afcbad92 100644
--- a/apps/calendar/ajax/settings/gettimezonedetection.php
+++ b/apps/calendar/ajax/settings/gettimezonedetection.php
@@ -5,7 +5,7 @@
  * later.
  * See the COPYING-README file.
  */
-require_once('../../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
 OC_JSON::success(array('detection' => OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezonedetection')));
\ No newline at end of file
diff --git a/apps/calendar/ajax/settings/guesstimezone.php b/apps/calendar/ajax/settings/guesstimezone.php
index c02b8d10b8d8352d93569880a70c2dbb830bafee..c0b4ef65263ecd00a01ab664a47a3f1e4de08229 100755
--- a/apps/calendar/ajax/settings/guesstimezone.php
+++ b/apps/calendar/ajax/settings/guesstimezone.php
@@ -5,7 +5,7 @@
  * later.
  * See the COPYING-README file.
  */
-require_once('../../../../lib/base.php');
+ 
 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
diff --git a/apps/calendar/ajax/settings/setfirstday.php b/apps/calendar/ajax/settings/setfirstday.php
index 3b6522122059598ac64f545e75e92fec9888e684..3b1b5481db4bc7315f38bf5ae9d6e5f91b9f78f3 100644
--- a/apps/calendar/ajax/settings/setfirstday.php
+++ b/apps/calendar/ajax/settings/setfirstday.php
@@ -5,7 +5,7 @@
  * later.
  * See the COPYING-README file.
  */
-require_once('../../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 if(isset($_POST["firstday"])){
 	OC_Preferences::setValue(OC_User::getUser(), 'calendar', 'firstday', $_POST["firstday"]);
diff --git a/apps/calendar/ajax/settings/settimeformat.php b/apps/calendar/ajax/settings/settimeformat.php
index 8f65447065c1deb22908bcf23b68d23a5bb0a358..374825a5d4043ac4095e69a319e62fe10f22d552 100644
--- a/apps/calendar/ajax/settings/settimeformat.php
+++ b/apps/calendar/ajax/settings/settimeformat.php
@@ -5,7 +5,7 @@
  * later.
  * See the COPYING-README file.
  */
-require_once('../../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 if(isset($_POST["timeformat"])){
 	OC_Preferences::setValue(OC_User::getUser(), 'calendar', 'timeformat', $_POST["timeformat"]);
diff --git a/apps/calendar/ajax/settings/settimezone.php b/apps/calendar/ajax/settings/settimezone.php
index 8dda28335f7fc7cb779ee9b08e901b4e1a4e6f6d..b0ca9dcd9448b2b92e1db4038e17c362d52abc34 100644
--- a/apps/calendar/ajax/settings/settimezone.php
+++ b/apps/calendar/ajax/settings/settimezone.php
@@ -7,7 +7,7 @@
  */
 
 // Init owncloud
-require_once('../../../../lib/base.php');
+ 
 
 $l=OC_L10N::get('calendar');
 
diff --git a/apps/calendar/ajax/settings/timeformat.php b/apps/calendar/ajax/settings/timeformat.php
index e0dbe8d3cd7b8631d6780434eb532e0fd7afaf5f..728b7155efeedafcb539ff2fbdde2facf3416075 100644
--- a/apps/calendar/ajax/settings/timeformat.php
+++ b/apps/calendar/ajax/settings/timeformat.php
@@ -5,7 +5,7 @@
  * later.
  * See the COPYING-README file.
  */
-require_once('../../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 $timeformat = OC_Preferences::getValue( OC_User::getUser(), 'calendar', 'timeformat', "24");
 OC_JSON::encodedPrint(array("timeformat" => $timeformat));
diff --git a/apps/calendar/ajax/settings/timezonedetection.php b/apps/calendar/ajax/settings/timezonedetection.php
index f67bab901e7e6197f30360a8f32d6ed17cf2f955..d29c5568e4914a200d104350c590609a087404a2 100644
--- a/apps/calendar/ajax/settings/timezonedetection.php
+++ b/apps/calendar/ajax/settings/timezonedetection.php
@@ -5,7 +5,7 @@
  * later.
  * See the COPYING-README file.
  */
-require_once('../../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
 if($_POST['timezonedetection'] == 'on'){
diff --git a/apps/calendar/ajax/share/changepermission.php b/apps/calendar/ajax/share/changepermission.php
index 41d49e7b5213bb251355faa7ea993bb9da100f9e..faf2a13c56b06f1e7b2f783d83b5b6ee532c0d38 100644
--- a/apps/calendar/ajax/share/changepermission.php
+++ b/apps/calendar/ajax/share/changepermission.php
@@ -5,7 +5,7 @@
  * later.
  * See the COPYING-README file.
  */
-require_once('../../../../lib/base.php');
+ 
 $id = strip_tags($_GET['id']);
 $idtype = strip_tags($_GET['idtype']);
 $permission = (int) strip_tags($_GET['permission']);
diff --git a/apps/calendar/ajax/share/dropdown.php b/apps/calendar/ajax/share/dropdown.php
index eb396d38fd9f067c562b8e449c659852bfc28499..85530c163ed1930a3f8821147bff2593c593347d 100644
--- a/apps/calendar/ajax/share/dropdown.php
+++ b/apps/calendar/ajax/share/dropdown.php
@@ -5,7 +5,7 @@
  * later.
  * See the COPYING-README file.
  */
-require_once('../../../../lib/base.php');
+ 
 $user = OC_USER::getUser();
 $calid = $_GET['calid'];
 $calendar = OC_Calendar_Calendar::find($calid);
diff --git a/apps/calendar/ajax/share/share.php b/apps/calendar/ajax/share/share.php
index 2e81040b4776906387ad016a9d8a85f92b1c4cd4..70f1ec26ae67831937cf4a87d43a9771de03ff71 100644
--- a/apps/calendar/ajax/share/share.php
+++ b/apps/calendar/ajax/share/share.php
@@ -5,7 +5,7 @@
  * later.
  * See the COPYING-README file.
  */
-require_once('../../../../lib/base.php');
+ 
 $id = strip_tags($_GET['id']);
 $idtype = strip_tags($_GET['idtype']);
 switch($idtype){
diff --git a/apps/calendar/ajax/share/unshare.php b/apps/calendar/ajax/share/unshare.php
index 5bedbaaf0a6cd63a3915b89c03f13d8c3f508ef7..c68fc23a6cb27acf3ee8e46e9f4ada2e0495a1b5 100644
--- a/apps/calendar/ajax/share/unshare.php
+++ b/apps/calendar/ajax/share/unshare.php
@@ -5,7 +5,7 @@
  * later.
  * See the COPYING-README file.
  */
-require_once('../../../../lib/base.php');
+ 
 $id = strip_tags($_GET['id']);
 $idtype = strip_tags($_GET['idtype']);
 switch($idtype){
diff --git a/apps/calendar/caldav.php b/apps/calendar/caldav.php
index b710b99ea43bf069cc8cf989e35a1b120b080dd3..7210b25879f47606a41ed0b5de07e96c494293b8 100644
--- a/apps/calendar/caldav.php
+++ b/apps/calendar/caldav.php
@@ -8,8 +8,8 @@
 
 // Do not load FS ...
 $RUNTIME_NOSETUPFS = true;
+require_once('../inc.php');
 
-require_once('../../lib/base.php');
 OC_Util::checkAppEnabled('calendar');
 
 // Backends
diff --git a/apps/calendar/export.php b/apps/calendar/export.php
index 95cba03906f77b76a054cfe5ae43130dfc576ea0..0972ee0f7884606bf3e97562c925091858dbf41a 100644
--- a/apps/calendar/export.php
+++ b/apps/calendar/export.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once ('../../lib/base.php');
+ 
 OC_Util::checkLoggedIn();
 OC_Util::checkAppEnabled('calendar');
 $cal = isset($_GET['calid']) ? $_GET['calid'] : NULL;
diff --git a/apps/calendar/index.php b/apps/calendar/index.php
index c44de7f07df0bf78e65125e76e764eb801627b9e..417d2b6c22510b5abf7c583afb9d08ce61ef0761 100644
--- a/apps/calendar/index.php
+++ b/apps/calendar/index.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once ('../../lib/base.php');
+ 
 OC_Util::checkLoggedIn();
 OC_Util::checkAppEnabled('calendar');
 
@@ -22,8 +22,8 @@ foreach($calendars as $calendar){
 	$eventSources[] = OC_Calendar_Calendar::getEventSourceInfo($calendar);
 }
 
-$eventSources[] = array('url' => 'ajax/events.php?calendar_id=shared_rw', 'backgroundColor' => '#1D2D44', 'borderColor' => '#888', 'textColor' => 'white', 'editable'=>'true');
-$eventSources[] = array('url' => 'ajax/events.php?calendar_id=shared_r', 'backgroundColor' => '#1D2D44', 'borderColor' => '#888', 'textColor' => 'white', 'editable' => 'false');
+$eventSources[] = array('url' => '?app=calendar&getfile=ajax/events.php?calendar_id=shared_rw', 'backgroundColor' => '#1D2D44', 'borderColor' => '#888', 'textColor' => 'white', 'editable'=>'true');
+$eventSources[] = array('url' => '?app=calendar&getfile=ajax/events.php?calendar_id=shared_r', 'backgroundColor' => '#1D2D44', 'borderColor' => '#888', 'textColor' => 'white', 'editable' => 'false');
 
 OC_Hook::emit('OC_Calendar', 'getSources', array('sources' => &$eventSources));
 $categories = OC_Calendar_App::getCategoryOptions();
diff --git a/apps/calendar/templates/part.editevent.php b/apps/calendar/templates/part.editevent.php
index 58314db1a6bfddc0776959eea17d22bb00605c0e..102366f8f08f67fe4204d084260461dea18155bc 100644
--- a/apps/calendar/templates/part.editevent.php
+++ b/apps/calendar/templates/part.editevent.php
@@ -5,9 +5,9 @@
 <?php echo $this->inc("part.eventform"); ?>
 	<div style="width: 100%;text-align: center;color: #FF1D1D;" id="errorbox"></div>
 	<span id="actions">
-		<input type="button" class="submit" style="float: left;" value="<?php echo $l->t("Submit");?>" onclick="Calendar.UI.validateEventForm('ajax/event/edit.php');">
-		<input type="button" class="submit" style="float: left;" name="delete" value="<?php echo $l->t("Delete");?>" onclick="Calendar.UI.submitDeleteEventForm('ajax/event/delete.php');">
-		<input type="button" class="submit" style="float: right;" name="export" value="<?php echo $l->t("Export");?>" onclick="window.location='export.php?eventid=<?php echo $_['eventid'] ?>';">
+		<input type="button" class="submit" style="float: left;" value="<?php echo $l->t("Submit");?>" onclick="Calendar.UI.validateEventForm('?app=calendar&getfile=ajax/event/edit.php');">
+		<input type="button" class="submit" style="float: left;" name="delete" value="<?php echo $l->t("Delete");?>" onclick="Calendar.UI.submitDeleteEventForm('?app=calendar&getfile=ajax/event/delete.php');">
+		<input type="button" class="submit" style="float: right;" name="export" value="<?php echo $l->t("Export");?>" onclick="window.location='?app=calendar&getfile=export.php?eventid=<?php echo $_['eventid'] ?>';">
 	</span>
 	</form>
 </div>
diff --git a/apps/calendar/templates/part.newevent.php b/apps/calendar/templates/part.newevent.php
index 11416260344b07c4a1f9dde7e33e9b9d9cc08b17..f4bb867b180a652f12e2909ca8e3a12f0e4f4b04 100644
--- a/apps/calendar/templates/part.newevent.php
+++ b/apps/calendar/templates/part.newevent.php
@@ -3,7 +3,7 @@
 <?php echo $this->inc("part.eventform"); ?>
 	<div style="width: 100%;text-align: center;color: #FF1D1D;" id="errorbox"></div>
 	<span id="actions">
-		<input type="button" class="submit" style="float: left;" value="<?php echo $l->t("Submit");?>" onclick="Calendar.UI.validateEventForm('ajax/event/new.php');">
+		<input type="button" class="submit" style="float: left;" value="<?php echo $l->t("Submit");?>" onclick="Calendar.UI.validateEventForm('?app=calendar&getfile=ajax/event/new.php');">
 	</span>
 	</form>
 </div>
diff --git a/apps/contacts/ajax/activation.php b/apps/contacts/ajax/activation.php
index d69e3dba3f8ce2c7a1259fa226ef6920c2cb3e24..06d1a7e24fcdb84c8063071bee464c3351d0dfa9 100644
--- a/apps/contacts/ajax/activation.php
+++ b/apps/contacts/ajax/activation.php
@@ -7,7 +7,7 @@
  * See the COPYING-README file.
  */
 
-require_once ("../../../lib/base.php");
+ 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('contacts');
 
diff --git a/apps/contacts/ajax/addbook.php b/apps/contacts/ajax/addbook.php
index f5852183cc340b380204c0a8ab7e705d3faeb2b0..f466d57e12e1da59e9f2d7c3f675e9a885512d40 100644
--- a/apps/contacts/ajax/addbook.php
+++ b/apps/contacts/ajax/addbook.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('contacts');
 $book = array(
diff --git a/apps/contacts/ajax/addcontact.php b/apps/contacts/ajax/addcontact.php
index 68da54655aea760a8521fe8f40e5cd575124a8e5..152277181bb6b5ec119a408335be499e0d5c5bc0 100644
--- a/apps/contacts/ajax/addcontact.php
+++ b/apps/contacts/ajax/addcontact.php
@@ -21,7 +21,7 @@
  */
 
 // Init owncloud
-require_once('../../../lib/base.php');
+ 
 function bailOut($msg) {
 	OC_JSON::error(array('data' => array('message' => $msg)));
 	OC_Log::write('contacts','ajax/addcontact.php: '.$msg, OC_Log::DEBUG);
diff --git a/apps/contacts/ajax/addproperty.php b/apps/contacts/ajax/addproperty.php
index d2c0291e8c62fcf3d5230835963fbc5ec06029a5..9a5e59692d635ee0a160e81e5570c58ca281ffee 100644
--- a/apps/contacts/ajax/addproperty.php
+++ b/apps/contacts/ajax/addproperty.php
@@ -21,7 +21,7 @@
  */
 
 // Init owncloud
-require_once('../../../lib/base.php');
+ 
 
 // Check if we are a user
 OC_JSON::checkLoggedIn();
diff --git a/apps/contacts/ajax/categories/categoriesfor.php b/apps/contacts/ajax/categories/categoriesfor.php
index c02c37914a22f97a379f575e94e4e52f8caf6fcd..39a7758c8fbdbf276cee9a923b50b00e7419b19d 100644
--- a/apps/contacts/ajax/categories/categoriesfor.php
+++ b/apps/contacts/ajax/categories/categoriesfor.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('contacts');
 
diff --git a/apps/contacts/ajax/categories/delete.php b/apps/contacts/ajax/categories/delete.php
index 3ba5aa16068eced43d40eec07c245b5ba84bd898..3cc2dea6638e41115c72e896416ea3bd7249a71a 100644
--- a/apps/contacts/ajax/categories/delete.php
+++ b/apps/contacts/ajax/categories/delete.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('contacts');
 
diff --git a/apps/contacts/ajax/categories/list.php b/apps/contacts/ajax/categories/list.php
index 64d74c82e69d3e34315fc5f3aaed658f8870b5f2..98c1c7051808905ca56c3832141ad82a71040de2 100644
--- a/apps/contacts/ajax/categories/list.php
+++ b/apps/contacts/ajax/categories/list.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('contacts');
 
diff --git a/apps/contacts/ajax/categories/rescan.php b/apps/contacts/ajax/categories/rescan.php
index 5f1057bab44e5a04f0eadaf6a0c252a8398f681c..09208c3f685fef4e2a987d719c7510f12510a42d 100644
--- a/apps/contacts/ajax/categories/rescan.php
+++ b/apps/contacts/ajax/categories/rescan.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('contacts');
 
diff --git a/apps/contacts/ajax/chooseaddressbook.php b/apps/contacts/ajax/chooseaddressbook.php
index d6080791299794e83ddebaa82386f97493e60e56..b47c872e9aaab432b71b18922f5994d3b00e3706 100644
--- a/apps/contacts/ajax/chooseaddressbook.php
+++ b/apps/contacts/ajax/chooseaddressbook.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('contacts');
 
diff --git a/apps/contacts/ajax/contactdetails.php b/apps/contacts/ajax/contactdetails.php
index 03895c862aab3ed195a885a962e6b54506e96737..13c3f80c3b5a9d1b1fa4741116d259ab56d53813 100644
--- a/apps/contacts/ajax/contactdetails.php
+++ b/apps/contacts/ajax/contactdetails.php
@@ -21,7 +21,7 @@
  */
 
 // Init owncloud
-require_once('../../../lib/base.php');
+ 
 function bailOut($msg) {
 	OC_JSON::error(array('data' => array('message' => $msg)));
 	OC_Log::write('contacts','ajax/contactdetails.php: '.$msg, OC_Log::DEBUG);
diff --git a/apps/contacts/ajax/contacts.php b/apps/contacts/ajax/contacts.php
index cf86764105f1a5bcadb50a0f0bf3f915dd2350a4..3e75e4c80e3acba7a06644b349b3a34eabfd9b88 100644
--- a/apps/contacts/ajax/contacts.php
+++ b/apps/contacts/ajax/contacts.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('contacts');
 
diff --git a/apps/contacts/ajax/createaddressbook.php b/apps/contacts/ajax/createaddressbook.php
index 28944fe864c8de48a602f2c92cb921869adcdbb6..5cdb9b49ef826e33136ab72c4b4f622084da8c27 100644
--- a/apps/contacts/ajax/createaddressbook.php
+++ b/apps/contacts/ajax/createaddressbook.php
@@ -6,7 +6,7 @@
  * later.
  * See the COPYING-README file.
  */
-require_once('../../../lib/base.php');
+ 
 
 // Check if we are a user
 OC_JSON::checkLoggedIn();
diff --git a/apps/contacts/ajax/cropphoto.php b/apps/contacts/ajax/cropphoto.php
index 878fb5610c611d2a81e4a4a64804d9c2c12b98a1..96e66ffb69c5ea4d8f2699878a6a0029e2dd9250 100644
--- a/apps/contacts/ajax/cropphoto.php
+++ b/apps/contacts/ajax/cropphoto.php
@@ -21,7 +21,7 @@
  */
 
 // Init owncloud
-require_once('../../../lib/base.php');
+ 
 
 // Check if we are a user
 OC_JSON::checkLoggedIn();
diff --git a/apps/contacts/ajax/deletebook.php b/apps/contacts/ajax/deletebook.php
index 46d8deb48687c44f01d133bba2bf496cfc272fd5..b80df526f9525c5ad6fd9abd0b5c1af98e272259 100644
--- a/apps/contacts/ajax/deletebook.php
+++ b/apps/contacts/ajax/deletebook.php
@@ -21,7 +21,7 @@
  */
 
 // Init owncloud
-require_once('../../../lib/base.php');
+ 
 
 // Check if we are a user
 OC_JSON::checkLoggedIn();
diff --git a/apps/contacts/ajax/deletecard.php b/apps/contacts/ajax/deletecard.php
index 5675aef5f15143d1ca5ade32a2a6b161a644d426..98cdb85f0fc938cd56064174618d86dfd20696d9 100644
--- a/apps/contacts/ajax/deletecard.php
+++ b/apps/contacts/ajax/deletecard.php
@@ -26,7 +26,7 @@ function bailOut($msg) {
 }
 
 // Init owncloud
-require_once('../../../lib/base.php');
+ 
 
 // Check if we are a user
 OC_JSON::checkLoggedIn();
diff --git a/apps/contacts/ajax/deleteproperty.php b/apps/contacts/ajax/deleteproperty.php
index ab0958cac58ab0a6cdb5c9ff3d2da78871c9845b..73786cb10cf07f858748ce50cc87e773ccaac77d 100644
--- a/apps/contacts/ajax/deleteproperty.php
+++ b/apps/contacts/ajax/deleteproperty.php
@@ -21,7 +21,7 @@
  */
 
 // Init owncloud
-require_once('../../../lib/base.php');
+ 
 
 // Check if we are a user
 OC_JSON::checkLoggedIn();
diff --git a/apps/contacts/ajax/editaddress.php b/apps/contacts/ajax/editaddress.php
index 4e6456f6045d42644b5c5b1e3a76e463395355d9..73f34ef5c6c58b52f5136523ed0d25f8c819eb13 100644
--- a/apps/contacts/ajax/editaddress.php
+++ b/apps/contacts/ajax/editaddress.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('contacts');
 
diff --git a/apps/contacts/ajax/editaddressbook.php b/apps/contacts/ajax/editaddressbook.php
index a6262f39b23e244ea7e5b2119cc48c630e86228a..ef797778d959fc5e7e8ae56517d81c8c84cc198d 100644
--- a/apps/contacts/ajax/editaddressbook.php
+++ b/apps/contacts/ajax/editaddressbook.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('contacts');
 $addressbook = OC_Contacts_App::getAddressbook($_GET['bookid']);
diff --git a/apps/contacts/ajax/editname.php b/apps/contacts/ajax/editname.php
index 31bdd125675445f1c173b5cb14bebb1d4224fff7..9e4d6814620b37f66798df2f790e8d93cb63f8f2 100644
--- a/apps/contacts/ajax/editname.php
+++ b/apps/contacts/ajax/editname.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('contacts');
 function bailOut($msg) {
diff --git a/apps/contacts/ajax/getdetails.php b/apps/contacts/ajax/getdetails.php
index 4819916f4c301ae8d9ab088599f55b9b3aacc53d..aac69f4c52ebaef6feeb2304df0c42dbac1d1714 100644
--- a/apps/contacts/ajax/getdetails.php
+++ b/apps/contacts/ajax/getdetails.php
@@ -21,7 +21,7 @@
  */
 
 // Init owncloud
-require_once('../../../lib/base.php');
+ 
 
 // Check if we are a user
 OC_JSON::checkLoggedIn();
diff --git a/apps/contacts/ajax/importdialog.php b/apps/contacts/ajax/importdialog.php
index 280e462f662307b3ee1c4635e53ea81ef6fc6513..cde6bb2f5c4fb301069ed59ef46087db3e93351d 100644
--- a/apps/contacts/ajax/importdialog.php
+++ b/apps/contacts/ajax/importdialog.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_Util::checkAppEnabled('contacts');
 $tmpl = new OC_Template('contacts', 'part.import');
diff --git a/apps/contacts/ajax/loadcard.php b/apps/contacts/ajax/loadcard.php
index 037fe2a6df279adba220b14a5484bc9baaab9740..4b2a65db911e12b4cf1d65f5a3265f2909668759 100644
--- a/apps/contacts/ajax/loadcard.php
+++ b/apps/contacts/ajax/loadcard.php
@@ -21,7 +21,7 @@
  */
 
 // Init owncloud
-require_once('../../../lib/base.php');
+ 
 function bailOut($msg) {
 	OC_JSON::error(array('data' => array('message' => $msg)));
 	OC_Log::write('contacts','ajax/loadcard.php: '.$msg, OC_Log::DEBUG);
diff --git a/apps/contacts/ajax/loadintro.php b/apps/contacts/ajax/loadintro.php
index 8e5673655a17541e9d1f513ba6439ef610eb98bc..7185c5cbe0ace8e5e3063b73e0cac910ded6241f 100644
--- a/apps/contacts/ajax/loadintro.php
+++ b/apps/contacts/ajax/loadintro.php
@@ -21,7 +21,7 @@
  */
 
 // Init owncloud
-require_once('../../../lib/base.php');
+ 
 function bailOut($msg) {
 	OC_JSON::error(array('data' => array('message' => $msg)));
 	OC_Log::write('contacts','ajax/loadintro.php: '.$msg, OC_Log::DEBUG);
diff --git a/apps/contacts/ajax/loadphoto.php b/apps/contacts/ajax/loadphoto.php
index 2f95cdc9328c7e6993920ac67db75c5e52f5e243..c076d97a7c24dccde1258f2f03ee812d2d439663 100644
--- a/apps/contacts/ajax/loadphoto.php
+++ b/apps/contacts/ajax/loadphoto.php
@@ -20,7 +20,7 @@
  *
  */
 // Init owncloud
-require_once('../../../lib/base.php');
+ 
 // Check if we are a user
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('contacts');
diff --git a/apps/contacts/ajax/newcontact.php b/apps/contacts/ajax/newcontact.php
index fcfd12ca80d7600ffce43dbbd9e7afa4fda94497..36c37e039e9e1a3b6f2ce2bbddab34f87a2d7332 100644
--- a/apps/contacts/ajax/newcontact.php
+++ b/apps/contacts/ajax/newcontact.php
@@ -21,7 +21,7 @@
  */
 
 // Init owncloud
-require_once('../../../lib/base.php');
+ 
 function bailOut($msg) {
 	OC_JSON::error(array('data' => array('message' => $msg)));
 	OC_Log::write('contacts','ajax/newcontact.php: '.$msg, OC_Log::DEBUG);
diff --git a/apps/contacts/ajax/savecrop.php b/apps/contacts/ajax/savecrop.php
index d003834ef8c963966e0d58f07fd6ed82d754d43d..c1a0e2b0583b6691093420174bfc7a6c3afed1e6 100644
--- a/apps/contacts/ajax/savecrop.php
+++ b/apps/contacts/ajax/savecrop.php
@@ -22,7 +22,7 @@
  *       Remember to delete tmp file at some point.
  */
 // Init owncloud
-require_once('../../../lib/base.php');
+ 
 OC_Log::write('contacts','ajax/savecrop.php: Huzzah!!!', OC_Log::DEBUG);
 
 // Check if we are a user
diff --git a/apps/contacts/ajax/saveproperty.php b/apps/contacts/ajax/saveproperty.php
index 99d55e7927acc7fc5115bd69c2cdbde41c9e28a1..e459ed733d8263bb819c9e92f0dfc3f77e6f86ad 100644
--- a/apps/contacts/ajax/saveproperty.php
+++ b/apps/contacts/ajax/saveproperty.php
@@ -21,7 +21,7 @@
  */
 
 // Init owncloud
-require_once('../../../lib/base.php');
+ 
 
 // Check if we are a user
 OC_JSON::checkLoggedIn();
diff --git a/apps/contacts/ajax/updateaddressbook.php b/apps/contacts/ajax/updateaddressbook.php
index 211df84b1d18811964964475fb76c4898e496464..06028db479a1f4c3a9745b352158fe673ffb8cd8 100644
--- a/apps/contacts/ajax/updateaddressbook.php
+++ b/apps/contacts/ajax/updateaddressbook.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../lib/base.php');
+ 
 
 // Check if we are a user
 OC_JSON::checkLoggedIn();
diff --git a/apps/contacts/ajax/uploadphoto.php b/apps/contacts/ajax/uploadphoto.php
index 15d4718241e83c4f9bcc0c49ef5711544f849e9e..082776f7f2738fe376a64412d10c98ae7998cf16 100644
--- a/apps/contacts/ajax/uploadphoto.php
+++ b/apps/contacts/ajax/uploadphoto.php
@@ -20,7 +20,7 @@
  *
  */
 // Init owncloud
-require_once('../../../lib/base.php');
+ 
 
 // Check if we are a user
 // Firefox and Konqueror tries to download application/json for me.  --Arthur
diff --git a/apps/contacts/carddav.php b/apps/contacts/carddav.php
index 654aeb66a72174ec9d73c60c76c4b3f13f6ab896..1a11ccdb3f711893cbcfd1f9c8be71484dfa6125 100644
--- a/apps/contacts/carddav.php
+++ b/apps/contacts/carddav.php
@@ -22,8 +22,8 @@
 
 // Do not load FS ...
 $RUNTIME_NOSETUPFS = true;
+require_once('../inc.php');
 
-require_once('../../lib/base.php');
 OC_Util::checkAppEnabled('contacts');
 
 // Backends
diff --git a/apps/contacts/css/contacts.css b/apps/contacts/css/contacts.css
index ae96c5e4e9fecb4f44e43b4c537fcbf70fbd6f19..e3d2cfbdd66be9eaa003d7d4a542d1dc73e53d40 100644
--- a/apps/contacts/css/contacts.css
+++ b/apps/contacts/css/contacts.css
@@ -11,7 +11,7 @@
 #actionbar { height: 30px; width: 60px; position: fixed; right: 0px; top: 4em; margin: 0 0 0 0; padding: 0 0 0 0; z-index: 1000; }
 #contacts_deletecard {position:absolute;top:15px;right:25px;}
 #contacts_downloadcard {position:absolute;top:15px;right:50px;}
-#contacts_propertymenu_button { position:absolute;top:15px;right:150px; background:url('../../../core/img/actions/add.svg') no-repeat center;	 }
+#contacts_propertymenu_button { position:absolute;top:15px;right:150px; background:url('%webroot%/core/img/actions/add.svg') no-repeat center;	 }
 #contacts_propertymenu { background-color: #fff; position:absolute;top:40px;right:150px; overflow:hidden; text-overflow:ellipsis; /*border: thin solid #1d2d44;*/  -moz-box-shadow:0 0 10px #000; -webkit-box-shadow:0 0 10px #000; box-shadow:0 0 10px #000; -moz-border-radius:0.5em; -webkit-border-radius:0.5em; border-radius:0.5em; -moz-border-radius:0.5em; -webkit-border-radius:0.5em; border-radius:0.5em; }
 #contacts_propertymenu li { display: block; font-weight: bold; height: 20px; width: 100px; }
 #contacts_propertymenu li a { padding: 3px; display: block }
@@ -35,20 +35,20 @@ dl.form { width: 100%; float: left; clear: right; margin: 0; padding: 0; }
 #address.form dl { min-width: 10em; }
 .droptarget { margin: 0.5em; padding: 0.5em; border: thin solid #ccc; -moz-border-radius:.3em; -webkit-border-radius:.3em; border-radius:.3em; }
 .droppable { margin: 0.5em; padding: 0.5em; border: thin dashed #333; -moz-border-radius:.3em; -webkit-border-radius:.3em; border-radius:.3em; }
-.loading { background: url('../../../core/img/loading.gif') no-repeat center !important; /*cursor: progress; */ cursor: wait; }
-.ui-autocomplete-loading { background: url('../../../core/img/loading.gif') right center no-repeat; }
+.loading { background: url('%webroot%/core/img/loading.gif') no-repeat center !important; /*cursor: progress; */ cursor: wait; }
+.ui-autocomplete-loading { background: url('%webroot%/core/img/loading.gif') right center no-repeat; }
 .float { float: left; }
 .listactions { height: 1em; width:60px; float: left; clear: right; }
 .add,.edit,.delete,.mail, .globe, .upload, .cloud { cursor: pointer; width: 20px; height: 20px; margin: 0; float: left; position:relative; opacity: 0.1; }
 .add:hover,.edit:hover,.delete:hover,.mail:hover, .globe:hover, .upload:hover, .cloud:hover { opacity: 1.0 }
-.add { background:url('../../../core/img/actions/add.svg') no-repeat center; clear: both; }
-.delete { background:url('../../../core/img/actions/delete.svg') no-repeat center; }
-.edit { background:url('../../../core/img/actions/rename.svg') no-repeat center; }
-.mail { background:url('../../../core/img/actions/mail.svg') no-repeat center; }
-.upload { background:url('../../../core/img/actions/upload.svg') no-repeat center; }
-.cloud { background:url('../../../core/img/places/picture.svg') no-repeat center; }
+.add { background:url('%webroot%/core/img/actions/add.svg') no-repeat center; clear: both; }
+.delete { background:url('%webroot%/core/img/actions/delete.svg') no-repeat center; }
+.edit { background:url('%webroot%/core/img/actions/rename.svg') no-repeat center; }
+.mail { background:url('%webroot%/core/img/actions/mail.svg') no-repeat center; }
+.upload { background:url('%webroot%/core/img/actions/upload.svg') no-repeat center; }
+.cloud { background:url('%webroot%/core/img/places/picture.svg') no-repeat center; }
 /*.globe { background:url('../img/globe.svg') no-repeat center; }*/
-.globe { background:url('../../../core/img/actions/public.svg') no-repeat center; }
+.globe { background:url('%webroot%/core/img/actions/public.svg') no-repeat center; }
 .transparent{ opacity: 0.6; }
 #edit_name_dialog { padding:0; }
 #edit_name_dialog > input { width: 15em; }
@@ -65,7 +65,7 @@ dl.form { width: 100%; float: left; clear: right; margin: 0; padding: 0; }
 
 .contactpart legend { width:auto; padding:.3em; border:1px solid #ddd; font-weight:bold; cursor:pointer; background:#f8f8f8; color:#555; text-shadow:#fff 0 1px 0; -moz-box-shadow:0 1px 1px #fff, 0 1px 1px #fff inset; -webkit-box-shadow:0 1px 1px #fff, 0 1px 1px #fff inset; -moz-border-radius:.5em; -webkit-border-radius:.5em; border-radius:.5em; }
 #cropbox { margin: auto; }
-#contacts_details_photo { border-radius: 0.5em; border: thin solid #bbb; margin: 0.3em; background: url(../../../core/img/loading.gif) no-repeat center center; display: block; -moz-box-shadow: 0 1px 3px #777; -webkit-box-shadow: 0 1px 3px #777; box-shadow: 0 1px 3px #777; }
+#contacts_details_photo { border-radius: 0.5em; border: thin solid #bbb; margin: 0.3em; background: url('%webroot%/core/img/loading.gif') no-repeat center center; display: block; -moz-box-shadow: 0 1px 3px #777; -webkit-box-shadow: 0 1px 3px #777; box-shadow: 0 1px 3px #777; }
 #contacts_details_photo:hover { background: #fff; cursor: default; }
 #phototools { position:absolute; margin: 5px 0 0 10px; width:auto; height:22px; padding:0px; background-color:#fff; list-style-type:none; border-radius: 0.5em; -moz-box-shadow: 0 1px 3px #777; -webkit-box-shadow: 0 1px 3px #777; box-shadow: 0 1px 3px #777; }
 #phototools li { display: inline; }
@@ -101,4 +101,3 @@ input[type="checkbox"] { width: 20px; height: 20px; vertical-align: bottom; }
 .propertylist li > select { float: left; max-width: 8em; }
 .typelist { float: left; max-width: 10em; } /* for multiselect */
 .addresslist { clear: both; }
-
diff --git a/apps/contacts/dynphoto.php b/apps/contacts/dynphoto.php
index 2beac15e1437db469517b6089e3b42acd5a28b77..c1646e483deb7fb624753ec7403eb7d9ef747ce6 100644
--- a/apps/contacts/dynphoto.php
+++ b/apps/contacts/dynphoto.php
@@ -21,7 +21,7 @@
  */
 
 // Init owncloud
-require_once('../../lib/base.php');
+
 $tmp_path = $_GET['tmp_path'];
 $maxsize = isset($_GET['maxsize']) ? $_GET['maxsize'] : -1;
 header("Cache-Control: no-cache, no-store, must-revalidate");
diff --git a/apps/contacts/export.php b/apps/contacts/export.php
index fb3e0a41ae7bc9eafe37c8718c6db2a3cbc424b2..95d02a9afd4a0efbb9d3a366ddc67be9797beb5f 100644
--- a/apps/contacts/export.php
+++ b/apps/contacts/export.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once ("../../lib/base.php");
+ 
 OC_Util::checkLoggedIn();
 OC_Util::checkAppEnabled('contacts');
 $bookid = isset($_GET['bookid']) ? $_GET['bookid'] : NULL;
diff --git a/apps/contacts/import.php b/apps/contacts/import.php
index 45f1b0c53dca2025820c67a26e1903bc2f7c00cf..8e0a427399b008c56730df781bf2a6686e5a9530 100644
--- a/apps/contacts/import.php
+++ b/apps/contacts/import.php
@@ -7,7 +7,7 @@
  */
 //check for addressbooks rights or create new one
 ob_start();
-require_once ('../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_Util::checkAppEnabled('contacts');
 $nl = "\n";
diff --git a/apps/contacts/index.php b/apps/contacts/index.php
index 4039b8afd3d9479813ca31a0dc3fe6a8f6daca06..d5545e761971600cc73d29d4af3fa83a55dbab37 100644
--- a/apps/contacts/index.php
+++ b/apps/contacts/index.php
@@ -6,7 +6,7 @@
  * later.
  * See the COPYING-README file.
  */
-require_once('../../lib/base.php');
+
 
 // Check if we are a user
 OC_Util::checkLoggedIn();
diff --git a/apps/contacts/js/contacts.js b/apps/contacts/js/contacts.js
index e649e1744c3ef995ea62a78586e88ae8ac653ec7..edb7da70407be80a20a56f729dc2c5fc8d38456d 100644
--- a/apps/contacts/js/contacts.js
+++ b/apps/contacts/js/contacts.js
@@ -302,7 +302,7 @@ Contacts={
 								Contacts.UI.loadHandlers();
 								Contacts.UI.Card.loadContact(jsondata.data);
 								$('#leftcontent .active').removeClass('active');
-								var item = '<li data-id="'+jsondata.data.id+'" class="active"><a href="index.php?id='+jsondata.data.id+'"  style="background: url(thumbnail.php?id='+jsondata.data.id+') no-repeat scroll 0% 0% transparent;">'+Contacts.UI.Card.fn+'</a></li>';
+								var item = '<li data-id="'+jsondata.data.id+'" class="active"><a href="index.php?id='+jsondata.data.id+'"  style="background: url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+jsondata.data.id+') no-repeat scroll 0% 0% transparent;">'+Contacts.UI.Card.fn+'</a></li>';
 								var added = false;
 								$('#leftcontent ul li').each(function(){
 									if ($(this).text().toLowerCase() > Contacts.UI.Card.fn.toLowerCase()) {
@@ -1528,12 +1528,12 @@ Contacts={
 			lazyupdate:function(){
 				$('#contacts li').live('inview', function(){
 					if (!$(this).find('a').attr('style')) {
-						$(this).find('a').css('background','url(thumbnail.php?id='+$(this).data('id')+') no-repeat');
+						$(this).find('a').css('background','url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+$(this).data('id')+') no-repeat');
 					}
 				});
 			},
 			refreshThumbnail:function(id){
-				$('#contacts [data-id="'+id+'"]').find('a').css('background','url(thumbnail.php?id='+id+'&refresh=1'+Math.random()+') no-repeat');
+				$('#contacts [data-id="'+id+'"]').find('a').css('background','url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+id+'&refresh=1'+Math.random()+') no-repeat');
 			}
 		}
 	}
@@ -1592,7 +1592,7 @@ $(document).ready(function(){
 				// whole part of element is visible
 				if (!$(this).find('a').attr('style')) {
 					//alert($(this).data('id') + ' has background: ' + $(this).attr('style'));
-					$(this).find('a').css('background','url(thumbnail.php?id='+$(this).data('id')+') no-repeat');
+					$(this).find('a').css('background','url('+OC.filePath('contacts', '', 'thumbnail.php')+'?id='+$(this).data('id')+') no-repeat');
 				}/* else {
 					alert($(this).data('id') + ' has style ' + $(this).attr('style').match('url'));
 				}*/
diff --git a/apps/contacts/photo.php b/apps/contacts/photo.php
index 117d0a9808f6b4b0147eaa4de3777070abaef676..c19ccccbc7fafe193020bd60ab3b7d2abaab0b17 100644
--- a/apps/contacts/photo.php
+++ b/apps/contacts/photo.php
@@ -9,7 +9,7 @@
  */
 
 // Init owncloud
-require_once('../../lib/base.php');
+
 OC_Util::checkLoggedIn();
 OC_Util::checkAppEnabled('contacts');
 
diff --git a/apps/contacts/templates/index.php b/apps/contacts/templates/index.php
index 256d10afc07fb5a290d9c355176c7b238b021029..d7aabbe76a555754433e68e9b5af065cf3b0a2ab 100644
--- a/apps/contacts/templates/index.php
+++ b/apps/contacts/templates/index.php
@@ -16,8 +16,8 @@
 </div>
 	<div id="bottomcontrols">
 		<form>
-			<img class="svg" id="contacts_newcontact" src="img/contact-new.svg" alt="<?php echo $l->t('Add Contact'); ?>"  title="<?php echo $l->t('Add Contact'); ?>" />
-			<img class="svg" id="chooseaddressbook" src="../../core/img/actions/settings.svg" alt="<?php echo $l->t('Addressbooks'); ?>" title="<?php echo $l->t('Addressbooks'); ?>" />
+			<img class="svg" id="contacts_newcontact" src="<?php echo OC_Helper::linkTo('contacts', 'img/contact-new.svg'); ?>" alt="<?php echo $l->t('Add Contact'); ?>"  title="<?php echo $l->t('Add Contact'); ?>" />
+			<img class="svg" id="chooseaddressbook" src="core/img/actions/settings.svg" alt="<?php echo $l->t('Addressbooks'); ?>" title="<?php echo $l->t('Addressbooks'); ?>" />
 		</form>
 	</div>
 <div id="rightcontent" class="rightcontent" data-id="<?php echo $_['id']; ?>">
diff --git a/apps/contacts/thumbnail.php b/apps/contacts/thumbnail.php
index 28b8eba22c91a032bb8d7218188ccda9efddc17b..13f16954cafeec67e3279d056efc4d249cd6907b 100644
--- a/apps/contacts/thumbnail.php
+++ b/apps/contacts/thumbnail.php
@@ -21,7 +21,7 @@
  */
 
 // Init owncloud
-require_once('../../lib/base.php');
+
 OC_JSON::checkLoggedIn();
 //OC_Util::checkLoggedIn();
 OC_Util::checkAppEnabled('contacts');
diff --git a/apps/external/ajax/setsites.php b/apps/external/ajax/setsites.php
index 0537b7ea5810fb92f9252c770b2100d8390641e4..3223bf68d9bf9fc5b14e8ba82de2b9b640038c0e 100644
--- a/apps/external/ajax/setsites.php
+++ b/apps/external/ajax/setsites.php
@@ -6,7 +6,7 @@
  * See the COPYING-README file.
  */
 
-require_once('../../../lib/base.php');
+ 
 OC_Util::checkAdminUser();
 
 $sites = array();
diff --git a/apps/external/index.php b/apps/external/index.php
index 1c20f59eaffc9b0e280e1fdef58c776f10d6d842..0baa62a94b67258e3cd87bf27fddd45d9679427a 100644
--- a/apps/external/index.php
+++ b/apps/external/index.php
@@ -20,7 +20,7 @@
  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
  * 
  */
-require_once('../../lib/base.php');
+
 require_once('lib/external.php');
 
 OC_Util::checkLoggedIn();
diff --git a/files/admin.php b/apps/files/admin.php
similarity index 98%
rename from files/admin.php
rename to apps/files/admin.php
index 4ae3ee512363bd3c12ddb2ac940d0c815672fca7..bdea70506fb9aadd16216ade3d7bd33305af71ae 100644
--- a/files/admin.php
+++ b/apps/files/admin.php
@@ -23,7 +23,7 @@
 
 
 // Init owncloud
-require_once('../lib/base.php');
+ 
 
 OC_Util::checkAdminUser();
 
diff --git a/files/ajax/autocomplete.php b/apps/files/ajax/autocomplete.php
similarity index 96%
rename from files/ajax/autocomplete.php
rename to apps/files/ajax/autocomplete.php
index 8d7a5b482bd490903705b1661c586d4339f2ab9b..8cdb6188a022f6d2dee9867d0386b0ae93893652 100644
--- a/files/ajax/autocomplete.php
+++ b/apps/files/ajax/autocomplete.php
@@ -3,7 +3,7 @@
 
 
 // Init owncloud
-require_once('../../lib/base.php');
+
 
 OC_JSON::checkLoggedIn();
 
diff --git a/files/ajax/delete.php b/apps/files/ajax/delete.php
similarity index 94%
rename from files/ajax/delete.php
rename to apps/files/ajax/delete.php
index 1725201fdd9e4541bce45d4334c6c86be60f274b..d8a01d7acf1c3731b30f88a559bb31745d52aa56 100644
--- a/files/ajax/delete.php
+++ b/apps/files/ajax/delete.php
@@ -1,7 +1,7 @@
 <?php
 
 // Init owncloud
-require_once('../../lib/base.php');
+
 
 OC_JSON::checkLoggedIn();
 
diff --git a/files/ajax/download.php b/apps/files/ajax/download.php
similarity index 96%
rename from files/ajax/download.php
rename to apps/files/ajax/download.php
index 39852613ab95ae10dd86fd86b7e07e029dc1d7db..65c04c36fafd655b06c849e379d05ec55c637f9c 100644
--- a/files/ajax/download.php
+++ b/apps/files/ajax/download.php
@@ -25,7 +25,7 @@
 $RUNTIME_APPTYPES=array('filesystem');
 
 // Init owncloud
-require_once('../../lib/base.php');
+
 
 // Check if we are a user
 OC_Util::checkLoggedIn();
diff --git a/files/ajax/list.php b/apps/files/ajax/list.php
similarity index 96%
rename from files/ajax/list.php
rename to apps/files/ajax/list.php
index ec9ab7342dd94df17585afc359de882816c375c0..83914332a7daea3a9b1584c9c48434e90d857150 100644
--- a/files/ajax/list.php
+++ b/apps/files/ajax/list.php
@@ -4,7 +4,7 @@
 $RUNTIME_APPTYPES=array('filesystem');
 
 // Init owncloud
-require_once('../../lib/base.php');
+
 
 OC_JSON::checkLoggedIn();
 
diff --git a/files/ajax/mimeicon.php b/apps/files/ajax/mimeicon.php
similarity index 76%
rename from files/ajax/mimeicon.php
rename to apps/files/ajax/mimeicon.php
index ff72ba0f5b76af7142000c5b981a7f60dc6f6d22..57898cd82d9c09f68289284c6a8e2a19c3573244 100644
--- a/files/ajax/mimeicon.php
+++ b/apps/files/ajax/mimeicon.php
@@ -4,7 +4,7 @@
 $RUNTIME_NOAPPS=false;
 
 // Init owncloud
-require_once('../../lib/base.php');
+
 
 print OC_Helper::mimetypeIcon($_GET['mime']);
 
diff --git a/files/ajax/move.php b/apps/files/ajax/move.php
similarity index 91%
rename from files/ajax/move.php
rename to apps/files/ajax/move.php
index 9af3f80208f5e0b8d31e8f00279a39efcc222ede..0ad314f873c26b20606bdadd26461b0a9a74d17d 100644
--- a/files/ajax/move.php
+++ b/apps/files/ajax/move.php
@@ -1,7 +1,7 @@
 <?php
 
 // Init owncloud
-require_once('../../lib/base.php');
+
 
 OC_JSON::checkLoggedIn();
 
diff --git a/files/ajax/newfile.php b/apps/files/ajax/newfile.php
similarity index 97%
rename from files/ajax/newfile.php
rename to apps/files/ajax/newfile.php
index 2d1372f06ee5fb8d40c57233fd6b964d9a9d6d5e..472b577a32a23254e2c95454c78db850cc3fe419 100644
--- a/files/ajax/newfile.php
+++ b/apps/files/ajax/newfile.php
@@ -1,7 +1,7 @@
 <?php
 
 // Init owncloud
-require_once('../../lib/base.php');
+
 
 OC_JSON::checkLoggedIn();
 
diff --git a/files/ajax/newfolder.php b/apps/files/ajax/newfolder.php
similarity index 93%
rename from files/ajax/newfolder.php
rename to apps/files/ajax/newfolder.php
index 228e369fbef95c336dfd6426470a9a0951f2bbb9..2aff95e5b357afed91c55ad00624deeac142e3fc 100644
--- a/files/ajax/newfolder.php
+++ b/apps/files/ajax/newfolder.php
@@ -1,7 +1,7 @@
 <?php
 
 // Init owncloud
-require_once('../../lib/base.php');
+
 
 OC_JSON::checkLoggedIn();
 
diff --git a/files/ajax/rawlist.php b/apps/files/ajax/rawlist.php
similarity index 94%
rename from files/ajax/rawlist.php
rename to apps/files/ajax/rawlist.php
index e02c5b6273342930cbb70695cc23f8931e48c50d..8f1990d1b8ff694a4bbb87123bacc03e4094bd21 100644
--- a/files/ajax/rawlist.php
+++ b/apps/files/ajax/rawlist.php
@@ -4,7 +4,7 @@
 $RUNTIME_APPTYPES=array('filesystem');
 
 // Init owncloud
-require_once('../../lib/base.php');
+
 require_once('../../lib/template.php');
 
 OC_JSON::checkLoggedIn();
diff --git a/files/ajax/rename.php b/apps/files/ajax/rename.php
similarity index 92%
rename from files/ajax/rename.php
rename to apps/files/ajax/rename.php
index a51b36635b376694166ab1914c8ab6004b24f2e3..dc5d3962abd7c3160bf5273a4ae4fad1c240553e 100644
--- a/files/ajax/rename.php
+++ b/apps/files/ajax/rename.php
@@ -1,7 +1,7 @@
 <?php
 
 // Init owncloud
-require_once('../../lib/base.php');
+
 
 OC_JSON::checkLoggedIn();
 
diff --git a/files/ajax/scan.php b/apps/files/ajax/scan.php
similarity index 95%
rename from files/ajax/scan.php
rename to apps/files/ajax/scan.php
index c60e34b51767429c81f0e4627901bef544e78538..a227dcc3ffc93a5bef7a30896eeb83effc25e7ed 100644
--- a/files/ajax/scan.php
+++ b/apps/files/ajax/scan.php
@@ -1,7 +1,5 @@
 <?php
 
-require_once '../../lib/base.php';
-
 set_time_limit(0);//scanning can take ages
 
 $force=isset($_GET['force']) and $_GET['force']=='true';
diff --git a/files/ajax/timezone.php b/apps/files/ajax/timezone.php
similarity index 100%
rename from files/ajax/timezone.php
rename to apps/files/ajax/timezone.php
diff --git a/files/ajax/upload.php b/apps/files/ajax/upload.php
similarity index 98%
rename from files/ajax/upload.php
rename to apps/files/ajax/upload.php
index b04796e3248591ae38a61397b1b708facb946248..c60e1a3752ac28be021b7cba3481eb5c0b799a7f 100644
--- a/files/ajax/upload.php
+++ b/apps/files/ajax/upload.php
@@ -1,7 +1,7 @@
 <?php
 
 // Init owncloud
-require_once('../../lib/base.php');
+
 
 // Firefox and Konqueror tries to download application/json for me.  --Arthur
 OC_JSON::setContentTypeHeader('text/plain');
diff --git a/files/appinfo/app.php b/apps/files/appinfo/app.php
similarity index 100%
rename from files/appinfo/app.php
rename to apps/files/appinfo/app.php
diff --git a/files/css/files.css b/apps/files/css/files.css
similarity index 96%
rename from files/css/files.css
rename to apps/files/css/files.css
index 9dce2d9f944de2bb22232dfbe260bdd787e03305..a135f7ded5b689a9e8b842f7d6eaf01e99286527 100644
--- a/files/css/files.css
+++ b/apps/files/css/files.css
@@ -20,7 +20,7 @@
 #new>ul>li>p { cursor:pointer; }
 #new>ul>li>input { padding:0.3em; margin:-0.3em; }
 
-#file_newfolder_name { background-image:url('../../core/img/places/folder.svg'); font-weight:normal; width:7em; }
+#file_newfolder_name { background-image:url('%webroot%/core/img/places/folder.svg'); font-weight:normal; width:7em; }
 .file_upload_start, .file_upload_filename { font-size:1em; }
 #file_newfolder_submit, #file_upload_submit { width:3em; }
 .file_upload_target { display:none; }
@@ -85,7 +85,7 @@ a.action>img { max-height:16px; max-width:16px; vertical-align:text-bottom; }
 .selectedActions a img { position:relative; top:.3em; }
 
 /* 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; position:fixed; }
+#navigation>ul>li:first-child { background:url('%webroot%/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; }
 
 #scanning-message{ top:40%; left:40%; position:absolute; display:none }
diff --git a/files/download.php b/apps/files/download.php
similarity index 97%
rename from files/download.php
rename to apps/files/download.php
index d1f5ba486d7eaed89341f15cf94edd249d81593f..ec4a6e1fc9c58d264e4fbebe4e466befec496019 100644
--- a/files/download.php
+++ b/apps/files/download.php
@@ -22,7 +22,7 @@
 */
 
 // Init owncloud
-require_once('../lib/base.php');
+ 
 
 // Check if we are a user
 OC_Util::checkLoggedIn();
diff --git a/files/index.php b/apps/files/index.php
similarity index 98%
rename from files/index.php
rename to apps/files/index.php
index 84dbb9f343fcbc8c2dc405622f02de84ea14e7fe..8464db30f0156caa1ff672a234a63358ede5a3ae 100644
--- a/files/index.php
+++ b/apps/files/index.php
@@ -21,10 +21,6 @@
 *
 */
 
-
-// Init owncloud
-require_once('../lib/base.php');
-
 // Check if we are a user
 OC_Util::checkLoggedIn();
 
diff --git a/files/js/admin.js b/apps/files/js/admin.js
similarity index 100%
rename from files/js/admin.js
rename to apps/files/js/admin.js
diff --git a/files/js/fileactions.js b/apps/files/js/fileactions.js
similarity index 97%
rename from files/js/fileactions.js
rename to apps/files/js/fileactions.js
index 975af938440f5854f7b37a20472ece6ec007bb97..68268a7d3a9ce0e8dd2a8870a6d4e915d7aaf365 100644
--- a/files/js/fileactions.js
+++ b/apps/files/js/fileactions.js
@@ -135,7 +135,7 @@ $(document).ready(function(){
 		var downloadScope = 'file';
 	}
 	FileActions.register(downloadScope,'Download',function(){return OC.imagePath('core','actions/download')},function(filename){
-		window.location='ajax/download.php?files='+encodeURIComponent(filename)+'&dir='+encodeURIComponent($('#dir').val());
+		window.location=OC.filePath('files', 'ajax', 'download.php') + '?files='+encodeURIComponent(filename)+'&dir='+encodeURIComponent($('#dir').val());
 	});
 });
 
diff --git a/files/js/filelist.js b/apps/files/js/filelist.js
similarity index 100%
rename from files/js/filelist.js
rename to apps/files/js/filelist.js
diff --git a/files/js/files.js b/apps/files/js/files.js
similarity index 99%
rename from files/js/files.js
rename to apps/files/js/files.js
index e13e256efc4f7594fdc261615840c390ca86ffc4..2dce00035e162fe0195c035ea21f2dc6ab41547f 100644
--- a/files/js/files.js
+++ b/apps/files/js/files.js
@@ -169,7 +169,7 @@ $(document).ready(function() {
 		var dir=$('#dir').val()||'/';
 		$('#notification').text(t('files','generating ZIP-file, it may take some time.'));
 		$('#notification').fadeIn();
-		window.location='ajax/download.php?files='+encodeURIComponent(files)+'&dir='+encodeURIComponent(dir);
+		window.location=OC.filePath('files', 'ajax', 'download.php') + '?files='+encodeURIComponent(files)+'&dir='+encodeURIComponent(dir);
 		return false;
 	});
 
@@ -572,7 +572,7 @@ var folderDropOptions={
 		var target=$(this).text().trim();
 		var dir=$('#dir').val();
 		$.ajax({
-			url: 'ajax/move.php',
+			url: OC.filePath('files', 'ajax', 'move.php'),
 		data: "dir="+encodeURIComponent(dir)+"&file="+encodeURIComponent(file)+'&target='+encodeURIComponent(dir)+'/'+encodeURIComponent(target),
 		complete: function(data){boolOperationFinished(data, function(){
 			var el = $('#fileList tr').filterAttr('data-file',file).find('td.filename');
@@ -598,7 +598,7 @@ var crumbDropOptions={
 			return;
 		}
 		$.ajax({
-			url: 'ajax/move.php',
+			url: OC.filePath('files', 'ajax', 'move.php'),
 		 data: "dir="+encodeURIComponent(dir)+"&file="+encodeURIComponent(file)+'&target='+encodeURIComponent(target),
 		 complete: function(data){boolOperationFinished(data, function(){
 			 FileList.remove(file);
diff --git a/files/js/jquery.fileupload.js b/apps/files/js/jquery.fileupload.js
similarity index 100%
rename from files/js/jquery.fileupload.js
rename to apps/files/js/jquery.fileupload.js
diff --git a/files/js/jquery.iframe-transport.js b/apps/files/js/jquery.iframe-transport.js
similarity index 100%
rename from files/js/jquery.iframe-transport.js
rename to apps/files/js/jquery.iframe-transport.js
diff --git a/files/js/timezone.js b/apps/files/js/timezone.js
similarity index 82%
rename from files/js/timezone.js
rename to apps/files/js/timezone.js
index d569683f2109491fa5c16a0f124aeac26014d793..4749417199d957169de66589408ccb743d9d67ec 100644
--- a/files/js/timezone.js
+++ b/apps/files/js/timezone.js
@@ -3,7 +3,7 @@ $(document).ready(function() {
 	var visitortimezone = (-new Date().getTimezoneOffset()/60);
 	$.ajax({
 		type: "GET",
-		url: "ajax/timezone.php",
+		url: OC.filePath('files', 'ajax', 'timezone.php'),
 		data: 'time='+ visitortimezone,
 		success: function(){
 			location.reload();
diff --git a/files/l10n/ar.php b/apps/files/l10n/ar.php
similarity index 100%
rename from files/l10n/ar.php
rename to apps/files/l10n/ar.php
diff --git a/files/l10n/bg_BG.php b/apps/files/l10n/bg_BG.php
similarity index 100%
rename from files/l10n/bg_BG.php
rename to apps/files/l10n/bg_BG.php
diff --git a/files/l10n/ca.php b/apps/files/l10n/ca.php
similarity index 100%
rename from files/l10n/ca.php
rename to apps/files/l10n/ca.php
diff --git a/files/l10n/cs_CZ.php b/apps/files/l10n/cs_CZ.php
similarity index 100%
rename from files/l10n/cs_CZ.php
rename to apps/files/l10n/cs_CZ.php
diff --git a/files/l10n/da.php b/apps/files/l10n/da.php
similarity index 100%
rename from files/l10n/da.php
rename to apps/files/l10n/da.php
diff --git a/files/l10n/de.php b/apps/files/l10n/de.php
similarity index 100%
rename from files/l10n/de.php
rename to apps/files/l10n/de.php
diff --git a/files/l10n/el.php b/apps/files/l10n/el.php
similarity index 100%
rename from files/l10n/el.php
rename to apps/files/l10n/el.php
diff --git a/files/l10n/eo.php b/apps/files/l10n/eo.php
similarity index 100%
rename from files/l10n/eo.php
rename to apps/files/l10n/eo.php
diff --git a/files/l10n/es.php b/apps/files/l10n/es.php
similarity index 100%
rename from files/l10n/es.php
rename to apps/files/l10n/es.php
diff --git a/files/l10n/et_EE.php b/apps/files/l10n/et_EE.php
similarity index 100%
rename from files/l10n/et_EE.php
rename to apps/files/l10n/et_EE.php
diff --git a/files/l10n/eu.php b/apps/files/l10n/eu.php
similarity index 100%
rename from files/l10n/eu.php
rename to apps/files/l10n/eu.php
diff --git a/files/l10n/fr.php b/apps/files/l10n/fr.php
similarity index 100%
rename from files/l10n/fr.php
rename to apps/files/l10n/fr.php
diff --git a/files/l10n/gl.php b/apps/files/l10n/gl.php
similarity index 100%
rename from files/l10n/gl.php
rename to apps/files/l10n/gl.php
diff --git a/files/l10n/he.php b/apps/files/l10n/he.php
similarity index 100%
rename from files/l10n/he.php
rename to apps/files/l10n/he.php
diff --git a/files/l10n/hr.php b/apps/files/l10n/hr.php
similarity index 100%
rename from files/l10n/hr.php
rename to apps/files/l10n/hr.php
diff --git a/files/l10n/hu_HU.php b/apps/files/l10n/hu_HU.php
similarity index 100%
rename from files/l10n/hu_HU.php
rename to apps/files/l10n/hu_HU.php
diff --git a/files/l10n/ia.php b/apps/files/l10n/ia.php
similarity index 100%
rename from files/l10n/ia.php
rename to apps/files/l10n/ia.php
diff --git a/files/l10n/id.php b/apps/files/l10n/id.php
similarity index 100%
rename from files/l10n/id.php
rename to apps/files/l10n/id.php
diff --git a/files/l10n/it.php b/apps/files/l10n/it.php
similarity index 100%
rename from files/l10n/it.php
rename to apps/files/l10n/it.php
diff --git a/files/l10n/ja_JP.php b/apps/files/l10n/ja_JP.php
similarity index 100%
rename from files/l10n/ja_JP.php
rename to apps/files/l10n/ja_JP.php
diff --git a/files/l10n/lb.php b/apps/files/l10n/lb.php
similarity index 100%
rename from files/l10n/lb.php
rename to apps/files/l10n/lb.php
diff --git a/files/l10n/lt_LT.php b/apps/files/l10n/lt_LT.php
similarity index 100%
rename from files/l10n/lt_LT.php
rename to apps/files/l10n/lt_LT.php
diff --git a/files/l10n/ms_MY.php b/apps/files/l10n/ms_MY.php
similarity index 100%
rename from files/l10n/ms_MY.php
rename to apps/files/l10n/ms_MY.php
diff --git a/files/l10n/nb_NO.php b/apps/files/l10n/nb_NO.php
similarity index 100%
rename from files/l10n/nb_NO.php
rename to apps/files/l10n/nb_NO.php
diff --git a/files/l10n/nl.php b/apps/files/l10n/nl.php
similarity index 100%
rename from files/l10n/nl.php
rename to apps/files/l10n/nl.php
diff --git a/files/l10n/nn_NO.php b/apps/files/l10n/nn_NO.php
similarity index 100%
rename from files/l10n/nn_NO.php
rename to apps/files/l10n/nn_NO.php
diff --git a/files/l10n/pl.php b/apps/files/l10n/pl.php
similarity index 100%
rename from files/l10n/pl.php
rename to apps/files/l10n/pl.php
diff --git a/files/l10n/pt_BR.php b/apps/files/l10n/pt_BR.php
similarity index 100%
rename from files/l10n/pt_BR.php
rename to apps/files/l10n/pt_BR.php
diff --git a/files/l10n/ro.php b/apps/files/l10n/ro.php
similarity index 100%
rename from files/l10n/ro.php
rename to apps/files/l10n/ro.php
diff --git a/files/l10n/ru.php b/apps/files/l10n/ru.php
similarity index 100%
rename from files/l10n/ru.php
rename to apps/files/l10n/ru.php
diff --git a/files/l10n/sk_SK.php b/apps/files/l10n/sk_SK.php
similarity index 100%
rename from files/l10n/sk_SK.php
rename to apps/files/l10n/sk_SK.php
diff --git a/files/l10n/sl.php b/apps/files/l10n/sl.php
similarity index 100%
rename from files/l10n/sl.php
rename to apps/files/l10n/sl.php
diff --git a/files/l10n/sr.php b/apps/files/l10n/sr.php
similarity index 100%
rename from files/l10n/sr.php
rename to apps/files/l10n/sr.php
diff --git a/files/l10n/sr@latin.php b/apps/files/l10n/sr@latin.php
similarity index 100%
rename from files/l10n/sr@latin.php
rename to apps/files/l10n/sr@latin.php
diff --git a/files/l10n/sv.php b/apps/files/l10n/sv.php
similarity index 100%
rename from files/l10n/sv.php
rename to apps/files/l10n/sv.php
diff --git a/files/l10n/th_TH.php b/apps/files/l10n/th_TH.php
similarity index 100%
rename from files/l10n/th_TH.php
rename to apps/files/l10n/th_TH.php
diff --git a/files/l10n/tr.php b/apps/files/l10n/tr.php
similarity index 100%
rename from files/l10n/tr.php
rename to apps/files/l10n/tr.php
diff --git a/files/l10n/xgettextfiles b/apps/files/l10n/xgettextfiles
similarity index 100%
rename from files/l10n/xgettextfiles
rename to apps/files/l10n/xgettextfiles
diff --git a/files/l10n/zh_CN.php b/apps/files/l10n/zh_CN.php
similarity index 100%
rename from files/l10n/zh_CN.php
rename to apps/files/l10n/zh_CN.php
diff --git a/files/settings.php b/apps/files/settings.php
similarity index 97%
rename from files/settings.php
rename to apps/files/settings.php
index c47eb130095a236b5c38135f5809ee13838c9e7d..41017c064efa9d85969850f1e23ef3fd6d12c810 100644
--- a/files/settings.php
+++ b/apps/files/settings.php
@@ -23,7 +23,7 @@
 
 
 // Init owncloud
-require_once('../lib/base.php');
+ 
 
 // Check if we are a user
 OC_Util::checkLoggedIn();
diff --git a/files/templates/admin.php b/apps/files/templates/admin.php
similarity index 100%
rename from files/templates/admin.php
rename to apps/files/templates/admin.php
diff --git a/files/templates/index.php b/apps/files/templates/index.php
similarity index 95%
rename from files/templates/index.php
rename to apps/files/templates/index.php
index 3c76eb0187d056dde6f24701097f0c7b01532d3a..fc385e1ed3ad78083ce970123ce030986186ed47 100644
--- a/files/templates/index.php
+++ b/apps/files/templates/index.php
@@ -12,7 +12,7 @@
 				</ul>
 			</div>
 			<div class="file_upload_wrapper svg">
-				<form data-upload-id='1' class="file_upload_form" action="ajax/upload.php" method="post" enctype="multipart/form-data" target="file_upload_target_1">
+				<form data-upload-id='1' class="file_upload_form" action="<?php echo OC_Helper::linkto('files', 'ajax/upload.php'); ?>" method="post" enctype="multipart/form-data" target="file_upload_target_1">
 					<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $_['uploadMaxFilesize'] ?>" id="max_upload">
 					<input type="hidden" class="max_human_file_size" value="(max <?php echo $_['uploadMaxHumanFilesize']; ?>)">
 					<input type="hidden" name="dir" value="<?php echo htmlentities($_['dir']) ?>" id="dir">
diff --git a/files/templates/part.breadcrumb.php b/apps/files/templates/part.breadcrumb.php
similarity index 100%
rename from files/templates/part.breadcrumb.php
rename to apps/files/templates/part.breadcrumb.php
diff --git a/files/templates/part.list.php b/apps/files/templates/part.list.php
similarity index 100%
rename from files/templates/part.list.php
rename to apps/files/templates/part.list.php
diff --git a/apps/files/webdav.php b/apps/files/webdav.php
new file mode 100644
index 0000000000000000000000000000000000000000..940bbfef52ee6dbe80bd0e61194e0680ef3fb025
--- /dev/null
+++ b/apps/files/webdav.php
@@ -0,0 +1,52 @@
+<?php
+
+/**
+ * ownCloud
+ *
+ * @author Frank Karlitschek
+ * @author Jakob Sack
+ * @copyright 2010 Frank Karlitschek karlitschek@kde.org
+ * @copyright 2011 Jakob Sack kde@jakobsack.de
+ *
+ * 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/>.
+ *
+ */
+
+// Do not load FS ...
+$RUNTIME_NOSETUPFS = true;
+require_once('../inc.php');
+
+// only need filesystem apps
+$RUNTIME_APPTYPES=array('filesystem','authentication');
+
+ 
+
+// Backends
+$authBackend = new OC_Connector_Sabre_Auth();
+$lockBackend = new OC_Connector_Sabre_Locks();
+
+// Create ownCloud Dir
+$publicDir = new OC_Connector_Sabre_Directory('');
+
+// Fire up server
+$server = new Sabre_DAV_Server($publicDir);
+$server->setBaseUri(OC::$APPSWEBROOT.'/apps/files/webdav.php');
+
+// Load plugins
+$server->addPlugin(new Sabre_DAV_Auth_Plugin($authBackend,'ownCloud'));
+$server->addPlugin(new Sabre_DAV_Locks_Plugin($lockBackend));
+$server->addPlugin(new Sabre_DAV_Browser_Plugin(false)); // Show something in the Browser, but no upload
+
+// And off we go!
+$server->exec();
diff --git a/apps/files_imageviewer/css/jquery.fancybox-1.3.4.css b/apps/files_imageviewer/css/jquery.fancybox-1.3.4.css
index 1dfd9b95d35ce0d58e1171912212219374df8bc4..5fdf7af14cbc790c9d60d133d42072ce485f363d 100644
--- a/apps/files_imageviewer/css/jquery.fancybox-1.3.4.css
+++ b/apps/files_imageviewer/css/jquery.fancybox-1.3.4.css
@@ -35,7 +35,7 @@
 	left: 0;
 	width: 40px;
 	height: 480px;
-	background-image: url('../img/fancybox.png');
+	background-image: url('%appswebroot%/apps/files_imageviewer/img/fancybox.png');
 }
 
 #fancybox-overlay {
@@ -99,7 +99,7 @@
 	right: -15px;
 	width: 30px;
 	height: 30px;
-	background: transparent url('../img/fancybox.png') -40px 0px;
+	background: transparent url('%appswebroot%/apps/files_imageviewer/img/fancybox.png') -40px 0px;
 	cursor: pointer;
 	z-index: 1103;
 	display: none;
@@ -137,7 +137,7 @@
 	width: 35%;
 	cursor: pointer;
 	outline: none;
-	background: transparent url('../img/blank.gif');
+	background: transparent url('%appswebroot%/apps/files_imageviewer/img/blank.gif');
 	z-index: 1102;
 	display: none;
 }
@@ -163,12 +163,12 @@
 }
 
 #fancybox-left-ico {
-	background-image: url('../img/fancybox.png');
+	background-image: url('%appswebroot%/apps/files_imageviewer/img/fancybox.png');
 	background-position: -40px -30px;
 }
 
 #fancybox-right-ico {
-	background-image: url('../img/fancybox.png');
+	background-image: url('%appswebroot%/apps/files_imageviewer/img/fancybox.png');
 	background-position: -40px -60px;
 }
 
@@ -199,13 +199,13 @@
 	top: -20px;
 	left: 0;
 	width: 100%;
-	background-image: url('../img/fancybox-x.png');
+	background-image: url('%appswebroot%/apps/files_imageviewer/img/fancybox-x.png');
 }
 
 #fancybox-bg-ne {
 	top: -20px;
 	right: -20px;
-	background-image: url('../img/fancybox.png');
+	background-image: url('%appswebroot%/apps/files_imageviewer/img/fancybox.png');
 	background-position: -40px -162px;
 }
 
@@ -213,14 +213,14 @@
 	top: 0;
 	right: -20px;
 	height: 100%;
-	background-image: url('../img/fancybox-y.png');
+	background-image: url('%appswebroot%/apps/files_imageviewer/img/fancybox-y.png');
 	background-position: -20px 0px;
 }
 
 #fancybox-bg-se {
 	bottom: -20px;
 	right: -20px;
-	background-image: url('../img/fancybox.png');
+	background-image: url('%appswebroot%/apps/files_imageviewer/img/fancybox.png');
 	background-position: -40px -182px; 
 }
 
@@ -228,14 +228,14 @@
 	bottom: -20px;
 	left: 0;
 	width: 100%;
-	background-image: url('../img/fancybox-x.png');
+	background-image: url('%appswebroot%/apps/files_imageviewer/img/fancybox-x.png');
 	background-position: 0px -20px;
 }
 
 #fancybox-bg-sw {
 	bottom: -20px;
 	left: -20px;
-	background-image: url('../img/fancybox.png');
+	background-image: url('%appswebroot%/apps/files_imageviewer/img/fancybox.png');
 	background-position: -40px -142px;
 }
 
@@ -243,13 +243,13 @@
 	top: 0;
 	left: -20px;
 	height: 100%;
-	background-image: url('../img/fancybox-y.png');
+	background-image: url('%appswebroot%/apps/files_imageviewer/img/fancybox-y.png');
 }
 
 #fancybox-bg-nw {
 	top: -20px;
 	left: -20px;
-	background-image: url('../img/fancybox.png');
+	background-image: url('%appswebroot%/apps/files_imageviewer/img/fancybox.png');
 	background-position: -40px -122px;
 }
 
@@ -282,7 +282,7 @@
 
 #fancybox-title-over {
 	padding: 10px;
-	background-image: url('../img/fancy_title_over.png');
+	background-image: url('%appswebroot%/apps/files_imageviewer/img/fancy_title_over.png');
 	display: block;
 }
 
@@ -306,7 +306,7 @@
 
 #fancybox-title-float-left {
 	padding: 0 0 0 15px;
-	background: url('../img/fancybox.png') -40px -90px no-repeat;
+	background: url('%appswebroot%/apps/files_imageviewer/img/fancybox.png') -40px -90px no-repeat;
 }
 
 #fancybox-title-float-main {
@@ -314,25 +314,25 @@
 	line-height: 29px;
 	font-weight: bold;
 	padding: 0 0 3px 0;
-	background: url('../img/fancybox-x.png') 0px -40px;
+	background: url('%appswebroot%/apps/files_imageviewer/img/fancybox-x.png') 0px -40px;
 }
 
 #fancybox-title-float-right {
 	padding: 0 0 0 15px;
-	background: url('../img/fancybox.png') -55px -90px no-repeat;
+	background: url('%appswebroot%/apps/files_imageviewer/img/fancybox.png') -55px -90px no-repeat;
 }
 
 /* IE6 */
 
-.fancybox-ie6 #fancybox-close { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_close.png', sizingMethod='scale'); }
+.fancybox-ie6 #fancybox-close { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='%appswebroot%/apps/files_imageviewer/img/fancy_close.png', sizingMethod='scale'); }
 
-.fancybox-ie6 #fancybox-left-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_nav_left.png', sizingMethod='scale'); }
-.fancybox-ie6 #fancybox-right-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_nav_right.png', sizingMethod='scale'); }
+.fancybox-ie6 #fancybox-left-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='%appswebroot%/apps/files_imageviewer/img/fancy_nav_left.png', sizingMethod='scale'); }
+.fancybox-ie6 #fancybox-right-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='%appswebroot%/apps/files_imageviewer/img/fancy_nav_right.png', sizingMethod='scale'); }
 
-.fancybox-ie6 #fancybox-title-over { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_title_over.png', sizingMethod='scale'); zoom: 1; }
-.fancybox-ie6 #fancybox-title-float-left { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_title_left.png', sizingMethod='scale'); }
-.fancybox-ie6 #fancybox-title-float-main { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_title_main.png', sizingMethod='scale'); }
-.fancybox-ie6 #fancybox-title-float-right { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_title_right.png', sizingMethod='scale'); }
+.fancybox-ie6 #fancybox-title-over { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='%appswebroot%/apps/files_imageviewer/img/fancy_title_over.png', sizingMethod='scale'); zoom: 1; }
+.fancybox-ie6 #fancybox-title-float-left { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='%appswebroot%/apps/files_imageviewer/img/fancy_title_left.png', sizingMethod='scale'); }
+.fancybox-ie6 #fancybox-title-float-main { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='%appswebroot%/apps/files_imageviewer/img/fancy_title_main.png', sizingMethod='scale'); }
+.fancybox-ie6 #fancybox-title-float-right { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='%appswebroot%/apps/files_imageviewer/img/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");
@@ -343,17 +343,17 @@
 	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='../img/fancy_loading.png', sizingMethod='scale'); }
+#fancybox-loading.fancybox-ie6 div	{ background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='%appswebroot%/apps/files_imageviewer/img/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='../img/fancy_shadow_n.png', sizingMethod='scale'); }
-.fancybox-ie #fancybox-bg-ne { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_shadow_ne.png', sizingMethod='scale'); }
-.fancybox-ie #fancybox-bg-e { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_shadow_e.png', sizingMethod='scale'); }
-.fancybox-ie #fancybox-bg-se { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_shadow_se.png', sizingMethod='scale'); }
-.fancybox-ie #fancybox-bg-s { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_shadow_s.png', sizingMethod='scale'); }
-.fancybox-ie #fancybox-bg-sw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_shadow_sw.png', sizingMethod='scale'); }
-.fancybox-ie #fancybox-bg-w { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_shadow_w.png', sizingMethod='scale'); }
-.fancybox-ie #fancybox-bg-nw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../img/fancy_shadow_nw.png', sizingMethod='scale'); }
+.fancybox-ie #fancybox-bg-n { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='%appswebroot%/apps/files_imageviewer/img/fancy_shadow_n.png', sizingMethod='scale'); }
+.fancybox-ie #fancybox-bg-ne { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='%appswebroot%/apps/files_imageviewer/img/fancy_shadow_ne.png', sizingMethod='scale'); }
+.fancybox-ie #fancybox-bg-e { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='%appswebroot%/apps/files_imageviewer/img/fancy_shadow_e.png', sizingMethod='scale'); }
+.fancybox-ie #fancybox-bg-se { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='%appswebroot%/apps/files_imageviewer/img/fancy_shadow_se.png', sizingMethod='scale'); }
+.fancybox-ie #fancybox-bg-s { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='%appswebroot%/apps/files_imageviewer/img/fancy_shadow_s.png', sizingMethod='scale'); }
+.fancybox-ie #fancybox-bg-sw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='%appswebroot%/apps/files_imageviewer/img/fancy_shadow_sw.png', sizingMethod='scale'); }
+.fancybox-ie #fancybox-bg-w { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='%appswebroot%/apps/files_imageviewer/img/fancy_shadow_w.png', sizingMethod='scale'); }
+.fancybox-ie #fancybox-bg-nw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='%appswebroot%/apps/files_imageviewer/img/fancy_shadow_nw.png', sizingMethod='scale'); }
diff --git a/apps/files_sharing/ajax/getitem.php b/apps/files_sharing/ajax/getitem.php
index ba01adffb9a6fa1e45fc95790db7af9e55edf1b6..c838895efbe269497ee65ac4b6b5d7e835b4b937 100644
--- a/apps/files_sharing/ajax/getitem.php
+++ b/apps/files_sharing/ajax/getitem.php
@@ -1,7 +1,7 @@
 <?php
 //$RUNTIME_NOAPPS = true;
 
-require_once('../../../lib/base.php');
+ 
 OC_JSON::checkAppEnabled('files_sharing');
 require_once('../lib_share.php');
 
diff --git a/apps/files_sharing/ajax/setpermissions.php b/apps/files_sharing/ajax/setpermissions.php
index 200202c704c0da0b95cb5a466240fc2bf5e82bbf..d46f6f0c7b4346c4573b4b2a1cf6a38911e6a32a 100644
--- a/apps/files_sharing/ajax/setpermissions.php
+++ b/apps/files_sharing/ajax/setpermissions.php
@@ -1,7 +1,7 @@
 <?php
 //$RUNTIME_NOAPPS = true;
 
-require_once('../../../lib/base.php');
+ 
 OC_JSON::checkAppEnabled('files_sharing');
 require_once('../lib_share.php');
 
diff --git a/apps/files_sharing/ajax/share.php b/apps/files_sharing/ajax/share.php
index 9b10260da5a0e10945f300b6d69559d3182c7064..cd9166913cb9e57bfb95691122898dd4f303461a 100644
--- a/apps/files_sharing/ajax/share.php
+++ b/apps/files_sharing/ajax/share.php
@@ -1,7 +1,7 @@
 <?php
 //$RUNTIME_NOAPPS = true;
 
-require_once('../../../lib/base.php');
+ 
 OC_JSON::checkAppEnabled('files_sharing');
 require_once('../lib_share.php');
 
diff --git a/apps/files_sharing/ajax/unshare.php b/apps/files_sharing/ajax/unshare.php
index d8a72a00efe4317dd41dffa672f550cefe122378..150d6504863220374e27c5800f9048011f1a740f 100644
--- a/apps/files_sharing/ajax/unshare.php
+++ b/apps/files_sharing/ajax/unshare.php
@@ -1,7 +1,7 @@
 <?php
 //$RUNTIME_NOAPPS = true;
 
-require_once('../../../lib/base.php');
+ 
 OC_JSON::checkAppEnabled('files_sharing');
 require_once('../lib_share.php');
 
diff --git a/apps/files_sharing/ajax/userautocomplete.php b/apps/files_sharing/ajax/userautocomplete.php
index 38b673ee51b585ebccbf7f9145a3d26a530fef94..cc22a0cd1a79d45a02c4a6d8172e190475283c97 100644
--- a/apps/files_sharing/ajax/userautocomplete.php
+++ b/apps/files_sharing/ajax/userautocomplete.php
@@ -1,7 +1,7 @@
 <?php
 //$RUNTIME_NOAPPS = true;
 
-require_once('../../../lib/base.php');
+ 
 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('files_sharing');
diff --git a/apps/files_sharing/list.php b/apps/files_sharing/list.php
index 721620dc92253b3c8313272380972d5e8c0f0288..a9006faf1a92a288254a207ee571fc9c705b2a06 100644
--- a/apps/files_sharing/list.php
+++ b/apps/files_sharing/list.php
@@ -20,7 +20,7 @@
  *
  */
 
-require_once('../../lib/base.php');
+
 require_once('lib_share.php');
 
 OC_Util::checkLoggedIn();
diff --git a/apps/files_texteditor/ajax/loadfile.php b/apps/files_texteditor/ajax/loadfile.php
index 8ece844aa29fdf2d32a8345c45b5a3c3a0b565c4..a946e26f210f60a641dd569393c872fb5160819f 100644
--- a/apps/files_texteditor/ajax/loadfile.php
+++ b/apps/files_texteditor/ajax/loadfile.php
@@ -21,7 +21,7 @@
  */
 
 // Init owncloud
-require_once('../../../lib/base.php');
+ 
 
 
 // Check if we are a user
diff --git a/apps/files_texteditor/ajax/mtime.php b/apps/files_texteditor/ajax/mtime.php
index df90a68ca7a37af3ad16a20b1d12894f1172fb2f..436592c383f7417843a03396eda94c7af9ad487f 100644
--- a/apps/files_texteditor/ajax/mtime.php
+++ b/apps/files_texteditor/ajax/mtime.php
@@ -21,7 +21,7 @@
  */
 
 // Init owncloud
-require_once('../../../lib/base.php');
+ 
 
 
 // Check if we are a user
diff --git a/apps/files_texteditor/ajax/savefile.php b/apps/files_texteditor/ajax/savefile.php
index 57a948478f52d6f4c8f8b1e38a6a82843c14761c..9f67cc4b4e6f325381448ecb6ece468869801dcc 100644
--- a/apps/files_texteditor/ajax/savefile.php
+++ b/apps/files_texteditor/ajax/savefile.php
@@ -21,7 +21,7 @@
  */
 
 // Init owncloud
-require_once('../../../lib/base.php');
+ 
 
 
 // Check if we are a user
diff --git a/apps/gallery/ajax/createAlbum.php b/apps/gallery/ajax/createAlbum.php
index 152f5834bcb4130d7f0f1db203c13f0aa521bbf0..ca02c3ae2093fe99d5982fd665da4680e0a62fa3 100644
--- a/apps/gallery/ajax/createAlbum.php
+++ b/apps/gallery/ajax/createAlbum.php
@@ -21,7 +21,7 @@
 * 
 */
 
-require_once('../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('gallery');
 
diff --git a/apps/gallery/ajax/galleryOp.php b/apps/gallery/ajax/galleryOp.php
index 1b3ad48f561046574d6f3c7ffadcf5580196a8c5..98cf71ec14f49c27a6fc64505ae0fa864034fa11 100644
--- a/apps/gallery/ajax/galleryOp.php
+++ b/apps/gallery/ajax/galleryOp.php
@@ -22,7 +22,7 @@
 */
 
 header('Content-type: text/html; charset=UTF-8') ;
-require_once('../../../lib/base.php');
+ 
 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('gallery');
diff --git a/apps/gallery/ajax/sharing.php b/apps/gallery/ajax/sharing.php
index fba85fa34ee8589336b45e172311d846aad3a866..ce56d652c6025746a246129edb6e1a53ed878389 100644
--- a/apps/gallery/ajax/sharing.php
+++ b/apps/gallery/ajax/sharing.php
@@ -21,7 +21,7 @@
 * 
 */
 
-require_once('../../../lib/base.php');
+ 
 
 if (!isset($_GET['token']) || !isset($_GET['operation'])) {
   OC_JSON::error(array('cause' => 'Not enought arguments'));
diff --git a/apps/gallery/ajax/thumbnail.php b/apps/gallery/ajax/thumbnail.php
index 184171f8fcadaad7eb5400aa575b6bf79fddd9bf..bf42fd2becb1d79af138481e01a14ad76ddde6f7 100644
--- a/apps/gallery/ajax/thumbnail.php
+++ b/apps/gallery/ajax/thumbnail.php
@@ -21,7 +21,7 @@
 * 
 */
 
-require_once('../../../lib/base.php');
+ 
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('gallery');
 
diff --git a/apps/gallery/css/sharing.css b/apps/gallery/css/sharing.css
index eaac82ebd605cf2a6429210640188fae42865ee1..d061fc3e6c1436db68dd7cbd0a18b06fa2ac2fc1 100644
--- a/apps/gallery/css/sharing.css
+++ b/apps/gallery/css/sharing.css
@@ -5,4 +5,4 @@ div.gallery_box:hover { color: black; }
 div.gallery_box h1 {font-size: 17px; font-weight: normal;}
 div#breadcrumb { border: 0; width: 70%; margin: 0 auto; padding: 25px 0; font-family: Verdana; text-align: center;}
 span.breadcrumbelement { margin: 10px; margin-right: 0; cursor: pointer;}
-span.inside { background-image: url('../img/breadcrumb.png'); padding-left: 20px; background-position: left; background-repeat: no-repeat;}
+span.inside { background-image: url('%appswebroot%/apps/gallery/img/breadcrumb.png'); padding-left: 20px; background-position: left; background-repeat: no-repeat;}
diff --git a/apps/gallery/index.php b/apps/gallery/index.php
index 7de7c0941429aa0c0f922a51f112aa3d2cda97a0..8c45cfb19fc9bf3d1bfefd83d3781e09a69383df 100644
--- a/apps/gallery/index.php
+++ b/apps/gallery/index.php
@@ -21,7 +21,7 @@
 * 
 */
 
-require_once('../../lib/base.php');
+
 
 OC_Util::checkLoggedIn();
 OC_Util::checkAppEnabled('gallery');
diff --git a/apps/gallery/lib/album.php b/apps/gallery/lib/album.php
index ef361a3791319e0661c1e44b11754e4843d11541..efc545f0205ccd208945f156a3a0782524c93a5d 100644
--- a/apps/gallery/lib/album.php
+++ b/apps/gallery/lib/album.php
@@ -92,7 +92,7 @@ class OC_Gallery_Album {
 	}
 
 	public static function changeThumbnailPath($oldname, $newname) {
-		require_once('../../../lib/base.php');
+		 
 		$thumbpath = OC::$CONFIG_DATADIRECTORY.'/../gallery/';
 		rename($thumbpath.$oldname.'.png', $thumbpath.$newname.'.png');
 	}
diff --git a/apps/gallery/lib/images_utils.php b/apps/gallery/lib/images_utils.php
index 126298913be10ce71e93ce5bfbdda8c2b8f70d71..6f3959a342d4701e6c7ff276ea1bbcf37d4adc70 100644
--- a/apps/gallery/lib/images_utils.php
+++ b/apps/gallery/lib/images_utils.php
@@ -22,7 +22,7 @@
 */
 
 if (file_exists('../../../lib/base.php'))
-  require_once('../../../lib/base.php');
+   
 elseif (file_exists('lib/base.php'))
   require_once('lib/base.php');
 
diff --git a/apps/gallery/sharing.php b/apps/gallery/sharing.php
index d7430becf4329b4c8c8efd87976f932520b0a7a1..2739f63d4e0599723e7eea0c7e6206a1c90e3fea 100644
--- a/apps/gallery/sharing.php
+++ b/apps/gallery/sharing.php
@@ -25,7 +25,7 @@ if (!isset($_GET['token']) || empty($_GET['token'])) {
   exit;
 }
 
-require_once('../../lib/base.php');
+
 
 OC_Util::checkAppEnabled('gallery');
 
diff --git a/apps/gallery/templates/index.php b/apps/gallery/templates/index.php
index cf654b68c0b9b7be54bfb3630e60061966220d56..43ba513186445c3f8da65dc793dd68a12651f1bc 100644
--- a/apps/gallery/templates/index.php
+++ b/apps/gallery/templates/index.php
@@ -24,7 +24,7 @@ $l = OC_L10N::get('gallery');
 		</div>
 	</div>
 	<div id="g-album-loading" class="crumb" style="display:none">
-		<img src="img/loading.gif">
+		<img src="<?php echo OC_Helper::linkto('gallery', 'img/loading.gif'); ?>">
 	</div>
 </div>
 <div id="gallery_list">
diff --git a/apps/inc.php b/apps/inc.php
new file mode 100644
index 0000000000000000000000000000000000000000..cbfab01417383f04658ccfa1baf68717e3f47f3d
--- /dev/null
+++ b/apps/inc.php
@@ -0,0 +1 @@
+<?php require_once('/Applications/MAMP/htdocs/owncloud/lib/base.php'); ?>
\ No newline at end of file
diff --git a/apps/media/ajax/api.php b/apps/media/ajax/api.php
index 9d9c14deb1705d02977e0b92d9f04a3314fba2ca..9c7b3efce759ef7320f26024d59f2f136b06d666 100644
--- a/apps/media/ajax/api.php
+++ b/apps/media/ajax/api.php
@@ -23,10 +23,9 @@
 
 header('Content-type: text/html; charset=UTF-8') ;
 
-require_once('../../../lib/base.php');
 OC_JSON::checkAppEnabled('media');
-require_once('../lib_collection.php');
-require_once('../lib_scanner.php');
+require_once(OC::$APPSROOT . '/apps/media/lib_collection.php');
+require_once(OC::$APPSROOT . '/apps/media/lib_scanner.php');
 
 error_reporting(E_ALL); //no script error reporting because of getID3
 
@@ -127,5 +126,4 @@ if($arguments['action']){
 			exit;
 	}
 }
-
-?>
+?>
\ No newline at end of file
diff --git a/apps/media/ajax/autoupdate.php b/apps/media/ajax/autoupdate.php
index a78b5e25dd1290f83b4d45506e1991130ae0b5ab..ea7c5006e7046bcde3349b594b9eaa0ef54f2311 100644
--- a/apps/media/ajax/autoupdate.php
+++ b/apps/media/ajax/autoupdate.php
@@ -27,7 +27,7 @@ header('Content-type: text/html; charset=UTF-8') ;
 $RUNTIME_NOAPPS=true;
 $RUNTIME_NOSETUPFS=true;
 
-require_once('../../../lib/base.php');
+ 
 OC_JSON::checkAppEnabled('media');
 
 $autoUpdate=(isset($_GET['autoupdate']) and $_GET['autoupdate']=='true');
diff --git a/apps/media/index.php b/apps/media/index.php
index 419d4ae0bde1bbc70ef0be4232201132236fc23f..cdb347628bf88f493d4d64f6c2dfb7185fb5dd82 100644
--- a/apps/media/index.php
+++ b/apps/media/index.php
@@ -22,14 +22,14 @@
 */
 
 
-require_once('../../lib/base.php');
+
 
 // Check if we are a user
 OC_Util::checkLoggedIn();
 OC_Util::checkAppEnabled('media');
 
-require_once('lib_collection.php');
-require_once('lib_scanner.php');
+require_once(OC::$APPSROOT . '/apps/media/lib_collection.php');
+require_once(OC::$APPSROOT . '/apps/media/lib_scanner.php');
 
 OC_Util::addScript('media','player');
 OC_Util::addScript('media','music');
diff --git a/apps/media/server/xml.server.php b/apps/media/server/xml.server.php
index cb9b68fc4224462444248e5e380c52c258492e6c..deb189fbedec5613bdef54c67b5e46944159b090 100644
--- a/apps/media/server/xml.server.php
+++ b/apps/media/server/xml.server.php
@@ -21,11 +21,11 @@
 * 
 */
 
+require_once('../../inc.php');
 
-require_once('../../../lib/base.php');
 OC_Util::checkAppEnabled('media');
-require_once('../lib_collection.php');
-require_once('../lib_ampache.php');
+ require_once(OC::$APPSROOT . '/apps/media/lib_collection.php');
+ require_once(OC::$APPSROOT . '/apps/media/lib_ampache.php');
 
 $arguments=$_POST;
 if(!isset($_POST['action']) and isset($_GET['action'])){
diff --git a/apps/media/tomahawk.php b/apps/media/tomahawk.php
index 6dd41233f12929f8c5deb6a67ae747e7a02ebe5c..019e80b0f24e30a855417ff6d2c6aa4f0fa52e52 100644
--- a/apps/media/tomahawk.php
+++ b/apps/media/tomahawk.php
@@ -22,10 +22,10 @@
 */
 
 $_POST=$_GET; //debug
+require_once('../inc.php');
 
-require_once('../../lib/base.php');
 OC_JSON::checkAppEnabled('media');
-require_once('lib_collection.php');
+require_once(OC::$APPSROOT . '/apps/media/lib_collection.php');
 
 $user=isset($_POST['user'])?$_POST['user']:'';
 $pass=isset($_POST['pass'])?$_POST['pass']:'';
diff --git a/apps/remoteStorage/WebDAV.php b/apps/remoteStorage/WebDAV.php
index cad465181a985488f5a70369f673e06c39b3988b..3522d1ed68349ac6552c18f7b9934b9a3567c745 100644
--- a/apps/remoteStorage/WebDAV.php
+++ b/apps/remoteStorage/WebDAV.php
@@ -29,7 +29,7 @@
 // Do not load FS ...
 $RUNTIME_NOSETUPFS = true;
 
-require_once('../../lib/base.php');
+
 OC_Util::checkAppEnabled('remoteStorage');
 require_once('Sabre/autoload.php');
 require_once('lib_remoteStorage.php');
diff --git a/apps/remoteStorage/ajax/revokeToken.php b/apps/remoteStorage/ajax/revokeToken.php
index ca56cf560ecdc868ee3f2e21a09d92673298b255..376fe29b3e7c66309f7e6e38277fee3a60f031f8 100644
--- a/apps/remoteStorage/ajax/revokeToken.php
+++ b/apps/remoteStorage/ajax/revokeToken.php
@@ -29,7 +29,7 @@
 // Do not load FS ...
 $RUNTIME_NOSETUPFS = true;
 
-require_once('../../../lib/base.php');
+ 
 OC_Util::checkAppEnabled('remoteStorage');
 require_once('Sabre/autoload.php');
 require_once('../lib_remoteStorage.php');
diff --git a/apps/remoteStorage/auth.php b/apps/remoteStorage/auth.php
index 2be648642a1e94b688b8a06f0a58a94a9dab661a..69d7cfc3b93516e5c99e56f8e5a8383b772ca9bd 100644
--- a/apps/remoteStorage/auth.php
+++ b/apps/remoteStorage/auth.php
@@ -29,7 +29,7 @@
 // Do not load FS ...
 $RUNTIME_NOSETUPFS = true;
 
-require_once('../../lib/base.php');
+
 OC_Util::checkAppEnabled('remoteStorage');
 require_once('Sabre/autoload.php');
 require_once('lib_remoteStorage.php');
diff --git a/apps/user_migrate/ajax/export.php b/apps/user_migrate/ajax/export.php
index 86745d6b1629efe2a8e9075a98370e988052bd70..99503cad142ce80523f271f9a87437bd3a67405d 100644
--- a/apps/user_migrate/ajax/export.php
+++ b/apps/user_migrate/ajax/export.php
@@ -21,7 +21,7 @@
  *
  */
 // Init owncloud
-require_once('../../../lib/base.php');
+ 
 
 // Check if we are a user
 OC_JSON::checkLoggedIn();
diff --git a/apps/user_webfinger/webfinger.php b/apps/user_webfinger/webfinger.php
index 9ada473ca875c7d35df18caab63da8020f96df95..51686111bf77709c5113afca0c45e406a0d71b7b 100644
--- a/apps/user_webfinger/webfinger.php
+++ b/apps/user_webfinger/webfinger.php
@@ -25,7 +25,7 @@ $SUBURI=substr(realpath($_SERVER["SCRIPT_FILENAME"]),strlen($SERVERROOT));
 $WEBROOT=substr($SUBURI,0,-34);
 */
 
-require_once('../../lib/base.php');
+
 $request = urldecode($_GET['q']);
 if($_GET['q']) {
 	$reqParts = explode('@', $request);
diff --git a/core/js/js.js b/core/js/js.js
index 019c40a0e1be0ce6b6f38f7ef8e050ec9611126f..12303d7dd91de1a7a3eafa3a18cdd7cc9b1015f5 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -31,8 +31,9 @@ t.cache={};
 
 OC={
 	webroot:oc_webroot,
+	appswebroot:oc_appswebroot,
 	currentUser:(typeof oc_current_user!=='undefined')?oc_current_user:false,
-	coreApps:['files','admin','log','search','settings','core','3rdparty'],
+	coreApps:['admin','log','search','settings','core','3rdparty'],
 	/**
 	 * get an absolute url to a file in an appen
 	 * @param app the id of the app the file belongs to
@@ -51,16 +52,34 @@ OC={
 	 */
 	filePath:function(app,type,file){
 		var isCore=OC.coreApps.indexOf(app)!=-1;
-		app+='/';
-		var link=OC.webroot+'/';
-		if(!isCore){
+		var link=OC.webroot;
+		if((file.substring(file.length-3) == 'php' || file.substring(file.length-3) == 'css') && !isCore){
+			link+='/?app=' + app + '&getfile=';
+			if(type){
+				link+=encodeURI(type + '/');
+			}
+			link+= file;
+		}else if(file.substring(file.length-3) != 'php' && !isCore){
+			link=OC.appswebroot;
+			link+='/';
 			link+='apps/';
+			link+=app+'/';
+			if(type){
+				link+=type+'/';
+			}
+			link+=file;
+		}else{
+			link+='/';
+			app+='/';
+			if(!isCore){
+				link+='apps/';
+			}
+			link+=app;
+			if(type){
+				link+=type+'/';
+			}
+			link+=file;	
 		}
-		link+=app;
-		if(type){
-			link+=type+'/';
-		}
-		link+=file;
 		return link;
 	},
 	/**
diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js
index a3aa1e8c149cb4313623491c7926633131a40590..6a3dac02ea7fb78a7ff4bc4467f4c82e8859113d 100644
--- a/core/js/oc-dialogs.js
+++ b/core/js/oc-dialogs.js
@@ -107,7 +107,7 @@ OCdialogs = {
     $(c_id + ' #dirtree').focus(function() { var t = $(this); t.data('oldval',  t.val())})
                          .change({dcid: c_id}, OC.dialogs.handleTreeListSelect);
     $(c_id).ready(function(){
-      $.getJSON(OC.webroot+'/files/ajax/rawlist.php', {mimetype: mimetype_filter} ,function(r){OC.dialogs.fillFilePicker(r, c_id, callback)});
+      $.getJSON(OC.filePath('files', 'ajax', 'rawlist.php'), {mimetype: mimetype_filter} ,function(r){OC.dialogs.fillFilePicker(r, c_id, callback)});
     }).data('multiselect', multiselect).data('mimetype',mimetype_filter);
     // build buttons
     var b = [
@@ -222,7 +222,7 @@ OCdialogs = {
     $(this).children().each(function(i, element) { if (skip_first) {skip_first = false; return; }path += '/'+$(element).text(); });
     $(event.data.dcid).data('path', path);
     $(event.data.dcid + ' .filepicker_loader').css('visibility', 'visible');
-    $.getJSON(OC.webroot+'/files/ajax/rawlist.php', {dir: path, mimetype: $(event.data.dcid).data('mimetype')}, function(r){OC.dialogs.fillFilePicker(r, event.data.dcid)});
+    $.getJSON(OC.filePath('files', 'ajax', 'rawlist.php'), {dir: path, mimetype: $(event.data.dcid).data('mimetype')}, function(r){OC.dialogs.fillFilePicker(r, event.data.dcid)});
   },
   // this function is in early development state, please dont use it unlsess you know what you are doing
   handlePickerClick:function(element, name, dcid) {
diff --git a/core/templates/layout.guest.php b/core/templates/layout.guest.php
index 2bd2e20df70852ee02fc0f563c77df894eaebbda..7ba7abdbf12238bc404a375eeb2ee8996a974fc2 100644
--- a/core/templates/layout.guest.php
+++ b/core/templates/layout.guest.php
@@ -9,6 +9,7 @@
 		<?php endforeach; ?>
 		<script type="text/javascript">
 			var oc_webroot = '<?php echo OC::$WEBROOT; ?>';
+			var oc_appswebroot = '<?php echo OC::$APPSWEBROOT; ?>';
 		</script>
 		<?php foreach($_['jsfiles'] as $jsfile): ?>
 			<script type="text/javascript" src="<?php echo $jsfile; ?>"></script>
diff --git a/core/templates/layout.user.php b/core/templates/layout.user.php
index 61eb0de9f421f36428a5001de7858069a5f829d1..df7897717f64f02898531c1fccbe5c3ec9508408 100644
--- a/core/templates/layout.user.php
+++ b/core/templates/layout.user.php
@@ -9,6 +9,7 @@
 		<?php endforeach; ?>
 		<script type="text/javascript">
 			var oc_webroot = '<?php echo OC::$WEBROOT; ?>';
+			var oc_appswebroot = '<?php echo OC::$APPSWEBROOT; ?>';
 			var oc_current_user = '<?php echo OC_User::getUser() ?>';
 		</script>
 		<?php foreach($_['jsfiles'] as $jsfile): ?>
diff --git a/files/webdav.php b/files/webdav.php
index 25e33024470d40881ef685643f444bb2880a8dda..3ed687041ca7785cbac8654854252ac1765ca807 100644
--- a/files/webdav.php
+++ b/files/webdav.php
@@ -25,11 +25,12 @@
 
 // Do not load FS ...
 $RUNTIME_NOSETUPFS = true;
+require_once('../lib/base.php');
 
 // only need filesystem apps
 $RUNTIME_APPTYPES=array('filesystem','authentication');
 
-require_once('../lib/base.php');
+ 
 
 // Backends
 $authBackend = new OC_Connector_Sabre_Auth();
diff --git a/index.php b/index.php
index 9fff459807e1641fc23d096ec11f7423419a18f3..fe8f7f15038e1f059765516852734500eb8fe1ed 100644
--- a/index.php
+++ b/index.php
@@ -50,14 +50,18 @@ if($_SERVER['REQUEST_METHOD']=='PROPFIND'){
 
 // Someone is logged in :
 elseif(OC_User::isLoggedIn()) {
+	OC_App::loadApps();
 	if(isset($_GET["logout"]) and ($_GET["logout"])) {
-		OC_App::loadApps();
 		OC_User::logout();
 		header("Location: ".OC::$WEBROOT.'/');
 		exit();
-	}
-	else {
-		OC_Util::redirectToDefaultPage();
+	}else{
+		if(is_null(OC::$REQUESTEDFILE)){
+			OC::loadapp();
+		}else{
+			OC::loadfile();
+		}
+		
 	}
 
 // For all others cases, we display the guest page :
diff --git a/lib/base.php b/lib/base.php
index a30f4e38c7802bb34be5bab05da8724d487fbaf9..1e28ea1ccfd54230f74110322434d683b4e22117 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -62,15 +62,22 @@ class OC{
 	 * the root path of the 3rdparty folder for http requests (e.g. owncloud/3rdparty)
 	 */
 	public static $THIRDPARTYWEBROOT = '';
-        /**
-         * The installation path of the apps folder on the server (e.g. /srv/http/owncloud)
-         */
-        public static $APPSROOT = '';
-        /**
-         * the root path of the apps folder for http requests (e.g. owncloud)
-         */
-        public static $APPSWEBROOT = '';
-
+	/**
+	 * The installation path of the apps folder on the server (e.g. /srv/http/owncloud)
+	 */
+	public static $APPSROOT = '';
+	/**
+	 * the root path of the apps folder for http requests (e.g. owncloud)
+	 */
+	public static $APPSWEBROOT = '';
+	/*
+	 * requested app
+	 */
+	public static $REQUESTEDAPP = '';
+	/*
+	 * requested file of app
+	 */
+	public static $REQUESTEDFILE = '';
 	/**
 	 * SPL autoload
 	 */
@@ -164,12 +171,15 @@ class OC{
 		}
 
 		// search the apps folder
-		if(file_exists(OC::$SERVERROOT.'/apps')){
+		if(OC_Config::getValue('appsroot', '')<>''){
+			OC::$APPSROOT=OC_Config::getValue('appsroot', '');
+			OC::$APPSWEBROOT=OC_Config::getValue('appsurl', '');
+		}elseif(file_exists(OC::$SERVERROOT.'/apps')){
 			OC::$APPSROOT=OC::$SERVERROOT;
 			OC::$APPSWEBROOT=OC::$WEBROOT;
 		}elseif(file_exists(OC::$SERVERROOT.'/../apps')){
-			OC::$APPSWEBROOT=rtrim(dirname(OC::$WEBROOT), '/');
 			OC::$APPSROOT=rtrim(dirname(OC::$SERVERROOT), '/');
+			OC::$APPSWEBROOT=rtrim(dirname(OC::$WEBROOT), '/');
 		}else{
 			echo("apps directory not found! Please put the ownCloud apps folder in the ownCloud folder or the folder above. You can also configure the location in the config.php file.");
 			exit;
@@ -264,6 +274,34 @@ class OC{
 		ini_set('session.cookie_httponly','1;');
 		session_start();
 	}
+	
+	public static function loadapp(){
+		if(file_exists(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/index.php')){
+			require_once(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/index.php');
+		}else{
+			trigger_error('The requested App was not found.', E_USER_ERROR);//load default app instead?
+		}
+	}
+	
+	public static function loadfile(){
+		if(file_exists(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE)){
+			if(substr(OC::$REQUESTEDFILE, -3) == 'css'){
+				$appswebroot = (string) OC::$APPSWEBROOT;
+				$webroot = (string) OC::$WEBROOT;
+				$cssfile = file_get_contents(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE);
+				$cssfile = str_replace('%appswebroot%', $appswebroot, $cssfile);
+				$cssfile = str_replace('%webroot%', $webroot, $cssfile);
+				header('Content-Type: text/css');
+				echo $cssfile;
+				exit;
+			}elseif(substr(OC::$REQUESTEDFILE, -3) == 'php'){
+				require_once(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE);
+			}	
+		}else{
+			header('HTTP/1.0 404 Not Found');
+			exit;
+		}
+	}
 
 	public static function init(){
 		// register autoloader
@@ -384,6 +422,30 @@ class OC{
 
 		//make sure temporary files are cleaned up
 		register_shutdown_function(array('OC_Helper','cleanTmp'));
+		
+		//parse the given parameters
+		self::$REQUESTEDAPP = (isset($_GET['app'])?strip_tags($_GET['app']):'files');
+		self::$REQUESTEDFILE = (isset($_GET['getfile'])?$_GET['getfile']:null);
+		if(substr_count(self::$REQUESTEDFILE, '?') != 0){
+			$file = substr(self::$REQUESTEDFILE, 0, strpos(self::$REQUESTEDFILE, '?'));
+			$param = substr(self::$REQUESTEDFILE, strpos(self::$REQUESTEDFILE, '?') + 1);
+			parse_str($param, $get);
+			$_GET = array_merge($_GET, $get);
+			self::$REQUESTEDFILE = $file;
+			$_GET['getfile'] = $file;
+		}
+		if(!is_null(self::$REQUESTEDFILE)){
+			$subdir = OC::$APPSROOT . '/' . self::$REQUESTEDAPP . '/' . self::$REQUESTEDFILE;
+			$parent = OC::$APPSROOT . '/' . self::$REQUESTEDAPP;
+			if(!OC_Helper::issubdirectory($subdir, $parent)){
+				self::$REQUESTEDFILE = null;
+				header('HTTP/1.0 404 Not Found');
+				exit;
+			}
+		}
+
+		//update path to lib base
+		@file_put_contents(OC::$APPSROOT . '/apps/inc.php', '<?php require_once(\'' . OC::$SERVERROOT . '/lib/base.php' . '\'); ?>');
 	}
 }
 
diff --git a/lib/helper.php b/lib/helper.php
index beb10280d935996781631c687950046a9dc06515..c5af76dbe525b5007ac663f87ed74fb55e68bbd1 100755
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -41,7 +41,15 @@ class OC_Helper {
 			$app .= '/';
 			// Check if the app is in the app folder
 			if( file_exists( OC::$APPSROOT . '/apps/'. $app.$file )){
-				$urlLinkTo =  OC::$APPSWEBROOT . '/apps/' . $app . $file;
+				if(substr($file, -3) == 'php' || substr($file, -3) == 'css'){	
+					if(substr($app, -1, 1) == '/'){
+						$app = substr($app, 0, strlen($app) - 1);
+					}
+					$urlLinkTo =  OC::$WEBROOT . '/?app=' . $app;
+					$urlLinkTo .= ($file!='index.php')?'&getfile=' . urlencode($file):'';
+				}else{
+					$urlLinkTo =  OC::$APPSWEBROOT . '/apps/' . $app . $file;
+				}
 			}
 			else{
 				$urlLinkTo =  OC::$WEBROOT . '/' . $app . $file;
@@ -543,4 +551,40 @@ class OC_Helper {
 
         return $newpath;
     }
+	
+	/*
+	 * checks if $sub is a subdirectory of $parent
+	 * 
+	 * @param $sub 
+	 * @param $parent
+	 * @return bool
+	 */
+	public static function issubdirectory($sub, $parent){
+		if($sub == null || $sub == '' || $parent == null || $parent == ''){
+			return false;
+		}
+		$realpath_sub = realpath($sub);
+		$realpath_parent = realpath($parent);
+		if(($realpath_sub == false && substr_count($realpath_sub, './') != 0) || ($realpath_parent == false && substr_count($realpath_parent, './') != 0)){ //it checks for  both ./ and ../
+			return false;
+		}
+		if($realpath_sub && $realpath_sub != '' && $realpath_parent && $realpath_parent != ''){
+			if(substr($realpath_sub, 0, strlen($realpath_parent)) == $realpath_parent){
+				return true;
+			}
+		}else{
+			if(substr($sub, 0, strlen($parent)) == $parent){
+				return true;
+			}
+		}
+		/*
+		echo 'SUB: ' . $sub . "\n";
+		echo 'PAR: ' . $parent . "\n";
+		echo 'REALSUB: ' . $realpath_sub . "\n";
+		echo 'REALPAR: ' . $realpath_parent . "\n";
+		echo substr($realpath_sub, 0, strlen($realpath_parent));
+		exit;
+		*/
+		return false;
+	}
 }
diff --git a/lib/template.php b/lib/template.php
index eeba2410b6880bec48cb594a3409b5b02f25e5d8..57e9c15f5e689a6c79ae0a6ed53f71e38ab6259a 100644
--- a/lib/template.php
+++ b/lib/template.php
@@ -323,7 +323,16 @@ class OC_Template{
 	 */
         public function appendIfExist($type, $root, $web, $file) {
                 if (is_file($root.'/'.$file)) {
-                        $this->append( $type, $web.'/'.$file);
+                		$pathes = explode('/', $file);
+                		if($type == 'cssfiles' && $root == OC::$APPSROOT && $pathes[0] == 'apps'){
+                				$app = $pathes[1];
+                				unset($pathes[0]);
+                				unset($pathes[1]);
+                				$path = implode('/', $pathes);
+                				$this->append( $type, OC_Helper::linkTo($app, $path));
+                		}else{
+                				$this->append( $type, $web.'/'.$file);
+                		}
                         return true;
                 }
                 return false;
diff --git a/lib/util.php b/lib/util.php
index 29d0691a63dbca3a59d138e0999a779f78808cda..b30b9dfd481ac07c1eec9dd1a14e35067303f453 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -301,7 +301,7 @@ class OC_Util {
 		if(isset($_REQUEST['redirect_url'])) {
 			header( 'Location: '.$_REQUEST['redirect_url']);
 		} else {
-			header( 'Location: '.OC::$WEBROOT.'/'.OC_Appconfig::getValue('core', 'defaultpage', 'files/index.php'));
+			header( 'Location: '.OC::$WEBROOT.'/'.OC_Appconfig::getValue('core', 'defaultpage', '?app=files'));
 		}
 		exit();
 	}