summaryrefslogtreecommitdiffstats
path: root/lib/private/search
diff options
context:
space:
mode:
authorAndrew Brown <andrew@casabrown.com>2014-02-17 17:57:27 -0800
committerJörn Friedrich Dreyer <jfd@butonic.de>2014-06-05 19:23:44 +0200
commit7a224f57626f684415b5f45660bd21ec7ebafe72 (patch)
treea5acb119de2c963ce26ef2eed59b75a2bfa1660c /lib/private/search
parent8a223eb62d9d0a1f92ce869ba2639816843cd1a6 (diff)
downloadnextcloud-server-7a224f57626f684415b5f45660bd21ec7ebafe72.tar.gz
nextcloud-server-7a224f57626f684415b5f45660bd21ec7ebafe72.zip
Move new search results to 'lib/private/search'
Diffstat (limited to 'lib/private/search')
-rw-r--r--lib/private/search/result.php2
-rw-r--r--lib/private/search/result/audio.php36
-rw-r--r--lib/private/search/result/file.php114
-rw-r--r--lib/private/search/result/folder.php33
-rw-r--r--lib/private/search/result/image.php36
5 files changed, 220 insertions, 1 deletions
diff --git a/lib/private/search/result.php b/lib/private/search/result.php
index 90e7081e753..d228f833810 100644
--- a/lib/private/search/result.php
+++ b/lib/private/search/result.php
@@ -22,7 +22,7 @@ namespace OC\Search;
/**
* The generic result of a search
*/
-abstract class Result {
+class Result {
/**
* A unique identifier for the result, usually given as the item ID in its
diff --git a/lib/private/search/result/audio.php b/lib/private/search/result/audio.php
new file mode 100644
index 00000000000..46f7396ec9f
--- /dev/null
+++ b/lib/private/search/result/audio.php
@@ -0,0 +1,36 @@
+<?php
+/**
+ * ownCloud
+ *
+ * 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/>.
+ *
+ */
+
+namespace OC\Search\Result;
+
+/**
+ * A found audio file
+ */
+class Audio extends \OC\Search\Result\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..0ecbc0ba1fa
--- /dev/null
+++ b/lib/private/search/result/file.php
@@ -0,0 +1,114 @@
+<?php
+/**
+ * ownCloud
+ *
+ * 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/>.
+ *
+ */
+
+namespace OC\Search\Result;
+
+/**
+ * A found file
+ */
+class File extends \OC\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 string $id unique identifier from application: '[app_name]/[item_identifier_in_app]'
+ * @param string $name displayed text of result
+ * @param string $link URL to the result within its app
+ * @param array $data file data given by provider
+ */
+ public function __construct(array $data = null) {
+ $info = pathinfo($data['path']);
+ $this->id = $data['fileid'];
+ $this->name = $info['basename'];
+ $this->link = \OCP\Util::linkTo(
+ 'files',
+ 'index.php',
+ array('dir' => $info['dirname'], 'file' => $info['basename'])
+ );
+ $this->permissions = self::get_permissions($data['path']);
+ $this->path = (strpos($data['path'], 'files') === 0) ? substr($data['path'], 5) : $data['path'];
+ $this->size = $data['size'];
+ $this->modified = $data['mtime'];
+ $this->mime_type = $data['mimetype'];
+ }
+
+ /**
+ * Determine permissions for a given file path
+ * @param string $path
+ * @return int
+ */
+ function get_permissions($path) {
+ // add read permissions
+ $permissions = \OCP\PERMISSION_READ;
+ // get directory
+ $fileinfo = pathinfo($path);
+ $dir = $fileinfo['dirname'] . '/';
+ // add update permissions
+ if (\OC_Filesystem::isUpdatable($dir)) {
+ $permissions |= \OCP\PERMISSION_UPDATE;
+ }
+ // add delete permissions
+ if (\OC_Filesystem::isDeletable($dir)) {
+ $permissions |= \OCP\PERMISSION_DELETE;
+ }
+ // add share permissions
+ if (\OC_Filesystem::isSharable($dir)) {
+ $permissions |= \OCP\PERMISSION_SHARE;
+ }
+ // return
+ return $permissions;
+ }
+
+}
diff --git a/lib/private/search/result/folder.php b/lib/private/search/result/folder.php
new file mode 100644
index 00000000000..8346f933b4d
--- /dev/null
+++ b/lib/private/search/result/folder.php
@@ -0,0 +1,33 @@
+<?php
+/**
+ * ownCloud
+ *
+ * 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/>.
+ *
+ */
+
+namespace OC\Search\Result;
+
+/**
+ * A found folder
+ */
+class Folder extends \OC\Search\Result\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..ecc706fffe6
--- /dev/null
+++ b/lib/private/search/result/image.php
@@ -0,0 +1,36 @@
+<?php
+/**
+ * ownCloud
+ *
+ * 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/>.
+ *
+ */
+
+namespace OC\Search\Result;
+
+/**
+ * A found image file
+ */
+class Image extends \OC\Search\Result\File {
+
+ /**
+ * Type name; translated in templates
+ * @var string
+ */
+ public $type = 'image';
+
+ /**
+ * @TODO add EXIF information
+ */
+}