From 82a61e2e1a0f392759b69f7336213ff70a7bc877 Mon Sep 17 00:00:00 2001
From: Frank Karlitschek <frank@owncloud.org>
Date: Wed, 2 May 2012 15:54:34 +0200
Subject: [PATCH] port oc_preferences

---
 apps/calendar/ajax/changeview.php             |  2 +-
 apps/calendar/ajax/event/new.form.php         |  4 +--
 apps/calendar/ajax/settings/getfirstday.php   |  2 +-
 .../ajax/settings/gettimezonedetection.php    |  2 +-
 apps/calendar/ajax/settings/guesstimezone.php |  4 +--
 apps/calendar/ajax/settings/setfirstday.php   |  2 +-
 apps/calendar/ajax/settings/settimeformat.php |  2 +-
 apps/calendar/ajax/settings/settimezone.php   |  2 +-
 apps/calendar/ajax/settings/timeformat.php    |  2 +-
 .../ajax/settings/timezonedetection.php       |  4 +--
 apps/calendar/index.php                       | 14 ++++----
 apps/calendar/lib/app.php                     |  2 +-
 apps/calendar/lib/object.php                  |  2 +-
 apps/calendar/lib/search.php                  |  2 +-
 apps/calendar/settings.php                    |  2 +-
 apps/calendar/templates/calendar.php          |  8 ++---
 apps/contacts/lib/addressbook.php             |  6 ++--
 apps/contacts/templates/index.php             |  2 +-
 apps/files_sharing/ajax/email.php             |  2 +-
 apps/gallery/ajax/galleryOp.php               | 10 +++---
 apps/gallery/lib/album.php                    |  2 +-
 apps/gallery/lib/hooks_handlers.php           |  2 +-
 apps/gallery/lib/photo.php                    |  2 +-
 apps/gallery/lib/scanner.php                  |  2 +-
 apps/gallery/templates/index.php              |  2 +-
 apps/media/ajax/api.php                       |  4 +--
 apps/media/ajax/autoupdate.php                |  2 +-
 apps/user_ldap/user_ldap.php                  |  4 +--
 apps/user_openid/settings.php                 |  2 +-
 lib/public/config.php                         | 35 +++++++++++++++++++
 30 files changed, 84 insertions(+), 49 deletions(-)

diff --git a/apps/calendar/ajax/changeview.php b/apps/calendar/ajax/changeview.php
index f53eb288b79..a637e62aad1 100755
--- a/apps/calendar/ajax/changeview.php
+++ b/apps/calendar/ajax/changeview.php
@@ -17,6 +17,6 @@ switch($view){
 		OC_JSON::error(array('message'=>'unexspected parameter: ' . $view));
 		exit;
 }
-OC_Preferences::setValue(OCP\USER::getUser(), 'calendar', 'currentview', $view);
+OCP\Config::setUserValue(OCP\USER::getUser(), 'calendar', 'currentview', $view);
 OC_JSON::success();
 ?>
diff --git a/apps/calendar/ajax/event/new.form.php b/apps/calendar/ajax/event/new.form.php
index a2fa48edf8a..376149b57c3 100755
--- a/apps/calendar/ajax/event/new.form.php
+++ b/apps/calendar/ajax/event/new.form.php
@@ -22,12 +22,12 @@ $end = $_POST['end'];
 $allday = $_POST['allday'];
 
 if (!$end){
-	$duration = OC_Preferences::getValue( OCP\USER::getUser(), 'calendar', 'duration', '60');
+	$duration = OCP\Config::getUserValue( OCP\USER::getUser(), 'calendar', 'duration', '60');
 	$end = $start + ($duration * 60);
 }
 $start = new DateTime('@'.$start);
 $end = new DateTime('@'.$end);
-$timezone = OC_Preferences::getValue(OCP\USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
+$timezone = OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
 $start->setTimezone(new DateTimeZone($timezone));
 $end->setTimezone(new DateTimeZone($timezone));
 
diff --git a/apps/calendar/ajax/settings/getfirstday.php b/apps/calendar/ajax/settings/getfirstday.php
index 3fe89c5bc56..dfc8b304b69 100755
--- a/apps/calendar/ajax/settings/getfirstday.php
+++ b/apps/calendar/ajax/settings/getfirstday.php
@@ -7,6 +7,6 @@
  */
  
 OC_JSON::checkLoggedIn();
-$firstday = OC_Preferences::getValue( OCP\USER::getUser(), 'calendar', 'firstday', 'mo');
+$firstday = OCP\Config::getUserValue( OCP\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 a5a71670ca9..be01807bbb4 100755
--- a/apps/calendar/ajax/settings/gettimezonedetection.php
+++ b/apps/calendar/ajax/settings/gettimezonedetection.php
@@ -8,4 +8,4 @@
  
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
-OC_JSON::success(array('detection' => OC_Preferences::getValue(OCP\USER::getUser(), 'calendar', 'timezonedetection')));
\ No newline at end of file
+OC_JSON::success(array('detection' => OCP\Config::getUserValue(OCP\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 9b86c305e44..19aa778472d 100755
--- a/apps/calendar/ajax/settings/guesstimezone.php
+++ b/apps/calendar/ajax/settings/guesstimezone.php
@@ -17,11 +17,11 @@ $lng = $_GET['long'];
 
 $timezone =  OC_Geo::timezone($lat, $lng);
 
-if($timezone == OC_Preferences::getValue(OCP\USER::getUser(), 'calendar', 'timezone')){
+if($timezone == OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'timezone')){
 	OC_JSON::success();
 	exit;
 }
-OC_Preferences::setValue(OCP\USER::getUser(), 'calendar', 'timezone', $timezone);
+OCP\Config::setUserValue(OCP\USER::getUser(), 'calendar', 'timezone', $timezone);
 $message = array('message'=> $l->t('New Timezone:') . $timezone);
 OC_JSON::success($message);
 ?>
\ No newline at end of file
diff --git a/apps/calendar/ajax/settings/setfirstday.php b/apps/calendar/ajax/settings/setfirstday.php
index 232a51733ba..0c6ab695365 100755
--- a/apps/calendar/ajax/settings/setfirstday.php
+++ b/apps/calendar/ajax/settings/setfirstday.php
@@ -8,7 +8,7 @@
  
 OC_JSON::checkLoggedIn();
 if(isset($_POST["firstday"])){
-	OC_Preferences::setValue(OCP\USER::getUser(), 'calendar', 'firstday', $_POST["firstday"]);
+	OCP\Config::setUserValue(OCP\USER::getUser(), 'calendar', 'firstday', $_POST["firstday"]);
 	OC_JSON::success();
 }else{
 	OC_JSON::error();
diff --git a/apps/calendar/ajax/settings/settimeformat.php b/apps/calendar/ajax/settings/settimeformat.php
index 428cb4220a1..d648545d9ca 100755
--- a/apps/calendar/ajax/settings/settimeformat.php
+++ b/apps/calendar/ajax/settings/settimeformat.php
@@ -8,7 +8,7 @@
  
 OC_JSON::checkLoggedIn();
 if(isset($_POST["timeformat"])){
-	OC_Preferences::setValue(OCP\USER::getUser(), 'calendar', 'timeformat', $_POST["timeformat"]);
+	OCP\Config::setUserValue(OCP\USER::getUser(), 'calendar', 'timeformat', $_POST["timeformat"]);
 	OC_JSON::success();
 }else{
 	OC_JSON::error();
diff --git a/apps/calendar/ajax/settings/settimezone.php b/apps/calendar/ajax/settings/settimezone.php
index efc23c0f979..abe14bd0ec7 100755
--- a/apps/calendar/ajax/settings/settimezone.php
+++ b/apps/calendar/ajax/settings/settimezone.php
@@ -18,7 +18,7 @@ OC_JSON::checkAppEnabled('calendar');
 // Get data
 if( isset( $_POST['timezone'] ) ){
 	$timezone=$_POST['timezone'];
-	OC_Preferences::setValue( OCP\USER::getUser(), 'calendar', 'timezone', $timezone );
+	OCP\Config::setUserValue( OCP\USER::getUser(), 'calendar', 'timezone', $timezone );
 	OC_JSON::success(array('data' => array( 'message' => $l->t('Timezone changed') )));
 }else{
 	OC_JSON::error(array('data' => array( 'message' => $l->t('Invalid request') )));
diff --git a/apps/calendar/ajax/settings/timeformat.php b/apps/calendar/ajax/settings/timeformat.php
index cec09394815..dbcfcb29b42 100755
--- a/apps/calendar/ajax/settings/timeformat.php
+++ b/apps/calendar/ajax/settings/timeformat.php
@@ -7,6 +7,6 @@
  */
  
 OC_JSON::checkLoggedIn();
-$timeformat = OC_Preferences::getValue( OCP\USER::getUser(), 'calendar', 'timeformat', "24");
+$timeformat = OCP\Config::getUserValue( OCP\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 17bd740beea..8cb375183bb 100755
--- a/apps/calendar/ajax/settings/timezonedetection.php
+++ b/apps/calendar/ajax/settings/timezonedetection.php
@@ -10,9 +10,9 @@ OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('calendar');
 if(array_key_exists('timezonedetection', $_POST)){
 	if($_POST['timezonedetection'] == 'on'){
-		OC_Preferences::setValue(OCP\USER::getUser(), 'calendar', 'timezonedetection', 'true');
+		OCP\Config::setUserValue(OCP\USER::getUser(), 'calendar', 'timezonedetection', 'true');
 	}else{
-		OC_Preferences::setValue(OCP\USER::getUser(), 'calendar', 'timezonedetection', 'false');
+		OCP\Config::setUserValue(OCP\USER::getUser(), 'calendar', 'timezonedetection', 'false');
 	}
 	OC_JSON::success();
 }else{
diff --git a/apps/calendar/index.php b/apps/calendar/index.php
index 0a77bdbf2ba..dcc7e25e3ec 100755
--- a/apps/calendar/index.php
+++ b/apps/calendar/index.php
@@ -29,21 +29,21 @@ OC_Hook::emit('OC_Calendar', 'getSources', array('sources' => &$eventSources));
 $categories = OC_Calendar_App::getCategoryOptions();
 
 //Fix currentview for fullcalendar
-if(OC_Preferences::getValue(OCP\USER::getUser(), 'calendar', 'currentview', 'month') == "oneweekview"){
-	OC_Preferences::setValue(OCP\USER::getUser(), "calendar", "currentview", "agendaWeek");
+if(OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'currentview', 'month') == "oneweekview"){
+	OCP\Config::setUserValue(OCP\USER::getUser(), "calendar", "currentview", "agendaWeek");
 }
-if(OC_Preferences::getValue(OCP\USER::getUser(), 'calendar', 'currentview', 'month') == "onemonthview"){
-	OC_Preferences::setValue(OCP\USER::getUser(), "calendar", "currentview", "month");
+if(OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'currentview', 'month') == "onemonthview"){
+	OCP\Config::setUserValue(OCP\USER::getUser(), "calendar", "currentview", "month");
 }
-if(OC_Preferences::getValue(OCP\USER::getUser(), 'calendar', 'currentview', 'month') == "listview"){
-	OC_Preferences::setValue(OCP\USER::getUser(), "calendar", "currentview", "list");
+if(OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'currentview', 'month') == "listview"){
+	OCP\Config::setUserValue(OCP\USER::getUser(), "calendar", "currentview", "list");
 }
 
 OCP\Util::addscript('3rdparty/fullcalendar', 'fullcalendar');
 OCP\Util::addStyle('3rdparty/fullcalendar', 'fullcalendar');
 OCP\Util::addscript('3rdparty/timepicker', 'jquery.ui.timepicker');
 OCP\Util::addStyle('3rdparty/timepicker', 'jquery.ui.timepicker');
-if(OC_Preferences::getValue(OCP\USER::getUser(), "calendar", "timezone") == null || OC_Preferences::getValue(OCP\USER::getUser(), 'calendar', 'timezonedetection') == 'true'){
+if(OCP\Config::getUserValue(OCP\USER::getUser(), "calendar", "timezone") == null || OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'timezonedetection') == 'true'){
 	OCP\Util::addscript('calendar', 'geo');
 }
 OCP\Util::addscript('calendar', 'calendar');
diff --git a/apps/calendar/lib/app.php b/apps/calendar/lib/app.php
index 7a52bf08dc7..f3e9bea86a3 100755
--- a/apps/calendar/lib/app.php
+++ b/apps/calendar/lib/app.php
@@ -9,7 +9,7 @@
  * This class manages our app actions
  */
 OC_Calendar_App::$l10n = new OC_L10N('calendar');
-OC_Calendar_App::$tz = OC_Preferences::getValue(OCP\USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
+OC_Calendar_App::$tz = OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
 class OC_Calendar_App{
 	const CALENDAR = 'calendar';
 	const EVENT = 'event';
diff --git a/apps/calendar/lib/object.php b/apps/calendar/lib/object.php
index d8e9d5fb946..018bf5beff1 100755
--- a/apps/calendar/lib/object.php
+++ b/apps/calendar/lib/object.php
@@ -761,7 +761,7 @@ class OC_Calendar_Object{
 			$vevent->setDateTime('DTSTART', $start, Sabre_VObject_Property_DateTime::DATE);
 			$vevent->setDateTime('DTEND', $end, Sabre_VObject_Property_DateTime::DATE);
 		}else{
-			$timezone = OC_Preferences::getValue(OCP\USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
+			$timezone = OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
 			$timezone = new DateTimeZone($timezone);
 			$start = new DateTime($from.' '.$fromtime, $timezone);
 			$end = new DateTime($to.' '.$totime, $timezone);
diff --git a/apps/calendar/lib/search.php b/apps/calendar/lib/search.php
index 3291e505249..03516b3b70c 100755
--- a/apps/calendar/lib/search.php
+++ b/apps/calendar/lib/search.php
@@ -12,7 +12,7 @@ class OC_Search_Provider_Calendar extends OC_Search_Provider{
 		}else{
 			$searchquery[] = $query;
 		}
-		$user_timezone = OC_Preferences::getValue(OCP\USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
+		$user_timezone = OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
 		$l = new OC_l10n('calendar');
 		foreach($calendars as $calendar){
 			$objects = OC_Calendar_Object::all($calendar['id']);
diff --git a/apps/calendar/settings.php b/apps/calendar/settings.php
index d6195108a2d..981df9ffafd 100755
--- a/apps/calendar/settings.php
+++ b/apps/calendar/settings.php
@@ -7,7 +7,7 @@
  */
 
 $tmpl = new OC_Template( 'calendar', 'settings');
-$timezone=OC_Preferences::getValue(OCP\USER::getUser(),'calendar','timezone','');
+$timezone=OCP\Config::getUserValue(OCP\USER::getUser(),'calendar','timezone','');
 $tmpl->assign('timezone',$timezone);
 $tmpl->assign('timezones',DateTimeZone::listIdentifiers());
 
diff --git a/apps/calendar/templates/calendar.php b/apps/calendar/templates/calendar.php
index 4285dc0f833..7e767e36732 100755
--- a/apps/calendar/templates/calendar.php
+++ b/apps/calendar/templates/calendar.php
@@ -1,13 +1,13 @@
 				<script type='text/javascript'>
-				var defaultView = '<?php echo OC_Preferences::getValue(OCP\USER::getUser(), 'calendar', 'currentview', 'month') ?>';
+				var defaultView = '<?php echo OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'currentview', 'month') ?>';
 				var eventSources = <?php echo json_encode($_['eventSources']) ?>;
 				var categories = <?php echo json_encode($_['categories']); ?>;
 				var dayNames = <?php echo json_encode($l->tA(array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'))) ?>;
 				var dayNamesShort = <?php echo json_encode($l->tA(array('Sun.', 'Mon.', 'Tue.', 'Wed.', 'Thu.', 'Fri.', 'Sat.'))) ?>;
 				var monthNames = <?php echo json_encode($l->tA(array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'))) ?>;
 				var monthNamesShort = <?php echo json_encode($l->tA(array('Jan.', 'Feb.', 'Mar.', 'Apr.', 'May.', 'Jun.', 'Jul.', 'Aug.', 'Sep.', 'Oct.', 'Nov.', 'Dec.'))) ?>;
-				var agendatime = '<?php echo ((int) OC_Preferences::getValue(OCP\USER::getUser(), 'calendar', 'timeformat', '24') == 24 ? 'HH:mm' : 'hh:mm tt'); ?>{ - <?php echo ((int) OC_Preferences::getValue(OCP\USER::getUser(), 'calendar', 'timeformat', '24') == 24 ? 'HH:mm' : 'hh:mm tt'); ?>}';
-				var defaulttime = '<?php echo ((int) OC_Preferences::getValue(OCP\USER::getUser(), 'calendar', 'timeformat', '24') == 24 ? 'HH:mm' : 'hh:mm tt'); ?>';
+				var agendatime = '<?php echo ((int) OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'timeformat', '24') == 24 ? 'HH:mm' : 'hh:mm tt'); ?>{ - <?php echo ((int) OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'timeformat', '24') == 24 ? 'HH:mm' : 'hh:mm tt'); ?>}';
+				var defaulttime = '<?php echo ((int) OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'timeformat', '24') == 24 ? 'HH:mm' : 'hh:mm tt'); ?>';
 				var allDayText = '<?php echo addslashes($l->t('All day')) ?>';
 				var newcalendar = '<?php echo addslashes($l->t('New Calendar')) ?>';
 				var missing_field = '<?php echo addslashes($l->t('Missing fields')) ?>';
@@ -20,7 +20,7 @@
 				var missing_field_startsbeforeends = '<?php echo addslashes($l->t('The event ends before it starts')) ?>';
 				var missing_field_dberror = '<?php echo addslashes($l->t('There was a database fail')) ?>';
 				var totalurl = '<?php echo OCP\Util::linkToAbsolute('calendar', 'caldav.php'); ?>/calendars';
-				var firstDay = '<?php echo (OC_Preferences::getValue(OCP\USER::getUser(), 'calendar', 'firstday', 'mo') == 'mo' ? '1' : '0'); ?>';
+				var firstDay = '<?php echo (OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'firstday', 'mo') == 'mo' ? '1' : '0'); ?>';
 				$(document).ready(function() {
 				<?php
 				if(array_key_exists('showevent', $_)){
diff --git a/apps/contacts/lib/addressbook.php b/apps/contacts/lib/addressbook.php
index 6aed9590447..b4bcc20d3bb 100755
--- a/apps/contacts/lib/addressbook.php
+++ b/apps/contacts/lib/addressbook.php
@@ -168,7 +168,7 @@ class OC_Contacts_Addressbook{
 		if(is_null($uid)){
 			$uid = OCP\USER::getUser();
 		}
-		$prefbooks = OC_Preferences::getValue($uid,'contacts','openaddressbooks',null);
+		$prefbooks = OCP\Config::getUserValue($uid,'contacts','openaddressbooks',null);
 		if(!$prefbooks){
 			$addressbooks = OC_Contacts_Addressbook::all($uid);
 			if(count($addressbooks) == 0){
@@ -176,7 +176,7 @@ class OC_Contacts_Addressbook{
 				$addressbooks = OC_Contacts_Addressbook::all($uid);
 			}
 			$prefbooks = $addressbooks[0]['id'];
-			OC_Preferences::setValue($uid,'contacts','openaddressbooks',$prefbooks);
+			OCP\Config::setUserValue($uid,'contacts','openaddressbooks',$prefbooks);
 		}
 		return explode(';',$prefbooks);
 	}
@@ -235,7 +235,7 @@ class OC_Contacts_Addressbook{
 		$openaddressbooks = self::cleanArray($openaddressbooks, false);
 		sort($openaddressbooks, SORT_NUMERIC);
 		// FIXME: I alway end up with a ';' prepending when imploding the array..?
-		OC_Preferences::setValue(OCP\USER::getUser(),'contacts','openaddressbooks',implode(';', $openaddressbooks));
+		OCP\Config::setUserValue(OCP\USER::getUser(),'contacts','openaddressbooks',implode(';', $openaddressbooks));
 
 		return true;
 	}
diff --git a/apps/contacts/templates/index.php b/apps/contacts/templates/index.php
index aa3885c4523..ab797deb169 100755
--- a/apps/contacts/templates/index.php
+++ b/apps/contacts/templates/index.php
@@ -1,7 +1,7 @@
 <script type='text/javascript'>
 	var totalurl = '<?php echo OCP\Util::linkToAbsolute('contacts', 'carddav.php'); ?>/addressbooks';
 	var categories = <?php echo json_encode($_['categories']); ?>;
-	var lang = '<?php echo OC_Preferences::getValue(OCP\USER::getUser(), 'core', 'lang', 'en'); ?>';
+	var lang = '<?php echo OCP\Config::getUserValue(OCP\USER::getUser(), 'core', 'lang', 'en'); ?>';
 </script>
 <div id="leftcontent" class="leftcontent">
 	<ul id="contacts">
diff --git a/apps/files_sharing/ajax/email.php b/apps/files_sharing/ajax/email.php
index b74e163b841..84202a23f5c 100755
--- a/apps/files_sharing/ajax/email.php
+++ b/apps/files_sharing/ajax/email.php
@@ -6,7 +6,7 @@ $user = OCP\USER::getUser();
 $subject = $user + ' ' + 'shared a file with you';
 $link = $_POST['link'] + '&f=' + $_POST['f'];
 $text = $user + ' ' + 'shared the file' + ' ' + $_POST['f'] + ' ' + 'with you.' + ' ' + 'It is available for download here:' + ' ' + $link;
-$fromaddress = OC_Preferences::getValue($user, 'settings', 'email', 'sharing-noreply@'.$_SERVER['HTTP_HOST']);
+$fromaddress = OCP\Config::getUserValue($user, 'settings', 'email', 'sharing-noreply@'.$_SERVER['HTTP_HOST']);
 OC_Mail::send($_POST['toaddress'], $_POST['toaddress'], $subject, $text, $fromaddress, $user);
 
 ?>
\ No newline at end of file
diff --git a/apps/gallery/ajax/galleryOp.php b/apps/gallery/ajax/galleryOp.php
index aaf4a7d8658..75b18c6f7bf 100755
--- a/apps/gallery/ajax/galleryOp.php
+++ b/apps/gallery/ajax/galleryOp.php
@@ -74,18 +74,18 @@ function handleStoreSettings($root, $order) {
     return;
   }
 
-  $current_root = OC_Preferences::getValue(OCP\USER::getUser(),'gallery', 'root', '/');
+  $current_root = OCP\Config::getUserValue(OCP\USER::getUser(),'gallery', 'root', '/');
   $root = trim($root);
   $root = rtrim($root, '/').'/';
   $rescan = $current_root==$root?'no':'yes';
-  OC_Preferences::setValue(OCP\USER::getUser(), 'gallery', 'root', $root);
-  OC_Preferences::setValue(OCP\USER::getUser(), 'gallery', 'order', $order);
+  OCP\Config::setUserValue(OCP\USER::getUser(), 'gallery', 'root', $root);
+  OCP\Config::setUserValue(OCP\USER::getUser(), 'gallery', 'order', $order);
   OC_JSON::success(array('rescan' => $rescan));
 }
 
 function handleGetGallery($path) {
   $a = array();
-  $root = OC_Preferences::getValue(OCP\USER::getUser(),'gallery', 'root', '/');
+  $root = OCP\Config::getUserValue(OCP\USER::getUser(),'gallery', 'root', '/');
   $path = utf8_decode(rtrim($root.$path,'/'));
   if($path == '') $path = '/';
   $pathLen = strlen($path);
@@ -127,7 +127,7 @@ function handleGetGallery($path) {
 function handleShare($path, $share, $recursive) {
   $recursive = $recursive == 'true' ? 1 : 0;
   $owner = OCP\USER::getUser();
-  $root = OC_Preferences::getValue(OCP\USER::getUser(),'gallery', 'root', '/');
+  $root = OCP\Config::getUserValue(OCP\USER::getUser(),'gallery', 'root', '/');
   $path = utf8_decode(rtrim($root.$path,'/'));
   if($path == '') $path = '/';
   $r = OC_Gallery_Album::find($owner, null, $path);
diff --git a/apps/gallery/lib/album.php b/apps/gallery/lib/album.php
index 8775cd52e11..f58140c4999 100755
--- a/apps/gallery/lib/album.php
+++ b/apps/gallery/lib/album.php
@@ -79,7 +79,7 @@ class OC_Gallery_Album {
 			$sql .= ' AND parent_path = ?';
 			$args[] = $parent;
 		}
-    $order = OC_Preferences::getValue($owner, 'gallery', 'order', 'ASC');
+    $order = OCP\Config::getUserValue($owner, 'gallery', 'order', 'ASC');
 		$sql .= ' ORDER BY album_name ' . $order;
 
 		$stmt = OC_DB::prepare($sql);
diff --git a/apps/gallery/lib/hooks_handlers.php b/apps/gallery/lib/hooks_handlers.php
index 525afc4127e..678d3fe7531 100755
--- a/apps/gallery/lib/hooks_handlers.php
+++ b/apps/gallery/lib/hooks_handlers.php
@@ -59,7 +59,7 @@ class OC_Gallery_Hooks_Handlers {
   }
 
   public static function pathInRoot($path) {
-    $root = OC_Preferences::getValue(OCP\USER::getUser(), 'gallery', 'root', '/');
+    $root = OCP\Config::getUserValue(OCP\USER::getUser(), 'gallery', 'root', '/');
     return substr($path, 0, strlen($path)>strlen($root)?strlen($root):strlen($path)) == $root;
   }
 
diff --git a/apps/gallery/lib/photo.php b/apps/gallery/lib/photo.php
index 7885ce2bf56..010eb9ab91b 100755
--- a/apps/gallery/lib/photo.php
+++ b/apps/gallery/lib/photo.php
@@ -98,6 +98,6 @@ class OC_Gallery_Photo {
 	}
 
 	public static function getGalleryRoot() {
-		return OC_Preferences::getValue(OCP\USER::getUser(), 'gallery', 'root', '');
+		return OCP\Config::getUserValue(OCP\USER::getUser(), 'gallery', 'root', '');
 	}
 }
diff --git a/apps/gallery/lib/scanner.php b/apps/gallery/lib/scanner.php
index 11c7541a75f..7a137cb3f50 100755
--- a/apps/gallery/lib/scanner.php
+++ b/apps/gallery/lib/scanner.php
@@ -24,7 +24,7 @@
 class OC_Gallery_Scanner {
 
 	public static function getGalleryRoot() {
-		return OC_Preferences::getValue(OCP\USER::getUser(), 'gallery', 'root', '/');
+		return OCP\Config::getUserValue(OCP\USER::getUser(), 'gallery', 'root', '/');
 	}
 	public static function getScanningRoot() {
 		return OC_Filesystem::getRoot().self::getGalleryRoot();
diff --git a/apps/gallery/templates/index.php b/apps/gallery/templates/index.php
index c9a6fb15627..854e4480bcf 100755
--- a/apps/gallery/templates/index.php
+++ b/apps/gallery/templates/index.php
@@ -9,7 +9,7 @@ OCP\Util::addscript('files_imageviewer', 'jquery.fancybox-1.3.4.pack');
 OCP\Util::addStyle( 'files_imageviewer', 'jquery.fancybox-1.3.4' );
 $l = OC_L10N::get('gallery');
 ?>
-<script type="text/javascript">var gallery_scanning_root='<? echo OC_Preferences::getValue(OCP\USER::getUser(), 'gallery', 'root', '/'); ?>'; var gallery_default_order = '<? echo OC_Preferences::getValue(OCP\USER::getUser(), 'gallery', 'order', 'ASC'); ?>';</script>
+<script type="text/javascript">var gallery_scanning_root='<? echo OCP\Config::getUserValue(OCP\USER::getUser(), 'gallery', 'root', '/'); ?>'; var gallery_default_order = '<? echo OCP\Config::getUserValue(OCP\USER::getUser(), 'gallery', 'order', 'ASC'); ?>';</script>
 <div id="controls">
 	<div id="scan">
 		<div id="scanprogressbar"></div>
diff --git a/apps/media/ajax/api.php b/apps/media/ajax/api.php
index 3238ebcc679..d648e6fe975 100755
--- a/apps/media/ajax/api.php
+++ b/apps/media/ajax/api.php
@@ -54,10 +54,10 @@ if($arguments['action']){
 		case 'delete':
 			$path=$arguments['path'];
 			OC_MEDIA_COLLECTION::deleteSongByPath($path);
-			$paths=explode(PATH_SEPARATOR,OC_Preferences::getValue(OCP\USER::getUser(),'media','paths',''));
+			$paths=explode(PATH_SEPARATOR,OCP\Config::getUserValue(OCP\USER::getUser(),'media','paths',''));
 			if(array_search($path,$paths)!==false){
 				unset($paths[array_search($path,$paths)]);
-				OC_Preferences::setValue(OCP\USER::getUser(),'media','paths',implode(PATH_SEPARATOR,$paths));
+				OCP\Config::setUserValue(OCP\USER::getUser(),'media','paths',implode(PATH_SEPARATOR,$paths));
 			}
 		case 'get_collection':
 			$data=array();
diff --git a/apps/media/ajax/autoupdate.php b/apps/media/ajax/autoupdate.php
index 24a7e2463f0..1efbea3acef 100755
--- a/apps/media/ajax/autoupdate.php
+++ b/apps/media/ajax/autoupdate.php
@@ -32,7 +32,7 @@ OC_JSON::checkAppEnabled('media');
 
 $autoUpdate=(isset($_GET['autoupdate']) and $_GET['autoupdate']=='true');
 
-OC_Preferences::setValue(OCP\USER::getUser(),'media','autoupdate',(integer)$autoUpdate);
+OCP\Config::setUserValue(OCP\USER::getUser(),'media','autoupdate',(integer)$autoUpdate);
 
 OC_JSON::success(array('data' => $autoUpdate));
 ?>
diff --git a/apps/user_ldap/user_ldap.php b/apps/user_ldap/user_ldap.php
index 40cf1db67ce..1a37630aad4 100755
--- a/apps/user_ldap/user_ldap.php
+++ b/apps/user_ldap/user_ldap.php
@@ -87,7 +87,7 @@ class OC_USER_LDAP extends OC_User_Backend {
 			$quota = false;
 		}
 		$quota = $quota != -1 ? $quota : $this->ldap_quota_def;
-		OC_Preferences::setValue($uid, 'files', 'quota', OCP\Util::computerFileSize($quota));
+		OCP\Config::setUserValue($uid, 'files', 'quota', OCP\Util::computerFileSize($quota));
 	}
 
 	private function setEmail( $uid ) {
@@ -95,7 +95,7 @@ class OC_USER_LDAP extends OC_User_Backend {
 			return false;
 
 		$email = $this->ldap_dc[$this->ldap_email_attr][0];
-		OC_Preferences::setValue($uid, 'settings', 'email', $email);
+		OCP\Config::setUserValue($uid, 'settings', 'email', $email);
 	}
 
 	//Connect to LDAP and store the resource
diff --git a/apps/user_openid/settings.php b/apps/user_openid/settings.php
index 33a3f232a17..cdffab0bc25 100755
--- a/apps/user_openid/settings.php
+++ b/apps/user_openid/settings.php
@@ -1,7 +1,7 @@
 <?php
 
 $tmpl = new OC_Template( 'user_openid', 'settings');
-$identity=OC_Preferences::getValue(OCP\USER::getUser(),'user_openid','identity','');
+$identity=OCP\Config::getUserValue(OCP\USER::getUser(),'user_openid','identity','');
 $tmpl->assign('identity',$identity);
 
 OCP\Util::addscript('user_openid','settings');
diff --git a/lib/public/config.php b/lib/public/config.php
index cbc7d916cf4..5681f20e3b3 100644
--- a/lib/public/config.php
+++ b/lib/public/config.php
@@ -92,6 +92,41 @@ class Config {
 	}
 
 
+        /**
+         * @brief Gets the preference
+         * @param $user user
+         * @param $app app
+         * @param $key key
+         * @param $default = null, default value if the key does not exist
+         * @returns the value or $default
+         *
+         * This function gets a value from the prefernces table. If the key does
+         * not exist the default value will be returnes
+         */
+        public static function getUserValue( $user, $app, $key, $default = null ){
+		return(\OC_Preferences::getValue( $user, $app, $key, $default ));
+	}
+
+
+        /**
+         * @brief sets a value in the preferences
+         * @param $user user
+         * @param $app app
+         * @param $key key
+         * @param $value value
+         * @returns true/false
+         *
+         * Adds a value to the preferences. If the key did not exist before, it
+         * will be added automagically.
+         */
+        public static function setUserValue( $user, $app, $key, $value ){
+		return(\OC_Preferences::setValue(  $user, $app, $key, $value ));
+	}
+
+
+
+
+
 
 }
 
-- 
GitLab