From 936c8ba1cc3b36fdc122276fc9a96de4a4003bd1 Mon Sep 17 00:00:00 2001
From: Georg Ehrke <dev@georgswebsite.de>
Date: Mon, 7 May 2012 15:39:17 +0200
Subject: [PATCH] improve remote.php and create public.php

---
 apps/calendar/appinfo/app.php      |  3 ++-
 apps/contacts/appinfo/app.php      |  2 +-
 apps/files/appinfo/app.php         |  2 +-
 apps/files_sharing/appinfo/app.php |  2 +-
 apps/files_sharing/js/share.js     |  2 +-
 core/js/js.js                      |  2 +-
 public.php                         | 10 ++++++++++
 remote.php                         |  6 +++---
 8 files changed, 20 insertions(+), 9 deletions(-)
 create mode 100644 public.php

diff --git a/apps/calendar/appinfo/app.php b/apps/calendar/appinfo/app.php
index 297d8e44b6..06fb925773 100755
--- a/apps/calendar/appinfo/app.php
+++ b/apps/calendar/appinfo/app.php
@@ -23,4 +23,5 @@ OCP\App::addNavigationEntry( array(
   'name' => $l->t('Calendar')));
 OCP\App::registerPersonal('calendar', 'settings');
 OC_Search::registerProvider('OC_Search_Provider_Calendar');
-OCP\CONFIG::setAppValue('core', 'caldav', '/apps/calendar/appinfo/remote.php');
\ No newline at end of file
+OCP\CONFIG::setAppValue('core', 'remote_caldav', '/apps/calendar/appinfo/remote.php');
+OCP\CONFIG::setAppValue('core', 'public_calendar', '/apps/calendar/appinfo/share.php');
\ No newline at end of file
diff --git a/apps/contacts/appinfo/app.php b/apps/contacts/appinfo/app.php
index 216e89d5c0..7e19673306 100755
--- a/apps/contacts/appinfo/app.php
+++ b/apps/contacts/appinfo/app.php
@@ -25,4 +25,4 @@ OCP\App::addNavigationEntry( array(
 OCP\App::registerPersonal('contacts','settings');
 OCP\Util::addscript('contacts', 'loader');
 OC_Search::registerProvider('OC_Search_Provider_Contacts');
-OCP\CONFIG::setAppValue('core', 'carddav', '/apps/contacts/appinfo/remote.php');
\ No newline at end of file
+OCP\CONFIG::setAppValue('core', 'remote_carddav', '/apps/contacts/appinfo/remote.php');
\ No newline at end of file
diff --git a/apps/files/appinfo/app.php b/apps/files/appinfo/app.php
index 2cc2d48602..e7358242dd 100755
--- a/apps/files/appinfo/app.php
+++ b/apps/files/appinfo/app.php
@@ -7,4 +7,4 @@ OCP\App::registerAdmin('files','admin');
 OCP\App::addNavigationEntry( array( "id" => "files_index", "order" => 0, "href" => OCP\Util::linkTo( "files", "index.php" ), "icon" => OCP\Util::imagePath( "core", "places/home.svg" ), "name" => $l->t("Files") ));
 
 OC_Search::registerProvider('OC_Search_Provider_File');
-OCP\CONFIG::setAppValue('core', 'webdav', '/apps/files/appinfo/remote.php');
\ No newline at end of file
+OCP\CONFIG::setAppValue('core', 'remote_webdav', '/apps/files/appinfo/remote.php');
\ No newline at end of file
diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php
index bd81a45cc5..b3b9776d29 100755
--- a/apps/files_sharing/appinfo/app.php
+++ b/apps/files_sharing/appinfo/app.php
@@ -17,5 +17,5 @@ if ($dir != '/Shared' || OCP\Config::getAppValue('files_sharing', 'resharing', '
 OCP\Util::addscript("3rdparty", "chosen/chosen.jquery.min");
 OCP\Util::addStyle( 'files_sharing', 'sharing' );
 OCP\Util::addStyle("3rdparty", "chosen/chosen");
-
+OCP\CONFIG::setAppValue('core', 'public_files', '/apps/files_sharing/get.php');
 ?>
diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js
index 7bfaa1f0c6..3dedde48c2 100644
--- a/apps/files_sharing/js/share.js
+++ b/apps/files_sharing/js/share.js
@@ -177,7 +177,7 @@ OC.Share={
 	},
 	showPrivateLink:function(item, token) {
 		$('#privateLinkCheckbox').attr('checked', true);
-		var link = parent.location.protocol+'//'+location.host+OC.linkTo('files_sharing','get.php')+'?token='+token;
+		var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service=files&token='+token;
 		if (token.indexOf('&path=') == -1) {
 			link += '&file=' + item;
 		} else {
diff --git a/core/js/js.js b/core/js/js.js
index 7585d4b09d..44255ed667 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -33,7 +33,7 @@ OC={
 	webroot:oc_webroot,
 	appswebroot:oc_appswebroot,
 	currentUser:(typeof oc_current_user!=='undefined')?oc_current_user:false,
-	coreApps:['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
diff --git a/public.php b/public.php
new file mode 100644
index 0000000000..27a75adec9
--- /dev/null
+++ b/public.php
@@ -0,0 +1,10 @@
+<?php
+$RUNTIME_NOSETUPFS = true;
+//$RUNTIME_NOAPPS = TRUE;
+require_once('lib/base.php');
+$file = OCP\CONFIG::getAppValue('core', 'public_' . strip_tags($_GET['service']));
+if(is_null($file)){
+	header('HTTP/1.0 404 Not Found');
+	exit;
+}
+require_once(OC::$APPSROOT . $file);
\ No newline at end of file
diff --git a/remote.php b/remote.php
index db2d1756f7..2a7ab167d0 100644
--- a/remote.php
+++ b/remote.php
@@ -7,10 +7,10 @@ if (!$pos = strpos($path_info, '/', 1)) {
 	$pos = strlen($path_info);
 }
 $service=substr($path_info, 1, $pos-1);
-$file = OCP\CONFIG::getAppValue('core', $service);
+$file = OCP\CONFIG::getAppValue('core', 'remote_' . $service);
 if(is_null($file)){
-	//header('HTTP/1.0 404 Not Found');
+	header('HTTP/1.0 404 Not Found');
 	exit;
 }
 $baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/';
-require_once(OC::$APPSROOT . $file);
+require_once(OC::$APPSROOT . $file);
\ No newline at end of file
-- 
GitLab