diff options
author | Michael Gapczynski <GapczynskiM@gmail.com> | 2011-07-29 10:23:15 -0400 |
---|---|---|
committer | Michael Gapczynski <GapczynskiM@gmail.com> | 2011-07-29 10:23:15 -0400 |
commit | fcc9f506417647a5b38f3ae9398730f064177e27 (patch) | |
tree | 658f61214f712cdea354ce4f41b8260423df8c55 /lib | |
parent | 67fe835f035e49783ba889010a005f40ed4c807d (diff) | |
parent | 46400a8124240679b7be4ae50ee932be31b18e2e (diff) | |
download | nextcloud-server-fcc9f506417647a5b38f3ae9398730f064177e27.tar.gz nextcloud-server-fcc9f506417647a5b38f3ae9398730f064177e27.zip |
Merge branch 'master' into sharing
Conflicts:
files/templates/index.php
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 2 | ||||
-rw-r--r-- | lib/filestorage.php | 58 | ||||
-rwxr-xr-x | lib/helper.php | 50 | ||||
-rw-r--r-- | lib/log.php | 8 | ||||
-rw-r--r-- | lib/ocs.php | 76 | ||||
-rw-r--r-- | lib/setup.php | 1 | ||||
-rw-r--r-- | lib/template.php | 23 |
7 files changed, 98 insertions, 120 deletions
diff --git a/lib/base.php b/lib/base.php index 56706b8f884..d81479e5a28 100644 --- a/lib/base.php +++ b/lib/base.php @@ -204,7 +204,7 @@ class OC_UTIL { * @return array */ public static function getVersion(){ - return array(1,60,0); + return array(1,90,0); } /** diff --git a/lib/filestorage.php b/lib/filestorage.php index 95e8c31eff2..601cf6f37fe 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -200,7 +200,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"); @@ -223,62 +223,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,'.'))); 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. */ |