diff options
author | Robin Appelman <icewind1991@gmail.com> | 2011-04-28 23:59:02 +0200 |
---|---|---|
committer | Robin Appelman <icewind1991@gmail.com> | 2011-04-28 23:59:02 +0200 |
commit | 5d358bb63ff5a93dd85c8045612d83ad52090da3 (patch) | |
tree | 10dd4067a231543364c7bd20b5cd63bdbffca0f2 /lib | |
parent | 8a6edd46541b47c4989c8666539b2c1ce2401c16 (diff) | |
parent | 96cb5a3d2e88c7ddab23aa799526d8ab687477c8 (diff) | |
download | nextcloud-server-5d358bb63ff5a93dd85c8045612d83ad52090da3.tar.gz nextcloud-server-5d358bb63ff5a93dd85c8045612d83ad52090da3.zip |
merge
Diffstat (limited to 'lib')
-rw-r--r-- | lib/HTTP/WebDAV/Server/Filesystem.php | 14 | ||||
-rw-r--r-- | lib/appconfig.php | 10 | ||||
-rw-r--r-- | lib/base.php | 37 | ||||
-rw-r--r-- | lib/database.php | 20 | ||||
-rw-r--r-- | lib/filestorage.php | 21 | ||||
-rw-r--r-- | lib/filesystem.php | 27 | ||||
-rw-r--r-- | lib/helper.php | 10 | ||||
-rw-r--r-- | lib/installer.php | 2 | ||||
-rw-r--r-- | lib/log.php | 60 | ||||
-rw-r--r-- | lib/search.php | 121 | ||||
-rw-r--r-- | lib/template.php | 19 |
11 files changed, 291 insertions, 50 deletions
diff --git a/lib/HTTP/WebDAV/Server/Filesystem.php b/lib/HTTP/WebDAV/Server/Filesystem.php index 49b2397175a..9cebee48d7c 100644 --- a/lib/HTTP/WebDAV/Server/Filesystem.php +++ b/lib/HTTP/WebDAV/Server/Filesystem.php @@ -297,12 +297,16 @@ while ($filename = readdir($handle)) { if ($filename != "." && $filename != "..") { - $fullpath = $fspath."/".$filename; + if( substr($fspath, -1) != '/' ){ + $fspath .= '/'; + } + $fullpath = $fspath.$filename; $name = htmlspecialchars($filename); + $uri = $_SERVER['SCRIPT_NAME'] . $fullpath; printf($format, - number_format(filesize($fullpath)), - strftime("%Y-%m-%d %H:%M:%S", filemtime($fullpath)), - "<a href='$name'>$name</a>"); + number_format(OC_FILESYSTEM::filesize($fullpath)), + strftime("%Y-%m-%d %H:%M:%S", OC_FILESYSTEM::filemtime($fullpath)), + "<a href='$uri'>$name</a>"); } } @@ -745,4 +749,4 @@ VALUES (?,?,?,?,?,'timeout',?,?)"); } } -?>
\ No newline at end of file +?> diff --git a/lib/appconfig.php b/lib/appconfig.php index df338a412db..f7c49ca19cc 100644 --- a/lib/appconfig.php +++ b/lib/appconfig.php @@ -47,7 +47,7 @@ class OC_APPCONFIG{ */ public static function getApps(){ // No magic in here! - $query = OC_DB::prepare( 'SELECT DISTINCT( `appid` ) FROM `*PREFIX*appconfig`' ); + $query = OC_DB::prepare( 'SELECT DISTINCT( appid ) FROM `*PREFIX*appconfig`' ); $result = $query->execute(); $apps = array(); @@ -68,7 +68,7 @@ class OC_APPCONFIG{ */ public static function getKeys( $app ){ // No magic in here as well - $query = OC_DB::prepare( 'SELECT `key` FROM `*PREFIX*appconfig` WHERE `appid` = ?' ); + $query = OC_DB::prepare( 'SELECT key FROM `*PREFIX*appconfig` WHERE `appid` = ?' ); $result = $query->execute( array( $app )); $keys = array(); @@ -91,7 +91,7 @@ class OC_APPCONFIG{ */ public static function getValue( $app, $key, $default = null ){ // At least some magic in here :-) - $query = OC_DB::prepare( 'SELECT `value` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `key` = ?' ); + $query = OC_DB::prepare( 'SELECT value FROM *PREFIX*appconfig WHERE appid = ? AND key = ?' ); $result = $query->execute( array( $app, $key )); if( !$result->numRows()){ @@ -118,11 +118,11 @@ class OC_APPCONFIG{ // null: does not exist if( is_null( $exists )){ - $query = OC_DB::prepare( 'INSERT INTO `*PREFIX*appconfig` ( `appid`, `key`, `value` ) VALUES( ?, ?, ? )' ); + $query = OC_DB::prepare( 'INSERT INTO *PREFIX*appconfig ( `appid`, `key`, `value` ) VALUES( ?, ?, ? )' ); $query->execute( array( $app, $key, $value )); } else{ - $query = OC_DB::prepare( 'UPDATE `*PREFIX*appconfig` SET `value` = ? WHERE `appid` = ? AND `key` = ?' ); + $query = OC_DB::prepare( 'UPDATE *PREFIX*appconfig SET value = ? WHERE appid = ? AND key = ?' ); $query->execute( array( $value, $app, $key )); } } diff --git a/lib/base.php b/lib/base.php index 2ed232cff2c..4bc96ad88f6 100644 --- a/lib/base.php +++ b/lib/base.php @@ -88,6 +88,7 @@ require_once('ocsclient.php'); require_once('connect.php'); require_once('remotestorage.php'); require_once('plugin.php'); +require_once('search.php'); $error=(count(OC_UTIL::checkServer())>0); @@ -191,7 +192,7 @@ class OC_UTIL { * @return array */ public static function getVersion(){ - return array(1,2,0); + return array(1,60,0); } /** @@ -204,7 +205,11 @@ class OC_UTIL { $file = $application; $application = ""; } - self::$scripts[] = "$application/js/$file"; + if( !empty( $application )){ + self::$scripts[] = "$application/js/$file"; + }else{ + self::$scripts[] = "js/$file"; + } } /** @@ -217,7 +222,11 @@ class OC_UTIL { $file = $application; $application = ""; } - self::$styles[] = "$application/css/$file"; + if( !empty( $application )){ + self::$styles[] = "$application/css/$file"; + }else{ + self::$styles[] = "css/$file"; + } } /** @@ -236,9 +245,9 @@ class OC_UTIL { * @param int $pagecount * @param int $page * @param string $url - * @return html-string + * @return OC_TEMPLATE */ - public static function showPageNavi($pagecount,$page,$url) { + public static function getPageNavi($pagecount,$page,$url) { $pagelinkcount=8; if ($pagecount>1) { @@ -253,7 +262,7 @@ class OC_UTIL { $tmpl->assign('pagestart',$pagestart); $tmpl->assign('pagestop',$pagestop); $tmpl->assign('url',$url); - $tmpl->printPage(); + return $tmpl; } } @@ -293,20 +302,6 @@ class OC_UTIL { //check for correct file permissions if(!stristr(PHP_OS, 'WIN')){ - if($CONFIG_DBTYPE=='sqlite'){ - $file=$SERVERROOT.'/'.$CONFIG_DBNAME; - if(file_exists($file)){ - $prems=substr(decoct(fileperms($file)),-3); - if(substr($prems,2,1)!='0'){ - @chmod($file,0660); - clearstatcache(); - $prems=substr(decoct(fileperms($file)),-3); - if(substr($prems,2,1)!='0'){ - $errors[]=array('error'=>'SQLite database file ('.$file.') is readable from the web<br/>','hint'=>$permissionsHint); - } - } - } - } $prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3); if(substr($prems,-1)!='0'){ OC_HELPER::chmodr($CONFIG_DATADIRECTORY_ROOT,0770); @@ -398,7 +393,7 @@ class OC_HOOK{ } // Call all slots - foreach( $registered[$signalclass][$signalname] as $i ){ + foreach( self::$registered[$signalclass][$signalname] as $i ){ call_user_func( array( $i["class"], $i["name"] ), $params ); } diff --git a/lib/database.php b/lib/database.php index 97651ccf50a..728e7359040 100644 --- a/lib/database.php +++ b/lib/database.php @@ -43,8 +43,8 @@ class OC_DB { $CONFIG_DBUSER = OC_CONFIG::getValue( "dbuser", "" );; $CONFIG_DBPASSWORD = OC_CONFIG::getValue( "dbpassword", "" );; $CONFIG_DBTYPE = OC_CONFIG::getValue( "dbtype", "sqlite" );; - global $DOCUMENTROOT; global $SERVERROOT; + $datadir=OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" ); // do nothing if the connection already has been established if(!self::$DBConnection){ @@ -64,7 +64,7 @@ class OC_DB { // sqlite $dsn = array( 'phptype' => 'sqlite', - 'database' => "$SERVERROOT/$CONFIG_DBNAME", + 'database' => "$datadir/$CONFIG_DBNAME.db", 'mode' => '0644' ); } elseif( $CONFIG_DBTYPE == 'mysql' ){ @@ -256,9 +256,9 @@ class OC_DB { if( $definition instanceof MDB2_Schema_Error ){ die( $definition->getMessage().': '.$definition->getUserInfo()); } - if(OC_CONFIG::getValue('dbtype','sqlite')=='sqlite'){ - $definition['overwrite']=true;//always overwrite for sqlite - } +// if(OC_CONFIG::getValue('dbtype','sqlite')=='sqlite'){ +// $definition['overwrite']=true;//always overwrite for sqlite +// } $ret=self::$schema->createDatabase( $definition ); // Die in case something went wrong @@ -300,7 +300,13 @@ class OC_DB { // We need Database type and table prefix $CONFIG_DBTYPE = OC_CONFIG::getValue( "dbtype", "sqlite" ); $CONFIG_DBTABLEPREFIX = OC_CONFIG::getValue( "dbtableprefix", "oc_" ); - + + // differences is getting the current timestamp + if( $CONFIG_DBTYPE == 'sqlite' ){ + $query = str_replace( 'NOW()', "strftime('%s', 'now')", $query ); + $query = str_replace( 'now()', "strftime('%s', 'now')", $query ); + } + // differences in escaping of table names (` for mysql) // Problem: what if there is a ` in the value we want to insert? if( $CONFIG_DBTYPE == 'sqlite' ){ @@ -310,7 +316,7 @@ class OC_DB { $query = str_replace( '`', '"', $query ); } - // replace table names + // replace table name prefix $query = str_replace( '*PREFIX*', $CONFIG_DBTABLEPREFIX, $query ); return $query; diff --git a/lib/filestorage.php b/lib/filestorage.php index 3d0bdf4cc0e..429961b3d69 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -62,6 +62,7 @@ class OC_FILESTORAGE{ public function getTree($path){} public function hash($type,$path,$raw){} public function free_space($path){} + public function search($query){} } @@ -468,7 +469,25 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ public function free_space($path){ return disk_free_space($this->datadir.$path); } - + + public function search($query){ + return $this->searchInDir($query); + } + + private function searchInDir($query,$dir=''){ + $files=array(); + foreach (scandir($this->datadir.$dir) as $item) { + if ($item == '.' || $item == '..') continue; + if(strstr(strtolower($item),strtolower($query))!==false){ + $files[]=$dir.'/'.$item; + } + if(is_dir($this->datadir.$dir.'/'.$item)){ + $files=array_merge($files,$this->searchInDir($query,$dir.'/'.$item)); + } + } + return $files; + } + /** * @brief get the size of folder and it's content * @param string $path file path diff --git a/lib/filesystem.php b/lib/filesystem.php index ca4d1a2c474..2b5c3a56b6e 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -194,6 +194,18 @@ class OC_FILESYSTEM{ } return $foundMountPoint; } + /** + * return the path to a local version of the file + * we need this because we can't know if a file is stored local or not from outside the filestorage and for some purposes a local file is needed + * @param string path + * @return string + */ + static public function getLocalFile($path){ + $parent=substr($path,0,strrpos($path,'/')); + if(self::canRead($parent) and $storage=self::getStorage($path)){ + return $storage->getLocalFile(self::getInternalPath($path)); + } + } static public function mkdir($path){ $parent=substr($path,0,strrpos($path,'/')); @@ -445,5 +457,20 @@ class OC_FILESYSTEM{ return $storage->free_space($path); } } + + static public function search($query){ + $files=array(); + $fakeRootLength=strlen(self::$fakeRoot); + foreach(self::$storages as $mountpoint=>$storage){ + $results=$storage->search($query); + foreach($results as $result){ + $file=str_replace('//','/',$mountpoint.$result); + $file=substr($file,$fakeRootLength); + $files[]=$file; + } + } + return $files; + + } } ?> diff --git a/lib/helper.php b/lib/helper.php index c4352ca3344..009e961397b 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -63,7 +63,11 @@ class OC_HELPER { if( file_exists( "$SERVERROOT/apps/img/$app/$image" )){ return "$WEBROOT/apps/img/$app/$image"; } - return "$WEBROOT/$app/img/$image"; + if( !empty( $app )){ + return "$WEBROOT/$app/img/$image"; + }else{ + return "$WEBROOT/img/$image"; + } } /** @@ -162,7 +166,7 @@ class OC_HELPER { * * Makes 2048 to 2 kB. */ - function chmodr($path, $filemode) { + static function chmodr($path, $filemode) { if (!is_dir($path)) return chmod($path, $filemode); $dh = opendir($path); @@ -173,7 +177,7 @@ class OC_HELPER { return FALSE; elseif(!is_dir($fullpath) && !chmod($fullpath, $filemode)) return FALSE; - elseif(!chmodr($fullpath, $filemode)) + elseif(!self::chmodr($fullpath, $filemode)) return FALSE; } } diff --git a/lib/installer.php b/lib/installer.php index 1222a22e71c..0646ef8e0ea 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -136,7 +136,7 @@ class OC_INSTALLER{ global $SERVERROOT; global $WEBROOT; $content="ErrorDocument 404 /$WEBROOT/templates/404.php\n"; - file_put_contents($SERVERROOT.'/.htaccess',$content); + @file_put_contents($SERVERROOT.'/.htaccess',$content); //supress errors in case we don't have permissions for it $content="deny from all"; file_put_contents(OC_CONFIG::getValue('datadirectory',$SERVERROOT.'/data').'/.htaccess',$content); diff --git a/lib/log.php b/lib/log.php index 231ff7997b1..02ad8162d51 100644 --- a/lib/log.php +++ b/lib/log.php @@ -50,8 +50,16 @@ class OC_LOG { * * This function adds another entry to the log database */ - public static function add( $appid, $subject, $predicate, $object = null ){ - // TODO: write function + public static function add( $appid, $subject, $predicate, $object = ' ' ){ + $query=OC_DB::prepare("INSERT INTO *PREFIX*log(`timestamp`,appid,user,action,info) VALUES(NOW(),?,?,?,?)"); + $result=$query->execute(array($appid,$subject,$predicate,$object)); + // Die if we have an error + if( PEAR::isError($result)) { + $entry = 'DB Error: "'.$result->getMessage().'"<br />'; + $entry .= 'Offending command was: '.$query.'<br />'; + error_log( $entry ); + die( $entry ); + } return true; } @@ -71,8 +79,33 @@ class OC_LOG { * - app: only entries for this app */ public static function get( $filter = array()){ - // TODO: write function - return array(); + $queryString='SELECT * FROM *PREFIX*log WHERE 1=1 '; + $params=array(); + if(isset($filter['from'])){ + $queryString.='AND `timestamp`>? '; + array_push($params,$filter('from')); + } + if(isset($filter['until'])){ + $queryString.='AND `timestamp`<? '; + array_push($params,$filter('until')); + } + if(isset($filter['user'])){ + $queryString.='AND user=? '; + array_push($params,$filter('user')); + } + if(isset($filter['app'])){ + $queryString.='AND appid=? '; + array_push($params,$filter('app')); + } + $query=OC_DB::prepare($queryString); + $result=$query->execute($params)->fetchAll(); + if(count($result)>0 and is_numeric($result[0]['timestamp'])){ + foreach($result as &$row){ + $row['timestamp']=OC_UTIL::formatDate($row['timestamp']); + } + } + return $result; + } /** @@ -83,9 +116,26 @@ class OC_LOG { * This function deletes all entries that are older than $date. */ public static function deleteBefore( $date ){ - // TODO: write function + $query=OC_DB::prepare("DELETE FROM *PREFIX*log WHERE `timestamp`<?"); + $query->execute(array($date)); return true; } + + /** + * @brief filter an array of log entries on action + * @param array $logs the log entries to filter + * @param array $actions an array of actions to filter for + * @returns array + */ + public static function filterAction($logs,$actions){ + $filteredLogs=array(); + foreach($logs as $log){ + if(array_search($log['action'],$actions)!==false){ + $filteredLogs[]=$log; + } + } + return $filteredLogs; + } } diff --git a/lib/search.php b/lib/search.php new file mode 100644 index 00000000000..ef82e225f3d --- /dev/null +++ b/lib/search.php @@ -0,0 +1,121 @@ +<?php +/** + * ownCloud + * + * @author Frank Karlitschek + * @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/>. + * + */ + + +/** + * provides an interface to all search providers + */ +class OC_SEARCH{ + static private $providers=array(); + + /** + * register a new search provider to be used + * @param OC_SearchProvider $provider + */ + public static function registerProvider($provider){ + self::$providers[]=$provider; + } + + /** + * search all provider for $query + * @param string query + * @return array An array of OC_SearchResult's + */ + public static function search($query){ + $results=array(); + foreach(self::$providers as $provider){ + $results=array_merge($results,$provider->search($query)); + } + return $results; + } +} + +/** + * provides search functionalty + */ +abstract class OC_SearchProvider{ + public function __construct(){ + OC_SEARCH::registerProvider($this); + } + + /** + * search for $query + * @param string $query + * @return array An array of OC_SearchResult's + */ + abstract function search($query); +} + +/** + * a result of a search + */ +class OC_SearchResult{ + private $name; + private $text; + private $link; + private $type; + + /** + * create a new search result + * @param string $name short name for the result + * @param string $text some more information about the result + * @param string $link link for the result + * @param string $type the type of result as human readable string ('File', 'Music', etc) + */ + public function __construct($name,$text,$link,$type){ + $this->name=$name; + $this->text=$text; + $this->link=$link; + $this->type=$type; + } + + public function __get($name){ + switch($name){ + case 'name': + return $this->name; + case 'text': + return $this->text; + case 'link': + return $this->link; + case 'type': + return $this->type; + } + } +} + +class OC_FileSearchProvider extends OC_SearchProvider{ + function search($query){ + $files=OC_FILESYSTEM::search($query); + $results=array(); + foreach($files as $file){ + if(OC_FILESYSTEM::is_dir($file)){ + $results[]=new OC_SearchResult(basename($file),$file,OC_HELPER::linkTo( 'files', 'index.php?dir='.$file ),'Files'); + }else{ + $results[]=new OC_SearchResult(basename($file),$file,OC_HELPER::linkTo( 'files', 'download.php?file='.$file ),'Files'); + } + } + return $results; + } +} + +new OC_FileSearchProvider(); +?>
\ No newline at end of file diff --git a/lib/template.php b/lib/template.php index dd1943ae7f5..0d6776aa26d 100644 --- a/lib/template.php +++ b/lib/template.php @@ -181,6 +181,7 @@ class OC_TEMPLATE{ { // global Data we need global $WEBROOT; + global $SERVERROOT; $data = $this->_fetch(); if( $this->renderas ) @@ -189,6 +190,9 @@ class OC_TEMPLATE{ if( $this->renderas == "user" ) { $page = new OC_TEMPLATE( "core", "layout.user" ); + $search=new OC_TEMPLATE( 'core', 'part.searchbox'); + $search->assign('searchurl',OC_HELPER::linkTo( 'search', 'index.php' )); + $page->assign('searchbox', $search->fetchPage()); // Add menu data // Add navigation entry @@ -197,6 +201,9 @@ class OC_TEMPLATE{ elseif( $this->renderas == "admin" ) { $page = new OC_TEMPLATE( "core", "layout.admin" ); + $search=new OC_TEMPLATE( 'core', 'part.searchbox'); + $search->assign('searchurl',OC_HELPER::linkTo( 'search', 'index.php' )); + $page->assign('searchbox', $search->fetchPage()); // Add menu data if( OC_GROUP::inGroup( $_SESSION["user_id"], "admin" )){ $page->assign( "settingsnavigation", OC_APP::getSettingsNavigation()); @@ -211,10 +218,18 @@ class OC_TEMPLATE{ // Add the css and js files foreach(OC_UTIL::$scripts as $script){ - $page->append( "jsfiles", "$WEBROOT/$script.js" ); + if(is_file("$SERVERROOT/apps/$script.js" )){ + $page->append( "jsfiles", "$WEBROOT/apps/$script.js" ); + }else{ + $page->append( "jsfiles", "$WEBROOT/$script.js" ); + } } foreach(OC_UTIL::$styles as $style){ - $page->append( "cssfiles", "$WEBROOT/$style.css" ); + if(is_file("$SERVERROOT/apps/$style.css" )){ + $page->append( "cssfiles", "$WEBROOT/apps/$style.css" ); + }else{ + $page->append( "cssfiles", "$WEBROOT/$style.css" ); + } } // Add css files and js files |