summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJakob Sack <kde@jakobsack.de>2011-04-16 14:59:27 +0200
committerJakob Sack <kde@jakobsack.de>2011-04-16 14:59:27 +0200
commitb5f913a3fc66a3036fc7ea291d67a72f7a0ecd40 (patch)
tree7c4fe7e0ad5a9ce246ae334d03629229039bb3e8 /lib
parent4c74029489194bb007ccf5310381b9dde48aedb3 (diff)
parent5112295723a841da0baa47c5560a43a2cf999119 (diff)
downloadnextcloud-server-b5f913a3fc66a3036fc7ea291d67a72f7a0ecd40.tar.gz
nextcloud-server-b5f913a3fc66a3036fc7ea291d67a72f7a0ecd40.zip
Merge branch 'refactoring' of git://anongit.kde.org/owncloud into refactoring
Diffstat (limited to 'lib')
-rw-r--r--lib/helper.php12
-rw-r--r--lib/ocs.php53
-rw-r--r--lib/ocsclient.php54
3 files changed, 86 insertions, 33 deletions
diff --git a/lib/helper.php b/lib/helper.php
index c51629f21cb..4fff7c28fea 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -36,12 +36,16 @@ class OC_HELPER {
public static function linkTo( $app, $file ){
global $WEBROOT;
global $SERVERROOT;
-
+
+ if(!empty($app)) {
+ $app .= '/';
+ }
+
// Check if the app is in the app folder
- if( file_exists( "$SERVERROOT/apps/$app/$file" )){
- return "$WEBROOT/apps/$app/$file";
+ if( file_exists( $SERVERROOT . '/apps/'. $app . $file )){
+ return $WEBROOT . '/apps/' . $app . $file;
}
- return "$WEBROOT/$app/$file";
+ return $WEBROOT . '/' . $app . $file;
}
/**
diff --git a/lib/ocs.php b/lib/ocs.php
index 2b1e706462a..4e9e6522e8b 100644
--- a/lib/ocs.php
+++ b/lib/ocs.php
@@ -400,16 +400,16 @@ class OC_OCS {
* @return string xml/json
*/
private static function activityGet($format,$page,$pagesize) {
- global $CONFIG_DBTABLEPREFIX;
-
$user=OC_OCS::checkpassword();
-
- $result = OC_DB::query("select count(*) as co from {$CONFIG_DBTABLEPREFIX}log");
+
+ $query = OC_DB::prepare('select count(*) as co from *PREFIX*log');
+ $result = $query->execute();
$entry=$result->fetchRow();
$totalcount=$entry['co'];
- OC_DB::free_result($result);
-
- $result = OC_DB::select("select id,timestamp,user,type,message from {$CONFIG_DBTABLEPREFIX}log order by timestamp desc limit " . ($page*$pagesize) . ",$pagesize");
+
+ $query=OC_DB::prepare('select id,timestamp,user,type,message from *PREFIX*log order by timestamp desc limit ?,?');
+ $result = $query->execute(array(($page*$pagesize),$pagesize))->fetchAll();
+
$itemscount=count($result);
$url='http://'.substr($_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'],0,-11).'';
@@ -512,24 +512,24 @@ class OC_OCS {
* @return array
*/
public static function getData($user,$app="",$key="",$like=false) {
- global $CONFIG_DBTABLEPREFIX;
- $user=OC_DB::escape($user);
- $key=OC_DB::escape($key);
- $app=OC_DB::escape($app);
$key="$user::$key";//ugly hack for the sake of keeping database scheme compatibiliy, needs to be replaced with a seperate user field the next time we break db compatibiliy
$compareFunction=($like)?'LIKE':'=';
if($app){
if (!trim($key)) {
- $result = OC_DB::select("select app, `key`,value,`timestamp` from {$CONFIG_DBTABLEPREFIX}privatedata where app='$app' order by `timestamp` desc");
+ $query = OC_DB::prepare('select app, `key`,value,`timestamp` from *PREFIX*privatedata where app=? order by `timestamp` desc');
+ $result=$query->execute(array($app))->fetchAll();
} else {
- $result = OC_DB::select("select app, `key`,value,`timestamp` from {$CONFIG_DBTABLEPREFIX}privatedata where app='$app' and `key` $compareFunction '$key' order by `timestamp` desc");
+ $query = OC_DB::prepare("select app, `key`,value,`timestamp` from *PREFIX*privatedata where app=? and `key` $compareFunction ? order by `timestamp` desc");
+ $result=$query->execute(array($app,$key))->fetchAll();
}
}else{
if (!trim($key)) {
- $result = OC_DB::select("select app, `key`,value,`timestamp` from {$CONFIG_DBTABLEPREFIX}privatedata order by `timestamp` desc");
+ $query = OC_DB::prepare('select app, `key`,value,`timestamp` from *PREFIX*privatedata order by `timestamp` desc');
+ $result=$query->execute()->fetchAll();
} else {
- $result = OC_DB::select("select app, `key`,value,`timestamp` from {$CONFIG_DBTABLEPREFIX}privatedata where `key` $compareFunction '$key' order by `timestamp` desc");
+ $query = OC_DB::prepare("select app, `key`,value,`timestamp` from *PREFIX*privatedata where `key` $compareFunction ? order by `timestamp` desc");
+ $result=$query->execute(array($key))->fetchAll();
}
}
$result=self::trimKeys($result,$user);
@@ -545,20 +545,18 @@ class OC_OCS {
* @return bool
*/
public static function setData($user, $app, $key, $value) {
- global $CONFIG_DBTABLEPREFIX;
- $app=OC_DB::escape($app);
- $key=OC_DB::escape($key);
- $user=OC_DB::escape($user);
- $value=OC_DB::escape($value);
$key="$user::$key";//ugly hack for the sake of keeping database scheme compatibiliy
- //TODO: prepared statements, locking tables, fancy stuff, error checking/handling
- $result=OC_DB::select("select count(*) as co from {$CONFIG_DBTABLEPREFIX}privatedata where `key` = '$key' and app = '$app'");
+ //TODO: locking tables, fancy stuff, error checking/handling
+ $query=OC_DB::prepare("select count(*) as co from *PREFIX*privatedata where `key` = ? and app = ?");
+ $result=$query->execute(array($key,$app))->fetchAll();
$totalcount=$result[0]['co'];
if ($totalcount != 0) {
- $result = OC_DB::query("update {$CONFIG_DBTABLEPREFIX}privatedata set value='$value', `timestamp` = now() where `key` = '$key' and app = '$app'");
+ $query=OC_DB::prepare("update *PREFIX*privatedata set value=?, `timestamp` = now() where `key` = ? and app = ?");
+
} else {
- $result = OC_DB::query("insert into {$CONFIG_DBTABLEPREFIX}privatedata(app, `key`, value, `timestamp`) values('$app', '$key', '$value', now())");
+ $result = OC_DB::prepare("insert into *PREFIX*privatedata(value, `key`, app, `timestamp`) values(?, ?, ?, now())");
}
+ $result = $query->execute(array($value,$key,$app));
if (PEAR::isError($result)){
$entry='DB Error: "'.$result->getMessage().'"<br />';
error_log($entry);
@@ -576,13 +574,10 @@ class OC_OCS {
* @return string xml/json
*/
public static function deleteData($user, $app, $key) {
- global $CONFIG_DBTABLEPREFIX;
- $app=OC_DB::escape($app);
- $key=OC_DB::escape($key);
- $user=OC_DB::escape($user);
$key="$user::$key";//ugly hack for the sake of keeping database scheme compatibiliy
//TODO: prepared statements, locking tables, fancy stuff, error checking/handling
- $result = OC_DB::query("delete from {$CONFIG_DBTABLEPREFIX}privatedata where `key` = '$key' and app = '$app'");
+ $query=OC_DB::prepare("delete from *PREFIX*privatedata where `key` = ? and app = ?");
+ $result = $query->execute(array($key,$app));
if (PEAR::isError($result)){
$entry='DB Error: "'.$result->getMessage().'"<br />';
error_log($entry);
diff --git a/lib/ocsclient.php b/lib/ocsclient.php
new file mode 100644
index 00000000000..0546ef39897
--- /dev/null
+++ b/lib/ocsclient.php
@@ -0,0 +1,54 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Frank Karlitschek
+ * @author Jakob Sack
+ * @copyright 2010 Frank Karlitschek karlitschek@kde.org
+ *
+ * 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/>.
+ *
+ */
+
+/**
+ * This class provides an easy way for apps to store config values in the
+ * database.
+ */
+
+class OC_OCSCLIENT{
+
+ /**
+ * @brief Get all the categories from the OCS server
+ * @returns array with category ids
+ *
+ * This function returns a list of all the application categories on the OCS server
+ */
+ public static function getCategories(){
+
+ return true;
+ }
+
+ /**
+ * @brief Get all the applications from the OCS server
+ * @returns array with application data
+ *
+ * This function returns a list of all the applications on the OCS server
+ */
+ public static function getApplications(){
+
+ return true;
+ }
+
+}
+?>