Index: openacs-4/packages/xowiki/tcl/includelet-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/includelet-procs.tcl,v
diff -u -N
--- openacs-4/packages/xowiki/tcl/includelet-procs.tcl 5 Jun 2012 08:33:42 -0000 1.181
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,4529 +0,0 @@
-::xo::library doc {
- XoWiki - define various kind of includelets
-
- @creation-date 2006-10-10
- @author Gustaf Neumann
- @cvs-id $Id: includelet-procs.tcl,v 1.181 2012/06/05 08:33:42 gustafn Exp $
-}
-namespace eval ::xowiki::includelet {
- #
- # Define a meta-class for creating Includelet classes.
- # We use a meta-class for making it easier to define properties
- # on classes of includelets, which can be used without instantiating
- # it. One can for example use the query from the page fragment
- # cache the caching properties of the class.
- #
- Class create ::xowiki::IncludeletClass \
- -superclass ::xotcl::Class \
- -parameter {
- {localized true}
- {personalized true}
- {cacheable false}
- {aggregating false}
- }
-
- # The general superclass for includelets
-
- Class create ::xowiki::Includelet \
- -superclass ::xo::Context \
- -parameter {
- {name ""}
- {title ""}
- {__decoration "portlet"}
- {parameter_declaration {}}
- {id}
- }
-#2.8.0r4
- ::xowiki::Includelet proc require_YUI_CSS {{-version 2.7.0} {-ajaxhelper true} path} {
- if {$ajaxhelper} {
- ::xo::Page requireCSS "/resources/ajaxhelper/yui/$path"
- } else {
- ::xo::Page requireCSS "http://yui.yahooapis.com/$version/build/$path"
- }
- }
-
- ::xowiki::Includelet proc require_YUI_JS {{-version 2.7.0} {-ajaxhelper true} path} {
- if {$ajaxhelper} {
- ::xo::Page requireJS "/resources/ajaxhelper/yui/$path"
- } else {
- ::xo::Page requireJS "http://yui.yahooapis.com/$version/build/$path"
- }
- }
-
- ::xowiki::Includelet proc describe_includelets {includelet_classes} {
- #my log "--plc=$includelet_classes "
- foreach cl $includelet_classes {
- set result ""
- append result "{{[namespace tail $cl]"
- foreach p [$cl info parameter] {
- if {[llength $p] != 2} continue
- foreach {name value} $p break
- if {$name eq "parameter_declaration"} {
- foreach pp $value {
- #append result ""
- switch [llength $pp] {
- 1 {append result " $pp"}
- 2 {
- set v [lindex $pp 1]
- if {$v eq ""} {set v {""}}
- append result " [lindex $pp 0] $v"
- }
- }
- #append result "\n"
- }
- }
- }
- append result "}}\n"
- my set html([namespace tail $cl]) $result
- my describe_includelets [$cl info subclass]
- }
- }
- ::xowiki::Includelet proc available_includelets {} {
- if {[my array exists html]} {my array unset html}
- my describe_includelets [::xowiki::Includelet info subclass]
- set result "
"
- foreach d [lsort [my array names html]] {
- append result "
" [my set html($d)] "
" \n
- }
- append result "
"
- return $result
- }
-
- ::xowiki::Includelet proc html_to_text {string} {
- return [string map [list "&" &] $string]
- }
-
- ::xowiki::Includelet proc js_name {name} {
- return [string map [list : _ # _] $name]
- }
-
- ::xowiki::Includelet proc js_encode {string} {
- string map [list \n \\n \" {\"} ' {\'}] $string
- }
-
- ::xowiki::Includelet proc html_encode {string} {
- # ' is not a known entity to some validators, so we use the
- # numerical entity here for encoding "'"
- return [string map [list & "&" < "<" > ">" \" """ ' "'"] $string]
- }
-
-
- ::xowiki::Includelet proc html_id {name} {
- # Construct a valid HTML id or name.
- # For details, see http://www.w3.org/TR/html4/types.html
- #
- # For XOTcl object names, strip first the colons
- set name [string trimleft $name :]
-
- # make sure, the ID starts with characters
- if {![regexp {^[A-Za-z]} $name]} {
- set name id_$name
- }
-
- # replace unwanted characters
- regsub -all {[^A-Za-z0-9_:.-]} $name _ name
- return $name
- }
-
- ::xowiki::Includelet proc publish_status_clause {{-base_table ci} value} {
- if {$value eq "all"} {
- # legacy
- set publish_status_clause ""
- } else {
- array set valid_state [list production 1 ready 1 live 1 expired 1]
- set clauses [list]
- foreach state [split $value |] {
- if {![info exists valid_state($state)]} {
- error "no such state: '$state'; valid states are: production, ready, live, expired"
- }
- lappend clauses "$base_table.publish_status='$state'"
- }
- set publish_status_clause " and ([join $clauses { or }])"
- }
- return $publish_status_clause
- }
-
- ::xowiki::Includelet proc locale_clause {
- -revisions
- -items
- package_id
- locale
- } {
- set default_locale [$package_id default_locale]
- set system_locale ""
-
- set with_system_locale [regexp {(.*)[+]system} $locale _ locale]
- if {$locale eq "default"} {
- set locale $default_locale
- set include_system_locale 0
- }
- #my msg "--L with_system_locale=$with_system_locale, locale=$locale, default_locale=$default_locale"
-
- set locale_clause ""
- if {$locale ne ""} {
- set locale_clause " and $revisions.nls_language = '$locale'"
- if {$with_system_locale} {
- set system_locale [lang::system::locale -package_id $package_id]
- #my msg "system_locale=$system_locale, default_locale=$default_locale"
- if {$system_locale ne $default_locale} {
- set locale_clause " and ($revisions.nls_language = '$locale'
- or $revisions.nls_language = '$system_locale' and not exists
- (select 1 from cr_items i where i.name = '[string range $locale 0 1]:' ||
- substring($items.name,4) and i.parent_id = $items.parent_id))"
- }
- }
- }
-
- #my msg "--locale $locale, def=$default_locale sys=$system_locale, cl=$locale_clause locale_clause=$locale_clause"
- return [list $locale $locale_clause]
- }
-
- ::xowiki::Includelet instproc category_clause {category_spec {item_ref p.item_id}} {
- # the category_spec has the syntax "a,b,c|d,e", where the values are category_ids
- # pipe symbols are or-operations, commas are and-operations;
- # no parenthesis are permitted
- set extra_where_clause ""
- set or_names [list]
- set ors [list]
- foreach cid_or [split $category_spec |] {
- set ands [list]
- set and_names [list]
- foreach cid_and [split $cid_or ,] {
- lappend and_names [::category::get_name $cid_and]
- lappend ands "exists (select 1 from category_object_map \
- where object_id = $item_ref and category_id = $cid_and)"
- }
- lappend or_names "[join $and_names { and }]"
- lappend ors "([join $ands { and }])"
- }
- set cnames "[join $or_names { or }]"
- set extra_where_clause "and ([join $ors { or }])"
- #my log "--cnames $category_spec -> $cnames"
- return [list $cnames $extra_where_clause]
- }
-
- ::xowiki::Includelet proc parent_id_clause {
- {-base_table bt}
- {-use_package_path true}
- {-parent_id ""}
- -base_package_id:required
- } {
- #
- # Get the package path and from it, the folder_ids. The parent_id
- # of the returned pages should be a direct child of the folder.
- #
- if {$parent_id eq ""} {
- set parent_id [$base_package_id folder_id]
- }
- set packages [$base_package_id package_path]
- if {$use_package_path && [llength $packages] > 0} {
- set parent_ids [list $parent_id]
- foreach p $packages {lappend parent_ids [$p folder_id]}
- return "$base_table.parent_id in ([join $parent_ids ,])"
- } else {
- return "$base_table.parent_id = $parent_id"
- }
- }
-
- ::xowiki::Includelet proc glob_clause {{-base_table ci} {-attribute name} value} {
- # Return a clause for name matching.
- # value uses * for matching
- set glob [string map [list * %] $value]
- return " and $base_table.$attribute like '$glob'"
- }
-
- #
- # Other helpers
- #
-
- ::xowiki::Includelet proc listing {
- -package_id
- {-count:boolean false}
- {-folder_id}
- {-parent_id ""}
- {-page_size 20}
- {-page_number ""}
- {-orderby ""}
- {-use_package_path true}
- {-extra_where_clause ""}
- {-glob ""}
- } {
- if {$count} {
- set attribute_selection "count(*)"
- set orderby "" ;# no need to order when we count
- set page_number "" ;# no pagination when count is used
- } else {
- set attribute_selection "i.name, r.title, p.page_id, r.publish_date, \
- r.mime_type, i.parent_id, o.package_id, \
- to_char(r.publish_date,'YYYY-MM-DD HH24:MI:SS') as formatted_date"
- }
- if {$page_number ne ""} {
- set limit $page_size
- set offset [expr {$page_size*($page_number-1)}]
- } else {
- set limit ""
- set offset ""
- }
- set parent_id_clause [::xowiki::Includelet parent_id_clause \
- -base_table i \
- -use_package_path $use_package_path \
- -parent_id $parent_id \
- -base_package_id $package_id]
-
- if {$glob ne ""} {
- append extra_where_clause [::xowiki::Includelet glob_clause -base_table i $glob]
- }
-
- set sql [::xo::db::sql select \
- -vars $attribute_selection \
- -from "cr_items i, cr_revisions r, xowiki_page p, acs_objects o" \
- -where "$parent_id_clause \
- and r.revision_id = i.live_revision \
- and i.item_id = o.object_id \
- and p.page_id = r.revision_id \
- and i.publish_status <> 'production' $extra_where_clause" \
- -orderby $orderby \
- -limit $limit -offset $offset]
-
- if {$count} {
- return [db_string [my qn count_listing] $sql]
- } else {
- set s [::xowiki::Page instantiate_objects -sql $sql]
- return $s
- }
- }
-
-
- #
- # inherited methods for all includelets
- #
-
- ::xowiki::Includelet instproc resolve_page_name {page_name} {
- return [[my set __including_page] resolve_included_page_name $page_name]
- }
-
- ::xowiki::Includelet instproc get_page_order {-source -ordered_pages -pages} {
- my instvar page_order ordered_pages
- #
- # first check, if we can load the page_order from the page
- # denoted by source
- #
- if {[info exists source]} {
- set p [my resolve_page_name $source]
- if {$p ne ""} {
- array set ia [$p set instance_attributes]
- if {[info exists ia(pages)]} {
- set pages $ia(pages)
- } elseif {[info exists ia(ordered_pages)]} {
- set ordered_pages $ia(ordered_pages)
- }
- }
- }
-
- # compute a list of ordered_pages from pages, if necessary
- if {[info exists ordered_pages]} {
- foreach {order page} $ordered_pages {set page_order($page) $order}
- } else {
- set i 0
- foreach page $pages {set page_order($page) [incr i]}
- }
- }
-
- ::xowiki::Includelet instproc include_head_entries {} {
- # The purpose of this method is to contain all calls to include
- # CSS files, javascript, etc. in the HTML Head. This kind of
- # requirements could as well be included e.g. in render, but this
- # won't work, if "render" is cached. This method is called before
- # render to be executed even when render is not due to caching.
- # It is intended to be overloaded by subclasses.
- }
-
- ::xowiki::Includelet instproc initialize {} {
- # This method is called at a time after init and before render.
- # It can be used to alter specified parameter from the user,
- # or to influence the rendering of a decoration (e.g. title etc.)
- }
-
- ::xowiki::Includelet instproc js_name {} {
- return [[self class] js_name [self]]
- }
-
- ::xowiki::Includelet instproc screen_name {user_id} {
- acs_user::get -user_id $user_id -array user
- return [expr {$user(screen_name) ne "" ? $user(screen_name) : $user(name)}]
- }
-}
-
-namespace eval ::xowiki::includelet {
- #############################################################################
- ::xowiki::IncludeletClass create available-includelets \
- -superclass ::xowiki::Includelet \
- -parameter {
- {title "The following includelets can be used in a page"}
- }
-
- available-includelets instproc render {} {
- my get_parameters
- return [::xowiki::Includelet available_includelets]
- }
-}
-
-namespace eval ::xowiki::includelet {
- #############################################################################
- # Page Fragment Cache
- #
- # The following mixin-class implements page fragment caching in the
- # xowiki-cache. Caching can be turned on for every
- # ::xowiki::IncludeletClass instance.
- #
- # Fragment caching depends in the class variables
- # - cacheable (the mixin is only registered, when cacheable is set to true)
- # - aggregating (requires flusing when items are added/edited/deleted)
- # - localized (dependency on locale)
- # - personalized (dependency on userid)
- #
- Class create ::xowiki::includelet::page_fragment_cache -instproc render {} {
- set c [my info class]
- #
- # Construct a key based on the class parameters and the
- # actual parameters
- #
- set key "PF-[my package_id]-"
- append key [expr {[$c aggregating] ? "agg" : "ind"}]
- append key "-$c [my set __caller_parameters]"
- if {[$c localized]} {append key -[my locale]}
- if {[$c personalized]} {append key -[::xo::cc user_id]}
- #
- # Get the HTML from the rendered includelet by calling "next"
- #
- set HTML [ns_cache eval xowiki_cache $key next]
- #
- # Some side-effects might be necessary, even when the HTML output
- # of the includelet is cached (e.g. some associative arrays,
- # etc.). For this purpose, we provide here a means to cache
- # additional some "includelet data", if the includelet provides
- # it.
- #
- if {[catch {set data [ns_cache get xowiki_cache $key-data]}]} {
- my cache_includelet_data $key-data
- } else {
- #my msg "eval $data"
- eval $data
- }
- return $HTML
- } -instproc cache_includelet_data {key} {
- #my msg "data=[next]"
- set data [next]
- if {$data ne ""} {ns_cache set xowiki_cache $key $data}
- }
-}
-namespace eval ::xowiki::includelet {
- #############################################################################
- # dotlrn style includelet decoration for includelets
- #
- Class create ::xowiki::includelet::decoration=portlet -instproc render {} {
- my instvar package_id name title
- set class [namespace tail [my info class]]
- set id [expr {[my exists id] ? "id='[my id]'" : ""}]
- set html [next]
- set localized_title [::xo::localize $title]
- set link [expr {[string match "*:*" $name] ?
- "$localized_title" :
- $localized_title}]
- ::xo::render_localizer
- return [subst [[self class] set template]]
- } -set template [expr {[apm_version_names_compare [ad_acs_version] 5.3.0] == 1 ?
- {
-
$link
-
$html
- } : {
$link
-
[next]
}
- }]
-
- Class create ::xowiki::includelet::decoration=edit -instproc render {} {
- my instvar package_id name title
- set class [namespace tail [my info class]]
- set id [expr {[my exists id] ? "id='[my id]'" : ""}]
- set html [next]
- set localized_title [::xo::localize $title]
- set edit_button [my include [list edit-item-button -book_mode true]]
- set link [expr {[string match "*:*" $name] ?
- "$localized_title" :
- $localized_title}]
- return [subst [[self class] set template]]
- } -set template {
-
$edit_button
-
$html
- }
-
- Class create ::xowiki::includelet::decoration=plain -instproc render {} {
- set class [namespace tail [my info class]]
- set id [expr {[my exists id] ? "id='[my id]'" : ""}]
- return "
[next]
"
- }
-
- Class create ::xowiki::includelet::decoration=rightbox -instproc render {} {
- set class [namespace tail [my info class]]
- set id [expr {[my exists id] ? "id='[my id]'" : ""}]
- return "
[next]
"
- }
-}
-
-namespace eval ::xowiki::includelet {
-
- ::xowiki::IncludeletClass create get \
- -superclass ::xowiki::Includelet \
- -parameter {
- {__decoration none}
- {parameter_declaration {
- {-variable}
- {-form_variable}
- {-source ""}
- }}
- } -instproc render {} {
- my get_parameters
- if {![info exists variable] && ![info exists form_variable]} {
- return "either -variable or -form_variable must be specified"
- }
- set page [my resolve_page_name $source]
-
- if {[info exists variable] && [$page exists $variable]} {
- return [$page set $variable]
- }
- if {[info exists form_variable] && [$page exists instance_attributes]} {
- array set __ia [$page set instance_attributes]
- if {[info exists __ia($form_variable)]} {
- return $__ia($form_variable)
- }
- }
- if {[info exists variable]} {
- return "no such variable $variable defined in page [$page set name]"
- }
- return "no such form_variable $form_variable defined in page [$page set name]"
- }
-
- ::xowiki::IncludeletClass create creation-date \
- -superclass ::xowiki::Includelet \
- -parameter {
- {__decoration none}
- {parameter_declaration {
- {-source ""}
- {-format "%m-%d-%Y"}
- }}
- } -instproc render {} {
- my get_parameters
- set page [my resolve_page_name $source]
- set time [$page set creation_date]
- regexp {^([^.]+)[.]} $time _ time
- return [lc_time_fmt [clock format [clock scan $time] -format "%Y-%m-%d %H:%M:%S"] $format [my locale]]
- #return [clock format [clock scan $time] -format $format]
- }
-
- #############################################################################
- # rss button
- #
- ::xowiki::IncludeletClass create rss-button \
- -superclass ::xowiki::Includelet \
- -parameter {
- {__decoration plain}
- {parameter_declaration {
- {-span "10d"}
- {-name_filter}
- {-entries_of}
- {-title}
- }}
- }
-
- rss-button instproc render {} {
- my get_parameters
- set parent_ids [[my set __including_page] parent_id]
- set href [export_vars -base [$package_id package_url] {{rss $span} parent_ids name_filter title entries_of}]
- regsub -all & $href "&" href
- ::xo::Page requireLink -rel alternate -type application/rss+xml -title RSS -href $href
- return "RSS"
- }
-
- #############################################################################
- # bookmarklet button
- #
- ::xowiki::IncludeletClass create bookmarklet-button \
- -superclass ::xowiki::Includelet \
- -parameter {
- {__decoration none}
- {parameter_declaration {
- {-siteurl ""}
- {-label ""}
- }}
- }
-
- bookmarklet-button instproc render {} {
- my get_parameters
- set parent_id [[my set __including_page] parent_id]
- set url [$package_id pretty_link -absolute 1 -siteurl $siteurl -parent_id $parent_id news-item]
- if {$label eq ""} {set label "Add to [$package_id instance_name]"}
- set href [subst -nocommands -nobackslash {
- javascript:d=document;w=window;t='';
- if(d.selection){t=d.selection.createRange().text} else
- if(d.getSelection){t=d.getSelection()} else
- if(w.getSelection){t=w.getSelection()}
- void(open('$url?m=create-new&title='+escape(d.title)+
- '&detail_link='+escape(d.location.href)+'&text='+escape(t),'_blank',
- 'scrollbars=yes,width=700,height=575,status=yes,resizable=yes,scrollbars=yes'))
- }]
- regsub -all {[\n ]+} $href " " href
- regsub -all & $href "&" href
- return "$label"
- }
-
- #############################################################################
- # set-parameter "includelet"
- #
- ::xowiki::IncludeletClass create set-parameter \
- -superclass ::xowiki::Includelet \
- -parameter {{__decoration none}}
-
- set-parameter instproc render {} {
- my get_parameters
- set pl [my set __caller_parameters]
- if {[llength $pl] % 2 == 1} {
- error "no even number of parameters '$pl'"
- }
- foreach {att value} $pl {
- ::xo::cc set_parameter $att $value
- }
- return ""
- }
-}
-
-namespace eval ::xowiki::includelet {
- #############################################################################
- # valid parameters for he categories includelet are
- # tree_name: match pattern, if specified displays only the trees
- # with matching names
- # no_tree_name: if specified, tree names are not displayed
- # open_page: name (e.g. en:iMacs) of the page to be opened initially
- # tree_style: boolean, default: true, display based on mktree
-
- ::xowiki::IncludeletClass create categories \
- -superclass ::xowiki::Includelet \
- -cacheable true -personalized false -aggregating true \
- -parameter {
- {title "#xowiki.categories#"}
- {parameter_declaration {
- {-tree_name ""}
- {-tree_style:boolean 1}
- {-no_tree_name:boolean 0}
- {-count:boolean 0}
- {-summary:boolean 0}
- {-locale ""}
- {-open_page ""}
- {-order_items_by "title,asc"}
- {-style "mktree"}
- {-category_ids ""}
- {-except_category_ids ""}
- {-allow_edit false}
- {-ordered_composite}
- }}
- }
-
- categories instproc initialize {} {
- my get_parameters
- if {!$tree_style} {
- set style sections
- }
- my set style $style
- }
-
- categories instproc include_head_entries {} {
- ::xowiki::Tree include_head_entries -renderer [my set style]
- }
-
- categories instproc category_tree_edit_button {-object_id:integer -locale {-allow_edit false} -tree_id:integer} {
- set allow_p [::xo::cc permission -object_id $object_id -privilege admin -party_id [::xo::cc set untrusted_user_id]]
- if {$allow_edit && $allow_p} {
- if {[info exists tree_id]} {
- #
- # If a tree_id is given, edit directly the category tree ...
- #
- set href "[[my package_id] package_url]?edit-category-tree&object_id=$object_id&tree_id=$tree_id"
- return [[my set __including_page] include \
- [list edit-item-button -link $href -title "Edit Category Tree" -target _blank]]
- } else {
- #
- # ... otherwise, manage categories (allow defining new category trees, map/unmap, etc.)
- #
- set href "[[my package_id] package_url]?manage-categories&object_id=$object_id"
- return [[my set __including_page] include \
- [list edit-item-button -link $href -title "Manage Categories" -target _blank]]]
- }
- }
- return ""
- }
- categories instproc category_tree_missing {{-name ""} -edit_html} {
- # todo i18n
- if {$name eq ""} {
- #set msg "No category tree found."
- # maybe it is better to stay quiet in case, no category name was provided
- set msg ""
- } else {
- set msg "No category tree with name '$name' found."
- }
- [my package_id] flush_page_fragment_cache -scope agg
- set html "
$msg
"
- if {$edit_html ne ""} {
- return "$html Manage Categories? $edit_html"
- }
- return $html
- }
-
- categories instproc render {} {
- my get_parameters
-
- set content ""
- set folder_id [$package_id folder_id]
- set open_item_id [expr {$open_page ne "" ?
- [::xo::db::CrClass lookup -name $open_page -parent_id $folder_id] : 0}]
-
- foreach {locale locale_clause} \
- [::xowiki::Includelet locale_clause -revisions r -items ci $package_id $locale] break
-
- set trees [::xowiki::Category get_mapped_trees -object_id $package_id -locale $locale \
- -names $tree_name \
- -output {tree_id tree_name}]
-
- #my msg "[llength $trees] == 0 && $tree_name"
- if {[llength $trees] == 0 && $tree_name ne ""} {
- # we have nothing left from mapped trees, maybe the tree_names are not mapped;
- # try to get these
- foreach name $tree_name {
- #set tree_id [lindex [category_tree::get_id $tree_name $locale] 0]
- set tree_id [lindex [category_tree::get_id $tree_name] 0]
- if {$tree_id ne ""} {
- lappend trees [list $tree_id $name]
- }
- }
- }
-
- set edit_html [my category_tree_edit_button -object_id $package_id -allow_edit $allow_edit]
- if {[llength $trees] == 0} {
- return [my category_tree_missing -name $tree_name -edit_html $edit_html]
- }
-
- if {![my exists id]} {my set id [::xowiki::Includelet html_id [self]]}
-
- foreach tree $trees {
- foreach {tree_id my_tree_name ...} $tree {break}
-
- set edit_html [my category_tree_edit_button -object_id $package_id \
- -allow_edit $allow_edit -tree_id $tree_id]
- #append content "
$edit_html
\n"
-
- if {!$no_tree_name} {
- append content "
$my_tree_name $edit_html
"
- } elseif {$edit_html ne ""} {
- append content "$edit_html "
- }
- set categories [list]
- set pos 0
- set cattree(0) [::xowiki::Tree new -volatile -orderby pos \
- -id [my id]-$my_tree_name -name $my_tree_name]
-
- set category_infos [::xowiki::Category get_category_infos \
- -locale $locale -tree_id $tree_id]
- foreach category_info $category_infos {
- foreach {cid category_label deprecated_p level} $category_info {break}
- set c [::xowiki::TreeNode new -orderby pos \
- -level $level -label $category_label -pos [incr pos]]
- set cattree($level) $c
- set plevel [expr {$level -1}]
- $cattree($plevel) add $c
- set category($cid) $c
- lappend categories $cid
- }
-
- if {[llength $categories] == 0} {
- return $content
- }
-
- if {[info exists ordered_composite]} {
- set items [list]
- foreach c [$ordered_composite children] {lappend items [$c item_id]}
-
- # If we have no item, provide a dummy one to avoid sql error
- # later
- if {[llength $items]<1} {set items -4711}
-
- if {$count} {
- set sql "category_object_map c
- where c.object_id in ([join $items ,]) "
- } else {
- # TODO: the non-count-part for the ordered_composite is not
- # tested yet. Although "ordered compostite" can be used
- # only programmatically for now, the code below should be
- # tested. It would be as well possible to obtain titles and
- # names etc. from the ordered composite, resulting in a
- # faster SQL like above.
- set sql "category_object_map c, cr_items ci, cr_revisions r
- where c.object_id in ([join $items ,])
- and c.object_id = ci.item_id and
- and r.revision_id = ci.live_revision
- "
- }
- } else {
- set sql "category_object_map c, cr_items ci, cr_revisions r, xowiki_page p \
- where c.object_id = ci.item_id and ci.parent_id = $folder_id \
- and ci.content_type not in ('::xowiki::PageTemplate') \
- and c.category_id in ([join $categories ,]) \
- and r.revision_id = ci.live_revision \
- and p.page_id = r.revision_id \
- and ci.publish_status <> 'production'"
- }
-
- if {$except_category_ids ne ""} {
- append sql \
- " and not exists (select * from category_object_map c2 \
- where ci.item_id = c2.object_id \
- and c2.category_id in ($except_category_ids))"
- }
- #ns_log notice "--c category_ids=$category_ids"
- if {$category_ids ne ""} {
- foreach cid [split $category_ids ,] {
- append sql " and exists (select * from category_object_map \
- where object_id = ci.item_id and category_id = $cid)"
- }
- }
- append sql $locale_clause
-
- if {$count} {
- db_foreach [my qn get_counts] \
- "select count(*) as nr,category_id from $sql group by category_id" {
- $category($category_id) set count $nr
- set s [expr {$summary ? "&summary=$summary" : ""}]
- $category($category_id) href [ad_conn url]?category_id=$category_id$s
- $category($category_id) open_tree
- }
- append content [$cattree(0) render -style [my set style]]
- } else {
- foreach {orderby direction} [split $order_items_by ,] break ;# e.g. "title,asc"
- set increasing [expr {$direction ne "desc"}]
- set order_column ", p.page_order"
-
- db_foreach [my qn get_pages] \
- "select ci.item_id, ci.name, ci.parent_id, r.title, category_id $order_column from $sql" {
- if {$title eq ""} {set title $name}
- set itemobj [Object new]
- set prefix ""
- set suffix ""
- foreach var {name title prefix suffix page_order} {$itemobj set $var [set $var]}
- $itemobj set href [::$package_id pretty_link -parent_id $parent_id $name]
- $cattree(0) add_item \
- -category $category($category_id) \
- -itemobj $itemobj \
- -orderby $orderby \
- -increasing $increasing \
- -open_item [expr {$item_id == $open_item_id}]
- }
- append content [$cattree(0) render -style [my set style]]
- }
- }
- return $content
- }
-}
-
-
-namespace eval ::xowiki::includelet {
- #############################################################################
- #
- # display recent entries by categories
- # -gustaf neumann
- #
- # valid parameters from the include are
- # tree_name: match pattern, if specified displays only the trees with matching names
- # max_entries: show given number of new entries
-
- ::xowiki::IncludeletClass create categories-recent \
- -superclass ::xowiki::Includelet \
- -cacheable true -personalized false -aggregating true \
- -parameter {
- {title "#xowiki.recently_changed_pages_by_categories#"}
- {parameter_declaration {
- {-max_entries:integer 10}
- {-tree_name ""}
- {-locale ""}
- {-pretty_age "off"}
- }}
- }
-
- categories-recent instproc initialize {} {
- my set style sections
- # When pretty age is activated, this includedlet is not suited for
- # caching (it could make sense e.g. when the age granularity is 1
- # minute or more). This measure here (turing off caching
- # completely) is a little bit too much, but it is safe.
- my get_parameters
- if {[[my info class] cacheable] && $pretty_age ne "off"} {
- [my info class] cacheable false
- }
- }
-
- categories-recent instproc include_head_entries {} {
- ::xowiki::Tree include_head_entries -renderer [my set style]
- }
-
- categories-recent instproc render {} {
- my get_parameters
-
- if {![my exists id]} {my set id [::xowiki::Includelet html_id [self]]}
- set cattree [::xowiki::Tree new -volatile -id [my id]]
-
- foreach {locale locale_clause} \
- [::xowiki::Includelet locale_clause -revisions r -items ci $package_id $locale] break
-
- set tree_ids [::xowiki::Category get_mapped_trees -object_id $package_id -locale $locale \
- -names $tree_name -output tree_id]
-
- if {$tree_ids ne ""} {
- set tree_select_clause "and c.tree_id in ([join $tree_ids ,])"
- } else {
- set tree_select_clause ""
- }
- set sql [::xo::db::sql select \
- -vars "c.category_id, ci.name, ci.parent_id, r.title, r.publish_date, \
- to_char(r.publish_date,'YYYY-MM-DD HH24:MI:SS') as formatted_date" \
- -from "category_object_map_tree c, cr_items ci, cr_revisions r, xowiki_page p" \
- -where "c.object_id = ci.item_id and ci.parent_id = [$package_id folder_id] \
- and r.revision_id = ci.live_revision \
- and p.page_id = r.revision_id $tree_select_clause $locale_clause \
- and ci.publish_status <> 'production'" \
- -orderby "publish_date desc" \
- -limit $max_entries]
- db_foreach [my qn get_pages] $sql {
- if {$title eq ""} {set title $name}
- set itemobj [Object new]
- set prefix ""
- set suffix ""
- switch -- $pretty_age {
- 1 {set suffix " ([::xowiki::utility pretty_age -timestamp [clock scan $formatted_date] -locale [my locale]])"}
- 2 {set suffix "([::xowiki::utility pretty_age -timestamp [clock scan $formatted_date] -locale [my locale] -levels 2])"}
- default {set prefix "$formatted_date "}
- }
- if {$prefix ne ""} {set prefix "$prefix";$itemobj set encoded(prefix) 1}
- if {$suffix ne ""} {set suffix "$suffix";$itemobj set encoded(suffix) 1}
- foreach var {name title prefix suffix} {$itemobj set $var [set $var]}
- $itemobj set href [::$package_id pretty_link -parent_id $parent_id $name]
-
- if {![info exists categories($category_id)]} {
- set categories($category_id) [::xowiki::TreeNode new \
- -label [category::get_name $category_id $locale] \
- -level 1]
- $cattree add $categories($category_id)
- }
- $cattree add_item -category $categories($category_id) -itemobj $itemobj
- }
- return [$cattree render -style [my set style]]
- }
-}
-
-
-namespace eval ::xowiki::includelet {
- #############################################################################
- #
- # display recent entries
- #
-
- ::xowiki::IncludeletClass create recent \
- -superclass ::xowiki::Includelet \
- -parameter {
- {title "#xowiki.recently_changed_pages#"}
- {parameter_declaration {
- {-max_entries:integer 10}
- {-allow_edit:boolean false}
- {-allow_delete:boolean false}
- {-pretty_age off}
- }}
- }
-
- recent instproc render {} {
- my get_parameters
- ::xo::Page requireCSS "/resources/acs-templating/lists.css"
- set admin_p [::xo::cc permission -object_id $package_id -privilege admin \
- -party_id [::xo::cc set untrusted_user_id]]
- set show_heritage $admin_p
-
- TableWidget t1 -volatile \
- -set allow_edit $allow_edit \
- -set allow_delete $allow_delete \
- -set show_heritage $admin_p \
- -columns {
- Field date -label [_ xowiki.Page-last_modified]
- if {[[my info parent] set allow_edit]} {
- AnchorField edit -CSSclass edit-item-button -label "" -html {style "padding-right: 2px;"} -richtext 1
- }
- if {[[my info parent] set show_heritage]} {
- AnchorField inherited -label "" -CSSclass inherited
- }
- AnchorField title -label [::xowiki::Page::slot::title set pretty_name]
- if {[[my info parent] set allow_delete]} {
- AnchorField delete -CSSclass delete-item-button -label "" -richtext 1
- }
- }
-
- set listing [::xowiki::Includelet listing \
- -package_id $package_id -page_number 1 -page_size $max_entries \
- -orderby "publish_date desc"]
-
- foreach entry [$listing children] {
- $entry instvar parent_id formatted_date page_id {title entry_title} {name entry_name}
- set entry_package_id [$entry set package_id]
-
- set page_link [$entry_package_id pretty_link -parent_id $parent_id $entry_name]
- switch -- $pretty_age {
- 1 {set age [::xowiki::utility pretty_age -timestamp [clock scan $formatted_date] -locale [my locale]]}
- 2 {set age [::xowiki::utility pretty_age -timestamp [clock scan $formatted_date] -locale [my locale] -levels 2]}
- default {set age $formatted_date}
- }
-
- t1 add \
- -title $entry_title \
- -title.href $page_link \
- -date $age
-
- if {$allow_edit} {
- set p [::xo::db::CrClass get_instance_from_db -item_id 0 -revision_id $page_id]
- set edit_link [$entry_package_id make_link -link $page_link $p edit return_url]
- #my log "page_link=$page_link, edit=$edit_link"
- [t1 last_child] set edit.href $edit_link
- [t1 last_child] set edit " "
- }
- if {$allow_delete} {
- if {![info exists p]} {
- set p [::xo::db::CrClass get_instance_from_db -item_id 0 -revision_id $page_id]
- }
- set delete_link [$entry_package_id make_link -link $page_link $p delete return_url]
- [t1 last_child] set delete.href $delete_link
- [t1 last_child] set delete " "
- }
- if {$show_heritage} {
- if {$entry_package_id == [my package_id]} {
- set href ""
- set title ""
- set alt ""
- set class ""
- set label ""
- } else {
- # provide a link to the original
- set href $page_link
- set label [$entry_package_id instance_name]
- set title [_ xowiki.view_in_context [list context $label]]
- set alt $title
- set class "inherited"
- }
- [t1 last_child] set inherited $label
- [t1 last_child] set inherited.href $href
- [t1 last_child] set inherited.title $title
- [t1 last_child] set inherited.CSSclass $class
- }
- }
- return [t1 asHTML]
- }
-}
-
-namespace eval ::xowiki::includelet {
- #############################################################################
- #
- # display last visited entries
- #
-
- ::xowiki::IncludeletClass create last-visited \
- -superclass ::xowiki::Includelet \
- -parameter {
- {title "#xowiki.last_visited_pages#"}
- {parameter_declaration {
- {-max_entries:integer 20}
- }}
- }
-
- last-visited instproc render {} {
- my get_parameters
- ::xo::Page requireCSS "/resources/acs-templating/lists.css"
-
- TableWidget t1 -volatile \
- -columns {
- AnchorField title -label [::xowiki::Page::slot::title set pretty_name]
- }
-
- db_foreach [my qn get_pages] \
- [::xo::db::sql select \
- -vars "i.parent_id, r.title,i.name, to_char(time,'YYYY-MM-DD HH24:MI:SS') as visited_date" \
- -from "xowiki_last_visited x, xowiki_page p, cr_items i, cr_revisions r" \
- -where "x.page_id = i.item_id and i.live_revision = p.page_id \
- and r.revision_id = p.page_id and x.user_id = [::xo::cc set untrusted_user_id] \
- and x.package_id = $package_id and i.publish_status <> 'production'" \
- -orderby "visited_date desc" \
- -limit $max_entries] \
- {
- t1 add \
- -title $title \
- -title.href [$package_id pretty_link -parent_id $parent_id $name]
- }
- return [t1 asHTML]
- }
-}
-
-
-namespace eval ::xowiki::includelet {
- #############################################################################
- #
- # list the most popular pages
- #
-
- ::xowiki::IncludeletClass create most-popular \
- -superclass ::xowiki::Includelet \
- -parameter {
- {title "#xowiki.most_popular_pages#"}
- {parameter_declaration {
- {-max_entries:integer "10"}
- {-interval}
- }}
- }
-
- most-popular instproc render {} {
- my get_parameters
- ::xo::Page requireCSS "/resources/acs-templating/lists.css"
-
- if {[info exists interval]} {
- #
- # If we have and interval, we cannot get report the number of visits
- # for that interval, since we have only the aggregated values in
- # the database.
- #
- my append title " in last $interval"
-
- TableWidget t1 -volatile \
- -columns {
- AnchorField title -label [::xowiki::Page::slot::title set pretty_name]
- Field users -label Visitors -html { align right }
- }
- set since_condition "and [::xo::db::sql since_interval_condition time $interval]"
- db_foreach [my qn get_pages] \
- [::xo::db::sql select \
- -vars "count(x.user_id) as nr_different_users, x.page_id, r.title,i.name, i.parent_id" \
- -from "xowiki_last_visited x, xowiki_page p, cr_items i, cr_revisions r" \
- -where "x.package_id = $package_id and x.page_id = i.item_id and \
- i.publish_status <> 'production' and i.live_revision = r.revision_id \
- and $since_condition" \
- -groupby "x.page_id, r.title, i.name, i.parent_id" \
- -orderby "nr_different_users desc" \
- -limit $max_entries ] {
- t1 add \
- -title $title \
- -title.href [$package_id pretty_link -parent_id $parent_id $name] \
- -users $nr_different_users
- }
- } else {
-
- TableWidget t1 -volatile \
- -columns {
- AnchorField title -label [::xowiki::Page::slot::title set pretty_name]
- Field count -label [_ xowiki.includelets-visits] -html { align right }
- Field users -label [_ xowiki.includelet-visitors] -html { align right }
- }
- db_foreach [my qn get_pages] \
- [::xo::db::sql select \
- -vars "sum(x.count) as sum, count(x.user_id) as nr_different_users, x.page_id, r.title,i.name, i.parent_id" \
- -from "xowiki_last_visited x, cr_items i, cr_revisions r" \
- -where "x.package_id = $package_id and x.page_id = i.item_id and \
- i.publish_status <> 'production' and i.live_revision = r.revision_id" \
- -groupby "x.page_id, r.title, i.name, i.parent_id" \
- -orderby "sum desc" \
- -limit $max_entries] {
- t1 add \
- -title $title \
- -title.href [$package_id pretty_link -parent_id $parent_id $name] \
- -users $nr_different_users \
- -count $sum
- }
- }
- return [t1 asHTML]
- }
-}
-
-namespace eval ::xowiki::includelet {
- #############################################################################
- #
- # list the most frequent visitors
- #
-
- ::xowiki::IncludeletClass create rss-client \
- -superclass ::xowiki::Includelet \
- -parameter {
- {title "#xowiki.rss_client#"}
- {parameter_declaration {
- {-url:required}
- {-max_entries:integer "15"}
- }}
- }
-
- rss-client instproc initialize {} {
- my instvar feed
- my get_parameters
- my set feed [::xowiki::RSS-client new -url $url -destroy_on_cleanup]
- if {[info command [$feed channel]] ne ""} {
- my title [ [$feed channel] title]
- }
- }
-
- rss-client instproc render {} {
- my instvar feed
- my get_parameters
- if {[info command [$feed channel]] eq ""} {
- set detail ""
- if {[$feed exists errorMessage]} {set detail \n[$feed set errorMessage]}
- return "No data available from $url $detail"
- } else {
- set channel [$feed channel]
- #set html "
[$channel title]
"
- set html "
\n"
- set i 0
- foreach item [ $feed items ] {
- append html "
[$item title] [$item description] #xowiki.weblog-more#\n"
- if {[incr i] >= $max_entries} break
- }
- append html "
\n"
- return $html
- }
- }
-}
-
-namespace eval ::xowiki::includelet {
- #############################################################################
- #
- # list the most frequent visitors
- #
-
- ::xowiki::IncludeletClass create most-frequent-visitors \
- -superclass ::xowiki::Includelet \
- -parameter {
- {title "#xowiki.most_frequent_visitors#"}
- {parameter_declaration {
- {-max_entries:integer "15"}
- }}
- }
-
- most-frequent-visitors instproc render {} {
- my get_parameters
- ::xo::Page requireCSS "/resources/acs-templating/lists.css"
-
- TableWidget t1 -volatile \
- -columns {
- Field user -label Visitors -html { align right }
- Field count -label Visits -html { align right }
- }
- db_foreach [my qn get_pages] \
- [::xo::db::sql select \
- -vars "sum(count) as sum, user_id" \
- -from "xowiki_last_visited" \
- -where "package_id = $package_id" \
- -groupby "user_id" \
- -orderby "sum desc" \
- -limit $max_entries] {
- t1 add \
- -user [::xo::get_user_name $user_id] \
- -count $sum
- }
- return [t1 asHTML]
- }
-
-}
-
-
-namespace eval ::xowiki::includelet {
- #############################################################################
- #
- # Display unread items
- #
- # Currently moderately useful
- #
- # TODO: display of unread *revisions* should be included optionally, one has to
- # consider what to do with auto-created stuff (put it into 'production' state?)
- #
-
- ::xowiki::IncludeletClass create unread-items \
- -superclass ::xowiki::Includelet \
- -parameter {
- {title "#xowiki.unread_items#"}
- {parameter_declaration {
- {-max_entries:integer 20}
- }}
- }
-
- unread-items instproc render {} {
- my get_parameters
- ::xo::Page requireCSS "/resources/acs-templating/lists.css"
-
- TableWidget t1 -volatile \
- -columns {
- AnchorField title -label [::xowiki::Page::slot::title set pretty_name]
- }
-
- set or_clause "or i.item_id in (
- select x.page_id
- from xowiki_last_visited x, acs_objects o \
- where x.time < o.last_modified
- and x.page_id = o.object_id
- and x.package_id = $package_id
- and x.user_id = [::xo::cc user_id]
- )"
-
- set or_clause ""
-
- db_foreach [my qn get_pages] \
- [::xo::db::sql select \
- -vars "a.title, i.name, i.parent_id" \
- -from "xowiki_page p, cr_items i, acs_objects a " \
- -where "(i.item_id not in (
- select x.page_id from xowiki_last_visited x
- where x.user_id = [::xo::cc user_id] and x.package_id = $package_id
- ) $or_clause
- )
- and i.live_revision = p.page_id
- and i.parent_id = [$package_id folder_id]
- and i.publish_status <> 'production'
- and a.object_id = i.item_id" \
- -orderby "a.creation_date desc" \
- -limit $max_entries] \
- {
- t1 add \
- -title $title \
- -title.href [$package_id pretty_link -parent_id $parent_id $name]
- }
- return [t1 asHTML]
- }
-}
-
-
-
-
-namespace eval ::xowiki::includelet {
- #############################################################################
- #
- # Show the tags
- #
-
- ::xowiki::IncludeletClass create tags \
- -superclass ::xowiki::Includelet \
- -parameter {
- {title "Tags"}
- {parameter_declaration {
- {-limit:integer 20}
- {-summary:boolean 0}
- {-popular:boolean 0}
- {-page}
- }}
- }
-
- tags instproc render {} {
- my get_parameters
- ::xo::Page requireCSS "/resources/acs-templating/lists.css"
-
- if {$popular} {
- set label [_ xowiki.popular_tags_label]
- set tag_type ptag
- set sql [::xo::db::sql select \
- -vars "count(*) as nr,tag" \
- -from xowiki_tags \
- -where "package_id=$package_id" \
- -groupby tag \
- -orderby tag \
- -limit $limit]
- } else {
- set label [_ xowiki.your_tags_label]
- set tag_type tag
- set sql "select count(*) as nr,tag from xowiki_tags where \
- user_id=[::xo::cc user_id] and package_id=$package_id group by tag order by tag"
- }
- set entries [list]
-
- if {![info exists page]} {set page [$package_id get_parameter weblog_page]}
-
- set href [$package_id package_url]tag/
- db_foreach [my qn get_counts] $sql {
- set q [list]
- if {$summary} {lappend q "summary=$summary"}
- if {$popular} {lappend q "popular=$popular"}
- set link $href$tag?[join $q &]
- #lappend entries "$tag ($nr)"
- lappend entries "$tag ($nr)"
- }
- return [expr {[llength $entries] > 0 ?
- "
$label
[join $entries {, }]
\n" :
- ""}]
- }
-
- ::xowiki::IncludeletClass create my-tags \
- -superclass ::xowiki::Includelet \
- -parameter {
- {__decoration none}
- {parameter_declaration {
- {-summary 1}
- }}
- id
- }
-
- my-tags instproc render {} {
- my get_parameters
- my instvar __including_page tags
- ::xo::Page requireJS "/resources/xowiki/get-http-object.js"
-
- set p_link [$__including_page pretty_link]
- set return_url "[::xo::cc url]?[::xo::cc actual_query]"
- set weblog_page [$package_id get_parameter weblog_page weblog]
- set save_tag_link [$package_id make_link -link $p_link $__including_page \
- save-tags return_url]
- set popular_tags_link [$package_id make_link -link $p_link $__including_page \
- popular-tags return_url weblog_page]
-
- set tags [lsort [::xowiki::Page get_tags -user_id [::xo::cc user_id] \
- -item_id [$__including_page item_id] -package_id $package_id]]
- set href [$package_id package_url]$weblog_page?summary=$summary&tag
-
- set entries [list]
-
- #foreach tag $tags {lappend entries "$tag"}
- set href [$package_id package_url]/tag/
- foreach tag $tags {lappend entries "$tag"}
- set tags_with_links [join [lsort $entries] {, }]
-
- if {![my exists id]} {my set id [::xowiki::Includelet html_id [self]]}
- set content [subst -nobackslashes {
- #xowiki.your_tags_label#: $tags_with_links
- (#xowiki.edit_link#,
- #xowiki.popular_tags_link#)
-
-
- }]
- return $content
- }
-
-
- ::xowiki::IncludeletClass create my-categories \
- -superclass ::xowiki::Includelet \
- -parameter {
- {__decoration none}
- {parameter_declaration {
- {-summary 1}
- }}
- }
-
- my-categories instproc render {} {
- my get_parameters
- my instvar __including_page
- set content ""
-
- set weblog_page [$package_id get_parameter weblog_page weblog]
- set entries [list]
- set href [$package_id package_url]$weblog_page?summary=$summary
- set notification_type ""
- if {[$package_id get_parameter "with_notifications" 1] &&
- [::xo::cc user_id] != 0} { ;# notifications require login
- set notification_type [notification::type::get_type_id -short_name xowiki_notif]
- }
- if {[$package_id exists_query_parameter return_url]} {
- set return_url [$package_id query_parameter return_url]
- }
- foreach cat_id [category::get_mapped_categories [$__including_page set item_id]] {
- foreach {category_id category_name tree_id tree_name} [category::get_data $cat_id] break
- #my log "--cat $cat_id $category_id $category_name $tree_id $tree_name"
- set entry "$category_name ($tree_name)"
- if {$notification_type ne ""} {
- set notification_text "Subscribe category $category_name in tree $tree_name"
- set notifications_return_url [expr {[info exists return_url] ? $return_url : [ad_return_url]}]
- set notification_image \
- ""
-
- set cat_notif_link [export_vars -base /notifications/request-new \
- {{return_url $notifications_return_url} \
- {pretty_name $notification_text} \
- {type_id $notification_type} \
- {object_id $category_id}}]
- append entry " " \
- ""
-
- }
- lappend entries $entry
- }
- if {[llength $entries]>0} {
- set content "#xowiki.categories#: [join $entries {, }]"
- }
- return $content
- }
-
- ::xowiki::IncludeletClass create my-general-comments \
- -superclass ::xowiki::Includelet \
- -parameter {{__decoration none}}
-
- my-general-comments instproc render {} {
- my get_parameters
- my instvar __including_page
- set item_id [$__including_page item_id]
- set gc_return_url [$package_id url]
- # Even, if general_comments is turned on, don't offer the
- # link to add comments, unless the user is logged in.
- # Otherwise, this attracts spammers and search bots
- if {[::xo::cc user_id] != 0} {
- set gc_link [general_comments_create_link \
- -object_name [$__including_page title] \
- $item_id $gc_return_url]
- set gc_link
$gc_link
- } else {
- set gc_link ""
- }
- set gc_comments [general_comments_get_comments $item_id $gc_return_url]
- if {$gc_comments ne ""} {
- return "
#general-comments.Comments#
$gc_comments
$gc_link"
- } else {
- return "$gc_link"
- }
- }
-
- ::xowiki::IncludeletClass create digg \
- -superclass ::xowiki::Includelet \
- -parameter {
- {__decoration none}
- {parameter_declaration {
- {-description ""}
- {-url}
- }}
- }
-
- digg instproc render {} {
- my get_parameters
- my instvar __including_page
- set digg_link [export_vars -base "http://digg.com/submit" {
- {phase 2}
- {url $url}
- {title "[string range [$__including_page title] 0 74]"}
- {body_text "[string range $description 0 349]"}
- }]
- regsub -all & $digg_link "&" digg_link
- return ""
- }
-
- ::xowiki::IncludeletClass create delicious \
- -superclass ::xowiki::Includelet \
- -parameter {
- {__decoration none}
- {parameter_declaration {
- {-description ""}
- {-tags ""}
- {-url}
- }}
- }
-
- delicious instproc render {} {
- my get_parameters
- my instvar __including_page
-
- # the following opens a window, where a user can edit the posted info.
- # however, it seems not possible to add tags this way automatically.
- # Alternatively, one could use the api as descibed below; this allows
- # tags, but no editing...
- # http://farm.tucows.com/blog/_archives/2005/3/24/462869.html#adding
-
- set delicious_link [export_vars -base "http://del.icio.us/post" {
- {v 4}
- {url $url}
- {title "[string range [$__including_page title] 0 79]"}
- {notes "[string range $description 0 199]"}
- tags
- }]
- regsub -all & $delicious_link "&" delicious_link
- return "del.icio.us"
- }
-
-
- ::xowiki::IncludeletClass create my-yahoo-publisher \
- -superclass ::xowiki::Includelet \
- -parameter {
- {__decoration none}
- {parameter_declaration {
- {-publisher ""}
- {-rssurl}
- }}
- }
-
- my-yahoo-publisher instproc render {} {
- my get_parameters
- my instvar __including_page
-
- set publisher [ad_urlencode $publisher]
- set feedname [ad_urlencode [$package_id get_parameter PackageTitle [$package_id instance_name]]]
- set rssurl [ad_urlencode $rssurl]
- set my_yahoo_link "http://us.rd.yahoo.com/my/atm/$publisher/$feedname/*http://add.my.yahoo.com/rss?url=$rssurl"
-
- return ""
- }
-
-
- #
- # my-references lists the pages which are refering to the
- # including page
- #
- ::xowiki::IncludeletClass create my-references \
- -superclass ::xowiki::Includelet \
- -parameter {{__decoration none}}
-
- my-references instproc render {} {
- my get_parameters
- my instvar __including_page
-
- set item_id [$__including_page item_id]
- set refs [list]
- # The same image might be linked both, as img or file on one page,
- # so we need DISTINCT.
-
- db_foreach [my qn get_references] "SELECT DISTINCT page,ci.name,ci.parent_id,o.package_id as pid \
- from xowiki_references,cr_items ci,acs_objects o \
- where reference=$item_id and ci.item_id = page and ci.item_id = o.object_id" {
- if {$pid eq ""} {
- # in version less then oacs 5.2, this returns empty
- set pid [db_string _ "select package_id from cr_folders where folder_id = :parent_id"]
- }
- if {$pid ne ""} {
- ::xowiki::Package require $pid
- lappend refs "$name"
- }
- }
- set references [join $refs ", "]
-
- array set lang {found "" undefined ""}
- foreach i [$__including_page array names lang_links] {
- set lang($i) [join [$__including_page set lang_links($i)] ", "]
- }
-
- append references " " $lang(found)
- set result ""
- if {$references ne " "} {
- append result "#xowiki.references_label# $references"
- }
- if {$lang(undefined) ne ""} {
- append result "#xowiki.create_this_page_in_language# $lang(undefined)"
- }
- return $result
- }
-
- #
- # my-refers lists the pages which are refered to by the
- # including page
- #
- ::xowiki::IncludeletClass create my-refers \
- -superclass ::xowiki::Includelet \
- -parameter {{__decoration none}}
-
- my-refers instproc render {} {
- my get_parameters
- my instvar __including_page
-
- set item_id [$__including_page item_id]
- set refs [list]
-
- db_foreach [my qn get_refers] "SELECT DISTINCT reference,ci.name,ci.parent_id,o.package_id as pid \
- from xowiki_references,cr_items ci,acs_objects o \
- where page=$item_id and ci.item_id = reference and ci.item_id = o.object_id" {
- if {$pid eq ""} {
- # in version less then oacs 5.2, this returns empty
- set pid [db_string _ "select package_id from cr_folders where folder_id = :parent_id"]
- }
- if {$pid ne ""} {
- ::xowiki::Package require $pid
- lappend refs "$name"
- }
- }
-
- set references [join $refs ", "]
-
- array set lang {found "" undefined ""}
- foreach i [$__including_page array names lang_links] {
- set lang($i) [join [$__including_page set lang_links($i)] ", "]
- }
- append references " " $lang(found)
- set result ""
- if {$references ne " "} {
- append result "#xowiki.references_of_label# $references"
- }
- if {$lang(undefined) ne ""} {
- append result "#xowiki.create_this_page_in_language# $lang(undefined)"
- }
- return $result
- }
-
-}
-
-namespace eval ::xowiki::includelet {
- #############################################################################
- # presence
- #
- ::xowiki::IncludeletClass create presence \
- -superclass ::xowiki::Includelet \
- -parameter {
- {__decoration rightbox}
- {parameter_declaration {
- {-interval "10 minutes"}
- {-max_users:integer 40}
- {-show_anonymous "summary"}
- {-page}
- }}
- }
-
- # TODO make display style -decoration
-
- presence instproc render {} {
- my get_parameters
-
- set summary 0
- if {[::xo::cc user_id] == 0} {
- switch -- $show_anonymous {
- nothing {return ""}
- all {set summary 0}
- default {set summary 1}
- }
- }
-
- if {[info exists page] && $page eq "this"} {
- my instvar __including_page
- set extra_where_clause "and page_id = [$__including_page item_id] "
- set what " on page [$__including_page title]"
- } else {
- set extra_where_clause ""
- set what " in community [$package_id instance_name]"
- }
-
- if {!$summary} {
- set select_users "user_id, to_char(max(time),'YYYY-MM-DD HH24:MI:SS') as max_time from xowiki_last_visited "
- }
- set since_condition [::xo::db::sql since_interval_condition time $interval]
- set where_clause "package_id=$package_id and $since_condition $extra_where_clause"
- set when " in last $interval"
-
- set output ""
-
- if {$summary} {
- set count [db_string [my qn presence_count_users] \
- "select count(distinct user_id) from xowiki_last_visited WHERE $where_clause"]
- } else {
- set values [db_list_of_lists [my qn get_users] \
- [::xo::db::sql select \
- -vars "user_id, to_char(max(time),'YYYY-MM-DD HH24:MI:SS') as max_time" \
- -from xowiki_last_visited \
- -where $where_clause \
- -groupby user_id \
- -orderby "max_time desc" \
- -limit $max_users ]]
- set count [llength $values]
- if {$count == $max_users} {
- # we have to check, whether there were more users...
- set count [db_string [my qn presence_count_users] \
- "select count(distinct user_id) from xowiki_last_visited WHERE $where_clause"]
- }
- foreach value $values {
- foreach {user_id time} $value break
- set seen($user_id) $time
-
- regexp {^([^.]+)[.]} $time _ time
- set pretty_time [util::age_pretty -timestamp_ansi $time \
- -sysdate_ansi [clock_to_ansi [clock seconds]] \
- -mode_3_fmt "%d %b %Y, at %X"]
- set name [::xo::get_user_name $user_id]
-
- append output "
-
- Form Name:
-
-
- }]
-
- return $inner_html$save_form
- }
-}
-
-namespace eval ::xowiki::includelet {
- #############################################################################
- # book style
- #
- ::xowiki::IncludeletClass create book \
- -superclass ::xowiki::Includelet \
- -instmixin PageReorderSupport \
- -parameter {
- {__decoration plain}
- {parameter_declaration {
- {-category_id}
- {-menu_buttons edit}
- {-folder_mode false}
- {-locale ""}
- {-range ""}
- {-allow_reorder ""}
- {-with_footer "false"}
- }}
- }
-
-
- book instproc render_item {
- -menu_buttons
- -content:required
- -object:required
- -level:required
- } {
- $object instvar page_order title name
- set menu [list]
- foreach b $menu_buttons {
- if {[info command ::xowiki::includelet::$b] eq ""} {
- set b $b-item-button
- }
- set html [$object include [list $b -book_mode true]]
- if {$html ne ""} {lappend menu $html}
- }
- set menu [join $menu " "]
- if {$menu ne ""} {
- #
not allowed in h*: style='float: right; position: relative; top: -32px
- set menu "$menu"
- }
- append output \
- "" $menu \
- "$page_order $title" \
- $content
- }
-
- book instproc render_items {
- -pages:required
- {-cnames ""}
- {-allow_reorder ""}
- -menu_buttons
- {-with_footer "false"}
- } {
- set output ""
- if {$cnames ne ""} {
- append output "
Filtered by categories: $cnames
"
- }
-
- my page_reorder_init_vars -allow_reorder $allow_reorder js last_level ID min_level
- set renderer default
-
- foreach o [$pages children] {
- $o instvar page_order page_id
- set level [expr {[regsub -all {[.]} $page_order _ page_order_js] + 1}]
-
- if {$allow_reorder ne ""} {
- #
- # Build a (nested) list structure mirroring the hierarchy
- # implied by the page_order. In essence, we provide CSS
- # classes for the ULs and provide IDs for ULs and LI elements,
- # and pass the associated page_order to javascript.
- #
- if {![regexp {^(.*)[.][^.]+$} $page_order _ prefix]} {set prefix ""}
-
- # First, insert the appropriate opening and closing of ULs. We
- # could handle here prefix changes as well as different lists
- # (e.g. 1.1 1.2 2.1)
- #
- if {$last_level != $level} {
- for {set l $last_level} {$l > $level} {incr l -1} {append output "\n" }
- for {set l $last_level} {$l < $level} {incr l} {
- regsub -all {[.]} $prefix _ prefix_js
- append output [my page_reorder_open_ul -min_level $min_level -ID $ID -prefix_js $prefix_js $l]
- }
- set last_level $level
- set last_prefix $prefix
- }
- # Pass the page_order for the element to javascript and add
- # the li element for the section.
- set item_id [my page_reorder_item_id -ID $ID -prefix_js $prefix_js -page_order $page_order js]
- append output "
"
- }
-
- set p [::xo::db::CrClass get_instance_from_db -item_id 0 -revision_id $page_id]
-
- $p set unresolved_references 0
- #$p set render_adp 0
- switch [$p info class] {
- ::xowiki::Form {
- set content [$p render]
- }
- default {
- set content [$p render -with_footer false]
- #set content [string map [list "\{\{" "\\\{\{"] $content]
- }
- }
-
- append output [my render_item \
- -menu_buttons $menu_buttons \
- -content $content \
- -object $p \
- -level $level]
- if {$with_footer} {
- append output [$p htmlFooter -content $content]
- }
- }
-
- if {$allow_reorder ne ""} {
- for {set l $last_level} {$l > 0} {incr l -1} {append output "\n" }
- append output "\n"
- }
- return $output
- }
-
- book instproc render_images {-addClass pages} {
- #
- # Return a list of the rendered images in HTML markup. The page
- # content is reduced to a bare image. Note that this function
- # does not return "pages" not containing images.
- #
- set imageList {}
- foreach o [$pages children] {
- set p [::xo::db::CrClass get_instance_from_db -item_id 0 -revision_id [$o set page_id]]
- set html [$p render -with_footer false]
- if {[regsub -nocase {^(.*)(]+>)(.*)$} $html {\2} html] < 1} continue
- if {[info exists addClass]} {
- regsub -nocase {class\s*=\s*'([^']+)'} $html "class='\\1 $addClass'" html
- }
- lappend imageList $html
- }
- return $imageList
- }
-
- book instproc render {} {
- my get_parameters
-
- my instvar __including_page
- lappend ::xowiki_page_item_id_rendered [$__including_page item_id]
- $__including_page set __is_book_page 1
-
- set allow_reorder [my page_reorder_check_allow $allow_reorder]
-
- set extra_where_clause ""
- set cnames ""
- if {[info exists category_id]} {
- foreach {cnames extra_where_clause} [my category_clause $category_id] break
- }
-
- foreach {locale locale_clause} \
- [::xowiki::Includelet locale_clause -revisions p -items p $package_id $locale] break
-
- if {$folder_mode} {
- # TODO just needed for michael aram?
- set parent_id [$__including_page item_id]
- } else {
- #set parent_id [$package_id folder_id]
- set parent_id [$__including_page parent_id]
- }
-
- set pages [::xowiki::Page instantiate_objects -sql \
- "select page_id, page_order, name, title, item_id \
- from xowiki_page_live_revision p \
- where parent_id = $parent_id \
- and not page_order is NULL $extra_where_clause \
- $locale_clause \
- [::xowiki::Page container_already_rendered item_id]" ]
- $pages mixin add ::xo::OrderedComposite::IndexCompare
- $pages orderby page_order
-
- #
- # filter range
- #
- if {$range ne ""} {
- foreach {from to} [split $range -] break
- foreach p [$pages children] {
- if {[$pages __value_compare [$p set page_order] $from 0] == -1
- || [$pages __value_compare [$p set page_order] $to 0] > 0} {
- $pages delete $p
- }
- }
- }
-
- if {[llength [$pages children]] < 1} {
- #
- # Provide a hint why not pages were found
- #
- set p [::xo::db::CrClass get_instance_from_db -item_id $parent_id]
- set output "
No pages with parent object [$p name], page_order not NULL and an appropriate publish status found
\n"
- } else {
- set output [my render_items \
- -menu_buttons $menu_buttons \
- -with_footer $with_footer \
- -pages $pages \
- -cnames $cnames \
- -allow_reorder $allow_reorder]
- }
- return $output
- }
-}
-
-namespace eval ::xowiki::includelet {
- #############################################################################
- # display a sequence of pages via W3C slidy
- #
- ::xowiki::IncludeletClass create slidy \
- -superclass ::xowiki::includelet::book
-
- slidy instproc render_items {
- -pages:required
- {-cnames ""}
- {-allow_reorder ""}
- -menu_buttons
- {-with_footer "false"}
- } {
- my instvar __including_page
- if {$cnames ne "" || $allow_reorder ne "" || $with_footer ne "false"} {
- error "ignoring cnames, allow_reorder, and with_footer for the time being"
- }
-
- set output ""
- foreach o [$pages children] {
- set p [::xo::db::CrClass get_instance_from_db -item_id 0 -revision_id [$o set page_id]]
- append output "
\n" [$p render -with_footer false] "\n
\n"
- }
-
- ns_return 200 text/html [subst {
-
- [$__including_page title]
-
-
-
-
-
-$output
-
- }]
- ad_script_abort
- }
-}
-
-namespace eval ::xowiki::includelet {
- #############################################################################
- # display a sequence of pages via jQuery Carousel
- #
- ::xowiki::IncludeletClass create jquery-carousel \
- -superclass ::xowiki::includelet::book
-
- jquery-carousel instproc render_items {
- -pages:required
- {-cnames ""}
- {-allow_reorder ""}
- -menu_buttons
- {-with_footer "false"}
- } {
- my instvar __including_page
- if {$cnames ne "" || $allow_reorder ne "" || $with_footer ne "false"} {
- error "ignoring cnames, allow_reorder, and with_footer for the time being"
- }
-
- set id [my js_name]
- append output \
- "
\n" \
-
[join [my render_images $pages] "
\n
"]
\
- "
\n"
-
- ::xo::Page requireJS "/resources/xowiki/jquery/jquery.min.js"
- ::xo::Page requireJS "/resources/xowiki/jquery.carousel.min.js"
- ::xo::Page requireJS [subst -novariables {
- $(function(){
- $("#[set id]").carousel( );
- });
- }]
- return $output
- }
-}
-
-namespace eval ::xowiki::includelet {
- #############################################################################
- # Display a sequence of images via the jQuery plugin
- #
- # Infinite Carousel
- #
- # http://www.catchmyfame.com/2009/08/27/jquery-infinite-carousel-plugin-1-2-released/
- #
- # This includelet works only with images
- #
- # Install: obtain jQuery plugin
- #
- # http://www.catchmyfame.com/jquery/jquery.infinitecarousel2.zip
- #
- # and install its files under packages/xowiki/resources/infiniteCarousel:
- #
- # infiniteCarousel/images/caption.gif
- # infiniteCarousel/images/leftright.gif
- # infiniteCarousel/images/playpause.gif
- # infiniteCarousel/jquery.infinitecarousel2.js
- # infiniteCarousel/jquery.infinitecarousel2.min.js
- #
- ::xowiki::IncludeletClass create jquery-infinite-carousel \
- -superclass ::xowiki::includelet::book
-
- jquery-infinite-carousel instproc render_items {
- -pages:required
- {-cnames ""}
- {-allow_reorder ""}
- -menu_buttons
- {-with_footer "false"}
- } {
- my instvar __including_page
- if {$cnames ne "" || $allow_reorder ne "" || $with_footer ne "false"} {
- error "ignoring cnames, allow_reorder, and with_footer for the time being"
- }
-
- set id [my js_name]
- append output \
- "
\n" \
-
[join [my render_images $pages] "
\n
"]
\
- "
\n"
-
- ::xo::Page requireJS "/resources/xowiki/jquery/jquery.min.js"
- ::xo::Page requireJS "/resources/xowiki/infiniteCarousel/jquery.infinitecarousel2.min.js"
- ::xo::Page requireJS [subst -novariables {
- $(function(){
- $("#[set id]").infiniteCarousel({
- displayTime: 6000,
- textholderHeight : .25,
- imagePath: '/resources/xowiki/infiniteCarousel/images/',
- });
- });}]
-
- return $output
- }
-}
-
-namespace eval ::xowiki::includelet {
- #############################################################################
- # Display a sequence of images via 3D Cloud Carousel
- #
- # This includelet works only with images.
- #
- # Install: get the jQuery plugins cloud-carousel and mousewheel from
- #
- # http://www.professorcloud.com/mainsite/carousel.htm
- # https://github.com/brandonaaron/jquery-mousewheel/downloads
- #
- # and install these files under
- #
- # packages/xowiki/resources/cloud-carousel.1.0.5.min.js
- # packages/xowiki/resources/jquery.mousewheel.min.js
- #
- # The following elements might be used in the page containing the includelet:
- #
- #
- #
- #
- #
- #
-
- ::xowiki::IncludeletClass create jquery-cloud-carousel \
- -superclass ::xowiki::includelet::book
-
- jquery-cloud-carousel instproc render_items {
- -pages:required
- {-cnames ""}
- {-allow_reorder ""}
- -menu_buttons
- {-with_footer "false"}
- } {
- my instvar __including_page
- if {$cnames ne "" || $allow_reorder ne "" || $with_footer ne "false"} {
- error "ignoring cnames, allow_reorder, and with_footer for the time being"
- }
-
- set id [my js_name]
- append output \
- "