Index: openacs-4/packages/xowiki/tcl/chat-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/chat-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/tcl/chat-procs.tcl 3 Feb 2006 22:17:41 -0000 1.1 @@ -0,0 +1,116 @@ +ad_library { + XoWiki - chat procs + + @creation-date 2006-02-02 + @author Gustaf Neumann + @cvs-id $Id: chat-procs.tcl,v 1.1 2006/02/03 22:17:41 gustafn Exp $ +} +namespace eval ::xowiki { + Class Message -parameter {time user_id msg} + Class Chat -superclass ::xo::OrderedComposite \ + -parameter {chat_id keep_nr_messages {encoder urlencode} {timewindow 600}} + Chat instproc context {user_id} { + if {![my exists now]} {my set now [clock clicks -milliseconds]} + if {$user_id == -1} {set user_id [ad_conn user_id]} + my set uid $user_id + my set array [self class]-[my set chat_id] + } + Chat instproc init {} { + my instvar array uid now + my context 0 + if {![nsv_exists $array-seen newest]} { + nsv_set $array-seen newest $now + } + } + Chat instproc add_msg {{-user_id -1} msg} { + my instvar array uid now + my context $user_id + set msg_id $now.$uid + nsv_set $array $msg_id [list $now [clock seconds] $uid $msg] + nsv_set $array-seen newest $now + my get_new -user_id $uid + } + Chat instproc check_age {key ago} { + my instvar array timewindow + if {$ago > $timewindow} { + nsv_unset $array $key + #my log "--c unsetting $key" + return 0 + } + return 1 + } + Chat instproc get_new {{-user_id -1}} { + my instvar array uid now + my context $user_id + set last [expr {[nsv_exists $array-seen $uid] ? [nsv_get $array-seen $uid] : 0}] + if {[nsv_get $array-seen newest]>$last} { + my log "--s must check $uid: [nsv_get $array-seen newest] > $last" + foreach {key value} [nsv_array get $array] { + foreach {timestamp secs user msg} $value break + if {$timestamp > $last} { + my add [Message new -time $secs -user_id $user -msg $msg] + } else { + my check_age $key [expr {($now - $timestamp) / 1000}] + } + } + nsv_set $array-seen $uid $now + } + my render + } + Chat instproc get_all {{-user_id -1}} { + my instvar array uid now + my context $user_id + foreach {key value} [nsv_array get $array] { + foreach {timestamp secs user msg} $value break + if {[my check_age $key [expr {($now - $timestamp) / 1000}]]} { + my add [Message new -time $secs -user_id $user -msg $msg] + } + } + nsv_set $array-seen $uid $now + my render + } + Chat instproc login {{-user_id -1}} { + my instvar array uid now + my context $user_id + # was the user already active? + if {![nsv_exists $array-seen $uid]} { + my add_msg -user_id $uid login + } + my encoder noencode + my get_all -user_id $uid + } + Chat instproc urlencode {string} {ns_urlencode $string} + Chat instproc noencode {string} {set string} + Chat instproc encode {string} {my [my encoder] $string} + Chat instproc render {} { + my orderby time + set result "" + foreach child [my children] { + set msg [$child msg] + set user_id [$child user_id] + set timelong [clock format [$child time]] + set timeshort [clock format [$child time] -format {[%H:%M:%S]}] + if {$user_id > 0} { + acs_user::get -user_id $user_id -array user + set name [expr {$user(screen_name) ne "" ? $user(screen_name) : $user(name)}] + set url "/shared/community-member?user%5fid=$user_id" + set creator "$name" + } else { + set creator "Nobody" + } + append result "$timeshort\ + [my encode $creator]\ + [my encode $msg]\n" + } + return $result + } + + if {0} { + Chat c1 -chat_id 222 + set _ "" + c1 add_msg "Hello World now" + append _ [c1 get_new] + + ns_return 200 text/html $_ + } +} \ No newline at end of file Index: openacs-4/packages/xowiki/tcl/xowiki-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/xowiki-procs.tcl,v diff -u -r1.10 -r1.11 --- openacs-4/packages/xowiki/tcl/xowiki-procs.tcl 30 Jan 2006 02:04:51 -0000 1.10 +++ openacs-4/packages/xowiki/tcl/xowiki-procs.tcl 3 Feb 2006 22:17:41 -0000 1.11 @@ -1,3 +1,11 @@ +ad_library { + XoWiki - main libraray classes and objects + + @creation-date 2006-01-10 + @author Gustaf Neumann + @cvs-id $Id$ +} + namespace eval ::xowiki { ::Generic::CrClass create Page -superclass ::Generic::CrItem \ -pretty_name "XoWiki Page" -pretty_plural "XoWiki Pages" \ @@ -228,7 +236,7 @@ $data render_adp false $data render -update_references } - my set submit_link pages/[ad_urlencode [$data set title]]? + my set submit_link pages/[ad_urlencode [$data lang]:[$data set title]]? } WikiForm instproc new_data {} { @@ -452,6 +460,59 @@ } } + Page proc import {-user_id -package-id -folder-id {-replace 0} -objects} { + set object_type [self] + if {![info exists folder_id]} {set folder_id [$object_type require_folder -name xowiki]} + if {![info exists package_id]} {set package_id [ad_conn package_id]} + if {![info exists user_id]} {set user_id [ad_conn user_id]} + if {![info exists objects]} {set objects [$object_type allinstances]} + + set msg "processing objects: $objects

" + set added 0 + set replaced 0 + foreach o $objects { + $o set parent_id $folder_id + $o set package_id $package_id + $o set creation_user $user_id + # page instances have references to page templates, add these first + if {[$o istype ::xowiki::PageInstance]} continue + set item [CrItem lookup -title [$o set title] -parent_id $folder_id] + if {$item != 0 && $replace} { ;# we delete the original + ::Generic::CrItem delete -item_id $item + set item 0 + incr replaced + } + if {$item == 0} { + $o save_new + incr added + } + } + + foreach o $objects { + if {[$o istype ::xowiki::PageInstance]} { + db_transaction { + set item [CrItem lookup -title [$o set title] -parent_id $folder_id] + if {$item != 0 && $replace} { ;# we delete the original + ::Generic::CrItem delete -item_id $item + set item 0 + incr replaced + } + if {$item == 0} { ;# the item does not exist -> update reference and save + set old_template_id [$o set page_template] + set template [CrItem lookup \ + -title [$old_template_id set title] \ + -parent_id $folder_id] + $o set page_template $template + $o save_new + incr added + } + } + } + $o destroy + } + append msg "$added objects inserted, $replaced objects replaced

" + } + # # data definitions # Index: openacs-4/packages/xowiki/www/view.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/Attic/view.adp,v diff -u -r1.5 -r1.6 --- openacs-4/packages/xowiki/www/view.adp 30 Jan 2006 02:04:51 -0000 1.5 +++ openacs-4/packages/xowiki/www/view.adp 3 Feb 2006 22:17:41 -0000 1.6 @@ -5,9 +5,37 @@ + +

Index: openacs-4/packages/xowiki/www/view.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/Attic/view.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/packages/xowiki/www/view.tcl 19 Jan 2006 23:01:58 -0000 1.4 +++ openacs-4/packages/xowiki/www/view.tcl 3 Feb 2006 22:17:41 -0000 1.5 @@ -14,11 +14,10 @@ {revision_id:integer 0} {folder_id:optional} {object_type:optional} + {master 1} } -ns_log notice "-- view item_id=$item_id, [info exists folder_id]" ::xowiki::Page set recursion_count 0 - set page [::Generic::CrItem instantiate \ -item_id $item_id \ -revision_id $revision_id] @@ -28,14 +27,18 @@ # export title, text, and description to current scope $page instvar title text description lang_links +if {$master} { + set context [list $title] + set base [apm_package_url_from_id [ad_conn package_id]] + set rev_link [export_vars -base ${base}revisions {{page_id $item_id} title}] + set edit_link [export_vars -base ${base}edit {item_id}] + set new_link [export_vars -base ${base}edit {object_type}] + set index_link [export_vars -base ${base} {}] -set context [list $title] -set base [apm_package_url_from_id [ad_conn package_id]] -set rev_link [export_vars -base ${base}revisions {{page_id $item_id} title}] -set edit_link [export_vars -base ${base}edit {item_id}] -set new_link [export_vars -base ${base}edit {object_type}] -set index_link [export_vars -base ${base} {}] - -set return_url [export_vars -base [ad_conn url] item_id] -set gc_link [general_comments_create_link $item_id $return_url] -set gc_comments [general_comments_get_comments $item_id $return_url] + set return_url [export_vars -base [ad_conn url] item_id] + set gc_link [general_comments_create_link $item_id $return_url] + set gc_comments [general_comments_get_comments $item_id $return_url] +} else { + ns_return 200 text/html $content + ad_script_abort +} Index: openacs-4/packages/xowiki/www/admin/import.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/admin/import.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/xowiki/www/admin/import.tcl 26 Jan 2006 01:30:46 -0000 1.2 +++ openacs-4/packages/xowiki/www/admin/import.tcl 3 Feb 2006 22:17:41 -0000 1.3 @@ -17,58 +17,12 @@ break } - set file_name [template::util::file::get_property filename $upload_file] set upload_tmpfile [template::util::file::get_property tmp_filename $upload_file] - set mime_type [template::util::file::get_property mime_type $upload_file] set f [open $upload_tmpfile]; set content [read $f]; close $f if {[catch {eval $content} error]} { - append msg "Error: $error" + set msg "Error: $error" } else { - - set replace 0 ;# 1 is overwrite mode - set object_type ::xowiki::Page - set folder_id [$object_type require_folder -name xowiki] - - append msg "objects=[$object_type allinstances]

" - set added 0 - foreach o [$object_type allinstances] { - $o set parent_id $folder_id - $o set package_id [ad_conn package_id] - # page instances have references to page templates, add these first - if {[$o istype ::xowiki::PageInstance]} continue - set item [CrItem lookup -title [$o set title] -parent_id $folder_id] - if {$item != 0 && $replace} { ;# we delete the original - ::Generic::CrItem delete -item_id $item - set item 0 - } - if {$item == 0} { - $o save_new - incr added - } - } - - foreach o [$object_type allinstances] { - if {[$o istype ::xowiki::PageInstance]} { - db_transaction { - set item [CrItem lookup -title [$o set title] -parent_id $folder_id] - if {$item != 0 && $replace} { ;# we delete the original - ::Generic::CrItem delete -item_id $item - set item 0 - } - if {$item == 0} { ;# the item does not exist -> update reference and save - set old_template_id [$o set page_template] - set template [CrItem lookup \ - -title [$old_template_id set title] \ - -parent_id $folder_id] - $o set page_template $template - $o save_new - incr added - } - } - } - $o destroy - } - append msg "$added objects inserted

" + set msg [::xowiki::Page import] } } Index: openacs-4/packages/xowiki/www/admin/samples/ajax-chat.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/admin/samples/ajax-chat.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/admin/samples/ajax-chat.tcl 3 Feb 2006 22:17:41 -0000 1.1 @@ -0,0 +1,46 @@ +namespace eval ::xowiki::tmp { + ::xowiki::Object create ajax-chat -noinit \ + -set object_type ::xowiki::Object \ + -set lang en \ + -set description {} \ + -set text { +proc content {} { + auth::require_login + set chat_id 22 + set path packages/xowiki/www/ajax/chat.js + if { ![file exists [acs_root_dir]/$path] } { + return -code error "File [acs_root_dir]/$path does not exist" + } + set file [open [acs_root_dir]/$path]; set js [read $file]; close $file + set login_url /xowiki/ajax/chat?m=login&id=$chat_id + set send_url /xowiki/ajax/chat?m=add_msg&id=$chat_id&msg= + set get_update "chatSendCmd(\"/xowiki/ajax/chat?m=get_new&id=$chat_id\",chatReceiver)" + set get_all "chatSendCmd(\"/xowiki/ajax/chat?m=get_all&id=$chat_id\",chatReceiver)" + return " + +

+ + + + 0 +   +" +} +} \ + -set nls_language en_US \ + -set mime_type {text/html} \ + -set title en:ajax-chat +} + +set page_title "Import XoWiki Pages" +set context {} +set msg [::xowiki::Page import -objects ::xowiki::tmp::ajax-chat -replace true] +template::set_file "[file dir $__adp_stub]/../importmsg" +ad_return_template Index: openacs-4/packages/xowiki/www/ajax/chat.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/ajax/Attic/chat.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/ajax/chat.js 3 Feb 2006 22:17:41 -0000 1.1 @@ -0,0 +1,74 @@ +function receiver1() { + if (http.readyState == 4) { + // alert('status code =' + http.status); + if (http.status != 200) { + alert('Something wrong in HTTP request, status code = ' + http.status); + } + } +} + +function chatReceiver() { + if (http.readyState == 4) { + // alert('status code =' + http.status); + if (http.status == 200) { + appendToMessages(http.responseText); + } else { + alert('Something wrong in HTTP request, status code = ' + http.status); + } + } +} + +function appendToMessages(content) { + var xmlobject = (new DOMParser()).parseFromString(content, 'application/xhtml+xml'); + //var xmlobject = (new DOMParser()).parseFromString(content, 'text/html'); + var items = xmlobject.getElementsByTagName('TR'); + //alert('found ' + items.length + ' items'); + var counter = document.getElementById('chatCounter'); + counter.innerHTML = parseInt(counter.innerHTML) + 1; + //document.getElementById('chatResponse').innerHTML = content; + + //if (items.length > 0) {alert('appending ' + content);} + var tbody = frames['ichat'].document.getElementById('messages').tBodies[0]; + //for (var i = 0 ; i < items.length ; i++) { + // tbody.appendChild(frames['ichat'].document.importNode(items[i],true)); + //} + var tr, td, e, s; + for (var i = 0 ; i < items.length ; i++) { + tr = document.createElement('tr'); + e = items[i].getElementsByTagName('TD'); + td = document.createElement('td'); + td.innerHTML = unescape(e[0].firstChild.nodeValue); + td.className = 'timestamp'; + tr.appendChild(td); + + td = document.createElement('td'); + s = e[1].firstChild.nodeValue; + td.innerHTML = unescape(e[1].firstChild.nodeValue.replace(/\+/g,' ')); + //td.appendChild(document.createTextNode(e[1].firstChild.nodeValue)); + td.className = 'user'; + tr.appendChild(td); + + td = document.createElement('td'); + td.innerHTML = unescape(e[2].firstChild.nodeValue.replace(/\+/g,' ')); + //td.appendChild(document.createTextNode(e[2].firstChild.nodeValue)); + td.className = 'message'; + tr.appendChild(td); + + //tbody.appendChild(items[i]); + //tbody.appendChild(items[i].cloneNode(true)); + tbody.appendChild(tr); + + } + frames['ichat'].window.scrollTo(0,tbody.offsetHeight); +} + +function chatSendMsg(send_url,handler) { + var msgField = document.getElementById('chatMsg'); + chatSendCmd(send_url + escape(msgField.value),handler); + msgField.value = ''; +} +function chatSendCmd(url,handler) { + http.open('GET', url, true); + http.onreadystatechange = handler; + http.send(null); +} Index: openacs-4/packages/xowiki/www/ajax/chat.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/ajax/Attic/chat.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/ajax/chat.tcl 3 Feb 2006 22:17:41 -0000 1.1 @@ -0,0 +1,35 @@ +ad_page_contract { + a tiny chat client + + @author Gustaf Neumann (gustaf.neumann@wu-wien.ac.at) + @creation-date Jan 31, 2006 + @cvs-id $Id: chat.tcl,v 1.1 2006/02/03 22:17:41 gustafn Exp $ +} -query { + m + id + msg:optional +} + +::xowiki::Chat c1 -volatile -chat_id $id +switch -- $m { + add_msg { + set _ [c1 $m $msg] + ns_log notice "--c add_msg returns '$_'" + } + login - + get_new - + get_all {set _ [c1 $m]} + default {ns_log error "--c unknown method $m called."} +} + +ns_return 200 text/html " + + + +$_
+ +" \ No newline at end of file