@@ -25,13 +25,13 @@ | |||
* provides an interface to all search providers | |||
* @deprecated see lib/search.php | |||
*/ | |||
class OC_Search{ | |||
class OC_Search { | |||
static private $providers=array(); | |||
static private $registeredProviders=array(); | |||
/** | |||
* remove all registered search providers | |||
* @deprecated see lib/search.php | |||
* @deprecated see lib/search.php | |||
*/ | |||
public static function clearProviders() { | |||
return \OC\Search::clearProviders(); | |||
@@ -40,7 +40,7 @@ class OC_Search{ | |||
/** | |||
* register a new search provider to be used | |||
* @param string $provider class name of a OC_Search_Provider | |||
* @deprecated see lib/search.php | |||
* @deprecated see lib/search.php | |||
*/ | |||
public static function registerProvider($class, $options=array()) { | |||
return \OC\Search::registerProvider($class, $options); | |||
@@ -50,7 +50,7 @@ class OC_Search{ | |||
* search all provider for $query | |||
* @param string query | |||
* @return array An array of OC_Search_Result's | |||
* @deprecated see lib/search.php | |||
* @deprecated see lib/search.php | |||
*/ | |||
public static function search($query) { | |||
return \OC\Search::search($query); | |||
@@ -59,9 +59,10 @@ class OC_Search{ | |||
/** | |||
* remove an existing search provider | |||
* @param string $provider class name of a OC_Search_Provider | |||
* @deprecated see lib/search.php | |||
* @deprecated see lib/search.php | |||
*/ | |||
public static function removeProvider($provider) { | |||
return \OC\Search::removeProvider($provider); | |||
} | |||
} |
@@ -17,6 +17,6 @@ | |||
* | |||
*/ | |||
abstract class OC_Search_Provider extends \OC\Search\Provider{ | |||
} | |||
abstract class OC_Search_Provider extends \OC\Search\Provider { | |||
} |
@@ -17,6 +17,6 @@ | |||
* | |||
*/ | |||
class OC_Search_Provider_File extends \OC\Search\Provider\File{ | |||
} | |||
class OC_Search_Provider_File extends \OC\Search\Provider\File { | |||
} |
@@ -17,6 +17,6 @@ | |||
* | |||
*/ | |||
class OC_Search_Result extends \OC\Search\Result{ | |||
} | |||
class OC_Search_Result extends \OC\Search\Result { | |||
} |
@@ -25,7 +25,7 @@ namespace OC; | |||
/** | |||
* Provide an interface to all search providers | |||
*/ | |||
class Search{ | |||
class Search { | |||
static private $providers=array(); | |||
static private $registeredProviders=array(); | |||
@@ -58,10 +58,10 @@ class Search{ | |||
*/ | |||
public static function removeProvider($provider) { | |||
self::$registeredProviders = array_filter( | |||
self::$registeredProviders, | |||
function ($element) use ($provider) { | |||
return ($element['class'] != $provider); | |||
} | |||
self::$registeredProviders, | |||
function ($element) use ($provider) { | |||
return ($element['class'] != $provider); | |||
} | |||
); | |||
// force regeneration of providers on next search | |||
self::$providers=array(); | |||
@@ -88,4 +88,5 @@ class Search{ | |||
self::$providers[]=new $class($options); | |||
} | |||
} | |||
} |
@@ -24,24 +24,24 @@ namespace OC\Search; | |||
*/ | |||
abstract class Provider { | |||
/** | |||
* List of options (currently unused) | |||
* @var array | |||
*/ | |||
private $options; | |||
/** | |||
* List of options (currently unused) | |||
* @var array | |||
*/ | |||
private $options; | |||
/** | |||
* Constructor | |||
* @param array $options | |||
*/ | |||
public function __construct($options) { | |||
$this->options = $options; | |||
} | |||
/** | |||
* Constructor | |||
* @param array $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); | |||
} | |||
/** | |||
* Search for $query | |||
* @param string $query | |||
* @return array An array of OC\Search\Result's | |||
*/ | |||
abstract public function search($query); | |||
} |
@@ -22,38 +22,39 @@ namespace OC\Search\Provider; | |||
/** | |||
* Provide search results from the 'files' app | |||
*/ | |||
class File extends \OC\Search\Provider{ | |||
/** | |||
* Search for files and folders matching the given query | |||
* @param string $query | |||
* @return \OC\Search\Result | |||
*/ | |||
function search($query) { | |||
$files = \OC\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 folder result | |||
if($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; | |||
} | |||
class File extends \OC\Search\Provider { | |||
/** | |||
* Search for files and folders matching the given query | |||
* @param string $query | |||
* @return \OC\Search\Result | |||
*/ | |||
function search($query) { | |||
$files = \OC\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 folder result | |||
if($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; | |||
} | |||
} |
@@ -24,42 +24,42 @@ namespace OC\Search; | |||
*/ | |||
abstract class Result { | |||
/** | |||
* A unique identifier for the result, usually given as the item ID in its | |||
* corresponding application. | |||
* @var string | |||
*/ | |||
public $id; | |||
/** | |||
* A unique identifier for the result, usually given as the item ID in its | |||
* corresponding application. | |||
* @var string | |||
*/ | |||
public $id; | |||
/** | |||
* The name of the item returned; this will be displayed in the search | |||
* results. | |||
* @var string | |||
*/ | |||
public $name; | |||
/** | |||
* The name of the item returned; this will be displayed in the search | |||
* results. | |||
* @var string | |||
*/ | |||
public $name; | |||
/** | |||
* URL to the application item. | |||
* @var string | |||
*/ | |||
public $link; | |||
/** | |||
* The type of search result returned; for consistency, name this the same | |||
* as the class name (e.g. \OC\Search\File -> 'file') in lowercase. | |||
* @var string | |||
*/ | |||
public $type = 'generic'; | |||
/** | |||
* URL to the application item. | |||
* @var string | |||
*/ | |||
public $link; | |||
/** | |||
* Create a new 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 | |||
*/ | |||
public function __construct($id = null, $name = null, $link = null) { | |||
$this->id = $id; | |||
$this->name = $name; | |||
$this->link = $link; | |||
} | |||
/** | |||
* The type of search result returned; for consistency, name this the same | |||
* as the class name (e.g. \OC\Search\File -> 'file') in lowercase. | |||
* @var string | |||
*/ | |||
public $type = 'generic'; | |||
/** | |||
* Create a new 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 | |||
*/ | |||
public function __construct($id = null, $name = null, $link = null) { | |||
$this->id = $id; | |||
$this->name = $name; | |||
$this->link = $link; | |||
} | |||
} |
@@ -23,87 +23,92 @@ 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; | |||
/** | |||
* Type name; translated in templates | |||
* @var string | |||
*/ | |||
public $type = 'file'; | |||
/** | |||
* Size, in bytes | |||
* @var int | |||
*/ | |||
public $size; | |||
/** | |||
* Path to file | |||
* @var string | |||
*/ | |||
public $path; | |||
/** | |||
* Date modified, in human readable form | |||
* @var string | |||
*/ | |||
public $modified; | |||
/** | |||
* Size, in bytes | |||
* @var int | |||
*/ | |||
public $size; | |||
/** | |||
* File mime type | |||
* @var string | |||
*/ | |||
public $mime_type; | |||
/** | |||
* Date modified, in human readable form | |||
* @var string | |||
*/ | |||
public $modified; | |||
/** | |||
* File permissions: | |||
* | |||
* @var string | |||
*/ | |||
public $permissions; | |||
/** | |||
* File mime type | |||
* @var string | |||
*/ | |||
public $mime_type; | |||
/** | |||
* 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']; | |||
} | |||
/** | |||
* File permissions: | |||
* | |||
* @var string | |||
*/ | |||
public $permissions; | |||
/** | |||
* 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; | |||
} | |||
} | |||
/** | |||
* 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; | |||
} | |||
} |
@@ -23,10 +23,11 @@ namespace OC\Search\Result; | |||
* A found folder | |||
*/ | |||
class Folder extends \OC\Search\Result\File { | |||
/** | |||
* Type name; translated in templates | |||
* @var string | |||
*/ | |||
public $type = 'folder'; | |||
} | |||
/** | |||
* Type name; translated in templates | |||
* @var string | |||
*/ | |||
public $type = 'folder'; | |||
} |