Skip to content

Commit

Permalink
Create Advanced Search app
Browse files Browse the repository at this point in the history
Allows users to interact with search results (e.g. delete, share) using
the same view available in the Files app. Much like iTunes, you can
interact with your search results in a file list. It uses the current
search providers available ownCloud (i.e. they only search by file name)
but I plan to start building more search providers soon. This project is
still in beta testing; please submit all bugs or feature requests to
https://github.com/andrewsbrown/owncloud-core/issues.
  • Loading branch information
abrown committed Dec 25, 2012
1 parent 78ba554 commit 8e2725d
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 0 deletions.
9 changes: 9 additions & 0 deletions search/appinfo/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

OCP\App::addNavigationEntry(array(
'id' => 'search',
'href' => OCP\Util::linkTo('search', 'index.php'),
'icon' => OCP\Util::imagePath('', 'actions/search.svg'),
'name' => 'Adv. Search',
'order' => 50
));
15 changes: 15 additions & 0 deletions search/appinfo/info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<info>
<id>search</id>
<name>Advanced Search</name>
<description>Allows users to interact with search results (e.g. delete, share) using the same view available in the Files app. Much like iTunes, you can interact with your search results in a file list. It uses the current search providers available ownCloud (i.e. they only search by file name) but I plan to start building more search providers soon. This project is still in beta testing; please submit all bugs or feature requests to https://github.com/andrewsbrown/owncloud-core/issues.</description>
<licence>AGPL</licence>
<author>Andrew Brown</author>
<require>4.9</require>
<shipped>false</shipped>
<standalone/>
<default_enable/>
<types>
<filesystem/>
</types>
</info>
1 change: 1 addition & 0 deletions search/appinfo/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.5
6 changes: 6 additions & 0 deletions search/css/search.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.search_button, .search_button:hover{
background-image: url('%webroot%/core/img/actions/search.svg');
background-repeat: no-repeat;
background-position: .4em center;
text-indent: 1.4em;
}
76 changes: 76 additions & 0 deletions search/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

// check if we are a user
OCP\User::checkLoggedIn();

// load files
OCP\Util::addStyle('files', 'files');
OCP\Util::addStyle('search', 'search');
OCP\Util::addscript('files', 'jquery.iframe-transport');
OCP\Util::addscript('files', 'jquery.fileupload');
OCP\Util::addscript('files', 'files');
OCP\Util::addscript('files', 'filelist');
OCP\Util::addscript('files', 'fileactions');
OCP\Util::addscript('files', 'keyboardshortcuts');

// activate link
OCP\App::setActiveNavigationEntry('search');

// get results
$query = (isset($_GET['query'])) ? $_GET['query'] : '';
$results = null;
if ($query) {
$results = OC_Search::search($query);
}

// create HTML table
$files = array();
if (is_array($results)) {
foreach ($results as $result) {
// create file
$_file = $result->fileData;
// discard versions
if (strpos($_file['path'], '_versions') === 0) {
continue;
}
// get basename and extension
$fileinfo = pathinfo($_file['name']);
$_file['basename'] = $fileinfo['filename'];
if (!empty($fileinfo['extension'])) {
$_file['extension'] = '.' . $fileinfo['extension'];
} else {
$_file['extension'] = '';
}
// get date
$_file['date'] = OCP\Util::formatDate($_file['mtime']);
// get directory
$_file['directory'] = str_replace('/' . $_file['name'], '', $_file['path']);
// get permissions
$_file['type'] = ($_file['mimetype'] == 'httpd/unix-directory') ? 'dir' : 'file';
$permissions = OCP\PERMISSION_READ;
if (!$_file['encrypted']) {
$permissions |= OCP\PERMISSION_SHARE;
}
if ($_file['type'] == 'dir' && $_file['writable']) {
$permissions |= OCP\PERMISSION_CREATE;
}
if ($_file['writable']) {
$permissions |= OCP\PERMISSION_UPDATE | OCP\PERMISSION_DELETE;
}
$_file['permissions'] = $permissions;
// add file
$files[] = $_file;
}
}
$list = new OCP\Template('files', 'part.list', '');
$list->assign('files', $files, false);
$list->assign('baseURL', OCP\Util::linkTo('files', 'index.php') . '?dir=', false);
$list->assign('downloadURL', OCP\Util::linkTo('files', 'download.php') . '?file=', false);

// populate main template
$tmpl = new OCP\Template('search', 'index', 'user');
$tmpl->assign('files', $files);
$tmpl->assign('fileList', $list->fetchPage(), false);
$tmpl->assign('breadcrumb', $query, true);
$tmpl->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
$tmpl->printPage();
43 changes: 43 additions & 0 deletions search/templates/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!--[if IE 8]><style>input[type="checkbox"]{padding:0;}table td{position:static !important;}</style><![endif]-->

<!-- search form -->
<div id="controls">
<form id="search-form" action="<?php echo OCP\Util::linkTo('search', 'index.php'); ?>" method="get">
<input type="text" name="query" id="search_query" value="<?php echo $_['breadcrumb']; ?>">
<button class="button search_button">Search</button>
</form>
</div>
<div id="file_action_panel"></div>
<div id='notification'></div>

<?php if (empty($_['files'])): ?>
<div id="emptyfolder"><?php echo $l->t('Nothing found.') ?></div>
<?php endif; ?>

<!-- results list -->
<table class="resultsList">
<thead>
<tr>
<th id='headerName'>
<input type="checkbox" id="select_all" />
<span class='name'><?php echo $l->t('Name'); ?></span>
<span class='selectedActions'>
<?php if ($_['allowZipDownload']) : ?>
<a href="" class="download"><img class='svg' alt="Download" src="<?php echo OCP\image_path("core", "actions/download.svg"); ?>" /> <?php echo $l->t('Download') ?></a>
<?php endif; ?>
</span>
</th>
<th id="headerSize"><?php echo $l->t('Size'); ?></th>
<th id="headerDate">
<span id="modified"><?php echo $l->t('Modified'); ?></span>
</th>
</tr>
</thead>
<tbody id="fileList">
<?php echo($_['fileList']); ?>
</tbody>
</table>
<div id="editor"></div>

<!-- config hints for javascript -->
<input type="hidden" name="allowZipDownload" id="allowZipDownload" value="<?php echo $_['allowZipDownload']; ?>" />

0 comments on commit 8e2725d

Please sign in to comment.