summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorZach Copley <zach@controlyourself.ca>2009-06-25 12:52:10 -0700
committerZach Copley <zach@controlyourself.ca>2009-06-25 12:52:10 -0700
commit27076227620d0beca7586affa8e89154a1648d70 (patch)
tree48432ac1b6ecf1559393da34fb1970f61348f98c /lib
parentc96572c0909793fd1f38def21f2577e13d98766d (diff)
Return clippy to his rightful place next to attachments
Diffstat (limited to 'lib')
-rw-r--r--lib/util.php35
1 files changed, 31 insertions, 4 deletions
diff --git a/lib/util.php b/lib/util.php
index 30b767c3e..f6d50b180 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -497,6 +497,22 @@ function common_linkify($url) {
$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'
// 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.
// I think the best option is another file_view table in the db
// 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'";
$file = new File;
$file->query($query);
$file->fetch();
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'";
$file2 = new File;
$file2->query($query);
$file2->fetch();
- if (empty($file2->file_id)) {
- $attrs['class'] = 'attachment';
- } else {
+ if (!empty($file2)) {
+ $has_thumb = true;
+ }
+ }
+
+ // Add clippy
+ if ($is_attachment) {
+ $attrs['class'] = 'attachment';
+ if ($has_thumb) {
$attrs['class'] = 'attachment thumbnail';
}
- $attrs['id'] = "attachment-{$file->file_id}";
+ $attrs['id'] = "attachment-{$attachment_id}";
}
+
return XMLStringer::estring('a', $attrs, $display);
}