XOOPS  2.6.0
metaweblogapi.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 {
25  {
27  $this->_setXoopsTagMap('storyid', 'postid');
28  $this->_setXoopsTagMap('published', 'dateCreated');
29  $this->_setXoopsTagMap('uid', 'userid');
30  //$this->_setXoopsTagMap('hometext', 'description');
31  }
32 
33  function newPost()
34  {
35  if (!$this->_checkUser($this->params[1], $this->params[2])) {
36 
37  $this->response->add(new XoopsXmlRpcFault(104));
38  } else {
39  if (!$fields = $this->_getPostFields(null, $this->params[0])) {
40  $this->response->add(new XoopsXmlRpcFault(106));
41  } else {
42  $missing = array();
43  $post = array();
44  foreach ($fields as $tag => $detail) {
45  $maptag = $this->_getXoopsTagMap($tag);
46  if (!isset($this->params[3][$maptag])) {
47  $data = $this->_getTagCdata($this->params[3]['description'], $maptag, true);
48  if (trim($data) == ''){
49  if ($detail['required']) {
50  $missing[] = $maptag;
51  }
52  } else {
53  $post[$tag] = $data;
54  }
55  } else {
56  $post[$tag] = $this->params[3][$maptag];
57  }
58  }
59  if (count($missing) > 0) {
60  $msg = '';
61  foreach ($missing as $m) {
62  $msg .= '<'.$m.'> ';echo $m;
63  }
64  $this->response->add(new XoopsXmlRpcFault(109, $msg));
65  } else {
66  $newparams = array();
67  $newparams[0] = $this->params[0];
68  $newparams[1] = $this->params[1];
69  $newparams[2] = $this->params[2];
70  foreach ($post as $key => $value) {
71  $newparams[3][$key] = $value;
72  unset($value);
73  }
74  $newparams[3]['xoops_text'] = $this->params[3]['description'];
75  if (isset($this->params[3]['categories']) && is_array($this->params[3]['categories'])) {
76  foreach ($this->params[3]['categories'] as $k => $v) {
77  $newparams[3]['categories'][$k] = $v;
78  }
79  }
80  $newparams[4] = $this->params[4];
81  $xoopsapi = $this->_getXoopsApi($newparams);
82  $xoopsapi->_setUser($this->user, $this->isadmin);
83  $xoopsapi->newPost();
84  }
85  }
86  }
87  }
88 
89  function editPost()
90  {
91  if (!$this->_checkUser($this->params[1], $this->params[2])) {
92  $this->response->add(new XoopsXmlRpcFault(104));
93  } else {
94  if (!$fields = $this->_getPostFields($this->params[0])) {
95  } else {
96  $missing = array();
97  $post = array();
98  foreach ($fields as $tag => $detail) {
99  $maptag = $this->_getXoopsTagMap($tag);
100  if (!isset($this->params[3][$maptag])) {
101  $data = $this->_getTagCdata($this->params[3]['description'], $maptag, true);
102  if (trim($data) == ''){
103  if ($detail['required']) {
104  $missing[] = $tag;
105  }
106  } else {
107  $post[$tag] = $data;
108  }
109  } else {
110  $post[$tag] = $this->params[3][$maptag];
111  }
112  }
113  if (count($missing) > 0) {
114  $msg = '';
115  foreach ($missing as $m) {
116  $msg .= '<'.$m.'> ';
117  }
118  $this->response->add(new XoopsXmlRpcFault(109, $msg));
119  } else {
120  $newparams = array();
121  $newparams[0] = $this->params[0];
122  $newparams[1] = $this->params[1];
123  $newparams[2] = $this->params[2];
124  foreach ($post as $key => $value) {
125  $newparams[3][$key] = $value;
126  unset($value);
127  }
128  if (isset($this->params[3]['categories']) && is_array($this->params[3]['categories'])) {
129  foreach ($this->params[3]['categories'] as $k => $v) {
130  $newparams[3]['categories'][$k] = $v;
131  }
132  }
133  $newparams[3]['xoops_text'] = $this->params[3]['description'];
134  $newparams[4] = $this->params[4];
135  $xoopsapi = $this->_getXoopsApi($newparams);
136  $xoopsapi->_setUser($this->user, $this->isadmin);
137  $xoopsapi->editPost();
138  }
139  }
140  }
141  }
142 
143  function getPost()
144  {
145  if (!$this->_checkUser($this->params[1], $this->params[2])) {
146  $this->response->add(new XoopsXmlRpcFault(104));
147  } else {
149  $xoopsapi = $this->_getXoopsApi($this->params);
150  $xoopsapi->_setUser($this->user, $this->isadmin);
151  $ret = $xoopsapi->getPost(false);
152  if (is_array($ret)) {
153  $struct = new XoopsXmlRpcStruct();
154  $content = '';
155  foreach ($ret as $key => $value) {
156  $maptag = $this->_getXoopsTagMap($key);
157  switch($maptag) {
158  case 'userid':
159  $struct->add('userid', new XoopsXmlRpcString($value));
160  break;
161  case 'dateCreated':
162  $struct->add('dateCreated', new XoopsXmlRpcDatetime($value));
163  break;
164  case 'postid':
165  $struct->add('postid', new XoopsXmlRpcString($value));
166  $struct->add('link', new XoopsXmlRpcString($xoops_url.'/modules/xoopssections/item.php?item='.$value));
167  $struct->add('permaLink', new XoopsXmlRpcString($xoops_url.'/modules/xoopssections/item.php?item='.$value));
168  break;
169  case 'title':
170  $struct->add('title', new XoopsXmlRpcString($value));
171  break;
172  default :
173  $content .= '<'.$key.'>'.trim($value).'</'.$key.'>';
174  break;
175  }
176  }
177  $struct->add('description', new XoopsXmlRpcString($content));
178  $this->response->add($struct);
179  } else {
180  $this->response->add(new XoopsXmlRpcFault(106));
181  }
182  }
183  }
184 
185  function getRecentPosts()
186  {
187  if (!$this->_checkUser($this->params[1], $this->params[2])) {
188  $this->response->add(new XoopsXmlRpcFault(104));
189  } else {
191  $xoopsapi = $this->_getXoopsApi($this->params);
192  $xoopsapi->_setUser($this->user, $this->isadmin);
193  $ret = $xoopsapi->getRecentPosts(false);
194  if (is_array($ret)) {
195  $arr = new XoopsXmlRpcArray();
196  $count = count($ret);
197  if ($count == 0) {
198  $this->response->add(new XoopsXmlRpcFault(106, 'Found 0 Entries'));
199  } else {
200  for ($i = 0; $i < $count; ++$i) {
201  $struct = new XoopsXmlRpcStruct();
202  $content = '';
203  foreach($ret[$i] as $key => $value) {
204  $maptag = $this->_getXoopsTagMap($key);
205  switch($maptag) {
206  case 'userid':
207  $struct->add('userid', new XoopsXmlRpcString($value));
208  break;
209  case 'dateCreated':
210  $struct->add('dateCreated', new XoopsXmlRpcDatetime($value));
211  break;
212  case 'postid':
213  $struct->add('postid', new XoopsXmlRpcString($value));
214  $struct->add('link', new XoopsXmlRpcString($xoops_url.'/modules/news/article.php?item_id='.$value));
215  $struct->add('permaLink', new XoopsXmlRpcString($xoops_url.'/modules/news/article.php?item_id='.$value));
216  break;
217  case 'title':
218  $struct->add('title', new XoopsXmlRpcString($value));
219  break;
220  default :
221  $content .= '<'.$key.'>'.trim($value).'</'.$key.'>';
222  break;
223  }
224  }
225  $struct->add('description', new XoopsXmlRpcString($content));
226  $arr->add($struct);
227  unset($struct);
228  }
229  $this->response->add($arr);
230  }
231  } else {
232  $this->response->add(new XoopsXmlRpcFault(106));
233  }
234  }
235  }
236 
237  function getCategories()
238  {
239  if (!$this->_checkUser($this->params[1], $this->params[2])) {
240  $this->response->add(new XoopsXmlRpcFault(104));
241  } else {
243  $xoopsapi = $this->_getXoopsApi($this->params);
244  $xoopsapi->_setUser($this->user, $this->isadmin);
245  $ret = $xoopsapi->getCategories(false);
246  if (is_array($ret)) {
247  $arr = new XoopsXmlRpcArray();
248  foreach ($ret as $id => $detail) {
249  $struct = new XoopsXmlRpcStruct();
250  $struct->add('description', new XoopsXmlRpcString($detail));
251  $struct->add('htmlUrl', new XoopsXmlRpcString($xoops_url.'/modules/news/index.php?storytopic='.$id));
252  $struct->add('rssUrl', new XoopsXmlRpcString(''));
253  $catstruct = new XoopsXmlRpcStruct();
254  $catstruct->add($detail['title'], $struct);
255  $arr->add($catstruct);
256  unset($struct);
257  unset($catstruct);
258  }
259  $this->response->add($arr);
260  } else {
261  $this->response->add(new XoopsXmlRpcFault(106));
262  }
263  }
264  }
265 }
266 ?>
$xoops_url
Definition: backend.php:32
_getXoopsApi(&$params)
Definition: xmlrpcapi.php:154
$i
Definition: dialog.php:68
MetaWeblogApi(&$params, &$response, &$module)
_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
$id
Definition: admin_menu.php:36
_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