1 |
<?php |
---|
2 |
/** |
---|
3 |
* XMLRPC Widget class |
---|
4 |
* |
---|
5 |
* @project CWC2 |
---|
6 |
* @revision $Id: |
---|
7 |
* @purpose XMLRPC Widget class |
---|
8 |
* @author DM Solutions Group (sfournier@dmsolutions.ca) |
---|
9 |
* @copyright |
---|
10 |
* <b>Copyright (c) 2002, DM Solutions Group Inc.</b> |
---|
11 |
* Permission is hereby granted, free of charge, to any person obtaining a |
---|
12 |
* copy of this software and associated documentation files (the "Software"), |
---|
13 |
* to deal in the Software without restriction, including without limitation |
---|
14 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
---|
15 |
* and/or sell copies of the Software, and to permit persons to whom the |
---|
16 |
* Software is furnished to do so, subject to the following conditions: |
---|
17 |
* |
---|
18 |
* The above copyright notice and this permission notice shall be included |
---|
19 |
* in all copies or substantial portions of the Software. |
---|
20 |
* |
---|
21 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
22 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
23 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
---|
24 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
25 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
---|
26 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
27 |
* DEALINGS IN THE SOFTWARE. |
---|
28 |
*/ |
---|
29 |
|
---|
30 |
//added this primarily for the documentation generator. |
---|
31 |
if (!defined("CHAMELEON_FS_CORE")) |
---|
32 |
{ |
---|
33 |
define( "CHAMELEON_FS_CORE", realpath(str_replace("\\","/",dirname(__FILE__))."/..") ); |
---|
34 |
} |
---|
35 |
include_once (CHAMELEON_FS_CORE."/SharedResource/SharedResource.widget.php"); |
---|
36 |
include_once (CHAMELEON_FS_CORE."/Widget.php"); |
---|
37 |
include_once ("IXR_Library.inc.php"); |
---|
38 |
|
---|
39 |
/** |
---|
40 |
* XMLRPCWidget |
---|
41 |
* |
---|
42 |
* @desc Widget that build a XMLRPC call. |
---|
43 |
*/ |
---|
44 |
class XMLRPC extends CWCWidget |
---|
45 |
{ |
---|
46 |
var $mszURI = ""; |
---|
47 |
var $mszHost = ""; |
---|
48 |
var $mszMethod = ""; |
---|
49 |
|
---|
50 |
var $mszParams = ""; |
---|
51 |
var $mszSeparator = "|"; |
---|
52 |
var $mszStructSeparator = "__STRUCT_SEPARATOR__"; |
---|
53 |
|
---|
54 |
var $mnPort = 80; |
---|
55 |
|
---|
56 |
var $mszResult = "XMLRPCResult"; |
---|
57 |
var $mbCacheResult = false; |
---|
58 |
|
---|
59 |
/** |
---|
60 |
* XMLRPCWidget |
---|
61 |
* |
---|
62 |
* Constructor method for the XMLRPC widget. |
---|
63 |
*/ |
---|
64 |
function XMLRPC() |
---|
65 |
{ |
---|
66 |
// invoke constructor of parent |
---|
67 |
parent::CWCWidget(); |
---|
68 |
|
---|
69 |
// set the description for this widget |
---|
70 |
$this->szWidgetDescription = <<<EOT |
---|
71 |
XMLRPC is a simple widget that simply returns the value from a URL variable. |
---|
72 |
EOT; |
---|
73 |
if ($this->mszURI == "") $this->maAttributes["URI"] = new StringAttribute( "URI", true ); |
---|
74 |
if ($this->mszHost == "") $this->maAttributes["HOST"] = new StringAttribute( "HOST", true ); |
---|
75 |
if ($this->mszMethod == "") $this->maAttributes["METHOD"] = new StringAttribute( "METHOD", true ); |
---|
76 |
|
---|
77 |
$this->maAttributes["PORT"] = new IntegerAttribute( "PORT", false ); |
---|
78 |
$this->maAttributes["PARAMS"] = new StringAttribute( "PARAMS", false ); |
---|
79 |
$this->maAttributes["SEPARATOR"] = new StringAttribute( "SEPARATOR", false ); |
---|
80 |
$this->maAttributes["RESULT"] = new StringAttribute( "RESULT", false ); |
---|
81 |
$this->maAttributes["CACHERESULT"] = new BooleanAttribute( "CACHERESULT", false ); |
---|
82 |
|
---|
83 |
$this->mnPriority = PRIORITY_SUPER; |
---|
84 |
$this->mnMaturityLevel = MATURITY_BETA; |
---|
85 |
} |
---|
86 |
|
---|
87 |
/** |
---|
88 |
* InitDefault |
---|
89 |
*/ |
---|
90 |
function InitDefaults() |
---|
91 |
{ |
---|
92 |
parent::InitDefaults(); |
---|
93 |
|
---|
94 |
if ($this->mszURI == "") $this->mszURI = $this->maParams["URI"]; |
---|
95 |
if ($this->mszHost == "") $this->mszHost = $this->maParams["HOST"]; |
---|
96 |
if ($this->mszMethod == "") $this->mszMethod = $this->maParams["METHOD"]; |
---|
97 |
|
---|
98 |
if (substr($this->mszHost, -1) == "/") |
---|
99 |
$this->mszHost = substr($this->mszHost, 0, -1); |
---|
100 |
|
---|
101 |
if (substr($this->mszURI, 0, 1) != "/") |
---|
102 |
$this->mszURI = "/".$this->mszURI; |
---|
103 |
|
---|
104 |
if (isset($this->maParams["PORT"])) |
---|
105 |
$this->mnPort = $this->maParams["PORT"]; |
---|
106 |
|
---|
107 |
if (isset($this->maParams["PARAMS"])) |
---|
108 |
$this->mszParams = $this->maParams["PARAMS"]; |
---|
109 |
|
---|
110 |
if (isset($this->maParams["SEPARATOR"])) |
---|
111 |
$this->mszSeparator = $this->maParams["SEPARATOR"]; |
---|
112 |
|
---|
113 |
if (isset($this->maParams["STRUCTSEPARATOR"])) |
---|
114 |
$this->mszStructSeparator = $this->maParams["STRUCTSEPARATOR"]; |
---|
115 |
|
---|
116 |
if (isset($this->maParams["RESULT"])) |
---|
117 |
$this->mszResult = $this->maParams["RESULT"]; |
---|
118 |
|
---|
119 |
if (isset($this->maParams["CACHERESULT"])) |
---|
120 |
{ |
---|
121 |
$this->mbCacheResult = $this->maParams["CACHERESULT"]; |
---|
122 |
|
---|
123 |
if (strcasecmp($this->mbCacheResult, "true") == 0) |
---|
124 |
$this->mbCacheResult = true; |
---|
125 |
else |
---|
126 |
$this->mbCacheResult = false; |
---|
127 |
} |
---|
128 |
} |
---|
129 |
|
---|
130 |
|
---|
131 |
|
---|
132 |
/** |
---|
133 |
* Parse URL |
---|
134 |
*/ |
---|
135 |
function ParseURL() |
---|
136 |
{ |
---|
137 |
$szKey = md5($this->mszMethod.$this->mszParams.$this->mszHost.$this->mszURI.$this->mnPort); |
---|
138 |
|
---|
139 |
if ($this->mbCacheResult) |
---|
140 |
{ |
---|
141 |
if (isset($_SESSION["XMLRPCWidgetCachedResult"][$szKey])) |
---|
142 |
{ |
---|
143 |
$result = $_SESSION["XMLRPCWidgetCachedResult"][$szKey]; |
---|
144 |
|
---|
145 |
// Put result in shared resource. |
---|
146 |
$this->maSharedResourceWidgets[$this->mszResult] =& $result; |
---|
147 |
return parent::ParseURL(); |
---|
148 |
} |
---|
149 |
} |
---|
150 |
|
---|
151 |
$aParams = $this->ProcessParams(); |
---|
152 |
|
---|
153 |
$result = $this->CallServer($aParams); |
---|
154 |
|
---|
155 |
if (is_array($result)) |
---|
156 |
{ |
---|
157 |
// Cache result if set. |
---|
158 |
if ($this->mbCacheResult) |
---|
159 |
{ |
---|
160 |
$_SESSION["XMLRPCWidgetCachedResult"][$szKey] = $result; |
---|
161 |
} |
---|
162 |
// Put result in shared resource. |
---|
163 |
$this->maSharedResourceWidgets[$this->mszResult] =& $result; |
---|
164 |
} |
---|
165 |
else |
---|
166 |
{ |
---|
167 |
return false; |
---|
168 |
} |
---|
169 |
return parent::ParseURL(); |
---|
170 |
} |
---|
171 |
|
---|
172 |
function CallServer($aParams) |
---|
173 |
{ |
---|
174 |
$client = new IXR_Client($this->mszHost.$this->mszURI); |
---|
175 |
$res = call_user_func_array(array(&$client, "query"), array_merge(array($this->mszMethod), $aParams)); |
---|
176 |
|
---|
177 |
return $client->getResponse(); |
---|
178 |
} |
---|
179 |
|
---|
180 |
function ProcessParams() |
---|
181 |
{ |
---|
182 |
$aParams = array(); |
---|
183 |
|
---|
184 |
// Parse Parameters |
---|
185 |
$aszParams = explode($this->mszStructSeparator, $this->mszParams); |
---|
186 |
|
---|
187 |
$nbParam = count($aszParams); |
---|
188 |
|
---|
189 |
for($i=0;$i<$nbParam;$i++) |
---|
190 |
{ |
---|
191 |
$aszParams2 = explode($this->mszSeparator, $aszParams[$i]); |
---|
192 |
|
---|
193 |
$nbParam2 = count($aszParams2)+1; |
---|
194 |
|
---|
195 |
$aTmp = array(); |
---|
196 |
for ($j=0;$j<=$nbParam2;$j=$j+2) |
---|
197 |
{ |
---|
198 |
if (isset($aszParams2[$j]) && isset($aszParams2[$j+1])) |
---|
199 |
{ |
---|
200 |
$aTmp[$aszParams2[$j]] = $aszParams2[$j+1]; |
---|
201 |
} |
---|
202 |
} |
---|
203 |
|
---|
204 |
if ($nbParam == 1) |
---|
205 |
{ |
---|
206 |
$aParams = array_merge($aParams, $aTmp); |
---|
207 |
} |
---|
208 |
else |
---|
209 |
{ |
---|
210 |
$aParams = array_merge($aParams, array($aTmp)); |
---|
211 |
} |
---|
212 |
} |
---|
213 |
|
---|
214 |
return $aParams; |
---|
215 |
} |
---|
216 |
} |
---|
217 |
?> |
---|