diff options
author | Jakob Sack <kde@jakobsack.de> | 2011-07-29 21:03:53 +0200 |
---|---|---|
committer | Jakob Sack <kde@jakobsack.de> | 2011-07-29 21:03:53 +0200 |
commit | 2ff8d7a8bc067901ecbc64599b86d1b325f5fe98 (patch) | |
tree | 7523d0e4bde9a9c691112a71e2b0fe4c6904c078 /lib/search | |
parent | 2bfad189e7e9c8ea78e4b5f78c9e779074dd991c (diff) | |
download | nextcloud-server-2ff8d7a8bc067901ecbc64599b86d1b325f5fe98.tar.gz nextcloud-server-2ff8d7a8bc067901ecbc64599b86d1b325f5fe98.zip |
One class per file!
Diffstat (limited to 'lib/search')
-rw-r--r-- | lib/search/provider.php | 16 | ||||
-rw-r--r-- | lib/search/provider/file.php | 16 | ||||
-rw-r--r-- | lib/search/result.php | 37 |
3 files changed, 69 insertions, 0 deletions
diff --git a/lib/search/provider.php b/lib/search/provider.php new file mode 100644 index 00000000000..f0e0ba85249 --- /dev/null +++ b/lib/search/provider.php @@ -0,0 +1,16 @@ +<?php +/** + * provides search functionalty + */ +abstract class OC_Search_Provider{ + public function __construct(){ + OC_SEARCH::registerProvider($this); + } + + /** + * search for $query + * @param string $query + * @return array An array of OC_Search_Result's + */ + abstract function search($query); +} diff --git a/lib/search/provider/file.php b/lib/search/provider/file.php new file mode 100644 index 00000000000..892c431e05a --- /dev/null +++ b/lib/search/provider/file.php @@ -0,0 +1,16 @@ +<?php + +class OC_Search_Provider_File extends OC_Search_Provider{ + function search($query){ + $files=OC_FILESYSTEM::search($query); + $results=array(); + foreach($files as $file){ + if(OC_FILESYSTEM::is_dir($file)){ + $results[]=new OC_Search_Result(basename($file),$file,OC_HELPER::linkTo( 'files', 'index.php?dir='.$file ),'Files'); + }else{ + $results[]=new OC_Search_Result(basename($file),$file,OC_HELPER::linkTo( 'files', 'download.php?file='.$file ),'Files'); + } + } + return $results; + } +} diff --git a/lib/search/result.php b/lib/search/result.php new file mode 100644 index 00000000000..80a6b494c5e --- /dev/null +++ b/lib/search/result.php @@ -0,0 +1,37 @@ +<?php +/** + * a result of a search + */ +class OC_Search_Result{ + 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; + } + } +} |