summaryrefslogtreecommitdiffstats
path: root/lib/private/search
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-09-25 13:36:30 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2013-09-30 16:36:59 +0200
commit9c9dc276b7a1d2592c4fb0a887888632dc1f1e29 (patch)
treebbe3aed3e09c31c68806bdb8acffef70ba08f51c /lib/private/search
parenta711399e62d5a9f14d4b748efe4354ee37e61f13 (diff)
downloadnextcloud-server-9c9dc276b7a1d2592c4fb0a887888632dc1f1e29.tar.gz
nextcloud-server-9c9dc276b7a1d2592c4fb0a887888632dc1f1e29.zip
move the private namespace OC into lib/private - OCP will stay in lib/public
Conflicts: lib/private/vcategories.php
Diffstat (limited to 'lib/private/search')
-rw-r--r--lib/private/search/provider.php18
-rw-r--r--lib/private/search/provider/file.php46
-rw-r--r--lib/private/search/result.php26
3 files changed, 90 insertions, 0 deletions
diff --git a/lib/private/search/provider.php b/lib/private/search/provider.php
new file mode 100644
index 00000000000..b617b9c5d94
--- /dev/null
+++ b/lib/private/search/provider.php
@@ -0,0 +1,18 @@
+<?php
+/**
+ * provides search functionalty
+ */
+abstract class OC_Search_Provider {
+ private $options;
+
+ public function __construct($options) {
+ $this->options=$options;
+ }
+
+ /**
+ * search for $query
+ * @param string $query
+ * @return array An array of OC_Search_Result's
+ */
+ abstract public function search($query);
+}
diff --git a/lib/private/search/provider/file.php b/lib/private/search/provider/file.php
new file mode 100644
index 00000000000..9bd50931517
--- /dev/null
+++ b/lib/private/search/provider/file.php
@@ -0,0 +1,46 @@
+<?php
+
+class OC_Search_Provider_File extends OC_Search_Provider{
+ function search($query) {
+ $files=\OC\Files\Filesystem::search($query, true);
+ $results=array();
+ $l=OC_L10N::get('lib');
+ foreach($files as $fileData) {
+ $path = $fileData['path'];
+ $mime = $fileData['mimetype'];
+
+ $name = basename($path);
+ $container = dirname($path);
+ $text = '';
+ $skip = false;
+ if($mime=='httpd/unix-directory') {
+ $link = OC_Helper::linkTo( 'files', 'index.php', array('dir' => $path));
+ $type = (string)$l->t('Files');
+ }else{
+ $link = OC_Helper::linkToRoute( 'download', array('file' => $path));
+ $mimeBase = $fileData['mimepart'];
+ switch($mimeBase) {
+ case 'audio':
+ $skip = true;
+ break;
+ case 'text':
+ $type = (string)$l->t('Text');
+ break;
+ case 'image':
+ $type = (string)$l->t('Images');
+ break;
+ default:
+ if($mime=='application/xml') {
+ $type = (string)$l->t('Text');
+ }else{
+ $type = (string)$l->t('Files');
+ }
+ }
+ }
+ if(!$skip) {
+ $results[] = new OC_Search_Result($name, $text, $link, $type, $container);
+ }
+ }
+ return $results;
+ }
+}
diff --git a/lib/private/search/result.php b/lib/private/search/result.php
new file mode 100644
index 00000000000..42275c2df11
--- /dev/null
+++ b/lib/private/search/result.php
@@ -0,0 +1,26 @@
+<?php
+/**
+ * a result of a search
+ */
+class OC_Search_Result{
+ public $name;
+ public $text;
+ public $link;
+ public $type;
+ public $container;
+
+ /**
+ * 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, $container) {
+ $this->name=$name;
+ $this->text=$text;
+ $this->link=$link;
+ $this->type=$type;
+ $this->container=$container;
+ }
+}