XOOPS  2.6.0
bloggerapi.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
23 {
24 
26  {
28  $this->_setXoopsTagMap('storyid', 'postid');
29  $this->_setXoopsTagMap('published', 'dateCreated');
30  $this->_setXoopsTagMap('uid', 'userid');
31  }
32 
33  function newPost()
34  {
35  if (!$this->_checkUser($this->params[2], $this->params[3])) {
36  $this->response->add(new XoopsXmlRpcFault(104));
37  } else {
38  if (!$fields = $this->_getPostFields(null, $this->params[1])) {
39  $this->response->add(new XoopsXmlRpcFault(106));
40  } else {
41  $missing = array();
42  $post = array();
43  foreach ($fields as $tag => $detail) {
44  $maptag = $this->_getXoopsTagMap($tag);
45  $data = $this->_getTagCdata($this->params[4], $maptag, true);
46  if (trim($data) == ''){
47  if ($detail['required']) {
48  $missing[] = $maptag;
49  }
50  } else {
51  $post[$tag] = $data;
52  }
53  }
54  if (count($missing) > 0) {
55  $msg = '';
56  foreach ($missing as $m) {
57  $msg .= '<'.$m.'> ';
58  }
59  $this->response->add(new XoopsXmlRpcFault(109, $msg));
60  } else {
61  $newparams = array();
62  // Xoops Api ignores App key
63  $newparams[0] = $this->params[1];
64  $newparams[1] = $this->params[2];
65  $newparams[2] = $this->params[3];
66  foreach ($post as $key => $value) {
67  $newparams[3][$key] = $value;
68  unset($value);
69  }
70  $newparams[3]['xoops_text'] = $this->params[4];
71  $newparams[4] = $this->params[5];
72  $xoopsapi = $this->_getXoopsApi($newparams);
73  $xoopsapi->_setUser($this->user, $this->isadmin);
74  $xoopsapi->newPost();
75  }
76  }
77  }
78  }
79 
80  function editPost()
81  {
82  if (!$this->_checkUser($this->params[2], $this->params[3])) {
83  $this->response->add(new XoopsXmlRpcFault(104));
84  } else {
85  if (!$fields = $this->_getPostFields($this->params[1])) {
86  } else {
87  $missing = array();
88  $post = array();
89  foreach ($fields as $tag => $detail) {
90  $data = $this->_getTagCdata($this->params[4], $tag, true);
91  if (trim($data) == ''){
92  if ($detail['required']) {
93  $missing[] = $tag;
94  }
95  } else {
96  $post[$tag] = $data;
97  }
98  }
99  if (count($missing) > 0) {
100  $msg = '';
101  foreach ($missing as $m) {
102  $msg .= '<'.$m.'> ';
103  }
104  $this->response->add(new XoopsXmlRpcFault(109, $msg));
105  } else {
106  $newparams = array();
107  // XOOPS API ignores App key (index 0 of params)
108  $newparams[0] = $this->params[1];
109  $newparams[1] = $this->params[2];
110  $newparams[2] = $this->params[3];
111  foreach ($post as $key => $value) {
112  $newparams[3][$key] = $value;
113  unset($value);
114  }
115  $newparams[3]['xoops_text'] = $this->params[4];
116  $newparams[4] = $this->params[5];
117  $xoopsapi = $this->_getXoopsApi($newparams);
118  $xoopsapi->_setUser($this->user, $this->isadmin);
119  $xoopsapi->editPost();
120  }
121  }
122  }
123  }
124 
125  function deletePost()
126  {
127  if (!$this->_checkUser($this->params[2], $this->params[3])) {
128  $this->response->add(new XoopsXmlRpcFault(104));
129  } else {
130  // XOOPS API ignores App key (index 0 of params)
131  array_shift($this->params);
132  $xoopsapi = $this->_getXoopsApi($this->params);
133  $xoopsapi->_setUser($this->user, $this->isadmin);
134  $xoopsapi->deletePost();
135  }
136  }
137 
138  function getPost()
139  {
140  if (!$this->_checkUser($this->params[2], $this->params[3])) {
141  $this->response->add(new XoopsXmlRpcFault(104));
142  } else {
143  // XOOPS API ignores App key (index 0 of params)
144  array_shift($this->params);
145  $xoopsapi = $this->_getXoopsApi($this->params);
146  $xoopsapi->_setUser($this->user, $this->isadmin);
147  $ret = $xoopsapi->getPost(false);
148  if (is_array($ret)) {
149  $struct = new XoopsXmlRpcStruct();
150  $content = '';
151  foreach ($ret as $key => $value) {
152  $maptag = $this->_getXoopsTagMap($key);
153  switch($maptag) {
154  case 'userid':
155  $struct->add('userid', new XoopsXmlRpcString($value));
156  break;
157  case 'dateCreated':
158  $struct->add('dateCreated', new XoopsXmlRpcDatetime($value));
159  break;
160  case 'postid':
161  $struct->add('postid', new XoopsXmlRpcString($value));
162  break;
163  default :
164  $content .= '<'.$key.'>'.trim($value).'</'.$key.'>';
165  break;
166  }
167  }
168  $struct->add('content', new XoopsXmlRpcString($content));
169  $this->response->add($struct);
170  } else {
171  $this->response->add(new XoopsXmlRpcFault(106));
172  }
173  }
174  }
175 
176  function getRecentPosts()
177  {
178  if (!$this->_checkUser($this->params[2], $this->params[3])) {
179  $this->response->add(new XoopsXmlRpcFault(104));
180  } else {
181  // XOOPS API ignores App key (index 0 of params)
182  array_shift($this->params);
183  $xoopsapi = $this->_getXoopsApi($this->params);
184  $xoopsapi->_setUser($this->user, $this->isadmin);
185  $ret = $xoopsapi->getRecentPosts(false);
186  if (is_array($ret)) {
187  $arr = new XoopsXmlRpcArray();
188  $count = count($ret);
189  if ($count == 0) {
190  $this->response->add(new XoopsXmlRpcFault(106, 'Found 0 Entries'));
191  } else {
192  for ($i = 0; $i < $count; ++$i) {
193  $struct = new XoopsXmlRpcStruct();
194  $content = '';
195  foreach($ret[$i] as $key => $value) {
196  $maptag = $this->_getXoopsTagMap($key);
197  switch($maptag) {
198  case 'userid':
199  $struct->add('userid', new XoopsXmlRpcString($value));
200  break;
201  case 'dateCreated':
202  $struct->add('dateCreated', new XoopsXmlRpcDatetime($value));
203  break;
204  case 'postid':
205  $struct->add('postid', new XoopsXmlRpcString($value));
206  break;
207  default :
208  $content .= '<'.$key.'>'.trim($value).'</'.$key.'>';
209  break;
210  }
211  }
212  $struct->add('content', new XoopsXmlRpcString($content));
213  $arr->add($struct);
214  unset($struct);
215  }
216  $this->response->add($arr);
217  }
218  } else {
219  $this->response->add(new XoopsXmlRpcFault(106));
220  }
221  }
222  }
223 
224  function getUsersBlogs()
225  {
226  if (!$this->_checkUser($this->params[1], $this->params[2])) {
227  $this->response->add(new XoopsXmlRpcFault(104));
228  } else {
229  $arr = new XoopsXmlRpcArray();
230  $struct = new XoopsXmlRpcStruct();
232  $struct->add('url', new XoopsXmlRpcString($xoops_url.'/modules/'.$this->module->getVar('dirname').'/'));
233  $struct->add('blogid', new XoopsXmlRpcString($this->module->getVar('mid')));
234  $struct->add('blogName', new XoopsXmlRpcString('XOOPS Blog'));
235  $arr->add($struct);
236  $this->response->add($arr);
237  }
238  }
239 
240  function getUserInfo()
241  {
242  if (!$this->_checkUser($this->params[1], $this->params[2])) {
243  $this->response->add(new XoopsXmlRpcFault(104));
244  } else {
245  $struct = new XoopsXmlRpcStruct();
246  $struct->add('nickname', new XoopsXmlRpcString($this->user->getVar('uname')));
247  $struct->add('userid', new XoopsXmlRpcString($this->user->getVar('uid')));
248  $struct->add('url', new XoopsXmlRpcString($this->user->getVar('url')));
249  $struct->add('email', new XoopsXmlRpcString($this->user->getVar('email')));
250  $struct->add('lastname', new XoopsXmlRpcString(''));
251  $struct->add('firstname', new XoopsXmlRpcString($this->user->getVar('name')));
252  $this->response->add($struct);
253  }
254  }
255 
256  function getTemplate()
257  {
258  if (!$this->_checkUser($this->params[2], $this->params[3])) {
259  $this->response->add(new XoopsXmlRpcFault(104));
260  } else {
261  switch ($this->params[5]) {
262  case 'main':
263  $this->response->add(new XoopsXmlRpcFault(107));
264  break;
265  case 'archiveIndex':
266  $this->response->add(new XoopsXmlRpcFault(107));
267  break;
268  default:
269  $this->response->add(new XoopsXmlRpcFault(107));
270  break;
271  }
272  }
273  }
274 
275  function setTemplate()
276  {
277  if (!$this->_checkUser($this->params[2], $this->params[3])) {
278  $this->response->add(new XoopsXmlRpcFault(104));
279  } else {
280  $this->response->add(new XoopsXmlRpcFault(107));
281  }
282  }
283 }
284 ?>
$xoops_url
Definition: backend.php:32
_getXoopsApi(&$params)
Definition: xmlrpcapi.php:154
$i
Definition: dialog.php:68
BloggerApi(&$params, &$response, &$module)
Definition: bloggerapi.php:25
_getTagCdata(&$text, $tag, $remove=true)
Definition: xmlrpcapi.php:139
XoopsXmlRpcApi(array &$params, XoopsXmlRpcResponse &$response, XoopsModule &$module)
Definition: xmlrpcapi.php:49
_getPostFields($post_id=null, $blog_id=null)
Definition: xmlrpcapi.php:97
_getXoopsTagMap($xoopstag)
Definition: xmlrpcapi.php:131
static get($name)
_checkUser($username, $password)
Definition: xmlrpcapi.php:64
_setXoopsTagMap($xoopstag, $blogtag)
Definition: xmlrpcapi.php:124
if(!is_object($module)||!$module->getVar('isactive')) $msg
Definition: groupperm.php:38