| 1 |
<?php |
|---|
| 2 |
global $CFG; |
|---|
| 3 |
global $db; |
|---|
| 4 |
global $search_exclusions; |
|---|
| 5 |
|
|---|
| 6 |
if (isset($parameter) && $parameter[0] == "file") { |
|---|
| 7 |
|
|---|
| 8 |
$search_exclusions[] = "folder"; |
|---|
| 9 |
$search_exclusions[] = "file"; |
|---|
| 10 |
$dbtag = $db->qstr($parameter[1]); |
|---|
| 11 |
|
|---|
| 12 |
$owner = optional_param('owner',0,PARAM_INT); |
|---|
| 13 |
$accessline = "(" . run("users:access_level_sql_where",$_SESSION['userid']) . ")"; |
|---|
| 14 |
$searchline_files = "$accessline and tagtype = 'file' and tag = " . $dbtag . ""; |
|---|
| 15 |
$searchline_folders = "$accessline and tagtype = 'folder' and tag = " . $dbtag . ""; |
|---|
| 16 |
$searchline_files = str_replace("access", "f.access", $searchline_files); |
|---|
| 17 |
$searchline_files = str_replace("owner", "f.owner", $searchline_files); |
|---|
| 18 |
$searchline_folders = str_replace("access", "ff.access", $searchline_folders); |
|---|
| 19 |
$searchline_folders = str_replace("owner", "ff.owner", $searchline_folders); |
|---|
| 20 |
|
|---|
| 21 |
$file_refs = get_records_sql('SELECT f.*,u.username,u.name AS fullname,t.ref FROM '.$CFG->prefix.'tags t |
|---|
| 22 |
JOIN '.$CFG->prefix.'files f ON f.ident = t.ref |
|---|
| 23 |
JOIN '.$CFG->prefix.'users u ON u.ident = t.owner |
|---|
| 24 |
WHERE '.$searchline_files.' LIMIT 50'); |
|---|
| 25 |
|
|---|
| 26 |
$folder_refs = get_records_sql('SELECT ff.*, u.username, u.name AS fullname, t.ref FROM '.$CFG->prefix.'tags t |
|---|
| 27 |
JOIN '.$CFG->prefix.'file_folders ff ON ff.ident = t.ref |
|---|
| 28 |
JOIN '.$CFG->prefix.'users u ON u.ident = t.owner |
|---|
| 29 |
WHERE '.$searchline_folders.' LIMIT 50'); |
|---|
| 30 |
$searchline = ""; |
|---|
| 31 |
if (!empty($folder_refs)) { |
|---|
| 32 |
foreach($folder_refs as $folder) { |
|---|
| 33 |
$run_result .= "\t<item>\n"; |
|---|
| 34 |
$run_result .= "\t\t<title><![CDATA[". __gettext("File folder") ." :: " . stripslashes($folder->fullname) . " :: " . stripslashes($folder->name) . "]]></title>\n"; |
|---|
| 35 |
$run_result .= "\t\t<link>" . url . $folder->username . "/files/" . $folder->ident . "</link>\n"; |
|---|
| 36 |
$run_result .= "\t</item>\n"; |
|---|
| 37 |
} |
|---|
| 38 |
} |
|---|
| 39 |
if (!empty($file_refs)) { |
|---|
| 40 |
require_once($CFG->dirroot.'lib/filelib.php'); |
|---|
| 41 |
foreach($file_refs as $file) { |
|---|
| 42 |
$mimetype = mimeinfo('type',$file->location); |
|---|
| 43 |
$run_result .= "\t<item>\n"; |
|---|
| 44 |
$run_result .= "\t\t<title><![CDATA[". __gettext("File") ." :: " . stripslashes($file->fullname) . " :: " . stripslashes($file->title) . "]]></title>\n"; |
|---|
| 45 |
$run_result .= "\t\t<link>" . url . $file->username . "/files/" . $file->folder . "/" . $file->ident . "/" . urlencode(stripslashes($file->originalname)) . "</link>\n"; |
|---|
| 46 |
$run_result .= "\t\t<enclosure url=\"" . url . $file->username . "/files/" . $file->folder . "/" . $file->ident . "/" .urlencode(htmlspecialchars(stripslashes($file->originalname), ENT_COMPAT, 'utf-8')) . "\" length=\"". $file->size ."\" mimetype=\"$mimetype\" />\n"; |
|---|
| 47 |
$run_result .= "\t</item>\n"; |
|---|
| 48 |
} |
|---|
| 49 |
} |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
?> |
|---|