sajax-0.12/php/Readme.txt0100644000175000017500000000020510226772213014245 0ustar tlacktlackSAJAX PHP BACKEND ----------------- Contributed and copyighted by Thomas Lackner and ModernMethod (http://www.modernmethod.com/). sajax-0.12/php/example_multiply.php0100644000175000017500000000152310226772213016416 0ustar tlacktlack Multiplier * = sajax-0.12/php/Sajax.php0100644000175000017500000002063210367343254014101 0ustar tlacktlack$v) { $esc_key = sajax_esc($k); if (is_numeric($k)) $s .= "$k: " . sajax_get_js_repr($v) . ", "; else $s .= "\"$esc_key\": " . sajax_get_js_repr($v) . ", "; } if (count($value)) $s = substr($s, 0, -2); return $s . " }"; } else { $esc_val = sajax_esc($value); $s = "'$esc_val'"; return $s; } } function sajax_handle_client_request() { global $sajax_export_list; $mode = ""; if (! empty($_GET["rs"])) $mode = "get"; if (!empty($_POST["rs"])) $mode = "post"; if (empty($mode)) return; $target = ""; if ($mode == "get") { // Bust cache in the head header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header ("Pragma: no-cache"); // HTTP/1.0 $func_name = $_GET["rs"]; if (! empty($_GET["rsargs"])) $args = $_GET["rsargs"]; else $args = array(); } else { $func_name = $_POST["rs"]; if (! empty($_POST["rsargs"])) $args = $_POST["rsargs"]; else $args = array(); } if (! in_array($func_name, $sajax_export_list)) echo "-:$func_name not callable"; else { echo "+:"; $result = call_user_func_array($func_name, $args); echo "var res = " . trim(sajax_get_js_repr($result)) . "; res;"; } exit; } function sajax_get_common_js() { global $sajax_debug_mode; global $sajax_request_type; global $sajax_remote_uri; global $sajax_failure_redirect; $t = strtoupper($sajax_request_type); if ($t != "" && $t != "GET" && $t != "POST") return "// Invalid type: $t.. \n\n"; ob_start(); ?> // remote scripting library // (c) copyright 2005 modernmethod, inc var sajax_debug_mode = ; var sajax_request_type = ""; var sajax_target_id = ""; var sajax_failure_redirect = ""; function sajax_debug(text) { if (sajax_debug_mode) alert(text); } function sajax_init_object() { sajax_debug("sajax_init_object() called..") var A; var msxmlhttp = new Array( 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'); for (var i = 0; i < msxmlhttp.length; i++) { try { A = new ActiveXObject(msxmlhttp[i]); } catch (e) { A = null; } } if(!A && typeof XMLHttpRequest != "undefined") A = new XMLHttpRequest(); if (!A) sajax_debug("Could not create connection object."); return A; } var sajax_requests = new Array(); function sajax_cancel() { for (var i = 0; i < sajax_requests.length; i++) sajax_requests[i].abort(); } function sajax_do_call(func_name, args) { var i, x, n; var uri; var post_data; var target_id; sajax_debug("in sajax_do_call().." + sajax_request_type + "/" + sajax_target_id); target_id = sajax_target_id; if (typeof(sajax_request_type) == "undefined" || sajax_request_type == "") sajax_request_type = "GET"; uri = ""; if (sajax_request_type == "GET") { if (uri.indexOf("?") == -1) uri += "?rs=" + escape(func_name); else uri += "&rs=" + escape(func_name); uri += "&rst=" + escape(sajax_target_id); uri += "&rsrnd=" + new Date().getTime(); for (i = 0; i < args.length-1; i++) uri += "&rsargs[]=" + escape(args[i]); post_data = null; } else if (sajax_request_type == "POST") { post_data = "rs=" + escape(func_name); post_data += "&rst=" + escape(sajax_target_id); post_data += "&rsrnd=" + new Date().getTime(); for (i = 0; i < args.length-1; i++) post_data = post_data + "&rsargs[]=" + escape(args[i]); } else { alert("Illegal request type: " + sajax_request_type); } x = sajax_init_object(); if (x == null) { if (sajax_failure_redirect != "") { location.href = sajax_failure_redirect; return false; } else { sajax_debug("NULL sajax object for user agent:\n" + navigator.userAgent); return false; } } else { x.open(sajax_request_type, uri, true); // window.open(uri); sajax_requests[sajax_requests.length] = x; if (sajax_request_type == "POST") { x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1"); x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); } x.onreadystatechange = function() { if (x.readyState != 4) return; sajax_debug("received " + x.responseText); var status; var data; var txt = x.responseText.replace(/^\s*|\s*$/g,""); status = txt.charAt(0); data = txt.substring(2); if (status == "") { // let's just assume this is a pre-response bailout and let it slide for now } else if (status == "-") alert("Error: " + data); else { if (target_id != "") document.getElementById(target_id).innerHTML = eval(data); else { try { var callback; var extra_data = false; if (typeof args[args.length-1] == "object") { callback = args[args.length-1].callback; extra_data = args[args.length-1].extra_data; } else { callback = args[args.length-1]; } callback(eval(data), extra_data); } catch (e) { sajax_debug("Caught error " + e + ": Could not eval " + data ); } } } } } sajax_debug(func_name + " uri = " + uri + "/post = " + post_data); x.send(post_data); sajax_debug(func_name + " waiting.."); delete x; return true; } // wrapper for function x_() { sajax_do_call("", x_.arguments); } sajax-0.12/php/example_date.php0100644000175000017500000000246610227025744015464 0ustar tlacktlack // 2- loading the server's date from the php function, // calling the javascript function to show it. // 3- scheduling another load to the next second // // Disclaimer: Hey! I dont speak english // Under (put your choice here) license function show_now() { //return server date return date("l dS of F Y h:i:s A"); } //starting SAJAX stuff $sajax_request_type = "GET"; sajax_init(); sajax_export("show_now"); sajax_handle_client_request(); ?> Show Server's Date Server date:
(loading...)
sajax-0.12/php/DEADJOE0100600000175000017500000000015010242126211013241 0ustar tlacktlack *** Modified files in JOE when it aborted on Mon May 16 10:22:01 2005 *** JOE was aborted by signal 15 sajax-0.12/php/example_types.php0100644000175000017500000000270710227000746015704 0ustar tlacktlack "Tom", "age" => 26); } function return_object() { class MyObj { var $name, $age; function MyObj($name, $age) { $this->name = $name; $this->age = $age; } } $o = new MyObj("Tom", 26); return $o; } function return_string() { return "Name: Tom / Age: 26"; } function return_int() { return 26; } function return_float() { return 26.25; } $sajax_request_type = "GET"; sajax_init(); sajax_export("return_array", "return_object", "return_string", "return_int", "return_float"); sajax_handle_client_request(); ?> sajax-0.12/php/example_options.php0100644000175000017500000000176310227011123016223 0ustar tlacktlack$v) { $s .= "$k:$v\n"; } return $s; } function test_post() { $s = "-- POST --\n"; foreach ($_POST as $k=>$v) { $s .= "$k:$v\n"; } return $s; } function get_the_time() { return date("Y-m-d h:i:s"); } // $sajax_debug_mode = 1; sajax_init(); sajax_export("test_get", "test_post", "get_the_time"); sajax_handle_client_request(); ?> Example of Sajax Options
Time will appear here
sajax-0.12/php/example_wall.php0100644000175000017500000000505010367343313015476 0ustar tlacktlack$dt $msg
\n"); fclose($f); } function refresh() { $lines = file("/tmp/wall.html"); // return the last 25 lines return join("\n", array_slice($lines, -25)); } $sajax_request_type = "GET"; sajax_init(); sajax_export("add_line", "refresh"); sajax_handle_client_request(); ?> Wall
Sajax v - You are a guinea pig - This example illustrates the simplest possible graffiti wall. It isn't meant to be perfect, featureful, or even useful.
Loading..
sajax-0.12/coldfusion/example_multiply.cfm0100644000175000017500000000156610226772213017761 0ustar tlacktlack function multiply(x, y) { return x * y; } sajax_init(); //sajax_debug_mode = 1;: sajax_export("multiply"); sajax_handle_client_request(); Multiplier * = sajax-0.12/coldfusion/sajax.cfm0100644000175000017500000001254010226772213015467 0ustar tlacktlack uri = cgi.query_string; if (find(uri,"?") gt 0) uri = uri & "?rs=" & urlencodedformat(func_name); else uri = uri & "&rs=" & urlencodedformat(func_name); uri = cgi.script_name & uri; // wrapper for #func_name# function x_#func_name#() { // count args; build URL sajax_do_call("#func_name#", "#sajax_esc(uri)#", x_#func_name#.arguments); } // remote scripting library // (c) copyright 2005 modernmethod, inc var sajax_debug_mode = #iif(sajax_debug_mode,'"true"','"false"')#; function sajax_debug(text) { if (sajax_debug_mode) alert("RSD: " + text) } function sajax_init_object() { sajax_debug("sajax_init_object() called..") var A; try { A=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { A=new ActiveXObject("Microsoft.XMLHTTP"); } catch (oc) { A=null; } } if(!A && typeof XMLHttpRequest != "undefined") A = new XMLHttpRequest(); if (!A) sajax_debug("Could not create connection object."); return A; } function sajax_do_call(func_name, url, args) { var i, x, n,responseText; url = url + "&rsargs="; for (i = 0; i < args.length-1; i++) url = url + escape(args[i]) + escape("#JSStringFormat(sajax_url_array_delim)#"); url = url + "&rsrnd=" + new Date().getTime(); x = sajax_init_object(); x.open("GET", url, true); x.onreadystatechange = function() { if (x.readyState != 4) return; responseText = x.responseText.replace(/^\s+/,''); // remove leading space, cf loves to put extra whitespace. sajax_debug("received " + responseText); var status; var data; status = responseText.charAt(0); data = responseText.substring(1); if (status == "-") alert("Error: " + data); else args[args.length-1](data); } x.send(null); sajax_debug(func_name + " url = " + url); sajax_debug(func_name + " waiting.."); delete x; } var func_name=""; var result=0; if(not isdefined("url.rs")) return; func_name = url['rs']; if(not ListFindNoCase(sajax_export_list, func_name)) writeoutput("-:#func_name# not callable"); else { writeoutput("+"); if(not isdefined("url.rsargs")) result = call_user_func(url['rs']); else result = call_user_func_array(url['rs'], get_url_array(url['rsargs'])); if(isdefined("result")) writeoutput(result); } if(sajax_test_mode eq 0) exit(); #output# -#cfcatch.type# #cfcatch.message# #cfcatch.detail# in #cfcatch.tagcontext[1].template# at #cfcatch.tagcontext[1].line# sajax_debug_mode = 0; sajax_test_mode = 0; sajax_export_list = ""; sajax_url_array_delim = chr(31); function call_user_func(user_func) { return(call_user_func_array(user_func,arraynew(1))); } function sajax_export() { var keys = structkeylist(arguments); var size = listlen(keys); var key = ""; for(i =1; i lte size;i=i+1) { key = listgetat(keys,i); sajax_export_list = listappend(sajax_export_list,arguments[key]); } } function call_user_func_array(user_func, arg_array) { var func_call = ""; var func_args = ""; var size = ArrayLen(arg_array); /* Loop though each of the args */ for(i=1; i lte size; i = i + 1) { func_args = func_args & "arg_array[#i#]"; if(i lt size) func_args = func_args & ","; } return(evaluate("#user_func#(#func_args#)")); } function get_url_array(url_array) { return(ListToArray(url_array,sajax_url_array_delim)); } function set_url_array(array) { return(ArrayToList(array,sajax_url_array_delim)); } function sajax_init() { } function sajax_show_common_js() { sajax_get_common_js(); } // javascript escape a value function sajax_esc(val) { return(jsstringformat(val)); } function sajax_show_one_stub(func_name) { sajax_get_one_stub(func_name); } sajax_js_has_been_shown = 0; function sajax_get_javascript() { if (not sajax_js_has_been_shown) { sajax_get_common_js(); sajax_js_has_been_shown = 1; } size = listlen(sajax_export_list); for(i = 1; i lte size; i=i+1) { func = listgetat(sajax_export_list,i); sajax_get_one_stub(func); } } function sajax_show_javascript() { sajax_get_javascript(); } SAJAX_INCLUDED = 1; sajax-0.12/coldfusion/test_sajax.cfm0100644000175000017500000000251010226772213016522 0ustar tlacktlack function assert(v1,v2){ writeoutput("#v1# = #v2#
"); } function test() { return(42); } function test2(v) { return(v); } function return_nothing() { } function make_error() { a = 1 + "a"; // cause an error }
assert(call_user_func("test"),42); foo = arraynew(1); foo[1] = 42; assert(call_user_func_array("test2",foo),foo[1]); foo = arraynew(1); foo[1] = 1; foo[2] = 2; a = set_url_array(foo); a = get_url_array(a); for(i = 1; i lte arraylen(foo);i=i+1) { assert(foo[i],a[i]); } sajax_export("test","test2","return_nothing","make_error"); assert(sajax_export_list,"test,test2,return_nothing,make_error"); sajax_test_mode = 1; url.rs = "test"; sajax_handle_client_request(); foo = arraynew(1); foo[1] = 43; writeoutput("
"); url.rs = "test2"; url.rsargs = set_url_array(foo); sajax_handle_client_request(); writeoutput("
"); url.rs = "return_nothing"; sajax_handle_client_request(); writeoutput("
"); url.rs = "make_error"; sajax_handle_client_request();
sajax-0.12/coldfusion/Readme.txt0100644000175000017500000000012710226772213015626 0ustar tlacktlackSAJAX COLDFUSION MX BACKEND --------------------------- Contributed by Eric Moritz. sajax-0.12/asp/Readme.txt0100644000175000017500000000012510367341352014244 0ustar tlacktlackASP support has been temporarily removed due to bugs. It will be back soon. - tlack sajax-0.12/io/example_multiply.io0100755000175000017500000000166110226772213016064 0ustar tlacktlack#!/usr/bin/env ioServer c := CGI clone multiply := method(x, y, x := x asNumber y := y asNumber return x * y ) s := Sajax clone s debug_mode := 1 s init s export("multiply") s handle_client_request write("Content-type: text/html\n\n") html := """ Multiplier * = """ write(html) sajax-0.12/io/Sajax.io0100755000175000017500000001041110226772213013531 0ustar tlacktlack// // Sajax Io Backend // (C) Copyright 2005 ModernMethod, Inc. // Released under BSD license // String interpolate := method( work := self clone last_idx := 0 while (1, idx := work find("", idx + 1) if (end_idx == Nil, // invalid interp expression.. we're done. break) // in the case of an empty interpolated expression, // lets move on if (end_idx - idx == 1, continue) // otherwise proceed with replacement. slotName := work substring(idx+1, end_idx) find_str := "" // write("doString(" .. slotName .. ")") replace_str := sender doString(slotName) work := work replace(find_str, replace_str) last_idx = end_idx + 1 ) return work ) Sajax := Object clone do ( debug_mode := 0 export_list := List clone js_has_been_shown := Nil init := method( return self ) handle_client_request := method( if (my_getenv("QUERY_STRING") == Nil, return ) form := CGI clone parse if (form hasKey("rs") == Nil, return ) write("Content-type: text/html\n"); write("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n"); write("Cache-Control: no-cache, must-revalidate\n"); write("Pragma: no-cache\n\n"); func_name := form at("rs") if (export_list contains(func_name) == Nil) then ( write("-:$func_name not callable\n") ) else ( write("+:") args := form at("rsargs[]") result := sender performWithArgList(func_name, args) write(result) ) exit; } show_common_js := method( if (debug_mode == 1, debugModeTrueFalse := "true", debugModeTrueFalse := "false") html := """ // remote scripting library // (c) copyright 2005 modernmethod, inc var rs_debug_mode = ; function rs_debug(text) { if (rs_debug_mode) alert("RSD: " + text) } function rs_init_object() { rs_debug("rs_init_object() called..") var A; try { A=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { A=new ActiveXObject("Microsoft.XMLHTTP"); } catch (oc) { A=null; } } if(!A && typeof XMLHttpRequest != "undefined") A = new XMLHttpRequest(); if (!A) rs_debug("Could not create connection object."); return A; } """ write(html interpolate) } esc := method(val, return val replace("\"", "\\\\\""); ) my_getenv := method(val, my_get := Nil if (?System) then ( my_get := System getSlot("getenv") ) else ( my_get := Object getSlot("getenv") ) return my_get(val) ) get_my_uri := method( uri := "http://www.example.com/" if (my_getenv("REQUEST_URI") != Nil) then ( uri := my_getenv("REQUEST_URI") ) else ( if (my_getenv("SCRIPT_NAME") != Nil) then ( uri := my_getenv("SCRIPT_NAME") if (my_getenv("QUERY_STRING") != Nil) then ( uri := uri .. "?" .. my_getenv("QUERY_STRING") ) ) ) return uri ) show_one := method(func_name, uri := get_my_uri func_name_encoded := CGI encodeUrlParam(func_name) if (uri contains("?") == Nil) then ( uri = uri .. "?rs=" .. func_name_encoded ) else ( uri = uri .. "&rs=" .. func_name_encoded ) html := """ // wrapper for function x_() { // count args; build URL var i, x, n; var url = ""; var a = x_.arguments; for (i = 0; i < a.length-1; i++) url = url + "&rsargs[]=" + escape(a[i]); url = url + "&rsrnd=" + new Date().getTime(); x = rs_init_object(); x.open("GET", url, true); x.onreadystatechange = function() { if (x.readyState != 4) return; rs_debug("received " + x.responseText); var status; var data; status = x.responseText.charAt(0); data = x.responseText.substring(2); if (status == "-") alert("Error: " + callback_n); else a[a.length-1](data); } x.send(null); rs_debug("x_ url = " + url); rs_debug("x_ waiting.."); delete x; } """ write(html interpolate) ) export := method(func, export_list add(func) } show_javascript := method( if (js_has_been_shown == Nil, show_common_js ) export_list foreach(index, func_name, show_one(func_name) ) ) ) sajax-0.12/perl/Readme.txt0100644000175000017500000000027010226772213014422 0ustar tlacktlackSAJAX PERL BACKEND ------------------ Contributed and copyighted by Nathan Schmidt (http://www.hinathan.com/). Additional guidance and consultation by Jason Purdy and Nate Mueller. sajax-0.12/perl/Sajax.pm0100644000175000017500000000704510226772213014077 0ustar tlacktlackpackage Sajax; use Data::Dumper; my $rs_debug_mode = 0; my $rs_js_has_been_shown = 0; my %rs_export_list = (); my %rs_coderef_list = (); sub incl_sajax { } sub rs_init { $rs_debug_mode = 0; $rs_js_has_been_shown = 0; %rs_export_list = (); %rs_coderef_list = (); } sub rs_handle_client_request { my($q)=@_; my $rv=""; if (!defined $q->param("rs")) { return undef; } my $func_name = $q->param("rs"); if ( defined $rs_export_list{$func_name}) { $rv .= "+:"; eval { $rv .= &$func_name($q->param("rsargs")); }; if($@) { print STDERR "Err:[$@]\n"; } } elsif ( defined $rs_coderef_list{$func_name}) { $rv .= "+:"; my $cr = $rs_coderef_list{$func_name}; eval { $rv .= &$cr($q->param("rsargs")); }; if($@) { print STDERR "Err:[$@]\n"; } } else { $rv .= "-:$func_name not callable"; } return $rv; } sub rs_show_common_js() { my $rv = ""; my $debug_mode = $rs_debug_mode ? "true" : "false"; my $CC = "\n// Perl backend version (c) copyright 2005 Nathan Schmidt"; $CC = ""; $rv .= <url(-query=>1); if ($uri =~ m/\?/) { $uri .= "&rs=".rs_urlencode($func_name); } else { $uri .= "?rs=".rs_urlencode($func_name); } my $urie = rs_esc($uri); $rv .= < * =
Show source EOT } print $rv; sajax-0.12/ruby/Sajax.rb0100644000175000017500000000654010226772213014104 0ustar tlacktlack#!/usr/bin/env ruby require 'cgi' require 'date' class Sajax def initialize(debug_mode=false) @debug_mode = debug_mode @export_list = Hash.new @js_has_been_shown = false @cgi = CGI.new end def handle_client_request func_name = @cgi.params['rs'].to_s if func_name == "" return end # Bust cache in the head @cgi.out({ "Expires" => "Mon, 26 Jul 1997 05:00:00 GMT", "Last-Modified" => DateTime.now.new_offset.strftime("%a, %d %m %H:%M:%S GMT"), # always modified "Cache-Control" => "no-cache, must-revalidate", # HTTP/1.1 "Pragma" => "no-cache", # HTTP/1.0 }) unless @export_list.has_key?(func_name) print "-:%s not callable" % func_name else print "+:" rsargs = @cgi.params['rsargs[]'] result = __send__(@export_list[func_name],*rsargs) print result end exit() end def show_common_js js_debug_mode = @debug_mode.to_s.downcase print <<-"EOS" // remote scripting library // (c) copyright 2005 modernmethod, inc var rs_debug_mode = #{js_debug_mode}; var rs_obj = false; var rs_callback = false; function rs_debug(text) { if (rs_debug_mode) alert("RSD: " + text) } function rs_init_object() { rs_debug("rs_init_object() called..") var A; try { A=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { A=new ActiveXObject("Microsoft.XMLHTTP"); } catch (oc) { A=null; } } if(!A && typeof XMLHttpRequest != "undefined") A = new XMLHttpRequest(); if (!A) rs_debug("Could not create connection object."); return A; } EOS end def rs_esc(val) return val.gsub('"', '\\\\"') end def show_one(func_name) uri = ENV['REQUEST_URI'] unless uri.include?('?') uri += "?rs=%s" % CGI.escape(func_name) else uri += "&rs=%s" % CGI.escape(func_name) end escapeduri = rs_esc(uri) print <<-"EOS" // wrapper for #{func_name} function x_#{func_name}(){ // count args; build URL var i, x, n; var url = "#{escapeduri}", a = x_#{func_name}.arguments; for (i = 0; i < a.length-1; i++) url = url + "&rsargs[]=" + escape(a[i]); x = rs_init_object(); x.open("GET", url, true); x.onreadystatechange = function() { if (x.readyState != 4) return; rs_debug("received " + x.responseText); var status; var data; status = x.responseText.charAt(0); data = x.responseText.substring(2); if (status == "-") alert("Error: " + callback_n); else a[a.length-1](data); } x.send(null); rs_debug("x_#{func_name} url = " + url); rs_debug("x_#{func_name} waiting.."); } EOS end def export(*args) for f in args @export_list[f] = f end end def show_javascript unless @js_has_been_shown show_common_js() @js_has_been_shown = true end for func_name in @export_list.keys show_one(func_name) end end end sajax-0.12/ruby/Readme.txt0100644000175000017500000000032310226772213014440 0ustar tlacktlackSAJAX RUBY BACKEND ------------------ Contributed and put into the public domain by an anonymous member of the Sajax forum. If anyone wants to take control of this port and improve it, it would be welcomed. sajax-0.12/python/Readme.txt0100644000175000017500000000046010226772213015002 0ustar tlacktlackSAJAX PYTHON BACKEND -------------------- Contributed and copyighted by Adam Collard. Additional guidance and consultation by Carlos Bueno. IMPORTANT: This backend is NOT licensed under the BSD-L. It is licensed under the Creative Commons "By" License version 2.0. Please see License.txt for details. sajax-0.12/python/multiply.py0100755000175000017500000000166510226772213015310 0ustar tlacktlack#!/usr/bin/env python import cgitb;cgitb.enable() import sajax1 def multiply(x,y): try: float_x, float_y = float(x), float(y) except: return 0 return float_x * float_y sajax1.sajax_init() sajax1.sajax_export(multiply) sajax1.sajax_handle_client_request() print """ PyMultiplier * = """ % locals() sajax-0.12/python/sajax1.py0100644000175000017500000000732710226772213014616 0ustar tlacktlack#!/usr/bin/env python import cgi import cgitb; cgitb.enable() import os import sys import datetime import urllib print "Content-type: text/html" sajax_debug_mode = False sajax_export_list = {} sajax_js_has_been_shown = False form = cgi.FieldStorage() def sajax_init(): pass def sajax_handle_client_request(): func_name = form.getfirst('rs') if func_name is None: return # Bust cache in the head print "Expires: Mon, 26 Jul 1997 05:00:00 GMT" print "Last-Modified: %s GMT" % datetime.datetime.utcnow().strftime( "%a, %d %m %H:%M:%S") # always modified print "Cache-Control: no-cache, must-revalidate" # HTTP/1.1 print "Pragma: no-cache" # HTTP/1.0 print if not func_name in sajax_export_list: print "-:%s not callable" % func_name else: print "+:", rsargs = form.getlist('rsargs[]') result = sajax_export_list[func_name](*rsargs) print result sys.exit() def sajax_get_common_js(): sajax_debug_modeJS = str(sajax_debug_mode).lower() return """\ // remote scripting library // (c) copyright 2005 modernmethod, inc var sajax_debug_mode = %(sajax_debug_modeJS)s; function sajax_debug(text) { if (sajax_debug_mode) alert("RSD: " + text) } function sajax_init_object() { sajax_debug("sajax_init_object() called..") var A; try { A=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { A=new ActiveXObject("Microsoft.XMLHTTP"); } catch (oc) { A=null; } } if(!A && typeof XMLHttpRequest != "undefined") A = new XMLHttpRequest(); if (!A) sajax_debug("Could not create connection object."); return A; } function sajax_do_call(func_name, url, args) { var i, x, n; for (i = 0; i < args.length-1; i++) url = url + "&rsargs[]=" + escape(args[i]); url = url + "&rsrnd=" + new Date().getTime(); x = sajax_init_object(); x.open("GET", url, true); x.onreadystatechange = function() { if (x.readyState != 4) return; sajax_debug("received " + x.responseText); var status; var data; status = x.responseText.charAt(0); data = x.responseText.substring(2); if (status == "-") alert("Error: " + data); else args[args.length-1](data); } x.send(null); sajax_debug(func_name + " url = " + url); sajax_debug(func_name + " waiting.."); delete x; } """ % locals() def sajax_show_common_js(): print sajax_get_common_js() def sajax_esc(val): return val.replace('"', '\\\\"') def sajax_get_one_stub(func_name): uri = os.environ['SCRIPT_NAME'] if os.environ.has_key('QUERY_STRING'): uri += "?" + os.environ['QUERY_STRING'] + "&rs=%s" % urllib.quote_plus(func_name) else: uri += "?rs=%s" % urllib.quote_plus(func_name) escapeduri = sajax_esc(uri) return """ // wrapper for %(func_name)s function x_%(func_name)s(){ // count args; build URL sajax_do_call("%(func_name)s", "%(escapeduri)s", x_%(func_name)s.arguments); } """ % locals() def sajax_show_one_stub(func_name): print sajax_get_one_stub(func_name) def sajax_export(*args): decorated = [(f.func_name, f) for f in args] sajax_export_list.update(dict(decorated)) def sajax_get_javascript(): global sajax_js_has_been_shown html = '' if not sajax_js_has_been_shown: html += sajax_get_common_js() sajax_js_has_been_shown = True for func_name in sajax_export_list.iterkeys(): html += sajax_get_one_stub(func_name) return html def sajax_show_javascript(): print sajax_get_javascript() sajax-0.12/python/wall.py0100755000175000017500000000406610226772213014366 0ustar tlacktlack#!/usr/bin/env python import cgi import cgitb;cgitb.enable() import datetime import os import sajax1 WALLFILE = '/tmp/wall.html' if not os.path.exists(WALLFILE): fh = open(WALLFILE, 'w') fh.close() def colourify_ip(ip): colour = ''.join(['%02x' % int(part) for part in ip.split('.')[-3:]]) return colour def add_line(msg): f = open("/tmp/wall.html","a") dt = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") msg = cgi.escape(msg) remote = os.environ['REMOTE_ADDR'] colour = colourify_ip(remote) f.write('%(dt)s %(msg)s
\n' % locals()) f.close() def refresh(): f = open("/tmp/wall.html") return '\n'.join(list(f)[-25:]) sajax1.sajax_init() sajax1.sajax_export(refresh, add_line) sajax1.sajax_handle_client_request() print """ PyWall Sajax - Wall Example
Loading..
""" % locals() sajax-0.12/python/License.txt0100644000175000017500000000036610226772213015174 0ustar tlacktlackThis work is licensed under the Creative Commons Attribution License. To view a copy of this license, visit http://creativecommons.org/licenses/by/2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. sajax-0.12/lua/sajax.lua0100644000175000017500000000565310226772213014126 0ustar tlacktlackmodule ("sajax") local export_list = {} local request_uri = "" function init () end function handle_client_request () if not cgi.rs then return end -- Bust cache in the head cgilua.header ("Expires", "Mon, 26 Jul 1997 05:00:00 GMT") -- Date in the past cgilua.header ("Last-Modified", os.date ("!%a, %d %b %Y %H:%M:%S GMT")) -- always modified cgilua.header ("Cache-Control", "no-cache, must-revalidate") -- HTTP/1.1 cgilua.header ("Pragma", "no-cache") -- HTTP/1.0 local funcname = cgi.rs if not export_list[funcname] then cgilua.put (string.format ("-:%s not callable", funcname)) else local func = export_list[funcname] local rsargs = cgi["rsargs[]"] local result if not rsargs then result = func() elseif type (rsargs) == "string" then result = func (rsargs) elseif type (rsargs) == "table" then result = func (unpack (rsargs)) else return end cgilua.put ("+:") cgilua.put (result) end return true end local function show_common_js () cgilua.put [[ // remote scripting library // (c) copyright 2005 modernmethod, inc var rs_debug_mode = false; function rs_debug(text) { if (rs_debug_mode) alert("RSD: " + text) } function rs_init_object() { rs_debug("rs_init_object() called..") var A; try { A=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { A=new ActiveXObject("Microsoft.XMLHTTP"); } catch (oc) { A=null; } } if(!A && typeof XMLHttpRequest != "undefined") A = new XMLHttpRequest(); if (!A) rs_debug("Could not create connection object."); return A; } ]] end local function show_one (funcname) local uri = request_uri if string.find (uri, "?") then uri = uri .. "&rs=" .. cgilua.urlcode.escape (funcname) else uri = uri .. "?rs=" .. cgilua.urlcode.escape (funcname) end cgilua.put (string.format ([[ // wrapper for %s function x_%s() { // count args; build URL var i, x, n; var url = "%s"; var a = x_%s.arguments; for (i = 0; i < a.length-1; i++) url = url + "&rsargs[]=" + escape(a[i]); url = url + "&rsrnd=" + new Date().getTime(); x = rs_init_object(); x.open("GET", url, true); x.onreadystatechange = function() { if (x.readyState != 4) return; rs_debug("received " + x.responseText); var status; var data; status = x.responseText.charAt(0); data = x.responseText.substring(2); if (status == "-") alert("Error: " + callback_n); else a[a.length-1](data); } x.send(null); rs_debug("x_%s url = " + url); rs_debug("x_%s waiting.."); delete x; } ]], funcname, funcname, uri, funcname, funcname, funcname)) end function export (funcname, func) export_list[funcname] = func end local js_has_been_shown = false function show_javascript () if not js_has_been_shown then show_common_js () js_has_been_shown = true end for fn,_ in pairs (export_list) do show_one (fn) end endsajax-0.12/lua/calculator.lp0100644000175000017500000000154210226772213014774 0ustar tlacktlack<% require "sajax" function multiply(x, y) return x * y end sajax.init() -- $rs_debug_mode = 1; sajax.export ("multiply", multiply) if sajax.handle_client_request () then return end %> Multiplier * = sajax-0.12/lua/Readme.txt0100644000175000017500000000015610226772213014244 0ustar tlacktlackSAJAX LUA BACKEND ----------------- Contributed and copyighted by Javier Guerra (http://www.guerrag.com/). sajax-0.12/Todo.txt0100644000175000017500000000151610300662641013170 0ustar tlacktlackSAJAX TO DO LIST ---------------- * Fix http://www.modernmethod.com/sajax/forum/viewtopic.php?p=308 * Return false if the object could not be created. * Make the whole darn thing an object * Add J2EE module * Apply Julien Grossiord's port non-80 patch. * Apply Steve Smith (ND)'s ColdFusion POST patch. * Better whitespace handling * Test if a function exists before allowing you to export it * Add Kae's IFRAME patch. * Add C# support. * All-numeric array indices -> JS array, not object. THINGS THAT WERE TO DO AND ARE NOW TO DONE ------------------------------------------ * Encode/serialize array elements * Support for "options" such as post-to-an-ID and POST/GET submit. * Added sajax_set_remote_url or something along those lines instead of $REQUEST_URI * Support POST * Add CFML, ASP.Net * Fix Perl module (with the contributed code) sajax-0.12/Changes.txt0100644000175000017500000000440110367342671013642 0ustar tlacktlackSAJAX CHANGELOG --------------- Sajax version 0.12 (January 30, 2006) * [php] Numerous improvements to serialization, support for varied PHP setups, addition of sajax_cancel(). * [asp] Removed due to serious bugs Sajax version 0.10 (March 21, 2005) * [php] Support for POST instead of just GET. Set $sajax_request_type. Based on code from Folletto Malefico, to whom I owe thanks. POST mode should be used if you are sending long requests (more than 512 bytes) or if you are modifying data with the request. * [php] (untested) Support for GET/POST to pages other than $REQUEST_URI. Set $sajax_remote_uri to the desired URL to get this behavior. * [php] Small fixes to the Wall example, thanks to Leonardo Lorieri and Jesse Sightler. * [cf] Cold Fusion MX support (Thanks Eric Moritz) * [asp] ASP support (Thanks Jared Nuzzolillo) * [python] Improvements to the Python backend from Adam Collard Sajax version 0.9 (March 15, 2005) * [php] Major changes to the PHP backend: * [php] Renamed incl_sajax.php to Sajax.php to fit PEAR and other language naming conventions * [php] Functions and vars previously named rs_* are now sajax_* * [php] Function stubs all call one generalized sajax_do_call() dispatcher * [php] Added non-echoing version of sajax_echo_javascript() called sajax_get_javascript via the magic of output buffering * [php] Changed all examples to support new framework * [perl] Applied fix for URL encoding of space (Thanks Max Maischein) * [ruby] Added Ruby backend contributed by anonymous author * [io] Added Io (http://www.iolanguage.com/) backend by Sajax team @ MM Sajax version 0.8 (March 9, 2005) * [php] Bug in the long-open-tags changes. Thanks to Matthew M. Vince. * [lua] Backend port added. Thanks to Javier Guerra. Sajax version 0.7 (March 9, 2005) * [php] Major bug calling remote functions without args. Sajax version 0.6 (March 8, 2005) * Layout of archive changed; base folder changed; subfolders added for backends * [php] Used short open tags by default. Thanks to Matthew M. Vince. * [perl] Backend port added. Thanks to Nathan Schmidt, Jason Purdy and Nate Mueller. * [python] Backend port added. Thanks to Adam Collard. Please note that this port is licensed under the Creative Commons "By" License version 2.0. sajax-0.12/Readme.txt0100644000175000017500000000064610226772213013467 0ustar tlacktlackWELCOME TO SAJAX ---------------- Sajax is a cross-platform, cross-browser web scripting toolkit that makes it easy to expose functions in your code to JavaScript. For more information about Sajax, please see the homepage: http://www.modernmethod.com/sajax/ In this archive you will find a folder for each platform that is currently supported. Please see individual documentation in each folder for specific errata.