Index: openacs-4/packages/acs-content-repository/acs-content-repository.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/acs-content-repository.info,v diff -u -r1.22 -r1.23 --- openacs-4/packages/acs-content-repository/acs-content-repository.info 17 May 2003 09:41:08 -0000 1.22 +++ openacs-4/packages/acs-content-repository/acs-content-repository.info 7 Jul 2003 12:25:53 -0000 1.23 @@ -7,7 +7,7 @@ t t - + oracle postgresql @@ -18,7 +18,7 @@ 2002-10-27 OpenACS - + Index: openacs-4/packages/acs-content-repository/sql/oracle/content-template.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/oracle/content-template.sql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/acs-content-repository/sql/oracle/content-template.sql 24 Mar 2001 22:00:48 -0000 1.1 +++ openacs-4/packages/acs-content-repository/sql/oracle/content-template.sql 7 Jul 2003 12:25:53 -0000 1.2 @@ -22,7 +22,9 @@ function new ( name in cr_items.name%TYPE, + text in varchar2 default null, parent_id in cr_items.parent_id%TYPE default null, + is_live in char default 't', template_id in cr_templates.template_id%TYPE default null, creation_date in acs_objects.creation_date%TYPE default sysdate, @@ -54,8 +56,10 @@ v_template_id := content_item.new ( item_id => content_template.new.template_id, name => content_template.new.name, + text => content_template.new.text, parent_id => v_parent_id, content_type => 'content_template', + is_live => content_template.new.is_live, creation_date => content_template.new.creation_date, creation_user => content_template.new.creation_user, creation_ip => content_template.new.creation_ip Index: openacs-4/packages/acs-content-repository/sql/oracle/packages-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/oracle/packages-create.sql,v diff -u -r1.8 -r1.9 --- openacs-4/packages/acs-content-repository/sql/oracle/packages-create.sql 17 May 2003 09:42:02 -0000 1.8 +++ openacs-4/packages/acs-content-repository/sql/oracle/packages-create.sql 7 Jul 2003 12:25:53 -0000 1.9 @@ -1378,7 +1378,10 @@ -- @param name The name for the template, must be a valid UNIX-like filename. -- If a template with this name already exists under the specified -- parent item, an error is thrown + -- @param text The body of the .adp template itself, defaults to null -- @param parent_id The parent of this item, defaults to null + -- @param is_live The should the revision be set live, defaults to 't'. Requires + -- that text is not null or there will be no revision to begin with -- @param template_id The id of the new template. A new id will be allocated if this -- parameter is null -- @param creation_date As in acs_object.new @@ -1389,7 +1392,9 @@ -- {content_type.register_template} --*/ name in cr_items.name%TYPE, + text in varchar2 default null, parent_id in cr_items.parent_id%TYPE default null, + is_live in char default 't', template_id in cr_templates.template_id%TYPE default null, creation_date in acs_objects.creation_date%TYPE default sysdate, Index: openacs-4/packages/acs-content-repository/sql/oracle/upgrade/upgrade-4.6.5-4.7d6.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/oracle/upgrade/upgrade-4.6.5-4.7d6.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-content-repository/sql/oracle/upgrade/upgrade-4.6.5-4.7d6.sql 7 Jul 2003 12:25:53 -0000 1.1 @@ -0,0 +1,7 @@ +-- Upgrade content_template.new() and make it take an optional text parameter. +-- If it is provided, a revision of the template will be created automatically. +-- You thus avoid calling content_revision.new() in a separate step ... +-- (ola@polyxena.net) + +@@ ../packages-create.sql +@@ ../content-item.sql Index: openacs-4/packages/acs-content-repository/sql/oracle/upgrade/upgrade-4.7d1-4.7d6.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/oracle/upgrade/upgrade-4.7d1-4.7d6.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-content-repository/sql/oracle/upgrade/upgrade-4.7d1-4.7d6.sql 7 Jul 2003 12:25:53 -0000 1.1 @@ -0,0 +1,7 @@ +-- Upgrade content_template.new() and make it take an optional text parameter. +-- If it is provided, a revision of the template will be created automatically. +-- You thus avoid calling content_revision.new() in a separate step ... +-- (ola@polyxena.net) + +@@ ../packages-create.sql +@@ ../content-item.sql Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-template.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-template.sql,v diff -u -r1.8 -r1.9 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-template.sql 17 May 2003 09:43:09 -0000 1.8 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-template.sql 7 Jul 2003 12:25:53 -0000 1.9 @@ -35,6 +35,7 @@ end;' language 'plpgsql'; -- function new + create function content_template__new (varchar,integer,integer,timestamptz,integer,varchar) returns integer as ' declare @@ -93,6 +94,85 @@ end;' language 'plpgsql'; +create or replace function content_template__new(varchar,text,bool) returns integer as ' +declare + new__name alias for $1; + new__text alias for $2; + new__is_live alias for $3; +begin + return content_template__new(new__name, + null, + null, + now(), + null, + null, + new__text, + new__is_live + ); + +end;' language 'plpgsql'; + + +create or replace function content_template__new (varchar,integer,integer,timestamptz,integer,varchar,text,bool) +returns integer as ' +declare + new__name alias for $1; + new__parent_id alias for $2; -- default null + new__template_id alias for $3; -- default null + new__creation_date alias for $4; -- default now() + new__creation_user alias for $5; -- default null + new__creation_ip alias for $6; -- default null + new__text alias for $7; -- default null + new__is_live alias for $8; -- default ''f'' + v_template_id cr_templates.template_id%TYPE; + v_parent_id cr_items.parent_id%TYPE; +begin + + if new__parent_id is null then + v_parent_id := content_template_globals.c_root_folder_id; + else + v_parent_id := new__parent_id; + end if; + + -- make sure we''re allowed to create a template in this folder + if content_folder__is_folder(new__parent_id) = ''t'' and + content_folder__is_registered(new__parent_id,''content_template'',''f'') = ''f'' then + + raise EXCEPTION ''-20000: This folder does not allow templates to be created''; + + else + v_template_id := content_item__new ( + new__template_id, -- new__item_id + new__name, -- new__name + v_parent_id, -- new__parent_id + null, -- new__title + new__creation_date, -- new__creation_date + new__creation_user, -- new__creation_user + null, -- new__context_id + new__creation_ip, -- new__creation_ip + new__is_live, -- new__is_live + ''text/plain'', -- new__mime_type + new__text, -- new__text + ''text'', -- new__storage_type + ''t'', -- new__security_inherit_p + ''CR_FILES'', -- new__storage_area_key + ''content_item'', -- new__item_subtype + ''content_template'' -- new__content_type + ); + + insert into cr_templates ( + template_id + ) values ( + v_template_id + ); + + return v_template_id; + + end if; + +end;' language 'plpgsql'; + + -- procedure delete create function content_template__delete (integer) returns integer as ' Index: openacs-4/packages/acs-content-repository/sql/postgresql/upgrade/upgrade-4.6.5-4.7d6.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/upgrade/upgrade-4.6.5-4.7d6.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-content-repository/sql/postgresql/upgrade/upgrade-4.6.5-4.7d6.sql 7 Jul 2003 12:25:53 -0000 1.1 @@ -0,0 +1,83 @@ +-- Make two new versions of content_template__new() and make the one that is a wrapper +-- (the first one) take two new params; new__text and new__is_live. +-- With this version, a revision of the template will be created automatically. +-- You thus avoid calling content_revision.new() in a separate step ... +-- (ola@polyxena.net) + +create or replace function content_template__new(varchar,text,bool) returns integer as ' +declare + new__name alias for $1; + new__text alias for $2; + new__is_live alias for $3; +begin + return content_template__new(new__name, + null, + null, + now(), + null, + null, + new__text, + new__is_live + ); + +end;' language 'plpgsql'; + + +create or replace function content_template__new (varchar,integer,integer,timestamptz,integer,varchar,text,bool) +returns integer as ' +declare + new__name alias for $1; + new__parent_id alias for $2; -- default null + new__template_id alias for $3; -- default null + new__creation_date alias for $4; -- default now() + new__creation_user alias for $5; -- default null + new__creation_ip alias for $6; -- default null + new__text alias for $7; -- default null + new__is_live alias for $8; -- default ''f'' + v_template_id cr_templates.template_id%TYPE; + v_parent_id cr_items.parent_id%TYPE; +begin + + if new__parent_id is null then + v_parent_id := content_template_globals.c_root_folder_id; + else + v_parent_id := new__parent_id; + end if; + + -- make sure we''re allowed to create a template in this folder + if content_folder__is_folder(new__parent_id) = ''t'' and + content_folder__is_registered(new__parent_id,''content_template'',''f'') = ''f'' then + + raise EXCEPTION ''-20000: This folder does not allow templates to be created''; + + else + v_template_id := content_item__new ( + new__template_id, -- new__item_id + new__name, -- new__name + v_parent_id, -- new__parent_id + null, -- new__title + new__creation_date, -- new__creation_date + new__creation_user, -- new__creation_user + null, -- new__context_id + new__creation_ip, -- new__creation_ip + new__is_live, -- new__is_live + ''text/plain'', -- new__mime_type + new__text, -- new__text + ''text'', -- new__storage_type + ''t'', -- new__security_inherit_p + ''CR_FILES'', -- new__storage_area_key + ''content_item'', -- new__item_subtype + ''content_template'' -- new__content_type + ); + + insert into cr_templates ( + template_id + ) values ( + v_template_id + ); + + return v_template_id; + + end if; + +end;' language 'plpgsql'; Index: openacs-4/packages/acs-content-repository/sql/postgresql/upgrade/upgrade-4.7d1-4.7d6.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/upgrade/upgrade-4.7d1-4.7d6.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-content-repository/sql/postgresql/upgrade/upgrade-4.7d1-4.7d6.sql 7 Jul 2003 12:25:53 -0000 1.1 @@ -0,0 +1,83 @@ +-- Make two new versions of content_template__new() and make the one that is a wrapper +-- (the first one) take two new params; new__text and new__is_live. +-- With this version, a revision of the template will be created automatically. +-- You thus avoid calling content_revision.new() in a separate step ... +-- (ola@polyxena.net) + +create or replace function content_template__new(varchar,text,bool) returns integer as ' +declare + new__name alias for $1; + new__text alias for $2; + new__is_live alias for $3; +begin + return content_template__new(new__name, + null, + null, + now(), + null, + null, + new__text, + new__is_live + ); + +end;' language 'plpgsql'; + + +create or replace function content_template__new (varchar,integer,integer,timestamptz,integer,varchar,text,bool) +returns integer as ' +declare + new__name alias for $1; + new__parent_id alias for $2; -- default null + new__template_id alias for $3; -- default null + new__creation_date alias for $4; -- default now() + new__creation_user alias for $5; -- default null + new__creation_ip alias for $6; -- default null + new__text alias for $7; -- default null + new__is_live alias for $8; -- default ''f'' + v_template_id cr_templates.template_id%TYPE; + v_parent_id cr_items.parent_id%TYPE; +begin + + if new__parent_id is null then + v_parent_id := content_template_globals.c_root_folder_id; + else + v_parent_id := new__parent_id; + end if; + + -- make sure we''re allowed to create a template in this folder + if content_folder__is_folder(new__parent_id) = ''t'' and + content_folder__is_registered(new__parent_id,''content_template'',''f'') = ''f'' then + + raise EXCEPTION ''-20000: This folder does not allow templates to be created''; + + else + v_template_id := content_item__new ( + new__template_id, -- new__item_id + new__name, -- new__name + v_parent_id, -- new__parent_id + null, -- new__title + new__creation_date, -- new__creation_date + new__creation_user, -- new__creation_user + null, -- new__context_id + new__creation_ip, -- new__creation_ip + new__is_live, -- new__is_live + ''text/plain'', -- new__mime_type + new__text, -- new__text + ''text'', -- new__storage_type + ''t'', -- new__security_inherit_p + ''CR_FILES'', -- new__storage_area_key + ''content_item'', -- new__item_subtype + ''content_template'' -- new__content_type + ); + + insert into cr_templates ( + template_id + ) values ( + v_template_id + ); + + return v_template_id; + + end if; + +end;' language 'plpgsql'; Index: openacs-4/packages/acs-content-repository/tcl/filter-procs-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/filter-procs-oracle.xql,v diff -u -r1.6 -r1.7 --- openacs-4/packages/acs-content-repository/tcl/filter-procs-oracle.xql 17 May 2003 09:43:54 -0000 1.6 +++ openacs-4/packages/acs-content-repository/tcl/filter-procs-oracle.xql 7 Jul 2003 12:25:53 -0000 1.7 @@ -3,14 +3,6 @@ oracle8.1.6 - - - - , content.blob_to_string(content) as text - - - - @@ -95,9 +87,8 @@ select - (select live_revision from cr_items where item_id = content_item.get_template(:item_id, :context)) as template_id, - content_template.get_path( - content_item.get_template(:item_id, :context),:template_root) as template_url + content_item.get_live_revision(content_item.get_template(:item_id, :context)) as template_id, + content_template.get_path(content_item.get_template(:item_id, :context), :template_root) as template_url from dual Index: openacs-4/packages/acs-content-repository/tcl/filter-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/filter-procs-postgresql.xql,v diff -u -r1.8 -r1.9 --- openacs-4/packages/acs-content-repository/tcl/filter-procs-postgresql.xql 17 May 2003 09:43:54 -0000 1.8 +++ openacs-4/packages/acs-content-repository/tcl/filter-procs-postgresql.xql 7 Jul 2003 12:25:53 -0000 1.9 @@ -2,14 +2,6 @@ postgresql7.1 - - - - , content as text - - - - @@ -79,12 +71,12 @@ select - (select live_revision from cr_items where item_id = content_item__get_template(:item_id, :context)) as template_id, - content_template__get_path( - content_item__get_template(:item_id, :context),:template_root) as template_url + content_item__get_live_revision(content_item__get_template(:item_id, :context)) as template_id, + content_template__get_path(content_item__get_template(:item_id, :context),:template_root) as template_url from dual + Index: openacs-4/packages/acs-content-repository/tcl/filter-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/filter-procs.tcl,v diff -u -r1.12 -r1.13 --- openacs-4/packages/acs-content-repository/tcl/filter-procs.tcl 17 May 2003 09:43:54 -0000 1.12 +++ openacs-4/packages/acs-content-repository/tcl/filter-procs.tcl 7 Jul 2003 12:25:53 -0000 1.13 @@ -62,7 +62,7 @@ return $item_id } -ad_proc -public get_content {} { +ad_proc -public get_content { { content_type {} } } { variable item_id variable revision_id @@ -88,14 +88,16 @@ return } - if { [string equal [lindex [split $mime_type "/"] 0] "text"] } { + if { [string equal -length 4 "text" $mime_type] } { set text_sql [db_map content_as_text] } else { set text_sql "" } # Get the content type - set content_type [db_string get_content_type ""] + if { [empty_string_p $content_type] } { + set content_type [db_string get_content_type ""] + } # Get the table name set table_name [db_string get_table_name ""] @@ -152,7 +154,7 @@ } -ad_proc -public init { urlvar rootvar {content_root ""} {template_root ""} {context "public"} {rev_id ""}} { +ad_proc -public init { urlvar rootvar {content_root ""} {template_root ""} {context "public"} {rev_id ""} {content_type ""} } { upvar $urlvar url $rootvar root_path @@ -181,7 +183,9 @@ set item_url $url set item_id $item_info(item_id) - set content_type $item_info(content_type) + if { [empty_string_p $content_type] } { + set content_type $item_info(content_type) + } # Make sure that a live revision exists if [empty_string_p $rev_id] { @@ -221,6 +225,38 @@ template::util::write_file $file $text } + set file ${root_path}/${url}.tcl + if ![file exists $file] { + + file mkdir [file dirname $file] + set text "\# Put the current revision's attributes in a onerow datasource named \"content\". +\# The detected content type is \"$content_type\". + +content::get_content $content_type + +if { !\[string equal -length 4 \"text\" \$content(mime_type)\] } { + \# It's a file. + cr_write_content -revision_id \$content(revision_id) + ad_script_abort +} + +\# Ordinary text/* mime type. +template::util::array_to_vars content + +set text \[cr_write_content -string -revision_id \$revision_id\] + +set text \[ad_html_text_convert -from \$mime_type -to text/html \$text\] + +set context {\$title} + +ad_return_template +" + + template::util::write_file $file $text + } + + + return 1 } Index: openacs-4/packages/acs-content-repository/tcl/filter-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/filter-procs.xql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/acs-content-repository/tcl/filter-procs.xql 17 May 2003 09:43:54 -0000 1.3 +++ openacs-4/packages/acs-content-repository/tcl/filter-procs.xql 7 Jul 2003 12:25:53 -0000 1.4 @@ -36,12 +36,19 @@ + + + + , content as text + + + + select x.*, - :item_id as item_id $text_sql, :content_type as content_type $text_sql from Index: openacs-4/packages/acs-content-repository/tcl/item-procs-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/Attic/item-procs-oracle.xql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-content-repository/tcl/item-procs-oracle.xql 17 May 2003 09:43:54 -0000 1.2 +++ openacs-4/packages/acs-content-repository/tcl/item-procs-oracle.xql 7 Jul 2003 12:25:53 -0000 1.3 @@ -26,7 +26,7 @@ - select content_item.get_path(:item_id) from dual + select content_item.get_path(:item_id, $root_folder_id) from dual Index: openacs-4/packages/acs-content-repository/tcl/item-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/Attic/item-procs-postgresql.xql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-content-repository/tcl/item-procs-postgresql.xql 17 May 2003 09:43:54 -0000 1.2 +++ openacs-4/packages/acs-content-repository/tcl/item-procs-postgresql.xql 7 Jul 2003 12:25:53 -0000 1.3 @@ -27,7 +27,7 @@ - select content_item__get_path(:item_id, null) + select content_item__get_path(:item_id, $root_folder_id) Index: openacs-4/packages/acs-content-repository/tcl/item-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/Attic/item-procs.tcl,v diff -u -r1.6 -r1.7 --- openacs-4/packages/acs-content-repository/tcl/item-procs.tcl 17 May 2003 09:43:54 -0000 1.6 +++ openacs-4/packages/acs-content-repository/tcl/item-procs.tcl 7 Jul 2003 12:25:53 -0000 1.7 @@ -77,15 +77,20 @@ } -ad_proc -public item::get_url { item_id } { +ad_proc -public item::get_url { + item_id + {-root_folder_id "null"} +} { @public get_url Retrieves the relative URL stub to th item. The URL is relative to the page root, and has no extension (Example: "/foo/bar/baz"). - @param item_id The item id - + @param item_id The item id + @param root_folder_id Starts path resolution from this folder. + Defaults to the root of the sitemap (when null). + @return The relative URL to the item, or an empty string on failure @see proc item::get_extended_url Index: openacs-4/packages/acs-content-repository/tcl/revision-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/revision-procs.tcl,v diff -u -r1.9 -r1.10 --- openacs-4/packages/acs-content-repository/tcl/revision-procs.tcl 17 May 2003 09:43:54 -0000 1.9 +++ openacs-4/packages/acs-content-repository/tcl/revision-procs.tcl 7 Jul 2003 12:25:53 -0000 1.10 @@ -1,15 +1,19 @@ # upload an item revision from a file ad_proc -public cr_write_content { + -string:boolean -item_id -revision_id } { + @param string specifies whether the content should be returned as a string + or (the default) be written to the HTML connection (ola@polyxena.net) @param item_id the item to write @param revision_id revision to write @author Don Baccus (dhogaza@pacifier.com) - Write out the specified content to the current HTML connection. Only one of + Write out the specified content to the current HTML connection or return + it to the caller by using the -string flag. Only one of item_id and revision_id should be passed to this procedure. If item_id is provided the item's live revision will be written, otherwise the specified revision. @@ -50,16 +54,23 @@ switch $storage_type { - text { + text { + set text [db_string write_text_content ""] + if { $string_p } { + return $text + } ReturnHeaders $mime_type - ns_write [db_string write_text_content ""] + ns_write $text } file { set path [cr_fs_path $storage_area_key] set filename [db_string write_file_content ""] ns_returnfile 200 $mime_type $filename } lob { + if { $string_p } { + return [db_blob_get write_lob_content ""] + } ReturnHeaders $mime_type db_write_blob write_lob_content "" } Index: openacs-4/packages/acs-content-repository/www/index.vuh =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/www/index.vuh,v diff -u -r1.7 -r1.8 --- openacs-4/packages/acs-content-repository/www/index.vuh 23 Feb 2003 18:19:19 -0000 1.7 +++ openacs-4/packages/acs-content-repository/www/index.vuh 7 Jul 2003 12:25:53 -0000 1.8 @@ -11,23 +11,22 @@ } # Get the paths -set the_url [ad_conn path_info] -set package_key [ad_conn package_key] set the_root [ns_info pageroot] +set the_url [ad_conn path_info] +set content_type "" + # Get the IDs -set content_root \ - [db_string content_root "select content_item.get_root_folder from dual"] -set template_root \ - [db_string template_root "select content_template.get_root_folder from dual"] +set content_root [db_string content_root ""] +set template_root [db_string template_root ""] # Serve the page # DRB: Note that content::init modifies the local variable the_root, which is treated # as though it's been passed by reference. This requires that the redirect treat the # path as an absolute path within the filesystem. -if { [content::init the_url the_root $content_root $template_root public $revision_id] } { +if { [content::init the_url the_root $content_root $template_root public $revision_id $content_type] } { set file "$the_root/$the_url" rp_internal_redirect -absolute_path $file } else {