Return clippy to his rightful place next to attachments

This commit is contained in:
Zach Copley 2009-06-25 12:52:10 -07:00
parent c96572c090
commit 2707622762

View File

@ -497,6 +497,22 @@ function common_linkify($url) {
$attrs = array('href' => $longurl, 'rel' => 'external'); $attrs = array('href' => $longurl, 'rel' => 'external');
$is_attachment = false;
$attachment_id = null;
$has_thumb = false;
// Check to see whether there's a filename associated with this URL.
// If there is, it's an upload and qualifies as an attachment
$localfile = File::staticGet('url', $longurl);
if (!empty($localfile)) {
if (isset($localfile->filename)) {
$is_attachment = true;
$attachment_id = $localfile->id;
}
}
// if this URL is an attachment, then we set class='attachment' and id='attahcment-ID' // if this URL is an attachment, then we set class='attachment' and id='attahcment-ID'
// where ID is the id of the attachment for the given URL. // where ID is the id of the attachment for the given URL.
// //
@ -504,24 +520,35 @@ function common_linkify($url) {
// we're currently picking up oembeds only. // we're currently picking up oembeds only.
// I think the best option is another file_view table in the db // I think the best option is another file_view table in the db
// and associated dbobject. // and associated dbobject.
$query = "select file_oembed.file_id as file_id from file join file_oembed on file.id = file_oembed.file_id where file.url='$longurl'"; $query = "select file_oembed.file_id as file_id from file join file_oembed on file.id = file_oembed.file_id where file.url='$longurl'";
$file = new File; $file = new File;
$file->query($query); $file->query($query);
$file->fetch(); $file->fetch();
if (!empty($file->file_id)) { if (!empty($file->file_id)) {
$is_attachment = true;
$attachment_id = $file->file_id;
$query = "select file_thumbnail.file_id as file_id from file join file_thumbnail on file.id = file_thumbnail.file_id where file.url='$longurl'"; $query = "select file_thumbnail.file_id as file_id from file join file_thumbnail on file.id = file_thumbnail.file_id where file.url='$longurl'";
$file2 = new File; $file2 = new File;
$file2->query($query); $file2->query($query);
$file2->fetch(); $file2->fetch();
if (empty($file2->file_id)) { if (!empty($file2)) {
$has_thumb = true;
}
}
// Add clippy
if ($is_attachment) {
$attrs['class'] = 'attachment'; $attrs['class'] = 'attachment';
} else { if ($has_thumb) {
$attrs['class'] = 'attachment thumbnail'; $attrs['class'] = 'attachment thumbnail';
} }
$attrs['id'] = "attachment-{$file->file_id}"; $attrs['id'] = "attachment-{$attachment_id}";
} }
return XMLStringer::estring('a', $attrs, $display); return XMLStringer::estring('a', $attrs, $display);
} }