| 1 |
<?php
|
| 2 |
|
| 3 |
// $Id: search_uploads.module,v 1.3 2008/07/16 14:18:28 pedrofaria Exp $
|
| 4 |
|
| 5 |
function search_uploads_perm() {
|
| 6 |
return array('search files');
|
| 7 |
}
|
| 8 |
|
| 9 |
function search_uploads_search($op = 'search', $keys = null) {
|
| 10 |
if (!user_access('search files')) {
|
| 11 |
return;
|
| 12 |
}
|
| 13 |
|
| 14 |
switch ($op) {
|
| 15 |
case 'name':
|
| 16 |
return t('Files');
|
| 17 |
|
| 18 |
case 'search':
|
| 19 |
$results = array();
|
| 20 |
|
| 21 |
$rs = db_query("SELECT * FROM {files} WHERE filename LIKE '%%%s%%' OR filepath LIKE '%%%s%%'", $keys, $keys);
|
| 22 |
while ($row = db_fetch_object($rs)) {
|
| 23 |
$node = node_load(array('nid' => $row->nid));
|
| 24 |
|
| 25 |
// checking if you have access to view node.
|
| 26 |
if (!node_access('view', $node)) {
|
| 27 |
continue;
|
| 28 |
}
|
| 29 |
|
| 30 |
$results[] = array(
|
| 31 |
'link' => url($row->filepath),
|
| 32 |
'type' => node_invoke($node, 'node_name'),
|
| 33 |
'title' => $row->filename,
|
| 34 |
'user' => theme('username', $node),
|
| 35 |
'date' => $node->changed,
|
| 36 |
'snippet' => t('File').": {$row->filename}<br />".t('Size').": ".format_size($row->filesize)."<br />".t('Content').": ".l($node->title, 'node/'.$node->nid),
|
| 37 |
);
|
| 38 |
}
|
| 39 |
|
| 40 |
return $results;
|
| 41 |
}
|
| 42 |
}
|
| 43 |
|