Browse Source
add search functionality, for now only searches files but plugins/apps can extend that
remotes/origin/stable
add search functionality, for now only searches files but plugins/apps can extend that
remotes/origin/stable
13 changed files with 267 additions and 3 deletions
-
4css/styles.css
-
1lib/base.php
-
21lib/filestorage.php
-
15lib/filesystem.php
-
121lib/search.php
-
6lib/template.php
-
5search/appinfo/app.php
-
17search/css/search.css
-
55search/index.php
-
17search/templates/index.php
-
2templates/layout.admin.php
-
2templates/layout.user.php
-
4templates/part.searchbox.php
@ -0,0 +1,121 @@ |
|||
<?php |
|||
/** |
|||
* ownCloud |
|||
* |
|||
* @author Frank Karlitschek |
|||
* @copyright 2010 Frank Karlitschek karlitschek@kde.org |
|||
* |
|||
* 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/>. |
|||
* |
|||
*/ |
|||
|
|||
|
|||
/** |
|||
* provides an interface to all search providers |
|||
*/ |
|||
class OC_SEARCH{ |
|||
static private $providers=array(); |
|||
|
|||
/** |
|||
* register a new search provider to be used |
|||
* @param OC_SearchProvider $provider |
|||
*/ |
|||
public static function registerProvider($provider){ |
|||
self::$providers[]=$provider; |
|||
} |
|||
|
|||
/** |
|||
* search all provider for $query |
|||
* @param string query |
|||
* @return array An array of OC_SearchResult's |
|||
*/ |
|||
public static function search($query){ |
|||
$results=array(); |
|||
foreach(self::$providers as $provider){ |
|||
$results=array_merge($results,$provider->search($query)); |
|||
} |
|||
return $results; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* provides search functionalty |
|||
*/ |
|||
abstract class OC_SearchProvider{ |
|||
public function __construct(){ |
|||
OC_SEARCH::registerProvider($this); |
|||
} |
|||
|
|||
/** |
|||
* search for $query |
|||
* @param string $query |
|||
* @return array An array of OC_SearchResult's |
|||
*/ |
|||
abstract function search($query); |
|||
} |
|||
|
|||
/** |
|||
* a result of a search |
|||
*/ |
|||
class OC_SearchResult{ |
|||
private $name; |
|||
private $text; |
|||
private $link; |
|||
private $type; |
|||
|
|||
/** |
|||
* 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){ |
|||
$this->name=$name; |
|||
$this->text=$text; |
|||
$this->link=$link; |
|||
$this->type=$type; |
|||
} |
|||
|
|||
public function __get($name){ |
|||
switch($name){ |
|||
case 'name': |
|||
return $this->name; |
|||
case 'text': |
|||
return $this->text; |
|||
case 'link': |
|||
return $this->link; |
|||
case 'type': |
|||
return $this->type; |
|||
} |
|||
} |
|||
} |
|||
|
|||
class OC_FileSearchProvider extends OC_SearchProvider{ |
|||
function search($query){ |
|||
$files=OC_FILESYSTEM::search($query); |
|||
$results=array(); |
|||
foreach($files as $file){ |
|||
if(OC_FILESYSTEM::is_dir($file)){ |
|||
$results[]=new OC_SearchResult(basename($file),$file,OC_HELPER::linkTo( 'files', 'index.php?dir='.$file ),'Files'); |
|||
}else{ |
|||
$results[]=new OC_SearchResult(basename($file),$file,OC_HELPER::linkTo( 'files', 'download.php?file='.$file ),'Files'); |
|||
} |
|||
} |
|||
return $results; |
|||
} |
|||
} |
|||
|
|||
new OC_FileSearchProvider(); |
|||
?>
|
|||
@ -0,0 +1,5 @@ |
|||
<?php |
|||
|
|||
OC_APP::register( array( 'order' => 2, "id" => 'search', 'name' => 'Search' )); |
|||
|
|||
?>
|
|||
@ -0,0 +1,17 @@ |
|||
#searchresults{ |
|||
margin: 2em; |
|||
list-style:none; |
|||
border: solid 1px #CCC; |
|||
} |
|||
|
|||
#searchresults li.resultHeader{ |
|||
font-size:1.2em; |
|||
font-weight:bold; |
|||
border-bottom: solid 1px #CCC; |
|||
padding:0.2em; |
|||
background-color:#eee; |
|||
} |
|||
|
|||
#searchresults li.result{ |
|||
margin-left:2em; |
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* ownCloud - ajax frontend |
|||
* |
|||
* @author Robin Appelman |
|||
* @copyright 2010 Robin Appelman icewind1991@gmail.com |
|||
* |
|||
* 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/>. |
|||
* |
|||
*/ |
|||
|
|||
|
|||
// Init owncloud
|
|||
require_once('../lib/base.php'); |
|||
require( 'template.php' ); |
|||
|
|||
// Check if we are a user
|
|||
if( !OC_USER::isLoggedIn()){ |
|||
header( "Location: ".OC_HELPER::linkTo( '', 'index.php' )); |
|||
exit(); |
|||
} |
|||
|
|||
// Load the files we need
|
|||
OC_UTIL::addStyle( 'search', 'search' ); |
|||
|
|||
$query=(isset($_POST['query']))?$_POST['query']:''; |
|||
if($query){ |
|||
$results=OC_SEARCH::search($query); |
|||
} |
|||
|
|||
$resultTypes=array(); |
|||
foreach($results as $result){ |
|||
if(!isset($resultTypes[$result->type])){ |
|||
$resultTypes[$result->type]=array(); |
|||
} |
|||
$resultTypes[$result->type][]=$result; |
|||
} |
|||
|
|||
$tmpl = new OC_TEMPLATE( 'search', 'index', 'user' ); |
|||
$tmpl->assign('resultTypes',$resultTypes); |
|||
$tmpl->printPage(); |
|||
|
|||
?>
|
|||
@ -0,0 +1,17 @@ |
|||
<ul id='searchresults'> |
|||
<?php foreach($_['resultTypes'] as $resultType):?>
|
|||
<li class='resultHeader'> |
|||
<p><?php echo $resultType[0]->type?></p>
|
|||
</li> |
|||
<?php foreach($resultType as $result):?>
|
|||
<li class='result'> |
|||
<p> |
|||
<a href='<?php echo $result->link?>' title='<?php echo $result->name?>'><?php echo $result->name?></a>
|
|||
</p> |
|||
<p> |
|||
<?php echo $result->text?>
|
|||
</p> |
|||
</li> |
|||
<?php endforeach;?>
|
|||
<?php endforeach;?>
|
|||
</ul> |
|||
@ -0,0 +1,4 @@ |
|||
<form class='searchbox' action='<?php echo $_['searchurl']?>' method='post'> |
|||
<input name='query' value='<?php if(isset($_POST['query'])){echo $_POST['query'];};?>'/> |
|||
<input type='submit' value='Search' class='prettybutton'/> |
|||
</form> |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue