Forum OpenACS Development: URL abstraction in oacs 3.4

Collapse
Posted by Dan Lazewatsky on
I know this has practically been discussed to death, but I haven't found a suitable solution.

I have a url of the form
http://myserver/package/page?id=1234
which I need to look like
http://myserver/package/somename
where I have a db mapping between id and somename.

All the solutions I've seen so far use vuh files which would be fine, but I'm not confident that my configuration supports that. I know this is possible to do (we have two packages that do this), but after digging through docs and code all day, I can't figure out how it's done, and of course, the other developers here who might know left and didn't leave any documentation.

Any suggestions would be much appreciated.

Collapse
Posted by Claudio Pasolini on
In the old OpenACS 3.x days they used ns_register_filter and ns_register_proc.
Collapse
Posted by Dan Lazewatsky on
3.3/3.4 actually changed to rp_register_directory_map. What I'm not sure about is that there are already two packages that do this, and I can't find where the calls to rp_register_directory_map are. acs-core/request-processor-init.tcl is where all the packages are registered, and seems like the logical place to do other custom directory mapping, but that's not where the existing calls are.
Collapse
Posted by Tom Jackson on
I'm guessing what you want is for users to visit the url path of /package/somename and then serve them /package/page?id=1234.

I can't figure out why you couldn't use an index.vuh file for this, unless one already exists for another purpose.

One complication is that if you use a .vuh file, you need to do a tiny amount of work before you can do a rp_internal_redirect. Here is an example page which does a url to query translation prior to doing the internal redirect:

ad_page_contract {

        Used Lab Equipment Searcher

} { {terms:trim ""}

} set urlv [ad_conn urlv] set urlc [ad_conn urlc]

set search "" set termCount 0 set title_words [list]

set mainkey [lindex $urlv 1] ns_log Notice "mainkey: $mainkey, urlv: $urlv"

if {[string eq "search" "$mainkey"]} { set urlv [split $terms] }

switch -exact -- $mainkey { "all" - "" { } "permalink" { set id [lindex $urlv end] rp_form_put ids.$id $id set title [db_string contentTitle " select content_title from cams_content where content_id = :id" -default ""] rp_form_put title $title } default { foreach original_term $urlv { set term $original_term if {[string match "*s" $term]} { set term [string range $term 0 end-1] } if {[string eq "lab" $term]} { continue } else { incr termCount lappend title_words $original_term set term "'%[string toupper [string map {' '' $ "" [ ""} $term]]%'" if {$termCount == 1} { append search "\n UPPER(\$column) like $term" } elseif {$termCount > 4} { break } else { append search "\n\$JOINER\n UPPER(\$column) like $term" } } } set title [join $title_words " : "] set JOINER "AND" set column content_title set FIRST_MATCH [subst $search] set sql " select content_id from cams_content where content_type_id = 472" set complete_sql "$sql AND $FIRST_MATCH" rp_form_put title $title set i 0 db_foreach "select_content_ids" $complete_sql { rp_form_put ids.$content_id $content_id incr i } if {$i == 0} { set JOINER "OR" set FIRST_MATCH [subst $search] set complete_sql "$sql AND $FIRST_MATCH limit 20" db_foreach "select_content_ids2" $complete_sql { rp_form_put ids.$content_id $content_id } } } }

rp_form_put content_type_id 472 set template "/packages/cams/www/one/one"

rp_internal_redirect "$template"