root/geowiki/jsrsServer.php.inc

Revision 9, 3.4 kB (checked in by mikel, 3 years ago)

geowiki initial checkin

Line 
1 <?php
2
3 //
4 // jsrsServer.php - javascript remote scripting server include
5 //
6 // Orginal Author:  Brent Ashley [jsrs@megahuge.com]
7 // PHP version   :  Sébastien Cramatte [sebastien@webeclaireur.com]
8 //                  Pierre Cailleux [cailleux@noos.fr]
9 // Date          :  May 2001
10 //
11 // see jsrsClient.js for version info
12 //
13 //  see license.txt for copyright and license info
14
15 function jsrsDispatch($validFuncs ){
16   $func = jsrsBuildFunc($validFuncs);
17  
18   if ($func != ""){
19     $retval;
20    
21     eval("\$retval =  " . $func . ";");
22    
23     if (strlen($retval)>0){
24       jsrsReturn($retval."");
25     } else {
26       jsrsReturn("");
27     }
28   } else {
29     jsrsReturnError("function builds as empty string");
30   }
31 }
32
33 function jsrsReturn($payload) {
34   global $C;
35   if(!isset($C)) $C = (isset($_REQUEST['C']) ? $_REQUEST['C'] : "");
36
37   Print (
38       "<html><head></head><body onload=\"p=document.layers?parentLayer:window.parent;p.jsrsLoaded('"
39     . $C . "');\">jsrsPayload:<br>"
40     . "<form name=\"jsrs_Form\"><textarea name=\"jsrs_Payload\" id=\"jsrs_Payload\">"
41     . jsrsEscape($payload) . "</textarea></form></body></html>");
42     exit();
43 }
44
45 function jsrsEscape($str){
46   // escape ampersands so special chars aren't interpreted
47   $tmp = ereg_replace( "&", "&amp;", $str );
48   // escape slashes  with whacks so end tags don't interfere with return html
49   return ereg_replace( "\/" , "\\/",$tmp);
50 }
51
52 /////////////////////////////
53 //
54 // user functions
55
56
57 function jsrsReturnError($str){
58   global $C;
59   if(!isset($C)) $C = (isset($_REQUEST['C']) ? $_REQUEST['C'] : "");
60  
61   // escape quotes
62   $cleanStr = ereg_replace("\'","\\'",$str);
63  
64   // !!!! --- Warning -- !!!
65   $cleanStr = "jsrsError: " . ereg_replace("\"", "\\\"", $cleanStr);
66   print ("<html><head></head><body "
67          . "onload=\"p=document.layers?parentLayer:window.parent;p.jsrsError('" . $C . "','" . urlencode($str) . "');\">"
68          . $cleanStr . "</body></html>" );
69   exit();
70 }
71
72 function jsrsArrayToString( $a, $delim ){
73   // user function to flatten 1-dim array to string for return to client
74   $d = "~";
75   if (!isset($delim)) $d = $delim;
76   return implode($a,$d);
77 }
78
79
80 function jsrsBuildFunc($validFuncs) {
81  global $F;
82  if(!isset($F)) $F = (isset($_REQUEST['F']) ? $_REQUEST['F'] : "");
83  
84  $func = "";
85  
86  if ($F != "") {
87   $func = $F;
88  
89      
90   // make sure it's in the dispatch list
91   if (strpos(strtoupper($validFuncs),strtoupper($func))===false)
92      jsrsReturnError($func . " is not a valid function" );
93    
94    $func .= "(";
95    $i = 0;
96    
97    //--- To optimize ! ---
98    eval("global \$P$i;");
99    eval("if(!isset(\$P$i)) \$P$i = (isset(\$_REQUEST['P$i']) ? \$_REQUEST['P$i']:'');");
100    $Ptmp = "P". $i;
101      
102    while ($$Ptmp!="") {
103     $parm = $$Ptmp;
104     $parm = substr($parm,1,strlen($parm)-2);
105     $func .= "\"" . $parm . "\",";
106     $i++;
107     eval("global \$P$i;");
108     eval("if(!isset(\$P$i)) \$P$i = (isset(\$_REQUEST['P$i']) ? \$_REQUEST['P$i']:'');");
109     $Ptmp = "P". $i;
110    }
111    
112    if (substr($func,strlen($func)-1,1)==",") 
113     $func = substr($func,0,strlen($func)-1);
114
115     $func .= ")";
116   }
117  
118  return $func;
119 }
120
121 function jsrsEvalEscape($thing) {
122  $tmp = ereg_replace($thing,"\r\n","\n");
123  return $tmp;
124 }
125
126 function jsrsVBArrayToString($a,$delim) {
127  // --- not use in PHP see jsrsArrayToString method
128  return jsrsArrayToString($a,$delim);
129 }
130
131
132 ?>
133
134
135
Note: See TracBrowser for help on using the browser.