Index: openacs-4/packages/attachments/www/go-to-attachment.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/go-to-attachment.tcl,v
diff -u -r1.12 -r1.12.2.1
--- openacs-4/packages/attachments/www/go-to-attachment.tcl 7 Aug 2017 23:48:04 -0000 1.12
+++ openacs-4/packages/attachments/www/go-to-attachment.tcl 11 Jul 2019 16:38:53 -0000 1.12.2.1
@@ -1,60 +1,76 @@
-
ad_page_contract {
Go to an attachment
-
+
@author Ben Adida (ben@openforce.net)
} {
{object_id:naturalnum,notnull}
{attachment_id:naturalnum,notnull}
}
-
+#
# We check permissions on the object
+#
permission::require_permission -object_id $object_id -privilege read
-
-# Get information about attachment
-set content_type [content::item::get_content_type -item_id $attachment_id]
-if { $content_type eq "" } {
+#
+# Get information about the attachment, and act depending on type
+#
+set object_type [acs_object_type $attachment_id]
+if {$object_type eq ""} {
+ #
+ # No object type
+ #
ad_return_complaint 1 [_ attachments.lt_No_such_attachment_fo]
return
-}
-
-switch $content_type {
- content_extlink {
- ad_returnredirect [db_string select_url {}]
- ad_script_abort
- return
+} elseif {[content::extlink::is_extlink -item_id $attachment_id]} {
+ #
+ # URL
+ #
+ ad_returnredirect [db_string select_url {}]
+ ad_script_abort
+ return
+} elseif {[content::item::is_subclass \
+ -object_type $object_type \
+ -supertype "content_item"]} {
+ #
+ # Content item, or subtype
+ #
+ db_1row select_attachment_info {}
+ if {[parameter::get -package_id $package_id -parameter BehaveLikeFilesystemP -default 0]} {
+ set filename $title
+ } else {
+ set filename $name
}
-
- file_storage_object {
- db_1row select_attachment_info {}
- if {[parameter::get -package_id $package_id -parameter BehaveLikeFilesystemP -default 0]} {
- set filename $title
- } else {
- set filename $name
- }
-
- # Test if the filename contains the extension, otherwise append it
- # This usually happens if you just rename the title (displayed filename) but forget
- # to append the extension to it.
-
- #file extension return "." extension without "."
- set file_extension_aux [concat .$file_extension]
-
- set extension [file extension $filename]
- if {$extension ne $file_extension_aux} {
- append filename ".${file_extension}"
- }
-
- ad_returnredirect "download/[ad_urlencode $filename]?object_id=$object_id&attachment_id=$attachment_id"
- ad_script_abort
- return
- }
-
- default {
- ad_return_complaint 1 [_ attachments.lt_dont_know_how_to_deal [list content_type $content_type]]
- return
- }
+} elseif {[content::item::is_subclass \
+ -object_type $object_type \
+ -supertype "content_revision"]} {
+ #
+ # Content revision, or subtype
+ #
+ db_1row select_attachment_info_specific_revision {}
+ set filename $title
+} else {
+ #
+ # Not a known object type, just give up
+ #
+ ad_return_complaint 1 [_ attachments.lt_dont_know_how_to_deal [list content_type $content_type]]
+ return
}
+#
+# Test if the filename contains the extension, otherwise append it
+# This usually happens if you just rename the title (displayed filename) but
+# forget to append the extension to it.
+#
+#file extension return "." extension without "."
+set file_extension_aux [concat .$file_extension]
+set extension [file extension $filename]
+if {$extension ne $file_extension_aux} {
+ append filename ".${file_extension}"
+}
+#
+# Redirect finally
+#
+ad_returnredirect "download/[ad_urlencode $filename]?object_id=$object_id&attachment_id=$attachment_id"
+ad_script_abort
+return
# Local variables:
# mode: tcl
Index: openacs-4/packages/attachments/www/go-to-attachment.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/go-to-attachment.xql,v
diff -u -r1.6 -r1.6.10.1
--- openacs-4/packages/attachments/www/go-to-attachment.xql 15 May 2007 20:14:19 -0000 1.6
+++ openacs-4/packages/attachments/www/go-to-attachment.xql 11 Jul 2019 16:38:53 -0000 1.6.10.1
@@ -21,4 +21,18 @@
+
+
+ select r.title,
+ o.package_id,
+ m.file_extension
+ from cr_revisions r,
+ acs_objects o,
+ cr_mime_types m
+ where revision_id = :attachment_id
+ and r.revision_id = o.object_id
+ and m.mime_type= r.mime_type
+
+
+
Index: openacs-4/packages/attachments/www/download/index.vuh
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/download/index.vuh,v
diff -u -r1.3.2.1 -r1.3.2.2
--- openacs-4/packages/attachments/www/download/index.vuh 11 Jul 2019 16:01:34 -0000 1.3.2.1
+++ openacs-4/packages/attachments/www/download/index.vuh 11 Jul 2019 16:38:53 -0000 1.3.2.2
@@ -11,22 +11,46 @@
object_id:naturalnum,notnull
attachment_id:naturalnum,notnull
}
-
+#
# Permission check
+#
permission::require_permission -object_id $object_id -privilege read
-
-
-
-# Get the live version
-# (and check that this is the right attachment while we're at it)
-set version_id [db_string select_version_id {} -default {}]
-
+#
+# Double check if this is the right attachment, and get the live revision if the
+# object is a 'content_item' or subtype
+#
+set object_type [acs_object_type $attachment_id]
+if {$object_type eq ""} {
+ #
+ # No object type
+ #
+ set version_id ""
+} elseif {[content::item::is_subclass \
+ -object_type $object_type \
+ -supertype "content_item"]} {
+ #
+ # Content item, or subtype
+ #
+ set version_id [db_string select_version_id {} -default {}]
+} elseif {[content::item::is_subclass \
+ -object_type $object_type \
+ -supertype "content_revision"]} {
+ #
+ # Content revision, or subtype
+ #
+ set version_id [db_string select_version_id_revision {} -default {}]
+}
+#
+# Last check
+#
if {$version_id eq ""} {
- ad_return_complaint 1 "bad attachment"
+ ad_return_complaint 1 [_ attachments.lt_No_such_attachment_fo]
ad_script_abort
return
}
-
+#
+# Good to go
+#
cr_write_content -revision_id $version_id
# Local variables:
Index: openacs-4/packages/attachments/www/download/index.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/attachments/www/download/index.xql,v
diff -u -r1.2 -r1.2.26.1
--- openacs-4/packages/attachments/www/download/index.xql 5 Aug 2002 21:11:55 -0000 1.2
+++ openacs-4/packages/attachments/www/download/index.xql 11 Jul 2019 16:38:54 -0000 1.2.26.1
@@ -10,5 +10,16 @@
and attachments.item_id = :attachment_id
-
+
+
+
+ select live_revision
+ from cr_items ci,
+ attachments at
+ where ci.live_revision = at.item_id
+ and at.item_id = :attachment_id
+ and at.object_id = :object_id;
+
+
+