- Publicity: Public Only All
weblog-procs.tcl
Xolirc weblog procs
- Location:
- packages/xolirc/tcl/weblog-procs.tcl
Procedures in this file
Detailed information
[ hide source ] | [ make this the default ]Content File Source
::xo::library doc { Xolirc weblog procs } ::xo::library require -package xowiki weblog-procs namespace eval ::xolirc { Class create ::xolirc::Weblog -superclass ::xowiki::Weblog ::xolirc::Weblog instproc init {} { my instvar filter_msg package_id nr_items next_page_link prev_page_link my instvar date category_id tag ptag page_number page_size summary items locale my instvar name_filter entry_label entries_of sort_composite summary_chars my log "--W starting" set folder_id [::$package_id folder_id] set filter_msg "" set query_parm "" # set up filters set extra_from_clause "" set extra_where_clause "" if {$date ne ""} { #set date_clause "and date_trunc('day',bt.publish_date) = '$date'" set date_clause "and [::xo::db::sql date_trunc_expression day bt.creation_date $date]" set filter_msg "Filtered by date $date" set query_parm "&date=$date" } else { set date_clause "" } if {$category_id ne ""} { set cnames [list] #append extra_where_clause "and c.object_id = ci.item_id and c.category_id = $category_id " #append extra_from_clause ",category_object_map c " foreach cid [split $category_id ,] { append extra_where_clause "and exists (select * from category_object_map \ where object_id = ci.item_id and category_id = $cid)" lappend cnames [::category::get_name $cid] } append extra_from_clause "" set filter_msg "Filtered by category [join $cnames {, }]" set query_parm "&category_id=$category_id" } #my msg "tag=$tag" if {$tag ne ""} { set filter_msg "Filtered by your tag $tag" append extra_from_clause ",xowiki_tags tags " append extra_where_clause "and tags.item_id = ci.item_id and tags.tag = :tag and \ tags.user_id = [::xo::cc user_id]" set query_parm "&tag=[ad_urlencode $tag]" } #my msg "ptag=$ptag" if {$ptag ne ""} { set filter_msg "Filtered by popular tag $ptag" append extra_from_clause ",xowiki_tags tags " append extra_where_clause "and tags.item_id = ci.item_id and tags.tag = :ptag " set query_parm "&ptag=[ad_urlencode $ptag]" } #my msg filter_msg=$filter_msg if {$name_filter ne ""} { append extra_where_clause "and ci.name ~ E'$name_filter' " } set base_type ::xowiki::Page set base_table xowiki_pagei set attributes [list bt.revision_id bt.creation_date bt.title bt.creator bt.creation_user \ ci.parent_id bt.description s.body pi.instance_attributes] set class_clause \ " and ci.content_type not in ('::xowiki::PageTemplate','::xowiki::Object')" if {$entries_of ne ""} { if {[string match "::*" $entries_of]} { # xotcl classes were provided as a filter set class_clause \ " and ci.content_type in ('[join [split $entries_of { }] ',']')" } else { # we use a form as a filter my instvar form_items set form_items [::xowiki::Weblog instantiate_forms \ -forms $entries_of \ -package_id $package_id] append extra_where_clause " and bt.page_template in ('[join $form_items ',']') and bt.page_instance_id = bt.revision_id " set base_type ::xowiki::FormPage set base_table xowiki_form_pagei set class_clause "" } } if {$locale ne ""} { #set locale "default+system" foreach {locale locale_clause} \ [::xowiki::Includelet locale_clause -revisions bt -items ci $package_id $locale] break #my msg "--L locale_clause=$locale_clause" append extra_where_clause $locale_clause } # create an item container, which delegates rendering to its children set items [::xo::OrderedComposite new -proc render {} { set content "" foreach c [my children] { append content [$c render] } return $content }] foreach i [split [my exclude_item_ids] ,] {lappend ::xowiki_page_item_id_rendered $i} $items set weblog_obj [self] set sql \ [list -folder_id $folder_id \ -select_attributes $attributes \ -orderby "creation_date desc" \ -base_table $base_table \ -from_clause "\ left outer join syndication s on s.object_id = bt.revision_id \ left join xowiki_page_instance pi on (bt.revision_id = pi.page_instance_id) \ $extra_from_clause" \ -where_clause "ci.item_id not in ([my exclude_item_ids]) \ and ci.name != '::$folder_id' and ci.name not like '%weblog%' $date_clause \ [::xowiki::Page container_already_rendered ci.item_id] \ $class_clause \ and ci.publish_status <> 'production' \ $extra_where_clause" ] if {$page_number ne ""} { lappend sql -page_number $page_number -page_size $page_size } set nr_items [db_string count [eval $base_type instance_select_query $sql -count true]] #my msg count=$nr_items #my msg sql=$sql set s [$base_type instantiate_objects -sql [eval $base_type instance_select_query $sql]] foreach c [$s children] { $c instvar revision_id creation_date title name item_id creator creation_user \ parent_id description body instance_attributes set time [::xo::db::tcl_date $creation_date tz] set pretty_date [util::age_pretty -timestamp_ansi $time \ -sysdate_ansi [clock_to_ansi [clock seconds]] \ -mode_3_fmt "%d %b %Y, at %X"] if {$summary} { # we need always: package_id item_id parent_id name title creator creation_user pretty_date set p [::xowiki::Page new \ -package_id $package_id -parent_id $parent_id \ -item_id $item_id -revision_id $revision_id \ -name $name -title $title -creator $creator] $p set creation_user $creation_user if {$description eq "" && [my compute_summary] && $body ne ""} { $p set description [my get_description -nr_chars $summary_chars $body] } else { $p set description $description } $p set instance_attributes $instance_attributes } else { # do full instantiation and rendering # ns_log notice "--Render object revision_id = $revision_id $name $title ::$revision_id?[my isobject ::$revision_id]" set p [::xo::db::CrClass get_instance_from_db -item_id 0 -revision_id $revision_id] # in cases, the revision was created already earlier, drop the mixins if {[$p info mixin] ne ""} {$p mixin {}} if {[my exists entry_flag]} {$p set [my entry_flag] 1} if {[my no_footer]} {$p set __no_footer 1} # if {[catch {$p set description [$p render]} errorMsg]} {} if {[catch {$p set description [$p render -with_footer false]} errorMsg]} { set description "Render Error ($errorMsg) $revision_id $name $title" } if {[my exists entry_flag]} {$p unset [my entry_flag]} #my log "--W $p render (mixins=[$p info mixin]) => $description" } $p set pretty_date $pretty_date $p set creation_date $creation_date #my log "--W setting $p set publish_date $publish_date" #$p proc destroy {} {my log "--Render temporal object destroyed"; next} #ns_log notice "--W Render object $p DONE $revision_id $name $title " $p mixin add [my set entry_renderer] #my log "--W items=$items, added mixin [my set entry_renderer] to $p, has now <[$p info mixin]>" $items add $p } array set smsg {1 full 0 summary} set weblog_href [$package_id package_url][$package_id get_parameter weblog_page] set flink "<a href='$weblog_href?summary=[expr {!$summary}]$query_parm'>$smsg($summary)</a>" if {$page_number ne ""} { set nr [llength [$items children]] set from [expr {($page_number-1)*$page_size+1}] set to [expr {($page_number-1)*$page_size+$nr}] set range [expr {$nr > 1 ? "$from - $to" : $from}] if {$filter_msg ne ""} { append filter_msg ", $range of $nr_items $entry_label (<a href='$weblog_href'>all</a>, $flink)" } else { append filter_msg "Showing $range of $nr_items $entry_label ($flink)" } set next_p [expr {$nr_items > $page_number*$page_size}] set prev_p [expr {$page_number > 1}] if {$next_p} { set query [::xo::update_query_variable [ns_conn query] page_number [expr {$page_number+1}]] set next_page_link [export_vars -base [::xo::cc url] $query] } if {$prev_p} { set query [::xo::update_query_variable [ns_conn query] page_number [expr {$page_number-1}]] set prev_page_link [export_vars -base [::xo::cc url] $query] } } #my proc destroy {} {my log "--W"; next} if {$sort_composite ne ""} { foreach {kind att direction} [split $sort_composite ,] break if {$kind eq "method"} {$items mixin add ::xo::OrderedComposite::MethodCompare} $items orderby -order [expr {$direction eq "asc" ? "increasing" : "decreasing"}] $att } my log "--W done" } }