fix formatting

This commit is contained in:
Jörn Friedrich Dreyer 2013-08-26 14:12:06 +02:00
parent a6583d3976
commit afd24385a8
10 changed files with 200 additions and 191 deletions

View File

@ -25,13 +25,13 @@
* provides an interface to all search providers * provides an interface to all search providers
* @deprecated see lib/search.php * @deprecated see lib/search.php
*/ */
class OC_Search{ class OC_Search {
static private $providers=array(); static private $providers=array();
static private $registeredProviders=array(); static private $registeredProviders=array();
/** /**
* remove all registered search providers * remove all registered search providers
* @deprecated see lib/search.php * @deprecated see lib/search.php
*/ */
public static function clearProviders() { public static function clearProviders() {
return \OC\Search::clearProviders(); return \OC\Search::clearProviders();
@ -40,7 +40,7 @@ class OC_Search{
/** /**
* register a new search provider to be used * register a new search provider to be used
* @param string $provider class name of a OC_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 registerProvider($class, $options=array()) { public static function registerProvider($class, $options=array()) {
return \OC\Search::registerProvider($class, $options); return \OC\Search::registerProvider($class, $options);
@ -50,7 +50,7 @@ class OC_Search{
* search all provider for $query * search all provider for $query
* @param string query * @param string query
* @return array An array of OC_Search_Result's * @return array An array of OC_Search_Result's
* @deprecated see lib/search.php * @deprecated see lib/search.php
*/ */
public static function search($query) { public static function search($query) {
return \OC\Search::search($query); return \OC\Search::search($query);
@ -59,9 +59,10 @@ class OC_Search{
/** /**
* remove an existing search provider * remove an existing search provider
* @param string $provider class name of a OC_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) { public static function removeProvider($provider) {
return \OC\Search::removeProvider($provider); return \OC\Search::removeProvider($provider);
} }
} }

View File

@ -17,6 +17,6 @@
* *
*/ */
abstract class OC_Search_Provider extends \OC\Search\Provider{ abstract class OC_Search_Provider extends \OC\Search\Provider {
} }

View File

@ -17,6 +17,6 @@
* *
*/ */
class OC_Search_Provider_File extends \OC\Search\Provider\File{ class OC_Search_Provider_File extends \OC\Search\Provider\File {
} }

View File

@ -17,6 +17,6 @@
* *
*/ */
class OC_Search_Result extends \OC\Search\Result{ class OC_Search_Result extends \OC\Search\Result {
} }

View File

@ -25,7 +25,7 @@ namespace OC;
/** /**
* Provide an interface to all search providers * Provide an interface to all search providers
*/ */
class Search{ class Search {
static private $providers=array(); static private $providers=array();
static private $registeredProviders=array(); static private $registeredProviders=array();
@ -58,10 +58,10 @@ class Search{
*/ */
public static function removeProvider($provider) { public static function removeProvider($provider) {
self::$registeredProviders = array_filter( self::$registeredProviders = array_filter(
self::$registeredProviders, self::$registeredProviders,
function ($element) use ($provider) { function ($element) use ($provider) {
return ($element['class'] != $provider); return ($element['class'] != $provider);
} }
); );
// force regeneration of providers on next search // force regeneration of providers on next search
self::$providers=array(); self::$providers=array();
@ -88,4 +88,5 @@ class Search{
self::$providers[]=new $class($options); self::$providers[]=new $class($options);
} }
} }
} }

View File

@ -24,24 +24,24 @@ namespace OC\Search;
*/ */
abstract class Provider { abstract class Provider {
/** /**
* List of options (currently unused) * List of options (currently unused)
* @var array * @var array
*/ */
private $options; private $options;
/** /**
* Constructor * Constructor
* @param array $options * @param array $options
*/ */
public function __construct($options) { public function __construct($options) {
$this->options = $options; $this->options = $options;
} }
/** /**
* Search for $query * Search for $query
* @param string $query * @param string $query
* @return array An array of OC\Search\Result's * @return array An array of OC\Search\Result's
*/ */
abstract public function search($query); abstract public function search($query);
} }

View File

@ -22,38 +22,39 @@ namespace OC\Search\Provider;
/** /**
* Provide search results from the 'files' app * Provide search results from the 'files' app
*/ */
class File extends \OC\Search\Provider{ class File extends \OC\Search\Provider {
/** /**
* Search for files and folders matching the given query * Search for files and folders matching the given query
* @param string $query * @param string $query
* @return \OC\Search\Result * @return \OC\Search\Result
*/ */
function search($query) { function search($query) {
$files = \OC\Files\Filesystem::search($query); $files = \OC\Files\Filesystem::search($query);
$results = array(); $results = array();
// edit results // edit results
foreach ($files as $fileData) { foreach ($files as $fileData) {
// skip versions // skip versions
if (strpos($fileData['path'], '_versions') === 0) { if (strpos($fileData['path'], '_versions') === 0) {
continue; continue;
} }
// skip top-level folder // skip top-level folder
if ($fileData['name'] == 'files' && $fileData['parent'] == -1) { if ($fileData['name'] === 'files' && $fileData['parent'] === -1) {
continue; continue;
} }
// create folder result // create folder result
if($fileData['mimetype'] == 'httpd/unix-directory'){ if($fileData['mimetype'] === 'httpd/unix-directory'){
$result = new \OC\Search\Result\Folder($fileData); $result = new \OC\Search\Result\Folder($fileData);
} }
// or create file result // or create file result
else{ else{
$result = new \OC\Search\Result\File($fileData); $result = new \OC\Search\Result\File($fileData);
} }
// add to results // add to results
$results[] = $result; $results[] = $result;
} }
// return // return
return $results; return $results;
} }
} }

View File

@ -24,42 +24,42 @@ namespace OC\Search;
*/ */
abstract class Result { abstract class Result {
/** /**
* A unique identifier for the result, usually given as the item ID in its * A unique identifier for the result, usually given as the item ID in its
* corresponding application. * corresponding application.
* @var string * @var string
*/ */
public $id; public $id;
/** /**
* The name of the item returned; this will be displayed in the search * The name of the item returned; this will be displayed in the search
* results. * results.
* @var string * @var string
*/ */
public $name; public $name;
/** /**
* URL to the application item. * URL to the application item.
* @var string * @var string
*/ */
public $link; 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';
/** /**
* Create a new search result * The type of search result returned; for consistency, name this the same
* @param string $id unique identifier from application: '[app_name]/[item_identifier_in_app]' * as the class name (e.g. \OC\Search\File -> 'file') in lowercase.
* @param string $name displayed text of result * @var string
* @param string $link URL to the result within its app */
*/ public $type = 'generic';
public function __construct($id = null, $name = null, $link = null) {
$this->id = $id; /**
$this->name = $name; * Create a new search result
$this->link = $link; * @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;
}
} }

View File

@ -23,87 +23,92 @@ namespace OC\Search\Result;
* A found file * A found file
*/ */
class File extends \OC\Search\Result { class File extends \OC\Search\Result {
/**
* Type name; translated in templates
* @var string
*/
public $type = 'file';
/** /**
* Path to file * Type name; translated in templates
* @var string * @var string
*/ */
public $path; public $type = 'file';
/** /**
* Size, in bytes * Path to file
* @var int * @var string
*/ */
public $size; public $path;
/** /**
* Date modified, in human readable form * Size, in bytes
* @var string * @var int
*/ */
public $modified; public $size;
/** /**
* File mime type * Date modified, in human readable form
* @var string * @var string
*/ */
public $mime_type; public $modified;
/** /**
* File permissions: * File mime type
* * @var string
* @var string */
*/ public $mime_type;
public $permissions;
/** /**
* Create a new file search result * File permissions:
* @param string $id unique identifier from application: '[app_name]/[item_identifier_in_app]' *
* @param string $name displayed text of result * @var string
* @param string $link URL to the result within its app */
* @param array $data file data given by provider public $permissions;
*/
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 * Create a new file search result
* @param string $path * @param string $id unique identifier from application: '[app_name]/[item_identifier_in_app]'
* @return int * @param string $name displayed text of result
*/ * @param string $link URL to the result within its app
function get_permissions($path) { * @param array $data file data given by provider
// add read permissions */
$permissions = \OCP\PERMISSION_READ; public function __construct(array $data = null) {
// get directory $info = pathinfo($data['path']);
$fileinfo = pathinfo($path); $this->id = $data['fileid'];
$dir = $fileinfo['dirname'] . '/'; $this->name = $info['basename'];
// add update permissions $this->link = \OCP\Util::linkTo(
if (\OC_Filesystem::isUpdatable($dir)) { 'files',
$permissions |= \OCP\PERMISSION_UPDATE; 'index.php',
} array('dir' => $info['dirname'], 'file' => $info['basename'])
// add delete permissions );
if (\OC_Filesystem::isDeletable($dir)) { $this->permissions = self::get_permissions($data['path']);
$permissions |= \OCP\PERMISSION_DELETE; $this->path = (strpos($data['path'], 'files') === 0) ? substr($data['path'], 5) : $data['path'];
} $this->size = $data['size'];
// add share permissions $this->modified = $data['mtime'];
if (\OC_Filesystem::isSharable($dir)) { $this->mime_type = $data['mimetype'];
$permissions |= \OCP\PERMISSION_SHARE; }
}
// return /**
return $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;
}
}

View File

@ -23,10 +23,11 @@ namespace OC\Search\Result;
* A found folder * A found folder
*/ */
class Folder extends \OC\Search\Result\File { class Folder extends \OC\Search\Result\File {
/** /**
* Type name; translated in templates * Type name; translated in templates
* @var string * @var string
*/ */
public $type = 'folder'; public $type = 'folder';
}
}