Index: openacs-4/packages/xowiki/tcl/link-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/link-procs.tcl,v diff -u -r1.106 -r1.107 --- openacs-4/packages/xowiki/tcl/link-procs.tcl 27 Jun 2018 12:07:09 -0000 1.106 +++ openacs-4/packages/xowiki/tcl/link-procs.tcl 3 Sep 2024 15:37:55 -0000 1.107 @@ -11,71 +11,73 @@ # generic link methods # Class create BaseLink -parameter { - cssclass cssid href label title target extra_query_parameter + cssclass cssid href label title target extra_query_parameter {anchor ""} {query ""} } BaseLink instproc built_in_target {} { # currently, we do not support named frames, which are mostly deprecated - return [expr {[:target] in {_blank _self _parent _top}}] + return [expr {${:target} in {_blank _self _parent _top}}] } - + BaseLink instproc anchor_atts {} { set atts {} - if {[info exists :title]} {lappend atts "title='[string map [list ' {'}] [:title]]'"} + if {[info exists :title]} {lappend atts "title='[string map [list ' {'}] ${:title}]'"} if {[info exists :target] && [:built_in_target]} { - lappend atts "target='[:target]'" + lappend atts "target='${:target}'" } return [join $atts " "] } BaseLink instproc mk_css_class {{-additional ""} {-default ""}} { - set cls [expr {[info exists :cssclass] ? [:cssclass] : $default}] + set cls [expr {[info exists :cssclass] ? ${:cssclass} : $default}] if {$additional ne ""} { if {$cls eq ""} {set cls $additional} else {append cls " " $additional} } if {$cls ne ""} {set cls "class='$cls'"} - return $cls + return $cls } BaseLink instproc mk_css_class_and_id {{-additional ""} {-default ""}} { - if {[info exists :cssid]} {set id "id='[:cssid]'"} else {set id ""} + if {[info exists :cssid]} {set id "id='${:cssid}'"} else {set id ""} set cls [:mk_css_class -additional $additional -default $default] return [string trim "$cls $id"] } # # external links # - Class create ExternalLink -superclass BaseLink + Class create ExternalLink -superclass BaseLink ExternalLink instproc render {} { set css_atts [:mk_css_class_and_id -additional external] - return "[ns_quotehtml ${:label}] " + return "${:label}" } # # internal links # Class create Link -superclass BaseLink -parameter { - {type link} name lang stripped_name page + {type link} name lang stripped_name page parent_id package_id item_id {form ""} revision_id is_self_link } Link instproc init {} { - set class [self class]::[:type] + #:log "--L link '${:name}' has item_id <[expr {[info exists :item_id] ? ${:item_id} : {none}}]>" + set class [self class]::${:type} if {[:isclass $class]} {:class $class} if {![info exists :name]} { - set :name [string trimleft [:lang]:${:stripped_name} :] + set :name [string trimleft ${:lang}:${:stripped_name} :] } elseif {![info exists :stripped_name]} { # set stripped name and lang from provided name or to the default if {![regexp {^(..):(.*)$} ${:name} _ lang :stripped_name]} { - set :stripped_name ${:name}; set :lang "" + set :stripped_name ${:name} + set :lang "" } } if {![info exists :label]} {set :label ${:name}} if {![info exists :parent_id]} {set :parent_id [${:page} parent_id]} if {![info exists :package_id]} {set :package_id [${:page} package_id]} - #:msg "--L link has class [:info class] // $class // [:type] // ${:parent_id}" + #:log "--L link '${:name}' has class [:info class] // $class // ${:type} // parent ${:parent_id} // page ${:page} // [info exists :item_id]" } Link instproc link_name {-lang -stripped_name} { return $lang:$stripped_name @@ -86,8 +88,7 @@ Link instproc render_target {href label} { #ns_log notice render_target - set target [:target] - if {[info commands ::xowiki::template::$target] ne ""} { + if {[info commands ::xowiki::template::${:target}] ne ""} { # # The target template exists. Use the template # @@ -97,38 +98,37 @@ # can be referenced multiple times. The link is included for # each occurrence. # - set item_id ${:item_id} - set targetId [xowiki::Includelet html_id ${:item_id}-$target] - set page [::xo::db::CrClass get_instance_from_db -item_id $item_id -revision_id 0] + set targetId [xowiki::Includelet html_id ${:item_id}-${:target}] + set page [::xo::db::CrClass get_instance_from_db -item_id ${:item_id} -revision_id 0] set content "Loading ..." set withBody true - - if {[::xowiki::template::$target render_content]} { + + if {[::xowiki::template::${:target} render_content]} { set key ::__xowiki_link_rendered($targetId) if {![info exists $key]} { set $key 1 set content [$page render_content] } else { #ns_log notice "modal with is already included: $key" - set page ::$item_id + set page ::${:item_id} set withBody false } } - set result [::xowiki::template::$target render \ + set result [::xowiki::template::${:target} render \ -with_body $withBody \ -title [$page title] \ -id $targetId \ -content $content \ -label $label \ -href $href] - + return $result } else { - ns_log notice "xowiki::link: unknown target $target" + ns_log notice "xowiki::link: unknown target ${:target}" return "$label" } } - + Link instproc render_found {href label} { if {$href eq ""} { return "$label" @@ -142,57 +142,75 @@ if {$href eq ""} { return \[$label\] } else { - return " $label" + return "$label" } } Link instproc pretty_link {item_id} { - return [::${:package_id} pretty_link -parent_id ${:parent_id} -lang [:lang] \ - -anchor [:anchor] -query [:query] [:name]] + if {$item_id == 0} { + set pageArg "" + } else { + set obj ::$item_id + if {![nsf::is object $obj]} { + set obj [::xo::db::CrClass get_instance_from_db -item_id $item_id] + } + set pageArg [list -page $obj] + } + return [::${:package_id} pretty_link \ + -parent_id ${:parent_id} \ + -lang ${:lang} \ + -anchor ${:anchor} \ + -query ${:query} \ + {*}$pageArg \ + ${:name}] } Link instproc new_link {} { - set page [:page] - set nls_language [$page get_nls_language_from_lang [:lang]] + set nls_language [${:page} get_nls_language_from_lang ${:lang}] if {${:form} ne ""} { - return [${:package_id} make_form_link -form ${:form} \ + return [::${:package_id} make_form_link \ + -form ${:form} \ -parent_id ${:parent_id} \ - -name [:name] \ + -name ${:name} \ -nls_language $nls_language] } - if {[$page exists __unresolved_object_type]} { + if {[${:page} exists __unresolved_object_type]} { + # # get the desired object_type for unresolved entries - set object_type [$page set __unresolved_object_type] + # + set object_type [${:page} set __unresolved_object_type] } else { - set object_type [[$page info class] set object_type] + set object_type [[${:page} info class] set object_type] if {$object_type ne "::xowiki::Page" && $object_type ne "::xowiki::PlainPage"} { + # # TODO: this is a temporary solution. We should find a way to # pass similar to file or image entries the type of this # entry. Maybe we can get the type as well from a kind of # blackboard, where the type of the "edit" wiki-menu-entry is # stored as well. + # set object_type ::xowiki::Page } } - return [$page new_link \ + return [${:page} new_link \ {*}[expr {[info exists object_type] ? [list -object_type $object_type] : {}}] \ - -name [:name] -title [:label] -parent_id ${:parent_id} \ + -name ${:name} -title ${:label} -parent_id ${:parent_id} \ -nls_language $nls_language ${:package_id}] } Link instproc render {} { - set page [:page] set item_id [:resolve] if {$item_id} { - $page references resolved [list $item_id [:type]] + ${:page} references resolved [list $item_id ${:type}] ::xowiki::Package require ${:package_id} if {![info exists :href]} { set :href [:pretty_link $item_id] } - :render_found ${:href} [:label] + :render_found ${:href} ${:label} } else { set new_link [:new_link] - set html [:render_not_found $new_link [:label]] - $page references unresolved $html + set html [:render_not_found $new_link ${:label}] + ${:page} references unresolved \ + [list parent_id ${:parent_id} name ${:name} link_type ${:type} html $html] return $html } } @@ -205,7 +223,7 @@ set package_id [site_node::get_children -node_id $a -package_key xowiki \ -filters [list name $name] -element package_id] if {$package_id ne ""} { - #:log "--LINK found package_id=$package_id [:isobject ::$package_id]" + #:log "--LINK found package_id=$package_id [nsf::is object ::$package_id]" ::xowiki::Package require $package_id return $package_id } @@ -226,114 +244,114 @@ {-label "LABEL"} {-href ""} } { - set result "" + set result "" # this can be used into templates as id to safely attach event # handlers to elements - set timed_id [clock microseconds] + set timed_id [clock microseconds] if {$with_link} {append result [subst [:link_template]]} if {$with_body} {append result [subst [:body_template]]} return $result } - # - # Small bootstrap modal - # - ::xowiki::LinkTemplate create ::xowiki::template::modal-sm -link_template { - $label - } -body_template { -
- } +# # +# # Small bootstrap modal +# # +# ::xowiki::LinkTemplate create ::xowiki::template::modal-sm -link_template { +# $label +# } -body_template { +# +# } - # - # Large bootstrap modal - # - ::xowiki::LinkTemplate create ::xowiki::template::modal-lg -link_template { - $label - } -body_template { - - } +# # +# # Large bootstrap modal +# # +# ::xowiki::LinkTemplate create ::xowiki::template::modal-lg -link_template { +# $label +# } -body_template { +# +# } - # - # Small bootstrap modal using ajax - # - ::xowiki::LinkTemplate create ::xowiki::template::modal-sm-ajax -render_content false -link_template { - $label - } -body_template { - - - } +# # +# # Small bootstrap modal using ajax +# # +# ::xowiki::LinkTemplate create ::xowiki::template::modal-sm-ajax -render_content false -link_template { +# $label +# } -body_template { +# +# +# } - # - # Large bootstrap modal using ajax - # - ::xowiki::LinkTemplate create ::xowiki::template::modal-lg-ajax -render_content false -link_template { -$label - } -body_template { - - -} +# # +# # Large bootstrap modal using ajax +# # +# ::xowiki::LinkTemplate create ::xowiki::template::modal-lg-ajax -render_content false -link_template { +# $label +# } -body_template { +# +# +# } # # folder links @@ -343,8 +361,11 @@ return $stripped_name } ::xowiki::Link::folder instproc pretty_link {item_id} { + set page [expr {$item_id == 0 ? "" : "-page ::$item_id"}] return [::${:package_id} pretty_link \ - -anchor [:anchor] -parent_id ${:parent_id} -query [:query] ${:name} ] + -anchor ${:anchor} -parent_id ${:parent_id} -query ${:query} \ + {*}$page \ + ${:name} ] } # @@ -354,25 +375,27 @@ return_only } ::xowiki::Link::language instproc render {} { - set page [:page] set item_id [:resolve] if {$item_id} { set image_css_class "found" - set link [${:package_id} pretty_link -lang ${:lang} -parent_id ${:parent_id} [:stripped_name]] + set link [::${:package_id} pretty_link \ + -lang ${:lang} -parent_id ${:parent_id} \ + -page $item_id \ + ${:stripped_name}] } else { set image_css_class "undefined" - set last_page_id [$page set item_id] - set object_type [[$page info class] set object_type] + set last_page_id [${:page} set item_id] + set object_type [[${:page} info class] set object_type] set name ${:name} - set link [${:package_id} make_link ${:package_id} \ + set link [::${:package_id} make_link ${:package_id} \ edit-new object_type name last_page_id] } # :log "--lang_link=$link" - if {[info exists :return_only] && [:return_only] ne $image_css_class} { + if {[info exists :return_only] && ${:return_only} ne $image_css_class} { set link "" } if {$link ne ""} { - $page lappend lang_links($image_css_class) \ + ${:page} lappend lang_links($image_css_class) \ "" } @@ -382,16 +405,16 @@ # # image links # - + Class create ::xowiki::Link::image -superclass ::xowiki::Link \ -parameter { - center float width height + center float width height padding padding-right padding-left padding-top padding-bottom margin margin-left margin-right margin-top margin-bottom - border border-width position top botton left right + border border-width position top bottom left right } ::xowiki::Link::image instproc resolve_href {href} { - set l [[:page] create_link $href] + set l [${:page} create_link $href] if {[$l istype ::xowiki::ExternalLink]} { set href [$l href] } else { @@ -401,26 +424,31 @@ return $href } ::xowiki::Link::image instproc render {} { - set page [:page] set item_id [:resolve] - #:log "-- image resolve for $page returned $item_id (name=${:name}, label=${:label})" - if {$item_id} { - set link [${:package_id} pretty_link -download true -query [:query] \ - -absolute [$page absolute_links] -parent_id ${:parent_id} ${:name}] - #:log "--l fully quali [$page absolute_links], link=$link" - $page references resolved [list $item_id [:type]] + #:log "-- image resolve for ${:page} returned $item_id (name=${:name}, label=${:label})" + if {$item_id != 0} { + set link [::${:package_id} pretty_link \ + -download true \ + -query ${:query} \ + -absolute [expr {[${:page} exists absolute_links] ? [${:page} absolute_links] : 0}] \ + -parent_id ${:parent_id} \ + -page $item_id \ + ${:name}] + #:log "--l fully quali [${:page} absolute_links], link=$link [info commands ::$item_id]" + ${:page} references resolved [list $item_id ${:type}] :render_found $link ${:label} } else { - set last_page_id [$page set item_id] + set last_page_id [${:page} set item_id] set object_type ::xowiki::File set name ${:name} - set link [${:package_id} make_link ${:package_id} edit-new object_type \ + set link [::${:package_id} make_link ${:package_id} edit-new object_type \ [list parent_id ${:parent_id}] \ [list title [ad_html_to_text -no_format -- ${:label}]] \ [list return_url [::xo::cc url]] \ - autoname name last_page_id] + autoname name last_page_id] set html [:render_not_found $link ${:label}] - $page references unresolved $html + ${:page} references unresolved \ + [list parent_id ${:parent_id} name ${:name} link_type ${:type} html $html] return $html } } @@ -430,49 +458,81 @@ float width height center padding padding-right padding-left padding-top padding-bottom margin margin-left margin-right margin-top margin-bottom - border border-width position top botton left right + border border-width position top bottom left right } { if {[info exists :$a]} { if {$a eq "center"} {set pre "