summaryrefslogtreecommitdiffstats
path: root/lib/private/Search
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2016-04-26 07:32:37 +0200
committerRoeland Jago Douma <rullzer@owncloud.com>2016-04-26 07:32:37 +0200
commita93c7d03871f5de6845501f15f161d5ed5607c5f (patch)
treea0e0cd0a84cf51cde23331d93db4de69adfd7661 /lib/private/Search
parentd8f327831e6f64658c50131c2e7344ee6fa0e86a (diff)
downloadnextcloud-server-a93c7d03871f5de6845501f15f161d5ed5607c5f.tar.gz
nextcloud-server-a93c7d03871f5de6845501f15f161d5ed5607c5f.zip
Move \OC\Search to PSR-4
Diffstat (limited to 'lib/private/Search')
-rw-r--r--lib/private/Search/Provider/File.php75
-rw-r--r--lib/private/Search/Result/Audio.php40
-rw-r--r--lib/private/Search/Result/File.php115
-rw-r--r--lib/private/Search/Result/Folder.php37
-rw-r--r--lib/private/Search/Result/Image.php40
5 files changed, 307 insertions, 0 deletions
diff --git a/lib/private/Search/Provider/File.php b/lib/private/Search/Provider/File.php
new file mode 100644
index 00000000000..69ffbd3ae6b
--- /dev/null
+++ b/lib/private/Search/Provider/File.php
@@ -0,0 +1,75 @@
+<?php
+/**
+ * @author Andrew Brown <andrew@casabrown.com>
+ * @author Bart Visscher <bartv@thisnet.nl>
+ * @author Jakob Sack <mail@jakobsack.de>
+ * @author Jörn Friedrich Dreyer <jfd@butonic.de>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\Search\Provider;
+use OC\Files\Filesystem;
+
+/**
+ * Provide search results from the 'files' app
+ */
+class File extends \OCP\Search\Provider {
+
+ /**
+ * Search for files and folders matching the given query
+ * @param string $query
+ * @return \OCP\Search\Result
+ */
+ function search($query) {
+ $files = Filesystem::search($query);
+ $results = array();
+ // edit results
+ foreach ($files as $fileData) {
+ // skip versions
+ if (strpos($fileData['path'], '_versions') === 0) {
+ continue;
+ }
+ // skip top-level folder
+ if ($fileData['name'] === 'files' && $fileData['parent'] === -1) {
+ continue;
+ }
+ // create audio result
+ if($fileData['mimepart'] === 'audio'){
+ $result = new \OC\Search\Result\Audio($fileData);
+ }
+ // create image result
+ elseif($fileData['mimepart'] === 'image'){
+ $result = new \OC\Search\Result\Image($fileData);
+ }
+ // create folder result
+ elseif($fileData['mimetype'] === 'httpd/unix-directory'){
+ $result = new \OC\Search\Result\Folder($fileData);
+ }
+ // or create file result
+ else{
+ $result = new \OC\Search\Result\File($fileData);
+ }
+ // add to results
+ $results[] = $result;
+ }
+ // return
+ return $results;
+ }
+
+}
diff --git a/lib/private/Search/Result/Audio.php b/lib/private/Search/Result/Audio.php
new file mode 100644
index 00000000000..3f9b3dc640c
--- /dev/null
+++ b/lib/private/Search/Result/Audio.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * @author Andrew Brown <andrew@casabrown.com>
+ * @author Jörn Friedrich Dreyer <jfd@butonic.de>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\Search\Result;
+
+/**
+ * A found audio file
+ */
+class Audio extends File {
+
+ /**
+ * Type name; translated in templates
+ * @var string
+ */
+ public $type = 'audio';
+
+ /**
+ * @TODO add ID3 information
+ */
+}
diff --git a/lib/private/Search/Result/File.php b/lib/private/Search/Result/File.php
new file mode 100644
index 00000000000..f1347001eaf
--- /dev/null
+++ b/lib/private/Search/Result/File.php
@@ -0,0 +1,115 @@
+<?php
+/**
+ * @author Andrew Brown <andrew@casabrown.com>
+ * @author Joas Schilling <nickvergessen@owncloud.com>
+ * @author Jörn Friedrich Dreyer <jfd@butonic.de>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\Search\Result;
+use OCP\Files\FileInfo;
+use OCP\Files\Folder;
+
+/**
+ * A found file
+ */
+class File extends \OCP\Search\Result {
+
+ /**
+ * Type name; translated in templates
+ * @var string
+ */
+ public $type = 'file';
+
+ /**
+ * Path to file
+ * @var string
+ */
+ public $path;
+
+ /**
+ * Size, in bytes
+ * @var int
+ */
+ public $size;
+
+ /**
+ * Date modified, in human readable form
+ * @var string
+ */
+ public $modified;
+
+ /**
+ * File mime type
+ * @var string
+ */
+ public $mime_type;
+
+ /**
+ * File permissions:
+ *
+ * @var string
+ */
+ public $permissions;
+
+ /**
+ * Create a new file search result
+ * @param FileInfo $data file data given by provider
+ */
+ public function __construct(FileInfo $data) {
+
+ $path = $this->getRelativePath($data->getPath());
+
+ $info = pathinfo($path);
+ $this->id = $data->getId();
+ $this->name = $info['basename'];
+ $this->link = \OC::$server->getURLGenerator()->linkToRoute(
+ 'files.view.index',
+ [
+ 'dir' => $info['dirname'],
+ 'scrollto' => $info['basename'],
+ ]
+ );
+ $this->permissions = $data->getPermissions();
+ $this->path = $path;
+ $this->size = $data->getSize();
+ $this->modified = $data->getMtime();
+ $this->mime = $data->getMimetype();
+ }
+
+ /**
+ * @var Folder $userFolderCache
+ */
+ static protected $userFolderCache = null;
+
+ /**
+ * converts a path relative to the users files folder
+ * eg /user/files/foo.txt -> /foo.txt
+ * @param string $path
+ * @return string relative path
+ */
+ protected function getRelativePath ($path) {
+ if (!isset(self::$userFolderCache)) {
+ $user = \OC::$server->getUserSession()->getUser()->getUID();
+ self::$userFolderCache = \OC::$server->getUserFolder($user);
+ }
+ return self::$userFolderCache->getRelativePath($path);
+ }
+
+}
diff --git a/lib/private/Search/Result/Folder.php b/lib/private/Search/Result/Folder.php
new file mode 100644
index 00000000000..6f0c0a7b2a5
--- /dev/null
+++ b/lib/private/Search/Result/Folder.php
@@ -0,0 +1,37 @@
+<?php
+/**
+ * @author Andrew Brown <andrew@casabrown.com>
+ * @author Jörn Friedrich Dreyer <jfd@butonic.de>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\Search\Result;
+
+/**
+ * A found folder
+ */
+class Folder extends File {
+
+ /**
+ * Type name; translated in templates
+ * @var string
+ */
+ public $type = 'folder';
+
+}
diff --git a/lib/private/Search/Result/Image.php b/lib/private/Search/Result/Image.php
new file mode 100644
index 00000000000..87b36fc9f73
--- /dev/null
+++ b/lib/private/Search/Result/Image.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * @author Andrew Brown <andrew@casabrown.com>
+ * @author Jörn Friedrich Dreyer <jfd@butonic.de>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\Search\Result;
+
+/**
+ * A found image file
+ */
+class Image extends File {
+
+ /**
+ * Type name; translated in templates
+ * @var string
+ */
+ public $type = 'image';
+
+ /**
+ * @TODO add EXIF information
+ */
+}