aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJakob Sack <kde@jakobsack.de>2011-07-29 20:42:24 +0200
committerJakob Sack <kde@jakobsack.de>2011-07-29 20:42:24 +0200
commit2bfad189e7e9c8ea78e4b5f78c9e779074dd991c (patch)
tree697204517c95647e382a4723545ade3950420913 /lib
parente69079f9354464d21f31ae8b6d9e47988ba22fb4 (diff)
parentd12d08e2f3553b06df6371535f971c9f193bd388 (diff)
downloadnextcloud-server-2bfad189e7e9c8ea78e4b5f78c9e779074dd991c.tar.gz
nextcloud-server-2bfad189e7e9c8ea78e4b5f78c9e779074dd991c.zip
Merge branch 'master' of git://anongit.kde.org/owncloud into autoload
Conflicts: lib/base.php lib/filestorage.php
Diffstat (limited to 'lib')
-rw-r--r--lib/app.php48
-rw-r--r--lib/base.php3
-rw-r--r--lib/filestorage.php2
-rw-r--r--lib/filestorage/local.php59
-rwxr-xr-xlib/helper.php50
-rw-r--r--lib/log.php8
-rw-r--r--lib/ocs.php76
-rw-r--r--lib/setup.php1
-rw-r--r--lib/template.php23
-rw-r--r--lib/util.php3
10 files changed, 126 insertions, 147 deletions
diff --git a/lib/app.php b/lib/app.php
index 475015f6779..b6c2512e79a 100644
--- a/lib/app.php
+++ b/lib/app.php
@@ -158,7 +158,10 @@ class OC_APP{
* the navigation. Lower values come first.
*/
public static function addNavigationEntry( $data ){
- // TODO: write function
+ $data['active']=false;
+ if(!isset($data['icon'])){
+ $data['icon']='';
+ }
OC_APP::$navigation[] = $data;
return true;
}
@@ -184,6 +187,10 @@ class OC_APP{
* the navigation. Lower values come first.
*/
public static function addNavigationSubEntry( $parent, $data ){
+ $data['active']=false;
+ if(!isset($data['icon'])){
+ $data['icon']='';
+ }
if( !array_key_exists( $parent, self::$subnavigation )){
self::$subnavigation[$parent] = array();
}
@@ -310,33 +317,34 @@ class OC_APP{
/// Private foo
private static function addSubNavigation( $list ){
- $found = false;
- foreach( self::$subnavigation as $parent => $selection ){
- foreach( $selection as $subentry ){
- if( $subentry['id'] == self::$activeapp ){
+ if(isset(self::$subnavigation[self::$activeapp])){
+ $subNav=self::$subnavigation[self::$activeapp];
+ foreach( $list as &$naventry ){
+ if( $naventry['id'] == self::$activeapp ){
+ $naventry['active'] = true;
+ $naventry['subnavigation'] = $subNav;
+ }
+ }
+ }else{
+ foreach(self::$subnavigation as $parent=>$entries){
+ $activeParent=false;
+ foreach($entries as &$subNav){
+ $subNav['active']=$subNav['id'] == self::$activeapp;
+ if($subNav['active']){
+ $activeParent=true;
+ }
+ }
+ if($activeParent){
foreach( $list as &$naventry ){
if( $naventry['id'] == $parent ){
$naventry['active'] = true;
- $naventry['subnavigation'] = $selection;
- }
- else{
- $naventry['active'] = false;
+ $naventry['subnavigation'] = $entries;
}
- } unset( $naventry );
- $found = true;
+ }
}
}
}
- // Mark subentry as active
- foreach( $list as &$naventry ){
- if( $naventry['active'] ){
- foreach( $naventry['subnavigation'] as &$subnaventry ){
- $subnaventry['active'] = $subnaventry['id'] == self::$activeapp? true : false;
- } unset( $subnaventry );
- }
- } unset( $naventry );
-
return $list;
}
diff --git a/lib/base.php b/lib/base.php
index 0c0921ca8b1..4e1b9bd0064 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -110,6 +110,3 @@ OC_UTIL::addStyle( "styles" );
if(!$error and !$RUNTIME_NOAPPS ){
OC_APP::loadApps();
}
-
-
-?>
diff --git a/lib/filestorage.php b/lib/filestorage.php
index ada85f1a50d..ba1a4b295aa 100644
--- a/lib/filestorage.php
+++ b/lib/filestorage.php
@@ -58,5 +58,3 @@ class OC_FILESTORAGE{
public function search($query){}
public function getLocalFile($path){}// get a path to a local version of the file, whether the original file is local or remote
}
-
-?> \ No newline at end of file
diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php
index 81a00dd8f4d..fd3f043de3b 100644
--- a/lib/filestorage/local.php
+++ b/lib/filestorage/local.php
@@ -138,7 +138,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
} else if (function_exists("mime_content_type")) {
// use mime magic extension if available
$mime_type = mime_content_type($this->datadir.$fspath);
- } else if (self::canExecute("file")) {
+ } else if (OC_HELPER::canExecute("file")) {
// it looks like we have a 'file' command,
// lets see it it does have mime support
$fp = popen("file -i -b '{$this->datadir}$fspath' 2>/dev/null", "r");
@@ -161,62 +161,6 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
}
}
- /**
- * detect if a given program is found in the search PATH
- *
- * helper function used by _mimetype() to detect if the
- * external 'file' utility is available
- *
- * @param string program name
- * @param string optional search path, defaults to $PATH
- * @return bool true if executable program found in path
- */
- private function canExecute($name, $path = false)
- {
- // path defaults to PATH from environment if not set
- if ($path === false) {
- $path = getenv("PATH");
- }
-
- // check method depends on operating system
- if (!strncmp(PHP_OS, "WIN", 3)) {
- // on Windows an appropriate COM or EXE file needs to exist
- $exts = array(".exe", ".com");
- $check_fn = "file_exists";
- } else {
- // anywhere else we look for an executable file of that name
- $exts = array("");
- $check_fn = "is_executable";
- }
-
- // Default check will be done with $path directories :
- $dirs = explode(PATH_SEPARATOR, $path);
-
- // WARNING : We have to check if open_basedir is enabled :
- $obd = ini_get('open_basedir');
-
- if($obd != "none")
- $obd_values = explode(PATH_SEPARATOR, $obd);
-
- if(count($obd_values) > 0)
- {
- // open_basedir is in effect !
- // We need to check if the program is in one of these dirs :
- $dirs = $obd_values;
- }
-
- foreach($dirs as $dir)
- {
- foreach($exts as $ext)
- {
- if($check_fn("$dir/$name".$ext))
- return true;
- }
- }
-
- return false;
- }
-
public function toTmpFile($path){
$tmpFolder=sys_get_temp_dir();
$filename=tempnam($tmpFolder,'OC_TEMP_FILE_'.substr($path,strrpos($path,'.')));
@@ -411,4 +355,3 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
}
}
}
-
diff --git a/lib/helper.php b/lib/helper.php
index 96d5bfad826..ffb25877433 100755
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -110,6 +110,11 @@ class OC_HELPER {
if( file_exists( "$SERVERROOT/core/img/mimetypes/$mimetype.png" )){
return "$WEBROOT/core/img/mimetypes/$mimetype.png";
}
+ //try only the first part of the mimetype
+ $mimetype=substr($mimetype,0,strpos($mimetype,'-'));
+ if( file_exists( "$SERVERROOT/core/img/mimetypes/$mimetype.png" )){
+ return "$WEBROOT/core/img/mimetypes/$mimetype.png";
+ }
else{
return "$WEBROOT/core/img/mimetypes/file.png";
}
@@ -267,6 +272,51 @@ class OC_HELPER {
if((isset($_REQUEST[$s]) && $_REQUEST[$s]==$v) || $v == $d)
print "checked=\"checked\" ";
}
+
+ /**
+ * detect if a given program is found in the search PATH
+ *
+ * @param string program name
+ * @param string optional search path, defaults to $PATH
+ * @return bool true if executable program found in path
+ */
+ public static function canExecute($name, $path = false){
+ // path defaults to PATH from environment if not set
+ if ($path === false) {
+ $path = getenv("PATH");
+ }
+ // check method depends on operating system
+ if (!strncmp(PHP_OS, "WIN", 3)) {
+ // on Windows an appropriate COM or EXE file needs to exist
+ $exts = array(".exe", ".com");
+ $check_fn = "file_exists";
+ } else {
+ // anywhere else we look for an executable file of that name
+ $exts = array("");
+ $check_fn = "is_executable";
+ }
+ // Default check will be done with $path directories :
+ $dirs = explode(PATH_SEPARATOR, $path);
+ // WARNING : We have to check if open_basedir is enabled :
+ $obd = ini_get('open_basedir');
+ if($obd != "none")
+ $obd_values = explode(PATH_SEPARATOR, $obd);
+ if(count($obd_values) > 0 and $obd_values[0])
+ {
+ // open_basedir is in effect !
+ // We need to check if the program is in one of these dirs :
+ $dirs = $obd_values;
+ }
+ foreach($dirs as $dir)
+ {
+ foreach($exts as $ext)
+ {
+ if($check_fn("$dir/$name".$ext))
+ return true;
+ }
+ }
+ return false;
+ }
}
?>
diff --git a/lib/log.php b/lib/log.php
index 894575ef059..764c094c919 100644
--- a/lib/log.php
+++ b/lib/log.php
@@ -51,7 +51,7 @@ class OC_LOG {
* This function adds another entry to the log database
*/
public static function add( $appid, $subject, $predicate, $object = ' ' ){
- $query=OC_DB::prepare("INSERT INTO *PREFIX*log(moment,appid,user,action,info) VALUES(NOW(),?,?,?,?)");
+ $query=OC_DB::prepare("INSERT INTO `*PREFIX*log`(moment,appid,user,action,info) VALUES(NOW(),?,?,?,?)");
$result=$query->execute(array($appid,$subject,$predicate,$object));
// Die if we have an error
if( PEAR::isError($result)) {
@@ -79,7 +79,7 @@ class OC_LOG {
* - app: only entries for this app
*/
public static function get( $filter = array()){
- $queryString='SELECT * FROM *PREFIX*log WHERE 1=1 ORDER BY moment DESC';
+ $queryString='SELECT * FROM `*PREFIX*log` WHERE 1=1 ORDER BY moment DESC';
$params=array();
if(isset($filter['from'])){
$queryString.='AND moment>? ';
@@ -116,7 +116,7 @@ class OC_LOG {
* This function deletes all entries that are older than $date.
*/
public static function deleteBefore( $date ){
- $query=OC_DB::prepare("DELETE FROM *PREFIX*log WHERE moment<?");
+ $query=OC_DB::prepare("DELETE FROM `*PREFIX*log` WHERE moment<?");
$query->execute(array($date));
return true;
}
@@ -128,7 +128,7 @@ class OC_LOG {
* This function deletes all log entries.
*/
public static function deleteAll(){
- $query=OC_DB::prepare("DELETE FROM *PREFIX*log");
+ $query=OC_DB::prepare("DELETE FROM `*PREFIX*log`");
$query->execute();
return true;
}
diff --git a/lib/ocs.php b/lib/ocs.php
index 4e9e6522e8b..b1be2cb11cf 100644
--- a/lib/ocs.php
+++ b/lib/ocs.php
@@ -463,7 +463,6 @@ class OC_OCS {
$xml[$i]['key']=$log['key'];
$xml[$i]['app']=$log['app'];
$xml[$i]['value']=$log['value'];
- $xml[$i]['timestamp']=$log['timestamp'];
}
@@ -511,28 +510,26 @@ class OC_OCS {
* @param bool $like use LIKE instead of = when comparing keys
* @return array
*/
- public static function getData($user,$app="",$key="",$like=false) {
- $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':'=';
-
+ public static function getData($user,$app="",$key="") {
if($app){
- if (!trim($key)) {
- $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 {
- $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();
- }
+ $apps=array($app);
+ }else{
+ $apps=OC_PREFERENCES::getApps($user);
+ }
+ if($key){
+ $keys=array($key);
}else{
- if (!trim($key)) {
- $query = OC_DB::prepare('select app, `key`,value,`timestamp` from *PREFIX*privatedata order by `timestamp` desc');
- $result=$query->execute()->fetchAll();
- } else {
- $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();
+ foreach($apps as $app){
+ $keys=OC_PREFERENCES::getKeys($user,$app);
+ }
+ }
+ $result=array();
+ foreach($apps as $app){
+ foreach($keys as $key){
+ $value=OC_PREFERENCES::getValue($user,$app,$key);
+ $result[]=array('app'=>$app,'key'=>$key,'value'=>$value);
}
}
- $result=self::trimKeys($result,$user);
return $result;
}
@@ -545,25 +542,7 @@ class OC_OCS {
* @return bool
*/
public static function setData($user, $app, $key, $value) {
- $key="$user::$key";//ugly hack for the sake of keeping database scheme compatibiliy
- //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) {
- $query=OC_DB::prepare("update *PREFIX*privatedata set value=?, `timestamp` = now() where `key` = ? and app = ?");
-
- } else {
- $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);
- return false;
- }else{
- return true;
- }
+ return OC_PREFERENCES::setValue($user,$app,$key,$value);
}
/**
@@ -574,26 +553,7 @@ class OC_OCS {
* @return string xml/json
*/
public static function deleteData($user, $app, $key) {
- $key="$user::$key";//ugly hack for the sake of keeping database scheme compatibiliy
- //TODO: prepared statements, locking tables, fancy stuff, error checking/handling
- $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);
- return false;
- }else{
- return true;
- }
- }
-
- //trim username prefixes from $array
- private static function trimKeys($array,$user){
- $length=strlen("$user::");
- foreach($array as &$item){
- $item['key']=substr($item['key'],$length);
- }
- return $array;
+ return OC_PREFERENCES::deleteKey($user,$app,$key);
}
}
diff --git a/lib/setup.php b/lib/setup.php
index 63ba4daab54..f9bc6fd1bdd 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -76,6 +76,7 @@ class OC_SETUP {
//write the config file
OC_CONFIG::setValue('datadirectory', $datadir);
OC_CONFIG::setValue('dbtype', $dbtype);
+ OC_CONFIG::setValue('version',implode('.',OC_UTIL::getVersion()));
if($dbtype == 'mysql') {
$dbuser = $options['dbuser'];
$dbpass = $options['dbpass'];
diff --git a/lib/template.php b/lib/template.php
index 3c0cdf7e161..99099d49d0f 100644
--- a/lib/template.php
+++ b/lib/template.php
@@ -75,6 +75,29 @@ function simple_file_size($bytes) {
else { return number_format($mbytes, 1); }
}
+function relative_modified_date($timestamp) {
+ $timediff = time() - $timestamp;
+ $diffminutes = round($timediff/60);
+ $diffhours = round($diffminutes/60);
+ $diffdays = round($diffhours/24);
+ $diffmonths = round($diffdays/31);
+ $diffyears = round($diffdays/365);
+ if($timediff < 60) { return 'seconds ago'; }
+ else if($timediff < 120) { return '1 minute ago'; }
+ else if($timediff < 3600) { return $diffminutes.' minutes ago'; }
+ //else if($timediff < 7200) { return '1 hour ago'; }
+ //else if($timediff < 86400) { return $diffhours.' hours ago'; }
+ else if($timediff < 86400) { return 'today'; }
+ else if($timediff < 172800) { return 'yesterday'; }
+ else if($timediff < 2678400) { return $diffdays.' days ago'; }
+ else if($timediff < 5184000) { return 'last month'; }
+ //else if($timediff < 31556926) { return $diffmonths.' months ago'; }
+ else if($timediff < 31556926) { return 'months ago'; }
+ else if($timediff < 63113852) { return 'last year'; }
+ else { return $diffyears.' years ago'; }
+}
+
+
/**
* This class provides the templates for owncloud.
*/
diff --git a/lib/util.php b/lib/util.php
index 8beb4a884bc..2a50114b053 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -82,7 +82,7 @@ class OC_UTIL {
* @return array
*/
public static function getVersion(){
- return array(1,60,0);
+ return array(1,90,0);
}
/**
@@ -242,4 +242,3 @@ class OC_UTIL {
return $errors;
}
}
-